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#include <linux/init.h>
36#include <linux/delay.h>
37#include "cxgb4.h"
38#include "t4_regs.h"
39#include "t4_values.h"
40#include "t4fw_api.h"
41#include "t4fw_version.h"
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
59 int polarity, int attempts, int delay, u32 *valp)
60{
61 while (1) {
62 u32 val = t4_read_reg(adapter, reg);
63
64 if (!!(val & mask) == polarity) {
65 if (valp)
66 *valp = val;
67 return 0;
68 }
69 if (--attempts == 0)
70 return -EAGAIN;
71 if (delay)
72 udelay(delay);
73 }
74}
75
76static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
77 int polarity, int attempts, int delay)
78{
79 return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
80 delay, NULL);
81}
82
83
84
85
86
87
88
89
90
91
92
93void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
94 u32 val)
95{
96 u32 v = t4_read_reg(adapter, addr) & ~mask;
97
98 t4_write_reg(adapter, addr, v | val);
99 (void) t4_read_reg(adapter, addr);
100}
101
102
103
104
105
106
107
108
109
110
111
112
113
114void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
115 unsigned int data_reg, u32 *vals,
116 unsigned int nregs, unsigned int start_idx)
117{
118 while (nregs--) {
119 t4_write_reg(adap, addr_reg, start_idx);
120 *vals++ = t4_read_reg(adap, data_reg);
121 start_idx++;
122 }
123}
124
125
126
127
128
129
130
131
132
133
134
135
136
137void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
138 unsigned int data_reg, const u32 *vals,
139 unsigned int nregs, unsigned int start_idx)
140{
141 while (nregs--) {
142 t4_write_reg(adap, addr_reg, start_idx++);
143 t4_write_reg(adap, data_reg, *vals++);
144 }
145}
146
147
148
149
150
151
152
153void t4_hw_pci_read_cfg4(struct adapter *adap, int reg, u32 *val)
154{
155 u32 req = FUNCTION_V(adap->pf) | REGISTER_V(reg);
156
157 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
158 req |= ENABLE_F;
159 else
160 req |= T6_ENABLE_F;
161
162 if (is_t4(adap->params.chip))
163 req |= LOCALCFG_F;
164
165 t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, req);
166 *val = t4_read_reg(adap, PCIE_CFG_SPACE_DATA_A);
167
168
169
170
171
172
173 t4_write_reg(adap, PCIE_CFG_SPACE_REQ_A, 0);
174}
175
176
177
178
179
180
181
182
183
184static void t4_report_fw_error(struct adapter *adap)
185{
186 static const char *const reason[] = {
187 "Crash",
188 "During Device Preparation",
189 "During Device Configuration",
190 "During Device Initialization",
191 "Unexpected Event",
192 "Insufficient Airflow",
193 "Device Shutdown",
194 "Reserved",
195 };
196 u32 pcie_fw;
197
198 pcie_fw = t4_read_reg(adap, PCIE_FW_A);
199 if (pcie_fw & PCIE_FW_ERR_F)
200 dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
201 reason[PCIE_FW_EVAL_G(pcie_fw)]);
202}
203
204
205
206
207static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
208 u32 mbox_addr)
209{
210 for ( ; nflit; nflit--, mbox_addr += 8)
211 *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
212}
213
214
215
216
217static void fw_asrt(struct adapter *adap, u32 mbox_addr)
218{
219 struct fw_debug_cmd asrt;
220
221 get_mbox_rpl(adap, (__be64 *)&asrt, sizeof(asrt) / 8, mbox_addr);
222 dev_alert(adap->pdev_dev,
223 "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
224 asrt.u.assert.filename_0_7, be32_to_cpu(asrt.u.assert.line),
225 be32_to_cpu(asrt.u.assert.x), be32_to_cpu(asrt.u.assert.y));
226}
227
228
229
230
231
232
233
234
235
236static void t4_record_mbox(struct adapter *adapter,
237 const __be64 *cmd, unsigned int size,
238 int access, int execute)
239{
240 struct mbox_cmd_log *log = adapter->mbox_log;
241 struct mbox_cmd *entry;
242 int i;
243
244 entry = mbox_cmd_log_entry(log, log->cursor++);
245 if (log->cursor == log->size)
246 log->cursor = 0;
247
248 for (i = 0; i < size / 8; i++)
249 entry->cmd[i] = be64_to_cpu(cmd[i]);
250 while (i < MBOX_LEN / 8)
251 entry->cmd[i++] = 0;
252 entry->timestamp = jiffies;
253 entry->seqno = log->seqno++;
254 entry->access = access;
255 entry->execute = execute;
256}
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,
282 int size, void *rpl, bool sleep_ok, int timeout)
283{
284 static const int delay[] = {
285 1, 1, 3, 5, 10, 10, 20, 50, 100, 200
286 };
287
288 struct mbox_list entry;
289 u16 access = 0;
290 u16 execute = 0;
291 u32 v;
292 u64 res;
293 int i, ms, delay_idx, ret;
294 const __be64 *p = cmd;
295 u32 data_reg = PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
296 u32 ctl_reg = PF_REG(mbox, CIM_PF_MAILBOX_CTRL_A);
297 __be64 cmd_rpl[MBOX_LEN / 8];
298 u32 pcie_fw;
299
300 if ((size & 15) || size > MBOX_LEN)
301 return -EINVAL;
302
303
304
305
306
307 if (adap->pdev->error_state != pci_channel_io_normal)
308 return -EIO;
309
310
311 if (timeout < 0) {
312 sleep_ok = false;
313 timeout = -timeout;
314 }
315
316
317
318
319
320
321 spin_lock_bh(&adap->mbox_lock);
322 list_add_tail(&entry.list, &adap->mlist.list);
323 spin_unlock_bh(&adap->mbox_lock);
324
325 delay_idx = 0;
326 ms = delay[0];
327
328 for (i = 0; ; i += ms) {
329
330
331
332
333
334 pcie_fw = t4_read_reg(adap, PCIE_FW_A);
335 if (i > FW_CMD_MAX_TIMEOUT || (pcie_fw & PCIE_FW_ERR_F)) {
336 spin_lock_bh(&adap->mbox_lock);
337 list_del(&entry.list);
338 spin_unlock_bh(&adap->mbox_lock);
339 ret = (pcie_fw & PCIE_FW_ERR_F) ? -ENXIO : -EBUSY;
340 t4_record_mbox(adap, cmd, size, access, ret);
341 return ret;
342 }
343
344
345
346
347 if (list_first_entry(&adap->mlist.list, struct mbox_list,
348 list) == &entry)
349 break;
350
351
352 if (sleep_ok) {
353 ms = delay[delay_idx];
354 if (delay_idx < ARRAY_SIZE(delay) - 1)
355 delay_idx++;
356 msleep(ms);
357 } else {
358 mdelay(ms);
359 }
360 }
361
362
363
364
365 v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
366 for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
367 v = MBOWNER_G(t4_read_reg(adap, ctl_reg));
368 if (v != MBOX_OWNER_DRV) {
369 spin_lock_bh(&adap->mbox_lock);
370 list_del(&entry.list);
371 spin_unlock_bh(&adap->mbox_lock);
372 ret = (v == MBOX_OWNER_FW) ? -EBUSY : -ETIMEDOUT;
373 t4_record_mbox(adap, cmd, size, access, ret);
374 return ret;
375 }
376
377
378 t4_record_mbox(adap, cmd, size, access, 0);
379 for (i = 0; i < size; i += 8)
380 t4_write_reg64(adap, data_reg + i, be64_to_cpu(*p++));
381
382 t4_write_reg(adap, ctl_reg, MBMSGVALID_F | MBOWNER_V(MBOX_OWNER_FW));
383 t4_read_reg(adap, ctl_reg);
384
385 delay_idx = 0;
386 ms = delay[0];
387
388 for (i = 0;
389 !((pcie_fw = t4_read_reg(adap, PCIE_FW_A)) & PCIE_FW_ERR_F) &&
390 i < timeout;
391 i += ms) {
392 if (sleep_ok) {
393 ms = delay[delay_idx];
394 if (delay_idx < ARRAY_SIZE(delay) - 1)
395 delay_idx++;
396 msleep(ms);
397 } else
398 mdelay(ms);
399
400 v = t4_read_reg(adap, ctl_reg);
401 if (MBOWNER_G(v) == MBOX_OWNER_DRV) {
402 if (!(v & MBMSGVALID_F)) {
403 t4_write_reg(adap, ctl_reg, 0);
404 continue;
405 }
406
407 get_mbox_rpl(adap, cmd_rpl, MBOX_LEN / 8, data_reg);
408 res = be64_to_cpu(cmd_rpl[0]);
409
410 if (FW_CMD_OP_G(res >> 32) == FW_DEBUG_CMD) {
411 fw_asrt(adap, data_reg);
412 res = FW_CMD_RETVAL_V(EIO);
413 } else if (rpl) {
414 memcpy(rpl, cmd_rpl, size);
415 }
416
417 t4_write_reg(adap, ctl_reg, 0);
418
419 execute = i + ms;
420 t4_record_mbox(adap, cmd_rpl,
421 MBOX_LEN, access, execute);
422 spin_lock_bh(&adap->mbox_lock);
423 list_del(&entry.list);
424 spin_unlock_bh(&adap->mbox_lock);
425 return -FW_CMD_RETVAL_G((int)res);
426 }
427 }
428
429 ret = (pcie_fw & PCIE_FW_ERR_F) ? -ENXIO : -ETIMEDOUT;
430 t4_record_mbox(adap, cmd, size, access, ret);
431 dev_err(adap->pdev_dev, "command %#x in mailbox %d timed out\n",
432 *(const u8 *)cmd, mbox);
433 t4_report_fw_error(adap);
434 spin_lock_bh(&adap->mbox_lock);
435 list_del(&entry.list);
436 spin_unlock_bh(&adap->mbox_lock);
437 t4_fatal_err(adap);
438 return ret;
439}
440
441int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
442 void *rpl, bool sleep_ok)
443{
444 return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl, sleep_ok,
445 FW_CMD_MAX_TIMEOUT);
446}
447
448static int t4_edc_err_read(struct adapter *adap, int idx)
449{
450 u32 edc_ecc_err_addr_reg;
451 u32 rdata_reg;
452
453 if (is_t4(adap->params.chip)) {
454 CH_WARN(adap, "%s: T4 NOT supported.\n", __func__);
455 return 0;
456 }
457 if (idx != 0 && idx != 1) {
458 CH_WARN(adap, "%s: idx %d NOT supported.\n", __func__, idx);
459 return 0;
460 }
461
462 edc_ecc_err_addr_reg = EDC_T5_REG(EDC_H_ECC_ERR_ADDR_A, idx);
463 rdata_reg = EDC_T5_REG(EDC_H_BIST_STATUS_RDATA_A, idx);
464
465 CH_WARN(adap,
466 "edc%d err addr 0x%x: 0x%x.\n",
467 idx, edc_ecc_err_addr_reg,
468 t4_read_reg(adap, edc_ecc_err_addr_reg));
469 CH_WARN(adap,
470 "bist: 0x%x, status %llx %llx %llx %llx %llx %llx %llx %llx %llx.\n",
471 rdata_reg,
472 (unsigned long long)t4_read_reg64(adap, rdata_reg),
473 (unsigned long long)t4_read_reg64(adap, rdata_reg + 8),
474 (unsigned long long)t4_read_reg64(adap, rdata_reg + 16),
475 (unsigned long long)t4_read_reg64(adap, rdata_reg + 24),
476 (unsigned long long)t4_read_reg64(adap, rdata_reg + 32),
477 (unsigned long long)t4_read_reg64(adap, rdata_reg + 40),
478 (unsigned long long)t4_read_reg64(adap, rdata_reg + 48),
479 (unsigned long long)t4_read_reg64(adap, rdata_reg + 56),
480 (unsigned long long)t4_read_reg64(adap, rdata_reg + 64));
481
482 return 0;
483}
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr,
503 u32 len, void *hbuf, int dir)
504{
505 u32 pos, offset, resid, memoffset;
506 u32 edc_size, mc_size, win_pf, mem_reg, mem_aperture, mem_base;
507 u32 *buf;
508
509
510
511 if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
512 return -EINVAL;
513 buf = (u32 *)hbuf;
514
515
516
517
518
519
520 resid = len & 0x3;
521 len -= resid;
522
523
524
525
526
527
528
529 edc_size = EDRAM0_SIZE_G(t4_read_reg(adap, MA_EDRAM0_BAR_A));
530 if (mtype != MEM_MC1)
531 memoffset = (mtype * (edc_size * 1024 * 1024));
532 else {
533 mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap,
534 MA_EXT_MEMORY0_BAR_A));
535 memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
536 }
537
538
539 addr = addr + memoffset;
540
541
542
543
544
545
546
547
548
549 mem_reg = t4_read_reg(adap,
550 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A,
551 win));
552 mem_aperture = 1 << (WINDOW_G(mem_reg) + WINDOW_SHIFT_X);
553 mem_base = PCIEOFST_G(mem_reg) << PCIEOFST_SHIFT_X;
554 if (is_t4(adap->params.chip))
555 mem_base -= adap->t4_bar0;
556 win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
557
558
559
560
561 pos = addr & ~(mem_aperture-1);
562 offset = addr - pos;
563
564
565
566
567
568 t4_write_reg(adap,
569 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win),
570 pos | win_pf);
571 t4_read_reg(adap,
572 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, win));
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608 while (len > 0) {
609 if (dir == T4_MEMORY_READ)
610 *buf++ = le32_to_cpu((__force __le32)t4_read_reg(adap,
611 mem_base + offset));
612 else
613 t4_write_reg(adap, mem_base + offset,
614 (__force u32)cpu_to_le32(*buf++));
615 offset += sizeof(__be32);
616 len -= sizeof(__be32);
617
618
619
620
621
622
623
624 if (offset == mem_aperture) {
625 pos += mem_aperture;
626 offset = 0;
627 t4_write_reg(adap,
628 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
629 win), pos | win_pf);
630 t4_read_reg(adap,
631 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A,
632 win));
633 }
634 }
635
636
637
638
639
640
641 if (resid) {
642 union {
643 u32 word;
644 char byte[4];
645 } last;
646 unsigned char *bp;
647 int i;
648
649 if (dir == T4_MEMORY_READ) {
650 last.word = le32_to_cpu(
651 (__force __le32)t4_read_reg(adap,
652 mem_base + offset));
653 for (bp = (unsigned char *)buf, i = resid; i < 4; i++)
654 bp[i] = last.byte[i];
655 } else {
656 last.word = *buf;
657 for (i = resid; i < 4; i++)
658 last.byte[i] = 0;
659 t4_write_reg(adap, mem_base + offset,
660 (__force u32)cpu_to_le32(last.word));
661 }
662 }
663
664 return 0;
665}
666
667
668
669
670
671
672u32 t4_read_pcie_cfg4(struct adapter *adap, int reg)
673{
674 u32 val, ldst_addrspace;
675
676
677
678
679 struct fw_ldst_cmd ldst_cmd;
680 int ret;
681
682 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
683 ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FUNC_PCIE);
684 ldst_cmd.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
685 FW_CMD_REQUEST_F |
686 FW_CMD_READ_F |
687 ldst_addrspace);
688 ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
689 ldst_cmd.u.pcie.select_naccess = FW_LDST_CMD_NACCESS_V(1);
690 ldst_cmd.u.pcie.ctrl_to_fn =
691 (FW_LDST_CMD_LC_F | FW_LDST_CMD_FN_V(adap->pf));
692 ldst_cmd.u.pcie.r = reg;
693
694
695
696
697 ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, sizeof(ldst_cmd),
698 &ldst_cmd);
699 if (ret == 0)
700 val = be32_to_cpu(ldst_cmd.u.pcie.data[0]);
701 else
702
703
704
705 t4_hw_pci_read_cfg4(adap, reg, &val);
706 return val;
707}
708
709
710
711
712
713static u32 t4_get_window(struct adapter *adap, u32 pci_base, u64 pci_mask,
714 u32 memwin_base)
715{
716 u32 ret;
717
718 if (is_t4(adap->params.chip)) {
719 u32 bar0;
720
721
722
723
724
725
726
727
728
729
730 bar0 = t4_read_pcie_cfg4(adap, pci_base);
731 bar0 &= pci_mask;
732 adap->t4_bar0 = bar0;
733
734 ret = bar0 + memwin_base;
735 } else {
736
737 ret = memwin_base;
738 }
739 return ret;
740}
741
742
743u32 t4_get_util_window(struct adapter *adap)
744{
745 return t4_get_window(adap, PCI_BASE_ADDRESS_0,
746 PCI_BASE_ADDRESS_MEM_MASK, MEMWIN0_BASE);
747}
748
749
750
751
752
753void t4_setup_memwin(struct adapter *adap, u32 memwin_base, u32 window)
754{
755 t4_write_reg(adap,
756 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window),
757 memwin_base | BIR_V(0) |
758 WINDOW_V(ilog2(MEMWIN0_APERTURE) - WINDOW_SHIFT_X));
759 t4_read_reg(adap,
760 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, window));
761}
762
763
764
765
766
767
768
769unsigned int t4_get_regs_len(struct adapter *adapter)
770{
771 unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
772
773 switch (chip_version) {
774 case CHELSIO_T4:
775 return T4_REGMAP_SIZE;
776
777 case CHELSIO_T5:
778 case CHELSIO_T6:
779 return T5_REGMAP_SIZE;
780 }
781
782 dev_err(adapter->pdev_dev,
783 "Unsupported chip version %d\n", chip_version);
784 return 0;
785}
786
787
788
789
790
791
792
793
794
795
796
797void t4_get_regs(struct adapter *adap, void *buf, size_t buf_size)
798{
799 static const unsigned int t4_reg_ranges[] = {
800 0x1008, 0x1108,
801 0x1180, 0x1184,
802 0x1190, 0x1194,
803 0x11a0, 0x11a4,
804 0x11b0, 0x11b4,
805 0x11fc, 0x123c,
806 0x1300, 0x173c,
807 0x1800, 0x18fc,
808 0x3000, 0x30d8,
809 0x30e0, 0x30e4,
810 0x30ec, 0x5910,
811 0x5920, 0x5924,
812 0x5960, 0x5960,
813 0x5968, 0x5968,
814 0x5970, 0x5970,
815 0x5978, 0x5978,
816 0x5980, 0x5980,
817 0x5988, 0x5988,
818 0x5990, 0x5990,
819 0x5998, 0x5998,
820 0x59a0, 0x59d4,
821 0x5a00, 0x5ae0,
822 0x5ae8, 0x5ae8,
823 0x5af0, 0x5af0,
824 0x5af8, 0x5af8,
825 0x6000, 0x6098,
826 0x6100, 0x6150,
827 0x6200, 0x6208,
828 0x6240, 0x6248,
829 0x6280, 0x62b0,
830 0x62c0, 0x6338,
831 0x6370, 0x638c,
832 0x6400, 0x643c,
833 0x6500, 0x6524,
834 0x6a00, 0x6a04,
835 0x6a14, 0x6a38,
836 0x6a60, 0x6a70,
837 0x6a78, 0x6a78,
838 0x6b00, 0x6b0c,
839 0x6b1c, 0x6b84,
840 0x6bf0, 0x6bf8,
841 0x6c00, 0x6c0c,
842 0x6c1c, 0x6c84,
843 0x6cf0, 0x6cf8,
844 0x6d00, 0x6d0c,
845 0x6d1c, 0x6d84,
846 0x6df0, 0x6df8,
847 0x6e00, 0x6e0c,
848 0x6e1c, 0x6e84,
849 0x6ef0, 0x6ef8,
850 0x6f00, 0x6f0c,
851 0x6f1c, 0x6f84,
852 0x6ff0, 0x6ff8,
853 0x7000, 0x700c,
854 0x701c, 0x7084,
855 0x70f0, 0x70f8,
856 0x7100, 0x710c,
857 0x711c, 0x7184,
858 0x71f0, 0x71f8,
859 0x7200, 0x720c,
860 0x721c, 0x7284,
861 0x72f0, 0x72f8,
862 0x7300, 0x730c,
863 0x731c, 0x7384,
864 0x73f0, 0x73f8,
865 0x7400, 0x7450,
866 0x7500, 0x7530,
867 0x7600, 0x760c,
868 0x7614, 0x761c,
869 0x7680, 0x76cc,
870 0x7700, 0x7798,
871 0x77c0, 0x77fc,
872 0x7900, 0x79fc,
873 0x7b00, 0x7b58,
874 0x7b60, 0x7b84,
875 0x7b8c, 0x7c38,
876 0x7d00, 0x7d38,
877 0x7d40, 0x7d80,
878 0x7d8c, 0x7ddc,
879 0x7de4, 0x7e04,
880 0x7e10, 0x7e1c,
881 0x7e24, 0x7e38,
882 0x7e40, 0x7e44,
883 0x7e4c, 0x7e78,
884 0x7e80, 0x7ea4,
885 0x7eac, 0x7edc,
886 0x7ee8, 0x7efc,
887 0x8dc0, 0x8e04,
888 0x8e10, 0x8e1c,
889 0x8e30, 0x8e78,
890 0x8ea0, 0x8eb8,
891 0x8ec0, 0x8f6c,
892 0x8fc0, 0x9008,
893 0x9010, 0x9058,
894 0x9060, 0x9060,
895 0x9068, 0x9074,
896 0x90fc, 0x90fc,
897 0x9400, 0x9408,
898 0x9410, 0x9458,
899 0x9600, 0x9600,
900 0x9608, 0x9638,
901 0x9640, 0x96bc,
902 0x9800, 0x9808,
903 0x9820, 0x983c,
904 0x9850, 0x9864,
905 0x9c00, 0x9c6c,
906 0x9c80, 0x9cec,
907 0x9d00, 0x9d6c,
908 0x9d80, 0x9dec,
909 0x9e00, 0x9e6c,
910 0x9e80, 0x9eec,
911 0x9f00, 0x9f6c,
912 0x9f80, 0x9fec,
913 0xd004, 0xd004,
914 0xd010, 0xd03c,
915 0xdfc0, 0xdfe0,
916 0xe000, 0xea7c,
917 0xf000, 0x11110,
918 0x11118, 0x11190,
919 0x19040, 0x1906c,
920 0x19078, 0x19080,
921 0x1908c, 0x190e4,
922 0x190f0, 0x190f8,
923 0x19100, 0x19110,
924 0x19120, 0x19124,
925 0x19150, 0x19194,
926 0x1919c, 0x191b0,
927 0x191d0, 0x191e8,
928 0x19238, 0x1924c,
929 0x193f8, 0x1943c,
930 0x1944c, 0x19474,
931 0x19490, 0x194e0,
932 0x194f0, 0x194f8,
933 0x19800, 0x19c08,
934 0x19c10, 0x19c90,
935 0x19ca0, 0x19ce4,
936 0x19cf0, 0x19d40,
937 0x19d50, 0x19d94,
938 0x19da0, 0x19de8,
939 0x19df0, 0x19e40,
940 0x19e50, 0x19e90,
941 0x19ea0, 0x19f4c,
942 0x1a000, 0x1a004,
943 0x1a010, 0x1a06c,
944 0x1a0b0, 0x1a0e4,
945 0x1a0ec, 0x1a0f4,
946 0x1a100, 0x1a108,
947 0x1a114, 0x1a120,
948 0x1a128, 0x1a130,
949 0x1a138, 0x1a138,
950 0x1a190, 0x1a1c4,
951 0x1a1fc, 0x1a1fc,
952 0x1e040, 0x1e04c,
953 0x1e284, 0x1e28c,
954 0x1e2c0, 0x1e2c0,
955 0x1e2e0, 0x1e2e0,
956 0x1e300, 0x1e384,
957 0x1e3c0, 0x1e3c8,
958 0x1e440, 0x1e44c,
959 0x1e684, 0x1e68c,
960 0x1e6c0, 0x1e6c0,
961 0x1e6e0, 0x1e6e0,
962 0x1e700, 0x1e784,
963 0x1e7c0, 0x1e7c8,
964 0x1e840, 0x1e84c,
965 0x1ea84, 0x1ea8c,
966 0x1eac0, 0x1eac0,
967 0x1eae0, 0x1eae0,
968 0x1eb00, 0x1eb84,
969 0x1ebc0, 0x1ebc8,
970 0x1ec40, 0x1ec4c,
971 0x1ee84, 0x1ee8c,
972 0x1eec0, 0x1eec0,
973 0x1eee0, 0x1eee0,
974 0x1ef00, 0x1ef84,
975 0x1efc0, 0x1efc8,
976 0x1f040, 0x1f04c,
977 0x1f284, 0x1f28c,
978 0x1f2c0, 0x1f2c0,
979 0x1f2e0, 0x1f2e0,
980 0x1f300, 0x1f384,
981 0x1f3c0, 0x1f3c8,
982 0x1f440, 0x1f44c,
983 0x1f684, 0x1f68c,
984 0x1f6c0, 0x1f6c0,
985 0x1f6e0, 0x1f6e0,
986 0x1f700, 0x1f784,
987 0x1f7c0, 0x1f7c8,
988 0x1f840, 0x1f84c,
989 0x1fa84, 0x1fa8c,
990 0x1fac0, 0x1fac0,
991 0x1fae0, 0x1fae0,
992 0x1fb00, 0x1fb84,
993 0x1fbc0, 0x1fbc8,
994 0x1fc40, 0x1fc4c,
995 0x1fe84, 0x1fe8c,
996 0x1fec0, 0x1fec0,
997 0x1fee0, 0x1fee0,
998 0x1ff00, 0x1ff84,
999 0x1ffc0, 0x1ffc8,
1000 0x20000, 0x2002c,
1001 0x20100, 0x2013c,
1002 0x20190, 0x201a0,
1003 0x201a8, 0x201b8,
1004 0x201c4, 0x201c8,
1005 0x20200, 0x20318,
1006 0x20400, 0x204b4,
1007 0x204c0, 0x20528,
1008 0x20540, 0x20614,
1009 0x21000, 0x21040,
1010 0x2104c, 0x21060,
1011 0x210c0, 0x210ec,
1012 0x21200, 0x21268,
1013 0x21270, 0x21284,
1014 0x212fc, 0x21388,
1015 0x21400, 0x21404,
1016 0x21500, 0x21500,
1017 0x21510, 0x21518,
1018 0x2152c, 0x21530,
1019 0x2153c, 0x2153c,
1020 0x21550, 0x21554,
1021 0x21600, 0x21600,
1022 0x21608, 0x2161c,
1023 0x21624, 0x21628,
1024 0x21630, 0x21634,
1025 0x2163c, 0x2163c,
1026 0x21700, 0x2171c,
1027 0x21780, 0x2178c,
1028 0x21800, 0x21818,
1029 0x21820, 0x21828,
1030 0x21830, 0x21848,
1031 0x21850, 0x21854,
1032 0x21860, 0x21868,
1033 0x21870, 0x21870,
1034 0x21878, 0x21898,
1035 0x218a0, 0x218a8,
1036 0x218b0, 0x218c8,
1037 0x218d0, 0x218d4,
1038 0x218e0, 0x218e8,
1039 0x218f0, 0x218f0,
1040 0x218f8, 0x21a18,
1041 0x21a20, 0x21a28,
1042 0x21a30, 0x21a48,
1043 0x21a50, 0x21a54,
1044 0x21a60, 0x21a68,
1045 0x21a70, 0x21a70,
1046 0x21a78, 0x21a98,
1047 0x21aa0, 0x21aa8,
1048 0x21ab0, 0x21ac8,
1049 0x21ad0, 0x21ad4,
1050 0x21ae0, 0x21ae8,
1051 0x21af0, 0x21af0,
1052 0x21af8, 0x21c18,
1053 0x21c20, 0x21c20,
1054 0x21c28, 0x21c30,
1055 0x21c38, 0x21c38,
1056 0x21c80, 0x21c98,
1057 0x21ca0, 0x21ca8,
1058 0x21cb0, 0x21cc8,
1059 0x21cd0, 0x21cd4,
1060 0x21ce0, 0x21ce8,
1061 0x21cf0, 0x21cf0,
1062 0x21cf8, 0x21d7c,
1063 0x21e00, 0x21e04,
1064 0x22000, 0x2202c,
1065 0x22100, 0x2213c,
1066 0x22190, 0x221a0,
1067 0x221a8, 0x221b8,
1068 0x221c4, 0x221c8,
1069 0x22200, 0x22318,
1070 0x22400, 0x224b4,
1071 0x224c0, 0x22528,
1072 0x22540, 0x22614,
1073 0x23000, 0x23040,
1074 0x2304c, 0x23060,
1075 0x230c0, 0x230ec,
1076 0x23200, 0x23268,
1077 0x23270, 0x23284,
1078 0x232fc, 0x23388,
1079 0x23400, 0x23404,
1080 0x23500, 0x23500,
1081 0x23510, 0x23518,
1082 0x2352c, 0x23530,
1083 0x2353c, 0x2353c,
1084 0x23550, 0x23554,
1085 0x23600, 0x23600,
1086 0x23608, 0x2361c,
1087 0x23624, 0x23628,
1088 0x23630, 0x23634,
1089 0x2363c, 0x2363c,
1090 0x23700, 0x2371c,
1091 0x23780, 0x2378c,
1092 0x23800, 0x23818,
1093 0x23820, 0x23828,
1094 0x23830, 0x23848,
1095 0x23850, 0x23854,
1096 0x23860, 0x23868,
1097 0x23870, 0x23870,
1098 0x23878, 0x23898,
1099 0x238a0, 0x238a8,
1100 0x238b0, 0x238c8,
1101 0x238d0, 0x238d4,
1102 0x238e0, 0x238e8,
1103 0x238f0, 0x238f0,
1104 0x238f8, 0x23a18,
1105 0x23a20, 0x23a28,
1106 0x23a30, 0x23a48,
1107 0x23a50, 0x23a54,
1108 0x23a60, 0x23a68,
1109 0x23a70, 0x23a70,
1110 0x23a78, 0x23a98,
1111 0x23aa0, 0x23aa8,
1112 0x23ab0, 0x23ac8,
1113 0x23ad0, 0x23ad4,
1114 0x23ae0, 0x23ae8,
1115 0x23af0, 0x23af0,
1116 0x23af8, 0x23c18,
1117 0x23c20, 0x23c20,
1118 0x23c28, 0x23c30,
1119 0x23c38, 0x23c38,
1120 0x23c80, 0x23c98,
1121 0x23ca0, 0x23ca8,
1122 0x23cb0, 0x23cc8,
1123 0x23cd0, 0x23cd4,
1124 0x23ce0, 0x23ce8,
1125 0x23cf0, 0x23cf0,
1126 0x23cf8, 0x23d7c,
1127 0x23e00, 0x23e04,
1128 0x24000, 0x2402c,
1129 0x24100, 0x2413c,
1130 0x24190, 0x241a0,
1131 0x241a8, 0x241b8,
1132 0x241c4, 0x241c8,
1133 0x24200, 0x24318,
1134 0x24400, 0x244b4,
1135 0x244c0, 0x24528,
1136 0x24540, 0x24614,
1137 0x25000, 0x25040,
1138 0x2504c, 0x25060,
1139 0x250c0, 0x250ec,
1140 0x25200, 0x25268,
1141 0x25270, 0x25284,
1142 0x252fc, 0x25388,
1143 0x25400, 0x25404,
1144 0x25500, 0x25500,
1145 0x25510, 0x25518,
1146 0x2552c, 0x25530,
1147 0x2553c, 0x2553c,
1148 0x25550, 0x25554,
1149 0x25600, 0x25600,
1150 0x25608, 0x2561c,
1151 0x25624, 0x25628,
1152 0x25630, 0x25634,
1153 0x2563c, 0x2563c,
1154 0x25700, 0x2571c,
1155 0x25780, 0x2578c,
1156 0x25800, 0x25818,
1157 0x25820, 0x25828,
1158 0x25830, 0x25848,
1159 0x25850, 0x25854,
1160 0x25860, 0x25868,
1161 0x25870, 0x25870,
1162 0x25878, 0x25898,
1163 0x258a0, 0x258a8,
1164 0x258b0, 0x258c8,
1165 0x258d0, 0x258d4,
1166 0x258e0, 0x258e8,
1167 0x258f0, 0x258f0,
1168 0x258f8, 0x25a18,
1169 0x25a20, 0x25a28,
1170 0x25a30, 0x25a48,
1171 0x25a50, 0x25a54,
1172 0x25a60, 0x25a68,
1173 0x25a70, 0x25a70,
1174 0x25a78, 0x25a98,
1175 0x25aa0, 0x25aa8,
1176 0x25ab0, 0x25ac8,
1177 0x25ad0, 0x25ad4,
1178 0x25ae0, 0x25ae8,
1179 0x25af0, 0x25af0,
1180 0x25af8, 0x25c18,
1181 0x25c20, 0x25c20,
1182 0x25c28, 0x25c30,
1183 0x25c38, 0x25c38,
1184 0x25c80, 0x25c98,
1185 0x25ca0, 0x25ca8,
1186 0x25cb0, 0x25cc8,
1187 0x25cd0, 0x25cd4,
1188 0x25ce0, 0x25ce8,
1189 0x25cf0, 0x25cf0,
1190 0x25cf8, 0x25d7c,
1191 0x25e00, 0x25e04,
1192 0x26000, 0x2602c,
1193 0x26100, 0x2613c,
1194 0x26190, 0x261a0,
1195 0x261a8, 0x261b8,
1196 0x261c4, 0x261c8,
1197 0x26200, 0x26318,
1198 0x26400, 0x264b4,
1199 0x264c0, 0x26528,
1200 0x26540, 0x26614,
1201 0x27000, 0x27040,
1202 0x2704c, 0x27060,
1203 0x270c0, 0x270ec,
1204 0x27200, 0x27268,
1205 0x27270, 0x27284,
1206 0x272fc, 0x27388,
1207 0x27400, 0x27404,
1208 0x27500, 0x27500,
1209 0x27510, 0x27518,
1210 0x2752c, 0x27530,
1211 0x2753c, 0x2753c,
1212 0x27550, 0x27554,
1213 0x27600, 0x27600,
1214 0x27608, 0x2761c,
1215 0x27624, 0x27628,
1216 0x27630, 0x27634,
1217 0x2763c, 0x2763c,
1218 0x27700, 0x2771c,
1219 0x27780, 0x2778c,
1220 0x27800, 0x27818,
1221 0x27820, 0x27828,
1222 0x27830, 0x27848,
1223 0x27850, 0x27854,
1224 0x27860, 0x27868,
1225 0x27870, 0x27870,
1226 0x27878, 0x27898,
1227 0x278a0, 0x278a8,
1228 0x278b0, 0x278c8,
1229 0x278d0, 0x278d4,
1230 0x278e0, 0x278e8,
1231 0x278f0, 0x278f0,
1232 0x278f8, 0x27a18,
1233 0x27a20, 0x27a28,
1234 0x27a30, 0x27a48,
1235 0x27a50, 0x27a54,
1236 0x27a60, 0x27a68,
1237 0x27a70, 0x27a70,
1238 0x27a78, 0x27a98,
1239 0x27aa0, 0x27aa8,
1240 0x27ab0, 0x27ac8,
1241 0x27ad0, 0x27ad4,
1242 0x27ae0, 0x27ae8,
1243 0x27af0, 0x27af0,
1244 0x27af8, 0x27c18,
1245 0x27c20, 0x27c20,
1246 0x27c28, 0x27c30,
1247 0x27c38, 0x27c38,
1248 0x27c80, 0x27c98,
1249 0x27ca0, 0x27ca8,
1250 0x27cb0, 0x27cc8,
1251 0x27cd0, 0x27cd4,
1252 0x27ce0, 0x27ce8,
1253 0x27cf0, 0x27cf0,
1254 0x27cf8, 0x27d7c,
1255 0x27e00, 0x27e04,
1256 };
1257
1258 static const unsigned int t5_reg_ranges[] = {
1259 0x1008, 0x10c0,
1260 0x10cc, 0x10f8,
1261 0x1100, 0x1100,
1262 0x110c, 0x1148,
1263 0x1180, 0x1184,
1264 0x1190, 0x1194,
1265 0x11a0, 0x11a4,
1266 0x11b0, 0x11b4,
1267 0x11fc, 0x123c,
1268 0x1280, 0x173c,
1269 0x1800, 0x18fc,
1270 0x3000, 0x3028,
1271 0x3060, 0x30b0,
1272 0x30b8, 0x30d8,
1273 0x30e0, 0x30fc,
1274 0x3140, 0x357c,
1275 0x35a8, 0x35cc,
1276 0x35ec, 0x35ec,
1277 0x3600, 0x5624,
1278 0x56cc, 0x56ec,
1279 0x56f4, 0x5720,
1280 0x5728, 0x575c,
1281 0x580c, 0x5814,
1282 0x5890, 0x589c,
1283 0x58a4, 0x58ac,
1284 0x58b8, 0x58bc,
1285 0x5940, 0x59c8,
1286 0x59d0, 0x59dc,
1287 0x59fc, 0x5a18,
1288 0x5a60, 0x5a70,
1289 0x5a80, 0x5a9c,
1290 0x5b94, 0x5bfc,
1291 0x6000, 0x6020,
1292 0x6028, 0x6040,
1293 0x6058, 0x609c,
1294 0x60a8, 0x614c,
1295 0x7700, 0x7798,
1296 0x77c0, 0x78fc,
1297 0x7b00, 0x7b58,
1298 0x7b60, 0x7b84,
1299 0x7b8c, 0x7c54,
1300 0x7d00, 0x7d38,
1301 0x7d40, 0x7d80,
1302 0x7d8c, 0x7ddc,
1303 0x7de4, 0x7e04,
1304 0x7e10, 0x7e1c,
1305 0x7e24, 0x7e38,
1306 0x7e40, 0x7e44,
1307 0x7e4c, 0x7e78,
1308 0x7e80, 0x7edc,
1309 0x7ee8, 0x7efc,
1310 0x8dc0, 0x8de0,
1311 0x8df8, 0x8e04,
1312 0x8e10, 0x8e84,
1313 0x8ea0, 0x8f84,
1314 0x8fc0, 0x9058,
1315 0x9060, 0x9060,
1316 0x9068, 0x90f8,
1317 0x9400, 0x9408,
1318 0x9410, 0x9470,
1319 0x9600, 0x9600,
1320 0x9608, 0x9638,
1321 0x9640, 0x96f4,
1322 0x9800, 0x9808,
1323 0x9820, 0x983c,
1324 0x9850, 0x9864,
1325 0x9c00, 0x9c6c,
1326 0x9c80, 0x9cec,
1327 0x9d00, 0x9d6c,
1328 0x9d80, 0x9dec,
1329 0x9e00, 0x9e6c,
1330 0x9e80, 0x9eec,
1331 0x9f00, 0x9f6c,
1332 0x9f80, 0xa020,
1333 0xd004, 0xd004,
1334 0xd010, 0xd03c,
1335 0xdfc0, 0xdfe0,
1336 0xe000, 0x1106c,
1337 0x11074, 0x11088,
1338 0x1109c, 0x1117c,
1339 0x11190, 0x11204,
1340 0x19040, 0x1906c,
1341 0x19078, 0x19080,
1342 0x1908c, 0x190e8,
1343 0x190f0, 0x190f8,
1344 0x19100, 0x19110,
1345 0x19120, 0x19124,
1346 0x19150, 0x19194,
1347 0x1919c, 0x191b0,
1348 0x191d0, 0x191e8,
1349 0x19238, 0x19290,
1350 0x193f8, 0x19428,
1351 0x19430, 0x19444,
1352 0x1944c, 0x1946c,
1353 0x19474, 0x19474,
1354 0x19490, 0x194cc,
1355 0x194f0, 0x194f8,
1356 0x19c00, 0x19c08,
1357 0x19c10, 0x19c60,
1358 0x19c94, 0x19ce4,
1359 0x19cf0, 0x19d40,
1360 0x19d50, 0x19d94,
1361 0x19da0, 0x19de8,
1362 0x19df0, 0x19e10,
1363 0x19e50, 0x19e90,
1364 0x19ea0, 0x19f24,
1365 0x19f34, 0x19f34,
1366 0x19f40, 0x19f50,
1367 0x19f90, 0x19fb4,
1368 0x19fc4, 0x19fe4,
1369 0x1a000, 0x1a004,
1370 0x1a010, 0x1a06c,
1371 0x1a0b0, 0x1a0e4,
1372 0x1a0ec, 0x1a0f8,
1373 0x1a100, 0x1a108,
1374 0x1a114, 0x1a120,
1375 0x1a128, 0x1a130,
1376 0x1a138, 0x1a138,
1377 0x1a190, 0x1a1c4,
1378 0x1a1fc, 0x1a1fc,
1379 0x1e008, 0x1e00c,
1380 0x1e040, 0x1e044,
1381 0x1e04c, 0x1e04c,
1382 0x1e284, 0x1e290,
1383 0x1e2c0, 0x1e2c0,
1384 0x1e2e0, 0x1e2e0,
1385 0x1e300, 0x1e384,
1386 0x1e3c0, 0x1e3c8,
1387 0x1e408, 0x1e40c,
1388 0x1e440, 0x1e444,
1389 0x1e44c, 0x1e44c,
1390 0x1e684, 0x1e690,
1391 0x1e6c0, 0x1e6c0,
1392 0x1e6e0, 0x1e6e0,
1393 0x1e700, 0x1e784,
1394 0x1e7c0, 0x1e7c8,
1395 0x1e808, 0x1e80c,
1396 0x1e840, 0x1e844,
1397 0x1e84c, 0x1e84c,
1398 0x1ea84, 0x1ea90,
1399 0x1eac0, 0x1eac0,
1400 0x1eae0, 0x1eae0,
1401 0x1eb00, 0x1eb84,
1402 0x1ebc0, 0x1ebc8,
1403 0x1ec08, 0x1ec0c,
1404 0x1ec40, 0x1ec44,
1405 0x1ec4c, 0x1ec4c,
1406 0x1ee84, 0x1ee90,
1407 0x1eec0, 0x1eec0,
1408 0x1eee0, 0x1eee0,
1409 0x1ef00, 0x1ef84,
1410 0x1efc0, 0x1efc8,
1411 0x1f008, 0x1f00c,
1412 0x1f040, 0x1f044,
1413 0x1f04c, 0x1f04c,
1414 0x1f284, 0x1f290,
1415 0x1f2c0, 0x1f2c0,
1416 0x1f2e0, 0x1f2e0,
1417 0x1f300, 0x1f384,
1418 0x1f3c0, 0x1f3c8,
1419 0x1f408, 0x1f40c,
1420 0x1f440, 0x1f444,
1421 0x1f44c, 0x1f44c,
1422 0x1f684, 0x1f690,
1423 0x1f6c0, 0x1f6c0,
1424 0x1f6e0, 0x1f6e0,
1425 0x1f700, 0x1f784,
1426 0x1f7c0, 0x1f7c8,
1427 0x1f808, 0x1f80c,
1428 0x1f840, 0x1f844,
1429 0x1f84c, 0x1f84c,
1430 0x1fa84, 0x1fa90,
1431 0x1fac0, 0x1fac0,
1432 0x1fae0, 0x1fae0,
1433 0x1fb00, 0x1fb84,
1434 0x1fbc0, 0x1fbc8,
1435 0x1fc08, 0x1fc0c,
1436 0x1fc40, 0x1fc44,
1437 0x1fc4c, 0x1fc4c,
1438 0x1fe84, 0x1fe90,
1439 0x1fec0, 0x1fec0,
1440 0x1fee0, 0x1fee0,
1441 0x1ff00, 0x1ff84,
1442 0x1ffc0, 0x1ffc8,
1443 0x30000, 0x30030,
1444 0x30100, 0x30144,
1445 0x30190, 0x301a0,
1446 0x301a8, 0x301b8,
1447 0x301c4, 0x301c8,
1448 0x301d0, 0x301d0,
1449 0x30200, 0x30318,
1450 0x30400, 0x304b4,
1451 0x304c0, 0x3052c,
1452 0x30540, 0x3061c,
1453 0x30800, 0x30828,
1454 0x30834, 0x30834,
1455 0x308c0, 0x30908,
1456 0x30910, 0x309ac,
1457 0x30a00, 0x30a14,
1458 0x30a1c, 0x30a2c,
1459 0x30a44, 0x30a50,
1460 0x30a74, 0x30a74,
1461 0x30a7c, 0x30afc,
1462 0x30b08, 0x30c24,
1463 0x30d00, 0x30d00,
1464 0x30d08, 0x30d14,
1465 0x30d1c, 0x30d20,
1466 0x30d3c, 0x30d3c,
1467 0x30d48, 0x30d50,
1468 0x31200, 0x3120c,
1469 0x31220, 0x31220,
1470 0x31240, 0x31240,
1471 0x31600, 0x3160c,
1472 0x31a00, 0x31a1c,
1473 0x31e00, 0x31e20,
1474 0x31e38, 0x31e3c,
1475 0x31e80, 0x31e80,
1476 0x31e88, 0x31ea8,
1477 0x31eb0, 0x31eb4,
1478 0x31ec8, 0x31ed4,
1479 0x31fb8, 0x32004,
1480 0x32200, 0x32200,
1481 0x32208, 0x32240,
1482 0x32248, 0x32280,
1483 0x32288, 0x322c0,
1484 0x322c8, 0x322fc,
1485 0x32600, 0x32630,
1486 0x32a00, 0x32abc,
1487 0x32b00, 0x32b10,
1488 0x32b20, 0x32b30,
1489 0x32b40, 0x32b50,
1490 0x32b60, 0x32b70,
1491 0x33000, 0x33028,
1492 0x33030, 0x33048,
1493 0x33060, 0x33068,
1494 0x33070, 0x3309c,
1495 0x330f0, 0x33128,
1496 0x33130, 0x33148,
1497 0x33160, 0x33168,
1498 0x33170, 0x3319c,
1499 0x331f0, 0x33238,
1500 0x33240, 0x33240,
1501 0x33248, 0x33250,
1502 0x3325c, 0x33264,
1503 0x33270, 0x332b8,
1504 0x332c0, 0x332e4,
1505 0x332f8, 0x33338,
1506 0x33340, 0x33340,
1507 0x33348, 0x33350,
1508 0x3335c, 0x33364,
1509 0x33370, 0x333b8,
1510 0x333c0, 0x333e4,
1511 0x333f8, 0x33428,
1512 0x33430, 0x33448,
1513 0x33460, 0x33468,
1514 0x33470, 0x3349c,
1515 0x334f0, 0x33528,
1516 0x33530, 0x33548,
1517 0x33560, 0x33568,
1518 0x33570, 0x3359c,
1519 0x335f0, 0x33638,
1520 0x33640, 0x33640,
1521 0x33648, 0x33650,
1522 0x3365c, 0x33664,
1523 0x33670, 0x336b8,
1524 0x336c0, 0x336e4,
1525 0x336f8, 0x33738,
1526 0x33740, 0x33740,
1527 0x33748, 0x33750,
1528 0x3375c, 0x33764,
1529 0x33770, 0x337b8,
1530 0x337c0, 0x337e4,
1531 0x337f8, 0x337fc,
1532 0x33814, 0x33814,
1533 0x3382c, 0x3382c,
1534 0x33880, 0x3388c,
1535 0x338e8, 0x338ec,
1536 0x33900, 0x33928,
1537 0x33930, 0x33948,
1538 0x33960, 0x33968,
1539 0x33970, 0x3399c,
1540 0x339f0, 0x33a38,
1541 0x33a40, 0x33a40,
1542 0x33a48, 0x33a50,
1543 0x33a5c, 0x33a64,
1544 0x33a70, 0x33ab8,
1545 0x33ac0, 0x33ae4,
1546 0x33af8, 0x33b10,
1547 0x33b28, 0x33b28,
1548 0x33b3c, 0x33b50,
1549 0x33bf0, 0x33c10,
1550 0x33c28, 0x33c28,
1551 0x33c3c, 0x33c50,
1552 0x33cf0, 0x33cfc,
1553 0x34000, 0x34030,
1554 0x34100, 0x34144,
1555 0x34190, 0x341a0,
1556 0x341a8, 0x341b8,
1557 0x341c4, 0x341c8,
1558 0x341d0, 0x341d0,
1559 0x34200, 0x34318,
1560 0x34400, 0x344b4,
1561 0x344c0, 0x3452c,
1562 0x34540, 0x3461c,
1563 0x34800, 0x34828,
1564 0x34834, 0x34834,
1565 0x348c0, 0x34908,
1566 0x34910, 0x349ac,
1567 0x34a00, 0x34a14,
1568 0x34a1c, 0x34a2c,
1569 0x34a44, 0x34a50,
1570 0x34a74, 0x34a74,
1571 0x34a7c, 0x34afc,
1572 0x34b08, 0x34c24,
1573 0x34d00, 0x34d00,
1574 0x34d08, 0x34d14,
1575 0x34d1c, 0x34d20,
1576 0x34d3c, 0x34d3c,
1577 0x34d48, 0x34d50,
1578 0x35200, 0x3520c,
1579 0x35220, 0x35220,
1580 0x35240, 0x35240,
1581 0x35600, 0x3560c,
1582 0x35a00, 0x35a1c,
1583 0x35e00, 0x35e20,
1584 0x35e38, 0x35e3c,
1585 0x35e80, 0x35e80,
1586 0x35e88, 0x35ea8,
1587 0x35eb0, 0x35eb4,
1588 0x35ec8, 0x35ed4,
1589 0x35fb8, 0x36004,
1590 0x36200, 0x36200,
1591 0x36208, 0x36240,
1592 0x36248, 0x36280,
1593 0x36288, 0x362c0,
1594 0x362c8, 0x362fc,
1595 0x36600, 0x36630,
1596 0x36a00, 0x36abc,
1597 0x36b00, 0x36b10,
1598 0x36b20, 0x36b30,
1599 0x36b40, 0x36b50,
1600 0x36b60, 0x36b70,
1601 0x37000, 0x37028,
1602 0x37030, 0x37048,
1603 0x37060, 0x37068,
1604 0x37070, 0x3709c,
1605 0x370f0, 0x37128,
1606 0x37130, 0x37148,
1607 0x37160, 0x37168,
1608 0x37170, 0x3719c,
1609 0x371f0, 0x37238,
1610 0x37240, 0x37240,
1611 0x37248, 0x37250,
1612 0x3725c, 0x37264,
1613 0x37270, 0x372b8,
1614 0x372c0, 0x372e4,
1615 0x372f8, 0x37338,
1616 0x37340, 0x37340,
1617 0x37348, 0x37350,
1618 0x3735c, 0x37364,
1619 0x37370, 0x373b8,
1620 0x373c0, 0x373e4,
1621 0x373f8, 0x37428,
1622 0x37430, 0x37448,
1623 0x37460, 0x37468,
1624 0x37470, 0x3749c,
1625 0x374f0, 0x37528,
1626 0x37530, 0x37548,
1627 0x37560, 0x37568,
1628 0x37570, 0x3759c,
1629 0x375f0, 0x37638,
1630 0x37640, 0x37640,
1631 0x37648, 0x37650,
1632 0x3765c, 0x37664,
1633 0x37670, 0x376b8,
1634 0x376c0, 0x376e4,
1635 0x376f8, 0x37738,
1636 0x37740, 0x37740,
1637 0x37748, 0x37750,
1638 0x3775c, 0x37764,
1639 0x37770, 0x377b8,
1640 0x377c0, 0x377e4,
1641 0x377f8, 0x377fc,
1642 0x37814, 0x37814,
1643 0x3782c, 0x3782c,
1644 0x37880, 0x3788c,
1645 0x378e8, 0x378ec,
1646 0x37900, 0x37928,
1647 0x37930, 0x37948,
1648 0x37960, 0x37968,
1649 0x37970, 0x3799c,
1650 0x379f0, 0x37a38,
1651 0x37a40, 0x37a40,
1652 0x37a48, 0x37a50,
1653 0x37a5c, 0x37a64,
1654 0x37a70, 0x37ab8,
1655 0x37ac0, 0x37ae4,
1656 0x37af8, 0x37b10,
1657 0x37b28, 0x37b28,
1658 0x37b3c, 0x37b50,
1659 0x37bf0, 0x37c10,
1660 0x37c28, 0x37c28,
1661 0x37c3c, 0x37c50,
1662 0x37cf0, 0x37cfc,
1663 0x38000, 0x38030,
1664 0x38100, 0x38144,
1665 0x38190, 0x381a0,
1666 0x381a8, 0x381b8,
1667 0x381c4, 0x381c8,
1668 0x381d0, 0x381d0,
1669 0x38200, 0x38318,
1670 0x38400, 0x384b4,
1671 0x384c0, 0x3852c,
1672 0x38540, 0x3861c,
1673 0x38800, 0x38828,
1674 0x38834, 0x38834,
1675 0x388c0, 0x38908,
1676 0x38910, 0x389ac,
1677 0x38a00, 0x38a14,
1678 0x38a1c, 0x38a2c,
1679 0x38a44, 0x38a50,
1680 0x38a74, 0x38a74,
1681 0x38a7c, 0x38afc,
1682 0x38b08, 0x38c24,
1683 0x38d00, 0x38d00,
1684 0x38d08, 0x38d14,
1685 0x38d1c, 0x38d20,
1686 0x38d3c, 0x38d3c,
1687 0x38d48, 0x38d50,
1688 0x39200, 0x3920c,
1689 0x39220, 0x39220,
1690 0x39240, 0x39240,
1691 0x39600, 0x3960c,
1692 0x39a00, 0x39a1c,
1693 0x39e00, 0x39e20,
1694 0x39e38, 0x39e3c,
1695 0x39e80, 0x39e80,
1696 0x39e88, 0x39ea8,
1697 0x39eb0, 0x39eb4,
1698 0x39ec8, 0x39ed4,
1699 0x39fb8, 0x3a004,
1700 0x3a200, 0x3a200,
1701 0x3a208, 0x3a240,
1702 0x3a248, 0x3a280,
1703 0x3a288, 0x3a2c0,
1704 0x3a2c8, 0x3a2fc,
1705 0x3a600, 0x3a630,
1706 0x3aa00, 0x3aabc,
1707 0x3ab00, 0x3ab10,
1708 0x3ab20, 0x3ab30,
1709 0x3ab40, 0x3ab50,
1710 0x3ab60, 0x3ab70,
1711 0x3b000, 0x3b028,
1712 0x3b030, 0x3b048,
1713 0x3b060, 0x3b068,
1714 0x3b070, 0x3b09c,
1715 0x3b0f0, 0x3b128,
1716 0x3b130, 0x3b148,
1717 0x3b160, 0x3b168,
1718 0x3b170, 0x3b19c,
1719 0x3b1f0, 0x3b238,
1720 0x3b240, 0x3b240,
1721 0x3b248, 0x3b250,
1722 0x3b25c, 0x3b264,
1723 0x3b270, 0x3b2b8,
1724 0x3b2c0, 0x3b2e4,
1725 0x3b2f8, 0x3b338,
1726 0x3b340, 0x3b340,
1727 0x3b348, 0x3b350,
1728 0x3b35c, 0x3b364,
1729 0x3b370, 0x3b3b8,
1730 0x3b3c0, 0x3b3e4,
1731 0x3b3f8, 0x3b428,
1732 0x3b430, 0x3b448,
1733 0x3b460, 0x3b468,
1734 0x3b470, 0x3b49c,
1735 0x3b4f0, 0x3b528,
1736 0x3b530, 0x3b548,
1737 0x3b560, 0x3b568,
1738 0x3b570, 0x3b59c,
1739 0x3b5f0, 0x3b638,
1740 0x3b640, 0x3b640,
1741 0x3b648, 0x3b650,
1742 0x3b65c, 0x3b664,
1743 0x3b670, 0x3b6b8,
1744 0x3b6c0, 0x3b6e4,
1745 0x3b6f8, 0x3b738,
1746 0x3b740, 0x3b740,
1747 0x3b748, 0x3b750,
1748 0x3b75c, 0x3b764,
1749 0x3b770, 0x3b7b8,
1750 0x3b7c0, 0x3b7e4,
1751 0x3b7f8, 0x3b7fc,
1752 0x3b814, 0x3b814,
1753 0x3b82c, 0x3b82c,
1754 0x3b880, 0x3b88c,
1755 0x3b8e8, 0x3b8ec,
1756 0x3b900, 0x3b928,
1757 0x3b930, 0x3b948,
1758 0x3b960, 0x3b968,
1759 0x3b970, 0x3b99c,
1760 0x3b9f0, 0x3ba38,
1761 0x3ba40, 0x3ba40,
1762 0x3ba48, 0x3ba50,
1763 0x3ba5c, 0x3ba64,
1764 0x3ba70, 0x3bab8,
1765 0x3bac0, 0x3bae4,
1766 0x3baf8, 0x3bb10,
1767 0x3bb28, 0x3bb28,
1768 0x3bb3c, 0x3bb50,
1769 0x3bbf0, 0x3bc10,
1770 0x3bc28, 0x3bc28,
1771 0x3bc3c, 0x3bc50,
1772 0x3bcf0, 0x3bcfc,
1773 0x3c000, 0x3c030,
1774 0x3c100, 0x3c144,
1775 0x3c190, 0x3c1a0,
1776 0x3c1a8, 0x3c1b8,
1777 0x3c1c4, 0x3c1c8,
1778 0x3c1d0, 0x3c1d0,
1779 0x3c200, 0x3c318,
1780 0x3c400, 0x3c4b4,
1781 0x3c4c0, 0x3c52c,
1782 0x3c540, 0x3c61c,
1783 0x3c800, 0x3c828,
1784 0x3c834, 0x3c834,
1785 0x3c8c0, 0x3c908,
1786 0x3c910, 0x3c9ac,
1787 0x3ca00, 0x3ca14,
1788 0x3ca1c, 0x3ca2c,
1789 0x3ca44, 0x3ca50,
1790 0x3ca74, 0x3ca74,
1791 0x3ca7c, 0x3cafc,
1792 0x3cb08, 0x3cc24,
1793 0x3cd00, 0x3cd00,
1794 0x3cd08, 0x3cd14,
1795 0x3cd1c, 0x3cd20,
1796 0x3cd3c, 0x3cd3c,
1797 0x3cd48, 0x3cd50,
1798 0x3d200, 0x3d20c,
1799 0x3d220, 0x3d220,
1800 0x3d240, 0x3d240,
1801 0x3d600, 0x3d60c,
1802 0x3da00, 0x3da1c,
1803 0x3de00, 0x3de20,
1804 0x3de38, 0x3de3c,
1805 0x3de80, 0x3de80,
1806 0x3de88, 0x3dea8,
1807 0x3deb0, 0x3deb4,
1808 0x3dec8, 0x3ded4,
1809 0x3dfb8, 0x3e004,
1810 0x3e200, 0x3e200,
1811 0x3e208, 0x3e240,
1812 0x3e248, 0x3e280,
1813 0x3e288, 0x3e2c0,
1814 0x3e2c8, 0x3e2fc,
1815 0x3e600, 0x3e630,
1816 0x3ea00, 0x3eabc,
1817 0x3eb00, 0x3eb10,
1818 0x3eb20, 0x3eb30,
1819 0x3eb40, 0x3eb50,
1820 0x3eb60, 0x3eb70,
1821 0x3f000, 0x3f028,
1822 0x3f030, 0x3f048,
1823 0x3f060, 0x3f068,
1824 0x3f070, 0x3f09c,
1825 0x3f0f0, 0x3f128,
1826 0x3f130, 0x3f148,
1827 0x3f160, 0x3f168,
1828 0x3f170, 0x3f19c,
1829 0x3f1f0, 0x3f238,
1830 0x3f240, 0x3f240,
1831 0x3f248, 0x3f250,
1832 0x3f25c, 0x3f264,
1833 0x3f270, 0x3f2b8,
1834 0x3f2c0, 0x3f2e4,
1835 0x3f2f8, 0x3f338,
1836 0x3f340, 0x3f340,
1837 0x3f348, 0x3f350,
1838 0x3f35c, 0x3f364,
1839 0x3f370, 0x3f3b8,
1840 0x3f3c0, 0x3f3e4,
1841 0x3f3f8, 0x3f428,
1842 0x3f430, 0x3f448,
1843 0x3f460, 0x3f468,
1844 0x3f470, 0x3f49c,
1845 0x3f4f0, 0x3f528,
1846 0x3f530, 0x3f548,
1847 0x3f560, 0x3f568,
1848 0x3f570, 0x3f59c,
1849 0x3f5f0, 0x3f638,
1850 0x3f640, 0x3f640,
1851 0x3f648, 0x3f650,
1852 0x3f65c, 0x3f664,
1853 0x3f670, 0x3f6b8,
1854 0x3f6c0, 0x3f6e4,
1855 0x3f6f8, 0x3f738,
1856 0x3f740, 0x3f740,
1857 0x3f748, 0x3f750,
1858 0x3f75c, 0x3f764,
1859 0x3f770, 0x3f7b8,
1860 0x3f7c0, 0x3f7e4,
1861 0x3f7f8, 0x3f7fc,
1862 0x3f814, 0x3f814,
1863 0x3f82c, 0x3f82c,
1864 0x3f880, 0x3f88c,
1865 0x3f8e8, 0x3f8ec,
1866 0x3f900, 0x3f928,
1867 0x3f930, 0x3f948,
1868 0x3f960, 0x3f968,
1869 0x3f970, 0x3f99c,
1870 0x3f9f0, 0x3fa38,
1871 0x3fa40, 0x3fa40,
1872 0x3fa48, 0x3fa50,
1873 0x3fa5c, 0x3fa64,
1874 0x3fa70, 0x3fab8,
1875 0x3fac0, 0x3fae4,
1876 0x3faf8, 0x3fb10,
1877 0x3fb28, 0x3fb28,
1878 0x3fb3c, 0x3fb50,
1879 0x3fbf0, 0x3fc10,
1880 0x3fc28, 0x3fc28,
1881 0x3fc3c, 0x3fc50,
1882 0x3fcf0, 0x3fcfc,
1883 0x40000, 0x4000c,
1884 0x40040, 0x40050,
1885 0x40060, 0x40068,
1886 0x4007c, 0x4008c,
1887 0x40094, 0x400b0,
1888 0x400c0, 0x40144,
1889 0x40180, 0x4018c,
1890 0x40200, 0x40254,
1891 0x40260, 0x40264,
1892 0x40270, 0x40288,
1893 0x40290, 0x40298,
1894 0x402ac, 0x402c8,
1895 0x402d0, 0x402e0,
1896 0x402f0, 0x402f0,
1897 0x40300, 0x4033c,
1898 0x403f8, 0x403fc,
1899 0x41304, 0x413c4,
1900 0x41400, 0x4140c,
1901 0x41414, 0x4141c,
1902 0x41480, 0x414d0,
1903 0x44000, 0x44054,
1904 0x4405c, 0x44078,
1905 0x440c0, 0x44174,
1906 0x44180, 0x441ac,
1907 0x441b4, 0x441b8,
1908 0x441c0, 0x44254,
1909 0x4425c, 0x44278,
1910 0x442c0, 0x44374,
1911 0x44380, 0x443ac,
1912 0x443b4, 0x443b8,
1913 0x443c0, 0x44454,
1914 0x4445c, 0x44478,
1915 0x444c0, 0x44574,
1916 0x44580, 0x445ac,
1917 0x445b4, 0x445b8,
1918 0x445c0, 0x44654,
1919 0x4465c, 0x44678,
1920 0x446c0, 0x44774,
1921 0x44780, 0x447ac,
1922 0x447b4, 0x447b8,
1923 0x447c0, 0x44854,
1924 0x4485c, 0x44878,
1925 0x448c0, 0x44974,
1926 0x44980, 0x449ac,
1927 0x449b4, 0x449b8,
1928 0x449c0, 0x449fc,
1929 0x45000, 0x45004,
1930 0x45010, 0x45030,
1931 0x45040, 0x45060,
1932 0x45068, 0x45068,
1933 0x45080, 0x45084,
1934 0x450a0, 0x450b0,
1935 0x45200, 0x45204,
1936 0x45210, 0x45230,
1937 0x45240, 0x45260,
1938 0x45268, 0x45268,
1939 0x45280, 0x45284,
1940 0x452a0, 0x452b0,
1941 0x460c0, 0x460e4,
1942 0x47000, 0x4703c,
1943 0x47044, 0x4708c,
1944 0x47200, 0x47250,
1945 0x47400, 0x47408,
1946 0x47414, 0x47420,
1947 0x47600, 0x47618,
1948 0x47800, 0x47814,
1949 0x48000, 0x4800c,
1950 0x48040, 0x48050,
1951 0x48060, 0x48068,
1952 0x4807c, 0x4808c,
1953 0x48094, 0x480b0,
1954 0x480c0, 0x48144,
1955 0x48180, 0x4818c,
1956 0x48200, 0x48254,
1957 0x48260, 0x48264,
1958 0x48270, 0x48288,
1959 0x48290, 0x48298,
1960 0x482ac, 0x482c8,
1961 0x482d0, 0x482e0,
1962 0x482f0, 0x482f0,
1963 0x48300, 0x4833c,
1964 0x483f8, 0x483fc,
1965 0x49304, 0x493c4,
1966 0x49400, 0x4940c,
1967 0x49414, 0x4941c,
1968 0x49480, 0x494d0,
1969 0x4c000, 0x4c054,
1970 0x4c05c, 0x4c078,
1971 0x4c0c0, 0x4c174,
1972 0x4c180, 0x4c1ac,
1973 0x4c1b4, 0x4c1b8,
1974 0x4c1c0, 0x4c254,
1975 0x4c25c, 0x4c278,
1976 0x4c2c0, 0x4c374,
1977 0x4c380, 0x4c3ac,
1978 0x4c3b4, 0x4c3b8,
1979 0x4c3c0, 0x4c454,
1980 0x4c45c, 0x4c478,
1981 0x4c4c0, 0x4c574,
1982 0x4c580, 0x4c5ac,
1983 0x4c5b4, 0x4c5b8,
1984 0x4c5c0, 0x4c654,
1985 0x4c65c, 0x4c678,
1986 0x4c6c0, 0x4c774,
1987 0x4c780, 0x4c7ac,
1988 0x4c7b4, 0x4c7b8,
1989 0x4c7c0, 0x4c854,
1990 0x4c85c, 0x4c878,
1991 0x4c8c0, 0x4c974,
1992 0x4c980, 0x4c9ac,
1993 0x4c9b4, 0x4c9b8,
1994 0x4c9c0, 0x4c9fc,
1995 0x4d000, 0x4d004,
1996 0x4d010, 0x4d030,
1997 0x4d040, 0x4d060,
1998 0x4d068, 0x4d068,
1999 0x4d080, 0x4d084,
2000 0x4d0a0, 0x4d0b0,
2001 0x4d200, 0x4d204,
2002 0x4d210, 0x4d230,
2003 0x4d240, 0x4d260,
2004 0x4d268, 0x4d268,
2005 0x4d280, 0x4d284,
2006 0x4d2a0, 0x4d2b0,
2007 0x4e0c0, 0x4e0e4,
2008 0x4f000, 0x4f03c,
2009 0x4f044, 0x4f08c,
2010 0x4f200, 0x4f250,
2011 0x4f400, 0x4f408,
2012 0x4f414, 0x4f420,
2013 0x4f600, 0x4f618,
2014 0x4f800, 0x4f814,
2015 0x50000, 0x50084,
2016 0x50090, 0x500cc,
2017 0x50400, 0x50400,
2018 0x50800, 0x50884,
2019 0x50890, 0x508cc,
2020 0x50c00, 0x50c00,
2021 0x51000, 0x5101c,
2022 0x51300, 0x51308,
2023 };
2024
2025 static const unsigned int t6_reg_ranges[] = {
2026 0x1008, 0x101c,
2027 0x1024, 0x10a8,
2028 0x10b4, 0x10f8,
2029 0x1100, 0x1114,
2030 0x111c, 0x112c,
2031 0x1138, 0x113c,
2032 0x1144, 0x114c,
2033 0x1180, 0x1184,
2034 0x1190, 0x1194,
2035 0x11a0, 0x11a4,
2036 0x11b0, 0x11b4,
2037 0x11fc, 0x1274,
2038 0x1280, 0x133c,
2039 0x1800, 0x18fc,
2040 0x3000, 0x302c,
2041 0x3060, 0x30b0,
2042 0x30b8, 0x30d8,
2043 0x30e0, 0x30fc,
2044 0x3140, 0x357c,
2045 0x35a8, 0x35cc,
2046 0x35ec, 0x35ec,
2047 0x3600, 0x5624,
2048 0x56cc, 0x56ec,
2049 0x56f4, 0x5720,
2050 0x5728, 0x575c,
2051 0x580c, 0x5814,
2052 0x5890, 0x589c,
2053 0x58a4, 0x58ac,
2054 0x58b8, 0x58bc,
2055 0x5940, 0x595c,
2056 0x5980, 0x598c,
2057 0x59b0, 0x59c8,
2058 0x59d0, 0x59dc,
2059 0x59fc, 0x5a18,
2060 0x5a60, 0x5a6c,
2061 0x5a80, 0x5a8c,
2062 0x5a94, 0x5a9c,
2063 0x5b94, 0x5bfc,
2064 0x5c10, 0x5e48,
2065 0x5e50, 0x5e94,
2066 0x5ea0, 0x5eb0,
2067 0x5ec0, 0x5ec0,
2068 0x5ec8, 0x5ed0,
2069 0x5ee0, 0x5ee0,
2070 0x5ef0, 0x5ef0,
2071 0x5f00, 0x5f00,
2072 0x6000, 0x6020,
2073 0x6028, 0x6040,
2074 0x6058, 0x609c,
2075 0x60a8, 0x619c,
2076 0x7700, 0x7798,
2077 0x77c0, 0x7880,
2078 0x78cc, 0x78fc,
2079 0x7b00, 0x7b58,
2080 0x7b60, 0x7b84,
2081 0x7b8c, 0x7c54,
2082 0x7d00, 0x7d38,
2083 0x7d40, 0x7d84,
2084 0x7d8c, 0x7ddc,
2085 0x7de4, 0x7e04,
2086 0x7e10, 0x7e1c,
2087 0x7e24, 0x7e38,
2088 0x7e40, 0x7e44,
2089 0x7e4c, 0x7e78,
2090 0x7e80, 0x7edc,
2091 0x7ee8, 0x7efc,
2092 0x8dc0, 0x8de4,
2093 0x8df8, 0x8e04,
2094 0x8e10, 0x8e84,
2095 0x8ea0, 0x8f88,
2096 0x8fb8, 0x9058,
2097 0x9060, 0x9060,
2098 0x9068, 0x90f8,
2099 0x9100, 0x9124,
2100 0x9400, 0x9470,
2101 0x9600, 0x9600,
2102 0x9608, 0x9638,
2103 0x9640, 0x9704,
2104 0x9710, 0x971c,
2105 0x9800, 0x9808,
2106 0x9820, 0x983c,
2107 0x9850, 0x9864,
2108 0x9c00, 0x9c6c,
2109 0x9c80, 0x9cec,
2110 0x9d00, 0x9d6c,
2111 0x9d80, 0x9dec,
2112 0x9e00, 0x9e6c,
2113 0x9e80, 0x9eec,
2114 0x9f00, 0x9f6c,
2115 0x9f80, 0xa020,
2116 0xd004, 0xd03c,
2117 0xd100, 0xd118,
2118 0xd200, 0xd214,
2119 0xd220, 0xd234,
2120 0xd240, 0xd254,
2121 0xd260, 0xd274,
2122 0xd280, 0xd294,
2123 0xd2a0, 0xd2b4,
2124 0xd2c0, 0xd2d4,
2125 0xd2e0, 0xd2f4,
2126 0xd300, 0xd31c,
2127 0xdfc0, 0xdfe0,
2128 0xe000, 0xf008,
2129 0xf010, 0xf018,
2130 0xf020, 0xf028,
2131 0x11000, 0x11014,
2132 0x11048, 0x1106c,
2133 0x11074, 0x11088,
2134 0x11098, 0x11120,
2135 0x1112c, 0x1117c,
2136 0x11190, 0x112e0,
2137 0x11300, 0x1130c,
2138 0x12000, 0x1206c,
2139 0x19040, 0x1906c,
2140 0x19078, 0x19080,
2141 0x1908c, 0x190e8,
2142 0x190f0, 0x190f8,
2143 0x19100, 0x19110,
2144 0x19120, 0x19124,
2145 0x19150, 0x19194,
2146 0x1919c, 0x191b0,
2147 0x191d0, 0x191e8,
2148 0x19238, 0x19290,
2149 0x192a4, 0x192b0,
2150 0x192bc, 0x192bc,
2151 0x19348, 0x1934c,
2152 0x193f8, 0x19418,
2153 0x19420, 0x19428,
2154 0x19430, 0x19444,
2155 0x1944c, 0x1946c,
2156 0x19474, 0x19474,
2157 0x19490, 0x194cc,
2158 0x194f0, 0x194f8,
2159 0x19c00, 0x19c48,
2160 0x19c50, 0x19c80,
2161 0x19c94, 0x19c98,
2162 0x19ca0, 0x19cbc,
2163 0x19ce4, 0x19ce4,
2164 0x19cf0, 0x19cf8,
2165 0x19d00, 0x19d28,
2166 0x19d50, 0x19d78,
2167 0x19d94, 0x19d98,
2168 0x19da0, 0x19dc8,
2169 0x19df0, 0x19e10,
2170 0x19e50, 0x19e6c,
2171 0x19ea0, 0x19ebc,
2172 0x19ec4, 0x19ef4,
2173 0x19f04, 0x19f2c,
2174 0x19f34, 0x19f34,
2175 0x19f40, 0x19f50,
2176 0x19f90, 0x19fac,
2177 0x19fc4, 0x19fc8,
2178 0x19fd0, 0x19fe4,
2179 0x1a000, 0x1a004,
2180 0x1a010, 0x1a06c,
2181 0x1a0b0, 0x1a0e4,
2182 0x1a0ec, 0x1a0f8,
2183 0x1a100, 0x1a108,
2184 0x1a114, 0x1a120,
2185 0x1a128, 0x1a130,
2186 0x1a138, 0x1a138,
2187 0x1a190, 0x1a1c4,
2188 0x1a1fc, 0x1a1fc,
2189 0x1e008, 0x1e00c,
2190 0x1e040, 0x1e044,
2191 0x1e04c, 0x1e04c,
2192 0x1e284, 0x1e290,
2193 0x1e2c0, 0x1e2c0,
2194 0x1e2e0, 0x1e2e0,
2195 0x1e300, 0x1e384,
2196 0x1e3c0, 0x1e3c8,
2197 0x1e408, 0x1e40c,
2198 0x1e440, 0x1e444,
2199 0x1e44c, 0x1e44c,
2200 0x1e684, 0x1e690,
2201 0x1e6c0, 0x1e6c0,
2202 0x1e6e0, 0x1e6e0,
2203 0x1e700, 0x1e784,
2204 0x1e7c0, 0x1e7c8,
2205 0x1e808, 0x1e80c,
2206 0x1e840, 0x1e844,
2207 0x1e84c, 0x1e84c,
2208 0x1ea84, 0x1ea90,
2209 0x1eac0, 0x1eac0,
2210 0x1eae0, 0x1eae0,
2211 0x1eb00, 0x1eb84,
2212 0x1ebc0, 0x1ebc8,
2213 0x1ec08, 0x1ec0c,
2214 0x1ec40, 0x1ec44,
2215 0x1ec4c, 0x1ec4c,
2216 0x1ee84, 0x1ee90,
2217 0x1eec0, 0x1eec0,
2218 0x1eee0, 0x1eee0,
2219 0x1ef00, 0x1ef84,
2220 0x1efc0, 0x1efc8,
2221 0x1f008, 0x1f00c,
2222 0x1f040, 0x1f044,
2223 0x1f04c, 0x1f04c,
2224 0x1f284, 0x1f290,
2225 0x1f2c0, 0x1f2c0,
2226 0x1f2e0, 0x1f2e0,
2227 0x1f300, 0x1f384,
2228 0x1f3c0, 0x1f3c8,
2229 0x1f408, 0x1f40c,
2230 0x1f440, 0x1f444,
2231 0x1f44c, 0x1f44c,
2232 0x1f684, 0x1f690,
2233 0x1f6c0, 0x1f6c0,
2234 0x1f6e0, 0x1f6e0,
2235 0x1f700, 0x1f784,
2236 0x1f7c0, 0x1f7c8,
2237 0x1f808, 0x1f80c,
2238 0x1f840, 0x1f844,
2239 0x1f84c, 0x1f84c,
2240 0x1fa84, 0x1fa90,
2241 0x1fac0, 0x1fac0,
2242 0x1fae0, 0x1fae0,
2243 0x1fb00, 0x1fb84,
2244 0x1fbc0, 0x1fbc8,
2245 0x1fc08, 0x1fc0c,
2246 0x1fc40, 0x1fc44,
2247 0x1fc4c, 0x1fc4c,
2248 0x1fe84, 0x1fe90,
2249 0x1fec0, 0x1fec0,
2250 0x1fee0, 0x1fee0,
2251 0x1ff00, 0x1ff84,
2252 0x1ffc0, 0x1ffc8,
2253 0x30000, 0x30030,
2254 0x30100, 0x30168,
2255 0x30190, 0x301a0,
2256 0x301a8, 0x301b8,
2257 0x301c4, 0x301c8,
2258 0x301d0, 0x301d0,
2259 0x30200, 0x30320,
2260 0x30400, 0x304b4,
2261 0x304c0, 0x3052c,
2262 0x30540, 0x3061c,
2263 0x30800, 0x308a0,
2264 0x308c0, 0x30908,
2265 0x30910, 0x309b8,
2266 0x30a00, 0x30a04,
2267 0x30a0c, 0x30a14,
2268 0x30a1c, 0x30a2c,
2269 0x30a44, 0x30a50,
2270 0x30a74, 0x30a74,
2271 0x30a7c, 0x30afc,
2272 0x30b08, 0x30c24,
2273 0x30d00, 0x30d14,
2274 0x30d1c, 0x30d3c,
2275 0x30d44, 0x30d4c,
2276 0x30d54, 0x30d74,
2277 0x30d7c, 0x30d7c,
2278 0x30de0, 0x30de0,
2279 0x30e00, 0x30ed4,
2280 0x30f00, 0x30fa4,
2281 0x30fc0, 0x30fc4,
2282 0x31000, 0x31004,
2283 0x31080, 0x310fc,
2284 0x31208, 0x31220,
2285 0x3123c, 0x31254,
2286 0x31300, 0x31300,
2287 0x31308, 0x3131c,
2288 0x31338, 0x3133c,
2289 0x31380, 0x31380,
2290 0x31388, 0x313a8,
2291 0x313b4, 0x313b4,
2292 0x31400, 0x31420,
2293 0x31438, 0x3143c,
2294 0x31480, 0x31480,
2295 0x314a8, 0x314a8,
2296 0x314b0, 0x314b4,
2297 0x314c8, 0x314d4,
2298 0x31a40, 0x31a4c,
2299 0x31af0, 0x31b20,
2300 0x31b38, 0x31b3c,
2301 0x31b80, 0x31b80,
2302 0x31ba8, 0x31ba8,
2303 0x31bb0, 0x31bb4,
2304 0x31bc8, 0x31bd4,
2305 0x32140, 0x3218c,
2306 0x321f0, 0x321f4,
2307 0x32200, 0x32200,
2308 0x32218, 0x32218,
2309 0x32400, 0x32400,
2310 0x32408, 0x3241c,
2311 0x32618, 0x32620,
2312 0x32664, 0x32664,
2313 0x326a8, 0x326a8,
2314 0x326ec, 0x326ec,
2315 0x32a00, 0x32abc,
2316 0x32b00, 0x32b18,
2317 0x32b20, 0x32b38,
2318 0x32b40, 0x32b58,
2319 0x32b60, 0x32b78,
2320 0x32c00, 0x32c00,
2321 0x32c08, 0x32c3c,
2322 0x33000, 0x3302c,
2323 0x33034, 0x33050,
2324 0x33058, 0x33058,
2325 0x33060, 0x3308c,
2326 0x3309c, 0x330ac,
2327 0x330c0, 0x330c0,
2328 0x330c8, 0x330d0,
2329 0x330d8, 0x330e0,
2330 0x330ec, 0x3312c,
2331 0x33134, 0x33150,
2332 0x33158, 0x33158,
2333 0x33160, 0x3318c,
2334 0x3319c, 0x331ac,
2335 0x331c0, 0x331c0,
2336 0x331c8, 0x331d0,
2337 0x331d8, 0x331e0,
2338 0x331ec, 0x33290,
2339 0x33298, 0x332c4,
2340 0x332e4, 0x33390,
2341 0x33398, 0x333c4,
2342 0x333e4, 0x3342c,
2343 0x33434, 0x33450,
2344 0x33458, 0x33458,
2345 0x33460, 0x3348c,
2346 0x3349c, 0x334ac,
2347 0x334c0, 0x334c0,
2348 0x334c8, 0x334d0,
2349 0x334d8, 0x334e0,
2350 0x334ec, 0x3352c,
2351 0x33534, 0x33550,
2352 0x33558, 0x33558,
2353 0x33560, 0x3358c,
2354 0x3359c, 0x335ac,
2355 0x335c0, 0x335c0,
2356 0x335c8, 0x335d0,
2357 0x335d8, 0x335e0,
2358 0x335ec, 0x33690,
2359 0x33698, 0x336c4,
2360 0x336e4, 0x33790,
2361 0x33798, 0x337c4,
2362 0x337e4, 0x337fc,
2363 0x33814, 0x33814,
2364 0x33854, 0x33868,
2365 0x33880, 0x3388c,
2366 0x338c0, 0x338d0,
2367 0x338e8, 0x338ec,
2368 0x33900, 0x3392c,
2369 0x33934, 0x33950,
2370 0x33958, 0x33958,
2371 0x33960, 0x3398c,
2372 0x3399c, 0x339ac,
2373 0x339c0, 0x339c0,
2374 0x339c8, 0x339d0,
2375 0x339d8, 0x339e0,
2376 0x339ec, 0x33a90,
2377 0x33a98, 0x33ac4,
2378 0x33ae4, 0x33b10,
2379 0x33b24, 0x33b28,
2380 0x33b38, 0x33b50,
2381 0x33bf0, 0x33c10,
2382 0x33c24, 0x33c28,
2383 0x33c38, 0x33c50,
2384 0x33cf0, 0x33cfc,
2385 0x34000, 0x34030,
2386 0x34100, 0x34168,
2387 0x34190, 0x341a0,
2388 0x341a8, 0x341b8,
2389 0x341c4, 0x341c8,
2390 0x341d0, 0x341d0,
2391 0x34200, 0x34320,
2392 0x34400, 0x344b4,
2393 0x344c0, 0x3452c,
2394 0x34540, 0x3461c,
2395 0x34800, 0x348a0,
2396 0x348c0, 0x34908,
2397 0x34910, 0x349b8,
2398 0x34a00, 0x34a04,
2399 0x34a0c, 0x34a14,
2400 0x34a1c, 0x34a2c,
2401 0x34a44, 0x34a50,
2402 0x34a74, 0x34a74,
2403 0x34a7c, 0x34afc,
2404 0x34b08, 0x34c24,
2405 0x34d00, 0x34d14,
2406 0x34d1c, 0x34d3c,
2407 0x34d44, 0x34d4c,
2408 0x34d54, 0x34d74,
2409 0x34d7c, 0x34d7c,
2410 0x34de0, 0x34de0,
2411 0x34e00, 0x34ed4,
2412 0x34f00, 0x34fa4,
2413 0x34fc0, 0x34fc4,
2414 0x35000, 0x35004,
2415 0x35080, 0x350fc,
2416 0x35208, 0x35220,
2417 0x3523c, 0x35254,
2418 0x35300, 0x35300,
2419 0x35308, 0x3531c,
2420 0x35338, 0x3533c,
2421 0x35380, 0x35380,
2422 0x35388, 0x353a8,
2423 0x353b4, 0x353b4,
2424 0x35400, 0x35420,
2425 0x35438, 0x3543c,
2426 0x35480, 0x35480,
2427 0x354a8, 0x354a8,
2428 0x354b0, 0x354b4,
2429 0x354c8, 0x354d4,
2430 0x35a40, 0x35a4c,
2431 0x35af0, 0x35b20,
2432 0x35b38, 0x35b3c,
2433 0x35b80, 0x35b80,
2434 0x35ba8, 0x35ba8,
2435 0x35bb0, 0x35bb4,
2436 0x35bc8, 0x35bd4,
2437 0x36140, 0x3618c,
2438 0x361f0, 0x361f4,
2439 0x36200, 0x36200,
2440 0x36218, 0x36218,
2441 0x36400, 0x36400,
2442 0x36408, 0x3641c,
2443 0x36618, 0x36620,
2444 0x36664, 0x36664,
2445 0x366a8, 0x366a8,
2446 0x366ec, 0x366ec,
2447 0x36a00, 0x36abc,
2448 0x36b00, 0x36b18,
2449 0x36b20, 0x36b38,
2450 0x36b40, 0x36b58,
2451 0x36b60, 0x36b78,
2452 0x36c00, 0x36c00,
2453 0x36c08, 0x36c3c,
2454 0x37000, 0x3702c,
2455 0x37034, 0x37050,
2456 0x37058, 0x37058,
2457 0x37060, 0x3708c,
2458 0x3709c, 0x370ac,
2459 0x370c0, 0x370c0,
2460 0x370c8, 0x370d0,
2461 0x370d8, 0x370e0,
2462 0x370ec, 0x3712c,
2463 0x37134, 0x37150,
2464 0x37158, 0x37158,
2465 0x37160, 0x3718c,
2466 0x3719c, 0x371ac,
2467 0x371c0, 0x371c0,
2468 0x371c8, 0x371d0,
2469 0x371d8, 0x371e0,
2470 0x371ec, 0x37290,
2471 0x37298, 0x372c4,
2472 0x372e4, 0x37390,
2473 0x37398, 0x373c4,
2474 0x373e4, 0x3742c,
2475 0x37434, 0x37450,
2476 0x37458, 0x37458,
2477 0x37460, 0x3748c,
2478 0x3749c, 0x374ac,
2479 0x374c0, 0x374c0,
2480 0x374c8, 0x374d0,
2481 0x374d8, 0x374e0,
2482 0x374ec, 0x3752c,
2483 0x37534, 0x37550,
2484 0x37558, 0x37558,
2485 0x37560, 0x3758c,
2486 0x3759c, 0x375ac,
2487 0x375c0, 0x375c0,
2488 0x375c8, 0x375d0,
2489 0x375d8, 0x375e0,
2490 0x375ec, 0x37690,
2491 0x37698, 0x376c4,
2492 0x376e4, 0x37790,
2493 0x37798, 0x377c4,
2494 0x377e4, 0x377fc,
2495 0x37814, 0x37814,
2496 0x37854, 0x37868,
2497 0x37880, 0x3788c,
2498 0x378c0, 0x378d0,
2499 0x378e8, 0x378ec,
2500 0x37900, 0x3792c,
2501 0x37934, 0x37950,
2502 0x37958, 0x37958,
2503 0x37960, 0x3798c,
2504 0x3799c, 0x379ac,
2505 0x379c0, 0x379c0,
2506 0x379c8, 0x379d0,
2507 0x379d8, 0x379e0,
2508 0x379ec, 0x37a90,
2509 0x37a98, 0x37ac4,
2510 0x37ae4, 0x37b10,
2511 0x37b24, 0x37b28,
2512 0x37b38, 0x37b50,
2513 0x37bf0, 0x37c10,
2514 0x37c24, 0x37c28,
2515 0x37c38, 0x37c50,
2516 0x37cf0, 0x37cfc,
2517 0x40040, 0x40040,
2518 0x40080, 0x40084,
2519 0x40100, 0x40100,
2520 0x40140, 0x401bc,
2521 0x40200, 0x40214,
2522 0x40228, 0x40228,
2523 0x40240, 0x40258,
2524 0x40280, 0x40280,
2525 0x40304, 0x40304,
2526 0x40330, 0x4033c,
2527 0x41304, 0x413c8,
2528 0x413d0, 0x413dc,
2529 0x413f0, 0x413f0,
2530 0x41400, 0x4140c,
2531 0x41414, 0x4141c,
2532 0x41480, 0x414d0,
2533 0x44000, 0x4407c,
2534 0x440c0, 0x441ac,
2535 0x441b4, 0x4427c,
2536 0x442c0, 0x443ac,
2537 0x443b4, 0x4447c,
2538 0x444c0, 0x445ac,
2539 0x445b4, 0x4467c,
2540 0x446c0, 0x447ac,
2541 0x447b4, 0x4487c,
2542 0x448c0, 0x449ac,
2543 0x449b4, 0x44a7c,
2544 0x44ac0, 0x44bac,
2545 0x44bb4, 0x44c7c,
2546 0x44cc0, 0x44dac,
2547 0x44db4, 0x44e7c,
2548 0x44ec0, 0x44fac,
2549 0x44fb4, 0x4507c,
2550 0x450c0, 0x451ac,
2551 0x451b4, 0x451fc,
2552 0x45800, 0x45804,
2553 0x45810, 0x45830,
2554 0x45840, 0x45860,
2555 0x45868, 0x45868,
2556 0x45880, 0x45884,
2557 0x458a0, 0x458b0,
2558 0x45a00, 0x45a04,
2559 0x45a10, 0x45a30,
2560 0x45a40, 0x45a60,
2561 0x45a68, 0x45a68,
2562 0x45a80, 0x45a84,
2563 0x45aa0, 0x45ab0,
2564 0x460c0, 0x460e4,
2565 0x47000, 0x4703c,
2566 0x47044, 0x4708c,
2567 0x47200, 0x47250,
2568 0x47400, 0x47408,
2569 0x47414, 0x47420,
2570 0x47600, 0x47618,
2571 0x47800, 0x47814,
2572 0x47820, 0x4782c,
2573 0x50000, 0x50084,
2574 0x50090, 0x500cc,
2575 0x50300, 0x50384,
2576 0x50400, 0x50400,
2577 0x50800, 0x50884,
2578 0x50890, 0x508cc,
2579 0x50b00, 0x50b84,
2580 0x50c00, 0x50c00,
2581 0x51000, 0x51020,
2582 0x51028, 0x510b0,
2583 0x51300, 0x51324,
2584 };
2585
2586 u32 *buf_end = (u32 *)((char *)buf + buf_size);
2587 const unsigned int *reg_ranges;
2588 int reg_ranges_size, range;
2589 unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
2590
2591
2592
2593
2594 switch (chip_version) {
2595 case CHELSIO_T4:
2596 reg_ranges = t4_reg_ranges;
2597 reg_ranges_size = ARRAY_SIZE(t4_reg_ranges);
2598 break;
2599
2600 case CHELSIO_T5:
2601 reg_ranges = t5_reg_ranges;
2602 reg_ranges_size = ARRAY_SIZE(t5_reg_ranges);
2603 break;
2604
2605 case CHELSIO_T6:
2606 reg_ranges = t6_reg_ranges;
2607 reg_ranges_size = ARRAY_SIZE(t6_reg_ranges);
2608 break;
2609
2610 default:
2611 dev_err(adap->pdev_dev,
2612 "Unsupported chip version %d\n", chip_version);
2613 return;
2614 }
2615
2616
2617
2618
2619 memset(buf, 0, buf_size);
2620 for (range = 0; range < reg_ranges_size; range += 2) {
2621 unsigned int reg = reg_ranges[range];
2622 unsigned int last_reg = reg_ranges[range + 1];
2623 u32 *bufp = (u32 *)((char *)buf + reg);
2624
2625
2626
2627
2628 while (reg <= last_reg && bufp < buf_end) {
2629 *bufp++ = t4_read_reg(adap, reg);
2630 reg += sizeof(u32);
2631 }
2632 }
2633}
2634
2635#define EEPROM_STAT_ADDR 0x7bfc
2636#define VPD_SIZE 0x800
2637#define VPD_BASE 0x400
2638#define VPD_BASE_OLD 0
2639#define VPD_LEN 1024
2640#define CHELSIO_VPD_UNIQUE_ID 0x82
2641
2642
2643
2644
2645
2646
2647
2648
2649int t4_seeprom_wp(struct adapter *adapter, bool enable)
2650{
2651 unsigned int v = enable ? 0xc : 0;
2652 int ret = pci_write_vpd(adapter->pdev, EEPROM_STAT_ADDR, 4, &v);
2653 return ret < 0 ? ret : 0;
2654}
2655
2656
2657
2658
2659
2660
2661
2662
2663int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
2664{
2665 int i, ret = 0, addr;
2666 int ec, sn, pn, na;
2667 u8 *vpd, csum;
2668 unsigned int vpdr_len, kw_offset, id_len;
2669
2670 vpd = vmalloc(VPD_LEN);
2671 if (!vpd)
2672 return -ENOMEM;
2673
2674
2675
2676
2677
2678
2679 ret = pci_set_vpd_size(adapter->pdev, VPD_SIZE);
2680 if (ret < 0)
2681 goto out;
2682
2683
2684
2685
2686 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(u32), vpd);
2687 if (ret < 0)
2688 goto out;
2689
2690
2691
2692
2693
2694
2695
2696 addr = *vpd == CHELSIO_VPD_UNIQUE_ID ? VPD_BASE : VPD_BASE_OLD;
2697
2698 ret = pci_read_vpd(adapter->pdev, addr, VPD_LEN, vpd);
2699 if (ret < 0)
2700 goto out;
2701
2702 if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
2703 dev_err(adapter->pdev_dev, "missing VPD ID string\n");
2704 ret = -EINVAL;
2705 goto out;
2706 }
2707
2708 id_len = pci_vpd_lrdt_size(vpd);
2709 if (id_len > ID_LEN)
2710 id_len = ID_LEN;
2711
2712 i = pci_vpd_find_tag(vpd, 0, VPD_LEN, PCI_VPD_LRDT_RO_DATA);
2713 if (i < 0) {
2714 dev_err(adapter->pdev_dev, "missing VPD-R section\n");
2715 ret = -EINVAL;
2716 goto out;
2717 }
2718
2719 vpdr_len = pci_vpd_lrdt_size(&vpd[i]);
2720 kw_offset = i + PCI_VPD_LRDT_TAG_SIZE;
2721 if (vpdr_len + kw_offset > VPD_LEN) {
2722 dev_err(adapter->pdev_dev, "bad VPD-R length %u\n", vpdr_len);
2723 ret = -EINVAL;
2724 goto out;
2725 }
2726
2727#define FIND_VPD_KW(var, name) do { \
2728 var = pci_vpd_find_info_keyword(vpd, kw_offset, vpdr_len, name); \
2729 if (var < 0) { \
2730 dev_err(adapter->pdev_dev, "missing VPD keyword " name "\n"); \
2731 ret = -EINVAL; \
2732 goto out; \
2733 } \
2734 var += PCI_VPD_INFO_FLD_HDR_SIZE; \
2735} while (0)
2736
2737 FIND_VPD_KW(i, "RV");
2738 for (csum = 0; i >= 0; i--)
2739 csum += vpd[i];
2740
2741 if (csum) {
2742 dev_err(adapter->pdev_dev,
2743 "corrupted VPD EEPROM, actual csum %u\n", csum);
2744 ret = -EINVAL;
2745 goto out;
2746 }
2747
2748 FIND_VPD_KW(ec, "EC");
2749 FIND_VPD_KW(sn, "SN");
2750 FIND_VPD_KW(pn, "PN");
2751 FIND_VPD_KW(na, "NA");
2752#undef FIND_VPD_KW
2753
2754 memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, id_len);
2755 strim(p->id);
2756 memcpy(p->ec, vpd + ec, EC_LEN);
2757 strim(p->ec);
2758 i = pci_vpd_info_field_size(vpd + sn - PCI_VPD_INFO_FLD_HDR_SIZE);
2759 memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
2760 strim(p->sn);
2761 i = pci_vpd_info_field_size(vpd + pn - PCI_VPD_INFO_FLD_HDR_SIZE);
2762 memcpy(p->pn, vpd + pn, min(i, PN_LEN));
2763 strim(p->pn);
2764 memcpy(p->na, vpd + na, min(i, MACADDR_LEN));
2765 strim((char *)p->na);
2766
2767out:
2768 vfree(vpd);
2769 return ret < 0 ? ret : 0;
2770}
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781int t4_get_vpd_params(struct adapter *adapter, struct vpd_params *p)
2782{
2783 u32 cclk_param, cclk_val;
2784 int ret;
2785
2786
2787
2788 ret = t4_get_raw_vpd_params(adapter, p);
2789 if (ret)
2790 return ret;
2791
2792
2793
2794
2795 cclk_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
2796 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CCLK));
2797 ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
2798 1, &cclk_param, &cclk_val);
2799
2800 if (ret)
2801 return ret;
2802 p->cclk = cclk_val;
2803
2804 return 0;
2805}
2806
2807
2808enum {
2809 SF_ATTEMPTS = 10,
2810
2811
2812 SF_PROG_PAGE = 2,
2813 SF_WR_DISABLE = 4,
2814 SF_RD_STATUS = 5,
2815 SF_WR_ENABLE = 6,
2816 SF_RD_DATA_FAST = 0xb,
2817 SF_RD_ID = 0x9f,
2818 SF_ERASE_SECTOR = 0xd8,
2819
2820 FW_MAX_SIZE = 16 * SF_SEC_SIZE,
2821};
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
2836 int lock, u32 *valp)
2837{
2838 int ret;
2839
2840 if (!byte_cnt || byte_cnt > 4)
2841 return -EINVAL;
2842 if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
2843 return -EBUSY;
2844 t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
2845 SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1));
2846 ret = t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
2847 if (!ret)
2848 *valp = t4_read_reg(adapter, SF_DATA_A);
2849 return ret;
2850}
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
2865 int lock, u32 val)
2866{
2867 if (!byte_cnt || byte_cnt > 4)
2868 return -EINVAL;
2869 if (t4_read_reg(adapter, SF_OP_A) & SF_BUSY_F)
2870 return -EBUSY;
2871 t4_write_reg(adapter, SF_DATA_A, val);
2872 t4_write_reg(adapter, SF_OP_A, SF_LOCK_V(lock) |
2873 SF_CONT_V(cont) | BYTECNT_V(byte_cnt - 1) | OP_V(1));
2874 return t4_wait_op_done(adapter, SF_OP_A, SF_BUSY_F, 0, SF_ATTEMPTS, 5);
2875}
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
2886{
2887 int ret;
2888 u32 status;
2889
2890 while (1) {
2891 if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
2892 (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
2893 return ret;
2894 if (!(status & 1))
2895 return 0;
2896 if (--attempts == 0)
2897 return -EAGAIN;
2898 if (delay)
2899 msleep(delay);
2900 }
2901}
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916int t4_read_flash(struct adapter *adapter, unsigned int addr,
2917 unsigned int nwords, u32 *data, int byte_oriented)
2918{
2919 int ret;
2920
2921 if (addr + nwords * sizeof(u32) > adapter->params.sf_size || (addr & 3))
2922 return -EINVAL;
2923
2924 addr = swab32(addr) | SF_RD_DATA_FAST;
2925
2926 if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
2927 (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
2928 return ret;
2929
2930 for ( ; nwords; nwords--, data++) {
2931 ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
2932 if (nwords == 1)
2933 t4_write_reg(adapter, SF_OP_A, 0);
2934 if (ret)
2935 return ret;
2936 if (byte_oriented)
2937 *data = (__force __u32)(cpu_to_be32(*data));
2938 }
2939 return 0;
2940}
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952static int t4_write_flash(struct adapter *adapter, unsigned int addr,
2953 unsigned int n, const u8 *data)
2954{
2955 int ret;
2956 u32 buf[64];
2957 unsigned int i, c, left, val, offset = addr & 0xff;
2958
2959 if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
2960 return -EINVAL;
2961
2962 val = swab32(addr) | SF_PROG_PAGE;
2963
2964 if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
2965 (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
2966 goto unlock;
2967
2968 for (left = n; left; left -= c) {
2969 c = min(left, 4U);
2970 for (val = 0, i = 0; i < c; ++i)
2971 val = (val << 8) + *data++;
2972
2973 ret = sf1_write(adapter, c, c != left, 1, val);
2974 if (ret)
2975 goto unlock;
2976 }
2977 ret = flash_wait_op(adapter, 8, 1);
2978 if (ret)
2979 goto unlock;
2980
2981 t4_write_reg(adapter, SF_OP_A, 0);
2982
2983
2984 ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
2985 if (ret)
2986 return ret;
2987
2988 if (memcmp(data - n, (u8 *)buf + offset, n)) {
2989 dev_err(adapter->pdev_dev,
2990 "failed to correctly write the flash page at %#x\n",
2991 addr);
2992 return -EIO;
2993 }
2994 return 0;
2995
2996unlock:
2997 t4_write_reg(adapter, SF_OP_A, 0);
2998 return ret;
2999}
3000
3001
3002
3003
3004
3005
3006
3007
3008int t4_get_fw_version(struct adapter *adapter, u32 *vers)
3009{
3010 return t4_read_flash(adapter, FLASH_FW_START +
3011 offsetof(struct fw_hdr, fw_ver), 1,
3012 vers, 0);
3013}
3014
3015
3016
3017
3018
3019
3020
3021
3022int t4_get_bs_version(struct adapter *adapter, u32 *vers)
3023{
3024 return t4_read_flash(adapter, FLASH_FWBOOTSTRAP_START +
3025 offsetof(struct fw_hdr, fw_ver), 1,
3026 vers, 0);
3027}
3028
3029
3030
3031
3032
3033
3034
3035
3036int t4_get_tp_version(struct adapter *adapter, u32 *vers)
3037{
3038 return t4_read_flash(adapter, FLASH_FW_START +
3039 offsetof(struct fw_hdr, tp_microcode_ver),
3040 1, vers, 0);
3041}
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053int t4_get_exprom_version(struct adapter *adap, u32 *vers)
3054{
3055 struct exprom_header {
3056 unsigned char hdr_arr[16];
3057 unsigned char hdr_ver[4];
3058 } *hdr;
3059 u32 exprom_header_buf[DIV_ROUND_UP(sizeof(struct exprom_header),
3060 sizeof(u32))];
3061 int ret;
3062
3063 ret = t4_read_flash(adap, FLASH_EXP_ROM_START,
3064 ARRAY_SIZE(exprom_header_buf), exprom_header_buf,
3065 0);
3066 if (ret)
3067 return ret;
3068
3069 hdr = (struct exprom_header *)exprom_header_buf;
3070 if (hdr->hdr_arr[0] != 0x55 || hdr->hdr_arr[1] != 0xaa)
3071 return -ENOENT;
3072
3073 *vers = (FW_HDR_FW_VER_MAJOR_V(hdr->hdr_ver[0]) |
3074 FW_HDR_FW_VER_MINOR_V(hdr->hdr_ver[1]) |
3075 FW_HDR_FW_VER_MICRO_V(hdr->hdr_ver[2]) |
3076 FW_HDR_FW_VER_BUILD_V(hdr->hdr_ver[3]));
3077 return 0;
3078}
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101int t4_get_vpd_version(struct adapter *adapter, u32 *vers)
3102{
3103 u32 vpdrev_param;
3104 int ret;
3105
3106 vpdrev_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3107 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_VPDREV));
3108 ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
3109 1, &vpdrev_param, vers);
3110 if (ret)
3111 *vers = 0;
3112 return ret;
3113}
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138int t4_get_scfg_version(struct adapter *adapter, u32 *vers)
3139{
3140 u32 scfgrev_param;
3141 int ret;
3142
3143 scfgrev_param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3144 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_SCFGREV));
3145 ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
3146 1, &scfgrev_param, vers);
3147 if (ret)
3148 *vers = 0;
3149 return ret;
3150}
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161int t4_get_version_info(struct adapter *adapter)
3162{
3163 int ret = 0;
3164
3165 #define FIRST_RET(__getvinfo) \
3166 do { \
3167 int __ret = __getvinfo; \
3168 if (__ret && !ret) \
3169 ret = __ret; \
3170 } while (0)
3171
3172 FIRST_RET(t4_get_fw_version(adapter, &adapter->params.fw_vers));
3173 FIRST_RET(t4_get_bs_version(adapter, &adapter->params.bs_vers));
3174 FIRST_RET(t4_get_tp_version(adapter, &adapter->params.tp_vers));
3175 FIRST_RET(t4_get_exprom_version(adapter, &adapter->params.er_vers));
3176 FIRST_RET(t4_get_scfg_version(adapter, &adapter->params.scfg_vers));
3177 FIRST_RET(t4_get_vpd_version(adapter, &adapter->params.vpd_vers));
3178
3179 #undef FIRST_RET
3180 return ret;
3181}
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191void t4_dump_version_info(struct adapter *adapter)
3192{
3193
3194 dev_info(adapter->pdev_dev, "Chelsio %s rev %d\n",
3195 adapter->params.vpd.id,
3196 CHELSIO_CHIP_RELEASE(adapter->params.chip));
3197 dev_info(adapter->pdev_dev, "S/N: %s, P/N: %s\n",
3198 adapter->params.vpd.sn, adapter->params.vpd.pn);
3199
3200
3201 if (!adapter->params.fw_vers)
3202 dev_warn(adapter->pdev_dev, "No firmware loaded\n");
3203 else
3204 dev_info(adapter->pdev_dev, "Firmware version: %u.%u.%u.%u\n",
3205 FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
3206 FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
3207 FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
3208 FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers));
3209
3210
3211
3212
3213 if (!adapter->params.bs_vers)
3214 dev_info(adapter->pdev_dev, "No bootstrap loaded\n");
3215 else
3216 dev_info(adapter->pdev_dev, "Bootstrap version: %u.%u.%u.%u\n",
3217 FW_HDR_FW_VER_MAJOR_G(adapter->params.bs_vers),
3218 FW_HDR_FW_VER_MINOR_G(adapter->params.bs_vers),
3219 FW_HDR_FW_VER_MICRO_G(adapter->params.bs_vers),
3220 FW_HDR_FW_VER_BUILD_G(adapter->params.bs_vers));
3221
3222
3223 if (!adapter->params.tp_vers)
3224 dev_warn(adapter->pdev_dev, "No TP Microcode loaded\n");
3225 else
3226 dev_info(adapter->pdev_dev,
3227 "TP Microcode version: %u.%u.%u.%u\n",
3228 FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
3229 FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
3230 FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
3231 FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
3232
3233
3234 if (!adapter->params.er_vers)
3235 dev_info(adapter->pdev_dev, "No Expansion ROM loaded\n");
3236 else
3237 dev_info(adapter->pdev_dev,
3238 "Expansion ROM version: %u.%u.%u.%u\n",
3239 FW_HDR_FW_VER_MAJOR_G(adapter->params.er_vers),
3240 FW_HDR_FW_VER_MINOR_G(adapter->params.er_vers),
3241 FW_HDR_FW_VER_MICRO_G(adapter->params.er_vers),
3242 FW_HDR_FW_VER_BUILD_G(adapter->params.er_vers));
3243
3244
3245 dev_info(adapter->pdev_dev, "Serial Configuration version: %#x\n",
3246 adapter->params.scfg_vers);
3247
3248
3249 dev_info(adapter->pdev_dev, "VPD version: %#x\n",
3250 adapter->params.vpd_vers);
3251}
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261int t4_check_fw_version(struct adapter *adap)
3262{
3263 int i, ret, major, minor, micro;
3264 int exp_major, exp_minor, exp_micro;
3265 unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
3266
3267 ret = t4_get_fw_version(adap, &adap->params.fw_vers);
3268
3269 for (i = 0; (ret == -EBUSY || ret == -EAGAIN) && i < 3; i++)
3270 ret = t4_get_fw_version(adap, &adap->params.fw_vers);
3271
3272 if (ret)
3273 return ret;
3274
3275 major = FW_HDR_FW_VER_MAJOR_G(adap->params.fw_vers);
3276 minor = FW_HDR_FW_VER_MINOR_G(adap->params.fw_vers);
3277 micro = FW_HDR_FW_VER_MICRO_G(adap->params.fw_vers);
3278
3279 switch (chip_version) {
3280 case CHELSIO_T4:
3281 exp_major = T4FW_MIN_VERSION_MAJOR;
3282 exp_minor = T4FW_MIN_VERSION_MINOR;
3283 exp_micro = T4FW_MIN_VERSION_MICRO;
3284 break;
3285 case CHELSIO_T5:
3286 exp_major = T5FW_MIN_VERSION_MAJOR;
3287 exp_minor = T5FW_MIN_VERSION_MINOR;
3288 exp_micro = T5FW_MIN_VERSION_MICRO;
3289 break;
3290 case CHELSIO_T6:
3291 exp_major = T6FW_MIN_VERSION_MAJOR;
3292 exp_minor = T6FW_MIN_VERSION_MINOR;
3293 exp_micro = T6FW_MIN_VERSION_MICRO;
3294 break;
3295 default:
3296 dev_err(adap->pdev_dev, "Unsupported chip type, %x\n",
3297 adap->chip);
3298 return -EINVAL;
3299 }
3300
3301 if (major < exp_major || (major == exp_major && minor < exp_minor) ||
3302 (major == exp_major && minor == exp_minor && micro < exp_micro)) {
3303 dev_err(adap->pdev_dev,
3304 "Card has firmware version %u.%u.%u, minimum "
3305 "supported firmware is %u.%u.%u.\n", major, minor,
3306 micro, exp_major, exp_minor, exp_micro);
3307 return -EFAULT;
3308 }
3309 return 0;
3310}
3311
3312
3313
3314
3315static int fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
3316{
3317
3318
3319 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
3320 return 1;
3321
3322#define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
3323 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
3324 SAME_INTF(ri) && SAME_INTF(iscsi) && SAME_INTF(fcoe))
3325 return 1;
3326#undef SAME_INTF
3327
3328 return 0;
3329}
3330
3331
3332
3333
3334
3335static int should_install_fs_fw(struct adapter *adap, int card_fw_usable,
3336 int k, int c)
3337{
3338 const char *reason;
3339
3340 if (!card_fw_usable) {
3341 reason = "incompatible or unusable";
3342 goto install;
3343 }
3344
3345 if (k > c) {
3346 reason = "older than the version supported with this driver";
3347 goto install;
3348 }
3349
3350 return 0;
3351
3352install:
3353 dev_err(adap->pdev_dev, "firmware on card (%u.%u.%u.%u) is %s, "
3354 "installing firmware %u.%u.%u.%u on card.\n",
3355 FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
3356 FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
3357 FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
3358 FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
3359
3360 return 1;
3361}
3362
3363int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
3364 const u8 *fw_data, unsigned int fw_size,
3365 struct fw_hdr *card_fw, enum dev_state state,
3366 int *reset)
3367{
3368 int ret, card_fw_usable, fs_fw_usable;
3369 const struct fw_hdr *fs_fw;
3370 const struct fw_hdr *drv_fw;
3371
3372 drv_fw = &fw_info->fw_hdr;
3373
3374
3375 ret = -t4_read_flash(adap, FLASH_FW_START,
3376 sizeof(*card_fw) / sizeof(uint32_t),
3377 (uint32_t *)card_fw, 1);
3378 if (ret == 0) {
3379 card_fw_usable = fw_compatible(drv_fw, (const void *)card_fw);
3380 } else {
3381 dev_err(adap->pdev_dev,
3382 "Unable to read card's firmware header: %d\n", ret);
3383 card_fw_usable = 0;
3384 }
3385
3386 if (fw_data != NULL) {
3387 fs_fw = (const void *)fw_data;
3388 fs_fw_usable = fw_compatible(drv_fw, fs_fw);
3389 } else {
3390 fs_fw = NULL;
3391 fs_fw_usable = 0;
3392 }
3393
3394 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
3395 (!fs_fw_usable || fs_fw->fw_ver == drv_fw->fw_ver)) {
3396
3397
3398
3399
3400 } else if (fs_fw_usable && state == DEV_STATE_UNINIT &&
3401 should_install_fs_fw(adap, card_fw_usable,
3402 be32_to_cpu(fs_fw->fw_ver),
3403 be32_to_cpu(card_fw->fw_ver))) {
3404 ret = -t4_fw_upgrade(adap, adap->mbox, fw_data,
3405 fw_size, 0);
3406 if (ret != 0) {
3407 dev_err(adap->pdev_dev,
3408 "failed to install firmware: %d\n", ret);
3409 goto bye;
3410 }
3411
3412
3413 *card_fw = *fs_fw;
3414 card_fw_usable = 1;
3415 *reset = 0;
3416 }
3417
3418 if (!card_fw_usable) {
3419 uint32_t d, c, k;
3420
3421 d = be32_to_cpu(drv_fw->fw_ver);
3422 c = be32_to_cpu(card_fw->fw_ver);
3423 k = fs_fw ? be32_to_cpu(fs_fw->fw_ver) : 0;
3424
3425 dev_err(adap->pdev_dev, "Cannot find a usable firmware: "
3426 "chip state %d, "
3427 "driver compiled with %d.%d.%d.%d, "
3428 "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
3429 state,
3430 FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
3431 FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
3432 FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
3433 FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
3434 FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
3435 FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
3436 ret = EINVAL;
3437 goto bye;
3438 }
3439
3440
3441 adap->params.fw_vers = be32_to_cpu(card_fw->fw_ver);
3442 adap->params.tp_vers = be32_to_cpu(card_fw->tp_microcode_ver);
3443
3444bye:
3445 return ret;
3446}
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456static int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
3457{
3458 int ret = 0;
3459
3460 if (end >= adapter->params.sf_nsec)
3461 return -EINVAL;
3462
3463 while (start <= end) {
3464 if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
3465 (ret = sf1_write(adapter, 4, 0, 1,
3466 SF_ERASE_SECTOR | (start << 8))) != 0 ||
3467 (ret = flash_wait_op(adapter, 14, 500)) != 0) {
3468 dev_err(adapter->pdev_dev,
3469 "erase of flash sector %d failed, error %d\n",
3470 start, ret);
3471 break;
3472 }
3473 start++;
3474 }
3475 t4_write_reg(adapter, SF_OP_A, 0);
3476 return ret;
3477}
3478
3479
3480
3481
3482
3483
3484
3485
3486unsigned int t4_flash_cfg_addr(struct adapter *adapter)
3487{
3488 if (adapter->params.sf_size == 0x100000)
3489 return FLASH_FPGA_CFG_START;
3490 else
3491 return FLASH_CFG_START;
3492}
3493
3494
3495
3496
3497
3498
3499static bool t4_fw_matches_chip(const struct adapter *adap,
3500 const struct fw_hdr *hdr)
3501{
3502
3503
3504
3505 if ((is_t4(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T4) ||
3506 (is_t5(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T5) ||
3507 (is_t6(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T6))
3508 return true;
3509
3510 dev_err(adap->pdev_dev,
3511 "FW image (%d) is not suitable for this adapter (%d)\n",
3512 hdr->chip, CHELSIO_CHIP_VERSION(adap->params.chip));
3513 return false;
3514}
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
3525{
3526 u32 csum;
3527 int ret, addr;
3528 unsigned int i;
3529 u8 first_page[SF_PAGE_SIZE];
3530 const __be32 *p = (const __be32 *)fw_data;
3531 const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
3532 unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
3533 unsigned int fw_img_start = adap->params.sf_fw_start;
3534 unsigned int fw_start_sec = fw_img_start / sf_sec_size;
3535
3536 if (!size) {
3537 dev_err(adap->pdev_dev, "FW image has no data\n");
3538 return -EINVAL;
3539 }
3540 if (size & 511) {
3541 dev_err(adap->pdev_dev,
3542 "FW image size not multiple of 512 bytes\n");
3543 return -EINVAL;
3544 }
3545 if ((unsigned int)be16_to_cpu(hdr->len512) * 512 != size) {
3546 dev_err(adap->pdev_dev,
3547 "FW image size differs from size in FW header\n");
3548 return -EINVAL;
3549 }
3550 if (size > FW_MAX_SIZE) {
3551 dev_err(adap->pdev_dev, "FW image too large, max is %u bytes\n",
3552 FW_MAX_SIZE);
3553 return -EFBIG;
3554 }
3555 if (!t4_fw_matches_chip(adap, hdr))
3556 return -EINVAL;
3557
3558 for (csum = 0, i = 0; i < size / sizeof(csum); i++)
3559 csum += be32_to_cpu(p[i]);
3560
3561 if (csum != 0xffffffff) {
3562 dev_err(adap->pdev_dev,
3563 "corrupted firmware image, checksum %#x\n", csum);
3564 return -EINVAL;
3565 }
3566
3567 i = DIV_ROUND_UP(size, sf_sec_size);
3568 ret = t4_flash_erase_sectors(adap, fw_start_sec, fw_start_sec + i - 1);
3569 if (ret)
3570 goto out;
3571
3572
3573
3574
3575
3576
3577 memcpy(first_page, fw_data, SF_PAGE_SIZE);
3578 ((struct fw_hdr *)first_page)->fw_ver = cpu_to_be32(0xffffffff);
3579 ret = t4_write_flash(adap, fw_img_start, SF_PAGE_SIZE, first_page);
3580 if (ret)
3581 goto out;
3582
3583 addr = fw_img_start;
3584 for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
3585 addr += SF_PAGE_SIZE;
3586 fw_data += SF_PAGE_SIZE;
3587 ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data);
3588 if (ret)
3589 goto out;
3590 }
3591
3592 ret = t4_write_flash(adap,
3593 fw_img_start + offsetof(struct fw_hdr, fw_ver),
3594 sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver);
3595out:
3596 if (ret)
3597 dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
3598 ret);
3599 else
3600 ret = t4_get_fw_version(adap, &adap->params.fw_vers);
3601 return ret;
3602}
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612int t4_phy_fw_ver(struct adapter *adap, int *phy_fw_ver)
3613{
3614 u32 param, val;
3615 int ret;
3616
3617 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3618 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
3619 FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
3620 FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_VERSION));
3621 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
3622 ¶m, &val);
3623 if (ret < 0)
3624 return ret;
3625 *phy_fw_ver = val;
3626 return 0;
3627}
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656int t4_load_phy_fw(struct adapter *adap,
3657 int win, spinlock_t *win_lock,
3658 int (*phy_fw_version)(const u8 *, size_t),
3659 const u8 *phy_fw_data, size_t phy_fw_size)
3660{
3661 unsigned long mtype = 0, maddr = 0;
3662 u32 param, val;
3663 int cur_phy_fw_ver = 0, new_phy_fw_vers = 0;
3664 int ret;
3665
3666
3667
3668
3669 if (phy_fw_version) {
3670 new_phy_fw_vers = phy_fw_version(phy_fw_data, phy_fw_size);
3671 ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
3672 if (ret < 0)
3673 return ret;
3674
3675 if (cur_phy_fw_ver >= new_phy_fw_vers) {
3676 CH_WARN(adap, "PHY Firmware already up-to-date, "
3677 "version %#x\n", cur_phy_fw_ver);
3678 return 0;
3679 }
3680 }
3681
3682
3683
3684
3685
3686
3687
3688 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3689 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
3690 FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
3691 FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
3692 val = phy_fw_size;
3693 ret = t4_query_params_rw(adap, adap->mbox, adap->pf, 0, 1,
3694 ¶m, &val, 1, true);
3695 if (ret < 0)
3696 return ret;
3697 mtype = val >> 8;
3698 maddr = (val & 0xff) << 16;
3699
3700
3701
3702
3703 if (win_lock)
3704 spin_lock_bh(win_lock);
3705 ret = t4_memory_rw(adap, win, mtype, maddr,
3706 phy_fw_size, (__be32 *)phy_fw_data,
3707 T4_MEMORY_WRITE);
3708 if (win_lock)
3709 spin_unlock_bh(win_lock);
3710 if (ret)
3711 return ret;
3712
3713
3714
3715
3716
3717
3718 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3719 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PHYFW) |
3720 FW_PARAMS_PARAM_Y_V(adap->params.portvec) |
3721 FW_PARAMS_PARAM_Z_V(FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD));
3722 ret = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
3723 ¶m, &val, 30000);
3724
3725
3726
3727
3728 if (phy_fw_version) {
3729 ret = t4_phy_fw_ver(adap, &cur_phy_fw_ver);
3730 if (ret < 0)
3731 return ret;
3732
3733 if (cur_phy_fw_ver != new_phy_fw_vers) {
3734 CH_WARN(adap, "PHY Firmware did not update: "
3735 "version on adapter %#x, "
3736 "version flashed %#x\n",
3737 cur_phy_fw_ver, new_phy_fw_vers);
3738 return -ENXIO;
3739 }
3740 }
3741
3742 return 1;
3743}
3744
3745
3746
3747
3748
3749
3750int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op)
3751{
3752 struct fw_params_cmd c;
3753
3754 memset(&c, 0, sizeof(c));
3755 c.op_to_vfn =
3756 cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
3757 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
3758 FW_PARAMS_CMD_PFN_V(adap->pf) |
3759 FW_PARAMS_CMD_VFN_V(0));
3760 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
3761 c.param[0].mnem =
3762 cpu_to_be32(FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3763 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FWCACHE));
3764 c.param[0].val = (__force __be32)op;
3765
3766 return t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), NULL);
3767}
3768
3769void t4_cim_read_pif_la(struct adapter *adap, u32 *pif_req, u32 *pif_rsp,
3770 unsigned int *pif_req_wrptr,
3771 unsigned int *pif_rsp_wrptr)
3772{
3773 int i, j;
3774 u32 cfg, val, req, rsp;
3775
3776 cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
3777 if (cfg & LADBGEN_F)
3778 t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
3779
3780 val = t4_read_reg(adap, CIM_DEBUGSTS_A);
3781 req = POLADBGWRPTR_G(val);
3782 rsp = PILADBGWRPTR_G(val);
3783 if (pif_req_wrptr)
3784 *pif_req_wrptr = req;
3785 if (pif_rsp_wrptr)
3786 *pif_rsp_wrptr = rsp;
3787
3788 for (i = 0; i < CIM_PIFLA_SIZE; i++) {
3789 for (j = 0; j < 6; j++) {
3790 t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(req) |
3791 PILADBGRDPTR_V(rsp));
3792 *pif_req++ = t4_read_reg(adap, CIM_PO_LA_DEBUGDATA_A);
3793 *pif_rsp++ = t4_read_reg(adap, CIM_PI_LA_DEBUGDATA_A);
3794 req++;
3795 rsp++;
3796 }
3797 req = (req + 2) & POLADBGRDPTR_M;
3798 rsp = (rsp + 2) & PILADBGRDPTR_M;
3799 }
3800 t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
3801}
3802
3803void t4_cim_read_ma_la(struct adapter *adap, u32 *ma_req, u32 *ma_rsp)
3804{
3805 u32 cfg;
3806 int i, j, idx;
3807
3808 cfg = t4_read_reg(adap, CIM_DEBUGCFG_A);
3809 if (cfg & LADBGEN_F)
3810 t4_write_reg(adap, CIM_DEBUGCFG_A, cfg ^ LADBGEN_F);
3811
3812 for (i = 0; i < CIM_MALA_SIZE; i++) {
3813 for (j = 0; j < 5; j++) {
3814 idx = 8 * i + j;
3815 t4_write_reg(adap, CIM_DEBUGCFG_A, POLADBGRDPTR_V(idx) |
3816 PILADBGRDPTR_V(idx));
3817 *ma_req++ = t4_read_reg(adap, CIM_PO_LA_MADEBUGDATA_A);
3818 *ma_rsp++ = t4_read_reg(adap, CIM_PI_LA_MADEBUGDATA_A);
3819 }
3820 }
3821 t4_write_reg(adap, CIM_DEBUGCFG_A, cfg);
3822}
3823
3824void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf)
3825{
3826 unsigned int i, j;
3827
3828 for (i = 0; i < 8; i++) {
3829 u32 *p = la_buf + i;
3830
3831 t4_write_reg(adap, ULP_RX_LA_CTL_A, i);
3832 j = t4_read_reg(adap, ULP_RX_LA_WRPTR_A);
3833 t4_write_reg(adap, ULP_RX_LA_RDPTR_A, j);
3834 for (j = 0; j < ULPRX_LA_SIZE; j++, p += 8)
3835 *p = t4_read_reg(adap, ULP_RX_LA_RDDATA_A);
3836 }
3837}
3838
3839#define ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
3840 FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_SPEED_25G | \
3841 FW_PORT_CAP_SPEED_40G | FW_PORT_CAP_SPEED_100G | \
3842 FW_PORT_CAP_ANEG)
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
3858 struct link_config *lc)
3859{
3860 struct fw_port_cmd c;
3861 unsigned int mdi = FW_PORT_CAP_MDI_V(FW_PORT_CAP_MDI_AUTO);
3862 unsigned int fc = 0, fec = 0, fw_fec = 0;
3863
3864 lc->link_ok = 0;
3865 if (lc->requested_fc & PAUSE_RX)
3866 fc |= FW_PORT_CAP_FC_RX;
3867 if (lc->requested_fc & PAUSE_TX)
3868 fc |= FW_PORT_CAP_FC_TX;
3869
3870 fec = lc->requested_fec & FEC_AUTO ? lc->auto_fec : lc->requested_fec;
3871
3872 if (fec & FEC_RS)
3873 fw_fec |= FW_PORT_CAP_FEC_RS;
3874 if (fec & FEC_BASER_RS)
3875 fw_fec |= FW_PORT_CAP_FEC_BASER_RS;
3876
3877 memset(&c, 0, sizeof(c));
3878 c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
3879 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
3880 FW_PORT_CMD_PORTID_V(port));
3881 c.action_to_len16 =
3882 cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
3883 FW_LEN16(c));
3884
3885 if (!(lc->supported & FW_PORT_CAP_ANEG)) {
3886 c.u.l1cfg.rcap = cpu_to_be32((lc->supported & ADVERT_MASK) |
3887 fc | fw_fec);
3888 lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
3889 } else if (lc->autoneg == AUTONEG_DISABLE) {
3890 c.u.l1cfg.rcap = cpu_to_be32(lc->requested_speed | fc |
3891 fw_fec | mdi);
3892 lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
3893 } else
3894 c.u.l1cfg.rcap = cpu_to_be32(lc->advertising | fc |
3895 fw_fec | mdi);
3896
3897 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
3898}
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
3909{
3910 struct fw_port_cmd c;
3911
3912 memset(&c, 0, sizeof(c));
3913 c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
3914 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
3915 FW_PORT_CMD_PORTID_V(port));
3916 c.action_to_len16 =
3917 cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
3918 FW_LEN16(c));
3919 c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP_ANEG);
3920 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
3921}
3922
3923typedef void (*int_handler_t)(struct adapter *adap);
3924
3925struct intr_info {
3926 unsigned int mask;
3927 const char *msg;
3928 short stat_idx;
3929 unsigned short fatal;
3930 int_handler_t int_handler;
3931};
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946static int t4_handle_intr_status(struct adapter *adapter, unsigned int reg,
3947 const struct intr_info *acts)
3948{
3949 int fatal = 0;
3950 unsigned int mask = 0;
3951 unsigned int status = t4_read_reg(adapter, reg);
3952
3953 for ( ; acts->mask; ++acts) {
3954 if (!(status & acts->mask))
3955 continue;
3956 if (acts->fatal) {
3957 fatal++;
3958 dev_alert(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
3959 status & acts->mask);
3960 } else if (acts->msg && printk_ratelimit())
3961 dev_warn(adapter->pdev_dev, "%s (0x%x)\n", acts->msg,
3962 status & acts->mask);
3963 if (acts->int_handler)
3964 acts->int_handler(adapter);
3965 mask |= acts->mask;
3966 }
3967 status &= mask;
3968 if (status)
3969 t4_write_reg(adapter, reg, status);
3970 return fatal;
3971}
3972
3973
3974
3975
3976static void pcie_intr_handler(struct adapter *adapter)
3977{
3978 static const struct intr_info sysbus_intr_info[] = {
3979 { RNPP_F, "RXNP array parity error", -1, 1 },
3980 { RPCP_F, "RXPC array parity error", -1, 1 },
3981 { RCIP_F, "RXCIF array parity error", -1, 1 },
3982 { RCCP_F, "Rx completions control array parity error", -1, 1 },
3983 { RFTP_F, "RXFT array parity error", -1, 1 },
3984 { 0 }
3985 };
3986 static const struct intr_info pcie_port_intr_info[] = {
3987 { TPCP_F, "TXPC array parity error", -1, 1 },
3988 { TNPP_F, "TXNP array parity error", -1, 1 },
3989 { TFTP_F, "TXFT array parity error", -1, 1 },
3990 { TCAP_F, "TXCA array parity error", -1, 1 },
3991 { TCIP_F, "TXCIF array parity error", -1, 1 },
3992 { RCAP_F, "RXCA array parity error", -1, 1 },
3993 { OTDD_F, "outbound request TLP discarded", -1, 1 },
3994 { RDPE_F, "Rx data parity error", -1, 1 },
3995 { TDUE_F, "Tx uncorrectable data error", -1, 1 },
3996 { 0 }
3997 };
3998 static const struct intr_info pcie_intr_info[] = {
3999 { MSIADDRLPERR_F, "MSI AddrL parity error", -1, 1 },
4000 { MSIADDRHPERR_F, "MSI AddrH parity error", -1, 1 },
4001 { MSIDATAPERR_F, "MSI data parity error", -1, 1 },
4002 { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
4003 { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
4004 { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
4005 { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
4006 { PIOCPLPERR_F, "PCI PIO completion FIFO parity error", -1, 1 },
4007 { PIOREQPERR_F, "PCI PIO request FIFO parity error", -1, 1 },
4008 { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
4009 { CCNTPERR_F, "PCI CMD channel count parity error", -1, 1 },
4010 { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
4011 { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
4012 { DCNTPERR_F, "PCI DMA channel count parity error", -1, 1 },
4013 { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
4014 { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
4015 { HCNTPERR_F, "PCI HMA channel count parity error", -1, 1 },
4016 { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
4017 { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
4018 { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
4019 { FIDPERR_F, "PCI FID parity error", -1, 1 },
4020 { INTXCLRPERR_F, "PCI INTx clear parity error", -1, 1 },
4021 { MATAGPERR_F, "PCI MA tag parity error", -1, 1 },
4022 { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
4023 { RXCPLPERR_F, "PCI Rx completion parity error", -1, 1 },
4024 { RXWRPERR_F, "PCI Rx write parity error", -1, 1 },
4025 { RPLPERR_F, "PCI replay buffer parity error", -1, 1 },
4026 { PCIESINT_F, "PCI core secondary fault", -1, 1 },
4027 { PCIEPINT_F, "PCI core primary fault", -1, 1 },
4028 { UNXSPLCPLERR_F, "PCI unexpected split completion error",
4029 -1, 0 },
4030 { 0 }
4031 };
4032
4033 static struct intr_info t5_pcie_intr_info[] = {
4034 { MSTGRPPERR_F, "Master Response Read Queue parity error",
4035 -1, 1 },
4036 { MSTTIMEOUTPERR_F, "Master Timeout FIFO parity error", -1, 1 },
4037 { MSIXSTIPERR_F, "MSI-X STI SRAM parity error", -1, 1 },
4038 { MSIXADDRLPERR_F, "MSI-X AddrL parity error", -1, 1 },
4039 { MSIXADDRHPERR_F, "MSI-X AddrH parity error", -1, 1 },
4040 { MSIXDATAPERR_F, "MSI-X data parity error", -1, 1 },
4041 { MSIXDIPERR_F, "MSI-X DI parity error", -1, 1 },
4042 { PIOCPLGRPPERR_F, "PCI PIO completion Group FIFO parity error",
4043 -1, 1 },
4044 { PIOREQGRPPERR_F, "PCI PIO request Group FIFO parity error",
4045 -1, 1 },
4046 { TARTAGPERR_F, "PCI PCI target tag FIFO parity error", -1, 1 },
4047 { MSTTAGQPERR_F, "PCI master tag queue parity error", -1, 1 },
4048 { CREQPERR_F, "PCI CMD channel request parity error", -1, 1 },
4049 { CRSPPERR_F, "PCI CMD channel response parity error", -1, 1 },
4050 { DREQWRPERR_F, "PCI DMA channel write request parity error",
4051 -1, 1 },
4052 { DREQPERR_F, "PCI DMA channel request parity error", -1, 1 },
4053 { DRSPPERR_F, "PCI DMA channel response parity error", -1, 1 },
4054 { HREQWRPERR_F, "PCI HMA channel count parity error", -1, 1 },
4055 { HREQPERR_F, "PCI HMA channel request parity error", -1, 1 },
4056 { HRSPPERR_F, "PCI HMA channel response parity error", -1, 1 },
4057 { CFGSNPPERR_F, "PCI config snoop FIFO parity error", -1, 1 },
4058 { FIDPERR_F, "PCI FID parity error", -1, 1 },
4059 { VFIDPERR_F, "PCI INTx clear parity error", -1, 1 },
4060 { MAGRPPERR_F, "PCI MA group FIFO parity error", -1, 1 },
4061 { PIOTAGPERR_F, "PCI PIO tag parity error", -1, 1 },
4062 { IPRXHDRGRPPERR_F, "PCI IP Rx header group parity error",
4063 -1, 1 },
4064 { IPRXDATAGRPPERR_F, "PCI IP Rx data group parity error",
4065 -1, 1 },
4066 { RPLPERR_F, "PCI IP replay buffer parity error", -1, 1 },
4067 { IPSOTPERR_F, "PCI IP SOT buffer parity error", -1, 1 },
4068 { TRGT1GRPPERR_F, "PCI TRGT1 group FIFOs parity error", -1, 1 },
4069 { READRSPERR_F, "Outbound read error", -1, 0 },
4070 { 0 }
4071 };
4072
4073 int fat;
4074
4075 if (is_t4(adapter->params.chip))
4076 fat = t4_handle_intr_status(adapter,
4077 PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS_A,
4078 sysbus_intr_info) +
4079 t4_handle_intr_status(adapter,
4080 PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS_A,
4081 pcie_port_intr_info) +
4082 t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
4083 pcie_intr_info);
4084 else
4085 fat = t4_handle_intr_status(adapter, PCIE_INT_CAUSE_A,
4086 t5_pcie_intr_info);
4087
4088 if (fat)
4089 t4_fatal_err(adapter);
4090}
4091
4092
4093
4094
4095static void tp_intr_handler(struct adapter *adapter)
4096{
4097 static const struct intr_info tp_intr_info[] = {
4098 { 0x3fffffff, "TP parity error", -1, 1 },
4099 { FLMTXFLSTEMPTY_F, "TP out of Tx pages", -1, 1 },
4100 { 0 }
4101 };
4102
4103 if (t4_handle_intr_status(adapter, TP_INT_CAUSE_A, tp_intr_info))
4104 t4_fatal_err(adapter);
4105}
4106
4107
4108
4109
4110static void sge_intr_handler(struct adapter *adapter)
4111{
4112 u64 v;
4113 u32 err;
4114
4115 static const struct intr_info sge_intr_info[] = {
4116 { ERR_CPL_EXCEED_IQE_SIZE_F,
4117 "SGE received CPL exceeding IQE size", -1, 1 },
4118 { ERR_INVALID_CIDX_INC_F,
4119 "SGE GTS CIDX increment too large", -1, 0 },
4120 { ERR_CPL_OPCODE_0_F, "SGE received 0-length CPL", -1, 0 },
4121 { DBFIFO_LP_INT_F, NULL, -1, 0, t4_db_full },
4122 { ERR_DATA_CPL_ON_HIGH_QID1_F | ERR_DATA_CPL_ON_HIGH_QID0_F,
4123 "SGE IQID > 1023 received CPL for FL", -1, 0 },
4124 { ERR_BAD_DB_PIDX3_F, "SGE DBP 3 pidx increment too large", -1,
4125 0 },
4126 { ERR_BAD_DB_PIDX2_F, "SGE DBP 2 pidx increment too large", -1,
4127 0 },
4128 { ERR_BAD_DB_PIDX1_F, "SGE DBP 1 pidx increment too large", -1,
4129 0 },
4130 { ERR_BAD_DB_PIDX0_F, "SGE DBP 0 pidx increment too large", -1,
4131 0 },
4132 { ERR_ING_CTXT_PRIO_F,
4133 "SGE too many priority ingress contexts", -1, 0 },
4134 { INGRESS_SIZE_ERR_F, "SGE illegal ingress QID", -1, 0 },
4135 { EGRESS_SIZE_ERR_F, "SGE illegal egress QID", -1, 0 },
4136 { 0 }
4137 };
4138
4139 static struct intr_info t4t5_sge_intr_info[] = {
4140 { ERR_DROPPED_DB_F, NULL, -1, 0, t4_db_dropped },
4141 { DBFIFO_HP_INT_F, NULL, -1, 0, t4_db_full },
4142 { ERR_EGR_CTXT_PRIO_F,
4143 "SGE too many priority egress contexts", -1, 0 },
4144 { 0 }
4145 };
4146
4147 v = (u64)t4_read_reg(adapter, SGE_INT_CAUSE1_A) |
4148 ((u64)t4_read_reg(adapter, SGE_INT_CAUSE2_A) << 32);
4149 if (v) {
4150 dev_alert(adapter->pdev_dev, "SGE parity error (%#llx)\n",
4151 (unsigned long long)v);
4152 t4_write_reg(adapter, SGE_INT_CAUSE1_A, v);
4153 t4_write_reg(adapter, SGE_INT_CAUSE2_A, v >> 32);
4154 }
4155
4156 v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A, sge_intr_info);
4157 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
4158 v |= t4_handle_intr_status(adapter, SGE_INT_CAUSE3_A,
4159 t4t5_sge_intr_info);
4160
4161 err = t4_read_reg(adapter, SGE_ERROR_STATS_A);
4162 if (err & ERROR_QID_VALID_F) {
4163 dev_err(adapter->pdev_dev, "SGE error for queue %u\n",
4164 ERROR_QID_G(err));
4165 if (err & UNCAPTURED_ERROR_F)
4166 dev_err(adapter->pdev_dev,
4167 "SGE UNCAPTURED_ERROR set (clearing)\n");
4168 t4_write_reg(adapter, SGE_ERROR_STATS_A, ERROR_QID_VALID_F |
4169 UNCAPTURED_ERROR_F);
4170 }
4171
4172 if (v != 0)
4173 t4_fatal_err(adapter);
4174}
4175
4176#define CIM_OBQ_INTR (OBQULP0PARERR_F | OBQULP1PARERR_F | OBQULP2PARERR_F |\
4177 OBQULP3PARERR_F | OBQSGEPARERR_F | OBQNCSIPARERR_F)
4178#define CIM_IBQ_INTR (IBQTP0PARERR_F | IBQTP1PARERR_F | IBQULPPARERR_F |\
4179 IBQSGEHIPARERR_F | IBQSGELOPARERR_F | IBQNCSIPARERR_F)
4180
4181
4182
4183
4184static void cim_intr_handler(struct adapter *adapter)
4185{
4186 static const struct intr_info cim_intr_info[] = {
4187 { PREFDROPINT_F, "CIM control register prefetch drop", -1, 1 },
4188 { CIM_OBQ_INTR, "CIM OBQ parity error", -1, 1 },
4189 { CIM_IBQ_INTR, "CIM IBQ parity error", -1, 1 },
4190 { MBUPPARERR_F, "CIM mailbox uP parity error", -1, 1 },
4191 { MBHOSTPARERR_F, "CIM mailbox host parity error", -1, 1 },
4192 { TIEQINPARERRINT_F, "CIM TIEQ outgoing parity error", -1, 1 },
4193 { TIEQOUTPARERRINT_F, "CIM TIEQ incoming parity error", -1, 1 },
4194 { TIMER0INT_F, "CIM TIMER0 interrupt", -1, 1 },
4195 { 0 }
4196 };
4197 static const struct intr_info cim_upintr_info[] = {
4198 { RSVDSPACEINT_F, "CIM reserved space access", -1, 1 },
4199 { ILLTRANSINT_F, "CIM illegal transaction", -1, 1 },
4200 { ILLWRINT_F, "CIM illegal write", -1, 1 },
4201 { ILLRDINT_F, "CIM illegal read", -1, 1 },
4202 { ILLRDBEINT_F, "CIM illegal read BE", -1, 1 },
4203 { ILLWRBEINT_F, "CIM illegal write BE", -1, 1 },
4204 { SGLRDBOOTINT_F, "CIM single read from boot space", -1, 1 },
4205 { SGLWRBOOTINT_F, "CIM single write to boot space", -1, 1 },
4206 { BLKWRBOOTINT_F, "CIM block write to boot space", -1, 1 },
4207 { SGLRDFLASHINT_F, "CIM single read from flash space", -1, 1 },
4208 { SGLWRFLASHINT_F, "CIM single write to flash space", -1, 1 },
4209 { BLKWRFLASHINT_F, "CIM block write to flash space", -1, 1 },
4210 { SGLRDEEPROMINT_F, "CIM single EEPROM read", -1, 1 },
4211 { SGLWREEPROMINT_F, "CIM single EEPROM write", -1, 1 },
4212 { BLKRDEEPROMINT_F, "CIM block EEPROM read", -1, 1 },
4213 { BLKWREEPROMINT_F, "CIM block EEPROM write", -1, 1 },
4214 { SGLRDCTLINT_F, "CIM single read from CTL space", -1, 1 },
4215 { SGLWRCTLINT_F, "CIM single write to CTL space", -1, 1 },
4216 { BLKRDCTLINT_F, "CIM block read from CTL space", -1, 1 },
4217 { BLKWRCTLINT_F, "CIM block write to CTL space", -1, 1 },
4218 { SGLRDPLINT_F, "CIM single read from PL space", -1, 1 },
4219 { SGLWRPLINT_F, "CIM single write to PL space", -1, 1 },
4220 { BLKRDPLINT_F, "CIM block read from PL space", -1, 1 },
4221 { BLKWRPLINT_F, "CIM block write to PL space", -1, 1 },
4222 { REQOVRLOOKUPINT_F, "CIM request FIFO overwrite", -1, 1 },
4223 { RSPOVRLOOKUPINT_F, "CIM response FIFO overwrite", -1, 1 },
4224 { TIMEOUTINT_F, "CIM PIF timeout", -1, 1 },
4225 { TIMEOUTMAINT_F, "CIM PIF MA timeout", -1, 1 },
4226 { 0 }
4227 };
4228
4229 u32 val, fw_err;
4230 int fat;
4231
4232 fw_err = t4_read_reg(adapter, PCIE_FW_A);
4233 if (fw_err & PCIE_FW_ERR_F)
4234 t4_report_fw_error(adapter);
4235
4236
4237
4238
4239
4240
4241
4242
4243 val = t4_read_reg(adapter, CIM_HOST_INT_CAUSE_A);
4244 if (val & TIMER0INT_F)
4245 if (!(fw_err & PCIE_FW_ERR_F) ||
4246 (PCIE_FW_EVAL_G(fw_err) != PCIE_FW_EVAL_CRASH))
4247 t4_write_reg(adapter, CIM_HOST_INT_CAUSE_A,
4248 TIMER0INT_F);
4249
4250 fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE_A,
4251 cim_intr_info) +
4252 t4_handle_intr_status(adapter, CIM_HOST_UPACC_INT_CAUSE_A,
4253 cim_upintr_info);
4254 if (fat)
4255 t4_fatal_err(adapter);
4256}
4257
4258
4259
4260
4261static void ulprx_intr_handler(struct adapter *adapter)
4262{
4263 static const struct intr_info ulprx_intr_info[] = {
4264 { 0x1800000, "ULPRX context error", -1, 1 },
4265 { 0x7fffff, "ULPRX parity error", -1, 1 },
4266 { 0 }
4267 };
4268
4269 if (t4_handle_intr_status(adapter, ULP_RX_INT_CAUSE_A, ulprx_intr_info))
4270 t4_fatal_err(adapter);
4271}
4272
4273
4274
4275
4276static void ulptx_intr_handler(struct adapter *adapter)
4277{
4278 static const struct intr_info ulptx_intr_info[] = {
4279 { PBL_BOUND_ERR_CH3_F, "ULPTX channel 3 PBL out of bounds", -1,
4280 0 },
4281 { PBL_BOUND_ERR_CH2_F, "ULPTX channel 2 PBL out of bounds", -1,
4282 0 },
4283 { PBL_BOUND_ERR_CH1_F, "ULPTX channel 1 PBL out of bounds", -1,
4284 0 },
4285 { PBL_BOUND_ERR_CH0_F, "ULPTX channel 0 PBL out of bounds", -1,
4286 0 },
4287 { 0xfffffff, "ULPTX parity error", -1, 1 },
4288 { 0 }
4289 };
4290
4291 if (t4_handle_intr_status(adapter, ULP_TX_INT_CAUSE_A, ulptx_intr_info))
4292 t4_fatal_err(adapter);
4293}
4294
4295
4296
4297
4298static void pmtx_intr_handler(struct adapter *adapter)
4299{
4300 static const struct intr_info pmtx_intr_info[] = {
4301 { PCMD_LEN_OVFL0_F, "PMTX channel 0 pcmd too large", -1, 1 },
4302 { PCMD_LEN_OVFL1_F, "PMTX channel 1 pcmd too large", -1, 1 },
4303 { PCMD_LEN_OVFL2_F, "PMTX channel 2 pcmd too large", -1, 1 },
4304 { ZERO_C_CMD_ERROR_F, "PMTX 0-length pcmd", -1, 1 },
4305 { PMTX_FRAMING_ERROR_F, "PMTX framing error", -1, 1 },
4306 { OESPI_PAR_ERROR_F, "PMTX oespi parity error", -1, 1 },
4307 { DB_OPTIONS_PAR_ERROR_F, "PMTX db_options parity error",
4308 -1, 1 },
4309 { ICSPI_PAR_ERROR_F, "PMTX icspi parity error", -1, 1 },
4310 { PMTX_C_PCMD_PAR_ERROR_F, "PMTX c_pcmd parity error", -1, 1},
4311 { 0 }
4312 };
4313
4314 if (t4_handle_intr_status(adapter, PM_TX_INT_CAUSE_A, pmtx_intr_info))
4315 t4_fatal_err(adapter);
4316}
4317
4318
4319
4320
4321static void pmrx_intr_handler(struct adapter *adapter)
4322{
4323 static const struct intr_info pmrx_intr_info[] = {
4324 { ZERO_E_CMD_ERROR_F, "PMRX 0-length pcmd", -1, 1 },
4325 { PMRX_FRAMING_ERROR_F, "PMRX framing error", -1, 1 },
4326 { OCSPI_PAR_ERROR_F, "PMRX ocspi parity error", -1, 1 },
4327 { DB_OPTIONS_PAR_ERROR_F, "PMRX db_options parity error",
4328 -1, 1 },
4329 { IESPI_PAR_ERROR_F, "PMRX iespi parity error", -1, 1 },
4330 { PMRX_E_PCMD_PAR_ERROR_F, "PMRX e_pcmd parity error", -1, 1},
4331 { 0 }
4332 };
4333
4334 if (t4_handle_intr_status(adapter, PM_RX_INT_CAUSE_A, pmrx_intr_info))
4335 t4_fatal_err(adapter);
4336}
4337
4338
4339
4340
4341static void cplsw_intr_handler(struct adapter *adapter)
4342{
4343 static const struct intr_info cplsw_intr_info[] = {
4344 { CIM_OP_MAP_PERR_F, "CPLSW CIM op_map parity error", -1, 1 },
4345 { CIM_OVFL_ERROR_F, "CPLSW CIM overflow", -1, 1 },
4346 { TP_FRAMING_ERROR_F, "CPLSW TP framing error", -1, 1 },
4347 { SGE_FRAMING_ERROR_F, "CPLSW SGE framing error", -1, 1 },
4348 { CIM_FRAMING_ERROR_F, "CPLSW CIM framing error", -1, 1 },
4349 { ZERO_SWITCH_ERROR_F, "CPLSW no-switch error", -1, 1 },
4350 { 0 }
4351 };
4352
4353 if (t4_handle_intr_status(adapter, CPL_INTR_CAUSE_A, cplsw_intr_info))
4354 t4_fatal_err(adapter);
4355}
4356
4357
4358
4359
4360static void le_intr_handler(struct adapter *adap)
4361{
4362 enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
4363 static const struct intr_info le_intr_info[] = {
4364 { LIPMISS_F, "LE LIP miss", -1, 0 },
4365 { LIP0_F, "LE 0 LIP error", -1, 0 },
4366 { PARITYERR_F, "LE parity error", -1, 1 },
4367 { UNKNOWNCMD_F, "LE unknown command", -1, 1 },
4368 { REQQPARERR_F, "LE request queue parity error", -1, 1 },
4369 { 0 }
4370 };
4371
4372 static struct intr_info t6_le_intr_info[] = {
4373 { T6_LIPMISS_F, "LE LIP miss", -1, 0 },
4374 { T6_LIP0_F, "LE 0 LIP error", -1, 0 },
4375 { TCAMINTPERR_F, "LE parity error", -1, 1 },
4376 { T6_UNKNOWNCMD_F, "LE unknown command", -1, 1 },
4377 { SSRAMINTPERR_F, "LE request queue parity error", -1, 1 },
4378 { 0 }
4379 };
4380
4381 if (t4_handle_intr_status(adap, LE_DB_INT_CAUSE_A,
4382 (chip <= CHELSIO_T5) ?
4383 le_intr_info : t6_le_intr_info))
4384 t4_fatal_err(adap);
4385}
4386
4387
4388
4389
4390static void mps_intr_handler(struct adapter *adapter)
4391{
4392 static const struct intr_info mps_rx_intr_info[] = {
4393 { 0xffffff, "MPS Rx parity error", -1, 1 },
4394 { 0 }
4395 };
4396 static const struct intr_info mps_tx_intr_info[] = {
4397 { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
4398 { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
4399 { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
4400 -1, 1 },
4401 { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
4402 -1, 1 },
4403 { BUBBLE_F, "MPS Tx underflow", -1, 1 },
4404 { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
4405 { FRMERR_F, "MPS Tx framing error", -1, 1 },
4406 { 0 }
4407 };
4408 static const struct intr_info t6_mps_tx_intr_info[] = {
4409 { TPFIFO_V(TPFIFO_M), "MPS Tx TP FIFO parity error", -1, 1 },
4410 { NCSIFIFO_F, "MPS Tx NC-SI FIFO parity error", -1, 1 },
4411 { TXDATAFIFO_V(TXDATAFIFO_M), "MPS Tx data FIFO parity error",
4412 -1, 1 },
4413 { TXDESCFIFO_V(TXDESCFIFO_M), "MPS Tx desc FIFO parity error",
4414 -1, 1 },
4415
4416 { SECNTERR_F, "MPS Tx SOP/EOP error", -1, 1 },
4417 { FRMERR_F, "MPS Tx framing error", -1, 1 },
4418 { 0 }
4419 };
4420 static const struct intr_info mps_trc_intr_info[] = {
4421 { FILTMEM_V(FILTMEM_M), "MPS TRC filter parity error", -1, 1 },
4422 { PKTFIFO_V(PKTFIFO_M), "MPS TRC packet FIFO parity error",
4423 -1, 1 },
4424 { MISCPERR_F, "MPS TRC misc parity error", -1, 1 },
4425 { 0 }
4426 };
4427 static const struct intr_info mps_stat_sram_intr_info[] = {
4428 { 0x1fffff, "MPS statistics SRAM parity error", -1, 1 },
4429 { 0 }
4430 };
4431 static const struct intr_info mps_stat_tx_intr_info[] = {
4432 { 0xfffff, "MPS statistics Tx FIFO parity error", -1, 1 },
4433 { 0 }
4434 };
4435 static const struct intr_info mps_stat_rx_intr_info[] = {
4436 { 0xffffff, "MPS statistics Rx FIFO parity error", -1, 1 },
4437 { 0 }
4438 };
4439 static const struct intr_info mps_cls_intr_info[] = {
4440 { MATCHSRAM_F, "MPS match SRAM parity error", -1, 1 },
4441 { MATCHTCAM_F, "MPS match TCAM parity error", -1, 1 },
4442 { HASHSRAM_F, "MPS hash SRAM parity error", -1, 1 },
4443 { 0 }
4444 };
4445
4446 int fat;
4447
4448 fat = t4_handle_intr_status(adapter, MPS_RX_PERR_INT_CAUSE_A,
4449 mps_rx_intr_info) +
4450 t4_handle_intr_status(adapter, MPS_TX_INT_CAUSE_A,
4451 is_t6(adapter->params.chip)
4452 ? t6_mps_tx_intr_info
4453 : mps_tx_intr_info) +
4454 t4_handle_intr_status(adapter, MPS_TRC_INT_CAUSE_A,
4455 mps_trc_intr_info) +
4456 t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_SRAM_A,
4457 mps_stat_sram_intr_info) +
4458 t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_TX_FIFO_A,
4459 mps_stat_tx_intr_info) +
4460 t4_handle_intr_status(adapter, MPS_STAT_PERR_INT_CAUSE_RX_FIFO_A,
4461 mps_stat_rx_intr_info) +
4462 t4_handle_intr_status(adapter, MPS_CLS_INT_CAUSE_A,
4463 mps_cls_intr_info);
4464
4465 t4_write_reg(adapter, MPS_INT_CAUSE_A, 0);
4466 t4_read_reg(adapter, MPS_INT_CAUSE_A);
4467 if (fat)
4468 t4_fatal_err(adapter);
4469}
4470
4471#define MEM_INT_MASK (PERR_INT_CAUSE_F | ECC_CE_INT_CAUSE_F | \
4472 ECC_UE_INT_CAUSE_F)
4473
4474
4475
4476
4477static void mem_intr_handler(struct adapter *adapter, int idx)
4478{
4479 static const char name[4][7] = { "EDC0", "EDC1", "MC/MC0", "MC1" };
4480
4481 unsigned int addr, cnt_addr, v;
4482
4483 if (idx <= MEM_EDC1) {
4484 addr = EDC_REG(EDC_INT_CAUSE_A, idx);
4485 cnt_addr = EDC_REG(EDC_ECC_STATUS_A, idx);
4486 } else if (idx == MEM_MC) {
4487 if (is_t4(adapter->params.chip)) {
4488 addr = MC_INT_CAUSE_A;
4489 cnt_addr = MC_ECC_STATUS_A;
4490 } else {
4491 addr = MC_P_INT_CAUSE_A;
4492 cnt_addr = MC_P_ECC_STATUS_A;
4493 }
4494 } else {
4495 addr = MC_REG(MC_P_INT_CAUSE_A, 1);
4496 cnt_addr = MC_REG(MC_P_ECC_STATUS_A, 1);
4497 }
4498
4499 v = t4_read_reg(adapter, addr) & MEM_INT_MASK;
4500 if (v & PERR_INT_CAUSE_F)
4501 dev_alert(adapter->pdev_dev, "%s FIFO parity error\n",
4502 name[idx]);
4503 if (v & ECC_CE_INT_CAUSE_F) {
4504 u32 cnt = ECC_CECNT_G(t4_read_reg(adapter, cnt_addr));
4505
4506 t4_edc_err_read(adapter, idx);
4507
4508 t4_write_reg(adapter, cnt_addr, ECC_CECNT_V(ECC_CECNT_M));
4509 if (printk_ratelimit())
4510 dev_warn(adapter->pdev_dev,
4511 "%u %s correctable ECC data error%s\n",
4512 cnt, name[idx], cnt > 1 ? "s" : "");
4513 }
4514 if (v & ECC_UE_INT_CAUSE_F)
4515 dev_alert(adapter->pdev_dev,
4516 "%s uncorrectable ECC data error\n", name[idx]);
4517
4518 t4_write_reg(adapter, addr, v);
4519 if (v & (PERR_INT_CAUSE_F | ECC_UE_INT_CAUSE_F))
4520 t4_fatal_err(adapter);
4521}
4522
4523
4524
4525
4526static void ma_intr_handler(struct adapter *adap)
4527{
4528 u32 v, status = t4_read_reg(adap, MA_INT_CAUSE_A);
4529
4530 if (status & MEM_PERR_INT_CAUSE_F) {
4531 dev_alert(adap->pdev_dev,
4532 "MA parity error, parity status %#x\n",
4533 t4_read_reg(adap, MA_PARITY_ERROR_STATUS1_A));
4534 if (is_t5(adap->params.chip))
4535 dev_alert(adap->pdev_dev,
4536 "MA parity error, parity status %#x\n",
4537 t4_read_reg(adap,
4538 MA_PARITY_ERROR_STATUS2_A));
4539 }
4540 if (status & MEM_WRAP_INT_CAUSE_F) {
4541 v = t4_read_reg(adap, MA_INT_WRAP_STATUS_A);
4542 dev_alert(adap->pdev_dev, "MA address wrap-around error by "
4543 "client %u to address %#x\n",
4544 MEM_WRAP_CLIENT_NUM_G(v),
4545 MEM_WRAP_ADDRESS_G(v) << 4);
4546 }
4547 t4_write_reg(adap, MA_INT_CAUSE_A, status);
4548 t4_fatal_err(adap);
4549}
4550
4551
4552
4553
4554static void smb_intr_handler(struct adapter *adap)
4555{
4556 static const struct intr_info smb_intr_info[] = {
4557 { MSTTXFIFOPARINT_F, "SMB master Tx FIFO parity error", -1, 1 },
4558 { MSTRXFIFOPARINT_F, "SMB master Rx FIFO parity error", -1, 1 },
4559 { SLVFIFOPARINT_F, "SMB slave FIFO parity error", -1, 1 },
4560 { 0 }
4561 };
4562
4563 if (t4_handle_intr_status(adap, SMB_INT_CAUSE_A, smb_intr_info))
4564 t4_fatal_err(adap);
4565}
4566
4567
4568
4569
4570static void ncsi_intr_handler(struct adapter *adap)
4571{
4572 static const struct intr_info ncsi_intr_info[] = {
4573 { CIM_DM_PRTY_ERR_F, "NC-SI CIM parity error", -1, 1 },
4574 { MPS_DM_PRTY_ERR_F, "NC-SI MPS parity error", -1, 1 },
4575 { TXFIFO_PRTY_ERR_F, "NC-SI Tx FIFO parity error", -1, 1 },
4576 { RXFIFO_PRTY_ERR_F, "NC-SI Rx FIFO parity error", -1, 1 },
4577 { 0 }
4578 };
4579
4580 if (t4_handle_intr_status(adap, NCSI_INT_CAUSE_A, ncsi_intr_info))
4581 t4_fatal_err(adap);
4582}
4583
4584
4585
4586
4587static void xgmac_intr_handler(struct adapter *adap, int port)
4588{
4589 u32 v, int_cause_reg;
4590
4591 if (is_t4(adap->params.chip))
4592 int_cause_reg = PORT_REG(port, XGMAC_PORT_INT_CAUSE_A);
4593 else
4594 int_cause_reg = T5_PORT_REG(port, MAC_PORT_INT_CAUSE_A);
4595
4596 v = t4_read_reg(adap, int_cause_reg);
4597
4598 v &= TXFIFO_PRTY_ERR_F | RXFIFO_PRTY_ERR_F;
4599 if (!v)
4600 return;
4601
4602 if (v & TXFIFO_PRTY_ERR_F)
4603 dev_alert(adap->pdev_dev, "XGMAC %d Tx FIFO parity error\n",
4604 port);
4605 if (v & RXFIFO_PRTY_ERR_F)
4606 dev_alert(adap->pdev_dev, "XGMAC %d Rx FIFO parity error\n",
4607 port);
4608 t4_write_reg(adap, PORT_REG(port, XGMAC_PORT_INT_CAUSE_A), v);
4609 t4_fatal_err(adap);
4610}
4611
4612
4613
4614
4615static void pl_intr_handler(struct adapter *adap)
4616{
4617 static const struct intr_info pl_intr_info[] = {
4618 { FATALPERR_F, "T4 fatal parity error", -1, 1 },
4619 { PERRVFID_F, "PL VFID_MAP parity error", -1, 1 },
4620 { 0 }
4621 };
4622
4623 if (t4_handle_intr_status(adap, PL_PL_INT_CAUSE_A, pl_intr_info))
4624 t4_fatal_err(adap);
4625}
4626
4627#define PF_INTR_MASK (PFSW_F)
4628#define GLBL_INTR_MASK (CIM_F | MPS_F | PL_F | PCIE_F | MC_F | EDC0_F | \
4629 EDC1_F | LE_F | TP_F | MA_F | PM_TX_F | PM_RX_F | ULP_RX_F | \
4630 CPL_SWITCH_F | SGE_F | ULP_TX_F | SF_F)
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640int t4_slow_intr_handler(struct adapter *adapter)
4641{
4642 u32 cause = t4_read_reg(adapter, PL_INT_CAUSE_A);
4643
4644 if (!(cause & GLBL_INTR_MASK))
4645 return 0;
4646 if (cause & CIM_F)
4647 cim_intr_handler(adapter);
4648 if (cause & MPS_F)
4649 mps_intr_handler(adapter);
4650 if (cause & NCSI_F)
4651 ncsi_intr_handler(adapter);
4652 if (cause & PL_F)
4653 pl_intr_handler(adapter);
4654 if (cause & SMB_F)
4655 smb_intr_handler(adapter);
4656 if (cause & XGMAC0_F)
4657 xgmac_intr_handler(adapter, 0);
4658 if (cause & XGMAC1_F)
4659 xgmac_intr_handler(adapter, 1);
4660 if (cause & XGMAC_KR0_F)
4661 xgmac_intr_handler(adapter, 2);
4662 if (cause & XGMAC_KR1_F)
4663 xgmac_intr_handler(adapter, 3);
4664 if (cause & PCIE_F)
4665 pcie_intr_handler(adapter);
4666 if (cause & MC_F)
4667 mem_intr_handler(adapter, MEM_MC);
4668 if (is_t5(adapter->params.chip) && (cause & MC1_F))
4669 mem_intr_handler(adapter, MEM_MC1);
4670 if (cause & EDC0_F)
4671 mem_intr_handler(adapter, MEM_EDC0);
4672 if (cause & EDC1_F)
4673 mem_intr_handler(adapter, MEM_EDC1);
4674 if (cause & LE_F)
4675 le_intr_handler(adapter);
4676 if (cause & TP_F)
4677 tp_intr_handler(adapter);
4678 if (cause & MA_F)
4679 ma_intr_handler(adapter);
4680 if (cause & PM_TX_F)
4681 pmtx_intr_handler(adapter);
4682 if (cause & PM_RX_F)
4683 pmrx_intr_handler(adapter);
4684 if (cause & ULP_RX_F)
4685 ulprx_intr_handler(adapter);
4686 if (cause & CPL_SWITCH_F)
4687 cplsw_intr_handler(adapter);
4688 if (cause & SGE_F)
4689 sge_intr_handler(adapter);
4690 if (cause & ULP_TX_F)
4691 ulptx_intr_handler(adapter);
4692
4693
4694 t4_write_reg(adapter, PL_INT_CAUSE_A, cause & GLBL_INTR_MASK);
4695 (void)t4_read_reg(adapter, PL_INT_CAUSE_A);
4696 return 1;
4697}
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712void t4_intr_enable(struct adapter *adapter)
4713{
4714 u32 val = 0;
4715 u32 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
4716 u32 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
4717 SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
4718
4719 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
4720 val = ERR_DROPPED_DB_F | ERR_EGR_CTXT_PRIO_F | DBFIFO_HP_INT_F;
4721 t4_write_reg(adapter, SGE_INT_ENABLE3_A, ERR_CPL_EXCEED_IQE_SIZE_F |
4722 ERR_INVALID_CIDX_INC_F | ERR_CPL_OPCODE_0_F |
4723 ERR_DATA_CPL_ON_HIGH_QID1_F | INGRESS_SIZE_ERR_F |
4724 ERR_DATA_CPL_ON_HIGH_QID0_F | ERR_BAD_DB_PIDX3_F |
4725 ERR_BAD_DB_PIDX2_F | ERR_BAD_DB_PIDX1_F |
4726 ERR_BAD_DB_PIDX0_F | ERR_ING_CTXT_PRIO_F |
4727 DBFIFO_LP_INT_F | EGRESS_SIZE_ERR_F | val);
4728 t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), PF_INTR_MASK);
4729 t4_set_reg_field(adapter, PL_INT_MAP0_A, 0, 1 << pf);
4730}
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740void t4_intr_disable(struct adapter *adapter)
4741{
4742 u32 whoami, pf;
4743
4744 if (pci_channel_offline(adapter->pdev))
4745 return;
4746
4747 whoami = t4_read_reg(adapter, PL_WHOAMI_A);
4748 pf = CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
4749 SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
4750
4751 t4_write_reg(adapter, MYPF_REG(PL_PF_INT_ENABLE_A), 0);
4752 t4_set_reg_field(adapter, PL_INT_MAP0_A, 1 << pf, 0);
4753}
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
4773 int start, int n, const u16 *rspq, unsigned int nrspq)
4774{
4775 int ret;
4776 const u16 *rsp = rspq;
4777 const u16 *rsp_end = rspq + nrspq;
4778 struct fw_rss_ind_tbl_cmd cmd;
4779
4780 memset(&cmd, 0, sizeof(cmd));
4781 cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
4782 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
4783 FW_RSS_IND_TBL_CMD_VIID_V(viid));
4784 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
4785
4786
4787 while (n > 0) {
4788 int nq = min(n, 32);
4789 __be32 *qp = &cmd.iq0_to_iq2;
4790
4791 cmd.niqid = cpu_to_be16(nq);
4792 cmd.startidx = cpu_to_be16(start);
4793
4794 start += nq;
4795 n -= nq;
4796
4797 while (nq > 0) {
4798 unsigned int v;
4799
4800 v = FW_RSS_IND_TBL_CMD_IQ0_V(*rsp);
4801 if (++rsp >= rsp_end)
4802 rsp = rspq;
4803 v |= FW_RSS_IND_TBL_CMD_IQ1_V(*rsp);
4804 if (++rsp >= rsp_end)
4805 rsp = rspq;
4806 v |= FW_RSS_IND_TBL_CMD_IQ2_V(*rsp);
4807 if (++rsp >= rsp_end)
4808 rsp = rspq;
4809
4810 *qp++ = cpu_to_be32(v);
4811 nq -= 3;
4812 }
4813
4814 ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
4815 if (ret)
4816 return ret;
4817 }
4818 return 0;
4819}
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
4831 unsigned int flags)
4832{
4833 struct fw_rss_glb_config_cmd c;
4834
4835 memset(&c, 0, sizeof(c));
4836 c.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_RSS_GLB_CONFIG_CMD) |
4837 FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
4838 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
4839 if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
4840 c.u.manual.mode_pkd =
4841 cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
4842 } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
4843 c.u.basicvirtual.mode_pkd =
4844 cpu_to_be32(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
4845 c.u.basicvirtual.synmapen_to_hashtoeplitz = cpu_to_be32(flags);
4846 } else
4847 return -EINVAL;
4848 return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
4849}
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
4862 unsigned int flags, unsigned int defq)
4863{
4864 struct fw_rss_vi_config_cmd c;
4865
4866 memset(&c, 0, sizeof(c));
4867 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
4868 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
4869 FW_RSS_VI_CONFIG_CMD_VIID_V(viid));
4870 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
4871 c.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(flags |
4872 FW_RSS_VI_CONFIG_CMD_DEFAULTQ_V(defq));
4873 return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
4874}
4875
4876
4877static int rd_rss_row(struct adapter *adap, int row, u32 *val)
4878{
4879 t4_write_reg(adap, TP_RSS_LKP_TABLE_A, 0xfff00000 | row);
4880 return t4_wait_op_done_val(adap, TP_RSS_LKP_TABLE_A, LKPTBLROWVLD_F, 1,
4881 5, 0, val);
4882}
4883
4884
4885
4886
4887
4888
4889
4890
4891int t4_read_rss(struct adapter *adapter, u16 *map)
4892{
4893 u32 val;
4894 int i, ret;
4895
4896 for (i = 0; i < RSS_NENTRIES / 2; ++i) {
4897 ret = rd_rss_row(adapter, i, &val);
4898 if (ret)
4899 return ret;
4900 *map++ = LKPTBLQUEUE0_G(val);
4901 *map++ = LKPTBLQUEUE1_G(val);
4902 }
4903 return 0;
4904}
4905
4906static unsigned int t4_use_ldst(struct adapter *adap)
4907{
4908 return (adap->flags & FW_OK) || !adap->use_bd;
4909}
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921static void t4_fw_tp_pio_rw(struct adapter *adap, u32 *vals, unsigned int nregs,
4922 unsigned int start_index, unsigned int rw)
4923{
4924 int ret, i;
4925 int cmd = FW_LDST_ADDRSPC_TP_PIO;
4926 struct fw_ldst_cmd c;
4927
4928 for (i = 0 ; i < nregs; i++) {
4929 memset(&c, 0, sizeof(c));
4930 c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
4931 FW_CMD_REQUEST_F |
4932 (rw ? FW_CMD_READ_F :
4933 FW_CMD_WRITE_F) |
4934 FW_LDST_CMD_ADDRSPACE_V(cmd));
4935 c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
4936
4937 c.u.addrval.addr = cpu_to_be32(start_index + i);
4938 c.u.addrval.val = rw ? 0 : cpu_to_be32(vals[i]);
4939 ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c);
4940 if (!ret && rw)
4941 vals[i] = be32_to_cpu(c.u.addrval.val);
4942 }
4943}
4944
4945
4946
4947
4948
4949
4950
4951
4952void t4_read_rss_key(struct adapter *adap, u32 *key)
4953{
4954 if (t4_use_ldst(adap))
4955 t4_fw_tp_pio_rw(adap, key, 10, TP_RSS_SECRET_KEY0_A, 1);
4956 else
4957 t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
4958 TP_RSS_SECRET_KEY0_A);
4959}
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx)
4972{
4973 u8 rss_key_addr_cnt = 16;
4974 u32 vrt = t4_read_reg(adap, TP_RSS_CONFIG_VRT_A);
4975
4976
4977
4978
4979
4980 if ((CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) &&
4981 (vrt & KEYEXTEND_F) && (KEYMODE_G(vrt) == 3))
4982 rss_key_addr_cnt = 32;
4983
4984 if (t4_use_ldst(adap))
4985 t4_fw_tp_pio_rw(adap, (void *)key, 10, TP_RSS_SECRET_KEY0_A, 0);
4986 else
4987 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A, key, 10,
4988 TP_RSS_SECRET_KEY0_A);
4989
4990 if (idx >= 0 && idx < rss_key_addr_cnt) {
4991 if (rss_key_addr_cnt > 16)
4992 t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
4993 KEYWRADDRX_V(idx >> 4) |
4994 T6_VFWRADDR_V(idx) | KEYWREN_F);
4995 else
4996 t4_write_reg(adap, TP_RSS_CONFIG_VRT_A,
4997 KEYWRADDR_V(idx) | KEYWREN_F);
4998 }
4999}
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
5011 u32 *valp)
5012{
5013 if (t4_use_ldst(adapter))
5014 t4_fw_tp_pio_rw(adapter, valp, 1,
5015 TP_RSS_PF0_CONFIG_A + index, 1);
5016 else
5017 t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
5018 valp, 1, TP_RSS_PF0_CONFIG_A + index);
5019}
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
5032 u32 *vfl, u32 *vfh)
5033{
5034 u32 vrt, mask, data;
5035
5036 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) {
5037 mask = VFWRADDR_V(VFWRADDR_M);
5038 data = VFWRADDR_V(index);
5039 } else {
5040 mask = T6_VFWRADDR_V(T6_VFWRADDR_M);
5041 data = T6_VFWRADDR_V(index);
5042 }
5043
5044
5045
5046 vrt = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
5047 vrt &= ~(VFRDRG_F | VFWREN_F | KEYWREN_F | mask);
5048 vrt |= data | VFRDEN_F;
5049 t4_write_reg(adapter, TP_RSS_CONFIG_VRT_A, vrt);
5050
5051
5052
5053 if (t4_use_ldst(adapter)) {
5054 t4_fw_tp_pio_rw(adapter, vfl, 1, TP_RSS_VFL_CONFIG_A, 1);
5055 t4_fw_tp_pio_rw(adapter, vfh, 1, TP_RSS_VFH_CONFIG_A, 1);
5056 } else {
5057 t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
5058 vfl, 1, TP_RSS_VFL_CONFIG_A);
5059 t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
5060 vfh, 1, TP_RSS_VFH_CONFIG_A);
5061 }
5062}
5063
5064
5065
5066
5067
5068
5069
5070u32 t4_read_rss_pf_map(struct adapter *adapter)
5071{
5072 u32 pfmap;
5073
5074 if (t4_use_ldst(adapter))
5075 t4_fw_tp_pio_rw(adapter, &pfmap, 1, TP_RSS_PF_MAP_A, 1);
5076 else
5077 t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
5078 &pfmap, 1, TP_RSS_PF_MAP_A);
5079 return pfmap;
5080}
5081
5082
5083
5084
5085
5086
5087
5088u32 t4_read_rss_pf_mask(struct adapter *adapter)
5089{
5090 u32 pfmask;
5091
5092 if (t4_use_ldst(adapter))
5093 t4_fw_tp_pio_rw(adapter, &pfmask, 1, TP_RSS_PF_MSK_A, 1);
5094 else
5095 t4_read_indirect(adapter, TP_PIO_ADDR_A, TP_PIO_DATA_A,
5096 &pfmask, 1, TP_RSS_PF_MSK_A);
5097 return pfmask;
5098}
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
5110 struct tp_tcp_stats *v6)
5111{
5112 u32 val[TP_MIB_TCP_RXT_SEG_LO_A - TP_MIB_TCP_OUT_RST_A + 1];
5113
5114#define STAT_IDX(x) ((TP_MIB_TCP_##x##_A) - TP_MIB_TCP_OUT_RST_A)
5115#define STAT(x) val[STAT_IDX(x)]
5116#define STAT64(x) (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
5117
5118 if (v4) {
5119 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
5120 ARRAY_SIZE(val), TP_MIB_TCP_OUT_RST_A);
5121 v4->tcp_out_rsts = STAT(OUT_RST);
5122 v4->tcp_in_segs = STAT64(IN_SEG);
5123 v4->tcp_out_segs = STAT64(OUT_SEG);
5124 v4->tcp_retrans_segs = STAT64(RXT_SEG);
5125 }
5126 if (v6) {
5127 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
5128 ARRAY_SIZE(val), TP_MIB_TCP_V6OUT_RST_A);
5129 v6->tcp_out_rsts = STAT(OUT_RST);
5130 v6->tcp_in_segs = STAT64(IN_SEG);
5131 v6->tcp_out_segs = STAT64(OUT_SEG);
5132 v6->tcp_retrans_segs = STAT64(RXT_SEG);
5133 }
5134#undef STAT64
5135#undef STAT
5136#undef STAT_IDX
5137}
5138
5139
5140
5141
5142
5143
5144
5145
5146void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st)
5147{
5148 int nchan = adap->params.arch.nchan;
5149
5150 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5151 st->mac_in_errs, nchan, TP_MIB_MAC_IN_ERR_0_A);
5152 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5153 st->hdr_in_errs, nchan, TP_MIB_HDR_IN_ERR_0_A);
5154 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5155 st->tcp_in_errs, nchan, TP_MIB_TCP_IN_ERR_0_A);
5156 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5157 st->tnl_cong_drops, nchan, TP_MIB_TNL_CNG_DROP_0_A);
5158 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5159 st->ofld_chan_drops, nchan, TP_MIB_OFD_CHN_DROP_0_A);
5160 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5161 st->tnl_tx_drops, nchan, TP_MIB_TNL_DROP_0_A);
5162 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5163 st->ofld_vlan_drops, nchan, TP_MIB_OFD_VLN_DROP_0_A);
5164 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5165 st->tcp6_in_errs, nchan, TP_MIB_TCP_V6IN_ERR_0_A);
5166
5167 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A,
5168 &st->ofld_no_neigh, 2, TP_MIB_OFD_ARP_DROP_A);
5169}
5170
5171
5172
5173
5174
5175
5176
5177
5178void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st)
5179{
5180 int nchan = adap->params.arch.nchan;
5181
5182 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->req,
5183 nchan, TP_MIB_CPL_IN_REQ_0_A);
5184 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, st->rsp,
5185 nchan, TP_MIB_CPL_OUT_RSP_0_A);
5186
5187}
5188
5189
5190
5191
5192
5193
5194
5195
5196void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st)
5197{
5198 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->rqe_dfr_pkt,
5199 2, TP_MIB_RQE_DFR_PKT_A);
5200}
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
5211 struct tp_fcoe_stats *st)
5212{
5213 u32 val[2];
5214
5215 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_ddp,
5216 1, TP_MIB_FCOE_DDP_0_A + idx);
5217 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, &st->frames_drop,
5218 1, TP_MIB_FCOE_DROP_0_A + idx);
5219 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val,
5220 2, TP_MIB_FCOE_BYTE_0_HI_A + 2 * idx);
5221 st->octets_ddp = ((u64)val[0] << 32) | val[1];
5222}
5223
5224
5225
5226
5227
5228
5229
5230
5231void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st)
5232{
5233 u32 val[4];
5234
5235 t4_read_indirect(adap, TP_MIB_INDEX_A, TP_MIB_DATA_A, val, 4,
5236 TP_MIB_USM_PKTS_A);
5237 st->frames = val[0];
5238 st->drops = val[1];
5239 st->octets = ((u64)val[2] << 32) | val[3];
5240}
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
5251{
5252 u32 v;
5253 int i;
5254
5255 for (i = 0; i < NMTUS; ++i) {
5256 t4_write_reg(adap, TP_MTU_TABLE_A,
5257 MTUINDEX_V(0xff) | MTUVALUE_V(i));
5258 v = t4_read_reg(adap, TP_MTU_TABLE_A);
5259 mtus[i] = MTUVALUE_G(v);
5260 if (mtu_log)
5261 mtu_log[i] = MTUWIDTH_G(v);
5262 }
5263}
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
5274{
5275 unsigned int mtu, w;
5276
5277 for (mtu = 0; mtu < NMTUS; ++mtu)
5278 for (w = 0; w < NCCTRL_WIN; ++w) {
5279 t4_write_reg(adap, TP_CCTRL_TABLE_A,
5280 ROWINDEX_V(0xffff) | (mtu << 5) | w);
5281 incr[mtu][w] = (u16)t4_read_reg(adap,
5282 TP_CCTRL_TABLE_A) & 0x1fff;
5283 }
5284}
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
5296 unsigned int mask, unsigned int val)
5297{
5298 t4_write_reg(adap, TP_PIO_ADDR_A, addr);
5299 val |= t4_read_reg(adap, TP_PIO_DATA_A) & ~mask;
5300 t4_write_reg(adap, TP_PIO_DATA_A, val);
5301}
5302
5303
5304
5305
5306
5307
5308
5309
5310static void init_cong_ctrl(unsigned short *a, unsigned short *b)
5311{
5312 a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
5313 a[9] = 2;
5314 a[10] = 3;
5315 a[11] = 4;
5316 a[12] = 5;
5317 a[13] = 6;
5318 a[14] = 7;
5319 a[15] = 8;
5320 a[16] = 9;
5321 a[17] = 10;
5322 a[18] = 14;
5323 a[19] = 17;
5324 a[20] = 21;
5325 a[21] = 25;
5326 a[22] = 30;
5327 a[23] = 35;
5328 a[24] = 45;
5329 a[25] = 60;
5330 a[26] = 80;
5331 a[27] = 100;
5332 a[28] = 200;
5333 a[29] = 300;
5334 a[30] = 400;
5335 a[31] = 500;
5336
5337 b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
5338 b[9] = b[10] = 1;
5339 b[11] = b[12] = 2;
5340 b[13] = b[14] = b[15] = b[16] = 3;
5341 b[17] = b[18] = b[19] = b[20] = b[21] = 4;
5342 b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
5343 b[28] = b[29] = 6;
5344 b[30] = b[31] = 7;
5345}
5346
5347
5348#define CC_MIN_INCR 2U
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
5363 const unsigned short *alpha, const unsigned short *beta)
5364{
5365 static const unsigned int avg_pkts[NCCTRL_WIN] = {
5366 2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
5367 896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
5368 28672, 40960, 57344, 81920, 114688, 163840, 229376
5369 };
5370
5371 unsigned int i, w;
5372
5373 for (i = 0; i < NMTUS; ++i) {
5374 unsigned int mtu = mtus[i];
5375 unsigned int log2 = fls(mtu);
5376
5377 if (!(mtu & ((1 << log2) >> 2)))
5378 log2--;
5379 t4_write_reg(adap, TP_MTU_TABLE_A, MTUINDEX_V(i) |
5380 MTUWIDTH_V(log2) | MTUVALUE_V(mtu));
5381
5382 for (w = 0; w < NCCTRL_WIN; ++w) {
5383 unsigned int inc;
5384
5385 inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
5386 CC_MIN_INCR);
5387
5388 t4_write_reg(adap, TP_CCTRL_TABLE_A, (i << 21) |
5389 (w << 16) | (beta[w] << 13) | inc);
5390 }
5391 }
5392}
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403static u64 chan_rate(struct adapter *adap, unsigned int bytes256)
5404{
5405 u64 v = bytes256 * adap->params.vpd.cclk;
5406
5407 return v * 62 + v / 2;
5408}
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate)
5420{
5421 u32 v;
5422
5423 v = t4_read_reg(adap, TP_TX_TRATE_A);
5424 nic_rate[0] = chan_rate(adap, TNLRATE0_G(v));
5425 nic_rate[1] = chan_rate(adap, TNLRATE1_G(v));
5426 if (adap->params.arch.nchan == NCHAN) {
5427 nic_rate[2] = chan_rate(adap, TNLRATE2_G(v));
5428 nic_rate[3] = chan_rate(adap, TNLRATE3_G(v));
5429 }
5430
5431 v = t4_read_reg(adap, TP_TX_ORATE_A);
5432 ofld_rate[0] = chan_rate(adap, OFDRATE0_G(v));
5433 ofld_rate[1] = chan_rate(adap, OFDRATE1_G(v));
5434 if (adap->params.arch.nchan == NCHAN) {
5435 ofld_rate[2] = chan_rate(adap, OFDRATE2_G(v));
5436 ofld_rate[3] = chan_rate(adap, OFDRATE3_G(v));
5437 }
5438}
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
5452 int idx, int enable)
5453{
5454 int i, ofst = idx * 4;
5455 u32 data_reg, mask_reg, cfg;
5456 u32 multitrc = TRCMULTIFILTER_F;
5457
5458 if (!enable) {
5459 t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
5460 return 0;
5461 }
5462
5463 cfg = t4_read_reg(adap, MPS_TRC_CFG_A);
5464 if (cfg & TRCMULTIFILTER_F) {
5465
5466
5467
5468
5469 if (tp->snap_len > ((10 * 1024 / 4) - (2 * 8)))
5470 return -EINVAL;
5471 } else {
5472
5473
5474
5475
5476 multitrc = 0;
5477 if (tp->snap_len > 9600 || idx)
5478 return -EINVAL;
5479 }
5480
5481 if (tp->port > (is_t4(adap->params.chip) ? 11 : 19) || tp->invert > 1 ||
5482 tp->skip_len > TFLENGTH_M || tp->skip_ofst > TFOFFSET_M ||
5483 tp->min_len > TFMINPKTSIZE_M)
5484 return -EINVAL;
5485
5486
5487 t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst, 0);
5488
5489 idx *= (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A);
5490 data_reg = MPS_TRC_FILTER0_MATCH_A + idx;
5491 mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + idx;
5492
5493 for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
5494 t4_write_reg(adap, data_reg, tp->data[i]);
5495 t4_write_reg(adap, mask_reg, ~tp->mask[i]);
5496 }
5497 t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst,
5498 TFCAPTUREMAX_V(tp->snap_len) |
5499 TFMINPKTSIZE_V(tp->min_len));
5500 t4_write_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst,
5501 TFOFFSET_V(tp->skip_ofst) | TFLENGTH_V(tp->skip_len) |
5502 (is_t4(adap->params.chip) ?
5503 TFPORT_V(tp->port) | TFEN_F | TFINVERTMATCH_V(tp->invert) :
5504 T5_TFPORT_V(tp->port) | T5_TFEN_F |
5505 T5_TFINVERTMATCH_V(tp->invert)));
5506
5507 return 0;
5508}
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
5520 int *enabled)
5521{
5522 u32 ctla, ctlb;
5523 int i, ofst = idx * 4;
5524 u32 data_reg, mask_reg;
5525
5526 ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A_A + ofst);
5527 ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B_A + ofst);
5528
5529 if (is_t4(adap->params.chip)) {
5530 *enabled = !!(ctla & TFEN_F);
5531 tp->port = TFPORT_G(ctla);
5532 tp->invert = !!(ctla & TFINVERTMATCH_F);
5533 } else {
5534 *enabled = !!(ctla & T5_TFEN_F);
5535 tp->port = T5_TFPORT_G(ctla);
5536 tp->invert = !!(ctla & T5_TFINVERTMATCH_F);
5537 }
5538 tp->snap_len = TFCAPTUREMAX_G(ctlb);
5539 tp->min_len = TFMINPKTSIZE_G(ctlb);
5540 tp->skip_ofst = TFOFFSET_G(ctla);
5541 tp->skip_len = TFLENGTH_G(ctla);
5542
5543 ofst = (MPS_TRC_FILTER1_MATCH_A - MPS_TRC_FILTER0_MATCH_A) * idx;
5544 data_reg = MPS_TRC_FILTER0_MATCH_A + ofst;
5545 mask_reg = MPS_TRC_FILTER0_DONT_CARE_A + ofst;
5546
5547 for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
5548 tp->mask[i] = ~t4_read_reg(adap, mask_reg);
5549 tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
5550 }
5551}
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
5562{
5563 int i;
5564 u32 data[2];
5565
5566 for (i = 0; i < adap->params.arch.pm_stats_cnt; i++) {
5567 t4_write_reg(adap, PM_TX_STAT_CONFIG_A, i + 1);
5568 cnt[i] = t4_read_reg(adap, PM_TX_STAT_COUNT_A);
5569 if (is_t4(adap->params.chip)) {
5570 cycles[i] = t4_read_reg64(adap, PM_TX_STAT_LSB_A);
5571 } else {
5572 t4_read_indirect(adap, PM_TX_DBG_CTRL_A,
5573 PM_TX_DBG_DATA_A, data, 2,
5574 PM_TX_DBG_STAT_MSB_A);
5575 cycles[i] = (((u64)data[0] << 32) | data[1]);
5576 }
5577 }
5578}
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
5589{
5590 int i;
5591 u32 data[2];
5592
5593 for (i = 0; i < adap->params.arch.pm_stats_cnt; i++) {
5594 t4_write_reg(adap, PM_RX_STAT_CONFIG_A, i + 1);
5595 cnt[i] = t4_read_reg(adap, PM_RX_STAT_COUNT_A);
5596 if (is_t4(adap->params.chip)) {
5597 cycles[i] = t4_read_reg64(adap, PM_RX_STAT_LSB_A);
5598 } else {
5599 t4_read_indirect(adap, PM_RX_DBG_CTRL_A,
5600 PM_RX_DBG_DATA_A, data, 2,
5601 PM_RX_DBG_STAT_MSB_A);
5602 cycles[i] = (((u64)data[0] << 32) | data[1]);
5603 }
5604 }
5605}
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616static inline unsigned int compute_mps_bg_map(struct adapter *adapter,
5617 int pidx)
5618{
5619 unsigned int chip_version, nports;
5620
5621 chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
5622 nports = 1 << NUMPORTS_G(t4_read_reg(adapter, MPS_CMN_CTL_A));
5623
5624 switch (chip_version) {
5625 case CHELSIO_T4:
5626 case CHELSIO_T5:
5627 switch (nports) {
5628 case 1: return 0xf;
5629 case 2: return 3 << (2 * pidx);
5630 case 4: return 1 << pidx;
5631 }
5632 break;
5633
5634 case CHELSIO_T6:
5635 switch (nports) {
5636 case 2: return 1 << (2 * pidx);
5637 }
5638 break;
5639 }
5640
5641 dev_err(adapter->pdev_dev, "Need MPS Buffer Group Map for Chip %0x, Nports %d\n",
5642 chip_version, nports);
5643
5644 return 0;
5645}
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656unsigned int t4_get_mps_bg_map(struct adapter *adapter, int pidx)
5657{
5658 u8 *mps_bg_map;
5659 unsigned int nports;
5660
5661 nports = 1 << NUMPORTS_G(t4_read_reg(adapter, MPS_CMN_CTL_A));
5662 if (pidx >= nports) {
5663 CH_WARN(adapter, "MPS Port Index %d >= Nports %d\n",
5664 pidx, nports);
5665 return 0;
5666 }
5667
5668
5669
5670 mps_bg_map = adapter->params.mps_bg_map;
5671 if (mps_bg_map[pidx])
5672 return mps_bg_map[pidx];
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684 if (adapter->flags & FW_OK) {
5685 u32 param, val;
5686 int ret;
5687
5688 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
5689 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_MPSBGMAP));
5690 ret = t4_query_params_ns(adapter, adapter->mbox, adapter->pf,
5691 0, 1, ¶m, &val);
5692 if (!ret) {
5693 int p;
5694
5695
5696
5697
5698 for (p = 0; p < MAX_NPORTS; p++, val >>= 8)
5699 mps_bg_map[p] = val & 0xff;
5700
5701 return mps_bg_map[pidx];
5702 }
5703 }
5704
5705
5706
5707
5708
5709 mps_bg_map[pidx] = compute_mps_bg_map(adapter, pidx);
5710 return mps_bg_map[pidx];
5711}
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722unsigned int t4_get_tp_ch_map(struct adapter *adap, int pidx)
5723{
5724 unsigned int chip_version = CHELSIO_CHIP_VERSION(adap->params.chip);
5725 unsigned int nports = 1 << NUMPORTS_G(t4_read_reg(adap, MPS_CMN_CTL_A));
5726
5727 if (pidx >= nports) {
5728 dev_warn(adap->pdev_dev, "TP Port Index %d >= Nports %d\n",
5729 pidx, nports);
5730 return 0;
5731 }
5732
5733 switch (chip_version) {
5734 case CHELSIO_T4:
5735 case CHELSIO_T5:
5736
5737
5738
5739
5740 switch (nports) {
5741 case 1: return 0xf;
5742 case 2: return 3 << (2 * pidx);
5743 case 4: return 1 << pidx;
5744 }
5745 break;
5746
5747 case CHELSIO_T6:
5748 switch (nports) {
5749 case 2: return 1 << pidx;
5750 }
5751 break;
5752 }
5753
5754 dev_err(adap->pdev_dev, "Need TP Channel Map for Chip %0x, Nports %d\n",
5755 chip_version, nports);
5756 return 0;
5757}
5758
5759
5760
5761
5762
5763const char *t4_get_port_type_description(enum fw_port_type port_type)
5764{
5765 static const char *const port_type_description[] = {
5766 "Fiber_XFI",
5767 "Fiber_XAUI",
5768 "BT_SGMII",
5769 "BT_XFI",
5770 "BT_XAUI",
5771 "KX4",
5772 "CX4",
5773 "KX",
5774 "KR",
5775 "SFP",
5776 "BP_AP",
5777 "BP4_AP",
5778 "QSFP_10G",
5779 "QSA",
5780 "QSFP",
5781 "BP40_BA",
5782 "KR4_100G",
5783 "CR4_QSFP",
5784 "CR_QSFP",
5785 "CR2_QSFP",
5786 "SFP28",
5787 "KR_SFP28",
5788 };
5789
5790 if (port_type < ARRAY_SIZE(port_type_description))
5791 return port_type_description[port_type];
5792 return "UNKNOWN";
5793}
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803void t4_get_port_stats_offset(struct adapter *adap, int idx,
5804 struct port_stats *stats,
5805 struct port_stats *offset)
5806{
5807 u64 *s, *o;
5808 int i;
5809
5810 t4_get_port_stats(adap, idx, stats);
5811 for (i = 0, s = (u64 *)stats, o = (u64 *)offset;
5812 i < (sizeof(struct port_stats) / sizeof(u64));
5813 i++, s++, o++)
5814 *s -= *o;
5815}
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
5826{
5827 u32 bgmap = t4_get_mps_bg_map(adap, idx);
5828 u32 stat_ctl = t4_read_reg(adap, MPS_STAT_CTL_A);
5829
5830#define GET_STAT(name) \
5831 t4_read_reg64(adap, \
5832 (is_t4(adap->params.chip) ? PORT_REG(idx, MPS_PORT_STAT_##name##_L) : \
5833 T5_PORT_REG(idx, MPS_PORT_STAT_##name##_L)))
5834#define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
5835
5836 p->tx_octets = GET_STAT(TX_PORT_BYTES);
5837 p->tx_frames = GET_STAT(TX_PORT_FRAMES);
5838 p->tx_bcast_frames = GET_STAT(TX_PORT_BCAST);
5839 p->tx_mcast_frames = GET_STAT(TX_PORT_MCAST);
5840 p->tx_ucast_frames = GET_STAT(TX_PORT_UCAST);
5841 p->tx_error_frames = GET_STAT(TX_PORT_ERROR);
5842 p->tx_frames_64 = GET_STAT(TX_PORT_64B);
5843 p->tx_frames_65_127 = GET_STAT(TX_PORT_65B_127B);
5844 p->tx_frames_128_255 = GET_STAT(TX_PORT_128B_255B);
5845 p->tx_frames_256_511 = GET_STAT(TX_PORT_256B_511B);
5846 p->tx_frames_512_1023 = GET_STAT(TX_PORT_512B_1023B);
5847 p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
5848 p->tx_frames_1519_max = GET_STAT(TX_PORT_1519B_MAX);
5849 p->tx_drop = GET_STAT(TX_PORT_DROP);
5850 p->tx_pause = GET_STAT(TX_PORT_PAUSE);
5851 p->tx_ppp0 = GET_STAT(TX_PORT_PPP0);
5852 p->tx_ppp1 = GET_STAT(TX_PORT_PPP1);
5853 p->tx_ppp2 = GET_STAT(TX_PORT_PPP2);
5854 p->tx_ppp3 = GET_STAT(TX_PORT_PPP3);
5855 p->tx_ppp4 = GET_STAT(TX_PORT_PPP4);
5856 p->tx_ppp5 = GET_STAT(TX_PORT_PPP5);
5857 p->tx_ppp6 = GET_STAT(TX_PORT_PPP6);
5858 p->tx_ppp7 = GET_STAT(TX_PORT_PPP7);
5859
5860 if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
5861 if (stat_ctl & COUNTPAUSESTATTX_F)
5862 p->tx_frames_64 -= p->tx_pause;
5863 if (stat_ctl & COUNTPAUSEMCTX_F)
5864 p->tx_mcast_frames -= p->tx_pause;
5865 }
5866 p->rx_octets = GET_STAT(RX_PORT_BYTES);
5867 p->rx_frames = GET_STAT(RX_PORT_FRAMES);
5868 p->rx_bcast_frames = GET_STAT(RX_PORT_BCAST);
5869 p->rx_mcast_frames = GET_STAT(RX_PORT_MCAST);
5870 p->rx_ucast_frames = GET_STAT(RX_PORT_UCAST);
5871 p->rx_too_long = GET_STAT(RX_PORT_MTU_ERROR);
5872 p->rx_jabber = GET_STAT(RX_PORT_MTU_CRC_ERROR);
5873 p->rx_fcs_err = GET_STAT(RX_PORT_CRC_ERROR);
5874 p->rx_len_err = GET_STAT(RX_PORT_LEN_ERROR);
5875 p->rx_symbol_err = GET_STAT(RX_PORT_SYM_ERROR);
5876 p->rx_runt = GET_STAT(RX_PORT_LESS_64B);
5877 p->rx_frames_64 = GET_STAT(RX_PORT_64B);
5878 p->rx_frames_65_127 = GET_STAT(RX_PORT_65B_127B);
5879 p->rx_frames_128_255 = GET_STAT(RX_PORT_128B_255B);
5880 p->rx_frames_256_511 = GET_STAT(RX_PORT_256B_511B);
5881 p->rx_frames_512_1023 = GET_STAT(RX_PORT_512B_1023B);
5882 p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
5883 p->rx_frames_1519_max = GET_STAT(RX_PORT_1519B_MAX);
5884 p->rx_pause = GET_STAT(RX_PORT_PAUSE);
5885 p->rx_ppp0 = GET_STAT(RX_PORT_PPP0);
5886 p->rx_ppp1 = GET_STAT(RX_PORT_PPP1);
5887 p->rx_ppp2 = GET_STAT(RX_PORT_PPP2);
5888 p->rx_ppp3 = GET_STAT(RX_PORT_PPP3);
5889 p->rx_ppp4 = GET_STAT(RX_PORT_PPP4);
5890 p->rx_ppp5 = GET_STAT(RX_PORT_PPP5);
5891 p->rx_ppp6 = GET_STAT(RX_PORT_PPP6);
5892 p->rx_ppp7 = GET_STAT(RX_PORT_PPP7);
5893
5894 if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
5895 if (stat_ctl & COUNTPAUSESTATRX_F)
5896 p->rx_frames_64 -= p->rx_pause;
5897 if (stat_ctl & COUNTPAUSEMCRX_F)
5898 p->rx_mcast_frames -= p->rx_pause;
5899 }
5900
5901 p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
5902 p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
5903 p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
5904 p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
5905 p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
5906 p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
5907 p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
5908 p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
5909
5910#undef GET_STAT
5911#undef GET_STAT_COM
5912}
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
5923{
5924 u32 bgmap = t4_get_mps_bg_map(adap, idx);
5925
5926#define GET_STAT(name) \
5927 t4_read_reg64(adap, \
5928 (is_t4(adap->params.chip) ? \
5929 PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L) : \
5930 T5_PORT_REG(idx, MPS_PORT_STAT_LB_PORT_##name##_L)))
5931#define GET_STAT_COM(name) t4_read_reg64(adap, MPS_STAT_##name##_L)
5932
5933 p->octets = GET_STAT(BYTES);
5934 p->frames = GET_STAT(FRAMES);
5935 p->bcast_frames = GET_STAT(BCAST);
5936 p->mcast_frames = GET_STAT(MCAST);
5937 p->ucast_frames = GET_STAT(UCAST);
5938 p->error_frames = GET_STAT(ERROR);
5939
5940 p->frames_64 = GET_STAT(64B);
5941 p->frames_65_127 = GET_STAT(65B_127B);
5942 p->frames_128_255 = GET_STAT(128B_255B);
5943 p->frames_256_511 = GET_STAT(256B_511B);
5944 p->frames_512_1023 = GET_STAT(512B_1023B);
5945 p->frames_1024_1518 = GET_STAT(1024B_1518B);
5946 p->frames_1519_max = GET_STAT(1519B_MAX);
5947 p->drop = GET_STAT(DROP_FRAMES);
5948
5949 p->ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
5950 p->ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
5951 p->ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
5952 p->ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
5953 p->trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
5954 p->trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
5955 p->trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
5956 p->trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
5957
5958#undef GET_STAT
5959#undef GET_STAT_COM
5960}
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
5971{
5972 memset(wr, 0, sizeof(*wr));
5973 wr->op_pkd = cpu_to_be32(FW_WR_OP_V(FW_FILTER_WR));
5974 wr->len16_pkd = cpu_to_be32(FW_WR_LEN16_V(sizeof(*wr) / 16));
5975 wr->tid_to_iq = cpu_to_be32(FW_FILTER_WR_TID_V(ftid) |
5976 FW_FILTER_WR_NOREPLY_V(qid < 0));
5977 wr->del_filter_to_l2tix = cpu_to_be32(FW_FILTER_WR_DEL_FILTER_F);
5978 if (qid >= 0)
5979 wr->rx_chan_rx_rpl_iq =
5980 cpu_to_be16(FW_FILTER_WR_RX_RPL_IQ_V(qid));
5981}
5982
5983#define INIT_CMD(var, cmd, rd_wr) do { \
5984 (var).op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_##cmd##_CMD) | \
5985 FW_CMD_REQUEST_F | \
5986 FW_CMD_##rd_wr##_F); \
5987 (var).retval_len16 = cpu_to_be32(FW_LEN16(var)); \
5988} while (0)
5989
5990int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
5991 u32 addr, u32 val)
5992{
5993 u32 ldst_addrspace;
5994 struct fw_ldst_cmd c;
5995
5996 memset(&c, 0, sizeof(c));
5997 ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FIRMWARE);
5998 c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
5999 FW_CMD_REQUEST_F |
6000 FW_CMD_WRITE_F |
6001 ldst_addrspace);
6002 c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
6003 c.u.addrval.addr = cpu_to_be32(addr);
6004 c.u.addrval.val = cpu_to_be32(val);
6005
6006 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6007}
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
6021 unsigned int mmd, unsigned int reg, u16 *valp)
6022{
6023 int ret;
6024 u32 ldst_addrspace;
6025 struct fw_ldst_cmd c;
6026
6027 memset(&c, 0, sizeof(c));
6028 ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
6029 c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
6030 FW_CMD_REQUEST_F | FW_CMD_READ_F |
6031 ldst_addrspace);
6032 c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
6033 c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
6034 FW_LDST_CMD_MMD_V(mmd));
6035 c.u.mdio.raddr = cpu_to_be16(reg);
6036
6037 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
6038 if (ret == 0)
6039 *valp = be16_to_cpu(c.u.mdio.rval);
6040 return ret;
6041}
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
6055 unsigned int mmd, unsigned int reg, u16 val)
6056{
6057 u32 ldst_addrspace;
6058 struct fw_ldst_cmd c;
6059
6060 memset(&c, 0, sizeof(c));
6061 ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MDIO);
6062 c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
6063 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
6064 ldst_addrspace);
6065 c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
6066 c.u.mdio.paddr_mmd = cpu_to_be16(FW_LDST_CMD_PADDR_V(phy_addr) |
6067 FW_LDST_CMD_MMD_V(mmd));
6068 c.u.mdio.raddr = cpu_to_be16(reg);
6069 c.u.mdio.rval = cpu_to_be16(val);
6070
6071 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6072}
6073
6074
6075
6076
6077
6078
6079void t4_sge_decode_idma_state(struct adapter *adapter, int state)
6080{
6081 static const char * const t4_decode[] = {
6082 "IDMA_IDLE",
6083 "IDMA_PUSH_MORE_CPL_FIFO",
6084 "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
6085 "Not used",
6086 "IDMA_PHYSADDR_SEND_PCIEHDR",
6087 "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
6088 "IDMA_PHYSADDR_SEND_PAYLOAD",
6089 "IDMA_SEND_FIFO_TO_IMSG",
6090 "IDMA_FL_REQ_DATA_FL_PREP",
6091 "IDMA_FL_REQ_DATA_FL",
6092 "IDMA_FL_DROP",
6093 "IDMA_FL_H_REQ_HEADER_FL",
6094 "IDMA_FL_H_SEND_PCIEHDR",
6095 "IDMA_FL_H_PUSH_CPL_FIFO",
6096 "IDMA_FL_H_SEND_CPL",
6097 "IDMA_FL_H_SEND_IP_HDR_FIRST",
6098 "IDMA_FL_H_SEND_IP_HDR",
6099 "IDMA_FL_H_REQ_NEXT_HEADER_FL",
6100 "IDMA_FL_H_SEND_NEXT_PCIEHDR",
6101 "IDMA_FL_H_SEND_IP_HDR_PADDING",
6102 "IDMA_FL_D_SEND_PCIEHDR",
6103 "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
6104 "IDMA_FL_D_REQ_NEXT_DATA_FL",
6105 "IDMA_FL_SEND_PCIEHDR",
6106 "IDMA_FL_PUSH_CPL_FIFO",
6107 "IDMA_FL_SEND_CPL",
6108 "IDMA_FL_SEND_PAYLOAD_FIRST",
6109 "IDMA_FL_SEND_PAYLOAD",
6110 "IDMA_FL_REQ_NEXT_DATA_FL",
6111 "IDMA_FL_SEND_NEXT_PCIEHDR",
6112 "IDMA_FL_SEND_PADDING",
6113 "IDMA_FL_SEND_COMPLETION_TO_IMSG",
6114 "IDMA_FL_SEND_FIFO_TO_IMSG",
6115 "IDMA_FL_REQ_DATAFL_DONE",
6116 "IDMA_FL_REQ_HEADERFL_DONE",
6117 };
6118 static const char * const t5_decode[] = {
6119 "IDMA_IDLE",
6120 "IDMA_ALMOST_IDLE",
6121 "IDMA_PUSH_MORE_CPL_FIFO",
6122 "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
6123 "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
6124 "IDMA_PHYSADDR_SEND_PCIEHDR",
6125 "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
6126 "IDMA_PHYSADDR_SEND_PAYLOAD",
6127 "IDMA_SEND_FIFO_TO_IMSG",
6128 "IDMA_FL_REQ_DATA_FL",
6129 "IDMA_FL_DROP",
6130 "IDMA_FL_DROP_SEND_INC",
6131 "IDMA_FL_H_REQ_HEADER_FL",
6132 "IDMA_FL_H_SEND_PCIEHDR",
6133 "IDMA_FL_H_PUSH_CPL_FIFO",
6134 "IDMA_FL_H_SEND_CPL",
6135 "IDMA_FL_H_SEND_IP_HDR_FIRST",
6136 "IDMA_FL_H_SEND_IP_HDR",
6137 "IDMA_FL_H_REQ_NEXT_HEADER_FL",
6138 "IDMA_FL_H_SEND_NEXT_PCIEHDR",
6139 "IDMA_FL_H_SEND_IP_HDR_PADDING",
6140 "IDMA_FL_D_SEND_PCIEHDR",
6141 "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
6142 "IDMA_FL_D_REQ_NEXT_DATA_FL",
6143 "IDMA_FL_SEND_PCIEHDR",
6144 "IDMA_FL_PUSH_CPL_FIFO",
6145 "IDMA_FL_SEND_CPL",
6146 "IDMA_FL_SEND_PAYLOAD_FIRST",
6147 "IDMA_FL_SEND_PAYLOAD",
6148 "IDMA_FL_REQ_NEXT_DATA_FL",
6149 "IDMA_FL_SEND_NEXT_PCIEHDR",
6150 "IDMA_FL_SEND_PADDING",
6151 "IDMA_FL_SEND_COMPLETION_TO_IMSG",
6152 };
6153 static const char * const t6_decode[] = {
6154 "IDMA_IDLE",
6155 "IDMA_PUSH_MORE_CPL_FIFO",
6156 "IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
6157 "IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
6158 "IDMA_PHYSADDR_SEND_PCIEHDR",
6159 "IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
6160 "IDMA_PHYSADDR_SEND_PAYLOAD",
6161 "IDMA_FL_REQ_DATA_FL",
6162 "IDMA_FL_DROP",
6163 "IDMA_FL_DROP_SEND_INC",
6164 "IDMA_FL_H_REQ_HEADER_FL",
6165 "IDMA_FL_H_SEND_PCIEHDR",
6166 "IDMA_FL_H_PUSH_CPL_FIFO",
6167 "IDMA_FL_H_SEND_CPL",
6168 "IDMA_FL_H_SEND_IP_HDR_FIRST",
6169 "IDMA_FL_H_SEND_IP_HDR",
6170 "IDMA_FL_H_REQ_NEXT_HEADER_FL",
6171 "IDMA_FL_H_SEND_NEXT_PCIEHDR",
6172 "IDMA_FL_H_SEND_IP_HDR_PADDING",
6173 "IDMA_FL_D_SEND_PCIEHDR",
6174 "IDMA_FL_D_SEND_CPL_AND_IP_HDR",
6175 "IDMA_FL_D_REQ_NEXT_DATA_FL",
6176 "IDMA_FL_SEND_PCIEHDR",
6177 "IDMA_FL_PUSH_CPL_FIFO",
6178 "IDMA_FL_SEND_CPL",
6179 "IDMA_FL_SEND_PAYLOAD_FIRST",
6180 "IDMA_FL_SEND_PAYLOAD",
6181 "IDMA_FL_REQ_NEXT_DATA_FL",
6182 "IDMA_FL_SEND_NEXT_PCIEHDR",
6183 "IDMA_FL_SEND_PADDING",
6184 "IDMA_FL_SEND_COMPLETION_TO_IMSG",
6185 };
6186 static const u32 sge_regs[] = {
6187 SGE_DEBUG_DATA_LOW_INDEX_2_A,
6188 SGE_DEBUG_DATA_LOW_INDEX_3_A,
6189 SGE_DEBUG_DATA_HIGH_INDEX_10_A,
6190 };
6191 const char **sge_idma_decode;
6192 int sge_idma_decode_nstates;
6193 int i;
6194 unsigned int chip_version = CHELSIO_CHIP_VERSION(adapter->params.chip);
6195
6196
6197
6198
6199 switch (chip_version) {
6200 case CHELSIO_T4:
6201 sge_idma_decode = (const char **)t4_decode;
6202 sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
6203 break;
6204
6205 case CHELSIO_T5:
6206 sge_idma_decode = (const char **)t5_decode;
6207 sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
6208 break;
6209
6210 case CHELSIO_T6:
6211 sge_idma_decode = (const char **)t6_decode;
6212 sge_idma_decode_nstates = ARRAY_SIZE(t6_decode);
6213 break;
6214
6215 default:
6216 dev_err(adapter->pdev_dev,
6217 "Unsupported chip version %d\n", chip_version);
6218 return;
6219 }
6220
6221 if (is_t4(adapter->params.chip)) {
6222 sge_idma_decode = (const char **)t4_decode;
6223 sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
6224 } else {
6225 sge_idma_decode = (const char **)t5_decode;
6226 sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
6227 }
6228
6229 if (state < sge_idma_decode_nstates)
6230 CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
6231 else
6232 CH_WARN(adapter, "idma state %d unknown\n", state);
6233
6234 for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
6235 CH_WARN(adapter, "SGE register %#x value %#x\n",
6236 sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
6237}
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox)
6248{
6249 int ret;
6250 u32 ldst_addrspace;
6251 struct fw_ldst_cmd c;
6252
6253 memset(&c, 0, sizeof(c));
6254 ldst_addrspace = FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_SGE_EGRC);
6255 c.op_to_addrspace = cpu_to_be32(FW_CMD_OP_V(FW_LDST_CMD) |
6256 FW_CMD_REQUEST_F | FW_CMD_READ_F |
6257 ldst_addrspace);
6258 c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
6259 c.u.idctxt.msg_ctxtflush = cpu_to_be32(FW_LDST_CMD_CTXTFLUSH_F);
6260
6261 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
6262 return ret;
6263}
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
6277 enum dev_master master, enum dev_state *state)
6278{
6279 int ret;
6280 struct fw_hello_cmd c;
6281 u32 v;
6282 unsigned int master_mbox;
6283 int retries = FW_CMD_HELLO_RETRIES;
6284
6285retry:
6286 memset(&c, 0, sizeof(c));
6287 INIT_CMD(c, HELLO, WRITE);
6288 c.err_to_clearinit = cpu_to_be32(
6289 FW_HELLO_CMD_MASTERDIS_V(master == MASTER_CANT) |
6290 FW_HELLO_CMD_MASTERFORCE_V(master == MASTER_MUST) |
6291 FW_HELLO_CMD_MBMASTER_V(master == MASTER_MUST ?
6292 mbox : FW_HELLO_CMD_MBMASTER_M) |
6293 FW_HELLO_CMD_MBASYNCNOT_V(evt_mbox) |
6294 FW_HELLO_CMD_STAGE_V(fw_hello_cmd_stage_os) |
6295 FW_HELLO_CMD_CLEARINIT_F);
6296
6297
6298
6299
6300
6301
6302
6303
6304 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
6305 if (ret < 0) {
6306 if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
6307 goto retry;
6308 if (t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_ERR_F)
6309 t4_report_fw_error(adap);
6310 return ret;
6311 }
6312
6313 v = be32_to_cpu(c.err_to_clearinit);
6314 master_mbox = FW_HELLO_CMD_MBMASTER_G(v);
6315 if (state) {
6316 if (v & FW_HELLO_CMD_ERR_F)
6317 *state = DEV_STATE_ERR;
6318 else if (v & FW_HELLO_CMD_INIT_F)
6319 *state = DEV_STATE_INIT;
6320 else
6321 *state = DEV_STATE_UNINIT;
6322 }
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335 if ((v & (FW_HELLO_CMD_ERR_F|FW_HELLO_CMD_INIT_F)) == 0 &&
6336 master_mbox != mbox) {
6337 int waiting = FW_CMD_HELLO_TIMEOUT;
6338
6339
6340
6341
6342
6343
6344
6345
6346 for (;;) {
6347 u32 pcie_fw;
6348
6349 msleep(50);
6350 waiting -= 50;
6351
6352
6353
6354
6355
6356
6357
6358 pcie_fw = t4_read_reg(adap, PCIE_FW_A);
6359 if (!(pcie_fw & (PCIE_FW_ERR_F|PCIE_FW_INIT_F))) {
6360 if (waiting <= 0) {
6361 if (retries-- > 0)
6362 goto retry;
6363
6364 return -ETIMEDOUT;
6365 }
6366 continue;
6367 }
6368
6369
6370
6371
6372
6373 if (state) {
6374 if (pcie_fw & PCIE_FW_ERR_F)
6375 *state = DEV_STATE_ERR;
6376 else if (pcie_fw & PCIE_FW_INIT_F)
6377 *state = DEV_STATE_INIT;
6378 }
6379
6380
6381
6382
6383
6384
6385 if (master_mbox == PCIE_FW_MASTER_M &&
6386 (pcie_fw & PCIE_FW_MASTER_VLD_F))
6387 master_mbox = PCIE_FW_MASTER_G(pcie_fw);
6388 break;
6389 }
6390 }
6391
6392 return master_mbox;
6393}
6394
6395
6396
6397
6398
6399
6400
6401
6402int t4_fw_bye(struct adapter *adap, unsigned int mbox)
6403{
6404 struct fw_bye_cmd c;
6405
6406 memset(&c, 0, sizeof(c));
6407 INIT_CMD(c, BYE, WRITE);
6408 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6409}
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419int t4_early_init(struct adapter *adap, unsigned int mbox)
6420{
6421 struct fw_initialize_cmd c;
6422
6423 memset(&c, 0, sizeof(c));
6424 INIT_CMD(c, INITIALIZE, WRITE);
6425 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6426}
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
6437{
6438 struct fw_reset_cmd c;
6439
6440 memset(&c, 0, sizeof(c));
6441 INIT_CMD(c, RESET, WRITE);
6442 c.val = cpu_to_be32(reset);
6443 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6444}
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
6463{
6464 int ret = 0;
6465
6466
6467
6468
6469
6470 if (mbox <= PCIE_FW_MASTER_M) {
6471 struct fw_reset_cmd c;
6472
6473 memset(&c, 0, sizeof(c));
6474 INIT_CMD(c, RESET, WRITE);
6475 c.val = cpu_to_be32(PIORST_F | PIORSTMODE_F);
6476 c.halt_pkd = cpu_to_be32(FW_RESET_CMD_HALT_F);
6477 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6478 }
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493 if (ret == 0 || force) {
6494 t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, UPCRST_F);
6495 t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F,
6496 PCIE_FW_HALT_F);
6497 }
6498
6499
6500
6501
6502
6503 return ret;
6504}
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
6528{
6529 if (reset) {
6530
6531
6532
6533
6534
6535 t4_set_reg_field(adap, PCIE_FW_A, PCIE_FW_HALT_F, 0);
6536
6537
6538
6539
6540
6541
6542
6543
6544 if (mbox <= PCIE_FW_MASTER_M) {
6545 t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
6546 msleep(100);
6547 if (t4_fw_reset(adap, mbox,
6548 PIORST_F | PIORSTMODE_F) == 0)
6549 return 0;
6550 }
6551
6552 t4_write_reg(adap, PL_RST_A, PIORST_F | PIORSTMODE_F);
6553 msleep(2000);
6554 } else {
6555 int ms;
6556
6557 t4_set_reg_field(adap, CIM_BOOT_CFG_A, UPCRST_F, 0);
6558 for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
6559 if (!(t4_read_reg(adap, PCIE_FW_A) & PCIE_FW_HALT_F))
6560 return 0;
6561 msleep(100);
6562 ms += 100;
6563 }
6564 return -ETIMEDOUT;
6565 }
6566 return 0;
6567}
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
6591 const u8 *fw_data, unsigned int size, int force)
6592{
6593 const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
6594 int reset, ret;
6595
6596 if (!t4_fw_matches_chip(adap, fw_hdr))
6597 return -EINVAL;
6598
6599
6600
6601
6602 adap->flags &= ~FW_OK;
6603
6604 ret = t4_fw_halt(adap, mbox, force);
6605 if (ret < 0 && !force)
6606 goto out;
6607
6608 ret = t4_load_fw(adap, fw_data, size);
6609 if (ret < 0)
6610 goto out;
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621 (void)t4_load_cfg(adap, NULL, 0);
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631 reset = ((be32_to_cpu(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
6632 ret = t4_fw_restart(adap, mbox, reset);
6633
6634
6635
6636
6637
6638
6639 (void)t4_init_devlog_params(adap);
6640out:
6641 adap->flags |= FW_OK;
6642 return ret;
6643}
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654int t4_fl_pkt_align(struct adapter *adap)
6655{
6656 u32 sge_control, sge_control2;
6657 unsigned int ingpadboundary, ingpackboundary, fl_align, ingpad_shift;
6658
6659 sge_control = t4_read_reg(adap, SGE_CONTROL_A);
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
6674 ingpad_shift = INGPADBOUNDARY_SHIFT_X;
6675 else
6676 ingpad_shift = T6_INGPADBOUNDARY_SHIFT_X;
6677
6678 ingpadboundary = 1 << (INGPADBOUNDARY_G(sge_control) + ingpad_shift);
6679
6680 fl_align = ingpadboundary;
6681 if (!is_t4(adap->params.chip)) {
6682
6683
6684
6685 sge_control2 = t4_read_reg(adap, SGE_CONTROL2_A);
6686 ingpackboundary = INGPACKBOUNDARY_G(sge_control2);
6687 if (ingpackboundary == INGPACKBOUNDARY_16B_X)
6688 ingpackboundary = 16;
6689 else
6690 ingpackboundary = 1 << (ingpackboundary +
6691 INGPACKBOUNDARY_SHIFT_X);
6692
6693 fl_align = max(ingpadboundary, ingpackboundary);
6694 }
6695 return fl_align;
6696}
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
6709 unsigned int cache_line_size)
6710{
6711 unsigned int page_shift = fls(page_size) - 1;
6712 unsigned int sge_hps = page_shift - 10;
6713 unsigned int stat_len = cache_line_size > 64 ? 128 : 64;
6714 unsigned int fl_align = cache_line_size < 32 ? 32 : cache_line_size;
6715 unsigned int fl_align_log = fls(fl_align) - 1;
6716
6717 t4_write_reg(adap, SGE_HOST_PAGE_SIZE_A,
6718 HOSTPAGESIZEPF0_V(sge_hps) |
6719 HOSTPAGESIZEPF1_V(sge_hps) |
6720 HOSTPAGESIZEPF2_V(sge_hps) |
6721 HOSTPAGESIZEPF3_V(sge_hps) |
6722 HOSTPAGESIZEPF4_V(sge_hps) |
6723 HOSTPAGESIZEPF5_V(sge_hps) |
6724 HOSTPAGESIZEPF6_V(sge_hps) |
6725 HOSTPAGESIZEPF7_V(sge_hps));
6726
6727 if (is_t4(adap->params.chip)) {
6728 t4_set_reg_field(adap, SGE_CONTROL_A,
6729 INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
6730 EGRSTATUSPAGESIZE_F,
6731 INGPADBOUNDARY_V(fl_align_log -
6732 INGPADBOUNDARY_SHIFT_X) |
6733 EGRSTATUSPAGESIZE_V(stat_len != 64));
6734 } else {
6735 unsigned int pack_align;
6736 unsigned int ingpad, ingpack;
6737 unsigned int pcie_cap;
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761 pack_align = fl_align;
6762 pcie_cap = pci_find_capability(adap->pdev, PCI_CAP_ID_EXP);
6763 if (pcie_cap) {
6764 unsigned int mps, mps_log;
6765 u16 devctl;
6766
6767
6768
6769
6770
6771 pci_read_config_word(adap->pdev,
6772 pcie_cap + PCI_EXP_DEVCTL,
6773 &devctl);
6774 mps_log = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5) + 7;
6775 mps = 1 << mps_log;
6776 if (mps > pack_align)
6777 pack_align = mps;
6778 }
6779
6780
6781
6782
6783
6784
6785 if (pack_align <= 16) {
6786 ingpack = INGPACKBOUNDARY_16B_X;
6787 fl_align = 16;
6788 } else if (pack_align == 32) {
6789 ingpack = INGPACKBOUNDARY_64B_X;
6790 fl_align = 64;
6791 } else {
6792 unsigned int pack_align_log = fls(pack_align) - 1;
6793
6794 ingpack = pack_align_log - INGPACKBOUNDARY_SHIFT_X;
6795 fl_align = pack_align;
6796 }
6797
6798
6799
6800
6801
6802
6803 if (is_t5(adap->params.chip))
6804 ingpad = INGPADBOUNDARY_32B_X;
6805 else
6806 ingpad = T6_INGPADBOUNDARY_8B_X;
6807
6808 t4_set_reg_field(adap, SGE_CONTROL_A,
6809 INGPADBOUNDARY_V(INGPADBOUNDARY_M) |
6810 EGRSTATUSPAGESIZE_F,
6811 INGPADBOUNDARY_V(ingpad) |
6812 EGRSTATUSPAGESIZE_V(stat_len != 64));
6813 t4_set_reg_field(adap, SGE_CONTROL2_A,
6814 INGPACKBOUNDARY_V(INGPACKBOUNDARY_M),
6815 INGPACKBOUNDARY_V(ingpack));
6816 }
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838 t4_write_reg(adap, SGE_FL_BUFFER_SIZE0_A, page_size);
6839 t4_write_reg(adap, SGE_FL_BUFFER_SIZE2_A,
6840 (t4_read_reg(adap, SGE_FL_BUFFER_SIZE2_A) + fl_align-1)
6841 & ~(fl_align-1));
6842 t4_write_reg(adap, SGE_FL_BUFFER_SIZE3_A,
6843 (t4_read_reg(adap, SGE_FL_BUFFER_SIZE3_A) + fl_align-1)
6844 & ~(fl_align-1));
6845
6846 t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(page_shift - 12));
6847
6848 return 0;
6849}
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
6860{
6861 struct fw_initialize_cmd c;
6862
6863 memset(&c, 0, sizeof(c));
6864 INIT_CMD(c, INITIALIZE, WRITE);
6865 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
6866}
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
6884 unsigned int vf, unsigned int nparams, const u32 *params,
6885 u32 *val, int rw, bool sleep_ok)
6886{
6887 int i, ret;
6888 struct fw_params_cmd c;
6889 __be32 *p = &c.param[0].mnem;
6890
6891 if (nparams > 7)
6892 return -EINVAL;
6893
6894 memset(&c, 0, sizeof(c));
6895 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
6896 FW_CMD_REQUEST_F | FW_CMD_READ_F |
6897 FW_PARAMS_CMD_PFN_V(pf) |
6898 FW_PARAMS_CMD_VFN_V(vf));
6899 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
6900
6901 for (i = 0; i < nparams; i++) {
6902 *p++ = cpu_to_be32(*params++);
6903 if (rw)
6904 *p = cpu_to_be32(*(val + i));
6905 p++;
6906 }
6907
6908 ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
6909 if (ret == 0)
6910 for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
6911 *val++ = be32_to_cpu(*p);
6912 return ret;
6913}
6914
6915int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
6916 unsigned int vf, unsigned int nparams, const u32 *params,
6917 u32 *val)
6918{
6919 return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0,
6920 true);
6921}
6922
6923int t4_query_params_ns(struct adapter *adap, unsigned int mbox, unsigned int pf,
6924 unsigned int vf, unsigned int nparams, const u32 *params,
6925 u32 *val)
6926{
6927 return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0,
6928 false);
6929}
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
6946 unsigned int pf, unsigned int vf,
6947 unsigned int nparams, const u32 *params,
6948 const u32 *val, int timeout)
6949{
6950 struct fw_params_cmd c;
6951 __be32 *p = &c.param[0].mnem;
6952
6953 if (nparams > 7)
6954 return -EINVAL;
6955
6956 memset(&c, 0, sizeof(c));
6957 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
6958 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
6959 FW_PARAMS_CMD_PFN_V(pf) |
6960 FW_PARAMS_CMD_VFN_V(vf));
6961 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
6962
6963 while (nparams--) {
6964 *p++ = cpu_to_be32(*params++);
6965 *p++ = cpu_to_be32(*val++);
6966 }
6967
6968 return t4_wr_mbox_timeout(adap, mbox, &c, sizeof(c), NULL, timeout);
6969}
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
6985 unsigned int vf, unsigned int nparams, const u32 *params,
6986 const u32 *val)
6987{
6988 return t4_set_params_timeout(adap, mbox, pf, vf, nparams, params, val,
6989 FW_CMD_MAX_TIMEOUT);
6990}
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
7014 unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
7015 unsigned int rxqi, unsigned int rxq, unsigned int tc,
7016 unsigned int vi, unsigned int cmask, unsigned int pmask,
7017 unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
7018{
7019 struct fw_pfvf_cmd c;
7020
7021 memset(&c, 0, sizeof(c));
7022 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) | FW_CMD_REQUEST_F |
7023 FW_CMD_WRITE_F | FW_PFVF_CMD_PFN_V(pf) |
7024 FW_PFVF_CMD_VFN_V(vf));
7025 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
7026 c.niqflint_niq = cpu_to_be32(FW_PFVF_CMD_NIQFLINT_V(rxqi) |
7027 FW_PFVF_CMD_NIQ_V(rxq));
7028 c.type_to_neq = cpu_to_be32(FW_PFVF_CMD_CMASK_V(cmask) |
7029 FW_PFVF_CMD_PMASK_V(pmask) |
7030 FW_PFVF_CMD_NEQ_V(txq));
7031 c.tc_to_nexactf = cpu_to_be32(FW_PFVF_CMD_TC_V(tc) |
7032 FW_PFVF_CMD_NVI_V(vi) |
7033 FW_PFVF_CMD_NEXACTF_V(nexact));
7034 c.r_caps_to_nethctrl = cpu_to_be32(FW_PFVF_CMD_R_CAPS_V(rcaps) |
7035 FW_PFVF_CMD_WX_CAPS_V(wxcaps) |
7036 FW_PFVF_CMD_NETHCTRL_V(txq_eth_ctrl));
7037 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7038}
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
7058 unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
7059 unsigned int *rss_size)
7060{
7061 int ret;
7062 struct fw_vi_cmd c;
7063
7064 memset(&c, 0, sizeof(c));
7065 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) | FW_CMD_REQUEST_F |
7066 FW_CMD_WRITE_F | FW_CMD_EXEC_F |
7067 FW_VI_CMD_PFN_V(pf) | FW_VI_CMD_VFN_V(vf));
7068 c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_ALLOC_F | FW_LEN16(c));
7069 c.portid_pkd = FW_VI_CMD_PORTID_V(port);
7070 c.nmac = nmac - 1;
7071
7072 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
7073 if (ret)
7074 return ret;
7075
7076 if (mac) {
7077 memcpy(mac, c.mac, sizeof(c.mac));
7078 switch (nmac) {
7079 case 5:
7080 memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
7081 case 4:
7082 memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
7083 case 3:
7084 memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
7085 case 2:
7086 memcpy(mac + 6, c.nmac0, sizeof(c.nmac0));
7087 }
7088 }
7089 if (rss_size)
7090 *rss_size = FW_VI_CMD_RSSSIZE_G(be16_to_cpu(c.rsssize_pkd));
7091 return FW_VI_CMD_VIID_G(be16_to_cpu(c.type_viid));
7092}
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
7105 unsigned int vf, unsigned int viid)
7106{
7107 struct fw_vi_cmd c;
7108
7109 memset(&c, 0, sizeof(c));
7110 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
7111 FW_CMD_REQUEST_F |
7112 FW_CMD_EXEC_F |
7113 FW_VI_CMD_PFN_V(pf) |
7114 FW_VI_CMD_VFN_V(vf));
7115 c.alloc_to_len16 = cpu_to_be32(FW_VI_CMD_FREE_F | FW_LEN16(c));
7116 c.type_viid = cpu_to_be16(FW_VI_CMD_VIID_V(viid));
7117
7118 return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
7119}
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
7136 int mtu, int promisc, int all_multi, int bcast, int vlanex,
7137 bool sleep_ok)
7138{
7139 struct fw_vi_rxmode_cmd c;
7140
7141
7142 if (mtu < 0)
7143 mtu = FW_RXMODE_MTU_NO_CHG;
7144 if (promisc < 0)
7145 promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
7146 if (all_multi < 0)
7147 all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
7148 if (bcast < 0)
7149 bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
7150 if (vlanex < 0)
7151 vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
7152
7153 memset(&c, 0, sizeof(c));
7154 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
7155 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7156 FW_VI_RXMODE_CMD_VIID_V(viid));
7157 c.retval_len16 = cpu_to_be32(FW_LEN16(c));
7158 c.mtu_to_vlanexen =
7159 cpu_to_be32(FW_VI_RXMODE_CMD_MTU_V(mtu) |
7160 FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
7161 FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
7162 FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
7163 FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
7164 return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
7165}
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
7190 unsigned int viid, bool free, unsigned int naddr,
7191 const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
7192{
7193 int offset, ret = 0;
7194 struct fw_vi_mac_cmd c;
7195 unsigned int nfilters = 0;
7196 unsigned int max_naddr = adap->params.arch.mps_tcam_size;
7197 unsigned int rem = naddr;
7198
7199 if (naddr > max_naddr)
7200 return -EINVAL;
7201
7202 for (offset = 0; offset < naddr ; ) {
7203 unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact) ?
7204 rem : ARRAY_SIZE(c.u.exact));
7205 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
7206 u.exact[fw_naddr]), 16);
7207 struct fw_vi_mac_exact *p;
7208 int i;
7209
7210 memset(&c, 0, sizeof(c));
7211 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7212 FW_CMD_REQUEST_F |
7213 FW_CMD_WRITE_F |
7214 FW_CMD_EXEC_V(free) |
7215 FW_VI_MAC_CMD_VIID_V(viid));
7216 c.freemacs_to_len16 =
7217 cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(free) |
7218 FW_CMD_LEN16_V(len16));
7219
7220 for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
7221 p->valid_to_idx =
7222 cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
7223 FW_VI_MAC_CMD_IDX_V(
7224 FW_VI_MAC_ADD_MAC));
7225 memcpy(p->macaddr, addr[offset + i],
7226 sizeof(p->macaddr));
7227 }
7228
7229
7230
7231
7232
7233 ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
7234 if (ret && ret != -FW_ENOMEM)
7235 break;
7236
7237 for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
7238 u16 index = FW_VI_MAC_CMD_IDX_G(
7239 be16_to_cpu(p->valid_to_idx));
7240
7241 if (idx)
7242 idx[offset + i] = (index >= max_naddr ?
7243 0xffff : index);
7244 if (index < max_naddr)
7245 nfilters++;
7246 else if (hash)
7247 *hash |= (1ULL <<
7248 hash_mac_addr(addr[offset + i]));
7249 }
7250
7251 free = false;
7252 offset += fw_naddr;
7253 rem -= fw_naddr;
7254 }
7255
7256 if (ret == 0 || ret == -FW_ENOMEM)
7257 ret = nfilters;
7258 return ret;
7259}
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274int t4_free_mac_filt(struct adapter *adap, unsigned int mbox,
7275 unsigned int viid, unsigned int naddr,
7276 const u8 **addr, bool sleep_ok)
7277{
7278 int offset, ret = 0;
7279 struct fw_vi_mac_cmd c;
7280 unsigned int nfilters = 0;
7281 unsigned int max_naddr = is_t4(adap->params.chip) ?
7282 NUM_MPS_CLS_SRAM_L_INSTANCES :
7283 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
7284 unsigned int rem = naddr;
7285
7286 if (naddr > max_naddr)
7287 return -EINVAL;
7288
7289 for (offset = 0; offset < (int)naddr ; ) {
7290 unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
7291 ? rem
7292 : ARRAY_SIZE(c.u.exact));
7293 size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
7294 u.exact[fw_naddr]), 16);
7295 struct fw_vi_mac_exact *p;
7296 int i;
7297
7298 memset(&c, 0, sizeof(c));
7299 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7300 FW_CMD_REQUEST_F |
7301 FW_CMD_WRITE_F |
7302 FW_CMD_EXEC_V(0) |
7303 FW_VI_MAC_CMD_VIID_V(viid));
7304 c.freemacs_to_len16 =
7305 cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(0) |
7306 FW_CMD_LEN16_V(len16));
7307
7308 for (i = 0, p = c.u.exact; i < (int)fw_naddr; i++, p++) {
7309 p->valid_to_idx = cpu_to_be16(
7310 FW_VI_MAC_CMD_VALID_F |
7311 FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_MAC_BASED_FREE));
7312 memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
7313 }
7314
7315 ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
7316 if (ret)
7317 break;
7318
7319 for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
7320 u16 index = FW_VI_MAC_CMD_IDX_G(
7321 be16_to_cpu(p->valid_to_idx));
7322
7323 if (index < max_naddr)
7324 nfilters++;
7325 }
7326
7327 offset += fw_naddr;
7328 rem -= fw_naddr;
7329 }
7330
7331 if (ret == 0)
7332 ret = nfilters;
7333 return ret;
7334}
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
7356 int idx, const u8 *addr, bool persist, bool add_smt)
7357{
7358 int ret, mode;
7359 struct fw_vi_mac_cmd c;
7360 struct fw_vi_mac_exact *p = c.u.exact;
7361 unsigned int max_mac_addr = adap->params.arch.mps_tcam_size;
7362
7363 if (idx < 0)
7364 idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
7365 mode = add_smt ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
7366
7367 memset(&c, 0, sizeof(c));
7368 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7369 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7370 FW_VI_MAC_CMD_VIID_V(viid));
7371 c.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16_V(1));
7372 p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
7373 FW_VI_MAC_CMD_SMAC_RESULT_V(mode) |
7374 FW_VI_MAC_CMD_IDX_V(idx));
7375 memcpy(p->macaddr, addr, sizeof(p->macaddr));
7376
7377 ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
7378 if (ret == 0) {
7379 ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
7380 if (ret >= max_mac_addr)
7381 ret = -ENOMEM;
7382 }
7383 return ret;
7384}
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
7398 bool ucast, u64 vec, bool sleep_ok)
7399{
7400 struct fw_vi_mac_cmd c;
7401
7402 memset(&c, 0, sizeof(c));
7403 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7404 FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7405 FW_VI_ENABLE_CMD_VIID_V(viid));
7406 c.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN_F |
7407 FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
7408 FW_CMD_LEN16_V(1));
7409 c.u.hash.hashvec = cpu_to_be64(vec);
7410 return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
7411}
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
7426 unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
7427{
7428 struct fw_vi_enable_cmd c;
7429
7430 memset(&c, 0, sizeof(c));
7431 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
7432 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
7433 FW_VI_ENABLE_CMD_VIID_V(viid));
7434 c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
7435 FW_VI_ENABLE_CMD_EEN_V(tx_en) |
7436 FW_VI_ENABLE_CMD_DCB_INFO_V(dcb_en) |
7437 FW_LEN16(c));
7438 return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
7439}
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
7452 bool rx_en, bool tx_en)
7453{
7454 return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
7455}
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
7467 unsigned int nblinks)
7468{
7469 struct fw_vi_enable_cmd c;
7470
7471 memset(&c, 0, sizeof(c));
7472 c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
7473 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
7474 FW_VI_ENABLE_CMD_VIID_V(viid));
7475 c.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED_F | FW_LEN16(c));
7476 c.blinkdur = cpu_to_be16(nblinks);
7477 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7478}
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495int t4_iq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
7496 unsigned int vf, unsigned int iqtype, unsigned int iqid,
7497 unsigned int fl0id, unsigned int fl1id)
7498{
7499 struct fw_iq_cmd c;
7500
7501 memset(&c, 0, sizeof(c));
7502 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
7503 FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
7504 FW_IQ_CMD_VFN_V(vf));
7505 c.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_IQSTOP_F | FW_LEN16(c));
7506 c.type_to_iqandstindex = cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
7507 c.iqid = cpu_to_be16(iqid);
7508 c.fl0id = cpu_to_be16(fl0id);
7509 c.fl1id = cpu_to_be16(fl1id);
7510 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7511}
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
7527 unsigned int vf, unsigned int iqtype, unsigned int iqid,
7528 unsigned int fl0id, unsigned int fl1id)
7529{
7530 struct fw_iq_cmd c;
7531
7532 memset(&c, 0, sizeof(c));
7533 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
7534 FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
7535 FW_IQ_CMD_VFN_V(vf));
7536 c.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE_F | FW_LEN16(c));
7537 c.type_to_iqandstindex = cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
7538 c.iqid = cpu_to_be16(iqid);
7539 c.fl0id = cpu_to_be16(fl0id);
7540 c.fl1id = cpu_to_be16(fl1id);
7541 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7542}
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
7555 unsigned int vf, unsigned int eqid)
7556{
7557 struct fw_eq_eth_cmd c;
7558
7559 memset(&c, 0, sizeof(c));
7560 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_ETH_CMD) |
7561 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
7562 FW_EQ_ETH_CMD_PFN_V(pf) |
7563 FW_EQ_ETH_CMD_VFN_V(vf));
7564 c.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE_F | FW_LEN16(c));
7565 c.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID_V(eqid));
7566 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7567}
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
7580 unsigned int vf, unsigned int eqid)
7581{
7582 struct fw_eq_ctrl_cmd c;
7583
7584 memset(&c, 0, sizeof(c));
7585 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_CTRL_CMD) |
7586 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
7587 FW_EQ_CTRL_CMD_PFN_V(pf) |
7588 FW_EQ_CTRL_CMD_VFN_V(vf));
7589 c.alloc_to_len16 = cpu_to_be32(FW_EQ_CTRL_CMD_FREE_F | FW_LEN16(c));
7590 c.cmpliqid_eqid = cpu_to_be32(FW_EQ_CTRL_CMD_EQID_V(eqid));
7591 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7592}
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
7605 unsigned int vf, unsigned int eqid)
7606{
7607 struct fw_eq_ofld_cmd c;
7608
7609 memset(&c, 0, sizeof(c));
7610 c.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
7611 FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
7612 FW_EQ_OFLD_CMD_PFN_V(pf) |
7613 FW_EQ_OFLD_CMD_VFN_V(vf));
7614 c.alloc_to_len16 = cpu_to_be32(FW_EQ_OFLD_CMD_FREE_F | FW_LEN16(c));
7615 c.eqid_pkd = cpu_to_be32(FW_EQ_OFLD_CMD_EQID_V(eqid));
7616 return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
7617}
7618
7619
7620
7621
7622
7623
7624
7625
7626static const char *t4_link_down_rc_str(unsigned char link_down_rc)
7627{
7628 static const char * const reason[] = {
7629 "Link Down",
7630 "Remote Fault",
7631 "Auto-negotiation Failure",
7632 "Reserved",
7633 "Insufficient Airflow",
7634 "Unable To Determine Reason",
7635 "No RX Signal Detected",
7636 "Reserved",
7637 };
7638
7639 if (link_down_rc >= ARRAY_SIZE(reason))
7640 return "Bad Reason Code";
7641
7642 return reason[link_down_rc];
7643}
7644
7645
7646
7647
7648
7649
7650
7651
7652void t4_handle_get_port_info(struct port_info *pi, const __be64 *rpl)
7653{
7654 const struct fw_port_cmd *p = (const void *)rpl;
7655 struct adapter *adap = pi->adapter;
7656
7657
7658 int speed = 0, fc = 0;
7659 struct link_config *lc;
7660 u32 stat = be32_to_cpu(p->u.info.lstatus_to_modtype);
7661 int link_ok = (stat & FW_PORT_CMD_LSTATUS_F) != 0;
7662 u32 mod = FW_PORT_CMD_MODTYPE_G(stat);
7663
7664 if (stat & FW_PORT_CMD_RXPAUSE_F)
7665 fc |= PAUSE_RX;
7666 if (stat & FW_PORT_CMD_TXPAUSE_F)
7667 fc |= PAUSE_TX;
7668 if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
7669 speed = 100;
7670 else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
7671 speed = 1000;
7672 else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
7673 speed = 10000;
7674 else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_25G))
7675 speed = 25000;
7676 else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
7677 speed = 40000;
7678 else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100G))
7679 speed = 100000;
7680
7681 lc = &pi->link_cfg;
7682
7683 if (mod != pi->mod_type) {
7684 pi->mod_type = mod;
7685 t4_os_portmod_changed(adap, pi->port_id);
7686 }
7687 if (link_ok != lc->link_ok || speed != lc->speed ||
7688 fc != lc->fc) {
7689 if (!link_ok && lc->link_ok) {
7690 unsigned char rc = FW_PORT_CMD_LINKDNRC_G(stat);
7691
7692 lc->link_down_rc = rc;
7693 dev_warn(adap->pdev_dev,
7694 "Port %d link down, reason: %s\n",
7695 pi->port_id, t4_link_down_rc_str(rc));
7696 }
7697 lc->link_ok = link_ok;
7698 lc->speed = speed;
7699 lc->fc = fc;
7700 lc->supported = be16_to_cpu(p->u.info.pcap);
7701 lc->lp_advertising = be16_to_cpu(p->u.info.lpacap);
7702
7703 t4_os_link_changed(adap, pi->port_id, link_ok);
7704 }
7705}
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715int t4_update_port_info(struct port_info *pi)
7716{
7717 struct fw_port_cmd port_cmd;
7718 int ret;
7719
7720 memset(&port_cmd, 0, sizeof(port_cmd));
7721 port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
7722 FW_CMD_REQUEST_F | FW_CMD_READ_F |
7723 FW_PORT_CMD_PORTID_V(pi->port_id));
7724 port_cmd.action_to_len16 = cpu_to_be32(
7725 FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
7726 FW_LEN16(port_cmd));
7727 ret = t4_wr_mbox(pi->adapter, pi->adapter->mbox,
7728 &port_cmd, sizeof(port_cmd), &port_cmd);
7729 if (ret)
7730 return ret;
7731
7732 t4_handle_get_port_info(pi, (__be64 *)&port_cmd);
7733 return 0;
7734}
7735
7736
7737
7738
7739
7740
7741
7742
7743int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
7744{
7745 u8 opcode = *(const u8 *)rpl;
7746
7747
7748
7749
7750
7751
7752 const struct fw_port_cmd *p = (const void *)rpl;
7753 unsigned int action =
7754 FW_PORT_CMD_ACTION_G(be32_to_cpu(p->action_to_len16));
7755
7756 if (opcode == FW_PORT_CMD && action == FW_PORT_ACTION_GET_PORT_INFO) {
7757 int i;
7758 int chan = FW_PORT_CMD_PORTID_G(be32_to_cpu(p->op_to_portid));
7759 struct port_info *pi = NULL;
7760
7761 for_each_port(adap, i) {
7762 pi = adap2pinfo(adap, i);
7763 if (pi->tx_chan == chan)
7764 break;
7765 }
7766
7767 t4_handle_get_port_info(pi, rpl);
7768 } else {
7769 dev_warn(adap->pdev_dev, "Unknown firmware reply %d\n", opcode);
7770 return -EINVAL;
7771 }
7772 return 0;
7773}
7774
7775static void get_pci_mode(struct adapter *adapter, struct pci_params *p)
7776{
7777 u16 val;
7778
7779 if (pci_is_pcie(adapter->pdev)) {
7780 pcie_capability_read_word(adapter->pdev, PCI_EXP_LNKSTA, &val);
7781 p->speed = val & PCI_EXP_LNKSTA_CLS;
7782 p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
7783 }
7784}
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794static void init_link_config(struct link_config *lc, unsigned int pcaps,
7795 unsigned int acaps)
7796{
7797 lc->supported = pcaps;
7798 lc->lp_advertising = 0;
7799 lc->requested_speed = 0;
7800 lc->speed = 0;
7801 lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
7802 lc->auto_fec = 0;
7803
7804
7805
7806
7807 if (acaps & FW_PORT_CAP_FEC_RS)
7808 lc->auto_fec |= FEC_RS;
7809 if (acaps & FW_PORT_CAP_FEC_BASER_RS)
7810 lc->auto_fec |= FEC_BASER_RS;
7811 lc->requested_fec = FEC_AUTO;
7812 lc->fec = lc->auto_fec;
7813
7814 if (lc->supported & FW_PORT_CAP_ANEG) {
7815 lc->advertising = lc->supported & ADVERT_MASK;
7816 lc->autoneg = AUTONEG_ENABLE;
7817 lc->requested_fc |= PAUSE_AUTONEG;
7818 } else {
7819 lc->advertising = 0;
7820 lc->autoneg = AUTONEG_DISABLE;
7821 }
7822}
7823
7824#define CIM_PF_NOACCESS 0xeeeeeeee
7825
7826int t4_wait_dev_ready(void __iomem *regs)
7827{
7828 u32 whoami;
7829
7830 whoami = readl(regs + PL_WHOAMI_A);
7831 if (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS)
7832 return 0;
7833
7834 msleep(500);
7835 whoami = readl(regs + PL_WHOAMI_A);
7836 return (whoami != 0xffffffff && whoami != CIM_PF_NOACCESS ? 0 : -EIO);
7837}
7838
7839struct flash_desc {
7840 u32 vendor_and_model_id;
7841 u32 size_mb;
7842};
7843
7844static int get_flash_params(struct adapter *adap)
7845{
7846
7847
7848
7849 static struct flash_desc supported_flash[] = {
7850 { 0x150201, 4 << 20 },
7851 };
7852
7853 int ret;
7854 u32 info;
7855
7856 ret = sf1_write(adap, 1, 1, 0, SF_RD_ID);
7857 if (!ret)
7858 ret = sf1_read(adap, 3, 0, 1, &info);
7859 t4_write_reg(adap, SF_OP_A, 0);
7860 if (ret)
7861 return ret;
7862
7863 for (ret = 0; ret < ARRAY_SIZE(supported_flash); ++ret)
7864 if (supported_flash[ret].vendor_and_model_id == info) {
7865 adap->params.sf_size = supported_flash[ret].size_mb;
7866 adap->params.sf_nsec =
7867 adap->params.sf_size / SF_SEC_SIZE;
7868 return 0;
7869 }
7870
7871 if ((info & 0xff) != 0x20)
7872 return -EINVAL;
7873 info >>= 16;
7874 if (info >= 0x14 && info < 0x18)
7875 adap->params.sf_nsec = 1 << (info - 16);
7876 else if (info == 0x18)
7877 adap->params.sf_nsec = 64;
7878 else
7879 return -EINVAL;
7880 adap->params.sf_size = 1 << info;
7881 adap->params.sf_fw_start =
7882 t4_read_reg(adap, CIM_BOOT_CFG_A) & BOOTADDR_M;
7883
7884 if (adap->params.sf_size < FLASH_MIN_SIZE)
7885 dev_warn(adap->pdev_dev, "WARNING!!! FLASH size %#x < %#x!!!\n",
7886 adap->params.sf_size, FLASH_MIN_SIZE);
7887 return 0;
7888}
7889
7890static void set_pcie_completion_timeout(struct adapter *adapter, u8 range)
7891{
7892 u16 val;
7893 u32 pcie_cap;
7894
7895 pcie_cap = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
7896 if (pcie_cap) {
7897 pci_read_config_word(adapter->pdev,
7898 pcie_cap + PCI_EXP_DEVCTL2, &val);
7899 val &= ~PCI_EXP_DEVCTL2_COMP_TIMEOUT;
7900 val |= range;
7901 pci_write_config_word(adapter->pdev,
7902 pcie_cap + PCI_EXP_DEVCTL2, val);
7903 }
7904}
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915int t4_prep_adapter(struct adapter *adapter)
7916{
7917 int ret, ver;
7918 uint16_t device_id;
7919 u32 pl_rev;
7920
7921 get_pci_mode(adapter, &adapter->params.pci);
7922 pl_rev = REV_G(t4_read_reg(adapter, PL_REV_A));
7923
7924 ret = get_flash_params(adapter);
7925 if (ret < 0) {
7926 dev_err(adapter->pdev_dev, "error %d identifying flash\n", ret);
7927 return ret;
7928 }
7929
7930
7931
7932 pci_read_config_word(adapter->pdev, PCI_DEVICE_ID, &device_id);
7933 ver = device_id >> 12;
7934 adapter->params.chip = 0;
7935 switch (ver) {
7936 case CHELSIO_T4:
7937 adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
7938 adapter->params.arch.sge_fl_db = DBPRIO_F;
7939 adapter->params.arch.mps_tcam_size =
7940 NUM_MPS_CLS_SRAM_L_INSTANCES;
7941 adapter->params.arch.mps_rplc_size = 128;
7942 adapter->params.arch.nchan = NCHAN;
7943 adapter->params.arch.pm_stats_cnt = PM_NSTATS;
7944 adapter->params.arch.vfcount = 128;
7945
7946
7947
7948 adapter->params.arch.cng_ch_bits_log = 2;
7949 break;
7950 case CHELSIO_T5:
7951 adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
7952 adapter->params.arch.sge_fl_db = DBPRIO_F | DBTYPE_F;
7953 adapter->params.arch.mps_tcam_size =
7954 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
7955 adapter->params.arch.mps_rplc_size = 128;
7956 adapter->params.arch.nchan = NCHAN;
7957 adapter->params.arch.pm_stats_cnt = PM_NSTATS;
7958 adapter->params.arch.vfcount = 128;
7959 adapter->params.arch.cng_ch_bits_log = 2;
7960 break;
7961 case CHELSIO_T6:
7962 adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
7963 adapter->params.arch.sge_fl_db = 0;
7964 adapter->params.arch.mps_tcam_size =
7965 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
7966 adapter->params.arch.mps_rplc_size = 256;
7967 adapter->params.arch.nchan = 2;
7968 adapter->params.arch.pm_stats_cnt = T6_PM_NSTATS;
7969 adapter->params.arch.vfcount = 256;
7970
7971
7972
7973 adapter->params.arch.cng_ch_bits_log = 3;
7974 break;
7975 default:
7976 dev_err(adapter->pdev_dev, "Device %d is not supported\n",
7977 device_id);
7978 return -EINVAL;
7979 }
7980
7981 adapter->params.cim_la_size = CIMLA_SIZE;
7982 init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
7983
7984
7985
7986
7987 adapter->params.nports = 1;
7988 adapter->params.portvec = 1;
7989 adapter->params.vpd.cclk = 50000;
7990
7991
7992 set_pcie_completion_timeout(adapter, 0xd);
7993 return 0;
7994}
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008int t4_shutdown_adapter(struct adapter *adapter)
8009{
8010 int port;
8011
8012 t4_intr_disable(adapter);
8013 t4_write_reg(adapter, DBG_GPIO_EN_A, 0);
8014 for_each_port(adapter, port) {
8015 u32 a_port_cfg = is_t4(adapter->params.chip) ?
8016 PORT_REG(port, XGMAC_PORT_CFG_A) :
8017 T5_PORT_REG(port, MAC_PORT_CFG_A);
8018
8019 t4_write_reg(adapter, a_port_cfg,
8020 t4_read_reg(adapter, a_port_cfg)
8021 & ~SIGNAL_DET_V(1));
8022 }
8023 t4_set_reg_field(adapter, SGE_CONTROL_A, GLOBALENABLE_F, 0);
8024
8025 return 0;
8026}
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054int t4_bar2_sge_qregs(struct adapter *adapter,
8055 unsigned int qid,
8056 enum t4_bar2_qtype qtype,
8057 int user,
8058 u64 *pbar2_qoffset,
8059 unsigned int *pbar2_qid)
8060{
8061 unsigned int page_shift, page_size, qpp_shift, qpp_mask;
8062 u64 bar2_page_offset, bar2_qoffset;
8063 unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
8064
8065
8066 if (!user && is_t4(adapter->params.chip))
8067 return -EINVAL;
8068
8069
8070
8071 page_shift = adapter->params.sge.hps + 10;
8072 page_size = 1 << page_shift;
8073
8074
8075
8076 qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
8077 ? adapter->params.sge.eq_qpp
8078 : adapter->params.sge.iq_qpp);
8079 qpp_mask = (1 << qpp_shift) - 1;
8080
8081
8082
8083
8084
8085
8086 bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
8087 bar2_qid = qid & qpp_mask;
8088 bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106 bar2_qoffset = bar2_page_offset;
8107 bar2_qinferred = (bar2_qid_offset < page_size);
8108 if (bar2_qinferred) {
8109 bar2_qoffset += bar2_qid_offset;
8110 bar2_qid = 0;
8111 }
8112
8113 *pbar2_qoffset = bar2_qoffset;
8114 *pbar2_qid = bar2_qid;
8115 return 0;
8116}
8117
8118
8119
8120
8121
8122
8123
8124
8125int t4_init_devlog_params(struct adapter *adap)
8126{
8127 struct devlog_params *dparams = &adap->params.devlog;
8128 u32 pf_dparams;
8129 unsigned int devlog_meminfo;
8130 struct fw_devlog_cmd devlog_cmd;
8131 int ret;
8132
8133
8134
8135
8136
8137 pf_dparams =
8138 t4_read_reg(adap, PCIE_FW_REG(PCIE_FW_PF_A, PCIE_FW_PF_DEVLOG));
8139 if (pf_dparams) {
8140 unsigned int nentries, nentries128;
8141
8142 dparams->memtype = PCIE_FW_PF_DEVLOG_MEMTYPE_G(pf_dparams);
8143 dparams->start = PCIE_FW_PF_DEVLOG_ADDR16_G(pf_dparams) << 4;
8144
8145 nentries128 = PCIE_FW_PF_DEVLOG_NENTRIES128_G(pf_dparams);
8146 nentries = (nentries128 + 1) * 128;
8147 dparams->size = nentries * sizeof(struct fw_devlog_e);
8148
8149 return 0;
8150 }
8151
8152
8153
8154 memset(&devlog_cmd, 0, sizeof(devlog_cmd));
8155 devlog_cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_DEVLOG_CMD) |
8156 FW_CMD_REQUEST_F | FW_CMD_READ_F);
8157 devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
8158 ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
8159 &devlog_cmd);
8160 if (ret)
8161 return ret;
8162
8163 devlog_meminfo =
8164 be32_to_cpu(devlog_cmd.memtype_devlog_memaddr16_devlog);
8165 dparams->memtype = FW_DEVLOG_CMD_MEMTYPE_DEVLOG_G(devlog_meminfo);
8166 dparams->start = FW_DEVLOG_CMD_MEMADDR16_DEVLOG_G(devlog_meminfo) << 4;
8167 dparams->size = be32_to_cpu(devlog_cmd.memsize_devlog);
8168
8169 return 0;
8170}
8171
8172
8173
8174
8175
8176
8177
8178int t4_init_sge_params(struct adapter *adapter)
8179{
8180 struct sge_params *sge_params = &adapter->params.sge;
8181 u32 hps, qpp;
8182 unsigned int s_hps, s_qpp;
8183
8184
8185
8186 hps = t4_read_reg(adapter, SGE_HOST_PAGE_SIZE_A);
8187 s_hps = (HOSTPAGESIZEPF0_S +
8188 (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * adapter->pf);
8189 sge_params->hps = ((hps >> s_hps) & HOSTPAGESIZEPF0_M);
8190
8191
8192
8193 s_qpp = (QUEUESPERPAGEPF0_S +
8194 (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * adapter->pf);
8195 qpp = t4_read_reg(adapter, SGE_EGRESS_QUEUES_PER_PAGE_PF_A);
8196 sge_params->eq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
8197 qpp = t4_read_reg(adapter, SGE_INGRESS_QUEUES_PER_PAGE_PF_A);
8198 sge_params->iq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_M);
8199
8200 return 0;
8201}
8202
8203
8204
8205
8206
8207
8208
8209int t4_init_tp_params(struct adapter *adap)
8210{
8211 int chan;
8212 u32 v;
8213
8214 v = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
8215 adap->params.tp.tre = TIMERRESOLUTION_G(v);
8216 adap->params.tp.dack_re = DELAYEDACKRESOLUTION_G(v);
8217
8218
8219 for (chan = 0; chan < NCHAN; chan++)
8220 adap->params.tp.tx_modq[chan] = chan;
8221
8222
8223
8224
8225 if (t4_use_ldst(adap)) {
8226 t4_fw_tp_pio_rw(adap, &adap->params.tp.vlan_pri_map, 1,
8227 TP_VLAN_PRI_MAP_A, 1);
8228 t4_fw_tp_pio_rw(adap, &adap->params.tp.ingress_config, 1,
8229 TP_INGRESS_CONFIG_A, 1);
8230 } else {
8231 t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
8232 &adap->params.tp.vlan_pri_map, 1,
8233 TP_VLAN_PRI_MAP_A);
8234 t4_read_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
8235 &adap->params.tp.ingress_config, 1,
8236 TP_INGRESS_CONFIG_A);
8237 }
8238
8239
8240
8241 if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
8242 v = t4_read_reg(adap, TP_OUT_CONFIG_A);
8243 adap->params.tp.rx_pkt_encap = (v & CRXPKTENC_F) ? 1 : 0;
8244 }
8245
8246
8247
8248
8249
8250 adap->params.tp.vlan_shift = t4_filter_field_shift(adap, VLAN_F);
8251 adap->params.tp.vnic_shift = t4_filter_field_shift(adap, VNIC_ID_F);
8252 adap->params.tp.port_shift = t4_filter_field_shift(adap, PORT_F);
8253 adap->params.tp.protocol_shift = t4_filter_field_shift(adap,
8254 PROTOCOL_F);
8255
8256
8257
8258
8259 if ((adap->params.tp.ingress_config & VNIC_F) == 0)
8260 adap->params.tp.vnic_shift = -1;
8261
8262 return 0;
8263}
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
8275{
8276 unsigned int filter_mode = adap->params.tp.vlan_pri_map;
8277 unsigned int sel;
8278 int field_shift;
8279
8280 if ((filter_mode & filter_sel) == 0)
8281 return -1;
8282
8283 for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
8284 switch (filter_mode & sel) {
8285 case FCOE_F:
8286 field_shift += FT_FCOE_W;
8287 break;
8288 case PORT_F:
8289 field_shift += FT_PORT_W;
8290 break;
8291 case VNIC_ID_F:
8292 field_shift += FT_VNIC_ID_W;
8293 break;
8294 case VLAN_F:
8295 field_shift += FT_VLAN_W;
8296 break;
8297 case TOS_F:
8298 field_shift += FT_TOS_W;
8299 break;
8300 case PROTOCOL_F:
8301 field_shift += FT_PROTOCOL_W;
8302 break;
8303 case ETHERTYPE_F:
8304 field_shift += FT_ETHERTYPE_W;
8305 break;
8306 case MACMATCH_F:
8307 field_shift += FT_MACMATCH_W;
8308 break;
8309 case MPSHITTYPE_F:
8310 field_shift += FT_MPSHITTYPE_W;
8311 break;
8312 case FRAGMENTATION_F:
8313 field_shift += FT_FRAGMENTATION_W;
8314 break;
8315 }
8316 }
8317 return field_shift;
8318}
8319
8320int t4_init_rss_mode(struct adapter *adap, int mbox)
8321{
8322 int i, ret;
8323 struct fw_rss_vi_config_cmd rvc;
8324
8325 memset(&rvc, 0, sizeof(rvc));
8326
8327 for_each_port(adap, i) {
8328 struct port_info *p = adap2pinfo(adap, i);
8329
8330 rvc.op_to_viid =
8331 cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
8332 FW_CMD_REQUEST_F | FW_CMD_READ_F |
8333 FW_RSS_VI_CONFIG_CMD_VIID_V(p->viid));
8334 rvc.retval_len16 = cpu_to_be32(FW_LEN16(rvc));
8335 ret = t4_wr_mbox(adap, mbox, &rvc, sizeof(rvc), &rvc);
8336 if (ret)
8337 return ret;
8338 p->rss_mode = be32_to_cpu(rvc.u.basicvirtual.defaultq_to_udpen);
8339 }
8340 return 0;
8341}
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357int t4_init_portinfo(struct port_info *pi, int mbox,
8358 int port, int pf, int vf, u8 mac[])
8359{
8360 int ret;
8361 struct fw_port_cmd c;
8362 unsigned int rss_size;
8363
8364 memset(&c, 0, sizeof(c));
8365 c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
8366 FW_CMD_REQUEST_F | FW_CMD_READ_F |
8367 FW_PORT_CMD_PORTID_V(port));
8368 c.action_to_len16 = cpu_to_be32(
8369 FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
8370 FW_LEN16(c));
8371 ret = t4_wr_mbox(pi->adapter, mbox, &c, sizeof(c), &c);
8372 if (ret)
8373 return ret;
8374
8375 ret = t4_alloc_vi(pi->adapter, mbox, port, pf, vf, 1, mac, &rss_size);
8376 if (ret < 0)
8377 return ret;
8378
8379 pi->viid = ret;
8380 pi->tx_chan = port;
8381 pi->lport = port;
8382 pi->rss_size = rss_size;
8383
8384 ret = be32_to_cpu(c.u.info.lstatus_to_modtype);
8385 pi->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP_F) ?
8386 FW_PORT_CMD_MDIOADDR_G(ret) : -1;
8387 pi->port_type = FW_PORT_CMD_PTYPE_G(ret);
8388 pi->mod_type = FW_PORT_MOD_TYPE_NA;
8389
8390 init_link_config(&pi->link_cfg, be16_to_cpu(c.u.info.pcap),
8391 be16_to_cpu(c.u.info.acap));
8392 return 0;
8393}
8394
8395int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
8396{
8397 u8 addr[6];
8398 int ret, i, j = 0;
8399
8400 for_each_port(adap, i) {
8401 struct port_info *pi = adap2pinfo(adap, i);
8402
8403 while ((adap->params.portvec & (1 << j)) == 0)
8404 j++;
8405
8406 ret = t4_init_portinfo(pi, mbox, j, pf, vf, addr);
8407 if (ret)
8408 return ret;
8409
8410 memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
8411 j++;
8412 }
8413 return 0;
8414}
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres)
8427{
8428 unsigned int i, v;
8429 int cim_num_obq = is_t4(adap->params.chip) ?
8430 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
8431
8432 for (i = 0; i < CIM_NUM_IBQ; i++) {
8433 t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, IBQSELECT_F |
8434 QUENUMSELECT_V(i));
8435 v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
8436
8437 *base++ = CIMQBASE_G(v) * 256;
8438 *size++ = CIMQSIZE_G(v) * 256;
8439 *thres++ = QUEFULLTHRSH_G(v) * 8;
8440 }
8441 for (i = 0; i < cim_num_obq; i++) {
8442 t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
8443 QUENUMSELECT_V(i));
8444 v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
8445
8446 *base++ = CIMQBASE_G(v) * 256;
8447 *size++ = CIMQSIZE_G(v) * 256;
8448 }
8449}
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
8463{
8464 int i, err, attempts;
8465 unsigned int addr;
8466 const unsigned int nwords = CIM_IBQ_SIZE * 4;
8467
8468 if (qid > 5 || (n & 3))
8469 return -EINVAL;
8470
8471 addr = qid * nwords;
8472 if (n > nwords)
8473 n = nwords;
8474
8475
8476
8477
8478 attempts = 1000000;
8479
8480 for (i = 0; i < n; i++, addr++) {
8481 t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, IBQDBGADDR_V(addr) |
8482 IBQDBGEN_F);
8483 err = t4_wait_op_done(adap, CIM_IBQ_DBG_CFG_A, IBQDBGBUSY_F, 0,
8484 attempts, 1);
8485 if (err)
8486 return err;
8487 *data++ = t4_read_reg(adap, CIM_IBQ_DBG_DATA_A);
8488 }
8489 t4_write_reg(adap, CIM_IBQ_DBG_CFG_A, 0);
8490 return i;
8491}
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data, size_t n)
8505{
8506 int i, err;
8507 unsigned int addr, v, nwords;
8508 int cim_num_obq = is_t4(adap->params.chip) ?
8509 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
8510
8511 if ((qid > (cim_num_obq - 1)) || (n & 3))
8512 return -EINVAL;
8513
8514 t4_write_reg(adap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
8515 QUENUMSELECT_V(qid));
8516 v = t4_read_reg(adap, CIM_QUEUE_CONFIG_CTRL_A);
8517
8518 addr = CIMQBASE_G(v) * 64;
8519 nwords = CIMQSIZE_G(v) * 64;
8520 if (n > nwords)
8521 n = nwords;
8522
8523 for (i = 0; i < n; i++, addr++) {
8524 t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, OBQDBGADDR_V(addr) |
8525 OBQDBGEN_F);
8526 err = t4_wait_op_done(adap, CIM_OBQ_DBG_CFG_A, OBQDBGBUSY_F, 0,
8527 2, 1);
8528 if (err)
8529 return err;
8530 *data++ = t4_read_reg(adap, CIM_OBQ_DBG_DATA_A);
8531 }
8532 t4_write_reg(adap, CIM_OBQ_DBG_CFG_A, 0);
8533 return i;
8534}
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
8546 unsigned int *valp)
8547{
8548 int ret = 0;
8549
8550 if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
8551 return -EBUSY;
8552
8553 for ( ; !ret && n--; addr += 4) {
8554 t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr);
8555 ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
8556 0, 5, 2);
8557 if (!ret)
8558 *valp++ = t4_read_reg(adap, CIM_HOST_ACC_DATA_A);
8559 }
8560 return ret;
8561}
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
8573 const unsigned int *valp)
8574{
8575 int ret = 0;
8576
8577 if (t4_read_reg(adap, CIM_HOST_ACC_CTRL_A) & HOSTBUSY_F)
8578 return -EBUSY;
8579
8580 for ( ; !ret && n--; addr += 4) {
8581 t4_write_reg(adap, CIM_HOST_ACC_DATA_A, *valp++);
8582 t4_write_reg(adap, CIM_HOST_ACC_CTRL_A, addr | HOSTWRITE_F);
8583 ret = t4_wait_op_done(adap, CIM_HOST_ACC_CTRL_A, HOSTBUSY_F,
8584 0, 5, 2);
8585 }
8586 return ret;
8587}
8588
8589static int t4_cim_write1(struct adapter *adap, unsigned int addr,
8590 unsigned int val)
8591{
8592 return t4_cim_write(adap, addr, 1, &val);
8593}
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr)
8606{
8607 int i, ret;
8608 unsigned int cfg, val, idx;
8609
8610 ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
8611 if (ret)
8612 return ret;
8613
8614 if (cfg & UPDBGLAEN_F) {
8615 ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A, 0);
8616 if (ret)
8617 return ret;
8618 }
8619
8620 ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
8621 if (ret)
8622 goto restart;
8623
8624 idx = UPDBGLAWRPTR_G(val);
8625 if (wrptr)
8626 *wrptr = idx;
8627
8628 for (i = 0; i < adap->params.cim_la_size; i++) {
8629 ret = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
8630 UPDBGLARDPTR_V(idx) | UPDBGLARDEN_F);
8631 if (ret)
8632 break;
8633 ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &val);
8634 if (ret)
8635 break;
8636 if (val & UPDBGLARDEN_F) {
8637 ret = -ETIMEDOUT;
8638 break;
8639 }
8640 ret = t4_cim_read(adap, UP_UP_DBG_LA_DATA_A, 1, &la_buf[i]);
8641 if (ret)
8642 break;
8643
8644
8645
8646
8647 if (is_t6(adap->params.chip) && (idx & 0xf) >= 9)
8648 idx = (idx & 0xff0) + 0x10;
8649 else
8650 idx++;
8651
8652 idx &= UPDBGLARDPTR_M;
8653 }
8654restart:
8655 if (cfg & UPDBGLAEN_F) {
8656 int r = t4_cim_write1(adap, UP_UP_DBG_LA_CFG_A,
8657 cfg & ~UPDBGLARDEN_F);
8658 if (!ret)
8659 ret = r;
8660 }
8661 return ret;
8662}
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
8675{
8676 bool last_incomplete;
8677 unsigned int i, cfg, val, idx;
8678
8679 cfg = t4_read_reg(adap, TP_DBG_LA_CONFIG_A) & 0xffff;
8680 if (cfg & DBGLAENABLE_F)
8681 t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
8682 adap->params.tp.la_mask | (cfg ^ DBGLAENABLE_F));
8683
8684 val = t4_read_reg(adap, TP_DBG_LA_CONFIG_A);
8685 idx = DBGLAWPTR_G(val);
8686 last_incomplete = DBGLAMODE_G(val) >= 2 && (val & DBGLAWHLF_F) == 0;
8687 if (last_incomplete)
8688 idx = (idx + 1) & DBGLARPTR_M;
8689 if (wrptr)
8690 *wrptr = idx;
8691
8692 val &= 0xffff;
8693 val &= ~DBGLARPTR_V(DBGLARPTR_M);
8694 val |= adap->params.tp.la_mask;
8695
8696 for (i = 0; i < TPLA_SIZE; i++) {
8697 t4_write_reg(adap, TP_DBG_LA_CONFIG_A, DBGLARPTR_V(idx) | val);
8698 la_buf[i] = t4_read_reg64(adap, TP_DBG_LA_DATAL_A);
8699 idx = (idx + 1) & DBGLARPTR_M;
8700 }
8701
8702
8703 if (last_incomplete)
8704 la_buf[TPLA_SIZE - 1] = ~0ULL;
8705
8706 if (cfg & DBGLAENABLE_F)
8707 t4_write_reg(adap, TP_DBG_LA_CONFIG_A,
8708 cfg | adap->params.tp.la_mask);
8709}
8710
8711
8712
8713
8714
8715
8716
8717
8718#define SGE_IDMA_WARN_THRESH 1
8719#define SGE_IDMA_WARN_REPEAT 300
8720
8721
8722
8723
8724
8725
8726
8727
8728void t4_idma_monitor_init(struct adapter *adapter,
8729 struct sge_idma_monitor_state *idma)
8730{
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743 idma->idma_1s_thresh = core_ticks_per_usec(adapter) * 1000000;
8744 idma->idma_stalled[0] = 0;
8745 idma->idma_stalled[1] = 0;
8746}
8747
8748
8749
8750
8751
8752
8753
8754
8755void t4_idma_monitor(struct adapter *adapter,
8756 struct sge_idma_monitor_state *idma,
8757 int hz, int ticks)
8758{
8759 int i, idma_same_state_cnt[2];
8760
8761
8762
8763
8764
8765
8766
8767
8768 t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 13);
8769 idma_same_state_cnt[0] = t4_read_reg(adapter, SGE_DEBUG_DATA_HIGH_A);
8770 idma_same_state_cnt[1] = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
8771
8772 for (i = 0; i < 2; i++) {
8773 u32 debug0, debug11;
8774
8775
8776
8777
8778
8779
8780
8781 if (idma_same_state_cnt[i] < idma->idma_1s_thresh) {
8782 if (idma->idma_stalled[i] >= SGE_IDMA_WARN_THRESH * hz)
8783 dev_warn(adapter->pdev_dev, "SGE idma%d, queue %u, "
8784 "resumed after %d seconds\n",
8785 i, idma->idma_qid[i],
8786 idma->idma_stalled[i] / hz);
8787 idma->idma_stalled[i] = 0;
8788 continue;
8789 }
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800 if (idma->idma_stalled[i] == 0) {
8801 idma->idma_stalled[i] = hz;
8802 idma->idma_warn[i] = 0;
8803 } else {
8804 idma->idma_stalled[i] += ticks;
8805 idma->idma_warn[i] -= ticks;
8806 }
8807
8808 if (idma->idma_stalled[i] < SGE_IDMA_WARN_THRESH * hz)
8809 continue;
8810
8811
8812
8813 if (idma->idma_warn[i] > 0)
8814 continue;
8815 idma->idma_warn[i] = SGE_IDMA_WARN_REPEAT * hz;
8816
8817
8818
8819
8820
8821 t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 0);
8822 debug0 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
8823 idma->idma_state[i] = (debug0 >> (i * 9)) & 0x3f;
8824
8825 t4_write_reg(adapter, SGE_DEBUG_INDEX_A, 11);
8826 debug11 = t4_read_reg(adapter, SGE_DEBUG_DATA_LOW_A);
8827 idma->idma_qid[i] = (debug11 >> (i * 16)) & 0xffff;
8828
8829 dev_warn(adapter->pdev_dev, "SGE idma%u, queue %u, potentially stuck in "
8830 "state %u for %d seconds (debug0=%#x, debug11=%#x)\n",
8831 i, idma->idma_qid[i], idma->idma_state[i],
8832 idma->idma_stalled[i] / hz,
8833 debug0, debug11);
8834 t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
8835 }
8836}
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846int t4_load_cfg(struct adapter *adap, const u8 *cfg_data, unsigned int size)
8847{
8848 int ret, i, n, cfg_addr;
8849 unsigned int addr;
8850 unsigned int flash_cfg_start_sec;
8851 unsigned int sf_sec_size = adap->params.sf_size / adap->params.sf_nsec;
8852
8853 cfg_addr = t4_flash_cfg_addr(adap);
8854 if (cfg_addr < 0)
8855 return cfg_addr;
8856
8857 addr = cfg_addr;
8858 flash_cfg_start_sec = addr / SF_SEC_SIZE;
8859
8860 if (size > FLASH_CFG_MAX_SIZE) {
8861 dev_err(adap->pdev_dev, "cfg file too large, max is %u bytes\n",
8862 FLASH_CFG_MAX_SIZE);
8863 return -EFBIG;
8864 }
8865
8866 i = DIV_ROUND_UP(FLASH_CFG_MAX_SIZE,
8867 sf_sec_size);
8868 ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
8869 flash_cfg_start_sec + i - 1);
8870
8871
8872
8873 if (ret || size == 0)
8874 goto out;
8875
8876
8877 for (i = 0; i < size; i += SF_PAGE_SIZE) {
8878 if ((size - i) < SF_PAGE_SIZE)
8879 n = size - i;
8880 else
8881 n = SF_PAGE_SIZE;
8882 ret = t4_write_flash(adap, addr, n, cfg_data);
8883 if (ret)
8884 goto out;
8885
8886 addr += SF_PAGE_SIZE;
8887 cfg_data += SF_PAGE_SIZE;
8888 }
8889
8890out:
8891 if (ret)
8892 dev_err(adap->pdev_dev, "config file %s failed %d\n",
8893 (size == 0 ? "clear" : "download"), ret);
8894 return ret;
8895}
8896
8897
8898
8899
8900
8901
8902
8903
8904int t4_set_vf_mac_acl(struct adapter *adapter, unsigned int vf,
8905 unsigned int naddr, u8 *addr)
8906{
8907 struct fw_acl_mac_cmd cmd;
8908
8909 memset(&cmd, 0, sizeof(cmd));
8910 cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_ACL_MAC_CMD) |
8911 FW_CMD_REQUEST_F |
8912 FW_CMD_WRITE_F |
8913 FW_ACL_MAC_CMD_PFN_V(adapter->pf) |
8914 FW_ACL_MAC_CMD_VFN_V(vf));
8915
8916
8917 cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
8918 cmd.nmac = naddr;
8919
8920 switch (adapter->pf) {
8921 case 3:
8922 memcpy(cmd.macaddr3, addr, sizeof(cmd.macaddr3));
8923 break;
8924 case 2:
8925 memcpy(cmd.macaddr2, addr, sizeof(cmd.macaddr2));
8926 break;
8927 case 1:
8928 memcpy(cmd.macaddr1, addr, sizeof(cmd.macaddr1));
8929 break;
8930 case 0:
8931 memcpy(cmd.macaddr0, addr, sizeof(cmd.macaddr0));
8932 break;
8933 }
8934
8935 return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
8936}
8937
8938int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
8939 int rateunit, int ratemode, int channel, int class,
8940 int minrate, int maxrate, int weight, int pktsize)
8941{
8942 struct fw_sched_cmd cmd;
8943
8944 memset(&cmd, 0, sizeof(cmd));
8945 cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_SCHED_CMD) |
8946 FW_CMD_REQUEST_F |
8947 FW_CMD_WRITE_F);
8948 cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
8949
8950 cmd.u.params.sc = FW_SCHED_SC_PARAMS;
8951 cmd.u.params.type = type;
8952 cmd.u.params.level = level;
8953 cmd.u.params.mode = mode;
8954 cmd.u.params.ch = channel;
8955 cmd.u.params.cl = class;
8956 cmd.u.params.unit = rateunit;
8957 cmd.u.params.rate = ratemode;
8958 cmd.u.params.min = cpu_to_be32(minrate);
8959 cmd.u.params.max = cpu_to_be32(maxrate);
8960 cmd.u.params.weight = cpu_to_be16(weight);
8961 cmd.u.params.pktsize = cpu_to_be16(pktsize);
8962
8963 return t4_wr_mbox_meat(adapter, adapter->mbox, &cmd, sizeof(cmd),
8964 NULL, 1);
8965}
8966