1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48#include <linux/firmware.h>
49#include <linux/mutex.h>
50#include <linux/module.h>
51#include <linux/delay.h>
52#include <linux/crc32.h>
53
54#include "hfi.h"
55#include "trace.h"
56
57
58
59
60
61
62#define DEFAULT_FW_8051_NAME_FPGA "hfi_dc8051.bin"
63#define DEFAULT_FW_8051_NAME_ASIC "hfi1_dc8051.fw"
64#define DEFAULT_FW_FABRIC_NAME "hfi1_fabric.fw"
65#define DEFAULT_FW_SBUS_NAME "hfi1_sbus.fw"
66#define DEFAULT_FW_PCIE_NAME "hfi1_pcie.fw"
67#define ALT_FW_8051_NAME_ASIC "hfi1_dc8051_d.fw"
68#define ALT_FW_FABRIC_NAME "hfi1_fabric_d.fw"
69#define ALT_FW_SBUS_NAME "hfi1_sbus_d.fw"
70#define ALT_FW_PCIE_NAME "hfi1_pcie_d.fw"
71
72MODULE_FIRMWARE(DEFAULT_FW_8051_NAME_ASIC);
73MODULE_FIRMWARE(DEFAULT_FW_FABRIC_NAME);
74MODULE_FIRMWARE(DEFAULT_FW_SBUS_NAME);
75MODULE_FIRMWARE(DEFAULT_FW_PCIE_NAME);
76
77static uint fw_8051_load = 1;
78static uint fw_fabric_serdes_load = 1;
79static uint fw_pcie_serdes_load = 1;
80static uint fw_sbus_load = 1;
81
82
83static char *fw_8051_name;
84static char *fw_fabric_serdes_name;
85static char *fw_sbus_name;
86static char *fw_pcie_serdes_name;
87
88#define SBUS_MAX_POLL_COUNT 100
89#define SBUS_COUNTER(reg, name) \
90 (((reg) >> ASIC_STS_SBUS_COUNTERS_##name##_CNT_SHIFT) & \
91 ASIC_STS_SBUS_COUNTERS_##name##_CNT_MASK)
92
93
94
95
96struct css_header {
97 u32 module_type;
98 u32 header_len;
99 u32 header_version;
100 u32 module_id;
101 u32 module_vendor;
102 u32 date;
103 u32 size;
104 u32 key_size;
105 u32 modulus_size;
106 u32 exponent_size;
107 u32 reserved[22];
108};
109
110
111#define CSS_MODULE_TYPE 0x00000006
112#define CSS_HEADER_LEN 0x000000a1
113#define CSS_HEADER_VERSION 0x00010000
114#define CSS_MODULE_VENDOR 0x00008086
115
116#define KEY_SIZE 256
117#define MU_SIZE 8
118#define EXPONENT_SIZE 4
119
120
121#define MAX_PLATFORM_CONFIG_FILE_SIZE 4096
122
123
124#define PLATFORM_CONFIG_FORMAT_4_FILE_SIZE 528
125
126
127struct firmware_file {
128 struct css_header css_header;
129 u8 modulus[KEY_SIZE];
130 u8 exponent[EXPONENT_SIZE];
131 u8 signature[KEY_SIZE];
132 u8 firmware[];
133};
134
135struct augmented_firmware_file {
136 struct css_header css_header;
137 u8 modulus[KEY_SIZE];
138 u8 exponent[EXPONENT_SIZE];
139 u8 signature[KEY_SIZE];
140 u8 r2[KEY_SIZE];
141 u8 mu[MU_SIZE];
142 u8 firmware[];
143};
144
145
146#define AUGMENT_SIZE (sizeof(struct augmented_firmware_file) - \
147 sizeof(struct firmware_file))
148
149struct firmware_details {
150
151 const struct firmware *fw;
152
153 struct css_header *css_header;
154 u8 *firmware_ptr;
155 u32 firmware_len;
156 u8 *modulus;
157 u8 *exponent;
158 u8 *signature;
159 u8 *r2;
160 u8 *mu;
161 struct augmented_firmware_file dummy_header;
162};
163
164
165
166
167
168static DEFINE_MUTEX(fw_mutex);
169enum fw_state {
170 FW_EMPTY,
171 FW_TRY,
172 FW_FINAL,
173 FW_ERR
174};
175
176static enum fw_state fw_state = FW_EMPTY;
177static int fw_err;
178static struct firmware_details fw_8051;
179static struct firmware_details fw_fabric;
180static struct firmware_details fw_pcie;
181static struct firmware_details fw_sbus;
182
183
184#define SPICO_SBUS 0x1
185#define SPICO_FABRIC 0x2
186#define ENABLE_SPICO_SMASK 0x1
187
188
189#define RSA_CMD_INIT 0x1
190#define RSA_CMD_START 0x2
191
192
193#define RSA_STATUS_IDLE 0x0
194#define RSA_STATUS_ACTIVE 0x1
195#define RSA_STATUS_DONE 0x2
196#define RSA_STATUS_FAILED 0x3
197
198
199#define RSA_ENGINE_TIMEOUT 100
200
201
202#define HM_TIMEOUT 10
203
204
205#define DC8051_ACCESS_TIMEOUT 100
206
207
208#define NUM_FABRIC_SERDES 4
209
210
211#define SBUS_READ_COMPLETE 0x4
212
213
214static const u8 fabric_serdes_addrs[2][NUM_FABRIC_SERDES] = {
215 { 0x01, 0x02, 0x03, 0x04 },
216 { 0x28, 0x29, 0x2a, 0x2b }
217};
218
219
220static const u8 pcie_serdes_addrs[2][NUM_PCIE_SERDES] = {
221 { 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16,
222 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26 },
223 { 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b, 0x3d,
224 0x3f, 0x41, 0x43, 0x45, 0x47, 0x49, 0x4b, 0x4d }
225};
226
227
228const u8 pcie_pcs_addrs[2][NUM_PCIE_SERDES] = {
229 { 0x09, 0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x15, 0x17,
230 0x19, 0x1b, 0x1d, 0x1f, 0x21, 0x23, 0x25, 0x27 },
231 { 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
232 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e }
233};
234
235
236static const u8 fabric_serdes_broadcast[2] = { 0xe4, 0xe5 };
237static const u8 all_fabric_serdes_broadcast = 0xe1;
238
239
240const u8 pcie_serdes_broadcast[2] = { 0xe2, 0xe3 };
241static const u8 all_pcie_serdes_broadcast = 0xe0;
242
243static const u32 platform_config_table_limits[PLATFORM_CONFIG_TABLE_MAX] = {
244 0,
245 SYSTEM_TABLE_MAX,
246 PORT_TABLE_MAX,
247 RX_PRESET_TABLE_MAX,
248 TX_PRESET_TABLE_MAX,
249 QSFP_ATTEN_TABLE_MAX,
250 VARIABLE_SETTINGS_TABLE_MAX
251};
252
253
254static void dispose_one_firmware(struct firmware_details *fdet);
255static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
256 struct firmware_details *fdet);
257static void dump_fw_version(struct hfi1_devdata *dd);
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272static int __read_8051_data(struct hfi1_devdata *dd, u32 addr, u64 *result)
273{
274 u64 reg;
275 int count;
276
277
278 reg = (addr & DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_MASK)
279 << DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_SHIFT;
280 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, reg);
281
282 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL,
283 reg | DC_DC8051_CFG_RAM_ACCESS_CTRL_READ_ENA_SMASK);
284
285
286 count = 0;
287 while ((read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_STATUS)
288 & DC_DC8051_CFG_RAM_ACCESS_STATUS_ACCESS_COMPLETED_SMASK)
289 == 0) {
290 count++;
291 if (count > DC8051_ACCESS_TIMEOUT) {
292 dd_dev_err(dd, "timeout reading 8051 data\n");
293 return -ENXIO;
294 }
295 ndelay(10);
296 }
297
298
299 *result = read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_RD_DATA);
300
301 return 0;
302}
303
304
305
306
307
308int read_8051_data(struct hfi1_devdata *dd, u32 addr, u32 len, u64 *result)
309{
310 unsigned long flags;
311 u32 done;
312 int ret = 0;
313
314 spin_lock_irqsave(&dd->dc8051_memlock, flags);
315
316
317 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, 0);
318
319 for (done = 0; done < len; addr += 8, done += 8, result++) {
320 ret = __read_8051_data(dd, addr, result);
321 if (ret)
322 break;
323 }
324
325
326 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, 0);
327
328 spin_unlock_irqrestore(&dd->dc8051_memlock, flags);
329
330 return ret;
331}
332
333
334
335
336static int write_8051(struct hfi1_devdata *dd, int code, u32 start,
337 const u8 *data, u32 len)
338{
339 u64 reg;
340 u32 offset;
341 int aligned, count;
342
343
344 aligned = ((unsigned long)data & 0x7) == 0;
345
346
347 reg = (code ? DC_DC8051_CFG_RAM_ACCESS_SETUP_RAM_SEL_SMASK : 0ull)
348 | DC_DC8051_CFG_RAM_ACCESS_SETUP_AUTO_INCR_ADDR_SMASK;
349 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, reg);
350
351 reg = ((start & DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_MASK)
352 << DC_DC8051_CFG_RAM_ACCESS_CTRL_ADDRESS_SHIFT)
353 | DC_DC8051_CFG_RAM_ACCESS_CTRL_WRITE_ENA_SMASK;
354 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, reg);
355
356
357 for (offset = 0; offset < len; offset += 8) {
358 int bytes = len - offset;
359
360 if (bytes < 8) {
361 reg = 0;
362 memcpy(®, &data[offset], bytes);
363 } else if (aligned) {
364 reg = *(u64 *)&data[offset];
365 } else {
366 memcpy(®, &data[offset], 8);
367 }
368 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_WR_DATA, reg);
369
370
371 count = 0;
372 while ((read_csr(dd, DC_DC8051_CFG_RAM_ACCESS_STATUS)
373 & DC_DC8051_CFG_RAM_ACCESS_STATUS_ACCESS_COMPLETED_SMASK)
374 == 0) {
375 count++;
376 if (count > DC8051_ACCESS_TIMEOUT) {
377 dd_dev_err(dd, "timeout writing 8051 data\n");
378 return -ENXIO;
379 }
380 udelay(1);
381 }
382 }
383
384
385 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_CTRL, 0);
386 write_csr(dd, DC_DC8051_CFG_RAM_ACCESS_SETUP, 0);
387
388 return 0;
389}
390
391
392static int invalid_header(struct hfi1_devdata *dd, const char *what,
393 u32 actual, u32 expected)
394{
395 if (actual == expected)
396 return 0;
397
398 dd_dev_err(dd,
399 "invalid firmware header field %s: expected 0x%x, actual 0x%x\n",
400 what, expected, actual);
401 return 1;
402}
403
404
405
406
407static int verify_css_header(struct hfi1_devdata *dd, struct css_header *css)
408{
409
410 if (invalid_header(dd, "module_type", css->module_type,
411 CSS_MODULE_TYPE) ||
412 invalid_header(dd, "header_len", css->header_len,
413 (sizeof(struct firmware_file) / 4)) ||
414 invalid_header(dd, "header_version", css->header_version,
415 CSS_HEADER_VERSION) ||
416 invalid_header(dd, "module_vendor", css->module_vendor,
417 CSS_MODULE_VENDOR) ||
418 invalid_header(dd, "key_size", css->key_size, KEY_SIZE / 4) ||
419 invalid_header(dd, "modulus_size", css->modulus_size,
420 KEY_SIZE / 4) ||
421 invalid_header(dd, "exponent_size", css->exponent_size,
422 EXPONENT_SIZE / 4)) {
423 return -EINVAL;
424 }
425 return 0;
426}
427
428
429
430
431static int payload_check(struct hfi1_devdata *dd, const char *name,
432 long file_size, long prefix_size)
433{
434
435 if (prefix_size >= file_size) {
436 dd_dev_err(dd,
437 "firmware \"%s\", size %ld, must be larger than %ld bytes\n",
438 name, file_size, prefix_size);
439 return -EINVAL;
440 }
441
442 return 0;
443}
444
445
446
447
448
449
450static int obtain_one_firmware(struct hfi1_devdata *dd, const char *name,
451 struct firmware_details *fdet)
452{
453 struct css_header *css;
454 int ret;
455
456 memset(fdet, 0, sizeof(*fdet));
457
458 ret = request_firmware(&fdet->fw, name, &dd->pcidev->dev);
459 if (ret) {
460 dd_dev_warn(dd, "cannot find firmware \"%s\", err %d\n",
461 name, ret);
462 return ret;
463 }
464
465
466 if (fdet->fw->size < sizeof(struct css_header)) {
467 dd_dev_err(dd, "firmware \"%s\" is too small\n", name);
468 ret = -EINVAL;
469 goto done;
470 }
471 css = (struct css_header *)fdet->fw->data;
472
473 hfi1_cdbg(FIRMWARE, "Firmware %s details:", name);
474 hfi1_cdbg(FIRMWARE, "file size: 0x%lx bytes", fdet->fw->size);
475 hfi1_cdbg(FIRMWARE, "CSS structure:");
476 hfi1_cdbg(FIRMWARE, " module_type 0x%x", css->module_type);
477 hfi1_cdbg(FIRMWARE, " header_len 0x%03x (0x%03x bytes)",
478 css->header_len, 4 * css->header_len);
479 hfi1_cdbg(FIRMWARE, " header_version 0x%x", css->header_version);
480 hfi1_cdbg(FIRMWARE, " module_id 0x%x", css->module_id);
481 hfi1_cdbg(FIRMWARE, " module_vendor 0x%x", css->module_vendor);
482 hfi1_cdbg(FIRMWARE, " date 0x%x", css->date);
483 hfi1_cdbg(FIRMWARE, " size 0x%03x (0x%03x bytes)",
484 css->size, 4 * css->size);
485 hfi1_cdbg(FIRMWARE, " key_size 0x%03x (0x%03x bytes)",
486 css->key_size, 4 * css->key_size);
487 hfi1_cdbg(FIRMWARE, " modulus_size 0x%03x (0x%03x bytes)",
488 css->modulus_size, 4 * css->modulus_size);
489 hfi1_cdbg(FIRMWARE, " exponent_size 0x%03x (0x%03x bytes)",
490 css->exponent_size, 4 * css->exponent_size);
491 hfi1_cdbg(FIRMWARE, "firmware size: 0x%lx bytes",
492 fdet->fw->size - sizeof(struct firmware_file));
493
494
495
496
497
498
499
500
501
502
503
504 ret = verify_css_header(dd, css);
505 if (ret) {
506 dd_dev_info(dd, "Invalid CSS header for \"%s\"\n", name);
507 } else if ((css->size * 4) == fdet->fw->size) {
508
509 struct firmware_file *ff = (struct firmware_file *)
510 fdet->fw->data;
511
512
513 ret = payload_check(dd, name, fdet->fw->size,
514 sizeof(struct firmware_file));
515 if (ret == 0) {
516 fdet->css_header = css;
517 fdet->modulus = ff->modulus;
518 fdet->exponent = ff->exponent;
519 fdet->signature = ff->signature;
520 fdet->r2 = fdet->dummy_header.r2;
521 fdet->mu = fdet->dummy_header.mu;
522 fdet->firmware_ptr = ff->firmware;
523 fdet->firmware_len = fdet->fw->size -
524 sizeof(struct firmware_file);
525
526
527
528
529 dd_dev_err(dd, "driver is unable to validate firmware without r2 and mu (not in firmware file)\n");
530 ret = -EINVAL;
531 }
532 } else if ((css->size * 4) + AUGMENT_SIZE == fdet->fw->size) {
533
534 struct augmented_firmware_file *aff =
535 (struct augmented_firmware_file *)fdet->fw->data;
536
537
538 ret = payload_check(dd, name, fdet->fw->size,
539 sizeof(struct augmented_firmware_file));
540 if (ret == 0) {
541 fdet->css_header = css;
542 fdet->modulus = aff->modulus;
543 fdet->exponent = aff->exponent;
544 fdet->signature = aff->signature;
545 fdet->r2 = aff->r2;
546 fdet->mu = aff->mu;
547 fdet->firmware_ptr = aff->firmware;
548 fdet->firmware_len = fdet->fw->size -
549 sizeof(struct augmented_firmware_file);
550 }
551 } else {
552
553 dd_dev_err(dd,
554 "invalid firmware header field size: expected 0x%lx or 0x%lx, actual 0x%x\n",
555 fdet->fw->size / 4,
556 (fdet->fw->size - AUGMENT_SIZE) / 4,
557 css->size);
558
559 ret = -EINVAL;
560 }
561
562done:
563
564 if (ret)
565 dispose_one_firmware(fdet);
566 return ret;
567}
568
569static void dispose_one_firmware(struct firmware_details *fdet)
570{
571 release_firmware(fdet->fw);
572
573 memset(fdet, 0, sizeof(*fdet));
574}
575
576
577
578
579
580
581
582
583
584static void __obtain_firmware(struct hfi1_devdata *dd)
585{
586 int err = 0;
587
588 if (fw_state == FW_FINAL)
589 return;
590 if (fw_state == FW_ERR)
591 return;
592
593
594retry:
595 if (fw_state == FW_TRY) {
596
597
598
599
600 dd_dev_warn(dd, "using alternate firmware names\n");
601
602
603
604
605
606 cond_resched();
607 if (fw_8051_load)
608 dispose_one_firmware(&fw_8051);
609 if (fw_fabric_serdes_load)
610 dispose_one_firmware(&fw_fabric);
611 if (fw_sbus_load)
612 dispose_one_firmware(&fw_sbus);
613 if (fw_pcie_serdes_load)
614 dispose_one_firmware(&fw_pcie);
615 fw_8051_name = ALT_FW_8051_NAME_ASIC;
616 fw_fabric_serdes_name = ALT_FW_FABRIC_NAME;
617 fw_sbus_name = ALT_FW_SBUS_NAME;
618 fw_pcie_serdes_name = ALT_FW_PCIE_NAME;
619
620
621
622
623
624
625
626 usleep_range(100, 120);
627 }
628
629 if (fw_sbus_load) {
630 err = obtain_one_firmware(dd, fw_sbus_name, &fw_sbus);
631 if (err)
632 goto done;
633 }
634
635 if (fw_pcie_serdes_load) {
636 err = obtain_one_firmware(dd, fw_pcie_serdes_name, &fw_pcie);
637 if (err)
638 goto done;
639 }
640
641 if (fw_fabric_serdes_load) {
642 err = obtain_one_firmware(dd, fw_fabric_serdes_name,
643 &fw_fabric);
644 if (err)
645 goto done;
646 }
647
648 if (fw_8051_load) {
649 err = obtain_one_firmware(dd, fw_8051_name, &fw_8051);
650 if (err)
651 goto done;
652 }
653
654done:
655 if (err) {
656
657 if (fw_state == FW_EMPTY && dd->icode == ICODE_RTL_SILICON) {
658
659 fw_state = FW_TRY;
660 goto retry;
661 }
662 dd_dev_err(dd, "unable to obtain working firmware\n");
663 fw_state = FW_ERR;
664 fw_err = -ENOENT;
665 } else {
666
667 if (fw_state == FW_EMPTY &&
668 dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
669 fw_state = FW_TRY;
670 else
671 fw_state = FW_FINAL;
672 }
673}
674
675
676
677
678
679
680
681
682
683
684static int obtain_firmware(struct hfi1_devdata *dd)
685{
686 unsigned long timeout;
687
688 mutex_lock(&fw_mutex);
689
690
691 timeout = jiffies + msecs_to_jiffies(40000);
692 while (fw_state == FW_TRY) {
693
694
695
696
697 if (time_after(jiffies, timeout)) {
698
699 dd_dev_err(dd, "Timeout waiting for firmware try");
700 fw_state = FW_ERR;
701 fw_err = -ETIMEDOUT;
702 break;
703 }
704 mutex_unlock(&fw_mutex);
705 msleep(20);
706 mutex_lock(&fw_mutex);
707 }
708
709
710
711 if (fw_state == FW_EMPTY)
712 __obtain_firmware(dd);
713
714 mutex_unlock(&fw_mutex);
715 return fw_err;
716}
717
718
719
720
721
722
723
724
725
726
727
728
729void dispose_firmware(void)
730{
731 dispose_one_firmware(&fw_8051);
732 dispose_one_firmware(&fw_fabric);
733 dispose_one_firmware(&fw_pcie);
734 dispose_one_firmware(&fw_sbus);
735
736
737 if (fw_state != FW_ERR)
738 fw_state = FW_EMPTY;
739}
740
741
742
743
744
745
746static int retry_firmware(struct hfi1_devdata *dd, int load_result)
747{
748 int retry;
749
750 mutex_lock(&fw_mutex);
751
752 if (load_result == 0) {
753
754
755
756
757 if (fw_state == FW_TRY)
758 fw_state = FW_FINAL;
759 retry = 0;
760 } else if (fw_state == FW_TRY) {
761
762 __obtain_firmware(dd);
763 retry = (fw_state == FW_FINAL);
764 } else {
765
766 retry = 0;
767 }
768
769 mutex_unlock(&fw_mutex);
770 return retry;
771}
772
773
774
775
776
777static void write_rsa_data(struct hfi1_devdata *dd, int what,
778 const u8 *data, int nbytes)
779{
780 int qw_size = nbytes / 8;
781 int i;
782
783 if (((unsigned long)data & 0x7) == 0) {
784
785 u64 *ptr = (u64 *)data;
786
787 for (i = 0; i < qw_size; i++, ptr++)
788 write_csr(dd, what + (8 * i), *ptr);
789 } else {
790
791 for (i = 0; i < qw_size; i++, data += 8) {
792 u64 value;
793
794 memcpy(&value, data, 8);
795 write_csr(dd, what + (8 * i), value);
796 }
797 }
798}
799
800
801
802
803
804static void write_streamed_rsa_data(struct hfi1_devdata *dd, int what,
805 const u8 *data, int nbytes)
806{
807 u64 *ptr = (u64 *)data;
808 int qw_size = nbytes / 8;
809
810 for (; qw_size > 0; qw_size--, ptr++)
811 write_csr(dd, what, *ptr);
812}
813
814
815
816
817
818static int run_rsa(struct hfi1_devdata *dd, const char *who,
819 const u8 *signature)
820{
821 unsigned long timeout;
822 u64 reg;
823 u32 status;
824 int ret = 0;
825
826
827 write_rsa_data(dd, MISC_CFG_RSA_SIGNATURE, signature, KEY_SIZE);
828
829
830 write_csr(dd, MISC_CFG_RSA_CMD, RSA_CMD_INIT);
831
832
833
834
835
836 status = (read_csr(dd, MISC_CFG_FW_CTRL)
837 & MISC_CFG_FW_CTRL_RSA_STATUS_SMASK)
838 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT;
839 if (status != RSA_STATUS_IDLE) {
840 dd_dev_err(dd, "%s security engine not idle - giving up\n",
841 who);
842 return -EBUSY;
843 }
844
845
846 write_csr(dd, MISC_CFG_RSA_CMD, RSA_CMD_START);
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869 timeout = msecs_to_jiffies(RSA_ENGINE_TIMEOUT) + jiffies;
870 while (1) {
871 status = (read_csr(dd, MISC_CFG_FW_CTRL)
872 & MISC_CFG_FW_CTRL_RSA_STATUS_SMASK)
873 >> MISC_CFG_FW_CTRL_RSA_STATUS_SHIFT;
874
875 if (status == RSA_STATUS_IDLE) {
876
877 dd_dev_err(dd, "%s firmware security bad idle state\n",
878 who);
879 ret = -EINVAL;
880 break;
881 } else if (status == RSA_STATUS_DONE) {
882
883 break;
884 } else if (status == RSA_STATUS_FAILED) {
885
886 ret = -EINVAL;
887 break;
888 }
889
890
891 if (time_after(jiffies, timeout)) {
892
893
894
895
896
897 dd_dev_err(dd, "%s firmware security time out\n", who);
898 ret = -ETIMEDOUT;
899 break;
900 }
901
902 msleep(20);
903 }
904
905
906
907
908
909
910
911 write_csr(dd, MISC_ERR_CLEAR,
912 MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK |
913 MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK);
914
915
916
917
918
919 reg = read_csr(dd, MISC_ERR_STATUS);
920 if (ret) {
921 if (reg & MISC_ERR_STATUS_MISC_FW_AUTH_FAILED_ERR_SMASK)
922 dd_dev_warn(dd, "%s firmware authorization failed\n",
923 who);
924 if (reg & MISC_ERR_STATUS_MISC_KEY_MISMATCH_ERR_SMASK)
925 dd_dev_warn(dd, "%s firmware key mismatch\n", who);
926 }
927
928 return ret;
929}
930
931static void load_security_variables(struct hfi1_devdata *dd,
932 struct firmware_details *fdet)
933{
934
935 write_rsa_data(dd, MISC_CFG_RSA_MODULUS, fdet->modulus, KEY_SIZE);
936
937 write_rsa_data(dd, MISC_CFG_RSA_R2, fdet->r2, KEY_SIZE);
938
939 write_rsa_data(dd, MISC_CFG_RSA_MU, fdet->mu, MU_SIZE);
940
941 write_streamed_rsa_data(dd, MISC_CFG_SHA_PRELOAD,
942 (u8 *)fdet->css_header,
943 sizeof(struct css_header));
944}
945
946
947static inline u32 get_firmware_state(struct hfi1_devdata *dd)
948{
949 u64 reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
950
951 return (reg >> DC_DC8051_STS_CUR_STATE_FIRMWARE_SHIFT)
952 & DC_DC8051_STS_CUR_STATE_FIRMWARE_MASK;
953}
954
955
956
957
958
959int wait_fm_ready(struct hfi1_devdata *dd, u32 mstimeout)
960{
961 unsigned long timeout;
962
963
964 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
965 return 0;
966
967 timeout = msecs_to_jiffies(mstimeout) + jiffies;
968 while (1) {
969 if (get_firmware_state(dd) == 0xa0)
970 return 0;
971 if (time_after(jiffies, timeout))
972 return -ETIMEDOUT;
973 usleep_range(1950, 2050);
974 }
975}
976
977
978
979
980static int load_8051_firmware(struct hfi1_devdata *dd,
981 struct firmware_details *fdet)
982{
983 u64 reg;
984 int ret;
985 u8 ver_major;
986 u8 ver_minor;
987 u8 ver_patch;
988
989
990
991
992
993
994
995
996 reg = DC_DC8051_CFG_RST_M8051W_SMASK
997 | DC_DC8051_CFG_RST_CRAM_SMASK
998 | DC_DC8051_CFG_RST_DRAM_SMASK
999 | DC_DC8051_CFG_RST_IRAM_SMASK
1000 | DC_DC8051_CFG_RST_SFR_SMASK;
1001 write_csr(dd, DC_DC8051_CFG_RST, reg);
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 reg = DC_DC8051_CFG_RST_M8051W_SMASK;
1013 write_csr(dd, DC_DC8051_CFG_RST, reg);
1014
1015
1016 load_security_variables(dd, fdet);
1017
1018
1019
1020
1021 write_csr(dd, MISC_CFG_FW_CTRL, 0);
1022
1023
1024 ret = write_8051(dd, 1, 0, fdet->firmware_ptr,
1025 fdet->firmware_len);
1026 if (ret)
1027 return ret;
1028
1029
1030
1031
1032
1033
1034
1035 write_csr(dd, MISC_CFG_FW_CTRL, MISC_CFG_FW_CTRL_FW_8051_LOADED_SMASK);
1036
1037
1038 ret = run_rsa(dd, "8051", fdet->signature);
1039 if (ret)
1040 return ret;
1041
1042
1043 write_csr(dd, DC_DC8051_CFG_RST, 0ull);
1044
1045
1046
1047
1048
1049 ret = wait_fm_ready(dd, TIMEOUT_8051_START);
1050 if (ret) {
1051 dd_dev_err(dd, "8051 start timeout, current state 0x%x\n",
1052 get_firmware_state(dd));
1053 return -ETIMEDOUT;
1054 }
1055
1056 read_misc_status(dd, &ver_major, &ver_minor, &ver_patch);
1057 dd_dev_info(dd, "8051 firmware version %d.%d.%d\n",
1058 (int)ver_major, (int)ver_minor, (int)ver_patch);
1059 dd->dc8051_ver = dc8051_ver(ver_major, ver_minor, ver_patch);
1060 ret = write_host_interface_version(dd, HOST_INTERFACE_VERSION);
1061 if (ret != HCMD_SUCCESS) {
1062 dd_dev_err(dd,
1063 "Failed to set host interface version, return 0x%x\n",
1064 ret);
1065 return -EIO;
1066 }
1067
1068 return 0;
1069}
1070
1071
1072
1073
1074
1075
1076void sbus_request(struct hfi1_devdata *dd,
1077 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in)
1078{
1079 write_csr(dd, ASIC_CFG_SBUS_REQUEST,
1080 ((u64)data_in << ASIC_CFG_SBUS_REQUEST_DATA_IN_SHIFT) |
1081 ((u64)command << ASIC_CFG_SBUS_REQUEST_COMMAND_SHIFT) |
1082 ((u64)data_addr << ASIC_CFG_SBUS_REQUEST_DATA_ADDR_SHIFT) |
1083 ((u64)receiver_addr <<
1084 ASIC_CFG_SBUS_REQUEST_RECEIVER_ADDR_SHIFT));
1085}
1086
1087
1088
1089
1090
1091
1092static u32 sbus_read(struct hfi1_devdata *dd, u8 receiver_addr, u8 data_addr,
1093 u32 data_in)
1094{
1095 u64 reg;
1096 int retries;
1097 int success = 0;
1098 u32 result = 0;
1099 u32 result_code = 0;
1100
1101 sbus_request(dd, receiver_addr, data_addr, READ_SBUS_RECEIVER, data_in);
1102
1103 for (retries = 0; retries < 100; retries++) {
1104 usleep_range(1000, 1200);
1105 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1106 result_code = (reg >> ASIC_STS_SBUS_RESULT_RESULT_CODE_SHIFT)
1107 & ASIC_STS_SBUS_RESULT_RESULT_CODE_MASK;
1108 if (result_code != SBUS_READ_COMPLETE)
1109 continue;
1110
1111 success = 1;
1112 result = (reg >> ASIC_STS_SBUS_RESULT_DATA_OUT_SHIFT)
1113 & ASIC_STS_SBUS_RESULT_DATA_OUT_MASK;
1114 break;
1115 }
1116
1117 if (!success) {
1118 dd_dev_err(dd, "%s: read failed, result code 0x%x\n", __func__,
1119 result_code);
1120 }
1121
1122 return result;
1123}
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133static void turn_off_spicos(struct hfi1_devdata *dd, int flags)
1134{
1135
1136 if (!is_ax(dd))
1137 return;
1138
1139 dd_dev_info(dd, "Turning off spicos:%s%s\n",
1140 flags & SPICO_SBUS ? " SBus" : "",
1141 flags & SPICO_FABRIC ? " fabric" : "");
1142
1143 write_csr(dd, MISC_CFG_FW_CTRL, ENABLE_SPICO_SMASK);
1144
1145 if (flags & SPICO_SBUS)
1146 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01,
1147 WRITE_SBUS_RECEIVER, 0x00000040);
1148
1149
1150 if (flags & SPICO_FABRIC)
1151 sbus_request(dd, fabric_serdes_broadcast[dd->hfi1_id],
1152 0x07, WRITE_SBUS_RECEIVER, 0x00000000);
1153 write_csr(dd, MISC_CFG_FW_CTRL, 0);
1154}
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170void fabric_serdes_reset(struct hfi1_devdata *dd)
1171{
1172 int ret;
1173
1174 if (!fw_fabric_serdes_load)
1175 return;
1176
1177 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1178 if (ret) {
1179 dd_dev_err(dd,
1180 "Cannot acquire SBus resource to reset fabric SerDes - perhaps you should reboot\n");
1181 return;
1182 }
1183 set_sbus_fast_mode(dd);
1184
1185 if (is_ax(dd)) {
1186
1187 u8 ra = fabric_serdes_broadcast[dd->hfi1_id];
1188
1189
1190 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011);
1191
1192 udelay(1);
1193
1194 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010);
1195
1196 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002);
1197 } else {
1198 turn_off_spicos(dd, SPICO_FABRIC);
1199
1200
1201
1202
1203
1204
1205
1206 (void)load_fabric_serdes_firmware(dd, &fw_fabric);
1207 }
1208
1209 clear_sbus_fast_mode(dd);
1210 release_chip_resource(dd, CR_SBUS);
1211}
1212
1213
1214int sbus_request_slow(struct hfi1_devdata *dd,
1215 u8 receiver_addr, u8 data_addr, u8 command, u32 data_in)
1216{
1217 u64 reg, count = 0;
1218
1219
1220 clear_sbus_fast_mode(dd);
1221
1222 sbus_request(dd, receiver_addr, data_addr, command, data_in);
1223 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1224 ASIC_CFG_SBUS_EXECUTE_EXECUTE_SMASK);
1225
1226 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1227 while (!((reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) &&
1228 (reg & ASIC_STS_SBUS_RESULT_RCV_DATA_VALID_SMASK))) {
1229 if (count++ >= SBUS_MAX_POLL_COUNT) {
1230 u64 counts = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1231
1232
1233
1234
1235
1236 if ((reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) &&
1237 (SBUS_COUNTER(counts, RCV_DATA_VALID) ==
1238 SBUS_COUNTER(counts, EXECUTE)))
1239 break;
1240 return -ETIMEDOUT;
1241 }
1242 udelay(1);
1243 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1244 }
1245 count = 0;
1246 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
1247
1248 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1249 while (reg & ASIC_STS_SBUS_RESULT_DONE_SMASK) {
1250 if (count++ >= SBUS_MAX_POLL_COUNT)
1251 return -ETIME;
1252 udelay(1);
1253 reg = read_csr(dd, ASIC_STS_SBUS_RESULT);
1254 }
1255 return 0;
1256}
1257
1258static int load_fabric_serdes_firmware(struct hfi1_devdata *dd,
1259 struct firmware_details *fdet)
1260{
1261 int i, err;
1262 const u8 ra = fabric_serdes_broadcast[dd->hfi1_id];
1263
1264 dd_dev_info(dd, "Downloading fabric firmware\n");
1265
1266
1267 load_security_variables(dd, fdet);
1268
1269 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000011);
1270
1271 udelay(1);
1272
1273 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000010);
1274
1275 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x40000000);
1276
1277 for (i = 0; i < fdet->firmware_len; i += 4) {
1278 sbus_request(dd, ra, 0x0a, WRITE_SBUS_RECEIVER,
1279 *(u32 *)&fdet->firmware_ptr[i]);
1280 }
1281
1282 sbus_request(dd, ra, 0x00, WRITE_SBUS_RECEIVER, 0x00000000);
1283
1284 sbus_request(dd, ra, 0x0b, WRITE_SBUS_RECEIVER, 0x000c0000);
1285
1286
1287 err = run_rsa(dd, "fabric serdes", fdet->signature);
1288 if (err)
1289 return err;
1290
1291
1292 sbus_request(dd, ra, 0x07, WRITE_SBUS_RECEIVER, 0x00000002);
1293
1294 sbus_request(dd, ra, 0x08, WRITE_SBUS_RECEIVER, 0x00000000);
1295
1296 return 0;
1297}
1298
1299static int load_sbus_firmware(struct hfi1_devdata *dd,
1300 struct firmware_details *fdet)
1301{
1302 int i, err;
1303 const u8 ra = SBUS_MASTER_BROADCAST;
1304
1305 dd_dev_info(dd, "Downloading SBus firmware\n");
1306
1307
1308 load_security_variables(dd, fdet);
1309
1310 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x000000c0);
1311
1312 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000240);
1313
1314 sbus_request(dd, ra, 0x03, WRITE_SBUS_RECEIVER, 0x80000000);
1315
1316 for (i = 0; i < fdet->firmware_len; i += 4) {
1317 sbus_request(dd, ra, 0x14, WRITE_SBUS_RECEIVER,
1318 *(u32 *)&fdet->firmware_ptr[i]);
1319 }
1320
1321 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000040);
1322
1323 sbus_request(dd, ra, 0x16, WRITE_SBUS_RECEIVER, 0x000c0000);
1324
1325
1326 err = run_rsa(dd, "SBus", fdet->signature);
1327 if (err)
1328 return err;
1329
1330
1331 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140);
1332
1333 return 0;
1334}
1335
1336static int load_pcie_serdes_firmware(struct hfi1_devdata *dd,
1337 struct firmware_details *fdet)
1338{
1339 int i;
1340 const u8 ra = SBUS_MASTER_BROADCAST;
1341
1342 dd_dev_info(dd, "Downloading PCIe firmware\n");
1343
1344
1345 load_security_variables(dd, fdet);
1346
1347 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000001);
1348
1349 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000d40);
1350
1351
1352
1353
1354
1355 for (i = 0; i < fdet->firmware_len; i += 4) {
1356 sbus_request(dd, ra, 0x04, WRITE_SBUS_RECEIVER,
1357 *(u32 *)&fdet->firmware_ptr[i]);
1358 }
1359
1360 sbus_request(dd, ra, 0x01, WRITE_SBUS_RECEIVER, 0x00000140);
1361
1362 sbus_request(dd, ra, 0x05, WRITE_SBUS_RECEIVER, 0x00000000);
1363
1364
1365
1366
1367
1368 return run_rsa(dd, "PCIe serdes", fdet->signature);
1369}
1370
1371
1372
1373
1374static void set_serdes_broadcast(struct hfi1_devdata *dd, u8 bg1, u8 bg2,
1375 const u8 *addrs, int count)
1376{
1377 while (--count >= 0) {
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390 sbus_request(dd, addrs[count], 0xfd, WRITE_SBUS_RECEIVER,
1391 (u32)bg1 << 4 | (u32)bg2 << 16);
1392 }
1393}
1394
1395int acquire_hw_mutex(struct hfi1_devdata *dd)
1396{
1397 unsigned long timeout;
1398 int try = 0;
1399 u8 mask = 1 << dd->hfi1_id;
1400 u8 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1401
1402 if (user == mask) {
1403 dd_dev_info(dd,
1404 "Hardware mutex already acquired, mutex mask %u\n",
1405 (u32)mask);
1406 return 0;
1407 }
1408
1409retry:
1410 timeout = msecs_to_jiffies(HM_TIMEOUT) + jiffies;
1411 while (1) {
1412 write_csr(dd, ASIC_CFG_MUTEX, mask);
1413 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1414 if (user == mask)
1415 return 0;
1416 if (time_after(jiffies, timeout))
1417 break;
1418 msleep(20);
1419 }
1420
1421
1422 dd_dev_err(dd,
1423 "Unable to acquire hardware mutex, mutex mask %u, my mask %u (%s)\n",
1424 (u32)user, (u32)mask, (try == 0) ? "retrying" : "giving up");
1425
1426 if (try == 0) {
1427
1428 write_csr(dd, ASIC_CFG_MUTEX, 0);
1429 try++;
1430 goto retry;
1431 }
1432
1433 return -EBUSY;
1434}
1435
1436void release_hw_mutex(struct hfi1_devdata *dd)
1437{
1438 u8 mask = 1 << dd->hfi1_id;
1439 u8 user = (u8)read_csr(dd, ASIC_CFG_MUTEX);
1440
1441 if (user != mask)
1442 dd_dev_warn(dd,
1443 "Unable to release hardware mutex, mutex mask %u, my mask %u\n",
1444 (u32)user, (u32)mask);
1445 else
1446 write_csr(dd, ASIC_CFG_MUTEX, 0);
1447}
1448
1449
1450static inline u64 resource_mask(u32 hfi1_id, u32 resource)
1451{
1452 return ((u64)resource) << (hfi1_id ? CR_DYN_SHIFT : 0);
1453}
1454
1455static void fail_mutex_acquire_message(struct hfi1_devdata *dd,
1456 const char *func)
1457{
1458 dd_dev_err(dd,
1459 "%s: hardware mutex stuck - suggest rebooting the machine\n",
1460 func);
1461}
1462
1463
1464
1465
1466
1467
1468static int __acquire_chip_resource(struct hfi1_devdata *dd, u32 resource)
1469{
1470 u64 scratch0, all_bits, my_bit;
1471 int ret;
1472
1473 if (resource & CR_DYN_MASK) {
1474
1475 if (dd->pcidev->device == PCI_DEVICE_ID_INTEL0 &&
1476 (resource & (CR_I2C1 | CR_I2C2))) {
1477
1478 all_bits = resource_mask(0, CR_I2C1 | CR_I2C2) |
1479 resource_mask(1, CR_I2C1 | CR_I2C2);
1480 } else {
1481 all_bits = resource_mask(0, resource) |
1482 resource_mask(1, resource);
1483 }
1484 my_bit = resource_mask(dd->hfi1_id, resource);
1485 } else {
1486
1487 all_bits = resource;
1488 my_bit = resource;
1489 }
1490
1491
1492 mutex_lock(&dd->asic_data->asic_resource_mutex);
1493
1494 ret = acquire_hw_mutex(dd);
1495 if (ret) {
1496 fail_mutex_acquire_message(dd, __func__);
1497 ret = -EIO;
1498 goto done;
1499 }
1500
1501 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1502 if (scratch0 & all_bits) {
1503 ret = -EBUSY;
1504 } else {
1505 write_csr(dd, ASIC_CFG_SCRATCH, scratch0 | my_bit);
1506
1507 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1508 }
1509
1510 release_hw_mutex(dd);
1511
1512done:
1513 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1514 return ret;
1515}
1516
1517
1518
1519
1520
1521
1522
1523
1524int acquire_chip_resource(struct hfi1_devdata *dd, u32 resource, u32 mswait)
1525{
1526 unsigned long timeout;
1527 int ret;
1528
1529 timeout = jiffies + msecs_to_jiffies(mswait);
1530 while (1) {
1531 ret = __acquire_chip_resource(dd, resource);
1532 if (ret != -EBUSY)
1533 return ret;
1534
1535 if (time_after_eq(jiffies, timeout))
1536 return -EBUSY;
1537 usleep_range(80, 120);
1538 }
1539}
1540
1541
1542
1543
1544void release_chip_resource(struct hfi1_devdata *dd, u32 resource)
1545{
1546 u64 scratch0, bit;
1547
1548
1549 if (!(resource & CR_DYN_MASK)) {
1550 dd_dev_err(dd, "%s: invalid resource 0x%x\n", __func__,
1551 resource);
1552 return;
1553 }
1554 bit = resource_mask(dd->hfi1_id, resource);
1555
1556
1557 mutex_lock(&dd->asic_data->asic_resource_mutex);
1558
1559 if (acquire_hw_mutex(dd)) {
1560 fail_mutex_acquire_message(dd, __func__);
1561 goto done;
1562 }
1563
1564 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1565 if ((scratch0 & bit) != 0) {
1566 scratch0 &= ~bit;
1567 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1568
1569 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1570 } else {
1571 dd_dev_warn(dd, "%s: id %d, resource 0x%x: bit not set\n",
1572 __func__, dd->hfi1_id, resource);
1573 }
1574
1575 release_hw_mutex(dd);
1576
1577done:
1578 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1579}
1580
1581
1582
1583
1584
1585bool check_chip_resource(struct hfi1_devdata *dd, u32 resource,
1586 const char *func)
1587{
1588 u64 scratch0, bit;
1589
1590 if (resource & CR_DYN_MASK)
1591 bit = resource_mask(dd->hfi1_id, resource);
1592 else
1593 bit = resource;
1594
1595 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1596 if ((scratch0 & bit) == 0) {
1597 if (func)
1598 dd_dev_warn(dd,
1599 "%s: id %d, resource 0x%x, not acquired!\n",
1600 func, dd->hfi1_id, resource);
1601 return false;
1602 }
1603 return true;
1604}
1605
1606static void clear_chip_resources(struct hfi1_devdata *dd, const char *func)
1607{
1608 u64 scratch0;
1609
1610
1611 mutex_lock(&dd->asic_data->asic_resource_mutex);
1612
1613 if (acquire_hw_mutex(dd)) {
1614 fail_mutex_acquire_message(dd, func);
1615 goto done;
1616 }
1617
1618
1619 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
1620 scratch0 &= ~resource_mask(dd->hfi1_id, CR_DYN_MASK);
1621 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
1622
1623 (void)read_csr(dd, ASIC_CFG_SCRATCH);
1624
1625 release_hw_mutex(dd);
1626
1627done:
1628 mutex_unlock(&dd->asic_data->asic_resource_mutex);
1629}
1630
1631void init_chip_resources(struct hfi1_devdata *dd)
1632{
1633
1634 clear_chip_resources(dd, __func__);
1635}
1636
1637void finish_chip_resources(struct hfi1_devdata *dd)
1638{
1639
1640 clear_chip_resources(dd, __func__);
1641}
1642
1643void set_sbus_fast_mode(struct hfi1_devdata *dd)
1644{
1645 write_csr(dd, ASIC_CFG_SBUS_EXECUTE,
1646 ASIC_CFG_SBUS_EXECUTE_FAST_MODE_SMASK);
1647}
1648
1649void clear_sbus_fast_mode(struct hfi1_devdata *dd)
1650{
1651 u64 reg, count = 0;
1652
1653 reg = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1654 while (SBUS_COUNTER(reg, EXECUTE) !=
1655 SBUS_COUNTER(reg, RCV_DATA_VALID)) {
1656 if (count++ >= SBUS_MAX_POLL_COUNT)
1657 break;
1658 udelay(1);
1659 reg = read_csr(dd, ASIC_STS_SBUS_COUNTERS);
1660 }
1661 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
1662}
1663
1664int load_firmware(struct hfi1_devdata *dd)
1665{
1666 int ret;
1667
1668 if (fw_fabric_serdes_load) {
1669 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
1670 if (ret)
1671 return ret;
1672
1673 set_sbus_fast_mode(dd);
1674
1675 set_serdes_broadcast(dd, all_fabric_serdes_broadcast,
1676 fabric_serdes_broadcast[dd->hfi1_id],
1677 fabric_serdes_addrs[dd->hfi1_id],
1678 NUM_FABRIC_SERDES);
1679 turn_off_spicos(dd, SPICO_FABRIC);
1680 do {
1681 ret = load_fabric_serdes_firmware(dd, &fw_fabric);
1682 } while (retry_firmware(dd, ret));
1683
1684 clear_sbus_fast_mode(dd);
1685 release_chip_resource(dd, CR_SBUS);
1686 if (ret)
1687 return ret;
1688 }
1689
1690 if (fw_8051_load) {
1691 do {
1692 ret = load_8051_firmware(dd, &fw_8051);
1693 } while (retry_firmware(dd, ret));
1694 if (ret)
1695 return ret;
1696 }
1697
1698 dump_fw_version(dd);
1699 return 0;
1700}
1701
1702int hfi1_firmware_init(struct hfi1_devdata *dd)
1703{
1704
1705 if (dd->icode != ICODE_RTL_SILICON) {
1706 fw_fabric_serdes_load = 0;
1707 fw_pcie_serdes_load = 0;
1708 fw_sbus_load = 0;
1709 }
1710
1711
1712 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
1713 fw_8051_load = 0;
1714
1715 if (!fw_8051_name) {
1716 if (dd->icode == ICODE_RTL_SILICON)
1717 fw_8051_name = DEFAULT_FW_8051_NAME_ASIC;
1718 else
1719 fw_8051_name = DEFAULT_FW_8051_NAME_FPGA;
1720 }
1721 if (!fw_fabric_serdes_name)
1722 fw_fabric_serdes_name = DEFAULT_FW_FABRIC_NAME;
1723 if (!fw_sbus_name)
1724 fw_sbus_name = DEFAULT_FW_SBUS_NAME;
1725 if (!fw_pcie_serdes_name)
1726 fw_pcie_serdes_name = DEFAULT_FW_PCIE_NAME;
1727
1728 return obtain_firmware(dd);
1729}
1730
1731
1732
1733
1734
1735
1736
1737
1738static int check_meta_version(struct hfi1_devdata *dd, u32 *system_table)
1739{
1740 u32 meta_ver, meta_ver_meta, ver_start, ver_len, mask;
1741 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1742
1743 if (!system_table)
1744 return -EINVAL;
1745
1746 meta_ver_meta =
1747 *(pcfgcache->config_tables[PLATFORM_CONFIG_SYSTEM_TABLE].table_metadata
1748 + SYSTEM_TABLE_META_VERSION);
1749
1750 mask = ((1 << METADATA_TABLE_FIELD_START_LEN_BITS) - 1);
1751 ver_start = meta_ver_meta & mask;
1752
1753 meta_ver_meta >>= METADATA_TABLE_FIELD_LEN_SHIFT;
1754
1755 mask = ((1 << METADATA_TABLE_FIELD_LEN_LEN_BITS) - 1);
1756 ver_len = meta_ver_meta & mask;
1757
1758 ver_start /= 8;
1759 meta_ver = *((u8 *)system_table + ver_start) & ((1 << ver_len) - 1);
1760
1761 if (meta_ver < 4) {
1762 dd_dev_info(
1763 dd, "%s:Please update platform config\n", __func__);
1764 return -EINVAL;
1765 }
1766 return 0;
1767}
1768
1769int parse_platform_config(struct hfi1_devdata *dd)
1770{
1771 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
1772 struct hfi1_pportdata *ppd = dd->pport;
1773 u32 *ptr = NULL;
1774 u32 header1 = 0, header2 = 0, magic_num = 0, crc = 0, file_length = 0;
1775 u32 record_idx = 0, table_type = 0, table_length_dwords = 0;
1776 int ret = -EINVAL;
1777
1778
1779
1780
1781
1782
1783
1784 if (ppd->config_from_scratch)
1785 return 0;
1786
1787 if (!dd->platform_config.data) {
1788 dd_dev_err(dd, "%s: Missing config file\n", __func__);
1789 goto bail;
1790 }
1791 ptr = (u32 *)dd->platform_config.data;
1792
1793 magic_num = *ptr;
1794 ptr++;
1795 if (magic_num != PLATFORM_CONFIG_MAGIC_NUM) {
1796 dd_dev_err(dd, "%s: Bad config file\n", __func__);
1797 goto bail;
1798 }
1799
1800
1801 file_length = (*ptr) * 4;
1802
1803
1804
1805
1806
1807
1808 if (file_length > MAX_PLATFORM_CONFIG_FILE_SIZE) {
1809 dd_dev_info(dd,
1810 "%s:File length out of bounds, using alternative format\n",
1811 __func__);
1812 file_length = PLATFORM_CONFIG_FORMAT_4_FILE_SIZE;
1813 } else {
1814 ptr++;
1815 }
1816
1817 if (file_length > dd->platform_config.size) {
1818 dd_dev_info(dd, "%s:File claims to be larger than read size\n",
1819 __func__);
1820 goto bail;
1821 } else if (file_length < dd->platform_config.size) {
1822 dd_dev_info(dd,
1823 "%s:File claims to be smaller than read size, continuing\n",
1824 __func__);
1825 }
1826
1827
1828
1829
1830
1831
1832
1833 while (ptr < (u32 *)(dd->platform_config.data + file_length)) {
1834 header1 = *ptr;
1835 header2 = *(ptr + 1);
1836 if (header1 != ~header2) {
1837 dd_dev_err(dd, "%s: Failed validation at offset %ld\n",
1838 __func__, (ptr - (u32 *)
1839 dd->platform_config.data));
1840 goto bail;
1841 }
1842
1843 record_idx = *ptr &
1844 ((1 << PLATFORM_CONFIG_HEADER_RECORD_IDX_LEN_BITS) - 1);
1845
1846 table_length_dwords = (*ptr >>
1847 PLATFORM_CONFIG_HEADER_TABLE_LENGTH_SHIFT) &
1848 ((1 << PLATFORM_CONFIG_HEADER_TABLE_LENGTH_LEN_BITS) - 1);
1849
1850 table_type = (*ptr >> PLATFORM_CONFIG_HEADER_TABLE_TYPE_SHIFT) &
1851 ((1 << PLATFORM_CONFIG_HEADER_TABLE_TYPE_LEN_BITS) - 1);
1852
1853
1854 ptr += 2;
1855
1856 if (record_idx) {
1857
1858 switch (table_type) {
1859 case PLATFORM_CONFIG_SYSTEM_TABLE:
1860 pcfgcache->config_tables[table_type].num_table =
1861 1;
1862 ret = check_meta_version(dd, ptr);
1863 if (ret)
1864 goto bail;
1865 break;
1866 case PLATFORM_CONFIG_PORT_TABLE:
1867 pcfgcache->config_tables[table_type].num_table =
1868 2;
1869 break;
1870 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1871
1872 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1873
1874 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1875
1876 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1877 pcfgcache->config_tables[table_type].num_table =
1878 table_length_dwords;
1879 break;
1880 default:
1881 dd_dev_err(dd,
1882 "%s: Unknown data table %d, offset %ld\n",
1883 __func__, table_type,
1884 (ptr - (u32 *)
1885 dd->platform_config.data));
1886 goto bail;
1887 }
1888 pcfgcache->config_tables[table_type].table = ptr;
1889 } else {
1890
1891 switch (table_type) {
1892 case PLATFORM_CONFIG_SYSTEM_TABLE:
1893
1894 case PLATFORM_CONFIG_PORT_TABLE:
1895
1896 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1897
1898 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1899
1900 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
1901
1902 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
1903 break;
1904 default:
1905 dd_dev_err(dd,
1906 "%s: Unknown meta table %d, offset %ld\n",
1907 __func__, table_type,
1908 (ptr -
1909 (u32 *)dd->platform_config.data));
1910 goto bail;
1911 }
1912 pcfgcache->config_tables[table_type].table_metadata =
1913 ptr;
1914 }
1915
1916
1917 crc = crc32_le(~(u32)0, (unsigned char const *)ptr,
1918 (table_length_dwords * 4));
1919 crc ^= ~(u32)0;
1920
1921
1922 ptr += table_length_dwords;
1923 if (crc != *ptr) {
1924 dd_dev_err(dd, "%s: Failed CRC check at offset %ld\n",
1925 __func__, (ptr -
1926 (u32 *)dd->platform_config.data));
1927 goto bail;
1928 }
1929
1930 ptr++;
1931 }
1932
1933 pcfgcache->cache_valid = 1;
1934 return 0;
1935bail:
1936 memset(pcfgcache, 0, sizeof(struct platform_config_cache));
1937 return ret;
1938}
1939
1940static void get_integrated_platform_config_field(
1941 struct hfi1_devdata *dd,
1942 enum platform_config_table_type_encoding table_type,
1943 int field_index, u32 *data)
1944{
1945 struct hfi1_pportdata *ppd = dd->pport;
1946 u8 *cache = ppd->qsfp_info.cache;
1947 u32 tx_preset = 0;
1948
1949 switch (table_type) {
1950 case PLATFORM_CONFIG_SYSTEM_TABLE:
1951 if (field_index == SYSTEM_TABLE_QSFP_POWER_CLASS_MAX)
1952 *data = ppd->max_power_class;
1953 else if (field_index == SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G)
1954 *data = ppd->default_atten;
1955 break;
1956 case PLATFORM_CONFIG_PORT_TABLE:
1957 if (field_index == PORT_TABLE_PORT_TYPE)
1958 *data = ppd->port_type;
1959 else if (field_index == PORT_TABLE_LOCAL_ATTEN_25G)
1960 *data = ppd->local_atten;
1961 else if (field_index == PORT_TABLE_REMOTE_ATTEN_25G)
1962 *data = ppd->remote_atten;
1963 break;
1964 case PLATFORM_CONFIG_RX_PRESET_TABLE:
1965 if (field_index == RX_PRESET_TABLE_QSFP_RX_CDR_APPLY)
1966 *data = (ppd->rx_preset & QSFP_RX_CDR_APPLY_SMASK) >>
1967 QSFP_RX_CDR_APPLY_SHIFT;
1968 else if (field_index == RX_PRESET_TABLE_QSFP_RX_EMP_APPLY)
1969 *data = (ppd->rx_preset & QSFP_RX_EMP_APPLY_SMASK) >>
1970 QSFP_RX_EMP_APPLY_SHIFT;
1971 else if (field_index == RX_PRESET_TABLE_QSFP_RX_AMP_APPLY)
1972 *data = (ppd->rx_preset & QSFP_RX_AMP_APPLY_SMASK) >>
1973 QSFP_RX_AMP_APPLY_SHIFT;
1974 else if (field_index == RX_PRESET_TABLE_QSFP_RX_CDR)
1975 *data = (ppd->rx_preset & QSFP_RX_CDR_SMASK) >>
1976 QSFP_RX_CDR_SHIFT;
1977 else if (field_index == RX_PRESET_TABLE_QSFP_RX_EMP)
1978 *data = (ppd->rx_preset & QSFP_RX_EMP_SMASK) >>
1979 QSFP_RX_EMP_SHIFT;
1980 else if (field_index == RX_PRESET_TABLE_QSFP_RX_AMP)
1981 *data = (ppd->rx_preset & QSFP_RX_AMP_SMASK) >>
1982 QSFP_RX_AMP_SHIFT;
1983 break;
1984 case PLATFORM_CONFIG_TX_PRESET_TABLE:
1985 if (cache[QSFP_EQ_INFO_OFFS] & 0x4)
1986 tx_preset = ppd->tx_preset_eq;
1987 else
1988 tx_preset = ppd->tx_preset_noeq;
1989 if (field_index == TX_PRESET_TABLE_PRECUR)
1990 *data = (tx_preset & TX_PRECUR_SMASK) >>
1991 TX_PRECUR_SHIFT;
1992 else if (field_index == TX_PRESET_TABLE_ATTN)
1993 *data = (tx_preset & TX_ATTN_SMASK) >>
1994 TX_ATTN_SHIFT;
1995 else if (field_index == TX_PRESET_TABLE_POSTCUR)
1996 *data = (tx_preset & TX_POSTCUR_SMASK) >>
1997 TX_POSTCUR_SHIFT;
1998 else if (field_index == TX_PRESET_TABLE_QSFP_TX_CDR_APPLY)
1999 *data = (tx_preset & QSFP_TX_CDR_APPLY_SMASK) >>
2000 QSFP_TX_CDR_APPLY_SHIFT;
2001 else if (field_index == TX_PRESET_TABLE_QSFP_TX_EQ_APPLY)
2002 *data = (tx_preset & QSFP_TX_EQ_APPLY_SMASK) >>
2003 QSFP_TX_EQ_APPLY_SHIFT;
2004 else if (field_index == TX_PRESET_TABLE_QSFP_TX_CDR)
2005 *data = (tx_preset & QSFP_TX_CDR_SMASK) >>
2006 QSFP_TX_CDR_SHIFT;
2007 else if (field_index == TX_PRESET_TABLE_QSFP_TX_EQ)
2008 *data = (tx_preset & QSFP_TX_EQ_SMASK) >>
2009 QSFP_TX_EQ_SHIFT;
2010 break;
2011 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
2012 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
2013 default:
2014 break;
2015 }
2016}
2017
2018static int get_platform_fw_field_metadata(struct hfi1_devdata *dd, int table,
2019 int field, u32 *field_len_bits,
2020 u32 *field_start_bits)
2021{
2022 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
2023 u32 *src_ptr = NULL;
2024
2025 if (!pcfgcache->cache_valid)
2026 return -EINVAL;
2027
2028 switch (table) {
2029 case PLATFORM_CONFIG_SYSTEM_TABLE:
2030
2031 case PLATFORM_CONFIG_PORT_TABLE:
2032
2033 case PLATFORM_CONFIG_RX_PRESET_TABLE:
2034
2035 case PLATFORM_CONFIG_TX_PRESET_TABLE:
2036
2037 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
2038
2039 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
2040 if (field && field < platform_config_table_limits[table])
2041 src_ptr =
2042 pcfgcache->config_tables[table].table_metadata + field;
2043 break;
2044 default:
2045 dd_dev_info(dd, "%s: Unknown table\n", __func__);
2046 break;
2047 }
2048
2049 if (!src_ptr)
2050 return -EINVAL;
2051
2052 if (field_start_bits)
2053 *field_start_bits = *src_ptr &
2054 ((1 << METADATA_TABLE_FIELD_START_LEN_BITS) - 1);
2055
2056 if (field_len_bits)
2057 *field_len_bits = (*src_ptr >> METADATA_TABLE_FIELD_LEN_SHIFT)
2058 & ((1 << METADATA_TABLE_FIELD_LEN_LEN_BITS) - 1);
2059
2060 return 0;
2061}
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079int get_platform_config_field(struct hfi1_devdata *dd,
2080 enum platform_config_table_type_encoding
2081 table_type, int table_index, int field_index,
2082 u32 *data, u32 len)
2083{
2084 int ret = 0, wlen = 0, seek = 0;
2085 u32 field_len_bits = 0, field_start_bits = 0, *src_ptr = NULL;
2086 struct platform_config_cache *pcfgcache = &dd->pcfg_cache;
2087 struct hfi1_pportdata *ppd = dd->pport;
2088
2089 if (data)
2090 memset(data, 0, len);
2091 else
2092 return -EINVAL;
2093
2094 if (ppd->config_from_scratch) {
2095
2096
2097
2098 get_integrated_platform_config_field(dd, table_type,
2099 field_index, data);
2100 return 0;
2101 }
2102
2103 ret = get_platform_fw_field_metadata(dd, table_type, field_index,
2104 &field_len_bits,
2105 &field_start_bits);
2106 if (ret)
2107 return -EINVAL;
2108
2109
2110 len *= 8;
2111
2112
2113 switch (table_type) {
2114 case PLATFORM_CONFIG_SYSTEM_TABLE:
2115 src_ptr = pcfgcache->config_tables[table_type].table;
2116
2117 if (field_index != SYSTEM_TABLE_QSFP_POWER_CLASS_MAX) {
2118 if (len < field_len_bits)
2119 return -EINVAL;
2120
2121 seek = field_start_bits / 8;
2122 wlen = field_len_bits / 8;
2123
2124 src_ptr = (u32 *)((u8 *)src_ptr + seek);
2125
2126
2127
2128
2129
2130 memcpy(data, src_ptr, wlen);
2131 return 0;
2132 }
2133 break;
2134 case PLATFORM_CONFIG_PORT_TABLE:
2135
2136 src_ptr = dd->hfi1_id ?
2137 pcfgcache->config_tables[table_type].table + 4 :
2138 pcfgcache->config_tables[table_type].table;
2139 break;
2140 case PLATFORM_CONFIG_RX_PRESET_TABLE:
2141
2142 case PLATFORM_CONFIG_TX_PRESET_TABLE:
2143
2144 case PLATFORM_CONFIG_QSFP_ATTEN_TABLE:
2145
2146 case PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE:
2147 src_ptr = pcfgcache->config_tables[table_type].table;
2148
2149 if (table_index <
2150 pcfgcache->config_tables[table_type].num_table)
2151 src_ptr += table_index;
2152 else
2153 src_ptr = NULL;
2154 break;
2155 default:
2156 dd_dev_info(dd, "%s: Unknown table\n", __func__);
2157 break;
2158 }
2159
2160 if (!src_ptr || len < field_len_bits)
2161 return -EINVAL;
2162
2163 src_ptr += (field_start_bits / 32);
2164 *data = (*src_ptr >> (field_start_bits % 32)) &
2165 ((1 << field_len_bits) - 1);
2166
2167 return 0;
2168}
2169
2170
2171
2172
2173
2174
2175
2176int load_pcie_firmware(struct hfi1_devdata *dd)
2177{
2178 int ret = 0;
2179
2180
2181 set_sbus_fast_mode(dd);
2182
2183 if (fw_sbus_load) {
2184 turn_off_spicos(dd, SPICO_SBUS);
2185 do {
2186 ret = load_sbus_firmware(dd, &fw_sbus);
2187 } while (retry_firmware(dd, ret));
2188 if (ret)
2189 goto done;
2190 }
2191
2192 if (fw_pcie_serdes_load) {
2193 dd_dev_info(dd, "Setting PCIe SerDes broadcast\n");
2194 set_serdes_broadcast(dd, all_pcie_serdes_broadcast,
2195 pcie_serdes_broadcast[dd->hfi1_id],
2196 pcie_serdes_addrs[dd->hfi1_id],
2197 NUM_PCIE_SERDES);
2198 do {
2199 ret = load_pcie_serdes_firmware(dd, &fw_pcie);
2200 } while (retry_firmware(dd, ret));
2201 if (ret)
2202 goto done;
2203 }
2204
2205done:
2206 clear_sbus_fast_mode(dd);
2207
2208 return ret;
2209}
2210
2211
2212
2213
2214void read_guid(struct hfi1_devdata *dd)
2215{
2216
2217 write_csr(dd, CCE_DC_CTRL, 0);
2218 (void)read_csr(dd, CCE_DC_CTRL);
2219
2220 dd->base_guid = read_csr(dd, DC_DC8051_CFG_LOCAL_GUID);
2221 dd_dev_info(dd, "GUID %llx",
2222 (unsigned long long)dd->base_guid);
2223}
2224
2225
2226static void dump_fw_version(struct hfi1_devdata *dd)
2227{
2228 u32 pcie_vers[NUM_PCIE_SERDES];
2229 u32 fabric_vers[NUM_FABRIC_SERDES];
2230 u32 sbus_vers;
2231 int i;
2232 int all_same;
2233 int ret;
2234 u8 rcv_addr;
2235
2236 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
2237 if (ret) {
2238 dd_dev_err(dd, "Unable to acquire SBus to read firmware versions\n");
2239 return;
2240 }
2241
2242
2243 set_sbus_fast_mode(dd);
2244
2245
2246 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x02, WRITE_SBUS_RECEIVER, 0);
2247 sbus_request(dd, SBUS_MASTER_BROADCAST, 0x07, WRITE_SBUS_RECEIVER, 0x1);
2248
2249 usleep_range(10000, 11000);
2250 sbus_vers = sbus_read(dd, SBUS_MASTER_BROADCAST, 0x08, 0x1);
2251 dd_dev_info(dd, "SBus Master firmware version 0x%08x\n", sbus_vers);
2252
2253
2254 all_same = 1;
2255 pcie_vers[0] = 0;
2256 for (i = 0; i < NUM_PCIE_SERDES; i++) {
2257 rcv_addr = pcie_serdes_addrs[dd->hfi1_id][i];
2258 sbus_request(dd, rcv_addr, 0x03, WRITE_SBUS_RECEIVER, 0);
2259
2260 usleep_range(10000, 11000);
2261 pcie_vers[i] = sbus_read(dd, rcv_addr, 0x04, 0x0);
2262 if (i > 0 && pcie_vers[0] != pcie_vers[i])
2263 all_same = 0;
2264 }
2265
2266 if (all_same) {
2267 dd_dev_info(dd, "PCIe SerDes firmware version 0x%x\n",
2268 pcie_vers[0]);
2269 } else {
2270 dd_dev_warn(dd, "PCIe SerDes do not have the same firmware version\n");
2271 for (i = 0; i < NUM_PCIE_SERDES; i++) {
2272 dd_dev_info(dd,
2273 "PCIe SerDes lane %d firmware version 0x%x\n",
2274 i, pcie_vers[i]);
2275 }
2276 }
2277
2278
2279 all_same = 1;
2280 fabric_vers[0] = 0;
2281 for (i = 0; i < NUM_FABRIC_SERDES; i++) {
2282 rcv_addr = fabric_serdes_addrs[dd->hfi1_id][i];
2283 sbus_request(dd, rcv_addr, 0x03, WRITE_SBUS_RECEIVER, 0);
2284
2285 usleep_range(10000, 11000);
2286 fabric_vers[i] = sbus_read(dd, rcv_addr, 0x04, 0x0);
2287 if (i > 0 && fabric_vers[0] != fabric_vers[i])
2288 all_same = 0;
2289 }
2290
2291 if (all_same) {
2292 dd_dev_info(dd, "Fabric SerDes firmware version 0x%x\n",
2293 fabric_vers[0]);
2294 } else {
2295 dd_dev_warn(dd, "Fabric SerDes do not have the same firmware version\n");
2296 for (i = 0; i < NUM_FABRIC_SERDES; i++) {
2297 dd_dev_info(dd,
2298 "Fabric SerDes lane %d firmware version 0x%x\n",
2299 i, fabric_vers[i]);
2300 }
2301 }
2302
2303 clear_sbus_fast_mode(dd);
2304 release_chip_resource(dd, CR_SBUS);
2305}
2306