1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright(c) 2015 - 2017 Intel Corporation.
6 #include <linux/firmware.h>
7 #include <linux/mutex.h>
8 #include <linux/delay.h>
9 #include <linux/crc32.h>
15 * Make it easy to toggle firmware file name and if it gets loaded by
16 * editing the following. This may be something we do while in development
17 * but not necessarily something a user would ever need to use.
19 #define DEFAULT_FW_8051_NAME_FPGA "hfi_dc8051.bin"
20 #define DEFAULT_FW_8051_NAME_ASIC "hfi1_dc8051.fw"
21 #define DEFAULT_FW_FABRIC_NAME "hfi1_fabric.fw"
22 #define DEFAULT_FW_SBUS_NAME "hfi1_sbus.fw"
23 #define DEFAULT_FW_PCIE_NAME "hfi1_pcie.fw"
24 #define ALT_FW_8051_NAME_ASIC "hfi1_dc8051_d.fw"
25 #define ALT_FW_FABRIC_NAME "hfi1_fabric_d.fw"
26 #define ALT_FW_SBUS_NAME "hfi1_sbus_d.fw"
27 #define ALT_FW_PCIE_NAME "hfi1_pcie_d.fw"
29 MODULE_FIRMWARE(DEFAULT_FW_8051_NAME_ASIC);
30 MODULE_FIRMWARE(DEFAULT_FW_FABRIC_NAME);
31 MODULE_FIRMWARE(DEFAULT_FW_SBUS_NAME);
32 MODULE_FIRMWARE(DEFAULT_FW_PCIE_NAME);
34 static uint fw_8051_load = 1;
35 static uint fw_fabric_serdes_load = 1;
36 static uint fw_pcie_serdes_load = 1;
37 static uint fw_sbus_load = 1;
39 /* Firmware file names get set in hfi1_firmware_init() based on the above */
40 static char *fw_8051_name;
41 static char *fw_fabric_serdes_name;
42 static char *fw_sbus_name;
43 static char *fw_pcie_serdes_name;
45 #define SBUS_MAX_POLL_COUNT 100
46 #define SBUS_COUNTER(reg, name) \
47 (((reg) >> ASIC_STS_SBUS_COUNTERS_##name##_CNT_SHIFT) & \
48 ASIC_STS_SBUS_COUNTERS_##name##_CNT_MASK)
51 * Firmware security header.
59 u32 date; /* BCD yyyymmdd */
60 u32 size; /* in DWORDs */
61 u32 key_size; /* in DWORDs */
62 u32 modulus_size; /* in DWORDs */
63 u32 exponent_size; /* in DWORDs */
67 /* expected field values */
68 #define CSS_MODULE_TYPE 0x00000006
69 #define CSS_HEADER_LEN 0x000000a1
70 #define CSS_HEADER_VERSION 0x00010000
71 #define CSS_MODULE_VENDOR 0x00008086
75 #define EXPONENT_SIZE 4
77 /* size of platform configuration partition */
78 #define MAX_PLATFORM_CONFIG_FILE_SIZE 4096
80 /* size of file of plaform configuration encoded in format version 4 */
81 #define PLATFORM_CONFIG_FORMAT_4_FILE_SIZE 528
84 struct firmware_file {
85 struct css_header css_header;
87 u8 exponent[EXPONENT_SIZE];
88 u8 signature[KEY_SIZE];
92 struct augmented_firmware_file {
93 struct css_header css_header;
95 u8 exponent[EXPONENT_SIZE];
96 u8 signature[KEY_SIZE];
102 /* augmented file size difference */
103 #define AUGMENT_SIZE (sizeof(struct augmented_firmware_file) - \
104 sizeof(struct firmware_file))
106 struct firmware_details {
107 /* Linux core piece */
108 const struct firmware *fw;
110 struct css_header *css_header;
111 u8 *firmware_ptr; /* pointer to binary data */
112 u32 firmware_len; /* length in bytes */
113 u8 *modulus; /* pointer to the modulus */
114 u8 *exponent; /* pointer to the exponent */
115 u8 *signature; /* pointer to the signature */
116 u8 *r2; /* pointer to r2 */
117 u8 *mu; /* pointer to mu */
118 struct augmented_firmware_file dummy_header;
122 * The mutex protects fw_state, fw_err, and all of the firmware_details
125 static DEFINE_MUTEX(fw_mutex);
133 static enum fw_state fw_state = FW_EMPTY;
135 static struct firmware_details fw_8051;
136 static struct firmware_details fw_fabric;
137 static struct firmware_details fw_pcie;
138 static struct firmware_details fw_sbus;
140 /* flags for turn_off_spicos() */
141 #define SPICO_SBUS 0x1
142 #define SPICO_FABRIC 0x2
143 #define ENABLE_SPICO_SMASK 0x1
145 /* security block commands */
146 #define RSA_CMD_INIT 0x1
147 #define RSA_CMD_START 0x2
149 /* security block status */
150 #define RSA_STATUS_IDLE 0x0
151 #define RSA_STATUS_ACTIVE 0x1
152 #define RSA_STATUS_DONE 0x2
153 #define RSA_STATUS_FAILED 0x3
155 /* RSA engine timeout, in ms */
156 #define RSA_ENGINE_TIMEOUT 100 /* ms */
158 /* hardware mutex timeout, in ms */
159 #define HM_TIMEOUT 10 /* ms */
161 /* 8051 memory access timeout, in us */
162 #define DC8051_ACCESS_TIMEOUT 100 /* us */
164 /* the number of fabric SerDes on the SBus */
165 #define NUM_FABRIC_SERDES 4
167 /* ASIC_STS_SBUS_RESULT.RESULT_CODE value */
168 #define SBUS_READ_COMPLETE 0x4
170 /* SBus fabric SerDes addresses, one set per HFI */
171 static const u8 fabric_serdes_addrs[2][NUM_FABRIC_SERDES] = {
172 { 0x01, 0x02, 0x03, 0x04 },
173 { 0x28, 0x29, 0x2a, 0x2b }
176 /* SBus PCIe SerDes addresses, one set per HFI */
177 static const u8 pcie_serdes_addrs[2][NUM_PCIE_SERDES] = {
178 { 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16,
179 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26 },
180 { 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b, 0x3d,
181 0x3f, 0x41, 0x43, 0x45, 0x47, 0x49, 0x4b, 0x4d }
184 /* SBus PCIe PCS addresses, one set per HFI */
185 const u8 pcie_pcs_addrs[2][NUM_PCIE_SERDES] = {
186 { 0x09, 0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x15, 0x17,
187 0x19, 0x1b, 0x1d, 0x1f, 0x21, 0x23, 0x25, 0x27 },
188 { 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
189 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e }
192 /* SBus fabric SerDes broadcast addresses, one per HFI */
193 static const u8 fabric_serdes_broadcast[2] = { 0xe4, 0xe5 };
194 static const u8 all_fabric_serdes_broadcast = 0xe1;
196 /* SBus PCIe SerDes broadcast addresses, one per HFI */
197 const u8 pcie_serdes_broadcast[2] = { 0xe2, 0xe3 };
198 static const u8 all_pcie_serdes_broadcast = 0xe0;
200 static const u32 platform_config_table_limits[PLATFORM_CONFIG_TABLE_MAX] = {
206 QSFP_ATTEN_TABLE_MAX,
207 VARIABLE_SETTINGS_TABLE_MAX
211 static void dispose_one_firmware(struct firmware_details *fdet);
212 static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
213 struct firmware_details *fdet);
214 static void dump_fw_version(struct hfi1_devdata *dd);
217 * Read a single 64-bit value from 8051 data memory.
220 * o caller to have already set up data read, no auto increment
221 * o caller to turn off read enable when finished
223 * The address argument is a byte offset. Bits 0:2 in the address are
224 * ignored - i.e. the hardware will always do aligned 8-byte reads as if
225 * the lower bits are zero.
227 * Return 0 on success, -ENXIO on a read error (timeout).
229 static int __read_8051_data(struct hfi1_devdata *dd, u32 addr, u64 *result)
234 /* step 1: set the address, clear enable */
235 reg = (addr & DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_MASK)
236 << DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_SHIFT;
237 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, reg);
239 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL,
240 reg | DC_DC8051_CFG_RAM_ACCESS_CTRL_READ_ENA_SMASK);
242 /* wait until ACCESS_COMPLETED is set */
244 while ((read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_STATUS)
245 & DC_DC8051_CFG_RAM_ACCESS_STATUS_ACCESS_COMPLETED_SMASK)
248 if (count > DC8051_ACCESS_TIMEOUT) {
249 dd_dev_err(dd, "timeout reading 8051 data\n");
255 /* gather the data */
256 *result = read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_RD_DATA);
262 * Read 8051 data starting at addr, for len bytes. Will read in 8-byte chunks.
263 * Return 0 on success, -errno on error.
265 int read_8051_data(struct hfi1_devdata *dd, u32 addr, u32 len, u64 *result)
271 spin_lock_irqsave(&dd->dc8051_memlock, flags);
273 /* data read set-up, no auto-increment */
274 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, 0);
276 for (done = 0; done < len; addr += 8, done += 8, result++) {
277 ret = __read_8051_data(dd, addr, result);
282 /* turn off read enable */
283 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, 0);
285 spin_unlock_irqrestore(&dd->dc8051_memlock, flags);
291 * Write data or code to the 8051 code or data RAM.
293 static int write_8051(struct hfi1_devdata *dd, int code, u32 start,
294 const u8 *data, u32 len)
300 /* check alignment */
301 aligned = ((unsigned long)data & 0x7) == 0;
304 reg = (code ? DC_DC8051_CFG_RAM_ACCESS_SETUP_RAM_SEL_SMASK : 0ull)
305 | DC_DC8051_CFG_RAM_ACCESS_SETUP_AUTO_INCR_ADDR_SMASK;
306 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, reg);
308 reg = ((start & DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_MASK)
309 << DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_SHIFT)
310 | DC_DC8051_CFG_RAM_ACCESS_CTRL_WRITE_ENA_SMASK;
311 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, reg);
314 for (offset = 0; offset < len; offset += 8) {
315 int bytes = len - offset;
319 memcpy(®, &data[offset], bytes);
320 } else if (aligned) {
321 reg = *(u64 *)&data[offset];
323 memcpy(®, &data[offset], 8);
325 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_WR_DATA, reg);
327 /* wait until ACCESS_COMPLETED is set */
329 while ((read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_STATUS)
330 & DC_DC8051_CFG_RAM_ACCESS_STATUS_ACCESS_COMPLETED_SMASK)
333 if (count > DC8051_ACCESS_TIMEOUT) {
334 dd_dev_err(dd, "timeout writing 8051 data\n");
341 /* turn off write access, auto increment (also sets to data access) */
342 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, 0);
343 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, 0);
348 /* return 0 if values match, non-zero and complain otherwise */
349 static int invalid_header(struct hfi1_devdata *dd, const char *what,
350 u32 actual, u32 expected)
352 if (actual == expected)
356 "invalid firmware header field %s: expected 0x%x, actual 0x%x\n",
357 what, expected, actual);
362 * Verify that the static fields in the CSS header match.
364 static int verify_css_header(struct hfi1_devdata *dd, struct css_header *css)
366 /* verify CSS header fields (most sizes are in DW, so add /4) */
367 if (invalid_header(dd, "module_type", css->module_type,
369 invalid_header(dd, "header_len", css->header_len,
370 (sizeof(struct firmware_file) / 4)) ||
371 invalid_header(dd, "header_version", css->header_version,
372 CSS_HEADER_VERSION) ||
373 invalid_header(dd, "module_vendor", css->module_vendor,
374 CSS_MODULE_VENDOR) ||
375 invalid_header(dd, "key_size", css->key_size, KEY_SIZE / 4) ||
376 invalid_header(dd, "modulus_size", css->modulus_size,
378 invalid_header(dd, "exponent_size", css->exponent_size,
379 EXPONENT_SIZE / 4)) {
386 * Make sure there are at least some bytes after the prefix.
388 static int payload_check(struct hfi1_devdata *dd, const char *name,
389 long file_size, long prefix_size)
391 /* make sure we have some payload */
392 if (prefix_size >= file_size) {
394 "firmware \"%s\", size %ld, must be larger than %ld bytes\n",
395 name, file_size, prefix_size);
403 * Request the firmware from the system. Extract the pieces and fill in
404 * fdet. If successful, the caller will need to call dispose_one_firmware().
405 * Returns 0 on success, -ERRNO on error.
407 static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
408 struct firmware_details *fdet)
410 struct css_header *css;
413 memset(fdet, 0, sizeof(*fdet));
415 ret = request_firmware(&fdet->fw, name, &dd->pcidev->dev);
417 dd_dev_warn(dd, "cannot find firmware \"%s\", err %d\n",
422 /* verify the firmware */
423 if (fdet->fw->size < sizeof(struct css_header)) {
424 dd_dev_err(dd, "firmware \"%s\" is too small\n", name);
428 css = (struct css_header *)fdet->fw->data;
430 hfi1_cdbg(FIRMWARE, "Firmware %s details:", name);
431 hfi1_cdbg(FIRMWARE, "file size: 0x%lx bytes", fdet->fw->size);
432 hfi1_cdbg(FIRMWARE, "CSS structure:");
433 hfi1_cdbg(FIRMWARE, " module_type 0x%x", css->module_type);
434 hfi1_cdbg(FIRMWARE, " header_len 0x%03x (0x%03x bytes)",
435 css->header_len, 4 * css->header_len);
436 hfi1_cdbg(FIRMWARE, " header_version 0x%x", css->header_version);
437 hfi1_cdbg(FIRMWARE, " module_id 0x%x", css->module_id);
438 hfi1_cdbg(FIRMWARE, " module_vendor 0x%x", css->module_vendor);
439 hfi1_cdbg(FIRMWARE, " date 0x%x", css->date);
440 hfi1_cdbg(FIRMWARE, " size 0x%03x (0x%03x bytes)",
441 css->size, 4 * css->size);
442 hfi1_cdbg(FIRMWARE, " key_size 0x%03x (0x%03x bytes)",
443 css->key_size, 4 * css->key_size);
444 hfi1_cdbg(FIRMWARE, " modulus_size 0x%03x (0x%03x bytes)",
445 css->modulus_size, 4 * css->modulus_size);
446 hfi1_cdbg(FIRMWARE, " exponent_size 0x%03x (0x%03x bytes)",
447 css->exponent_size, 4 * css->exponent_size);
448 hfi1_cdbg(FIRMWARE, "firmware size: 0x%lx bytes",
449 fdet->fw->size - sizeof(struct firmware_file));
452 * If the file does not have a valid CSS header, fail.
453 * Otherwise, check the CSS size field for an expected size.
454 * The augmented file has r2 and mu inserted after the header
455 * was generated, so there will be a known difference between
456 * the CSS header size and the actual file size. Use this
457 * difference to identify an augmented file.
459 * Note: css->size is in DWORDs, multiply by 4 to get bytes.
461 ret = verify_css_header(dd, css);
463 dd_dev_info(dd, "Invalid CSS header for \"%s\"\n", name);
464 } else if ((css->size * 4) == fdet->fw->size) {
465 /* non-augmented firmware file */
466 struct firmware_file *ff = (struct firmware_file *)
469 /* make sure there are bytes in the payload */
470 ret = payload_check(dd, name, fdet->fw->size,
471 sizeof(struct firmware_file));
473 fdet->css_header = css;
474 fdet->modulus = ff->modulus;
475 fdet->exponent = ff->exponent;
476 fdet->signature = ff->signature;
477 fdet->r2 = fdet->dummy_header.r2; /* use dummy space */
478 fdet->mu = fdet->dummy_header.mu; /* use dummy space */
479 fdet->firmware_ptr = ff->firmware;
480 fdet->firmware_len = fdet->fw->size -
481 sizeof(struct firmware_file);
483 * Header does not include r2 and mu - generate here.
486 dd_dev_err(dd, "driver is unable to validate firmware without r2 and mu (not in firmware file)\n");
489 } else if ((css->size * 4) + AUGMENT_SIZE == fdet->fw->size) {
490 /* augmented firmware file */
491 struct augmented_firmware_file *aff =
492 (struct augmented_firmware_file *)fdet->fw->data;
494 /* make sure there are bytes in the payload */
495 ret = payload_check(dd, name, fdet->fw->size,
496 sizeof(struct augmented_firmware_file));
498 fdet->css_header = css;
499 fdet->modulus = aff->modulus;
500 fdet->exponent = aff->exponent;
501 fdet->signature = aff->signature;
504 fdet->firmware_ptr = aff->firmware;
505 fdet->firmware_len = fdet->fw->size -
506 sizeof(struct augmented_firmware_file);
509 /* css->size check failed */
511 "invalid firmware header field size: expected 0x%lx or 0x%lx, actual 0x%x\n",
513 (fdet->fw->size - AUGMENT_SIZE) / 4,
520 /* if returning an error, clean up after ourselves */
522 dispose_one_firmware(fdet);
526 static void dispose_one_firmware(struct firmware_details *fdet)
528 release_firmware(fdet->fw);
529 /* erase all previous information */
530 memset(fdet, 0, sizeof(*fdet));
534 * Obtain the 4 firmwares from the OS. All must be obtained at once or not
535 * at all. If called with the firmware state in FW_TRY, use alternate names.
536 * On exit, this routine will have set the firmware state to one of FW_TRY,
537 * FW_FINAL, or FW_ERR.
539 * Must be holding fw_mutex.
541 static void __obtain_firmware(struct hfi1_devdata *dd)
545 if (fw_state == FW_FINAL) /* nothing more to obtain */
547 if (fw_state == FW_ERR) /* already in error */
550 /* fw_state is FW_EMPTY or FW_TRY */
552 if (fw_state == FW_TRY) {
554 * We tried the original and it failed. Move to the
557 dd_dev_warn(dd, "using alternate firmware names\n");
559 * Let others run. Some systems, when missing firmware, does
560 * something that holds for 30 seconds. If we do that twice
561 * in a row it triggers task blocked warning.
565 dispose_one_firmware(&fw_8051);
566 if (fw_fabric_serdes_load)
567 dispose_one_firmware(&fw_fabric);
569 dispose_one_firmware(&fw_sbus);
570 if (fw_pcie_serdes_load)
571 dispose_one_firmware(&fw_pcie);
572 fw_8051_name = ALT_FW_8051_NAME_ASIC;
573 fw_fabric_serdes_name = ALT_FW_FABRIC_NAME;
574 fw_sbus_name = ALT_FW_SBUS_NAME;
575 fw_pcie_serdes_name = ALT_FW_PCIE_NAME;
578 * Add a delay before obtaining and loading debug firmware.
579 * Authorization will fail if the delay between firmware
580 * authorization events is shorter than 50us. Add 100us to
581 * make a delay time safe.
583 usleep_range(100, 120);
587 err = obtain_one_firmware(dd, fw_sbus_name, &fw_sbus);
592 if (fw_pcie_serdes_load) {
593 err = obtain_one_firmware(dd, fw_pcie_serdes_name, &fw_pcie);
598 if (fw_fabric_serdes_load) {
599 err = obtain_one_firmware(dd, fw_fabric_serdes_name,
606 err = obtain_one_firmware(dd, fw_8051_name, &fw_8051);
613 /* oops, had problems obtaining a firmware */
614 if (fw_state == FW_EMPTY && dd->icode == ICODE_RTL_SILICON) {
615 /* retry with alternate (RTL only) */
619 dd_dev_err(dd, "unable to obtain working firmware\n");
624 if (fw_state == FW_EMPTY &&
625 dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
626 fw_state = FW_TRY; /* may retry later */
628 fw_state = FW_FINAL; /* cannot try again */
633 * Called by all HFIs when loading their firmware - i.e. device probe time.
634 * The first one will do the actual firmware load. Use a mutex to resolve
635 * any possible race condition.
637 * The call to this routine cannot be moved to driver load because the kernel
638 * call request_firmware() requires a device which is only available after
639 * the first device probe.
641 static int obtain_firmware(struct hfi1_devdata *dd)
643 unsigned long timeout;
645 mutex_lock(&fw_mutex);
647 /* 40s delay due to long delay on missing firmware on some systems */
648 timeout = jiffies + msecs_to_jiffies(40000);
649 while (fw_state == FW_TRY) {
651 * Another device is trying the firmware. Wait until it
652 * decides what works (or not).
654 if (time_after(jiffies, timeout)) {
655 /* waited too long */
656 dd_dev_err(dd, "Timeout waiting for firmware try");
661 mutex_unlock(&fw_mutex);
662 msleep(20); /* arbitrary delay */
663 mutex_lock(&fw_mutex);
665 /* not in FW_TRY state */
667 /* set fw_state to FW_TRY, FW_FINAL, or FW_ERR, and fw_err */
668 if (fw_state == FW_EMPTY)
669 __obtain_firmware(dd);
671 mutex_unlock(&fw_mutex);
676 * Called when the driver unloads. The timing is asymmetric with its
677 * counterpart, obtain_firmware(). If called at device remove time,
678 * then it is conceivable that another device could probe while the
679 * firmware is being disposed. The mutexes can be moved to do that
680 * safely, but then the firmware would be requested from the OS multiple
683 * No mutex is needed as the driver is unloading and there cannot be any
686 void dispose_firmware(void)
688 dispose_one_firmware(&fw_8051);
689 dispose_one_firmware(&fw_fabric);
690 dispose_one_firmware(&fw_pcie);
691 dispose_one_firmware(&fw_sbus);
693 /* retain the error state, otherwise revert to empty */
694 if (fw_state != FW_ERR)
699 * Called with the result of a firmware download.
701 * Return 1 to retry loading the firmware, 0 to stop.
703 static int retry_firmware(struct hfi1_devdata *dd, int load_result)
707 mutex_lock(&fw_mutex);
709 if (load_result == 0) {
711 * The load succeeded, so expect all others to do the same.
712 * Do not retry again.
714 if (fw_state == FW_TRY)
716 retry = 0; /* do NOT retry */
717 } else if (fw_state == FW_TRY) {
718 /* load failed, obtain alternate firmware */
719 __obtain_firmware(dd);
720 retry = (fw_state == FW_FINAL);
722 /* else in FW_FINAL or FW_ERR, no retry in either case */
726 mutex_unlock(&fw_mutex);
731 * Write a block of data to a given array CSR. All calls will be in
732 * multiples of 8 bytes.
734 static void write_rsa_data(struct hfi1_devdata *dd, int what,
735 const u8 *data, int nbytes)
737 int qw_size = nbytes / 8;
740 if (((unsigned long)data & 0x7) == 0) {
742 u64 *ptr = (u64 *)data;
744 for (i = 0; i < qw_size; i++, ptr++)
745 write_csr(dd, what + (8 * i), *ptr);
748 for (i = 0; i < qw_size; i++, data += 8) {
751 memcpy(&value, data, 8);
752 write_csr(dd, what + (8 * i), value);
758 * Write a block of data to a given CSR as a stream of writes. All calls will
759 * be in multiples of 8 bytes.
761 static void write_streamed_rsa_data(struct hfi1_devdata *dd, int what,
762 const u8 *data, int nbytes)
764 u64 *ptr = (u64 *)data;
765 int qw_size = nbytes / 8;
767 for (; qw_size > 0; qw_size--, ptr++)
768 write_csr(dd, what, *ptr);
772 * Download the signature and start the RSA mechanism. Wait for
773 * RSA_ENGINE_TIMEOUT before giving up.
775 static int run_rsa(struct hfi1_devdata *dd, const char *who,
778 unsigned long timeout;
783 /* write the signature */
784 write_rsa_data(dd, MISC_CFG_RSA_SIGNATURE, signature, KEY_SIZE);
787 write_csr(dd, MISC_CFG_RSA_CMD, RSA_CMD_INIT);
790 * Make sure the engine is idle and insert a delay between the two
791 * writes to MISC_CFG_RSA_CMD.
793 status = (read_csr(dd, MISC_CFG_FW_CTRL)
794 & MISC_CFG_FW_CTRL_RSA_STATUS_SMASK)
795 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT;
796 if (status != RSA_STATUS_IDLE) {
797 dd_dev_err(dd, "%s security engine not idle - giving up\n",
803 write_csr(dd, MISC_CFG_RSA_CMD, RSA_CMD_START);
806 * Look for the result.
808 * The RSA engine is hooked up to two MISC errors. The driver
809 * masks these errors as they do not respond to the standard
810 * error "clear down" mechanism. Look for these errors here and
811 * clear them when possible. This routine will exit with the
812 * errors of the current run still set.
814 * MISC_FW_AUTH_FAILED_ERR
815 * Firmware authorization failed. This can be cleared by
816 * re-initializing the RSA engine, then clearing the status bit.
817 * Do not re-init the RSA angine immediately after a successful
818 * run - this will reset the current authorization.
820 * MISC_KEY_MISMATCH_ERR
821 * Key does not match. The only way to clear this is to load
822 * a matching key then clear the status bit. If this error
823 * is raised, it will persist outside of this routine until a
824 * matching key is loaded.
826 timeout = msecs_to_jiffies(RSA_ENGINE_TIMEOUT) + jiffies;
828 status = (read_csr(dd, MISC_CFG_FW_CTRL)
829 & MISC_CFG_FW_CTRL_RSA_STATUS_SMASK)
830 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT;
832 if (status == RSA_STATUS_IDLE) {
833 /* should not happen */
834 dd_dev_err(dd, "%s firmware security bad idle state\n",
838 } else if (status == RSA_STATUS_DONE) {
839 /* finished successfully */
841 } else if (status == RSA_STATUS_FAILED) {
842 /* finished unsuccessfully */
846 /* else still active */
848 if (time_after(jiffies, timeout)) {
850 * Timed out while active. We can't reset the engine
851 * if it is stuck active, but run through the
852 * error code to see what error bits are set.
854 dd_dev_err(dd, "%s firmware security time out\n", who);
863 * Arrive here on success or failure. Clear all RSA engine
864 * errors. All current errors will stick - the RSA logic is keeping
865 * error high. All previous errors will clear - the RSA logic
866 * is not keeping the error high.
868 write_csr(dd, MISC_ERR_CLEAR,
869 MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK |
870 MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK);
872 * All that is left are the current errors. Print warnings on
873 * authorization failure details, if any. Firmware authorization
874 * can be retried, so these are only warnings.
876 reg = read_csr(dd, MISC_ERR_STATUS);
878 if (reg & MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK)
879 dd_dev_warn(dd, "%s firmware authorization failed\n",
881 if (reg & MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK)
882 dd_dev_warn(dd, "%s firmware key mismatch\n", who);
888 static void load_security_variables(struct hfi1_devdata *dd,
889 struct firmware_details *fdet)
891 /* Security variables a. Write the modulus */
892 write_rsa_data(dd, MISC_CFG_RSA_MODULUS, fdet->modulus, KEY_SIZE);
893 /* Security variables b. Write the r2 */
894 write_rsa_data(dd, MISC_CFG_RSA_R2, fdet->r2, KEY_SIZE);
895 /* Security variables c. Write the mu */
896 write_rsa_data(dd, MISC_CFG_RSA_MU, fdet->mu, MU_SIZE);
897 /* Security variables d. Write the header */
898 write_streamed_rsa_data(dd, MISC_CFG_SHA_PRELOAD,
899 (u8 *)fdet->css_header,
900 sizeof(struct css_header));
903 /* return the 8051 firmware state */
904 static inline u32 get_firmware_state(struct hfi1_devdata *dd)
906 u64 reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
908 return (reg >> DC_DC8051_STS_CUR_STATE_FIRMWARE_SHIFT)
909 & DC_DC8051_STS_CUR_STATE_FIRMWARE_MASK;
913 * Wait until the firmware is up and ready to take host requests.
914 * Return 0 on success, -ETIMEDOUT on timeout.
916 int wait_fm_ready(struct hfi1_devdata *dd, u32 mstimeout)
918 unsigned long timeout;
920 /* in the simulator, the fake 8051 is always ready */
921 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
924 timeout = msecs_to_jiffies(mstimeout) + jiffies;
926 if (get_firmware_state(dd) == 0xa0) /* ready */
928 if (time_after(jiffies, timeout)) /* timed out */
930 usleep_range(1950, 2050); /* sleep 2ms-ish */
935 * Load the 8051 firmware.
937 static int load_8051_firmware(struct hfi1_devdata *dd,
938 struct firmware_details *fdet)
948 * Load DC 8051 firmware
951 * DC reset step 1: Reset DC8051
953 reg = DC_DC8051_CFG_RST_M8051W_SMASK
954 | DC_DC8051_CFG_RST_CRAM_SMASK
955 | DC_DC8051_CFG_RST_DRAM_SMASK
956 | DC_DC8051_CFG_RST_IRAM_SMASK
957 | DC_DC8051_CFG_RST_SFR_SMASK;
958 write_csr(dd, DC_DC8051_CFG_RST, reg);
961 * DC reset step 2 (optional): Load 8051 data memory with link
966 * DC reset step 3: Load DC8051 firmware
968 /* release all but the core reset */
969 reg = DC_DC8051_CFG_RST_M8051W_SMASK;
970 write_csr(dd, DC_DC8051_CFG_RST, reg);
972 /* Firmware load step 1 */
973 load_security_variables(dd, fdet);
976 * Firmware load step 2. Clear MISC_CFG_FW_CTRL.FW_8051_LOADED
978 write_csr(dd, MISC_CFG_FW_CTRL, 0);
980 /* Firmware load steps 3-5 */
981 ret = write_8051(dd, 1/*code*/, 0, fdet->firmware_ptr,
987 * DC reset step 4. Host starts the DC8051 firmware
990 * Firmware load step 6. Set MISC_CFG_FW_CTRL.FW_8051_LOADED
992 write_csr(dd, MISC_CFG_FW_CTRL, MISC_CFG_FW_CTRL_FW_8051_LOADED_SMASK);
994 /* Firmware load steps 7-10 */
995 ret = run_rsa(dd, "8051", fdet->signature);
999 /* clear all reset bits, releasing the 8051 */
1000 write_csr(dd, DC_DC8051_CFG_RST, 0ull);
1003 * DC reset step 5. Wait for firmware to be ready to accept host
1006 ret = wait_fm_ready(dd, TIMEOUT_8051_START);
1007 if (ret) { /* timed out */
1008 dd_dev_err(dd, "8051 start timeout, current state 0x%x\n",
1009 get_firmware_state(dd));
1013 read_misc_status(dd, &ver_major, &ver_minor, &ver_patch);
1014 dd_dev_info(dd, "8051 firmware version %d.%d.%d\n",
1015 (int)ver_major, (int)ver_minor, (int)ver_patch);
1016 dd->dc8051_ver = dc8051_ver(ver_major, ver_minor, ver_patch);
1017 ret = write_host_interface_version(dd, HOST_INTERFACE_VERSION);
1018 if (ret != HCMD_SUCCESS) {
1020 "Failed to set host interface version, return 0x%x\n",
1029 * Write the SBus request register
1031 * No need for masking - the arguments are sized exactly.
1033 void sbus_request(struct hfi1_devdata *dd,
1034 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in)
1036 write_csr(dd, ASIC_CFG_SBUS_REQUEST,
1037 ((u64)data_in << ASIC_CFG_SBUS_REQUEST_DATA_IN_SHIFT) |
1038 ((u64)command << ASIC_CFG_SBUS_REQUEST_COMMAND_SHIFT) |
1039 ((u64)data_addr << ASIC_CFG_SBUS_REQUEST_DATA_ADDR_SHIFT) |
1040 ((u64)receiver_addr <<
1041 ASIC_CFG_SBUS_REQUEST_RECEIVER_ADDR_SHIFT));
1045 * Read a value from the SBus.
1047 * Requires the caller to be in fast mode
1049 static u32 sbus_read(struct hfi1_devdata *dd, u8 receiver_addr, u8 data_addr,
1056 u32 result_code = 0;
1058 sbus_request(dd, receiver_addr, data_addr, READ_SBUS_RECEIVER, data_in);
1060 for (retries = 0; retries < 100; retries++) {
1061 usleep_range(1000, 1200); /* arbitrary */
1062 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1063 result_code = (reg >> ASIC_STS_SBUS_RESULT_RESULT_CODE_SHIFT)
1064 & ASIC_STS_SBUS_RESULT_RESULT_CODE_MASK;
1065 if (result_code != SBUS_READ_COMPLETE)
1069 result = (reg >> ASIC_STS_SBUS_RESULT_DATA_OUT_SHIFT)
1070 & ASIC_STS_SBUS_RESULT_DATA_OUT_MASK;
1075 dd_dev_err(dd, "%s: read failed, result code 0x%x\n", __func__,
1083 * Turn off the SBus and fabric serdes spicos.
1085 * + Must be called with Sbus fast mode turned on.
1086 * + Must be called after fabric serdes broadcast is set up.
1087 * + Must be called before the 8051 is loaded - assumes 8051 is not loaded
1088 * when using MISC_CFG_FW_CTRL.
1090 static void turn_off_spicos(struct hfi1_devdata *dd, int flags)
1092 /* only needed on A0 */
1096 dd_dev_info(dd, "Turning off spicos:%s%s\n",
1097 flags & SPICO_SBUS ? " SBus" : "",
1098 flags & SPICO_FABRIC ? " fabric" : "");
1100 write_csr(dd, MISC_CFG_FW_CTRL, ENABLE_SPICO_SMASK);
1101 /* disable SBus spico */
1102 if (flags & SPICO_SBUS)
1103 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01,
1104 WRITE_SBUS_RECEIVER, 0x00000040);
1106 /* disable the fabric serdes spicos */
1107 if (flags & SPICO_FABRIC)
1108 sbus_request(dd, fabric_serdes_broadcast[dd->hfi1_id],
1109 0x07, WRITE_SBUS_RECEIVER, 0x00000000);
1110 write_csr(dd, MISC_CFG_FW_CTRL, 0);
1114 * Reset all of the fabric serdes for this HFI in preparation to take the
1117 * To do a reset, we need to write to the serdes registers. Unfortunately,
1118 * the fabric serdes download to the other HFI on the ASIC will have turned
1119 * off the firmware validation on this HFI. This means we can't write to the
1120 * registers to reset the serdes. Work around this by performing a complete
1121 * re-download and validation of the fabric serdes firmware. This, as a
1122 * by-product, will reset the serdes. NOTE: the re-download requires that
1123 * the 8051 be in the Offline state. I.e. not actively trying to use the
1124 * serdes. This routine is called at the point where the link is Offline and
1125 * is getting ready to go to Polling.
1127 void fabric_serdes_reset(struct hfi1_devdata *dd)
1131 if (!fw_fabric_serdes_load)
1134 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1137 "Cannot acquire SBus resource to reset fabric SerDes - perhaps you should reboot\n");
1140 set_sbus_fast_mode(dd);
1143 /* A0 serdes do not work with a re-download */
1144 u8 ra = fabric_serdes_broadcast[dd->hfi1_id];
1146 /* place SerDes in reset and disable SPICO */
1147 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011);
1148 /* wait 100 refclk cycles @ 156.25MHz => 640ns */
1150 /* remove SerDes reset */
1151 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010);
1152 /* turn SPICO enable on */
1153 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002);
1155 turn_off_spicos(dd, SPICO_FABRIC);
1157 * No need for firmware retry - what to download has already
1159 * No need to pay attention to the load return - the only
1160 * failure is a validation failure, which has already been
1161 * checked by the initial download.
1163 (void)load_fabric_serdes_firmware(dd, &fw_fabric);
1166 clear_sbus_fast_mode(dd);
1167 release_chip_resource(dd, CR_SBUS);
1170 /* Access to the SBus in this routine should probably be serialized */
1171 int sbus_request_slow(struct hfi1_devdata *dd,
1172 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in)
1176 /* make sure fast mode is clear */
1177 clear_sbus_fast_mode(dd);
1179 sbus_request(dd, receiver_addr, data_addr, command, data_in);
1180 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1181 ASIC_CFG_SBUS_EXECUTE_EXECUTE_SMASK);
1182 /* Wait for both DONE and RCV_DATA_VALID to go high */
1183 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1184 while (!((reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) &&
1185 (reg & ASIC_STS_SBUS_RESULT_RCV_DATA_VALID_SMASK))) {
1186 if (count++ >= SBUS_MAX_POLL_COUNT) {
1187 u64 counts = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1189 * If the loop has timed out, we are OK if DONE bit
1190 * is set and RCV_DATA_VALID and EXECUTE counters
1191 * are the same. If not, we cannot proceed.
1193 if ((reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) &&
1194 (SBUS_COUNTER(counts, RCV_DATA_VALID) ==
1195 SBUS_COUNTER(counts, EXECUTE)))
1200 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1203 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
1204 /* Wait for DONE to clear after EXECUTE is cleared */
1205 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1206 while (reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) {
1207 if (count++ >= SBUS_MAX_POLL_COUNT)
1210 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1215 static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
1216 struct firmware_details *fdet)
1219 const u8 ra = fabric_serdes_broadcast[dd->hfi1_id]; /* receiver addr */
1221 dd_dev_info(dd, "Downloading fabric firmware\n");
1223 /* step 1: load security variables */
1224 load_security_variables(dd, fdet);
1225 /* step 2: place SerDes in reset and disable SPICO */
1226 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011);
1227 /* wait 100 refclk cycles @ 156.25MHz => 640ns */
1229 /* step 3: remove SerDes reset */
1230 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010);
1231 /* step 4: assert IMEM override */
1232 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x40000000);
1233 /* step 5: download SerDes machine code */
1234 for (i = 0; i < fdet->firmware_len; i += 4) {
1235 sbus_request(dd, ra, 0x0a, WRITE_SBUS_RECEIVER,
1236 *(u32 *)&fdet->firmware_ptr[i]);
1238 /* step 6: IMEM override off */
1239 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x00000000);
1240 /* step 7: turn ECC on */
1241 sbus_request(dd, ra, 0x0b, WRITE_SBUS_RECEIVER, 0x000c0000);
1243 /* steps 8-11: run the RSA engine */
1244 err = run_rsa(dd, "fabric serdes", fdet->signature);
1248 /* step 12: turn SPICO enable on */
1249 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002);
1250 /* step 13: enable core hardware interrupts */
1251 sbus_request(dd, ra, 0x08, WRITE_SBUS_RECEIVER, 0x00000000);
1256 static int load_sbus_firmware(struct hfi1_devdata *dd,
1257 struct firmware_details *fdet)
1260 const u8 ra = SBUS_MASTER_BROADCAST; /* receiver address */
1262 dd_dev_info(dd, "Downloading SBus firmware\n");
1264 /* step 1: load security variables */
1265 load_security_variables(dd, fdet);
1266 /* step 2: place SPICO into reset and enable off */
1267 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x000000c0);
1268 /* step 3: remove reset, enable off, IMEM_CNTRL_EN on */
1269 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000240);
1270 /* step 4: set starting IMEM address for burst download */
1271 sbus_request(dd, ra, 0x03, WRITE_SBUS_RECEIVER, 0x80000000);
1272 /* step 5: download the SBus Master machine code */
1273 for (i = 0; i < fdet->firmware_len; i += 4) {
1274 sbus_request(dd, ra, 0x14, WRITE_SBUS_RECEIVER,
1275 *(u32 *)&fdet->firmware_ptr[i]);
1277 /* step 6: set IMEM_CNTL_EN off */
1278 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000040);
1279 /* step 7: turn ECC on */
1280 sbus_request(dd, ra, 0x16, WRITE_SBUS_RECEIVER, 0x000c0000);
1282 /* steps 8-11: run the RSA engine */
1283 err = run_rsa(dd, "SBus", fdet->signature);
1287 /* step 12: set SPICO_ENABLE on */
1288 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140);
1293 static int load_pcie_serdes_firmware(struct hfi1_devdata *dd,
1294 struct firmware_details *fdet)
1297 const u8 ra = SBUS_MASTER_BROADCAST; /* receiver address */
1299 dd_dev_info(dd, "Downloading PCIe firmware\n");
1301 /* step 1: load security variables */
1302 load_security_variables(dd, fdet);
1303 /* step 2: assert single step (halts the SBus Master spico) */
1304 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000001);
1305 /* step 3: enable XDMEM access */
1306 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000d40);
1307 /* step 4: load firmware into SBus Master XDMEM */
1309 * NOTE: the dmem address, write_en, and wdata are all pre-packed,
1310 * we only need to pick up the bytes and write them
1312 for (i = 0; i < fdet->firmware_len; i += 4) {
1313 sbus_request(dd, ra, 0x04, WRITE_SBUS_RECEIVER,
1314 *(u32 *)&fdet->firmware_ptr[i]);
1316 /* step 5: disable XDMEM access */
1317 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140);
1318 /* step 6: allow SBus Spico to run */
1319 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000000);
1322 * steps 7-11: run RSA, if it succeeds, firmware is available to
1325 return run_rsa(dd, "PCIe serdes", fdet->signature);
1329 * Set the given broadcast values on the given list of devices.
1331 static void set_serdes_broadcast(struct hfi1_devdata *dd, u8 bg1, u8 bg2,
1332 const u8 *addrs, int count)
1334 while (--count >= 0) {
1336 * Set BROADCAST_GROUP_1 and BROADCAST_GROUP_2, leave
1337 * defaults for everything else. Do not read-modify-write,
1338 * per instruction from the manufacturer.
1342 * ----- ---------------------------------
1343 * 0 IGNORE_BROADCAST (default 0)
1344 * 11:4 BROADCAST_GROUP_1 (default 0xff)
1345 * 23:16 BROADCAST_GROUP_2 (default 0xff)
1347 sbus_request(dd, addrs[count], 0xfd, WRITE_SBUS_RECEIVER,
1348 (u32)bg1 << 4 | (u32)bg2 << 16);
1352 int acquire_hw_mutex(struct hfi1_devdata *dd)
1354 unsigned long timeout;
1356 u8 mask = 1 << dd->hfi1_id;
1357 u8 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1361 "Hardware mutex already acquired, mutex mask %u\n",
1367 timeout = msecs_to_jiffies(HM_TIMEOUT) + jiffies;
1369 write_csr(dd, ASIC_CFG_MUTEX, mask);
1370 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1372 return 0; /* success */
1373 if (time_after(jiffies, timeout))
1374 break; /* timed out */
1380 "Unable to acquire hardware mutex, mutex mask %u, my mask %u (%s)\n",
1381 (u32)user, (u32)mask, (try == 0) ? "retrying" : "giving up");
1384 /* break mutex and retry */
1385 write_csr(dd, ASIC_CFG_MUTEX, 0);
1393 void release_hw_mutex(struct hfi1_devdata *dd)
1395 u8 mask = 1 << dd->hfi1_id;
1396 u8 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1400 "Unable to release hardware mutex, mutex mask %u, my mask %u\n",
1401 (u32)user, (u32)mask);
1403 write_csr(dd, ASIC_CFG_MUTEX, 0);
1406 /* return the given resource bit(s) as a mask for the given HFI */
1407 static inline u64 resource_mask(u32 hfi1_id, u32 resource)
1409 return ((u64)resource) << (hfi1_id ? CR_DYN_SHIFT : 0);
1412 static void fail_mutex_acquire_message(struct hfi1_devdata *dd,
1416 "%s: hardware mutex stuck - suggest rebooting the machine\n",
1421 * Acquire access to a chip resource.
1423 * Return 0 on success, -EBUSY if resource busy, -EIO if mutex acquire failed.
1425 static int __acquire_chip_resource(struct hfi1_devdata *dd, u32 resource)
1427 u64 scratch0, all_bits, my_bit;
1430 if (resource & CR_DYN_MASK) {
1431 /* a dynamic resource is in use if either HFI has set the bit */
1432 if (dd->pcidev->device == PCI_DEVICE_ID_INTEL0 &&
1433 (resource & (CR_I2C1 | CR_I2C2))) {
1434 /* discrete devices must serialize across both chains */
1435 all_bits = resource_mask(0, CR_I2C1 | CR_I2C2) |
1436 resource_mask(1, CR_I2C1 | CR_I2C2);
1438 all_bits = resource_mask(0, resource) |
1439 resource_mask(1, resource);
1441 my_bit = resource_mask(dd->hfi1_id, resource);
1443 /* non-dynamic resources are not split between HFIs */
1444 all_bits = resource;
1448 /* lock against other callers within the driver wanting a resource */
1449 mutex_lock(&dd->asic_data->asic_resource_mutex);
1451 ret = acquire_hw_mutex(dd);
1453 fail_mutex_acquire_message(dd, __func__);
1458 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1459 if (scratch0 & all_bits) {
1462 write_csr(dd, ASIC_CFG_SCRATCH, scratch0 | my_bit);
1463 /* force write to be visible to other HFI on another OS */
1464 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1467 release_hw_mutex(dd);
1470 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1475 * Acquire access to a chip resource, wait up to mswait milliseconds for
1476 * the resource to become available.
1478 * Return 0 on success, -EBUSY if busy (even after wait), -EIO if mutex
1481 int acquire_chip_resource(struct hfi1_devdata *dd, u32 resource, u32 mswait)
1483 unsigned long timeout;
1486 timeout = jiffies + msecs_to_jiffies(mswait);
1488 ret = __acquire_chip_resource(dd, resource);
1491 /* resource is busy, check our timeout */
1492 if (time_after_eq(jiffies, timeout))
1494 usleep_range(80, 120); /* arbitrary delay */
1499 * Release access to a chip resource
1501 void release_chip_resource(struct hfi1_devdata *dd, u32 resource)
1505 /* only dynamic resources should ever be cleared */
1506 if (!(resource & CR_DYN_MASK)) {
1507 dd_dev_err(dd, "%s: invalid resource 0x%x\n", __func__,
1511 bit = resource_mask(dd->hfi1_id, resource);
1513 /* lock against other callers within the driver wanting a resource */
1514 mutex_lock(&dd->asic_data->asic_resource_mutex);
1516 if (acquire_hw_mutex(dd)) {
1517 fail_mutex_acquire_message(dd, __func__);
1521 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1522 if ((scratch0 & bit) != 0) {
1524 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1525 /* force write to be visible to other HFI on another OS */
1526 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1528 dd_dev_warn(dd, "%s: id %d, resource 0x%x: bit not set\n",
1529 __func__, dd->hfi1_id, resource);
1532 release_hw_mutex(dd);
1535 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1539 * Return true if resource is set, false otherwise. Print a warning
1540 * if not set and a function is supplied.
1542 bool check_chip_resource(struct hfi1_devdata *dd, u32 resource,
1547 if (resource & CR_DYN_MASK)
1548 bit = resource_mask(dd->hfi1_id, resource);
1552 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1553 if ((scratch0 & bit) == 0) {
1556 "%s: id %d, resource 0x%x, not acquired!\n",
1557 func, dd->hfi1_id, resource);
1563 static void clear_chip_resources(struct hfi1_devdata *dd, const char *func)
1567 /* lock against other callers within the driver wanting a resource */
1568 mutex_lock(&dd->asic_data->asic_resource_mutex);
1570 if (acquire_hw_mutex(dd)) {
1571 fail_mutex_acquire_message(dd, func);
1575 /* clear all dynamic access bits for this HFI */
1576 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1577 scratch0 &= ~resource_mask(dd->hfi1_id, CR_DYN_MASK);
1578 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1579 /* force write to be visible to other HFI on another OS */
1580 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1582 release_hw_mutex(dd);
1585 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1588 void init_chip_resources(struct hfi1_devdata *dd)
1590 /* clear any holds left by us */
1591 clear_chip_resources(dd, __func__);
1594 void finish_chip_resources(struct hfi1_devdata *dd)
1596 /* clear any holds left by us */
1597 clear_chip_resources(dd, __func__);
1600 void set_sbus_fast_mode(struct hfi1_devdata *dd)
1602 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1603 ASIC_CFG_SBUS_EXECUTE_FAST_MODE_SMASK);
1606 void clear_sbus_fast_mode(struct hfi1_devdata *dd)
1610 reg = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1611 while (SBUS_COUNTER(reg, EXECUTE) !=
1612 SBUS_COUNTER(reg, RCV_DATA_VALID)) {
1613 if (count++ >= SBUS_MAX_POLL_COUNT)
1616 reg = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1618 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
1621 int load_firmware(struct hfi1_devdata *dd)
1625 if (fw_fabric_serdes_load) {
1626 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1630 set_sbus_fast_mode(dd);
1632 set_serdes_broadcast(dd, all_fabric_serdes_broadcast,
1633 fabric_serdes_broadcast[dd->hfi1_id],
1634 fabric_serdes_addrs[dd->hfi1_id],
1636 turn_off_spicos(dd, SPICO_FABRIC);
1638 ret = load_fabric_serdes_firmware(dd, &fw_fabric);
1639 } while (retry_firmware(dd, ret));
1641 clear_sbus_fast_mode(dd);
1642 release_chip_resource(dd, CR_SBUS);
1649 ret = load_8051_firmware(dd, &fw_8051);
1650 } while (retry_firmware(dd, ret));
1655 dump_fw_version(dd);
1659 int hfi1_firmware_init(struct hfi1_devdata *dd)
1661 /* only RTL can use these */
1662 if (dd->icode != ICODE_RTL_SILICON) {
1663 fw_fabric_serdes_load = 0;
1664 fw_pcie_serdes_load = 0;
1668 /* no 8051 or QSFP on simulator */
1669 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
1672 if (!fw_8051_name) {
1673 if (dd->icode == ICODE_RTL_SILICON)
1674 fw_8051_name = DEFAULT_FW_8051_NAME_ASIC;
1676 fw_8051_name = DEFAULT_FW_8051_NAME_FPGA;
1678 if (!fw_fabric_serdes_name)
1679 fw_fabric_serdes_name = DEFAULT_FW_FABRIC_NAME;
1681 fw_sbus_name = DEFAULT_FW_SBUS_NAME;
1682 if (!fw_pcie_serdes_name)
1683 fw_pcie_serdes_name = DEFAULT_FW_PCIE_NAME;
1685 return obtain_firmware(dd);
1689 * This function is a helper function for parse_platform_config(...) and
1690 * does not check for validity of the platform configuration cache
1691 * (because we know it is invalid as we are building up the cache).
1692 * As such, this should not be called from anywhere other than
1693 * parse_platform_config
1695 static int check_meta_version(struct hfi1_devdata *dd, u32 *system_table)
1697 u32 meta_ver, meta_ver_meta, ver_start, ver_len, mask;
1698 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1704 *(pcfgcache->config_tables[PLATFORM_CONFIG_SYSTEM_TABLE].table_metadata
1705 + SYSTEM_TABLE_META_VERSION);
1707 mask = ((1 << METADATA_TABLE_FIELD_START_LEN_BITS) - 1);
1708 ver_start = meta_ver_meta & mask;
1710 meta_ver_meta >>= METADATA_TABLE_FIELD_LEN_SHIFT;
1712 mask = ((1 << METADATA_TABLE_FIELD_LEN_LEN_BITS) - 1);
1713 ver_len = meta_ver_meta & mask;
1716 meta_ver = *((u8 *)system_table + ver_start) & ((1 << ver_len) - 1);
1720 dd, "%s:Please update platform config\n", __func__);
1726 int parse_platform_config(struct hfi1_devdata *dd)
1728 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1729 struct hfi1_pportdata *ppd = dd->pport;
1731 u32 header1 = 0, header2 = 0, magic_num = 0, crc = 0, file_length = 0;
1732 u32 record_idx = 0, table_type = 0, table_length_dwords = 0;
1733 int ret = -EINVAL; /* assume failure */
1736 * For integrated devices that did not fall back to the default file,
1737 * the SI tuning information for active channels is acquired from the
1738 * scratch register bitmap, thus there is no platform config to parse.
1739 * Skip parsing in these situations.
1741 if (ppd->config_from_scratch)
1744 if (!dd->platform_config.data) {
1745 dd_dev_err(dd, "%s: Missing config file\n", __func__);
1749 ptr = (u32 *)dd->platform_config.data;
1753 if (magic_num != PLATFORM_CONFIG_MAGIC_NUM) {
1754 dd_dev_err(dd, "%s: Bad config file\n", __func__);
1759 /* Field is file size in DWORDs */
1760 file_length = (*ptr) * 4;
1763 * Length can't be larger than partition size. Assume platform
1764 * config format version 4 is being used. Interpret the file size
1765 * field as header instead by not moving the pointer.
1767 if (file_length > MAX_PLATFORM_CONFIG_FILE_SIZE) {
1769 "%s:File length out of bounds, using alternative format\n",
1771 file_length = PLATFORM_CONFIG_FORMAT_4_FILE_SIZE;
1776 if (file_length > dd->platform_config.size) {
1777 dd_dev_info(dd, "%s:File claims to be larger than read size\n",
1781 } else if (file_length < dd->platform_config.size) {
1783 "%s:File claims to be smaller than read size, continuing\n",
1786 /* exactly equal, perfection */
1789 * In both cases where we proceed, using the self-reported file length
1790 * is the safer option. In case of old format a predefined value is
1793 while (ptr < (u32 *)(dd->platform_config.data + file_length)) {
1795 header2 = *(ptr + 1);
1796 if (header1 != ~header2) {
1797 dd_dev_err(dd, "%s: Failed validation at offset %ld\n",
1798 __func__, (ptr - (u32 *)
1799 dd->platform_config.data));
1805 ((1 << PLATFORM_CONFIG_HEADER_RECORD_IDX_LEN_BITS) - 1);
1807 table_length_dwords = (*ptr >>
1808 PLATFORM_CONFIG_HEADER_TABLE_LENGTH_SHIFT) &
1809 ((1 << PLATFORM_CONFIG_HEADER_TABLE_LENGTH_LEN_BITS) - 1);
1811 table_type = (*ptr >> PLATFORM_CONFIG_HEADER_TABLE_TYPE_SHIFT) &
1812 ((1 << PLATFORM_CONFIG_HEADER_TABLE_TYPE_LEN_BITS) - 1);
1814 /* Done with this set of headers */
1819 switch (table_type) {
1820 case PLATFORM_CONFIG_SYSTEM_TABLE:
1821 pcfgcache->config_tables[table_type].num_table =
1823 ret = check_meta_version(dd, ptr);
1827 case PLATFORM_CONFIG_PORT_TABLE:
1828 pcfgcache->config_tables[table_type].num_table =
1831 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1832 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1833 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1834 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1835 pcfgcache->config_tables[table_type].num_table =
1836 table_length_dwords;
1840 "%s: Unknown data table %d, offset %ld\n",
1841 __func__, table_type,
1843 dd->platform_config.data));
1845 goto bail; /* We don't trust this file now */
1847 pcfgcache->config_tables[table_type].table = ptr;
1849 /* metadata table */
1850 switch (table_type) {
1851 case PLATFORM_CONFIG_SYSTEM_TABLE:
1852 case PLATFORM_CONFIG_PORT_TABLE:
1853 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1854 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1855 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1856 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1860 "%s: Unknown meta table %d, offset %ld\n",
1861 __func__, table_type,
1863 (u32 *)dd->platform_config.data));
1865 goto bail; /* We don't trust this file now */
1867 pcfgcache->config_tables[table_type].table_metadata =
1871 /* Calculate and check table crc */
1872 crc = crc32_le(~(u32)0, (unsigned char const *)ptr,
1873 (table_length_dwords * 4));
1876 /* Jump the table */
1877 ptr += table_length_dwords;
1879 dd_dev_err(dd, "%s: Failed CRC check at offset %ld\n",
1881 (u32 *)dd->platform_config.data));
1885 /* Jump the CRC DWORD */
1889 pcfgcache->cache_valid = 1;
1892 memset(pcfgcache, 0, sizeof(struct platform_config_cache));
1896 static void get_integrated_platform_config_field(
1897 struct hfi1_devdata *dd,
1898 enum platform_config_table_type_encoding table_type,
1899 int field_index, u32 *data)
1901 struct hfi1_pportdata *ppd = dd->pport;
1902 u8 *cache = ppd->qsfp_info.cache;
1905 switch (table_type) {
1906 case PLATFORM_CONFIG_SYSTEM_TABLE:
1907 if (field_index == SYSTEM_TABLE_QSFP_POWER_CLASS_MAX)
1908 *data = ppd->max_power_class;
1909 else if (field_index == SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G)
1910 *data = ppd->default_atten;
1912 case PLATFORM_CONFIG_PORT_TABLE:
1913 if (field_index == PORT_TABLE_PORT_TYPE)
1914 *data = ppd->port_type;
1915 else if (field_index == PORT_TABLE_LOCAL_ATTEN_25G)
1916 *data = ppd->local_atten;
1917 else if (field_index == PORT_TABLE_REMOTE_ATTEN_25G)
1918 *data = ppd->remote_atten;
1920 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1921 if (field_index == RX_PRESET_TABLE_QSFP_RX_CDR_APPLY)
1922 *data = (ppd->rx_preset & QSFP_RX_CDR_APPLY_SMASK) >>
1923 QSFP_RX_CDR_APPLY_SHIFT;
1924 else if (field_index == RX_PRESET_TABLE_QSFP_RX_EMP_APPLY)
1925 *data = (ppd->rx_preset & QSFP_RX_EMP_APPLY_SMASK) >>
1926 QSFP_RX_EMP_APPLY_SHIFT;
1927 else if (field_index == RX_PRESET_TABLE_QSFP_RX_AMP_APPLY)
1928 *data = (ppd->rx_preset & QSFP_RX_AMP_APPLY_SMASK) >>
1929 QSFP_RX_AMP_APPLY_SHIFT;
1930 else if (field_index == RX_PRESET_TABLE_QSFP_RX_CDR)
1931 *data = (ppd->rx_preset & QSFP_RX_CDR_SMASK) >>
1933 else if (field_index == RX_PRESET_TABLE_QSFP_RX_EMP)
1934 *data = (ppd->rx_preset & QSFP_RX_EMP_SMASK) >>
1936 else if (field_index == RX_PRESET_TABLE_QSFP_RX_AMP)
1937 *data = (ppd->rx_preset & QSFP_RX_AMP_SMASK) >>
1940 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1941 if (cache[QSFP_EQ_INFO_OFFS] & 0x4)
1942 tx_preset = ppd->tx_preset_eq;
1944 tx_preset = ppd->tx_preset_noeq;
1945 if (field_index == TX_PRESET_TABLE_PRECUR)
1946 *data = (tx_preset & TX_PRECUR_SMASK) >>
1948 else if (field_index == TX_PRESET_TABLE_ATTN)
1949 *data = (tx_preset & TX_ATTN_SMASK) >>
1951 else if (field_index == TX_PRESET_TABLE_POSTCUR)
1952 *data = (tx_preset & TX_POSTCUR_SMASK) >>
1954 else if (field_index == TX_PRESET_TABLE_QSFP_TX_CDR_APPLY)
1955 *data = (tx_preset & QSFP_TX_CDR_APPLY_SMASK) >>
1956 QSFP_TX_CDR_APPLY_SHIFT;
1957 else if (field_index == TX_PRESET_TABLE_QSFP_TX_EQ_APPLY)
1958 *data = (tx_preset & QSFP_TX_EQ_APPLY_SMASK) >>
1959 QSFP_TX_EQ_APPLY_SHIFT;
1960 else if (field_index == TX_PRESET_TABLE_QSFP_TX_CDR)
1961 *data = (tx_preset & QSFP_TX_CDR_SMASK) >>
1963 else if (field_index == TX_PRESET_TABLE_QSFP_TX_EQ)
1964 *data = (tx_preset & QSFP_TX_EQ_SMASK) >>
1967 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1968 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1974 static int get_platform_fw_field_metadata(struct hfi1_devdata *dd, int table,
1975 int field, u32 *field_len_bits,
1976 u32 *field_start_bits)
1978 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1979 u32 *src_ptr = NULL;
1981 if (!pcfgcache->cache_valid)
1985 case PLATFORM_CONFIG_SYSTEM_TABLE:
1986 case PLATFORM_CONFIG_PORT_TABLE:
1987 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1988 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1989 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1990 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1991 if (field && field < platform_config_table_limits[table])
1993 pcfgcache->config_tables[table].table_metadata + field;
1996 dd_dev_info(dd, "%s: Unknown table\n", __func__);
2003 if (field_start_bits)
2004 *field_start_bits = *src_ptr &
2005 ((1 << METADATA_TABLE_FIELD_START_LEN_BITS) - 1);
2008 *field_len_bits = (*src_ptr >> METADATA_TABLE_FIELD_LEN_SHIFT)
2009 & ((1 << METADATA_TABLE_FIELD_LEN_LEN_BITS) - 1);
2014 /* This is the central interface to getting data out of the platform config
2015 * file. It depends on parse_platform_config() having populated the
2016 * platform_config_cache in hfi1_devdata, and checks the cache_valid member to
2017 * validate the sanity of the cache.
2019 * The non-obvious parameters:
2020 * @table_index: Acts as a look up key into which instance of the tables the
2021 * relevant field is fetched from.
2023 * This applies to the data tables that have multiple instances. The port table
2024 * is an exception to this rule as each HFI only has one port and thus the
2025 * relevant table can be distinguished by hfi_id.
2027 * @data: pointer to memory that will be populated with the field requested.
2028 * @len: length of memory pointed by @data in bytes.
2030 int get_platform_config_field(struct hfi1_devdata *dd,
2031 enum platform_config_table_type_encoding
2032 table_type, int table_index, int field_index,
2035 int ret = 0, wlen = 0, seek = 0;
2036 u32 field_len_bits = 0, field_start_bits = 0, *src_ptr = NULL;
2037 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
2038 struct hfi1_pportdata *ppd = dd->pport;
2041 memset(data, 0, len);
2045 if (ppd->config_from_scratch) {
2047 * Use saved configuration from ppd for integrated platforms
2049 get_integrated_platform_config_field(dd, table_type,
2054 ret = get_platform_fw_field_metadata(dd, table_type, field_index,
2060 /* Convert length to bits */
2063 /* Our metadata function checked cache_valid and field_index for us */
2064 switch (table_type) {
2065 case PLATFORM_CONFIG_SYSTEM_TABLE:
2066 src_ptr = pcfgcache->config_tables[table_type].table;
2068 if (field_index != SYSTEM_TABLE_QSFP_POWER_CLASS_MAX) {
2069 if (len < field_len_bits)
2072 seek = field_start_bits / 8;
2073 wlen = field_len_bits / 8;
2075 src_ptr = (u32 *)((u8 *)src_ptr + seek);
2078 * We expect the field to be byte aligned and whole byte
2079 * lengths if we are here
2081 memcpy(data, src_ptr, wlen);
2085 case PLATFORM_CONFIG_PORT_TABLE:
2086 /* Port table is 4 DWORDS */
2087 src_ptr = dd->hfi1_id ?
2088 pcfgcache->config_tables[table_type].table + 4 :
2089 pcfgcache->config_tables[table_type].table;
2091 case PLATFORM_CONFIG_RX_PRESET_TABLE:
2092 case PLATFORM_CONFIG_TX_PRESET_TABLE:
2093 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
2094 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
2095 src_ptr = pcfgcache->config_tables[table_type].table;
2098 pcfgcache->config_tables[table_type].num_table)
2099 src_ptr += table_index;
2104 dd_dev_info(dd, "%s: Unknown table\n", __func__);
2108 if (!src_ptr || len < field_len_bits)
2111 src_ptr += (field_start_bits / 32);
2112 *data = (*src_ptr >> (field_start_bits % 32)) &
2113 ((1 << field_len_bits) - 1);
2119 * Download the firmware needed for the Gen3 PCIe SerDes. An update
2120 * to the SBus firmware is needed before updating the PCIe firmware.
2122 * Note: caller must be holding the SBus resource.
2124 int load_pcie_firmware(struct hfi1_devdata *dd)
2128 /* both firmware loads below use the SBus */
2129 set_sbus_fast_mode(dd);
2132 turn_off_spicos(dd, SPICO_SBUS);
2134 ret = load_sbus_firmware(dd, &fw_sbus);
2135 } while (retry_firmware(dd, ret));
2140 if (fw_pcie_serdes_load) {
2141 dd_dev_info(dd, "Setting PCIe SerDes broadcast\n");
2142 set_serdes_broadcast(dd, all_pcie_serdes_broadcast,
2143 pcie_serdes_broadcast[dd->hfi1_id],
2144 pcie_serdes_addrs[dd->hfi1_id],
2147 ret = load_pcie_serdes_firmware(dd, &fw_pcie);
2148 } while (retry_firmware(dd, ret));
2154 clear_sbus_fast_mode(dd);
2160 * Read the GUID from the hardware, store it in dd.
2162 void read_guid(struct hfi1_devdata *dd)
2164 /* Take the DC out of reset to get a valid GUID value */
2165 write_csr(dd, CCE_DC_CTRL, 0);
2166 (void)read_csr(dd, CCE_DC_CTRL);
2168 dd->base_guid = read_csr(dd, DC_DC8051_CFG_LOCAL_GUID);
2169 dd_dev_info(dd, "GUID %llx",
2170 (unsigned long long)dd->base_guid);
2173 /* read and display firmware version info */
2174 static void dump_fw_version(struct hfi1_devdata *dd)
2176 u32 pcie_vers[NUM_PCIE_SERDES];
2177 u32 fabric_vers[NUM_FABRIC_SERDES];
2184 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
2186 dd_dev_err(dd, "Unable to acquire SBus to read firmware versions\n");
2191 set_sbus_fast_mode(dd);
2193 /* read version for SBus Master */
2194 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x02, WRITE_SBUS_RECEIVER, 0);
2195 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x07, WRITE_SBUS_RECEIVER, 0x1);
2196 /* wait for interrupt to be processed */
2197 usleep_range(10000, 11000);
2198 sbus_vers = sbus_read(dd, SBUS_MASTER_BROADCAST, 0x08, 0x1);
2199 dd_dev_info(dd, "SBus Master firmware version 0x%08x\n", sbus_vers);
2201 /* read version for PCIe SerDes */
2204 for (i = 0; i < NUM_PCIE_SERDES; i++) {
2205 rcv_addr = pcie_serdes_addrs[dd->hfi1_id][i];
2206 sbus_request(dd, rcv_addr, 0x03, WRITE_SBUS_RECEIVER, 0);
2207 /* wait for interrupt to be processed */
2208 usleep_range(10000, 11000);
2209 pcie_vers[i] = sbus_read(dd, rcv_addr, 0x04, 0x0);
2210 if (i > 0 && pcie_vers[0] != pcie_vers[i])
2215 dd_dev_info(dd, "PCIe SerDes firmware version 0x%x\n",
2218 dd_dev_warn(dd, "PCIe SerDes do not have the same firmware version\n");
2219 for (i = 0; i < NUM_PCIE_SERDES; i++) {
2221 "PCIe SerDes lane %d firmware version 0x%x\n",
2226 /* read version for fabric SerDes */
2229 for (i = 0; i < NUM_FABRIC_SERDES; i++) {
2230 rcv_addr = fabric_serdes_addrs[dd->hfi1_id][i];
2231 sbus_request(dd, rcv_addr, 0x03, WRITE_SBUS_RECEIVER, 0);
2232 /* wait for interrupt to be processed */
2233 usleep_range(10000, 11000);
2234 fabric_vers[i] = sbus_read(dd, rcv_addr, 0x04, 0x0);
2235 if (i > 0 && fabric_vers[0] != fabric_vers[i])
2240 dd_dev_info(dd, "Fabric SerDes firmware version 0x%x\n",
2243 dd_dev_warn(dd, "Fabric SerDes do not have the same firmware version\n");
2244 for (i = 0; i < NUM_FABRIC_SERDES; i++) {
2246 "Fabric SerDes lane %d firmware version 0x%x\n",
2251 clear_sbus_fast_mode(dd);
2252 release_chip_resource(dd, CR_SBUS);