Skip to content

Commit d7163ea

Browse files
committed
add minor version to info command
Add the minor version number to the info command through reading the sysfs device version attribute in linux, all other platforms use gas_read of device_version in sys_info register. Info adding the resulting device version coverted to minor ver and added to HW revision section of the print device info cmd.
1 parent 3bb6ce6 commit d7163ea

File tree

11 files changed

+65
-1
lines changed

11 files changed

+65
-1
lines changed

cli/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ static int print_dev_info(struct switchtec_dev *dev)
191191
char version[32];
192192
enum switchtec_boot_phase phase;
193193
enum switchtec_rev hw_rev;
194+
char minor_str[8] = "";
195+
int dev_ver;
196+
int minor_ver;
194197

195198
device_id = switchtec_device_id(dev);
196199

@@ -203,11 +206,20 @@ static int print_dev_info(struct switchtec_dev *dev)
203206
switchtec_perror("dev info");
204207
return ret;
205208
}
209+
if (switchtec_is_gen5(dev)) {
210+
switchtec_get_device_version(dev, &dev_ver);
211+
if (ret) {
212+
switchtec_perror("dev version");
213+
return ret;
214+
}
215+
minor_ver = ((dev_ver >> 0x10) & 0xFF);
216+
sprintf(minor_str, ".%d", minor_ver);
217+
}
206218

207219
printf("%s (%s):\n", switchtec_name(dev),
208220
switchtec_phase_id_str(phase));
209221
printf(" Generation: %s\n", switchtec_gen_str(dev));
210-
printf(" HW Revision: %s\n", switchtec_rev_str(hw_rev));
222+
printf(" HW Revision: %s%s\n", switchtec_rev_str(hw_rev), minor_str);
211223
printf(" Variant: %s\n",
212224
device_id ? switchtec_variant_str(dev) : "N/A");
213225
if (device_id)

inc/switchtec/switchtec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ int switchtec_list(struct switchtec_device_info **devlist);
358358
void switchtec_list_free(struct switchtec_device_info *devlist);
359359
int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf,
360360
size_t buflen);
361+
int switchtec_get_device_version(struct switchtec_dev *dev, int *res);
361362
int switchtec_cmd(struct switchtec_dev *dev, uint32_t cmd,
362363
const void *payload, size_t payload_len, void *resp,
363364
size_t resp_len);

lib/platform/gasops.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ int gasop_get_fw_version(struct switchtec_dev *dev, char *buf,
188188
return 0;
189189
}
190190

191+
int gasop_get_device_version(struct switchtec_dev *dev, int *res)
192+
{
193+
uint32_t dev_ver;
194+
dev_ver = gas_reg_read32(dev, sys_info.device_version);
195+
196+
*res = dev_ver;
197+
return 0;
198+
}
199+
191200
int gasop_pff_to_port(struct switchtec_dev *dev, int pff,
192201
int *partition, int *port)
193202
{

lib/platform/gasops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int gasop_cmd(struct switchtec_dev *dev, uint32_t cmd,
3636
int gasop_get_device_id(struct switchtec_dev *dev);
3737
int gasop_get_fw_version(struct switchtec_dev *dev, char *buf,
3838
size_t buflen);
39+
int gasop_get_device_version(struct switchtec_dev *dev, int *res);
3940
int gasop_pff_to_port(struct switchtec_dev *dev, int pff,
4041
int *partition, int *port);
4142
int gasop_port_to_pff(struct switchtec_dev *dev, int partition,

lib/platform/linux-eth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ static const struct switchtec_ops eth_ops = {
524524
.cmd = eth_cmd,
525525
.get_device_id = gasop_get_device_id,
526526
.get_fw_version = gasop_get_fw_version,
527+
.get_device_version = gasop_get_device_version,
527528
.pff_to_port = gasop_pff_to_port,
528529
.port_to_pff = gasop_port_to_pff,
529530
.flash_part = gasop_flash_part,

lib/platform/linux-i2c.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ static const struct switchtec_ops i2c_ops = {
623623
.cmd = gasop_cmd,
624624
.get_device_id = gasop_get_device_id,
625625
.get_fw_version = gasop_get_fw_version,
626+
.get_device_version = gasop_get_device_version,
626627
.pff_to_port = gasop_pff_to_port,
627628
.port_to_pff = gasop_port_to_pff,
628629
.flash_part = gasop_flash_part,

lib/platform/linux-uart.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ static const struct switchtec_ops uart_ops = {
439439
.cmd = gasop_cmd,
440440
.get_device_id = gasop_get_device_id,
441441
.get_fw_version = gasop_get_fw_version,
442+
.get_device_version = gasop_get_device_version,
442443
.pff_to_port = gasop_pff_to_port,
443444
.port_to_pff = gasop_port_to_pff,
444445
.flash_part = gasop_flash_part,

lib/platform/linux.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,26 @@ static int linux_get_fw_version(struct switchtec_dev *dev, char *buf,
300300
return 0;
301301
}
302302

303+
static int linux_get_device_version(struct switchtec_dev *dev, int *version_res)
304+
{
305+
int ret;
306+
int version;
307+
char syspath[PATH_MAX];
308+
struct switchtec_linux *ldev = to_switchtec_linux(dev);
309+
310+
ret = dev_to_sysfs_path(ldev, "device_version", syspath, sizeof(syspath));
311+
if (ret)
312+
return ret;
313+
314+
version = sysfs_read_int(syspath, 16);
315+
if (version < 0)
316+
return version;
317+
318+
memcpy(version_res, &version, sizeof(int));
319+
320+
return 0;
321+
}
322+
303323
static int submit_cmd(struct switchtec_linux *ldev, uint32_t cmd,
304324
const void *payload, size_t payload_len)
305325
{
@@ -971,6 +991,7 @@ static const struct switchtec_ops linux_ops = {
971991
.close = linux_close,
972992
.get_device_id = linux_get_device_id,
973993
.get_fw_version = linux_get_fw_version,
994+
.get_device_version = linux_get_device_version,
974995
.cmd = linux_cmd,
975996
.get_devices = linux_get_devices,
976997
.pff_to_port = linux_pff_to_port,

lib/platform/platform.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ int switchtec_get_fw_version(struct switchtec_dev *dev, char *buf,
150150
return 0;
151151
}
152152

153+
/**
154+
* @brief Get the minor version number as a user readable int
155+
* @ingroup Device
156+
* @param[in] dev Switchtec device handle
157+
* @param[in] res Int to put the version in
158+
*/
159+
int switchtec_get_device_version(struct switchtec_dev *dev, int *res)
160+
{
161+
int ret;
162+
if (!dev->ops->get_device_version)
163+
return 0;
164+
165+
return dev->ops->get_device_version(dev, res);
166+
}
167+
153168
/**
154169
* @brief Execute an MRPC command
155170
* @ingroup Device

lib/platform/windows.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ static const struct switchtec_ops windows_ops = {
432432

433433
.get_device_id = gasop_get_device_id,
434434
.get_fw_version = gasop_get_fw_version,
435+
.get_device_version = gasop_get_device_version,
435436
.pff_to_port = gasop_pff_to_port,
436437
.port_to_pff = gasop_port_to_pff,
437438
.flash_part = gasop_flash_part,

0 commit comments

Comments
 (0)