10 #include <linux/slab.h>
12 #include <linux/bitops.h>
14 #define MASK(n) ((1ULL<<(n))-1)
15 #define OCM_WIN_P3P(addr) (addr & 0xffc0000)
17 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
19 #define CRB_BLK(off) ((off >> 20) & 0x3f)
20 #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
21 #define CRB_WINDOW_2M (0x130060)
22 #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
23 #define CRB_INDIRECT_2M (0x1e0000UL)
44 {{{1, 0x0100000, 0x0102000, 0x120000},
45 {1, 0x0110000, 0x0120000, 0x130000},
46 {1, 0x0120000, 0x0122000, 0x124000},
47 {1, 0x0130000, 0x0132000, 0x126000},
48 {1, 0x0140000, 0x0142000, 0x128000},
49 {1, 0x0150000, 0x0152000, 0x12a000},
50 {1, 0x0160000, 0x0170000, 0x110000},
51 {1, 0x0170000, 0x0172000, 0x12e000},
52 {0, 0x0000000, 0x0000000, 0x000000},
53 {0, 0x0000000, 0x0000000, 0x000000},
54 {0, 0x0000000, 0x0000000, 0x000000},
55 {0, 0x0000000, 0x0000000, 0x000000},
56 {0, 0x0000000, 0x0000000, 0x000000},
57 {0, 0x0000000, 0x0000000, 0x000000},
58 {1, 0x01e0000, 0x01e0800, 0x122000},
59 {0, 0x0000000, 0x0000000, 0x000000} } },
60 {{{1, 0x0200000, 0x0210000, 0x180000} } },
62 {{{1, 0x0400000, 0x0401000, 0x169000} } },
63 {{{1, 0x0500000, 0x0510000, 0x140000} } },
64 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },
65 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },
66 {{{1, 0x0800000, 0x0802000, 0x170000},
67 {0, 0x0000000, 0x0000000, 0x000000},
68 {0, 0x0000000, 0x0000000, 0x000000},
69 {0, 0x0000000, 0x0000000, 0x000000},
70 {0, 0x0000000, 0x0000000, 0x000000},
71 {0, 0x0000000, 0x0000000, 0x000000},
72 {0, 0x0000000, 0x0000000, 0x000000},
73 {0, 0x0000000, 0x0000000, 0x000000},
74 {0, 0x0000000, 0x0000000, 0x000000},
75 {0, 0x0000000, 0x0000000, 0x000000},
76 {0, 0x0000000, 0x0000000, 0x000000},
77 {0, 0x0000000, 0x0000000, 0x000000},
78 {0, 0x0000000, 0x0000000, 0x000000},
79 {0, 0x0000000, 0x0000000, 0x000000},
80 {0, 0x0000000, 0x0000000, 0x000000},
81 {1, 0x08f0000, 0x08f2000, 0x172000} } },
82 {{{1, 0x0900000, 0x0902000, 0x174000},
83 {0, 0x0000000, 0x0000000, 0x000000},
84 {0, 0x0000000, 0x0000000, 0x000000},
85 {0, 0x0000000, 0x0000000, 0x000000},
86 {0, 0x0000000, 0x0000000, 0x000000},
87 {0, 0x0000000, 0x0000000, 0x000000},
88 {0, 0x0000000, 0x0000000, 0x000000},
89 {0, 0x0000000, 0x0000000, 0x000000},
90 {0, 0x0000000, 0x0000000, 0x000000},
91 {0, 0x0000000, 0x0000000, 0x000000},
92 {0, 0x0000000, 0x0000000, 0x000000},
93 {0, 0x0000000, 0x0000000, 0x000000},
94 {0, 0x0000000, 0x0000000, 0x000000},
95 {0, 0x0000000, 0x0000000, 0x000000},
96 {0, 0x0000000, 0x0000000, 0x000000},
97 {1, 0x09f0000, 0x09f2000, 0x176000} } },
98 {{{0, 0x0a00000, 0x0a02000, 0x178000},
99 {0, 0x0000000, 0x0000000, 0x000000},
100 {0, 0x0000000, 0x0000000, 0x000000},
101 {0, 0x0000000, 0x0000000, 0x000000},
102 {0, 0x0000000, 0x0000000, 0x000000},
103 {0, 0x0000000, 0x0000000, 0x000000},
104 {0, 0x0000000, 0x0000000, 0x000000},
105 {0, 0x0000000, 0x0000000, 0x000000},
106 {0, 0x0000000, 0x0000000, 0x000000},
107 {0, 0x0000000, 0x0000000, 0x000000},
108 {0, 0x0000000, 0x0000000, 0x000000},
109 {0, 0x0000000, 0x0000000, 0x000000},
110 {0, 0x0000000, 0x0000000, 0x000000},
111 {0, 0x0000000, 0x0000000, 0x000000},
112 {0, 0x0000000, 0x0000000, 0x000000},
113 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
114 {{{0, 0x0b00000, 0x0b02000, 0x17c000},
115 {0, 0x0000000, 0x0000000, 0x000000},
116 {0, 0x0000000, 0x0000000, 0x000000},
117 {0, 0x0000000, 0x0000000, 0x000000},
118 {0, 0x0000000, 0x0000000, 0x000000},
119 {0, 0x0000000, 0x0000000, 0x000000},
120 {0, 0x0000000, 0x0000000, 0x000000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {0, 0x0000000, 0x0000000, 0x000000},
123 {0, 0x0000000, 0x0000000, 0x000000},
124 {0, 0x0000000, 0x0000000, 0x000000},
125 {0, 0x0000000, 0x0000000, 0x000000},
126 {0, 0x0000000, 0x0000000, 0x000000},
127 {0, 0x0000000, 0x0000000, 0x000000},
128 {0, 0x0000000, 0x0000000, 0x000000},
129 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
130 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },
131 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },
132 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },
133 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },
134 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },
135 {{{1, 0x1100000, 0x1101000, 0x160000} } },
136 {{{1, 0x1200000, 0x1201000, 0x161000} } },
137 {{{1, 0x1300000, 0x1301000, 0x162000} } },
138 {{{1, 0x1400000, 0x1401000, 0x163000} } },
139 {{{1, 0x1500000, 0x1501000, 0x165000} } },
140 {{{1, 0x1600000, 0x1601000, 0x166000} } },
147 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },
148 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },
149 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },
151 {{{1, 0x2100000, 0x2102000, 0x120000},
152 {1, 0x2110000, 0x2120000, 0x130000},
153 {1, 0x2120000, 0x2122000, 0x124000},
154 {1, 0x2130000, 0x2132000, 0x126000},
155 {1, 0x2140000, 0x2142000, 0x128000},
156 {1, 0x2150000, 0x2152000, 0x12a000},
157 {1, 0x2160000, 0x2170000, 0x110000},
158 {1, 0x2170000, 0x2172000, 0x12e000},
159 {0, 0x0000000, 0x0000000, 0x000000},
160 {0, 0x0000000, 0x0000000, 0x000000},
161 {0, 0x0000000, 0x0000000, 0x000000},
162 {0, 0x0000000, 0x0000000, 0x000000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {0, 0x0000000, 0x0000000, 0x000000} } },
167 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },
173 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },
174 {{{1, 0x2900000, 0x2901000, 0x16b000} } },
175 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },
176 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },
177 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },
178 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },
179 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },
180 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },
181 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },
182 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },
183 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },
184 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },
186 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },
187 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },
188 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },
189 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },
190 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },
191 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },
194 {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },
195 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },
196 {{{1, 0x3f00000, 0x3f01000, 0x168000} } }
202 static const unsigned crb_hub_agt[64] = {
271 #define QLCNIC_PCIE_SEM_TIMEOUT 10000
284 "Failed to acquire sem=%d lock; holdby=%d\n",
285 sem, id_reg ?
QLCRD32(adapter, id_reg) : -1);
307 u32 i, producer, consumer;
318 __netif_tx_lock_bh(tx_ring->
txq);
323 if (nr_desc >= qlcnic_tx_avail(tx_ring)) {
324 netif_tx_stop_queue(tx_ring->
txq);
326 if (qlcnic_tx_avail(tx_ring) > nr_desc) {
328 netif_tx_wake_queue(tx_ring->
txq);
330 adapter->
stats.xmit_off++;
331 __netif_tx_unlock_bh(tx_ring->
txq);
337 cmd_desc = &cmd_desc_arr[
i];
349 }
while (i != nr_desc);
355 __netif_tx_unlock_bh(tx_ring->
txq);
385 static int qlcnic_nic_add_mac(
struct qlcnic_adapter *adapter,
const u8 *addr)
400 "failed to add mac address filter\n");
405 if (qlcnic_sre_macaddr_change(adapter,
420 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
427 qlcnic_nic_add_mac(adapter, adapter->
mac_addr);
428 qlcnic_nic_add_mac(adapter, bcast_addr);
444 qlcnic_nic_add_mac(adapter, ha->
addr);
474 return qlcnic_send_cmd_descs(adapter,
483 while (!list_empty(head)) {
485 qlcnic_sre_macaddr_change(adapter,
499 for (i = 0; i < adapter->
fhash.fmax; i++) {
500 head = &(adapter->
fhash.fhead[
i]);
506 qlcnic_sre_macaddr_change(adapter,
511 adapter->
fhash.fnum--;
512 hlist_del(&tmp_fil->
fnode);
527 for (i = 0; i < adapter->
fhash.fmax; i++) {
528 head = &(adapter->
fhash.fhead[
i]);
531 qlcnic_sre_macaddr_change(adapter, tmp_fil->
faddr,
535 adapter->
fhash.fnum--;
536 hlist_del(&tmp_fil->
fnode);
556 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
558 dev_err(&adapter->
pdev->dev,
"%sting loopback mode failed\n",
559 flag ?
"Set" :
"Reset");
610 ((
u64) adapter->
ahw->coal.rx_time_us) << 16);
612 ((
u64) adapter->
ahw->coal.type) << 32 |
613 ((
u64) adapter->
ahw->coal.sts_ring_mask) << 40);
614 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
617 "Could not send interrupt coalescing parameters\n");
639 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
642 "Could not send configure hw lro request\n");
666 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
669 "Could not send configure bridge mode request\n");
677 #define RSS_HASHTYPE_IP_TCP 0x3
685 static const u64 key[] = {
686 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
687 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
688 0x255b0ec26d5a56daULL
709 ((
u64)(enable & 0x1) << 8) |
712 for (i = 0; i < 5; i++)
715 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
742 "could not notify %s IP 0x%x reuqest\n",
761 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
764 "could not configure link notification\n");
787 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
790 "could not cleanup lro flows\n");
910 dev_err(&adapter->
pdev->dev,
"Invalid offset 0x%lx\n", off);
915 if (
readl(addr) != window) {
916 if (printk_ratelimit())
918 "failed to set CRB window to %d off 0x%lx\n",
932 rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
943 rv = qlcnic_pci_set_crbwindow_2M(adapter, off);
952 "%s: invalid offset: 0x%016lx\n", __func__, off);
965 rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
974 if (!qlcnic_pci_set_crbwindow_2M(adapter, off))
982 "%s: invalid offset: 0x%016lx\n", __func__, off);
993 WARN_ON(qlcnic_pci_get_crb_addr_2M(adapter, offset, &addr));
1007 writel(window, adapter->
ahw->ocm_win_crb);
1025 ret = qlcnic_pci_set_window_2M(adapter, off, &start);
1029 addr = adapter->
ahw->pci_base0 +
start;
1032 *data =
readq(addr);
1045 void __iomem *addr = adapter->
ahw->pci_base0 +
1049 *data =
readq(addr);
1056 void __iomem *addr = adapter->
ahw->pci_base0 +
1064 #define MAX_CTL_CHECK 1000
1093 return qlcnic_pci_mem_access_direct(adapter, off, &data, 1);
1116 if (j >= MAX_CTL_CHECK) {
1121 i = (off & 0xf) ? 0 : 2;
1126 i = (off & 0xf) ? 2 : 0;
1128 writel(data & 0xffffffff,
1130 writel((data >> 32) & 0xffffffff,
1143 if (j >= MAX_CTL_CHECK) {
1144 if (printk_ratelimit())
1146 "failed to write through agent\n");
1185 return qlcnic_pci_mem_access_direct(adapter,
1207 if (j >= MAX_CTL_CHECK) {
1208 if (printk_ratelimit())
1210 "failed to read through agent\n");
1217 temp =
readl(mem_crb + off8 + 4);
1218 val = (
u64)temp << 32;
1219 val |=
readl(mem_crb + off8);
1239 dev_err(&pdev->
dev,
"invalid board config, magic=%08x\n",
1252 if ((gpio & 0x8000) == 0)
1256 switch (board_type) {
1275 adapter->
ahw->port_type = (adapter->
portnum < 2) ?
1279 dev_err(&pdev->
dev,
"unknown board type %x\n", board_type);
1293 if (wol_cfg & (1
UL << adapter->
portnum)) {
1295 if (wol_cfg & (1 << adapter->
portnum))
1317 rv = qlcnic_send_cmd_descs(adapter, (
struct cmd_desc_type0 *)&req, 1);
1319 dev_err(&adapter->
pdev->dev,
"LED configuration failed.\n");
1336 for (i = 0; i < crb->
no_ops; i++) {
1350 void __iomem *base = adapter->
ahw->pci_base0;
1359 for (i = 0; i < no_ops; i++) {
1362 for (k = 0; k < 8; k++) {
1363 if (!(ctr->
opcode & (1 << k)))
1376 (data & ctr->
val2));
1381 (data | ctr->
val3));
1384 while (timeout <= ctr->timeout) {
1386 if ((data & ctr->
val2) == ctr->
val1)
1393 "Timed out, aborting poll CRB\n");
1424 "Unknown opcode\n");
1440 void __iomem *base = adapter->
ahw->pci_base0;
1443 for (loop = 0; loop < mux->
no_ops; loop++) {
1459 void __iomem *base = adapter->
ahw->pci_base0;
1465 for (loop = 0; loop < que->
no_ops; loop++) {
1468 for (i = 0; i <
cnt; i++) {
1488 for (i = 0; i < ocm->
no_ops; i++) {
1503 void __iomem *base = adapter->
ahw->pci_base0;
1505 fl_addr = rom->
addr;
1515 for (i = 0; i <
size; i++) {
1516 addr = fl_addr & 0xFFFF0000;
1533 void __iomem *base = adapter->
ahw->pci_base0;
1538 for (i = 0; i < l1->
no_ops; i++) {
1560 u8 poll_mask, poll_to, time_out = 0;
1561 void __iomem *base = adapter->
ahw->pci_base0;
1568 for (i = 0; i < l2->
no_ops; i++) {
1577 if (!(data & poll_mask))
1581 }
while (time_out <= poll_to);
1583 if (time_out > poll_to) {
1585 "Timeout exceeded in %s, aborting dump\n",
1610 void __iomem *base = adapter->
ahw->pci_base0;
1612 reg_read = mem->
size;
1615 if ((addr & 0xf) || (reg_read%16)) {
1617 "Unaligned memory addr:0x%x size:0x%x\n",
1624 while (reg_read != 0) {
1635 if (i == MAX_CTL_CHECK) {
1636 if (printk_ratelimit()) {
1638 "failed to read through agent\n");
1643 for (i = 0; i < 4; i++) {
1693 if (size != entry->
hdr.cap_size) {
1695 "Invalidate dump, Type:%d\tMask:%d\tSize:%dCap_size:%d\n",
1696 entry->
hdr.type, entry->
hdr.mask, size, entry->
hdr.cap_size);
1697 dev_info(dev,
"Aborting further dump capture\n");
1716 "Previous dump not cleared, not capturing dump\n");
1727 if (!fw_dump->
data) {
1729 "Unable to allocate (%d KB) for fw dump\n",
1733 buffer = fw_dump->
data;
1737 entry_offset = tmpl_hdr->
offset;
1742 entry = (
void *)tmpl_hdr + entry_offset;
1745 entry_offset += entry->
hdr.offset;
1750 while (ops_index < ops_cnt) {
1751 if (entry->
hdr.type == fw_dump_ops[ops_index].
opcode)
1755 if (ops_index == ops_cnt) {
1757 "Invalid entry type %d, exiting dump\n",
1762 dump = fw_dump_ops[ops_index].
handler(adapter, entry, buffer);
1763 if (dump && !qlcnic_valid_dump_entry(&adapter->
pdev->dev, entry,
1766 buf_offset += entry->
hdr.cap_size;
1767 entry_offset += entry->
hdr.offset;
1768 buffer = fw_dump->
data + buf_offset;
1770 if (dump_size != buf_offset) {
1772 "Captured(%d) and expected size(%d) do not match\n",
1773 buf_offset, dump_size);
1777 snprintf(mesg,
sizeof(mesg),
"FW_DUMP=%s",
1779 dev_info(&adapter->
pdev->dev,
"Dump data, %d bytes captured\n",