]>
Commit | Line | Data |
---|---|---|
34f80b04 | 1 | /* bnx2x_main.c: Broadcom Everest network driver. |
a2fbb9ea | 2 | * |
247fa82b | 3 | * Copyright (c) 2007-2013 Broadcom Corporation |
a2fbb9ea ET |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation. | |
8 | * | |
24e3fcef EG |
9 | * Maintained by: Eilon Greenstein <eilong@broadcom.com> |
10 | * Written by: Eliezer Tamir | |
a2fbb9ea ET |
11 | * Based on code from Michael Chan's bnx2 driver |
12 | * UDP CSUM errata workaround by Arik Gendelman | |
ca00392c | 13 | * Slowpath and fastpath rework by Vladislav Zolotarov |
c14423fe | 14 | * Statistics and Link management by Yitchak Gertner |
a2fbb9ea ET |
15 | * |
16 | */ | |
17 | ||
f1deab50 JP |
18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
19 | ||
a2fbb9ea ET |
20 | #include <linux/module.h> |
21 | #include <linux/moduleparam.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/device.h> /* for dev_info() */ | |
24 | #include <linux/timer.h> | |
25 | #include <linux/errno.h> | |
26 | #include <linux/ioport.h> | |
27 | #include <linux/slab.h> | |
a2fbb9ea ET |
28 | #include <linux/interrupt.h> |
29 | #include <linux/pci.h> | |
30 | #include <linux/init.h> | |
31 | #include <linux/netdevice.h> | |
32 | #include <linux/etherdevice.h> | |
33 | #include <linux/skbuff.h> | |
34 | #include <linux/dma-mapping.h> | |
35 | #include <linux/bitops.h> | |
36 | #include <linux/irq.h> | |
37 | #include <linux/delay.h> | |
38 | #include <asm/byteorder.h> | |
39 | #include <linux/time.h> | |
40 | #include <linux/ethtool.h> | |
41 | #include <linux/mii.h> | |
0c6671b0 | 42 | #include <linux/if_vlan.h> |
a2fbb9ea | 43 | #include <net/ip.h> |
619c5cb6 | 44 | #include <net/ipv6.h> |
a2fbb9ea ET |
45 | #include <net/tcp.h> |
46 | #include <net/checksum.h> | |
34f80b04 | 47 | #include <net/ip6_checksum.h> |
a2fbb9ea ET |
48 | #include <linux/workqueue.h> |
49 | #include <linux/crc32.h> | |
34f80b04 | 50 | #include <linux/crc32c.h> |
a2fbb9ea ET |
51 | #include <linux/prefetch.h> |
52 | #include <linux/zlib.h> | |
a2fbb9ea | 53 | #include <linux/io.h> |
452427b0 | 54 | #include <linux/semaphore.h> |
45229b42 | 55 | #include <linux/stringify.h> |
7ab24bfd | 56 | #include <linux/vmalloc.h> |
a2fbb9ea | 57 | |
a2fbb9ea ET |
58 | #include "bnx2x.h" |
59 | #include "bnx2x_init.h" | |
94a78b79 | 60 | #include "bnx2x_init_ops.h" |
9f6c9258 | 61 | #include "bnx2x_cmn.h" |
1ab4434c | 62 | #include "bnx2x_vfpf.h" |
e4901dde | 63 | #include "bnx2x_dcb.h" |
042181f5 | 64 | #include "bnx2x_sp.h" |
a2fbb9ea | 65 | |
94a78b79 VZ |
66 | #include <linux/firmware.h> |
67 | #include "bnx2x_fw_file_hdr.h" | |
68 | /* FW files */ | |
45229b42 BH |
69 | #define FW_FILE_VERSION \ |
70 | __stringify(BCM_5710_FW_MAJOR_VERSION) "." \ | |
71 | __stringify(BCM_5710_FW_MINOR_VERSION) "." \ | |
72 | __stringify(BCM_5710_FW_REVISION_VERSION) "." \ | |
73 | __stringify(BCM_5710_FW_ENGINEERING_VERSION) | |
560131f3 DK |
74 | #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw" |
75 | #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw" | |
f2e0899f | 76 | #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw" |
94a78b79 | 77 | |
2e499d3c BW |
78 | #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN) |
79 | ||
34f80b04 EG |
80 | /* Time in jiffies before concluding the transmitter is hung */ |
81 | #define TX_TIMEOUT (5*HZ) | |
a2fbb9ea | 82 | |
0329aba1 | 83 | static char version[] = |
619c5cb6 | 84 | "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver " |
a2fbb9ea ET |
85 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
86 | ||
24e3fcef | 87 | MODULE_AUTHOR("Eliezer Tamir"); |
f2e0899f | 88 | MODULE_DESCRIPTION("Broadcom NetXtreme II " |
619c5cb6 VZ |
89 | "BCM57710/57711/57711E/" |
90 | "57712/57712_MF/57800/57800_MF/57810/57810_MF/" | |
91 | "57840/57840_MF Driver"); | |
a2fbb9ea ET |
92 | MODULE_LICENSE("GPL"); |
93 | MODULE_VERSION(DRV_MODULE_VERSION); | |
45229b42 BH |
94 | MODULE_FIRMWARE(FW_FILE_NAME_E1); |
95 | MODULE_FIRMWARE(FW_FILE_NAME_E1H); | |
f2e0899f | 96 | MODULE_FIRMWARE(FW_FILE_NAME_E2); |
a2fbb9ea | 97 | |
ca00392c | 98 | |
d6214d7a | 99 | int num_queues; |
54b9ddaa | 100 | module_param(num_queues, int, 0); |
96305234 DK |
101 | MODULE_PARM_DESC(num_queues, |
102 | " Set number of queues (default is as a number of CPUs)"); | |
555f6c78 | 103 | |
19680c48 | 104 | static int disable_tpa; |
19680c48 | 105 | module_param(disable_tpa, int, 0); |
9898f86d | 106 | MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); |
8badd27a | 107 | |
9ee3d37b DK |
108 | #define INT_MODE_INTx 1 |
109 | #define INT_MODE_MSI 2 | |
0e8d2ec5 | 110 | int int_mode; |
8badd27a | 111 | module_param(int_mode, int, 0); |
619c5cb6 | 112 | MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X " |
cdaa7cb8 | 113 | "(1 INT#x; 2 MSI)"); |
8badd27a | 114 | |
a18f5128 EG |
115 | static int dropless_fc; |
116 | module_param(dropless_fc, int, 0); | |
117 | MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); | |
118 | ||
8d5726c4 EG |
119 | static int mrrs = -1; |
120 | module_param(mrrs, int, 0); | |
121 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); | |
122 | ||
9898f86d | 123 | static int debug; |
a2fbb9ea | 124 | module_param(debug, int, 0); |
9898f86d EG |
125 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
126 | ||
a2fbb9ea | 127 | |
619c5cb6 VZ |
128 | |
129 | struct workqueue_struct *bnx2x_wq; | |
ec6ba945 | 130 | |
1ef1d45a BW |
131 | struct bnx2x_mac_vals { |
132 | u32 xmac_addr; | |
133 | u32 xmac_val; | |
134 | u32 emac_addr; | |
135 | u32 emac_val; | |
136 | u32 umac_addr; | |
137 | u32 umac_val; | |
138 | u32 bmac_addr; | |
139 | u32 bmac_val[2]; | |
140 | }; | |
141 | ||
a2fbb9ea ET |
142 | enum bnx2x_board_type { |
143 | BCM57710 = 0, | |
619c5cb6 VZ |
144 | BCM57711, |
145 | BCM57711E, | |
146 | BCM57712, | |
147 | BCM57712_MF, | |
1ab4434c | 148 | BCM57712_VF, |
619c5cb6 VZ |
149 | BCM57800, |
150 | BCM57800_MF, | |
1ab4434c | 151 | BCM57800_VF, |
619c5cb6 VZ |
152 | BCM57810, |
153 | BCM57810_MF, | |
1ab4434c | 154 | BCM57810_VF, |
c3def943 YM |
155 | BCM57840_4_10, |
156 | BCM57840_2_20, | |
7e8e02df | 157 | BCM57840_MF, |
1ab4434c | 158 | BCM57840_VF, |
7e8e02df | 159 | BCM57811, |
1ab4434c AE |
160 | BCM57811_MF, |
161 | BCM57840_O, | |
162 | BCM57840_MFO, | |
163 | BCM57811_VF | |
a2fbb9ea ET |
164 | }; |
165 | ||
34f80b04 | 166 | /* indexed by board_type, above */ |
53a10565 | 167 | static struct { |
a2fbb9ea | 168 | char *name; |
0329aba1 | 169 | } board_info[] = { |
1ab4434c AE |
170 | [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" }, |
171 | [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" }, | |
172 | [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" }, | |
173 | [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" }, | |
174 | [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" }, | |
175 | [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" }, | |
176 | [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" }, | |
177 | [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" }, | |
178 | [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" }, | |
179 | [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" }, | |
180 | [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" }, | |
181 | [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" }, | |
182 | [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" }, | |
183 | [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" }, | |
184 | [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" }, | |
185 | [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }, | |
186 | [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" }, | |
187 | [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" }, | |
188 | [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" }, | |
189 | [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" }, | |
190 | [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" } | |
a2fbb9ea ET |
191 | }; |
192 | ||
619c5cb6 VZ |
193 | #ifndef PCI_DEVICE_ID_NX2_57710 |
194 | #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710 | |
195 | #endif | |
196 | #ifndef PCI_DEVICE_ID_NX2_57711 | |
197 | #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711 | |
198 | #endif | |
199 | #ifndef PCI_DEVICE_ID_NX2_57711E | |
200 | #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E | |
201 | #endif | |
202 | #ifndef PCI_DEVICE_ID_NX2_57712 | |
203 | #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712 | |
204 | #endif | |
205 | #ifndef PCI_DEVICE_ID_NX2_57712_MF | |
206 | #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF | |
207 | #endif | |
8395be5e AE |
208 | #ifndef PCI_DEVICE_ID_NX2_57712_VF |
209 | #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF | |
210 | #endif | |
619c5cb6 VZ |
211 | #ifndef PCI_DEVICE_ID_NX2_57800 |
212 | #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800 | |
213 | #endif | |
214 | #ifndef PCI_DEVICE_ID_NX2_57800_MF | |
215 | #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF | |
216 | #endif | |
8395be5e AE |
217 | #ifndef PCI_DEVICE_ID_NX2_57800_VF |
218 | #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF | |
219 | #endif | |
619c5cb6 VZ |
220 | #ifndef PCI_DEVICE_ID_NX2_57810 |
221 | #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810 | |
222 | #endif | |
223 | #ifndef PCI_DEVICE_ID_NX2_57810_MF | |
224 | #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF | |
225 | #endif | |
c3def943 YM |
226 | #ifndef PCI_DEVICE_ID_NX2_57840_O |
227 | #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE | |
228 | #endif | |
8395be5e AE |
229 | #ifndef PCI_DEVICE_ID_NX2_57810_VF |
230 | #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF | |
231 | #endif | |
c3def943 YM |
232 | #ifndef PCI_DEVICE_ID_NX2_57840_4_10 |
233 | #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10 | |
234 | #endif | |
235 | #ifndef PCI_DEVICE_ID_NX2_57840_2_20 | |
236 | #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20 | |
237 | #endif | |
238 | #ifndef PCI_DEVICE_ID_NX2_57840_MFO | |
239 | #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE | |
619c5cb6 VZ |
240 | #endif |
241 | #ifndef PCI_DEVICE_ID_NX2_57840_MF | |
242 | #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF | |
243 | #endif | |
8395be5e AE |
244 | #ifndef PCI_DEVICE_ID_NX2_57840_VF |
245 | #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF | |
246 | #endif | |
7e8e02df BW |
247 | #ifndef PCI_DEVICE_ID_NX2_57811 |
248 | #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811 | |
249 | #endif | |
250 | #ifndef PCI_DEVICE_ID_NX2_57811_MF | |
251 | #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF | |
252 | #endif | |
8395be5e AE |
253 | #ifndef PCI_DEVICE_ID_NX2_57811_VF |
254 | #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF | |
255 | #endif | |
256 | ||
a3aa1884 | 257 | static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = { |
e4ed7113 EG |
258 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, |
259 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, | |
260 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E }, | |
f2e0899f | 261 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 }, |
619c5cb6 | 262 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF }, |
8395be5e | 263 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF }, |
619c5cb6 VZ |
264 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 }, |
265 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF }, | |
8395be5e | 266 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF }, |
619c5cb6 VZ |
267 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 }, |
268 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF }, | |
c3def943 YM |
269 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O }, |
270 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 }, | |
271 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 }, | |
8395be5e | 272 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF }, |
c3def943 | 273 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO }, |
619c5cb6 | 274 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF }, |
8395be5e | 275 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF }, |
7e8e02df BW |
276 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 }, |
277 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF }, | |
8395be5e | 278 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF }, |
a2fbb9ea ET |
279 | { 0 } |
280 | }; | |
281 | ||
282 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); | |
283 | ||
452427b0 YM |
284 | /* Global resources for unloading a previously loaded device */ |
285 | #define BNX2X_PREV_WAIT_NEEDED 1 | |
286 | static DEFINE_SEMAPHORE(bnx2x_prev_sem); | |
287 | static LIST_HEAD(bnx2x_prev_list); | |
a2fbb9ea ET |
288 | /**************************************************************************** |
289 | * General service functions | |
290 | ****************************************************************************/ | |
291 | ||
1191cb83 | 292 | static void __storm_memset_dma_mapping(struct bnx2x *bp, |
619c5cb6 VZ |
293 | u32 addr, dma_addr_t mapping) |
294 | { | |
295 | REG_WR(bp, addr, U64_LO(mapping)); | |
296 | REG_WR(bp, addr + 4, U64_HI(mapping)); | |
297 | } | |
298 | ||
1191cb83 ED |
299 | static void storm_memset_spq_addr(struct bnx2x *bp, |
300 | dma_addr_t mapping, u16 abs_fid) | |
619c5cb6 VZ |
301 | { |
302 | u32 addr = XSEM_REG_FAST_MEMORY + | |
303 | XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid); | |
304 | ||
305 | __storm_memset_dma_mapping(bp, addr, mapping); | |
306 | } | |
307 | ||
1191cb83 ED |
308 | static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid, |
309 | u16 pf_id) | |
523224a3 | 310 | { |
619c5cb6 VZ |
311 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid), |
312 | pf_id); | |
313 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid), | |
314 | pf_id); | |
315 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid), | |
316 | pf_id); | |
317 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid), | |
318 | pf_id); | |
523224a3 DK |
319 | } |
320 | ||
1191cb83 ED |
321 | static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid, |
322 | u8 enable) | |
619c5cb6 VZ |
323 | { |
324 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid), | |
325 | enable); | |
326 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid), | |
327 | enable); | |
328 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid), | |
329 | enable); | |
330 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid), | |
331 | enable); | |
332 | } | |
523224a3 | 333 | |
1191cb83 ED |
334 | static void storm_memset_eq_data(struct bnx2x *bp, |
335 | struct event_ring_data *eq_data, | |
523224a3 DK |
336 | u16 pfid) |
337 | { | |
338 | size_t size = sizeof(struct event_ring_data); | |
339 | ||
340 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid); | |
341 | ||
342 | __storm_memset_struct(bp, addr, size, (u32 *)eq_data); | |
343 | } | |
344 | ||
1191cb83 ED |
345 | static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod, |
346 | u16 pfid) | |
523224a3 DK |
347 | { |
348 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid); | |
349 | REG_WR16(bp, addr, eq_prod); | |
350 | } | |
351 | ||
a2fbb9ea ET |
352 | /* used only at init |
353 | * locking is done by mcp | |
354 | */ | |
8d96286a | 355 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
a2fbb9ea ET |
356 | { |
357 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
358 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); | |
359 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
360 | PCICFG_VENDOR_ID_OFFSET); | |
361 | } | |
362 | ||
a2fbb9ea ET |
363 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
364 | { | |
365 | u32 val; | |
366 | ||
367 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
368 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); | |
369 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
370 | PCICFG_VENDOR_ID_OFFSET); | |
371 | ||
372 | return val; | |
373 | } | |
a2fbb9ea | 374 | |
f2e0899f DK |
375 | #define DMAE_DP_SRC_GRC "grc src_addr [%08x]" |
376 | #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]" | |
377 | #define DMAE_DP_DST_GRC "grc dst_addr [%08x]" | |
378 | #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]" | |
379 | #define DMAE_DP_DST_NONE "dst_addr [none]" | |
380 | ||
fd1fc79d AE |
381 | void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl) |
382 | { | |
383 | u32 src_type = dmae->opcode & DMAE_COMMAND_SRC; | |
384 | ||
385 | switch (dmae->opcode & DMAE_COMMAND_DST) { | |
386 | case DMAE_CMD_DST_PCI: | |
387 | if (src_type == DMAE_CMD_SRC_PCI) | |
388 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
389 | "src [%x:%08x], len [%d*4], dst [%x:%08x]\n" | |
390 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
391 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
392 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
393 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
394 | dmae->comp_val); | |
395 | else | |
396 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
397 | "src [%08x], len [%d*4], dst [%x:%08x]\n" | |
398 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
399 | dmae->opcode, dmae->src_addr_lo >> 2, | |
400 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
401 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
402 | dmae->comp_val); | |
403 | break; | |
404 | case DMAE_CMD_DST_GRC: | |
405 | if (src_type == DMAE_CMD_SRC_PCI) | |
406 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
407 | "src [%x:%08x], len [%d*4], dst_addr [%08x]\n" | |
408 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
409 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
410 | dmae->len, dmae->dst_addr_lo >> 2, | |
411 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
412 | dmae->comp_val); | |
413 | else | |
414 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
415 | "src [%08x], len [%d*4], dst [%08x]\n" | |
416 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
417 | dmae->opcode, dmae->src_addr_lo >> 2, | |
418 | dmae->len, dmae->dst_addr_lo >> 2, | |
419 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
420 | dmae->comp_val); | |
421 | break; | |
422 | default: | |
423 | if (src_type == DMAE_CMD_SRC_PCI) | |
424 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
425 | "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n" | |
426 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
427 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
428 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
429 | dmae->comp_val); | |
430 | else | |
431 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
432 | "src_addr [%08x] len [%d * 4] dst_addr [none]\n" | |
433 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
434 | dmae->opcode, dmae->src_addr_lo >> 2, | |
435 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
436 | dmae->comp_val); | |
437 | break; | |
438 | } | |
439 | } | |
f2e0899f | 440 | |
a2fbb9ea | 441 | /* copy command into DMAE command memory and set DMAE command go */ |
6c719d00 | 442 | void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx) |
a2fbb9ea ET |
443 | { |
444 | u32 cmd_offset; | |
445 | int i; | |
446 | ||
447 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); | |
448 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { | |
449 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); | |
a2fbb9ea ET |
450 | } |
451 | REG_WR(bp, dmae_reg_go_c[idx], 1); | |
452 | } | |
453 | ||
f2e0899f | 454 | u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type) |
a2fbb9ea | 455 | { |
f2e0899f DK |
456 | return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) | |
457 | DMAE_CMD_C_ENABLE); | |
458 | } | |
ad8d3948 | 459 | |
f2e0899f DK |
460 | u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode) |
461 | { | |
462 | return opcode & ~DMAE_CMD_SRC_RESET; | |
463 | } | |
ad8d3948 | 464 | |
f2e0899f DK |
465 | u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type, |
466 | bool with_comp, u8 comp_type) | |
467 | { | |
468 | u32 opcode = 0; | |
469 | ||
470 | opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) | | |
471 | (dst_type << DMAE_COMMAND_DST_SHIFT)); | |
ad8d3948 | 472 | |
f2e0899f DK |
473 | opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET); |
474 | ||
475 | opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0); | |
3395a033 DK |
476 | opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) | |
477 | (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT)); | |
f2e0899f | 478 | opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT); |
a2fbb9ea | 479 | |
a2fbb9ea | 480 | #ifdef __BIG_ENDIAN |
f2e0899f | 481 | opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP; |
a2fbb9ea | 482 | #else |
f2e0899f | 483 | opcode |= DMAE_CMD_ENDIANITY_DW_SWAP; |
a2fbb9ea | 484 | #endif |
f2e0899f DK |
485 | if (with_comp) |
486 | opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type); | |
487 | return opcode; | |
488 | } | |
489 | ||
fd1fc79d | 490 | void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, |
8d96286a | 491 | struct dmae_command *dmae, |
492 | u8 src_type, u8 dst_type) | |
f2e0899f DK |
493 | { |
494 | memset(dmae, 0, sizeof(struct dmae_command)); | |
495 | ||
496 | /* set the opcode */ | |
497 | dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type, | |
498 | true, DMAE_COMP_PCI); | |
499 | ||
500 | /* fill in the completion parameters */ | |
501 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); | |
502 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); | |
503 | dmae->comp_val = DMAE_COMP_VAL; | |
504 | } | |
505 | ||
fd1fc79d AE |
506 | /* issue a dmae command over the init-channel and wait for completion */ |
507 | int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae) | |
f2e0899f DK |
508 | { |
509 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); | |
5e374b5a | 510 | int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000; |
f2e0899f DK |
511 | int rc = 0; |
512 | ||
619c5cb6 VZ |
513 | /* |
514 | * Lock the dmae channel. Disable BHs to prevent a dead-lock | |
515 | * as long as this code is called both from syscall context and | |
516 | * from ndo_set_rx_mode() flow that may be called from BH. | |
517 | */ | |
6e30dd4e | 518 | spin_lock_bh(&bp->dmae_lock); |
5ff7b6d4 | 519 | |
f2e0899f | 520 | /* reset completion */ |
a2fbb9ea ET |
521 | *wb_comp = 0; |
522 | ||
f2e0899f DK |
523 | /* post the command on the channel used for initializations */ |
524 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); | |
a2fbb9ea | 525 | |
f2e0899f | 526 | /* wait for completion */ |
a2fbb9ea | 527 | udelay(5); |
f2e0899f | 528 | while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) { |
ad8d3948 | 529 | |
95c6c616 AE |
530 | if (!cnt || |
531 | (bp->recovery_state != BNX2X_RECOVERY_DONE && | |
532 | bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) { | |
c3eefaf6 | 533 | BNX2X_ERR("DMAE timeout!\n"); |
f2e0899f DK |
534 | rc = DMAE_TIMEOUT; |
535 | goto unlock; | |
a2fbb9ea | 536 | } |
ad8d3948 | 537 | cnt--; |
f2e0899f | 538 | udelay(50); |
a2fbb9ea | 539 | } |
f2e0899f DK |
540 | if (*wb_comp & DMAE_PCI_ERR_FLAG) { |
541 | BNX2X_ERR("DMAE PCI error!\n"); | |
542 | rc = DMAE_PCI_ERROR; | |
543 | } | |
544 | ||
f2e0899f | 545 | unlock: |
6e30dd4e | 546 | spin_unlock_bh(&bp->dmae_lock); |
f2e0899f DK |
547 | return rc; |
548 | } | |
549 | ||
550 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, | |
551 | u32 len32) | |
552 | { | |
553 | struct dmae_command dmae; | |
554 | ||
555 | if (!bp->dmae_ready) { | |
556 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
557 | ||
127a425e AE |
558 | if (CHIP_IS_E1(bp)) |
559 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); | |
560 | else | |
561 | bnx2x_init_str_wr(bp, dst_addr, data, len32); | |
f2e0899f DK |
562 | return; |
563 | } | |
564 | ||
565 | /* set opcode and fixed command fields */ | |
566 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC); | |
567 | ||
568 | /* fill in addresses and len */ | |
569 | dmae.src_addr_lo = U64_LO(dma_addr); | |
570 | dmae.src_addr_hi = U64_HI(dma_addr); | |
571 | dmae.dst_addr_lo = dst_addr >> 2; | |
572 | dmae.dst_addr_hi = 0; | |
573 | dmae.len = len32; | |
574 | ||
f2e0899f DK |
575 | /* issue the command and wait for completion */ |
576 | bnx2x_issue_dmae_with_comp(bp, &dmae); | |
a2fbb9ea ET |
577 | } |
578 | ||
c18487ee | 579 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
a2fbb9ea | 580 | { |
5ff7b6d4 | 581 | struct dmae_command dmae; |
ad8d3948 EG |
582 | |
583 | if (!bp->dmae_ready) { | |
584 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
585 | int i; | |
586 | ||
51c1a580 | 587 | if (CHIP_IS_E1(bp)) |
127a425e AE |
588 | for (i = 0; i < len32; i++) |
589 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); | |
51c1a580 | 590 | else |
127a425e AE |
591 | for (i = 0; i < len32; i++) |
592 | data[i] = REG_RD(bp, src_addr + i*4); | |
593 | ||
ad8d3948 EG |
594 | return; |
595 | } | |
596 | ||
f2e0899f DK |
597 | /* set opcode and fixed command fields */ |
598 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI); | |
a2fbb9ea | 599 | |
f2e0899f | 600 | /* fill in addresses and len */ |
5ff7b6d4 EG |
601 | dmae.src_addr_lo = src_addr >> 2; |
602 | dmae.src_addr_hi = 0; | |
603 | dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); | |
604 | dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); | |
605 | dmae.len = len32; | |
ad8d3948 | 606 | |
f2e0899f DK |
607 | /* issue the command and wait for completion */ |
608 | bnx2x_issue_dmae_with_comp(bp, &dmae); | |
ad8d3948 EG |
609 | } |
610 | ||
8d96286a | 611 | static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, |
612 | u32 addr, u32 len) | |
573f2035 | 613 | { |
02e3c6cb | 614 | int dmae_wr_max = DMAE_LEN32_WR_MAX(bp); |
573f2035 EG |
615 | int offset = 0; |
616 | ||
02e3c6cb | 617 | while (len > dmae_wr_max) { |
573f2035 | 618 | bnx2x_write_dmae(bp, phys_addr + offset, |
02e3c6cb VZ |
619 | addr + offset, dmae_wr_max); |
620 | offset += dmae_wr_max * 4; | |
621 | len -= dmae_wr_max; | |
573f2035 EG |
622 | } |
623 | ||
624 | bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len); | |
625 | } | |
626 | ||
a2fbb9ea ET |
627 | static int bnx2x_mc_assert(struct bnx2x *bp) |
628 | { | |
a2fbb9ea | 629 | char last_idx; |
34f80b04 EG |
630 | int i, rc = 0; |
631 | u32 row0, row1, row2, row3; | |
632 | ||
633 | /* XSTORM */ | |
634 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + | |
635 | XSTORM_ASSERT_LIST_INDEX_OFFSET); | |
636 | if (last_idx) | |
637 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
638 | ||
639 | /* print the asserts */ | |
640 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
641 | ||
642 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
643 | XSTORM_ASSERT_LIST_OFFSET(i)); | |
644 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
645 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
646 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
647 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
648 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
649 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
650 | ||
651 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 652 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
653 | i, row3, row2, row1, row0); |
654 | rc++; | |
655 | } else { | |
656 | break; | |
657 | } | |
658 | } | |
659 | ||
660 | /* TSTORM */ | |
661 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + | |
662 | TSTORM_ASSERT_LIST_INDEX_OFFSET); | |
663 | if (last_idx) | |
664 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
665 | ||
666 | /* print the asserts */ | |
667 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
668 | ||
669 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
670 | TSTORM_ASSERT_LIST_OFFSET(i)); | |
671 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
672 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
673 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
674 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
675 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
676 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
677 | ||
678 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 679 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
680 | i, row3, row2, row1, row0); |
681 | rc++; | |
682 | } else { | |
683 | break; | |
684 | } | |
685 | } | |
686 | ||
687 | /* CSTORM */ | |
688 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + | |
689 | CSTORM_ASSERT_LIST_INDEX_OFFSET); | |
690 | if (last_idx) | |
691 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
692 | ||
693 | /* print the asserts */ | |
694 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
695 | ||
696 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
697 | CSTORM_ASSERT_LIST_OFFSET(i)); | |
698 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
699 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
700 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
701 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
702 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
703 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
704 | ||
705 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 706 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
707 | i, row3, row2, row1, row0); |
708 | rc++; | |
709 | } else { | |
710 | break; | |
711 | } | |
712 | } | |
713 | ||
714 | /* USTORM */ | |
715 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + | |
716 | USTORM_ASSERT_LIST_INDEX_OFFSET); | |
717 | if (last_idx) | |
718 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
719 | ||
720 | /* print the asserts */ | |
721 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
722 | ||
723 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
724 | USTORM_ASSERT_LIST_OFFSET(i)); | |
725 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
726 | USTORM_ASSERT_LIST_OFFSET(i) + 4); | |
727 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
728 | USTORM_ASSERT_LIST_OFFSET(i) + 8); | |
729 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
730 | USTORM_ASSERT_LIST_OFFSET(i) + 12); | |
731 | ||
732 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 733 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
734 | i, row3, row2, row1, row0); |
735 | rc++; | |
736 | } else { | |
737 | break; | |
a2fbb9ea ET |
738 | } |
739 | } | |
34f80b04 | 740 | |
a2fbb9ea ET |
741 | return rc; |
742 | } | |
c14423fe | 743 | |
7a25cc73 | 744 | void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl) |
a2fbb9ea | 745 | { |
7a25cc73 | 746 | u32 addr, val; |
a2fbb9ea | 747 | u32 mark, offset; |
4781bfad | 748 | __be32 data[9]; |
a2fbb9ea | 749 | int word; |
f2e0899f | 750 | u32 trace_shmem_base; |
2145a920 VZ |
751 | if (BP_NOMCP(bp)) { |
752 | BNX2X_ERR("NO MCP - can not dump\n"); | |
753 | return; | |
754 | } | |
7a25cc73 DK |
755 | netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n", |
756 | (bp->common.bc_ver & 0xff0000) >> 16, | |
757 | (bp->common.bc_ver & 0xff00) >> 8, | |
758 | (bp->common.bc_ver & 0xff)); | |
759 | ||
760 | val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER); | |
761 | if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER)) | |
51c1a580 | 762 | BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val); |
cdaa7cb8 | 763 | |
f2e0899f DK |
764 | if (BP_PATH(bp) == 0) |
765 | trace_shmem_base = bp->common.shmem_base; | |
766 | else | |
767 | trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr); | |
de128804 DK |
768 | addr = trace_shmem_base - 0x800; |
769 | ||
770 | /* validate TRCB signature */ | |
771 | mark = REG_RD(bp, addr); | |
772 | if (mark != MFW_TRACE_SIGNATURE) { | |
773 | BNX2X_ERR("Trace buffer signature is missing."); | |
774 | return ; | |
775 | } | |
776 | ||
777 | /* read cyclic buffer pointer */ | |
778 | addr += 4; | |
cdaa7cb8 | 779 | mark = REG_RD(bp, addr); |
f2e0899f DK |
780 | mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH) |
781 | + ((mark + 0x3) & ~0x3) - 0x08000000; | |
7a25cc73 | 782 | printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark); |
a2fbb9ea | 783 | |
7a25cc73 | 784 | printk("%s", lvl); |
2de67439 YM |
785 | |
786 | /* dump buffer after the mark */ | |
f2e0899f | 787 | for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) { |
a2fbb9ea | 788 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 789 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 790 | data[8] = 0x0; |
7995c64e | 791 | pr_cont("%s", (char *)data); |
a2fbb9ea | 792 | } |
2de67439 YM |
793 | |
794 | /* dump buffer before the mark */ | |
cdaa7cb8 | 795 | for (offset = addr + 4; offset <= mark; offset += 0x8*4) { |
a2fbb9ea | 796 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 797 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 798 | data[8] = 0x0; |
7995c64e | 799 | pr_cont("%s", (char *)data); |
a2fbb9ea | 800 | } |
7a25cc73 DK |
801 | printk("%s" "end of fw dump\n", lvl); |
802 | } | |
803 | ||
1191cb83 | 804 | static void bnx2x_fw_dump(struct bnx2x *bp) |
7a25cc73 DK |
805 | { |
806 | bnx2x_fw_dump_lvl(bp, KERN_ERR); | |
a2fbb9ea ET |
807 | } |
808 | ||
823e1d90 YM |
809 | static void bnx2x_hc_int_disable(struct bnx2x *bp) |
810 | { | |
811 | int port = BP_PORT(bp); | |
812 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; | |
813 | u32 val = REG_RD(bp, addr); | |
814 | ||
815 | /* in E1 we must use only PCI configuration space to disable | |
816 | * MSI/MSIX capablility | |
817 | * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block | |
818 | */ | |
819 | if (CHIP_IS_E1(bp)) { | |
820 | /* Since IGU_PF_CONF_MSI_MSIX_EN still always on | |
821 | * Use mask register to prevent from HC sending interrupts | |
822 | * after we exit the function | |
823 | */ | |
824 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0); | |
825 | ||
826 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
827 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
828 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
829 | } else | |
830 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
831 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
832 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
833 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
834 | ||
835 | DP(NETIF_MSG_IFDOWN, | |
836 | "write %x to HC %d (addr 0x%x)\n", | |
837 | val, port, addr); | |
838 | ||
839 | /* flush all outstanding writes */ | |
840 | mmiowb(); | |
841 | ||
842 | REG_WR(bp, addr, val); | |
843 | if (REG_RD(bp, addr) != val) | |
844 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); | |
845 | } | |
846 | ||
847 | static void bnx2x_igu_int_disable(struct bnx2x *bp) | |
848 | { | |
849 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
850 | ||
851 | val &= ~(IGU_PF_CONF_MSI_MSIX_EN | | |
852 | IGU_PF_CONF_INT_LINE_EN | | |
853 | IGU_PF_CONF_ATTN_BIT_EN); | |
854 | ||
855 | DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val); | |
856 | ||
857 | /* flush all outstanding writes */ | |
858 | mmiowb(); | |
859 | ||
860 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
861 | if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val) | |
862 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); | |
863 | } | |
864 | ||
865 | static void bnx2x_int_disable(struct bnx2x *bp) | |
866 | { | |
867 | if (bp->common.int_block == INT_BLOCK_HC) | |
868 | bnx2x_hc_int_disable(bp); | |
869 | else | |
870 | bnx2x_igu_int_disable(bp); | |
871 | } | |
872 | ||
873 | void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int) | |
a2fbb9ea ET |
874 | { |
875 | int i; | |
523224a3 DK |
876 | u16 j; |
877 | struct hc_sp_status_block_data sp_sb_data; | |
878 | int func = BP_FUNC(bp); | |
879 | #ifdef BNX2X_STOP_ON_ERROR | |
880 | u16 start = 0, end = 0; | |
6383c0b3 | 881 | u8 cos; |
523224a3 | 882 | #endif |
823e1d90 YM |
883 | if (disable_int) |
884 | bnx2x_int_disable(bp); | |
a2fbb9ea | 885 | |
66e855f3 | 886 | bp->stats_state = STATS_STATE_DISABLED; |
7a752993 | 887 | bp->eth_stats.unrecoverable_error++; |
66e855f3 YG |
888 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
889 | ||
a2fbb9ea ET |
890 | BNX2X_ERR("begin crash dump -----------------\n"); |
891 | ||
8440d2b6 EG |
892 | /* Indices */ |
893 | /* Common */ | |
51c1a580 | 894 | BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n", |
619c5cb6 VZ |
895 | bp->def_idx, bp->def_att_idx, bp->attn_state, |
896 | bp->spq_prod_idx, bp->stats_counter); | |
523224a3 DK |
897 | BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n", |
898 | bp->def_status_blk->atten_status_block.attn_bits, | |
899 | bp->def_status_blk->atten_status_block.attn_bits_ack, | |
900 | bp->def_status_blk->atten_status_block.status_block_id, | |
901 | bp->def_status_blk->atten_status_block.attn_bits_index); | |
902 | BNX2X_ERR(" def ("); | |
903 | for (i = 0; i < HC_SP_SB_MAX_INDICES; i++) | |
904 | pr_cont("0x%x%s", | |
f1deab50 JP |
905 | bp->def_status_blk->sp_sb.index_values[i], |
906 | (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " "); | |
523224a3 DK |
907 | |
908 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
909 | *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
910 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
911 | i*sizeof(u32)); | |
912 | ||
f1deab50 | 913 | pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n", |
523224a3 DK |
914 | sp_sb_data.igu_sb_id, |
915 | sp_sb_data.igu_seg_id, | |
916 | sp_sb_data.p_func.pf_id, | |
917 | sp_sb_data.p_func.vnic_id, | |
918 | sp_sb_data.p_func.vf_id, | |
619c5cb6 VZ |
919 | sp_sb_data.p_func.vf_valid, |
920 | sp_sb_data.state); | |
523224a3 | 921 | |
8440d2b6 | 922 | |
ec6ba945 | 923 | for_each_eth_queue(bp, i) { |
a2fbb9ea | 924 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
523224a3 | 925 | int loop; |
f2e0899f | 926 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
927 | struct hc_status_block_data_e1x sb_data_e1x; |
928 | struct hc_status_block_sm *hc_sm_p = | |
619c5cb6 VZ |
929 | CHIP_IS_E1x(bp) ? |
930 | sb_data_e1x.common.state_machine : | |
931 | sb_data_e2.common.state_machine; | |
523224a3 | 932 | struct hc_index_data *hc_index_p = |
619c5cb6 VZ |
933 | CHIP_IS_E1x(bp) ? |
934 | sb_data_e1x.index_data : | |
935 | sb_data_e2.index_data; | |
6383c0b3 | 936 | u8 data_size, cos; |
523224a3 | 937 | u32 *sb_data_p; |
6383c0b3 | 938 | struct bnx2x_fp_txdata txdata; |
523224a3 DK |
939 | |
940 | /* Rx */ | |
51c1a580 | 941 | BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n", |
8440d2b6 | 942 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
523224a3 | 943 | fp->rx_comp_prod, |
66e855f3 | 944 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
51c1a580 | 945 | BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n", |
8440d2b6 | 946 | fp->rx_sge_prod, fp->last_max_sge, |
523224a3 | 947 | le16_to_cpu(fp->fp_hc_idx)); |
a2fbb9ea | 948 | |
523224a3 | 949 | /* Tx */ |
6383c0b3 AE |
950 | for_each_cos_in_tx_queue(fp, cos) |
951 | { | |
65565884 | 952 | txdata = *fp->txdata_ptr[cos]; |
51c1a580 | 953 | BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n", |
6383c0b3 AE |
954 | i, txdata.tx_pkt_prod, |
955 | txdata.tx_pkt_cons, txdata.tx_bd_prod, | |
956 | txdata.tx_bd_cons, | |
957 | le16_to_cpu(*txdata.tx_cons_sb)); | |
958 | } | |
523224a3 | 959 | |
619c5cb6 VZ |
960 | loop = CHIP_IS_E1x(bp) ? |
961 | HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2; | |
523224a3 DK |
962 | |
963 | /* host sb data */ | |
964 | ||
ec6ba945 VZ |
965 | if (IS_FCOE_FP(fp)) |
966 | continue; | |
55c11941 | 967 | |
523224a3 DK |
968 | BNX2X_ERR(" run indexes ("); |
969 | for (j = 0; j < HC_SB_MAX_SM; j++) | |
970 | pr_cont("0x%x%s", | |
971 | fp->sb_running_index[j], | |
972 | (j == HC_SB_MAX_SM - 1) ? ")" : " "); | |
973 | ||
974 | BNX2X_ERR(" indexes ("); | |
975 | for (j = 0; j < loop; j++) | |
976 | pr_cont("0x%x%s", | |
977 | fp->sb_index_values[j], | |
978 | (j == loop - 1) ? ")" : " "); | |
979 | /* fw sb data */ | |
619c5cb6 VZ |
980 | data_size = CHIP_IS_E1x(bp) ? |
981 | sizeof(struct hc_status_block_data_e1x) : | |
982 | sizeof(struct hc_status_block_data_e2); | |
523224a3 | 983 | data_size /= sizeof(u32); |
619c5cb6 VZ |
984 | sb_data_p = CHIP_IS_E1x(bp) ? |
985 | (u32 *)&sb_data_e1x : | |
986 | (u32 *)&sb_data_e2; | |
523224a3 DK |
987 | /* copy sb data in here */ |
988 | for (j = 0; j < data_size; j++) | |
989 | *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
990 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) + | |
991 | j * sizeof(u32)); | |
992 | ||
619c5cb6 | 993 | if (!CHIP_IS_E1x(bp)) { |
51c1a580 | 994 | pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n", |
f2e0899f DK |
995 | sb_data_e2.common.p_func.pf_id, |
996 | sb_data_e2.common.p_func.vf_id, | |
997 | sb_data_e2.common.p_func.vf_valid, | |
998 | sb_data_e2.common.p_func.vnic_id, | |
619c5cb6 VZ |
999 | sb_data_e2.common.same_igu_sb_1b, |
1000 | sb_data_e2.common.state); | |
f2e0899f | 1001 | } else { |
51c1a580 | 1002 | pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n", |
f2e0899f DK |
1003 | sb_data_e1x.common.p_func.pf_id, |
1004 | sb_data_e1x.common.p_func.vf_id, | |
1005 | sb_data_e1x.common.p_func.vf_valid, | |
1006 | sb_data_e1x.common.p_func.vnic_id, | |
619c5cb6 VZ |
1007 | sb_data_e1x.common.same_igu_sb_1b, |
1008 | sb_data_e1x.common.state); | |
f2e0899f | 1009 | } |
523224a3 DK |
1010 | |
1011 | /* SB_SMs data */ | |
1012 | for (j = 0; j < HC_SB_MAX_SM; j++) { | |
51c1a580 MS |
1013 | pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n", |
1014 | j, hc_sm_p[j].__flags, | |
1015 | hc_sm_p[j].igu_sb_id, | |
1016 | hc_sm_p[j].igu_seg_id, | |
1017 | hc_sm_p[j].time_to_expire, | |
1018 | hc_sm_p[j].timer_value); | |
523224a3 DK |
1019 | } |
1020 | ||
1021 | /* Indecies data */ | |
1022 | for (j = 0; j < loop; j++) { | |
51c1a580 | 1023 | pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j, |
523224a3 DK |
1024 | hc_index_p[j].flags, |
1025 | hc_index_p[j].timeout); | |
1026 | } | |
8440d2b6 | 1027 | } |
a2fbb9ea | 1028 | |
523224a3 | 1029 | #ifdef BNX2X_STOP_ON_ERROR |
04c46736 YM |
1030 | |
1031 | /* event queue */ | |
1032 | for (i = 0; i < NUM_EQ_DESC; i++) { | |
1033 | u32 *data = (u32 *)&bp->eq_ring[i].message.data; | |
1034 | ||
1035 | BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n", | |
1036 | i, bp->eq_ring[i].message.opcode, | |
1037 | bp->eq_ring[i].message.error); | |
1038 | BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]); | |
1039 | } | |
1040 | ||
8440d2b6 EG |
1041 | /* Rings */ |
1042 | /* Rx */ | |
55c11941 | 1043 | for_each_valid_rx_queue(bp, i) { |
8440d2b6 | 1044 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea ET |
1045 | |
1046 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); | |
1047 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); | |
8440d2b6 | 1048 | for (j = start; j != end; j = RX_BD(j + 1)) { |
a2fbb9ea ET |
1049 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
1050 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; | |
1051 | ||
c3eefaf6 | 1052 | BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
44151acb | 1053 | i, j, rx_bd[1], rx_bd[0], sw_bd->data); |
a2fbb9ea ET |
1054 | } |
1055 | ||
3196a88a EG |
1056 | start = RX_SGE(fp->rx_sge_prod); |
1057 | end = RX_SGE(fp->last_max_sge); | |
8440d2b6 | 1058 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
7a9b2557 VZ |
1059 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
1060 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; | |
1061 | ||
c3eefaf6 EG |
1062 | BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
1063 | i, j, rx_sge[1], rx_sge[0], sw_page->page); | |
7a9b2557 VZ |
1064 | } |
1065 | ||
a2fbb9ea ET |
1066 | start = RCQ_BD(fp->rx_comp_cons - 10); |
1067 | end = RCQ_BD(fp->rx_comp_cons + 503); | |
8440d2b6 | 1068 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
a2fbb9ea ET |
1069 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
1070 | ||
c3eefaf6 EG |
1071 | BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n", |
1072 | i, j, cqe[0], cqe[1], cqe[2], cqe[3]); | |
a2fbb9ea ET |
1073 | } |
1074 | } | |
1075 | ||
8440d2b6 | 1076 | /* Tx */ |
55c11941 | 1077 | for_each_valid_tx_queue(bp, i) { |
8440d2b6 | 1078 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
6383c0b3 | 1079 | for_each_cos_in_tx_queue(fp, cos) { |
65565884 | 1080 | struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos]; |
6383c0b3 AE |
1081 | |
1082 | start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10); | |
1083 | end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245); | |
1084 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
1085 | struct sw_tx_bd *sw_bd = | |
1086 | &txdata->tx_buf_ring[j]; | |
1087 | ||
51c1a580 | 1088 | BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n", |
6383c0b3 AE |
1089 | i, cos, j, sw_bd->skb, |
1090 | sw_bd->first_bd); | |
1091 | } | |
8440d2b6 | 1092 | |
6383c0b3 AE |
1093 | start = TX_BD(txdata->tx_bd_cons - 10); |
1094 | end = TX_BD(txdata->tx_bd_cons + 254); | |
1095 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
1096 | u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j]; | |
8440d2b6 | 1097 | |
51c1a580 | 1098 | BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n", |
6383c0b3 AE |
1099 | i, cos, j, tx_bd[0], tx_bd[1], |
1100 | tx_bd[2], tx_bd[3]); | |
1101 | } | |
8440d2b6 EG |
1102 | } |
1103 | } | |
523224a3 | 1104 | #endif |
34f80b04 | 1105 | bnx2x_fw_dump(bp); |
a2fbb9ea ET |
1106 | bnx2x_mc_assert(bp); |
1107 | BNX2X_ERR("end crash dump -----------------\n"); | |
a2fbb9ea ET |
1108 | } |
1109 | ||
619c5cb6 VZ |
1110 | /* |
1111 | * FLR Support for E2 | |
1112 | * | |
1113 | * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW | |
1114 | * initialization. | |
1115 | */ | |
1116 | #define FLR_WAIT_USEC 10000 /* 10 miliseconds */ | |
89db4ad8 AE |
1117 | #define FLR_WAIT_INTERVAL 50 /* usec */ |
1118 | #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */ | |
619c5cb6 VZ |
1119 | |
1120 | struct pbf_pN_buf_regs { | |
1121 | int pN; | |
1122 | u32 init_crd; | |
1123 | u32 crd; | |
1124 | u32 crd_freed; | |
1125 | }; | |
1126 | ||
1127 | struct pbf_pN_cmd_regs { | |
1128 | int pN; | |
1129 | u32 lines_occup; | |
1130 | u32 lines_freed; | |
1131 | }; | |
1132 | ||
1133 | static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp, | |
1134 | struct pbf_pN_buf_regs *regs, | |
1135 | u32 poll_count) | |
1136 | { | |
1137 | u32 init_crd, crd, crd_start, crd_freed, crd_freed_start; | |
1138 | u32 cur_cnt = poll_count; | |
1139 | ||
1140 | crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed); | |
1141 | crd = crd_start = REG_RD(bp, regs->crd); | |
1142 | init_crd = REG_RD(bp, regs->init_crd); | |
1143 | ||
1144 | DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd); | |
1145 | DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd); | |
1146 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed); | |
1147 | ||
1148 | while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) < | |
1149 | (init_crd - crd_start))) { | |
1150 | if (cur_cnt--) { | |
89db4ad8 | 1151 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1152 | crd = REG_RD(bp, regs->crd); |
1153 | crd_freed = REG_RD(bp, regs->crd_freed); | |
1154 | } else { | |
1155 | DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n", | |
1156 | regs->pN); | |
1157 | DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n", | |
1158 | regs->pN, crd); | |
1159 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n", | |
1160 | regs->pN, crd_freed); | |
1161 | break; | |
1162 | } | |
1163 | } | |
1164 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n", | |
89db4ad8 | 1165 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1166 | } |
1167 | ||
1168 | static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp, | |
1169 | struct pbf_pN_cmd_regs *regs, | |
1170 | u32 poll_count) | |
1171 | { | |
1172 | u32 occup, to_free, freed, freed_start; | |
1173 | u32 cur_cnt = poll_count; | |
1174 | ||
1175 | occup = to_free = REG_RD(bp, regs->lines_occup); | |
1176 | freed = freed_start = REG_RD(bp, regs->lines_freed); | |
1177 | ||
1178 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); | |
1179 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); | |
1180 | ||
1181 | while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) { | |
1182 | if (cur_cnt--) { | |
89db4ad8 | 1183 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1184 | occup = REG_RD(bp, regs->lines_occup); |
1185 | freed = REG_RD(bp, regs->lines_freed); | |
1186 | } else { | |
1187 | DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n", | |
1188 | regs->pN); | |
1189 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", | |
1190 | regs->pN, occup); | |
1191 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", | |
1192 | regs->pN, freed); | |
1193 | break; | |
1194 | } | |
1195 | } | |
1196 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n", | |
89db4ad8 | 1197 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1198 | } |
1199 | ||
1191cb83 ED |
1200 | static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg, |
1201 | u32 expected, u32 poll_count) | |
619c5cb6 VZ |
1202 | { |
1203 | u32 cur_cnt = poll_count; | |
1204 | u32 val; | |
1205 | ||
1206 | while ((val = REG_RD(bp, reg)) != expected && cur_cnt--) | |
89db4ad8 | 1207 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1208 | |
1209 | return val; | |
1210 | } | |
1211 | ||
d16132ce AE |
1212 | int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg, |
1213 | char *msg, u32 poll_cnt) | |
619c5cb6 VZ |
1214 | { |
1215 | u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt); | |
1216 | if (val != 0) { | |
1217 | BNX2X_ERR("%s usage count=%d\n", msg, val); | |
1218 | return 1; | |
1219 | } | |
1220 | return 0; | |
1221 | } | |
1222 | ||
d16132ce AE |
1223 | /* Common routines with VF FLR cleanup */ |
1224 | u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp) | |
619c5cb6 VZ |
1225 | { |
1226 | /* adjust polling timeout */ | |
1227 | if (CHIP_REV_IS_EMUL(bp)) | |
1228 | return FLR_POLL_CNT * 2000; | |
1229 | ||
1230 | if (CHIP_REV_IS_FPGA(bp)) | |
1231 | return FLR_POLL_CNT * 120; | |
1232 | ||
1233 | return FLR_POLL_CNT; | |
1234 | } | |
1235 | ||
d16132ce | 1236 | void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count) |
619c5cb6 VZ |
1237 | { |
1238 | struct pbf_pN_cmd_regs cmd_regs[] = { | |
1239 | {0, (CHIP_IS_E3B0(bp)) ? | |
1240 | PBF_REG_TQ_OCCUPANCY_Q0 : | |
1241 | PBF_REG_P0_TQ_OCCUPANCY, | |
1242 | (CHIP_IS_E3B0(bp)) ? | |
1243 | PBF_REG_TQ_LINES_FREED_CNT_Q0 : | |
1244 | PBF_REG_P0_TQ_LINES_FREED_CNT}, | |
1245 | {1, (CHIP_IS_E3B0(bp)) ? | |
1246 | PBF_REG_TQ_OCCUPANCY_Q1 : | |
1247 | PBF_REG_P1_TQ_OCCUPANCY, | |
1248 | (CHIP_IS_E3B0(bp)) ? | |
1249 | PBF_REG_TQ_LINES_FREED_CNT_Q1 : | |
1250 | PBF_REG_P1_TQ_LINES_FREED_CNT}, | |
1251 | {4, (CHIP_IS_E3B0(bp)) ? | |
1252 | PBF_REG_TQ_OCCUPANCY_LB_Q : | |
1253 | PBF_REG_P4_TQ_OCCUPANCY, | |
1254 | (CHIP_IS_E3B0(bp)) ? | |
1255 | PBF_REG_TQ_LINES_FREED_CNT_LB_Q : | |
1256 | PBF_REG_P4_TQ_LINES_FREED_CNT} | |
1257 | }; | |
1258 | ||
1259 | struct pbf_pN_buf_regs buf_regs[] = { | |
1260 | {0, (CHIP_IS_E3B0(bp)) ? | |
1261 | PBF_REG_INIT_CRD_Q0 : | |
1262 | PBF_REG_P0_INIT_CRD , | |
1263 | (CHIP_IS_E3B0(bp)) ? | |
1264 | PBF_REG_CREDIT_Q0 : | |
1265 | PBF_REG_P0_CREDIT, | |
1266 | (CHIP_IS_E3B0(bp)) ? | |
1267 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 : | |
1268 | PBF_REG_P0_INTERNAL_CRD_FREED_CNT}, | |
1269 | {1, (CHIP_IS_E3B0(bp)) ? | |
1270 | PBF_REG_INIT_CRD_Q1 : | |
1271 | PBF_REG_P1_INIT_CRD, | |
1272 | (CHIP_IS_E3B0(bp)) ? | |
1273 | PBF_REG_CREDIT_Q1 : | |
1274 | PBF_REG_P1_CREDIT, | |
1275 | (CHIP_IS_E3B0(bp)) ? | |
1276 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 : | |
1277 | PBF_REG_P1_INTERNAL_CRD_FREED_CNT}, | |
1278 | {4, (CHIP_IS_E3B0(bp)) ? | |
1279 | PBF_REG_INIT_CRD_LB_Q : | |
1280 | PBF_REG_P4_INIT_CRD, | |
1281 | (CHIP_IS_E3B0(bp)) ? | |
1282 | PBF_REG_CREDIT_LB_Q : | |
1283 | PBF_REG_P4_CREDIT, | |
1284 | (CHIP_IS_E3B0(bp)) ? | |
1285 | PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q : | |
1286 | PBF_REG_P4_INTERNAL_CRD_FREED_CNT}, | |
1287 | }; | |
1288 | ||
1289 | int i; | |
1290 | ||
1291 | /* Verify the command queues are flushed P0, P1, P4 */ | |
1292 | for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) | |
1293 | bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count); | |
1294 | ||
1295 | ||
1296 | /* Verify the transmission buffers are flushed P0, P1, P4 */ | |
1297 | for (i = 0; i < ARRAY_SIZE(buf_regs); i++) | |
1298 | bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count); | |
1299 | } | |
1300 | ||
1301 | #define OP_GEN_PARAM(param) \ | |
1302 | (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM) | |
1303 | ||
1304 | #define OP_GEN_TYPE(type) \ | |
1305 | (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE) | |
1306 | ||
1307 | #define OP_GEN_AGG_VECT(index) \ | |
1308 | (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX) | |
1309 | ||
1310 | ||
d16132ce | 1311 | int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt) |
619c5cb6 | 1312 | { |
86564c3f | 1313 | u32 op_gen_command = 0; |
619c5cb6 VZ |
1314 | |
1315 | u32 comp_addr = BAR_CSTRORM_INTMEM + | |
1316 | CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func); | |
1317 | int ret = 0; | |
1318 | ||
1319 | if (REG_RD(bp, comp_addr)) { | |
89db4ad8 | 1320 | BNX2X_ERR("Cleanup complete was not 0 before sending\n"); |
619c5cb6 VZ |
1321 | return 1; |
1322 | } | |
1323 | ||
86564c3f YM |
1324 | op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX); |
1325 | op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE); | |
1326 | op_gen_command |= OP_GEN_AGG_VECT(clnup_func); | |
1327 | op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT; | |
619c5cb6 | 1328 | |
89db4ad8 | 1329 | DP(BNX2X_MSG_SP, "sending FW Final cleanup\n"); |
86564c3f | 1330 | REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command); |
619c5cb6 VZ |
1331 | |
1332 | if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) { | |
1333 | BNX2X_ERR("FW final cleanup did not succeed\n"); | |
51c1a580 MS |
1334 | DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n", |
1335 | (REG_RD(bp, comp_addr))); | |
d16132ce AE |
1336 | bnx2x_panic(); |
1337 | return 1; | |
619c5cb6 VZ |
1338 | } |
1339 | /* Zero completion for nxt FLR */ | |
1340 | REG_WR(bp, comp_addr, 0); | |
1341 | ||
1342 | return ret; | |
1343 | } | |
1344 | ||
b56e9670 | 1345 | u8 bnx2x_is_pcie_pending(struct pci_dev *dev) |
619c5cb6 | 1346 | { |
619c5cb6 VZ |
1347 | u16 status; |
1348 | ||
2a80eebc | 1349 | pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status); |
619c5cb6 VZ |
1350 | return status & PCI_EXP_DEVSTA_TRPND; |
1351 | } | |
1352 | ||
1353 | /* PF FLR specific routines | |
1354 | */ | |
1355 | static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt) | |
1356 | { | |
1357 | ||
1358 | /* wait for CFC PF usage-counter to zero (includes all the VFs) */ | |
1359 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1360 | CFC_REG_NUM_LCIDS_INSIDE_PF, | |
1361 | "CFC PF usage counter timed out", | |
1362 | poll_cnt)) | |
1363 | return 1; | |
1364 | ||
1365 | ||
1366 | /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */ | |
1367 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1368 | DORQ_REG_PF_USAGE_CNT, | |
1369 | "DQ PF usage counter timed out", | |
1370 | poll_cnt)) | |
1371 | return 1; | |
1372 | ||
1373 | /* Wait for QM PF usage-counter to zero (until DQ cleanup) */ | |
1374 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1375 | QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp), | |
1376 | "QM PF usage counter timed out", | |
1377 | poll_cnt)) | |
1378 | return 1; | |
1379 | ||
1380 | /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */ | |
1381 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1382 | TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp), | |
1383 | "Timers VNIC usage counter timed out", | |
1384 | poll_cnt)) | |
1385 | return 1; | |
1386 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1387 | TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp), | |
1388 | "Timers NUM_SCANS usage counter timed out", | |
1389 | poll_cnt)) | |
1390 | return 1; | |
1391 | ||
1392 | /* Wait DMAE PF usage counter to zero */ | |
1393 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1394 | dmae_reg_go_c[INIT_DMAE_C(bp)], | |
1395 | "DMAE dommand register timed out", | |
1396 | poll_cnt)) | |
1397 | return 1; | |
1398 | ||
1399 | return 0; | |
1400 | } | |
1401 | ||
1402 | static void bnx2x_hw_enable_status(struct bnx2x *bp) | |
1403 | { | |
1404 | u32 val; | |
1405 | ||
1406 | val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF); | |
1407 | DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val); | |
1408 | ||
1409 | val = REG_RD(bp, PBF_REG_DISABLE_PF); | |
1410 | DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val); | |
1411 | ||
1412 | val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN); | |
1413 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val); | |
1414 | ||
1415 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN); | |
1416 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val); | |
1417 | ||
1418 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK); | |
1419 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val); | |
1420 | ||
1421 | val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR); | |
1422 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val); | |
1423 | ||
1424 | val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR); | |
1425 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val); | |
1426 | ||
1427 | val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); | |
1428 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", | |
1429 | val); | |
1430 | } | |
1431 | ||
1432 | static int bnx2x_pf_flr_clnup(struct bnx2x *bp) | |
1433 | { | |
1434 | u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp); | |
1435 | ||
1436 | DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp)); | |
1437 | ||
1438 | /* Re-enable PF target read access */ | |
1439 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); | |
1440 | ||
1441 | /* Poll HW usage counters */ | |
89db4ad8 | 1442 | DP(BNX2X_MSG_SP, "Polling usage counters\n"); |
619c5cb6 VZ |
1443 | if (bnx2x_poll_hw_usage_counters(bp, poll_cnt)) |
1444 | return -EBUSY; | |
1445 | ||
1446 | /* Zero the igu 'trailing edge' and 'leading edge' */ | |
1447 | ||
1448 | /* Send the FW cleanup command */ | |
1449 | if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt)) | |
1450 | return -EBUSY; | |
1451 | ||
1452 | /* ATC cleanup */ | |
1453 | ||
1454 | /* Verify TX hw is flushed */ | |
1455 | bnx2x_tx_hw_flushed(bp, poll_cnt); | |
1456 | ||
1457 | /* Wait 100ms (not adjusted according to platform) */ | |
1458 | msleep(100); | |
1459 | ||
1460 | /* Verify no pending pci transactions */ | |
1461 | if (bnx2x_is_pcie_pending(bp->pdev)) | |
1462 | BNX2X_ERR("PCIE Transactions still pending\n"); | |
1463 | ||
1464 | /* Debug */ | |
1465 | bnx2x_hw_enable_status(bp); | |
1466 | ||
1467 | /* | |
1468 | * Master enable - Due to WB DMAE writes performed before this | |
1469 | * register is re-initialized as part of the regular function init | |
1470 | */ | |
1471 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
1472 | ||
1473 | return 0; | |
1474 | } | |
1475 | ||
f2e0899f | 1476 | static void bnx2x_hc_int_enable(struct bnx2x *bp) |
a2fbb9ea | 1477 | { |
34f80b04 | 1478 | int port = BP_PORT(bp); |
a2fbb9ea ET |
1479 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
1480 | u32 val = REG_RD(bp, addr); | |
69c326b3 DK |
1481 | bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false; |
1482 | bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false; | |
1483 | bool msi = (bp->flags & USING_MSI_FLAG) ? true : false; | |
a2fbb9ea ET |
1484 | |
1485 | if (msix) { | |
8badd27a EG |
1486 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
1487 | HC_CONFIG_0_REG_INT_LINE_EN_0); | |
a2fbb9ea ET |
1488 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
1489 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
69c326b3 DK |
1490 | if (single_msix) |
1491 | val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0; | |
8badd27a EG |
1492 | } else if (msi) { |
1493 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; | |
1494 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
1495 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
1496 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
a2fbb9ea ET |
1497 | } else { |
1498 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
615f8fd9 | 1499 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
a2fbb9ea ET |
1500 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
1501 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
615f8fd9 | 1502 | |
a0fd065c | 1503 | if (!CHIP_IS_E1(bp)) { |
51c1a580 MS |
1504 | DP(NETIF_MSG_IFUP, |
1505 | "write %x to HC %d (addr 0x%x)\n", val, port, addr); | |
615f8fd9 | 1506 | |
a0fd065c | 1507 | REG_WR(bp, addr, val); |
615f8fd9 | 1508 | |
a0fd065c DK |
1509 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
1510 | } | |
a2fbb9ea ET |
1511 | } |
1512 | ||
a0fd065c DK |
1513 | if (CHIP_IS_E1(bp)) |
1514 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF); | |
1515 | ||
51c1a580 MS |
1516 | DP(NETIF_MSG_IFUP, |
1517 | "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr, | |
1518 | (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); | |
a2fbb9ea ET |
1519 | |
1520 | REG_WR(bp, addr, val); | |
37dbbf32 EG |
1521 | /* |
1522 | * Ensure that HC_CONFIG is written before leading/trailing edge config | |
1523 | */ | |
1524 | mmiowb(); | |
1525 | barrier(); | |
34f80b04 | 1526 | |
f2e0899f | 1527 | if (!CHIP_IS_E1(bp)) { |
34f80b04 | 1528 | /* init leading/trailing edge */ |
fb3bff17 | 1529 | if (IS_MF(bp)) { |
3395a033 | 1530 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
34f80b04 | 1531 | if (bp->port.pmf) |
4acac6a5 EG |
1532 | /* enable nig and gpio3 attention */ |
1533 | val |= 0x1100; | |
34f80b04 EG |
1534 | } else |
1535 | val = 0xffff; | |
1536 | ||
1537 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
1538 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
1539 | } | |
37dbbf32 EG |
1540 | |
1541 | /* Make sure that interrupts are indeed enabled from here on */ | |
1542 | mmiowb(); | |
a2fbb9ea ET |
1543 | } |
1544 | ||
f2e0899f DK |
1545 | static void bnx2x_igu_int_enable(struct bnx2x *bp) |
1546 | { | |
1547 | u32 val; | |
30a5de77 DK |
1548 | bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false; |
1549 | bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false; | |
1550 | bool msi = (bp->flags & USING_MSI_FLAG) ? true : false; | |
f2e0899f DK |
1551 | |
1552 | val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
1553 | ||
1554 | if (msix) { | |
1555 | val &= ~(IGU_PF_CONF_INT_LINE_EN | | |
1556 | IGU_PF_CONF_SINGLE_ISR_EN); | |
ebe61d80 | 1557 | val |= (IGU_PF_CONF_MSI_MSIX_EN | |
f2e0899f | 1558 | IGU_PF_CONF_ATTN_BIT_EN); |
30a5de77 DK |
1559 | |
1560 | if (single_msix) | |
1561 | val |= IGU_PF_CONF_SINGLE_ISR_EN; | |
f2e0899f DK |
1562 | } else if (msi) { |
1563 | val &= ~IGU_PF_CONF_INT_LINE_EN; | |
ebe61d80 | 1564 | val |= (IGU_PF_CONF_MSI_MSIX_EN | |
f2e0899f DK |
1565 | IGU_PF_CONF_ATTN_BIT_EN | |
1566 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1567 | } else { | |
1568 | val &= ~IGU_PF_CONF_MSI_MSIX_EN; | |
ebe61d80 | 1569 | val |= (IGU_PF_CONF_INT_LINE_EN | |
f2e0899f DK |
1570 | IGU_PF_CONF_ATTN_BIT_EN | |
1571 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1572 | } | |
1573 | ||
ebe61d80 YM |
1574 | /* Clean previous status - need to configure igu prior to ack*/ |
1575 | if ((!msix) || single_msix) { | |
1576 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1577 | bnx2x_ack_int(bp); | |
1578 | } | |
1579 | ||
1580 | val |= IGU_PF_CONF_FUNC_EN; | |
1581 | ||
51c1a580 | 1582 | DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n", |
f2e0899f DK |
1583 | val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
1584 | ||
1585 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1586 | ||
79a8557a YM |
1587 | if (val & IGU_PF_CONF_INT_LINE_EN) |
1588 | pci_intx(bp->pdev, true); | |
1589 | ||
f2e0899f DK |
1590 | barrier(); |
1591 | ||
1592 | /* init leading/trailing edge */ | |
1593 | if (IS_MF(bp)) { | |
3395a033 | 1594 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
1595 | if (bp->port.pmf) |
1596 | /* enable nig and gpio3 attention */ | |
1597 | val |= 0x1100; | |
1598 | } else | |
1599 | val = 0xffff; | |
1600 | ||
1601 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); | |
1602 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
1603 | ||
1604 | /* Make sure that interrupts are indeed enabled from here on */ | |
1605 | mmiowb(); | |
1606 | } | |
1607 | ||
1608 | void bnx2x_int_enable(struct bnx2x *bp) | |
1609 | { | |
1610 | if (bp->common.int_block == INT_BLOCK_HC) | |
1611 | bnx2x_hc_int_enable(bp); | |
1612 | else | |
1613 | bnx2x_igu_int_enable(bp); | |
1614 | } | |
1615 | ||
9f6c9258 | 1616 | void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
a2fbb9ea | 1617 | { |
a2fbb9ea | 1618 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
8badd27a | 1619 | int i, offset; |
a2fbb9ea | 1620 | |
f8ef6e44 YG |
1621 | if (disable_hw) |
1622 | /* prevent the HW from sending interrupts */ | |
1623 | bnx2x_int_disable(bp); | |
a2fbb9ea ET |
1624 | |
1625 | /* make sure all ISRs are done */ | |
1626 | if (msix) { | |
8badd27a EG |
1627 | synchronize_irq(bp->msix_table[0].vector); |
1628 | offset = 1; | |
55c11941 MS |
1629 | if (CNIC_SUPPORT(bp)) |
1630 | offset++; | |
ec6ba945 | 1631 | for_each_eth_queue(bp, i) |
754a2f52 | 1632 | synchronize_irq(bp->msix_table[offset++].vector); |
a2fbb9ea ET |
1633 | } else |
1634 | synchronize_irq(bp->pdev->irq); | |
1635 | ||
1636 | /* make sure sp_task is not running */ | |
1cf167f2 | 1637 | cancel_delayed_work(&bp->sp_task); |
3deb8167 | 1638 | cancel_delayed_work(&bp->period_task); |
1cf167f2 | 1639 | flush_workqueue(bnx2x_wq); |
a2fbb9ea ET |
1640 | } |
1641 | ||
34f80b04 | 1642 | /* fast path */ |
a2fbb9ea ET |
1643 | |
1644 | /* | |
34f80b04 | 1645 | * General service functions |
a2fbb9ea ET |
1646 | */ |
1647 | ||
72fd0718 VZ |
1648 | /* Return true if succeeded to acquire the lock */ |
1649 | static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource) | |
1650 | { | |
1651 | u32 lock_status; | |
1652 | u32 resource_bit = (1 << resource); | |
1653 | int func = BP_FUNC(bp); | |
1654 | u32 hw_lock_control_reg; | |
1655 | ||
51c1a580 MS |
1656 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1657 | "Trying to take a lock on resource %d\n", resource); | |
72fd0718 VZ |
1658 | |
1659 | /* Validating that the resource is within range */ | |
1660 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1661 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
72fd0718 VZ |
1662 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
1663 | resource, HW_LOCK_MAX_RESOURCE_VALUE); | |
0fdf4d09 | 1664 | return false; |
72fd0718 VZ |
1665 | } |
1666 | ||
1667 | if (func <= 5) | |
1668 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1669 | else | |
1670 | hw_lock_control_reg = | |
1671 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1672 | ||
1673 | /* Try to acquire the lock */ | |
1674 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); | |
1675 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
1676 | if (lock_status & resource_bit) | |
1677 | return true; | |
1678 | ||
51c1a580 MS |
1679 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1680 | "Failed to get a lock on resource %d\n", resource); | |
72fd0718 VZ |
1681 | return false; |
1682 | } | |
1683 | ||
c9ee9206 VZ |
1684 | /** |
1685 | * bnx2x_get_leader_lock_resource - get the recovery leader resource id | |
1686 | * | |
1687 | * @bp: driver handle | |
1688 | * | |
1689 | * Returns the recovery leader resource id according to the engine this function | |
1690 | * belongs to. Currently only only 2 engines is supported. | |
1691 | */ | |
1191cb83 | 1692 | static int bnx2x_get_leader_lock_resource(struct bnx2x *bp) |
c9ee9206 VZ |
1693 | { |
1694 | if (BP_PATH(bp)) | |
1695 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_1; | |
1696 | else | |
1697 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_0; | |
1698 | } | |
1699 | ||
1700 | /** | |
2de67439 | 1701 | * bnx2x_trylock_leader_lock- try to acquire a leader lock. |
c9ee9206 VZ |
1702 | * |
1703 | * @bp: driver handle | |
1704 | * | |
2de67439 | 1705 | * Tries to acquire a leader lock for current engine. |
c9ee9206 | 1706 | */ |
1191cb83 | 1707 | static bool bnx2x_trylock_leader_lock(struct bnx2x *bp) |
c9ee9206 VZ |
1708 | { |
1709 | return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1710 | } | |
1711 | ||
619c5cb6 | 1712 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err); |
55c11941 | 1713 | |
fd1fc79d AE |
1714 | /* schedule the sp task and mark that interrupt occurred (runs from ISR) */ |
1715 | static int bnx2x_schedule_sp_task(struct bnx2x *bp) | |
1716 | { | |
1717 | /* Set the interrupt occurred bit for the sp-task to recognize it | |
1718 | * must ack the interrupt and transition according to the IGU | |
1719 | * state machine. | |
1720 | */ | |
1721 | atomic_set(&bp->interrupt_occurred, 1); | |
1722 | ||
1723 | /* The sp_task must execute only after this bit | |
1724 | * is set, otherwise we will get out of sync and miss all | |
1725 | * further interrupts. Hence, the barrier. | |
1726 | */ | |
1727 | smp_wmb(); | |
1728 | ||
1729 | /* schedule sp_task to workqueue */ | |
1730 | return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); | |
1731 | } | |
3196a88a | 1732 | |
619c5cb6 | 1733 | void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe) |
a2fbb9ea ET |
1734 | { |
1735 | struct bnx2x *bp = fp->bp; | |
1736 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
1737 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
619c5cb6 | 1738 | enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX; |
15192a8c | 1739 | struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a2fbb9ea | 1740 | |
34f80b04 | 1741 | DP(BNX2X_MSG_SP, |
a2fbb9ea | 1742 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
0626b899 | 1743 | fp->index, cid, command, bp->state, |
34f80b04 | 1744 | rr_cqe->ramrod_cqe.ramrod_type); |
a2fbb9ea | 1745 | |
fd1fc79d AE |
1746 | /* If cid is within VF range, replace the slowpath object with the |
1747 | * one corresponding to this VF | |
1748 | */ | |
1749 | if (cid >= BNX2X_FIRST_VF_CID && | |
1750 | cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS) | |
1751 | bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj); | |
1752 | ||
619c5cb6 VZ |
1753 | switch (command) { |
1754 | case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE): | |
d6cae238 | 1755 | DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid); |
619c5cb6 VZ |
1756 | drv_cmd = BNX2X_Q_CMD_UPDATE; |
1757 | break; | |
d6cae238 | 1758 | |
619c5cb6 | 1759 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP): |
d6cae238 | 1760 | DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid); |
619c5cb6 | 1761 | drv_cmd = BNX2X_Q_CMD_SETUP; |
a2fbb9ea ET |
1762 | break; |
1763 | ||
6383c0b3 | 1764 | case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP): |
51c1a580 | 1765 | DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid); |
6383c0b3 AE |
1766 | drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; |
1767 | break; | |
1768 | ||
619c5cb6 | 1769 | case (RAMROD_CMD_ID_ETH_HALT): |
d6cae238 | 1770 | DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid); |
619c5cb6 | 1771 | drv_cmd = BNX2X_Q_CMD_HALT; |
a2fbb9ea ET |
1772 | break; |
1773 | ||
619c5cb6 | 1774 | case (RAMROD_CMD_ID_ETH_TERMINATE): |
d6cae238 | 1775 | DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid); |
619c5cb6 | 1776 | drv_cmd = BNX2X_Q_CMD_TERMINATE; |
a2fbb9ea ET |
1777 | break; |
1778 | ||
619c5cb6 | 1779 | case (RAMROD_CMD_ID_ETH_EMPTY): |
d6cae238 | 1780 | DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid); |
619c5cb6 | 1781 | drv_cmd = BNX2X_Q_CMD_EMPTY; |
993ac7b5 | 1782 | break; |
619c5cb6 VZ |
1783 | |
1784 | default: | |
1785 | BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n", | |
1786 | command, fp->index); | |
1787 | return; | |
523224a3 | 1788 | } |
3196a88a | 1789 | |
619c5cb6 VZ |
1790 | if ((drv_cmd != BNX2X_Q_CMD_MAX) && |
1791 | q_obj->complete_cmd(bp, q_obj, drv_cmd)) | |
1792 | /* q_obj->complete_cmd() failure means that this was | |
1793 | * an unexpected completion. | |
1794 | * | |
1795 | * In this case we don't want to increase the bp->spq_left | |
1796 | * because apparently we haven't sent this command the first | |
1797 | * place. | |
1798 | */ | |
1799 | #ifdef BNX2X_STOP_ON_ERROR | |
1800 | bnx2x_panic(); | |
1801 | #else | |
1802 | return; | |
1803 | #endif | |
fd1fc79d AE |
1804 | /* SRIOV: reschedule any 'in_progress' operations */ |
1805 | bnx2x_iov_sp_event(bp, cid, true); | |
619c5cb6 | 1806 | |
8fe23fbd | 1807 | smp_mb__before_atomic_inc(); |
6e30dd4e | 1808 | atomic_inc(&bp->cq_spq_left); |
619c5cb6 VZ |
1809 | /* push the change in bp->spq_left and towards the memory */ |
1810 | smp_mb__after_atomic_inc(); | |
49d66772 | 1811 | |
d6cae238 VZ |
1812 | DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left)); |
1813 | ||
a3348722 BW |
1814 | if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) && |
1815 | (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) { | |
1816 | /* if Q update ramrod is completed for last Q in AFEX vif set | |
1817 | * flow, then ACK MCP at the end | |
1818 | * | |
1819 | * mark pending ACK to MCP bit. | |
1820 | * prevent case that both bits are cleared. | |
1821 | * At the end of load/unload driver checks that | |
2de67439 | 1822 | * sp_state is cleared, and this order prevents |
a3348722 BW |
1823 | * races |
1824 | */ | |
1825 | smp_mb__before_clear_bit(); | |
1826 | set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state); | |
1827 | wmb(); | |
1828 | clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state); | |
1829 | smp_mb__after_clear_bit(); | |
1830 | ||
fd1fc79d AE |
1831 | /* schedule the sp task as mcp ack is required */ |
1832 | bnx2x_schedule_sp_task(bp); | |
a3348722 BW |
1833 | } |
1834 | ||
523224a3 | 1835 | return; |
a2fbb9ea ET |
1836 | } |
1837 | ||
9f6c9258 | 1838 | irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
a2fbb9ea | 1839 | { |
555f6c78 | 1840 | struct bnx2x *bp = netdev_priv(dev_instance); |
a2fbb9ea | 1841 | u16 status = bnx2x_ack_int(bp); |
34f80b04 | 1842 | u16 mask; |
ca00392c | 1843 | int i; |
6383c0b3 | 1844 | u8 cos; |
a2fbb9ea | 1845 | |
34f80b04 | 1846 | /* Return here if interrupt is shared and it's not for us */ |
a2fbb9ea ET |
1847 | if (unlikely(status == 0)) { |
1848 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); | |
1849 | return IRQ_NONE; | |
1850 | } | |
f5372251 | 1851 | DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status); |
a2fbb9ea | 1852 | |
3196a88a EG |
1853 | #ifdef BNX2X_STOP_ON_ERROR |
1854 | if (unlikely(bp->panic)) | |
1855 | return IRQ_HANDLED; | |
1856 | #endif | |
1857 | ||
ec6ba945 | 1858 | for_each_eth_queue(bp, i) { |
ca00392c | 1859 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea | 1860 | |
55c11941 | 1861 | mask = 0x2 << (fp->index + CNIC_SUPPORT(bp)); |
ca00392c | 1862 | if (status & mask) { |
619c5cb6 | 1863 | /* Handle Rx or Tx according to SB id */ |
54b9ddaa | 1864 | prefetch(fp->rx_cons_sb); |
6383c0b3 | 1865 | for_each_cos_in_tx_queue(fp, cos) |
65565884 | 1866 | prefetch(fp->txdata_ptr[cos]->tx_cons_sb); |
523224a3 | 1867 | prefetch(&fp->sb_running_index[SM_RX_ID]); |
54b9ddaa | 1868 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
ca00392c EG |
1869 | status &= ~mask; |
1870 | } | |
a2fbb9ea ET |
1871 | } |
1872 | ||
55c11941 MS |
1873 | if (CNIC_SUPPORT(bp)) { |
1874 | mask = 0x2; | |
1875 | if (status & (mask | 0x1)) { | |
1876 | struct cnic_ops *c_ops = NULL; | |
993ac7b5 | 1877 | |
ad9b4359 MC |
1878 | rcu_read_lock(); |
1879 | c_ops = rcu_dereference(bp->cnic_ops); | |
1880 | if (c_ops && (bp->cnic_eth_dev.drv_state & | |
1881 | CNIC_DRV_STATE_HANDLES_IRQ)) | |
1882 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
1883 | rcu_read_unlock(); | |
993ac7b5 | 1884 | |
55c11941 MS |
1885 | status &= ~mask; |
1886 | } | |
993ac7b5 | 1887 | } |
a2fbb9ea | 1888 | |
34f80b04 | 1889 | if (unlikely(status & 0x1)) { |
fd1fc79d AE |
1890 | |
1891 | /* schedule sp task to perform default status block work, ack | |
1892 | * attentions and enable interrupts. | |
1893 | */ | |
1894 | bnx2x_schedule_sp_task(bp); | |
a2fbb9ea ET |
1895 | |
1896 | status &= ~0x1; | |
1897 | if (!status) | |
1898 | return IRQ_HANDLED; | |
1899 | } | |
1900 | ||
cdaa7cb8 VZ |
1901 | if (unlikely(status)) |
1902 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", | |
34f80b04 | 1903 | status); |
a2fbb9ea | 1904 | |
c18487ee | 1905 | return IRQ_HANDLED; |
a2fbb9ea ET |
1906 | } |
1907 | ||
c18487ee YR |
1908 | /* Link */ |
1909 | ||
1910 | /* | |
1911 | * General service functions | |
1912 | */ | |
a2fbb9ea | 1913 | |
9f6c9258 | 1914 | int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1915 | { |
1916 | u32 lock_status; | |
1917 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1918 | int func = BP_FUNC(bp); |
1919 | u32 hw_lock_control_reg; | |
c18487ee | 1920 | int cnt; |
a2fbb9ea | 1921 | |
c18487ee YR |
1922 | /* Validating that the resource is within range */ |
1923 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1924 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1925 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1926 | return -EINVAL; | |
1927 | } | |
a2fbb9ea | 1928 | |
4a37fb66 YG |
1929 | if (func <= 5) { |
1930 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1931 | } else { | |
1932 | hw_lock_control_reg = | |
1933 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1934 | } | |
1935 | ||
c18487ee | 1936 | /* Validating that the resource is not already taken */ |
4a37fb66 | 1937 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 1938 | if (lock_status & resource_bit) { |
51c1a580 | 1939 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n", |
c18487ee YR |
1940 | lock_status, resource_bit); |
1941 | return -EEXIST; | |
1942 | } | |
a2fbb9ea | 1943 | |
46230476 EG |
1944 | /* Try for 5 second every 5ms */ |
1945 | for (cnt = 0; cnt < 1000; cnt++) { | |
c18487ee | 1946 | /* Try to acquire the lock */ |
4a37fb66 YG |
1947 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
1948 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
c18487ee YR |
1949 | if (lock_status & resource_bit) |
1950 | return 0; | |
a2fbb9ea | 1951 | |
c18487ee | 1952 | msleep(5); |
a2fbb9ea | 1953 | } |
51c1a580 | 1954 | BNX2X_ERR("Timeout\n"); |
c18487ee YR |
1955 | return -EAGAIN; |
1956 | } | |
a2fbb9ea | 1957 | |
c9ee9206 VZ |
1958 | int bnx2x_release_leader_lock(struct bnx2x *bp) |
1959 | { | |
1960 | return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1961 | } | |
1962 | ||
9f6c9258 | 1963 | int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1964 | { |
1965 | u32 lock_status; | |
1966 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1967 | int func = BP_FUNC(bp); |
1968 | u32 hw_lock_control_reg; | |
a2fbb9ea | 1969 | |
c18487ee YR |
1970 | /* Validating that the resource is within range */ |
1971 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1972 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1973 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1974 | return -EINVAL; | |
1975 | } | |
1976 | ||
4a37fb66 YG |
1977 | if (func <= 5) { |
1978 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1979 | } else { | |
1980 | hw_lock_control_reg = | |
1981 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1982 | } | |
1983 | ||
c18487ee | 1984 | /* Validating that the resource is currently taken */ |
4a37fb66 | 1985 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 1986 | if (!(lock_status & resource_bit)) { |
51c1a580 | 1987 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n", |
c18487ee YR |
1988 | lock_status, resource_bit); |
1989 | return -EFAULT; | |
a2fbb9ea ET |
1990 | } |
1991 | ||
9f6c9258 DK |
1992 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
1993 | return 0; | |
c18487ee | 1994 | } |
a2fbb9ea | 1995 | |
9f6c9258 | 1996 | |
4acac6a5 EG |
1997 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
1998 | { | |
1999 | /* The GPIO should be swapped if swap register is set and active */ | |
2000 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
2001 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
2002 | int gpio_shift = gpio_num + | |
2003 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2004 | u32 gpio_mask = (1 << gpio_shift); | |
2005 | u32 gpio_reg; | |
2006 | int value; | |
2007 | ||
2008 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
2009 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2010 | return -EINVAL; | |
2011 | } | |
2012 | ||
2013 | /* read GPIO value */ | |
2014 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
2015 | ||
2016 | /* get the requested pin value */ | |
2017 | if ((gpio_reg & gpio_mask) == gpio_mask) | |
2018 | value = 1; | |
2019 | else | |
2020 | value = 0; | |
2021 | ||
2022 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); | |
2023 | ||
2024 | return value; | |
2025 | } | |
2026 | ||
17de50b7 | 2027 | int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
c18487ee YR |
2028 | { |
2029 | /* The GPIO should be swapped if swap register is set and active */ | |
2030 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
17de50b7 | 2031 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
c18487ee YR |
2032 | int gpio_shift = gpio_num + |
2033 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2034 | u32 gpio_mask = (1 << gpio_shift); | |
2035 | u32 gpio_reg; | |
a2fbb9ea | 2036 | |
c18487ee YR |
2037 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
2038 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2039 | return -EINVAL; | |
2040 | } | |
a2fbb9ea | 2041 | |
4a37fb66 | 2042 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
c18487ee YR |
2043 | /* read GPIO and mask except the float bits */ |
2044 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); | |
a2fbb9ea | 2045 | |
c18487ee YR |
2046 | switch (mode) { |
2047 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
51c1a580 MS |
2048 | DP(NETIF_MSG_LINK, |
2049 | "Set GPIO %d (shift %d) -> output low\n", | |
c18487ee YR |
2050 | gpio_num, gpio_shift); |
2051 | /* clear FLOAT and set CLR */ | |
2052 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2053 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); | |
2054 | break; | |
a2fbb9ea | 2055 | |
c18487ee | 2056 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
51c1a580 MS |
2057 | DP(NETIF_MSG_LINK, |
2058 | "Set GPIO %d (shift %d) -> output high\n", | |
c18487ee YR |
2059 | gpio_num, gpio_shift); |
2060 | /* clear FLOAT and set SET */ | |
2061 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2062 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); | |
2063 | break; | |
a2fbb9ea | 2064 | |
17de50b7 | 2065 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
51c1a580 MS |
2066 | DP(NETIF_MSG_LINK, |
2067 | "Set GPIO %d (shift %d) -> input\n", | |
c18487ee YR |
2068 | gpio_num, gpio_shift); |
2069 | /* set FLOAT */ | |
2070 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2071 | break; | |
a2fbb9ea | 2072 | |
c18487ee YR |
2073 | default: |
2074 | break; | |
a2fbb9ea ET |
2075 | } |
2076 | ||
c18487ee | 2077 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
4a37fb66 | 2078 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
f1410647 | 2079 | |
c18487ee | 2080 | return 0; |
a2fbb9ea ET |
2081 | } |
2082 | ||
0d40f0d4 YR |
2083 | int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode) |
2084 | { | |
2085 | u32 gpio_reg = 0; | |
2086 | int rc = 0; | |
2087 | ||
2088 | /* Any port swapping should be handled by caller. */ | |
2089 | ||
2090 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2091 | /* read GPIO and mask except the float bits */ | |
2092 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
2093 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2094 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS); | |
2095 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS); | |
2096 | ||
2097 | switch (mode) { | |
2098 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
2099 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins); | |
2100 | /* set CLR */ | |
2101 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS); | |
2102 | break; | |
2103 | ||
2104 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: | |
2105 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins); | |
2106 | /* set SET */ | |
2107 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS); | |
2108 | break; | |
2109 | ||
2110 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: | |
2111 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins); | |
2112 | /* set FLOAT */ | |
2113 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2114 | break; | |
2115 | ||
2116 | default: | |
2117 | BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode); | |
2118 | rc = -EINVAL; | |
2119 | break; | |
2120 | } | |
2121 | ||
2122 | if (rc == 0) | |
2123 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); | |
2124 | ||
2125 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2126 | ||
2127 | return rc; | |
2128 | } | |
2129 | ||
4acac6a5 EG |
2130 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
2131 | { | |
2132 | /* The GPIO should be swapped if swap register is set and active */ | |
2133 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
2134 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
2135 | int gpio_shift = gpio_num + | |
2136 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2137 | u32 gpio_mask = (1 << gpio_shift); | |
2138 | u32 gpio_reg; | |
2139 | ||
2140 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
2141 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2142 | return -EINVAL; | |
2143 | } | |
2144 | ||
2145 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2146 | /* read GPIO int */ | |
2147 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); | |
2148 | ||
2149 | switch (mode) { | |
2150 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: | |
51c1a580 MS |
2151 | DP(NETIF_MSG_LINK, |
2152 | "Clear GPIO INT %d (shift %d) -> output low\n", | |
2153 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2154 | /* clear SET and set CLR */ |
2155 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2156 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2157 | break; | |
2158 | ||
2159 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: | |
51c1a580 MS |
2160 | DP(NETIF_MSG_LINK, |
2161 | "Set GPIO INT %d (shift %d) -> output high\n", | |
2162 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2163 | /* clear CLR and set SET */ |
2164 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2165 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2166 | break; | |
2167 | ||
2168 | default: | |
2169 | break; | |
2170 | } | |
2171 | ||
2172 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); | |
2173 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2174 | ||
2175 | return 0; | |
2176 | } | |
2177 | ||
d6d99a3f | 2178 | static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode) |
a2fbb9ea | 2179 | { |
c18487ee | 2180 | u32 spio_reg; |
a2fbb9ea | 2181 | |
d6d99a3f YM |
2182 | /* Only 2 SPIOs are configurable */ |
2183 | if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) { | |
2184 | BNX2X_ERR("Invalid SPIO 0x%x\n", spio); | |
c18487ee | 2185 | return -EINVAL; |
a2fbb9ea ET |
2186 | } |
2187 | ||
4a37fb66 | 2188 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee | 2189 | /* read SPIO and mask except the float bits */ |
d6d99a3f | 2190 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT); |
a2fbb9ea | 2191 | |
c18487ee | 2192 | switch (mode) { |
d6d99a3f YM |
2193 | case MISC_SPIO_OUTPUT_LOW: |
2194 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio); | |
c18487ee | 2195 | /* clear FLOAT and set CLR */ |
d6d99a3f YM |
2196 | spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); |
2197 | spio_reg |= (spio << MISC_SPIO_CLR_POS); | |
c18487ee | 2198 | break; |
a2fbb9ea | 2199 | |
d6d99a3f YM |
2200 | case MISC_SPIO_OUTPUT_HIGH: |
2201 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio); | |
c18487ee | 2202 | /* clear FLOAT and set SET */ |
d6d99a3f YM |
2203 | spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); |
2204 | spio_reg |= (spio << MISC_SPIO_SET_POS); | |
c18487ee | 2205 | break; |
a2fbb9ea | 2206 | |
d6d99a3f YM |
2207 | case MISC_SPIO_INPUT_HI_Z: |
2208 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio); | |
c18487ee | 2209 | /* set FLOAT */ |
d6d99a3f | 2210 | spio_reg |= (spio << MISC_SPIO_FLOAT_POS); |
c18487ee | 2211 | break; |
a2fbb9ea | 2212 | |
c18487ee YR |
2213 | default: |
2214 | break; | |
a2fbb9ea ET |
2215 | } |
2216 | ||
c18487ee | 2217 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
4a37fb66 | 2218 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee | 2219 | |
a2fbb9ea ET |
2220 | return 0; |
2221 | } | |
2222 | ||
9f6c9258 | 2223 | void bnx2x_calc_fc_adv(struct bnx2x *bp) |
a2fbb9ea | 2224 | { |
a22f0788 | 2225 | u8 cfg_idx = bnx2x_get_link_cfg_idx(bp); |
ad33ea3a EG |
2226 | switch (bp->link_vars.ieee_fc & |
2227 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { | |
c18487ee | 2228 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
a22f0788 | 2229 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2230 | ADVERTISED_Pause); |
c18487ee | 2231 | break; |
356e2385 | 2232 | |
c18487ee | 2233 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
a22f0788 | 2234 | bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause | |
f85582f8 | 2235 | ADVERTISED_Pause); |
c18487ee | 2236 | break; |
356e2385 | 2237 | |
c18487ee | 2238 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
a22f0788 | 2239 | bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause; |
c18487ee | 2240 | break; |
356e2385 | 2241 | |
c18487ee | 2242 | default: |
a22f0788 | 2243 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2244 | ADVERTISED_Pause); |
c18487ee YR |
2245 | break; |
2246 | } | |
2247 | } | |
f1410647 | 2248 | |
cd1dfce2 | 2249 | static void bnx2x_set_requested_fc(struct bnx2x *bp) |
c18487ee | 2250 | { |
cd1dfce2 YM |
2251 | /* Initialize link parameters structure variables |
2252 | * It is recommended to turn off RX FC for jumbo frames | |
2253 | * for better performance | |
2254 | */ | |
2255 | if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000)) | |
2256 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; | |
2257 | else | |
2258 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; | |
2259 | } | |
a2fbb9ea | 2260 | |
cd1dfce2 YM |
2261 | int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
2262 | { | |
2263 | int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp); | |
2264 | u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx]; | |
2265 | ||
2266 | if (!BP_NOMCP(bp)) { | |
2267 | bnx2x_set_requested_fc(bp); | |
4a37fb66 | 2268 | bnx2x_acquire_phy_lock(bp); |
b5bf9068 | 2269 | |
a22f0788 | 2270 | if (load_mode == LOAD_DIAG) { |
1cb0c788 YR |
2271 | struct link_params *lp = &bp->link_params; |
2272 | lp->loopback_mode = LOOPBACK_XGXS; | |
2273 | /* do PHY loopback at 10G speed, if possible */ | |
2274 | if (lp->req_line_speed[cfx_idx] < SPEED_10000) { | |
2275 | if (lp->speed_cap_mask[cfx_idx] & | |
2276 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) | |
2277 | lp->req_line_speed[cfx_idx] = | |
2278 | SPEED_10000; | |
2279 | else | |
2280 | lp->req_line_speed[cfx_idx] = | |
2281 | SPEED_1000; | |
2282 | } | |
a22f0788 | 2283 | } |
b5bf9068 | 2284 | |
8970b2e4 MS |
2285 | if (load_mode == LOAD_LOOPBACK_EXT) { |
2286 | struct link_params *lp = &bp->link_params; | |
2287 | lp->loopback_mode = LOOPBACK_EXT; | |
2288 | } | |
2289 | ||
19680c48 | 2290 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
b5bf9068 | 2291 | |
4a37fb66 | 2292 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2293 | |
3c96c68b EG |
2294 | bnx2x_calc_fc_adv(bp); |
2295 | ||
cd1dfce2 | 2296 | if (bp->link_vars.link_up) { |
b5bf9068 | 2297 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
19680c48 | 2298 | bnx2x_link_report(bp); |
cd1dfce2 YM |
2299 | } |
2300 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
a22f0788 | 2301 | bp->link_params.req_line_speed[cfx_idx] = req_line_speed; |
19680c48 EG |
2302 | return rc; |
2303 | } | |
f5372251 | 2304 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
19680c48 | 2305 | return -EINVAL; |
a2fbb9ea ET |
2306 | } |
2307 | ||
9f6c9258 | 2308 | void bnx2x_link_set(struct bnx2x *bp) |
a2fbb9ea | 2309 | { |
19680c48 | 2310 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2311 | bnx2x_acquire_phy_lock(bp); |
19680c48 | 2312 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
4a37fb66 | 2313 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2314 | |
19680c48 EG |
2315 | bnx2x_calc_fc_adv(bp); |
2316 | } else | |
f5372251 | 2317 | BNX2X_ERR("Bootcode is missing - can not set link\n"); |
c18487ee | 2318 | } |
a2fbb9ea | 2319 | |
c18487ee YR |
2320 | static void bnx2x__link_reset(struct bnx2x *bp) |
2321 | { | |
19680c48 | 2322 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2323 | bnx2x_acquire_phy_lock(bp); |
5d07d868 | 2324 | bnx2x_lfa_reset(&bp->link_params, &bp->link_vars); |
4a37fb66 | 2325 | bnx2x_release_phy_lock(bp); |
19680c48 | 2326 | } else |
f5372251 | 2327 | BNX2X_ERR("Bootcode is missing - can not reset link\n"); |
c18487ee | 2328 | } |
a2fbb9ea | 2329 | |
5d07d868 YM |
2330 | void bnx2x_force_link_reset(struct bnx2x *bp) |
2331 | { | |
2332 | bnx2x_acquire_phy_lock(bp); | |
2333 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); | |
2334 | bnx2x_release_phy_lock(bp); | |
2335 | } | |
2336 | ||
a22f0788 | 2337 | u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes) |
c18487ee | 2338 | { |
2145a920 | 2339 | u8 rc = 0; |
a2fbb9ea | 2340 | |
2145a920 VZ |
2341 | if (!BP_NOMCP(bp)) { |
2342 | bnx2x_acquire_phy_lock(bp); | |
a22f0788 YR |
2343 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars, |
2344 | is_serdes); | |
2145a920 VZ |
2345 | bnx2x_release_phy_lock(bp); |
2346 | } else | |
2347 | BNX2X_ERR("Bootcode is missing - can not test link\n"); | |
a2fbb9ea | 2348 | |
c18487ee YR |
2349 | return rc; |
2350 | } | |
a2fbb9ea | 2351 | |
34f80b04 | 2352 | |
2691d51d EG |
2353 | /* Calculates the sum of vn_min_rates. |
2354 | It's needed for further normalizing of the min_rates. | |
2355 | Returns: | |
2356 | sum of vn_min_rates. | |
2357 | or | |
2358 | 0 - if all the min_rates are 0. | |
2359 | In the later case fainess algorithm should be deactivated. | |
2360 | If not all min_rates are zero then those that are zeroes will be set to 1. | |
2361 | */ | |
b475d78f YM |
2362 | static void bnx2x_calc_vn_min(struct bnx2x *bp, |
2363 | struct cmng_init_input *input) | |
2691d51d EG |
2364 | { |
2365 | int all_zero = 1; | |
2691d51d EG |
2366 | int vn; |
2367 | ||
3395a033 | 2368 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
f2e0899f | 2369 | u32 vn_cfg = bp->mf_config[vn]; |
2691d51d EG |
2370 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
2371 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; | |
2372 | ||
2373 | /* Skip hidden vns */ | |
2374 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) | |
b475d78f | 2375 | vn_min_rate = 0; |
2691d51d | 2376 | /* If min rate is zero - set it to 1 */ |
b475d78f | 2377 | else if (!vn_min_rate) |
2691d51d EG |
2378 | vn_min_rate = DEF_MIN_RATE; |
2379 | else | |
2380 | all_zero = 0; | |
2381 | ||
b475d78f | 2382 | input->vnic_min_rate[vn] = vn_min_rate; |
2691d51d EG |
2383 | } |
2384 | ||
30ae438b DK |
2385 | /* if ETS or all min rates are zeros - disable fairness */ |
2386 | if (BNX2X_IS_ETS_ENABLED(bp)) { | |
b475d78f | 2387 | input->flags.cmng_enables &= |
30ae438b DK |
2388 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
2389 | DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n"); | |
2390 | } else if (all_zero) { | |
b475d78f | 2391 | input->flags.cmng_enables &= |
b015e3d1 | 2392 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
b475d78f YM |
2393 | DP(NETIF_MSG_IFUP, |
2394 | "All MIN values are zeroes fairness will be disabled\n"); | |
b015e3d1 | 2395 | } else |
b475d78f | 2396 | input->flags.cmng_enables |= |
b015e3d1 | 2397 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
2691d51d EG |
2398 | } |
2399 | ||
b475d78f YM |
2400 | static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn, |
2401 | struct cmng_init_input *input) | |
34f80b04 | 2402 | { |
b475d78f | 2403 | u16 vn_max_rate; |
f2e0899f | 2404 | u32 vn_cfg = bp->mf_config[vn]; |
34f80b04 | 2405 | |
b475d78f | 2406 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
34f80b04 | 2407 | vn_max_rate = 0; |
b475d78f | 2408 | else { |
faa6fcbb DK |
2409 | u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg); |
2410 | ||
b475d78f | 2411 | if (IS_MF_SI(bp)) { |
faa6fcbb DK |
2412 | /* maxCfg in percents of linkspeed */ |
2413 | vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100; | |
b475d78f | 2414 | } else /* SD modes */ |
faa6fcbb DK |
2415 | /* maxCfg is absolute in 100Mb units */ |
2416 | vn_max_rate = maxCfg * 100; | |
34f80b04 | 2417 | } |
f85582f8 | 2418 | |
b475d78f | 2419 | DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate); |
34f80b04 | 2420 | |
b475d78f | 2421 | input->vnic_max_rate[vn] = vn_max_rate; |
34f80b04 | 2422 | } |
f85582f8 | 2423 | |
b475d78f | 2424 | |
523224a3 DK |
2425 | static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp) |
2426 | { | |
2427 | if (CHIP_REV_IS_SLOW(bp)) | |
2428 | return CMNG_FNS_NONE; | |
fb3bff17 | 2429 | if (IS_MF(bp)) |
523224a3 DK |
2430 | return CMNG_FNS_MINMAX; |
2431 | ||
2432 | return CMNG_FNS_NONE; | |
2433 | } | |
2434 | ||
2ae17f66 | 2435 | void bnx2x_read_mf_cfg(struct bnx2x *bp) |
523224a3 | 2436 | { |
0793f83f | 2437 | int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1); |
523224a3 DK |
2438 | |
2439 | if (BP_NOMCP(bp)) | |
2440 | return; /* what should be the default bvalue in this case */ | |
2441 | ||
0793f83f DK |
2442 | /* For 2 port configuration the absolute function number formula |
2443 | * is: | |
2444 | * abs_func = 2 * vn + BP_PORT + BP_PATH | |
2445 | * | |
2446 | * and there are 4 functions per port | |
2447 | * | |
2448 | * For 4 port configuration it is | |
2449 | * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH | |
2450 | * | |
2451 | * and there are 2 functions per port | |
2452 | */ | |
3395a033 | 2453 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
0793f83f DK |
2454 | int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp); |
2455 | ||
2456 | if (func >= E1H_FUNC_MAX) | |
2457 | break; | |
2458 | ||
f2e0899f | 2459 | bp->mf_config[vn] = |
523224a3 DK |
2460 | MF_CFG_RD(bp, func_mf_config[func].config); |
2461 | } | |
a3348722 BW |
2462 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
2463 | DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n"); | |
2464 | bp->flags |= MF_FUNC_DIS; | |
2465 | } else { | |
2466 | DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n"); | |
2467 | bp->flags &= ~MF_FUNC_DIS; | |
2468 | } | |
523224a3 DK |
2469 | } |
2470 | ||
2471 | static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type) | |
2472 | { | |
b475d78f YM |
2473 | struct cmng_init_input input; |
2474 | memset(&input, 0, sizeof(struct cmng_init_input)); | |
2475 | ||
2476 | input.port_rate = bp->link_vars.line_speed; | |
523224a3 DK |
2477 | |
2478 | if (cmng_type == CMNG_FNS_MINMAX) { | |
2479 | int vn; | |
2480 | ||
523224a3 DK |
2481 | /* read mf conf from shmem */ |
2482 | if (read_cfg) | |
2483 | bnx2x_read_mf_cfg(bp); | |
2484 | ||
523224a3 | 2485 | /* vn_weight_sum and enable fairness if not 0 */ |
b475d78f | 2486 | bnx2x_calc_vn_min(bp, &input); |
523224a3 DK |
2487 | |
2488 | /* calculate and set min-max rate for each vn */ | |
c4154f25 | 2489 | if (bp->port.pmf) |
3395a033 | 2490 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) |
b475d78f | 2491 | bnx2x_calc_vn_max(bp, vn, &input); |
523224a3 DK |
2492 | |
2493 | /* always enable rate shaping and fairness */ | |
b475d78f | 2494 | input.flags.cmng_enables |= |
523224a3 | 2495 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
b475d78f YM |
2496 | |
2497 | bnx2x_init_cmng(&input, &bp->cmng); | |
523224a3 DK |
2498 | return; |
2499 | } | |
2500 | ||
2501 | /* rate shaping and fairness are disabled */ | |
2502 | DP(NETIF_MSG_IFUP, | |
2503 | "rate shaping and fairness are disabled\n"); | |
2504 | } | |
34f80b04 | 2505 | |
1191cb83 ED |
2506 | static void storm_memset_cmng(struct bnx2x *bp, |
2507 | struct cmng_init *cmng, | |
2508 | u8 port) | |
2509 | { | |
2510 | int vn; | |
2511 | size_t size = sizeof(struct cmng_struct_per_port); | |
2512 | ||
2513 | u32 addr = BAR_XSTRORM_INTMEM + | |
2514 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port); | |
2515 | ||
2516 | __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port); | |
2517 | ||
2518 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { | |
2519 | int func = func_by_vn(bp, vn); | |
2520 | ||
2521 | addr = BAR_XSTRORM_INTMEM + | |
2522 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func); | |
2523 | size = sizeof(struct rate_shaping_vars_per_vn); | |
2524 | __storm_memset_struct(bp, addr, size, | |
2525 | (u32 *)&cmng->vnic.vnic_max_rate[vn]); | |
2526 | ||
2527 | addr = BAR_XSTRORM_INTMEM + | |
2528 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func); | |
2529 | size = sizeof(struct fairness_vars_per_vn); | |
2530 | __storm_memset_struct(bp, addr, size, | |
2531 | (u32 *)&cmng->vnic.vnic_min_rate[vn]); | |
2532 | } | |
2533 | } | |
2534 | ||
c18487ee YR |
2535 | /* This function is called upon link interrupt */ |
2536 | static void bnx2x_link_attn(struct bnx2x *bp) | |
2537 | { | |
bb2a0f7a YG |
2538 | /* Make sure that we are synced with the current statistics */ |
2539 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2540 | ||
c18487ee | 2541 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
a2fbb9ea | 2542 | |
bb2a0f7a YG |
2543 | if (bp->link_vars.link_up) { |
2544 | ||
1c06328c | 2545 | /* dropless flow control */ |
f2e0899f | 2546 | if (!CHIP_IS_E1(bp) && bp->dropless_fc) { |
1c06328c EG |
2547 | int port = BP_PORT(bp); |
2548 | u32 pause_enabled = 0; | |
2549 | ||
2550 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) | |
2551 | pause_enabled = 1; | |
2552 | ||
2553 | REG_WR(bp, BAR_USTRORM_INTMEM + | |
ca00392c | 2554 | USTORM_ETH_PAUSE_ENABLED_OFFSET(port), |
1c06328c EG |
2555 | pause_enabled); |
2556 | } | |
2557 | ||
619c5cb6 | 2558 | if (bp->link_vars.mac_type != MAC_TYPE_EMAC) { |
bb2a0f7a YG |
2559 | struct host_port_stats *pstats; |
2560 | ||
2561 | pstats = bnx2x_sp(bp, port_stats); | |
619c5cb6 | 2562 | /* reset old mac stats */ |
bb2a0f7a YG |
2563 | memset(&(pstats->mac_stx[0]), 0, |
2564 | sizeof(struct mac_stx)); | |
2565 | } | |
f34d28ea | 2566 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a YG |
2567 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
2568 | } | |
2569 | ||
f2e0899f DK |
2570 | if (bp->link_vars.link_up && bp->link_vars.line_speed) { |
2571 | int cmng_fns = bnx2x_get_cmng_fns_mode(bp); | |
8a1c38d1 | 2572 | |
f2e0899f DK |
2573 | if (cmng_fns != CMNG_FNS_NONE) { |
2574 | bnx2x_cmng_fns_init(bp, false, cmng_fns); | |
2575 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
2576 | } else | |
2577 | /* rate shaping and fairness are disabled */ | |
2578 | DP(NETIF_MSG_IFUP, | |
2579 | "single function mode without fairness\n"); | |
34f80b04 | 2580 | } |
9fdc3e95 | 2581 | |
2ae17f66 VZ |
2582 | __bnx2x_link_report(bp); |
2583 | ||
9fdc3e95 DK |
2584 | if (IS_MF(bp)) |
2585 | bnx2x_link_sync_notify(bp); | |
c18487ee | 2586 | } |
a2fbb9ea | 2587 | |
9f6c9258 | 2588 | void bnx2x__link_status_update(struct bnx2x *bp) |
c18487ee | 2589 | { |
2ae17f66 | 2590 | if (bp->state != BNX2X_STATE_OPEN) |
c18487ee | 2591 | return; |
a2fbb9ea | 2592 | |
00253a8c | 2593 | /* read updated dcb configuration */ |
ad5afc89 AE |
2594 | if (IS_PF(bp)) { |
2595 | bnx2x_dcbx_pmf_update(bp); | |
2596 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); | |
2597 | if (bp->link_vars.link_up) | |
2598 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); | |
2599 | else | |
2600 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2601 | /* indicate link status */ | |
2602 | bnx2x_link_report(bp); | |
a2fbb9ea | 2603 | |
ad5afc89 AE |
2604 | } else { /* VF */ |
2605 | bp->port.supported[0] |= (SUPPORTED_10baseT_Half | | |
2606 | SUPPORTED_10baseT_Full | | |
2607 | SUPPORTED_100baseT_Half | | |
2608 | SUPPORTED_100baseT_Full | | |
2609 | SUPPORTED_1000baseT_Full | | |
2610 | SUPPORTED_2500baseX_Full | | |
2611 | SUPPORTED_10000baseT_Full | | |
2612 | SUPPORTED_TP | | |
2613 | SUPPORTED_FIBRE | | |
2614 | SUPPORTED_Autoneg | | |
2615 | SUPPORTED_Pause | | |
2616 | SUPPORTED_Asym_Pause); | |
2617 | bp->port.advertising[0] = bp->port.supported[0]; | |
2618 | ||
2619 | bp->link_params.bp = bp; | |
2620 | bp->link_params.port = BP_PORT(bp); | |
2621 | bp->link_params.req_duplex[0] = DUPLEX_FULL; | |
2622 | bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE; | |
2623 | bp->link_params.req_line_speed[0] = SPEED_10000; | |
2624 | bp->link_params.speed_cap_mask[0] = 0x7f0000; | |
2625 | bp->link_params.switch_cfg = SWITCH_CFG_10G; | |
2626 | bp->link_vars.mac_type = MAC_TYPE_BMAC; | |
2627 | bp->link_vars.line_speed = SPEED_10000; | |
2628 | bp->link_vars.link_status = | |
2629 | (LINK_STATUS_LINK_UP | | |
2630 | LINK_STATUS_SPEED_AND_DUPLEX_10GTFD); | |
2631 | bp->link_vars.link_up = 1; | |
2632 | bp->link_vars.duplex = DUPLEX_FULL; | |
2633 | bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE; | |
2634 | __bnx2x_link_report(bp); | |
bb2a0f7a | 2635 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
ad5afc89 | 2636 | } |
a2fbb9ea | 2637 | } |
a2fbb9ea | 2638 | |
a3348722 BW |
2639 | static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid, |
2640 | u16 vlan_val, u8 allowed_prio) | |
2641 | { | |
86564c3f | 2642 | struct bnx2x_func_state_params func_params = {NULL}; |
a3348722 BW |
2643 | struct bnx2x_func_afex_update_params *f_update_params = |
2644 | &func_params.params.afex_update; | |
2645 | ||
2646 | func_params.f_obj = &bp->func_obj; | |
2647 | func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE; | |
2648 | ||
2649 | /* no need to wait for RAMROD completion, so don't | |
2650 | * set RAMROD_COMP_WAIT flag | |
2651 | */ | |
2652 | ||
2653 | f_update_params->vif_id = vifid; | |
2654 | f_update_params->afex_default_vlan = vlan_val; | |
2655 | f_update_params->allowed_priorities = allowed_prio; | |
2656 | ||
2657 | /* if ramrod can not be sent, response to MCP immediately */ | |
2658 | if (bnx2x_func_state_change(bp, &func_params) < 0) | |
2659 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
2660 | ||
2661 | return 0; | |
2662 | } | |
2663 | ||
2664 | static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type, | |
2665 | u16 vif_index, u8 func_bit_map) | |
2666 | { | |
86564c3f | 2667 | struct bnx2x_func_state_params func_params = {NULL}; |
a3348722 BW |
2668 | struct bnx2x_func_afex_viflists_params *update_params = |
2669 | &func_params.params.afex_viflists; | |
2670 | int rc; | |
2671 | u32 drv_msg_code; | |
2672 | ||
2673 | /* validate only LIST_SET and LIST_GET are received from switch */ | |
2674 | if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET)) | |
2675 | BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n", | |
2676 | cmd_type); | |
2677 | ||
2678 | func_params.f_obj = &bp->func_obj; | |
2679 | func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS; | |
2680 | ||
2681 | /* set parameters according to cmd_type */ | |
2682 | update_params->afex_vif_list_command = cmd_type; | |
86564c3f | 2683 | update_params->vif_list_index = vif_index; |
a3348722 BW |
2684 | update_params->func_bit_map = |
2685 | (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map; | |
2686 | update_params->func_to_clear = 0; | |
2687 | drv_msg_code = | |
2688 | (cmd_type == VIF_LIST_RULE_GET) ? | |
2689 | DRV_MSG_CODE_AFEX_LISTGET_ACK : | |
2690 | DRV_MSG_CODE_AFEX_LISTSET_ACK; | |
2691 | ||
2692 | /* if ramrod can not be sent, respond to MCP immediately for | |
2693 | * SET and GET requests (other are not triggered from MCP) | |
2694 | */ | |
2695 | rc = bnx2x_func_state_change(bp, &func_params); | |
2696 | if (rc < 0) | |
2697 | bnx2x_fw_command(bp, drv_msg_code, 0); | |
2698 | ||
2699 | return 0; | |
2700 | } | |
2701 | ||
2702 | static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd) | |
2703 | { | |
2704 | struct afex_stats afex_stats; | |
2705 | u32 func = BP_ABS_FUNC(bp); | |
2706 | u32 mf_config; | |
2707 | u16 vlan_val; | |
2708 | u32 vlan_prio; | |
2709 | u16 vif_id; | |
2710 | u8 allowed_prio; | |
2711 | u8 vlan_mode; | |
2712 | u32 addr_to_write, vifid, addrs, stats_type, i; | |
2713 | ||
2714 | if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) { | |
2715 | vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2716 | DP(BNX2X_MSG_MCP, | |
2717 | "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid); | |
2718 | bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0); | |
2719 | } | |
2720 | ||
2721 | if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) { | |
2722 | vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2723 | addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]); | |
2724 | DP(BNX2X_MSG_MCP, | |
2725 | "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n", | |
2726 | vifid, addrs); | |
2727 | bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid, | |
2728 | addrs); | |
2729 | } | |
2730 | ||
2731 | if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) { | |
2732 | addr_to_write = SHMEM2_RD(bp, | |
2733 | afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]); | |
2734 | stats_type = SHMEM2_RD(bp, | |
2735 | afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2736 | ||
2737 | DP(BNX2X_MSG_MCP, | |
2738 | "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n", | |
2739 | addr_to_write); | |
2740 | ||
2741 | bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type); | |
2742 | ||
2743 | /* write response to scratchpad, for MCP */ | |
2744 | for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++) | |
2745 | REG_WR(bp, addr_to_write + i*sizeof(u32), | |
2746 | *(((u32 *)(&afex_stats))+i)); | |
2747 | ||
2748 | /* send ack message to MCP */ | |
2749 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0); | |
2750 | } | |
2751 | ||
2752 | if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) { | |
2753 | mf_config = MF_CFG_RD(bp, func_mf_config[func].config); | |
2754 | bp->mf_config[BP_VN(bp)] = mf_config; | |
2755 | DP(BNX2X_MSG_MCP, | |
2756 | "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n", | |
2757 | mf_config); | |
2758 | ||
2759 | /* if VIF_SET is "enabled" */ | |
2760 | if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) { | |
2761 | /* set rate limit directly to internal RAM */ | |
2762 | struct cmng_init_input cmng_input; | |
2763 | struct rate_shaping_vars_per_vn m_rs_vn; | |
2764 | size_t size = sizeof(struct rate_shaping_vars_per_vn); | |
2765 | u32 addr = BAR_XSTRORM_INTMEM + | |
2766 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp)); | |
2767 | ||
2768 | bp->mf_config[BP_VN(bp)] = mf_config; | |
2769 | ||
2770 | bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input); | |
2771 | m_rs_vn.vn_counter.rate = | |
2772 | cmng_input.vnic_max_rate[BP_VN(bp)]; | |
2773 | m_rs_vn.vn_counter.quota = | |
2774 | (m_rs_vn.vn_counter.rate * | |
2775 | RS_PERIODIC_TIMEOUT_USEC) / 8; | |
2776 | ||
2777 | __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn); | |
2778 | ||
2779 | /* read relevant values from mf_cfg struct in shmem */ | |
2780 | vif_id = | |
2781 | (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
2782 | FUNC_MF_CFG_E1HOV_TAG_MASK) >> | |
2783 | FUNC_MF_CFG_E1HOV_TAG_SHIFT; | |
2784 | vlan_val = | |
2785 | (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
2786 | FUNC_MF_CFG_AFEX_VLAN_MASK) >> | |
2787 | FUNC_MF_CFG_AFEX_VLAN_SHIFT; | |
2788 | vlan_prio = (mf_config & | |
2789 | FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >> | |
2790 | FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT; | |
2791 | vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT); | |
2792 | vlan_mode = | |
2793 | (MF_CFG_RD(bp, | |
2794 | func_mf_config[func].afex_config) & | |
2795 | FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >> | |
2796 | FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT; | |
2797 | allowed_prio = | |
2798 | (MF_CFG_RD(bp, | |
2799 | func_mf_config[func].afex_config) & | |
2800 | FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >> | |
2801 | FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT; | |
2802 | ||
2803 | /* send ramrod to FW, return in case of failure */ | |
2804 | if (bnx2x_afex_func_update(bp, vif_id, vlan_val, | |
2805 | allowed_prio)) | |
2806 | return; | |
2807 | ||
2808 | bp->afex_def_vlan_tag = vlan_val; | |
2809 | bp->afex_vlan_mode = vlan_mode; | |
2810 | } else { | |
2811 | /* notify link down because BP->flags is disabled */ | |
2812 | bnx2x_link_report(bp); | |
2813 | ||
2814 | /* send INVALID VIF ramrod to FW */ | |
2815 | bnx2x_afex_func_update(bp, 0xFFFF, 0, 0); | |
2816 | ||
2817 | /* Reset the default afex VLAN */ | |
2818 | bp->afex_def_vlan_tag = -1; | |
2819 | } | |
2820 | } | |
2821 | } | |
2822 | ||
34f80b04 EG |
2823 | static void bnx2x_pmf_update(struct bnx2x *bp) |
2824 | { | |
2825 | int port = BP_PORT(bp); | |
2826 | u32 val; | |
2827 | ||
2828 | bp->port.pmf = 1; | |
51c1a580 | 2829 | DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf); |
34f80b04 | 2830 | |
3deb8167 YR |
2831 | /* |
2832 | * We need the mb() to ensure the ordering between the writing to | |
2833 | * bp->port.pmf here and reading it from the bnx2x_periodic_task(). | |
2834 | */ | |
2835 | smp_mb(); | |
2836 | ||
2837 | /* queue a periodic task */ | |
2838 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
2839 | ||
ef01854e DK |
2840 | bnx2x_dcbx_pmf_update(bp); |
2841 | ||
34f80b04 | 2842 | /* enable nig attention */ |
3395a033 | 2843 | val = (0xff0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
2844 | if (bp->common.int_block == INT_BLOCK_HC) { |
2845 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
2846 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
619c5cb6 | 2847 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
2848 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); |
2849 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
2850 | } | |
bb2a0f7a YG |
2851 | |
2852 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); | |
34f80b04 EG |
2853 | } |
2854 | ||
c18487ee | 2855 | /* end of Link */ |
a2fbb9ea ET |
2856 | |
2857 | /* slow path */ | |
2858 | ||
2859 | /* | |
2860 | * General service functions | |
2861 | */ | |
2862 | ||
2691d51d | 2863 | /* send the MCP a request, block until there is a reply */ |
a22f0788 | 2864 | u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param) |
2691d51d | 2865 | { |
f2e0899f | 2866 | int mb_idx = BP_FW_MB_IDX(bp); |
a5971d43 | 2867 | u32 seq; |
2691d51d EG |
2868 | u32 rc = 0; |
2869 | u32 cnt = 1; | |
2870 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; | |
2871 | ||
c4ff7cbf | 2872 | mutex_lock(&bp->fw_mb_mutex); |
a5971d43 | 2873 | seq = ++bp->fw_seq; |
f2e0899f DK |
2874 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param); |
2875 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq)); | |
2876 | ||
754a2f52 DK |
2877 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n", |
2878 | (command | seq), param); | |
2691d51d EG |
2879 | |
2880 | do { | |
2881 | /* let the FW do it's magic ... */ | |
2882 | msleep(delay); | |
2883 | ||
f2e0899f | 2884 | rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header); |
2691d51d | 2885 | |
c4ff7cbf EG |
2886 | /* Give the FW up to 5 second (500*10ms) */ |
2887 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); | |
2691d51d EG |
2888 | |
2889 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", | |
2890 | cnt*delay, rc, seq); | |
2891 | ||
2892 | /* is this a reply to our command? */ | |
2893 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) | |
2894 | rc &= FW_MSG_CODE_MASK; | |
2895 | else { | |
2896 | /* FW BUG! */ | |
2897 | BNX2X_ERR("FW failed to respond!\n"); | |
2898 | bnx2x_fw_dump(bp); | |
2899 | rc = 0; | |
2900 | } | |
c4ff7cbf | 2901 | mutex_unlock(&bp->fw_mb_mutex); |
2691d51d EG |
2902 | |
2903 | return rc; | |
2904 | } | |
2905 | ||
ec6ba945 | 2906 | |
1191cb83 ED |
2907 | static void storm_memset_func_cfg(struct bnx2x *bp, |
2908 | struct tstorm_eth_function_common_config *tcfg, | |
2909 | u16 abs_fid) | |
2910 | { | |
2911 | size_t size = sizeof(struct tstorm_eth_function_common_config); | |
2912 | ||
2913 | u32 addr = BAR_TSTRORM_INTMEM + | |
2914 | TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid); | |
2915 | ||
2916 | __storm_memset_struct(bp, addr, size, (u32 *)tcfg); | |
2917 | } | |
2918 | ||
619c5cb6 VZ |
2919 | void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p) |
2920 | { | |
2921 | if (CHIP_IS_E1x(bp)) { | |
2922 | struct tstorm_eth_function_common_config tcfg = {0}; | |
2923 | ||
2924 | storm_memset_func_cfg(bp, &tcfg, p->func_id); | |
2925 | } | |
2926 | ||
2927 | /* Enable the function in the FW */ | |
2928 | storm_memset_vf_to_pf(bp, p->func_id, p->pf_id); | |
2929 | storm_memset_func_en(bp, p->func_id, 1); | |
2930 | ||
2931 | /* spq */ | |
2932 | if (p->func_flgs & FUNC_FLG_SPQ) { | |
2933 | storm_memset_spq_addr(bp, p->spq_map, p->func_id); | |
2934 | REG_WR(bp, XSEM_REG_FAST_MEMORY + | |
2935 | XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod); | |
2936 | } | |
2937 | } | |
2938 | ||
6383c0b3 AE |
2939 | /** |
2940 | * bnx2x_get_tx_only_flags - Return common flags | |
2941 | * | |
2942 | * @bp device handle | |
2943 | * @fp queue handle | |
2944 | * @zero_stats TRUE if statistics zeroing is needed | |
2945 | * | |
2946 | * Return the flags that are common for the Tx-only and not normal connections. | |
2947 | */ | |
1191cb83 ED |
2948 | static unsigned long bnx2x_get_common_flags(struct bnx2x *bp, |
2949 | struct bnx2x_fastpath *fp, | |
2950 | bool zero_stats) | |
28912902 | 2951 | { |
619c5cb6 VZ |
2952 | unsigned long flags = 0; |
2953 | ||
2954 | /* PF driver will always initialize the Queue to an ACTIVE state */ | |
2955 | __set_bit(BNX2X_Q_FLG_ACTIVE, &flags); | |
28912902 | 2956 | |
6383c0b3 AE |
2957 | /* tx only connections collect statistics (on the same index as the |
2958 | * parent connection). The statistics are zeroed when the parent | |
2959 | * connection is initialized. | |
2960 | */ | |
50f0a562 BW |
2961 | |
2962 | __set_bit(BNX2X_Q_FLG_STATS, &flags); | |
2963 | if (zero_stats) | |
2964 | __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags); | |
2965 | ||
6383c0b3 | 2966 | |
823e1d90 YM |
2967 | #ifdef BNX2X_STOP_ON_ERROR |
2968 | __set_bit(BNX2X_Q_FLG_TX_SEC, &flags); | |
2969 | #endif | |
2970 | ||
6383c0b3 AE |
2971 | return flags; |
2972 | } | |
2973 | ||
1191cb83 ED |
2974 | static unsigned long bnx2x_get_q_flags(struct bnx2x *bp, |
2975 | struct bnx2x_fastpath *fp, | |
2976 | bool leading) | |
6383c0b3 AE |
2977 | { |
2978 | unsigned long flags = 0; | |
2979 | ||
619c5cb6 VZ |
2980 | /* calculate other queue flags */ |
2981 | if (IS_MF_SD(bp)) | |
2982 | __set_bit(BNX2X_Q_FLG_OV, &flags); | |
28912902 | 2983 | |
a3348722 | 2984 | if (IS_FCOE_FP(fp)) { |
619c5cb6 | 2985 | __set_bit(BNX2X_Q_FLG_FCOE, &flags); |
a3348722 BW |
2986 | /* For FCoE - force usage of default priority (for afex) */ |
2987 | __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags); | |
2988 | } | |
523224a3 | 2989 | |
f5219d8e | 2990 | if (!fp->disable_tpa) { |
619c5cb6 | 2991 | __set_bit(BNX2X_Q_FLG_TPA, &flags); |
f5219d8e | 2992 | __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags); |
621b4d66 DK |
2993 | if (fp->mode == TPA_MODE_GRO) |
2994 | __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags); | |
f5219d8e | 2995 | } |
619c5cb6 | 2996 | |
619c5cb6 VZ |
2997 | if (leading) { |
2998 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags); | |
2999 | __set_bit(BNX2X_Q_FLG_MCAST, &flags); | |
3000 | } | |
523224a3 | 3001 | |
619c5cb6 VZ |
3002 | /* Always set HW VLAN stripping */ |
3003 | __set_bit(BNX2X_Q_FLG_VLAN, &flags); | |
523224a3 | 3004 | |
a3348722 BW |
3005 | /* configure silent vlan removal */ |
3006 | if (IS_MF_AFEX(bp)) | |
3007 | __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags); | |
3008 | ||
6383c0b3 AE |
3009 | |
3010 | return flags | bnx2x_get_common_flags(bp, fp, true); | |
523224a3 DK |
3011 | } |
3012 | ||
619c5cb6 | 3013 | static void bnx2x_pf_q_prep_general(struct bnx2x *bp, |
6383c0b3 AE |
3014 | struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init, |
3015 | u8 cos) | |
619c5cb6 VZ |
3016 | { |
3017 | gen_init->stat_id = bnx2x_stats_id(fp); | |
3018 | gen_init->spcl_id = fp->cl_id; | |
3019 | ||
3020 | /* Always use mini-jumbo MTU for FCoE L2 ring */ | |
3021 | if (IS_FCOE_FP(fp)) | |
3022 | gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU; | |
3023 | else | |
3024 | gen_init->mtu = bp->dev->mtu; | |
6383c0b3 AE |
3025 | |
3026 | gen_init->cos = cos; | |
619c5cb6 VZ |
3027 | } |
3028 | ||
3029 | static void bnx2x_pf_rx_q_prep(struct bnx2x *bp, | |
523224a3 | 3030 | struct bnx2x_fastpath *fp, struct rxq_pause_params *pause, |
619c5cb6 | 3031 | struct bnx2x_rxq_setup_params *rxq_init) |
523224a3 | 3032 | { |
619c5cb6 | 3033 | u8 max_sge = 0; |
523224a3 DK |
3034 | u16 sge_sz = 0; |
3035 | u16 tpa_agg_size = 0; | |
3036 | ||
523224a3 | 3037 | if (!fp->disable_tpa) { |
dfacf138 DK |
3038 | pause->sge_th_lo = SGE_TH_LO(bp); |
3039 | pause->sge_th_hi = SGE_TH_HI(bp); | |
3040 | ||
3041 | /* validate SGE ring has enough to cross high threshold */ | |
3042 | WARN_ON(bp->dropless_fc && | |
3043 | pause->sge_th_hi + FW_PREFETCH_CNT > | |
3044 | MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES); | |
3045 | ||
924d75ab | 3046 | tpa_agg_size = TPA_AGG_SIZE; |
523224a3 DK |
3047 | max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >> |
3048 | SGE_PAGE_SHIFT; | |
3049 | max_sge = ((max_sge + PAGES_PER_SGE - 1) & | |
3050 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; | |
924d75ab | 3051 | sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff); |
523224a3 DK |
3052 | } |
3053 | ||
3054 | /* pause - not for e1 */ | |
3055 | if (!CHIP_IS_E1(bp)) { | |
dfacf138 DK |
3056 | pause->bd_th_lo = BD_TH_LO(bp); |
3057 | pause->bd_th_hi = BD_TH_HI(bp); | |
3058 | ||
3059 | pause->rcq_th_lo = RCQ_TH_LO(bp); | |
3060 | pause->rcq_th_hi = RCQ_TH_HI(bp); | |
3061 | /* | |
3062 | * validate that rings have enough entries to cross | |
3063 | * high thresholds | |
3064 | */ | |
3065 | WARN_ON(bp->dropless_fc && | |
3066 | pause->bd_th_hi + FW_PREFETCH_CNT > | |
3067 | bp->rx_ring_size); | |
3068 | WARN_ON(bp->dropless_fc && | |
3069 | pause->rcq_th_hi + FW_PREFETCH_CNT > | |
3070 | NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT); | |
619c5cb6 | 3071 | |
523224a3 DK |
3072 | pause->pri_map = 1; |
3073 | } | |
3074 | ||
3075 | /* rxq setup */ | |
523224a3 DK |
3076 | rxq_init->dscr_map = fp->rx_desc_mapping; |
3077 | rxq_init->sge_map = fp->rx_sge_mapping; | |
3078 | rxq_init->rcq_map = fp->rx_comp_mapping; | |
3079 | rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE; | |
a8c94b91 | 3080 | |
619c5cb6 VZ |
3081 | /* This should be a maximum number of data bytes that may be |
3082 | * placed on the BD (not including paddings). | |
3083 | */ | |
e52fcb24 ED |
3084 | rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START - |
3085 | BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING; | |
a8c94b91 | 3086 | |
523224a3 | 3087 | rxq_init->cl_qzone_id = fp->cl_qzone_id; |
523224a3 DK |
3088 | rxq_init->tpa_agg_sz = tpa_agg_size; |
3089 | rxq_init->sge_buf_sz = sge_sz; | |
3090 | rxq_init->max_sges_pkt = max_sge; | |
619c5cb6 | 3091 | rxq_init->rss_engine_id = BP_FUNC(bp); |
259afa1f | 3092 | rxq_init->mcast_engine_id = BP_FUNC(bp); |
619c5cb6 VZ |
3093 | |
3094 | /* Maximum number or simultaneous TPA aggregation for this Queue. | |
3095 | * | |
2de67439 | 3096 | * For PF Clients it should be the maximum available number. |
619c5cb6 VZ |
3097 | * VF driver(s) may want to define it to a smaller value. |
3098 | */ | |
dfacf138 | 3099 | rxq_init->max_tpa_queues = MAX_AGG_QS(bp); |
619c5cb6 | 3100 | |
523224a3 DK |
3101 | rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
3102 | rxq_init->fw_sb_id = fp->fw_sb_id; | |
3103 | ||
ec6ba945 VZ |
3104 | if (IS_FCOE_FP(fp)) |
3105 | rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS; | |
3106 | else | |
6383c0b3 | 3107 | rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
a3348722 BW |
3108 | /* configure silent vlan removal |
3109 | * if multi function mode is afex, then mask default vlan | |
3110 | */ | |
3111 | if (IS_MF_AFEX(bp)) { | |
3112 | rxq_init->silent_removal_value = bp->afex_def_vlan_tag; | |
3113 | rxq_init->silent_removal_mask = VLAN_VID_MASK; | |
3114 | } | |
523224a3 DK |
3115 | } |
3116 | ||
619c5cb6 | 3117 | static void bnx2x_pf_tx_q_prep(struct bnx2x *bp, |
6383c0b3 AE |
3118 | struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init, |
3119 | u8 cos) | |
523224a3 | 3120 | { |
65565884 | 3121 | txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping; |
6383c0b3 | 3122 | txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos; |
523224a3 DK |
3123 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; |
3124 | txq_init->fw_sb_id = fp->fw_sb_id; | |
ec6ba945 | 3125 | |
619c5cb6 VZ |
3126 | /* |
3127 | * set the tss leading client id for TX classfication == | |
3128 | * leading RSS client id | |
3129 | */ | |
3130 | txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id); | |
3131 | ||
ec6ba945 VZ |
3132 | if (IS_FCOE_FP(fp)) { |
3133 | txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS; | |
3134 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE; | |
3135 | } | |
523224a3 DK |
3136 | } |
3137 | ||
8d96286a | 3138 | static void bnx2x_pf_init(struct bnx2x *bp) |
523224a3 DK |
3139 | { |
3140 | struct bnx2x_func_init_params func_init = {0}; | |
523224a3 DK |
3141 | struct event_ring_data eq_data = { {0} }; |
3142 | u16 flags; | |
3143 | ||
619c5cb6 | 3144 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
3145 | /* reset IGU PF statistics: MSIX + ATTN */ |
3146 | /* PF */ | |
3147 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
3148 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
3149 | (CHIP_MODE_IS_4_PORT(bp) ? | |
3150 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
3151 | /* ATTN */ | |
3152 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
3153 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
3154 | BNX2X_IGU_STAS_MSG_PF_CNT*4 + | |
3155 | (CHIP_MODE_IS_4_PORT(bp) ? | |
3156 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
3157 | } | |
3158 | ||
523224a3 DK |
3159 | /* function setup flags */ |
3160 | flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); | |
3161 | ||
619c5cb6 VZ |
3162 | /* This flag is relevant for E1x only. |
3163 | * E2 doesn't have a TPA configuration in a function level. | |
523224a3 | 3164 | */ |
619c5cb6 | 3165 | flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; |
523224a3 DK |
3166 | |
3167 | func_init.func_flgs = flags; | |
3168 | func_init.pf_id = BP_FUNC(bp); | |
3169 | func_init.func_id = BP_FUNC(bp); | |
523224a3 DK |
3170 | func_init.spq_map = bp->spq_mapping; |
3171 | func_init.spq_prod = bp->spq_prod_idx; | |
3172 | ||
3173 | bnx2x_func_init(bp, &func_init); | |
3174 | ||
3175 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); | |
3176 | ||
3177 | /* | |
619c5cb6 VZ |
3178 | * Congestion management values depend on the link rate |
3179 | * There is no active link so initial link rate is set to 10 Gbps. | |
3180 | * When the link comes up The congestion management values are | |
3181 | * re-calculated according to the actual link rate. | |
3182 | */ | |
523224a3 DK |
3183 | bp->link_vars.line_speed = SPEED_10000; |
3184 | bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp)); | |
3185 | ||
3186 | /* Only the PMF sets the HW */ | |
3187 | if (bp->port.pmf) | |
3188 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
3189 | ||
86564c3f | 3190 | /* init Event Queue - PCI bus guarantees correct endianity*/ |
523224a3 DK |
3191 | eq_data.base_addr.hi = U64_HI(bp->eq_mapping); |
3192 | eq_data.base_addr.lo = U64_LO(bp->eq_mapping); | |
3193 | eq_data.producer = bp->eq_prod; | |
3194 | eq_data.index_id = HC_SP_INDEX_EQ_CONS; | |
3195 | eq_data.sb_id = DEF_SB_ID; | |
3196 | storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp)); | |
3197 | } | |
3198 | ||
3199 | ||
3200 | static void bnx2x_e1h_disable(struct bnx2x *bp) | |
3201 | { | |
3202 | int port = BP_PORT(bp); | |
3203 | ||
619c5cb6 | 3204 | bnx2x_tx_disable(bp); |
523224a3 DK |
3205 | |
3206 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
523224a3 DK |
3207 | } |
3208 | ||
3209 | static void bnx2x_e1h_enable(struct bnx2x *bp) | |
3210 | { | |
3211 | int port = BP_PORT(bp); | |
3212 | ||
3213 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); | |
3214 | ||
3215 | /* Tx queue should be only reenabled */ | |
3216 | netif_tx_wake_all_queues(bp->dev); | |
3217 | ||
3218 | /* | |
3219 | * Should not call netif_carrier_on since it will be called if the link | |
3220 | * is up when checking for link state | |
3221 | */ | |
3222 | } | |
3223 | ||
1d187b34 BW |
3224 | #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3 |
3225 | ||
3226 | static void bnx2x_drv_info_ether_stat(struct bnx2x *bp) | |
3227 | { | |
3228 | struct eth_stats_info *ether_stat = | |
3229 | &bp->slowpath->drv_info_to_mcp.ether_stat; | |
3230 | ||
786fdf0b DC |
3231 | strlcpy(ether_stat->version, DRV_MODULE_VERSION, |
3232 | ETH_STAT_INFO_VERSION_LEN); | |
1d187b34 | 3233 | |
15192a8c BW |
3234 | bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj, |
3235 | DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED, | |
3236 | ether_stat->mac_local); | |
1d187b34 BW |
3237 | |
3238 | ether_stat->mtu_size = bp->dev->mtu; | |
3239 | ||
3240 | if (bp->dev->features & NETIF_F_RXCSUM) | |
3241 | ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK; | |
3242 | if (bp->dev->features & NETIF_F_TSO) | |
3243 | ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK; | |
3244 | ether_stat->feature_flags |= bp->common.boot_mode; | |
3245 | ||
3246 | ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0; | |
3247 | ||
3248 | ether_stat->txq_size = bp->tx_ring_size; | |
3249 | ether_stat->rxq_size = bp->rx_ring_size; | |
3250 | } | |
3251 | ||
3252 | static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp) | |
3253 | { | |
3254 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; | |
3255 | struct fcoe_stats_info *fcoe_stat = | |
3256 | &bp->slowpath->drv_info_to_mcp.fcoe_stat; | |
3257 | ||
55c11941 MS |
3258 | if (!CNIC_LOADED(bp)) |
3259 | return; | |
3260 | ||
2e499d3c BW |
3261 | memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT, |
3262 | bp->fip_mac, ETH_ALEN); | |
1d187b34 BW |
3263 | |
3264 | fcoe_stat->qos_priority = | |
3265 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE]; | |
3266 | ||
3267 | /* insert FCoE stats from ramrod response */ | |
3268 | if (!NO_FCOE(bp)) { | |
3269 | struct tstorm_per_queue_stats *fcoe_q_tstorm_stats = | |
65565884 | 3270 | &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)]. |
1d187b34 BW |
3271 | tstorm_queue_statistics; |
3272 | ||
3273 | struct xstorm_per_queue_stats *fcoe_q_xstorm_stats = | |
65565884 | 3274 | &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)]. |
1d187b34 BW |
3275 | xstorm_queue_statistics; |
3276 | ||
3277 | struct fcoe_statistics_params *fw_fcoe_stat = | |
3278 | &bp->fw_stats_data->fcoe; | |
3279 | ||
86564c3f YM |
3280 | ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0, |
3281 | fcoe_stat->rx_bytes_lo, | |
3282 | fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt); | |
1d187b34 | 3283 | |
86564c3f YM |
3284 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3285 | fcoe_q_tstorm_stats->rcv_ucast_bytes.hi, | |
3286 | fcoe_stat->rx_bytes_lo, | |
3287 | fcoe_q_tstorm_stats->rcv_ucast_bytes.lo); | |
1d187b34 | 3288 | |
86564c3f YM |
3289 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3290 | fcoe_q_tstorm_stats->rcv_bcast_bytes.hi, | |
3291 | fcoe_stat->rx_bytes_lo, | |
3292 | fcoe_q_tstorm_stats->rcv_bcast_bytes.lo); | |
1d187b34 | 3293 | |
86564c3f YM |
3294 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3295 | fcoe_q_tstorm_stats->rcv_mcast_bytes.hi, | |
3296 | fcoe_stat->rx_bytes_lo, | |
3297 | fcoe_q_tstorm_stats->rcv_mcast_bytes.lo); | |
1d187b34 | 3298 | |
86564c3f YM |
3299 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3300 | fcoe_stat->rx_frames_lo, | |
3301 | fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt); | |
1d187b34 | 3302 | |
86564c3f YM |
3303 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3304 | fcoe_stat->rx_frames_lo, | |
3305 | fcoe_q_tstorm_stats->rcv_ucast_pkts); | |
1d187b34 | 3306 | |
86564c3f YM |
3307 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3308 | fcoe_stat->rx_frames_lo, | |
3309 | fcoe_q_tstorm_stats->rcv_bcast_pkts); | |
1d187b34 | 3310 | |
86564c3f YM |
3311 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3312 | fcoe_stat->rx_frames_lo, | |
3313 | fcoe_q_tstorm_stats->rcv_mcast_pkts); | |
1d187b34 | 3314 | |
86564c3f YM |
3315 | ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0, |
3316 | fcoe_stat->tx_bytes_lo, | |
3317 | fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt); | |
1d187b34 | 3318 | |
86564c3f YM |
3319 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3320 | fcoe_q_xstorm_stats->ucast_bytes_sent.hi, | |
3321 | fcoe_stat->tx_bytes_lo, | |
3322 | fcoe_q_xstorm_stats->ucast_bytes_sent.lo); | |
1d187b34 | 3323 | |
86564c3f YM |
3324 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3325 | fcoe_q_xstorm_stats->bcast_bytes_sent.hi, | |
3326 | fcoe_stat->tx_bytes_lo, | |
3327 | fcoe_q_xstorm_stats->bcast_bytes_sent.lo); | |
1d187b34 | 3328 | |
86564c3f YM |
3329 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3330 | fcoe_q_xstorm_stats->mcast_bytes_sent.hi, | |
3331 | fcoe_stat->tx_bytes_lo, | |
3332 | fcoe_q_xstorm_stats->mcast_bytes_sent.lo); | |
1d187b34 | 3333 | |
86564c3f YM |
3334 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3335 | fcoe_stat->tx_frames_lo, | |
3336 | fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt); | |
1d187b34 | 3337 | |
86564c3f YM |
3338 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3339 | fcoe_stat->tx_frames_lo, | |
3340 | fcoe_q_xstorm_stats->ucast_pkts_sent); | |
1d187b34 | 3341 | |
86564c3f YM |
3342 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3343 | fcoe_stat->tx_frames_lo, | |
3344 | fcoe_q_xstorm_stats->bcast_pkts_sent); | |
1d187b34 | 3345 | |
86564c3f YM |
3346 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3347 | fcoe_stat->tx_frames_lo, | |
3348 | fcoe_q_xstorm_stats->mcast_pkts_sent); | |
1d187b34 BW |
3349 | } |
3350 | ||
1d187b34 BW |
3351 | /* ask L5 driver to add data to the struct */ |
3352 | bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD); | |
1d187b34 BW |
3353 | } |
3354 | ||
3355 | static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp) | |
3356 | { | |
3357 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; | |
3358 | struct iscsi_stats_info *iscsi_stat = | |
3359 | &bp->slowpath->drv_info_to_mcp.iscsi_stat; | |
3360 | ||
55c11941 MS |
3361 | if (!CNIC_LOADED(bp)) |
3362 | return; | |
3363 | ||
2e499d3c BW |
3364 | memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT, |
3365 | bp->cnic_eth_dev.iscsi_mac, ETH_ALEN); | |
1d187b34 BW |
3366 | |
3367 | iscsi_stat->qos_priority = | |
3368 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI]; | |
3369 | ||
1d187b34 BW |
3370 | /* ask L5 driver to add data to the struct */ |
3371 | bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD); | |
1d187b34 BW |
3372 | } |
3373 | ||
0793f83f DK |
3374 | /* called due to MCP event (on pmf): |
3375 | * reread new bandwidth configuration | |
3376 | * configure FW | |
3377 | * notify others function about the change | |
3378 | */ | |
1191cb83 | 3379 | static void bnx2x_config_mf_bw(struct bnx2x *bp) |
0793f83f DK |
3380 | { |
3381 | if (bp->link_vars.link_up) { | |
3382 | bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX); | |
3383 | bnx2x_link_sync_notify(bp); | |
3384 | } | |
3385 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
3386 | } | |
3387 | ||
1191cb83 | 3388 | static void bnx2x_set_mf_bw(struct bnx2x *bp) |
0793f83f DK |
3389 | { |
3390 | bnx2x_config_mf_bw(bp); | |
3391 | bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0); | |
3392 | } | |
3393 | ||
c8c60d88 YM |
3394 | static void bnx2x_handle_eee_event(struct bnx2x *bp) |
3395 | { | |
3396 | DP(BNX2X_MSG_MCP, "EEE - LLDP event\n"); | |
3397 | bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0); | |
3398 | } | |
3399 | ||
1d187b34 BW |
3400 | static void bnx2x_handle_drv_info_req(struct bnx2x *bp) |
3401 | { | |
3402 | enum drv_info_opcode op_code; | |
3403 | u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control); | |
3404 | ||
3405 | /* if drv_info version supported by MFW doesn't match - send NACK */ | |
3406 | if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) { | |
3407 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3408 | return; | |
3409 | } | |
3410 | ||
3411 | op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >> | |
3412 | DRV_INFO_CONTROL_OP_CODE_SHIFT; | |
3413 | ||
3414 | memset(&bp->slowpath->drv_info_to_mcp, 0, | |
3415 | sizeof(union drv_info_to_mcp)); | |
3416 | ||
3417 | switch (op_code) { | |
3418 | case ETH_STATS_OPCODE: | |
3419 | bnx2x_drv_info_ether_stat(bp); | |
3420 | break; | |
3421 | case FCOE_STATS_OPCODE: | |
3422 | bnx2x_drv_info_fcoe_stat(bp); | |
3423 | break; | |
3424 | case ISCSI_STATS_OPCODE: | |
3425 | bnx2x_drv_info_iscsi_stat(bp); | |
3426 | break; | |
3427 | default: | |
3428 | /* if op code isn't supported - send NACK */ | |
3429 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3430 | return; | |
3431 | } | |
3432 | ||
3433 | /* if we got drv_info attn from MFW then these fields are defined in | |
3434 | * shmem2 for sure | |
3435 | */ | |
3436 | SHMEM2_WR(bp, drv_info_host_addr_lo, | |
3437 | U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3438 | SHMEM2_WR(bp, drv_info_host_addr_hi, | |
3439 | U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3440 | ||
3441 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0); | |
3442 | } | |
3443 | ||
523224a3 DK |
3444 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
3445 | { | |
3446 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); | |
3447 | ||
3448 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { | |
3449 | ||
3450 | /* | |
3451 | * This is the only place besides the function initialization | |
3452 | * where the bp->flags can change so it is done without any | |
3453 | * locks | |
3454 | */ | |
f2e0899f | 3455 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
51c1a580 | 3456 | DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n"); |
523224a3 DK |
3457 | bp->flags |= MF_FUNC_DIS; |
3458 | ||
3459 | bnx2x_e1h_disable(bp); | |
3460 | } else { | |
51c1a580 | 3461 | DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n"); |
523224a3 DK |
3462 | bp->flags &= ~MF_FUNC_DIS; |
3463 | ||
3464 | bnx2x_e1h_enable(bp); | |
3465 | } | |
3466 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; | |
3467 | } | |
3468 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { | |
0793f83f | 3469 | bnx2x_config_mf_bw(bp); |
523224a3 DK |
3470 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
3471 | } | |
3472 | ||
3473 | /* Report results to MCP */ | |
3474 | if (dcc_event) | |
3475 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0); | |
3476 | else | |
3477 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0); | |
3478 | } | |
3479 | ||
3480 | /* must be called under the spq lock */ | |
1191cb83 | 3481 | static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp) |
523224a3 DK |
3482 | { |
3483 | struct eth_spe *next_spe = bp->spq_prod_bd; | |
3484 | ||
3485 | if (bp->spq_prod_bd == bp->spq_last_bd) { | |
3486 | bp->spq_prod_bd = bp->spq; | |
3487 | bp->spq_prod_idx = 0; | |
51c1a580 | 3488 | DP(BNX2X_MSG_SP, "end of spq\n"); |
523224a3 DK |
3489 | } else { |
3490 | bp->spq_prod_bd++; | |
3491 | bp->spq_prod_idx++; | |
3492 | } | |
3493 | return next_spe; | |
3494 | } | |
3495 | ||
3496 | /* must be called under the spq lock */ | |
1191cb83 | 3497 | static void bnx2x_sp_prod_update(struct bnx2x *bp) |
28912902 MC |
3498 | { |
3499 | int func = BP_FUNC(bp); | |
3500 | ||
53e51e2f VZ |
3501 | /* |
3502 | * Make sure that BD data is updated before writing the producer: | |
3503 | * BD data is written to the memory, the producer is read from the | |
3504 | * memory, thus we need a full memory barrier to ensure the ordering. | |
3505 | */ | |
3506 | mb(); | |
28912902 | 3507 | |
523224a3 | 3508 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
f85582f8 | 3509 | bp->spq_prod_idx); |
28912902 MC |
3510 | mmiowb(); |
3511 | } | |
3512 | ||
619c5cb6 VZ |
3513 | /** |
3514 | * bnx2x_is_contextless_ramrod - check if the current command ends on EQ | |
3515 | * | |
3516 | * @cmd: command to check | |
3517 | * @cmd_type: command type | |
3518 | */ | |
1191cb83 | 3519 | static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type) |
619c5cb6 VZ |
3520 | { |
3521 | if ((cmd_type == NONE_CONNECTION_TYPE) || | |
6383c0b3 | 3522 | (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) || |
619c5cb6 VZ |
3523 | (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || |
3524 | (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || | |
3525 | (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || | |
3526 | (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || | |
3527 | (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) | |
3528 | return true; | |
3529 | else | |
3530 | return false; | |
3531 | ||
3532 | } | |
3533 | ||
3534 | ||
3535 | /** | |
3536 | * bnx2x_sp_post - place a single command on an SP ring | |
3537 | * | |
3538 | * @bp: driver handle | |
3539 | * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) | |
3540 | * @cid: SW CID the command is related to | |
3541 | * @data_hi: command private data address (high 32 bits) | |
3542 | * @data_lo: command private data address (low 32 bits) | |
3543 | * @cmd_type: command type (e.g. NONE, ETH) | |
3544 | * | |
3545 | * SP data is handled as if it's always an address pair, thus data fields are | |
3546 | * not swapped to little endian in upper functions. Instead this function swaps | |
3547 | * data as if it's two u32 fields. | |
3548 | */ | |
9f6c9258 | 3549 | int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
619c5cb6 | 3550 | u32 data_hi, u32 data_lo, int cmd_type) |
a2fbb9ea | 3551 | { |
28912902 | 3552 | struct eth_spe *spe; |
523224a3 | 3553 | u16 type; |
619c5cb6 | 3554 | bool common = bnx2x_is_contextless_ramrod(command, cmd_type); |
a2fbb9ea | 3555 | |
a2fbb9ea | 3556 | #ifdef BNX2X_STOP_ON_ERROR |
51c1a580 MS |
3557 | if (unlikely(bp->panic)) { |
3558 | BNX2X_ERR("Can't post SP when there is panic\n"); | |
a2fbb9ea | 3559 | return -EIO; |
51c1a580 | 3560 | } |
a2fbb9ea ET |
3561 | #endif |
3562 | ||
34f80b04 | 3563 | spin_lock_bh(&bp->spq_lock); |
a2fbb9ea | 3564 | |
6e30dd4e VZ |
3565 | if (common) { |
3566 | if (!atomic_read(&bp->eq_spq_left)) { | |
3567 | BNX2X_ERR("BUG! EQ ring full!\n"); | |
3568 | spin_unlock_bh(&bp->spq_lock); | |
3569 | bnx2x_panic(); | |
3570 | return -EBUSY; | |
3571 | } | |
3572 | } else if (!atomic_read(&bp->cq_spq_left)) { | |
3573 | BNX2X_ERR("BUG! SPQ ring full!\n"); | |
3574 | spin_unlock_bh(&bp->spq_lock); | |
3575 | bnx2x_panic(); | |
3576 | return -EBUSY; | |
a2fbb9ea | 3577 | } |
f1410647 | 3578 | |
28912902 MC |
3579 | spe = bnx2x_sp_get_next(bp); |
3580 | ||
a2fbb9ea | 3581 | /* CID needs port number to be encoded int it */ |
28912902 | 3582 | spe->hdr.conn_and_cmd_data = |
cdaa7cb8 VZ |
3583 | cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) | |
3584 | HW_CID(bp, cid)); | |
523224a3 | 3585 | |
619c5cb6 | 3586 | type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE; |
a2fbb9ea | 3587 | |
523224a3 DK |
3588 | type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) & |
3589 | SPE_HDR_FUNCTION_ID); | |
a2fbb9ea | 3590 | |
523224a3 DK |
3591 | spe->hdr.type = cpu_to_le16(type); |
3592 | ||
3593 | spe->data.update_data_addr.hi = cpu_to_le32(data_hi); | |
3594 | spe->data.update_data_addr.lo = cpu_to_le32(data_lo); | |
3595 | ||
d6cae238 VZ |
3596 | /* |
3597 | * It's ok if the actual decrement is issued towards the memory | |
3598 | * somewhere between the spin_lock and spin_unlock. Thus no | |
3599 | * more explict memory barrier is needed. | |
3600 | */ | |
3601 | if (common) | |
3602 | atomic_dec(&bp->eq_spq_left); | |
3603 | else | |
3604 | atomic_dec(&bp->cq_spq_left); | |
6e30dd4e | 3605 | |
a2fbb9ea | 3606 | |
51c1a580 MS |
3607 | DP(BNX2X_MSG_SP, |
3608 | "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n", | |
cdaa7cb8 VZ |
3609 | bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping), |
3610 | (u32)(U64_LO(bp->spq_mapping) + | |
d6cae238 | 3611 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, common, |
6e30dd4e VZ |
3612 | HW_CID(bp, cid), data_hi, data_lo, type, |
3613 | atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left)); | |
cdaa7cb8 | 3614 | |
28912902 | 3615 | bnx2x_sp_prod_update(bp); |
34f80b04 | 3616 | spin_unlock_bh(&bp->spq_lock); |
a2fbb9ea ET |
3617 | return 0; |
3618 | } | |
3619 | ||
3620 | /* acquire split MCP access lock register */ | |
4a37fb66 | 3621 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
a2fbb9ea | 3622 | { |
72fd0718 | 3623 | u32 j, val; |
34f80b04 | 3624 | int rc = 0; |
a2fbb9ea ET |
3625 | |
3626 | might_sleep(); | |
72fd0718 | 3627 | for (j = 0; j < 1000; j++) { |
a2fbb9ea ET |
3628 | val = (1UL << 31); |
3629 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); | |
3630 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); | |
3631 | if (val & (1L << 31)) | |
3632 | break; | |
3633 | ||
3634 | msleep(5); | |
3635 | } | |
a2fbb9ea | 3636 | if (!(val & (1L << 31))) { |
19680c48 | 3637 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
a2fbb9ea ET |
3638 | rc = -EBUSY; |
3639 | } | |
3640 | ||
3641 | return rc; | |
3642 | } | |
3643 | ||
4a37fb66 YG |
3644 | /* release split MCP access lock register */ |
3645 | static void bnx2x_release_alr(struct bnx2x *bp) | |
a2fbb9ea | 3646 | { |
72fd0718 | 3647 | REG_WR(bp, GRCBASE_MCP + 0x9c, 0); |
a2fbb9ea ET |
3648 | } |
3649 | ||
523224a3 DK |
3650 | #define BNX2X_DEF_SB_ATT_IDX 0x0001 |
3651 | #define BNX2X_DEF_SB_IDX 0x0002 | |
3652 | ||
1191cb83 | 3653 | static u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
a2fbb9ea | 3654 | { |
523224a3 | 3655 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
a2fbb9ea ET |
3656 | u16 rc = 0; |
3657 | ||
3658 | barrier(); /* status block is written to by the chip */ | |
a2fbb9ea ET |
3659 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
3660 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; | |
523224a3 | 3661 | rc |= BNX2X_DEF_SB_ATT_IDX; |
a2fbb9ea | 3662 | } |
523224a3 DK |
3663 | |
3664 | if (bp->def_idx != def_sb->sp_sb.running_index) { | |
3665 | bp->def_idx = def_sb->sp_sb.running_index; | |
3666 | rc |= BNX2X_DEF_SB_IDX; | |
a2fbb9ea | 3667 | } |
523224a3 DK |
3668 | |
3669 | /* Do not reorder: indecies reading should complete before handling */ | |
3670 | barrier(); | |
a2fbb9ea ET |
3671 | return rc; |
3672 | } | |
3673 | ||
3674 | /* | |
3675 | * slow path service functions | |
3676 | */ | |
3677 | ||
3678 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) | |
3679 | { | |
34f80b04 | 3680 | int port = BP_PORT(bp); |
a2fbb9ea ET |
3681 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
3682 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
877e9aa4 ET |
3683 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
3684 | NIG_REG_MASK_INTERRUPT_PORT0; | |
3fcaf2e5 | 3685 | u32 aeu_mask; |
87942b46 | 3686 | u32 nig_mask = 0; |
f2e0899f | 3687 | u32 reg_addr; |
a2fbb9ea | 3688 | |
a2fbb9ea ET |
3689 | if (bp->attn_state & asserted) |
3690 | BNX2X_ERR("IGU ERROR\n"); | |
3691 | ||
3fcaf2e5 EG |
3692 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
3693 | aeu_mask = REG_RD(bp, aeu_addr); | |
3694 | ||
a2fbb9ea | 3695 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
3fcaf2e5 | 3696 | aeu_mask, asserted); |
72fd0718 | 3697 | aeu_mask &= ~(asserted & 0x3ff); |
3fcaf2e5 | 3698 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 3699 | |
3fcaf2e5 EG |
3700 | REG_WR(bp, aeu_addr, aeu_mask); |
3701 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea | 3702 | |
3fcaf2e5 | 3703 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
a2fbb9ea | 3704 | bp->attn_state |= asserted; |
3fcaf2e5 | 3705 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
a2fbb9ea ET |
3706 | |
3707 | if (asserted & ATTN_HARD_WIRED_MASK) { | |
3708 | if (asserted & ATTN_NIG_FOR_FUNC) { | |
a2fbb9ea | 3709 | |
a5e9a7cf EG |
3710 | bnx2x_acquire_phy_lock(bp); |
3711 | ||
877e9aa4 | 3712 | /* save nig interrupt mask */ |
87942b46 | 3713 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
a2fbb9ea | 3714 | |
361c391e YR |
3715 | /* If nig_mask is not set, no need to call the update |
3716 | * function. | |
3717 | */ | |
3718 | if (nig_mask) { | |
3719 | REG_WR(bp, nig_int_mask_addr, 0); | |
3720 | ||
3721 | bnx2x_link_attn(bp); | |
3722 | } | |
a2fbb9ea ET |
3723 | |
3724 | /* handle unicore attn? */ | |
3725 | } | |
3726 | if (asserted & ATTN_SW_TIMER_4_FUNC) | |
3727 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); | |
3728 | ||
3729 | if (asserted & GPIO_2_FUNC) | |
3730 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); | |
3731 | ||
3732 | if (asserted & GPIO_3_FUNC) | |
3733 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); | |
3734 | ||
3735 | if (asserted & GPIO_4_FUNC) | |
3736 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); | |
3737 | ||
3738 | if (port == 0) { | |
3739 | if (asserted & ATTN_GENERAL_ATTN_1) { | |
3740 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); | |
3741 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); | |
3742 | } | |
3743 | if (asserted & ATTN_GENERAL_ATTN_2) { | |
3744 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); | |
3745 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); | |
3746 | } | |
3747 | if (asserted & ATTN_GENERAL_ATTN_3) { | |
3748 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); | |
3749 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); | |
3750 | } | |
3751 | } else { | |
3752 | if (asserted & ATTN_GENERAL_ATTN_4) { | |
3753 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); | |
3754 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); | |
3755 | } | |
3756 | if (asserted & ATTN_GENERAL_ATTN_5) { | |
3757 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); | |
3758 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); | |
3759 | } | |
3760 | if (asserted & ATTN_GENERAL_ATTN_6) { | |
3761 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); | |
3762 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); | |
3763 | } | |
3764 | } | |
3765 | ||
3766 | } /* if hardwired */ | |
3767 | ||
f2e0899f DK |
3768 | if (bp->common.int_block == INT_BLOCK_HC) |
3769 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
3770 | COMMAND_REG_ATTN_BITS_SET); | |
3771 | else | |
3772 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); | |
3773 | ||
3774 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted, | |
3775 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
3776 | REG_WR(bp, reg_addr, asserted); | |
a2fbb9ea ET |
3777 | |
3778 | /* now set back the mask */ | |
a5e9a7cf | 3779 | if (asserted & ATTN_NIG_FOR_FUNC) { |
27c1151c YR |
3780 | /* Verify that IGU ack through BAR was written before restoring |
3781 | * NIG mask. This loop should exit after 2-3 iterations max. | |
3782 | */ | |
3783 | if (bp->common.int_block != INT_BLOCK_HC) { | |
3784 | u32 cnt = 0, igu_acked; | |
3785 | do { | |
3786 | igu_acked = REG_RD(bp, | |
3787 | IGU_REG_ATTENTION_ACK_BITS); | |
3788 | } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) && | |
3789 | (++cnt < MAX_IGU_ATTN_ACK_TO)); | |
3790 | if (!igu_acked) | |
3791 | DP(NETIF_MSG_HW, | |
3792 | "Failed to verify IGU ack on time\n"); | |
3793 | barrier(); | |
3794 | } | |
87942b46 | 3795 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
a5e9a7cf EG |
3796 | bnx2x_release_phy_lock(bp); |
3797 | } | |
a2fbb9ea ET |
3798 | } |
3799 | ||
1191cb83 | 3800 | static void bnx2x_fan_failure(struct bnx2x *bp) |
fd4ef40d EG |
3801 | { |
3802 | int port = BP_PORT(bp); | |
b7737c9b | 3803 | u32 ext_phy_config; |
fd4ef40d | 3804 | /* mark the failure */ |
b7737c9b YR |
3805 | ext_phy_config = |
3806 | SHMEM_RD(bp, | |
3807 | dev_info.port_hw_config[port].external_phy_config); | |
3808 | ||
3809 | ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; | |
3810 | ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; | |
fd4ef40d | 3811 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
b7737c9b | 3812 | ext_phy_config); |
fd4ef40d EG |
3813 | |
3814 | /* log the failure */ | |
51c1a580 MS |
3815 | netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n" |
3816 | "Please contact OEM Support for assistance\n"); | |
8304859a AE |
3817 | |
3818 | /* | |
2de67439 | 3819 | * Schedule device reset (unload) |
8304859a AE |
3820 | * This is due to some boards consuming sufficient power when driver is |
3821 | * up to overheat if fan fails. | |
3822 | */ | |
3823 | smp_mb__before_clear_bit(); | |
3824 | set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state); | |
3825 | smp_mb__after_clear_bit(); | |
3826 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
3827 | ||
fd4ef40d | 3828 | } |
ab6ad5a4 | 3829 | |
1191cb83 | 3830 | static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
a2fbb9ea | 3831 | { |
34f80b04 | 3832 | int port = BP_PORT(bp); |
877e9aa4 | 3833 | int reg_offset; |
d90d96ba | 3834 | u32 val; |
877e9aa4 | 3835 | |
34f80b04 EG |
3836 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
3837 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
877e9aa4 | 3838 | |
34f80b04 | 3839 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
877e9aa4 ET |
3840 | |
3841 | val = REG_RD(bp, reg_offset); | |
3842 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; | |
3843 | REG_WR(bp, reg_offset, val); | |
3844 | ||
3845 | BNX2X_ERR("SPIO5 hw attention\n"); | |
3846 | ||
fd4ef40d | 3847 | /* Fan failure attention */ |
d90d96ba | 3848 | bnx2x_hw_reset_phy(&bp->link_params); |
fd4ef40d | 3849 | bnx2x_fan_failure(bp); |
877e9aa4 | 3850 | } |
34f80b04 | 3851 | |
3deb8167 | 3852 | if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) { |
589abe3a EG |
3853 | bnx2x_acquire_phy_lock(bp); |
3854 | bnx2x_handle_module_detect_int(&bp->link_params); | |
3855 | bnx2x_release_phy_lock(bp); | |
3856 | } | |
3857 | ||
34f80b04 EG |
3858 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
3859 | ||
3860 | val = REG_RD(bp, reg_offset); | |
3861 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); | |
3862 | REG_WR(bp, reg_offset, val); | |
3863 | ||
3864 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", | |
0fc5d009 | 3865 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
34f80b04 EG |
3866 | bnx2x_panic(); |
3867 | } | |
877e9aa4 ET |
3868 | } |
3869 | ||
1191cb83 | 3870 | static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
877e9aa4 ET |
3871 | { |
3872 | u32 val; | |
3873 | ||
0626b899 | 3874 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
877e9aa4 ET |
3875 | |
3876 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); | |
3877 | BNX2X_ERR("DB hw attention 0x%x\n", val); | |
3878 | /* DORQ discard attention */ | |
3879 | if (val & 0x2) | |
3880 | BNX2X_ERR("FATAL error from DORQ\n"); | |
3881 | } | |
34f80b04 EG |
3882 | |
3883 | if (attn & HW_INTERRUT_ASSERT_SET_1) { | |
3884 | ||
3885 | int port = BP_PORT(bp); | |
3886 | int reg_offset; | |
3887 | ||
3888 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : | |
3889 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); | |
3890 | ||
3891 | val = REG_RD(bp, reg_offset); | |
3892 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); | |
3893 | REG_WR(bp, reg_offset, val); | |
3894 | ||
3895 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", | |
0fc5d009 | 3896 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
34f80b04 EG |
3897 | bnx2x_panic(); |
3898 | } | |
877e9aa4 ET |
3899 | } |
3900 | ||
1191cb83 | 3901 | static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
877e9aa4 ET |
3902 | { |
3903 | u32 val; | |
3904 | ||
3905 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { | |
3906 | ||
3907 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); | |
3908 | BNX2X_ERR("CFC hw attention 0x%x\n", val); | |
3909 | /* CFC error attention */ | |
3910 | if (val & 0x2) | |
3911 | BNX2X_ERR("FATAL error from CFC\n"); | |
3912 | } | |
3913 | ||
3914 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { | |
877e9aa4 | 3915 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
619c5cb6 | 3916 | BNX2X_ERR("PXP hw attention-0 0x%x\n", val); |
877e9aa4 ET |
3917 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
3918 | if (val & 0x18000) | |
3919 | BNX2X_ERR("FATAL error from PXP\n"); | |
619c5cb6 VZ |
3920 | |
3921 | if (!CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
3922 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1); |
3923 | BNX2X_ERR("PXP hw attention-1 0x%x\n", val); | |
3924 | } | |
877e9aa4 | 3925 | } |
34f80b04 EG |
3926 | |
3927 | if (attn & HW_INTERRUT_ASSERT_SET_2) { | |
3928 | ||
3929 | int port = BP_PORT(bp); | |
3930 | int reg_offset; | |
3931 | ||
3932 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : | |
3933 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); | |
3934 | ||
3935 | val = REG_RD(bp, reg_offset); | |
3936 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); | |
3937 | REG_WR(bp, reg_offset, val); | |
3938 | ||
3939 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", | |
0fc5d009 | 3940 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
34f80b04 EG |
3941 | bnx2x_panic(); |
3942 | } | |
877e9aa4 ET |
3943 | } |
3944 | ||
1191cb83 | 3945 | static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
877e9aa4 | 3946 | { |
34f80b04 EG |
3947 | u32 val; |
3948 | ||
877e9aa4 ET |
3949 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
3950 | ||
34f80b04 EG |
3951 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
3952 | int func = BP_FUNC(bp); | |
3953 | ||
3954 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
a3348722 | 3955 | bnx2x_read_mf_cfg(bp); |
f2e0899f DK |
3956 | bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp, |
3957 | func_mf_config[BP_ABS_FUNC(bp)].config); | |
3958 | val = SHMEM_RD(bp, | |
3959 | func_mb[BP_FW_MB_IDX(bp)].drv_status); | |
2691d51d EG |
3960 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
3961 | bnx2x_dcc_event(bp, | |
3962 | (val & DRV_STATUS_DCC_EVENT_MASK)); | |
0793f83f DK |
3963 | |
3964 | if (val & DRV_STATUS_SET_MF_BW) | |
3965 | bnx2x_set_mf_bw(bp); | |
3966 | ||
1d187b34 BW |
3967 | if (val & DRV_STATUS_DRV_INFO_REQ) |
3968 | bnx2x_handle_drv_info_req(bp); | |
d16132ce AE |
3969 | |
3970 | if (val & DRV_STATUS_VF_DISABLED) | |
3971 | bnx2x_vf_handle_flr_event(bp); | |
3972 | ||
2691d51d | 3973 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
34f80b04 EG |
3974 | bnx2x_pmf_update(bp); |
3975 | ||
e4901dde | 3976 | if (bp->port.pmf && |
785b9b1a SR |
3977 | (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) && |
3978 | bp->dcbx_enabled > 0) | |
e4901dde VZ |
3979 | /* start dcbx state machine */ |
3980 | bnx2x_dcbx_set_params(bp, | |
3981 | BNX2X_DCBX_STATE_NEG_RECEIVED); | |
a3348722 BW |
3982 | if (val & DRV_STATUS_AFEX_EVENT_MASK) |
3983 | bnx2x_handle_afex_cmd(bp, | |
3984 | val & DRV_STATUS_AFEX_EVENT_MASK); | |
c8c60d88 YM |
3985 | if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS) |
3986 | bnx2x_handle_eee_event(bp); | |
3deb8167 YR |
3987 | if (bp->link_vars.periodic_flags & |
3988 | PERIODIC_FLAGS_LINK_EVENT) { | |
3989 | /* sync with link */ | |
3990 | bnx2x_acquire_phy_lock(bp); | |
3991 | bp->link_vars.periodic_flags &= | |
3992 | ~PERIODIC_FLAGS_LINK_EVENT; | |
3993 | bnx2x_release_phy_lock(bp); | |
3994 | if (IS_MF(bp)) | |
3995 | bnx2x_link_sync_notify(bp); | |
3996 | bnx2x_link_report(bp); | |
3997 | } | |
3998 | /* Always call it here: bnx2x_link_report() will | |
3999 | * prevent the link indication duplication. | |
4000 | */ | |
4001 | bnx2x__link_status_update(bp); | |
34f80b04 | 4002 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
877e9aa4 ET |
4003 | |
4004 | BNX2X_ERR("MC assert!\n"); | |
d6cae238 | 4005 | bnx2x_mc_assert(bp); |
877e9aa4 ET |
4006 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
4007 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); | |
4008 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); | |
4009 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); | |
4010 | bnx2x_panic(); | |
4011 | ||
4012 | } else if (attn & BNX2X_MCP_ASSERT) { | |
4013 | ||
4014 | BNX2X_ERR("MCP assert!\n"); | |
4015 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); | |
34f80b04 | 4016 | bnx2x_fw_dump(bp); |
877e9aa4 ET |
4017 | |
4018 | } else | |
4019 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); | |
4020 | } | |
4021 | ||
4022 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { | |
34f80b04 EG |
4023 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
4024 | if (attn & BNX2X_GRC_TIMEOUT) { | |
f2e0899f DK |
4025 | val = CHIP_IS_E1(bp) ? 0 : |
4026 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN); | |
34f80b04 EG |
4027 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
4028 | } | |
4029 | if (attn & BNX2X_GRC_RSV) { | |
f2e0899f DK |
4030 | val = CHIP_IS_E1(bp) ? 0 : |
4031 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN); | |
34f80b04 EG |
4032 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
4033 | } | |
877e9aa4 | 4034 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
877e9aa4 ET |
4035 | } |
4036 | } | |
4037 | ||
c9ee9206 VZ |
4038 | /* |
4039 | * Bits map: | |
4040 | * 0-7 - Engine0 load counter. | |
4041 | * 8-15 - Engine1 load counter. | |
4042 | * 16 - Engine0 RESET_IN_PROGRESS bit. | |
4043 | * 17 - Engine1 RESET_IN_PROGRESS bit. | |
4044 | * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function | |
4045 | * on the engine | |
4046 | * 19 - Engine1 ONE_IS_LOADED. | |
4047 | * 20 - Chip reset flow bit. When set none-leader must wait for both engines | |
4048 | * leader to complete (check for both RESET_IN_PROGRESS bits and not for | |
4049 | * just the one belonging to its engine). | |
4050 | * | |
4051 | */ | |
4052 | #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 | |
4053 | ||
4054 | #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff | |
4055 | #define BNX2X_PATH0_LOAD_CNT_SHIFT 0 | |
4056 | #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 | |
4057 | #define BNX2X_PATH1_LOAD_CNT_SHIFT 8 | |
4058 | #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 | |
4059 | #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 | |
4060 | #define BNX2X_GLOBAL_RESET_BIT 0x00040000 | |
4061 | ||
4062 | /* | |
4063 | * Set the GLOBAL_RESET bit. | |
4064 | * | |
4065 | * Should be run under rtnl lock | |
4066 | */ | |
4067 | void bnx2x_set_reset_global(struct bnx2x *bp) | |
4068 | { | |
f16da43b AE |
4069 | u32 val; |
4070 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
4071 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 4072 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT); |
f16da43b | 4073 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 VZ |
4074 | } |
4075 | ||
4076 | /* | |
4077 | * Clear the GLOBAL_RESET bit. | |
4078 | * | |
4079 | * Should be run under rtnl lock | |
4080 | */ | |
1191cb83 | 4081 | static void bnx2x_clear_reset_global(struct bnx2x *bp) |
c9ee9206 | 4082 | { |
f16da43b AE |
4083 | u32 val; |
4084 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
4085 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 4086 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT)); |
f16da43b | 4087 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 | 4088 | } |
f85582f8 | 4089 | |
72fd0718 | 4090 | /* |
c9ee9206 VZ |
4091 | * Checks the GLOBAL_RESET bit. |
4092 | * | |
72fd0718 VZ |
4093 | * should be run under rtnl lock |
4094 | */ | |
1191cb83 | 4095 | static bool bnx2x_reset_is_global(struct bnx2x *bp) |
c9ee9206 VZ |
4096 | { |
4097 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
4098 | ||
4099 | DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val); | |
4100 | return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false; | |
4101 | } | |
4102 | ||
4103 | /* | |
4104 | * Clear RESET_IN_PROGRESS bit for the current engine. | |
4105 | * | |
4106 | * Should be run under rtnl lock | |
4107 | */ | |
1191cb83 | 4108 | static void bnx2x_set_reset_done(struct bnx2x *bp) |
72fd0718 | 4109 | { |
f16da43b | 4110 | u32 val; |
c9ee9206 VZ |
4111 | u32 bit = BP_PATH(bp) ? |
4112 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
4113 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4114 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
4115 | |
4116 | /* Clear the bit */ | |
4117 | val &= ~bit; | |
4118 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
4119 | |
4120 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
72fd0718 VZ |
4121 | } |
4122 | ||
4123 | /* | |
c9ee9206 VZ |
4124 | * Set RESET_IN_PROGRESS for the current engine. |
4125 | * | |
72fd0718 VZ |
4126 | * should be run under rtnl lock |
4127 | */ | |
c9ee9206 | 4128 | void bnx2x_set_reset_in_progress(struct bnx2x *bp) |
72fd0718 | 4129 | { |
f16da43b | 4130 | u32 val; |
c9ee9206 VZ |
4131 | u32 bit = BP_PATH(bp) ? |
4132 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
4133 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4134 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
4135 | |
4136 | /* Set the bit */ | |
4137 | val |= bit; | |
4138 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 4139 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
4140 | } |
4141 | ||
4142 | /* | |
c9ee9206 | 4143 | * Checks the RESET_IN_PROGRESS bit for the given engine. |
72fd0718 VZ |
4144 | * should be run under rtnl lock |
4145 | */ | |
c9ee9206 | 4146 | bool bnx2x_reset_is_done(struct bnx2x *bp, int engine) |
72fd0718 | 4147 | { |
c9ee9206 VZ |
4148 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
4149 | u32 bit = engine ? | |
4150 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
4151 | ||
4152 | /* return false if bit is set */ | |
4153 | return (val & bit) ? false : true; | |
72fd0718 VZ |
4154 | } |
4155 | ||
4156 | /* | |
889b9af3 | 4157 | * set pf load for the current pf. |
c9ee9206 | 4158 | * |
72fd0718 VZ |
4159 | * should be run under rtnl lock |
4160 | */ | |
889b9af3 | 4161 | void bnx2x_set_pf_load(struct bnx2x *bp) |
72fd0718 | 4162 | { |
f16da43b | 4163 | u32 val1, val; |
c9ee9206 VZ |
4164 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
4165 | BNX2X_PATH0_LOAD_CNT_MASK; | |
4166 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4167 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 4168 | |
f16da43b AE |
4169 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4170 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
4171 | ||
51c1a580 | 4172 | DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 4173 | |
c9ee9206 VZ |
4174 | /* get the current counter value */ |
4175 | val1 = (val & mask) >> shift; | |
4176 | ||
889b9af3 AE |
4177 | /* set bit of that PF */ |
4178 | val1 |= (1 << bp->pf_num); | |
c9ee9206 VZ |
4179 | |
4180 | /* clear the old value */ | |
4181 | val &= ~mask; | |
4182 | ||
4183 | /* set the new one */ | |
4184 | val |= ((val1 << shift) & mask); | |
4185 | ||
4186 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 4187 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
4188 | } |
4189 | ||
c9ee9206 | 4190 | /** |
889b9af3 | 4191 | * bnx2x_clear_pf_load - clear pf load mark |
c9ee9206 VZ |
4192 | * |
4193 | * @bp: driver handle | |
4194 | * | |
4195 | * Should be run under rtnl lock. | |
4196 | * Decrements the load counter for the current engine. Returns | |
889b9af3 | 4197 | * whether other functions are still loaded |
72fd0718 | 4198 | */ |
889b9af3 | 4199 | bool bnx2x_clear_pf_load(struct bnx2x *bp) |
72fd0718 | 4200 | { |
f16da43b | 4201 | u32 val1, val; |
c9ee9206 VZ |
4202 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
4203 | BNX2X_PATH0_LOAD_CNT_MASK; | |
4204 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4205 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 4206 | |
f16da43b AE |
4207 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4208 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
51c1a580 | 4209 | DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 4210 | |
c9ee9206 VZ |
4211 | /* get the current counter value */ |
4212 | val1 = (val & mask) >> shift; | |
4213 | ||
889b9af3 AE |
4214 | /* clear bit of that PF */ |
4215 | val1 &= ~(1 << bp->pf_num); | |
c9ee9206 VZ |
4216 | |
4217 | /* clear the old value */ | |
4218 | val &= ~mask; | |
4219 | ||
4220 | /* set the new one */ | |
4221 | val |= ((val1 << shift) & mask); | |
4222 | ||
4223 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
4224 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4225 | return val1 != 0; | |
72fd0718 VZ |
4226 | } |
4227 | ||
4228 | /* | |
889b9af3 | 4229 | * Read the load status for the current engine. |
c9ee9206 | 4230 | * |
72fd0718 VZ |
4231 | * should be run under rtnl lock |
4232 | */ | |
1191cb83 | 4233 | static bool bnx2x_get_load_status(struct bnx2x *bp, int engine) |
72fd0718 | 4234 | { |
c9ee9206 VZ |
4235 | u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK : |
4236 | BNX2X_PATH0_LOAD_CNT_MASK); | |
4237 | u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4238 | BNX2X_PATH0_LOAD_CNT_SHIFT); | |
4239 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
4240 | ||
51c1a580 | 4241 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val); |
c9ee9206 VZ |
4242 | |
4243 | val = (val & mask) >> shift; | |
4244 | ||
51c1a580 MS |
4245 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n", |
4246 | engine, val); | |
c9ee9206 | 4247 | |
889b9af3 | 4248 | return val != 0; |
72fd0718 VZ |
4249 | } |
4250 | ||
1191cb83 | 4251 | static void _print_next_block(int idx, const char *blk) |
72fd0718 | 4252 | { |
f1deab50 | 4253 | pr_cont("%s%s", idx ? ", " : "", blk); |
72fd0718 VZ |
4254 | } |
4255 | ||
1191cb83 ED |
4256 | static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num, |
4257 | bool print) | |
72fd0718 VZ |
4258 | { |
4259 | int i = 0; | |
4260 | u32 cur_bit = 0; | |
4261 | for (i = 0; sig; i++) { | |
4262 | cur_bit = ((u32)0x1 << i); | |
4263 | if (sig & cur_bit) { | |
4264 | switch (cur_bit) { | |
4265 | case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: | |
c9ee9206 VZ |
4266 | if (print) |
4267 | _print_next_block(par_num++, "BRB"); | |
72fd0718 VZ |
4268 | break; |
4269 | case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: | |
c9ee9206 VZ |
4270 | if (print) |
4271 | _print_next_block(par_num++, "PARSER"); | |
72fd0718 VZ |
4272 | break; |
4273 | case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: | |
c9ee9206 VZ |
4274 | if (print) |
4275 | _print_next_block(par_num++, "TSDM"); | |
72fd0718 VZ |
4276 | break; |
4277 | case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: | |
c9ee9206 VZ |
4278 | if (print) |
4279 | _print_next_block(par_num++, | |
4280 | "SEARCHER"); | |
4281 | break; | |
4282 | case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: | |
4283 | if (print) | |
4284 | _print_next_block(par_num++, "TCM"); | |
72fd0718 VZ |
4285 | break; |
4286 | case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
4287 | if (print) |
4288 | _print_next_block(par_num++, "TSEMI"); | |
4289 | break; | |
4290 | case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: | |
4291 | if (print) | |
4292 | _print_next_block(par_num++, "XPB"); | |
72fd0718 VZ |
4293 | break; |
4294 | } | |
4295 | ||
4296 | /* Clear the bit */ | |
4297 | sig &= ~cur_bit; | |
4298 | } | |
4299 | } | |
4300 | ||
4301 | return par_num; | |
4302 | } | |
4303 | ||
1191cb83 ED |
4304 | static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num, |
4305 | bool *global, bool print) | |
72fd0718 VZ |
4306 | { |
4307 | int i = 0; | |
4308 | u32 cur_bit = 0; | |
4309 | for (i = 0; sig; i++) { | |
4310 | cur_bit = ((u32)0x1 << i); | |
4311 | if (sig & cur_bit) { | |
4312 | switch (cur_bit) { | |
c9ee9206 VZ |
4313 | case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: |
4314 | if (print) | |
4315 | _print_next_block(par_num++, "PBF"); | |
72fd0718 VZ |
4316 | break; |
4317 | case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: | |
c9ee9206 VZ |
4318 | if (print) |
4319 | _print_next_block(par_num++, "QM"); | |
4320 | break; | |
4321 | case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: | |
4322 | if (print) | |
4323 | _print_next_block(par_num++, "TM"); | |
72fd0718 VZ |
4324 | break; |
4325 | case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: | |
c9ee9206 VZ |
4326 | if (print) |
4327 | _print_next_block(par_num++, "XSDM"); | |
4328 | break; | |
4329 | case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: | |
4330 | if (print) | |
4331 | _print_next_block(par_num++, "XCM"); | |
72fd0718 VZ |
4332 | break; |
4333 | case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
4334 | if (print) |
4335 | _print_next_block(par_num++, "XSEMI"); | |
72fd0718 VZ |
4336 | break; |
4337 | case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: | |
c9ee9206 VZ |
4338 | if (print) |
4339 | _print_next_block(par_num++, | |
4340 | "DOORBELLQ"); | |
4341 | break; | |
4342 | case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: | |
4343 | if (print) | |
4344 | _print_next_block(par_num++, "NIG"); | |
72fd0718 VZ |
4345 | break; |
4346 | case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: | |
c9ee9206 VZ |
4347 | if (print) |
4348 | _print_next_block(par_num++, | |
4349 | "VAUX PCI CORE"); | |
4350 | *global = true; | |
72fd0718 VZ |
4351 | break; |
4352 | case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: | |
c9ee9206 VZ |
4353 | if (print) |
4354 | _print_next_block(par_num++, "DEBUG"); | |
72fd0718 VZ |
4355 | break; |
4356 | case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: | |
c9ee9206 VZ |
4357 | if (print) |
4358 | _print_next_block(par_num++, "USDM"); | |
72fd0718 | 4359 | break; |
8736c826 VZ |
4360 | case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR: |
4361 | if (print) | |
4362 | _print_next_block(par_num++, "UCM"); | |
4363 | break; | |
72fd0718 | 4364 | case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: |
c9ee9206 VZ |
4365 | if (print) |
4366 | _print_next_block(par_num++, "USEMI"); | |
72fd0718 VZ |
4367 | break; |
4368 | case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: | |
c9ee9206 VZ |
4369 | if (print) |
4370 | _print_next_block(par_num++, "UPB"); | |
72fd0718 VZ |
4371 | break; |
4372 | case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: | |
c9ee9206 VZ |
4373 | if (print) |
4374 | _print_next_block(par_num++, "CSDM"); | |
72fd0718 | 4375 | break; |
8736c826 VZ |
4376 | case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR: |
4377 | if (print) | |
4378 | _print_next_block(par_num++, "CCM"); | |
4379 | break; | |
72fd0718 VZ |
4380 | } |
4381 | ||
4382 | /* Clear the bit */ | |
4383 | sig &= ~cur_bit; | |
4384 | } | |
4385 | } | |
4386 | ||
4387 | return par_num; | |
4388 | } | |
4389 | ||
1191cb83 ED |
4390 | static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num, |
4391 | bool print) | |
72fd0718 VZ |
4392 | { |
4393 | int i = 0; | |
4394 | u32 cur_bit = 0; | |
4395 | for (i = 0; sig; i++) { | |
4396 | cur_bit = ((u32)0x1 << i); | |
4397 | if (sig & cur_bit) { | |
4398 | switch (cur_bit) { | |
4399 | case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
4400 | if (print) |
4401 | _print_next_block(par_num++, "CSEMI"); | |
72fd0718 VZ |
4402 | break; |
4403 | case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: | |
c9ee9206 VZ |
4404 | if (print) |
4405 | _print_next_block(par_num++, "PXP"); | |
72fd0718 VZ |
4406 | break; |
4407 | case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: | |
c9ee9206 VZ |
4408 | if (print) |
4409 | _print_next_block(par_num++, | |
72fd0718 VZ |
4410 | "PXPPCICLOCKCLIENT"); |
4411 | break; | |
4412 | case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: | |
c9ee9206 VZ |
4413 | if (print) |
4414 | _print_next_block(par_num++, "CFC"); | |
72fd0718 VZ |
4415 | break; |
4416 | case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: | |
c9ee9206 VZ |
4417 | if (print) |
4418 | _print_next_block(par_num++, "CDU"); | |
4419 | break; | |
4420 | case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: | |
4421 | if (print) | |
4422 | _print_next_block(par_num++, "DMAE"); | |
72fd0718 VZ |
4423 | break; |
4424 | case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: | |
c9ee9206 VZ |
4425 | if (print) |
4426 | _print_next_block(par_num++, "IGU"); | |
72fd0718 VZ |
4427 | break; |
4428 | case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: | |
c9ee9206 VZ |
4429 | if (print) |
4430 | _print_next_block(par_num++, "MISC"); | |
72fd0718 VZ |
4431 | break; |
4432 | } | |
4433 | ||
4434 | /* Clear the bit */ | |
4435 | sig &= ~cur_bit; | |
4436 | } | |
4437 | } | |
4438 | ||
4439 | return par_num; | |
4440 | } | |
4441 | ||
1191cb83 ED |
4442 | static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num, |
4443 | bool *global, bool print) | |
72fd0718 VZ |
4444 | { |
4445 | int i = 0; | |
4446 | u32 cur_bit = 0; | |
4447 | for (i = 0; sig; i++) { | |
4448 | cur_bit = ((u32)0x1 << i); | |
4449 | if (sig & cur_bit) { | |
4450 | switch (cur_bit) { | |
4451 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: | |
c9ee9206 VZ |
4452 | if (print) |
4453 | _print_next_block(par_num++, "MCP ROM"); | |
4454 | *global = true; | |
72fd0718 VZ |
4455 | break; |
4456 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: | |
c9ee9206 VZ |
4457 | if (print) |
4458 | _print_next_block(par_num++, | |
4459 | "MCP UMP RX"); | |
4460 | *global = true; | |
72fd0718 VZ |
4461 | break; |
4462 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: | |
c9ee9206 VZ |
4463 | if (print) |
4464 | _print_next_block(par_num++, | |
4465 | "MCP UMP TX"); | |
4466 | *global = true; | |
72fd0718 VZ |
4467 | break; |
4468 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: | |
c9ee9206 VZ |
4469 | if (print) |
4470 | _print_next_block(par_num++, | |
4471 | "MCP SCPAD"); | |
4472 | *global = true; | |
72fd0718 VZ |
4473 | break; |
4474 | } | |
4475 | ||
4476 | /* Clear the bit */ | |
4477 | sig &= ~cur_bit; | |
4478 | } | |
4479 | } | |
4480 | ||
4481 | return par_num; | |
4482 | } | |
4483 | ||
1191cb83 ED |
4484 | static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num, |
4485 | bool print) | |
8736c826 VZ |
4486 | { |
4487 | int i = 0; | |
4488 | u32 cur_bit = 0; | |
4489 | for (i = 0; sig; i++) { | |
4490 | cur_bit = ((u32)0x1 << i); | |
4491 | if (sig & cur_bit) { | |
4492 | switch (cur_bit) { | |
4493 | case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR: | |
4494 | if (print) | |
4495 | _print_next_block(par_num++, "PGLUE_B"); | |
4496 | break; | |
4497 | case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR: | |
4498 | if (print) | |
4499 | _print_next_block(par_num++, "ATC"); | |
4500 | break; | |
4501 | } | |
4502 | ||
4503 | /* Clear the bit */ | |
4504 | sig &= ~cur_bit; | |
4505 | } | |
4506 | } | |
4507 | ||
4508 | return par_num; | |
4509 | } | |
4510 | ||
1191cb83 ED |
4511 | static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, |
4512 | u32 *sig) | |
72fd0718 | 4513 | { |
8736c826 VZ |
4514 | if ((sig[0] & HW_PRTY_ASSERT_SET_0) || |
4515 | (sig[1] & HW_PRTY_ASSERT_SET_1) || | |
4516 | (sig[2] & HW_PRTY_ASSERT_SET_2) || | |
4517 | (sig[3] & HW_PRTY_ASSERT_SET_3) || | |
4518 | (sig[4] & HW_PRTY_ASSERT_SET_4)) { | |
72fd0718 | 4519 | int par_num = 0; |
51c1a580 MS |
4520 | DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n" |
4521 | "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n", | |
8736c826 VZ |
4522 | sig[0] & HW_PRTY_ASSERT_SET_0, |
4523 | sig[1] & HW_PRTY_ASSERT_SET_1, | |
4524 | sig[2] & HW_PRTY_ASSERT_SET_2, | |
4525 | sig[3] & HW_PRTY_ASSERT_SET_3, | |
4526 | sig[4] & HW_PRTY_ASSERT_SET_4); | |
c9ee9206 VZ |
4527 | if (print) |
4528 | netdev_err(bp->dev, | |
4529 | "Parity errors detected in blocks: "); | |
4530 | par_num = bnx2x_check_blocks_with_parity0( | |
8736c826 | 4531 | sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print); |
c9ee9206 | 4532 | par_num = bnx2x_check_blocks_with_parity1( |
8736c826 | 4533 | sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print); |
c9ee9206 | 4534 | par_num = bnx2x_check_blocks_with_parity2( |
8736c826 | 4535 | sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print); |
c9ee9206 | 4536 | par_num = bnx2x_check_blocks_with_parity3( |
8736c826 VZ |
4537 | sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print); |
4538 | par_num = bnx2x_check_blocks_with_parity4( | |
4539 | sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print); | |
4540 | ||
c9ee9206 VZ |
4541 | if (print) |
4542 | pr_cont("\n"); | |
8736c826 | 4543 | |
72fd0718 VZ |
4544 | return true; |
4545 | } else | |
4546 | return false; | |
4547 | } | |
4548 | ||
c9ee9206 VZ |
4549 | /** |
4550 | * bnx2x_chk_parity_attn - checks for parity attentions. | |
4551 | * | |
4552 | * @bp: driver handle | |
4553 | * @global: true if there was a global attention | |
4554 | * @print: show parity attention in syslog | |
4555 | */ | |
4556 | bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print) | |
877e9aa4 | 4557 | { |
8736c826 | 4558 | struct attn_route attn = { {0} }; |
72fd0718 VZ |
4559 | int port = BP_PORT(bp); |
4560 | ||
4561 | attn.sig[0] = REG_RD(bp, | |
4562 | MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + | |
4563 | port*4); | |
4564 | attn.sig[1] = REG_RD(bp, | |
4565 | MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + | |
4566 | port*4); | |
4567 | attn.sig[2] = REG_RD(bp, | |
4568 | MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + | |
4569 | port*4); | |
4570 | attn.sig[3] = REG_RD(bp, | |
4571 | MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + | |
4572 | port*4); | |
4573 | ||
8736c826 VZ |
4574 | if (!CHIP_IS_E1x(bp)) |
4575 | attn.sig[4] = REG_RD(bp, | |
4576 | MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + | |
4577 | port*4); | |
4578 | ||
4579 | return bnx2x_parity_attn(bp, global, print, attn.sig); | |
72fd0718 VZ |
4580 | } |
4581 | ||
f2e0899f | 4582 | |
1191cb83 | 4583 | static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn) |
f2e0899f DK |
4584 | { |
4585 | u32 val; | |
4586 | if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { | |
4587 | ||
4588 | val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); | |
4589 | BNX2X_ERR("PGLUE hw attention 0x%x\n", val); | |
4590 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) | |
51c1a580 | 4591 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n"); |
f2e0899f | 4592 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) |
51c1a580 | 4593 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n"); |
f2e0899f | 4594 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) |
51c1a580 | 4595 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n"); |
f2e0899f | 4596 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) |
51c1a580 | 4597 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n"); |
f2e0899f DK |
4598 | if (val & |
4599 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) | |
51c1a580 | 4600 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n"); |
f2e0899f DK |
4601 | if (val & |
4602 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) | |
51c1a580 | 4603 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n"); |
f2e0899f | 4604 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) |
51c1a580 | 4605 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n"); |
f2e0899f | 4606 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) |
51c1a580 | 4607 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n"); |
f2e0899f | 4608 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) |
51c1a580 | 4609 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n"); |
f2e0899f DK |
4610 | } |
4611 | if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { | |
4612 | val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR); | |
4613 | BNX2X_ERR("ATC hw attention 0x%x\n", val); | |
4614 | if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) | |
4615 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); | |
4616 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) | |
51c1a580 | 4617 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n"); |
f2e0899f | 4618 | if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) |
51c1a580 | 4619 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n"); |
f2e0899f | 4620 | if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) |
51c1a580 | 4621 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n"); |
f2e0899f DK |
4622 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) |
4623 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); | |
4624 | if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) | |
51c1a580 | 4625 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n"); |
f2e0899f DK |
4626 | } |
4627 | ||
4628 | if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4629 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { | |
4630 | BNX2X_ERR("FATAL parity attention set4 0x%x\n", | |
4631 | (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4632 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); | |
4633 | } | |
4634 | ||
4635 | } | |
4636 | ||
72fd0718 VZ |
4637 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
4638 | { | |
4639 | struct attn_route attn, *group_mask; | |
34f80b04 | 4640 | int port = BP_PORT(bp); |
877e9aa4 | 4641 | int index; |
a2fbb9ea ET |
4642 | u32 reg_addr; |
4643 | u32 val; | |
3fcaf2e5 | 4644 | u32 aeu_mask; |
c9ee9206 | 4645 | bool global = false; |
a2fbb9ea ET |
4646 | |
4647 | /* need to take HW lock because MCP or other port might also | |
4648 | try to handle this event */ | |
4a37fb66 | 4649 | bnx2x_acquire_alr(bp); |
a2fbb9ea | 4650 | |
c9ee9206 VZ |
4651 | if (bnx2x_chk_parity_attn(bp, &global, true)) { |
4652 | #ifndef BNX2X_STOP_ON_ERROR | |
72fd0718 | 4653 | bp->recovery_state = BNX2X_RECOVERY_INIT; |
7be08a72 | 4654 | schedule_delayed_work(&bp->sp_rtnl_task, 0); |
72fd0718 VZ |
4655 | /* Disable HW interrupts */ |
4656 | bnx2x_int_disable(bp); | |
72fd0718 VZ |
4657 | /* In case of parity errors don't handle attentions so that |
4658 | * other function would "see" parity errors. | |
4659 | */ | |
c9ee9206 VZ |
4660 | #else |
4661 | bnx2x_panic(); | |
4662 | #endif | |
4663 | bnx2x_release_alr(bp); | |
72fd0718 VZ |
4664 | return; |
4665 | } | |
4666 | ||
a2fbb9ea ET |
4667 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
4668 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); | |
4669 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); | |
4670 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); | |
619c5cb6 | 4671 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
4672 | attn.sig[4] = |
4673 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); | |
4674 | else | |
4675 | attn.sig[4] = 0; | |
4676 | ||
4677 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n", | |
4678 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); | |
a2fbb9ea ET |
4679 | |
4680 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { | |
4681 | if (deasserted & (1 << index)) { | |
72fd0718 | 4682 | group_mask = &bp->attn_group[index]; |
a2fbb9ea | 4683 | |
51c1a580 | 4684 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n", |
f2e0899f DK |
4685 | index, |
4686 | group_mask->sig[0], group_mask->sig[1], | |
4687 | group_mask->sig[2], group_mask->sig[3], | |
4688 | group_mask->sig[4]); | |
a2fbb9ea | 4689 | |
f2e0899f DK |
4690 | bnx2x_attn_int_deasserted4(bp, |
4691 | attn.sig[4] & group_mask->sig[4]); | |
877e9aa4 | 4692 | bnx2x_attn_int_deasserted3(bp, |
72fd0718 | 4693 | attn.sig[3] & group_mask->sig[3]); |
877e9aa4 | 4694 | bnx2x_attn_int_deasserted1(bp, |
72fd0718 | 4695 | attn.sig[1] & group_mask->sig[1]); |
877e9aa4 | 4696 | bnx2x_attn_int_deasserted2(bp, |
72fd0718 | 4697 | attn.sig[2] & group_mask->sig[2]); |
877e9aa4 | 4698 | bnx2x_attn_int_deasserted0(bp, |
72fd0718 | 4699 | attn.sig[0] & group_mask->sig[0]); |
a2fbb9ea ET |
4700 | } |
4701 | } | |
4702 | ||
4a37fb66 | 4703 | bnx2x_release_alr(bp); |
a2fbb9ea | 4704 | |
f2e0899f DK |
4705 | if (bp->common.int_block == INT_BLOCK_HC) |
4706 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
4707 | COMMAND_REG_ATTN_BITS_CLR); | |
4708 | else | |
4709 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); | |
a2fbb9ea ET |
4710 | |
4711 | val = ~deasserted; | |
f2e0899f DK |
4712 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val, |
4713 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
5c862848 | 4714 | REG_WR(bp, reg_addr, val); |
a2fbb9ea | 4715 | |
a2fbb9ea | 4716 | if (~bp->attn_state & deasserted) |
3fcaf2e5 | 4717 | BNX2X_ERR("IGU ERROR\n"); |
a2fbb9ea ET |
4718 | |
4719 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
4720 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
4721 | ||
3fcaf2e5 EG |
4722 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
4723 | aeu_mask = REG_RD(bp, reg_addr); | |
4724 | ||
4725 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", | |
4726 | aeu_mask, deasserted); | |
72fd0718 | 4727 | aeu_mask |= (deasserted & 0x3ff); |
3fcaf2e5 | 4728 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 4729 | |
3fcaf2e5 EG |
4730 | REG_WR(bp, reg_addr, aeu_mask); |
4731 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea ET |
4732 | |
4733 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); | |
4734 | bp->attn_state &= ~deasserted; | |
4735 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); | |
4736 | } | |
4737 | ||
4738 | static void bnx2x_attn_int(struct bnx2x *bp) | |
4739 | { | |
4740 | /* read local copy of bits */ | |
68d59484 EG |
4741 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
4742 | attn_bits); | |
4743 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. | |
4744 | attn_bits_ack); | |
a2fbb9ea ET |
4745 | u32 attn_state = bp->attn_state; |
4746 | ||
4747 | /* look for changed bits */ | |
4748 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; | |
4749 | u32 deasserted = ~attn_bits & attn_ack & attn_state; | |
4750 | ||
4751 | DP(NETIF_MSG_HW, | |
4752 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", | |
4753 | attn_bits, attn_ack, asserted, deasserted); | |
4754 | ||
4755 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) | |
34f80b04 | 4756 | BNX2X_ERR("BAD attention state\n"); |
a2fbb9ea ET |
4757 | |
4758 | /* handle bits that were raised */ | |
4759 | if (asserted) | |
4760 | bnx2x_attn_int_asserted(bp, asserted); | |
4761 | ||
4762 | if (deasserted) | |
4763 | bnx2x_attn_int_deasserted(bp, deasserted); | |
4764 | } | |
4765 | ||
619c5cb6 VZ |
4766 | void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
4767 | u16 index, u8 op, u8 update) | |
4768 | { | |
dc1ba591 AE |
4769 | u32 igu_addr = bp->igu_base_addr; |
4770 | igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; | |
619c5cb6 VZ |
4771 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, |
4772 | igu_addr); | |
4773 | } | |
4774 | ||
1191cb83 | 4775 | static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod) |
523224a3 DK |
4776 | { |
4777 | /* No memory barriers */ | |
4778 | storm_memset_eq_prod(bp, prod, BP_FUNC(bp)); | |
4779 | mmiowb(); /* keep prod updates ordered */ | |
4780 | } | |
4781 | ||
523224a3 DK |
4782 | static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid, |
4783 | union event_ring_elem *elem) | |
4784 | { | |
619c5cb6 VZ |
4785 | u8 err = elem->message.error; |
4786 | ||
523224a3 | 4787 | if (!bp->cnic_eth_dev.starting_cid || |
c3a8ce61 VZ |
4788 | (cid < bp->cnic_eth_dev.starting_cid && |
4789 | cid != bp->cnic_eth_dev.iscsi_l2_cid)) | |
523224a3 DK |
4790 | return 1; |
4791 | ||
4792 | DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid); | |
4793 | ||
619c5cb6 VZ |
4794 | if (unlikely(err)) { |
4795 | ||
523224a3 DK |
4796 | BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n", |
4797 | cid); | |
823e1d90 | 4798 | bnx2x_panic_dump(bp, false); |
523224a3 | 4799 | } |
619c5cb6 | 4800 | bnx2x_cnic_cfc_comp(bp, cid, err); |
523224a3 DK |
4801 | return 0; |
4802 | } | |
523224a3 | 4803 | |
1191cb83 | 4804 | static void bnx2x_handle_mcast_eqe(struct bnx2x *bp) |
619c5cb6 VZ |
4805 | { |
4806 | struct bnx2x_mcast_ramrod_params rparam; | |
4807 | int rc; | |
4808 | ||
4809 | memset(&rparam, 0, sizeof(rparam)); | |
4810 | ||
4811 | rparam.mcast_obj = &bp->mcast_obj; | |
4812 | ||
4813 | netif_addr_lock_bh(bp->dev); | |
4814 | ||
4815 | /* Clear pending state for the last command */ | |
4816 | bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw); | |
4817 | ||
4818 | /* If there are pending mcast commands - send them */ | |
4819 | if (bp->mcast_obj.check_pending(&bp->mcast_obj)) { | |
4820 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); | |
4821 | if (rc < 0) | |
4822 | BNX2X_ERR("Failed to send pending mcast commands: %d\n", | |
4823 | rc); | |
4824 | } | |
4825 | ||
4826 | netif_addr_unlock_bh(bp->dev); | |
4827 | } | |
4828 | ||
1191cb83 ED |
4829 | static void bnx2x_handle_classification_eqe(struct bnx2x *bp, |
4830 | union event_ring_elem *elem) | |
619c5cb6 VZ |
4831 | { |
4832 | unsigned long ramrod_flags = 0; | |
4833 | int rc = 0; | |
4834 | u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK; | |
4835 | struct bnx2x_vlan_mac_obj *vlan_mac_obj; | |
4836 | ||
4837 | /* Always push next commands out, don't wait here */ | |
4838 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
4839 | ||
86564c3f YM |
4840 | switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo) |
4841 | >> BNX2X_SWCID_SHIFT) { | |
619c5cb6 | 4842 | case BNX2X_FILTER_MAC_PENDING: |
51c1a580 | 4843 | DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n"); |
55c11941 | 4844 | if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp))) |
619c5cb6 VZ |
4845 | vlan_mac_obj = &bp->iscsi_l2_mac_obj; |
4846 | else | |
15192a8c | 4847 | vlan_mac_obj = &bp->sp_objs[cid].mac_obj; |
619c5cb6 VZ |
4848 | |
4849 | break; | |
619c5cb6 | 4850 | case BNX2X_FILTER_MCAST_PENDING: |
51c1a580 | 4851 | DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n"); |
619c5cb6 VZ |
4852 | /* This is only relevant for 57710 where multicast MACs are |
4853 | * configured as unicast MACs using the same ramrod. | |
4854 | */ | |
4855 | bnx2x_handle_mcast_eqe(bp); | |
4856 | return; | |
4857 | default: | |
4858 | BNX2X_ERR("Unsupported classification command: %d\n", | |
4859 | elem->message.data.eth_event.echo); | |
4860 | return; | |
4861 | } | |
4862 | ||
4863 | rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags); | |
4864 | ||
4865 | if (rc < 0) | |
4866 | BNX2X_ERR("Failed to schedule new commands: %d\n", rc); | |
4867 | else if (rc > 0) | |
4868 | DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n"); | |
4869 | ||
4870 | } | |
4871 | ||
619c5cb6 | 4872 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start); |
619c5cb6 | 4873 | |
1191cb83 | 4874 | static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp) |
619c5cb6 VZ |
4875 | { |
4876 | netif_addr_lock_bh(bp->dev); | |
4877 | ||
4878 | clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
4879 | ||
4880 | /* Send rx_mode command again if was requested */ | |
4881 | if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state)) | |
4882 | bnx2x_set_storm_rx_mode(bp); | |
619c5cb6 VZ |
4883 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, |
4884 | &bp->sp_state)) | |
4885 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
4886 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, | |
4887 | &bp->sp_state)) | |
4888 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
619c5cb6 VZ |
4889 | |
4890 | netif_addr_unlock_bh(bp->dev); | |
4891 | } | |
4892 | ||
1191cb83 | 4893 | static void bnx2x_after_afex_vif_lists(struct bnx2x *bp, |
a3348722 BW |
4894 | union event_ring_elem *elem) |
4895 | { | |
4896 | if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) { | |
4897 | DP(BNX2X_MSG_SP, | |
4898 | "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n", | |
4899 | elem->message.data.vif_list_event.func_bit_map); | |
4900 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK, | |
4901 | elem->message.data.vif_list_event.func_bit_map); | |
4902 | } else if (elem->message.data.vif_list_event.echo == | |
4903 | VIF_LIST_RULE_SET) { | |
4904 | DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n"); | |
4905 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0); | |
4906 | } | |
4907 | } | |
4908 | ||
4909 | /* called with rtnl_lock */ | |
1191cb83 | 4910 | static void bnx2x_after_function_update(struct bnx2x *bp) |
a3348722 BW |
4911 | { |
4912 | int q, rc; | |
4913 | struct bnx2x_fastpath *fp; | |
4914 | struct bnx2x_queue_state_params queue_params = {NULL}; | |
4915 | struct bnx2x_queue_update_params *q_update_params = | |
4916 | &queue_params.params.update; | |
4917 | ||
2de67439 | 4918 | /* Send Q update command with afex vlan removal values for all Qs */ |
a3348722 BW |
4919 | queue_params.cmd = BNX2X_Q_CMD_UPDATE; |
4920 | ||
4921 | /* set silent vlan removal values according to vlan mode */ | |
4922 | __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG, | |
4923 | &q_update_params->update_flags); | |
4924 | __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, | |
4925 | &q_update_params->update_flags); | |
4926 | __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags); | |
4927 | ||
4928 | /* in access mode mark mask and value are 0 to strip all vlans */ | |
4929 | if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) { | |
4930 | q_update_params->silent_removal_value = 0; | |
4931 | q_update_params->silent_removal_mask = 0; | |
4932 | } else { | |
4933 | q_update_params->silent_removal_value = | |
4934 | (bp->afex_def_vlan_tag & VLAN_VID_MASK); | |
4935 | q_update_params->silent_removal_mask = VLAN_VID_MASK; | |
4936 | } | |
4937 | ||
4938 | for_each_eth_queue(bp, q) { | |
4939 | /* Set the appropriate Queue object */ | |
4940 | fp = &bp->fp[q]; | |
15192a8c | 4941 | queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a3348722 BW |
4942 | |
4943 | /* send the ramrod */ | |
4944 | rc = bnx2x_queue_state_change(bp, &queue_params); | |
4945 | if (rc < 0) | |
4946 | BNX2X_ERR("Failed to config silent vlan rem for Q %d\n", | |
4947 | q); | |
4948 | } | |
4949 | ||
fea75645 | 4950 | if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) { |
65565884 | 4951 | fp = &bp->fp[FCOE_IDX(bp)]; |
15192a8c | 4952 | queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a3348722 BW |
4953 | |
4954 | /* clear pending completion bit */ | |
4955 | __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags); | |
4956 | ||
4957 | /* mark latest Q bit */ | |
4958 | smp_mb__before_clear_bit(); | |
4959 | set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state); | |
4960 | smp_mb__after_clear_bit(); | |
4961 | ||
4962 | /* send Q update ramrod for FCoE Q */ | |
4963 | rc = bnx2x_queue_state_change(bp, &queue_params); | |
4964 | if (rc < 0) | |
4965 | BNX2X_ERR("Failed to config silent vlan rem for Q %d\n", | |
4966 | q); | |
4967 | } else { | |
4968 | /* If no FCoE ring - ACK MCP now */ | |
4969 | bnx2x_link_report(bp); | |
4970 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
4971 | } | |
a3348722 BW |
4972 | } |
4973 | ||
1191cb83 | 4974 | static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj( |
619c5cb6 VZ |
4975 | struct bnx2x *bp, u32 cid) |
4976 | { | |
94f05b0f | 4977 | DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid); |
55c11941 MS |
4978 | |
4979 | if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp))) | |
15192a8c | 4980 | return &bnx2x_fcoe_sp_obj(bp, q_obj); |
619c5cb6 | 4981 | else |
15192a8c | 4982 | return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj; |
619c5cb6 VZ |
4983 | } |
4984 | ||
523224a3 DK |
4985 | static void bnx2x_eq_int(struct bnx2x *bp) |
4986 | { | |
4987 | u16 hw_cons, sw_cons, sw_prod; | |
4988 | union event_ring_elem *elem; | |
55c11941 | 4989 | u8 echo; |
523224a3 DK |
4990 | u32 cid; |
4991 | u8 opcode; | |
fd1fc79d | 4992 | int rc, spqe_cnt = 0; |
619c5cb6 VZ |
4993 | struct bnx2x_queue_sp_obj *q_obj; |
4994 | struct bnx2x_func_sp_obj *f_obj = &bp->func_obj; | |
4995 | struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw; | |
523224a3 DK |
4996 | |
4997 | hw_cons = le16_to_cpu(*bp->eq_cons_sb); | |
4998 | ||
4999 | /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256. | |
5000 | * when we get the the next-page we nned to adjust so the loop | |
5001 | * condition below will be met. The next element is the size of a | |
5002 | * regular element and hence incrementing by 1 | |
5003 | */ | |
5004 | if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) | |
5005 | hw_cons++; | |
5006 | ||
25985edc | 5007 | /* This function may never run in parallel with itself for a |
523224a3 DK |
5008 | * specific bp, thus there is no need in "paired" read memory |
5009 | * barrier here. | |
5010 | */ | |
5011 | sw_cons = bp->eq_cons; | |
5012 | sw_prod = bp->eq_prod; | |
5013 | ||
d6cae238 | 5014 | DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n", |
6e30dd4e | 5015 | hw_cons, sw_cons, atomic_read(&bp->eq_spq_left)); |
523224a3 DK |
5016 | |
5017 | for (; sw_cons != hw_cons; | |
5018 | sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { | |
5019 | ||
523224a3 DK |
5020 | elem = &bp->eq_ring[EQ_DESC(sw_cons)]; |
5021 | ||
fd1fc79d AE |
5022 | rc = bnx2x_iov_eq_sp_event(bp, elem); |
5023 | if (!rc) { | |
5024 | DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n", | |
5025 | rc); | |
5026 | goto next_spqe; | |
5027 | } | |
523224a3 | 5028 | |
86564c3f YM |
5029 | /* elem CID originates from FW; actually LE */ |
5030 | cid = SW_CID((__force __le32) | |
5031 | elem->message.data.cfc_del_event.cid); | |
5032 | opcode = elem->message.opcode; | |
523224a3 DK |
5033 | |
5034 | /* handle eq element */ | |
5035 | switch (opcode) { | |
fd1fc79d AE |
5036 | case EVENT_RING_OPCODE_VF_PF_CHANNEL: |
5037 | DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n"); | |
5038 | bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event); | |
5039 | continue; | |
5040 | ||
523224a3 | 5041 | case EVENT_RING_OPCODE_STAT_QUERY: |
51c1a580 MS |
5042 | DP(BNX2X_MSG_SP | BNX2X_MSG_STATS, |
5043 | "got statistics comp event %d\n", | |
619c5cb6 | 5044 | bp->stats_comp++); |
523224a3 | 5045 | /* nothing to do with stats comp */ |
d6cae238 | 5046 | goto next_spqe; |
523224a3 DK |
5047 | |
5048 | case EVENT_RING_OPCODE_CFC_DEL: | |
5049 | /* handle according to cid range */ | |
5050 | /* | |
5051 | * we may want to verify here that the bp state is | |
5052 | * HALTING | |
5053 | */ | |
d6cae238 | 5054 | DP(BNX2X_MSG_SP, |
523224a3 | 5055 | "got delete ramrod for MULTI[%d]\n", cid); |
55c11941 MS |
5056 | |
5057 | if (CNIC_LOADED(bp) && | |
5058 | !bnx2x_cnic_handle_cfc_del(bp, cid, elem)) | |
523224a3 | 5059 | goto next_spqe; |
55c11941 | 5060 | |
619c5cb6 VZ |
5061 | q_obj = bnx2x_cid_to_q_obj(bp, cid); |
5062 | ||
5063 | if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL)) | |
5064 | break; | |
5065 | ||
5066 | ||
523224a3 DK |
5067 | |
5068 | goto next_spqe; | |
e4901dde VZ |
5069 | |
5070 | case EVENT_RING_OPCODE_STOP_TRAFFIC: | |
51c1a580 | 5071 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n"); |
6debea87 DK |
5072 | if (f_obj->complete_cmd(bp, f_obj, |
5073 | BNX2X_F_CMD_TX_STOP)) | |
5074 | break; | |
e4901dde VZ |
5075 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED); |
5076 | goto next_spqe; | |
619c5cb6 | 5077 | |
e4901dde | 5078 | case EVENT_RING_OPCODE_START_TRAFFIC: |
51c1a580 | 5079 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n"); |
6debea87 DK |
5080 | if (f_obj->complete_cmd(bp, f_obj, |
5081 | BNX2X_F_CMD_TX_START)) | |
5082 | break; | |
e4901dde VZ |
5083 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED); |
5084 | goto next_spqe; | |
55c11941 | 5085 | |
a3348722 | 5086 | case EVENT_RING_OPCODE_FUNCTION_UPDATE: |
55c11941 MS |
5087 | echo = elem->message.data.function_update_event.echo; |
5088 | if (echo == SWITCH_UPDATE) { | |
5089 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, | |
5090 | "got FUNC_SWITCH_UPDATE ramrod\n"); | |
5091 | if (f_obj->complete_cmd( | |
5092 | bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE)) | |
5093 | break; | |
a3348722 | 5094 | |
55c11941 MS |
5095 | } else { |
5096 | DP(BNX2X_MSG_SP | BNX2X_MSG_MCP, | |
5097 | "AFEX: ramrod completed FUNCTION_UPDATE\n"); | |
5098 | f_obj->complete_cmd(bp, f_obj, | |
5099 | BNX2X_F_CMD_AFEX_UPDATE); | |
5100 | ||
5101 | /* We will perform the Queues update from | |
5102 | * sp_rtnl task as all Queue SP operations | |
5103 | * should run under rtnl_lock. | |
5104 | */ | |
5105 | smp_mb__before_clear_bit(); | |
5106 | set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, | |
5107 | &bp->sp_rtnl_state); | |
5108 | smp_mb__after_clear_bit(); | |
5109 | ||
5110 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
5111 | } | |
a3348722 | 5112 | |
a3348722 BW |
5113 | goto next_spqe; |
5114 | ||
5115 | case EVENT_RING_OPCODE_AFEX_VIF_LISTS: | |
5116 | f_obj->complete_cmd(bp, f_obj, | |
5117 | BNX2X_F_CMD_AFEX_VIFLISTS); | |
5118 | bnx2x_after_afex_vif_lists(bp, elem); | |
5119 | goto next_spqe; | |
619c5cb6 | 5120 | case EVENT_RING_OPCODE_FUNCTION_START: |
51c1a580 MS |
5121 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
5122 | "got FUNC_START ramrod\n"); | |
619c5cb6 VZ |
5123 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START)) |
5124 | break; | |
5125 | ||
5126 | goto next_spqe; | |
5127 | ||
5128 | case EVENT_RING_OPCODE_FUNCTION_STOP: | |
51c1a580 MS |
5129 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
5130 | "got FUNC_STOP ramrod\n"); | |
619c5cb6 VZ |
5131 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP)) |
5132 | break; | |
5133 | ||
5134 | goto next_spqe; | |
523224a3 DK |
5135 | } |
5136 | ||
5137 | switch (opcode | bp->state) { | |
619c5cb6 VZ |
5138 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
5139 | BNX2X_STATE_OPEN): | |
5140 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | | |
523224a3 | 5141 | BNX2X_STATE_OPENING_WAIT4_PORT): |
619c5cb6 VZ |
5142 | cid = elem->message.data.eth_event.echo & |
5143 | BNX2X_SWCID_MASK; | |
d6cae238 | 5144 | DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n", |
619c5cb6 VZ |
5145 | cid); |
5146 | rss_raw->clear_pending(rss_raw); | |
523224a3 DK |
5147 | break; |
5148 | ||
619c5cb6 VZ |
5149 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN): |
5150 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG): | |
5151 | case (EVENT_RING_OPCODE_SET_MAC | | |
523224a3 | 5152 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
619c5cb6 VZ |
5153 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
5154 | BNX2X_STATE_OPEN): | |
5155 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
5156 | BNX2X_STATE_DIAG): | |
5157 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
5158 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 5159 | DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n"); |
619c5cb6 | 5160 | bnx2x_handle_classification_eqe(bp, elem); |
523224a3 DK |
5161 | break; |
5162 | ||
619c5cb6 VZ |
5163 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
5164 | BNX2X_STATE_OPEN): | |
5165 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
5166 | BNX2X_STATE_DIAG): | |
5167 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
5168 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 5169 | DP(BNX2X_MSG_SP, "got mcast ramrod\n"); |
619c5cb6 | 5170 | bnx2x_handle_mcast_eqe(bp); |
523224a3 DK |
5171 | break; |
5172 | ||
619c5cb6 VZ |
5173 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
5174 | BNX2X_STATE_OPEN): | |
5175 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
5176 | BNX2X_STATE_DIAG): | |
5177 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
523224a3 | 5178 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
d6cae238 | 5179 | DP(BNX2X_MSG_SP, "got rx_mode ramrod\n"); |
619c5cb6 | 5180 | bnx2x_handle_rx_mode_eqe(bp); |
523224a3 DK |
5181 | break; |
5182 | default: | |
5183 | /* unknown event log error and continue */ | |
619c5cb6 VZ |
5184 | BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n", |
5185 | elem->message.opcode, bp->state); | |
523224a3 DK |
5186 | } |
5187 | next_spqe: | |
5188 | spqe_cnt++; | |
5189 | } /* for */ | |
5190 | ||
8fe23fbd | 5191 | smp_mb__before_atomic_inc(); |
6e30dd4e | 5192 | atomic_add(spqe_cnt, &bp->eq_spq_left); |
523224a3 DK |
5193 | |
5194 | bp->eq_cons = sw_cons; | |
5195 | bp->eq_prod = sw_prod; | |
5196 | /* Make sure that above mem writes were issued towards the memory */ | |
5197 | smp_wmb(); | |
5198 | ||
5199 | /* update producer */ | |
5200 | bnx2x_update_eq_prod(bp, bp->eq_prod); | |
5201 | } | |
5202 | ||
a2fbb9ea ET |
5203 | static void bnx2x_sp_task(struct work_struct *work) |
5204 | { | |
1cf167f2 | 5205 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
a2fbb9ea | 5206 | |
fd1fc79d | 5207 | DP(BNX2X_MSG_SP, "sp task invoked\n"); |
a2fbb9ea | 5208 | |
fd1fc79d AE |
5209 | /* make sure the atomic interupt_occurred has been written */ |
5210 | smp_rmb(); | |
5211 | if (atomic_read(&bp->interrupt_occurred)) { | |
a2fbb9ea | 5212 | |
fd1fc79d AE |
5213 | /* what work needs to be performed? */ |
5214 | u16 status = bnx2x_update_dsb_idx(bp); | |
cdaa7cb8 | 5215 | |
fd1fc79d AE |
5216 | DP(BNX2X_MSG_SP, "status %x\n", status); |
5217 | DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n"); | |
5218 | atomic_set(&bp->interrupt_occurred, 0); | |
5219 | ||
5220 | /* HW attentions */ | |
5221 | if (status & BNX2X_DEF_SB_ATT_IDX) { | |
5222 | bnx2x_attn_int(bp); | |
5223 | status &= ~BNX2X_DEF_SB_ATT_IDX; | |
5224 | } | |
5225 | ||
5226 | /* SP events: STAT_QUERY and others */ | |
5227 | if (status & BNX2X_DEF_SB_IDX) { | |
5228 | struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp); | |
523224a3 | 5229 | |
55c11941 | 5230 | if (FCOE_INIT(bp) && |
fd1fc79d AE |
5231 | (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) { |
5232 | /* Prevent local bottom-halves from running as | |
5233 | * we are going to change the local NAPI list. | |
5234 | */ | |
5235 | local_bh_disable(); | |
5236 | napi_schedule(&bnx2x_fcoe(bp, napi)); | |
5237 | local_bh_enable(); | |
5238 | } | |
5239 | ||
5240 | /* Handle EQ completions */ | |
5241 | bnx2x_eq_int(bp); | |
5242 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, | |
5243 | le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1); | |
5244 | ||
5245 | status &= ~BNX2X_DEF_SB_IDX; | |
019dbb4c | 5246 | } |
55c11941 | 5247 | |
fd1fc79d AE |
5248 | /* if status is non zero then perhaps something went wrong */ |
5249 | if (unlikely(status)) | |
5250 | DP(BNX2X_MSG_SP, | |
5251 | "got an unknown interrupt! (status 0x%x)\n", status); | |
523224a3 | 5252 | |
fd1fc79d AE |
5253 | /* ack status block only if something was actually handled */ |
5254 | bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID, | |
5255 | le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1); | |
523224a3 | 5256 | |
cdaa7cb8 VZ |
5257 | } |
5258 | ||
fd1fc79d AE |
5259 | /* must be called after the EQ processing (since eq leads to sriov |
5260 | * ramrod completion flows). | |
5261 | * This flow may have been scheduled by the arrival of a ramrod | |
5262 | * completion, or by the sriov code rescheduling itself. | |
5263 | */ | |
5264 | bnx2x_iov_sp_task(bp); | |
a3348722 BW |
5265 | |
5266 | /* afex - poll to check if VIFSET_ACK should be sent to MFW */ | |
5267 | if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, | |
5268 | &bp->sp_state)) { | |
5269 | bnx2x_link_report(bp); | |
5270 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
5271 | } | |
a2fbb9ea ET |
5272 | } |
5273 | ||
9f6c9258 | 5274 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
a2fbb9ea ET |
5275 | { |
5276 | struct net_device *dev = dev_instance; | |
5277 | struct bnx2x *bp = netdev_priv(dev); | |
5278 | ||
523224a3 DK |
5279 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, |
5280 | IGU_INT_DISABLE, 0); | |
a2fbb9ea ET |
5281 | |
5282 | #ifdef BNX2X_STOP_ON_ERROR | |
5283 | if (unlikely(bp->panic)) | |
5284 | return IRQ_HANDLED; | |
5285 | #endif | |
5286 | ||
55c11941 | 5287 | if (CNIC_LOADED(bp)) { |
993ac7b5 MC |
5288 | struct cnic_ops *c_ops; |
5289 | ||
5290 | rcu_read_lock(); | |
5291 | c_ops = rcu_dereference(bp->cnic_ops); | |
5292 | if (c_ops) | |
5293 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
5294 | rcu_read_unlock(); | |
5295 | } | |
55c11941 | 5296 | |
fd1fc79d AE |
5297 | /* schedule sp task to perform default status block work, ack |
5298 | * attentions and enable interrupts. | |
5299 | */ | |
5300 | bnx2x_schedule_sp_task(bp); | |
a2fbb9ea ET |
5301 | |
5302 | return IRQ_HANDLED; | |
5303 | } | |
5304 | ||
5305 | /* end of slow path */ | |
5306 | ||
619c5cb6 VZ |
5307 | |
5308 | void bnx2x_drv_pulse(struct bnx2x *bp) | |
5309 | { | |
5310 | SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb, | |
5311 | bp->fw_drv_pulse_wr_seq); | |
5312 | } | |
5313 | ||
a2fbb9ea ET |
5314 | static void bnx2x_timer(unsigned long data) |
5315 | { | |
5316 | struct bnx2x *bp = (struct bnx2x *) data; | |
5317 | ||
5318 | if (!netif_running(bp->dev)) | |
5319 | return; | |
5320 | ||
67c431a5 AE |
5321 | if (IS_PF(bp) && |
5322 | !BP_NOMCP(bp)) { | |
f2e0899f | 5323 | int mb_idx = BP_FW_MB_IDX(bp); |
a2fbb9ea ET |
5324 | u32 drv_pulse; |
5325 | u32 mcp_pulse; | |
5326 | ||
5327 | ++bp->fw_drv_pulse_wr_seq; | |
5328 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; | |
5329 | /* TBD - add SYSTEM_TIME */ | |
5330 | drv_pulse = bp->fw_drv_pulse_wr_seq; | |
619c5cb6 | 5331 | bnx2x_drv_pulse(bp); |
a2fbb9ea | 5332 | |
f2e0899f | 5333 | mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) & |
a2fbb9ea ET |
5334 | MCP_PULSE_SEQ_MASK); |
5335 | /* The delta between driver pulse and mcp response | |
5336 | * should be 1 (before mcp response) or 0 (after mcp response) | |
5337 | */ | |
5338 | if ((drv_pulse != mcp_pulse) && | |
5339 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { | |
5340 | /* someone lost a heartbeat... */ | |
5341 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", | |
5342 | drv_pulse, mcp_pulse); | |
5343 | } | |
5344 | } | |
5345 | ||
f34d28ea | 5346 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a | 5347 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
a2fbb9ea | 5348 | |
abc5a021 AE |
5349 | /* sample pf vf bulletin board for new posts from pf */ |
5350 | if (IS_VF(bp)) | |
5351 | bnx2x_sample_bulletin(bp); | |
5352 | ||
a2fbb9ea ET |
5353 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
5354 | } | |
5355 | ||
5356 | /* end of Statistics */ | |
5357 | ||
5358 | /* nic init */ | |
5359 | ||
5360 | /* | |
5361 | * nic init service functions | |
5362 | */ | |
5363 | ||
1191cb83 | 5364 | static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len) |
a2fbb9ea | 5365 | { |
523224a3 DK |
5366 | u32 i; |
5367 | if (!(len%4) && !(addr%4)) | |
5368 | for (i = 0; i < len; i += 4) | |
5369 | REG_WR(bp, addr + i, fill); | |
5370 | else | |
5371 | for (i = 0; i < len; i++) | |
5372 | REG_WR8(bp, addr + i, fill); | |
34f80b04 | 5373 | |
34f80b04 EG |
5374 | } |
5375 | ||
523224a3 | 5376 | /* helper: writes FP SP data to FW - data_size in dwords */ |
1191cb83 ED |
5377 | static void bnx2x_wr_fp_sb_data(struct bnx2x *bp, |
5378 | int fw_sb_id, | |
5379 | u32 *sb_data_p, | |
5380 | u32 data_size) | |
34f80b04 | 5381 | { |
a2fbb9ea | 5382 | int index; |
523224a3 DK |
5383 | for (index = 0; index < data_size; index++) |
5384 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
5385 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + | |
5386 | sizeof(u32)*index, | |
5387 | *(sb_data_p + index)); | |
5388 | } | |
a2fbb9ea | 5389 | |
1191cb83 | 5390 | static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id) |
523224a3 DK |
5391 | { |
5392 | u32 *sb_data_p; | |
5393 | u32 data_size = 0; | |
f2e0899f | 5394 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 | 5395 | struct hc_status_block_data_e1x sb_data_e1x; |
a2fbb9ea | 5396 | |
523224a3 | 5397 | /* disable the function first */ |
619c5cb6 | 5398 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 5399 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 5400 | sb_data_e2.common.state = SB_DISABLED; |
f2e0899f DK |
5401 | sb_data_e2.common.p_func.vf_valid = false; |
5402 | sb_data_p = (u32 *)&sb_data_e2; | |
5403 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
5404 | } else { | |
5405 | memset(&sb_data_e1x, 0, | |
5406 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 5407 | sb_data_e1x.common.state = SB_DISABLED; |
f2e0899f DK |
5408 | sb_data_e1x.common.p_func.vf_valid = false; |
5409 | sb_data_p = (u32 *)&sb_data_e1x; | |
5410 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
5411 | } | |
523224a3 | 5412 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
a2fbb9ea | 5413 | |
523224a3 DK |
5414 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
5415 | CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0, | |
5416 | CSTORM_STATUS_BLOCK_SIZE); | |
5417 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5418 | CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0, | |
5419 | CSTORM_SYNC_BLOCK_SIZE); | |
5420 | } | |
34f80b04 | 5421 | |
523224a3 | 5422 | /* helper: writes SP SB data to FW */ |
1191cb83 | 5423 | static void bnx2x_wr_sp_sb_data(struct bnx2x *bp, |
523224a3 DK |
5424 | struct hc_sp_status_block_data *sp_sb_data) |
5425 | { | |
5426 | int func = BP_FUNC(bp); | |
5427 | int i; | |
5428 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
5429 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
5430 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
5431 | i*sizeof(u32), | |
5432 | *((u32 *)sp_sb_data + i)); | |
34f80b04 EG |
5433 | } |
5434 | ||
1191cb83 | 5435 | static void bnx2x_zero_sp_sb(struct bnx2x *bp) |
34f80b04 EG |
5436 | { |
5437 | int func = BP_FUNC(bp); | |
523224a3 DK |
5438 | struct hc_sp_status_block_data sp_sb_data; |
5439 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
a2fbb9ea | 5440 | |
619c5cb6 | 5441 | sp_sb_data.state = SB_DISABLED; |
523224a3 DK |
5442 | sp_sb_data.p_func.vf_valid = false; |
5443 | ||
5444 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); | |
5445 | ||
5446 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5447 | CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0, | |
5448 | CSTORM_SP_STATUS_BLOCK_SIZE); | |
5449 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5450 | CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0, | |
5451 | CSTORM_SP_SYNC_BLOCK_SIZE); | |
5452 | ||
5453 | } | |
5454 | ||
5455 | ||
1191cb83 | 5456 | static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, |
523224a3 DK |
5457 | int igu_sb_id, int igu_seg_id) |
5458 | { | |
5459 | hc_sm->igu_sb_id = igu_sb_id; | |
5460 | hc_sm->igu_seg_id = igu_seg_id; | |
5461 | hc_sm->timer_value = 0xFF; | |
5462 | hc_sm->time_to_expire = 0xFFFFFFFF; | |
a2fbb9ea ET |
5463 | } |
5464 | ||
150966ad AE |
5465 | |
5466 | /* allocates state machine ids. */ | |
1191cb83 | 5467 | static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data) |
150966ad AE |
5468 | { |
5469 | /* zero out state machine indices */ | |
5470 | /* rx indices */ | |
5471 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
5472 | ||
5473 | /* tx indices */ | |
5474 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
5475 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID; | |
5476 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID; | |
5477 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID; | |
5478 | ||
5479 | /* map indices */ | |
5480 | /* rx indices */ | |
5481 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |= | |
5482 | SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5483 | ||
5484 | /* tx indices */ | |
5485 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |= | |
5486 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5487 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |= | |
5488 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5489 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |= | |
5490 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5491 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |= | |
5492 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5493 | } | |
5494 | ||
b93288d5 | 5495 | void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid, |
523224a3 | 5496 | u8 vf_valid, int fw_sb_id, int igu_sb_id) |
a2fbb9ea | 5497 | { |
523224a3 DK |
5498 | int igu_seg_id; |
5499 | ||
f2e0899f | 5500 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
5501 | struct hc_status_block_data_e1x sb_data_e1x; |
5502 | struct hc_status_block_sm *hc_sm_p; | |
523224a3 DK |
5503 | int data_size; |
5504 | u32 *sb_data_p; | |
5505 | ||
f2e0899f DK |
5506 | if (CHIP_INT_MODE_IS_BC(bp)) |
5507 | igu_seg_id = HC_SEG_ACCESS_NORM; | |
5508 | else | |
5509 | igu_seg_id = IGU_SEG_ACCESS_NORM; | |
523224a3 DK |
5510 | |
5511 | bnx2x_zero_fp_sb(bp, fw_sb_id); | |
5512 | ||
619c5cb6 | 5513 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 5514 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 5515 | sb_data_e2.common.state = SB_ENABLED; |
f2e0899f DK |
5516 | sb_data_e2.common.p_func.pf_id = BP_FUNC(bp); |
5517 | sb_data_e2.common.p_func.vf_id = vfid; | |
5518 | sb_data_e2.common.p_func.vf_valid = vf_valid; | |
5519 | sb_data_e2.common.p_func.vnic_id = BP_VN(bp); | |
5520 | sb_data_e2.common.same_igu_sb_1b = true; | |
5521 | sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping); | |
5522 | sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping); | |
5523 | hc_sm_p = sb_data_e2.common.state_machine; | |
f2e0899f DK |
5524 | sb_data_p = (u32 *)&sb_data_e2; |
5525 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
150966ad | 5526 | bnx2x_map_sb_state_machines(sb_data_e2.index_data); |
f2e0899f DK |
5527 | } else { |
5528 | memset(&sb_data_e1x, 0, | |
5529 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 5530 | sb_data_e1x.common.state = SB_ENABLED; |
f2e0899f DK |
5531 | sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp); |
5532 | sb_data_e1x.common.p_func.vf_id = 0xff; | |
5533 | sb_data_e1x.common.p_func.vf_valid = false; | |
5534 | sb_data_e1x.common.p_func.vnic_id = BP_VN(bp); | |
5535 | sb_data_e1x.common.same_igu_sb_1b = true; | |
5536 | sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping); | |
5537 | sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping); | |
5538 | hc_sm_p = sb_data_e1x.common.state_machine; | |
f2e0899f DK |
5539 | sb_data_p = (u32 *)&sb_data_e1x; |
5540 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
150966ad | 5541 | bnx2x_map_sb_state_machines(sb_data_e1x.index_data); |
f2e0899f | 5542 | } |
523224a3 DK |
5543 | |
5544 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], | |
5545 | igu_sb_id, igu_seg_id); | |
5546 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], | |
5547 | igu_sb_id, igu_seg_id); | |
5548 | ||
51c1a580 | 5549 | DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id); |
523224a3 | 5550 | |
86564c3f | 5551 | /* write indices to HW - PCI guarantees endianity of regpairs */ |
523224a3 DK |
5552 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
5553 | } | |
5554 | ||
619c5cb6 | 5555 | static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id, |
523224a3 DK |
5556 | u16 tx_usec, u16 rx_usec) |
5557 | { | |
6383c0b3 | 5558 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS, |
523224a3 | 5559 | false, rx_usec); |
6383c0b3 AE |
5560 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, |
5561 | HC_INDEX_ETH_TX_CQ_CONS_COS0, false, | |
5562 | tx_usec); | |
5563 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5564 | HC_INDEX_ETH_TX_CQ_CONS_COS1, false, | |
5565 | tx_usec); | |
5566 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5567 | HC_INDEX_ETH_TX_CQ_CONS_COS2, false, | |
5568 | tx_usec); | |
523224a3 | 5569 | } |
f2e0899f | 5570 | |
523224a3 DK |
5571 | static void bnx2x_init_def_sb(struct bnx2x *bp) |
5572 | { | |
5573 | struct host_sp_status_block *def_sb = bp->def_status_blk; | |
5574 | dma_addr_t mapping = bp->def_status_blk_mapping; | |
5575 | int igu_sp_sb_index; | |
5576 | int igu_seg_id; | |
34f80b04 EG |
5577 | int port = BP_PORT(bp); |
5578 | int func = BP_FUNC(bp); | |
f2eaeb58 | 5579 | int reg_offset, reg_offset_en5; |
a2fbb9ea | 5580 | u64 section; |
523224a3 DK |
5581 | int index; |
5582 | struct hc_sp_status_block_data sp_sb_data; | |
5583 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
5584 | ||
f2e0899f DK |
5585 | if (CHIP_INT_MODE_IS_BC(bp)) { |
5586 | igu_sp_sb_index = DEF_SB_IGU_ID; | |
5587 | igu_seg_id = HC_SEG_ACCESS_DEF; | |
5588 | } else { | |
5589 | igu_sp_sb_index = bp->igu_dsb_id; | |
5590 | igu_seg_id = IGU_SEG_ACCESS_DEF; | |
5591 | } | |
a2fbb9ea ET |
5592 | |
5593 | /* ATTN */ | |
523224a3 | 5594 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
a2fbb9ea | 5595 | atten_status_block); |
523224a3 | 5596 | def_sb->atten_status_block.status_block_id = igu_sp_sb_index; |
a2fbb9ea | 5597 | |
49d66772 ET |
5598 | bp->attn_state = 0; |
5599 | ||
a2fbb9ea ET |
5600 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
5601 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
f2eaeb58 DK |
5602 | reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 : |
5603 | MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0); | |
34f80b04 | 5604 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
523224a3 DK |
5605 | int sindex; |
5606 | /* take care of sig[0]..sig[4] */ | |
5607 | for (sindex = 0; sindex < 4; sindex++) | |
5608 | bp->attn_group[index].sig[sindex] = | |
5609 | REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index); | |
f2e0899f | 5610 | |
619c5cb6 | 5611 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
5612 | /* |
5613 | * enable5 is separate from the rest of the registers, | |
5614 | * and therefore the address skip is 4 | |
5615 | * and not 16 between the different groups | |
5616 | */ | |
5617 | bp->attn_group[index].sig[4] = REG_RD(bp, | |
f2eaeb58 | 5618 | reg_offset_en5 + 0x4*index); |
f2e0899f DK |
5619 | else |
5620 | bp->attn_group[index].sig[4] = 0; | |
a2fbb9ea ET |
5621 | } |
5622 | ||
f2e0899f DK |
5623 | if (bp->common.int_block == INT_BLOCK_HC) { |
5624 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : | |
5625 | HC_REG_ATTN_MSG0_ADDR_L); | |
5626 | ||
5627 | REG_WR(bp, reg_offset, U64_LO(section)); | |
5628 | REG_WR(bp, reg_offset + 4, U64_HI(section)); | |
619c5cb6 | 5629 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
5630 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); |
5631 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); | |
5632 | } | |
a2fbb9ea | 5633 | |
523224a3 DK |
5634 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
5635 | sp_sb); | |
a2fbb9ea | 5636 | |
523224a3 | 5637 | bnx2x_zero_sp_sb(bp); |
a2fbb9ea | 5638 | |
86564c3f | 5639 | /* PCI guarantees endianity of regpairs */ |
619c5cb6 | 5640 | sp_sb_data.state = SB_ENABLED; |
523224a3 DK |
5641 | sp_sb_data.host_sb_addr.lo = U64_LO(section); |
5642 | sp_sb_data.host_sb_addr.hi = U64_HI(section); | |
5643 | sp_sb_data.igu_sb_id = igu_sp_sb_index; | |
5644 | sp_sb_data.igu_seg_id = igu_seg_id; | |
5645 | sp_sb_data.p_func.pf_id = func; | |
f2e0899f | 5646 | sp_sb_data.p_func.vnic_id = BP_VN(bp); |
523224a3 | 5647 | sp_sb_data.p_func.vf_id = 0xff; |
a2fbb9ea | 5648 | |
523224a3 | 5649 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
49d66772 | 5650 | |
523224a3 | 5651 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); |
a2fbb9ea ET |
5652 | } |
5653 | ||
9f6c9258 | 5654 | void bnx2x_update_coalesce(struct bnx2x *bp) |
a2fbb9ea | 5655 | { |
a2fbb9ea ET |
5656 | int i; |
5657 | ||
ec6ba945 | 5658 | for_each_eth_queue(bp, i) |
523224a3 | 5659 | bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id, |
423cfa7e | 5660 | bp->tx_ticks, bp->rx_ticks); |
a2fbb9ea ET |
5661 | } |
5662 | ||
a2fbb9ea ET |
5663 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
5664 | { | |
a2fbb9ea | 5665 | spin_lock_init(&bp->spq_lock); |
6e30dd4e | 5666 | atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING); |
a2fbb9ea | 5667 | |
a2fbb9ea | 5668 | bp->spq_prod_idx = 0; |
a2fbb9ea ET |
5669 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
5670 | bp->spq_prod_bd = bp->spq; | |
5671 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; | |
a2fbb9ea ET |
5672 | } |
5673 | ||
523224a3 | 5674 | static void bnx2x_init_eq_ring(struct bnx2x *bp) |
a2fbb9ea ET |
5675 | { |
5676 | int i; | |
523224a3 DK |
5677 | for (i = 1; i <= NUM_EQ_PAGES; i++) { |
5678 | union event_ring_elem *elem = | |
5679 | &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1]; | |
a2fbb9ea | 5680 | |
523224a3 DK |
5681 | elem->next_page.addr.hi = |
5682 | cpu_to_le32(U64_HI(bp->eq_mapping + | |
5683 | BCM_PAGE_SIZE * (i % NUM_EQ_PAGES))); | |
5684 | elem->next_page.addr.lo = | |
5685 | cpu_to_le32(U64_LO(bp->eq_mapping + | |
5686 | BCM_PAGE_SIZE*(i % NUM_EQ_PAGES))); | |
a2fbb9ea | 5687 | } |
523224a3 DK |
5688 | bp->eq_cons = 0; |
5689 | bp->eq_prod = NUM_EQ_DESC; | |
5690 | bp->eq_cons_sb = BNX2X_EQ_INDEX; | |
6e30dd4e VZ |
5691 | /* we want a warning message before it gets rought... */ |
5692 | atomic_set(&bp->eq_spq_left, | |
5693 | min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1); | |
a2fbb9ea ET |
5694 | } |
5695 | ||
619c5cb6 | 5696 | /* called with netif_addr_lock_bh() */ |
924d75ab YM |
5697 | int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id, |
5698 | unsigned long rx_mode_flags, | |
5699 | unsigned long rx_accept_flags, | |
5700 | unsigned long tx_accept_flags, | |
5701 | unsigned long ramrod_flags) | |
ab532cf3 | 5702 | { |
619c5cb6 VZ |
5703 | struct bnx2x_rx_mode_ramrod_params ramrod_param; |
5704 | int rc; | |
5705 | ||
5706 | memset(&ramrod_param, 0, sizeof(ramrod_param)); | |
5707 | ||
5708 | /* Prepare ramrod parameters */ | |
5709 | ramrod_param.cid = 0; | |
5710 | ramrod_param.cl_id = cl_id; | |
5711 | ramrod_param.rx_mode_obj = &bp->rx_mode_obj; | |
5712 | ramrod_param.func_id = BP_FUNC(bp); | |
ab532cf3 | 5713 | |
619c5cb6 VZ |
5714 | ramrod_param.pstate = &bp->sp_state; |
5715 | ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING; | |
ab532cf3 | 5716 | |
619c5cb6 VZ |
5717 | ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata); |
5718 | ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata); | |
5719 | ||
5720 | set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
5721 | ||
5722 | ramrod_param.ramrod_flags = ramrod_flags; | |
5723 | ramrod_param.rx_mode_flags = rx_mode_flags; | |
5724 | ||
5725 | ramrod_param.rx_accept_flags = rx_accept_flags; | |
5726 | ramrod_param.tx_accept_flags = tx_accept_flags; | |
5727 | ||
5728 | rc = bnx2x_config_rx_mode(bp, &ramrod_param); | |
5729 | if (rc < 0) { | |
5730 | BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode); | |
924d75ab | 5731 | return rc; |
619c5cb6 | 5732 | } |
924d75ab YM |
5733 | |
5734 | return 0; | |
a2fbb9ea ET |
5735 | } |
5736 | ||
86564c3f YM |
5737 | static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode, |
5738 | unsigned long *rx_accept_flags, | |
5739 | unsigned long *tx_accept_flags) | |
471de716 | 5740 | { |
924d75ab YM |
5741 | /* Clear the flags first */ |
5742 | *rx_accept_flags = 0; | |
5743 | *tx_accept_flags = 0; | |
619c5cb6 | 5744 | |
924d75ab | 5745 | switch (rx_mode) { |
619c5cb6 VZ |
5746 | case BNX2X_RX_MODE_NONE: |
5747 | /* | |
5748 | * 'drop all' supersedes any accept flags that may have been | |
5749 | * passed to the function. | |
5750 | */ | |
5751 | break; | |
5752 | case BNX2X_RX_MODE_NORMAL: | |
924d75ab YM |
5753 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); |
5754 | __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags); | |
5755 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5756 | |
5757 | /* internal switching mode */ | |
924d75ab YM |
5758 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
5759 | __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags); | |
5760 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5761 | |
5762 | break; | |
5763 | case BNX2X_RX_MODE_ALLMULTI: | |
924d75ab YM |
5764 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); |
5765 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags); | |
5766 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5767 | |
5768 | /* internal switching mode */ | |
924d75ab YM |
5769 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
5770 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags); | |
5771 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5772 | |
5773 | break; | |
5774 | case BNX2X_RX_MODE_PROMISC: | |
5775 | /* According to deffinition of SI mode, iface in promisc mode | |
5776 | * should receive matched and unmatched (in resolution of port) | |
5777 | * unicast packets. | |
5778 | */ | |
924d75ab YM |
5779 | __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags); |
5780 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); | |
5781 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags); | |
5782 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5783 | |
5784 | /* internal switching mode */ | |
924d75ab YM |
5785 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags); |
5786 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5787 | |
5788 | if (IS_MF_SI(bp)) | |
924d75ab | 5789 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags); |
619c5cb6 | 5790 | else |
924d75ab | 5791 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
619c5cb6 VZ |
5792 | |
5793 | break; | |
5794 | default: | |
924d75ab YM |
5795 | BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode); |
5796 | return -EINVAL; | |
619c5cb6 | 5797 | } |
de832a55 | 5798 | |
924d75ab | 5799 | /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */ |
619c5cb6 | 5800 | if (bp->rx_mode != BNX2X_RX_MODE_NONE) { |
924d75ab YM |
5801 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags); |
5802 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags); | |
34f80b04 EG |
5803 | } |
5804 | ||
924d75ab YM |
5805 | return 0; |
5806 | } | |
5807 | ||
5808 | /* called with netif_addr_lock_bh() */ | |
5809 | int bnx2x_set_storm_rx_mode(struct bnx2x *bp) | |
5810 | { | |
5811 | unsigned long rx_mode_flags = 0, ramrod_flags = 0; | |
5812 | unsigned long rx_accept_flags = 0, tx_accept_flags = 0; | |
5813 | int rc; | |
5814 | ||
5815 | if (!NO_FCOE(bp)) | |
5816 | /* Configure rx_mode of FCoE Queue */ | |
5817 | __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags); | |
5818 | ||
5819 | rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags, | |
5820 | &tx_accept_flags); | |
5821 | if (rc) | |
5822 | return rc; | |
5823 | ||
619c5cb6 VZ |
5824 | __set_bit(RAMROD_RX, &ramrod_flags); |
5825 | __set_bit(RAMROD_TX, &ramrod_flags); | |
5826 | ||
924d75ab YM |
5827 | return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, |
5828 | rx_accept_flags, tx_accept_flags, | |
5829 | ramrod_flags); | |
619c5cb6 VZ |
5830 | } |
5831 | ||
5832 | static void bnx2x_init_internal_common(struct bnx2x *bp) | |
5833 | { | |
5834 | int i; | |
5835 | ||
0793f83f DK |
5836 | if (IS_MF_SI(bp)) |
5837 | /* | |
5838 | * In switch independent mode, the TSTORM needs to accept | |
5839 | * packets that failed classification, since approximate match | |
5840 | * mac addresses aren't written to NIG LLH | |
5841 | */ | |
5842 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
5843 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2); | |
619c5cb6 VZ |
5844 | else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */ |
5845 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
5846 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0); | |
0793f83f | 5847 | |
523224a3 DK |
5848 | /* Zero this manually as its initialization is |
5849 | currently missing in the initTool */ | |
5850 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) | |
ca00392c | 5851 | REG_WR(bp, BAR_USTRORM_INTMEM + |
523224a3 | 5852 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
619c5cb6 | 5853 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
5854 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET, |
5855 | CHIP_INT_MODE_IS_BC(bp) ? | |
5856 | HC_IGU_BC_MODE : HC_IGU_NBC_MODE); | |
5857 | } | |
523224a3 | 5858 | } |
8a1c38d1 | 5859 | |
471de716 EG |
5860 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
5861 | { | |
5862 | switch (load_code) { | |
5863 | case FW_MSG_CODE_DRV_LOAD_COMMON: | |
f2e0899f | 5864 | case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: |
471de716 EG |
5865 | bnx2x_init_internal_common(bp); |
5866 | /* no break */ | |
5867 | ||
5868 | case FW_MSG_CODE_DRV_LOAD_PORT: | |
619c5cb6 | 5869 | /* nothing to do */ |
471de716 EG |
5870 | /* no break */ |
5871 | ||
5872 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: | |
523224a3 DK |
5873 | /* internal memory per function is |
5874 | initialized inside bnx2x_pf_init */ | |
471de716 EG |
5875 | break; |
5876 | ||
5877 | default: | |
5878 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); | |
5879 | break; | |
5880 | } | |
5881 | } | |
5882 | ||
619c5cb6 | 5883 | static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp) |
523224a3 | 5884 | { |
55c11941 | 5885 | return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp); |
619c5cb6 | 5886 | } |
523224a3 | 5887 | |
619c5cb6 VZ |
5888 | static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp) |
5889 | { | |
55c11941 | 5890 | return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp); |
619c5cb6 VZ |
5891 | } |
5892 | ||
1191cb83 | 5893 | static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp) |
619c5cb6 VZ |
5894 | { |
5895 | if (CHIP_IS_E1x(fp->bp)) | |
5896 | return BP_L_ID(fp->bp) + fp->index; | |
5897 | else /* We want Client ID to be the same as IGU SB ID for 57712 */ | |
5898 | return bnx2x_fp_igu_sb_id(fp); | |
5899 | } | |
5900 | ||
6383c0b3 | 5901 | static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx) |
619c5cb6 VZ |
5902 | { |
5903 | struct bnx2x_fastpath *fp = &bp->fp[fp_idx]; | |
6383c0b3 | 5904 | u8 cos; |
619c5cb6 | 5905 | unsigned long q_type = 0; |
6383c0b3 | 5906 | u32 cids[BNX2X_MULTI_TX_COS] = { 0 }; |
f233cafe | 5907 | fp->rx_queue = fp_idx; |
b3b83c3f | 5908 | fp->cid = fp_idx; |
619c5cb6 VZ |
5909 | fp->cl_id = bnx2x_fp_cl_id(fp); |
5910 | fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp); | |
5911 | fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp); | |
523224a3 | 5912 | /* qZone id equals to FW (per path) client id */ |
619c5cb6 VZ |
5913 | fp->cl_qzone_id = bnx2x_fp_qzone_id(fp); |
5914 | ||
523224a3 | 5915 | /* init shortcut */ |
619c5cb6 | 5916 | fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp); |
7a752993 | 5917 | |
523224a3 DK |
5918 | /* Setup SB indicies */ |
5919 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; | |
523224a3 | 5920 | |
619c5cb6 VZ |
5921 | /* Configure Queue State object */ |
5922 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); | |
5923 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); | |
6383c0b3 AE |
5924 | |
5925 | BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS); | |
5926 | ||
5927 | /* init tx data */ | |
5928 | for_each_cos_in_tx_queue(fp, cos) { | |
65565884 MS |
5929 | bnx2x_init_txdata(bp, fp->txdata_ptr[cos], |
5930 | CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp), | |
5931 | FP_COS_TO_TXQ(fp, cos, bp), | |
5932 | BNX2X_TX_SB_INDEX_BASE + cos, fp); | |
5933 | cids[cos] = fp->txdata_ptr[cos]->cid; | |
6383c0b3 AE |
5934 | } |
5935 | ||
ad5afc89 AE |
5936 | /* nothing more for vf to do here */ |
5937 | if (IS_VF(bp)) | |
5938 | return; | |
5939 | ||
5940 | bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false, | |
5941 | fp->fw_sb_id, fp->igu_sb_id); | |
5942 | bnx2x_update_fpsb_idx(fp); | |
15192a8c BW |
5943 | bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids, |
5944 | fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata), | |
6383c0b3 | 5945 | bnx2x_sp_mapping(bp, q_rdata), q_type); |
619c5cb6 VZ |
5946 | |
5947 | /** | |
5948 | * Configure classification DBs: Always enable Tx switching | |
5949 | */ | |
5950 | bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX); | |
5951 | ||
ad5afc89 AE |
5952 | DP(NETIF_MSG_IFUP, |
5953 | "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n", | |
5954 | fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id, | |
5955 | fp->igu_sb_id); | |
523224a3 DK |
5956 | } |
5957 | ||
1191cb83 ED |
5958 | static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata) |
5959 | { | |
5960 | int i; | |
5961 | ||
5962 | for (i = 1; i <= NUM_TX_RINGS; i++) { | |
5963 | struct eth_tx_next_bd *tx_next_bd = | |
5964 | &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd; | |
5965 | ||
5966 | tx_next_bd->addr_hi = | |
5967 | cpu_to_le32(U64_HI(txdata->tx_desc_mapping + | |
5968 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); | |
5969 | tx_next_bd->addr_lo = | |
5970 | cpu_to_le32(U64_LO(txdata->tx_desc_mapping + | |
5971 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); | |
5972 | } | |
5973 | ||
5974 | SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1); | |
5975 | txdata->tx_db.data.zero_fill1 = 0; | |
5976 | txdata->tx_db.data.prod = 0; | |
5977 | ||
5978 | txdata->tx_pkt_prod = 0; | |
5979 | txdata->tx_pkt_cons = 0; | |
5980 | txdata->tx_bd_prod = 0; | |
5981 | txdata->tx_bd_cons = 0; | |
5982 | txdata->tx_pkt = 0; | |
5983 | } | |
5984 | ||
55c11941 MS |
5985 | static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp) |
5986 | { | |
5987 | int i; | |
5988 | ||
5989 | for_each_tx_queue_cnic(bp, i) | |
5990 | bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]); | |
5991 | } | |
1191cb83 ED |
5992 | static void bnx2x_init_tx_rings(struct bnx2x *bp) |
5993 | { | |
5994 | int i; | |
5995 | u8 cos; | |
5996 | ||
55c11941 | 5997 | for_each_eth_queue(bp, i) |
1191cb83 | 5998 | for_each_cos_in_tx_queue(&bp->fp[i], cos) |
65565884 | 5999 | bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]); |
1191cb83 ED |
6000 | } |
6001 | ||
55c11941 | 6002 | void bnx2x_nic_init_cnic(struct bnx2x *bp) |
a2fbb9ea | 6003 | { |
ec6ba945 VZ |
6004 | if (!NO_FCOE(bp)) |
6005 | bnx2x_init_fcoe_fp(bp); | |
523224a3 DK |
6006 | |
6007 | bnx2x_init_sb(bp, bp->cnic_sb_mapping, | |
6008 | BNX2X_VF_ID_INVALID, false, | |
619c5cb6 | 6009 | bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp)); |
523224a3 | 6010 | |
55c11941 MS |
6011 | /* ensure status block indices were read */ |
6012 | rmb(); | |
6013 | bnx2x_init_rx_rings_cnic(bp); | |
6014 | bnx2x_init_tx_rings_cnic(bp); | |
6015 | ||
6016 | /* flush all */ | |
6017 | mb(); | |
6018 | mmiowb(); | |
6019 | } | |
a2fbb9ea | 6020 | |
55c11941 MS |
6021 | void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
6022 | { | |
6023 | int i; | |
6024 | ||
6025 | for_each_eth_queue(bp, i) | |
6026 | bnx2x_init_eth_fp(bp, i); | |
ad5afc89 AE |
6027 | |
6028 | /* ensure status block indices were read */ | |
6029 | rmb(); | |
6030 | bnx2x_init_rx_rings(bp); | |
6031 | bnx2x_init_tx_rings(bp); | |
6032 | ||
6033 | if (IS_VF(bp)) | |
6034 | return; | |
6035 | ||
020c7e3f YR |
6036 | /* Initialize MOD_ABS interrupts */ |
6037 | bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id, | |
6038 | bp->common.shmem_base, bp->common.shmem2_base, | |
6039 | BP_PORT(bp)); | |
16119785 | 6040 | |
523224a3 | 6041 | bnx2x_init_def_sb(bp); |
5c862848 | 6042 | bnx2x_update_dsb_idx(bp); |
a2fbb9ea | 6043 | bnx2x_init_sp_ring(bp); |
523224a3 | 6044 | bnx2x_init_eq_ring(bp); |
471de716 | 6045 | bnx2x_init_internal(bp, load_code); |
523224a3 | 6046 | bnx2x_pf_init(bp); |
0ef00459 EG |
6047 | bnx2x_stats_init(bp); |
6048 | ||
0ef00459 EG |
6049 | /* flush all before enabling interrupts */ |
6050 | mb(); | |
6051 | mmiowb(); | |
6052 | ||
615f8fd9 | 6053 | bnx2x_int_enable(bp); |
eb8da205 EG |
6054 | |
6055 | /* Check for SPIO5 */ | |
6056 | bnx2x_attn_int_deasserted0(bp, | |
6057 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & | |
6058 | AEU_INPUTS_ATTN_BITS_SPIO5); | |
a2fbb9ea ET |
6059 | } |
6060 | ||
6061 | /* end of nic init */ | |
6062 | ||
6063 | /* | |
6064 | * gzip service functions | |
6065 | */ | |
6066 | ||
6067 | static int bnx2x_gunzip_init(struct bnx2x *bp) | |
6068 | { | |
1a983142 FT |
6069 | bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE, |
6070 | &bp->gunzip_mapping, GFP_KERNEL); | |
a2fbb9ea ET |
6071 | if (bp->gunzip_buf == NULL) |
6072 | goto gunzip_nomem1; | |
6073 | ||
6074 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); | |
6075 | if (bp->strm == NULL) | |
6076 | goto gunzip_nomem2; | |
6077 | ||
7ab24bfd | 6078 | bp->strm->workspace = vmalloc(zlib_inflate_workspacesize()); |
a2fbb9ea ET |
6079 | if (bp->strm->workspace == NULL) |
6080 | goto gunzip_nomem3; | |
6081 | ||
6082 | return 0; | |
6083 | ||
6084 | gunzip_nomem3: | |
6085 | kfree(bp->strm); | |
6086 | bp->strm = NULL; | |
6087 | ||
6088 | gunzip_nomem2: | |
1a983142 FT |
6089 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
6090 | bp->gunzip_mapping); | |
a2fbb9ea ET |
6091 | bp->gunzip_buf = NULL; |
6092 | ||
6093 | gunzip_nomem1: | |
51c1a580 | 6094 | BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n"); |
a2fbb9ea ET |
6095 | return -ENOMEM; |
6096 | } | |
6097 | ||
6098 | static void bnx2x_gunzip_end(struct bnx2x *bp) | |
6099 | { | |
b3b83c3f | 6100 | if (bp->strm) { |
7ab24bfd | 6101 | vfree(bp->strm->workspace); |
b3b83c3f DK |
6102 | kfree(bp->strm); |
6103 | bp->strm = NULL; | |
6104 | } | |
a2fbb9ea ET |
6105 | |
6106 | if (bp->gunzip_buf) { | |
1a983142 FT |
6107 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
6108 | bp->gunzip_mapping); | |
a2fbb9ea ET |
6109 | bp->gunzip_buf = NULL; |
6110 | } | |
6111 | } | |
6112 | ||
94a78b79 | 6113 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
a2fbb9ea ET |
6114 | { |
6115 | int n, rc; | |
6116 | ||
6117 | /* check gzip header */ | |
94a78b79 VZ |
6118 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
6119 | BNX2X_ERR("Bad gzip header\n"); | |
a2fbb9ea | 6120 | return -EINVAL; |
94a78b79 | 6121 | } |
a2fbb9ea ET |
6122 | |
6123 | n = 10; | |
6124 | ||
34f80b04 | 6125 | #define FNAME 0x8 |
a2fbb9ea ET |
6126 | |
6127 | if (zbuf[3] & FNAME) | |
6128 | while ((zbuf[n++] != 0) && (n < len)); | |
6129 | ||
94a78b79 | 6130 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
a2fbb9ea ET |
6131 | bp->strm->avail_in = len - n; |
6132 | bp->strm->next_out = bp->gunzip_buf; | |
6133 | bp->strm->avail_out = FW_BUF_SIZE; | |
6134 | ||
6135 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); | |
6136 | if (rc != Z_OK) | |
6137 | return rc; | |
6138 | ||
6139 | rc = zlib_inflate(bp->strm, Z_FINISH); | |
6140 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) | |
7995c64e JP |
6141 | netdev_err(bp->dev, "Firmware decompression error: %s\n", |
6142 | bp->strm->msg); | |
a2fbb9ea ET |
6143 | |
6144 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); | |
6145 | if (bp->gunzip_outlen & 0x3) | |
51c1a580 MS |
6146 | netdev_err(bp->dev, |
6147 | "Firmware decompression error: gunzip_outlen (%d) not aligned\n", | |
cdaa7cb8 | 6148 | bp->gunzip_outlen); |
a2fbb9ea ET |
6149 | bp->gunzip_outlen >>= 2; |
6150 | ||
6151 | zlib_inflateEnd(bp->strm); | |
6152 | ||
6153 | if (rc == Z_STREAM_END) | |
6154 | return 0; | |
6155 | ||
6156 | return rc; | |
6157 | } | |
6158 | ||
6159 | /* nic load/unload */ | |
6160 | ||
6161 | /* | |
34f80b04 | 6162 | * General service functions |
a2fbb9ea ET |
6163 | */ |
6164 | ||
6165 | /* send a NIG loopback debug packet */ | |
6166 | static void bnx2x_lb_pckt(struct bnx2x *bp) | |
6167 | { | |
a2fbb9ea | 6168 | u32 wb_write[3]; |
a2fbb9ea ET |
6169 | |
6170 | /* Ethernet source and destination addresses */ | |
a2fbb9ea ET |
6171 | wb_write[0] = 0x55555555; |
6172 | wb_write[1] = 0x55555555; | |
34f80b04 | 6173 | wb_write[2] = 0x20; /* SOP */ |
a2fbb9ea | 6174 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
6175 | |
6176 | /* NON-IP protocol */ | |
a2fbb9ea ET |
6177 | wb_write[0] = 0x09000000; |
6178 | wb_write[1] = 0x55555555; | |
34f80b04 | 6179 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
a2fbb9ea | 6180 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
6181 | } |
6182 | ||
6183 | /* some of the internal memories | |
6184 | * are not directly readable from the driver | |
6185 | * to test them we send debug packets | |
6186 | */ | |
6187 | static int bnx2x_int_mem_test(struct bnx2x *bp) | |
6188 | { | |
6189 | int factor; | |
6190 | int count, i; | |
6191 | u32 val = 0; | |
6192 | ||
ad8d3948 | 6193 | if (CHIP_REV_IS_FPGA(bp)) |
a2fbb9ea | 6194 | factor = 120; |
ad8d3948 EG |
6195 | else if (CHIP_REV_IS_EMUL(bp)) |
6196 | factor = 200; | |
6197 | else | |
a2fbb9ea | 6198 | factor = 1; |
a2fbb9ea | 6199 | |
a2fbb9ea ET |
6200 | /* Disable inputs of parser neighbor blocks */ |
6201 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
6202 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
6203 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 6204 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
6205 | |
6206 | /* Write 0 to parser credits for CFC search request */ | |
6207 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
6208 | ||
6209 | /* send Ethernet packet */ | |
6210 | bnx2x_lb_pckt(bp); | |
6211 | ||
6212 | /* TODO do i reset NIG statistic? */ | |
6213 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
6214 | count = 1000 * factor; | |
6215 | while (count) { | |
34f80b04 | 6216 | |
a2fbb9ea ET |
6217 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
6218 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
6219 | if (val == 0x10) |
6220 | break; | |
6221 | ||
6222 | msleep(10); | |
6223 | count--; | |
6224 | } | |
6225 | if (val != 0x10) { | |
6226 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
6227 | return -1; | |
6228 | } | |
6229 | ||
6230 | /* Wait until PRS register shows 1 packet */ | |
6231 | count = 1000 * factor; | |
6232 | while (count) { | |
6233 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
a2fbb9ea ET |
6234 | if (val == 1) |
6235 | break; | |
6236 | ||
6237 | msleep(10); | |
6238 | count--; | |
6239 | } | |
6240 | if (val != 0x1) { | |
6241 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6242 | return -2; | |
6243 | } | |
6244 | ||
6245 | /* Reset and init BRB, PRS */ | |
34f80b04 | 6246 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
a2fbb9ea | 6247 | msleep(50); |
34f80b04 | 6248 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
a2fbb9ea | 6249 | msleep(50); |
619c5cb6 VZ |
6250 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
6251 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
a2fbb9ea ET |
6252 | |
6253 | DP(NETIF_MSG_HW, "part2\n"); | |
6254 | ||
6255 | /* Disable inputs of parser neighbor blocks */ | |
6256 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
6257 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
6258 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 6259 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
6260 | |
6261 | /* Write 0 to parser credits for CFC search request */ | |
6262 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
6263 | ||
6264 | /* send 10 Ethernet packets */ | |
6265 | for (i = 0; i < 10; i++) | |
6266 | bnx2x_lb_pckt(bp); | |
6267 | ||
6268 | /* Wait until NIG register shows 10 + 1 | |
6269 | packets of size 11*0x10 = 0xb0 */ | |
6270 | count = 1000 * factor; | |
6271 | while (count) { | |
34f80b04 | 6272 | |
a2fbb9ea ET |
6273 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
6274 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
6275 | if (val == 0xb0) |
6276 | break; | |
6277 | ||
6278 | msleep(10); | |
6279 | count--; | |
6280 | } | |
6281 | if (val != 0xb0) { | |
6282 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
6283 | return -3; | |
6284 | } | |
6285 | ||
6286 | /* Wait until PRS register shows 2 packets */ | |
6287 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
6288 | if (val != 2) | |
6289 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6290 | ||
6291 | /* Write 1 to parser credits for CFC search request */ | |
6292 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); | |
6293 | ||
6294 | /* Wait until PRS register shows 3 packets */ | |
6295 | msleep(10 * factor); | |
6296 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
6297 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
6298 | if (val != 3) | |
6299 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6300 | ||
6301 | /* clear NIG EOP FIFO */ | |
6302 | for (i = 0; i < 11; i++) | |
6303 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); | |
6304 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); | |
6305 | if (val != 1) { | |
6306 | BNX2X_ERR("clear of NIG failed\n"); | |
6307 | return -4; | |
6308 | } | |
6309 | ||
6310 | /* Reset and init BRB, PRS, NIG */ | |
6311 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); | |
6312 | msleep(50); | |
6313 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); | |
6314 | msleep(50); | |
619c5cb6 VZ |
6315 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
6316 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
55c11941 MS |
6317 | if (!CNIC_SUPPORT(bp)) |
6318 | /* set NIC mode */ | |
6319 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
a2fbb9ea ET |
6320 | |
6321 | /* Enable inputs of parser neighbor blocks */ | |
6322 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); | |
6323 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); | |
6324 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); | |
3196a88a | 6325 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
a2fbb9ea ET |
6326 | |
6327 | DP(NETIF_MSG_HW, "done\n"); | |
6328 | ||
6329 | return 0; /* OK */ | |
6330 | } | |
6331 | ||
4a33bc03 | 6332 | static void bnx2x_enable_blocks_attention(struct bnx2x *bp) |
a2fbb9ea | 6333 | { |
b343d002 YM |
6334 | u32 val; |
6335 | ||
a2fbb9ea | 6336 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
619c5cb6 | 6337 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6338 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40); |
6339 | else | |
6340 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); | |
a2fbb9ea ET |
6341 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
6342 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
f2e0899f DK |
6343 | /* |
6344 | * mask read length error interrupts in brb for parser | |
6345 | * (parsing unit and 'checksum and crc' unit) | |
6346 | * these errors are legal (PU reads fixed length and CAC can cause | |
6347 | * read length error on truncated packets) | |
6348 | */ | |
6349 | REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00); | |
a2fbb9ea ET |
6350 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
6351 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); | |
6352 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); | |
6353 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); | |
6354 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); | |
34f80b04 EG |
6355 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
6356 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
6357 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
6358 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); | |
6359 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); | |
34f80b04 EG |
6360 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
6361 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
6362 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
6363 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); | |
6364 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); | |
6365 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); | |
34f80b04 EG |
6366 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
6367 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ | |
f85582f8 | 6368 | |
b343d002 YM |
6369 | val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT | |
6370 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF | | |
6371 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN; | |
6372 | if (!CHIP_IS_E1x(bp)) | |
6373 | val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED | | |
6374 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED; | |
6375 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val); | |
6376 | ||
a2fbb9ea ET |
6377 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
6378 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); | |
6379 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); | |
34f80b04 | 6380 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
619c5cb6 VZ |
6381 | |
6382 | if (!CHIP_IS_E1x(bp)) | |
6383 | /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ | |
6384 | REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); | |
6385 | ||
a2fbb9ea ET |
6386 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
6387 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); | |
34f80b04 | 6388 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
4a33bc03 | 6389 | REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */ |
a2fbb9ea ET |
6390 | } |
6391 | ||
81f75bbf EG |
6392 | static void bnx2x_reset_common(struct bnx2x *bp) |
6393 | { | |
619c5cb6 VZ |
6394 | u32 val = 0x1400; |
6395 | ||
81f75bbf EG |
6396 | /* reset_common */ |
6397 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
6398 | 0xd3ffff7f); | |
619c5cb6 VZ |
6399 | |
6400 | if (CHIP_IS_E3(bp)) { | |
6401 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
6402 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
6403 | } | |
6404 | ||
6405 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val); | |
6406 | } | |
6407 | ||
6408 | static void bnx2x_setup_dmae(struct bnx2x *bp) | |
6409 | { | |
6410 | bp->dmae_ready = 0; | |
6411 | spin_lock_init(&bp->dmae_lock); | |
81f75bbf EG |
6412 | } |
6413 | ||
573f2035 EG |
6414 | static void bnx2x_init_pxp(struct bnx2x *bp) |
6415 | { | |
6416 | u16 devctl; | |
6417 | int r_order, w_order; | |
6418 | ||
2a80eebc | 6419 | pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl); |
573f2035 EG |
6420 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
6421 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); | |
6422 | if (bp->mrrs == -1) | |
6423 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); | |
6424 | else { | |
6425 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); | |
6426 | r_order = bp->mrrs; | |
6427 | } | |
6428 | ||
6429 | bnx2x_init_pxp_arb(bp, r_order, w_order); | |
6430 | } | |
fd4ef40d EG |
6431 | |
6432 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) | |
6433 | { | |
2145a920 | 6434 | int is_required; |
fd4ef40d | 6435 | u32 val; |
2145a920 | 6436 | int port; |
fd4ef40d | 6437 | |
2145a920 VZ |
6438 | if (BP_NOMCP(bp)) |
6439 | return; | |
6440 | ||
6441 | is_required = 0; | |
fd4ef40d EG |
6442 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
6443 | SHARED_HW_CFG_FAN_FAILURE_MASK; | |
6444 | ||
6445 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) | |
6446 | is_required = 1; | |
6447 | ||
6448 | /* | |
6449 | * The fan failure mechanism is usually related to the PHY type since | |
6450 | * the power consumption of the board is affected by the PHY. Currently, | |
6451 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. | |
6452 | */ | |
6453 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) | |
6454 | for (port = PORT_0; port < PORT_MAX; port++) { | |
fd4ef40d | 6455 | is_required |= |
d90d96ba YR |
6456 | bnx2x_fan_failure_det_req( |
6457 | bp, | |
6458 | bp->common.shmem_base, | |
a22f0788 | 6459 | bp->common.shmem2_base, |
d90d96ba | 6460 | port); |
fd4ef40d EG |
6461 | } |
6462 | ||
6463 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); | |
6464 | ||
6465 | if (is_required == 0) | |
6466 | return; | |
6467 | ||
6468 | /* Fan failure is indicated by SPIO 5 */ | |
d6d99a3f | 6469 | bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z); |
fd4ef40d EG |
6470 | |
6471 | /* set to active low mode */ | |
6472 | val = REG_RD(bp, MISC_REG_SPIO_INT); | |
d6d99a3f | 6473 | val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS); |
fd4ef40d EG |
6474 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
6475 | ||
6476 | /* enable interrupt to signal the IGU */ | |
6477 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
d6d99a3f | 6478 | val |= MISC_SPIO_SPIO5; |
fd4ef40d EG |
6479 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
6480 | } | |
6481 | ||
c9ee9206 | 6482 | void bnx2x_pf_disable(struct bnx2x *bp) |
f2e0899f DK |
6483 | { |
6484 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
6485 | val &= ~IGU_PF_CONF_FUNC_EN; | |
6486 | ||
6487 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
6488 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
6489 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0); | |
6490 | } | |
6491 | ||
1191cb83 | 6492 | static void bnx2x__common_init_phy(struct bnx2x *bp) |
619c5cb6 VZ |
6493 | { |
6494 | u32 shmem_base[2], shmem2_base[2]; | |
b884d95b YR |
6495 | /* Avoid common init in case MFW supports LFA */ |
6496 | if (SHMEM2_RD(bp, size) > | |
6497 | (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)])) | |
6498 | return; | |
619c5cb6 VZ |
6499 | shmem_base[0] = bp->common.shmem_base; |
6500 | shmem2_base[0] = bp->common.shmem2_base; | |
6501 | if (!CHIP_IS_E1x(bp)) { | |
6502 | shmem_base[1] = | |
6503 | SHMEM2_RD(bp, other_shmem_base_addr); | |
6504 | shmem2_base[1] = | |
6505 | SHMEM2_RD(bp, other_shmem2_base_addr); | |
6506 | } | |
6507 | bnx2x_acquire_phy_lock(bp); | |
6508 | bnx2x_common_init_phy(bp, shmem_base, shmem2_base, | |
6509 | bp->common.chip_id); | |
6510 | bnx2x_release_phy_lock(bp); | |
6511 | } | |
6512 | ||
6513 | /** | |
6514 | * bnx2x_init_hw_common - initialize the HW at the COMMON phase. | |
6515 | * | |
6516 | * @bp: driver handle | |
6517 | */ | |
6518 | static int bnx2x_init_hw_common(struct bnx2x *bp) | |
a2fbb9ea | 6519 | { |
619c5cb6 | 6520 | u32 val; |
a2fbb9ea | 6521 | |
51c1a580 | 6522 | DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp)); |
a2fbb9ea | 6523 | |
2031bd3a | 6524 | /* |
2de67439 | 6525 | * take the RESET lock to protect undi_unload flow from accessing |
2031bd3a DK |
6526 | * registers while we're resetting the chip |
6527 | */ | |
7a06a122 | 6528 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6529 | |
81f75bbf | 6530 | bnx2x_reset_common(bp); |
34f80b04 | 6531 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
a2fbb9ea | 6532 | |
619c5cb6 VZ |
6533 | val = 0xfffc; |
6534 | if (CHIP_IS_E3(bp)) { | |
6535 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
6536 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
6537 | } | |
6538 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val); | |
6539 | ||
7a06a122 | 6540 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6541 | |
619c5cb6 | 6542 | bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON); |
a2fbb9ea | 6543 | |
619c5cb6 VZ |
6544 | if (!CHIP_IS_E1x(bp)) { |
6545 | u8 abs_func_id; | |
f2e0899f DK |
6546 | |
6547 | /** | |
6548 | * 4-port mode or 2-port mode we need to turn of master-enable | |
6549 | * for everyone, after that, turn it back on for self. | |
6550 | * so, we disregard multi-function or not, and always disable | |
6551 | * for all functions on the given path, this means 0,2,4,6 for | |
6552 | * path 0 and 1,3,5,7 for path 1 | |
6553 | */ | |
619c5cb6 VZ |
6554 | for (abs_func_id = BP_PATH(bp); |
6555 | abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) { | |
6556 | if (abs_func_id == BP_ABS_FUNC(bp)) { | |
f2e0899f DK |
6557 | REG_WR(bp, |
6558 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, | |
6559 | 1); | |
6560 | continue; | |
6561 | } | |
6562 | ||
619c5cb6 | 6563 | bnx2x_pretend_func(bp, abs_func_id); |
f2e0899f DK |
6564 | /* clear pf enable */ |
6565 | bnx2x_pf_disable(bp); | |
6566 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6567 | } | |
6568 | } | |
a2fbb9ea | 6569 | |
619c5cb6 | 6570 | bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON); |
34f80b04 EG |
6571 | if (CHIP_IS_E1(bp)) { |
6572 | /* enable HW interrupt from PXP on USDM overflow | |
6573 | bit 16 on INT_MASK_0 */ | |
6574 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); | |
6575 | } | |
a2fbb9ea | 6576 | |
619c5cb6 | 6577 | bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON); |
34f80b04 | 6578 | bnx2x_init_pxp(bp); |
a2fbb9ea ET |
6579 | |
6580 | #ifdef __BIG_ENDIAN | |
34f80b04 EG |
6581 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
6582 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); | |
6583 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); | |
6584 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); | |
6585 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); | |
8badd27a EG |
6586 | /* make sure this value is 0 */ |
6587 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); | |
34f80b04 EG |
6588 | |
6589 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ | |
6590 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); | |
6591 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); | |
6592 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); | |
6593 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); | |
a2fbb9ea ET |
6594 | #endif |
6595 | ||
523224a3 DK |
6596 | bnx2x_ilt_init_page_size(bp, INITOP_SET); |
6597 | ||
34f80b04 EG |
6598 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
6599 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); | |
a2fbb9ea | 6600 | |
34f80b04 EG |
6601 | /* let the HW do it's magic ... */ |
6602 | msleep(100); | |
6603 | /* finish PXP init */ | |
6604 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); | |
6605 | if (val != 1) { | |
6606 | BNX2X_ERR("PXP2 CFG failed\n"); | |
6607 | return -EBUSY; | |
6608 | } | |
6609 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); | |
6610 | if (val != 1) { | |
6611 | BNX2X_ERR("PXP2 RD_INIT failed\n"); | |
6612 | return -EBUSY; | |
6613 | } | |
a2fbb9ea | 6614 | |
f2e0899f DK |
6615 | /* Timers bug workaround E2 only. We need to set the entire ILT to |
6616 | * have entries with value "0" and valid bit on. | |
6617 | * This needs to be done by the first PF that is loaded in a path | |
6618 | * (i.e. common phase) | |
6619 | */ | |
619c5cb6 VZ |
6620 | if (!CHIP_IS_E1x(bp)) { |
6621 | /* In E2 there is a bug in the timers block that can cause function 6 / 7 | |
6622 | * (i.e. vnic3) to start even if it is marked as "scan-off". | |
6623 | * This occurs when a different function (func2,3) is being marked | |
6624 | * as "scan-off". Real-life scenario for example: if a driver is being | |
6625 | * load-unloaded while func6,7 are down. This will cause the timer to access | |
6626 | * the ilt, translate to a logical address and send a request to read/write. | |
6627 | * Since the ilt for the function that is down is not valid, this will cause | |
6628 | * a translation error which is unrecoverable. | |
6629 | * The Workaround is intended to make sure that when this happens nothing fatal | |
6630 | * will occur. The workaround: | |
6631 | * 1. First PF driver which loads on a path will: | |
6632 | * a. After taking the chip out of reset, by using pretend, | |
6633 | * it will write "0" to the following registers of | |
6634 | * the other vnics. | |
6635 | * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
6636 | * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); | |
6637 | * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); | |
6638 | * And for itself it will write '1' to | |
6639 | * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable | |
6640 | * dmae-operations (writing to pram for example.) | |
6641 | * note: can be done for only function 6,7 but cleaner this | |
6642 | * way. | |
6643 | * b. Write zero+valid to the entire ILT. | |
6644 | * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of | |
6645 | * VNIC3 (of that port). The range allocated will be the | |
6646 | * entire ILT. This is needed to prevent ILT range error. | |
6647 | * 2. Any PF driver load flow: | |
6648 | * a. ILT update with the physical addresses of the allocated | |
6649 | * logical pages. | |
6650 | * b. Wait 20msec. - note that this timeout is needed to make | |
6651 | * sure there are no requests in one of the PXP internal | |
6652 | * queues with "old" ILT addresses. | |
6653 | * c. PF enable in the PGLC. | |
6654 | * d. Clear the was_error of the PF in the PGLC. (could have | |
2de67439 | 6655 | * occurred while driver was down) |
619c5cb6 VZ |
6656 | * e. PF enable in the CFC (WEAK + STRONG) |
6657 | * f. Timers scan enable | |
6658 | * 3. PF driver unload flow: | |
6659 | * a. Clear the Timers scan_en. | |
6660 | * b. Polling for scan_on=0 for that PF. | |
6661 | * c. Clear the PF enable bit in the PXP. | |
6662 | * d. Clear the PF enable in the CFC (WEAK + STRONG) | |
6663 | * e. Write zero+valid to all ILT entries (The valid bit must | |
6664 | * stay set) | |
6665 | * f. If this is VNIC 3 of a port then also init | |
6666 | * first_timers_ilt_entry to zero and last_timers_ilt_entry | |
6667 | * to the last enrty in the ILT. | |
6668 | * | |
6669 | * Notes: | |
6670 | * Currently the PF error in the PGLC is non recoverable. | |
6671 | * In the future the there will be a recovery routine for this error. | |
6672 | * Currently attention is masked. | |
6673 | * Having an MCP lock on the load/unload process does not guarantee that | |
6674 | * there is no Timer disable during Func6/7 enable. This is because the | |
6675 | * Timers scan is currently being cleared by the MCP on FLR. | |
6676 | * Step 2.d can be done only for PF6/7 and the driver can also check if | |
6677 | * there is error before clearing it. But the flow above is simpler and | |
6678 | * more general. | |
6679 | * All ILT entries are written by zero+valid and not just PF6/7 | |
6680 | * ILT entries since in the future the ILT entries allocation for | |
6681 | * PF-s might be dynamic. | |
6682 | */ | |
f2e0899f DK |
6683 | struct ilt_client_info ilt_cli; |
6684 | struct bnx2x_ilt ilt; | |
6685 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
6686 | memset(&ilt, 0, sizeof(struct bnx2x_ilt)); | |
6687 | ||
b595076a | 6688 | /* initialize dummy TM client */ |
f2e0899f DK |
6689 | ilt_cli.start = 0; |
6690 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
6691 | ilt_cli.client_num = ILT_CLIENT_TM; | |
6692 | ||
6693 | /* Step 1: set zeroes to all ilt page entries with valid bit on | |
6694 | * Step 2: set the timers first/last ilt entry to point | |
6695 | * to the entire range to prevent ILT range error for 3rd/4th | |
2de67439 | 6696 | * vnic (this code assumes existence of the vnic) |
f2e0899f DK |
6697 | * |
6698 | * both steps performed by call to bnx2x_ilt_client_init_op() | |
6699 | * with dummy TM client | |
6700 | * | |
6701 | * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT | |
6702 | * and his brother are split registers | |
6703 | */ | |
6704 | bnx2x_pretend_func(bp, (BP_PATH(bp) + 6)); | |
6705 | bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR); | |
6706 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6707 | ||
6708 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN); | |
6709 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN); | |
6710 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); | |
6711 | } | |
6712 | ||
34f80b04 EG |
6713 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
6714 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); | |
a2fbb9ea | 6715 | |
619c5cb6 | 6716 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6717 | int factor = CHIP_REV_IS_EMUL(bp) ? 1000 : |
6718 | (CHIP_REV_IS_FPGA(bp) ? 400 : 0); | |
619c5cb6 | 6719 | bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON); |
f2e0899f | 6720 | |
619c5cb6 | 6721 | bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON); |
f2e0899f DK |
6722 | |
6723 | /* let the HW do it's magic ... */ | |
6724 | do { | |
6725 | msleep(200); | |
6726 | val = REG_RD(bp, ATC_REG_ATC_INIT_DONE); | |
6727 | } while (factor-- && (val != 1)); | |
6728 | ||
6729 | if (val != 1) { | |
6730 | BNX2X_ERR("ATC_INIT failed\n"); | |
6731 | return -EBUSY; | |
6732 | } | |
6733 | } | |
6734 | ||
619c5cb6 | 6735 | bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON); |
a2fbb9ea | 6736 | |
b56e9670 AE |
6737 | bnx2x_iov_init_dmae(bp); |
6738 | ||
34f80b04 EG |
6739 | /* clean the DMAE memory */ |
6740 | bp->dmae_ready = 1; | |
619c5cb6 VZ |
6741 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1); |
6742 | ||
6743 | bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON); | |
6744 | ||
6745 | bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON); | |
6746 | ||
6747 | bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON); | |
a2fbb9ea | 6748 | |
619c5cb6 | 6749 | bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON); |
a2fbb9ea | 6750 | |
34f80b04 EG |
6751 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
6752 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); | |
6753 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); | |
6754 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); | |
6755 | ||
619c5cb6 | 6756 | bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON); |
37b091ba | 6757 | |
f85582f8 | 6758 | |
523224a3 DK |
6759 | /* QM queues pointers table */ |
6760 | bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET); | |
6761 | ||
34f80b04 EG |
6762 | /* soft reset pulse */ |
6763 | REG_WR(bp, QM_REG_SOFT_RESET, 1); | |
6764 | REG_WR(bp, QM_REG_SOFT_RESET, 0); | |
a2fbb9ea | 6765 | |
55c11941 MS |
6766 | if (CNIC_SUPPORT(bp)) |
6767 | bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON); | |
a2fbb9ea | 6768 | |
619c5cb6 | 6769 | bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON); |
523224a3 | 6770 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT); |
619c5cb6 | 6771 | if (!CHIP_REV_IS_SLOW(bp)) |
34f80b04 EG |
6772 | /* enable hw interrupt from doorbell Q */ |
6773 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); | |
a2fbb9ea | 6774 | |
619c5cb6 | 6775 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
f2e0899f | 6776 | |
619c5cb6 | 6777 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
26c8fa4d | 6778 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
619c5cb6 | 6779 | |
f2e0899f | 6780 | if (!CHIP_IS_E1(bp)) |
619c5cb6 | 6781 | REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan); |
f85582f8 | 6782 | |
a3348722 BW |
6783 | if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) { |
6784 | if (IS_MF_AFEX(bp)) { | |
6785 | /* configure that VNTag and VLAN headers must be | |
6786 | * received in afex mode | |
6787 | */ | |
6788 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE); | |
6789 | REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA); | |
6790 | REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6); | |
6791 | REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926); | |
6792 | REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4); | |
6793 | } else { | |
6794 | /* Bit-map indicating which L2 hdrs may appear | |
6795 | * after the basic Ethernet header | |
6796 | */ | |
6797 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, | |
6798 | bp->path_has_ovlan ? 7 : 6); | |
6799 | } | |
6800 | } | |
a2fbb9ea | 6801 | |
619c5cb6 VZ |
6802 | bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON); |
6803 | bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON); | |
6804 | bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON); | |
6805 | bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON); | |
a2fbb9ea | 6806 | |
619c5cb6 VZ |
6807 | if (!CHIP_IS_E1x(bp)) { |
6808 | /* reset VFC memories */ | |
6809 | REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6810 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6811 | VFC_MEMORIES_RST_REG_RAM_RST); | |
6812 | REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6813 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6814 | VFC_MEMORIES_RST_REG_RAM_RST); | |
a2fbb9ea | 6815 | |
619c5cb6 VZ |
6816 | msleep(20); |
6817 | } | |
a2fbb9ea | 6818 | |
619c5cb6 VZ |
6819 | bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON); |
6820 | bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON); | |
6821 | bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON); | |
6822 | bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON); | |
f2e0899f | 6823 | |
34f80b04 EG |
6824 | /* sync semi rtc */ |
6825 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
6826 | 0x80000000); | |
6827 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, | |
6828 | 0x80000000); | |
a2fbb9ea | 6829 | |
619c5cb6 VZ |
6830 | bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON); |
6831 | bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON); | |
6832 | bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON); | |
a2fbb9ea | 6833 | |
a3348722 BW |
6834 | if (!CHIP_IS_E1x(bp)) { |
6835 | if (IS_MF_AFEX(bp)) { | |
6836 | /* configure that VNTag and VLAN headers must be | |
6837 | * sent in afex mode | |
6838 | */ | |
6839 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE); | |
6840 | REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA); | |
6841 | REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6); | |
6842 | REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926); | |
6843 | REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4); | |
6844 | } else { | |
6845 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, | |
6846 | bp->path_has_ovlan ? 7 : 6); | |
6847 | } | |
6848 | } | |
f2e0899f | 6849 | |
34f80b04 | 6850 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
f85582f8 | 6851 | |
619c5cb6 VZ |
6852 | bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON); |
6853 | ||
55c11941 MS |
6854 | if (CNIC_SUPPORT(bp)) { |
6855 | REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672); | |
6856 | REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); | |
6857 | REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b); | |
6858 | REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a); | |
6859 | REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116); | |
6860 | REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b); | |
6861 | REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf); | |
6862 | REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); | |
6863 | REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f); | |
6864 | REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7); | |
6865 | } | |
34f80b04 | 6866 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
a2fbb9ea | 6867 | |
34f80b04 EG |
6868 | if (sizeof(union cdu_context) != 1024) |
6869 | /* we currently assume that a context is 1024 bytes */ | |
51c1a580 MS |
6870 | dev_alert(&bp->pdev->dev, |
6871 | "please adjust the size of cdu_context(%ld)\n", | |
6872 | (long)sizeof(union cdu_context)); | |
a2fbb9ea | 6873 | |
619c5cb6 | 6874 | bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON); |
34f80b04 EG |
6875 | val = (4 << 24) + (0 << 12) + 1024; |
6876 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); | |
a2fbb9ea | 6877 | |
619c5cb6 | 6878 | bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON); |
34f80b04 | 6879 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
8d9c5f34 EG |
6880 | /* enable context validation interrupt from CFC */ |
6881 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
6882 | ||
6883 | /* set the thresholds to prevent CFC/CDU race */ | |
6884 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); | |
a2fbb9ea | 6885 | |
619c5cb6 | 6886 | bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON); |
f2e0899f | 6887 | |
619c5cb6 | 6888 | if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp)) |
f2e0899f DK |
6889 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36); |
6890 | ||
619c5cb6 VZ |
6891 | bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON); |
6892 | bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON); | |
a2fbb9ea | 6893 | |
34f80b04 EG |
6894 | /* Reset PCIE errors for debug */ |
6895 | REG_WR(bp, 0x2814, 0xffffffff); | |
6896 | REG_WR(bp, 0x3820, 0xffffffff); | |
a2fbb9ea | 6897 | |
619c5cb6 | 6898 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6899 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, |
6900 | (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | | |
6901 | PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); | |
6902 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, | |
6903 | (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | | |
6904 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | | |
6905 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); | |
6906 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, | |
6907 | (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | | |
6908 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | | |
6909 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); | |
6910 | } | |
6911 | ||
619c5cb6 | 6912 | bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON); |
f2e0899f | 6913 | if (!CHIP_IS_E1(bp)) { |
619c5cb6 VZ |
6914 | /* in E3 this done in per-port section */ |
6915 | if (!CHIP_IS_E3(bp)) | |
6916 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
f2e0899f | 6917 | } |
619c5cb6 VZ |
6918 | if (CHIP_IS_E1H(bp)) |
6919 | /* not applicable for E2 (and above ...) */ | |
6920 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp)); | |
34f80b04 EG |
6921 | |
6922 | if (CHIP_REV_IS_SLOW(bp)) | |
6923 | msleep(200); | |
6924 | ||
6925 | /* finish CFC init */ | |
6926 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); | |
6927 | if (val != 1) { | |
6928 | BNX2X_ERR("CFC LL_INIT failed\n"); | |
6929 | return -EBUSY; | |
6930 | } | |
6931 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); | |
6932 | if (val != 1) { | |
6933 | BNX2X_ERR("CFC AC_INIT failed\n"); | |
6934 | return -EBUSY; | |
6935 | } | |
6936 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); | |
6937 | if (val != 1) { | |
6938 | BNX2X_ERR("CFC CAM_INIT failed\n"); | |
6939 | return -EBUSY; | |
6940 | } | |
6941 | REG_WR(bp, CFC_REG_DEBUG0, 0); | |
f1410647 | 6942 | |
f2e0899f DK |
6943 | if (CHIP_IS_E1(bp)) { |
6944 | /* read NIG statistic | |
6945 | to see if this is our first up since powerup */ | |
6946 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); | |
6947 | val = *bnx2x_sp(bp, wb_data[0]); | |
34f80b04 | 6948 | |
f2e0899f DK |
6949 | /* do internal memory self test */ |
6950 | if ((val == 0) && bnx2x_int_mem_test(bp)) { | |
6951 | BNX2X_ERR("internal mem self test failed\n"); | |
6952 | return -EBUSY; | |
6953 | } | |
34f80b04 EG |
6954 | } |
6955 | ||
fd4ef40d EG |
6956 | bnx2x_setup_fan_failure_detection(bp); |
6957 | ||
34f80b04 EG |
6958 | /* clear PXP2 attentions */ |
6959 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); | |
a2fbb9ea | 6960 | |
4a33bc03 | 6961 | bnx2x_enable_blocks_attention(bp); |
c9ee9206 | 6962 | bnx2x_enable_blocks_parity(bp); |
a2fbb9ea | 6963 | |
6bbca910 | 6964 | if (!BP_NOMCP(bp)) { |
619c5cb6 VZ |
6965 | if (CHIP_IS_E1x(bp)) |
6966 | bnx2x__common_init_phy(bp); | |
6bbca910 YR |
6967 | } else |
6968 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); | |
6969 | ||
34f80b04 EG |
6970 | return 0; |
6971 | } | |
a2fbb9ea | 6972 | |
619c5cb6 VZ |
6973 | /** |
6974 | * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase. | |
6975 | * | |
6976 | * @bp: driver handle | |
6977 | */ | |
6978 | static int bnx2x_init_hw_common_chip(struct bnx2x *bp) | |
6979 | { | |
6980 | int rc = bnx2x_init_hw_common(bp); | |
6981 | ||
6982 | if (rc) | |
6983 | return rc; | |
6984 | ||
6985 | /* In E2 2-PORT mode, same ext phy is used for the two paths */ | |
6986 | if (!BP_NOMCP(bp)) | |
6987 | bnx2x__common_init_phy(bp); | |
6988 | ||
6989 | return 0; | |
6990 | } | |
6991 | ||
523224a3 | 6992 | static int bnx2x_init_hw_port(struct bnx2x *bp) |
34f80b04 EG |
6993 | { |
6994 | int port = BP_PORT(bp); | |
619c5cb6 | 6995 | int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; |
1c06328c | 6996 | u32 low, high; |
34f80b04 | 6997 | u32 val; |
a2fbb9ea | 6998 | |
619c5cb6 | 6999 | |
51c1a580 | 7000 | DP(NETIF_MSG_HW, "starting port init port %d\n", port); |
34f80b04 EG |
7001 | |
7002 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); | |
a2fbb9ea | 7003 | |
619c5cb6 VZ |
7004 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
7005 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); | |
7006 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
ca00392c | 7007 | |
f2e0899f DK |
7008 | /* Timers bug workaround: disables the pf_master bit in pglue at |
7009 | * common phase, we need to enable it here before any dmae access are | |
7010 | * attempted. Therefore we manually added the enable-master to the | |
7011 | * port phase (it also happens in the function phase) | |
7012 | */ | |
619c5cb6 | 7013 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7014 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
7015 | ||
619c5cb6 VZ |
7016 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
7017 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
7018 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); | |
7019 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
7020 | ||
7021 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
7022 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
7023 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
7024 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
a2fbb9ea | 7025 | |
523224a3 DK |
7026 | /* QM cid (connection) count */ |
7027 | bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET); | |
a2fbb9ea | 7028 | |
55c11941 MS |
7029 | if (CNIC_SUPPORT(bp)) { |
7030 | bnx2x_init_block(bp, BLOCK_TM, init_phase); | |
7031 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20); | |
7032 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); | |
7033 | } | |
cdaa7cb8 | 7034 | |
619c5cb6 | 7035 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
f2e0899f | 7036 | |
2b674047 DK |
7037 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
7038 | ||
f2e0899f | 7039 | if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) { |
619c5cb6 VZ |
7040 | |
7041 | if (IS_MF(bp)) | |
7042 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); | |
7043 | else if (bp->dev->mtu > 4096) { | |
7044 | if (bp->flags & ONE_PORT_FLAG) | |
7045 | low = 160; | |
7046 | else { | |
7047 | val = bp->dev->mtu; | |
7048 | /* (24*1024 + val*4)/256 */ | |
7049 | low = 96 + (val/64) + | |
7050 | ((val % 64) ? 1 : 0); | |
7051 | } | |
7052 | } else | |
7053 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); | |
7054 | high = low + 56; /* 14*1024/256 */ | |
f2e0899f DK |
7055 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
7056 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); | |
1c06328c | 7057 | } |
1c06328c | 7058 | |
619c5cb6 VZ |
7059 | if (CHIP_MODE_IS_4_PORT(bp)) |
7060 | REG_WR(bp, (BP_PORT(bp) ? | |
7061 | BRB1_REG_MAC_GUARANTIED_1 : | |
7062 | BRB1_REG_MAC_GUARANTIED_0), 40); | |
1c06328c | 7063 | |
ca00392c | 7064 | |
619c5cb6 | 7065 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
a3348722 BW |
7066 | if (CHIP_IS_E3B0(bp)) { |
7067 | if (IS_MF_AFEX(bp)) { | |
7068 | /* configure headers for AFEX mode */ | |
7069 | REG_WR(bp, BP_PORT(bp) ? | |
7070 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : | |
7071 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE); | |
7072 | REG_WR(bp, BP_PORT(bp) ? | |
7073 | PRS_REG_HDRS_AFTER_TAG_0_PORT_1 : | |
7074 | PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6); | |
7075 | REG_WR(bp, BP_PORT(bp) ? | |
7076 | PRS_REG_MUST_HAVE_HDRS_PORT_1 : | |
7077 | PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA); | |
7078 | } else { | |
7079 | /* Ovlan exists only if we are in multi-function + | |
7080 | * switch-dependent mode, in switch-independent there | |
7081 | * is no ovlan headers | |
7082 | */ | |
7083 | REG_WR(bp, BP_PORT(bp) ? | |
7084 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : | |
7085 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, | |
7086 | (bp->path_has_ovlan ? 7 : 6)); | |
7087 | } | |
7088 | } | |
356e2385 | 7089 | |
619c5cb6 VZ |
7090 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
7091 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
7092 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
7093 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
356e2385 | 7094 | |
619c5cb6 VZ |
7095 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
7096 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
7097 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
7098 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
34f80b04 | 7099 | |
619c5cb6 VZ |
7100 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
7101 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
a2fbb9ea | 7102 | |
619c5cb6 VZ |
7103 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
7104 | ||
7105 | if (CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
7106 | /* configure PBF to work without PAUSE mtu 9000 */ |
7107 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); | |
a2fbb9ea | 7108 | |
f2e0899f DK |
7109 | /* update threshold */ |
7110 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); | |
7111 | /* update init credit */ | |
7112 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); | |
a2fbb9ea | 7113 | |
f2e0899f DK |
7114 | /* probe changes */ |
7115 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); | |
7116 | udelay(50); | |
7117 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); | |
7118 | } | |
a2fbb9ea | 7119 | |
55c11941 MS |
7120 | if (CNIC_SUPPORT(bp)) |
7121 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); | |
7122 | ||
619c5cb6 VZ |
7123 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
7124 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); | |
34f80b04 EG |
7125 | |
7126 | if (CHIP_IS_E1(bp)) { | |
7127 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
7128 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
7129 | } | |
619c5cb6 | 7130 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
34f80b04 | 7131 | |
619c5cb6 | 7132 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 7133 | |
619c5cb6 | 7134 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
34f80b04 EG |
7135 | /* init aeu_mask_attn_func_0/1: |
7136 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use | |
7137 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF | |
7138 | * bits 4-7 are used for "per vn group attention" */ | |
e4901dde VZ |
7139 | val = IS_MF(bp) ? 0xF7 : 0x7; |
7140 | /* Enable DCBX attention for all but E1 */ | |
7141 | val |= CHIP_IS_E1(bp) ? 0 : 0x10; | |
7142 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); | |
34f80b04 | 7143 | |
619c5cb6 VZ |
7144 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
7145 | ||
7146 | if (!CHIP_IS_E1x(bp)) { | |
7147 | /* Bit-map indicating which L2 hdrs may appear after the | |
7148 | * basic Ethernet header | |
7149 | */ | |
a3348722 BW |
7150 | if (IS_MF_AFEX(bp)) |
7151 | REG_WR(bp, BP_PORT(bp) ? | |
7152 | NIG_REG_P1_HDRS_AFTER_BASIC : | |
7153 | NIG_REG_P0_HDRS_AFTER_BASIC, 0xE); | |
7154 | else | |
7155 | REG_WR(bp, BP_PORT(bp) ? | |
7156 | NIG_REG_P1_HDRS_AFTER_BASIC : | |
7157 | NIG_REG_P0_HDRS_AFTER_BASIC, | |
7158 | IS_MF_SD(bp) ? 7 : 6); | |
619c5cb6 VZ |
7159 | |
7160 | if (CHIP_IS_E3(bp)) | |
7161 | REG_WR(bp, BP_PORT(bp) ? | |
7162 | NIG_REG_LLH1_MF_MODE : | |
7163 | NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
7164 | } | |
7165 | if (!CHIP_IS_E3(bp)) | |
7166 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); | |
34f80b04 | 7167 | |
f2e0899f | 7168 | if (!CHIP_IS_E1(bp)) { |
fb3bff17 | 7169 | /* 0x2 disable mf_ov, 0x1 enable */ |
34f80b04 | 7170 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
0793f83f | 7171 | (IS_MF_SD(bp) ? 0x1 : 0x2)); |
34f80b04 | 7172 | |
619c5cb6 | 7173 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7174 | val = 0; |
7175 | switch (bp->mf_mode) { | |
7176 | case MULTI_FUNCTION_SD: | |
7177 | val = 1; | |
7178 | break; | |
7179 | case MULTI_FUNCTION_SI: | |
a3348722 | 7180 | case MULTI_FUNCTION_AFEX: |
f2e0899f DK |
7181 | val = 2; |
7182 | break; | |
7183 | } | |
7184 | ||
7185 | REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE : | |
7186 | NIG_REG_LLH0_CLS_TYPE), val); | |
7187 | } | |
1c06328c EG |
7188 | { |
7189 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); | |
7190 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); | |
7191 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); | |
7192 | } | |
34f80b04 EG |
7193 | } |
7194 | ||
619c5cb6 VZ |
7195 | /* If SPIO5 is set to generate interrupts, enable it for this port */ |
7196 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
d6d99a3f | 7197 | if (val & MISC_SPIO_SPIO5) { |
4d295db0 EG |
7198 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
7199 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
7200 | val = REG_RD(bp, reg_addr); | |
f1410647 | 7201 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
4d295db0 | 7202 | REG_WR(bp, reg_addr, val); |
f1410647 | 7203 | } |
a2fbb9ea | 7204 | |
34f80b04 EG |
7205 | return 0; |
7206 | } | |
7207 | ||
34f80b04 EG |
7208 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
7209 | { | |
7210 | int reg; | |
32d68de1 | 7211 | u32 wb_write[2]; |
34f80b04 | 7212 | |
f2e0899f | 7213 | if (CHIP_IS_E1(bp)) |
34f80b04 | 7214 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
f2e0899f DK |
7215 | else |
7216 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; | |
34f80b04 | 7217 | |
32d68de1 YM |
7218 | wb_write[0] = ONCHIP_ADDR1(addr); |
7219 | wb_write[1] = ONCHIP_ADDR2(addr); | |
7220 | REG_WR_DMAE(bp, reg, wb_write, 2); | |
34f80b04 EG |
7221 | } |
7222 | ||
b56e9670 | 7223 | void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf) |
1191cb83 ED |
7224 | { |
7225 | u32 data, ctl, cnt = 100; | |
7226 | u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA; | |
7227 | u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL; | |
7228 | u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4; | |
7229 | u32 sb_bit = 1 << (idu_sb_id%32); | |
b56e9670 | 7230 | u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT; |
1191cb83 ED |
7231 | u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id; |
7232 | ||
7233 | /* Not supported in BC mode */ | |
7234 | if (CHIP_INT_MODE_IS_BC(bp)) | |
7235 | return; | |
7236 | ||
7237 | data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup | |
7238 | << IGU_REGULAR_CLEANUP_TYPE_SHIFT) | | |
7239 | IGU_REGULAR_CLEANUP_SET | | |
7240 | IGU_REGULAR_BCLEANUP; | |
7241 | ||
7242 | ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT | | |
7243 | func_encode << IGU_CTRL_REG_FID_SHIFT | | |
7244 | IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT; | |
7245 | ||
7246 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", | |
7247 | data, igu_addr_data); | |
7248 | REG_WR(bp, igu_addr_data, data); | |
7249 | mmiowb(); | |
7250 | barrier(); | |
7251 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", | |
7252 | ctl, igu_addr_ctl); | |
7253 | REG_WR(bp, igu_addr_ctl, ctl); | |
7254 | mmiowb(); | |
7255 | barrier(); | |
7256 | ||
7257 | /* wait for clean up to finish */ | |
7258 | while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt) | |
7259 | msleep(20); | |
7260 | ||
7261 | ||
7262 | if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) { | |
7263 | DP(NETIF_MSG_HW, | |
7264 | "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n", | |
7265 | idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt); | |
7266 | } | |
7267 | } | |
7268 | ||
7269 | static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id) | |
f2e0899f | 7270 | { |
619c5cb6 | 7271 | bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/); |
f2e0899f DK |
7272 | } |
7273 | ||
1191cb83 | 7274 | static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func) |
f2e0899f DK |
7275 | { |
7276 | u32 i, base = FUNC_ILT_BASE(func); | |
7277 | for (i = base; i < base + ILT_PER_FUNC; i++) | |
7278 | bnx2x_ilt_wr(bp, i, 0); | |
7279 | } | |
7280 | ||
55c11941 | 7281 | |
910cc727 | 7282 | static void bnx2x_init_searcher(struct bnx2x *bp) |
55c11941 MS |
7283 | { |
7284 | int port = BP_PORT(bp); | |
7285 | bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM); | |
7286 | /* T1 hash bits value determines the T1 number of entries */ | |
7287 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS); | |
7288 | } | |
7289 | ||
7290 | static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend) | |
7291 | { | |
7292 | int rc; | |
7293 | struct bnx2x_func_state_params func_params = {NULL}; | |
7294 | struct bnx2x_func_switch_update_params *switch_update_params = | |
7295 | &func_params.params.switch_update; | |
7296 | ||
7297 | /* Prepare parameters for function state transitions */ | |
7298 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
7299 | __set_bit(RAMROD_RETRY, &func_params.ramrod_flags); | |
7300 | ||
7301 | func_params.f_obj = &bp->func_obj; | |
7302 | func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE; | |
7303 | ||
7304 | /* Function parameters */ | |
7305 | switch_update_params->suspend = suspend; | |
7306 | ||
7307 | rc = bnx2x_func_state_change(bp, &func_params); | |
7308 | ||
7309 | return rc; | |
7310 | } | |
7311 | ||
910cc727 | 7312 | static int bnx2x_reset_nic_mode(struct bnx2x *bp) |
55c11941 MS |
7313 | { |
7314 | int rc, i, port = BP_PORT(bp); | |
7315 | int vlan_en = 0, mac_en[NUM_MACS]; | |
7316 | ||
7317 | ||
7318 | /* Close input from network */ | |
7319 | if (bp->mf_mode == SINGLE_FUNCTION) { | |
7320 | bnx2x_set_rx_filter(&bp->link_params, 0); | |
7321 | } else { | |
7322 | vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7323 | NIG_REG_LLH0_FUNC_EN); | |
7324 | REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7325 | NIG_REG_LLH0_FUNC_EN, 0); | |
7326 | for (i = 0; i < NUM_MACS; i++) { | |
7327 | mac_en[i] = REG_RD(bp, port ? | |
7328 | (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7329 | 4 * i) : | |
7330 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + | |
7331 | 4 * i)); | |
7332 | REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7333 | 4 * i) : | |
7334 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0); | |
7335 | } | |
7336 | } | |
7337 | ||
7338 | /* Close BMC to host */ | |
7339 | REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE : | |
7340 | NIG_REG_P1_TX_MNG_HOST_ENABLE, 0); | |
7341 | ||
7342 | /* Suspend Tx switching to the PF. Completion of this ramrod | |
7343 | * further guarantees that all the packets of that PF / child | |
7344 | * VFs in BRB were processed by the Parser, so it is safe to | |
7345 | * change the NIC_MODE register. | |
7346 | */ | |
7347 | rc = bnx2x_func_switch_update(bp, 1); | |
7348 | if (rc) { | |
7349 | BNX2X_ERR("Can't suspend tx-switching!\n"); | |
7350 | return rc; | |
7351 | } | |
7352 | ||
7353 | /* Change NIC_MODE register */ | |
7354 | REG_WR(bp, PRS_REG_NIC_MODE, 0); | |
7355 | ||
7356 | /* Open input from network */ | |
7357 | if (bp->mf_mode == SINGLE_FUNCTION) { | |
7358 | bnx2x_set_rx_filter(&bp->link_params, 1); | |
7359 | } else { | |
7360 | REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7361 | NIG_REG_LLH0_FUNC_EN, vlan_en); | |
7362 | for (i = 0; i < NUM_MACS; i++) { | |
7363 | REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7364 | 4 * i) : | |
7365 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), | |
7366 | mac_en[i]); | |
7367 | } | |
7368 | } | |
7369 | ||
7370 | /* Enable BMC to host */ | |
7371 | REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE : | |
7372 | NIG_REG_P1_TX_MNG_HOST_ENABLE, 1); | |
7373 | ||
7374 | /* Resume Tx switching to the PF */ | |
7375 | rc = bnx2x_func_switch_update(bp, 0); | |
7376 | if (rc) { | |
7377 | BNX2X_ERR("Can't resume tx-switching!\n"); | |
7378 | return rc; | |
7379 | } | |
7380 | ||
7381 | DP(NETIF_MSG_IFUP, "NIC MODE disabled\n"); | |
7382 | return 0; | |
7383 | } | |
7384 | ||
7385 | int bnx2x_init_hw_func_cnic(struct bnx2x *bp) | |
7386 | { | |
7387 | int rc; | |
7388 | ||
7389 | bnx2x_ilt_init_op_cnic(bp, INITOP_SET); | |
7390 | ||
7391 | if (CONFIGURE_NIC_MODE(bp)) { | |
7392 | /* Configrue searcher as part of function hw init */ | |
7393 | bnx2x_init_searcher(bp); | |
7394 | ||
7395 | /* Reset NIC mode */ | |
7396 | rc = bnx2x_reset_nic_mode(bp); | |
7397 | if (rc) | |
7398 | BNX2X_ERR("Can't change NIC mode!\n"); | |
7399 | return rc; | |
7400 | } | |
7401 | ||
7402 | return 0; | |
7403 | } | |
7404 | ||
523224a3 | 7405 | static int bnx2x_init_hw_func(struct bnx2x *bp) |
34f80b04 EG |
7406 | { |
7407 | int port = BP_PORT(bp); | |
7408 | int func = BP_FUNC(bp); | |
619c5cb6 | 7409 | int init_phase = PHASE_PF0 + func; |
523224a3 DK |
7410 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
7411 | u16 cdu_ilt_start; | |
8badd27a | 7412 | u32 addr, val; |
f4a66897 | 7413 | u32 main_mem_base, main_mem_size, main_mem_prty_clr; |
89db4ad8 | 7414 | int i, main_mem_width, rc; |
34f80b04 | 7415 | |
51c1a580 | 7416 | DP(NETIF_MSG_HW, "starting func init func %d\n", func); |
34f80b04 | 7417 | |
619c5cb6 | 7418 | /* FLR cleanup - hmmm */ |
89db4ad8 AE |
7419 | if (!CHIP_IS_E1x(bp)) { |
7420 | rc = bnx2x_pf_flr_clnup(bp); | |
04c46736 YM |
7421 | if (rc) { |
7422 | bnx2x_fw_dump(bp); | |
89db4ad8 | 7423 | return rc; |
04c46736 | 7424 | } |
89db4ad8 | 7425 | } |
619c5cb6 | 7426 | |
8badd27a | 7427 | /* set MSI reconfigure capability */ |
f2e0899f DK |
7428 | if (bp->common.int_block == INT_BLOCK_HC) { |
7429 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); | |
7430 | val = REG_RD(bp, addr); | |
7431 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; | |
7432 | REG_WR(bp, addr, val); | |
7433 | } | |
8badd27a | 7434 | |
619c5cb6 VZ |
7435 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
7436 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
7437 | ||
523224a3 DK |
7438 | ilt = BP_ILT(bp); |
7439 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; | |
37b091ba | 7440 | |
290ca2bb AE |
7441 | if (IS_SRIOV(bp)) |
7442 | cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS; | |
7443 | cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start); | |
7444 | ||
7445 | /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes | |
7446 | * those of the VFs, so start line should be reset | |
7447 | */ | |
7448 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; | |
523224a3 | 7449 | for (i = 0; i < L2_ILT_LINES(bp); i++) { |
a052997e | 7450 | ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt; |
523224a3 | 7451 | ilt->lines[cdu_ilt_start + i].page_mapping = |
a052997e MS |
7452 | bp->context[i].cxt_mapping; |
7453 | ilt->lines[cdu_ilt_start + i].size = bp->context[i].size; | |
37b091ba | 7454 | } |
290ca2bb | 7455 | |
523224a3 | 7456 | bnx2x_ilt_init_op(bp, INITOP_SET); |
f85582f8 | 7457 | |
55c11941 MS |
7458 | if (!CONFIGURE_NIC_MODE(bp)) { |
7459 | bnx2x_init_searcher(bp); | |
7460 | REG_WR(bp, PRS_REG_NIC_MODE, 0); | |
7461 | DP(NETIF_MSG_IFUP, "NIC MODE disabled\n"); | |
7462 | } else { | |
7463 | /* Set NIC mode */ | |
7464 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
7465 | DP(NETIF_MSG_IFUP, "NIC MODE configrued\n"); | |
37b091ba | 7466 | |
55c11941 | 7467 | } |
37b091ba | 7468 | |
619c5cb6 | 7469 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7470 | u32 pf_conf = IGU_PF_CONF_FUNC_EN; |
7471 | ||
7472 | /* Turn on a single ISR mode in IGU if driver is going to use | |
7473 | * INT#x or MSI | |
7474 | */ | |
7475 | if (!(bp->flags & USING_MSIX_FLAG)) | |
7476 | pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; | |
7477 | /* | |
7478 | * Timers workaround bug: function init part. | |
7479 | * Need to wait 20msec after initializing ILT, | |
7480 | * needed to make sure there are no requests in | |
7481 | * one of the PXP internal queues with "old" ILT addresses | |
7482 | */ | |
7483 | msleep(20); | |
7484 | /* | |
7485 | * Master enable - Due to WB DMAE writes performed before this | |
7486 | * register is re-initialized as part of the regular function | |
7487 | * init | |
7488 | */ | |
7489 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
7490 | /* Enable the function in IGU */ | |
7491 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf); | |
7492 | } | |
7493 | ||
523224a3 | 7494 | bp->dmae_ready = 1; |
34f80b04 | 7495 | |
619c5cb6 | 7496 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
523224a3 | 7497 | |
619c5cb6 | 7498 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7499 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); |
7500 | ||
619c5cb6 VZ |
7501 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
7502 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
7503 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); | |
7504 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); | |
7505 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); | |
7506 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
7507 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
7508 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
7509 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
7510 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); | |
7511 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
7512 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
7513 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
7514 | ||
7515 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
7516 | REG_WR(bp, QM_REG_PF_EN, 1); |
7517 | ||
619c5cb6 VZ |
7518 | if (!CHIP_IS_E1x(bp)) { |
7519 | REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7520 | REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7521 | REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7522 | REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7523 | } | |
7524 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
7525 | ||
7526 | bnx2x_init_block(bp, BLOCK_TM, init_phase); | |
7527 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); | |
b56e9670 AE |
7528 | |
7529 | bnx2x_iov_init_dq(bp); | |
7530 | ||
619c5cb6 VZ |
7531 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
7532 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); | |
7533 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); | |
7534 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
7535 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
7536 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
7537 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); | |
7538 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
7539 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); | |
7540 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
7541 | REG_WR(bp, PBF_REG_DISABLE_PF, 0); |
7542 | ||
619c5cb6 | 7543 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
523224a3 | 7544 | |
619c5cb6 | 7545 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
34f80b04 | 7546 | |
619c5cb6 | 7547 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7548 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1); |
7549 | ||
fb3bff17 | 7550 | if (IS_MF(bp)) { |
34f80b04 | 7551 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
fb3bff17 | 7552 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov); |
34f80b04 EG |
7553 | } |
7554 | ||
619c5cb6 | 7555 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
523224a3 | 7556 | |
34f80b04 | 7557 | /* HC init per function */ |
f2e0899f DK |
7558 | if (bp->common.int_block == INT_BLOCK_HC) { |
7559 | if (CHIP_IS_E1H(bp)) { | |
7560 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
7561 | ||
7562 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
7563 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
7564 | } | |
619c5cb6 | 7565 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
f2e0899f DK |
7566 | |
7567 | } else { | |
7568 | int num_segs, sb_idx, prod_offset; | |
7569 | ||
34f80b04 EG |
7570 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
7571 | ||
619c5cb6 | 7572 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7573 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
7574 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
7575 | } | |
7576 | ||
619c5cb6 | 7577 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 7578 | |
619c5cb6 | 7579 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7580 | int dsb_idx = 0; |
7581 | /** | |
7582 | * Producer memory: | |
7583 | * E2 mode: address 0-135 match to the mapping memory; | |
7584 | * 136 - PF0 default prod; 137 - PF1 default prod; | |
7585 | * 138 - PF2 default prod; 139 - PF3 default prod; | |
7586 | * 140 - PF0 attn prod; 141 - PF1 attn prod; | |
7587 | * 142 - PF2 attn prod; 143 - PF3 attn prod; | |
7588 | * 144-147 reserved. | |
7589 | * | |
7590 | * E1.5 mode - In backward compatible mode; | |
7591 | * for non default SB; each even line in the memory | |
7592 | * holds the U producer and each odd line hold | |
7593 | * the C producer. The first 128 producers are for | |
7594 | * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 | |
7595 | * producers are for the DSB for each PF. | |
7596 | * Each PF has five segments: (the order inside each | |
7597 | * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; | |
7598 | * 132-135 C prods; 136-139 X prods; 140-143 T prods; | |
7599 | * 144-147 attn prods; | |
7600 | */ | |
7601 | /* non-default-status-blocks */ | |
7602 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
7603 | IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; | |
7604 | for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) { | |
7605 | prod_offset = (bp->igu_base_sb + sb_idx) * | |
7606 | num_segs; | |
7607 | ||
7608 | for (i = 0; i < num_segs; i++) { | |
7609 | addr = IGU_REG_PROD_CONS_MEMORY + | |
7610 | (prod_offset + i) * 4; | |
7611 | REG_WR(bp, addr, 0); | |
7612 | } | |
7613 | /* send consumer update with value 0 */ | |
7614 | bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx, | |
7615 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7616 | bnx2x_igu_clear_sb(bp, | |
7617 | bp->igu_base_sb + sb_idx); | |
7618 | } | |
7619 | ||
7620 | /* default-status-blocks */ | |
7621 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
7622 | IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; | |
7623 | ||
7624 | if (CHIP_MODE_IS_4_PORT(bp)) | |
7625 | dsb_idx = BP_FUNC(bp); | |
7626 | else | |
3395a033 | 7627 | dsb_idx = BP_VN(bp); |
f2e0899f DK |
7628 | |
7629 | prod_offset = (CHIP_INT_MODE_IS_BC(bp) ? | |
7630 | IGU_BC_BASE_DSB_PROD + dsb_idx : | |
7631 | IGU_NORM_BASE_DSB_PROD + dsb_idx); | |
7632 | ||
3395a033 DK |
7633 | /* |
7634 | * igu prods come in chunks of E1HVN_MAX (4) - | |
7635 | * does not matters what is the current chip mode | |
7636 | */ | |
f2e0899f DK |
7637 | for (i = 0; i < (num_segs * E1HVN_MAX); |
7638 | i += E1HVN_MAX) { | |
7639 | addr = IGU_REG_PROD_CONS_MEMORY + | |
7640 | (prod_offset + i)*4; | |
7641 | REG_WR(bp, addr, 0); | |
7642 | } | |
7643 | /* send consumer update with 0 */ | |
7644 | if (CHIP_INT_MODE_IS_BC(bp)) { | |
7645 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7646 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7647 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7648 | CSTORM_ID, 0, IGU_INT_NOP, 1); | |
7649 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7650 | XSTORM_ID, 0, IGU_INT_NOP, 1); | |
7651 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7652 | TSTORM_ID, 0, IGU_INT_NOP, 1); | |
7653 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7654 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
7655 | } else { | |
7656 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7657 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7658 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7659 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
7660 | } | |
7661 | bnx2x_igu_clear_sb(bp, bp->igu_dsb_id); | |
7662 | ||
7663 | /* !!! these should become driver const once | |
7664 | rf-tool supports split-68 const */ | |
7665 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); | |
7666 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); | |
7667 | REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); | |
7668 | REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); | |
7669 | REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); | |
7670 | REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); | |
7671 | } | |
34f80b04 | 7672 | } |
34f80b04 | 7673 | |
c14423fe | 7674 | /* Reset PCIE errors for debug */ |
a2fbb9ea ET |
7675 | REG_WR(bp, 0x2114, 0xffffffff); |
7676 | REG_WR(bp, 0x2120, 0xffffffff); | |
523224a3 | 7677 | |
f4a66897 VZ |
7678 | if (CHIP_IS_E1x(bp)) { |
7679 | main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ | |
7680 | main_mem_base = HC_REG_MAIN_MEMORY + | |
7681 | BP_PORT(bp) * (main_mem_size * 4); | |
7682 | main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; | |
7683 | main_mem_width = 8; | |
7684 | ||
7685 | val = REG_RD(bp, main_mem_prty_clr); | |
7686 | if (val) | |
51c1a580 MS |
7687 | DP(NETIF_MSG_HW, |
7688 | "Hmmm... Parity errors in HC block during function init (0x%x)!\n", | |
7689 | val); | |
f4a66897 VZ |
7690 | |
7691 | /* Clear "false" parity errors in MSI-X table */ | |
7692 | for (i = main_mem_base; | |
7693 | i < main_mem_base + main_mem_size * 4; | |
7694 | i += main_mem_width) { | |
7695 | bnx2x_read_dmae(bp, i, main_mem_width / 4); | |
7696 | bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), | |
7697 | i, main_mem_width / 4); | |
7698 | } | |
7699 | /* Clear HC parity attention */ | |
7700 | REG_RD(bp, main_mem_prty_clr); | |
7701 | } | |
7702 | ||
619c5cb6 VZ |
7703 | #ifdef BNX2X_STOP_ON_ERROR |
7704 | /* Enable STORMs SP logging */ | |
7705 | REG_WR8(bp, BAR_USTRORM_INTMEM + | |
7706 | USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7707 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
7708 | TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7709 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
7710 | CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7711 | REG_WR8(bp, BAR_XSTRORM_INTMEM + | |
7712 | XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7713 | #endif | |
7714 | ||
b7737c9b | 7715 | bnx2x_phy_probe(&bp->link_params); |
f85582f8 | 7716 | |
34f80b04 EG |
7717 | return 0; |
7718 | } | |
7719 | ||
a2fbb9ea | 7720 | |
55c11941 MS |
7721 | void bnx2x_free_mem_cnic(struct bnx2x *bp) |
7722 | { | |
7723 | bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE); | |
7724 | ||
7725 | if (!CHIP_IS_E1x(bp)) | |
7726 | BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping, | |
7727 | sizeof(struct host_hc_status_block_e2)); | |
7728 | else | |
7729 | BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping, | |
7730 | sizeof(struct host_hc_status_block_e1x)); | |
7731 | ||
7732 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); | |
7733 | } | |
7734 | ||
9f6c9258 | 7735 | void bnx2x_free_mem(struct bnx2x *bp) |
a2fbb9ea | 7736 | { |
a052997e MS |
7737 | int i; |
7738 | ||
a2fbb9ea | 7739 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
523224a3 | 7740 | sizeof(struct host_sp_status_block)); |
a2fbb9ea | 7741 | |
619c5cb6 VZ |
7742 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
7743 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); | |
7744 | ||
a2fbb9ea | 7745 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
34f80b04 | 7746 | sizeof(struct bnx2x_slowpath)); |
a2fbb9ea | 7747 | |
a052997e MS |
7748 | for (i = 0; i < L2_ILT_LINES(bp); i++) |
7749 | BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping, | |
7750 | bp->context[i].size); | |
523224a3 DK |
7751 | bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE); |
7752 | ||
7753 | BNX2X_FREE(bp->ilt->lines); | |
f85582f8 | 7754 | |
7a9b2557 | 7755 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
a2fbb9ea | 7756 | |
523224a3 DK |
7757 | BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping, |
7758 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
580d9d08 YM |
7759 | |
7760 | bnx2x_iov_free_mem(bp); | |
619c5cb6 VZ |
7761 | } |
7762 | ||
a2fbb9ea | 7763 | |
55c11941 | 7764 | int bnx2x_alloc_mem_cnic(struct bnx2x *bp) |
a2fbb9ea | 7765 | { |
619c5cb6 VZ |
7766 | if (!CHIP_IS_E1x(bp)) |
7767 | /* size = the status block + ramrod buffers */ | |
f2e0899f DK |
7768 | BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, |
7769 | sizeof(struct host_hc_status_block_e2)); | |
7770 | else | |
55c11941 MS |
7771 | BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, |
7772 | &bp->cnic_sb_mapping, | |
7773 | sizeof(struct | |
7774 | host_hc_status_block_e1x)); | |
8badd27a | 7775 | |
55c11941 MS |
7776 | if (CONFIGURE_NIC_MODE(bp)) |
7777 | /* allocate searcher T2 table, as it wan't allocated before */ | |
7778 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); | |
7779 | ||
7780 | /* write address to which L5 should insert its values */ | |
7781 | bp->cnic_eth_dev.addr_drv_info_to_mcp = | |
7782 | &bp->slowpath->drv_info_to_mcp; | |
7783 | ||
7784 | if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC)) | |
7785 | goto alloc_mem_err; | |
7786 | ||
7787 | return 0; | |
7788 | ||
7789 | alloc_mem_err: | |
7790 | bnx2x_free_mem_cnic(bp); | |
7791 | BNX2X_ERR("Can't allocate memory\n"); | |
7792 | return -ENOMEM; | |
7793 | } | |
7794 | ||
7795 | int bnx2x_alloc_mem(struct bnx2x *bp) | |
7796 | { | |
7797 | int i, allocated, context_size; | |
a2fbb9ea | 7798 | |
55c11941 MS |
7799 | if (!CONFIGURE_NIC_MODE(bp)) |
7800 | /* allocate searcher T2 table */ | |
7801 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); | |
8badd27a | 7802 | |
523224a3 DK |
7803 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
7804 | sizeof(struct host_sp_status_block)); | |
a2fbb9ea | 7805 | |
523224a3 DK |
7806 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
7807 | sizeof(struct bnx2x_slowpath)); | |
a2fbb9ea | 7808 | |
a052997e MS |
7809 | /* Allocate memory for CDU context: |
7810 | * This memory is allocated separately and not in the generic ILT | |
7811 | * functions because CDU differs in few aspects: | |
7812 | * 1. There are multiple entities allocating memory for context - | |
7813 | * 'regular' driver, CNIC and SRIOV driver. Each separately controls | |
7814 | * its own ILT lines. | |
7815 | * 2. Since CDU page-size is not a single 4KB page (which is the case | |
7816 | * for the other ILT clients), to be efficient we want to support | |
7817 | * allocation of sub-page-size in the last entry. | |
7818 | * 3. Context pointers are used by the driver to pass to FW / update | |
7819 | * the context (for the other ILT clients the pointers are used just to | |
7820 | * free the memory during unload). | |
7821 | */ | |
7822 | context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp); | |
65abd74d | 7823 | |
a052997e MS |
7824 | for (i = 0, allocated = 0; allocated < context_size; i++) { |
7825 | bp->context[i].size = min(CDU_ILT_PAGE_SZ, | |
7826 | (context_size - allocated)); | |
7827 | BNX2X_PCI_ALLOC(bp->context[i].vcxt, | |
7828 | &bp->context[i].cxt_mapping, | |
7829 | bp->context[i].size); | |
7830 | allocated += bp->context[i].size; | |
7831 | } | |
523224a3 | 7832 | BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); |
65abd74d | 7833 | |
523224a3 DK |
7834 | if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) |
7835 | goto alloc_mem_err; | |
65abd74d | 7836 | |
67c431a5 AE |
7837 | if (bnx2x_iov_alloc_mem(bp)) |
7838 | goto alloc_mem_err; | |
7839 | ||
9f6c9258 DK |
7840 | /* Slow path ring */ |
7841 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); | |
65abd74d | 7842 | |
523224a3 DK |
7843 | /* EQ */ |
7844 | BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, | |
7845 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
ab532cf3 | 7846 | |
9f6c9258 | 7847 | return 0; |
e1510706 | 7848 | |
9f6c9258 DK |
7849 | alloc_mem_err: |
7850 | bnx2x_free_mem(bp); | |
51c1a580 | 7851 | BNX2X_ERR("Can't allocate memory\n"); |
9f6c9258 | 7852 | return -ENOMEM; |
65abd74d YG |
7853 | } |
7854 | ||
a2fbb9ea ET |
7855 | /* |
7856 | * Init service functions | |
7857 | */ | |
a2fbb9ea | 7858 | |
619c5cb6 VZ |
7859 | int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac, |
7860 | struct bnx2x_vlan_mac_obj *obj, bool set, | |
7861 | int mac_type, unsigned long *ramrod_flags) | |
a2fbb9ea | 7862 | { |
619c5cb6 VZ |
7863 | int rc; |
7864 | struct bnx2x_vlan_mac_ramrod_params ramrod_param; | |
a2fbb9ea | 7865 | |
619c5cb6 | 7866 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
a2fbb9ea | 7867 | |
619c5cb6 VZ |
7868 | /* Fill general parameters */ |
7869 | ramrod_param.vlan_mac_obj = obj; | |
7870 | ramrod_param.ramrod_flags = *ramrod_flags; | |
a2fbb9ea | 7871 | |
619c5cb6 VZ |
7872 | /* Fill a user request section if needed */ |
7873 | if (!test_bit(RAMROD_CONT, ramrod_flags)) { | |
7874 | memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); | |
a2fbb9ea | 7875 | |
619c5cb6 | 7876 | __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); |
e3553b29 | 7877 | |
619c5cb6 VZ |
7878 | /* Set the command: ADD or DEL */ |
7879 | if (set) | |
7880 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD; | |
7881 | else | |
7882 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL; | |
a2fbb9ea ET |
7883 | } |
7884 | ||
619c5cb6 | 7885 | rc = bnx2x_config_vlan_mac(bp, &ramrod_param); |
7b5342d9 YM |
7886 | |
7887 | if (rc == -EEXIST) { | |
7888 | DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc); | |
7889 | /* do not treat adding same MAC as error */ | |
7890 | rc = 0; | |
7891 | } else if (rc < 0) | |
619c5cb6 | 7892 | BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); |
7b5342d9 | 7893 | |
619c5cb6 | 7894 | return rc; |
a2fbb9ea ET |
7895 | } |
7896 | ||
619c5cb6 VZ |
7897 | int bnx2x_del_all_macs(struct bnx2x *bp, |
7898 | struct bnx2x_vlan_mac_obj *mac_obj, | |
7899 | int mac_type, bool wait_for_comp) | |
e665bfda | 7900 | { |
619c5cb6 VZ |
7901 | int rc; |
7902 | unsigned long ramrod_flags = 0, vlan_mac_flags = 0; | |
0793f83f | 7903 | |
619c5cb6 VZ |
7904 | /* Wait for completion of requested */ |
7905 | if (wait_for_comp) | |
7906 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
0793f83f | 7907 | |
619c5cb6 VZ |
7908 | /* Set the mac type of addresses we want to clear */ |
7909 | __set_bit(mac_type, &vlan_mac_flags); | |
0793f83f | 7910 | |
619c5cb6 VZ |
7911 | rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags); |
7912 | if (rc < 0) | |
7913 | BNX2X_ERR("Failed to delete MACs: %d\n", rc); | |
0793f83f | 7914 | |
619c5cb6 | 7915 | return rc; |
0793f83f DK |
7916 | } |
7917 | ||
619c5cb6 | 7918 | int bnx2x_set_eth_mac(struct bnx2x *bp, bool set) |
523224a3 | 7919 | { |
619c5cb6 | 7920 | unsigned long ramrod_flags = 0; |
e665bfda | 7921 | |
a3348722 BW |
7922 | if (is_zero_ether_addr(bp->dev->dev_addr) && |
7923 | (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) { | |
51c1a580 MS |
7924 | DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN, |
7925 | "Ignoring Zero MAC for STORAGE SD mode\n"); | |
614c76df DK |
7926 | return 0; |
7927 | } | |
614c76df | 7928 | |
619c5cb6 | 7929 | DP(NETIF_MSG_IFUP, "Adding Eth MAC\n"); |
0793f83f | 7930 | |
619c5cb6 VZ |
7931 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
7932 | /* Eth MAC is set on RSS leading client (fp[0]) */ | |
15192a8c BW |
7933 | return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj, |
7934 | set, BNX2X_ETH_MAC, &ramrod_flags); | |
e665bfda | 7935 | } |
6e30dd4e | 7936 | |
619c5cb6 | 7937 | int bnx2x_setup_leading(struct bnx2x *bp) |
ec6ba945 | 7938 | { |
619c5cb6 | 7939 | return bnx2x_setup_queue(bp, &bp->fp[0], 1); |
993ac7b5 | 7940 | } |
a2fbb9ea | 7941 | |
d6214d7a | 7942 | /** |
e8920674 | 7943 | * bnx2x_set_int_mode - configure interrupt mode |
d6214d7a | 7944 | * |
e8920674 | 7945 | * @bp: driver handle |
d6214d7a | 7946 | * |
e8920674 | 7947 | * In case of MSI-X it will also try to enable MSI-X. |
d6214d7a | 7948 | */ |
1ab4434c | 7949 | int bnx2x_set_int_mode(struct bnx2x *bp) |
ca00392c | 7950 | { |
1ab4434c AE |
7951 | int rc = 0; |
7952 | ||
7953 | if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) | |
7954 | return -EINVAL; | |
7955 | ||
9ee3d37b | 7956 | switch (int_mode) { |
1ab4434c AE |
7957 | case BNX2X_INT_MODE_MSIX: |
7958 | /* attempt to enable msix */ | |
7959 | rc = bnx2x_enable_msix(bp); | |
7960 | ||
7961 | /* msix attained */ | |
7962 | if (!rc) | |
7963 | return 0; | |
7964 | ||
7965 | /* vfs use only msix */ | |
7966 | if (rc && IS_VF(bp)) | |
7967 | return rc; | |
7968 | ||
7969 | /* failed to enable multiple MSI-X */ | |
7970 | BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n", | |
7971 | bp->num_queues, | |
7972 | 1 + bp->num_cnic_queues); | |
7973 | ||
7974 | /* falling through... */ | |
7975 | case BNX2X_INT_MODE_MSI: | |
d6214d7a | 7976 | bnx2x_enable_msi(bp); |
1ab4434c | 7977 | |
d6214d7a | 7978 | /* falling through... */ |
1ab4434c | 7979 | case BNX2X_INT_MODE_INTX: |
55c11941 MS |
7980 | bp->num_ethernet_queues = 1; |
7981 | bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues; | |
51c1a580 | 7982 | BNX2X_DEV_INFO("set number of queues to 1\n"); |
ca00392c | 7983 | break; |
d6214d7a | 7984 | default: |
1ab4434c AE |
7985 | BNX2X_DEV_INFO("unknown value in int_mode module parameter\n"); |
7986 | return -EINVAL; | |
9f6c9258 | 7987 | } |
1ab4434c | 7988 | return 0; |
a2fbb9ea ET |
7989 | } |
7990 | ||
1ab4434c | 7991 | /* must be called prior to any HW initializations */ |
c2bff63f DK |
7992 | static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp) |
7993 | { | |
290ca2bb AE |
7994 | if (IS_SRIOV(bp)) |
7995 | return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS; | |
c2bff63f DK |
7996 | return L2_ILT_LINES(bp); |
7997 | } | |
7998 | ||
523224a3 DK |
7999 | void bnx2x_ilt_set_info(struct bnx2x *bp) |
8000 | { | |
8001 | struct ilt_client_info *ilt_client; | |
8002 | struct bnx2x_ilt *ilt = BP_ILT(bp); | |
8003 | u16 line = 0; | |
8004 | ||
8005 | ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp)); | |
8006 | DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line); | |
8007 | ||
8008 | /* CDU */ | |
8009 | ilt_client = &ilt->clients[ILT_CLIENT_CDU]; | |
8010 | ilt_client->client_num = ILT_CLIENT_CDU; | |
8011 | ilt_client->page_size = CDU_ILT_PAGE_SZ; | |
8012 | ilt_client->flags = ILT_CLIENT_SKIP_MEM; | |
8013 | ilt_client->start = line; | |
619c5cb6 | 8014 | line += bnx2x_cid_ilt_lines(bp); |
55c11941 MS |
8015 | |
8016 | if (CNIC_SUPPORT(bp)) | |
8017 | line += CNIC_ILT_LINES; | |
523224a3 DK |
8018 | ilt_client->end = line - 1; |
8019 | ||
51c1a580 | 8020 | DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", |
523224a3 DK |
8021 | ilt_client->start, |
8022 | ilt_client->end, | |
8023 | ilt_client->page_size, | |
8024 | ilt_client->flags, | |
8025 | ilog2(ilt_client->page_size >> 12)); | |
8026 | ||
8027 | /* QM */ | |
8028 | if (QM_INIT(bp->qm_cid_count)) { | |
8029 | ilt_client = &ilt->clients[ILT_CLIENT_QM]; | |
8030 | ilt_client->client_num = ILT_CLIENT_QM; | |
8031 | ilt_client->page_size = QM_ILT_PAGE_SZ; | |
8032 | ilt_client->flags = 0; | |
8033 | ilt_client->start = line; | |
8034 | ||
8035 | /* 4 bytes for each cid */ | |
8036 | line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4, | |
8037 | QM_ILT_PAGE_SZ); | |
8038 | ||
8039 | ilt_client->end = line - 1; | |
8040 | ||
51c1a580 MS |
8041 | DP(NETIF_MSG_IFUP, |
8042 | "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
523224a3 DK |
8043 | ilt_client->start, |
8044 | ilt_client->end, | |
8045 | ilt_client->page_size, | |
8046 | ilt_client->flags, | |
8047 | ilog2(ilt_client->page_size >> 12)); | |
8048 | ||
8049 | } | |
523224a3 | 8050 | |
55c11941 MS |
8051 | if (CNIC_SUPPORT(bp)) { |
8052 | /* SRC */ | |
8053 | ilt_client = &ilt->clients[ILT_CLIENT_SRC]; | |
8054 | ilt_client->client_num = ILT_CLIENT_SRC; | |
8055 | ilt_client->page_size = SRC_ILT_PAGE_SZ; | |
8056 | ilt_client->flags = 0; | |
8057 | ilt_client->start = line; | |
8058 | line += SRC_ILT_LINES; | |
8059 | ilt_client->end = line - 1; | |
523224a3 | 8060 | |
55c11941 MS |
8061 | DP(NETIF_MSG_IFUP, |
8062 | "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
8063 | ilt_client->start, | |
8064 | ilt_client->end, | |
8065 | ilt_client->page_size, | |
8066 | ilt_client->flags, | |
8067 | ilog2(ilt_client->page_size >> 12)); | |
9f6c9258 | 8068 | |
55c11941 MS |
8069 | /* TM */ |
8070 | ilt_client = &ilt->clients[ILT_CLIENT_TM]; | |
8071 | ilt_client->client_num = ILT_CLIENT_TM; | |
8072 | ilt_client->page_size = TM_ILT_PAGE_SZ; | |
8073 | ilt_client->flags = 0; | |
8074 | ilt_client->start = line; | |
8075 | line += TM_ILT_LINES; | |
8076 | ilt_client->end = line - 1; | |
523224a3 | 8077 | |
55c11941 MS |
8078 | DP(NETIF_MSG_IFUP, |
8079 | "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
8080 | ilt_client->start, | |
8081 | ilt_client->end, | |
8082 | ilt_client->page_size, | |
8083 | ilt_client->flags, | |
8084 | ilog2(ilt_client->page_size >> 12)); | |
8085 | } | |
9f6c9258 | 8086 | |
619c5cb6 | 8087 | BUG_ON(line > ILT_MAX_LINES); |
523224a3 | 8088 | } |
f85582f8 | 8089 | |
619c5cb6 VZ |
8090 | /** |
8091 | * bnx2x_pf_q_prep_init - prepare INIT transition parameters | |
8092 | * | |
8093 | * @bp: driver handle | |
8094 | * @fp: pointer to fastpath | |
8095 | * @init_params: pointer to parameters structure | |
8096 | * | |
8097 | * parameters configured: | |
8098 | * - HC configuration | |
8099 | * - Queue's CDU context | |
8100 | */ | |
1191cb83 | 8101 | static void bnx2x_pf_q_prep_init(struct bnx2x *bp, |
619c5cb6 | 8102 | struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params) |
a2fbb9ea | 8103 | { |
6383c0b3 AE |
8104 | |
8105 | u8 cos; | |
a052997e MS |
8106 | int cxt_index, cxt_offset; |
8107 | ||
619c5cb6 VZ |
8108 | /* FCoE Queue uses Default SB, thus has no HC capabilities */ |
8109 | if (!IS_FCOE_FP(fp)) { | |
8110 | __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags); | |
8111 | __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags); | |
8112 | ||
8113 | /* If HC is supporterd, enable host coalescing in the transition | |
8114 | * to INIT state. | |
8115 | */ | |
8116 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags); | |
8117 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags); | |
8118 | ||
8119 | /* HC rate */ | |
8120 | init_params->rx.hc_rate = bp->rx_ticks ? | |
8121 | (1000000 / bp->rx_ticks) : 0; | |
8122 | init_params->tx.hc_rate = bp->tx_ticks ? | |
8123 | (1000000 / bp->tx_ticks) : 0; | |
8124 | ||
8125 | /* FW SB ID */ | |
8126 | init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = | |
8127 | fp->fw_sb_id; | |
8128 | ||
8129 | /* | |
8130 | * CQ index among the SB indices: FCoE clients uses the default | |
8131 | * SB, therefore it's different. | |
8132 | */ | |
6383c0b3 AE |
8133 | init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
8134 | init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS; | |
619c5cb6 VZ |
8135 | } |
8136 | ||
6383c0b3 AE |
8137 | /* set maximum number of COSs supported by this queue */ |
8138 | init_params->max_cos = fp->max_cos; | |
8139 | ||
51c1a580 | 8140 | DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n", |
6383c0b3 AE |
8141 | fp->index, init_params->max_cos); |
8142 | ||
8143 | /* set the context pointers queue object */ | |
a052997e | 8144 | for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) { |
65565884 MS |
8145 | cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS; |
8146 | cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index * | |
a052997e | 8147 | ILT_PAGE_CIDS); |
6383c0b3 | 8148 | init_params->cxts[cos] = |
a052997e MS |
8149 | &bp->context[cxt_index].vcxt[cxt_offset].eth; |
8150 | } | |
619c5cb6 VZ |
8151 | } |
8152 | ||
910cc727 | 8153 | static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
6383c0b3 AE |
8154 | struct bnx2x_queue_state_params *q_params, |
8155 | struct bnx2x_queue_setup_tx_only_params *tx_only_params, | |
8156 | int tx_index, bool leading) | |
8157 | { | |
8158 | memset(tx_only_params, 0, sizeof(*tx_only_params)); | |
8159 | ||
8160 | /* Set the command */ | |
8161 | q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; | |
8162 | ||
8163 | /* Set tx-only QUEUE flags: don't zero statistics */ | |
8164 | tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false); | |
8165 | ||
8166 | /* choose the index of the cid to send the slow path on */ | |
8167 | tx_only_params->cid_index = tx_index; | |
8168 | ||
8169 | /* Set general TX_ONLY_SETUP parameters */ | |
8170 | bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index); | |
8171 | ||
8172 | /* Set Tx TX_ONLY_SETUP parameters */ | |
8173 | bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index); | |
8174 | ||
51c1a580 MS |
8175 | DP(NETIF_MSG_IFUP, |
8176 | "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n", | |
6383c0b3 AE |
8177 | tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX], |
8178 | q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id, | |
8179 | tx_only_params->gen_params.spcl_id, tx_only_params->flags); | |
8180 | ||
8181 | /* send the ramrod */ | |
8182 | return bnx2x_queue_state_change(bp, q_params); | |
8183 | } | |
8184 | ||
8185 | ||
619c5cb6 VZ |
8186 | /** |
8187 | * bnx2x_setup_queue - setup queue | |
8188 | * | |
8189 | * @bp: driver handle | |
8190 | * @fp: pointer to fastpath | |
8191 | * @leading: is leading | |
8192 | * | |
8193 | * This function performs 2 steps in a Queue state machine | |
8194 | * actually: 1) RESET->INIT 2) INIT->SETUP | |
8195 | */ | |
8196 | ||
8197 | int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp, | |
8198 | bool leading) | |
8199 | { | |
3b603066 | 8200 | struct bnx2x_queue_state_params q_params = {NULL}; |
619c5cb6 VZ |
8201 | struct bnx2x_queue_setup_params *setup_params = |
8202 | &q_params.params.setup; | |
6383c0b3 AE |
8203 | struct bnx2x_queue_setup_tx_only_params *tx_only_params = |
8204 | &q_params.params.tx_only; | |
a2fbb9ea | 8205 | int rc; |
6383c0b3 AE |
8206 | u8 tx_index; |
8207 | ||
51c1a580 | 8208 | DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index); |
a2fbb9ea | 8209 | |
ec6ba945 VZ |
8210 | /* reset IGU state skip FCoE L2 queue */ |
8211 | if (!IS_FCOE_FP(fp)) | |
8212 | bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, | |
523224a3 | 8213 | IGU_INT_ENABLE, 0); |
a2fbb9ea | 8214 | |
15192a8c | 8215 | q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
619c5cb6 VZ |
8216 | /* We want to wait for completion in this context */ |
8217 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 8218 | |
619c5cb6 VZ |
8219 | /* Prepare the INIT parameters */ |
8220 | bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init); | |
ec6ba945 | 8221 | |
619c5cb6 VZ |
8222 | /* Set the command */ |
8223 | q_params.cmd = BNX2X_Q_CMD_INIT; | |
8224 | ||
8225 | /* Change the state to INIT */ | |
8226 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8227 | if (rc) { | |
6383c0b3 | 8228 | BNX2X_ERR("Queue(%d) INIT failed\n", fp->index); |
619c5cb6 VZ |
8229 | return rc; |
8230 | } | |
ec6ba945 | 8231 | |
51c1a580 | 8232 | DP(NETIF_MSG_IFUP, "init complete\n"); |
6383c0b3 AE |
8233 | |
8234 | ||
619c5cb6 VZ |
8235 | /* Now move the Queue to the SETUP state... */ |
8236 | memset(setup_params, 0, sizeof(*setup_params)); | |
a2fbb9ea | 8237 | |
619c5cb6 VZ |
8238 | /* Set QUEUE flags */ |
8239 | setup_params->flags = bnx2x_get_q_flags(bp, fp, leading); | |
523224a3 | 8240 | |
619c5cb6 | 8241 | /* Set general SETUP parameters */ |
6383c0b3 AE |
8242 | bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params, |
8243 | FIRST_TX_COS_INDEX); | |
619c5cb6 | 8244 | |
6383c0b3 | 8245 | bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params, |
619c5cb6 VZ |
8246 | &setup_params->rxq_params); |
8247 | ||
6383c0b3 AE |
8248 | bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params, |
8249 | FIRST_TX_COS_INDEX); | |
619c5cb6 VZ |
8250 | |
8251 | /* Set the command */ | |
8252 | q_params.cmd = BNX2X_Q_CMD_SETUP; | |
8253 | ||
55c11941 MS |
8254 | if (IS_FCOE_FP(fp)) |
8255 | bp->fcoe_init = true; | |
8256 | ||
619c5cb6 VZ |
8257 | /* Change the state to SETUP */ |
8258 | rc = bnx2x_queue_state_change(bp, &q_params); | |
6383c0b3 AE |
8259 | if (rc) { |
8260 | BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index); | |
8261 | return rc; | |
8262 | } | |
8263 | ||
8264 | /* loop through the relevant tx-only indices */ | |
8265 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
8266 | tx_index < fp->max_cos; | |
8267 | tx_index++) { | |
8268 | ||
8269 | /* prepare and send tx-only ramrod*/ | |
8270 | rc = bnx2x_setup_tx_only(bp, fp, &q_params, | |
8271 | tx_only_params, tx_index, leading); | |
8272 | if (rc) { | |
8273 | BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n", | |
8274 | fp->index, tx_index); | |
8275 | return rc; | |
8276 | } | |
8277 | } | |
523224a3 | 8278 | |
34f80b04 | 8279 | return rc; |
a2fbb9ea ET |
8280 | } |
8281 | ||
619c5cb6 | 8282 | static int bnx2x_stop_queue(struct bnx2x *bp, int index) |
a2fbb9ea | 8283 | { |
619c5cb6 | 8284 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
6383c0b3 | 8285 | struct bnx2x_fp_txdata *txdata; |
3b603066 | 8286 | struct bnx2x_queue_state_params q_params = {NULL}; |
6383c0b3 AE |
8287 | int rc, tx_index; |
8288 | ||
51c1a580 | 8289 | DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid); |
a2fbb9ea | 8290 | |
15192a8c | 8291 | q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
619c5cb6 VZ |
8292 | /* We want to wait for completion in this context */ |
8293 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 8294 | |
6383c0b3 AE |
8295 | |
8296 | /* close tx-only connections */ | |
8297 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
8298 | tx_index < fp->max_cos; | |
8299 | tx_index++){ | |
8300 | ||
8301 | /* ascertain this is a normal queue*/ | |
65565884 | 8302 | txdata = fp->txdata_ptr[tx_index]; |
6383c0b3 | 8303 | |
51c1a580 | 8304 | DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n", |
6383c0b3 AE |
8305 | txdata->txq_index); |
8306 | ||
8307 | /* send halt terminate on tx-only connection */ | |
8308 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; | |
8309 | memset(&q_params.params.terminate, 0, | |
8310 | sizeof(q_params.params.terminate)); | |
8311 | q_params.params.terminate.cid_index = tx_index; | |
8312 | ||
8313 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8314 | if (rc) | |
8315 | return rc; | |
8316 | ||
8317 | /* send halt terminate on tx-only connection */ | |
8318 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; | |
8319 | memset(&q_params.params.cfc_del, 0, | |
8320 | sizeof(q_params.params.cfc_del)); | |
8321 | q_params.params.cfc_del.cid_index = tx_index; | |
8322 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8323 | if (rc) | |
8324 | return rc; | |
8325 | } | |
8326 | /* Stop the primary connection: */ | |
8327 | /* ...halt the connection */ | |
619c5cb6 VZ |
8328 | q_params.cmd = BNX2X_Q_CMD_HALT; |
8329 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8330 | if (rc) | |
da5a662a | 8331 | return rc; |
a2fbb9ea | 8332 | |
6383c0b3 | 8333 | /* ...terminate the connection */ |
619c5cb6 | 8334 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; |
6383c0b3 AE |
8335 | memset(&q_params.params.terminate, 0, |
8336 | sizeof(q_params.params.terminate)); | |
8337 | q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 VZ |
8338 | rc = bnx2x_queue_state_change(bp, &q_params); |
8339 | if (rc) | |
523224a3 | 8340 | return rc; |
6383c0b3 | 8341 | /* ...delete cfc entry */ |
619c5cb6 | 8342 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; |
6383c0b3 AE |
8343 | memset(&q_params.params.cfc_del, 0, |
8344 | sizeof(q_params.params.cfc_del)); | |
8345 | q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 | 8346 | return bnx2x_queue_state_change(bp, &q_params); |
523224a3 DK |
8347 | } |
8348 | ||
8349 | ||
34f80b04 EG |
8350 | static void bnx2x_reset_func(struct bnx2x *bp) |
8351 | { | |
8352 | int port = BP_PORT(bp); | |
8353 | int func = BP_FUNC(bp); | |
f2e0899f | 8354 | int i; |
523224a3 DK |
8355 | |
8356 | /* Disable the function in the FW */ | |
8357 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); | |
8358 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); | |
8359 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); | |
8360 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); | |
8361 | ||
8362 | /* FP SBs */ | |
ec6ba945 | 8363 | for_each_eth_queue(bp, i) { |
523224a3 | 8364 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
619c5cb6 | 8365 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
6383c0b3 AE |
8366 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), |
8367 | SB_DISABLED); | |
523224a3 DK |
8368 | } |
8369 | ||
55c11941 MS |
8370 | if (CNIC_LOADED(bp)) |
8371 | /* CNIC SB */ | |
8372 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
8373 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET | |
8374 | (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED); | |
8375 | ||
523224a3 | 8376 | /* SP SB */ |
619c5cb6 | 8377 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
2de67439 YM |
8378 | CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), |
8379 | SB_DISABLED); | |
523224a3 DK |
8380 | |
8381 | for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) | |
8382 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), | |
8383 | 0); | |
34f80b04 EG |
8384 | |
8385 | /* Configure IGU */ | |
f2e0899f DK |
8386 | if (bp->common.int_block == INT_BLOCK_HC) { |
8387 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
8388 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
8389 | } else { | |
8390 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); | |
8391 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
8392 | } | |
34f80b04 | 8393 | |
55c11941 MS |
8394 | if (CNIC_LOADED(bp)) { |
8395 | /* Disable Timer scan */ | |
8396 | REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0); | |
8397 | /* | |
8398 | * Wait for at least 10ms and up to 2 second for the timers | |
8399 | * scan to complete | |
8400 | */ | |
8401 | for (i = 0; i < 200; i++) { | |
8402 | msleep(10); | |
8403 | if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4)) | |
8404 | break; | |
8405 | } | |
37b091ba | 8406 | } |
34f80b04 | 8407 | /* Clear ILT */ |
f2e0899f DK |
8408 | bnx2x_clear_func_ilt(bp, func); |
8409 | ||
8410 | /* Timers workaround bug for E2: if this is vnic-3, | |
8411 | * we need to set the entire ilt range for this timers. | |
8412 | */ | |
619c5cb6 | 8413 | if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) { |
f2e0899f DK |
8414 | struct ilt_client_info ilt_cli; |
8415 | /* use dummy TM client */ | |
8416 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
8417 | ilt_cli.start = 0; | |
8418 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
8419 | ilt_cli.client_num = ILT_CLIENT_TM; | |
8420 | ||
8421 | bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR); | |
8422 | } | |
8423 | ||
8424 | /* this assumes that reset_port() called before reset_func()*/ | |
619c5cb6 | 8425 | if (!CHIP_IS_E1x(bp)) |
f2e0899f | 8426 | bnx2x_pf_disable(bp); |
523224a3 DK |
8427 | |
8428 | bp->dmae_ready = 0; | |
34f80b04 EG |
8429 | } |
8430 | ||
8431 | static void bnx2x_reset_port(struct bnx2x *bp) | |
8432 | { | |
8433 | int port = BP_PORT(bp); | |
8434 | u32 val; | |
8435 | ||
619c5cb6 VZ |
8436 | /* Reset physical Link */ |
8437 | bnx2x__link_reset(bp); | |
8438 | ||
34f80b04 EG |
8439 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
8440 | ||
8441 | /* Do not rcv packets to BRB */ | |
8442 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); | |
8443 | /* Do not direct rcv packets that are not for MCP to the BRB */ | |
8444 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : | |
8445 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); | |
8446 | ||
8447 | /* Configure AEU */ | |
8448 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); | |
8449 | ||
8450 | msleep(100); | |
8451 | /* Check for BRB port occupancy */ | |
8452 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); | |
8453 | if (val) | |
8454 | DP(NETIF_MSG_IFDOWN, | |
33471629 | 8455 | "BRB1 is not empty %d blocks are occupied\n", val); |
34f80b04 EG |
8456 | |
8457 | /* TODO: Close Doorbell port? */ | |
8458 | } | |
8459 | ||
1191cb83 | 8460 | static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code) |
34f80b04 | 8461 | { |
3b603066 | 8462 | struct bnx2x_func_state_params func_params = {NULL}; |
34f80b04 | 8463 | |
619c5cb6 VZ |
8464 | /* Prepare parameters for function state transitions */ |
8465 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
34f80b04 | 8466 | |
619c5cb6 VZ |
8467 | func_params.f_obj = &bp->func_obj; |
8468 | func_params.cmd = BNX2X_F_CMD_HW_RESET; | |
34f80b04 | 8469 | |
619c5cb6 | 8470 | func_params.params.hw_init.load_phase = load_code; |
49d66772 | 8471 | |
619c5cb6 | 8472 | return bnx2x_func_state_change(bp, &func_params); |
34f80b04 EG |
8473 | } |
8474 | ||
1191cb83 | 8475 | static int bnx2x_func_stop(struct bnx2x *bp) |
ec6ba945 | 8476 | { |
3b603066 | 8477 | struct bnx2x_func_state_params func_params = {NULL}; |
619c5cb6 | 8478 | int rc; |
228241eb | 8479 | |
619c5cb6 VZ |
8480 | /* Prepare parameters for function state transitions */ |
8481 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
8482 | func_params.f_obj = &bp->func_obj; | |
8483 | func_params.cmd = BNX2X_F_CMD_STOP; | |
da5a662a | 8484 | |
619c5cb6 VZ |
8485 | /* |
8486 | * Try to stop the function the 'good way'. If fails (in case | |
8487 | * of a parity error during bnx2x_chip_cleanup()) and we are | |
8488 | * not in a debug mode, perform a state transaction in order to | |
8489 | * enable further HW_RESET transaction. | |
8490 | */ | |
8491 | rc = bnx2x_func_state_change(bp, &func_params); | |
8492 | if (rc) { | |
34f80b04 | 8493 | #ifdef BNX2X_STOP_ON_ERROR |
619c5cb6 | 8494 | return rc; |
34f80b04 | 8495 | #else |
51c1a580 | 8496 | BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n"); |
619c5cb6 VZ |
8497 | __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); |
8498 | return bnx2x_func_state_change(bp, &func_params); | |
34f80b04 | 8499 | #endif |
228241eb | 8500 | } |
a2fbb9ea | 8501 | |
619c5cb6 VZ |
8502 | return 0; |
8503 | } | |
523224a3 | 8504 | |
619c5cb6 VZ |
8505 | /** |
8506 | * bnx2x_send_unload_req - request unload mode from the MCP. | |
8507 | * | |
8508 | * @bp: driver handle | |
8509 | * @unload_mode: requested function's unload mode | |
8510 | * | |
8511 | * Return unload mode returned by the MCP: COMMON, PORT or FUNC. | |
8512 | */ | |
8513 | u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode) | |
8514 | { | |
8515 | u32 reset_code = 0; | |
8516 | int port = BP_PORT(bp); | |
3101c2bc | 8517 | |
619c5cb6 | 8518 | /* Select the UNLOAD request mode */ |
65abd74d YG |
8519 | if (unload_mode == UNLOAD_NORMAL) |
8520 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
8521 | ||
7d0446c2 | 8522 | else if (bp->flags & NO_WOL_FLAG) |
65abd74d | 8523 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
65abd74d | 8524 | |
7d0446c2 | 8525 | else if (bp->wol) { |
65abd74d YG |
8526 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
8527 | u8 *mac_addr = bp->dev->dev_addr; | |
8528 | u32 val; | |
f9977903 DK |
8529 | u16 pmc; |
8530 | ||
65abd74d | 8531 | /* The mac address is written to entries 1-4 to |
f9977903 DK |
8532 | * preserve entry 0 which is used by the PMF |
8533 | */ | |
3395a033 | 8534 | u8 entry = (BP_VN(bp) + 1)*8; |
65abd74d YG |
8535 | |
8536 | val = (mac_addr[0] << 8) | mac_addr[1]; | |
8537 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); | |
8538 | ||
8539 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | | |
8540 | (mac_addr[4] << 8) | mac_addr[5]; | |
8541 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); | |
8542 | ||
f9977903 DK |
8543 | /* Enable the PME and clear the status */ |
8544 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc); | |
8545 | pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS; | |
8546 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc); | |
8547 | ||
65abd74d YG |
8548 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
8549 | ||
8550 | } else | |
8551 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
da5a662a | 8552 | |
619c5cb6 VZ |
8553 | /* Send the request to the MCP */ |
8554 | if (!BP_NOMCP(bp)) | |
8555 | reset_code = bnx2x_fw_command(bp, reset_code, 0); | |
8556 | else { | |
8557 | int path = BP_PATH(bp); | |
8558 | ||
51c1a580 | 8559 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
8560 | path, load_count[path][0], load_count[path][1], |
8561 | load_count[path][2]); | |
8562 | load_count[path][0]--; | |
8563 | load_count[path][1 + port]--; | |
51c1a580 | 8564 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
8565 | path, load_count[path][0], load_count[path][1], |
8566 | load_count[path][2]); | |
8567 | if (load_count[path][0] == 0) | |
8568 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; | |
8569 | else if (load_count[path][1 + port] == 0) | |
8570 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; | |
8571 | else | |
8572 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; | |
8573 | } | |
8574 | ||
8575 | return reset_code; | |
8576 | } | |
8577 | ||
8578 | /** | |
8579 | * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP. | |
8580 | * | |
8581 | * @bp: driver handle | |
5d07d868 | 8582 | * @keep_link: true iff link should be kept up |
619c5cb6 | 8583 | */ |
5d07d868 | 8584 | void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link) |
619c5cb6 | 8585 | { |
5d07d868 YM |
8586 | u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0; |
8587 | ||
619c5cb6 VZ |
8588 | /* Report UNLOAD_DONE to MCP */ |
8589 | if (!BP_NOMCP(bp)) | |
5d07d868 | 8590 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param); |
619c5cb6 VZ |
8591 | } |
8592 | ||
1191cb83 | 8593 | static int bnx2x_func_wait_started(struct bnx2x *bp) |
6debea87 DK |
8594 | { |
8595 | int tout = 50; | |
8596 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; | |
8597 | ||
8598 | if (!bp->port.pmf) | |
8599 | return 0; | |
8600 | ||
8601 | /* | |
8602 | * (assumption: No Attention from MCP at this stage) | |
8603 | * PMF probably in the middle of TXdisable/enable transaction | |
8604 | * 1. Sync IRS for default SB | |
8605 | * 2. Sync SP queue - this guarantes us that attention handling started | |
8606 | * 3. Wait, that TXdisable/enable transaction completes | |
8607 | * | |
8608 | * 1+2 guranty that if DCBx attention was scheduled it already changed | |
8609 | * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy | |
8610 | * received complettion for the transaction the state is TX_STOPPED. | |
8611 | * State will return to STARTED after completion of TX_STOPPED-->STARTED | |
8612 | * transaction. | |
8613 | */ | |
8614 | ||
8615 | /* make sure default SB ISR is done */ | |
8616 | if (msix) | |
8617 | synchronize_irq(bp->msix_table[0].vector); | |
8618 | else | |
8619 | synchronize_irq(bp->pdev->irq); | |
8620 | ||
8621 | flush_workqueue(bnx2x_wq); | |
8622 | ||
8623 | while (bnx2x_func_get_state(bp, &bp->func_obj) != | |
8624 | BNX2X_F_STATE_STARTED && tout--) | |
8625 | msleep(20); | |
8626 | ||
8627 | if (bnx2x_func_get_state(bp, &bp->func_obj) != | |
8628 | BNX2X_F_STATE_STARTED) { | |
8629 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 | 8630 | BNX2X_ERR("Wrong function state\n"); |
6debea87 DK |
8631 | return -EBUSY; |
8632 | #else | |
8633 | /* | |
8634 | * Failed to complete the transaction in a "good way" | |
8635 | * Force both transactions with CLR bit | |
8636 | */ | |
3b603066 | 8637 | struct bnx2x_func_state_params func_params = {NULL}; |
6debea87 | 8638 | |
51c1a580 MS |
8639 | DP(NETIF_MSG_IFDOWN, |
8640 | "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n"); | |
6debea87 DK |
8641 | |
8642 | func_params.f_obj = &bp->func_obj; | |
8643 | __set_bit(RAMROD_DRV_CLR_ONLY, | |
8644 | &func_params.ramrod_flags); | |
8645 | ||
8646 | /* STARTED-->TX_ST0PPED */ | |
8647 | func_params.cmd = BNX2X_F_CMD_TX_STOP; | |
8648 | bnx2x_func_state_change(bp, &func_params); | |
8649 | ||
8650 | /* TX_ST0PPED-->STARTED */ | |
8651 | func_params.cmd = BNX2X_F_CMD_TX_START; | |
8652 | return bnx2x_func_state_change(bp, &func_params); | |
8653 | #endif | |
8654 | } | |
8655 | ||
8656 | return 0; | |
8657 | } | |
8658 | ||
5d07d868 | 8659 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link) |
619c5cb6 VZ |
8660 | { |
8661 | int port = BP_PORT(bp); | |
6383c0b3 AE |
8662 | int i, rc = 0; |
8663 | u8 cos; | |
3b603066 | 8664 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 VZ |
8665 | u32 reset_code; |
8666 | ||
8667 | /* Wait until tx fastpath tasks complete */ | |
8668 | for_each_tx_queue(bp, i) { | |
8669 | struct bnx2x_fastpath *fp = &bp->fp[i]; | |
8670 | ||
6383c0b3 | 8671 | for_each_cos_in_tx_queue(fp, cos) |
65565884 | 8672 | rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]); |
619c5cb6 VZ |
8673 | #ifdef BNX2X_STOP_ON_ERROR |
8674 | if (rc) | |
8675 | return; | |
8676 | #endif | |
8677 | } | |
8678 | ||
8679 | /* Give HW time to discard old tx messages */ | |
0926d499 | 8680 | usleep_range(1000, 2000); |
619c5cb6 VZ |
8681 | |
8682 | /* Clean all ETH MACs */ | |
15192a8c BW |
8683 | rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC, |
8684 | false); | |
619c5cb6 VZ |
8685 | if (rc < 0) |
8686 | BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc); | |
8687 | ||
8688 | /* Clean up UC list */ | |
15192a8c | 8689 | rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC, |
619c5cb6 VZ |
8690 | true); |
8691 | if (rc < 0) | |
51c1a580 MS |
8692 | BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n", |
8693 | rc); | |
619c5cb6 VZ |
8694 | |
8695 | /* Disable LLH */ | |
8696 | if (!CHIP_IS_E1(bp)) | |
8697 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
8698 | ||
8699 | /* Set "drop all" (stop Rx). | |
8700 | * We need to take a netif_addr_lock() here in order to prevent | |
8701 | * a race between the completion code and this code. | |
8702 | */ | |
8703 | netif_addr_lock_bh(bp->dev); | |
8704 | /* Schedule the rx_mode command */ | |
8705 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
8706 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
8707 | else | |
8708 | bnx2x_set_storm_rx_mode(bp); | |
8709 | ||
8710 | /* Cleanup multicast configuration */ | |
8711 | rparam.mcast_obj = &bp->mcast_obj; | |
8712 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
8713 | if (rc < 0) | |
8714 | BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc); | |
8715 | ||
8716 | netif_addr_unlock_bh(bp->dev); | |
8717 | ||
f1929b01 | 8718 | bnx2x_iov_chip_cleanup(bp); |
619c5cb6 | 8719 | |
6debea87 DK |
8720 | |
8721 | /* | |
8722 | * Send the UNLOAD_REQUEST to the MCP. This will return if | |
8723 | * this function should perform FUNC, PORT or COMMON HW | |
8724 | * reset. | |
8725 | */ | |
8726 | reset_code = bnx2x_send_unload_req(bp, unload_mode); | |
8727 | ||
8728 | /* | |
8729 | * (assumption: No Attention from MCP at this stage) | |
8730 | * PMF probably in the middle of TXdisable/enable transaction | |
8731 | */ | |
8732 | rc = bnx2x_func_wait_started(bp); | |
8733 | if (rc) { | |
8734 | BNX2X_ERR("bnx2x_func_wait_started failed\n"); | |
8735 | #ifdef BNX2X_STOP_ON_ERROR | |
8736 | return; | |
8737 | #endif | |
8738 | } | |
8739 | ||
34f80b04 | 8740 | /* Close multi and leading connections |
619c5cb6 VZ |
8741 | * Completions for ramrods are collected in a synchronous way |
8742 | */ | |
55c11941 | 8743 | for_each_eth_queue(bp, i) |
619c5cb6 | 8744 | if (bnx2x_stop_queue(bp, i)) |
523224a3 DK |
8745 | #ifdef BNX2X_STOP_ON_ERROR |
8746 | return; | |
8747 | #else | |
228241eb | 8748 | goto unload_error; |
523224a3 | 8749 | #endif |
55c11941 MS |
8750 | |
8751 | if (CNIC_LOADED(bp)) { | |
8752 | for_each_cnic_queue(bp, i) | |
8753 | if (bnx2x_stop_queue(bp, i)) | |
8754 | #ifdef BNX2X_STOP_ON_ERROR | |
8755 | return; | |
8756 | #else | |
8757 | goto unload_error; | |
8758 | #endif | |
8759 | } | |
8760 | ||
619c5cb6 VZ |
8761 | /* If SP settings didn't get completed so far - something |
8762 | * very wrong has happen. | |
8763 | */ | |
8764 | if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) | |
8765 | BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n"); | |
a2fbb9ea | 8766 | |
619c5cb6 VZ |
8767 | #ifndef BNX2X_STOP_ON_ERROR |
8768 | unload_error: | |
8769 | #endif | |
523224a3 | 8770 | rc = bnx2x_func_stop(bp); |
da5a662a | 8771 | if (rc) { |
523224a3 | 8772 | BNX2X_ERR("Function stop failed!\n"); |
da5a662a | 8773 | #ifdef BNX2X_STOP_ON_ERROR |
523224a3 | 8774 | return; |
523224a3 | 8775 | #endif |
34f80b04 | 8776 | } |
a2fbb9ea | 8777 | |
523224a3 DK |
8778 | /* Disable HW interrupts, NAPI */ |
8779 | bnx2x_netif_stop(bp, 1); | |
26614ba5 MS |
8780 | /* Delete all NAPI objects */ |
8781 | bnx2x_del_all_napi(bp); | |
55c11941 MS |
8782 | if (CNIC_LOADED(bp)) |
8783 | bnx2x_del_all_napi_cnic(bp); | |
523224a3 DK |
8784 | |
8785 | /* Release IRQs */ | |
d6214d7a | 8786 | bnx2x_free_irq(bp); |
523224a3 | 8787 | |
a2fbb9ea | 8788 | /* Reset the chip */ |
619c5cb6 VZ |
8789 | rc = bnx2x_reset_hw(bp, reset_code); |
8790 | if (rc) | |
8791 | BNX2X_ERR("HW_RESET failed\n"); | |
a2fbb9ea | 8792 | |
356e2385 | 8793 | |
619c5cb6 | 8794 | /* Report UNLOAD_DONE to MCP */ |
5d07d868 | 8795 | bnx2x_send_unload_done(bp, keep_link); |
72fd0718 VZ |
8796 | } |
8797 | ||
9f6c9258 | 8798 | void bnx2x_disable_close_the_gate(struct bnx2x *bp) |
72fd0718 VZ |
8799 | { |
8800 | u32 val; | |
8801 | ||
51c1a580 | 8802 | DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n"); |
72fd0718 VZ |
8803 | |
8804 | if (CHIP_IS_E1(bp)) { | |
8805 | int port = BP_PORT(bp); | |
8806 | u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
8807 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
8808 | ||
8809 | val = REG_RD(bp, addr); | |
8810 | val &= ~(0x300); | |
8811 | REG_WR(bp, addr, val); | |
619c5cb6 | 8812 | } else { |
72fd0718 VZ |
8813 | val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK); |
8814 | val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | | |
8815 | MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); | |
8816 | REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val); | |
8817 | } | |
8818 | } | |
8819 | ||
72fd0718 VZ |
8820 | /* Close gates #2, #3 and #4: */ |
8821 | static void bnx2x_set_234_gates(struct bnx2x *bp, bool close) | |
8822 | { | |
c9ee9206 | 8823 | u32 val; |
72fd0718 VZ |
8824 | |
8825 | /* Gates #2 and #4a are closed/opened for "not E1" only */ | |
8826 | if (!CHIP_IS_E1(bp)) { | |
8827 | /* #4 */ | |
c9ee9206 | 8828 | REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close); |
72fd0718 | 8829 | /* #2 */ |
c9ee9206 | 8830 | REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); |
72fd0718 VZ |
8831 | } |
8832 | ||
8833 | /* #3 */ | |
c9ee9206 VZ |
8834 | if (CHIP_IS_E1x(bp)) { |
8835 | /* Prevent interrupts from HC on both ports */ | |
8836 | val = REG_RD(bp, HC_REG_CONFIG_1); | |
8837 | REG_WR(bp, HC_REG_CONFIG_1, | |
8838 | (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : | |
8839 | (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); | |
8840 | ||
8841 | val = REG_RD(bp, HC_REG_CONFIG_0); | |
8842 | REG_WR(bp, HC_REG_CONFIG_0, | |
8843 | (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : | |
8844 | (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); | |
8845 | } else { | |
d82603c6 | 8846 | /* Prevent incoming interrupts in IGU */ |
c9ee9206 VZ |
8847 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
8848 | ||
8849 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, | |
8850 | (!close) ? | |
8851 | (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : | |
8852 | (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); | |
8853 | } | |
72fd0718 | 8854 | |
51c1a580 | 8855 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n", |
72fd0718 VZ |
8856 | close ? "closing" : "opening"); |
8857 | mmiowb(); | |
8858 | } | |
8859 | ||
8860 | #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */ | |
8861 | ||
8862 | static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val) | |
8863 | { | |
8864 | /* Do some magic... */ | |
8865 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); | |
8866 | *magic_val = val & SHARED_MF_CLP_MAGIC; | |
8867 | MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); | |
8868 | } | |
8869 | ||
e8920674 DK |
8870 | /** |
8871 | * bnx2x_clp_reset_done - restore the value of the `magic' bit. | |
72fd0718 | 8872 | * |
e8920674 DK |
8873 | * @bp: driver handle |
8874 | * @magic_val: old value of the `magic' bit. | |
72fd0718 VZ |
8875 | */ |
8876 | static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val) | |
8877 | { | |
8878 | /* Restore the `magic' bit value... */ | |
72fd0718 VZ |
8879 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
8880 | MF_CFG_WR(bp, shared_mf_config.clp_mb, | |
8881 | (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); | |
8882 | } | |
8883 | ||
f85582f8 | 8884 | /** |
e8920674 | 8885 | * bnx2x_reset_mcp_prep - prepare for MCP reset. |
72fd0718 | 8886 | * |
e8920674 DK |
8887 | * @bp: driver handle |
8888 | * @magic_val: old value of 'magic' bit. | |
8889 | * | |
8890 | * Takes care of CLP configurations. | |
72fd0718 VZ |
8891 | */ |
8892 | static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val) | |
8893 | { | |
8894 | u32 shmem; | |
8895 | u32 validity_offset; | |
8896 | ||
51c1a580 | 8897 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n"); |
72fd0718 VZ |
8898 | |
8899 | /* Set `magic' bit in order to save MF config */ | |
8900 | if (!CHIP_IS_E1(bp)) | |
8901 | bnx2x_clp_reset_prep(bp, magic_val); | |
8902 | ||
8903 | /* Get shmem offset */ | |
8904 | shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
c55e771b BW |
8905 | validity_offset = |
8906 | offsetof(struct shmem_region, validity_map[BP_PORT(bp)]); | |
72fd0718 VZ |
8907 | |
8908 | /* Clear validity map flags */ | |
8909 | if (shmem > 0) | |
8910 | REG_WR(bp, shmem + validity_offset, 0); | |
8911 | } | |
8912 | ||
8913 | #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ | |
8914 | #define MCP_ONE_TIMEOUT 100 /* 100 ms */ | |
8915 | ||
e8920674 DK |
8916 | /** |
8917 | * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT | |
72fd0718 | 8918 | * |
e8920674 | 8919 | * @bp: driver handle |
72fd0718 | 8920 | */ |
1191cb83 | 8921 | static void bnx2x_mcp_wait_one(struct bnx2x *bp) |
72fd0718 VZ |
8922 | { |
8923 | /* special handling for emulation and FPGA, | |
8924 | wait 10 times longer */ | |
8925 | if (CHIP_REV_IS_SLOW(bp)) | |
8926 | msleep(MCP_ONE_TIMEOUT*10); | |
8927 | else | |
8928 | msleep(MCP_ONE_TIMEOUT); | |
8929 | } | |
8930 | ||
1b6e2ceb DK |
8931 | /* |
8932 | * initializes bp->common.shmem_base and waits for validity signature to appear | |
8933 | */ | |
8934 | static int bnx2x_init_shmem(struct bnx2x *bp) | |
72fd0718 | 8935 | { |
1b6e2ceb DK |
8936 | int cnt = 0; |
8937 | u32 val = 0; | |
72fd0718 | 8938 | |
1b6e2ceb DK |
8939 | do { |
8940 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
8941 | if (bp->common.shmem_base) { | |
8942 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); | |
8943 | if (val & SHR_MEM_VALIDITY_MB) | |
8944 | return 0; | |
8945 | } | |
72fd0718 | 8946 | |
1b6e2ceb | 8947 | bnx2x_mcp_wait_one(bp); |
72fd0718 | 8948 | |
1b6e2ceb | 8949 | } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); |
72fd0718 | 8950 | |
1b6e2ceb | 8951 | BNX2X_ERR("BAD MCP validity signature\n"); |
72fd0718 | 8952 | |
1b6e2ceb DK |
8953 | return -ENODEV; |
8954 | } | |
72fd0718 | 8955 | |
1b6e2ceb DK |
8956 | static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val) |
8957 | { | |
8958 | int rc = bnx2x_init_shmem(bp); | |
72fd0718 | 8959 | |
72fd0718 VZ |
8960 | /* Restore the `magic' bit value */ |
8961 | if (!CHIP_IS_E1(bp)) | |
8962 | bnx2x_clp_reset_done(bp, magic_val); | |
8963 | ||
8964 | return rc; | |
8965 | } | |
8966 | ||
8967 | static void bnx2x_pxp_prep(struct bnx2x *bp) | |
8968 | { | |
8969 | if (!CHIP_IS_E1(bp)) { | |
8970 | REG_WR(bp, PXP2_REG_RD_START_INIT, 0); | |
8971 | REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0); | |
72fd0718 VZ |
8972 | mmiowb(); |
8973 | } | |
8974 | } | |
8975 | ||
8976 | /* | |
8977 | * Reset the whole chip except for: | |
8978 | * - PCIE core | |
8979 | * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by | |
8980 | * one reset bit) | |
8981 | * - IGU | |
8982 | * - MISC (including AEU) | |
8983 | * - GRC | |
8984 | * - RBCN, RBCP | |
8985 | */ | |
c9ee9206 | 8986 | static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global) |
72fd0718 VZ |
8987 | { |
8988 | u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; | |
8736c826 | 8989 | u32 global_bits2, stay_reset2; |
c9ee9206 VZ |
8990 | |
8991 | /* | |
8992 | * Bits that have to be set in reset_mask2 if we want to reset 'global' | |
8993 | * (per chip) blocks. | |
8994 | */ | |
8995 | global_bits2 = | |
8996 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | | |
8997 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; | |
72fd0718 | 8998 | |
c55e771b BW |
8999 | /* Don't reset the following blocks. |
9000 | * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be | |
9001 | * reset, as in 4 port device they might still be owned | |
9002 | * by the MCP (there is only one leader per path). | |
9003 | */ | |
72fd0718 VZ |
9004 | not_reset_mask1 = |
9005 | MISC_REGISTERS_RESET_REG_1_RST_HC | | |
9006 | MISC_REGISTERS_RESET_REG_1_RST_PXPV | | |
9007 | MISC_REGISTERS_RESET_REG_1_RST_PXP; | |
9008 | ||
9009 | not_reset_mask2 = | |
c9ee9206 | 9010 | MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | |
72fd0718 VZ |
9011 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | |
9012 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | | |
9013 | MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | | |
9014 | MISC_REGISTERS_RESET_REG_2_RST_RBCN | | |
9015 | MISC_REGISTERS_RESET_REG_2_RST_GRC | | |
9016 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | | |
8736c826 VZ |
9017 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B | |
9018 | MISC_REGISTERS_RESET_REG_2_RST_ATC | | |
c55e771b BW |
9019 | MISC_REGISTERS_RESET_REG_2_PGLC | |
9020 | MISC_REGISTERS_RESET_REG_2_RST_BMAC0 | | |
9021 | MISC_REGISTERS_RESET_REG_2_RST_BMAC1 | | |
9022 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0 | | |
9023 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1 | | |
9024 | MISC_REGISTERS_RESET_REG_2_UMAC0 | | |
9025 | MISC_REGISTERS_RESET_REG_2_UMAC1; | |
72fd0718 | 9026 | |
8736c826 VZ |
9027 | /* |
9028 | * Keep the following blocks in reset: | |
9029 | * - all xxMACs are handled by the bnx2x_link code. | |
9030 | */ | |
9031 | stay_reset2 = | |
8736c826 VZ |
9032 | MISC_REGISTERS_RESET_REG_2_XMAC | |
9033 | MISC_REGISTERS_RESET_REG_2_XMAC_SOFT; | |
9034 | ||
9035 | /* Full reset masks according to the chip */ | |
72fd0718 VZ |
9036 | reset_mask1 = 0xffffffff; |
9037 | ||
9038 | if (CHIP_IS_E1(bp)) | |
9039 | reset_mask2 = 0xffff; | |
8736c826 | 9040 | else if (CHIP_IS_E1H(bp)) |
72fd0718 | 9041 | reset_mask2 = 0x1ffff; |
8736c826 VZ |
9042 | else if (CHIP_IS_E2(bp)) |
9043 | reset_mask2 = 0xfffff; | |
9044 | else /* CHIP_IS_E3 */ | |
9045 | reset_mask2 = 0x3ffffff; | |
c9ee9206 VZ |
9046 | |
9047 | /* Don't reset global blocks unless we need to */ | |
9048 | if (!global) | |
9049 | reset_mask2 &= ~global_bits2; | |
9050 | ||
9051 | /* | |
9052 | * In case of attention in the QM, we need to reset PXP | |
9053 | * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM | |
9054 | * because otherwise QM reset would release 'close the gates' shortly | |
9055 | * before resetting the PXP, then the PSWRQ would send a write | |
9056 | * request to PGLUE. Then when PXP is reset, PGLUE would try to | |
9057 | * read the payload data from PSWWR, but PSWWR would not | |
9058 | * respond. The write queue in PGLUE would stuck, dmae commands | |
9059 | * would not return. Therefore it's important to reset the second | |
9060 | * reset register (containing the | |
9061 | * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the | |
9062 | * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM | |
9063 | * bit). | |
9064 | */ | |
72fd0718 VZ |
9065 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
9066 | reset_mask2 & (~not_reset_mask2)); | |
9067 | ||
c9ee9206 VZ |
9068 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
9069 | reset_mask1 & (~not_reset_mask1)); | |
9070 | ||
72fd0718 VZ |
9071 | barrier(); |
9072 | mmiowb(); | |
9073 | ||
8736c826 VZ |
9074 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, |
9075 | reset_mask2 & (~stay_reset2)); | |
9076 | ||
9077 | barrier(); | |
9078 | mmiowb(); | |
9079 | ||
c9ee9206 | 9080 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1); |
72fd0718 VZ |
9081 | mmiowb(); |
9082 | } | |
9083 | ||
c9ee9206 VZ |
9084 | /** |
9085 | * bnx2x_er_poll_igu_vq - poll for pending writes bit. | |
9086 | * It should get cleared in no more than 1s. | |
9087 | * | |
9088 | * @bp: driver handle | |
9089 | * | |
9090 | * It should get cleared in no more than 1s. Returns 0 if | |
9091 | * pending writes bit gets cleared. | |
9092 | */ | |
9093 | static int bnx2x_er_poll_igu_vq(struct bnx2x *bp) | |
9094 | { | |
9095 | u32 cnt = 1000; | |
9096 | u32 pend_bits = 0; | |
9097 | ||
9098 | do { | |
9099 | pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS); | |
9100 | ||
9101 | if (pend_bits == 0) | |
9102 | break; | |
9103 | ||
0926d499 | 9104 | usleep_range(1000, 2000); |
c9ee9206 VZ |
9105 | } while (cnt-- > 0); |
9106 | ||
9107 | if (cnt <= 0) { | |
9108 | BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n", | |
9109 | pend_bits); | |
9110 | return -EBUSY; | |
9111 | } | |
9112 | ||
9113 | return 0; | |
9114 | } | |
9115 | ||
9116 | static int bnx2x_process_kill(struct bnx2x *bp, bool global) | |
72fd0718 VZ |
9117 | { |
9118 | int cnt = 1000; | |
9119 | u32 val = 0; | |
9120 | u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; | |
2de67439 | 9121 | u32 tags_63_32 = 0; |
72fd0718 VZ |
9122 | |
9123 | /* Empty the Tetris buffer, wait for 1s */ | |
9124 | do { | |
9125 | sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT); | |
9126 | blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT); | |
9127 | port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0); | |
9128 | port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1); | |
9129 | pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2); | |
c55e771b BW |
9130 | if (CHIP_IS_E3(bp)) |
9131 | tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32); | |
9132 | ||
72fd0718 VZ |
9133 | if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && |
9134 | ((port_is_idle_0 & 0x1) == 0x1) && | |
9135 | ((port_is_idle_1 & 0x1) == 0x1) && | |
c55e771b BW |
9136 | (pgl_exp_rom2 == 0xffffffff) && |
9137 | (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff))) | |
72fd0718 | 9138 | break; |
0926d499 | 9139 | usleep_range(1000, 2000); |
72fd0718 VZ |
9140 | } while (cnt-- > 0); |
9141 | ||
9142 | if (cnt <= 0) { | |
51c1a580 MS |
9143 | BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n"); |
9144 | BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n", | |
72fd0718 VZ |
9145 | sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, |
9146 | pgl_exp_rom2); | |
9147 | return -EAGAIN; | |
9148 | } | |
9149 | ||
9150 | barrier(); | |
9151 | ||
9152 | /* Close gates #2, #3 and #4 */ | |
9153 | bnx2x_set_234_gates(bp, true); | |
9154 | ||
c9ee9206 VZ |
9155 | /* Poll for IGU VQs for 57712 and newer chips */ |
9156 | if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp)) | |
9157 | return -EAGAIN; | |
9158 | ||
9159 | ||
72fd0718 VZ |
9160 | /* TBD: Indicate that "process kill" is in progress to MCP */ |
9161 | ||
9162 | /* Clear "unprepared" bit */ | |
9163 | REG_WR(bp, MISC_REG_UNPREPARED, 0); | |
9164 | barrier(); | |
9165 | ||
9166 | /* Make sure all is written to the chip before the reset */ | |
9167 | mmiowb(); | |
9168 | ||
9169 | /* Wait for 1ms to empty GLUE and PCI-E core queues, | |
9170 | * PSWHST, GRC and PSWRD Tetris buffer. | |
9171 | */ | |
0926d499 | 9172 | usleep_range(1000, 2000); |
72fd0718 VZ |
9173 | |
9174 | /* Prepare to chip reset: */ | |
9175 | /* MCP */ | |
c9ee9206 VZ |
9176 | if (global) |
9177 | bnx2x_reset_mcp_prep(bp, &val); | |
72fd0718 VZ |
9178 | |
9179 | /* PXP */ | |
9180 | bnx2x_pxp_prep(bp); | |
9181 | barrier(); | |
9182 | ||
9183 | /* reset the chip */ | |
c9ee9206 | 9184 | bnx2x_process_kill_chip_reset(bp, global); |
72fd0718 VZ |
9185 | barrier(); |
9186 | ||
9187 | /* Recover after reset: */ | |
9188 | /* MCP */ | |
c9ee9206 | 9189 | if (global && bnx2x_reset_mcp_comp(bp, val)) |
72fd0718 VZ |
9190 | return -EAGAIN; |
9191 | ||
c9ee9206 VZ |
9192 | /* TBD: Add resetting the NO_MCP mode DB here */ |
9193 | ||
72fd0718 VZ |
9194 | /* Open the gates #2, #3 and #4 */ |
9195 | bnx2x_set_234_gates(bp, false); | |
9196 | ||
9197 | /* TBD: IGU/AEU preparation bring back the AEU/IGU to a | |
9198 | * reset state, re-enable attentions. */ | |
9199 | ||
a2fbb9ea ET |
9200 | return 0; |
9201 | } | |
9202 | ||
910cc727 | 9203 | static int bnx2x_leader_reset(struct bnx2x *bp) |
72fd0718 VZ |
9204 | { |
9205 | int rc = 0; | |
c9ee9206 | 9206 | bool global = bnx2x_reset_is_global(bp); |
95c6c616 AE |
9207 | u32 load_code; |
9208 | ||
9209 | /* if not going to reset MCP - load "fake" driver to reset HW while | |
9210 | * driver is owner of the HW | |
9211 | */ | |
9212 | if (!global && !BP_NOMCP(bp)) { | |
5d07d868 YM |
9213 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, |
9214 | DRV_MSG_CODE_LOAD_REQ_WITH_LFA); | |
95c6c616 AE |
9215 | if (!load_code) { |
9216 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9217 | rc = -EAGAIN; | |
9218 | goto exit_leader_reset; | |
9219 | } | |
9220 | if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) && | |
9221 | (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) { | |
9222 | BNX2X_ERR("MCP unexpected resp, aborting\n"); | |
9223 | rc = -EAGAIN; | |
9224 | goto exit_leader_reset2; | |
9225 | } | |
9226 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0); | |
9227 | if (!load_code) { | |
9228 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9229 | rc = -EAGAIN; | |
9230 | goto exit_leader_reset2; | |
9231 | } | |
9232 | } | |
c9ee9206 | 9233 | |
72fd0718 | 9234 | /* Try to recover after the failure */ |
c9ee9206 | 9235 | if (bnx2x_process_kill(bp, global)) { |
51c1a580 MS |
9236 | BNX2X_ERR("Something bad had happen on engine %d! Aii!\n", |
9237 | BP_PATH(bp)); | |
72fd0718 | 9238 | rc = -EAGAIN; |
95c6c616 | 9239 | goto exit_leader_reset2; |
72fd0718 VZ |
9240 | } |
9241 | ||
c9ee9206 VZ |
9242 | /* |
9243 | * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver | |
9244 | * state. | |
9245 | */ | |
72fd0718 | 9246 | bnx2x_set_reset_done(bp); |
c9ee9206 VZ |
9247 | if (global) |
9248 | bnx2x_clear_reset_global(bp); | |
72fd0718 | 9249 | |
95c6c616 AE |
9250 | exit_leader_reset2: |
9251 | /* unload "fake driver" if it was loaded */ | |
9252 | if (!global && !BP_NOMCP(bp)) { | |
9253 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0); | |
9254 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); | |
9255 | } | |
72fd0718 VZ |
9256 | exit_leader_reset: |
9257 | bp->is_leader = 0; | |
c9ee9206 VZ |
9258 | bnx2x_release_leader_lock(bp); |
9259 | smp_mb(); | |
72fd0718 VZ |
9260 | return rc; |
9261 | } | |
9262 | ||
1191cb83 | 9263 | static void bnx2x_recovery_failed(struct bnx2x *bp) |
c9ee9206 VZ |
9264 | { |
9265 | netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n"); | |
9266 | ||
9267 | /* Disconnect this device */ | |
9268 | netif_device_detach(bp->dev); | |
9269 | ||
9270 | /* | |
9271 | * Block ifup for all function on this engine until "process kill" | |
9272 | * or power cycle. | |
9273 | */ | |
9274 | bnx2x_set_reset_in_progress(bp); | |
9275 | ||
9276 | /* Shut down the power */ | |
9277 | bnx2x_set_power_state(bp, PCI_D3hot); | |
9278 | ||
9279 | bp->recovery_state = BNX2X_RECOVERY_FAILED; | |
9280 | ||
9281 | smp_mb(); | |
9282 | } | |
9283 | ||
9284 | /* | |
9285 | * Assumption: runs under rtnl lock. This together with the fact | |
6383c0b3 | 9286 | * that it's called only from bnx2x_sp_rtnl() ensure that it |
72fd0718 VZ |
9287 | * will never be called when netif_running(bp->dev) is false. |
9288 | */ | |
9289 | static void bnx2x_parity_recover(struct bnx2x *bp) | |
9290 | { | |
c9ee9206 | 9291 | bool global = false; |
7a752993 | 9292 | u32 error_recovered, error_unrecovered; |
95c6c616 | 9293 | bool is_parity; |
c9ee9206 | 9294 | |
72fd0718 VZ |
9295 | DP(NETIF_MSG_HW, "Handling parity\n"); |
9296 | while (1) { | |
9297 | switch (bp->recovery_state) { | |
9298 | case BNX2X_RECOVERY_INIT: | |
9299 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n"); | |
95c6c616 AE |
9300 | is_parity = bnx2x_chk_parity_attn(bp, &global, false); |
9301 | WARN_ON(!is_parity); | |
c9ee9206 | 9302 | |
72fd0718 | 9303 | /* Try to get a LEADER_LOCK HW lock */ |
c9ee9206 VZ |
9304 | if (bnx2x_trylock_leader_lock(bp)) { |
9305 | bnx2x_set_reset_in_progress(bp); | |
9306 | /* | |
9307 | * Check if there is a global attention and if | |
9308 | * there was a global attention, set the global | |
9309 | * reset bit. | |
9310 | */ | |
9311 | ||
9312 | if (global) | |
9313 | bnx2x_set_reset_global(bp); | |
9314 | ||
72fd0718 | 9315 | bp->is_leader = 1; |
c9ee9206 | 9316 | } |
72fd0718 VZ |
9317 | |
9318 | /* Stop the driver */ | |
9319 | /* If interface has been removed - break */ | |
5d07d868 | 9320 | if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false)) |
72fd0718 VZ |
9321 | return; |
9322 | ||
9323 | bp->recovery_state = BNX2X_RECOVERY_WAIT; | |
c9ee9206 | 9324 | |
c9ee9206 VZ |
9325 | /* Ensure "is_leader", MCP command sequence and |
9326 | * "recovery_state" update values are seen on other | |
9327 | * CPUs. | |
72fd0718 | 9328 | */ |
c9ee9206 | 9329 | smp_mb(); |
72fd0718 VZ |
9330 | break; |
9331 | ||
9332 | case BNX2X_RECOVERY_WAIT: | |
9333 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n"); | |
9334 | if (bp->is_leader) { | |
c9ee9206 | 9335 | int other_engine = BP_PATH(bp) ? 0 : 1; |
889b9af3 AE |
9336 | bool other_load_status = |
9337 | bnx2x_get_load_status(bp, other_engine); | |
9338 | bool load_status = | |
9339 | bnx2x_get_load_status(bp, BP_PATH(bp)); | |
c9ee9206 VZ |
9340 | global = bnx2x_reset_is_global(bp); |
9341 | ||
9342 | /* | |
9343 | * In case of a parity in a global block, let | |
9344 | * the first leader that performs a | |
9345 | * leader_reset() reset the global blocks in | |
9346 | * order to clear global attentions. Otherwise | |
9347 | * the the gates will remain closed for that | |
9348 | * engine. | |
9349 | */ | |
889b9af3 AE |
9350 | if (load_status || |
9351 | (global && other_load_status)) { | |
72fd0718 VZ |
9352 | /* Wait until all other functions get |
9353 | * down. | |
9354 | */ | |
7be08a72 | 9355 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
9356 | HZ/10); |
9357 | return; | |
9358 | } else { | |
9359 | /* If all other functions got down - | |
9360 | * try to bring the chip back to | |
9361 | * normal. In any case it's an exit | |
9362 | * point for a leader. | |
9363 | */ | |
c9ee9206 VZ |
9364 | if (bnx2x_leader_reset(bp)) { |
9365 | bnx2x_recovery_failed(bp); | |
72fd0718 VZ |
9366 | return; |
9367 | } | |
9368 | ||
c9ee9206 VZ |
9369 | /* If we are here, means that the |
9370 | * leader has succeeded and doesn't | |
9371 | * want to be a leader any more. Try | |
9372 | * to continue as a none-leader. | |
9373 | */ | |
9374 | break; | |
72fd0718 VZ |
9375 | } |
9376 | } else { /* non-leader */ | |
c9ee9206 | 9377 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) { |
72fd0718 VZ |
9378 | /* Try to get a LEADER_LOCK HW lock as |
9379 | * long as a former leader may have | |
9380 | * been unloaded by the user or | |
9381 | * released a leadership by another | |
9382 | * reason. | |
9383 | */ | |
c9ee9206 | 9384 | if (bnx2x_trylock_leader_lock(bp)) { |
72fd0718 VZ |
9385 | /* I'm a leader now! Restart a |
9386 | * switch case. | |
9387 | */ | |
9388 | bp->is_leader = 1; | |
9389 | break; | |
9390 | } | |
9391 | ||
7be08a72 | 9392 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
9393 | HZ/10); |
9394 | return; | |
9395 | ||
c9ee9206 VZ |
9396 | } else { |
9397 | /* | |
9398 | * If there was a global attention, wait | |
9399 | * for it to be cleared. | |
9400 | */ | |
9401 | if (bnx2x_reset_is_global(bp)) { | |
9402 | schedule_delayed_work( | |
7be08a72 AE |
9403 | &bp->sp_rtnl_task, |
9404 | HZ/10); | |
c9ee9206 VZ |
9405 | return; |
9406 | } | |
9407 | ||
7a752993 AE |
9408 | error_recovered = |
9409 | bp->eth_stats.recoverable_error; | |
9410 | error_unrecovered = | |
9411 | bp->eth_stats.unrecoverable_error; | |
95c6c616 AE |
9412 | bp->recovery_state = |
9413 | BNX2X_RECOVERY_NIC_LOADING; | |
9414 | if (bnx2x_nic_load(bp, LOAD_NORMAL)) { | |
7a752993 | 9415 | error_unrecovered++; |
95c6c616 | 9416 | netdev_err(bp->dev, |
51c1a580 | 9417 | "Recovery failed. Power cycle needed\n"); |
95c6c616 AE |
9418 | /* Disconnect this device */ |
9419 | netif_device_detach(bp->dev); | |
9420 | /* Shut down the power */ | |
9421 | bnx2x_set_power_state( | |
9422 | bp, PCI_D3hot); | |
9423 | smp_mb(); | |
9424 | } else { | |
c9ee9206 VZ |
9425 | bp->recovery_state = |
9426 | BNX2X_RECOVERY_DONE; | |
7a752993 | 9427 | error_recovered++; |
c9ee9206 VZ |
9428 | smp_mb(); |
9429 | } | |
7a752993 AE |
9430 | bp->eth_stats.recoverable_error = |
9431 | error_recovered; | |
9432 | bp->eth_stats.unrecoverable_error = | |
9433 | error_unrecovered; | |
c9ee9206 | 9434 | |
72fd0718 VZ |
9435 | return; |
9436 | } | |
9437 | } | |
9438 | default: | |
9439 | return; | |
9440 | } | |
9441 | } | |
9442 | } | |
9443 | ||
56ad3152 MS |
9444 | static int bnx2x_close(struct net_device *dev); |
9445 | ||
72fd0718 VZ |
9446 | /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is |
9447 | * scheduled on a general queue in order to prevent a dead lock. | |
9448 | */ | |
7be08a72 | 9449 | static void bnx2x_sp_rtnl_task(struct work_struct *work) |
34f80b04 | 9450 | { |
7be08a72 | 9451 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work); |
34f80b04 EG |
9452 | |
9453 | rtnl_lock(); | |
9454 | ||
8395be5e AE |
9455 | if (!netif_running(bp->dev)) { |
9456 | rtnl_unlock(); | |
9457 | return; | |
9458 | } | |
7be08a72 AE |
9459 | |
9460 | /* if stop on error is defined no recovery flows should be executed */ | |
9461 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 | 9462 | BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n" |
7be08a72 | 9463 | "you will need to reboot when done\n"); |
b1fb8740 | 9464 | goto sp_rtnl_not_reset; |
7be08a72 | 9465 | #endif |
34f80b04 | 9466 | |
7be08a72 AE |
9467 | if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) { |
9468 | /* | |
b1fb8740 VZ |
9469 | * Clear all pending SP commands as we are going to reset the |
9470 | * function anyway. | |
7be08a72 | 9471 | */ |
b1fb8740 VZ |
9472 | bp->sp_rtnl_state = 0; |
9473 | smp_mb(); | |
9474 | ||
72fd0718 | 9475 | bnx2x_parity_recover(bp); |
b1fb8740 | 9476 | |
8395be5e AE |
9477 | rtnl_unlock(); |
9478 | return; | |
b1fb8740 VZ |
9479 | } |
9480 | ||
9481 | if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) { | |
9482 | /* | |
9483 | * Clear all pending SP commands as we are going to reset the | |
9484 | * function anyway. | |
9485 | */ | |
9486 | bp->sp_rtnl_state = 0; | |
9487 | smp_mb(); | |
9488 | ||
5d07d868 | 9489 | bnx2x_nic_unload(bp, UNLOAD_NORMAL, true); |
72fd0718 | 9490 | bnx2x_nic_load(bp, LOAD_NORMAL); |
b1fb8740 | 9491 | |
8395be5e AE |
9492 | rtnl_unlock(); |
9493 | return; | |
72fd0718 | 9494 | } |
b1fb8740 VZ |
9495 | #ifdef BNX2X_STOP_ON_ERROR |
9496 | sp_rtnl_not_reset: | |
9497 | #endif | |
9498 | if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state)) | |
9499 | bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos); | |
a3348722 BW |
9500 | if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state)) |
9501 | bnx2x_after_function_update(bp); | |
8304859a AE |
9502 | /* |
9503 | * in case of fan failure we need to reset id if the "stop on error" | |
9504 | * debug flag is set, since we trying to prevent permanent overheating | |
9505 | * damage | |
9506 | */ | |
9507 | if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) { | |
51c1a580 | 9508 | DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n"); |
8304859a AE |
9509 | netif_device_detach(bp->dev); |
9510 | bnx2x_close(bp->dev); | |
8395be5e AE |
9511 | rtnl_unlock(); |
9512 | return; | |
8304859a AE |
9513 | } |
9514 | ||
381ac16b AE |
9515 | if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) { |
9516 | DP(BNX2X_MSG_SP, | |
9517 | "sending set mcast vf pf channel message from rtnl sp-task\n"); | |
9518 | bnx2x_vfpf_set_mcast(bp->dev); | |
9519 | } | |
9520 | ||
9521 | if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE, | |
9522 | &bp->sp_rtnl_state)) { | |
9523 | DP(BNX2X_MSG_SP, | |
9524 | "sending set storm rx mode vf pf channel message from rtnl sp-task\n"); | |
9525 | bnx2x_vfpf_storm_rx_mode(bp); | |
9526 | } | |
9527 | ||
8395be5e AE |
9528 | /* work which needs rtnl lock not-taken (as it takes the lock itself and |
9529 | * can be called from other contexts as well) | |
9530 | */ | |
34f80b04 | 9531 | rtnl_unlock(); |
8395be5e | 9532 | |
6411280a | 9533 | /* enable SR-IOV if applicable */ |
8395be5e | 9534 | if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, |
6411280a AE |
9535 | &bp->sp_rtnl_state)) |
9536 | bnx2x_enable_sriov(bp); | |
34f80b04 EG |
9537 | } |
9538 | ||
3deb8167 YR |
9539 | static void bnx2x_period_task(struct work_struct *work) |
9540 | { | |
9541 | struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work); | |
9542 | ||
9543 | if (!netif_running(bp->dev)) | |
9544 | goto period_task_exit; | |
9545 | ||
9546 | if (CHIP_REV_IS_SLOW(bp)) { | |
9547 | BNX2X_ERR("period task called on emulation, ignoring\n"); | |
9548 | goto period_task_exit; | |
9549 | } | |
9550 | ||
9551 | bnx2x_acquire_phy_lock(bp); | |
9552 | /* | |
9553 | * The barrier is needed to ensure the ordering between the writing to | |
9554 | * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and | |
9555 | * the reading here. | |
9556 | */ | |
9557 | smp_mb(); | |
9558 | if (bp->port.pmf) { | |
9559 | bnx2x_period_func(&bp->link_params, &bp->link_vars); | |
9560 | ||
9561 | /* Re-queue task in 1 sec */ | |
9562 | queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ); | |
9563 | } | |
9564 | ||
9565 | bnx2x_release_phy_lock(bp); | |
9566 | period_task_exit: | |
9567 | return; | |
9568 | } | |
9569 | ||
a2fbb9ea ET |
9570 | /* |
9571 | * Init service functions | |
9572 | */ | |
9573 | ||
b56e9670 | 9574 | u32 bnx2x_get_pretend_reg(struct bnx2x *bp) |
f2e0899f DK |
9575 | { |
9576 | u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; | |
9577 | u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; | |
9578 | return base + (BP_ABS_FUNC(bp)) * stride; | |
f1ef27ef EG |
9579 | } |
9580 | ||
1ef1d45a BW |
9581 | static void bnx2x_prev_unload_close_mac(struct bnx2x *bp, |
9582 | struct bnx2x_mac_vals *vals) | |
34f80b04 | 9583 | { |
452427b0 YM |
9584 | u32 val, base_addr, offset, mask, reset_reg; |
9585 | bool mac_stopped = false; | |
9586 | u8 port = BP_PORT(bp); | |
34f80b04 | 9587 | |
1ef1d45a BW |
9588 | /* reset addresses as they also mark which values were changed */ |
9589 | vals->bmac_addr = 0; | |
9590 | vals->umac_addr = 0; | |
9591 | vals->xmac_addr = 0; | |
9592 | vals->emac_addr = 0; | |
9593 | ||
452427b0 | 9594 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2); |
f16da43b | 9595 | |
452427b0 YM |
9596 | if (!CHIP_IS_E3(bp)) { |
9597 | val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4); | |
9598 | mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port; | |
9599 | if ((mask & reset_reg) && val) { | |
9600 | u32 wb_data[2]; | |
9601 | BNX2X_DEV_INFO("Disable bmac Rx\n"); | |
9602 | base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM | |
9603 | : NIG_REG_INGRESS_BMAC0_MEM; | |
9604 | offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL | |
9605 | : BIGMAC_REGISTER_BMAC_CONTROL; | |
7a06a122 | 9606 | |
452427b0 YM |
9607 | /* |
9608 | * use rd/wr since we cannot use dmae. This is safe | |
9609 | * since MCP won't access the bus due to the request | |
9610 | * to unload, and no function on the path can be | |
9611 | * loaded at this time. | |
9612 | */ | |
9613 | wb_data[0] = REG_RD(bp, base_addr + offset); | |
9614 | wb_data[1] = REG_RD(bp, base_addr + offset + 0x4); | |
1ef1d45a BW |
9615 | vals->bmac_addr = base_addr + offset; |
9616 | vals->bmac_val[0] = wb_data[0]; | |
9617 | vals->bmac_val[1] = wb_data[1]; | |
452427b0 | 9618 | wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE; |
1ef1d45a BW |
9619 | REG_WR(bp, vals->bmac_addr, wb_data[0]); |
9620 | REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]); | |
452427b0 YM |
9621 | |
9622 | } | |
9623 | BNX2X_DEV_INFO("Disable emac Rx\n"); | |
1ef1d45a BW |
9624 | vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4; |
9625 | vals->emac_val = REG_RD(bp, vals->emac_addr); | |
9626 | REG_WR(bp, vals->emac_addr, 0); | |
452427b0 YM |
9627 | mac_stopped = true; |
9628 | } else { | |
9629 | if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) { | |
9630 | BNX2X_DEV_INFO("Disable xmac Rx\n"); | |
9631 | base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0; | |
9632 | val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI); | |
9633 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
9634 | val & ~(1 << 1)); | |
9635 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
9636 | val | (1 << 1)); | |
1ef1d45a BW |
9637 | vals->xmac_addr = base_addr + XMAC_REG_CTRL; |
9638 | vals->xmac_val = REG_RD(bp, vals->xmac_addr); | |
9639 | REG_WR(bp, vals->xmac_addr, 0); | |
452427b0 YM |
9640 | mac_stopped = true; |
9641 | } | |
9642 | mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port; | |
9643 | if (mask & reset_reg) { | |
9644 | BNX2X_DEV_INFO("Disable umac Rx\n"); | |
9645 | base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0; | |
1ef1d45a BW |
9646 | vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG; |
9647 | vals->umac_val = REG_RD(bp, vals->umac_addr); | |
9648 | REG_WR(bp, vals->umac_addr, 0); | |
452427b0 YM |
9649 | mac_stopped = true; |
9650 | } | |
9651 | } | |
9652 | ||
9653 | if (mac_stopped) | |
9654 | msleep(20); | |
9655 | ||
9656 | } | |
9657 | ||
9658 | #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4)) | |
9659 | #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff) | |
9660 | #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff) | |
9661 | #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq)) | |
9662 | ||
1dd06ae8 | 9663 | static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc) |
452427b0 YM |
9664 | { |
9665 | u16 rcq, bd; | |
9666 | u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port)); | |
9667 | ||
9668 | rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc; | |
9669 | bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc; | |
9670 | ||
9671 | tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd); | |
9672 | REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg); | |
9673 | ||
9674 | BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n", | |
9675 | port, bd, rcq); | |
9676 | } | |
9677 | ||
0329aba1 | 9678 | static int bnx2x_prev_mcp_done(struct bnx2x *bp) |
452427b0 | 9679 | { |
5d07d868 YM |
9680 | u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, |
9681 | DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET); | |
452427b0 YM |
9682 | if (!rc) { |
9683 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9684 | return -EBUSY; | |
9685 | } | |
9686 | ||
9687 | return 0; | |
9688 | } | |
9689 | ||
c63da990 BW |
9690 | static struct bnx2x_prev_path_list * |
9691 | bnx2x_prev_path_get_entry(struct bnx2x *bp) | |
9692 | { | |
9693 | struct bnx2x_prev_path_list *tmp_list; | |
9694 | ||
9695 | list_for_each_entry(tmp_list, &bnx2x_prev_list, list) | |
9696 | if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot && | |
9697 | bp->pdev->bus->number == tmp_list->bus && | |
9698 | BP_PATH(bp) == tmp_list->path) | |
9699 | return tmp_list; | |
9700 | ||
9701 | return NULL; | |
9702 | } | |
9703 | ||
0329aba1 | 9704 | static bool bnx2x_prev_is_path_marked(struct bnx2x *bp) |
452427b0 YM |
9705 | { |
9706 | struct bnx2x_prev_path_list *tmp_list; | |
9707 | int rc = false; | |
9708 | ||
9709 | if (down_trylock(&bnx2x_prev_sem)) | |
9710 | return false; | |
9711 | ||
9712 | list_for_each_entry(tmp_list, &bnx2x_prev_list, list) { | |
9713 | if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot && | |
9714 | bp->pdev->bus->number == tmp_list->bus && | |
9715 | BP_PATH(bp) == tmp_list->path) { | |
9716 | rc = true; | |
9717 | BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n", | |
9718 | BP_PATH(bp)); | |
9719 | break; | |
9720 | } | |
9721 | } | |
9722 | ||
9723 | up(&bnx2x_prev_sem); | |
9724 | ||
9725 | return rc; | |
9726 | } | |
9727 | ||
c63da990 | 9728 | static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi) |
452427b0 YM |
9729 | { |
9730 | struct bnx2x_prev_path_list *tmp_list; | |
9731 | int rc; | |
9732 | ||
ea4b3857 | 9733 | tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL); |
452427b0 YM |
9734 | if (!tmp_list) { |
9735 | BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n"); | |
9736 | return -ENOMEM; | |
9737 | } | |
9738 | ||
9739 | tmp_list->bus = bp->pdev->bus->number; | |
9740 | tmp_list->slot = PCI_SLOT(bp->pdev->devfn); | |
9741 | tmp_list->path = BP_PATH(bp); | |
c63da990 | 9742 | tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0; |
452427b0 YM |
9743 | |
9744 | rc = down_interruptible(&bnx2x_prev_sem); | |
9745 | if (rc) { | |
9746 | BNX2X_ERR("Received %d when tried to take lock\n", rc); | |
9747 | kfree(tmp_list); | |
9748 | } else { | |
9749 | BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n", | |
9750 | BP_PATH(bp)); | |
9751 | list_add(&tmp_list->list, &bnx2x_prev_list); | |
9752 | up(&bnx2x_prev_sem); | |
9753 | } | |
9754 | ||
9755 | return rc; | |
9756 | } | |
9757 | ||
0329aba1 | 9758 | static int bnx2x_do_flr(struct bnx2x *bp) |
452427b0 | 9759 | { |
2a80eebc | 9760 | int i; |
452427b0 YM |
9761 | u16 status; |
9762 | struct pci_dev *dev = bp->pdev; | |
9763 | ||
8eee694c YM |
9764 | |
9765 | if (CHIP_IS_E1x(bp)) { | |
9766 | BNX2X_DEV_INFO("FLR not supported in E1/E1H\n"); | |
9767 | return -EINVAL; | |
9768 | } | |
9769 | ||
9770 | /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */ | |
9771 | if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) { | |
9772 | BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n", | |
9773 | bp->common.bc_ver); | |
9774 | return -EINVAL; | |
9775 | } | |
452427b0 | 9776 | |
452427b0 YM |
9777 | /* Wait for Transaction Pending bit clean */ |
9778 | for (i = 0; i < 4; i++) { | |
9779 | if (i) | |
9780 | msleep((1 << (i - 1)) * 100); | |
9781 | ||
2a80eebc | 9782 | pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status); |
452427b0 YM |
9783 | if (!(status & PCI_EXP_DEVSTA_TRPND)) |
9784 | goto clear; | |
9785 | } | |
9786 | ||
9787 | dev_err(&dev->dev, | |
9788 | "transaction is not cleared; proceeding with reset anyway\n"); | |
9789 | ||
9790 | clear: | |
452427b0 | 9791 | |
8eee694c | 9792 | BNX2X_DEV_INFO("Initiating FLR\n"); |
452427b0 YM |
9793 | bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0); |
9794 | ||
9795 | return 0; | |
9796 | } | |
9797 | ||
0329aba1 | 9798 | static int bnx2x_prev_unload_uncommon(struct bnx2x *bp) |
452427b0 YM |
9799 | { |
9800 | int rc; | |
9801 | ||
9802 | BNX2X_DEV_INFO("Uncommon unload Flow\n"); | |
9803 | ||
9804 | /* Test if previous unload process was already finished for this path */ | |
9805 | if (bnx2x_prev_is_path_marked(bp)) | |
9806 | return bnx2x_prev_mcp_done(bp); | |
9807 | ||
04c46736 YM |
9808 | BNX2X_DEV_INFO("Path is unmarked\n"); |
9809 | ||
452427b0 YM |
9810 | /* If function has FLR capabilities, and existing FW version matches |
9811 | * the one required, then FLR will be sufficient to clean any residue | |
9812 | * left by previous driver | |
9813 | */ | |
ad5afc89 | 9814 | rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION); |
8eee694c YM |
9815 | |
9816 | if (!rc) { | |
9817 | /* fw version is good */ | |
9818 | BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n"); | |
9819 | rc = bnx2x_do_flr(bp); | |
9820 | } | |
9821 | ||
9822 | if (!rc) { | |
9823 | /* FLR was performed */ | |
9824 | BNX2X_DEV_INFO("FLR successful\n"); | |
9825 | return 0; | |
9826 | } | |
9827 | ||
9828 | BNX2X_DEV_INFO("Could not FLR\n"); | |
452427b0 YM |
9829 | |
9830 | /* Close the MCP request, return failure*/ | |
9831 | rc = bnx2x_prev_mcp_done(bp); | |
9832 | if (!rc) | |
9833 | rc = BNX2X_PREV_WAIT_NEEDED; | |
9834 | ||
9835 | return rc; | |
9836 | } | |
9837 | ||
0329aba1 | 9838 | static int bnx2x_prev_unload_common(struct bnx2x *bp) |
452427b0 YM |
9839 | { |
9840 | u32 reset_reg, tmp_reg = 0, rc; | |
c63da990 | 9841 | bool prev_undi = false; |
1ef1d45a BW |
9842 | struct bnx2x_mac_vals mac_vals; |
9843 | ||
452427b0 YM |
9844 | /* It is possible a previous function received 'common' answer, |
9845 | * but hasn't loaded yet, therefore creating a scenario of | |
9846 | * multiple functions receiving 'common' on the same path. | |
9847 | */ | |
9848 | BNX2X_DEV_INFO("Common unload Flow\n"); | |
9849 | ||
1ef1d45a BW |
9850 | memset(&mac_vals, 0, sizeof(mac_vals)); |
9851 | ||
452427b0 YM |
9852 | if (bnx2x_prev_is_path_marked(bp)) |
9853 | return bnx2x_prev_mcp_done(bp); | |
9854 | ||
9855 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1); | |
9856 | ||
9857 | /* Reset should be performed after BRB is emptied */ | |
9858 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) { | |
9859 | u32 timer_count = 1000; | |
452427b0 YM |
9860 | |
9861 | /* Close the MAC Rx to prevent BRB from filling up */ | |
1ef1d45a BW |
9862 | bnx2x_prev_unload_close_mac(bp, &mac_vals); |
9863 | ||
9864 | /* close LLH filters towards the BRB */ | |
9865 | bnx2x_set_rx_filter(&bp->link_params, 0); | |
452427b0 YM |
9866 | |
9867 | /* Check if the UNDI driver was previously loaded | |
34f80b04 EG |
9868 | * UNDI driver initializes CID offset for normal bell to 0x7 |
9869 | */ | |
452427b0 YM |
9870 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) { |
9871 | tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST); | |
9872 | if (tmp_reg == 0x7) { | |
9873 | BNX2X_DEV_INFO("UNDI previously loaded\n"); | |
9874 | prev_undi = true; | |
9875 | /* clear the UNDI indication */ | |
9876 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); | |
a74801c5 YM |
9877 | /* clear possible idle check errors */ |
9878 | REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0); | |
34f80b04 | 9879 | } |
452427b0 YM |
9880 | } |
9881 | /* wait until BRB is empty */ | |
9882 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); | |
9883 | while (timer_count) { | |
9884 | u32 prev_brb = tmp_reg; | |
34f80b04 | 9885 | |
452427b0 YM |
9886 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); |
9887 | if (!tmp_reg) | |
9888 | break; | |
619c5cb6 | 9889 | |
452427b0 | 9890 | BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg); |
619c5cb6 | 9891 | |
452427b0 YM |
9892 | /* reset timer as long as BRB actually gets emptied */ |
9893 | if (prev_brb > tmp_reg) | |
9894 | timer_count = 1000; | |
9895 | else | |
9896 | timer_count--; | |
da5a662a | 9897 | |
452427b0 YM |
9898 | /* If UNDI resides in memory, manually increment it */ |
9899 | if (prev_undi) | |
9900 | bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1); | |
da5a662a | 9901 | |
452427b0 | 9902 | udelay(10); |
7a06a122 | 9903 | } |
452427b0 YM |
9904 | |
9905 | if (!timer_count) | |
9906 | BNX2X_ERR("Failed to empty BRB, hope for the best\n"); | |
9907 | ||
34f80b04 | 9908 | } |
f16da43b | 9909 | |
452427b0 YM |
9910 | /* No packets are in the pipeline, path is ready for reset */ |
9911 | bnx2x_reset_common(bp); | |
9912 | ||
1ef1d45a BW |
9913 | if (mac_vals.xmac_addr) |
9914 | REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val); | |
9915 | if (mac_vals.umac_addr) | |
9916 | REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val); | |
9917 | if (mac_vals.emac_addr) | |
9918 | REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val); | |
9919 | if (mac_vals.bmac_addr) { | |
9920 | REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]); | |
9921 | REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]); | |
9922 | } | |
9923 | ||
c63da990 | 9924 | rc = bnx2x_prev_mark_path(bp, prev_undi); |
452427b0 YM |
9925 | if (rc) { |
9926 | bnx2x_prev_mcp_done(bp); | |
9927 | return rc; | |
9928 | } | |
9929 | ||
9930 | return bnx2x_prev_mcp_done(bp); | |
9931 | } | |
9932 | ||
24f06716 AE |
9933 | /* previous driver DMAE transaction may have occurred when pre-boot stage ended |
9934 | * and boot began, or when kdump kernel was loaded. Either case would invalidate | |
9935 | * the addresses of the transaction, resulting in was-error bit set in the pci | |
9936 | * causing all hw-to-host pcie transactions to timeout. If this happened we want | |
9937 | * to clear the interrupt which detected this from the pglueb and the was done | |
9938 | * bit | |
9939 | */ | |
0329aba1 | 9940 | static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp) |
24f06716 | 9941 | { |
4a25417c AE |
9942 | if (!CHIP_IS_E1x(bp)) { |
9943 | u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS); | |
9944 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) { | |
04c46736 YM |
9945 | DP(BNX2X_MSG_SP, |
9946 | "'was error' bit was found to be set in pglueb upon startup. Clearing\n"); | |
4a25417c AE |
9947 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, |
9948 | 1 << BP_FUNC(bp)); | |
9949 | } | |
24f06716 AE |
9950 | } |
9951 | } | |
9952 | ||
0329aba1 | 9953 | static int bnx2x_prev_unload(struct bnx2x *bp) |
452427b0 YM |
9954 | { |
9955 | int time_counter = 10; | |
9956 | u32 rc, fw, hw_lock_reg, hw_lock_val; | |
c63da990 | 9957 | struct bnx2x_prev_path_list *prev_list; |
452427b0 YM |
9958 | BNX2X_DEV_INFO("Entering Previous Unload Flow\n"); |
9959 | ||
24f06716 AE |
9960 | /* clear hw from errors which may have resulted from an interrupted |
9961 | * dmae transaction. | |
9962 | */ | |
9963 | bnx2x_prev_interrupted_dmae(bp); | |
9964 | ||
9965 | /* Release previously held locks */ | |
452427b0 YM |
9966 | hw_lock_reg = (BP_FUNC(bp) <= 5) ? |
9967 | (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) : | |
9968 | (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8); | |
9969 | ||
9970 | hw_lock_val = (REG_RD(bp, hw_lock_reg)); | |
9971 | if (hw_lock_val) { | |
9972 | if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) { | |
9973 | BNX2X_DEV_INFO("Release Previously held NVRAM lock\n"); | |
9974 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, | |
9975 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp))); | |
9976 | } | |
9977 | ||
9978 | BNX2X_DEV_INFO("Release Previously held hw lock\n"); | |
9979 | REG_WR(bp, hw_lock_reg, 0xffffffff); | |
9980 | } else | |
9981 | BNX2X_DEV_INFO("No need to release hw/nvram locks\n"); | |
9982 | ||
9983 | if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) { | |
9984 | BNX2X_DEV_INFO("Release previously held alr\n"); | |
9985 | REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0); | |
9986 | } | |
9987 | ||
452427b0 YM |
9988 | do { |
9989 | /* Lock MCP using an unload request */ | |
9990 | fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0); | |
9991 | if (!fw) { | |
9992 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9993 | rc = -EBUSY; | |
9994 | break; | |
9995 | } | |
9996 | ||
9997 | if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) { | |
9998 | rc = bnx2x_prev_unload_common(bp); | |
9999 | break; | |
10000 | } | |
10001 | ||
10002 | /* non-common reply from MCP night require looping */ | |
10003 | rc = bnx2x_prev_unload_uncommon(bp); | |
10004 | if (rc != BNX2X_PREV_WAIT_NEEDED) | |
10005 | break; | |
10006 | ||
10007 | msleep(20); | |
10008 | } while (--time_counter); | |
10009 | ||
10010 | if (!time_counter || rc) { | |
10011 | BNX2X_ERR("Failed unloading previous driver, aborting\n"); | |
10012 | rc = -EBUSY; | |
10013 | } | |
10014 | ||
c63da990 BW |
10015 | /* Mark function if its port was used to boot from SAN */ |
10016 | prev_list = bnx2x_prev_path_get_entry(bp); | |
10017 | if (prev_list && (prev_list->undi & (1 << BP_PORT(bp)))) | |
10018 | bp->link_params.feature_config_flags |= | |
10019 | FEATURE_CONFIG_BOOT_FROM_SAN; | |
10020 | ||
452427b0 YM |
10021 | BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc); |
10022 | ||
10023 | return rc; | |
34f80b04 EG |
10024 | } |
10025 | ||
0329aba1 | 10026 | static void bnx2x_get_common_hwinfo(struct bnx2x *bp) |
34f80b04 | 10027 | { |
1d187b34 | 10028 | u32 val, val2, val3, val4, id, boot_mode; |
72ce58c3 | 10029 | u16 pmc; |
34f80b04 EG |
10030 | |
10031 | /* Get the chip revision id and number. */ | |
10032 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ | |
10033 | val = REG_RD(bp, MISC_REG_CHIP_NUM); | |
10034 | id = ((val & 0xffff) << 16); | |
10035 | val = REG_RD(bp, MISC_REG_CHIP_REV); | |
10036 | id |= ((val & 0xf) << 12); | |
10037 | val = REG_RD(bp, MISC_REG_CHIP_METAL); | |
10038 | id |= ((val & 0xff) << 4); | |
5a40e08e | 10039 | val = REG_RD(bp, MISC_REG_BOND_ID); |
34f80b04 EG |
10040 | id |= (val & 0xf); |
10041 | bp->common.chip_id = id; | |
523224a3 | 10042 | |
7e8e02df BW |
10043 | /* force 57811 according to MISC register */ |
10044 | if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) { | |
10045 | if (CHIP_IS_57810(bp)) | |
10046 | bp->common.chip_id = (CHIP_NUM_57811 << 16) | | |
10047 | (bp->common.chip_id & 0x0000FFFF); | |
10048 | else if (CHIP_IS_57810_MF(bp)) | |
10049 | bp->common.chip_id = (CHIP_NUM_57811_MF << 16) | | |
10050 | (bp->common.chip_id & 0x0000FFFF); | |
10051 | bp->common.chip_id |= 0x1; | |
10052 | } | |
10053 | ||
523224a3 DK |
10054 | /* Set doorbell size */ |
10055 | bp->db_size = (1 << BNX2X_DB_SHIFT); | |
10056 | ||
619c5cb6 | 10057 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
10058 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR); |
10059 | if ((val & 1) == 0) | |
10060 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN); | |
10061 | else | |
10062 | val = (val >> 1) & 1; | |
10063 | BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" : | |
10064 | "2_PORT_MODE"); | |
10065 | bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE : | |
10066 | CHIP_2_PORT_MODE; | |
10067 | ||
10068 | if (CHIP_MODE_IS_4_PORT(bp)) | |
10069 | bp->pfid = (bp->pf_num >> 1); /* 0..3 */ | |
10070 | else | |
10071 | bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */ | |
10072 | } else { | |
10073 | bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */ | |
10074 | bp->pfid = bp->pf_num; /* 0..7 */ | |
10075 | } | |
10076 | ||
51c1a580 MS |
10077 | BNX2X_DEV_INFO("pf_id: %x", bp->pfid); |
10078 | ||
f2e0899f DK |
10079 | bp->link_params.chip_id = bp->common.chip_id; |
10080 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); | |
523224a3 | 10081 | |
1c06328c EG |
10082 | val = (REG_RD(bp, 0x2874) & 0x55); |
10083 | if ((bp->common.chip_id & 0x1) || | |
10084 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { | |
10085 | bp->flags |= ONE_PORT_FLAG; | |
10086 | BNX2X_DEV_INFO("single port device\n"); | |
10087 | } | |
10088 | ||
34f80b04 | 10089 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
754a2f52 | 10090 | bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE << |
34f80b04 EG |
10091 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
10092 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", | |
10093 | bp->common.flash_size, bp->common.flash_size); | |
10094 | ||
1b6e2ceb DK |
10095 | bnx2x_init_shmem(bp); |
10096 | ||
619c5cb6 VZ |
10097 | |
10098 | ||
f2e0899f DK |
10099 | bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ? |
10100 | MISC_REG_GENERIC_CR_1 : | |
10101 | MISC_REG_GENERIC_CR_0)); | |
1b6e2ceb | 10102 | |
34f80b04 | 10103 | bp->link_params.shmem_base = bp->common.shmem_base; |
a22f0788 | 10104 | bp->link_params.shmem2_base = bp->common.shmem2_base; |
b884d95b YR |
10105 | if (SHMEM2_RD(bp, size) > |
10106 | (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)])) | |
10107 | bp->link_params.lfa_base = | |
10108 | REG_RD(bp, bp->common.shmem2_base + | |
10109 | (u32)offsetof(struct shmem2_region, | |
10110 | lfa_host_addr[BP_PORT(bp)])); | |
10111 | else | |
10112 | bp->link_params.lfa_base = 0; | |
2691d51d EG |
10113 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
10114 | bp->common.shmem_base, bp->common.shmem2_base); | |
34f80b04 | 10115 | |
f2e0899f | 10116 | if (!bp->common.shmem_base) { |
34f80b04 EG |
10117 | BNX2X_DEV_INFO("MCP not active\n"); |
10118 | bp->flags |= NO_MCP_FLAG; | |
10119 | return; | |
10120 | } | |
10121 | ||
34f80b04 | 10122 | bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config); |
35b19ba5 | 10123 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
34f80b04 EG |
10124 | |
10125 | bp->link_params.hw_led_mode = ((bp->common.hw_config & | |
10126 | SHARED_HW_CFG_LED_MODE_MASK) >> | |
10127 | SHARED_HW_CFG_LED_MODE_SHIFT); | |
10128 | ||
c2c8b03e EG |
10129 | bp->link_params.feature_config_flags = 0; |
10130 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); | |
10131 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) | |
10132 | bp->link_params.feature_config_flags |= | |
10133 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
10134 | else | |
10135 | bp->link_params.feature_config_flags &= | |
10136 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
10137 | ||
34f80b04 EG |
10138 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
10139 | bp->common.bc_ver = val; | |
10140 | BNX2X_DEV_INFO("bc_ver %X\n", val); | |
10141 | if (val < BNX2X_BC_VER) { | |
10142 | /* for now only warn | |
10143 | * later we might need to enforce this */ | |
51c1a580 MS |
10144 | BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n", |
10145 | BNX2X_BC_VER, val); | |
34f80b04 | 10146 | } |
4d295db0 | 10147 | bp->link_params.feature_config_flags |= |
a22f0788 | 10148 | (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ? |
f85582f8 DK |
10149 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
10150 | ||
a22f0788 YR |
10151 | bp->link_params.feature_config_flags |= |
10152 | (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ? | |
10153 | FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0; | |
a3348722 BW |
10154 | bp->link_params.feature_config_flags |= |
10155 | (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ? | |
10156 | FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0; | |
85242eea YR |
10157 | bp->link_params.feature_config_flags |= |
10158 | (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ? | |
10159 | FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0; | |
55386fe8 YR |
10160 | |
10161 | bp->link_params.feature_config_flags |= | |
10162 | (val >= REQ_BC_VER_4_MT_SUPPORTED) ? | |
10163 | FEATURE_CONFIG_MT_SUPPORT : 0; | |
10164 | ||
0e898dd7 BW |
10165 | bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ? |
10166 | BC_SUPPORTS_PFC_STATS : 0; | |
85242eea | 10167 | |
2e499d3c BW |
10168 | bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ? |
10169 | BC_SUPPORTS_FCOE_FEATURES : 0; | |
10170 | ||
9876879f BW |
10171 | bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ? |
10172 | BC_SUPPORTS_DCBX_MSG_NON_PMF : 0; | |
1d187b34 BW |
10173 | boot_mode = SHMEM_RD(bp, |
10174 | dev_info.port_feature_config[BP_PORT(bp)].mba_config) & | |
10175 | PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK; | |
10176 | switch (boot_mode) { | |
10177 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE: | |
10178 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE; | |
10179 | break; | |
10180 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB: | |
10181 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI; | |
10182 | break; | |
10183 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT: | |
10184 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE; | |
10185 | break; | |
10186 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE: | |
10187 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE; | |
10188 | break; | |
10189 | } | |
10190 | ||
f9a3ebbe DK |
10191 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
10192 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; | |
10193 | ||
72ce58c3 | 10194 | BNX2X_DEV_INFO("%sWoL capable\n", |
f5372251 | 10195 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
34f80b04 EG |
10196 | |
10197 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); | |
10198 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); | |
10199 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); | |
10200 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); | |
10201 | ||
cdaa7cb8 VZ |
10202 | dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n", |
10203 | val, val2, val3, val4); | |
34f80b04 EG |
10204 | } |
10205 | ||
f2e0899f DK |
10206 | #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) |
10207 | #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) | |
10208 | ||
0329aba1 | 10209 | static int bnx2x_get_igu_cam_info(struct bnx2x *bp) |
f2e0899f DK |
10210 | { |
10211 | int pfid = BP_FUNC(bp); | |
f2e0899f DK |
10212 | int igu_sb_id; |
10213 | u32 val; | |
6383c0b3 | 10214 | u8 fid, igu_sb_cnt = 0; |
f2e0899f DK |
10215 | |
10216 | bp->igu_base_sb = 0xff; | |
f2e0899f | 10217 | if (CHIP_INT_MODE_IS_BC(bp)) { |
3395a033 | 10218 | int vn = BP_VN(bp); |
6383c0b3 | 10219 | igu_sb_cnt = bp->igu_sb_cnt; |
f2e0899f DK |
10220 | bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) * |
10221 | FP_SB_MAX_E1x; | |
10222 | ||
10223 | bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x + | |
10224 | (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn); | |
10225 | ||
9b341bb1 | 10226 | return 0; |
f2e0899f DK |
10227 | } |
10228 | ||
10229 | /* IGU in normal mode - read CAM */ | |
10230 | for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; | |
10231 | igu_sb_id++) { | |
10232 | val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); | |
10233 | if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) | |
10234 | continue; | |
10235 | fid = IGU_FID(val); | |
10236 | if ((fid & IGU_FID_ENCODE_IS_PF)) { | |
10237 | if ((fid & IGU_FID_PF_NUM_MASK) != pfid) | |
10238 | continue; | |
10239 | if (IGU_VEC(val) == 0) | |
10240 | /* default status block */ | |
10241 | bp->igu_dsb_id = igu_sb_id; | |
10242 | else { | |
10243 | if (bp->igu_base_sb == 0xff) | |
10244 | bp->igu_base_sb = igu_sb_id; | |
6383c0b3 | 10245 | igu_sb_cnt++; |
f2e0899f DK |
10246 | } |
10247 | } | |
10248 | } | |
619c5cb6 | 10249 | |
6383c0b3 | 10250 | #ifdef CONFIG_PCI_MSI |
185d4c8b AE |
10251 | /* Due to new PF resource allocation by MFW T7.4 and above, it's |
10252 | * optional that number of CAM entries will not be equal to the value | |
10253 | * advertised in PCI. | |
10254 | * Driver should use the minimal value of both as the actual status | |
10255 | * block count | |
619c5cb6 | 10256 | */ |
185d4c8b | 10257 | bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt); |
6383c0b3 | 10258 | #endif |
619c5cb6 | 10259 | |
9b341bb1 | 10260 | if (igu_sb_cnt == 0) { |
f2e0899f | 10261 | BNX2X_ERR("CAM configuration error\n"); |
9b341bb1 BW |
10262 | return -EINVAL; |
10263 | } | |
10264 | ||
10265 | return 0; | |
f2e0899f DK |
10266 | } |
10267 | ||
1dd06ae8 | 10268 | static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg) |
a2fbb9ea | 10269 | { |
a22f0788 YR |
10270 | int cfg_size = 0, idx, port = BP_PORT(bp); |
10271 | ||
10272 | /* Aggregation of supported attributes of all external phys */ | |
10273 | bp->port.supported[0] = 0; | |
10274 | bp->port.supported[1] = 0; | |
b7737c9b YR |
10275 | switch (bp->link_params.num_phys) { |
10276 | case 1: | |
a22f0788 YR |
10277 | bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported; |
10278 | cfg_size = 1; | |
10279 | break; | |
b7737c9b | 10280 | case 2: |
a22f0788 YR |
10281 | bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported; |
10282 | cfg_size = 1; | |
10283 | break; | |
10284 | case 3: | |
10285 | if (bp->link_params.multi_phy_config & | |
10286 | PORT_HW_CFG_PHY_SWAPPED_ENABLED) { | |
10287 | bp->port.supported[1] = | |
10288 | bp->link_params.phy[EXT_PHY1].supported; | |
10289 | bp->port.supported[0] = | |
10290 | bp->link_params.phy[EXT_PHY2].supported; | |
10291 | } else { | |
10292 | bp->port.supported[0] = | |
10293 | bp->link_params.phy[EXT_PHY1].supported; | |
10294 | bp->port.supported[1] = | |
10295 | bp->link_params.phy[EXT_PHY2].supported; | |
10296 | } | |
10297 | cfg_size = 2; | |
10298 | break; | |
b7737c9b | 10299 | } |
a2fbb9ea | 10300 | |
a22f0788 | 10301 | if (!(bp->port.supported[0] || bp->port.supported[1])) { |
51c1a580 | 10302 | BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n", |
b7737c9b | 10303 | SHMEM_RD(bp, |
a22f0788 YR |
10304 | dev_info.port_hw_config[port].external_phy_config), |
10305 | SHMEM_RD(bp, | |
10306 | dev_info.port_hw_config[port].external_phy_config2)); | |
a2fbb9ea | 10307 | return; |
f85582f8 | 10308 | } |
a2fbb9ea | 10309 | |
619c5cb6 VZ |
10310 | if (CHIP_IS_E3(bp)) |
10311 | bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR); | |
10312 | else { | |
10313 | switch (switch_cfg) { | |
10314 | case SWITCH_CFG_1G: | |
10315 | bp->port.phy_addr = REG_RD( | |
10316 | bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); | |
10317 | break; | |
10318 | case SWITCH_CFG_10G: | |
10319 | bp->port.phy_addr = REG_RD( | |
10320 | bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); | |
10321 | break; | |
10322 | default: | |
10323 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", | |
10324 | bp->port.link_config[0]); | |
10325 | return; | |
10326 | } | |
a2fbb9ea | 10327 | } |
619c5cb6 | 10328 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
a22f0788 YR |
10329 | /* mask what we support according to speed_cap_mask per configuration */ |
10330 | for (idx = 0; idx < cfg_size; idx++) { | |
10331 | if (!(bp->link_params.speed_cap_mask[idx] & | |
c18487ee | 10332 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
a22f0788 | 10333 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half; |
a2fbb9ea | 10334 | |
a22f0788 | 10335 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10336 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
a22f0788 | 10337 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full; |
a2fbb9ea | 10338 | |
a22f0788 | 10339 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10340 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
a22f0788 | 10341 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half; |
a2fbb9ea | 10342 | |
a22f0788 | 10343 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10344 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
a22f0788 | 10345 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full; |
a2fbb9ea | 10346 | |
a22f0788 | 10347 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10348 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
a22f0788 | 10349 | bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half | |
f85582f8 | 10350 | SUPPORTED_1000baseT_Full); |
a2fbb9ea | 10351 | |
a22f0788 | 10352 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10353 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
a22f0788 | 10354 | bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full; |
a2fbb9ea | 10355 | |
a22f0788 | 10356 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10357 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
a22f0788 YR |
10358 | bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full; |
10359 | ||
10360 | } | |
a2fbb9ea | 10361 | |
a22f0788 YR |
10362 | BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0], |
10363 | bp->port.supported[1]); | |
a2fbb9ea ET |
10364 | } |
10365 | ||
0329aba1 | 10366 | static void bnx2x_link_settings_requested(struct bnx2x *bp) |
a2fbb9ea | 10367 | { |
a22f0788 YR |
10368 | u32 link_config, idx, cfg_size = 0; |
10369 | bp->port.advertising[0] = 0; | |
10370 | bp->port.advertising[1] = 0; | |
10371 | switch (bp->link_params.num_phys) { | |
10372 | case 1: | |
10373 | case 2: | |
10374 | cfg_size = 1; | |
10375 | break; | |
10376 | case 3: | |
10377 | cfg_size = 2; | |
10378 | break; | |
10379 | } | |
10380 | for (idx = 0; idx < cfg_size; idx++) { | |
10381 | bp->link_params.req_duplex[idx] = DUPLEX_FULL; | |
10382 | link_config = bp->port.link_config[idx]; | |
10383 | switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { | |
f85582f8 | 10384 | case PORT_FEATURE_LINK_SPEED_AUTO: |
a22f0788 YR |
10385 | if (bp->port.supported[idx] & SUPPORTED_Autoneg) { |
10386 | bp->link_params.req_line_speed[idx] = | |
10387 | SPEED_AUTO_NEG; | |
10388 | bp->port.advertising[idx] |= | |
10389 | bp->port.supported[idx]; | |
10bd1f24 MY |
10390 | if (bp->link_params.phy[EXT_PHY1].type == |
10391 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) | |
10392 | bp->port.advertising[idx] |= | |
10393 | (SUPPORTED_100baseT_Half | | |
10394 | SUPPORTED_100baseT_Full); | |
f85582f8 DK |
10395 | } else { |
10396 | /* force 10G, no AN */ | |
a22f0788 YR |
10397 | bp->link_params.req_line_speed[idx] = |
10398 | SPEED_10000; | |
10399 | bp->port.advertising[idx] |= | |
10400 | (ADVERTISED_10000baseT_Full | | |
f85582f8 | 10401 | ADVERTISED_FIBRE); |
a22f0788 | 10402 | continue; |
f85582f8 DK |
10403 | } |
10404 | break; | |
a2fbb9ea | 10405 | |
f85582f8 | 10406 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
a22f0788 YR |
10407 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) { |
10408 | bp->link_params.req_line_speed[idx] = | |
10409 | SPEED_10; | |
10410 | bp->port.advertising[idx] |= | |
10411 | (ADVERTISED_10baseT_Full | | |
f85582f8 DK |
10412 | ADVERTISED_TP); |
10413 | } else { | |
51c1a580 | 10414 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 | 10415 | link_config, |
a22f0788 | 10416 | bp->link_params.speed_cap_mask[idx]); |
f85582f8 DK |
10417 | return; |
10418 | } | |
10419 | break; | |
a2fbb9ea | 10420 | |
f85582f8 | 10421 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
a22f0788 YR |
10422 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) { |
10423 | bp->link_params.req_line_speed[idx] = | |
10424 | SPEED_10; | |
10425 | bp->link_params.req_duplex[idx] = | |
10426 | DUPLEX_HALF; | |
10427 | bp->port.advertising[idx] |= | |
10428 | (ADVERTISED_10baseT_Half | | |
f85582f8 DK |
10429 | ADVERTISED_TP); |
10430 | } else { | |
51c1a580 | 10431 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
10432 | link_config, |
10433 | bp->link_params.speed_cap_mask[idx]); | |
10434 | return; | |
10435 | } | |
10436 | break; | |
a2fbb9ea | 10437 | |
f85582f8 DK |
10438 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
10439 | if (bp->port.supported[idx] & | |
10440 | SUPPORTED_100baseT_Full) { | |
a22f0788 YR |
10441 | bp->link_params.req_line_speed[idx] = |
10442 | SPEED_100; | |
10443 | bp->port.advertising[idx] |= | |
10444 | (ADVERTISED_100baseT_Full | | |
f85582f8 DK |
10445 | ADVERTISED_TP); |
10446 | } else { | |
51c1a580 | 10447 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
10448 | link_config, |
10449 | bp->link_params.speed_cap_mask[idx]); | |
10450 | return; | |
10451 | } | |
10452 | break; | |
a2fbb9ea | 10453 | |
f85582f8 DK |
10454 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
10455 | if (bp->port.supported[idx] & | |
10456 | SUPPORTED_100baseT_Half) { | |
10457 | bp->link_params.req_line_speed[idx] = | |
10458 | SPEED_100; | |
10459 | bp->link_params.req_duplex[idx] = | |
10460 | DUPLEX_HALF; | |
a22f0788 YR |
10461 | bp->port.advertising[idx] |= |
10462 | (ADVERTISED_100baseT_Half | | |
f85582f8 DK |
10463 | ADVERTISED_TP); |
10464 | } else { | |
51c1a580 | 10465 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
10466 | link_config, |
10467 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
10468 | return; |
10469 | } | |
10470 | break; | |
a2fbb9ea | 10471 | |
f85582f8 | 10472 | case PORT_FEATURE_LINK_SPEED_1G: |
a22f0788 YR |
10473 | if (bp->port.supported[idx] & |
10474 | SUPPORTED_1000baseT_Full) { | |
10475 | bp->link_params.req_line_speed[idx] = | |
10476 | SPEED_1000; | |
10477 | bp->port.advertising[idx] |= | |
10478 | (ADVERTISED_1000baseT_Full | | |
f85582f8 DK |
10479 | ADVERTISED_TP); |
10480 | } else { | |
51c1a580 | 10481 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
10482 | link_config, |
10483 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
10484 | return; |
10485 | } | |
10486 | break; | |
a2fbb9ea | 10487 | |
f85582f8 | 10488 | case PORT_FEATURE_LINK_SPEED_2_5G: |
a22f0788 YR |
10489 | if (bp->port.supported[idx] & |
10490 | SUPPORTED_2500baseX_Full) { | |
10491 | bp->link_params.req_line_speed[idx] = | |
10492 | SPEED_2500; | |
10493 | bp->port.advertising[idx] |= | |
10494 | (ADVERTISED_2500baseX_Full | | |
34f80b04 | 10495 | ADVERTISED_TP); |
f85582f8 | 10496 | } else { |
51c1a580 | 10497 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 10498 | link_config, |
f85582f8 DK |
10499 | bp->link_params.speed_cap_mask[idx]); |
10500 | return; | |
10501 | } | |
10502 | break; | |
a2fbb9ea | 10503 | |
f85582f8 | 10504 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
a22f0788 YR |
10505 | if (bp->port.supported[idx] & |
10506 | SUPPORTED_10000baseT_Full) { | |
10507 | bp->link_params.req_line_speed[idx] = | |
10508 | SPEED_10000; | |
10509 | bp->port.advertising[idx] |= | |
10510 | (ADVERTISED_10000baseT_Full | | |
34f80b04 | 10511 | ADVERTISED_FIBRE); |
f85582f8 | 10512 | } else { |
51c1a580 | 10513 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 10514 | link_config, |
f85582f8 DK |
10515 | bp->link_params.speed_cap_mask[idx]); |
10516 | return; | |
10517 | } | |
10518 | break; | |
3c9ada22 YR |
10519 | case PORT_FEATURE_LINK_SPEED_20G: |
10520 | bp->link_params.req_line_speed[idx] = SPEED_20000; | |
a2fbb9ea | 10521 | |
3c9ada22 | 10522 | break; |
f85582f8 | 10523 | default: |
51c1a580 | 10524 | BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n", |
754a2f52 | 10525 | link_config); |
f85582f8 DK |
10526 | bp->link_params.req_line_speed[idx] = |
10527 | SPEED_AUTO_NEG; | |
10528 | bp->port.advertising[idx] = | |
10529 | bp->port.supported[idx]; | |
10530 | break; | |
10531 | } | |
a2fbb9ea | 10532 | |
a22f0788 | 10533 | bp->link_params.req_flow_ctrl[idx] = (link_config & |
34f80b04 | 10534 | PORT_FEATURE_FLOW_CONTROL_MASK); |
cd1dfce2 YM |
10535 | if (bp->link_params.req_flow_ctrl[idx] == |
10536 | BNX2X_FLOW_CTRL_AUTO) { | |
10537 | if (!(bp->port.supported[idx] & SUPPORTED_Autoneg)) | |
10538 | bp->link_params.req_flow_ctrl[idx] = | |
10539 | BNX2X_FLOW_CTRL_NONE; | |
10540 | else | |
10541 | bnx2x_set_requested_fc(bp); | |
a22f0788 | 10542 | } |
a2fbb9ea | 10543 | |
51c1a580 | 10544 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n", |
a22f0788 YR |
10545 | bp->link_params.req_line_speed[idx], |
10546 | bp->link_params.req_duplex[idx], | |
10547 | bp->link_params.req_flow_ctrl[idx], | |
10548 | bp->port.advertising[idx]); | |
10549 | } | |
a2fbb9ea ET |
10550 | } |
10551 | ||
0329aba1 | 10552 | static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi) |
e665bfda | 10553 | { |
86564c3f YM |
10554 | __be16 mac_hi_be = cpu_to_be16(mac_hi); |
10555 | __be32 mac_lo_be = cpu_to_be32(mac_lo); | |
10556 | memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be)); | |
10557 | memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be)); | |
e665bfda MC |
10558 | } |
10559 | ||
0329aba1 | 10560 | static void bnx2x_get_port_hwinfo(struct bnx2x *bp) |
a2fbb9ea | 10561 | { |
34f80b04 | 10562 | int port = BP_PORT(bp); |
589abe3a | 10563 | u32 config; |
c8c60d88 | 10564 | u32 ext_phy_type, ext_phy_config, eee_mode; |
a2fbb9ea | 10565 | |
c18487ee | 10566 | bp->link_params.bp = bp; |
34f80b04 | 10567 | bp->link_params.port = port; |
c18487ee | 10568 | |
c18487ee | 10569 | bp->link_params.lane_config = |
a2fbb9ea | 10570 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
4d295db0 | 10571 | |
a22f0788 | 10572 | bp->link_params.speed_cap_mask[0] = |
a2fbb9ea ET |
10573 | SHMEM_RD(bp, |
10574 | dev_info.port_hw_config[port].speed_capability_mask); | |
a22f0788 YR |
10575 | bp->link_params.speed_cap_mask[1] = |
10576 | SHMEM_RD(bp, | |
10577 | dev_info.port_hw_config[port].speed_capability_mask2); | |
10578 | bp->port.link_config[0] = | |
a2fbb9ea ET |
10579 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
10580 | ||
a22f0788 YR |
10581 | bp->port.link_config[1] = |
10582 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2); | |
c2c8b03e | 10583 | |
a22f0788 YR |
10584 | bp->link_params.multi_phy_config = |
10585 | SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config); | |
3ce2c3f9 EG |
10586 | /* If the device is capable of WoL, set the default state according |
10587 | * to the HW | |
10588 | */ | |
4d295db0 | 10589 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
3ce2c3f9 EG |
10590 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
10591 | (config & PORT_FEATURE_WOL_ENABLED)); | |
10592 | ||
4ba7699b YM |
10593 | if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) == |
10594 | PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp)) | |
10595 | bp->flags |= NO_ISCSI_FLAG; | |
10596 | if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) == | |
10597 | PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp))) | |
10598 | bp->flags |= NO_FCOE_FLAG; | |
10599 | ||
51c1a580 | 10600 | BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n", |
c18487ee | 10601 | bp->link_params.lane_config, |
a22f0788 YR |
10602 | bp->link_params.speed_cap_mask[0], |
10603 | bp->port.link_config[0]); | |
a2fbb9ea | 10604 | |
a22f0788 | 10605 | bp->link_params.switch_cfg = (bp->port.link_config[0] & |
f85582f8 | 10606 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
b7737c9b | 10607 | bnx2x_phy_probe(&bp->link_params); |
c18487ee | 10608 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
a2fbb9ea ET |
10609 | |
10610 | bnx2x_link_settings_requested(bp); | |
10611 | ||
01cd4528 EG |
10612 | /* |
10613 | * If connected directly, work with the internal PHY, otherwise, work | |
10614 | * with the external PHY | |
10615 | */ | |
b7737c9b YR |
10616 | ext_phy_config = |
10617 | SHMEM_RD(bp, | |
10618 | dev_info.port_hw_config[port].external_phy_config); | |
10619 | ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config); | |
01cd4528 | 10620 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
b7737c9b | 10621 | bp->mdio.prtad = bp->port.phy_addr; |
01cd4528 EG |
10622 | |
10623 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && | |
10624 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) | |
10625 | bp->mdio.prtad = | |
b7737c9b | 10626 | XGXS_EXT_PHY_ADDR(ext_phy_config); |
5866df6d | 10627 | |
c8c60d88 YM |
10628 | /* Configure link feature according to nvram value */ |
10629 | eee_mode = (((SHMEM_RD(bp, dev_info. | |
10630 | port_feature_config[port].eee_power_mode)) & | |
10631 | PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >> | |
10632 | PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT); | |
10633 | if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) { | |
10634 | bp->link_params.eee_mode = EEE_MODE_ADV_LPI | | |
10635 | EEE_MODE_ENABLE_LPI | | |
10636 | EEE_MODE_OUTPUT_TIME; | |
10637 | } else { | |
10638 | bp->link_params.eee_mode = 0; | |
10639 | } | |
0793f83f | 10640 | } |
01cd4528 | 10641 | |
b306f5ed | 10642 | void bnx2x_get_iscsi_info(struct bnx2x *bp) |
2ba45142 | 10643 | { |
9e62e912 | 10644 | u32 no_flags = NO_ISCSI_FLAG; |
bf61ee14 | 10645 | int port = BP_PORT(bp); |
2ba45142 | 10646 | u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
bf61ee14 | 10647 | drv_lic_key[port].max_iscsi_conn); |
2ba45142 | 10648 | |
55c11941 MS |
10649 | if (!CNIC_SUPPORT(bp)) { |
10650 | bp->flags |= no_flags; | |
10651 | return; | |
10652 | } | |
10653 | ||
b306f5ed | 10654 | /* Get the number of maximum allowed iSCSI connections */ |
2ba45142 VZ |
10655 | bp->cnic_eth_dev.max_iscsi_conn = |
10656 | (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >> | |
10657 | BNX2X_MAX_ISCSI_INIT_CONN_SHIFT; | |
10658 | ||
b306f5ed DK |
10659 | BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n", |
10660 | bp->cnic_eth_dev.max_iscsi_conn); | |
10661 | ||
10662 | /* | |
10663 | * If maximum allowed number of connections is zero - | |
10664 | * disable the feature. | |
10665 | */ | |
10666 | if (!bp->cnic_eth_dev.max_iscsi_conn) | |
9e62e912 | 10667 | bp->flags |= no_flags; |
55c11941 | 10668 | |
b306f5ed DK |
10669 | } |
10670 | ||
0329aba1 | 10671 | static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func) |
9e62e912 DK |
10672 | { |
10673 | /* Port info */ | |
10674 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
10675 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper); | |
10676 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
10677 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower); | |
10678 | ||
10679 | /* Node info */ | |
10680 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
10681 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper); | |
10682 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
10683 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower); | |
10684 | } | |
0329aba1 | 10685 | static void bnx2x_get_fcoe_info(struct bnx2x *bp) |
b306f5ed DK |
10686 | { |
10687 | int port = BP_PORT(bp); | |
10688 | int func = BP_ABS_FUNC(bp); | |
b306f5ed DK |
10689 | u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
10690 | drv_lic_key[port].max_fcoe_conn); | |
10691 | ||
55c11941 MS |
10692 | if (!CNIC_SUPPORT(bp)) { |
10693 | bp->flags |= NO_FCOE_FLAG; | |
10694 | return; | |
10695 | } | |
10696 | ||
b306f5ed | 10697 | /* Get the number of maximum allowed FCoE connections */ |
2ba45142 VZ |
10698 | bp->cnic_eth_dev.max_fcoe_conn = |
10699 | (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >> | |
10700 | BNX2X_MAX_FCOE_INIT_CONN_SHIFT; | |
10701 | ||
bf61ee14 VZ |
10702 | /* Read the WWN: */ |
10703 | if (!IS_MF(bp)) { | |
10704 | /* Port info */ | |
10705 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
10706 | SHMEM_RD(bp, | |
2de67439 | 10707 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
10708 | fcoe_wwn_port_name_upper); |
10709 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
10710 | SHMEM_RD(bp, | |
2de67439 | 10711 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
10712 | fcoe_wwn_port_name_lower); |
10713 | ||
10714 | /* Node info */ | |
10715 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
10716 | SHMEM_RD(bp, | |
2de67439 | 10717 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
10718 | fcoe_wwn_node_name_upper); |
10719 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
10720 | SHMEM_RD(bp, | |
2de67439 | 10721 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
10722 | fcoe_wwn_node_name_lower); |
10723 | } else if (!IS_MF_SD(bp)) { | |
bf61ee14 VZ |
10724 | /* |
10725 | * Read the WWN info only if the FCoE feature is enabled for | |
10726 | * this function. | |
10727 | */ | |
7b5342d9 | 10728 | if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp)) |
9e62e912 DK |
10729 | bnx2x_get_ext_wwn_info(bp, func); |
10730 | ||
382e513a | 10731 | } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) { |
9e62e912 | 10732 | bnx2x_get_ext_wwn_info(bp, func); |
382e513a | 10733 | } |
bf61ee14 | 10734 | |
b306f5ed | 10735 | BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn); |
2ba45142 | 10736 | |
bf61ee14 VZ |
10737 | /* |
10738 | * If maximum allowed number of connections is zero - | |
2ba45142 VZ |
10739 | * disable the feature. |
10740 | */ | |
2ba45142 VZ |
10741 | if (!bp->cnic_eth_dev.max_fcoe_conn) |
10742 | bp->flags |= NO_FCOE_FLAG; | |
10743 | } | |
b306f5ed | 10744 | |
0329aba1 | 10745 | static void bnx2x_get_cnic_info(struct bnx2x *bp) |
b306f5ed DK |
10746 | { |
10747 | /* | |
10748 | * iSCSI may be dynamically disabled but reading | |
10749 | * info here we will decrease memory usage by driver | |
10750 | * if the feature is disabled for good | |
10751 | */ | |
10752 | bnx2x_get_iscsi_info(bp); | |
10753 | bnx2x_get_fcoe_info(bp); | |
10754 | } | |
2ba45142 | 10755 | |
0329aba1 | 10756 | static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp) |
0793f83f DK |
10757 | { |
10758 | u32 val, val2; | |
10759 | int func = BP_ABS_FUNC(bp); | |
10760 | int port = BP_PORT(bp); | |
2ba45142 VZ |
10761 | u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac; |
10762 | u8 *fip_mac = bp->fip_mac; | |
0793f83f | 10763 | |
55c11941 MS |
10764 | if (IS_MF(bp)) { |
10765 | /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or | |
2ba45142 | 10766 | * FCoE MAC then the appropriate feature should be disabled. |
55c11941 MS |
10767 | * In non SD mode features configuration comes from struct |
10768 | * func_ext_config. | |
2ba45142 | 10769 | */ |
55c11941 | 10770 | if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) { |
0793f83f DK |
10771 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); |
10772 | if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { | |
10773 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
55c11941 | 10774 | iscsi_mac_addr_upper); |
0793f83f | 10775 | val = MF_CFG_RD(bp, func_ext_config[func]. |
55c11941 | 10776 | iscsi_mac_addr_lower); |
2ba45142 | 10777 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
55c11941 MS |
10778 | BNX2X_DEV_INFO |
10779 | ("Read iSCSI MAC: %pM\n", iscsi_mac); | |
10780 | } else { | |
2ba45142 | 10781 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
55c11941 | 10782 | } |
2ba45142 VZ |
10783 | |
10784 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { | |
10785 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
55c11941 | 10786 | fcoe_mac_addr_upper); |
2ba45142 | 10787 | val = MF_CFG_RD(bp, func_ext_config[func]. |
55c11941 | 10788 | fcoe_mac_addr_lower); |
2ba45142 | 10789 | bnx2x_set_mac_buf(fip_mac, val, val2); |
55c11941 MS |
10790 | BNX2X_DEV_INFO |
10791 | ("Read FCoE L2 MAC: %pM\n", fip_mac); | |
10792 | } else { | |
2ba45142 | 10793 | bp->flags |= NO_FCOE_FLAG; |
55c11941 | 10794 | } |
a3348722 BW |
10795 | |
10796 | bp->mf_ext_config = cfg; | |
10797 | ||
9e62e912 | 10798 | } else { /* SD MODE */ |
55c11941 MS |
10799 | if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) { |
10800 | /* use primary mac as iscsi mac */ | |
10801 | memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN); | |
10802 | ||
10803 | BNX2X_DEV_INFO("SD ISCSI MODE\n"); | |
10804 | BNX2X_DEV_INFO | |
10805 | ("Read iSCSI MAC: %pM\n", iscsi_mac); | |
10806 | } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) { | |
10807 | /* use primary mac as fip mac */ | |
10808 | memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN); | |
10809 | BNX2X_DEV_INFO("SD FCoE MODE\n"); | |
10810 | BNX2X_DEV_INFO | |
10811 | ("Read FIP MAC: %pM\n", fip_mac); | |
614c76df | 10812 | } |
0793f83f | 10813 | } |
a3348722 | 10814 | |
55c11941 MS |
10815 | if (IS_MF_STORAGE_SD(bp)) |
10816 | /* Zero primary MAC configuration */ | |
10817 | memset(bp->dev->dev_addr, 0, ETH_ALEN); | |
10818 | ||
f72839d0 | 10819 | if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp)) |
a3348722 BW |
10820 | /* use FIP MAC as primary MAC */ |
10821 | memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN); | |
10822 | ||
0793f83f | 10823 | } else { |
0793f83f | 10824 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 10825 | iscsi_mac_upper); |
0793f83f | 10826 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 10827 | iscsi_mac_lower); |
2ba45142 | 10828 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
c03bd39c VZ |
10829 | |
10830 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
55c11941 | 10831 | fcoe_fip_mac_upper); |
c03bd39c | 10832 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 10833 | fcoe_fip_mac_lower); |
c03bd39c | 10834 | bnx2x_set_mac_buf(fip_mac, val, val2); |
0793f83f DK |
10835 | } |
10836 | ||
55c11941 | 10837 | /* Disable iSCSI OOO if MAC configuration is invalid. */ |
426b9241 | 10838 | if (!is_valid_ether_addr(iscsi_mac)) { |
55c11941 | 10839 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
426b9241 DK |
10840 | memset(iscsi_mac, 0, ETH_ALEN); |
10841 | } | |
10842 | ||
55c11941 | 10843 | /* Disable FCoE if MAC configuration is invalid. */ |
426b9241 DK |
10844 | if (!is_valid_ether_addr(fip_mac)) { |
10845 | bp->flags |= NO_FCOE_FLAG; | |
10846 | memset(bp->fip_mac, 0, ETH_ALEN); | |
10847 | } | |
55c11941 MS |
10848 | } |
10849 | ||
0329aba1 | 10850 | static void bnx2x_get_mac_hwinfo(struct bnx2x *bp) |
55c11941 MS |
10851 | { |
10852 | u32 val, val2; | |
10853 | int func = BP_ABS_FUNC(bp); | |
10854 | int port = BP_PORT(bp); | |
10855 | ||
10856 | /* Zero primary MAC configuration */ | |
10857 | memset(bp->dev->dev_addr, 0, ETH_ALEN); | |
10858 | ||
10859 | if (BP_NOMCP(bp)) { | |
10860 | BNX2X_ERROR("warning: random MAC workaround active\n"); | |
10861 | eth_hw_addr_random(bp->dev); | |
10862 | } else if (IS_MF(bp)) { | |
10863 | val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); | |
10864 | val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); | |
10865 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && | |
10866 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) | |
10867 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
10868 | ||
10869 | if (CNIC_SUPPORT(bp)) | |
10870 | bnx2x_get_cnic_mac_hwinfo(bp); | |
10871 | } else { | |
10872 | /* in SF read MACs from port configuration */ | |
10873 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); | |
10874 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); | |
10875 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
10876 | ||
10877 | if (CNIC_SUPPORT(bp)) | |
10878 | bnx2x_get_cnic_mac_hwinfo(bp); | |
10879 | } | |
10880 | ||
10881 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); | |
619c5cb6 | 10882 | |
614c76df | 10883 | if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr)) |
619c5cb6 | 10884 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
10885 | "bad Ethernet MAC address configuration: %pM\n" |
10886 | "change it manually before bringing up the appropriate network interface\n", | |
0f9dad10 | 10887 | bp->dev->dev_addr); |
7964211d | 10888 | } |
51c1a580 | 10889 | |
0329aba1 | 10890 | static bool bnx2x_get_dropless_info(struct bnx2x *bp) |
7964211d YM |
10891 | { |
10892 | int tmp; | |
10893 | u32 cfg; | |
51c1a580 | 10894 | |
7964211d YM |
10895 | if (IS_MF(bp) && !CHIP_IS_E1x(bp)) { |
10896 | /* Take function: tmp = func */ | |
10897 | tmp = BP_ABS_FUNC(bp); | |
10898 | cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg); | |
10899 | cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING); | |
10900 | } else { | |
10901 | /* Take port: tmp = port */ | |
10902 | tmp = BP_PORT(bp); | |
10903 | cfg = SHMEM_RD(bp, | |
10904 | dev_info.port_hw_config[tmp].generic_features); | |
10905 | cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED); | |
10906 | } | |
10907 | return cfg; | |
34f80b04 EG |
10908 | } |
10909 | ||
0329aba1 | 10910 | static int bnx2x_get_hwinfo(struct bnx2x *bp) |
34f80b04 | 10911 | { |
0793f83f | 10912 | int /*abs*/func = BP_ABS_FUNC(bp); |
b8ee8328 | 10913 | int vn; |
0793f83f | 10914 | u32 val = 0; |
34f80b04 | 10915 | int rc = 0; |
a2fbb9ea | 10916 | |
34f80b04 | 10917 | bnx2x_get_common_hwinfo(bp); |
a2fbb9ea | 10918 | |
6383c0b3 AE |
10919 | /* |
10920 | * initialize IGU parameters | |
10921 | */ | |
f2e0899f DK |
10922 | if (CHIP_IS_E1x(bp)) { |
10923 | bp->common.int_block = INT_BLOCK_HC; | |
10924 | ||
10925 | bp->igu_dsb_id = DEF_SB_IGU_ID; | |
10926 | bp->igu_base_sb = 0; | |
f2e0899f DK |
10927 | } else { |
10928 | bp->common.int_block = INT_BLOCK_IGU; | |
7a06a122 DK |
10929 | |
10930 | /* do not allow device reset during IGU info preocessing */ | |
10931 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); | |
10932 | ||
f2e0899f | 10933 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
619c5cb6 VZ |
10934 | |
10935 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { | |
10936 | int tout = 5000; | |
10937 | ||
10938 | BNX2X_DEV_INFO("FORCING Normal Mode\n"); | |
10939 | ||
10940 | val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); | |
10941 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val); | |
10942 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f); | |
10943 | ||
10944 | while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
10945 | tout--; | |
0926d499 | 10946 | usleep_range(1000, 2000); |
619c5cb6 VZ |
10947 | } |
10948 | ||
10949 | if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
10950 | dev_err(&bp->pdev->dev, | |
10951 | "FORCING Normal Mode failed!!!\n"); | |
9b341bb1 BW |
10952 | bnx2x_release_hw_lock(bp, |
10953 | HW_LOCK_RESOURCE_RESET); | |
619c5cb6 VZ |
10954 | return -EPERM; |
10955 | } | |
10956 | } | |
10957 | ||
f2e0899f | 10958 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
619c5cb6 | 10959 | BNX2X_DEV_INFO("IGU Backward Compatible Mode\n"); |
f2e0899f DK |
10960 | bp->common.int_block |= INT_BLOCK_MODE_BW_COMP; |
10961 | } else | |
619c5cb6 | 10962 | BNX2X_DEV_INFO("IGU Normal Mode\n"); |
523224a3 | 10963 | |
9b341bb1 | 10964 | rc = bnx2x_get_igu_cam_info(bp); |
7a06a122 | 10965 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
9b341bb1 BW |
10966 | if (rc) |
10967 | return rc; | |
f2e0899f | 10968 | } |
619c5cb6 VZ |
10969 | |
10970 | /* | |
10971 | * set base FW non-default (fast path) status block id, this value is | |
10972 | * used to initialize the fw_sb_id saved on the fp/queue structure to | |
10973 | * determine the id used by the FW. | |
10974 | */ | |
10975 | if (CHIP_IS_E1x(bp)) | |
10976 | bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp); | |
10977 | else /* | |
10978 | * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of | |
10979 | * the same queue are indicated on the same IGU SB). So we prefer | |
10980 | * FW and IGU SBs to be the same value. | |
10981 | */ | |
10982 | bp->base_fw_ndsb = bp->igu_base_sb; | |
10983 | ||
10984 | BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n" | |
10985 | "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb, | |
10986 | bp->igu_sb_cnt, bp->base_fw_ndsb); | |
f2e0899f DK |
10987 | |
10988 | /* | |
10989 | * Initialize MF configuration | |
10990 | */ | |
523224a3 | 10991 | |
fb3bff17 DK |
10992 | bp->mf_ov = 0; |
10993 | bp->mf_mode = 0; | |
3395a033 | 10994 | vn = BP_VN(bp); |
0793f83f | 10995 | |
f2e0899f | 10996 | if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) { |
619c5cb6 VZ |
10997 | BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n", |
10998 | bp->common.shmem2_base, SHMEM2_RD(bp, size), | |
10999 | (u32)offsetof(struct shmem2_region, mf_cfg_addr)); | |
11000 | ||
f2e0899f DK |
11001 | if (SHMEM2_HAS(bp, mf_cfg_addr)) |
11002 | bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr); | |
11003 | else | |
11004 | bp->common.mf_cfg_base = bp->common.shmem_base + | |
523224a3 DK |
11005 | offsetof(struct shmem_region, func_mb) + |
11006 | E1H_FUNC_MAX * sizeof(struct drv_func_mb); | |
0793f83f DK |
11007 | /* |
11008 | * get mf configuration: | |
25985edc | 11009 | * 1. existence of MF configuration |
0793f83f DK |
11010 | * 2. MAC address must be legal (check only upper bytes) |
11011 | * for Switch-Independent mode; | |
11012 | * OVLAN must be legal for Switch-Dependent mode | |
11013 | * 3. SF_MODE configures specific MF mode | |
11014 | */ | |
11015 | if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
11016 | /* get mf configuration */ | |
11017 | val = SHMEM_RD(bp, | |
11018 | dev_info.shared_feature_config.config); | |
11019 | val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK; | |
11020 | ||
11021 | switch (val) { | |
11022 | case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: | |
11023 | val = MF_CFG_RD(bp, func_mf_config[func]. | |
11024 | mac_upper); | |
11025 | /* check for legal mac (upper bytes)*/ | |
11026 | if (val != 0xffff) { | |
11027 | bp->mf_mode = MULTI_FUNCTION_SI; | |
11028 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11029 | func_mf_config[func].config); | |
11030 | } else | |
51c1a580 | 11031 | BNX2X_DEV_INFO("illegal MAC address for SI\n"); |
0793f83f | 11032 | break; |
a3348722 BW |
11033 | case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE: |
11034 | if ((!CHIP_IS_E1x(bp)) && | |
11035 | (MF_CFG_RD(bp, func_mf_config[func]. | |
11036 | mac_upper) != 0xffff) && | |
11037 | (SHMEM2_HAS(bp, | |
11038 | afex_driver_support))) { | |
11039 | bp->mf_mode = MULTI_FUNCTION_AFEX; | |
11040 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11041 | func_mf_config[func].config); | |
11042 | } else { | |
11043 | BNX2X_DEV_INFO("can not configure afex mode\n"); | |
11044 | } | |
11045 | break; | |
0793f83f DK |
11046 | case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: |
11047 | /* get OV configuration */ | |
11048 | val = MF_CFG_RD(bp, | |
11049 | func_mf_config[FUNC_0].e1hov_tag); | |
11050 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; | |
11051 | ||
11052 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { | |
11053 | bp->mf_mode = MULTI_FUNCTION_SD; | |
11054 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11055 | func_mf_config[func].config); | |
11056 | } else | |
754a2f52 | 11057 | BNX2X_DEV_INFO("illegal OV for SD\n"); |
0793f83f DK |
11058 | break; |
11059 | default: | |
11060 | /* Unknown configuration: reset mf_config */ | |
11061 | bp->mf_config[vn] = 0; | |
51c1a580 | 11062 | BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val); |
0793f83f DK |
11063 | } |
11064 | } | |
a2fbb9ea | 11065 | |
2691d51d | 11066 | BNX2X_DEV_INFO("%s function mode\n", |
fb3bff17 | 11067 | IS_MF(bp) ? "multi" : "single"); |
2691d51d | 11068 | |
0793f83f DK |
11069 | switch (bp->mf_mode) { |
11070 | case MULTI_FUNCTION_SD: | |
11071 | val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
11072 | FUNC_MF_CFG_E1HOV_TAG_MASK; | |
2691d51d | 11073 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
fb3bff17 | 11074 | bp->mf_ov = val; |
619c5cb6 VZ |
11075 | bp->path_has_ovlan = true; |
11076 | ||
51c1a580 MS |
11077 | BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n", |
11078 | func, bp->mf_ov, bp->mf_ov); | |
2691d51d | 11079 | } else { |
619c5cb6 | 11080 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
11081 | "No valid MF OV for func %d, aborting\n", |
11082 | func); | |
619c5cb6 | 11083 | return -EPERM; |
34f80b04 | 11084 | } |
0793f83f | 11085 | break; |
a3348722 BW |
11086 | case MULTI_FUNCTION_AFEX: |
11087 | BNX2X_DEV_INFO("func %d is in MF afex mode\n", func); | |
11088 | break; | |
0793f83f | 11089 | case MULTI_FUNCTION_SI: |
51c1a580 MS |
11090 | BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n", |
11091 | func); | |
0793f83f DK |
11092 | break; |
11093 | default: | |
11094 | if (vn) { | |
619c5cb6 | 11095 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
11096 | "VN %d is in a single function mode, aborting\n", |
11097 | vn); | |
619c5cb6 | 11098 | return -EPERM; |
2691d51d | 11099 | } |
0793f83f | 11100 | break; |
34f80b04 | 11101 | } |
0793f83f | 11102 | |
619c5cb6 VZ |
11103 | /* check if other port on the path needs ovlan: |
11104 | * Since MF configuration is shared between ports | |
11105 | * Possible mixed modes are only | |
11106 | * {SF, SI} {SF, SD} {SD, SF} {SI, SF} | |
11107 | */ | |
11108 | if (CHIP_MODE_IS_4_PORT(bp) && | |
11109 | !bp->path_has_ovlan && | |
11110 | !IS_MF(bp) && | |
11111 | bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
11112 | u8 other_port = !BP_PORT(bp); | |
11113 | u8 other_func = BP_PATH(bp) + 2*other_port; | |
11114 | val = MF_CFG_RD(bp, | |
11115 | func_mf_config[other_func].e1hov_tag); | |
11116 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) | |
11117 | bp->path_has_ovlan = true; | |
11118 | } | |
34f80b04 | 11119 | } |
a2fbb9ea | 11120 | |
f2e0899f DK |
11121 | /* adjust igu_sb_cnt to MF for E1x */ |
11122 | if (CHIP_IS_E1x(bp) && IS_MF(bp)) | |
523224a3 DK |
11123 | bp->igu_sb_cnt /= E1HVN_MAX; |
11124 | ||
619c5cb6 VZ |
11125 | /* port info */ |
11126 | bnx2x_get_port_hwinfo(bp); | |
f2e0899f | 11127 | |
0793f83f DK |
11128 | /* Get MAC addresses */ |
11129 | bnx2x_get_mac_hwinfo(bp); | |
a2fbb9ea | 11130 | |
2ba45142 | 11131 | bnx2x_get_cnic_info(bp); |
2ba45142 | 11132 | |
34f80b04 EG |
11133 | return rc; |
11134 | } | |
11135 | ||
0329aba1 | 11136 | static void bnx2x_read_fwinfo(struct bnx2x *bp) |
34f24c7f VZ |
11137 | { |
11138 | int cnt, i, block_end, rodi; | |
fcdf95cb | 11139 | char vpd_start[BNX2X_VPD_LEN+1]; |
34f24c7f VZ |
11140 | char str_id_reg[VENDOR_ID_LEN+1]; |
11141 | char str_id_cap[VENDOR_ID_LEN+1]; | |
fcdf95cb BW |
11142 | char *vpd_data; |
11143 | char *vpd_extended_data = NULL; | |
34f24c7f VZ |
11144 | u8 len; |
11145 | ||
fcdf95cb | 11146 | cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start); |
34f24c7f VZ |
11147 | memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); |
11148 | ||
11149 | if (cnt < BNX2X_VPD_LEN) | |
11150 | goto out_not_found; | |
11151 | ||
fcdf95cb BW |
11152 | /* VPD RO tag should be first tag after identifier string, hence |
11153 | * we should be able to find it in first BNX2X_VPD_LEN chars | |
11154 | */ | |
11155 | i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN, | |
34f24c7f VZ |
11156 | PCI_VPD_LRDT_RO_DATA); |
11157 | if (i < 0) | |
11158 | goto out_not_found; | |
11159 | ||
34f24c7f | 11160 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + |
fcdf95cb | 11161 | pci_vpd_lrdt_size(&vpd_start[i]); |
34f24c7f VZ |
11162 | |
11163 | i += PCI_VPD_LRDT_TAG_SIZE; | |
11164 | ||
fcdf95cb BW |
11165 | if (block_end > BNX2X_VPD_LEN) { |
11166 | vpd_extended_data = kmalloc(block_end, GFP_KERNEL); | |
11167 | if (vpd_extended_data == NULL) | |
11168 | goto out_not_found; | |
11169 | ||
11170 | /* read rest of vpd image into vpd_extended_data */ | |
11171 | memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN); | |
11172 | cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN, | |
11173 | block_end - BNX2X_VPD_LEN, | |
11174 | vpd_extended_data + BNX2X_VPD_LEN); | |
11175 | if (cnt < (block_end - BNX2X_VPD_LEN)) | |
11176 | goto out_not_found; | |
11177 | vpd_data = vpd_extended_data; | |
11178 | } else | |
11179 | vpd_data = vpd_start; | |
11180 | ||
11181 | /* now vpd_data holds full vpd content in both cases */ | |
34f24c7f VZ |
11182 | |
11183 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
11184 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
11185 | if (rodi < 0) | |
11186 | goto out_not_found; | |
11187 | ||
11188 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
11189 | ||
11190 | if (len != VENDOR_ID_LEN) | |
11191 | goto out_not_found; | |
11192 | ||
11193 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
11194 | ||
11195 | /* vendor specific info */ | |
11196 | snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); | |
11197 | snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); | |
11198 | if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || | |
11199 | !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { | |
11200 | ||
11201 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
11202 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
11203 | if (rodi >= 0) { | |
11204 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
11205 | ||
11206 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
11207 | ||
11208 | if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { | |
11209 | memcpy(bp->fw_ver, &vpd_data[rodi], len); | |
11210 | bp->fw_ver[len] = ' '; | |
11211 | } | |
11212 | } | |
fcdf95cb | 11213 | kfree(vpd_extended_data); |
34f24c7f VZ |
11214 | return; |
11215 | } | |
11216 | out_not_found: | |
fcdf95cb | 11217 | kfree(vpd_extended_data); |
34f24c7f VZ |
11218 | return; |
11219 | } | |
11220 | ||
0329aba1 | 11221 | static void bnx2x_set_modes_bitmap(struct bnx2x *bp) |
619c5cb6 VZ |
11222 | { |
11223 | u32 flags = 0; | |
11224 | ||
11225 | if (CHIP_REV_IS_FPGA(bp)) | |
11226 | SET_FLAGS(flags, MODE_FPGA); | |
11227 | else if (CHIP_REV_IS_EMUL(bp)) | |
11228 | SET_FLAGS(flags, MODE_EMUL); | |
11229 | else | |
11230 | SET_FLAGS(flags, MODE_ASIC); | |
11231 | ||
11232 | if (CHIP_MODE_IS_4_PORT(bp)) | |
11233 | SET_FLAGS(flags, MODE_PORT4); | |
11234 | else | |
11235 | SET_FLAGS(flags, MODE_PORT2); | |
11236 | ||
11237 | if (CHIP_IS_E2(bp)) | |
11238 | SET_FLAGS(flags, MODE_E2); | |
11239 | else if (CHIP_IS_E3(bp)) { | |
11240 | SET_FLAGS(flags, MODE_E3); | |
11241 | if (CHIP_REV(bp) == CHIP_REV_Ax) | |
11242 | SET_FLAGS(flags, MODE_E3_A0); | |
6383c0b3 AE |
11243 | else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/ |
11244 | SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3); | |
619c5cb6 VZ |
11245 | } |
11246 | ||
11247 | if (IS_MF(bp)) { | |
11248 | SET_FLAGS(flags, MODE_MF); | |
11249 | switch (bp->mf_mode) { | |
11250 | case MULTI_FUNCTION_SD: | |
11251 | SET_FLAGS(flags, MODE_MF_SD); | |
11252 | break; | |
11253 | case MULTI_FUNCTION_SI: | |
11254 | SET_FLAGS(flags, MODE_MF_SI); | |
11255 | break; | |
a3348722 BW |
11256 | case MULTI_FUNCTION_AFEX: |
11257 | SET_FLAGS(flags, MODE_MF_AFEX); | |
11258 | break; | |
619c5cb6 VZ |
11259 | } |
11260 | } else | |
11261 | SET_FLAGS(flags, MODE_SF); | |
11262 | ||
11263 | #if defined(__LITTLE_ENDIAN) | |
11264 | SET_FLAGS(flags, MODE_LITTLE_ENDIAN); | |
11265 | #else /*(__BIG_ENDIAN)*/ | |
11266 | SET_FLAGS(flags, MODE_BIG_ENDIAN); | |
11267 | #endif | |
11268 | INIT_MODE_FLAGS(bp) = flags; | |
11269 | } | |
11270 | ||
0329aba1 | 11271 | static int bnx2x_init_bp(struct bnx2x *bp) |
34f80b04 | 11272 | { |
f2e0899f | 11273 | int func; |
34f80b04 EG |
11274 | int rc; |
11275 | ||
34f80b04 | 11276 | mutex_init(&bp->port.phy_mutex); |
c4ff7cbf | 11277 | mutex_init(&bp->fw_mb_mutex); |
bb7e95c8 | 11278 | spin_lock_init(&bp->stats_lock); |
55c11941 | 11279 | |
a2fbb9ea | 11280 | |
1cf167f2 | 11281 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
7be08a72 | 11282 | INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task); |
3deb8167 | 11283 | INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task); |
1ab4434c AE |
11284 | if (IS_PF(bp)) { |
11285 | rc = bnx2x_get_hwinfo(bp); | |
11286 | if (rc) | |
11287 | return rc; | |
11288 | } else { | |
11289 | random_ether_addr(bp->dev->dev_addr); | |
11290 | } | |
34f80b04 | 11291 | |
619c5cb6 VZ |
11292 | bnx2x_set_modes_bitmap(bp); |
11293 | ||
11294 | rc = bnx2x_alloc_mem_bp(bp); | |
11295 | if (rc) | |
11296 | return rc; | |
523224a3 | 11297 | |
34f24c7f | 11298 | bnx2x_read_fwinfo(bp); |
f2e0899f DK |
11299 | |
11300 | func = BP_FUNC(bp); | |
11301 | ||
34f80b04 | 11302 | /* need to reset chip if undi was active */ |
1ab4434c | 11303 | if (IS_PF(bp) && !BP_NOMCP(bp)) { |
452427b0 YM |
11304 | /* init fw_seq */ |
11305 | bp->fw_seq = | |
11306 | SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & | |
11307 | DRV_MSG_SEQ_NUMBER_MASK; | |
11308 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); | |
11309 | ||
11310 | bnx2x_prev_unload(bp); | |
11311 | } | |
11312 | ||
34f80b04 EG |
11313 | |
11314 | if (CHIP_REV_IS_FPGA(bp)) | |
cdaa7cb8 | 11315 | dev_err(&bp->pdev->dev, "FPGA detected\n"); |
34f80b04 EG |
11316 | |
11317 | if (BP_NOMCP(bp) && (func == 0)) | |
51c1a580 | 11318 | dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n"); |
34f80b04 | 11319 | |
614c76df | 11320 | bp->disable_tpa = disable_tpa; |
a3348722 | 11321 | bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp); |
614c76df | 11322 | |
7a9b2557 | 11323 | /* Set TPA flags */ |
614c76df | 11324 | if (bp->disable_tpa) { |
621b4d66 | 11325 | bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
11326 | bp->dev->features &= ~NETIF_F_LRO; |
11327 | } else { | |
621b4d66 | 11328 | bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
11329 | bp->dev->features |= NETIF_F_LRO; |
11330 | } | |
11331 | ||
a18f5128 EG |
11332 | if (CHIP_IS_E1(bp)) |
11333 | bp->dropless_fc = 0; | |
11334 | else | |
7964211d | 11335 | bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp); |
a18f5128 | 11336 | |
8d5726c4 | 11337 | bp->mrrs = mrrs; |
7a9b2557 | 11338 | |
a3348722 | 11339 | bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL; |
1ab4434c AE |
11340 | if (IS_VF(bp)) |
11341 | bp->rx_ring_size = MAX_RX_AVAIL; | |
34f80b04 | 11342 | |
7d323bfd | 11343 | /* make sure that the numbers are in the right granularity */ |
523224a3 DK |
11344 | bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR; |
11345 | bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR; | |
34f80b04 | 11346 | |
fc543637 | 11347 | bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ; |
34f80b04 EG |
11348 | |
11349 | init_timer(&bp->timer); | |
11350 | bp->timer.expires = jiffies + bp->current_interval; | |
11351 | bp->timer.data = (unsigned long) bp; | |
11352 | bp->timer.function = bnx2x_timer; | |
11353 | ||
0370cf90 BW |
11354 | if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) && |
11355 | SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) && | |
11356 | SHMEM2_RD(bp, dcbx_lldp_params_offset) && | |
11357 | SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) { | |
11358 | bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON); | |
11359 | bnx2x_dcbx_init_params(bp); | |
11360 | } else { | |
11361 | bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF); | |
11362 | } | |
e4901dde | 11363 | |
619c5cb6 VZ |
11364 | if (CHIP_IS_E1x(bp)) |
11365 | bp->cnic_base_cl_id = FP_SB_MAX_E1x; | |
11366 | else | |
11367 | bp->cnic_base_cl_id = FP_SB_MAX_E2; | |
619c5cb6 | 11368 | |
6383c0b3 | 11369 | /* multiple tx priority */ |
1ab4434c AE |
11370 | if (IS_VF(bp)) |
11371 | bp->max_cos = 1; | |
11372 | else if (CHIP_IS_E1x(bp)) | |
6383c0b3 | 11373 | bp->max_cos = BNX2X_MULTI_TX_COS_E1X; |
1ab4434c | 11374 | else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) |
6383c0b3 | 11375 | bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0; |
1ab4434c | 11376 | else if (CHIP_IS_E3B0(bp)) |
6383c0b3 | 11377 | bp->max_cos = BNX2X_MULTI_TX_COS_E3B0; |
1ab4434c AE |
11378 | else |
11379 | BNX2X_ERR("unknown chip %x revision %x\n", | |
11380 | CHIP_NUM(bp), CHIP_REV(bp)); | |
11381 | BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos); | |
6383c0b3 | 11382 | |
55c11941 MS |
11383 | /* We need at least one default status block for slow-path events, |
11384 | * second status block for the L2 queue, and a third status block for | |
11385 | * CNIC if supproted. | |
11386 | */ | |
11387 | if (CNIC_SUPPORT(bp)) | |
11388 | bp->min_msix_vec_cnt = 3; | |
11389 | else | |
11390 | bp->min_msix_vec_cnt = 2; | |
11391 | BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt); | |
11392 | ||
34f80b04 | 11393 | return rc; |
a2fbb9ea ET |
11394 | } |
11395 | ||
a2fbb9ea | 11396 | |
de0c62db DK |
11397 | /**************************************************************************** |
11398 | * General service functions | |
11399 | ****************************************************************************/ | |
a2fbb9ea | 11400 | |
619c5cb6 VZ |
11401 | /* |
11402 | * net_device service functions | |
11403 | */ | |
11404 | ||
8395be5e AE |
11405 | static int bnx2x_open_epilog(struct bnx2x *bp) |
11406 | { | |
11407 | /* Enable sriov via delayed work. This must be done via delayed work | |
11408 | * because it causes the probe of the vf devices to be run, which invoke | |
11409 | * register_netdevice which must have rtnl lock taken. As we are holding | |
11410 | * the lock right now, that could only work if the probe would not take | |
11411 | * the lock. However, as the probe of the vf may be called from other | |
11412 | * contexts as well (such as passthrough to vm failes) it can't assume | |
11413 | * the lock is being held for it. Using delayed work here allows the | |
11414 | * probe code to simply take the lock (i.e. wait for it to be released | |
11415 | * if it is being held). | |
11416 | */ | |
11417 | smp_mb__before_clear_bit(); | |
11418 | set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state); | |
11419 | smp_mb__after_clear_bit(); | |
11420 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
11421 | ||
11422 | return 0; | |
11423 | } | |
11424 | ||
bb2a0f7a | 11425 | /* called with rtnl_lock */ |
a2fbb9ea ET |
11426 | static int bnx2x_open(struct net_device *dev) |
11427 | { | |
11428 | struct bnx2x *bp = netdev_priv(dev); | |
c9ee9206 VZ |
11429 | bool global = false; |
11430 | int other_engine = BP_PATH(bp) ? 0 : 1; | |
889b9af3 | 11431 | bool other_load_status, load_status; |
8395be5e | 11432 | int rc; |
a2fbb9ea | 11433 | |
1355b704 MY |
11434 | bp->stats_init = true; |
11435 | ||
6eccabb3 EG |
11436 | netif_carrier_off(dev); |
11437 | ||
a2fbb9ea ET |
11438 | bnx2x_set_power_state(bp, PCI_D0); |
11439 | ||
ad5afc89 | 11440 | /* If parity had happen during the unload, then attentions |
c9ee9206 VZ |
11441 | * and/or RECOVERY_IN_PROGRES may still be set. In this case we |
11442 | * want the first function loaded on the current engine to | |
11443 | * complete the recovery. | |
ad5afc89 | 11444 | * Parity recovery is only relevant for PF driver. |
c9ee9206 | 11445 | */ |
ad5afc89 AE |
11446 | if (IS_PF(bp)) { |
11447 | other_load_status = bnx2x_get_load_status(bp, other_engine); | |
11448 | load_status = bnx2x_get_load_status(bp, BP_PATH(bp)); | |
11449 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || | |
11450 | bnx2x_chk_parity_attn(bp, &global, true)) { | |
11451 | do { | |
11452 | /* If there are attentions and they are in a | |
11453 | * global blocks, set the GLOBAL_RESET bit | |
11454 | * regardless whether it will be this function | |
11455 | * that will complete the recovery or not. | |
11456 | */ | |
11457 | if (global) | |
11458 | bnx2x_set_reset_global(bp); | |
72fd0718 | 11459 | |
ad5afc89 AE |
11460 | /* Only the first function on the current |
11461 | * engine should try to recover in open. In case | |
11462 | * of attentions in global blocks only the first | |
11463 | * in the chip should try to recover. | |
11464 | */ | |
11465 | if ((!load_status && | |
11466 | (!global || !other_load_status)) && | |
11467 | bnx2x_trylock_leader_lock(bp) && | |
11468 | !bnx2x_leader_reset(bp)) { | |
11469 | netdev_info(bp->dev, | |
11470 | "Recovered in open\n"); | |
11471 | break; | |
11472 | } | |
72fd0718 | 11473 | |
ad5afc89 AE |
11474 | /* recovery has failed... */ |
11475 | bnx2x_set_power_state(bp, PCI_D3hot); | |
11476 | bp->recovery_state = BNX2X_RECOVERY_FAILED; | |
72fd0718 | 11477 | |
ad5afc89 AE |
11478 | BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n" |
11479 | "If you still see this message after a few retries then power cycle is required.\n"); | |
72fd0718 | 11480 | |
ad5afc89 AE |
11481 | return -EAGAIN; |
11482 | } while (0); | |
11483 | } | |
11484 | } | |
72fd0718 VZ |
11485 | |
11486 | bp->recovery_state = BNX2X_RECOVERY_DONE; | |
8395be5e AE |
11487 | rc = bnx2x_nic_load(bp, LOAD_OPEN); |
11488 | if (rc) | |
11489 | return rc; | |
11490 | return bnx2x_open_epilog(bp); | |
a2fbb9ea ET |
11491 | } |
11492 | ||
bb2a0f7a | 11493 | /* called with rtnl_lock */ |
56ad3152 | 11494 | static int bnx2x_close(struct net_device *dev) |
a2fbb9ea | 11495 | { |
a2fbb9ea ET |
11496 | struct bnx2x *bp = netdev_priv(dev); |
11497 | ||
11498 | /* Unload the driver, release IRQs */ | |
5d07d868 | 11499 | bnx2x_nic_unload(bp, UNLOAD_CLOSE, false); |
c9ee9206 VZ |
11500 | |
11501 | /* Power off */ | |
d3dbfee0 | 11502 | bnx2x_set_power_state(bp, PCI_D3hot); |
a2fbb9ea ET |
11503 | |
11504 | return 0; | |
11505 | } | |
11506 | ||
1191cb83 ED |
11507 | static int bnx2x_init_mcast_macs_list(struct bnx2x *bp, |
11508 | struct bnx2x_mcast_ramrod_params *p) | |
6e30dd4e | 11509 | { |
619c5cb6 VZ |
11510 | int mc_count = netdev_mc_count(bp->dev); |
11511 | struct bnx2x_mcast_list_elem *mc_mac = | |
11512 | kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); | |
11513 | struct netdev_hw_addr *ha; | |
6e30dd4e | 11514 | |
619c5cb6 VZ |
11515 | if (!mc_mac) |
11516 | return -ENOMEM; | |
6e30dd4e | 11517 | |
619c5cb6 | 11518 | INIT_LIST_HEAD(&p->mcast_list); |
6e30dd4e | 11519 | |
619c5cb6 VZ |
11520 | netdev_for_each_mc_addr(ha, bp->dev) { |
11521 | mc_mac->mac = bnx2x_mc_addr(ha); | |
11522 | list_add_tail(&mc_mac->link, &p->mcast_list); | |
11523 | mc_mac++; | |
6e30dd4e | 11524 | } |
619c5cb6 VZ |
11525 | |
11526 | p->mcast_list_len = mc_count; | |
11527 | ||
11528 | return 0; | |
6e30dd4e VZ |
11529 | } |
11530 | ||
1191cb83 | 11531 | static void bnx2x_free_mcast_macs_list( |
619c5cb6 VZ |
11532 | struct bnx2x_mcast_ramrod_params *p) |
11533 | { | |
11534 | struct bnx2x_mcast_list_elem *mc_mac = | |
11535 | list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem, | |
11536 | link); | |
11537 | ||
11538 | WARN_ON(!mc_mac); | |
11539 | kfree(mc_mac); | |
11540 | } | |
11541 | ||
11542 | /** | |
11543 | * bnx2x_set_uc_list - configure a new unicast MACs list. | |
11544 | * | |
11545 | * @bp: driver handle | |
6e30dd4e | 11546 | * |
619c5cb6 | 11547 | * We will use zero (0) as a MAC type for these MACs. |
6e30dd4e | 11548 | */ |
1191cb83 | 11549 | static int bnx2x_set_uc_list(struct bnx2x *bp) |
6e30dd4e | 11550 | { |
619c5cb6 | 11551 | int rc; |
6e30dd4e | 11552 | struct net_device *dev = bp->dev; |
6e30dd4e | 11553 | struct netdev_hw_addr *ha; |
15192a8c | 11554 | struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj; |
619c5cb6 | 11555 | unsigned long ramrod_flags = 0; |
6e30dd4e | 11556 | |
619c5cb6 VZ |
11557 | /* First schedule a cleanup up of old configuration */ |
11558 | rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false); | |
11559 | if (rc < 0) { | |
11560 | BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc); | |
11561 | return rc; | |
11562 | } | |
6e30dd4e VZ |
11563 | |
11564 | netdev_for_each_uc_addr(ha, dev) { | |
619c5cb6 VZ |
11565 | rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, |
11566 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
7b5342d9 YM |
11567 | if (rc == -EEXIST) { |
11568 | DP(BNX2X_MSG_SP, | |
11569 | "Failed to schedule ADD operations: %d\n", rc); | |
11570 | /* do not treat adding same MAC as error */ | |
11571 | rc = 0; | |
11572 | ||
11573 | } else if (rc < 0) { | |
11574 | ||
619c5cb6 VZ |
11575 | BNX2X_ERR("Failed to schedule ADD operations: %d\n", |
11576 | rc); | |
11577 | return rc; | |
6e30dd4e VZ |
11578 | } |
11579 | } | |
11580 | ||
619c5cb6 VZ |
11581 | /* Execute the pending commands */ |
11582 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
11583 | return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */, | |
11584 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
6e30dd4e VZ |
11585 | } |
11586 | ||
1191cb83 | 11587 | static int bnx2x_set_mc_list(struct bnx2x *bp) |
6e30dd4e | 11588 | { |
619c5cb6 | 11589 | struct net_device *dev = bp->dev; |
3b603066 | 11590 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 | 11591 | int rc = 0; |
6e30dd4e | 11592 | |
619c5cb6 | 11593 | rparam.mcast_obj = &bp->mcast_obj; |
6e30dd4e | 11594 | |
619c5cb6 VZ |
11595 | /* first, clear all configured multicast MACs */ |
11596 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
11597 | if (rc < 0) { | |
51c1a580 | 11598 | BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc); |
619c5cb6 VZ |
11599 | return rc; |
11600 | } | |
6e30dd4e | 11601 | |
619c5cb6 VZ |
11602 | /* then, configure a new MACs list */ |
11603 | if (netdev_mc_count(dev)) { | |
11604 | rc = bnx2x_init_mcast_macs_list(bp, &rparam); | |
11605 | if (rc) { | |
51c1a580 MS |
11606 | BNX2X_ERR("Failed to create multicast MACs list: %d\n", |
11607 | rc); | |
619c5cb6 VZ |
11608 | return rc; |
11609 | } | |
6e30dd4e | 11610 | |
619c5cb6 VZ |
11611 | /* Now add the new MACs */ |
11612 | rc = bnx2x_config_mcast(bp, &rparam, | |
11613 | BNX2X_MCAST_CMD_ADD); | |
11614 | if (rc < 0) | |
51c1a580 MS |
11615 | BNX2X_ERR("Failed to set a new multicast configuration: %d\n", |
11616 | rc); | |
6e30dd4e | 11617 | |
619c5cb6 VZ |
11618 | bnx2x_free_mcast_macs_list(&rparam); |
11619 | } | |
6e30dd4e | 11620 | |
619c5cb6 | 11621 | return rc; |
6e30dd4e VZ |
11622 | } |
11623 | ||
619c5cb6 | 11624 | /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */ |
9f6c9258 | 11625 | void bnx2x_set_rx_mode(struct net_device *dev) |
34f80b04 EG |
11626 | { |
11627 | struct bnx2x *bp = netdev_priv(dev); | |
11628 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; | |
34f80b04 EG |
11629 | |
11630 | if (bp->state != BNX2X_STATE_OPEN) { | |
11631 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); | |
11632 | return; | |
11633 | } | |
11634 | ||
619c5cb6 | 11635 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags); |
34f80b04 EG |
11636 | |
11637 | if (dev->flags & IFF_PROMISC) | |
11638 | rx_mode = BNX2X_RX_MODE_PROMISC; | |
619c5cb6 VZ |
11639 | else if ((dev->flags & IFF_ALLMULTI) || |
11640 | ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) && | |
11641 | CHIP_IS_E1(bp))) | |
34f80b04 | 11642 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
6e30dd4e | 11643 | else { |
381ac16b AE |
11644 | if (IS_PF(bp)) { |
11645 | /* some multicasts */ | |
11646 | if (bnx2x_set_mc_list(bp) < 0) | |
11647 | rx_mode = BNX2X_RX_MODE_ALLMULTI; | |
34f80b04 | 11648 | |
381ac16b AE |
11649 | if (bnx2x_set_uc_list(bp) < 0) |
11650 | rx_mode = BNX2X_RX_MODE_PROMISC; | |
11651 | } else { | |
11652 | /* configuring mcast to a vf involves sleeping (when we | |
11653 | * wait for the pf's response). Since this function is | |
11654 | * called from non sleepable context we must schedule | |
11655 | * a work item for this purpose | |
11656 | */ | |
11657 | smp_mb__before_clear_bit(); | |
11658 | set_bit(BNX2X_SP_RTNL_VFPF_MCAST, | |
11659 | &bp->sp_rtnl_state); | |
11660 | smp_mb__after_clear_bit(); | |
11661 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
11662 | } | |
34f80b04 EG |
11663 | } |
11664 | ||
11665 | bp->rx_mode = rx_mode; | |
614c76df DK |
11666 | /* handle ISCSI SD mode */ |
11667 | if (IS_MF_ISCSI_SD(bp)) | |
11668 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
619c5cb6 VZ |
11669 | |
11670 | /* Schedule the rx_mode command */ | |
11671 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) { | |
11672 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
11673 | return; | |
11674 | } | |
11675 | ||
381ac16b AE |
11676 | if (IS_PF(bp)) { |
11677 | bnx2x_set_storm_rx_mode(bp); | |
11678 | } else { | |
11679 | /* configuring rx mode to storms in a vf involves sleeping (when | |
11680 | * we wait for the pf's response). Since this function is | |
11681 | * called from non sleepable context we must schedule | |
11682 | * a work item for this purpose | |
11683 | */ | |
11684 | smp_mb__before_clear_bit(); | |
11685 | set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE, | |
11686 | &bp->sp_rtnl_state); | |
11687 | smp_mb__after_clear_bit(); | |
11688 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
11689 | } | |
34f80b04 EG |
11690 | } |
11691 | ||
c18487ee | 11692 | /* called with rtnl_lock */ |
01cd4528 EG |
11693 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
11694 | int devad, u16 addr) | |
a2fbb9ea | 11695 | { |
01cd4528 EG |
11696 | struct bnx2x *bp = netdev_priv(netdev); |
11697 | u16 value; | |
11698 | int rc; | |
a2fbb9ea | 11699 | |
01cd4528 EG |
11700 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
11701 | prtad, devad, addr); | |
a2fbb9ea | 11702 | |
01cd4528 EG |
11703 | /* The HW expects different devad if CL22 is used */ |
11704 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
c18487ee | 11705 | |
01cd4528 | 11706 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 11707 | rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value); |
01cd4528 EG |
11708 | bnx2x_release_phy_lock(bp); |
11709 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); | |
a2fbb9ea | 11710 | |
01cd4528 EG |
11711 | if (!rc) |
11712 | rc = value; | |
11713 | return rc; | |
11714 | } | |
a2fbb9ea | 11715 | |
01cd4528 EG |
11716 | /* called with rtnl_lock */ |
11717 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, | |
11718 | u16 addr, u16 value) | |
11719 | { | |
11720 | struct bnx2x *bp = netdev_priv(netdev); | |
01cd4528 EG |
11721 | int rc; |
11722 | ||
51c1a580 MS |
11723 | DP(NETIF_MSG_LINK, |
11724 | "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n", | |
11725 | prtad, devad, addr, value); | |
01cd4528 | 11726 | |
01cd4528 EG |
11727 | /* The HW expects different devad if CL22 is used */ |
11728 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
a2fbb9ea | 11729 | |
01cd4528 | 11730 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 11731 | rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value); |
01cd4528 EG |
11732 | bnx2x_release_phy_lock(bp); |
11733 | return rc; | |
11734 | } | |
c18487ee | 11735 | |
01cd4528 EG |
11736 | /* called with rtnl_lock */ |
11737 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |
11738 | { | |
11739 | struct bnx2x *bp = netdev_priv(dev); | |
11740 | struct mii_ioctl_data *mdio = if_mii(ifr); | |
a2fbb9ea | 11741 | |
01cd4528 EG |
11742 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
11743 | mdio->phy_id, mdio->reg_num, mdio->val_in); | |
a2fbb9ea | 11744 | |
01cd4528 EG |
11745 | if (!netif_running(dev)) |
11746 | return -EAGAIN; | |
11747 | ||
11748 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); | |
a2fbb9ea ET |
11749 | } |
11750 | ||
257ddbda | 11751 | #ifdef CONFIG_NET_POLL_CONTROLLER |
a2fbb9ea ET |
11752 | static void poll_bnx2x(struct net_device *dev) |
11753 | { | |
11754 | struct bnx2x *bp = netdev_priv(dev); | |
14a15d61 | 11755 | int i; |
a2fbb9ea | 11756 | |
14a15d61 MS |
11757 | for_each_eth_queue(bp, i) { |
11758 | struct bnx2x_fastpath *fp = &bp->fp[i]; | |
11759 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); | |
11760 | } | |
a2fbb9ea ET |
11761 | } |
11762 | #endif | |
11763 | ||
614c76df DK |
11764 | static int bnx2x_validate_addr(struct net_device *dev) |
11765 | { | |
11766 | struct bnx2x *bp = netdev_priv(dev); | |
11767 | ||
51c1a580 MS |
11768 | if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) { |
11769 | BNX2X_ERR("Non-valid Ethernet address\n"); | |
614c76df | 11770 | return -EADDRNOTAVAIL; |
51c1a580 | 11771 | } |
614c76df DK |
11772 | return 0; |
11773 | } | |
11774 | ||
c64213cd SH |
11775 | static const struct net_device_ops bnx2x_netdev_ops = { |
11776 | .ndo_open = bnx2x_open, | |
11777 | .ndo_stop = bnx2x_close, | |
11778 | .ndo_start_xmit = bnx2x_start_xmit, | |
8307fa3e | 11779 | .ndo_select_queue = bnx2x_select_queue, |
6e30dd4e | 11780 | .ndo_set_rx_mode = bnx2x_set_rx_mode, |
c64213cd | 11781 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
614c76df | 11782 | .ndo_validate_addr = bnx2x_validate_addr, |
c64213cd SH |
11783 | .ndo_do_ioctl = bnx2x_ioctl, |
11784 | .ndo_change_mtu = bnx2x_change_mtu, | |
66371c44 MM |
11785 | .ndo_fix_features = bnx2x_fix_features, |
11786 | .ndo_set_features = bnx2x_set_features, | |
c64213cd | 11787 | .ndo_tx_timeout = bnx2x_tx_timeout, |
257ddbda | 11788 | #ifdef CONFIG_NET_POLL_CONTROLLER |
c64213cd SH |
11789 | .ndo_poll_controller = poll_bnx2x, |
11790 | #endif | |
6383c0b3 | 11791 | .ndo_setup_tc = bnx2x_setup_tc, |
6411280a | 11792 | #ifdef CONFIG_BNX2X_SRIOV |
abc5a021 | 11793 | .ndo_set_vf_mac = bnx2x_set_vf_mac, |
6411280a | 11794 | #endif |
55c11941 | 11795 | #ifdef NETDEV_FCOE_WWNN |
bf61ee14 VZ |
11796 | .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn, |
11797 | #endif | |
c64213cd SH |
11798 | }; |
11799 | ||
1191cb83 | 11800 | static int bnx2x_set_coherency_mask(struct bnx2x *bp) |
619c5cb6 VZ |
11801 | { |
11802 | struct device *dev = &bp->pdev->dev; | |
11803 | ||
11804 | if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { | |
11805 | bp->flags |= USING_DAC_FLAG; | |
11806 | if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { | |
51c1a580 | 11807 | dev_err(dev, "dma_set_coherent_mask failed, aborting\n"); |
619c5cb6 VZ |
11808 | return -EIO; |
11809 | } | |
11810 | } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) { | |
11811 | dev_err(dev, "System does not support DMA, aborting\n"); | |
11812 | return -EIO; | |
11813 | } | |
11814 | ||
11815 | return 0; | |
11816 | } | |
11817 | ||
1ab4434c AE |
11818 | static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev, |
11819 | struct net_device *dev, unsigned long board_type) | |
a2fbb9ea | 11820 | { |
a2fbb9ea | 11821 | int rc; |
c22610d0 | 11822 | u32 pci_cfg_dword; |
65087cfe AE |
11823 | bool chip_is_e1x = (board_type == BCM57710 || |
11824 | board_type == BCM57711 || | |
11825 | board_type == BCM57711E); | |
a2fbb9ea ET |
11826 | |
11827 | SET_NETDEV_DEV(dev, &pdev->dev); | |
a2fbb9ea | 11828 | |
34f80b04 EG |
11829 | bp->dev = dev; |
11830 | bp->pdev = pdev; | |
a2fbb9ea ET |
11831 | |
11832 | rc = pci_enable_device(pdev); | |
11833 | if (rc) { | |
cdaa7cb8 VZ |
11834 | dev_err(&bp->pdev->dev, |
11835 | "Cannot enable PCI device, aborting\n"); | |
a2fbb9ea ET |
11836 | goto err_out; |
11837 | } | |
11838 | ||
11839 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | |
cdaa7cb8 VZ |
11840 | dev_err(&bp->pdev->dev, |
11841 | "Cannot find PCI device base address, aborting\n"); | |
a2fbb9ea ET |
11842 | rc = -ENODEV; |
11843 | goto err_out_disable; | |
11844 | } | |
11845 | ||
1ab4434c AE |
11846 | if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
11847 | dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n"); | |
a2fbb9ea ET |
11848 | rc = -ENODEV; |
11849 | goto err_out_disable; | |
11850 | } | |
11851 | ||
092a5fc9 YR |
11852 | pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword); |
11853 | if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) == | |
11854 | PCICFG_REVESION_ID_ERROR_VAL) { | |
11855 | pr_err("PCI device error, probably due to fan failure, aborting\n"); | |
11856 | rc = -ENODEV; | |
11857 | goto err_out_disable; | |
11858 | } | |
11859 | ||
34f80b04 EG |
11860 | if (atomic_read(&pdev->enable_cnt) == 1) { |
11861 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); | |
11862 | if (rc) { | |
cdaa7cb8 VZ |
11863 | dev_err(&bp->pdev->dev, |
11864 | "Cannot obtain PCI resources, aborting\n"); | |
34f80b04 EG |
11865 | goto err_out_disable; |
11866 | } | |
a2fbb9ea | 11867 | |
34f80b04 EG |
11868 | pci_set_master(pdev); |
11869 | pci_save_state(pdev); | |
11870 | } | |
a2fbb9ea | 11871 | |
1ab4434c AE |
11872 | if (IS_PF(bp)) { |
11873 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
11874 | if (bp->pm_cap == 0) { | |
11875 | dev_err(&bp->pdev->dev, | |
11876 | "Cannot find power management capability, aborting\n"); | |
11877 | rc = -EIO; | |
11878 | goto err_out_release; | |
11879 | } | |
a2fbb9ea ET |
11880 | } |
11881 | ||
77c98e6a | 11882 | if (!pci_is_pcie(pdev)) { |
51c1a580 | 11883 | dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n"); |
a2fbb9ea ET |
11884 | rc = -EIO; |
11885 | goto err_out_release; | |
11886 | } | |
11887 | ||
619c5cb6 VZ |
11888 | rc = bnx2x_set_coherency_mask(bp); |
11889 | if (rc) | |
a2fbb9ea | 11890 | goto err_out_release; |
a2fbb9ea | 11891 | |
34f80b04 EG |
11892 | dev->mem_start = pci_resource_start(pdev, 0); |
11893 | dev->base_addr = dev->mem_start; | |
11894 | dev->mem_end = pci_resource_end(pdev, 0); | |
a2fbb9ea ET |
11895 | |
11896 | dev->irq = pdev->irq; | |
11897 | ||
275f165f | 11898 | bp->regview = pci_ioremap_bar(pdev, 0); |
a2fbb9ea | 11899 | if (!bp->regview) { |
cdaa7cb8 VZ |
11900 | dev_err(&bp->pdev->dev, |
11901 | "Cannot map register space, aborting\n"); | |
a2fbb9ea ET |
11902 | rc = -ENOMEM; |
11903 | goto err_out_release; | |
11904 | } | |
11905 | ||
c22610d0 AE |
11906 | /* In E1/E1H use pci device function given by kernel. |
11907 | * In E2/E3 read physical function from ME register since these chips | |
11908 | * support Physical Device Assignment where kernel BDF maybe arbitrary | |
11909 | * (depending on hypervisor). | |
11910 | */ | |
2de67439 | 11911 | if (chip_is_e1x) { |
c22610d0 | 11912 | bp->pf_num = PCI_FUNC(pdev->devfn); |
2de67439 YM |
11913 | } else { |
11914 | /* chip is E2/3*/ | |
c22610d0 AE |
11915 | pci_read_config_dword(bp->pdev, |
11916 | PCICFG_ME_REGISTER, &pci_cfg_dword); | |
11917 | bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >> | |
2de67439 | 11918 | ME_REG_ABS_PF_NUM_SHIFT); |
c22610d0 | 11919 | } |
51c1a580 | 11920 | BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num); |
c22610d0 | 11921 | |
a2fbb9ea ET |
11922 | bnx2x_set_power_state(bp, PCI_D0); |
11923 | ||
34f80b04 EG |
11924 | /* clean indirect addresses */ |
11925 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
11926 | PCICFG_VENDOR_ID_OFFSET); | |
a5c53dbc DK |
11927 | /* |
11928 | * Clean the following indirect addresses for all functions since it | |
9f0096a1 DK |
11929 | * is not used by the driver. |
11930 | */ | |
1ab4434c AE |
11931 | if (IS_PF(bp)) { |
11932 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0); | |
11933 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0); | |
11934 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0); | |
11935 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0); | |
11936 | ||
11937 | if (chip_is_e1x) { | |
11938 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0); | |
11939 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0); | |
11940 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0); | |
11941 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0); | |
11942 | } | |
a5c53dbc | 11943 | |
1ab4434c AE |
11944 | /* Enable internal target-read (in case we are probed after PF |
11945 | * FLR). Must be done prior to any BAR read access. Only for | |
11946 | * 57712 and up | |
11947 | */ | |
11948 | if (!chip_is_e1x) | |
11949 | REG_WR(bp, | |
11950 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); | |
a5c53dbc | 11951 | } |
a2fbb9ea | 11952 | |
34f80b04 | 11953 | dev->watchdog_timeo = TX_TIMEOUT; |
a2fbb9ea | 11954 | |
c64213cd | 11955 | dev->netdev_ops = &bnx2x_netdev_ops; |
de0c62db | 11956 | bnx2x_set_ethtool_ops(dev); |
5316bc0b | 11957 | |
01789349 JP |
11958 | dev->priv_flags |= IFF_UNICAST_FLT; |
11959 | ||
66371c44 | 11960 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
621b4d66 DK |
11961 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | |
11962 | NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO | | |
11963 | NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX; | |
66371c44 MM |
11964 | |
11965 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
11966 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; | |
11967 | ||
11968 | dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX; | |
5316bc0b | 11969 | if (bp->flags & USING_DAC_FLAG) |
66371c44 | 11970 | dev->features |= NETIF_F_HIGHDMA; |
a2fbb9ea | 11971 | |
538dd2e3 MB |
11972 | /* Add Loopback capability to the device */ |
11973 | dev->hw_features |= NETIF_F_LOOPBACK; | |
11974 | ||
98507672 | 11975 | #ifdef BCM_DCBNL |
785b9b1a SR |
11976 | dev->dcbnl_ops = &bnx2x_dcbnl_ops; |
11977 | #endif | |
11978 | ||
01cd4528 EG |
11979 | /* get_port_hwinfo() will set prtad and mmds properly */ |
11980 | bp->mdio.prtad = MDIO_PRTAD_NONE; | |
11981 | bp->mdio.mmds = 0; | |
11982 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; | |
11983 | bp->mdio.dev = dev; | |
11984 | bp->mdio.mdio_read = bnx2x_mdio_read; | |
11985 | bp->mdio.mdio_write = bnx2x_mdio_write; | |
11986 | ||
a2fbb9ea ET |
11987 | return 0; |
11988 | ||
a2fbb9ea | 11989 | err_out_release: |
34f80b04 EG |
11990 | if (atomic_read(&pdev->enable_cnt) == 1) |
11991 | pci_release_regions(pdev); | |
a2fbb9ea ET |
11992 | |
11993 | err_out_disable: | |
11994 | pci_disable_device(pdev); | |
11995 | pci_set_drvdata(pdev, NULL); | |
11996 | ||
11997 | err_out: | |
11998 | return rc; | |
11999 | } | |
12000 | ||
1dd06ae8 | 12001 | static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed) |
25047950 | 12002 | { |
1ab4434c | 12003 | u32 val = 0; |
25047950 | 12004 | |
1ab4434c | 12005 | pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val); |
37f9ce62 | 12006 | *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
25047950 | 12007 | |
37f9ce62 EG |
12008 | /* return value of 1=2.5GHz 2=5GHz */ |
12009 | *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; | |
25047950 | 12010 | } |
37f9ce62 | 12011 | |
6891dd25 | 12012 | static int bnx2x_check_firmware(struct bnx2x *bp) |
94a78b79 | 12013 | { |
37f9ce62 | 12014 | const struct firmware *firmware = bp->firmware; |
94a78b79 VZ |
12015 | struct bnx2x_fw_file_hdr *fw_hdr; |
12016 | struct bnx2x_fw_file_section *sections; | |
94a78b79 | 12017 | u32 offset, len, num_ops; |
86564c3f | 12018 | __be16 *ops_offsets; |
94a78b79 | 12019 | int i; |
37f9ce62 | 12020 | const u8 *fw_ver; |
94a78b79 | 12021 | |
51c1a580 MS |
12022 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) { |
12023 | BNX2X_ERR("Wrong FW size\n"); | |
94a78b79 | 12024 | return -EINVAL; |
51c1a580 | 12025 | } |
94a78b79 VZ |
12026 | |
12027 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; | |
12028 | sections = (struct bnx2x_fw_file_section *)fw_hdr; | |
12029 | ||
12030 | /* Make sure none of the offsets and sizes make us read beyond | |
12031 | * the end of the firmware data */ | |
12032 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { | |
12033 | offset = be32_to_cpu(sections[i].offset); | |
12034 | len = be32_to_cpu(sections[i].len); | |
12035 | if (offset + len > firmware->size) { | |
51c1a580 | 12036 | BNX2X_ERR("Section %d length is out of bounds\n", i); |
94a78b79 VZ |
12037 | return -EINVAL; |
12038 | } | |
12039 | } | |
12040 | ||
12041 | /* Likewise for the init_ops offsets */ | |
12042 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); | |
86564c3f | 12043 | ops_offsets = (__force __be16 *)(firmware->data + offset); |
94a78b79 VZ |
12044 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); |
12045 | ||
12046 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { | |
12047 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { | |
51c1a580 | 12048 | BNX2X_ERR("Section offset %d is out of bounds\n", i); |
94a78b79 VZ |
12049 | return -EINVAL; |
12050 | } | |
12051 | } | |
12052 | ||
12053 | /* Check FW version */ | |
12054 | offset = be32_to_cpu(fw_hdr->fw_version.offset); | |
12055 | fw_ver = firmware->data + offset; | |
12056 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || | |
12057 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || | |
12058 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || | |
12059 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { | |
51c1a580 MS |
12060 | BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n", |
12061 | fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3], | |
12062 | BCM_5710_FW_MAJOR_VERSION, | |
94a78b79 VZ |
12063 | BCM_5710_FW_MINOR_VERSION, |
12064 | BCM_5710_FW_REVISION_VERSION, | |
12065 | BCM_5710_FW_ENGINEERING_VERSION); | |
ab6ad5a4 | 12066 | return -EINVAL; |
94a78b79 VZ |
12067 | } |
12068 | ||
12069 | return 0; | |
12070 | } | |
12071 | ||
1191cb83 | 12072 | static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12073 | { |
ab6ad5a4 EG |
12074 | const __be32 *source = (const __be32 *)_source; |
12075 | u32 *target = (u32 *)_target; | |
94a78b79 | 12076 | u32 i; |
94a78b79 VZ |
12077 | |
12078 | for (i = 0; i < n/4; i++) | |
12079 | target[i] = be32_to_cpu(source[i]); | |
12080 | } | |
12081 | ||
12082 | /* | |
12083 | Ops array is stored in the following format: | |
12084 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} | |
12085 | */ | |
1191cb83 | 12086 | static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12087 | { |
ab6ad5a4 EG |
12088 | const __be32 *source = (const __be32 *)_source; |
12089 | struct raw_op *target = (struct raw_op *)_target; | |
94a78b79 | 12090 | u32 i, j, tmp; |
94a78b79 | 12091 | |
ab6ad5a4 | 12092 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
94a78b79 VZ |
12093 | tmp = be32_to_cpu(source[j]); |
12094 | target[i].op = (tmp >> 24) & 0xff; | |
cdaa7cb8 VZ |
12095 | target[i].offset = tmp & 0xffffff; |
12096 | target[i].raw_data = be32_to_cpu(source[j + 1]); | |
94a78b79 VZ |
12097 | } |
12098 | } | |
ab6ad5a4 | 12099 | |
1aa8b471 | 12100 | /* IRO array is stored in the following format: |
523224a3 DK |
12101 | * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) } |
12102 | */ | |
1191cb83 | 12103 | static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n) |
523224a3 DK |
12104 | { |
12105 | const __be32 *source = (const __be32 *)_source; | |
12106 | struct iro *target = (struct iro *)_target; | |
12107 | u32 i, j, tmp; | |
12108 | ||
12109 | for (i = 0, j = 0; i < n/sizeof(struct iro); i++) { | |
12110 | target[i].base = be32_to_cpu(source[j]); | |
12111 | j++; | |
12112 | tmp = be32_to_cpu(source[j]); | |
12113 | target[i].m1 = (tmp >> 16) & 0xffff; | |
12114 | target[i].m2 = tmp & 0xffff; | |
12115 | j++; | |
12116 | tmp = be32_to_cpu(source[j]); | |
12117 | target[i].m3 = (tmp >> 16) & 0xffff; | |
12118 | target[i].size = tmp & 0xffff; | |
12119 | j++; | |
12120 | } | |
12121 | } | |
12122 | ||
1191cb83 | 12123 | static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12124 | { |
ab6ad5a4 EG |
12125 | const __be16 *source = (const __be16 *)_source; |
12126 | u16 *target = (u16 *)_target; | |
94a78b79 | 12127 | u32 i; |
94a78b79 VZ |
12128 | |
12129 | for (i = 0; i < n/2; i++) | |
12130 | target[i] = be16_to_cpu(source[i]); | |
12131 | } | |
12132 | ||
7995c64e JP |
12133 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
12134 | do { \ | |
12135 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ | |
12136 | bp->arr = kmalloc(len, GFP_KERNEL); \ | |
e404decb | 12137 | if (!bp->arr) \ |
7995c64e | 12138 | goto lbl; \ |
7995c64e JP |
12139 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
12140 | (u8 *)bp->arr, len); \ | |
12141 | } while (0) | |
94a78b79 | 12142 | |
3b603066 | 12143 | static int bnx2x_init_firmware(struct bnx2x *bp) |
94a78b79 | 12144 | { |
c0ea452e | 12145 | const char *fw_file_name; |
94a78b79 | 12146 | struct bnx2x_fw_file_hdr *fw_hdr; |
45229b42 | 12147 | int rc; |
94a78b79 | 12148 | |
c0ea452e MS |
12149 | if (bp->firmware) |
12150 | return 0; | |
94a78b79 | 12151 | |
c0ea452e MS |
12152 | if (CHIP_IS_E1(bp)) |
12153 | fw_file_name = FW_FILE_NAME_E1; | |
12154 | else if (CHIP_IS_E1H(bp)) | |
12155 | fw_file_name = FW_FILE_NAME_E1H; | |
12156 | else if (!CHIP_IS_E1x(bp)) | |
12157 | fw_file_name = FW_FILE_NAME_E2; | |
12158 | else { | |
12159 | BNX2X_ERR("Unsupported chip revision\n"); | |
12160 | return -EINVAL; | |
12161 | } | |
12162 | BNX2X_DEV_INFO("Loading %s\n", fw_file_name); | |
94a78b79 | 12163 | |
c0ea452e MS |
12164 | rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); |
12165 | if (rc) { | |
12166 | BNX2X_ERR("Can't load firmware file %s\n", | |
12167 | fw_file_name); | |
12168 | goto request_firmware_exit; | |
12169 | } | |
eb2afd4a | 12170 | |
c0ea452e MS |
12171 | rc = bnx2x_check_firmware(bp); |
12172 | if (rc) { | |
12173 | BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); | |
12174 | goto request_firmware_exit; | |
94a78b79 VZ |
12175 | } |
12176 | ||
12177 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; | |
12178 | ||
12179 | /* Initialize the pointers to the init arrays */ | |
12180 | /* Blob */ | |
12181 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); | |
12182 | ||
12183 | /* Opcodes */ | |
12184 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); | |
12185 | ||
12186 | /* Offsets */ | |
ab6ad5a4 EG |
12187 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
12188 | be16_to_cpu_n); | |
94a78b79 VZ |
12189 | |
12190 | /* STORMs firmware */ | |
573f2035 EG |
12191 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
12192 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); | |
12193 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12194 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); | |
12195 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12196 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); | |
12197 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + | |
12198 | be32_to_cpu(fw_hdr->usem_pram_data.offset); | |
12199 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12200 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); | |
12201 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12202 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); | |
12203 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12204 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); | |
12205 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12206 | be32_to_cpu(fw_hdr->csem_pram_data.offset); | |
523224a3 DK |
12207 | /* IRO */ |
12208 | BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro); | |
94a78b79 VZ |
12209 | |
12210 | return 0; | |
ab6ad5a4 | 12211 | |
523224a3 DK |
12212 | iro_alloc_err: |
12213 | kfree(bp->init_ops_offsets); | |
94a78b79 VZ |
12214 | init_offsets_alloc_err: |
12215 | kfree(bp->init_ops); | |
12216 | init_ops_alloc_err: | |
12217 | kfree(bp->init_data); | |
12218 | request_firmware_exit: | |
12219 | release_firmware(bp->firmware); | |
127d0a19 | 12220 | bp->firmware = NULL; |
94a78b79 VZ |
12221 | |
12222 | return rc; | |
12223 | } | |
12224 | ||
619c5cb6 VZ |
12225 | static void bnx2x_release_firmware(struct bnx2x *bp) |
12226 | { | |
12227 | kfree(bp->init_ops_offsets); | |
12228 | kfree(bp->init_ops); | |
12229 | kfree(bp->init_data); | |
12230 | release_firmware(bp->firmware); | |
eb2afd4a | 12231 | bp->firmware = NULL; |
619c5cb6 VZ |
12232 | } |
12233 | ||
12234 | ||
12235 | static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = { | |
12236 | .init_hw_cmn_chip = bnx2x_init_hw_common_chip, | |
12237 | .init_hw_cmn = bnx2x_init_hw_common, | |
12238 | .init_hw_port = bnx2x_init_hw_port, | |
12239 | .init_hw_func = bnx2x_init_hw_func, | |
12240 | ||
12241 | .reset_hw_cmn = bnx2x_reset_common, | |
12242 | .reset_hw_port = bnx2x_reset_port, | |
12243 | .reset_hw_func = bnx2x_reset_func, | |
12244 | ||
12245 | .gunzip_init = bnx2x_gunzip_init, | |
12246 | .gunzip_end = bnx2x_gunzip_end, | |
12247 | ||
12248 | .init_fw = bnx2x_init_firmware, | |
12249 | .release_fw = bnx2x_release_firmware, | |
12250 | }; | |
12251 | ||
12252 | void bnx2x__init_func_obj(struct bnx2x *bp) | |
12253 | { | |
12254 | /* Prepare DMAE related driver resources */ | |
12255 | bnx2x_setup_dmae(bp); | |
12256 | ||
12257 | bnx2x_init_func_obj(bp, &bp->func_obj, | |
12258 | bnx2x_sp(bp, func_rdata), | |
12259 | bnx2x_sp_mapping(bp, func_rdata), | |
a3348722 BW |
12260 | bnx2x_sp(bp, func_afex_rdata), |
12261 | bnx2x_sp_mapping(bp, func_afex_rdata), | |
619c5cb6 VZ |
12262 | &bnx2x_func_sp_drv); |
12263 | } | |
12264 | ||
12265 | /* must be called after sriov-enable */ | |
1191cb83 | 12266 | static int bnx2x_set_qm_cid_count(struct bnx2x *bp) |
523224a3 | 12267 | { |
37ae41a9 | 12268 | int cid_count = BNX2X_L2_MAX_CID(bp); |
94a78b79 | 12269 | |
290ca2bb AE |
12270 | if (IS_SRIOV(bp)) |
12271 | cid_count += BNX2X_VF_CIDS; | |
12272 | ||
55c11941 MS |
12273 | if (CNIC_SUPPORT(bp)) |
12274 | cid_count += CNIC_CID_MAX; | |
290ca2bb | 12275 | |
523224a3 DK |
12276 | return roundup(cid_count, QM_CID_ROUND); |
12277 | } | |
f85582f8 | 12278 | |
619c5cb6 | 12279 | /** |
6383c0b3 | 12280 | * bnx2x_get_num_none_def_sbs - return the number of none default SBs |
619c5cb6 VZ |
12281 | * |
12282 | * @dev: pci device | |
12283 | * | |
12284 | */ | |
55c11941 | 12285 | static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, |
1ab4434c | 12286 | int cnic_cnt, bool is_vf) |
619c5cb6 | 12287 | { |
1ab4434c AE |
12288 | int pos, index; |
12289 | u16 control = 0; | |
619c5cb6 VZ |
12290 | |
12291 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); | |
6383c0b3 AE |
12292 | |
12293 | /* | |
12294 | * If MSI-X is not supported - return number of SBs needed to support | |
12295 | * one fast path queue: one FP queue + SB for CNIC | |
12296 | */ | |
1ab4434c AE |
12297 | if (!pos) { |
12298 | dev_info(&pdev->dev, "no msix capability found\n"); | |
55c11941 | 12299 | return 1 + cnic_cnt; |
1ab4434c AE |
12300 | } |
12301 | dev_info(&pdev->dev, "msix capability found\n"); | |
619c5cb6 | 12302 | |
6383c0b3 AE |
12303 | /* |
12304 | * The value in the PCI configuration space is the index of the last | |
12305 | * entry, namely one less than the actual size of the table, which is | |
12306 | * exactly what we want to return from this function: number of all SBs | |
12307 | * without the default SB. | |
1ab4434c | 12308 | * For VFs there is no default SB, then we return (index+1). |
6383c0b3 | 12309 | */ |
619c5cb6 | 12310 | pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control); |
619c5cb6 | 12311 | |
1ab4434c | 12312 | index = control & PCI_MSIX_FLAGS_QSIZE; |
4bd9b0ff | 12313 | |
1ab4434c AE |
12314 | return is_vf ? index + 1 : index; |
12315 | } | |
523224a3 | 12316 | |
1ab4434c AE |
12317 | static int set_max_cos_est(int chip_id) |
12318 | { | |
12319 | switch (chip_id) { | |
f2e0899f DK |
12320 | case BCM57710: |
12321 | case BCM57711: | |
12322 | case BCM57711E: | |
1ab4434c | 12323 | return BNX2X_MULTI_TX_COS_E1X; |
f2e0899f | 12324 | case BCM57712: |
619c5cb6 | 12325 | case BCM57712_MF: |
1ab4434c AE |
12326 | case BCM57712_VF: |
12327 | return BNX2X_MULTI_TX_COS_E2_E3A0; | |
619c5cb6 VZ |
12328 | case BCM57800: |
12329 | case BCM57800_MF: | |
1ab4434c | 12330 | case BCM57800_VF: |
619c5cb6 VZ |
12331 | case BCM57810: |
12332 | case BCM57810_MF: | |
c3def943 YM |
12333 | case BCM57840_4_10: |
12334 | case BCM57840_2_20: | |
1ab4434c | 12335 | case BCM57840_O: |
c3def943 | 12336 | case BCM57840_MFO: |
1ab4434c | 12337 | case BCM57810_VF: |
619c5cb6 | 12338 | case BCM57840_MF: |
1ab4434c | 12339 | case BCM57840_VF: |
7e8e02df BW |
12340 | case BCM57811: |
12341 | case BCM57811_MF: | |
1ab4434c AE |
12342 | case BCM57811_VF: |
12343 | return BNX2X_MULTI_TX_COS_E3B0; | |
12344 | return 1; | |
f2e0899f | 12345 | default: |
1ab4434c | 12346 | pr_err("Unknown board_type (%d), aborting\n", chip_id); |
870634b0 | 12347 | return -ENODEV; |
f2e0899f | 12348 | } |
1ab4434c | 12349 | } |
f2e0899f | 12350 | |
1ab4434c AE |
12351 | static int set_is_vf(int chip_id) |
12352 | { | |
12353 | switch (chip_id) { | |
12354 | case BCM57712_VF: | |
12355 | case BCM57800_VF: | |
12356 | case BCM57810_VF: | |
12357 | case BCM57840_VF: | |
12358 | case BCM57811_VF: | |
12359 | return true; | |
12360 | default: | |
12361 | return false; | |
12362 | } | |
12363 | } | |
6383c0b3 | 12364 | |
1ab4434c AE |
12365 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev); |
12366 | ||
12367 | static int bnx2x_init_one(struct pci_dev *pdev, | |
12368 | const struct pci_device_id *ent) | |
12369 | { | |
12370 | struct net_device *dev = NULL; | |
12371 | struct bnx2x *bp; | |
12372 | int pcie_width, pcie_speed; | |
12373 | int rc, max_non_def_sbs; | |
12374 | int rx_count, tx_count, rss_count, doorbell_size; | |
12375 | int max_cos_est; | |
12376 | bool is_vf; | |
12377 | int cnic_cnt; | |
12378 | ||
12379 | /* An estimated maximum supported CoS number according to the chip | |
12380 | * version. | |
12381 | * We will try to roughly estimate the maximum number of CoSes this chip | |
12382 | * may support in order to minimize the memory allocated for Tx | |
12383 | * netdev_queue's. This number will be accurately calculated during the | |
12384 | * initialization of bp->max_cos based on the chip versions AND chip | |
12385 | * revision in the bnx2x_init_bp(). | |
12386 | */ | |
12387 | max_cos_est = set_max_cos_est(ent->driver_data); | |
12388 | if (max_cos_est < 0) | |
12389 | return max_cos_est; | |
12390 | is_vf = set_is_vf(ent->driver_data); | |
12391 | cnic_cnt = is_vf ? 0 : 1; | |
12392 | ||
12393 | max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf); | |
6383c0b3 AE |
12394 | |
12395 | /* Maximum number of RSS queues: one IGU SB goes to CNIC */ | |
1ab4434c AE |
12396 | rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt; |
12397 | ||
12398 | if (rss_count < 1) | |
12399 | return -EINVAL; | |
6383c0b3 AE |
12400 | |
12401 | /* Maximum number of netdev Rx queues: RSS + FCoE L2 */ | |
55c11941 | 12402 | rx_count = rss_count + cnic_cnt; |
6383c0b3 | 12403 | |
1ab4434c | 12404 | /* Maximum number of netdev Tx queues: |
37ae41a9 | 12405 | * Maximum TSS queues * Maximum supported number of CoS + FCoE L2 |
6383c0b3 | 12406 | */ |
55c11941 | 12407 | tx_count = rss_count * max_cos_est + cnic_cnt; |
f85582f8 | 12408 | |
a2fbb9ea | 12409 | /* dev zeroed in init_etherdev */ |
6383c0b3 | 12410 | dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count); |
41de8d4c | 12411 | if (!dev) |
a2fbb9ea ET |
12412 | return -ENOMEM; |
12413 | ||
a2fbb9ea | 12414 | bp = netdev_priv(dev); |
a2fbb9ea | 12415 | |
1ab4434c AE |
12416 | bp->flags = 0; |
12417 | if (is_vf) | |
12418 | bp->flags |= IS_VF_FLAG; | |
12419 | ||
6383c0b3 | 12420 | bp->igu_sb_cnt = max_non_def_sbs; |
1ab4434c | 12421 | bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM; |
6383c0b3 | 12422 | bp->msg_enable = debug; |
55c11941 | 12423 | bp->cnic_support = cnic_cnt; |
4bd9b0ff | 12424 | bp->cnic_probe = bnx2x_cnic_probe; |
55c11941 | 12425 | |
6383c0b3 | 12426 | pci_set_drvdata(pdev, dev); |
523224a3 | 12427 | |
1ab4434c | 12428 | rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data); |
a2fbb9ea ET |
12429 | if (rc < 0) { |
12430 | free_netdev(dev); | |
12431 | return rc; | |
12432 | } | |
12433 | ||
1ab4434c AE |
12434 | BNX2X_DEV_INFO("This is a %s function\n", |
12435 | IS_PF(bp) ? "physical" : "virtual"); | |
55c11941 | 12436 | BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off"); |
1ab4434c | 12437 | BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs); |
60aa0509 | 12438 | BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n", |
2de67439 | 12439 | tx_count, rx_count); |
60aa0509 | 12440 | |
34f80b04 | 12441 | rc = bnx2x_init_bp(bp); |
693fc0d1 EG |
12442 | if (rc) |
12443 | goto init_one_exit; | |
12444 | ||
1ab4434c AE |
12445 | /* Map doorbells here as we need the real value of bp->max_cos which |
12446 | * is initialized in bnx2x_init_bp() to determine the number of | |
12447 | * l2 connections. | |
6383c0b3 | 12448 | */ |
1ab4434c | 12449 | if (IS_VF(bp)) { |
6411280a AE |
12450 | bnx2x_vf_map_doorbells(bp); |
12451 | rc = bnx2x_vf_pci_alloc(bp); | |
12452 | if (rc) | |
12453 | goto init_one_exit; | |
1ab4434c AE |
12454 | } else { |
12455 | doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT); | |
12456 | if (doorbell_size > pci_resource_len(pdev, 2)) { | |
12457 | dev_err(&bp->pdev->dev, | |
12458 | "Cannot map doorbells, bar size too small, aborting\n"); | |
12459 | rc = -ENOMEM; | |
12460 | goto init_one_exit; | |
12461 | } | |
12462 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), | |
12463 | doorbell_size); | |
37ae41a9 | 12464 | } |
6383c0b3 AE |
12465 | if (!bp->doorbells) { |
12466 | dev_err(&bp->pdev->dev, | |
12467 | "Cannot map doorbell space, aborting\n"); | |
12468 | rc = -ENOMEM; | |
12469 | goto init_one_exit; | |
12470 | } | |
12471 | ||
be1f1ffa AE |
12472 | if (IS_VF(bp)) { |
12473 | rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count); | |
12474 | if (rc) | |
12475 | goto init_one_exit; | |
12476 | } | |
12477 | ||
290ca2bb AE |
12478 | /* Enable SRIOV if capability found in configuration space. |
12479 | * Once the generic SR-IOV framework makes it in from the | |
12480 | * pci tree this will be revised, to allow dynamic control | |
12481 | * over the number of VFs. Right now, change the num of vfs | |
12482 | * param below to enable SR-IOV. | |
12483 | */ | |
12484 | rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/); | |
12485 | if (rc) | |
12486 | goto init_one_exit; | |
12487 | ||
523224a3 | 12488 | /* calc qm_cid_count */ |
6383c0b3 | 12489 | bp->qm_cid_count = bnx2x_set_qm_cid_count(bp); |
1ab4434c | 12490 | BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count); |
523224a3 | 12491 | |
55c11941 | 12492 | /* disable FCOE L2 queue for E1x*/ |
62ac0dc9 | 12493 | if (CHIP_IS_E1x(bp)) |
ec6ba945 VZ |
12494 | bp->flags |= NO_FCOE_FLAG; |
12495 | ||
477864dd DK |
12496 | /* disable FCOE for 57840 device, until FW supports it */ |
12497 | switch (ent->driver_data) { | |
12498 | case BCM57840_O: | |
12499 | case BCM57840_4_10: | |
12500 | case BCM57840_2_20: | |
12501 | case BCM57840_MFO: | |
12502 | case BCM57840_MF: | |
12503 | bp->flags |= NO_FCOE_FLAG; | |
12504 | } | |
0e8d2ec5 MS |
12505 | |
12506 | /* Set bp->num_queues for MSI-X mode*/ | |
12507 | bnx2x_set_num_queues(bp); | |
12508 | ||
25985edc | 12509 | /* Configure interrupt mode: try to enable MSI-X/MSI if |
0e8d2ec5 | 12510 | * needed. |
d6214d7a | 12511 | */ |
1ab4434c AE |
12512 | rc = bnx2x_set_int_mode(bp); |
12513 | if (rc) { | |
12514 | dev_err(&pdev->dev, "Cannot set interrupts\n"); | |
12515 | goto init_one_exit; | |
12516 | } | |
04c46736 | 12517 | BNX2X_DEV_INFO("set interrupts successfully\n"); |
d6214d7a | 12518 | |
1ab4434c | 12519 | /* register the net device */ |
b340007f VZ |
12520 | rc = register_netdev(dev); |
12521 | if (rc) { | |
12522 | dev_err(&pdev->dev, "Cannot register net device\n"); | |
12523 | goto init_one_exit; | |
12524 | } | |
1ab4434c | 12525 | BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name); |
b340007f | 12526 | |
55c11941 | 12527 | |
ec6ba945 VZ |
12528 | if (!NO_FCOE(bp)) { |
12529 | /* Add storage MAC address */ | |
12530 | rtnl_lock(); | |
12531 | dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
12532 | rtnl_unlock(); | |
12533 | } | |
ec6ba945 | 12534 | |
37f9ce62 | 12535 | bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed); |
1ab4434c AE |
12536 | BNX2X_DEV_INFO("got pcie width %d and speed %d\n", |
12537 | pcie_width, pcie_speed); | |
d6214d7a | 12538 | |
51c1a580 MS |
12539 | BNX2X_DEV_INFO( |
12540 | "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n", | |
94f05b0f JP |
12541 | board_info[ent->driver_data].name, |
12542 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), | |
12543 | pcie_width, | |
12544 | ((!CHIP_IS_E2(bp) && pcie_speed == 2) || | |
12545 | (CHIP_IS_E2(bp) && pcie_speed == 1)) ? | |
12546 | "5GHz (Gen2)" : "2.5GHz", | |
12547 | dev->base_addr, bp->pdev->irq, dev->dev_addr); | |
c016201c | 12548 | |
a2fbb9ea | 12549 | return 0; |
34f80b04 EG |
12550 | |
12551 | init_one_exit: | |
12552 | if (bp->regview) | |
12553 | iounmap(bp->regview); | |
12554 | ||
1ab4434c | 12555 | if (IS_PF(bp) && bp->doorbells) |
34f80b04 EG |
12556 | iounmap(bp->doorbells); |
12557 | ||
12558 | free_netdev(dev); | |
12559 | ||
12560 | if (atomic_read(&pdev->enable_cnt) == 1) | |
12561 | pci_release_regions(pdev); | |
12562 | ||
12563 | pci_disable_device(pdev); | |
12564 | pci_set_drvdata(pdev, NULL); | |
12565 | ||
12566 | return rc; | |
a2fbb9ea ET |
12567 | } |
12568 | ||
0329aba1 | 12569 | static void bnx2x_remove_one(struct pci_dev *pdev) |
a2fbb9ea ET |
12570 | { |
12571 | struct net_device *dev = pci_get_drvdata(pdev); | |
228241eb ET |
12572 | struct bnx2x *bp; |
12573 | ||
12574 | if (!dev) { | |
cdaa7cb8 | 12575 | dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n"); |
228241eb ET |
12576 | return; |
12577 | } | |
228241eb | 12578 | bp = netdev_priv(dev); |
a2fbb9ea | 12579 | |
ec6ba945 VZ |
12580 | /* Delete storage MAC address */ |
12581 | if (!NO_FCOE(bp)) { | |
12582 | rtnl_lock(); | |
12583 | dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
12584 | rtnl_unlock(); | |
12585 | } | |
ec6ba945 | 12586 | |
98507672 SR |
12587 | #ifdef BCM_DCBNL |
12588 | /* Delete app tlvs from dcbnl */ | |
12589 | bnx2x_dcbnl_update_applist(bp, true); | |
12590 | #endif | |
12591 | ||
a2fbb9ea ET |
12592 | unregister_netdev(dev); |
12593 | ||
084d6cbb | 12594 | /* Power on: we can't let PCI layer write to us while we are in D3 */ |
1ab4434c AE |
12595 | if (IS_PF(bp)) |
12596 | bnx2x_set_power_state(bp, PCI_D0); | |
084d6cbb | 12597 | |
d6214d7a DK |
12598 | /* Disable MSI/MSI-X */ |
12599 | bnx2x_disable_msi(bp); | |
f85582f8 | 12600 | |
084d6cbb | 12601 | /* Power off */ |
1ab4434c AE |
12602 | if (IS_PF(bp)) |
12603 | bnx2x_set_power_state(bp, PCI_D3hot); | |
084d6cbb | 12604 | |
72fd0718 | 12605 | /* Make sure RESET task is not scheduled before continuing */ |
7be08a72 | 12606 | cancel_delayed_work_sync(&bp->sp_rtnl_task); |
290ca2bb AE |
12607 | |
12608 | bnx2x_iov_remove_one(bp); | |
12609 | ||
4513f925 AE |
12610 | /* send message via vfpf channel to release the resources of this vf */ |
12611 | if (IS_VF(bp)) | |
12612 | bnx2x_vfpf_release(bp); | |
72fd0718 | 12613 | |
a2fbb9ea ET |
12614 | if (bp->regview) |
12615 | iounmap(bp->regview); | |
12616 | ||
1ab4434c AE |
12617 | /* for vf doorbells are part of the regview and were unmapped along with |
12618 | * it. FW is only loaded by PF. | |
12619 | */ | |
12620 | if (IS_PF(bp)) { | |
12621 | if (bp->doorbells) | |
12622 | iounmap(bp->doorbells); | |
eb2afd4a | 12623 | |
1ab4434c AE |
12624 | bnx2x_release_firmware(bp); |
12625 | } | |
523224a3 DK |
12626 | bnx2x_free_mem_bp(bp); |
12627 | ||
a2fbb9ea | 12628 | free_netdev(dev); |
34f80b04 EG |
12629 | |
12630 | if (atomic_read(&pdev->enable_cnt) == 1) | |
12631 | pci_release_regions(pdev); | |
12632 | ||
a2fbb9ea ET |
12633 | pci_disable_device(pdev); |
12634 | pci_set_drvdata(pdev, NULL); | |
12635 | } | |
12636 | ||
f8ef6e44 YG |
12637 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
12638 | { | |
12639 | int i; | |
12640 | ||
12641 | bp->state = BNX2X_STATE_ERROR; | |
12642 | ||
12643 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
12644 | ||
55c11941 MS |
12645 | if (CNIC_LOADED(bp)) |
12646 | bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD); | |
12647 | ||
619c5cb6 VZ |
12648 | /* Stop Tx */ |
12649 | bnx2x_tx_disable(bp); | |
12650 | ||
f8ef6e44 | 12651 | bnx2x_netif_stop(bp, 0); |
26614ba5 MS |
12652 | /* Delete all NAPI objects */ |
12653 | bnx2x_del_all_napi(bp); | |
55c11941 MS |
12654 | if (CNIC_LOADED(bp)) |
12655 | bnx2x_del_all_napi_cnic(bp); | |
f8ef6e44 YG |
12656 | |
12657 | del_timer_sync(&bp->timer); | |
619c5cb6 VZ |
12658 | |
12659 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
f8ef6e44 YG |
12660 | |
12661 | /* Release IRQs */ | |
d6214d7a | 12662 | bnx2x_free_irq(bp); |
f8ef6e44 | 12663 | |
f8ef6e44 YG |
12664 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
12665 | bnx2x_free_skbs(bp); | |
523224a3 | 12666 | |
ec6ba945 | 12667 | for_each_rx_queue(bp, i) |
f8ef6e44 | 12668 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
d6214d7a | 12669 | |
f8ef6e44 YG |
12670 | bnx2x_free_mem(bp); |
12671 | ||
12672 | bp->state = BNX2X_STATE_CLOSED; | |
12673 | ||
619c5cb6 VZ |
12674 | netif_carrier_off(bp->dev); |
12675 | ||
f8ef6e44 YG |
12676 | return 0; |
12677 | } | |
12678 | ||
12679 | static void bnx2x_eeh_recover(struct bnx2x *bp) | |
12680 | { | |
12681 | u32 val; | |
12682 | ||
12683 | mutex_init(&bp->port.phy_mutex); | |
12684 | ||
f8ef6e44 YG |
12685 | |
12686 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); | |
12687 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) | |
12688 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) | |
12689 | BNX2X_ERR("BAD MCP validity signature\n"); | |
f8ef6e44 YG |
12690 | } |
12691 | ||
493adb1f WX |
12692 | /** |
12693 | * bnx2x_io_error_detected - called when PCI error is detected | |
12694 | * @pdev: Pointer to PCI device | |
12695 | * @state: The current pci connection state | |
12696 | * | |
12697 | * This function is called after a PCI bus error affecting | |
12698 | * this device has been detected. | |
12699 | */ | |
12700 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, | |
12701 | pci_channel_state_t state) | |
12702 | { | |
12703 | struct net_device *dev = pci_get_drvdata(pdev); | |
12704 | struct bnx2x *bp = netdev_priv(dev); | |
12705 | ||
12706 | rtnl_lock(); | |
12707 | ||
12708 | netif_device_detach(dev); | |
12709 | ||
07ce50e4 DN |
12710 | if (state == pci_channel_io_perm_failure) { |
12711 | rtnl_unlock(); | |
12712 | return PCI_ERS_RESULT_DISCONNECT; | |
12713 | } | |
12714 | ||
493adb1f | 12715 | if (netif_running(dev)) |
f8ef6e44 | 12716 | bnx2x_eeh_nic_unload(bp); |
493adb1f WX |
12717 | |
12718 | pci_disable_device(pdev); | |
12719 | ||
12720 | rtnl_unlock(); | |
12721 | ||
12722 | /* Request a slot reset */ | |
12723 | return PCI_ERS_RESULT_NEED_RESET; | |
12724 | } | |
12725 | ||
12726 | /** | |
12727 | * bnx2x_io_slot_reset - called after the PCI bus has been reset | |
12728 | * @pdev: Pointer to PCI device | |
12729 | * | |
12730 | * Restart the card from scratch, as if from a cold-boot. | |
12731 | */ | |
12732 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) | |
12733 | { | |
12734 | struct net_device *dev = pci_get_drvdata(pdev); | |
12735 | struct bnx2x *bp = netdev_priv(dev); | |
12736 | ||
12737 | rtnl_lock(); | |
12738 | ||
12739 | if (pci_enable_device(pdev)) { | |
12740 | dev_err(&pdev->dev, | |
12741 | "Cannot re-enable PCI device after reset\n"); | |
12742 | rtnl_unlock(); | |
12743 | return PCI_ERS_RESULT_DISCONNECT; | |
12744 | } | |
12745 | ||
12746 | pci_set_master(pdev); | |
12747 | pci_restore_state(pdev); | |
12748 | ||
12749 | if (netif_running(dev)) | |
12750 | bnx2x_set_power_state(bp, PCI_D0); | |
12751 | ||
12752 | rtnl_unlock(); | |
12753 | ||
12754 | return PCI_ERS_RESULT_RECOVERED; | |
12755 | } | |
12756 | ||
12757 | /** | |
12758 | * bnx2x_io_resume - called when traffic can start flowing again | |
12759 | * @pdev: Pointer to PCI device | |
12760 | * | |
12761 | * This callback is called when the error recovery driver tells us that | |
12762 | * its OK to resume normal operation. | |
12763 | */ | |
12764 | static void bnx2x_io_resume(struct pci_dev *pdev) | |
12765 | { | |
12766 | struct net_device *dev = pci_get_drvdata(pdev); | |
12767 | struct bnx2x *bp = netdev_priv(dev); | |
12768 | ||
72fd0718 | 12769 | if (bp->recovery_state != BNX2X_RECOVERY_DONE) { |
51c1a580 | 12770 | netdev_err(bp->dev, "Handling parity error recovery. Try again later\n"); |
72fd0718 VZ |
12771 | return; |
12772 | } | |
12773 | ||
493adb1f WX |
12774 | rtnl_lock(); |
12775 | ||
f8ef6e44 YG |
12776 | bnx2x_eeh_recover(bp); |
12777 | ||
493adb1f | 12778 | if (netif_running(dev)) |
f8ef6e44 | 12779 | bnx2x_nic_load(bp, LOAD_NORMAL); |
493adb1f WX |
12780 | |
12781 | netif_device_attach(dev); | |
12782 | ||
12783 | rtnl_unlock(); | |
12784 | } | |
12785 | ||
3646f0e5 | 12786 | static const struct pci_error_handlers bnx2x_err_handler = { |
493adb1f | 12787 | .error_detected = bnx2x_io_error_detected, |
356e2385 EG |
12788 | .slot_reset = bnx2x_io_slot_reset, |
12789 | .resume = bnx2x_io_resume, | |
493adb1f WX |
12790 | }; |
12791 | ||
a2fbb9ea | 12792 | static struct pci_driver bnx2x_pci_driver = { |
493adb1f WX |
12793 | .name = DRV_MODULE_NAME, |
12794 | .id_table = bnx2x_pci_tbl, | |
12795 | .probe = bnx2x_init_one, | |
0329aba1 | 12796 | .remove = bnx2x_remove_one, |
493adb1f WX |
12797 | .suspend = bnx2x_suspend, |
12798 | .resume = bnx2x_resume, | |
12799 | .err_handler = &bnx2x_err_handler, | |
a2fbb9ea ET |
12800 | }; |
12801 | ||
12802 | static int __init bnx2x_init(void) | |
12803 | { | |
dd21ca6d SG |
12804 | int ret; |
12805 | ||
7995c64e | 12806 | pr_info("%s", version); |
938cf541 | 12807 | |
1cf167f2 EG |
12808 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
12809 | if (bnx2x_wq == NULL) { | |
7995c64e | 12810 | pr_err("Cannot create workqueue\n"); |
1cf167f2 EG |
12811 | return -ENOMEM; |
12812 | } | |
12813 | ||
dd21ca6d SG |
12814 | ret = pci_register_driver(&bnx2x_pci_driver); |
12815 | if (ret) { | |
7995c64e | 12816 | pr_err("Cannot register driver\n"); |
dd21ca6d SG |
12817 | destroy_workqueue(bnx2x_wq); |
12818 | } | |
12819 | return ret; | |
a2fbb9ea ET |
12820 | } |
12821 | ||
12822 | static void __exit bnx2x_cleanup(void) | |
12823 | { | |
452427b0 | 12824 | struct list_head *pos, *q; |
a2fbb9ea | 12825 | pci_unregister_driver(&bnx2x_pci_driver); |
1cf167f2 EG |
12826 | |
12827 | destroy_workqueue(bnx2x_wq); | |
452427b0 YM |
12828 | |
12829 | /* Free globablly allocated resources */ | |
12830 | list_for_each_safe(pos, q, &bnx2x_prev_list) { | |
12831 | struct bnx2x_prev_path_list *tmp = | |
12832 | list_entry(pos, struct bnx2x_prev_path_list, list); | |
12833 | list_del(pos); | |
12834 | kfree(tmp); | |
12835 | } | |
a2fbb9ea ET |
12836 | } |
12837 | ||
3deb8167 YR |
12838 | void bnx2x_notify_link_changed(struct bnx2x *bp) |
12839 | { | |
12840 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1); | |
12841 | } | |
12842 | ||
a2fbb9ea ET |
12843 | module_init(bnx2x_init); |
12844 | module_exit(bnx2x_cleanup); | |
12845 | ||
619c5cb6 VZ |
12846 | /** |
12847 | * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s). | |
12848 | * | |
12849 | * @bp: driver handle | |
12850 | * @set: set or clear the CAM entry | |
12851 | * | |
12852 | * This function will wait until the ramdord completion returns. | |
12853 | * Return 0 if success, -ENODEV if ramrod doesn't return. | |
12854 | */ | |
1191cb83 | 12855 | static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp) |
619c5cb6 VZ |
12856 | { |
12857 | unsigned long ramrod_flags = 0; | |
12858 | ||
12859 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
12860 | return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac, | |
12861 | &bp->iscsi_l2_mac_obj, true, | |
12862 | BNX2X_ISCSI_ETH_MAC, &ramrod_flags); | |
12863 | } | |
993ac7b5 MC |
12864 | |
12865 | /* count denotes the number of new completions we have seen */ | |
12866 | static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count) | |
12867 | { | |
12868 | struct eth_spe *spe; | |
a052997e | 12869 | int cxt_index, cxt_offset; |
993ac7b5 MC |
12870 | |
12871 | #ifdef BNX2X_STOP_ON_ERROR | |
12872 | if (unlikely(bp->panic)) | |
12873 | return; | |
12874 | #endif | |
12875 | ||
12876 | spin_lock_bh(&bp->spq_lock); | |
c2bff63f | 12877 | BUG_ON(bp->cnic_spq_pending < count); |
993ac7b5 MC |
12878 | bp->cnic_spq_pending -= count; |
12879 | ||
993ac7b5 | 12880 | |
c2bff63f DK |
12881 | for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) { |
12882 | u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type) | |
12883 | & SPE_HDR_CONN_TYPE) >> | |
12884 | SPE_HDR_CONN_TYPE_SHIFT; | |
619c5cb6 VZ |
12885 | u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data) |
12886 | >> SPE_HDR_CMD_ID_SHIFT) & 0xff; | |
c2bff63f DK |
12887 | |
12888 | /* Set validation for iSCSI L2 client before sending SETUP | |
12889 | * ramrod | |
12890 | */ | |
12891 | if (type == ETH_CONNECTION_TYPE) { | |
a052997e | 12892 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) { |
37ae41a9 | 12893 | cxt_index = BNX2X_ISCSI_ETH_CID(bp) / |
a052997e | 12894 | ILT_PAGE_CIDS; |
37ae41a9 | 12895 | cxt_offset = BNX2X_ISCSI_ETH_CID(bp) - |
a052997e MS |
12896 | (cxt_index * ILT_PAGE_CIDS); |
12897 | bnx2x_set_ctx_validation(bp, | |
12898 | &bp->context[cxt_index]. | |
12899 | vcxt[cxt_offset].eth, | |
37ae41a9 | 12900 | BNX2X_ISCSI_ETH_CID(bp)); |
a052997e | 12901 | } |
c2bff63f DK |
12902 | } |
12903 | ||
619c5cb6 VZ |
12904 | /* |
12905 | * There may be not more than 8 L2, not more than 8 L5 SPEs | |
12906 | * and in the air. We also check that number of outstanding | |
6e30dd4e VZ |
12907 | * COMMON ramrods is not more than the EQ and SPQ can |
12908 | * accommodate. | |
c2bff63f | 12909 | */ |
6e30dd4e VZ |
12910 | if (type == ETH_CONNECTION_TYPE) { |
12911 | if (!atomic_read(&bp->cq_spq_left)) | |
12912 | break; | |
12913 | else | |
12914 | atomic_dec(&bp->cq_spq_left); | |
12915 | } else if (type == NONE_CONNECTION_TYPE) { | |
12916 | if (!atomic_read(&bp->eq_spq_left)) | |
c2bff63f DK |
12917 | break; |
12918 | else | |
6e30dd4e | 12919 | atomic_dec(&bp->eq_spq_left); |
ec6ba945 VZ |
12920 | } else if ((type == ISCSI_CONNECTION_TYPE) || |
12921 | (type == FCOE_CONNECTION_TYPE)) { | |
c2bff63f DK |
12922 | if (bp->cnic_spq_pending >= |
12923 | bp->cnic_eth_dev.max_kwqe_pending) | |
12924 | break; | |
12925 | else | |
12926 | bp->cnic_spq_pending++; | |
12927 | } else { | |
12928 | BNX2X_ERR("Unknown SPE type: %d\n", type); | |
12929 | bnx2x_panic(); | |
993ac7b5 | 12930 | break; |
c2bff63f | 12931 | } |
993ac7b5 MC |
12932 | |
12933 | spe = bnx2x_sp_get_next(bp); | |
12934 | *spe = *bp->cnic_kwq_cons; | |
12935 | ||
51c1a580 | 12936 | DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n", |
993ac7b5 MC |
12937 | bp->cnic_spq_pending, bp->cnic_kwq_pending, count); |
12938 | ||
12939 | if (bp->cnic_kwq_cons == bp->cnic_kwq_last) | |
12940 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
12941 | else | |
12942 | bp->cnic_kwq_cons++; | |
12943 | } | |
12944 | bnx2x_sp_prod_update(bp); | |
12945 | spin_unlock_bh(&bp->spq_lock); | |
12946 | } | |
12947 | ||
12948 | static int bnx2x_cnic_sp_queue(struct net_device *dev, | |
12949 | struct kwqe_16 *kwqes[], u32 count) | |
12950 | { | |
12951 | struct bnx2x *bp = netdev_priv(dev); | |
12952 | int i; | |
12953 | ||
12954 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 MS |
12955 | if (unlikely(bp->panic)) { |
12956 | BNX2X_ERR("Can't post to SP queue while panic\n"); | |
993ac7b5 | 12957 | return -EIO; |
51c1a580 | 12958 | } |
993ac7b5 MC |
12959 | #endif |
12960 | ||
95c6c616 AE |
12961 | if ((bp->recovery_state != BNX2X_RECOVERY_DONE) && |
12962 | (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) { | |
51c1a580 | 12963 | BNX2X_ERR("Handling parity error recovery. Try again later\n"); |
95c6c616 AE |
12964 | return -EAGAIN; |
12965 | } | |
12966 | ||
993ac7b5 MC |
12967 | spin_lock_bh(&bp->spq_lock); |
12968 | ||
12969 | for (i = 0; i < count; i++) { | |
12970 | struct eth_spe *spe = (struct eth_spe *)kwqes[i]; | |
12971 | ||
12972 | if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT) | |
12973 | break; | |
12974 | ||
12975 | *bp->cnic_kwq_prod = *spe; | |
12976 | ||
12977 | bp->cnic_kwq_pending++; | |
12978 | ||
51c1a580 | 12979 | DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n", |
993ac7b5 | 12980 | spe->hdr.conn_and_cmd_data, spe->hdr.type, |
523224a3 DK |
12981 | spe->data.update_data_addr.hi, |
12982 | spe->data.update_data_addr.lo, | |
993ac7b5 MC |
12983 | bp->cnic_kwq_pending); |
12984 | ||
12985 | if (bp->cnic_kwq_prod == bp->cnic_kwq_last) | |
12986 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
12987 | else | |
12988 | bp->cnic_kwq_prod++; | |
12989 | } | |
12990 | ||
12991 | spin_unlock_bh(&bp->spq_lock); | |
12992 | ||
12993 | if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending) | |
12994 | bnx2x_cnic_sp_post(bp, 0); | |
12995 | ||
12996 | return i; | |
12997 | } | |
12998 | ||
12999 | static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
13000 | { | |
13001 | struct cnic_ops *c_ops; | |
13002 | int rc = 0; | |
13003 | ||
13004 | mutex_lock(&bp->cnic_mutex); | |
13707f9e ED |
13005 | c_ops = rcu_dereference_protected(bp->cnic_ops, |
13006 | lockdep_is_held(&bp->cnic_mutex)); | |
993ac7b5 MC |
13007 | if (c_ops) |
13008 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
13009 | mutex_unlock(&bp->cnic_mutex); | |
13010 | ||
13011 | return rc; | |
13012 | } | |
13013 | ||
13014 | static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
13015 | { | |
13016 | struct cnic_ops *c_ops; | |
13017 | int rc = 0; | |
13018 | ||
13019 | rcu_read_lock(); | |
13020 | c_ops = rcu_dereference(bp->cnic_ops); | |
13021 | if (c_ops) | |
13022 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
13023 | rcu_read_unlock(); | |
13024 | ||
13025 | return rc; | |
13026 | } | |
13027 | ||
13028 | /* | |
13029 | * for commands that have no data | |
13030 | */ | |
9f6c9258 | 13031 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd) |
993ac7b5 MC |
13032 | { |
13033 | struct cnic_ctl_info ctl = {0}; | |
13034 | ||
13035 | ctl.cmd = cmd; | |
13036 | ||
13037 | return bnx2x_cnic_ctl_send(bp, &ctl); | |
13038 | } | |
13039 | ||
619c5cb6 | 13040 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err) |
993ac7b5 | 13041 | { |
619c5cb6 | 13042 | struct cnic_ctl_info ctl = {0}; |
993ac7b5 MC |
13043 | |
13044 | /* first we tell CNIC and only then we count this as a completion */ | |
13045 | ctl.cmd = CNIC_CTL_COMPLETION_CMD; | |
13046 | ctl.data.comp.cid = cid; | |
619c5cb6 | 13047 | ctl.data.comp.error = err; |
993ac7b5 MC |
13048 | |
13049 | bnx2x_cnic_ctl_send_bh(bp, &ctl); | |
c2bff63f | 13050 | bnx2x_cnic_sp_post(bp, 0); |
993ac7b5 MC |
13051 | } |
13052 | ||
619c5cb6 VZ |
13053 | |
13054 | /* Called with netif_addr_lock_bh() taken. | |
13055 | * Sets an rx_mode config for an iSCSI ETH client. | |
13056 | * Doesn't block. | |
13057 | * Completion should be checked outside. | |
13058 | */ | |
13059 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start) | |
13060 | { | |
13061 | unsigned long accept_flags = 0, ramrod_flags = 0; | |
13062 | u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
13063 | int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED; | |
13064 | ||
13065 | if (start) { | |
13066 | /* Start accepting on iSCSI L2 ring. Accept all multicasts | |
13067 | * because it's the only way for UIO Queue to accept | |
13068 | * multicasts (in non-promiscuous mode only one Queue per | |
13069 | * function will receive multicast packets (leading in our | |
13070 | * case). | |
13071 | */ | |
13072 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags); | |
13073 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags); | |
13074 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags); | |
13075 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); | |
13076 | ||
13077 | /* Clear STOP_PENDING bit if START is requested */ | |
13078 | clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state); | |
13079 | ||
13080 | sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED; | |
13081 | } else | |
13082 | /* Clear START_PENDING bit if STOP is requested */ | |
13083 | clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state); | |
13084 | ||
13085 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
13086 | set_bit(sched_state, &bp->sp_state); | |
13087 | else { | |
13088 | __set_bit(RAMROD_RX, &ramrod_flags); | |
13089 | bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0, | |
13090 | ramrod_flags); | |
13091 | } | |
13092 | } | |
13093 | ||
13094 | ||
993ac7b5 MC |
13095 | static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl) |
13096 | { | |
13097 | struct bnx2x *bp = netdev_priv(dev); | |
13098 | int rc = 0; | |
13099 | ||
13100 | switch (ctl->cmd) { | |
13101 | case DRV_CTL_CTXTBL_WR_CMD: { | |
13102 | u32 index = ctl->data.io.offset; | |
13103 | dma_addr_t addr = ctl->data.io.dma_addr; | |
13104 | ||
13105 | bnx2x_ilt_wr(bp, index, addr); | |
13106 | break; | |
13107 | } | |
13108 | ||
c2bff63f DK |
13109 | case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: { |
13110 | int count = ctl->data.credit.credit_count; | |
993ac7b5 MC |
13111 | |
13112 | bnx2x_cnic_sp_post(bp, count); | |
13113 | break; | |
13114 | } | |
13115 | ||
13116 | /* rtnl_lock is held. */ | |
13117 | case DRV_CTL_START_L2_CMD: { | |
619c5cb6 VZ |
13118 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
13119 | unsigned long sp_bits = 0; | |
13120 | ||
13121 | /* Configure the iSCSI classification object */ | |
13122 | bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj, | |
13123 | cp->iscsi_l2_client_id, | |
13124 | cp->iscsi_l2_cid, BP_FUNC(bp), | |
13125 | bnx2x_sp(bp, mac_rdata), | |
13126 | bnx2x_sp_mapping(bp, mac_rdata), | |
13127 | BNX2X_FILTER_MAC_PENDING, | |
13128 | &bp->sp_state, BNX2X_OBJ_TYPE_RX, | |
13129 | &bp->macs_pool); | |
ec6ba945 | 13130 | |
523224a3 | 13131 | /* Set iSCSI MAC address */ |
619c5cb6 VZ |
13132 | rc = bnx2x_set_iscsi_eth_mac_addr(bp); |
13133 | if (rc) | |
13134 | break; | |
523224a3 DK |
13135 | |
13136 | mmiowb(); | |
13137 | barrier(); | |
13138 | ||
619c5cb6 VZ |
13139 | /* Start accepting on iSCSI L2 ring */ |
13140 | ||
13141 | netif_addr_lock_bh(dev); | |
13142 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
13143 | netif_addr_unlock_bh(dev); | |
13144 | ||
13145 | /* bits to wait on */ | |
13146 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
13147 | __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits); | |
13148 | ||
13149 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
13150 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 | 13151 | |
993ac7b5 MC |
13152 | break; |
13153 | } | |
13154 | ||
13155 | /* rtnl_lock is held. */ | |
13156 | case DRV_CTL_STOP_L2_CMD: { | |
619c5cb6 | 13157 | unsigned long sp_bits = 0; |
993ac7b5 | 13158 | |
523224a3 | 13159 | /* Stop accepting on iSCSI L2 ring */ |
619c5cb6 VZ |
13160 | netif_addr_lock_bh(dev); |
13161 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
13162 | netif_addr_unlock_bh(dev); | |
13163 | ||
13164 | /* bits to wait on */ | |
13165 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
13166 | __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits); | |
13167 | ||
13168 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
13169 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 DK |
13170 | |
13171 | mmiowb(); | |
13172 | barrier(); | |
13173 | ||
13174 | /* Unset iSCSI L2 MAC */ | |
619c5cb6 VZ |
13175 | rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj, |
13176 | BNX2X_ISCSI_ETH_MAC, true); | |
993ac7b5 MC |
13177 | break; |
13178 | } | |
c2bff63f DK |
13179 | case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: { |
13180 | int count = ctl->data.credit.credit_count; | |
13181 | ||
13182 | smp_mb__before_atomic_inc(); | |
6e30dd4e | 13183 | atomic_add(count, &bp->cq_spq_left); |
c2bff63f DK |
13184 | smp_mb__after_atomic_inc(); |
13185 | break; | |
13186 | } | |
1d187b34 | 13187 | case DRV_CTL_ULP_REGISTER_CMD: { |
2e499d3c | 13188 | int ulp_type = ctl->data.register_data.ulp_type; |
1d187b34 BW |
13189 | |
13190 | if (CHIP_IS_E3(bp)) { | |
13191 | int idx = BP_FW_MB_IDX(bp); | |
2e499d3c BW |
13192 | u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); |
13193 | int path = BP_PATH(bp); | |
13194 | int port = BP_PORT(bp); | |
13195 | int i; | |
13196 | u32 scratch_offset; | |
13197 | u32 *host_addr; | |
1d187b34 | 13198 | |
2e499d3c | 13199 | /* first write capability to shmem2 */ |
1d187b34 BW |
13200 | if (ulp_type == CNIC_ULP_ISCSI) |
13201 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
13202 | else if (ulp_type == CNIC_ULP_FCOE) | |
13203 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
13204 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
2e499d3c BW |
13205 | |
13206 | if ((ulp_type != CNIC_ULP_FCOE) || | |
13207 | (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) || | |
13208 | (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES))) | |
13209 | break; | |
13210 | ||
13211 | /* if reached here - should write fcoe capabilities */ | |
13212 | scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr); | |
13213 | if (!scratch_offset) | |
13214 | break; | |
13215 | scratch_offset += offsetof(struct glob_ncsi_oem_data, | |
13216 | fcoe_features[path][port]); | |
13217 | host_addr = (u32 *) &(ctl->data.register_data. | |
13218 | fcoe_features); | |
13219 | for (i = 0; i < sizeof(struct fcoe_capabilities); | |
13220 | i += 4) | |
13221 | REG_WR(bp, scratch_offset + i, | |
13222 | *(host_addr + i/4)); | |
1d187b34 BW |
13223 | } |
13224 | break; | |
13225 | } | |
2e499d3c | 13226 | |
1d187b34 BW |
13227 | case DRV_CTL_ULP_UNREGISTER_CMD: { |
13228 | int ulp_type = ctl->data.ulp_type; | |
13229 | ||
13230 | if (CHIP_IS_E3(bp)) { | |
13231 | int idx = BP_FW_MB_IDX(bp); | |
13232 | u32 cap; | |
13233 | ||
13234 | cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); | |
13235 | if (ulp_type == CNIC_ULP_ISCSI) | |
13236 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
13237 | else if (ulp_type == CNIC_ULP_FCOE) | |
13238 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
13239 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
13240 | } | |
13241 | break; | |
13242 | } | |
993ac7b5 MC |
13243 | |
13244 | default: | |
13245 | BNX2X_ERR("unknown command %x\n", ctl->cmd); | |
13246 | rc = -EINVAL; | |
13247 | } | |
13248 | ||
13249 | return rc; | |
13250 | } | |
13251 | ||
9f6c9258 | 13252 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) |
993ac7b5 MC |
13253 | { |
13254 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13255 | ||
13256 | if (bp->flags & USING_MSIX_FLAG) { | |
13257 | cp->drv_state |= CNIC_DRV_STATE_USING_MSIX; | |
13258 | cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX; | |
13259 | cp->irq_arr[0].vector = bp->msix_table[1].vector; | |
13260 | } else { | |
13261 | cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX; | |
13262 | cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX; | |
13263 | } | |
619c5cb6 | 13264 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
13265 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb; |
13266 | else | |
13267 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; | |
13268 | ||
619c5cb6 VZ |
13269 | cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); |
13270 | cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); | |
993ac7b5 MC |
13271 | cp->irq_arr[1].status_blk = bp->def_status_blk; |
13272 | cp->irq_arr[1].status_blk_num = DEF_SB_ID; | |
523224a3 | 13273 | cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; |
993ac7b5 MC |
13274 | |
13275 | cp->num_irq = 2; | |
13276 | } | |
13277 | ||
37ae41a9 MS |
13278 | void bnx2x_setup_cnic_info(struct bnx2x *bp) |
13279 | { | |
13280 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13281 | ||
13282 | ||
13283 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + | |
13284 | bnx2x_cid_ilt_lines(bp); | |
13285 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; | |
13286 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp); | |
13287 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp); | |
13288 | ||
13289 | if (NO_ISCSI_OOO(bp)) | |
13290 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; | |
13291 | } | |
13292 | ||
993ac7b5 MC |
13293 | static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops, |
13294 | void *data) | |
13295 | { | |
13296 | struct bnx2x *bp = netdev_priv(dev); | |
13297 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
55c11941 MS |
13298 | int rc; |
13299 | ||
13300 | DP(NETIF_MSG_IFUP, "Register_cnic called\n"); | |
993ac7b5 | 13301 | |
51c1a580 MS |
13302 | if (ops == NULL) { |
13303 | BNX2X_ERR("NULL ops received\n"); | |
993ac7b5 | 13304 | return -EINVAL; |
51c1a580 | 13305 | } |
993ac7b5 | 13306 | |
55c11941 MS |
13307 | if (!CNIC_SUPPORT(bp)) { |
13308 | BNX2X_ERR("Can't register CNIC when not supported\n"); | |
13309 | return -EOPNOTSUPP; | |
13310 | } | |
13311 | ||
13312 | if (!CNIC_LOADED(bp)) { | |
13313 | rc = bnx2x_load_cnic(bp); | |
13314 | if (rc) { | |
13315 | BNX2X_ERR("CNIC-related load failed\n"); | |
13316 | return rc; | |
13317 | } | |
13318 | ||
13319 | } | |
13320 | ||
13321 | bp->cnic_enabled = true; | |
13322 | ||
993ac7b5 MC |
13323 | bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL); |
13324 | if (!bp->cnic_kwq) | |
13325 | return -ENOMEM; | |
13326 | ||
13327 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
13328 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
13329 | bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT; | |
13330 | ||
13331 | bp->cnic_spq_pending = 0; | |
13332 | bp->cnic_kwq_pending = 0; | |
13333 | ||
13334 | bp->cnic_data = data; | |
13335 | ||
13336 | cp->num_irq = 0; | |
619c5cb6 | 13337 | cp->drv_state |= CNIC_DRV_STATE_REGD; |
523224a3 | 13338 | cp->iro_arr = bp->iro_arr; |
993ac7b5 | 13339 | |
993ac7b5 | 13340 | bnx2x_setup_cnic_irq_info(bp); |
c2bff63f | 13341 | |
993ac7b5 MC |
13342 | rcu_assign_pointer(bp->cnic_ops, ops); |
13343 | ||
13344 | return 0; | |
13345 | } | |
13346 | ||
13347 | static int bnx2x_unregister_cnic(struct net_device *dev) | |
13348 | { | |
13349 | struct bnx2x *bp = netdev_priv(dev); | |
13350 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13351 | ||
13352 | mutex_lock(&bp->cnic_mutex); | |
993ac7b5 | 13353 | cp->drv_state = 0; |
2cfa5a04 | 13354 | RCU_INIT_POINTER(bp->cnic_ops, NULL); |
993ac7b5 MC |
13355 | mutex_unlock(&bp->cnic_mutex); |
13356 | synchronize_rcu(); | |
fea75645 | 13357 | bp->cnic_enabled = false; |
993ac7b5 MC |
13358 | kfree(bp->cnic_kwq); |
13359 | bp->cnic_kwq = NULL; | |
13360 | ||
13361 | return 0; | |
13362 | } | |
13363 | ||
13364 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev) | |
13365 | { | |
13366 | struct bnx2x *bp = netdev_priv(dev); | |
13367 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13368 | ||
2ba45142 VZ |
13369 | /* If both iSCSI and FCoE are disabled - return NULL in |
13370 | * order to indicate CNIC that it should not try to work | |
13371 | * with this device. | |
13372 | */ | |
13373 | if (NO_ISCSI(bp) && NO_FCOE(bp)) | |
13374 | return NULL; | |
13375 | ||
993ac7b5 MC |
13376 | cp->drv_owner = THIS_MODULE; |
13377 | cp->chip_id = CHIP_ID(bp); | |
13378 | cp->pdev = bp->pdev; | |
13379 | cp->io_base = bp->regview; | |
13380 | cp->io_base2 = bp->doorbells; | |
13381 | cp->max_kwqe_pending = 8; | |
523224a3 | 13382 | cp->ctx_blk_size = CDU_ILT_PAGE_SZ; |
c2bff63f DK |
13383 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
13384 | bnx2x_cid_ilt_lines(bp); | |
993ac7b5 | 13385 | cp->ctx_tbl_len = CNIC_ILT_LINES; |
c2bff63f | 13386 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; |
993ac7b5 MC |
13387 | cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue; |
13388 | cp->drv_ctl = bnx2x_drv_ctl; | |
13389 | cp->drv_register_cnic = bnx2x_register_cnic; | |
13390 | cp->drv_unregister_cnic = bnx2x_unregister_cnic; | |
37ae41a9 | 13391 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp); |
619c5cb6 VZ |
13392 | cp->iscsi_l2_client_id = |
13393 | bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
37ae41a9 | 13394 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp); |
c2bff63f | 13395 | |
2ba45142 VZ |
13396 | if (NO_ISCSI_OOO(bp)) |
13397 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; | |
13398 | ||
13399 | if (NO_ISCSI(bp)) | |
13400 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI; | |
13401 | ||
13402 | if (NO_FCOE(bp)) | |
13403 | cp->drv_state |= CNIC_DRV_STATE_NO_FCOE; | |
13404 | ||
51c1a580 MS |
13405 | BNX2X_DEV_INFO( |
13406 | "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n", | |
c2bff63f DK |
13407 | cp->ctx_blk_size, |
13408 | cp->ctx_tbl_offset, | |
13409 | cp->ctx_tbl_len, | |
13410 | cp->starting_cid); | |
993ac7b5 MC |
13411 | return cp; |
13412 | } | |
993ac7b5 | 13413 | |
6411280a | 13414 | u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp) |
9b176b6b | 13415 | { |
6411280a AE |
13416 | struct bnx2x *bp = fp->bp; |
13417 | u32 offset = BAR_USTRORM_INTMEM; | |
abc5a021 | 13418 | |
6411280a AE |
13419 | if (IS_VF(bp)) |
13420 | return bnx2x_vf_ustorm_prods_offset(bp, fp); | |
13421 | else if (!CHIP_IS_E1x(bp)) | |
13422 | offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id); | |
13423 | else | |
13424 | offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id); | |
8d9ac297 | 13425 | |
6411280a | 13426 | return offset; |
8d9ac297 | 13427 | } |
381ac16b | 13428 | |
6411280a AE |
13429 | /* called only on E1H or E2. |
13430 | * When pretending to be PF, the pretend value is the function number 0...7 | |
13431 | * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID | |
13432 | * combination | |
13433 | */ | |
13434 | int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val) | |
381ac16b | 13435 | { |
6411280a | 13436 | u32 pretend_reg; |
381ac16b | 13437 | |
23826850 | 13438 | if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX) |
6411280a | 13439 | return -1; |
381ac16b | 13440 | |
6411280a AE |
13441 | /* get my own pretend register */ |
13442 | pretend_reg = bnx2x_get_pretend_reg(bp); | |
13443 | REG_WR(bp, pretend_reg, pretend_func_val); | |
13444 | REG_RD(bp, pretend_reg); | |
381ac16b AE |
13445 | return 0; |
13446 | } |