Skip to content

Commit a41225f

Browse files
committed
Merge branch 'devel'
2 parents 11d81a3 + 53da28d commit a41225f

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

cli/main.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,31 @@ static int print_dev_info(struct switchtec_dev *dev)
189189
int ret;
190190
int device_id;
191191
char version[64];
192+
enum switchtec_boot_phase phase;
192193
enum switchtec_rev hw_rev;
193194

194195
device_id = switchtec_device_id(dev);
195196

196197
ret = switchtec_get_fw_version(dev, version, sizeof(version));
197-
if (ret < 0) {
198-
switchtec_perror("dev info");
199-
return ret;
200-
}
198+
if (ret < 0)
199+
strcpy(version, "N/A");
201200

202-
ret = switchtec_get_device_info(dev, NULL, NULL, &hw_rev);
201+
ret = switchtec_get_device_info(dev, &phase, NULL, &hw_rev);
203202
if (ret) {
204203
switchtec_perror("dev info");
205204
return ret;
206205
}
207206

208-
printf("%s:\n", switchtec_name(dev));
207+
printf("%s (%s):\n", switchtec_name(dev),
208+
switchtec_phase_id_str(phase));
209209
printf(" Generation: %s\n", switchtec_gen_str(dev));
210210
printf(" HW Revision: %s\n", switchtec_rev_str(hw_rev));
211-
printf(" Variant: %s\n", switchtec_variant_str(dev));
212-
printf(" Device ID: 0x%04x\n", device_id);
211+
printf(" Variant: %s\n",
212+
device_id ? switchtec_variant_str(dev) : "N/A");
213+
if (device_id)
214+
printf(" Device ID: 0x%04x\n", device_id);
215+
else
216+
printf(" Device ID: %s\n", "N/A");
213217
printf(" FW Version: %s\n", version);
214218

215219
return 0;

cli/mfg.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@ static const struct argconfig_choice secure_state_choices[] = {
6464
{}
6565
};
6666

67-
static const char* phase_id_to_string(enum switchtec_boot_phase phase_id)
68-
{
69-
switch(phase_id) {
70-
case SWITCHTEC_BOOT_PHASE_BL1:
71-
return "BL1";
72-
case SWITCHTEC_BOOT_PHASE_BL2:
73-
return "BL2";
74-
case SWITCHTEC_BOOT_PHASE_FW:
75-
return "Main Firmware";
76-
default:
77-
return "Unknown Phase";
78-
}
79-
}
80-
8167
#define CMD_DESC_PING "ping device and get current boot phase"
8268

8369
static int ping(int argc, char **argv)
@@ -282,7 +268,8 @@ static int info(int argc, char **argv)
282268
}
283269

284270
phase_id = switchtec_boot_phase(cfg.dev);
285-
printf("Current Boot Phase: \t\t\t%s\n", phase_id_to_string(phase_id));
271+
printf("Current Boot Phase: \t\t\t%s\n",
272+
switchtec_phase_id_str(phase_id));
286273

287274
ret = switchtec_sn_ver_get(cfg.dev, &sn_info);
288275
if (ret) {

inc/switchtec/switchtec.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,24 @@ static inline const char *switchtec_variant_str(struct switchtec_dev *dev)
610610
return str;
611611
}
612612

613+
/**
614+
* @brief Return the phase string for a phase id.
615+
*/
616+
static inline const char* switchtec_phase_id_str(
617+
enum switchtec_boot_phase phase_id)
618+
{
619+
switch(phase_id) {
620+
case SWITCHTEC_BOOT_PHASE_BL1:
621+
return "BL1";
622+
case SWITCHTEC_BOOT_PHASE_BL2:
623+
return "BL2";
624+
case SWITCHTEC_BOOT_PHASE_FW:
625+
return "Main Firmware";
626+
default:
627+
return "Unknown Phase";
628+
}
629+
}
630+
613631
/** @brief Number of GT/s capable for each PCI generation or \p link_rate */
614632
static const float switchtec_gen_transfers[] = {0, 2.5, 5, 8, 16, 32};
615633
/** @brief Number of GB/s capable for each PCI generation or \p link_rate */
@@ -835,6 +853,8 @@ int switchtec_fw_read(struct switchtec_dev *dev, unsigned long addr,
835853
size_t len, void *buf);
836854
void switchtec_fw_perror(const char *s, int ret);
837855
int switchtec_fw_file_info(int fd, struct switchtec_fw_image_info *info);
856+
int switchtec_get_device_id_bl2(struct switchtec_dev *dev,
857+
unsigned short *device_id);
838858
int switchtec_fw_file_secure_version_newer(struct switchtec_dev *dev,
839859
int img_fd);
840860
const char *switchtec_fw_image_type(const struct switchtec_fw_image_info *info);

lib/fw.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,27 @@ static int switchtec_fw_part_info(struct switchtec_dev *dev, int nr_info,
10971097
return nr_info;
10981098
}
10991099

1100+
int switchtec_get_device_id_bl2(struct switchtec_dev *dev,
1101+
unsigned short *device_id)
1102+
{
1103+
int ret;
1104+
uint8_t subcmd = MRPC_PART_INFO_GET_ALL_INFO;
1105+
struct switchtec_flash_info_gen4 all_info;
1106+
1107+
if (dev->gen != SWITCHTEC_GEN_UNKNOWN)
1108+
return -EINVAL;
1109+
1110+
ret = switchtec_cmd(dev, MRPC_PART_INFO, &subcmd,
1111+
sizeof(subcmd), &all_info,
1112+
sizeof(all_info));
1113+
if (ret)
1114+
return ret;
1115+
1116+
*device_id = le16toh(all_info.device_id);
1117+
1118+
return 0;
1119+
}
1120+
11001121
static long multicfg_subcmd(struct switchtec_dev *dev, uint32_t subcmd,
11011122
uint8_t index)
11021123
{

lib/platform/linux.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,9 @@ static void event_summary_copy(struct switchtec_event_summary *dst,
829829

830830
for (i = 0; i < SWITCHTEC_MAX_PFF_CSR && i < size; i++)
831831
dst->pff[i] = src->pff[i];
832+
833+
for (; i < SWITCHTEC_MAX_PFF_CSR; i++)
834+
dst->pff[i] = 0;
832835
}
833836

834837
#define EV(t, n)[SWITCHTEC_ ## t ## _EVT_ ## n] = \

lib/switchtec.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,16 @@ static int set_gen_variant(struct switchtec_dev * dev)
186186
dev->gen = SWITCHTEC_GEN_UNKNOWN;
187187
dev->var = SWITCHTEC_VAR_UNKNOWN;
188188
dev->device_id = dev->ops->get_device_id(dev);
189+
if (!dev->device_id)
190+
switchtec_get_device_id_bl2(dev,
191+
(unsigned short *)&dev->device_id);
189192

190193
while (id->device_id) {
191194
if (id->device_id == dev->device_id) {
192195
dev->gen = id->gen;
193196
dev->var = id->var;
194197

195-
return 0;
198+
break;
196199
}
197200

198201
id++;

0 commit comments

Comments
 (0)