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 | |
34f80b04 EG |
78 | /* Time in jiffies before concluding the transmitter is hung */ |
79 | #define TX_TIMEOUT (5*HZ) | |
a2fbb9ea | 80 | |
0329aba1 | 81 | static char version[] = |
619c5cb6 | 82 | "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver " |
a2fbb9ea ET |
83 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
84 | ||
24e3fcef | 85 | MODULE_AUTHOR("Eliezer Tamir"); |
f2e0899f | 86 | MODULE_DESCRIPTION("Broadcom NetXtreme II " |
619c5cb6 VZ |
87 | "BCM57710/57711/57711E/" |
88 | "57712/57712_MF/57800/57800_MF/57810/57810_MF/" | |
89 | "57840/57840_MF Driver"); | |
a2fbb9ea ET |
90 | MODULE_LICENSE("GPL"); |
91 | MODULE_VERSION(DRV_MODULE_VERSION); | |
45229b42 BH |
92 | MODULE_FIRMWARE(FW_FILE_NAME_E1); |
93 | MODULE_FIRMWARE(FW_FILE_NAME_E1H); | |
f2e0899f | 94 | MODULE_FIRMWARE(FW_FILE_NAME_E2); |
a2fbb9ea | 95 | |
d6214d7a | 96 | int num_queues; |
54b9ddaa | 97 | module_param(num_queues, int, 0); |
96305234 DK |
98 | MODULE_PARM_DESC(num_queues, |
99 | " Set number of queues (default is as a number of CPUs)"); | |
555f6c78 | 100 | |
19680c48 | 101 | static int disable_tpa; |
19680c48 | 102 | module_param(disable_tpa, int, 0); |
9898f86d | 103 | MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); |
8badd27a | 104 | |
0e8d2ec5 | 105 | int int_mode; |
8badd27a | 106 | module_param(int_mode, int, 0); |
619c5cb6 | 107 | MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X " |
cdaa7cb8 | 108 | "(1 INT#x; 2 MSI)"); |
8badd27a | 109 | |
a18f5128 EG |
110 | static int dropless_fc; |
111 | module_param(dropless_fc, int, 0); | |
112 | MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); | |
113 | ||
8d5726c4 EG |
114 | static int mrrs = -1; |
115 | module_param(mrrs, int, 0); | |
116 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); | |
117 | ||
9898f86d | 118 | static int debug; |
a2fbb9ea | 119 | module_param(debug, int, 0); |
9898f86d EG |
120 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
121 | ||
619c5cb6 | 122 | struct workqueue_struct *bnx2x_wq; |
ec6ba945 | 123 | |
1ef1d45a BW |
124 | struct bnx2x_mac_vals { |
125 | u32 xmac_addr; | |
126 | u32 xmac_val; | |
127 | u32 emac_addr; | |
128 | u32 emac_val; | |
129 | u32 umac_addr; | |
130 | u32 umac_val; | |
131 | u32 bmac_addr; | |
132 | u32 bmac_val[2]; | |
133 | }; | |
134 | ||
a2fbb9ea ET |
135 | enum bnx2x_board_type { |
136 | BCM57710 = 0, | |
619c5cb6 VZ |
137 | BCM57711, |
138 | BCM57711E, | |
139 | BCM57712, | |
140 | BCM57712_MF, | |
1ab4434c | 141 | BCM57712_VF, |
619c5cb6 VZ |
142 | BCM57800, |
143 | BCM57800_MF, | |
1ab4434c | 144 | BCM57800_VF, |
619c5cb6 VZ |
145 | BCM57810, |
146 | BCM57810_MF, | |
1ab4434c | 147 | BCM57810_VF, |
c3def943 YM |
148 | BCM57840_4_10, |
149 | BCM57840_2_20, | |
7e8e02df | 150 | BCM57840_MF, |
1ab4434c | 151 | BCM57840_VF, |
7e8e02df | 152 | BCM57811, |
1ab4434c AE |
153 | BCM57811_MF, |
154 | BCM57840_O, | |
155 | BCM57840_MFO, | |
156 | BCM57811_VF | |
a2fbb9ea ET |
157 | }; |
158 | ||
34f80b04 | 159 | /* indexed by board_type, above */ |
53a10565 | 160 | static struct { |
a2fbb9ea | 161 | char *name; |
0329aba1 | 162 | } board_info[] = { |
1ab4434c AE |
163 | [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" }, |
164 | [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" }, | |
165 | [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" }, | |
166 | [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" }, | |
167 | [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" }, | |
168 | [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" }, | |
169 | [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" }, | |
170 | [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" }, | |
171 | [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" }, | |
172 | [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" }, | |
173 | [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" }, | |
174 | [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" }, | |
175 | [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" }, | |
176 | [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" }, | |
177 | [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" }, | |
178 | [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }, | |
179 | [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" }, | |
180 | [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" }, | |
181 | [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" }, | |
182 | [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" }, | |
183 | [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" } | |
a2fbb9ea ET |
184 | }; |
185 | ||
619c5cb6 VZ |
186 | #ifndef PCI_DEVICE_ID_NX2_57710 |
187 | #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710 | |
188 | #endif | |
189 | #ifndef PCI_DEVICE_ID_NX2_57711 | |
190 | #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711 | |
191 | #endif | |
192 | #ifndef PCI_DEVICE_ID_NX2_57711E | |
193 | #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E | |
194 | #endif | |
195 | #ifndef PCI_DEVICE_ID_NX2_57712 | |
196 | #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712 | |
197 | #endif | |
198 | #ifndef PCI_DEVICE_ID_NX2_57712_MF | |
199 | #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF | |
200 | #endif | |
8395be5e AE |
201 | #ifndef PCI_DEVICE_ID_NX2_57712_VF |
202 | #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF | |
203 | #endif | |
619c5cb6 VZ |
204 | #ifndef PCI_DEVICE_ID_NX2_57800 |
205 | #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800 | |
206 | #endif | |
207 | #ifndef PCI_DEVICE_ID_NX2_57800_MF | |
208 | #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF | |
209 | #endif | |
8395be5e AE |
210 | #ifndef PCI_DEVICE_ID_NX2_57800_VF |
211 | #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF | |
212 | #endif | |
619c5cb6 VZ |
213 | #ifndef PCI_DEVICE_ID_NX2_57810 |
214 | #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810 | |
215 | #endif | |
216 | #ifndef PCI_DEVICE_ID_NX2_57810_MF | |
217 | #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF | |
218 | #endif | |
c3def943 YM |
219 | #ifndef PCI_DEVICE_ID_NX2_57840_O |
220 | #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE | |
221 | #endif | |
8395be5e AE |
222 | #ifndef PCI_DEVICE_ID_NX2_57810_VF |
223 | #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF | |
224 | #endif | |
c3def943 YM |
225 | #ifndef PCI_DEVICE_ID_NX2_57840_4_10 |
226 | #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10 | |
227 | #endif | |
228 | #ifndef PCI_DEVICE_ID_NX2_57840_2_20 | |
229 | #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20 | |
230 | #endif | |
231 | #ifndef PCI_DEVICE_ID_NX2_57840_MFO | |
232 | #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE | |
619c5cb6 VZ |
233 | #endif |
234 | #ifndef PCI_DEVICE_ID_NX2_57840_MF | |
235 | #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF | |
236 | #endif | |
8395be5e AE |
237 | #ifndef PCI_DEVICE_ID_NX2_57840_VF |
238 | #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF | |
239 | #endif | |
7e8e02df BW |
240 | #ifndef PCI_DEVICE_ID_NX2_57811 |
241 | #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811 | |
242 | #endif | |
243 | #ifndef PCI_DEVICE_ID_NX2_57811_MF | |
244 | #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF | |
245 | #endif | |
8395be5e AE |
246 | #ifndef PCI_DEVICE_ID_NX2_57811_VF |
247 | #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF | |
248 | #endif | |
249 | ||
a3aa1884 | 250 | static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = { |
e4ed7113 EG |
251 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, |
252 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, | |
253 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E }, | |
f2e0899f | 254 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 }, |
619c5cb6 | 255 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF }, |
8395be5e | 256 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF }, |
619c5cb6 VZ |
257 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 }, |
258 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF }, | |
8395be5e | 259 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF }, |
619c5cb6 VZ |
260 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 }, |
261 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF }, | |
c3def943 YM |
262 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O }, |
263 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 }, | |
264 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 }, | |
8395be5e | 265 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF }, |
c3def943 | 266 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO }, |
619c5cb6 | 267 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF }, |
8395be5e | 268 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF }, |
7e8e02df BW |
269 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 }, |
270 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF }, | |
8395be5e | 271 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF }, |
a2fbb9ea ET |
272 | { 0 } |
273 | }; | |
274 | ||
275 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); | |
276 | ||
452427b0 YM |
277 | /* Global resources for unloading a previously loaded device */ |
278 | #define BNX2X_PREV_WAIT_NEEDED 1 | |
279 | static DEFINE_SEMAPHORE(bnx2x_prev_sem); | |
280 | static LIST_HEAD(bnx2x_prev_list); | |
a2fbb9ea ET |
281 | /**************************************************************************** |
282 | * General service functions | |
283 | ****************************************************************************/ | |
284 | ||
1191cb83 | 285 | static void __storm_memset_dma_mapping(struct bnx2x *bp, |
619c5cb6 VZ |
286 | u32 addr, dma_addr_t mapping) |
287 | { | |
288 | REG_WR(bp, addr, U64_LO(mapping)); | |
289 | REG_WR(bp, addr + 4, U64_HI(mapping)); | |
290 | } | |
291 | ||
1191cb83 ED |
292 | static void storm_memset_spq_addr(struct bnx2x *bp, |
293 | dma_addr_t mapping, u16 abs_fid) | |
619c5cb6 VZ |
294 | { |
295 | u32 addr = XSEM_REG_FAST_MEMORY + | |
296 | XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid); | |
297 | ||
298 | __storm_memset_dma_mapping(bp, addr, mapping); | |
299 | } | |
300 | ||
1191cb83 ED |
301 | static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid, |
302 | u16 pf_id) | |
523224a3 | 303 | { |
619c5cb6 VZ |
304 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid), |
305 | pf_id); | |
306 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid), | |
307 | pf_id); | |
308 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid), | |
309 | pf_id); | |
310 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid), | |
311 | pf_id); | |
523224a3 DK |
312 | } |
313 | ||
1191cb83 ED |
314 | static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid, |
315 | u8 enable) | |
619c5cb6 VZ |
316 | { |
317 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid), | |
318 | enable); | |
319 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid), | |
320 | enable); | |
321 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid), | |
322 | enable); | |
323 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid), | |
324 | enable); | |
325 | } | |
523224a3 | 326 | |
1191cb83 ED |
327 | static void storm_memset_eq_data(struct bnx2x *bp, |
328 | struct event_ring_data *eq_data, | |
523224a3 DK |
329 | u16 pfid) |
330 | { | |
331 | size_t size = sizeof(struct event_ring_data); | |
332 | ||
333 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid); | |
334 | ||
335 | __storm_memset_struct(bp, addr, size, (u32 *)eq_data); | |
336 | } | |
337 | ||
1191cb83 ED |
338 | static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod, |
339 | u16 pfid) | |
523224a3 DK |
340 | { |
341 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid); | |
342 | REG_WR16(bp, addr, eq_prod); | |
343 | } | |
344 | ||
a2fbb9ea ET |
345 | /* used only at init |
346 | * locking is done by mcp | |
347 | */ | |
8d96286a | 348 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
a2fbb9ea ET |
349 | { |
350 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
351 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); | |
352 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
353 | PCICFG_VENDOR_ID_OFFSET); | |
354 | } | |
355 | ||
a2fbb9ea ET |
356 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
357 | { | |
358 | u32 val; | |
359 | ||
360 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
361 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); | |
362 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
363 | PCICFG_VENDOR_ID_OFFSET); | |
364 | ||
365 | return val; | |
366 | } | |
a2fbb9ea | 367 | |
f2e0899f DK |
368 | #define DMAE_DP_SRC_GRC "grc src_addr [%08x]" |
369 | #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]" | |
370 | #define DMAE_DP_DST_GRC "grc dst_addr [%08x]" | |
371 | #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]" | |
372 | #define DMAE_DP_DST_NONE "dst_addr [none]" | |
373 | ||
6bf07b8e YM |
374 | static void bnx2x_dp_dmae(struct bnx2x *bp, |
375 | struct dmae_command *dmae, int msglvl) | |
fd1fc79d AE |
376 | { |
377 | u32 src_type = dmae->opcode & DMAE_COMMAND_SRC; | |
6bf07b8e | 378 | int i; |
fd1fc79d AE |
379 | |
380 | switch (dmae->opcode & DMAE_COMMAND_DST) { | |
381 | case DMAE_CMD_DST_PCI: | |
382 | if (src_type == DMAE_CMD_SRC_PCI) | |
383 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
384 | "src [%x:%08x], len [%d*4], dst [%x:%08x]\n" | |
385 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
386 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
387 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
388 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
389 | dmae->comp_val); | |
390 | else | |
391 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
392 | "src [%08x], len [%d*4], dst [%x:%08x]\n" | |
393 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
394 | dmae->opcode, dmae->src_addr_lo >> 2, | |
395 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
396 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
397 | dmae->comp_val); | |
398 | break; | |
399 | case DMAE_CMD_DST_GRC: | |
400 | if (src_type == DMAE_CMD_SRC_PCI) | |
401 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
402 | "src [%x:%08x], len [%d*4], dst_addr [%08x]\n" | |
403 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
404 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
405 | dmae->len, dmae->dst_addr_lo >> 2, | |
406 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
407 | dmae->comp_val); | |
408 | else | |
409 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
410 | "src [%08x], len [%d*4], dst [%08x]\n" | |
411 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
412 | dmae->opcode, dmae->src_addr_lo >> 2, | |
413 | dmae->len, dmae->dst_addr_lo >> 2, | |
414 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
415 | dmae->comp_val); | |
416 | break; | |
417 | default: | |
418 | if (src_type == DMAE_CMD_SRC_PCI) | |
419 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
420 | "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n" | |
421 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
422 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
423 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
424 | dmae->comp_val); | |
425 | else | |
426 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
427 | "src_addr [%08x] len [%d * 4] dst_addr [none]\n" | |
428 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
429 | dmae->opcode, dmae->src_addr_lo >> 2, | |
430 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
431 | dmae->comp_val); | |
432 | break; | |
433 | } | |
6bf07b8e YM |
434 | |
435 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) | |
436 | DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n", | |
437 | i, *(((u32 *)dmae) + i)); | |
fd1fc79d | 438 | } |
f2e0899f | 439 | |
a2fbb9ea | 440 | /* copy command into DMAE command memory and set DMAE command go */ |
6c719d00 | 441 | void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx) |
a2fbb9ea ET |
442 | { |
443 | u32 cmd_offset; | |
444 | int i; | |
445 | ||
446 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); | |
447 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { | |
448 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); | |
a2fbb9ea ET |
449 | } |
450 | REG_WR(bp, dmae_reg_go_c[idx], 1); | |
451 | } | |
452 | ||
f2e0899f | 453 | u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type) |
a2fbb9ea | 454 | { |
f2e0899f DK |
455 | return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) | |
456 | DMAE_CMD_C_ENABLE); | |
457 | } | |
ad8d3948 | 458 | |
f2e0899f DK |
459 | u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode) |
460 | { | |
461 | return opcode & ~DMAE_CMD_SRC_RESET; | |
462 | } | |
ad8d3948 | 463 | |
f2e0899f DK |
464 | u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type, |
465 | bool with_comp, u8 comp_type) | |
466 | { | |
467 | u32 opcode = 0; | |
468 | ||
469 | opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) | | |
470 | (dst_type << DMAE_COMMAND_DST_SHIFT)); | |
ad8d3948 | 471 | |
f2e0899f DK |
472 | opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET); |
473 | ||
474 | opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0); | |
3395a033 DK |
475 | opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) | |
476 | (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT)); | |
f2e0899f | 477 | opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT); |
a2fbb9ea | 478 | |
a2fbb9ea | 479 | #ifdef __BIG_ENDIAN |
f2e0899f | 480 | opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP; |
a2fbb9ea | 481 | #else |
f2e0899f | 482 | opcode |= DMAE_CMD_ENDIANITY_DW_SWAP; |
a2fbb9ea | 483 | #endif |
f2e0899f DK |
484 | if (with_comp) |
485 | opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type); | |
486 | return opcode; | |
487 | } | |
488 | ||
fd1fc79d | 489 | void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, |
8d96286a | 490 | struct dmae_command *dmae, |
491 | u8 src_type, u8 dst_type) | |
f2e0899f DK |
492 | { |
493 | memset(dmae, 0, sizeof(struct dmae_command)); | |
494 | ||
495 | /* set the opcode */ | |
496 | dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type, | |
497 | true, DMAE_COMP_PCI); | |
498 | ||
499 | /* fill in the completion parameters */ | |
500 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); | |
501 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); | |
502 | dmae->comp_val = DMAE_COMP_VAL; | |
503 | } | |
504 | ||
fd1fc79d | 505 | /* issue a dmae command over the init-channel and wait for completion */ |
32316a46 AE |
506 | int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae, |
507 | u32 *comp) | |
f2e0899f | 508 | { |
5e374b5a | 509 | int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000; |
f2e0899f DK |
510 | int rc = 0; |
511 | ||
6bf07b8e YM |
512 | bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE); |
513 | ||
514 | /* Lock the dmae channel. Disable BHs to prevent a dead-lock | |
619c5cb6 VZ |
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 */ |
32316a46 | 521 | *comp = 0; |
a2fbb9ea | 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); |
32316a46 | 528 | while ((*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 | } |
32316a46 | 540 | if (*comp & DMAE_PCI_ERR_FLAG) { |
f2e0899f DK |
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 | { | |
6bf07b8e | 553 | int rc; |
f2e0899f DK |
554 | struct dmae_command dmae; |
555 | ||
556 | if (!bp->dmae_ready) { | |
557 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
558 | ||
127a425e AE |
559 | if (CHIP_IS_E1(bp)) |
560 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); | |
561 | else | |
562 | bnx2x_init_str_wr(bp, dst_addr, data, len32); | |
f2e0899f DK |
563 | return; |
564 | } | |
565 | ||
566 | /* set opcode and fixed command fields */ | |
567 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC); | |
568 | ||
569 | /* fill in addresses and len */ | |
570 | dmae.src_addr_lo = U64_LO(dma_addr); | |
571 | dmae.src_addr_hi = U64_HI(dma_addr); | |
572 | dmae.dst_addr_lo = dst_addr >> 2; | |
573 | dmae.dst_addr_hi = 0; | |
574 | dmae.len = len32; | |
575 | ||
f2e0899f | 576 | /* issue the command and wait for completion */ |
32316a46 | 577 | rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp)); |
6bf07b8e YM |
578 | if (rc) { |
579 | BNX2X_ERR("DMAE returned failure %d\n", rc); | |
9dcd9acd | 580 | #ifdef BNX2X_STOP_ON_ERROR |
6bf07b8e | 581 | bnx2x_panic(); |
9dcd9acd | 582 | #endif |
6bf07b8e | 583 | } |
a2fbb9ea ET |
584 | } |
585 | ||
c18487ee | 586 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
a2fbb9ea | 587 | { |
6bf07b8e | 588 | int rc; |
5ff7b6d4 | 589 | struct dmae_command dmae; |
ad8d3948 EG |
590 | |
591 | if (!bp->dmae_ready) { | |
592 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
593 | int i; | |
594 | ||
51c1a580 | 595 | if (CHIP_IS_E1(bp)) |
127a425e AE |
596 | for (i = 0; i < len32; i++) |
597 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); | |
51c1a580 | 598 | else |
127a425e AE |
599 | for (i = 0; i < len32; i++) |
600 | data[i] = REG_RD(bp, src_addr + i*4); | |
601 | ||
ad8d3948 EG |
602 | return; |
603 | } | |
604 | ||
f2e0899f DK |
605 | /* set opcode and fixed command fields */ |
606 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI); | |
a2fbb9ea | 607 | |
f2e0899f | 608 | /* fill in addresses and len */ |
5ff7b6d4 EG |
609 | dmae.src_addr_lo = src_addr >> 2; |
610 | dmae.src_addr_hi = 0; | |
611 | dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); | |
612 | dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); | |
613 | dmae.len = len32; | |
ad8d3948 | 614 | |
f2e0899f | 615 | /* issue the command and wait for completion */ |
32316a46 | 616 | rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp)); |
6bf07b8e YM |
617 | if (rc) { |
618 | BNX2X_ERR("DMAE returned failure %d\n", rc); | |
9dcd9acd | 619 | #ifdef BNX2X_STOP_ON_ERROR |
6bf07b8e | 620 | bnx2x_panic(); |
9dcd9acd | 621 | #endif |
c957d09f | 622 | } |
ad8d3948 EG |
623 | } |
624 | ||
8d96286a | 625 | static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, |
626 | u32 addr, u32 len) | |
573f2035 | 627 | { |
02e3c6cb | 628 | int dmae_wr_max = DMAE_LEN32_WR_MAX(bp); |
573f2035 EG |
629 | int offset = 0; |
630 | ||
02e3c6cb | 631 | while (len > dmae_wr_max) { |
573f2035 | 632 | bnx2x_write_dmae(bp, phys_addr + offset, |
02e3c6cb VZ |
633 | addr + offset, dmae_wr_max); |
634 | offset += dmae_wr_max * 4; | |
635 | len -= dmae_wr_max; | |
573f2035 EG |
636 | } |
637 | ||
638 | bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len); | |
639 | } | |
640 | ||
a2fbb9ea ET |
641 | static int bnx2x_mc_assert(struct bnx2x *bp) |
642 | { | |
a2fbb9ea | 643 | char last_idx; |
34f80b04 EG |
644 | int i, rc = 0; |
645 | u32 row0, row1, row2, row3; | |
646 | ||
647 | /* XSTORM */ | |
648 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + | |
649 | XSTORM_ASSERT_LIST_INDEX_OFFSET); | |
650 | if (last_idx) | |
651 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
652 | ||
653 | /* print the asserts */ | |
654 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
655 | ||
656 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
657 | XSTORM_ASSERT_LIST_OFFSET(i)); | |
658 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
659 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
660 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
661 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
662 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
663 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
664 | ||
665 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 666 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
667 | i, row3, row2, row1, row0); |
668 | rc++; | |
669 | } else { | |
670 | break; | |
671 | } | |
672 | } | |
673 | ||
674 | /* TSTORM */ | |
675 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + | |
676 | TSTORM_ASSERT_LIST_INDEX_OFFSET); | |
677 | if (last_idx) | |
678 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
679 | ||
680 | /* print the asserts */ | |
681 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
682 | ||
683 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
684 | TSTORM_ASSERT_LIST_OFFSET(i)); | |
685 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
686 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
687 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
688 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
689 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
690 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
691 | ||
692 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 693 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
694 | i, row3, row2, row1, row0); |
695 | rc++; | |
696 | } else { | |
697 | break; | |
698 | } | |
699 | } | |
700 | ||
701 | /* CSTORM */ | |
702 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + | |
703 | CSTORM_ASSERT_LIST_INDEX_OFFSET); | |
704 | if (last_idx) | |
705 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
706 | ||
707 | /* print the asserts */ | |
708 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
709 | ||
710 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
711 | CSTORM_ASSERT_LIST_OFFSET(i)); | |
712 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
713 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
714 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
715 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
716 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
717 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
718 | ||
719 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 720 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
721 | i, row3, row2, row1, row0); |
722 | rc++; | |
723 | } else { | |
724 | break; | |
725 | } | |
726 | } | |
727 | ||
728 | /* USTORM */ | |
729 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + | |
730 | USTORM_ASSERT_LIST_INDEX_OFFSET); | |
731 | if (last_idx) | |
732 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
733 | ||
734 | /* print the asserts */ | |
735 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
736 | ||
737 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
738 | USTORM_ASSERT_LIST_OFFSET(i)); | |
739 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
740 | USTORM_ASSERT_LIST_OFFSET(i) + 4); | |
741 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
742 | USTORM_ASSERT_LIST_OFFSET(i) + 8); | |
743 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
744 | USTORM_ASSERT_LIST_OFFSET(i) + 12); | |
745 | ||
746 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 747 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
748 | i, row3, row2, row1, row0); |
749 | rc++; | |
750 | } else { | |
751 | break; | |
a2fbb9ea ET |
752 | } |
753 | } | |
34f80b04 | 754 | |
a2fbb9ea ET |
755 | return rc; |
756 | } | |
c14423fe | 757 | |
1a6974b2 YM |
758 | #define MCPR_TRACE_BUFFER_SIZE (0x800) |
759 | #define SCRATCH_BUFFER_SIZE(bp) \ | |
760 | (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000)) | |
761 | ||
7a25cc73 | 762 | void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl) |
a2fbb9ea | 763 | { |
7a25cc73 | 764 | u32 addr, val; |
a2fbb9ea | 765 | u32 mark, offset; |
4781bfad | 766 | __be32 data[9]; |
a2fbb9ea | 767 | int word; |
f2e0899f | 768 | u32 trace_shmem_base; |
2145a920 VZ |
769 | if (BP_NOMCP(bp)) { |
770 | BNX2X_ERR("NO MCP - can not dump\n"); | |
771 | return; | |
772 | } | |
7a25cc73 DK |
773 | netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n", |
774 | (bp->common.bc_ver & 0xff0000) >> 16, | |
775 | (bp->common.bc_ver & 0xff00) >> 8, | |
776 | (bp->common.bc_ver & 0xff)); | |
777 | ||
778 | val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER); | |
779 | if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER)) | |
51c1a580 | 780 | BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val); |
cdaa7cb8 | 781 | |
f2e0899f DK |
782 | if (BP_PATH(bp) == 0) |
783 | trace_shmem_base = bp->common.shmem_base; | |
784 | else | |
785 | trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr); | |
1a6974b2 YM |
786 | |
787 | /* sanity */ | |
788 | if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE || | |
789 | trace_shmem_base >= MCPR_SCRATCH_BASE(bp) + | |
790 | SCRATCH_BUFFER_SIZE(bp)) { | |
791 | BNX2X_ERR("Unable to dump trace buffer (mark %x)\n", | |
792 | trace_shmem_base); | |
793 | return; | |
794 | } | |
795 | ||
796 | addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE; | |
de128804 DK |
797 | |
798 | /* validate TRCB signature */ | |
799 | mark = REG_RD(bp, addr); | |
800 | if (mark != MFW_TRACE_SIGNATURE) { | |
801 | BNX2X_ERR("Trace buffer signature is missing."); | |
802 | return ; | |
803 | } | |
804 | ||
805 | /* read cyclic buffer pointer */ | |
806 | addr += 4; | |
cdaa7cb8 | 807 | mark = REG_RD(bp, addr); |
1a6974b2 YM |
808 | mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000; |
809 | if (mark >= trace_shmem_base || mark < addr + 4) { | |
810 | BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n"); | |
811 | return; | |
812 | } | |
7a25cc73 | 813 | printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark); |
a2fbb9ea | 814 | |
7a25cc73 | 815 | printk("%s", lvl); |
2de67439 YM |
816 | |
817 | /* dump buffer after the mark */ | |
1a6974b2 | 818 | for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) { |
a2fbb9ea | 819 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 820 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 821 | data[8] = 0x0; |
7995c64e | 822 | pr_cont("%s", (char *)data); |
a2fbb9ea | 823 | } |
2de67439 YM |
824 | |
825 | /* dump buffer before the mark */ | |
cdaa7cb8 | 826 | for (offset = addr + 4; offset <= mark; offset += 0x8*4) { |
a2fbb9ea | 827 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 828 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 829 | data[8] = 0x0; |
7995c64e | 830 | pr_cont("%s", (char *)data); |
a2fbb9ea | 831 | } |
7a25cc73 DK |
832 | printk("%s" "end of fw dump\n", lvl); |
833 | } | |
834 | ||
1191cb83 | 835 | static void bnx2x_fw_dump(struct bnx2x *bp) |
7a25cc73 DK |
836 | { |
837 | bnx2x_fw_dump_lvl(bp, KERN_ERR); | |
a2fbb9ea ET |
838 | } |
839 | ||
823e1d90 YM |
840 | static void bnx2x_hc_int_disable(struct bnx2x *bp) |
841 | { | |
842 | int port = BP_PORT(bp); | |
843 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; | |
844 | u32 val = REG_RD(bp, addr); | |
845 | ||
846 | /* in E1 we must use only PCI configuration space to disable | |
16a5fd92 YM |
847 | * MSI/MSIX capability |
848 | * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block | |
823e1d90 YM |
849 | */ |
850 | if (CHIP_IS_E1(bp)) { | |
851 | /* Since IGU_PF_CONF_MSI_MSIX_EN still always on | |
852 | * Use mask register to prevent from HC sending interrupts | |
853 | * after we exit the function | |
854 | */ | |
855 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0); | |
856 | ||
857 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
858 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
859 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
860 | } else | |
861 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
862 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
863 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
864 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
865 | ||
866 | DP(NETIF_MSG_IFDOWN, | |
867 | "write %x to HC %d (addr 0x%x)\n", | |
868 | val, port, addr); | |
869 | ||
870 | /* flush all outstanding writes */ | |
871 | mmiowb(); | |
872 | ||
873 | REG_WR(bp, addr, val); | |
874 | if (REG_RD(bp, addr) != val) | |
6bf07b8e | 875 | BNX2X_ERR("BUG! Proper val not read from IGU!\n"); |
823e1d90 YM |
876 | } |
877 | ||
878 | static void bnx2x_igu_int_disable(struct bnx2x *bp) | |
879 | { | |
880 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
881 | ||
882 | val &= ~(IGU_PF_CONF_MSI_MSIX_EN | | |
883 | IGU_PF_CONF_INT_LINE_EN | | |
884 | IGU_PF_CONF_ATTN_BIT_EN); | |
885 | ||
886 | DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val); | |
887 | ||
888 | /* flush all outstanding writes */ | |
889 | mmiowb(); | |
890 | ||
891 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
892 | if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val) | |
6bf07b8e | 893 | BNX2X_ERR("BUG! Proper val not read from IGU!\n"); |
823e1d90 YM |
894 | } |
895 | ||
896 | static void bnx2x_int_disable(struct bnx2x *bp) | |
897 | { | |
898 | if (bp->common.int_block == INT_BLOCK_HC) | |
899 | bnx2x_hc_int_disable(bp); | |
900 | else | |
901 | bnx2x_igu_int_disable(bp); | |
902 | } | |
903 | ||
904 | void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int) | |
a2fbb9ea ET |
905 | { |
906 | int i; | |
523224a3 DK |
907 | u16 j; |
908 | struct hc_sp_status_block_data sp_sb_data; | |
909 | int func = BP_FUNC(bp); | |
910 | #ifdef BNX2X_STOP_ON_ERROR | |
911 | u16 start = 0, end = 0; | |
6383c0b3 | 912 | u8 cos; |
523224a3 | 913 | #endif |
823e1d90 YM |
914 | if (disable_int) |
915 | bnx2x_int_disable(bp); | |
a2fbb9ea | 916 | |
66e855f3 | 917 | bp->stats_state = STATS_STATE_DISABLED; |
7a752993 | 918 | bp->eth_stats.unrecoverable_error++; |
66e855f3 YG |
919 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
920 | ||
a2fbb9ea ET |
921 | BNX2X_ERR("begin crash dump -----------------\n"); |
922 | ||
8440d2b6 EG |
923 | /* Indices */ |
924 | /* Common */ | |
51c1a580 | 925 | 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 |
926 | bp->def_idx, bp->def_att_idx, bp->attn_state, |
927 | bp->spq_prod_idx, bp->stats_counter); | |
523224a3 DK |
928 | BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n", |
929 | bp->def_status_blk->atten_status_block.attn_bits, | |
930 | bp->def_status_blk->atten_status_block.attn_bits_ack, | |
931 | bp->def_status_blk->atten_status_block.status_block_id, | |
932 | bp->def_status_blk->atten_status_block.attn_bits_index); | |
933 | BNX2X_ERR(" def ("); | |
934 | for (i = 0; i < HC_SP_SB_MAX_INDICES; i++) | |
935 | pr_cont("0x%x%s", | |
f1deab50 JP |
936 | bp->def_status_blk->sp_sb.index_values[i], |
937 | (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " "); | |
523224a3 DK |
938 | |
939 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
940 | *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
941 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
942 | i*sizeof(u32)); | |
943 | ||
f1deab50 | 944 | 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 |
945 | sp_sb_data.igu_sb_id, |
946 | sp_sb_data.igu_seg_id, | |
947 | sp_sb_data.p_func.pf_id, | |
948 | sp_sb_data.p_func.vnic_id, | |
949 | sp_sb_data.p_func.vf_id, | |
619c5cb6 VZ |
950 | sp_sb_data.p_func.vf_valid, |
951 | sp_sb_data.state); | |
523224a3 | 952 | |
ec6ba945 | 953 | for_each_eth_queue(bp, i) { |
a2fbb9ea | 954 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
523224a3 | 955 | int loop; |
f2e0899f | 956 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
957 | struct hc_status_block_data_e1x sb_data_e1x; |
958 | struct hc_status_block_sm *hc_sm_p = | |
619c5cb6 VZ |
959 | CHIP_IS_E1x(bp) ? |
960 | sb_data_e1x.common.state_machine : | |
961 | sb_data_e2.common.state_machine; | |
523224a3 | 962 | struct hc_index_data *hc_index_p = |
619c5cb6 VZ |
963 | CHIP_IS_E1x(bp) ? |
964 | sb_data_e1x.index_data : | |
965 | sb_data_e2.index_data; | |
6383c0b3 | 966 | u8 data_size, cos; |
523224a3 | 967 | u32 *sb_data_p; |
6383c0b3 | 968 | struct bnx2x_fp_txdata txdata; |
523224a3 DK |
969 | |
970 | /* Rx */ | |
51c1a580 | 971 | 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 | 972 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
523224a3 | 973 | fp->rx_comp_prod, |
66e855f3 | 974 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
51c1a580 | 975 | BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n", |
8440d2b6 | 976 | fp->rx_sge_prod, fp->last_max_sge, |
523224a3 | 977 | le16_to_cpu(fp->fp_hc_idx)); |
a2fbb9ea | 978 | |
523224a3 | 979 | /* Tx */ |
6383c0b3 AE |
980 | for_each_cos_in_tx_queue(fp, cos) |
981 | { | |
65565884 | 982 | txdata = *fp->txdata_ptr[cos]; |
51c1a580 | 983 | 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 |
984 | i, txdata.tx_pkt_prod, |
985 | txdata.tx_pkt_cons, txdata.tx_bd_prod, | |
986 | txdata.tx_bd_cons, | |
987 | le16_to_cpu(*txdata.tx_cons_sb)); | |
988 | } | |
523224a3 | 989 | |
619c5cb6 VZ |
990 | loop = CHIP_IS_E1x(bp) ? |
991 | HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2; | |
523224a3 DK |
992 | |
993 | /* host sb data */ | |
994 | ||
ec6ba945 VZ |
995 | if (IS_FCOE_FP(fp)) |
996 | continue; | |
55c11941 | 997 | |
523224a3 DK |
998 | BNX2X_ERR(" run indexes ("); |
999 | for (j = 0; j < HC_SB_MAX_SM; j++) | |
1000 | pr_cont("0x%x%s", | |
1001 | fp->sb_running_index[j], | |
1002 | (j == HC_SB_MAX_SM - 1) ? ")" : " "); | |
1003 | ||
1004 | BNX2X_ERR(" indexes ("); | |
1005 | for (j = 0; j < loop; j++) | |
1006 | pr_cont("0x%x%s", | |
1007 | fp->sb_index_values[j], | |
1008 | (j == loop - 1) ? ")" : " "); | |
1009 | /* fw sb data */ | |
619c5cb6 VZ |
1010 | data_size = CHIP_IS_E1x(bp) ? |
1011 | sizeof(struct hc_status_block_data_e1x) : | |
1012 | sizeof(struct hc_status_block_data_e2); | |
523224a3 | 1013 | data_size /= sizeof(u32); |
619c5cb6 VZ |
1014 | sb_data_p = CHIP_IS_E1x(bp) ? |
1015 | (u32 *)&sb_data_e1x : | |
1016 | (u32 *)&sb_data_e2; | |
523224a3 DK |
1017 | /* copy sb data in here */ |
1018 | for (j = 0; j < data_size; j++) | |
1019 | *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
1020 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) + | |
1021 | j * sizeof(u32)); | |
1022 | ||
619c5cb6 | 1023 | if (!CHIP_IS_E1x(bp)) { |
51c1a580 | 1024 | 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 |
1025 | sb_data_e2.common.p_func.pf_id, |
1026 | sb_data_e2.common.p_func.vf_id, | |
1027 | sb_data_e2.common.p_func.vf_valid, | |
1028 | sb_data_e2.common.p_func.vnic_id, | |
619c5cb6 VZ |
1029 | sb_data_e2.common.same_igu_sb_1b, |
1030 | sb_data_e2.common.state); | |
f2e0899f | 1031 | } else { |
51c1a580 | 1032 | 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 |
1033 | sb_data_e1x.common.p_func.pf_id, |
1034 | sb_data_e1x.common.p_func.vf_id, | |
1035 | sb_data_e1x.common.p_func.vf_valid, | |
1036 | sb_data_e1x.common.p_func.vnic_id, | |
619c5cb6 VZ |
1037 | sb_data_e1x.common.same_igu_sb_1b, |
1038 | sb_data_e1x.common.state); | |
f2e0899f | 1039 | } |
523224a3 DK |
1040 | |
1041 | /* SB_SMs data */ | |
1042 | for (j = 0; j < HC_SB_MAX_SM; j++) { | |
51c1a580 MS |
1043 | 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", |
1044 | j, hc_sm_p[j].__flags, | |
1045 | hc_sm_p[j].igu_sb_id, | |
1046 | hc_sm_p[j].igu_seg_id, | |
1047 | hc_sm_p[j].time_to_expire, | |
1048 | hc_sm_p[j].timer_value); | |
523224a3 DK |
1049 | } |
1050 | ||
16a5fd92 | 1051 | /* Indices data */ |
523224a3 | 1052 | for (j = 0; j < loop; j++) { |
51c1a580 | 1053 | pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j, |
523224a3 DK |
1054 | hc_index_p[j].flags, |
1055 | hc_index_p[j].timeout); | |
1056 | } | |
8440d2b6 | 1057 | } |
a2fbb9ea | 1058 | |
523224a3 | 1059 | #ifdef BNX2X_STOP_ON_ERROR |
04c46736 YM |
1060 | |
1061 | /* event queue */ | |
6bf07b8e | 1062 | BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod); |
04c46736 YM |
1063 | for (i = 0; i < NUM_EQ_DESC; i++) { |
1064 | u32 *data = (u32 *)&bp->eq_ring[i].message.data; | |
1065 | ||
1066 | BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n", | |
1067 | i, bp->eq_ring[i].message.opcode, | |
1068 | bp->eq_ring[i].message.error); | |
1069 | BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]); | |
1070 | } | |
1071 | ||
8440d2b6 EG |
1072 | /* Rings */ |
1073 | /* Rx */ | |
55c11941 | 1074 | for_each_valid_rx_queue(bp, i) { |
8440d2b6 | 1075 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea ET |
1076 | |
1077 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); | |
1078 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); | |
8440d2b6 | 1079 | for (j = start; j != end; j = RX_BD(j + 1)) { |
a2fbb9ea ET |
1080 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
1081 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; | |
1082 | ||
c3eefaf6 | 1083 | BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
44151acb | 1084 | i, j, rx_bd[1], rx_bd[0], sw_bd->data); |
a2fbb9ea ET |
1085 | } |
1086 | ||
3196a88a EG |
1087 | start = RX_SGE(fp->rx_sge_prod); |
1088 | end = RX_SGE(fp->last_max_sge); | |
8440d2b6 | 1089 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
7a9b2557 VZ |
1090 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
1091 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; | |
1092 | ||
c3eefaf6 EG |
1093 | BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
1094 | i, j, rx_sge[1], rx_sge[0], sw_page->page); | |
7a9b2557 VZ |
1095 | } |
1096 | ||
a2fbb9ea ET |
1097 | start = RCQ_BD(fp->rx_comp_cons - 10); |
1098 | end = RCQ_BD(fp->rx_comp_cons + 503); | |
8440d2b6 | 1099 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
a2fbb9ea ET |
1100 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
1101 | ||
c3eefaf6 EG |
1102 | BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n", |
1103 | i, j, cqe[0], cqe[1], cqe[2], cqe[3]); | |
a2fbb9ea ET |
1104 | } |
1105 | } | |
1106 | ||
8440d2b6 | 1107 | /* Tx */ |
55c11941 | 1108 | for_each_valid_tx_queue(bp, i) { |
8440d2b6 | 1109 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
6383c0b3 | 1110 | for_each_cos_in_tx_queue(fp, cos) { |
65565884 | 1111 | struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos]; |
6383c0b3 AE |
1112 | |
1113 | start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10); | |
1114 | end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245); | |
1115 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
1116 | struct sw_tx_bd *sw_bd = | |
1117 | &txdata->tx_buf_ring[j]; | |
1118 | ||
51c1a580 | 1119 | BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n", |
6383c0b3 AE |
1120 | i, cos, j, sw_bd->skb, |
1121 | sw_bd->first_bd); | |
1122 | } | |
8440d2b6 | 1123 | |
6383c0b3 AE |
1124 | start = TX_BD(txdata->tx_bd_cons - 10); |
1125 | end = TX_BD(txdata->tx_bd_cons + 254); | |
1126 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
1127 | u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j]; | |
8440d2b6 | 1128 | |
51c1a580 | 1129 | BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n", |
6383c0b3 AE |
1130 | i, cos, j, tx_bd[0], tx_bd[1], |
1131 | tx_bd[2], tx_bd[3]); | |
1132 | } | |
8440d2b6 EG |
1133 | } |
1134 | } | |
523224a3 | 1135 | #endif |
34f80b04 | 1136 | bnx2x_fw_dump(bp); |
a2fbb9ea ET |
1137 | bnx2x_mc_assert(bp); |
1138 | BNX2X_ERR("end crash dump -----------------\n"); | |
a2fbb9ea ET |
1139 | } |
1140 | ||
619c5cb6 VZ |
1141 | /* |
1142 | * FLR Support for E2 | |
1143 | * | |
1144 | * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW | |
1145 | * initialization. | |
1146 | */ | |
16a5fd92 | 1147 | #define FLR_WAIT_USEC 10000 /* 10 milliseconds */ |
89db4ad8 AE |
1148 | #define FLR_WAIT_INTERVAL 50 /* usec */ |
1149 | #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */ | |
619c5cb6 VZ |
1150 | |
1151 | struct pbf_pN_buf_regs { | |
1152 | int pN; | |
1153 | u32 init_crd; | |
1154 | u32 crd; | |
1155 | u32 crd_freed; | |
1156 | }; | |
1157 | ||
1158 | struct pbf_pN_cmd_regs { | |
1159 | int pN; | |
1160 | u32 lines_occup; | |
1161 | u32 lines_freed; | |
1162 | }; | |
1163 | ||
1164 | static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp, | |
1165 | struct pbf_pN_buf_regs *regs, | |
1166 | u32 poll_count) | |
1167 | { | |
1168 | u32 init_crd, crd, crd_start, crd_freed, crd_freed_start; | |
1169 | u32 cur_cnt = poll_count; | |
1170 | ||
1171 | crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed); | |
1172 | crd = crd_start = REG_RD(bp, regs->crd); | |
1173 | init_crd = REG_RD(bp, regs->init_crd); | |
1174 | ||
1175 | DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd); | |
1176 | DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd); | |
1177 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed); | |
1178 | ||
1179 | while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) < | |
1180 | (init_crd - crd_start))) { | |
1181 | if (cur_cnt--) { | |
89db4ad8 | 1182 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1183 | crd = REG_RD(bp, regs->crd); |
1184 | crd_freed = REG_RD(bp, regs->crd_freed); | |
1185 | } else { | |
1186 | DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n", | |
1187 | regs->pN); | |
1188 | DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n", | |
1189 | regs->pN, crd); | |
1190 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n", | |
1191 | regs->pN, crd_freed); | |
1192 | break; | |
1193 | } | |
1194 | } | |
1195 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n", | |
89db4ad8 | 1196 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1197 | } |
1198 | ||
1199 | static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp, | |
1200 | struct pbf_pN_cmd_regs *regs, | |
1201 | u32 poll_count) | |
1202 | { | |
1203 | u32 occup, to_free, freed, freed_start; | |
1204 | u32 cur_cnt = poll_count; | |
1205 | ||
1206 | occup = to_free = REG_RD(bp, regs->lines_occup); | |
1207 | freed = freed_start = REG_RD(bp, regs->lines_freed); | |
1208 | ||
1209 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); | |
1210 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); | |
1211 | ||
1212 | while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) { | |
1213 | if (cur_cnt--) { | |
89db4ad8 | 1214 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1215 | occup = REG_RD(bp, regs->lines_occup); |
1216 | freed = REG_RD(bp, regs->lines_freed); | |
1217 | } else { | |
1218 | DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n", | |
1219 | regs->pN); | |
1220 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", | |
1221 | regs->pN, occup); | |
1222 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", | |
1223 | regs->pN, freed); | |
1224 | break; | |
1225 | } | |
1226 | } | |
1227 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n", | |
89db4ad8 | 1228 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1229 | } |
1230 | ||
1191cb83 ED |
1231 | static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg, |
1232 | u32 expected, u32 poll_count) | |
619c5cb6 VZ |
1233 | { |
1234 | u32 cur_cnt = poll_count; | |
1235 | u32 val; | |
1236 | ||
1237 | while ((val = REG_RD(bp, reg)) != expected && cur_cnt--) | |
89db4ad8 | 1238 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1239 | |
1240 | return val; | |
1241 | } | |
1242 | ||
d16132ce AE |
1243 | int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg, |
1244 | char *msg, u32 poll_cnt) | |
619c5cb6 VZ |
1245 | { |
1246 | u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt); | |
1247 | if (val != 0) { | |
1248 | BNX2X_ERR("%s usage count=%d\n", msg, val); | |
1249 | return 1; | |
1250 | } | |
1251 | return 0; | |
1252 | } | |
1253 | ||
d16132ce AE |
1254 | /* Common routines with VF FLR cleanup */ |
1255 | u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp) | |
619c5cb6 VZ |
1256 | { |
1257 | /* adjust polling timeout */ | |
1258 | if (CHIP_REV_IS_EMUL(bp)) | |
1259 | return FLR_POLL_CNT * 2000; | |
1260 | ||
1261 | if (CHIP_REV_IS_FPGA(bp)) | |
1262 | return FLR_POLL_CNT * 120; | |
1263 | ||
1264 | return FLR_POLL_CNT; | |
1265 | } | |
1266 | ||
d16132ce | 1267 | void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count) |
619c5cb6 VZ |
1268 | { |
1269 | struct pbf_pN_cmd_regs cmd_regs[] = { | |
1270 | {0, (CHIP_IS_E3B0(bp)) ? | |
1271 | PBF_REG_TQ_OCCUPANCY_Q0 : | |
1272 | PBF_REG_P0_TQ_OCCUPANCY, | |
1273 | (CHIP_IS_E3B0(bp)) ? | |
1274 | PBF_REG_TQ_LINES_FREED_CNT_Q0 : | |
1275 | PBF_REG_P0_TQ_LINES_FREED_CNT}, | |
1276 | {1, (CHIP_IS_E3B0(bp)) ? | |
1277 | PBF_REG_TQ_OCCUPANCY_Q1 : | |
1278 | PBF_REG_P1_TQ_OCCUPANCY, | |
1279 | (CHIP_IS_E3B0(bp)) ? | |
1280 | PBF_REG_TQ_LINES_FREED_CNT_Q1 : | |
1281 | PBF_REG_P1_TQ_LINES_FREED_CNT}, | |
1282 | {4, (CHIP_IS_E3B0(bp)) ? | |
1283 | PBF_REG_TQ_OCCUPANCY_LB_Q : | |
1284 | PBF_REG_P4_TQ_OCCUPANCY, | |
1285 | (CHIP_IS_E3B0(bp)) ? | |
1286 | PBF_REG_TQ_LINES_FREED_CNT_LB_Q : | |
1287 | PBF_REG_P4_TQ_LINES_FREED_CNT} | |
1288 | }; | |
1289 | ||
1290 | struct pbf_pN_buf_regs buf_regs[] = { | |
1291 | {0, (CHIP_IS_E3B0(bp)) ? | |
1292 | PBF_REG_INIT_CRD_Q0 : | |
1293 | PBF_REG_P0_INIT_CRD , | |
1294 | (CHIP_IS_E3B0(bp)) ? | |
1295 | PBF_REG_CREDIT_Q0 : | |
1296 | PBF_REG_P0_CREDIT, | |
1297 | (CHIP_IS_E3B0(bp)) ? | |
1298 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 : | |
1299 | PBF_REG_P0_INTERNAL_CRD_FREED_CNT}, | |
1300 | {1, (CHIP_IS_E3B0(bp)) ? | |
1301 | PBF_REG_INIT_CRD_Q1 : | |
1302 | PBF_REG_P1_INIT_CRD, | |
1303 | (CHIP_IS_E3B0(bp)) ? | |
1304 | PBF_REG_CREDIT_Q1 : | |
1305 | PBF_REG_P1_CREDIT, | |
1306 | (CHIP_IS_E3B0(bp)) ? | |
1307 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 : | |
1308 | PBF_REG_P1_INTERNAL_CRD_FREED_CNT}, | |
1309 | {4, (CHIP_IS_E3B0(bp)) ? | |
1310 | PBF_REG_INIT_CRD_LB_Q : | |
1311 | PBF_REG_P4_INIT_CRD, | |
1312 | (CHIP_IS_E3B0(bp)) ? | |
1313 | PBF_REG_CREDIT_LB_Q : | |
1314 | PBF_REG_P4_CREDIT, | |
1315 | (CHIP_IS_E3B0(bp)) ? | |
1316 | PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q : | |
1317 | PBF_REG_P4_INTERNAL_CRD_FREED_CNT}, | |
1318 | }; | |
1319 | ||
1320 | int i; | |
1321 | ||
1322 | /* Verify the command queues are flushed P0, P1, P4 */ | |
1323 | for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) | |
1324 | bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count); | |
1325 | ||
619c5cb6 VZ |
1326 | /* Verify the transmission buffers are flushed P0, P1, P4 */ |
1327 | for (i = 0; i < ARRAY_SIZE(buf_regs); i++) | |
1328 | bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count); | |
1329 | } | |
1330 | ||
1331 | #define OP_GEN_PARAM(param) \ | |
1332 | (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM) | |
1333 | ||
1334 | #define OP_GEN_TYPE(type) \ | |
1335 | (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE) | |
1336 | ||
1337 | #define OP_GEN_AGG_VECT(index) \ | |
1338 | (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX) | |
1339 | ||
d16132ce | 1340 | int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt) |
619c5cb6 | 1341 | { |
86564c3f | 1342 | u32 op_gen_command = 0; |
619c5cb6 VZ |
1343 | u32 comp_addr = BAR_CSTRORM_INTMEM + |
1344 | CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func); | |
1345 | int ret = 0; | |
1346 | ||
1347 | if (REG_RD(bp, comp_addr)) { | |
89db4ad8 | 1348 | BNX2X_ERR("Cleanup complete was not 0 before sending\n"); |
619c5cb6 VZ |
1349 | return 1; |
1350 | } | |
1351 | ||
86564c3f YM |
1352 | op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX); |
1353 | op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE); | |
1354 | op_gen_command |= OP_GEN_AGG_VECT(clnup_func); | |
1355 | op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT; | |
619c5cb6 | 1356 | |
89db4ad8 | 1357 | DP(BNX2X_MSG_SP, "sending FW Final cleanup\n"); |
86564c3f | 1358 | REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command); |
619c5cb6 VZ |
1359 | |
1360 | if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) { | |
1361 | BNX2X_ERR("FW final cleanup did not succeed\n"); | |
51c1a580 MS |
1362 | DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n", |
1363 | (REG_RD(bp, comp_addr))); | |
d16132ce AE |
1364 | bnx2x_panic(); |
1365 | return 1; | |
619c5cb6 | 1366 | } |
16a5fd92 | 1367 | /* Zero completion for next FLR */ |
619c5cb6 VZ |
1368 | REG_WR(bp, comp_addr, 0); |
1369 | ||
1370 | return ret; | |
1371 | } | |
1372 | ||
b56e9670 | 1373 | u8 bnx2x_is_pcie_pending(struct pci_dev *dev) |
619c5cb6 | 1374 | { |
619c5cb6 VZ |
1375 | u16 status; |
1376 | ||
2a80eebc | 1377 | pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status); |
619c5cb6 VZ |
1378 | return status & PCI_EXP_DEVSTA_TRPND; |
1379 | } | |
1380 | ||
1381 | /* PF FLR specific routines | |
1382 | */ | |
1383 | static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt) | |
1384 | { | |
619c5cb6 VZ |
1385 | /* wait for CFC PF usage-counter to zero (includes all the VFs) */ |
1386 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1387 | CFC_REG_NUM_LCIDS_INSIDE_PF, | |
1388 | "CFC PF usage counter timed out", | |
1389 | poll_cnt)) | |
1390 | return 1; | |
1391 | ||
619c5cb6 VZ |
1392 | /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */ |
1393 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1394 | DORQ_REG_PF_USAGE_CNT, | |
1395 | "DQ PF usage counter timed out", | |
1396 | poll_cnt)) | |
1397 | return 1; | |
1398 | ||
1399 | /* Wait for QM PF usage-counter to zero (until DQ cleanup) */ | |
1400 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1401 | QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp), | |
1402 | "QM PF usage counter timed out", | |
1403 | poll_cnt)) | |
1404 | return 1; | |
1405 | ||
1406 | /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */ | |
1407 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1408 | TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp), | |
1409 | "Timers VNIC usage counter timed out", | |
1410 | poll_cnt)) | |
1411 | return 1; | |
1412 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1413 | TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp), | |
1414 | "Timers NUM_SCANS usage counter timed out", | |
1415 | poll_cnt)) | |
1416 | return 1; | |
1417 | ||
1418 | /* Wait DMAE PF usage counter to zero */ | |
1419 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1420 | dmae_reg_go_c[INIT_DMAE_C(bp)], | |
6bf07b8e | 1421 | "DMAE command register timed out", |
619c5cb6 VZ |
1422 | poll_cnt)) |
1423 | return 1; | |
1424 | ||
1425 | return 0; | |
1426 | } | |
1427 | ||
1428 | static void bnx2x_hw_enable_status(struct bnx2x *bp) | |
1429 | { | |
1430 | u32 val; | |
1431 | ||
1432 | val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF); | |
1433 | DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val); | |
1434 | ||
1435 | val = REG_RD(bp, PBF_REG_DISABLE_PF); | |
1436 | DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val); | |
1437 | ||
1438 | val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN); | |
1439 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val); | |
1440 | ||
1441 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN); | |
1442 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val); | |
1443 | ||
1444 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK); | |
1445 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val); | |
1446 | ||
1447 | val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR); | |
1448 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val); | |
1449 | ||
1450 | val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR); | |
1451 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val); | |
1452 | ||
1453 | val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); | |
1454 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", | |
1455 | val); | |
1456 | } | |
1457 | ||
1458 | static int bnx2x_pf_flr_clnup(struct bnx2x *bp) | |
1459 | { | |
1460 | u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp); | |
1461 | ||
1462 | DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp)); | |
1463 | ||
1464 | /* Re-enable PF target read access */ | |
1465 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); | |
1466 | ||
1467 | /* Poll HW usage counters */ | |
89db4ad8 | 1468 | DP(BNX2X_MSG_SP, "Polling usage counters\n"); |
619c5cb6 VZ |
1469 | if (bnx2x_poll_hw_usage_counters(bp, poll_cnt)) |
1470 | return -EBUSY; | |
1471 | ||
1472 | /* Zero the igu 'trailing edge' and 'leading edge' */ | |
1473 | ||
1474 | /* Send the FW cleanup command */ | |
1475 | if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt)) | |
1476 | return -EBUSY; | |
1477 | ||
1478 | /* ATC cleanup */ | |
1479 | ||
1480 | /* Verify TX hw is flushed */ | |
1481 | bnx2x_tx_hw_flushed(bp, poll_cnt); | |
1482 | ||
1483 | /* Wait 100ms (not adjusted according to platform) */ | |
1484 | msleep(100); | |
1485 | ||
1486 | /* Verify no pending pci transactions */ | |
1487 | if (bnx2x_is_pcie_pending(bp->pdev)) | |
1488 | BNX2X_ERR("PCIE Transactions still pending\n"); | |
1489 | ||
1490 | /* Debug */ | |
1491 | bnx2x_hw_enable_status(bp); | |
1492 | ||
1493 | /* | |
1494 | * Master enable - Due to WB DMAE writes performed before this | |
1495 | * register is re-initialized as part of the regular function init | |
1496 | */ | |
1497 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
1498 | ||
1499 | return 0; | |
1500 | } | |
1501 | ||
f2e0899f | 1502 | static void bnx2x_hc_int_enable(struct bnx2x *bp) |
a2fbb9ea | 1503 | { |
34f80b04 | 1504 | int port = BP_PORT(bp); |
a2fbb9ea ET |
1505 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
1506 | u32 val = REG_RD(bp, addr); | |
69c326b3 DK |
1507 | bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false; |
1508 | bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false; | |
1509 | bool msi = (bp->flags & USING_MSI_FLAG) ? true : false; | |
a2fbb9ea ET |
1510 | |
1511 | if (msix) { | |
8badd27a EG |
1512 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
1513 | HC_CONFIG_0_REG_INT_LINE_EN_0); | |
a2fbb9ea ET |
1514 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
1515 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
69c326b3 DK |
1516 | if (single_msix) |
1517 | val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0; | |
8badd27a EG |
1518 | } else if (msi) { |
1519 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; | |
1520 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
1521 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
1522 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
a2fbb9ea ET |
1523 | } else { |
1524 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
615f8fd9 | 1525 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
a2fbb9ea ET |
1526 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
1527 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
615f8fd9 | 1528 | |
a0fd065c | 1529 | if (!CHIP_IS_E1(bp)) { |
51c1a580 MS |
1530 | DP(NETIF_MSG_IFUP, |
1531 | "write %x to HC %d (addr 0x%x)\n", val, port, addr); | |
615f8fd9 | 1532 | |
a0fd065c | 1533 | REG_WR(bp, addr, val); |
615f8fd9 | 1534 | |
a0fd065c DK |
1535 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
1536 | } | |
a2fbb9ea ET |
1537 | } |
1538 | ||
a0fd065c DK |
1539 | if (CHIP_IS_E1(bp)) |
1540 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF); | |
1541 | ||
51c1a580 MS |
1542 | DP(NETIF_MSG_IFUP, |
1543 | "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr, | |
1544 | (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); | |
a2fbb9ea ET |
1545 | |
1546 | REG_WR(bp, addr, val); | |
37dbbf32 EG |
1547 | /* |
1548 | * Ensure that HC_CONFIG is written before leading/trailing edge config | |
1549 | */ | |
1550 | mmiowb(); | |
1551 | barrier(); | |
34f80b04 | 1552 | |
f2e0899f | 1553 | if (!CHIP_IS_E1(bp)) { |
34f80b04 | 1554 | /* init leading/trailing edge */ |
fb3bff17 | 1555 | if (IS_MF(bp)) { |
3395a033 | 1556 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
34f80b04 | 1557 | if (bp->port.pmf) |
4acac6a5 EG |
1558 | /* enable nig and gpio3 attention */ |
1559 | val |= 0x1100; | |
34f80b04 EG |
1560 | } else |
1561 | val = 0xffff; | |
1562 | ||
1563 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
1564 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
1565 | } | |
37dbbf32 EG |
1566 | |
1567 | /* Make sure that interrupts are indeed enabled from here on */ | |
1568 | mmiowb(); | |
a2fbb9ea ET |
1569 | } |
1570 | ||
f2e0899f DK |
1571 | static void bnx2x_igu_int_enable(struct bnx2x *bp) |
1572 | { | |
1573 | u32 val; | |
30a5de77 DK |
1574 | bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false; |
1575 | bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false; | |
1576 | bool msi = (bp->flags & USING_MSI_FLAG) ? true : false; | |
f2e0899f DK |
1577 | |
1578 | val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
1579 | ||
1580 | if (msix) { | |
1581 | val &= ~(IGU_PF_CONF_INT_LINE_EN | | |
1582 | IGU_PF_CONF_SINGLE_ISR_EN); | |
ebe61d80 | 1583 | val |= (IGU_PF_CONF_MSI_MSIX_EN | |
f2e0899f | 1584 | IGU_PF_CONF_ATTN_BIT_EN); |
30a5de77 DK |
1585 | |
1586 | if (single_msix) | |
1587 | val |= IGU_PF_CONF_SINGLE_ISR_EN; | |
f2e0899f DK |
1588 | } else if (msi) { |
1589 | val &= ~IGU_PF_CONF_INT_LINE_EN; | |
ebe61d80 | 1590 | val |= (IGU_PF_CONF_MSI_MSIX_EN | |
f2e0899f DK |
1591 | IGU_PF_CONF_ATTN_BIT_EN | |
1592 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1593 | } else { | |
1594 | val &= ~IGU_PF_CONF_MSI_MSIX_EN; | |
ebe61d80 | 1595 | val |= (IGU_PF_CONF_INT_LINE_EN | |
f2e0899f DK |
1596 | IGU_PF_CONF_ATTN_BIT_EN | |
1597 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1598 | } | |
1599 | ||
ebe61d80 YM |
1600 | /* Clean previous status - need to configure igu prior to ack*/ |
1601 | if ((!msix) || single_msix) { | |
1602 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1603 | bnx2x_ack_int(bp); | |
1604 | } | |
1605 | ||
1606 | val |= IGU_PF_CONF_FUNC_EN; | |
1607 | ||
51c1a580 | 1608 | DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n", |
f2e0899f DK |
1609 | val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
1610 | ||
1611 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1612 | ||
79a8557a YM |
1613 | if (val & IGU_PF_CONF_INT_LINE_EN) |
1614 | pci_intx(bp->pdev, true); | |
1615 | ||
f2e0899f DK |
1616 | barrier(); |
1617 | ||
1618 | /* init leading/trailing edge */ | |
1619 | if (IS_MF(bp)) { | |
3395a033 | 1620 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
1621 | if (bp->port.pmf) |
1622 | /* enable nig and gpio3 attention */ | |
1623 | val |= 0x1100; | |
1624 | } else | |
1625 | val = 0xffff; | |
1626 | ||
1627 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); | |
1628 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
1629 | ||
1630 | /* Make sure that interrupts are indeed enabled from here on */ | |
1631 | mmiowb(); | |
1632 | } | |
1633 | ||
1634 | void bnx2x_int_enable(struct bnx2x *bp) | |
1635 | { | |
1636 | if (bp->common.int_block == INT_BLOCK_HC) | |
1637 | bnx2x_hc_int_enable(bp); | |
1638 | else | |
1639 | bnx2x_igu_int_enable(bp); | |
1640 | } | |
1641 | ||
9f6c9258 | 1642 | void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
a2fbb9ea | 1643 | { |
a2fbb9ea | 1644 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
8badd27a | 1645 | int i, offset; |
a2fbb9ea | 1646 | |
f8ef6e44 YG |
1647 | if (disable_hw) |
1648 | /* prevent the HW from sending interrupts */ | |
1649 | bnx2x_int_disable(bp); | |
a2fbb9ea ET |
1650 | |
1651 | /* make sure all ISRs are done */ | |
1652 | if (msix) { | |
8badd27a EG |
1653 | synchronize_irq(bp->msix_table[0].vector); |
1654 | offset = 1; | |
55c11941 MS |
1655 | if (CNIC_SUPPORT(bp)) |
1656 | offset++; | |
ec6ba945 | 1657 | for_each_eth_queue(bp, i) |
754a2f52 | 1658 | synchronize_irq(bp->msix_table[offset++].vector); |
a2fbb9ea ET |
1659 | } else |
1660 | synchronize_irq(bp->pdev->irq); | |
1661 | ||
1662 | /* make sure sp_task is not running */ | |
1cf167f2 | 1663 | cancel_delayed_work(&bp->sp_task); |
3deb8167 | 1664 | cancel_delayed_work(&bp->period_task); |
1cf167f2 | 1665 | flush_workqueue(bnx2x_wq); |
a2fbb9ea ET |
1666 | } |
1667 | ||
34f80b04 | 1668 | /* fast path */ |
a2fbb9ea ET |
1669 | |
1670 | /* | |
34f80b04 | 1671 | * General service functions |
a2fbb9ea ET |
1672 | */ |
1673 | ||
72fd0718 VZ |
1674 | /* Return true if succeeded to acquire the lock */ |
1675 | static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource) | |
1676 | { | |
1677 | u32 lock_status; | |
1678 | u32 resource_bit = (1 << resource); | |
1679 | int func = BP_FUNC(bp); | |
1680 | u32 hw_lock_control_reg; | |
1681 | ||
51c1a580 MS |
1682 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1683 | "Trying to take a lock on resource %d\n", resource); | |
72fd0718 VZ |
1684 | |
1685 | /* Validating that the resource is within range */ | |
1686 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1687 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
72fd0718 VZ |
1688 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
1689 | resource, HW_LOCK_MAX_RESOURCE_VALUE); | |
0fdf4d09 | 1690 | return false; |
72fd0718 VZ |
1691 | } |
1692 | ||
1693 | if (func <= 5) | |
1694 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1695 | else | |
1696 | hw_lock_control_reg = | |
1697 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1698 | ||
1699 | /* Try to acquire the lock */ | |
1700 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); | |
1701 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
1702 | if (lock_status & resource_bit) | |
1703 | return true; | |
1704 | ||
51c1a580 MS |
1705 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1706 | "Failed to get a lock on resource %d\n", resource); | |
72fd0718 VZ |
1707 | return false; |
1708 | } | |
1709 | ||
c9ee9206 VZ |
1710 | /** |
1711 | * bnx2x_get_leader_lock_resource - get the recovery leader resource id | |
1712 | * | |
1713 | * @bp: driver handle | |
1714 | * | |
1715 | * Returns the recovery leader resource id according to the engine this function | |
1716 | * belongs to. Currently only only 2 engines is supported. | |
1717 | */ | |
1191cb83 | 1718 | static int bnx2x_get_leader_lock_resource(struct bnx2x *bp) |
c9ee9206 VZ |
1719 | { |
1720 | if (BP_PATH(bp)) | |
1721 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_1; | |
1722 | else | |
1723 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_0; | |
1724 | } | |
1725 | ||
1726 | /** | |
2de67439 | 1727 | * bnx2x_trylock_leader_lock- try to acquire a leader lock. |
c9ee9206 VZ |
1728 | * |
1729 | * @bp: driver handle | |
1730 | * | |
2de67439 | 1731 | * Tries to acquire a leader lock for current engine. |
c9ee9206 | 1732 | */ |
1191cb83 | 1733 | static bool bnx2x_trylock_leader_lock(struct bnx2x *bp) |
c9ee9206 VZ |
1734 | { |
1735 | return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1736 | } | |
1737 | ||
619c5cb6 | 1738 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err); |
55c11941 | 1739 | |
fd1fc79d AE |
1740 | /* schedule the sp task and mark that interrupt occurred (runs from ISR) */ |
1741 | static int bnx2x_schedule_sp_task(struct bnx2x *bp) | |
1742 | { | |
1743 | /* Set the interrupt occurred bit for the sp-task to recognize it | |
1744 | * must ack the interrupt and transition according to the IGU | |
1745 | * state machine. | |
1746 | */ | |
1747 | atomic_set(&bp->interrupt_occurred, 1); | |
1748 | ||
1749 | /* The sp_task must execute only after this bit | |
1750 | * is set, otherwise we will get out of sync and miss all | |
1751 | * further interrupts. Hence, the barrier. | |
1752 | */ | |
1753 | smp_wmb(); | |
1754 | ||
1755 | /* schedule sp_task to workqueue */ | |
1756 | return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); | |
1757 | } | |
3196a88a | 1758 | |
619c5cb6 | 1759 | void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe) |
a2fbb9ea ET |
1760 | { |
1761 | struct bnx2x *bp = fp->bp; | |
1762 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
1763 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
619c5cb6 | 1764 | enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX; |
15192a8c | 1765 | struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a2fbb9ea | 1766 | |
34f80b04 | 1767 | DP(BNX2X_MSG_SP, |
a2fbb9ea | 1768 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
0626b899 | 1769 | fp->index, cid, command, bp->state, |
34f80b04 | 1770 | rr_cqe->ramrod_cqe.ramrod_type); |
a2fbb9ea | 1771 | |
fd1fc79d AE |
1772 | /* If cid is within VF range, replace the slowpath object with the |
1773 | * one corresponding to this VF | |
1774 | */ | |
1775 | if (cid >= BNX2X_FIRST_VF_CID && | |
1776 | cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS) | |
1777 | bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj); | |
1778 | ||
619c5cb6 VZ |
1779 | switch (command) { |
1780 | case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE): | |
d6cae238 | 1781 | DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid); |
619c5cb6 VZ |
1782 | drv_cmd = BNX2X_Q_CMD_UPDATE; |
1783 | break; | |
d6cae238 | 1784 | |
619c5cb6 | 1785 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP): |
d6cae238 | 1786 | DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid); |
619c5cb6 | 1787 | drv_cmd = BNX2X_Q_CMD_SETUP; |
a2fbb9ea ET |
1788 | break; |
1789 | ||
6383c0b3 | 1790 | case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP): |
51c1a580 | 1791 | DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid); |
6383c0b3 AE |
1792 | drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; |
1793 | break; | |
1794 | ||
619c5cb6 | 1795 | case (RAMROD_CMD_ID_ETH_HALT): |
d6cae238 | 1796 | DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid); |
619c5cb6 | 1797 | drv_cmd = BNX2X_Q_CMD_HALT; |
a2fbb9ea ET |
1798 | break; |
1799 | ||
619c5cb6 | 1800 | case (RAMROD_CMD_ID_ETH_TERMINATE): |
6bf07b8e | 1801 | DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid); |
619c5cb6 | 1802 | drv_cmd = BNX2X_Q_CMD_TERMINATE; |
a2fbb9ea ET |
1803 | break; |
1804 | ||
619c5cb6 | 1805 | case (RAMROD_CMD_ID_ETH_EMPTY): |
d6cae238 | 1806 | DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid); |
619c5cb6 | 1807 | drv_cmd = BNX2X_Q_CMD_EMPTY; |
993ac7b5 | 1808 | break; |
619c5cb6 VZ |
1809 | |
1810 | default: | |
1811 | BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n", | |
1812 | command, fp->index); | |
1813 | return; | |
523224a3 | 1814 | } |
3196a88a | 1815 | |
619c5cb6 VZ |
1816 | if ((drv_cmd != BNX2X_Q_CMD_MAX) && |
1817 | q_obj->complete_cmd(bp, q_obj, drv_cmd)) | |
1818 | /* q_obj->complete_cmd() failure means that this was | |
1819 | * an unexpected completion. | |
1820 | * | |
1821 | * In this case we don't want to increase the bp->spq_left | |
1822 | * because apparently we haven't sent this command the first | |
1823 | * place. | |
1824 | */ | |
1825 | #ifdef BNX2X_STOP_ON_ERROR | |
1826 | bnx2x_panic(); | |
1827 | #else | |
1828 | return; | |
1829 | #endif | |
fd1fc79d AE |
1830 | /* SRIOV: reschedule any 'in_progress' operations */ |
1831 | bnx2x_iov_sp_event(bp, cid, true); | |
619c5cb6 | 1832 | |
8fe23fbd | 1833 | smp_mb__before_atomic_inc(); |
6e30dd4e | 1834 | atomic_inc(&bp->cq_spq_left); |
619c5cb6 VZ |
1835 | /* push the change in bp->spq_left and towards the memory */ |
1836 | smp_mb__after_atomic_inc(); | |
49d66772 | 1837 | |
d6cae238 VZ |
1838 | DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left)); |
1839 | ||
a3348722 BW |
1840 | if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) && |
1841 | (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) { | |
1842 | /* if Q update ramrod is completed for last Q in AFEX vif set | |
1843 | * flow, then ACK MCP at the end | |
1844 | * | |
1845 | * mark pending ACK to MCP bit. | |
1846 | * prevent case that both bits are cleared. | |
1847 | * At the end of load/unload driver checks that | |
2de67439 | 1848 | * sp_state is cleared, and this order prevents |
a3348722 BW |
1849 | * races |
1850 | */ | |
1851 | smp_mb__before_clear_bit(); | |
1852 | set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state); | |
1853 | wmb(); | |
1854 | clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state); | |
1855 | smp_mb__after_clear_bit(); | |
1856 | ||
fd1fc79d AE |
1857 | /* schedule the sp task as mcp ack is required */ |
1858 | bnx2x_schedule_sp_task(bp); | |
a3348722 BW |
1859 | } |
1860 | ||
523224a3 | 1861 | return; |
a2fbb9ea ET |
1862 | } |
1863 | ||
9f6c9258 | 1864 | irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
a2fbb9ea | 1865 | { |
555f6c78 | 1866 | struct bnx2x *bp = netdev_priv(dev_instance); |
a2fbb9ea | 1867 | u16 status = bnx2x_ack_int(bp); |
34f80b04 | 1868 | u16 mask; |
ca00392c | 1869 | int i; |
6383c0b3 | 1870 | u8 cos; |
a2fbb9ea | 1871 | |
34f80b04 | 1872 | /* Return here if interrupt is shared and it's not for us */ |
a2fbb9ea ET |
1873 | if (unlikely(status == 0)) { |
1874 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); | |
1875 | return IRQ_NONE; | |
1876 | } | |
f5372251 | 1877 | DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status); |
a2fbb9ea | 1878 | |
3196a88a EG |
1879 | #ifdef BNX2X_STOP_ON_ERROR |
1880 | if (unlikely(bp->panic)) | |
1881 | return IRQ_HANDLED; | |
1882 | #endif | |
1883 | ||
ec6ba945 | 1884 | for_each_eth_queue(bp, i) { |
ca00392c | 1885 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea | 1886 | |
55c11941 | 1887 | mask = 0x2 << (fp->index + CNIC_SUPPORT(bp)); |
ca00392c | 1888 | if (status & mask) { |
619c5cb6 | 1889 | /* Handle Rx or Tx according to SB id */ |
6383c0b3 | 1890 | for_each_cos_in_tx_queue(fp, cos) |
65565884 | 1891 | prefetch(fp->txdata_ptr[cos]->tx_cons_sb); |
523224a3 | 1892 | prefetch(&fp->sb_running_index[SM_RX_ID]); |
54b9ddaa | 1893 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
ca00392c EG |
1894 | status &= ~mask; |
1895 | } | |
a2fbb9ea ET |
1896 | } |
1897 | ||
55c11941 MS |
1898 | if (CNIC_SUPPORT(bp)) { |
1899 | mask = 0x2; | |
1900 | if (status & (mask | 0x1)) { | |
1901 | struct cnic_ops *c_ops = NULL; | |
993ac7b5 | 1902 | |
ad9b4359 MC |
1903 | rcu_read_lock(); |
1904 | c_ops = rcu_dereference(bp->cnic_ops); | |
1905 | if (c_ops && (bp->cnic_eth_dev.drv_state & | |
1906 | CNIC_DRV_STATE_HANDLES_IRQ)) | |
1907 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
1908 | rcu_read_unlock(); | |
993ac7b5 | 1909 | |
55c11941 MS |
1910 | status &= ~mask; |
1911 | } | |
993ac7b5 | 1912 | } |
a2fbb9ea | 1913 | |
34f80b04 | 1914 | if (unlikely(status & 0x1)) { |
fd1fc79d AE |
1915 | |
1916 | /* schedule sp task to perform default status block work, ack | |
1917 | * attentions and enable interrupts. | |
1918 | */ | |
1919 | bnx2x_schedule_sp_task(bp); | |
a2fbb9ea ET |
1920 | |
1921 | status &= ~0x1; | |
1922 | if (!status) | |
1923 | return IRQ_HANDLED; | |
1924 | } | |
1925 | ||
cdaa7cb8 VZ |
1926 | if (unlikely(status)) |
1927 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", | |
34f80b04 | 1928 | status); |
a2fbb9ea | 1929 | |
c18487ee | 1930 | return IRQ_HANDLED; |
a2fbb9ea ET |
1931 | } |
1932 | ||
c18487ee YR |
1933 | /* Link */ |
1934 | ||
1935 | /* | |
1936 | * General service functions | |
1937 | */ | |
a2fbb9ea | 1938 | |
9f6c9258 | 1939 | int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1940 | { |
1941 | u32 lock_status; | |
1942 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1943 | int func = BP_FUNC(bp); |
1944 | u32 hw_lock_control_reg; | |
c18487ee | 1945 | int cnt; |
a2fbb9ea | 1946 | |
c18487ee YR |
1947 | /* Validating that the resource is within range */ |
1948 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1949 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1950 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1951 | return -EINVAL; | |
1952 | } | |
a2fbb9ea | 1953 | |
4a37fb66 YG |
1954 | if (func <= 5) { |
1955 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1956 | } else { | |
1957 | hw_lock_control_reg = | |
1958 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1959 | } | |
1960 | ||
c18487ee | 1961 | /* Validating that the resource is not already taken */ |
4a37fb66 | 1962 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 1963 | if (lock_status & resource_bit) { |
51c1a580 | 1964 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n", |
c18487ee YR |
1965 | lock_status, resource_bit); |
1966 | return -EEXIST; | |
1967 | } | |
a2fbb9ea | 1968 | |
46230476 EG |
1969 | /* Try for 5 second every 5ms */ |
1970 | for (cnt = 0; cnt < 1000; cnt++) { | |
c18487ee | 1971 | /* Try to acquire the lock */ |
4a37fb66 YG |
1972 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
1973 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
c18487ee YR |
1974 | if (lock_status & resource_bit) |
1975 | return 0; | |
a2fbb9ea | 1976 | |
639d65b8 | 1977 | usleep_range(5000, 10000); |
a2fbb9ea | 1978 | } |
51c1a580 | 1979 | BNX2X_ERR("Timeout\n"); |
c18487ee YR |
1980 | return -EAGAIN; |
1981 | } | |
a2fbb9ea | 1982 | |
c9ee9206 VZ |
1983 | int bnx2x_release_leader_lock(struct bnx2x *bp) |
1984 | { | |
1985 | return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1986 | } | |
1987 | ||
9f6c9258 | 1988 | int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1989 | { |
1990 | u32 lock_status; | |
1991 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1992 | int func = BP_FUNC(bp); |
1993 | u32 hw_lock_control_reg; | |
a2fbb9ea | 1994 | |
c18487ee YR |
1995 | /* Validating that the resource is within range */ |
1996 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1997 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1998 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1999 | return -EINVAL; | |
2000 | } | |
2001 | ||
4a37fb66 YG |
2002 | if (func <= 5) { |
2003 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
2004 | } else { | |
2005 | hw_lock_control_reg = | |
2006 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
2007 | } | |
2008 | ||
c18487ee | 2009 | /* Validating that the resource is currently taken */ |
4a37fb66 | 2010 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 2011 | if (!(lock_status & resource_bit)) { |
6bf07b8e YM |
2012 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n", |
2013 | lock_status, resource_bit); | |
c18487ee | 2014 | return -EFAULT; |
a2fbb9ea ET |
2015 | } |
2016 | ||
9f6c9258 DK |
2017 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
2018 | return 0; | |
c18487ee | 2019 | } |
a2fbb9ea | 2020 | |
4acac6a5 EG |
2021 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
2022 | { | |
2023 | /* The GPIO should be swapped if swap register is set and active */ | |
2024 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
2025 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
2026 | int gpio_shift = gpio_num + | |
2027 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2028 | u32 gpio_mask = (1 << gpio_shift); | |
2029 | u32 gpio_reg; | |
2030 | int value; | |
2031 | ||
2032 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
2033 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2034 | return -EINVAL; | |
2035 | } | |
2036 | ||
2037 | /* read GPIO value */ | |
2038 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
2039 | ||
2040 | /* get the requested pin value */ | |
2041 | if ((gpio_reg & gpio_mask) == gpio_mask) | |
2042 | value = 1; | |
2043 | else | |
2044 | value = 0; | |
2045 | ||
2046 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); | |
2047 | ||
2048 | return value; | |
2049 | } | |
2050 | ||
17de50b7 | 2051 | int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
c18487ee YR |
2052 | { |
2053 | /* The GPIO should be swapped if swap register is set and active */ | |
2054 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
17de50b7 | 2055 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
c18487ee YR |
2056 | int gpio_shift = gpio_num + |
2057 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2058 | u32 gpio_mask = (1 << gpio_shift); | |
2059 | u32 gpio_reg; | |
a2fbb9ea | 2060 | |
c18487ee YR |
2061 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
2062 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2063 | return -EINVAL; | |
2064 | } | |
a2fbb9ea | 2065 | |
4a37fb66 | 2066 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
c18487ee YR |
2067 | /* read GPIO and mask except the float bits */ |
2068 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); | |
a2fbb9ea | 2069 | |
c18487ee YR |
2070 | switch (mode) { |
2071 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
51c1a580 MS |
2072 | DP(NETIF_MSG_LINK, |
2073 | "Set GPIO %d (shift %d) -> output low\n", | |
c18487ee YR |
2074 | gpio_num, gpio_shift); |
2075 | /* clear FLOAT and set CLR */ | |
2076 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2077 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); | |
2078 | break; | |
a2fbb9ea | 2079 | |
c18487ee | 2080 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
51c1a580 MS |
2081 | DP(NETIF_MSG_LINK, |
2082 | "Set GPIO %d (shift %d) -> output high\n", | |
c18487ee YR |
2083 | gpio_num, gpio_shift); |
2084 | /* clear FLOAT and set SET */ | |
2085 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2086 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); | |
2087 | break; | |
a2fbb9ea | 2088 | |
17de50b7 | 2089 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
51c1a580 MS |
2090 | DP(NETIF_MSG_LINK, |
2091 | "Set GPIO %d (shift %d) -> input\n", | |
c18487ee YR |
2092 | gpio_num, gpio_shift); |
2093 | /* set FLOAT */ | |
2094 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2095 | break; | |
a2fbb9ea | 2096 | |
c18487ee YR |
2097 | default: |
2098 | break; | |
a2fbb9ea ET |
2099 | } |
2100 | ||
c18487ee | 2101 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
4a37fb66 | 2102 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
f1410647 | 2103 | |
c18487ee | 2104 | return 0; |
a2fbb9ea ET |
2105 | } |
2106 | ||
0d40f0d4 YR |
2107 | int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode) |
2108 | { | |
2109 | u32 gpio_reg = 0; | |
2110 | int rc = 0; | |
2111 | ||
2112 | /* Any port swapping should be handled by caller. */ | |
2113 | ||
2114 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2115 | /* read GPIO and mask except the float bits */ | |
2116 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
2117 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2118 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS); | |
2119 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS); | |
2120 | ||
2121 | switch (mode) { | |
2122 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
2123 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins); | |
2124 | /* set CLR */ | |
2125 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS); | |
2126 | break; | |
2127 | ||
2128 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: | |
2129 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins); | |
2130 | /* set SET */ | |
2131 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS); | |
2132 | break; | |
2133 | ||
2134 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: | |
2135 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins); | |
2136 | /* set FLOAT */ | |
2137 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2138 | break; | |
2139 | ||
2140 | default: | |
2141 | BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode); | |
2142 | rc = -EINVAL; | |
2143 | break; | |
2144 | } | |
2145 | ||
2146 | if (rc == 0) | |
2147 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); | |
2148 | ||
2149 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2150 | ||
2151 | return rc; | |
2152 | } | |
2153 | ||
4acac6a5 EG |
2154 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
2155 | { | |
2156 | /* The GPIO should be swapped if swap register is set and active */ | |
2157 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
2158 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
2159 | int gpio_shift = gpio_num + | |
2160 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2161 | u32 gpio_mask = (1 << gpio_shift); | |
2162 | u32 gpio_reg; | |
2163 | ||
2164 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
2165 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2166 | return -EINVAL; | |
2167 | } | |
2168 | ||
2169 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2170 | /* read GPIO int */ | |
2171 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); | |
2172 | ||
2173 | switch (mode) { | |
2174 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: | |
51c1a580 MS |
2175 | DP(NETIF_MSG_LINK, |
2176 | "Clear GPIO INT %d (shift %d) -> output low\n", | |
2177 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2178 | /* clear SET and set CLR */ |
2179 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2180 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2181 | break; | |
2182 | ||
2183 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: | |
51c1a580 MS |
2184 | DP(NETIF_MSG_LINK, |
2185 | "Set GPIO INT %d (shift %d) -> output high\n", | |
2186 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2187 | /* clear CLR and set SET */ |
2188 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2189 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2190 | break; | |
2191 | ||
2192 | default: | |
2193 | break; | |
2194 | } | |
2195 | ||
2196 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); | |
2197 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2198 | ||
2199 | return 0; | |
2200 | } | |
2201 | ||
d6d99a3f | 2202 | static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode) |
a2fbb9ea | 2203 | { |
c18487ee | 2204 | u32 spio_reg; |
a2fbb9ea | 2205 | |
d6d99a3f YM |
2206 | /* Only 2 SPIOs are configurable */ |
2207 | if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) { | |
2208 | BNX2X_ERR("Invalid SPIO 0x%x\n", spio); | |
c18487ee | 2209 | return -EINVAL; |
a2fbb9ea ET |
2210 | } |
2211 | ||
4a37fb66 | 2212 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee | 2213 | /* read SPIO and mask except the float bits */ |
d6d99a3f | 2214 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT); |
a2fbb9ea | 2215 | |
c18487ee | 2216 | switch (mode) { |
d6d99a3f YM |
2217 | case MISC_SPIO_OUTPUT_LOW: |
2218 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio); | |
c18487ee | 2219 | /* clear FLOAT and set CLR */ |
d6d99a3f YM |
2220 | spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); |
2221 | spio_reg |= (spio << MISC_SPIO_CLR_POS); | |
c18487ee | 2222 | break; |
a2fbb9ea | 2223 | |
d6d99a3f YM |
2224 | case MISC_SPIO_OUTPUT_HIGH: |
2225 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio); | |
c18487ee | 2226 | /* clear FLOAT and set SET */ |
d6d99a3f YM |
2227 | spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS); |
2228 | spio_reg |= (spio << MISC_SPIO_SET_POS); | |
c18487ee | 2229 | break; |
a2fbb9ea | 2230 | |
d6d99a3f YM |
2231 | case MISC_SPIO_INPUT_HI_Z: |
2232 | DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio); | |
c18487ee | 2233 | /* set FLOAT */ |
d6d99a3f | 2234 | spio_reg |= (spio << MISC_SPIO_FLOAT_POS); |
c18487ee | 2235 | break; |
a2fbb9ea | 2236 | |
c18487ee YR |
2237 | default: |
2238 | break; | |
a2fbb9ea ET |
2239 | } |
2240 | ||
c18487ee | 2241 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
4a37fb66 | 2242 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee | 2243 | |
a2fbb9ea ET |
2244 | return 0; |
2245 | } | |
2246 | ||
9f6c9258 | 2247 | void bnx2x_calc_fc_adv(struct bnx2x *bp) |
a2fbb9ea | 2248 | { |
a22f0788 | 2249 | u8 cfg_idx = bnx2x_get_link_cfg_idx(bp); |
ad33ea3a EG |
2250 | switch (bp->link_vars.ieee_fc & |
2251 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { | |
c18487ee | 2252 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
a22f0788 | 2253 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2254 | ADVERTISED_Pause); |
c18487ee | 2255 | break; |
356e2385 | 2256 | |
c18487ee | 2257 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
a22f0788 | 2258 | bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause | |
f85582f8 | 2259 | ADVERTISED_Pause); |
c18487ee | 2260 | break; |
356e2385 | 2261 | |
c18487ee | 2262 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
a22f0788 | 2263 | bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause; |
c18487ee | 2264 | break; |
356e2385 | 2265 | |
c18487ee | 2266 | default: |
a22f0788 | 2267 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2268 | ADVERTISED_Pause); |
c18487ee YR |
2269 | break; |
2270 | } | |
2271 | } | |
f1410647 | 2272 | |
cd1dfce2 | 2273 | static void bnx2x_set_requested_fc(struct bnx2x *bp) |
c18487ee | 2274 | { |
cd1dfce2 YM |
2275 | /* Initialize link parameters structure variables |
2276 | * It is recommended to turn off RX FC for jumbo frames | |
2277 | * for better performance | |
2278 | */ | |
2279 | if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000)) | |
2280 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; | |
2281 | else | |
2282 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; | |
2283 | } | |
a2fbb9ea | 2284 | |
9156b30b DK |
2285 | static void bnx2x_init_dropless_fc(struct bnx2x *bp) |
2286 | { | |
2287 | u32 pause_enabled = 0; | |
2288 | ||
2289 | if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) { | |
2290 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) | |
2291 | pause_enabled = 1; | |
2292 | ||
2293 | REG_WR(bp, BAR_USTRORM_INTMEM + | |
2294 | USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)), | |
2295 | pause_enabled); | |
2296 | } | |
2297 | ||
2298 | DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n", | |
2299 | pause_enabled ? "enabled" : "disabled"); | |
2300 | } | |
2301 | ||
cd1dfce2 YM |
2302 | int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
2303 | { | |
2304 | int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp); | |
2305 | u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx]; | |
2306 | ||
2307 | if (!BP_NOMCP(bp)) { | |
2308 | bnx2x_set_requested_fc(bp); | |
4a37fb66 | 2309 | bnx2x_acquire_phy_lock(bp); |
b5bf9068 | 2310 | |
a22f0788 | 2311 | if (load_mode == LOAD_DIAG) { |
1cb0c788 YR |
2312 | struct link_params *lp = &bp->link_params; |
2313 | lp->loopback_mode = LOOPBACK_XGXS; | |
2314 | /* do PHY loopback at 10G speed, if possible */ | |
2315 | if (lp->req_line_speed[cfx_idx] < SPEED_10000) { | |
2316 | if (lp->speed_cap_mask[cfx_idx] & | |
2317 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) | |
2318 | lp->req_line_speed[cfx_idx] = | |
2319 | SPEED_10000; | |
2320 | else | |
2321 | lp->req_line_speed[cfx_idx] = | |
2322 | SPEED_1000; | |
2323 | } | |
a22f0788 | 2324 | } |
b5bf9068 | 2325 | |
8970b2e4 MS |
2326 | if (load_mode == LOAD_LOOPBACK_EXT) { |
2327 | struct link_params *lp = &bp->link_params; | |
2328 | lp->loopback_mode = LOOPBACK_EXT; | |
2329 | } | |
2330 | ||
19680c48 | 2331 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
b5bf9068 | 2332 | |
4a37fb66 | 2333 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2334 | |
9156b30b DK |
2335 | bnx2x_init_dropless_fc(bp); |
2336 | ||
3c96c68b EG |
2337 | bnx2x_calc_fc_adv(bp); |
2338 | ||
cd1dfce2 | 2339 | if (bp->link_vars.link_up) { |
b5bf9068 | 2340 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
19680c48 | 2341 | bnx2x_link_report(bp); |
cd1dfce2 YM |
2342 | } |
2343 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
a22f0788 | 2344 | bp->link_params.req_line_speed[cfx_idx] = req_line_speed; |
19680c48 EG |
2345 | return rc; |
2346 | } | |
f5372251 | 2347 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
19680c48 | 2348 | return -EINVAL; |
a2fbb9ea ET |
2349 | } |
2350 | ||
9f6c9258 | 2351 | void bnx2x_link_set(struct bnx2x *bp) |
a2fbb9ea | 2352 | { |
19680c48 | 2353 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2354 | bnx2x_acquire_phy_lock(bp); |
19680c48 | 2355 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
4a37fb66 | 2356 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2357 | |
9156b30b DK |
2358 | bnx2x_init_dropless_fc(bp); |
2359 | ||
19680c48 EG |
2360 | bnx2x_calc_fc_adv(bp); |
2361 | } else | |
f5372251 | 2362 | BNX2X_ERR("Bootcode is missing - can not set link\n"); |
c18487ee | 2363 | } |
a2fbb9ea | 2364 | |
c18487ee YR |
2365 | static void bnx2x__link_reset(struct bnx2x *bp) |
2366 | { | |
19680c48 | 2367 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2368 | bnx2x_acquire_phy_lock(bp); |
5d07d868 | 2369 | bnx2x_lfa_reset(&bp->link_params, &bp->link_vars); |
4a37fb66 | 2370 | bnx2x_release_phy_lock(bp); |
19680c48 | 2371 | } else |
f5372251 | 2372 | BNX2X_ERR("Bootcode is missing - can not reset link\n"); |
c18487ee | 2373 | } |
a2fbb9ea | 2374 | |
5d07d868 YM |
2375 | void bnx2x_force_link_reset(struct bnx2x *bp) |
2376 | { | |
2377 | bnx2x_acquire_phy_lock(bp); | |
2378 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); | |
2379 | bnx2x_release_phy_lock(bp); | |
2380 | } | |
2381 | ||
a22f0788 | 2382 | u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes) |
c18487ee | 2383 | { |
2145a920 | 2384 | u8 rc = 0; |
a2fbb9ea | 2385 | |
2145a920 VZ |
2386 | if (!BP_NOMCP(bp)) { |
2387 | bnx2x_acquire_phy_lock(bp); | |
a22f0788 YR |
2388 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars, |
2389 | is_serdes); | |
2145a920 VZ |
2390 | bnx2x_release_phy_lock(bp); |
2391 | } else | |
2392 | BNX2X_ERR("Bootcode is missing - can not test link\n"); | |
a2fbb9ea | 2393 | |
c18487ee YR |
2394 | return rc; |
2395 | } | |
a2fbb9ea | 2396 | |
2691d51d EG |
2397 | /* Calculates the sum of vn_min_rates. |
2398 | It's needed for further normalizing of the min_rates. | |
2399 | Returns: | |
2400 | sum of vn_min_rates. | |
2401 | or | |
2402 | 0 - if all the min_rates are 0. | |
16a5fd92 | 2403 | In the later case fairness algorithm should be deactivated. |
2691d51d EG |
2404 | If not all min_rates are zero then those that are zeroes will be set to 1. |
2405 | */ | |
b475d78f YM |
2406 | static void bnx2x_calc_vn_min(struct bnx2x *bp, |
2407 | struct cmng_init_input *input) | |
2691d51d EG |
2408 | { |
2409 | int all_zero = 1; | |
2691d51d EG |
2410 | int vn; |
2411 | ||
3395a033 | 2412 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
f2e0899f | 2413 | u32 vn_cfg = bp->mf_config[vn]; |
2691d51d EG |
2414 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
2415 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; | |
2416 | ||
2417 | /* Skip hidden vns */ | |
2418 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) | |
b475d78f | 2419 | vn_min_rate = 0; |
2691d51d | 2420 | /* If min rate is zero - set it to 1 */ |
b475d78f | 2421 | else if (!vn_min_rate) |
2691d51d EG |
2422 | vn_min_rate = DEF_MIN_RATE; |
2423 | else | |
2424 | all_zero = 0; | |
2425 | ||
b475d78f | 2426 | input->vnic_min_rate[vn] = vn_min_rate; |
2691d51d EG |
2427 | } |
2428 | ||
30ae438b DK |
2429 | /* if ETS or all min rates are zeros - disable fairness */ |
2430 | if (BNX2X_IS_ETS_ENABLED(bp)) { | |
b475d78f | 2431 | input->flags.cmng_enables &= |
30ae438b DK |
2432 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
2433 | DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n"); | |
2434 | } else if (all_zero) { | |
b475d78f | 2435 | input->flags.cmng_enables &= |
b015e3d1 | 2436 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
b475d78f YM |
2437 | DP(NETIF_MSG_IFUP, |
2438 | "All MIN values are zeroes fairness will be disabled\n"); | |
b015e3d1 | 2439 | } else |
b475d78f | 2440 | input->flags.cmng_enables |= |
b015e3d1 | 2441 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
2691d51d EG |
2442 | } |
2443 | ||
b475d78f YM |
2444 | static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn, |
2445 | struct cmng_init_input *input) | |
34f80b04 | 2446 | { |
b475d78f | 2447 | u16 vn_max_rate; |
f2e0899f | 2448 | u32 vn_cfg = bp->mf_config[vn]; |
34f80b04 | 2449 | |
b475d78f | 2450 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
34f80b04 | 2451 | vn_max_rate = 0; |
b475d78f | 2452 | else { |
faa6fcbb DK |
2453 | u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg); |
2454 | ||
b475d78f | 2455 | if (IS_MF_SI(bp)) { |
faa6fcbb DK |
2456 | /* maxCfg in percents of linkspeed */ |
2457 | vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100; | |
b475d78f | 2458 | } else /* SD modes */ |
faa6fcbb DK |
2459 | /* maxCfg is absolute in 100Mb units */ |
2460 | vn_max_rate = maxCfg * 100; | |
34f80b04 | 2461 | } |
f85582f8 | 2462 | |
b475d78f | 2463 | DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate); |
34f80b04 | 2464 | |
b475d78f | 2465 | input->vnic_max_rate[vn] = vn_max_rate; |
34f80b04 | 2466 | } |
f85582f8 | 2467 | |
523224a3 DK |
2468 | static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp) |
2469 | { | |
2470 | if (CHIP_REV_IS_SLOW(bp)) | |
2471 | return CMNG_FNS_NONE; | |
fb3bff17 | 2472 | if (IS_MF(bp)) |
523224a3 DK |
2473 | return CMNG_FNS_MINMAX; |
2474 | ||
2475 | return CMNG_FNS_NONE; | |
2476 | } | |
2477 | ||
2ae17f66 | 2478 | void bnx2x_read_mf_cfg(struct bnx2x *bp) |
523224a3 | 2479 | { |
0793f83f | 2480 | int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1); |
523224a3 DK |
2481 | |
2482 | if (BP_NOMCP(bp)) | |
16a5fd92 | 2483 | return; /* what should be the default value in this case */ |
523224a3 | 2484 | |
0793f83f DK |
2485 | /* For 2 port configuration the absolute function number formula |
2486 | * is: | |
2487 | * abs_func = 2 * vn + BP_PORT + BP_PATH | |
2488 | * | |
2489 | * and there are 4 functions per port | |
2490 | * | |
2491 | * For 4 port configuration it is | |
2492 | * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH | |
2493 | * | |
2494 | * and there are 2 functions per port | |
2495 | */ | |
3395a033 | 2496 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
0793f83f DK |
2497 | int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp); |
2498 | ||
2499 | if (func >= E1H_FUNC_MAX) | |
2500 | break; | |
2501 | ||
f2e0899f | 2502 | bp->mf_config[vn] = |
523224a3 DK |
2503 | MF_CFG_RD(bp, func_mf_config[func].config); |
2504 | } | |
a3348722 BW |
2505 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
2506 | DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n"); | |
2507 | bp->flags |= MF_FUNC_DIS; | |
2508 | } else { | |
2509 | DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n"); | |
2510 | bp->flags &= ~MF_FUNC_DIS; | |
2511 | } | |
523224a3 DK |
2512 | } |
2513 | ||
2514 | static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type) | |
2515 | { | |
b475d78f YM |
2516 | struct cmng_init_input input; |
2517 | memset(&input, 0, sizeof(struct cmng_init_input)); | |
2518 | ||
2519 | input.port_rate = bp->link_vars.line_speed; | |
523224a3 | 2520 | |
568e2426 | 2521 | if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) { |
523224a3 DK |
2522 | int vn; |
2523 | ||
523224a3 DK |
2524 | /* read mf conf from shmem */ |
2525 | if (read_cfg) | |
2526 | bnx2x_read_mf_cfg(bp); | |
2527 | ||
523224a3 | 2528 | /* vn_weight_sum and enable fairness if not 0 */ |
b475d78f | 2529 | bnx2x_calc_vn_min(bp, &input); |
523224a3 DK |
2530 | |
2531 | /* calculate and set min-max rate for each vn */ | |
c4154f25 | 2532 | if (bp->port.pmf) |
3395a033 | 2533 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) |
b475d78f | 2534 | bnx2x_calc_vn_max(bp, vn, &input); |
523224a3 DK |
2535 | |
2536 | /* always enable rate shaping and fairness */ | |
b475d78f | 2537 | input.flags.cmng_enables |= |
523224a3 | 2538 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
b475d78f YM |
2539 | |
2540 | bnx2x_init_cmng(&input, &bp->cmng); | |
523224a3 DK |
2541 | return; |
2542 | } | |
2543 | ||
2544 | /* rate shaping and fairness are disabled */ | |
2545 | DP(NETIF_MSG_IFUP, | |
2546 | "rate shaping and fairness are disabled\n"); | |
2547 | } | |
34f80b04 | 2548 | |
1191cb83 ED |
2549 | static void storm_memset_cmng(struct bnx2x *bp, |
2550 | struct cmng_init *cmng, | |
2551 | u8 port) | |
2552 | { | |
2553 | int vn; | |
2554 | size_t size = sizeof(struct cmng_struct_per_port); | |
2555 | ||
2556 | u32 addr = BAR_XSTRORM_INTMEM + | |
2557 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port); | |
2558 | ||
2559 | __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port); | |
2560 | ||
2561 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { | |
2562 | int func = func_by_vn(bp, vn); | |
2563 | ||
2564 | addr = BAR_XSTRORM_INTMEM + | |
2565 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func); | |
2566 | size = sizeof(struct rate_shaping_vars_per_vn); | |
2567 | __storm_memset_struct(bp, addr, size, | |
2568 | (u32 *)&cmng->vnic.vnic_max_rate[vn]); | |
2569 | ||
2570 | addr = BAR_XSTRORM_INTMEM + | |
2571 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func); | |
2572 | size = sizeof(struct fairness_vars_per_vn); | |
2573 | __storm_memset_struct(bp, addr, size, | |
2574 | (u32 *)&cmng->vnic.vnic_min_rate[vn]); | |
2575 | } | |
2576 | } | |
2577 | ||
568e2426 DK |
2578 | /* init cmng mode in HW according to local configuration */ |
2579 | void bnx2x_set_local_cmng(struct bnx2x *bp) | |
2580 | { | |
2581 | int cmng_fns = bnx2x_get_cmng_fns_mode(bp); | |
2582 | ||
2583 | if (cmng_fns != CMNG_FNS_NONE) { | |
2584 | bnx2x_cmng_fns_init(bp, false, cmng_fns); | |
2585 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
2586 | } else { | |
2587 | /* rate shaping and fairness are disabled */ | |
2588 | DP(NETIF_MSG_IFUP, | |
2589 | "single function mode without fairness\n"); | |
2590 | } | |
2591 | } | |
2592 | ||
c18487ee YR |
2593 | /* This function is called upon link interrupt */ |
2594 | static void bnx2x_link_attn(struct bnx2x *bp) | |
2595 | { | |
bb2a0f7a YG |
2596 | /* Make sure that we are synced with the current statistics */ |
2597 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2598 | ||
c18487ee | 2599 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
a2fbb9ea | 2600 | |
9156b30b | 2601 | bnx2x_init_dropless_fc(bp); |
1c06328c | 2602 | |
9156b30b | 2603 | if (bp->link_vars.link_up) { |
1c06328c | 2604 | |
619c5cb6 | 2605 | if (bp->link_vars.mac_type != MAC_TYPE_EMAC) { |
bb2a0f7a YG |
2606 | struct host_port_stats *pstats; |
2607 | ||
2608 | pstats = bnx2x_sp(bp, port_stats); | |
619c5cb6 | 2609 | /* reset old mac stats */ |
bb2a0f7a YG |
2610 | memset(&(pstats->mac_stx[0]), 0, |
2611 | sizeof(struct mac_stx)); | |
2612 | } | |
f34d28ea | 2613 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a YG |
2614 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
2615 | } | |
2616 | ||
568e2426 DK |
2617 | if (bp->link_vars.link_up && bp->link_vars.line_speed) |
2618 | bnx2x_set_local_cmng(bp); | |
9fdc3e95 | 2619 | |
2ae17f66 VZ |
2620 | __bnx2x_link_report(bp); |
2621 | ||
9fdc3e95 DK |
2622 | if (IS_MF(bp)) |
2623 | bnx2x_link_sync_notify(bp); | |
c18487ee | 2624 | } |
a2fbb9ea | 2625 | |
9f6c9258 | 2626 | void bnx2x__link_status_update(struct bnx2x *bp) |
c18487ee | 2627 | { |
2ae17f66 | 2628 | if (bp->state != BNX2X_STATE_OPEN) |
c18487ee | 2629 | return; |
a2fbb9ea | 2630 | |
00253a8c | 2631 | /* read updated dcb configuration */ |
ad5afc89 AE |
2632 | if (IS_PF(bp)) { |
2633 | bnx2x_dcbx_pmf_update(bp); | |
2634 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); | |
2635 | if (bp->link_vars.link_up) | |
2636 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); | |
2637 | else | |
2638 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2639 | /* indicate link status */ | |
2640 | bnx2x_link_report(bp); | |
a2fbb9ea | 2641 | |
ad5afc89 AE |
2642 | } else { /* VF */ |
2643 | bp->port.supported[0] |= (SUPPORTED_10baseT_Half | | |
2644 | SUPPORTED_10baseT_Full | | |
2645 | SUPPORTED_100baseT_Half | | |
2646 | SUPPORTED_100baseT_Full | | |
2647 | SUPPORTED_1000baseT_Full | | |
2648 | SUPPORTED_2500baseX_Full | | |
2649 | SUPPORTED_10000baseT_Full | | |
2650 | SUPPORTED_TP | | |
2651 | SUPPORTED_FIBRE | | |
2652 | SUPPORTED_Autoneg | | |
2653 | SUPPORTED_Pause | | |
2654 | SUPPORTED_Asym_Pause); | |
2655 | bp->port.advertising[0] = bp->port.supported[0]; | |
2656 | ||
2657 | bp->link_params.bp = bp; | |
2658 | bp->link_params.port = BP_PORT(bp); | |
2659 | bp->link_params.req_duplex[0] = DUPLEX_FULL; | |
2660 | bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE; | |
2661 | bp->link_params.req_line_speed[0] = SPEED_10000; | |
2662 | bp->link_params.speed_cap_mask[0] = 0x7f0000; | |
2663 | bp->link_params.switch_cfg = SWITCH_CFG_10G; | |
2664 | bp->link_vars.mac_type = MAC_TYPE_BMAC; | |
2665 | bp->link_vars.line_speed = SPEED_10000; | |
2666 | bp->link_vars.link_status = | |
2667 | (LINK_STATUS_LINK_UP | | |
2668 | LINK_STATUS_SPEED_AND_DUPLEX_10GTFD); | |
2669 | bp->link_vars.link_up = 1; | |
2670 | bp->link_vars.duplex = DUPLEX_FULL; | |
2671 | bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE; | |
2672 | __bnx2x_link_report(bp); | |
bb2a0f7a | 2673 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
ad5afc89 | 2674 | } |
a2fbb9ea | 2675 | } |
a2fbb9ea | 2676 | |
a3348722 BW |
2677 | static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid, |
2678 | u16 vlan_val, u8 allowed_prio) | |
2679 | { | |
86564c3f | 2680 | struct bnx2x_func_state_params func_params = {NULL}; |
a3348722 BW |
2681 | struct bnx2x_func_afex_update_params *f_update_params = |
2682 | &func_params.params.afex_update; | |
2683 | ||
2684 | func_params.f_obj = &bp->func_obj; | |
2685 | func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE; | |
2686 | ||
2687 | /* no need to wait for RAMROD completion, so don't | |
2688 | * set RAMROD_COMP_WAIT flag | |
2689 | */ | |
2690 | ||
2691 | f_update_params->vif_id = vifid; | |
2692 | f_update_params->afex_default_vlan = vlan_val; | |
2693 | f_update_params->allowed_priorities = allowed_prio; | |
2694 | ||
2695 | /* if ramrod can not be sent, response to MCP immediately */ | |
2696 | if (bnx2x_func_state_change(bp, &func_params) < 0) | |
2697 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
2698 | ||
2699 | return 0; | |
2700 | } | |
2701 | ||
2702 | static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type, | |
2703 | u16 vif_index, u8 func_bit_map) | |
2704 | { | |
86564c3f | 2705 | struct bnx2x_func_state_params func_params = {NULL}; |
a3348722 BW |
2706 | struct bnx2x_func_afex_viflists_params *update_params = |
2707 | &func_params.params.afex_viflists; | |
2708 | int rc; | |
2709 | u32 drv_msg_code; | |
2710 | ||
2711 | /* validate only LIST_SET and LIST_GET are received from switch */ | |
2712 | if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET)) | |
2713 | BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n", | |
2714 | cmd_type); | |
2715 | ||
2716 | func_params.f_obj = &bp->func_obj; | |
2717 | func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS; | |
2718 | ||
2719 | /* set parameters according to cmd_type */ | |
2720 | update_params->afex_vif_list_command = cmd_type; | |
86564c3f | 2721 | update_params->vif_list_index = vif_index; |
a3348722 BW |
2722 | update_params->func_bit_map = |
2723 | (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map; | |
2724 | update_params->func_to_clear = 0; | |
2725 | drv_msg_code = | |
2726 | (cmd_type == VIF_LIST_RULE_GET) ? | |
2727 | DRV_MSG_CODE_AFEX_LISTGET_ACK : | |
2728 | DRV_MSG_CODE_AFEX_LISTSET_ACK; | |
2729 | ||
2730 | /* if ramrod can not be sent, respond to MCP immediately for | |
2731 | * SET and GET requests (other are not triggered from MCP) | |
2732 | */ | |
2733 | rc = bnx2x_func_state_change(bp, &func_params); | |
2734 | if (rc < 0) | |
2735 | bnx2x_fw_command(bp, drv_msg_code, 0); | |
2736 | ||
2737 | return 0; | |
2738 | } | |
2739 | ||
2740 | static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd) | |
2741 | { | |
2742 | struct afex_stats afex_stats; | |
2743 | u32 func = BP_ABS_FUNC(bp); | |
2744 | u32 mf_config; | |
2745 | u16 vlan_val; | |
2746 | u32 vlan_prio; | |
2747 | u16 vif_id; | |
2748 | u8 allowed_prio; | |
2749 | u8 vlan_mode; | |
2750 | u32 addr_to_write, vifid, addrs, stats_type, i; | |
2751 | ||
2752 | if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) { | |
2753 | vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2754 | DP(BNX2X_MSG_MCP, | |
2755 | "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid); | |
2756 | bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0); | |
2757 | } | |
2758 | ||
2759 | if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) { | |
2760 | vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2761 | addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]); | |
2762 | DP(BNX2X_MSG_MCP, | |
2763 | "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n", | |
2764 | vifid, addrs); | |
2765 | bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid, | |
2766 | addrs); | |
2767 | } | |
2768 | ||
2769 | if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) { | |
2770 | addr_to_write = SHMEM2_RD(bp, | |
2771 | afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]); | |
2772 | stats_type = SHMEM2_RD(bp, | |
2773 | afex_param1_to_driver[BP_FW_MB_IDX(bp)]); | |
2774 | ||
2775 | DP(BNX2X_MSG_MCP, | |
2776 | "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n", | |
2777 | addr_to_write); | |
2778 | ||
2779 | bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type); | |
2780 | ||
2781 | /* write response to scratchpad, for MCP */ | |
2782 | for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++) | |
2783 | REG_WR(bp, addr_to_write + i*sizeof(u32), | |
2784 | *(((u32 *)(&afex_stats))+i)); | |
2785 | ||
2786 | /* send ack message to MCP */ | |
2787 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0); | |
2788 | } | |
2789 | ||
2790 | if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) { | |
2791 | mf_config = MF_CFG_RD(bp, func_mf_config[func].config); | |
2792 | bp->mf_config[BP_VN(bp)] = mf_config; | |
2793 | DP(BNX2X_MSG_MCP, | |
2794 | "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n", | |
2795 | mf_config); | |
2796 | ||
2797 | /* if VIF_SET is "enabled" */ | |
2798 | if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) { | |
2799 | /* set rate limit directly to internal RAM */ | |
2800 | struct cmng_init_input cmng_input; | |
2801 | struct rate_shaping_vars_per_vn m_rs_vn; | |
2802 | size_t size = sizeof(struct rate_shaping_vars_per_vn); | |
2803 | u32 addr = BAR_XSTRORM_INTMEM + | |
2804 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp)); | |
2805 | ||
2806 | bp->mf_config[BP_VN(bp)] = mf_config; | |
2807 | ||
2808 | bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input); | |
2809 | m_rs_vn.vn_counter.rate = | |
2810 | cmng_input.vnic_max_rate[BP_VN(bp)]; | |
2811 | m_rs_vn.vn_counter.quota = | |
2812 | (m_rs_vn.vn_counter.rate * | |
2813 | RS_PERIODIC_TIMEOUT_USEC) / 8; | |
2814 | ||
2815 | __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn); | |
2816 | ||
2817 | /* read relevant values from mf_cfg struct in shmem */ | |
2818 | vif_id = | |
2819 | (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
2820 | FUNC_MF_CFG_E1HOV_TAG_MASK) >> | |
2821 | FUNC_MF_CFG_E1HOV_TAG_SHIFT; | |
2822 | vlan_val = | |
2823 | (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
2824 | FUNC_MF_CFG_AFEX_VLAN_MASK) >> | |
2825 | FUNC_MF_CFG_AFEX_VLAN_SHIFT; | |
2826 | vlan_prio = (mf_config & | |
2827 | FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >> | |
2828 | FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT; | |
2829 | vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT); | |
2830 | vlan_mode = | |
2831 | (MF_CFG_RD(bp, | |
2832 | func_mf_config[func].afex_config) & | |
2833 | FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >> | |
2834 | FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT; | |
2835 | allowed_prio = | |
2836 | (MF_CFG_RD(bp, | |
2837 | func_mf_config[func].afex_config) & | |
2838 | FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >> | |
2839 | FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT; | |
2840 | ||
2841 | /* send ramrod to FW, return in case of failure */ | |
2842 | if (bnx2x_afex_func_update(bp, vif_id, vlan_val, | |
2843 | allowed_prio)) | |
2844 | return; | |
2845 | ||
2846 | bp->afex_def_vlan_tag = vlan_val; | |
2847 | bp->afex_vlan_mode = vlan_mode; | |
2848 | } else { | |
2849 | /* notify link down because BP->flags is disabled */ | |
2850 | bnx2x_link_report(bp); | |
2851 | ||
2852 | /* send INVALID VIF ramrod to FW */ | |
2853 | bnx2x_afex_func_update(bp, 0xFFFF, 0, 0); | |
2854 | ||
2855 | /* Reset the default afex VLAN */ | |
2856 | bp->afex_def_vlan_tag = -1; | |
2857 | } | |
2858 | } | |
2859 | } | |
2860 | ||
34f80b04 EG |
2861 | static void bnx2x_pmf_update(struct bnx2x *bp) |
2862 | { | |
2863 | int port = BP_PORT(bp); | |
2864 | u32 val; | |
2865 | ||
2866 | bp->port.pmf = 1; | |
51c1a580 | 2867 | DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf); |
34f80b04 | 2868 | |
3deb8167 YR |
2869 | /* |
2870 | * We need the mb() to ensure the ordering between the writing to | |
2871 | * bp->port.pmf here and reading it from the bnx2x_periodic_task(). | |
2872 | */ | |
2873 | smp_mb(); | |
2874 | ||
2875 | /* queue a periodic task */ | |
2876 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
2877 | ||
ef01854e DK |
2878 | bnx2x_dcbx_pmf_update(bp); |
2879 | ||
34f80b04 | 2880 | /* enable nig attention */ |
3395a033 | 2881 | val = (0xff0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
2882 | if (bp->common.int_block == INT_BLOCK_HC) { |
2883 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
2884 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
619c5cb6 | 2885 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
2886 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); |
2887 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
2888 | } | |
bb2a0f7a YG |
2889 | |
2890 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); | |
34f80b04 EG |
2891 | } |
2892 | ||
c18487ee | 2893 | /* end of Link */ |
a2fbb9ea ET |
2894 | |
2895 | /* slow path */ | |
2896 | ||
2897 | /* | |
2898 | * General service functions | |
2899 | */ | |
2900 | ||
2691d51d | 2901 | /* send the MCP a request, block until there is a reply */ |
a22f0788 | 2902 | u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param) |
2691d51d | 2903 | { |
f2e0899f | 2904 | int mb_idx = BP_FW_MB_IDX(bp); |
a5971d43 | 2905 | u32 seq; |
2691d51d EG |
2906 | u32 rc = 0; |
2907 | u32 cnt = 1; | |
2908 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; | |
2909 | ||
c4ff7cbf | 2910 | mutex_lock(&bp->fw_mb_mutex); |
a5971d43 | 2911 | seq = ++bp->fw_seq; |
f2e0899f DK |
2912 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param); |
2913 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq)); | |
2914 | ||
754a2f52 DK |
2915 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n", |
2916 | (command | seq), param); | |
2691d51d EG |
2917 | |
2918 | do { | |
2919 | /* let the FW do it's magic ... */ | |
2920 | msleep(delay); | |
2921 | ||
f2e0899f | 2922 | rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header); |
2691d51d | 2923 | |
c4ff7cbf EG |
2924 | /* Give the FW up to 5 second (500*10ms) */ |
2925 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); | |
2691d51d EG |
2926 | |
2927 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", | |
2928 | cnt*delay, rc, seq); | |
2929 | ||
2930 | /* is this a reply to our command? */ | |
2931 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) | |
2932 | rc &= FW_MSG_CODE_MASK; | |
2933 | else { | |
2934 | /* FW BUG! */ | |
2935 | BNX2X_ERR("FW failed to respond!\n"); | |
2936 | bnx2x_fw_dump(bp); | |
2937 | rc = 0; | |
2938 | } | |
c4ff7cbf | 2939 | mutex_unlock(&bp->fw_mb_mutex); |
2691d51d EG |
2940 | |
2941 | return rc; | |
2942 | } | |
2943 | ||
1191cb83 ED |
2944 | static void storm_memset_func_cfg(struct bnx2x *bp, |
2945 | struct tstorm_eth_function_common_config *tcfg, | |
2946 | u16 abs_fid) | |
2947 | { | |
2948 | size_t size = sizeof(struct tstorm_eth_function_common_config); | |
2949 | ||
2950 | u32 addr = BAR_TSTRORM_INTMEM + | |
2951 | TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid); | |
2952 | ||
2953 | __storm_memset_struct(bp, addr, size, (u32 *)tcfg); | |
2954 | } | |
2955 | ||
619c5cb6 VZ |
2956 | void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p) |
2957 | { | |
2958 | if (CHIP_IS_E1x(bp)) { | |
2959 | struct tstorm_eth_function_common_config tcfg = {0}; | |
2960 | ||
2961 | storm_memset_func_cfg(bp, &tcfg, p->func_id); | |
2962 | } | |
2963 | ||
2964 | /* Enable the function in the FW */ | |
2965 | storm_memset_vf_to_pf(bp, p->func_id, p->pf_id); | |
2966 | storm_memset_func_en(bp, p->func_id, 1); | |
2967 | ||
2968 | /* spq */ | |
2969 | if (p->func_flgs & FUNC_FLG_SPQ) { | |
2970 | storm_memset_spq_addr(bp, p->spq_map, p->func_id); | |
2971 | REG_WR(bp, XSEM_REG_FAST_MEMORY + | |
2972 | XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod); | |
2973 | } | |
2974 | } | |
2975 | ||
6383c0b3 | 2976 | /** |
16a5fd92 | 2977 | * bnx2x_get_common_flags - Return common flags |
6383c0b3 AE |
2978 | * |
2979 | * @bp device handle | |
2980 | * @fp queue handle | |
2981 | * @zero_stats TRUE if statistics zeroing is needed | |
2982 | * | |
2983 | * Return the flags that are common for the Tx-only and not normal connections. | |
2984 | */ | |
1191cb83 ED |
2985 | static unsigned long bnx2x_get_common_flags(struct bnx2x *bp, |
2986 | struct bnx2x_fastpath *fp, | |
2987 | bool zero_stats) | |
28912902 | 2988 | { |
619c5cb6 VZ |
2989 | unsigned long flags = 0; |
2990 | ||
2991 | /* PF driver will always initialize the Queue to an ACTIVE state */ | |
2992 | __set_bit(BNX2X_Q_FLG_ACTIVE, &flags); | |
28912902 | 2993 | |
6383c0b3 | 2994 | /* tx only connections collect statistics (on the same index as the |
91226790 DK |
2995 | * parent connection). The statistics are zeroed when the parent |
2996 | * connection is initialized. | |
6383c0b3 | 2997 | */ |
50f0a562 BW |
2998 | |
2999 | __set_bit(BNX2X_Q_FLG_STATS, &flags); | |
3000 | if (zero_stats) | |
3001 | __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags); | |
3002 | ||
91226790 | 3003 | __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags); |
e287a75c | 3004 | __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags); |
6383c0b3 | 3005 | |
823e1d90 YM |
3006 | #ifdef BNX2X_STOP_ON_ERROR |
3007 | __set_bit(BNX2X_Q_FLG_TX_SEC, &flags); | |
3008 | #endif | |
3009 | ||
6383c0b3 AE |
3010 | return flags; |
3011 | } | |
3012 | ||
1191cb83 ED |
3013 | static unsigned long bnx2x_get_q_flags(struct bnx2x *bp, |
3014 | struct bnx2x_fastpath *fp, | |
3015 | bool leading) | |
6383c0b3 AE |
3016 | { |
3017 | unsigned long flags = 0; | |
3018 | ||
619c5cb6 VZ |
3019 | /* calculate other queue flags */ |
3020 | if (IS_MF_SD(bp)) | |
3021 | __set_bit(BNX2X_Q_FLG_OV, &flags); | |
28912902 | 3022 | |
a3348722 | 3023 | if (IS_FCOE_FP(fp)) { |
619c5cb6 | 3024 | __set_bit(BNX2X_Q_FLG_FCOE, &flags); |
a3348722 BW |
3025 | /* For FCoE - force usage of default priority (for afex) */ |
3026 | __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags); | |
3027 | } | |
523224a3 | 3028 | |
f5219d8e | 3029 | if (!fp->disable_tpa) { |
619c5cb6 | 3030 | __set_bit(BNX2X_Q_FLG_TPA, &flags); |
f5219d8e | 3031 | __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags); |
621b4d66 DK |
3032 | if (fp->mode == TPA_MODE_GRO) |
3033 | __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags); | |
f5219d8e | 3034 | } |
619c5cb6 | 3035 | |
619c5cb6 VZ |
3036 | if (leading) { |
3037 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags); | |
3038 | __set_bit(BNX2X_Q_FLG_MCAST, &flags); | |
3039 | } | |
523224a3 | 3040 | |
619c5cb6 VZ |
3041 | /* Always set HW VLAN stripping */ |
3042 | __set_bit(BNX2X_Q_FLG_VLAN, &flags); | |
523224a3 | 3043 | |
a3348722 BW |
3044 | /* configure silent vlan removal */ |
3045 | if (IS_MF_AFEX(bp)) | |
3046 | __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags); | |
3047 | ||
6383c0b3 | 3048 | return flags | bnx2x_get_common_flags(bp, fp, true); |
523224a3 DK |
3049 | } |
3050 | ||
619c5cb6 | 3051 | static void bnx2x_pf_q_prep_general(struct bnx2x *bp, |
6383c0b3 AE |
3052 | struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init, |
3053 | u8 cos) | |
619c5cb6 VZ |
3054 | { |
3055 | gen_init->stat_id = bnx2x_stats_id(fp); | |
3056 | gen_init->spcl_id = fp->cl_id; | |
3057 | ||
3058 | /* Always use mini-jumbo MTU for FCoE L2 ring */ | |
3059 | if (IS_FCOE_FP(fp)) | |
3060 | gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU; | |
3061 | else | |
3062 | gen_init->mtu = bp->dev->mtu; | |
6383c0b3 AE |
3063 | |
3064 | gen_init->cos = cos; | |
619c5cb6 VZ |
3065 | } |
3066 | ||
3067 | static void bnx2x_pf_rx_q_prep(struct bnx2x *bp, | |
523224a3 | 3068 | struct bnx2x_fastpath *fp, struct rxq_pause_params *pause, |
619c5cb6 | 3069 | struct bnx2x_rxq_setup_params *rxq_init) |
523224a3 | 3070 | { |
619c5cb6 | 3071 | u8 max_sge = 0; |
523224a3 DK |
3072 | u16 sge_sz = 0; |
3073 | u16 tpa_agg_size = 0; | |
3074 | ||
523224a3 | 3075 | if (!fp->disable_tpa) { |
dfacf138 DK |
3076 | pause->sge_th_lo = SGE_TH_LO(bp); |
3077 | pause->sge_th_hi = SGE_TH_HI(bp); | |
3078 | ||
3079 | /* validate SGE ring has enough to cross high threshold */ | |
3080 | WARN_ON(bp->dropless_fc && | |
3081 | pause->sge_th_hi + FW_PREFETCH_CNT > | |
3082 | MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES); | |
3083 | ||
924d75ab | 3084 | tpa_agg_size = TPA_AGG_SIZE; |
523224a3 DK |
3085 | max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >> |
3086 | SGE_PAGE_SHIFT; | |
3087 | max_sge = ((max_sge + PAGES_PER_SGE - 1) & | |
3088 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; | |
924d75ab | 3089 | sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff); |
523224a3 DK |
3090 | } |
3091 | ||
3092 | /* pause - not for e1 */ | |
3093 | if (!CHIP_IS_E1(bp)) { | |
dfacf138 DK |
3094 | pause->bd_th_lo = BD_TH_LO(bp); |
3095 | pause->bd_th_hi = BD_TH_HI(bp); | |
3096 | ||
3097 | pause->rcq_th_lo = RCQ_TH_LO(bp); | |
3098 | pause->rcq_th_hi = RCQ_TH_HI(bp); | |
3099 | /* | |
3100 | * validate that rings have enough entries to cross | |
3101 | * high thresholds | |
3102 | */ | |
3103 | WARN_ON(bp->dropless_fc && | |
3104 | pause->bd_th_hi + FW_PREFETCH_CNT > | |
3105 | bp->rx_ring_size); | |
3106 | WARN_ON(bp->dropless_fc && | |
3107 | pause->rcq_th_hi + FW_PREFETCH_CNT > | |
3108 | NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT); | |
619c5cb6 | 3109 | |
523224a3 DK |
3110 | pause->pri_map = 1; |
3111 | } | |
3112 | ||
3113 | /* rxq setup */ | |
523224a3 DK |
3114 | rxq_init->dscr_map = fp->rx_desc_mapping; |
3115 | rxq_init->sge_map = fp->rx_sge_mapping; | |
3116 | rxq_init->rcq_map = fp->rx_comp_mapping; | |
3117 | rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE; | |
a8c94b91 | 3118 | |
619c5cb6 VZ |
3119 | /* This should be a maximum number of data bytes that may be |
3120 | * placed on the BD (not including paddings). | |
3121 | */ | |
e52fcb24 | 3122 | rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START - |
3cdeec22 | 3123 | BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING; |
a8c94b91 | 3124 | |
523224a3 | 3125 | rxq_init->cl_qzone_id = fp->cl_qzone_id; |
523224a3 DK |
3126 | rxq_init->tpa_agg_sz = tpa_agg_size; |
3127 | rxq_init->sge_buf_sz = sge_sz; | |
3128 | rxq_init->max_sges_pkt = max_sge; | |
619c5cb6 | 3129 | rxq_init->rss_engine_id = BP_FUNC(bp); |
259afa1f | 3130 | rxq_init->mcast_engine_id = BP_FUNC(bp); |
619c5cb6 VZ |
3131 | |
3132 | /* Maximum number or simultaneous TPA aggregation for this Queue. | |
3133 | * | |
2de67439 | 3134 | * For PF Clients it should be the maximum available number. |
619c5cb6 VZ |
3135 | * VF driver(s) may want to define it to a smaller value. |
3136 | */ | |
dfacf138 | 3137 | rxq_init->max_tpa_queues = MAX_AGG_QS(bp); |
619c5cb6 | 3138 | |
523224a3 DK |
3139 | rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
3140 | rxq_init->fw_sb_id = fp->fw_sb_id; | |
3141 | ||
ec6ba945 VZ |
3142 | if (IS_FCOE_FP(fp)) |
3143 | rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS; | |
3144 | else | |
6383c0b3 | 3145 | rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
a3348722 BW |
3146 | /* configure silent vlan removal |
3147 | * if multi function mode is afex, then mask default vlan | |
3148 | */ | |
3149 | if (IS_MF_AFEX(bp)) { | |
3150 | rxq_init->silent_removal_value = bp->afex_def_vlan_tag; | |
3151 | rxq_init->silent_removal_mask = VLAN_VID_MASK; | |
3152 | } | |
523224a3 DK |
3153 | } |
3154 | ||
619c5cb6 | 3155 | static void bnx2x_pf_tx_q_prep(struct bnx2x *bp, |
6383c0b3 AE |
3156 | struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init, |
3157 | u8 cos) | |
523224a3 | 3158 | { |
65565884 | 3159 | txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping; |
6383c0b3 | 3160 | txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos; |
523224a3 DK |
3161 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; |
3162 | txq_init->fw_sb_id = fp->fw_sb_id; | |
ec6ba945 | 3163 | |
619c5cb6 | 3164 | /* |
16a5fd92 | 3165 | * set the tss leading client id for TX classification == |
619c5cb6 VZ |
3166 | * leading RSS client id |
3167 | */ | |
3168 | txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id); | |
3169 | ||
ec6ba945 VZ |
3170 | if (IS_FCOE_FP(fp)) { |
3171 | txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS; | |
3172 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE; | |
3173 | } | |
523224a3 DK |
3174 | } |
3175 | ||
8d96286a | 3176 | static void bnx2x_pf_init(struct bnx2x *bp) |
523224a3 DK |
3177 | { |
3178 | struct bnx2x_func_init_params func_init = {0}; | |
523224a3 DK |
3179 | struct event_ring_data eq_data = { {0} }; |
3180 | u16 flags; | |
3181 | ||
619c5cb6 | 3182 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
3183 | /* reset IGU PF statistics: MSIX + ATTN */ |
3184 | /* PF */ | |
3185 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
3186 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
3187 | (CHIP_MODE_IS_4_PORT(bp) ? | |
3188 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
3189 | /* ATTN */ | |
3190 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
3191 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
3192 | BNX2X_IGU_STAS_MSG_PF_CNT*4 + | |
3193 | (CHIP_MODE_IS_4_PORT(bp) ? | |
3194 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
3195 | } | |
3196 | ||
523224a3 DK |
3197 | /* function setup flags */ |
3198 | flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); | |
3199 | ||
619c5cb6 VZ |
3200 | /* This flag is relevant for E1x only. |
3201 | * E2 doesn't have a TPA configuration in a function level. | |
523224a3 | 3202 | */ |
619c5cb6 | 3203 | flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; |
523224a3 DK |
3204 | |
3205 | func_init.func_flgs = flags; | |
3206 | func_init.pf_id = BP_FUNC(bp); | |
3207 | func_init.func_id = BP_FUNC(bp); | |
523224a3 DK |
3208 | func_init.spq_map = bp->spq_mapping; |
3209 | func_init.spq_prod = bp->spq_prod_idx; | |
3210 | ||
3211 | bnx2x_func_init(bp, &func_init); | |
3212 | ||
3213 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); | |
3214 | ||
3215 | /* | |
619c5cb6 VZ |
3216 | * Congestion management values depend on the link rate |
3217 | * There is no active link so initial link rate is set to 10 Gbps. | |
3218 | * When the link comes up The congestion management values are | |
3219 | * re-calculated according to the actual link rate. | |
3220 | */ | |
523224a3 DK |
3221 | bp->link_vars.line_speed = SPEED_10000; |
3222 | bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp)); | |
3223 | ||
3224 | /* Only the PMF sets the HW */ | |
3225 | if (bp->port.pmf) | |
3226 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
3227 | ||
86564c3f | 3228 | /* init Event Queue - PCI bus guarantees correct endianity*/ |
523224a3 DK |
3229 | eq_data.base_addr.hi = U64_HI(bp->eq_mapping); |
3230 | eq_data.base_addr.lo = U64_LO(bp->eq_mapping); | |
3231 | eq_data.producer = bp->eq_prod; | |
3232 | eq_data.index_id = HC_SP_INDEX_EQ_CONS; | |
3233 | eq_data.sb_id = DEF_SB_ID; | |
3234 | storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp)); | |
3235 | } | |
3236 | ||
523224a3 DK |
3237 | static void bnx2x_e1h_disable(struct bnx2x *bp) |
3238 | { | |
3239 | int port = BP_PORT(bp); | |
3240 | ||
619c5cb6 | 3241 | bnx2x_tx_disable(bp); |
523224a3 DK |
3242 | |
3243 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
523224a3 DK |
3244 | } |
3245 | ||
3246 | static void bnx2x_e1h_enable(struct bnx2x *bp) | |
3247 | { | |
3248 | int port = BP_PORT(bp); | |
3249 | ||
3250 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); | |
3251 | ||
16a5fd92 | 3252 | /* Tx queue should be only re-enabled */ |
523224a3 DK |
3253 | netif_tx_wake_all_queues(bp->dev); |
3254 | ||
3255 | /* | |
3256 | * Should not call netif_carrier_on since it will be called if the link | |
3257 | * is up when checking for link state | |
3258 | */ | |
3259 | } | |
3260 | ||
1d187b34 BW |
3261 | #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3 |
3262 | ||
3263 | static void bnx2x_drv_info_ether_stat(struct bnx2x *bp) | |
3264 | { | |
3265 | struct eth_stats_info *ether_stat = | |
3266 | &bp->slowpath->drv_info_to_mcp.ether_stat; | |
3ec9f9ca AE |
3267 | struct bnx2x_vlan_mac_obj *mac_obj = |
3268 | &bp->sp_objs->mac_obj; | |
3269 | int i; | |
1d187b34 | 3270 | |
786fdf0b DC |
3271 | strlcpy(ether_stat->version, DRV_MODULE_VERSION, |
3272 | ETH_STAT_INFO_VERSION_LEN); | |
1d187b34 | 3273 | |
3ec9f9ca AE |
3274 | /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the |
3275 | * mac_local field in ether_stat struct. The base address is offset by 2 | |
3276 | * bytes to account for the field being 8 bytes but a mac address is | |
3277 | * only 6 bytes. Likewise, the stride for the get_n_elements function is | |
3278 | * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes | |
3279 | * allocated by the ether_stat struct, so the macs will land in their | |
3280 | * proper positions. | |
3281 | */ | |
3282 | for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++) | |
3283 | memset(ether_stat->mac_local + i, 0, | |
3284 | sizeof(ether_stat->mac_local[0])); | |
3285 | mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj, | |
3286 | DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED, | |
3287 | ether_stat->mac_local + MAC_PAD, MAC_PAD, | |
3288 | ETH_ALEN); | |
1d187b34 | 3289 | ether_stat->mtu_size = bp->dev->mtu; |
1d187b34 BW |
3290 | if (bp->dev->features & NETIF_F_RXCSUM) |
3291 | ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK; | |
3292 | if (bp->dev->features & NETIF_F_TSO) | |
3293 | ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK; | |
3294 | ether_stat->feature_flags |= bp->common.boot_mode; | |
3295 | ||
3296 | ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0; | |
3297 | ||
3298 | ether_stat->txq_size = bp->tx_ring_size; | |
3299 | ether_stat->rxq_size = bp->rx_ring_size; | |
3300 | } | |
3301 | ||
3302 | static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp) | |
3303 | { | |
3304 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; | |
3305 | struct fcoe_stats_info *fcoe_stat = | |
3306 | &bp->slowpath->drv_info_to_mcp.fcoe_stat; | |
3307 | ||
55c11941 MS |
3308 | if (!CNIC_LOADED(bp)) |
3309 | return; | |
3310 | ||
3ec9f9ca | 3311 | memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN); |
1d187b34 BW |
3312 | |
3313 | fcoe_stat->qos_priority = | |
3314 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE]; | |
3315 | ||
3316 | /* insert FCoE stats from ramrod response */ | |
3317 | if (!NO_FCOE(bp)) { | |
3318 | struct tstorm_per_queue_stats *fcoe_q_tstorm_stats = | |
65565884 | 3319 | &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)]. |
1d187b34 BW |
3320 | tstorm_queue_statistics; |
3321 | ||
3322 | struct xstorm_per_queue_stats *fcoe_q_xstorm_stats = | |
65565884 | 3323 | &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)]. |
1d187b34 BW |
3324 | xstorm_queue_statistics; |
3325 | ||
3326 | struct fcoe_statistics_params *fw_fcoe_stat = | |
3327 | &bp->fw_stats_data->fcoe; | |
3328 | ||
86564c3f YM |
3329 | ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0, |
3330 | fcoe_stat->rx_bytes_lo, | |
3331 | fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt); | |
1d187b34 | 3332 | |
86564c3f YM |
3333 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3334 | fcoe_q_tstorm_stats->rcv_ucast_bytes.hi, | |
3335 | fcoe_stat->rx_bytes_lo, | |
3336 | fcoe_q_tstorm_stats->rcv_ucast_bytes.lo); | |
1d187b34 | 3337 | |
86564c3f YM |
3338 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3339 | fcoe_q_tstorm_stats->rcv_bcast_bytes.hi, | |
3340 | fcoe_stat->rx_bytes_lo, | |
3341 | fcoe_q_tstorm_stats->rcv_bcast_bytes.lo); | |
1d187b34 | 3342 | |
86564c3f YM |
3343 | ADD_64_LE(fcoe_stat->rx_bytes_hi, |
3344 | fcoe_q_tstorm_stats->rcv_mcast_bytes.hi, | |
3345 | fcoe_stat->rx_bytes_lo, | |
3346 | fcoe_q_tstorm_stats->rcv_mcast_bytes.lo); | |
1d187b34 | 3347 | |
86564c3f YM |
3348 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3349 | fcoe_stat->rx_frames_lo, | |
3350 | fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt); | |
1d187b34 | 3351 | |
86564c3f YM |
3352 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3353 | fcoe_stat->rx_frames_lo, | |
3354 | fcoe_q_tstorm_stats->rcv_ucast_pkts); | |
1d187b34 | 3355 | |
86564c3f YM |
3356 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3357 | fcoe_stat->rx_frames_lo, | |
3358 | fcoe_q_tstorm_stats->rcv_bcast_pkts); | |
1d187b34 | 3359 | |
86564c3f YM |
3360 | ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0, |
3361 | fcoe_stat->rx_frames_lo, | |
3362 | fcoe_q_tstorm_stats->rcv_mcast_pkts); | |
1d187b34 | 3363 | |
86564c3f YM |
3364 | ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0, |
3365 | fcoe_stat->tx_bytes_lo, | |
3366 | fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt); | |
1d187b34 | 3367 | |
86564c3f YM |
3368 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3369 | fcoe_q_xstorm_stats->ucast_bytes_sent.hi, | |
3370 | fcoe_stat->tx_bytes_lo, | |
3371 | fcoe_q_xstorm_stats->ucast_bytes_sent.lo); | |
1d187b34 | 3372 | |
86564c3f YM |
3373 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3374 | fcoe_q_xstorm_stats->bcast_bytes_sent.hi, | |
3375 | fcoe_stat->tx_bytes_lo, | |
3376 | fcoe_q_xstorm_stats->bcast_bytes_sent.lo); | |
1d187b34 | 3377 | |
86564c3f YM |
3378 | ADD_64_LE(fcoe_stat->tx_bytes_hi, |
3379 | fcoe_q_xstorm_stats->mcast_bytes_sent.hi, | |
3380 | fcoe_stat->tx_bytes_lo, | |
3381 | fcoe_q_xstorm_stats->mcast_bytes_sent.lo); | |
1d187b34 | 3382 | |
86564c3f YM |
3383 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3384 | fcoe_stat->tx_frames_lo, | |
3385 | fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt); | |
1d187b34 | 3386 | |
86564c3f YM |
3387 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3388 | fcoe_stat->tx_frames_lo, | |
3389 | fcoe_q_xstorm_stats->ucast_pkts_sent); | |
1d187b34 | 3390 | |
86564c3f YM |
3391 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3392 | fcoe_stat->tx_frames_lo, | |
3393 | fcoe_q_xstorm_stats->bcast_pkts_sent); | |
1d187b34 | 3394 | |
86564c3f YM |
3395 | ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0, |
3396 | fcoe_stat->tx_frames_lo, | |
3397 | fcoe_q_xstorm_stats->mcast_pkts_sent); | |
1d187b34 BW |
3398 | } |
3399 | ||
1d187b34 BW |
3400 | /* ask L5 driver to add data to the struct */ |
3401 | bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD); | |
1d187b34 BW |
3402 | } |
3403 | ||
3404 | static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp) | |
3405 | { | |
3406 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; | |
3407 | struct iscsi_stats_info *iscsi_stat = | |
3408 | &bp->slowpath->drv_info_to_mcp.iscsi_stat; | |
3409 | ||
55c11941 MS |
3410 | if (!CNIC_LOADED(bp)) |
3411 | return; | |
3412 | ||
3ec9f9ca AE |
3413 | memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac, |
3414 | ETH_ALEN); | |
1d187b34 BW |
3415 | |
3416 | iscsi_stat->qos_priority = | |
3417 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI]; | |
3418 | ||
1d187b34 BW |
3419 | /* ask L5 driver to add data to the struct */ |
3420 | bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD); | |
1d187b34 BW |
3421 | } |
3422 | ||
0793f83f DK |
3423 | /* called due to MCP event (on pmf): |
3424 | * reread new bandwidth configuration | |
3425 | * configure FW | |
3426 | * notify others function about the change | |
3427 | */ | |
1191cb83 | 3428 | static void bnx2x_config_mf_bw(struct bnx2x *bp) |
0793f83f DK |
3429 | { |
3430 | if (bp->link_vars.link_up) { | |
3431 | bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX); | |
3432 | bnx2x_link_sync_notify(bp); | |
3433 | } | |
3434 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
3435 | } | |
3436 | ||
1191cb83 | 3437 | static void bnx2x_set_mf_bw(struct bnx2x *bp) |
0793f83f DK |
3438 | { |
3439 | bnx2x_config_mf_bw(bp); | |
3440 | bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0); | |
3441 | } | |
3442 | ||
c8c60d88 YM |
3443 | static void bnx2x_handle_eee_event(struct bnx2x *bp) |
3444 | { | |
3445 | DP(BNX2X_MSG_MCP, "EEE - LLDP event\n"); | |
3446 | bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0); | |
3447 | } | |
3448 | ||
1d187b34 BW |
3449 | static void bnx2x_handle_drv_info_req(struct bnx2x *bp) |
3450 | { | |
3451 | enum drv_info_opcode op_code; | |
3452 | u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control); | |
3453 | ||
3454 | /* if drv_info version supported by MFW doesn't match - send NACK */ | |
3455 | if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) { | |
3456 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3457 | return; | |
3458 | } | |
3459 | ||
3460 | op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >> | |
3461 | DRV_INFO_CONTROL_OP_CODE_SHIFT; | |
3462 | ||
3463 | memset(&bp->slowpath->drv_info_to_mcp, 0, | |
3464 | sizeof(union drv_info_to_mcp)); | |
3465 | ||
3466 | switch (op_code) { | |
3467 | case ETH_STATS_OPCODE: | |
3468 | bnx2x_drv_info_ether_stat(bp); | |
3469 | break; | |
3470 | case FCOE_STATS_OPCODE: | |
3471 | bnx2x_drv_info_fcoe_stat(bp); | |
3472 | break; | |
3473 | case ISCSI_STATS_OPCODE: | |
3474 | bnx2x_drv_info_iscsi_stat(bp); | |
3475 | break; | |
3476 | default: | |
3477 | /* if op code isn't supported - send NACK */ | |
3478 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3479 | return; | |
3480 | } | |
3481 | ||
3482 | /* if we got drv_info attn from MFW then these fields are defined in | |
3483 | * shmem2 for sure | |
3484 | */ | |
3485 | SHMEM2_WR(bp, drv_info_host_addr_lo, | |
3486 | U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3487 | SHMEM2_WR(bp, drv_info_host_addr_hi, | |
3488 | U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3489 | ||
3490 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0); | |
3491 | } | |
3492 | ||
523224a3 DK |
3493 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
3494 | { | |
3495 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); | |
3496 | ||
3497 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { | |
3498 | ||
3499 | /* | |
3500 | * This is the only place besides the function initialization | |
3501 | * where the bp->flags can change so it is done without any | |
3502 | * locks | |
3503 | */ | |
f2e0899f | 3504 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
51c1a580 | 3505 | DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n"); |
523224a3 DK |
3506 | bp->flags |= MF_FUNC_DIS; |
3507 | ||
3508 | bnx2x_e1h_disable(bp); | |
3509 | } else { | |
51c1a580 | 3510 | DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n"); |
523224a3 DK |
3511 | bp->flags &= ~MF_FUNC_DIS; |
3512 | ||
3513 | bnx2x_e1h_enable(bp); | |
3514 | } | |
3515 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; | |
3516 | } | |
3517 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { | |
0793f83f | 3518 | bnx2x_config_mf_bw(bp); |
523224a3 DK |
3519 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
3520 | } | |
3521 | ||
3522 | /* Report results to MCP */ | |
3523 | if (dcc_event) | |
3524 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0); | |
3525 | else | |
3526 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0); | |
3527 | } | |
3528 | ||
3529 | /* must be called under the spq lock */ | |
1191cb83 | 3530 | static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp) |
523224a3 DK |
3531 | { |
3532 | struct eth_spe *next_spe = bp->spq_prod_bd; | |
3533 | ||
3534 | if (bp->spq_prod_bd == bp->spq_last_bd) { | |
3535 | bp->spq_prod_bd = bp->spq; | |
3536 | bp->spq_prod_idx = 0; | |
51c1a580 | 3537 | DP(BNX2X_MSG_SP, "end of spq\n"); |
523224a3 DK |
3538 | } else { |
3539 | bp->spq_prod_bd++; | |
3540 | bp->spq_prod_idx++; | |
3541 | } | |
3542 | return next_spe; | |
3543 | } | |
3544 | ||
3545 | /* must be called under the spq lock */ | |
1191cb83 | 3546 | static void bnx2x_sp_prod_update(struct bnx2x *bp) |
28912902 MC |
3547 | { |
3548 | int func = BP_FUNC(bp); | |
3549 | ||
53e51e2f VZ |
3550 | /* |
3551 | * Make sure that BD data is updated before writing the producer: | |
3552 | * BD data is written to the memory, the producer is read from the | |
3553 | * memory, thus we need a full memory barrier to ensure the ordering. | |
3554 | */ | |
3555 | mb(); | |
28912902 | 3556 | |
523224a3 | 3557 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
f85582f8 | 3558 | bp->spq_prod_idx); |
28912902 MC |
3559 | mmiowb(); |
3560 | } | |
3561 | ||
619c5cb6 VZ |
3562 | /** |
3563 | * bnx2x_is_contextless_ramrod - check if the current command ends on EQ | |
3564 | * | |
3565 | * @cmd: command to check | |
3566 | * @cmd_type: command type | |
3567 | */ | |
1191cb83 | 3568 | static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type) |
619c5cb6 VZ |
3569 | { |
3570 | if ((cmd_type == NONE_CONNECTION_TYPE) || | |
6383c0b3 | 3571 | (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) || |
619c5cb6 VZ |
3572 | (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || |
3573 | (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || | |
3574 | (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || | |
3575 | (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || | |
3576 | (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) | |
3577 | return true; | |
3578 | else | |
3579 | return false; | |
619c5cb6 VZ |
3580 | } |
3581 | ||
619c5cb6 VZ |
3582 | /** |
3583 | * bnx2x_sp_post - place a single command on an SP ring | |
3584 | * | |
3585 | * @bp: driver handle | |
3586 | * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) | |
3587 | * @cid: SW CID the command is related to | |
3588 | * @data_hi: command private data address (high 32 bits) | |
3589 | * @data_lo: command private data address (low 32 bits) | |
3590 | * @cmd_type: command type (e.g. NONE, ETH) | |
3591 | * | |
3592 | * SP data is handled as if it's always an address pair, thus data fields are | |
3593 | * not swapped to little endian in upper functions. Instead this function swaps | |
3594 | * data as if it's two u32 fields. | |
3595 | */ | |
9f6c9258 | 3596 | int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
619c5cb6 | 3597 | u32 data_hi, u32 data_lo, int cmd_type) |
a2fbb9ea | 3598 | { |
28912902 | 3599 | struct eth_spe *spe; |
523224a3 | 3600 | u16 type; |
619c5cb6 | 3601 | bool common = bnx2x_is_contextless_ramrod(command, cmd_type); |
a2fbb9ea | 3602 | |
a2fbb9ea | 3603 | #ifdef BNX2X_STOP_ON_ERROR |
51c1a580 MS |
3604 | if (unlikely(bp->panic)) { |
3605 | BNX2X_ERR("Can't post SP when there is panic\n"); | |
a2fbb9ea | 3606 | return -EIO; |
51c1a580 | 3607 | } |
a2fbb9ea ET |
3608 | #endif |
3609 | ||
34f80b04 | 3610 | spin_lock_bh(&bp->spq_lock); |
a2fbb9ea | 3611 | |
6e30dd4e VZ |
3612 | if (common) { |
3613 | if (!atomic_read(&bp->eq_spq_left)) { | |
3614 | BNX2X_ERR("BUG! EQ ring full!\n"); | |
3615 | spin_unlock_bh(&bp->spq_lock); | |
3616 | bnx2x_panic(); | |
3617 | return -EBUSY; | |
3618 | } | |
3619 | } else if (!atomic_read(&bp->cq_spq_left)) { | |
3620 | BNX2X_ERR("BUG! SPQ ring full!\n"); | |
3621 | spin_unlock_bh(&bp->spq_lock); | |
3622 | bnx2x_panic(); | |
3623 | return -EBUSY; | |
a2fbb9ea | 3624 | } |
f1410647 | 3625 | |
28912902 MC |
3626 | spe = bnx2x_sp_get_next(bp); |
3627 | ||
a2fbb9ea | 3628 | /* CID needs port number to be encoded int it */ |
28912902 | 3629 | spe->hdr.conn_and_cmd_data = |
cdaa7cb8 VZ |
3630 | cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) | |
3631 | HW_CID(bp, cid)); | |
523224a3 | 3632 | |
619c5cb6 | 3633 | type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE; |
a2fbb9ea | 3634 | |
523224a3 DK |
3635 | type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) & |
3636 | SPE_HDR_FUNCTION_ID); | |
a2fbb9ea | 3637 | |
523224a3 DK |
3638 | spe->hdr.type = cpu_to_le16(type); |
3639 | ||
3640 | spe->data.update_data_addr.hi = cpu_to_le32(data_hi); | |
3641 | spe->data.update_data_addr.lo = cpu_to_le32(data_lo); | |
3642 | ||
d6cae238 VZ |
3643 | /* |
3644 | * It's ok if the actual decrement is issued towards the memory | |
3645 | * somewhere between the spin_lock and spin_unlock. Thus no | |
16a5fd92 | 3646 | * more explicit memory barrier is needed. |
d6cae238 VZ |
3647 | */ |
3648 | if (common) | |
3649 | atomic_dec(&bp->eq_spq_left); | |
3650 | else | |
3651 | atomic_dec(&bp->cq_spq_left); | |
6e30dd4e | 3652 | |
51c1a580 MS |
3653 | DP(BNX2X_MSG_SP, |
3654 | "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 |
3655 | bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping), |
3656 | (u32)(U64_LO(bp->spq_mapping) + | |
d6cae238 | 3657 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, common, |
6e30dd4e VZ |
3658 | HW_CID(bp, cid), data_hi, data_lo, type, |
3659 | atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left)); | |
cdaa7cb8 | 3660 | |
28912902 | 3661 | bnx2x_sp_prod_update(bp); |
34f80b04 | 3662 | spin_unlock_bh(&bp->spq_lock); |
a2fbb9ea ET |
3663 | return 0; |
3664 | } | |
3665 | ||
3666 | /* acquire split MCP access lock register */ | |
4a37fb66 | 3667 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
a2fbb9ea | 3668 | { |
72fd0718 | 3669 | u32 j, val; |
34f80b04 | 3670 | int rc = 0; |
a2fbb9ea ET |
3671 | |
3672 | might_sleep(); | |
72fd0718 | 3673 | for (j = 0; j < 1000; j++) { |
3cdeec22 YM |
3674 | REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK); |
3675 | val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK); | |
3676 | if (val & MCPR_ACCESS_LOCK_LOCK) | |
a2fbb9ea ET |
3677 | break; |
3678 | ||
639d65b8 | 3679 | usleep_range(5000, 10000); |
a2fbb9ea | 3680 | } |
3cdeec22 | 3681 | if (!(val & MCPR_ACCESS_LOCK_LOCK)) { |
19680c48 | 3682 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
a2fbb9ea ET |
3683 | rc = -EBUSY; |
3684 | } | |
3685 | ||
3686 | return rc; | |
3687 | } | |
3688 | ||
4a37fb66 YG |
3689 | /* release split MCP access lock register */ |
3690 | static void bnx2x_release_alr(struct bnx2x *bp) | |
a2fbb9ea | 3691 | { |
3cdeec22 | 3692 | REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0); |
a2fbb9ea ET |
3693 | } |
3694 | ||
523224a3 DK |
3695 | #define BNX2X_DEF_SB_ATT_IDX 0x0001 |
3696 | #define BNX2X_DEF_SB_IDX 0x0002 | |
3697 | ||
1191cb83 | 3698 | static u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
a2fbb9ea | 3699 | { |
523224a3 | 3700 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
a2fbb9ea ET |
3701 | u16 rc = 0; |
3702 | ||
3703 | barrier(); /* status block is written to by the chip */ | |
a2fbb9ea ET |
3704 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
3705 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; | |
523224a3 | 3706 | rc |= BNX2X_DEF_SB_ATT_IDX; |
a2fbb9ea | 3707 | } |
523224a3 DK |
3708 | |
3709 | if (bp->def_idx != def_sb->sp_sb.running_index) { | |
3710 | bp->def_idx = def_sb->sp_sb.running_index; | |
3711 | rc |= BNX2X_DEF_SB_IDX; | |
a2fbb9ea | 3712 | } |
523224a3 | 3713 | |
16a5fd92 | 3714 | /* Do not reorder: indices reading should complete before handling */ |
523224a3 | 3715 | barrier(); |
a2fbb9ea ET |
3716 | return rc; |
3717 | } | |
3718 | ||
3719 | /* | |
3720 | * slow path service functions | |
3721 | */ | |
3722 | ||
3723 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) | |
3724 | { | |
34f80b04 | 3725 | int port = BP_PORT(bp); |
a2fbb9ea ET |
3726 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
3727 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
877e9aa4 ET |
3728 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
3729 | NIG_REG_MASK_INTERRUPT_PORT0; | |
3fcaf2e5 | 3730 | u32 aeu_mask; |
87942b46 | 3731 | u32 nig_mask = 0; |
f2e0899f | 3732 | u32 reg_addr; |
a2fbb9ea | 3733 | |
a2fbb9ea ET |
3734 | if (bp->attn_state & asserted) |
3735 | BNX2X_ERR("IGU ERROR\n"); | |
3736 | ||
3fcaf2e5 EG |
3737 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
3738 | aeu_mask = REG_RD(bp, aeu_addr); | |
3739 | ||
a2fbb9ea | 3740 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
3fcaf2e5 | 3741 | aeu_mask, asserted); |
72fd0718 | 3742 | aeu_mask &= ~(asserted & 0x3ff); |
3fcaf2e5 | 3743 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 3744 | |
3fcaf2e5 EG |
3745 | REG_WR(bp, aeu_addr, aeu_mask); |
3746 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea | 3747 | |
3fcaf2e5 | 3748 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
a2fbb9ea | 3749 | bp->attn_state |= asserted; |
3fcaf2e5 | 3750 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
a2fbb9ea ET |
3751 | |
3752 | if (asserted & ATTN_HARD_WIRED_MASK) { | |
3753 | if (asserted & ATTN_NIG_FOR_FUNC) { | |
a2fbb9ea | 3754 | |
a5e9a7cf EG |
3755 | bnx2x_acquire_phy_lock(bp); |
3756 | ||
877e9aa4 | 3757 | /* save nig interrupt mask */ |
87942b46 | 3758 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
a2fbb9ea | 3759 | |
361c391e YR |
3760 | /* If nig_mask is not set, no need to call the update |
3761 | * function. | |
3762 | */ | |
3763 | if (nig_mask) { | |
3764 | REG_WR(bp, nig_int_mask_addr, 0); | |
3765 | ||
3766 | bnx2x_link_attn(bp); | |
3767 | } | |
a2fbb9ea ET |
3768 | |
3769 | /* handle unicore attn? */ | |
3770 | } | |
3771 | if (asserted & ATTN_SW_TIMER_4_FUNC) | |
3772 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); | |
3773 | ||
3774 | if (asserted & GPIO_2_FUNC) | |
3775 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); | |
3776 | ||
3777 | if (asserted & GPIO_3_FUNC) | |
3778 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); | |
3779 | ||
3780 | if (asserted & GPIO_4_FUNC) | |
3781 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); | |
3782 | ||
3783 | if (port == 0) { | |
3784 | if (asserted & ATTN_GENERAL_ATTN_1) { | |
3785 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); | |
3786 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); | |
3787 | } | |
3788 | if (asserted & ATTN_GENERAL_ATTN_2) { | |
3789 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); | |
3790 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); | |
3791 | } | |
3792 | if (asserted & ATTN_GENERAL_ATTN_3) { | |
3793 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); | |
3794 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); | |
3795 | } | |
3796 | } else { | |
3797 | if (asserted & ATTN_GENERAL_ATTN_4) { | |
3798 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); | |
3799 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); | |
3800 | } | |
3801 | if (asserted & ATTN_GENERAL_ATTN_5) { | |
3802 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); | |
3803 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); | |
3804 | } | |
3805 | if (asserted & ATTN_GENERAL_ATTN_6) { | |
3806 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); | |
3807 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); | |
3808 | } | |
3809 | } | |
3810 | ||
3811 | } /* if hardwired */ | |
3812 | ||
f2e0899f DK |
3813 | if (bp->common.int_block == INT_BLOCK_HC) |
3814 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
3815 | COMMAND_REG_ATTN_BITS_SET); | |
3816 | else | |
3817 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); | |
3818 | ||
3819 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted, | |
3820 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
3821 | REG_WR(bp, reg_addr, asserted); | |
a2fbb9ea ET |
3822 | |
3823 | /* now set back the mask */ | |
a5e9a7cf | 3824 | if (asserted & ATTN_NIG_FOR_FUNC) { |
27c1151c YR |
3825 | /* Verify that IGU ack through BAR was written before restoring |
3826 | * NIG mask. This loop should exit after 2-3 iterations max. | |
3827 | */ | |
3828 | if (bp->common.int_block != INT_BLOCK_HC) { | |
3829 | u32 cnt = 0, igu_acked; | |
3830 | do { | |
3831 | igu_acked = REG_RD(bp, | |
3832 | IGU_REG_ATTENTION_ACK_BITS); | |
3833 | } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) && | |
3834 | (++cnt < MAX_IGU_ATTN_ACK_TO)); | |
3835 | if (!igu_acked) | |
3836 | DP(NETIF_MSG_HW, | |
3837 | "Failed to verify IGU ack on time\n"); | |
3838 | barrier(); | |
3839 | } | |
87942b46 | 3840 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
a5e9a7cf EG |
3841 | bnx2x_release_phy_lock(bp); |
3842 | } | |
a2fbb9ea ET |
3843 | } |
3844 | ||
1191cb83 | 3845 | static void bnx2x_fan_failure(struct bnx2x *bp) |
fd4ef40d EG |
3846 | { |
3847 | int port = BP_PORT(bp); | |
b7737c9b | 3848 | u32 ext_phy_config; |
fd4ef40d | 3849 | /* mark the failure */ |
b7737c9b YR |
3850 | ext_phy_config = |
3851 | SHMEM_RD(bp, | |
3852 | dev_info.port_hw_config[port].external_phy_config); | |
3853 | ||
3854 | ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; | |
3855 | ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; | |
fd4ef40d | 3856 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
b7737c9b | 3857 | ext_phy_config); |
fd4ef40d EG |
3858 | |
3859 | /* log the failure */ | |
51c1a580 MS |
3860 | netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n" |
3861 | "Please contact OEM Support for assistance\n"); | |
8304859a | 3862 | |
16a5fd92 | 3863 | /* Schedule device reset (unload) |
8304859a AE |
3864 | * This is due to some boards consuming sufficient power when driver is |
3865 | * up to overheat if fan fails. | |
3866 | */ | |
3867 | smp_mb__before_clear_bit(); | |
3868 | set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state); | |
3869 | smp_mb__after_clear_bit(); | |
3870 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
fd4ef40d | 3871 | } |
ab6ad5a4 | 3872 | |
1191cb83 | 3873 | static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
a2fbb9ea | 3874 | { |
34f80b04 | 3875 | int port = BP_PORT(bp); |
877e9aa4 | 3876 | int reg_offset; |
d90d96ba | 3877 | u32 val; |
877e9aa4 | 3878 | |
34f80b04 EG |
3879 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
3880 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
877e9aa4 | 3881 | |
34f80b04 | 3882 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
877e9aa4 ET |
3883 | |
3884 | val = REG_RD(bp, reg_offset); | |
3885 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; | |
3886 | REG_WR(bp, reg_offset, val); | |
3887 | ||
3888 | BNX2X_ERR("SPIO5 hw attention\n"); | |
3889 | ||
fd4ef40d | 3890 | /* Fan failure attention */ |
d90d96ba | 3891 | bnx2x_hw_reset_phy(&bp->link_params); |
fd4ef40d | 3892 | bnx2x_fan_failure(bp); |
877e9aa4 | 3893 | } |
34f80b04 | 3894 | |
3deb8167 | 3895 | if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) { |
589abe3a EG |
3896 | bnx2x_acquire_phy_lock(bp); |
3897 | bnx2x_handle_module_detect_int(&bp->link_params); | |
3898 | bnx2x_release_phy_lock(bp); | |
3899 | } | |
3900 | ||
34f80b04 EG |
3901 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
3902 | ||
3903 | val = REG_RD(bp, reg_offset); | |
3904 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); | |
3905 | REG_WR(bp, reg_offset, val); | |
3906 | ||
3907 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", | |
0fc5d009 | 3908 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
34f80b04 EG |
3909 | bnx2x_panic(); |
3910 | } | |
877e9aa4 ET |
3911 | } |
3912 | ||
1191cb83 | 3913 | static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
877e9aa4 ET |
3914 | { |
3915 | u32 val; | |
3916 | ||
0626b899 | 3917 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
877e9aa4 ET |
3918 | |
3919 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); | |
3920 | BNX2X_ERR("DB hw attention 0x%x\n", val); | |
3921 | /* DORQ discard attention */ | |
3922 | if (val & 0x2) | |
3923 | BNX2X_ERR("FATAL error from DORQ\n"); | |
3924 | } | |
34f80b04 EG |
3925 | |
3926 | if (attn & HW_INTERRUT_ASSERT_SET_1) { | |
3927 | ||
3928 | int port = BP_PORT(bp); | |
3929 | int reg_offset; | |
3930 | ||
3931 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : | |
3932 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); | |
3933 | ||
3934 | val = REG_RD(bp, reg_offset); | |
3935 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); | |
3936 | REG_WR(bp, reg_offset, val); | |
3937 | ||
3938 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", | |
0fc5d009 | 3939 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
34f80b04 EG |
3940 | bnx2x_panic(); |
3941 | } | |
877e9aa4 ET |
3942 | } |
3943 | ||
1191cb83 | 3944 | static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
877e9aa4 ET |
3945 | { |
3946 | u32 val; | |
3947 | ||
3948 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { | |
3949 | ||
3950 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); | |
3951 | BNX2X_ERR("CFC hw attention 0x%x\n", val); | |
3952 | /* CFC error attention */ | |
3953 | if (val & 0x2) | |
3954 | BNX2X_ERR("FATAL error from CFC\n"); | |
3955 | } | |
3956 | ||
3957 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { | |
877e9aa4 | 3958 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
619c5cb6 | 3959 | BNX2X_ERR("PXP hw attention-0 0x%x\n", val); |
877e9aa4 ET |
3960 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
3961 | if (val & 0x18000) | |
3962 | BNX2X_ERR("FATAL error from PXP\n"); | |
619c5cb6 VZ |
3963 | |
3964 | if (!CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
3965 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1); |
3966 | BNX2X_ERR("PXP hw attention-1 0x%x\n", val); | |
3967 | } | |
877e9aa4 | 3968 | } |
34f80b04 EG |
3969 | |
3970 | if (attn & HW_INTERRUT_ASSERT_SET_2) { | |
3971 | ||
3972 | int port = BP_PORT(bp); | |
3973 | int reg_offset; | |
3974 | ||
3975 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : | |
3976 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); | |
3977 | ||
3978 | val = REG_RD(bp, reg_offset); | |
3979 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); | |
3980 | REG_WR(bp, reg_offset, val); | |
3981 | ||
3982 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", | |
0fc5d009 | 3983 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
34f80b04 EG |
3984 | bnx2x_panic(); |
3985 | } | |
877e9aa4 ET |
3986 | } |
3987 | ||
1191cb83 | 3988 | static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
877e9aa4 | 3989 | { |
34f80b04 EG |
3990 | u32 val; |
3991 | ||
877e9aa4 ET |
3992 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
3993 | ||
34f80b04 EG |
3994 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
3995 | int func = BP_FUNC(bp); | |
3996 | ||
3997 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
a3348722 | 3998 | bnx2x_read_mf_cfg(bp); |
f2e0899f DK |
3999 | bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp, |
4000 | func_mf_config[BP_ABS_FUNC(bp)].config); | |
4001 | val = SHMEM_RD(bp, | |
4002 | func_mb[BP_FW_MB_IDX(bp)].drv_status); | |
2691d51d EG |
4003 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
4004 | bnx2x_dcc_event(bp, | |
4005 | (val & DRV_STATUS_DCC_EVENT_MASK)); | |
0793f83f DK |
4006 | |
4007 | if (val & DRV_STATUS_SET_MF_BW) | |
4008 | bnx2x_set_mf_bw(bp); | |
4009 | ||
1d187b34 BW |
4010 | if (val & DRV_STATUS_DRV_INFO_REQ) |
4011 | bnx2x_handle_drv_info_req(bp); | |
d16132ce AE |
4012 | |
4013 | if (val & DRV_STATUS_VF_DISABLED) | |
4014 | bnx2x_vf_handle_flr_event(bp); | |
4015 | ||
2691d51d | 4016 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
34f80b04 EG |
4017 | bnx2x_pmf_update(bp); |
4018 | ||
e4901dde | 4019 | if (bp->port.pmf && |
785b9b1a SR |
4020 | (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) && |
4021 | bp->dcbx_enabled > 0) | |
e4901dde VZ |
4022 | /* start dcbx state machine */ |
4023 | bnx2x_dcbx_set_params(bp, | |
4024 | BNX2X_DCBX_STATE_NEG_RECEIVED); | |
a3348722 BW |
4025 | if (val & DRV_STATUS_AFEX_EVENT_MASK) |
4026 | bnx2x_handle_afex_cmd(bp, | |
4027 | val & DRV_STATUS_AFEX_EVENT_MASK); | |
c8c60d88 YM |
4028 | if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS) |
4029 | bnx2x_handle_eee_event(bp); | |
3deb8167 YR |
4030 | if (bp->link_vars.periodic_flags & |
4031 | PERIODIC_FLAGS_LINK_EVENT) { | |
4032 | /* sync with link */ | |
4033 | bnx2x_acquire_phy_lock(bp); | |
4034 | bp->link_vars.periodic_flags &= | |
4035 | ~PERIODIC_FLAGS_LINK_EVENT; | |
4036 | bnx2x_release_phy_lock(bp); | |
4037 | if (IS_MF(bp)) | |
4038 | bnx2x_link_sync_notify(bp); | |
4039 | bnx2x_link_report(bp); | |
4040 | } | |
4041 | /* Always call it here: bnx2x_link_report() will | |
4042 | * prevent the link indication duplication. | |
4043 | */ | |
4044 | bnx2x__link_status_update(bp); | |
34f80b04 | 4045 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
877e9aa4 ET |
4046 | |
4047 | BNX2X_ERR("MC assert!\n"); | |
d6cae238 | 4048 | bnx2x_mc_assert(bp); |
877e9aa4 ET |
4049 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
4050 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); | |
4051 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); | |
4052 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); | |
4053 | bnx2x_panic(); | |
4054 | ||
4055 | } else if (attn & BNX2X_MCP_ASSERT) { | |
4056 | ||
4057 | BNX2X_ERR("MCP assert!\n"); | |
4058 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); | |
34f80b04 | 4059 | bnx2x_fw_dump(bp); |
877e9aa4 ET |
4060 | |
4061 | } else | |
4062 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); | |
4063 | } | |
4064 | ||
4065 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { | |
34f80b04 EG |
4066 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
4067 | if (attn & BNX2X_GRC_TIMEOUT) { | |
f2e0899f DK |
4068 | val = CHIP_IS_E1(bp) ? 0 : |
4069 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN); | |
34f80b04 EG |
4070 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
4071 | } | |
4072 | if (attn & BNX2X_GRC_RSV) { | |
f2e0899f DK |
4073 | val = CHIP_IS_E1(bp) ? 0 : |
4074 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN); | |
34f80b04 EG |
4075 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
4076 | } | |
877e9aa4 | 4077 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
877e9aa4 ET |
4078 | } |
4079 | } | |
4080 | ||
c9ee9206 VZ |
4081 | /* |
4082 | * Bits map: | |
4083 | * 0-7 - Engine0 load counter. | |
4084 | * 8-15 - Engine1 load counter. | |
4085 | * 16 - Engine0 RESET_IN_PROGRESS bit. | |
4086 | * 17 - Engine1 RESET_IN_PROGRESS bit. | |
4087 | * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function | |
4088 | * on the engine | |
4089 | * 19 - Engine1 ONE_IS_LOADED. | |
4090 | * 20 - Chip reset flow bit. When set none-leader must wait for both engines | |
4091 | * leader to complete (check for both RESET_IN_PROGRESS bits and not for | |
4092 | * just the one belonging to its engine). | |
4093 | * | |
4094 | */ | |
4095 | #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 | |
4096 | ||
4097 | #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff | |
4098 | #define BNX2X_PATH0_LOAD_CNT_SHIFT 0 | |
4099 | #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 | |
4100 | #define BNX2X_PATH1_LOAD_CNT_SHIFT 8 | |
4101 | #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 | |
4102 | #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 | |
4103 | #define BNX2X_GLOBAL_RESET_BIT 0x00040000 | |
4104 | ||
4105 | /* | |
4106 | * Set the GLOBAL_RESET bit. | |
4107 | * | |
4108 | * Should be run under rtnl lock | |
4109 | */ | |
4110 | void bnx2x_set_reset_global(struct bnx2x *bp) | |
4111 | { | |
f16da43b AE |
4112 | u32 val; |
4113 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
4114 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 4115 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT); |
f16da43b | 4116 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 VZ |
4117 | } |
4118 | ||
4119 | /* | |
4120 | * Clear the GLOBAL_RESET bit. | |
4121 | * | |
4122 | * Should be run under rtnl lock | |
4123 | */ | |
1191cb83 | 4124 | static void bnx2x_clear_reset_global(struct bnx2x *bp) |
c9ee9206 | 4125 | { |
f16da43b AE |
4126 | u32 val; |
4127 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
4128 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 4129 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT)); |
f16da43b | 4130 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 | 4131 | } |
f85582f8 | 4132 | |
72fd0718 | 4133 | /* |
c9ee9206 VZ |
4134 | * Checks the GLOBAL_RESET bit. |
4135 | * | |
72fd0718 VZ |
4136 | * should be run under rtnl lock |
4137 | */ | |
1191cb83 | 4138 | static bool bnx2x_reset_is_global(struct bnx2x *bp) |
c9ee9206 | 4139 | { |
3cdeec22 | 4140 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
c9ee9206 VZ |
4141 | |
4142 | DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val); | |
4143 | return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false; | |
4144 | } | |
4145 | ||
4146 | /* | |
4147 | * Clear RESET_IN_PROGRESS bit for the current engine. | |
4148 | * | |
4149 | * Should be run under rtnl lock | |
4150 | */ | |
1191cb83 | 4151 | static void bnx2x_set_reset_done(struct bnx2x *bp) |
72fd0718 | 4152 | { |
f16da43b | 4153 | u32 val; |
c9ee9206 VZ |
4154 | u32 bit = BP_PATH(bp) ? |
4155 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
4156 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4157 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
4158 | |
4159 | /* Clear the bit */ | |
4160 | val &= ~bit; | |
4161 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
4162 | |
4163 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
72fd0718 VZ |
4164 | } |
4165 | ||
4166 | /* | |
c9ee9206 VZ |
4167 | * Set RESET_IN_PROGRESS for the current engine. |
4168 | * | |
72fd0718 VZ |
4169 | * should be run under rtnl lock |
4170 | */ | |
c9ee9206 | 4171 | void bnx2x_set_reset_in_progress(struct bnx2x *bp) |
72fd0718 | 4172 | { |
f16da43b | 4173 | u32 val; |
c9ee9206 VZ |
4174 | u32 bit = BP_PATH(bp) ? |
4175 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
4176 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4177 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
4178 | |
4179 | /* Set the bit */ | |
4180 | val |= bit; | |
4181 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 4182 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
4183 | } |
4184 | ||
4185 | /* | |
c9ee9206 | 4186 | * Checks the RESET_IN_PROGRESS bit for the given engine. |
72fd0718 VZ |
4187 | * should be run under rtnl lock |
4188 | */ | |
c9ee9206 | 4189 | bool bnx2x_reset_is_done(struct bnx2x *bp, int engine) |
72fd0718 | 4190 | { |
3cdeec22 | 4191 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
c9ee9206 VZ |
4192 | u32 bit = engine ? |
4193 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
4194 | ||
4195 | /* return false if bit is set */ | |
4196 | return (val & bit) ? false : true; | |
72fd0718 VZ |
4197 | } |
4198 | ||
4199 | /* | |
889b9af3 | 4200 | * set pf load for the current pf. |
c9ee9206 | 4201 | * |
72fd0718 VZ |
4202 | * should be run under rtnl lock |
4203 | */ | |
889b9af3 | 4204 | void bnx2x_set_pf_load(struct bnx2x *bp) |
72fd0718 | 4205 | { |
f16da43b | 4206 | u32 val1, val; |
c9ee9206 VZ |
4207 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
4208 | BNX2X_PATH0_LOAD_CNT_MASK; | |
4209 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4210 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 4211 | |
f16da43b AE |
4212 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4213 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
4214 | ||
51c1a580 | 4215 | DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 4216 | |
c9ee9206 VZ |
4217 | /* get the current counter value */ |
4218 | val1 = (val & mask) >> shift; | |
4219 | ||
889b9af3 AE |
4220 | /* set bit of that PF */ |
4221 | val1 |= (1 << bp->pf_num); | |
c9ee9206 VZ |
4222 | |
4223 | /* clear the old value */ | |
4224 | val &= ~mask; | |
4225 | ||
4226 | /* set the new one */ | |
4227 | val |= ((val1 << shift) & mask); | |
4228 | ||
4229 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 4230 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
4231 | } |
4232 | ||
c9ee9206 | 4233 | /** |
889b9af3 | 4234 | * bnx2x_clear_pf_load - clear pf load mark |
c9ee9206 VZ |
4235 | * |
4236 | * @bp: driver handle | |
4237 | * | |
4238 | * Should be run under rtnl lock. | |
4239 | * Decrements the load counter for the current engine. Returns | |
889b9af3 | 4240 | * whether other functions are still loaded |
72fd0718 | 4241 | */ |
889b9af3 | 4242 | bool bnx2x_clear_pf_load(struct bnx2x *bp) |
72fd0718 | 4243 | { |
f16da43b | 4244 | u32 val1, val; |
c9ee9206 VZ |
4245 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
4246 | BNX2X_PATH0_LOAD_CNT_MASK; | |
4247 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4248 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 4249 | |
f16da43b AE |
4250 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4251 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
51c1a580 | 4252 | DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 4253 | |
c9ee9206 VZ |
4254 | /* get the current counter value */ |
4255 | val1 = (val & mask) >> shift; | |
4256 | ||
889b9af3 AE |
4257 | /* clear bit of that PF */ |
4258 | val1 &= ~(1 << bp->pf_num); | |
c9ee9206 VZ |
4259 | |
4260 | /* clear the old value */ | |
4261 | val &= ~mask; | |
4262 | ||
4263 | /* set the new one */ | |
4264 | val |= ((val1 << shift) & mask); | |
4265 | ||
4266 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
4267 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
4268 | return val1 != 0; | |
72fd0718 VZ |
4269 | } |
4270 | ||
4271 | /* | |
889b9af3 | 4272 | * Read the load status for the current engine. |
c9ee9206 | 4273 | * |
72fd0718 VZ |
4274 | * should be run under rtnl lock |
4275 | */ | |
1191cb83 | 4276 | static bool bnx2x_get_load_status(struct bnx2x *bp, int engine) |
72fd0718 | 4277 | { |
c9ee9206 VZ |
4278 | u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK : |
4279 | BNX2X_PATH0_LOAD_CNT_MASK); | |
4280 | u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
4281 | BNX2X_PATH0_LOAD_CNT_SHIFT); | |
4282 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
4283 | ||
51c1a580 | 4284 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val); |
c9ee9206 VZ |
4285 | |
4286 | val = (val & mask) >> shift; | |
4287 | ||
51c1a580 MS |
4288 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n", |
4289 | engine, val); | |
c9ee9206 | 4290 | |
889b9af3 | 4291 | return val != 0; |
72fd0718 VZ |
4292 | } |
4293 | ||
6bf07b8e YM |
4294 | static void _print_parity(struct bnx2x *bp, u32 reg) |
4295 | { | |
4296 | pr_cont(" [0x%08x] ", REG_RD(bp, reg)); | |
4297 | } | |
4298 | ||
1191cb83 | 4299 | static void _print_next_block(int idx, const char *blk) |
72fd0718 | 4300 | { |
f1deab50 | 4301 | pr_cont("%s%s", idx ? ", " : "", blk); |
72fd0718 VZ |
4302 | } |
4303 | ||
4293b9f5 DK |
4304 | static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig, |
4305 | int *par_num, bool print) | |
72fd0718 | 4306 | { |
4293b9f5 DK |
4307 | u32 cur_bit; |
4308 | bool res; | |
4309 | int i; | |
4310 | ||
4311 | res = false; | |
4312 | ||
72fd0718 | 4313 | for (i = 0; sig; i++) { |
4293b9f5 | 4314 | cur_bit = (0x1UL << i); |
72fd0718 | 4315 | if (sig & cur_bit) { |
4293b9f5 DK |
4316 | res |= true; /* Each bit is real error! */ |
4317 | ||
4318 | if (print) { | |
4319 | switch (cur_bit) { | |
4320 | case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: | |
4321 | _print_next_block((*par_num)++, "BRB"); | |
6bf07b8e YM |
4322 | _print_parity(bp, |
4323 | BRB1_REG_BRB1_PRTY_STS); | |
4293b9f5 DK |
4324 | break; |
4325 | case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: | |
4326 | _print_next_block((*par_num)++, | |
4327 | "PARSER"); | |
6bf07b8e | 4328 | _print_parity(bp, PRS_REG_PRS_PRTY_STS); |
4293b9f5 DK |
4329 | break; |
4330 | case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: | |
4331 | _print_next_block((*par_num)++, "TSDM"); | |
6bf07b8e YM |
4332 | _print_parity(bp, |
4333 | TSDM_REG_TSDM_PRTY_STS); | |
4293b9f5 DK |
4334 | break; |
4335 | case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: | |
4336 | _print_next_block((*par_num)++, | |
c9ee9206 | 4337 | "SEARCHER"); |
6bf07b8e | 4338 | _print_parity(bp, SRC_REG_SRC_PRTY_STS); |
4293b9f5 DK |
4339 | break; |
4340 | case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: | |
4341 | _print_next_block((*par_num)++, "TCM"); | |
4342 | _print_parity(bp, TCM_REG_TCM_PRTY_STS); | |
4343 | break; | |
4344 | case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: | |
4345 | _print_next_block((*par_num)++, | |
4346 | "TSEMI"); | |
6bf07b8e YM |
4347 | _print_parity(bp, |
4348 | TSEM_REG_TSEM_PRTY_STS_0); | |
4349 | _print_parity(bp, | |
4350 | TSEM_REG_TSEM_PRTY_STS_1); | |
4293b9f5 DK |
4351 | break; |
4352 | case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: | |
4353 | _print_next_block((*par_num)++, "XPB"); | |
6bf07b8e YM |
4354 | _print_parity(bp, GRCBASE_XPB + |
4355 | PB_REG_PB_PRTY_STS); | |
4293b9f5 | 4356 | break; |
6bf07b8e | 4357 | } |
72fd0718 VZ |
4358 | } |
4359 | ||
4360 | /* Clear the bit */ | |
4361 | sig &= ~cur_bit; | |
4362 | } | |
4363 | } | |
4364 | ||
4293b9f5 | 4365 | return res; |
72fd0718 VZ |
4366 | } |
4367 | ||
4293b9f5 DK |
4368 | static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig, |
4369 | int *par_num, bool *global, | |
6bf07b8e | 4370 | bool print) |
72fd0718 | 4371 | { |
4293b9f5 DK |
4372 | u32 cur_bit; |
4373 | bool res; | |
4374 | int i; | |
4375 | ||
4376 | res = false; | |
4377 | ||
72fd0718 | 4378 | for (i = 0; sig; i++) { |
4293b9f5 | 4379 | cur_bit = (0x1UL << i); |
72fd0718 | 4380 | if (sig & cur_bit) { |
4293b9f5 | 4381 | res |= true; /* Each bit is real error! */ |
72fd0718 | 4382 | switch (cur_bit) { |
c9ee9206 | 4383 | case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: |
6bf07b8e | 4384 | if (print) { |
4293b9f5 | 4385 | _print_next_block((*par_num)++, "PBF"); |
6bf07b8e YM |
4386 | _print_parity(bp, PBF_REG_PBF_PRTY_STS); |
4387 | } | |
72fd0718 VZ |
4388 | break; |
4389 | case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: | |
6bf07b8e | 4390 | if (print) { |
4293b9f5 | 4391 | _print_next_block((*par_num)++, "QM"); |
6bf07b8e YM |
4392 | _print_parity(bp, QM_REG_QM_PRTY_STS); |
4393 | } | |
c9ee9206 VZ |
4394 | break; |
4395 | case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: | |
6bf07b8e | 4396 | if (print) { |
4293b9f5 | 4397 | _print_next_block((*par_num)++, "TM"); |
6bf07b8e YM |
4398 | _print_parity(bp, TM_REG_TM_PRTY_STS); |
4399 | } | |
72fd0718 VZ |
4400 | break; |
4401 | case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: | |
6bf07b8e | 4402 | if (print) { |
4293b9f5 | 4403 | _print_next_block((*par_num)++, "XSDM"); |
6bf07b8e YM |
4404 | _print_parity(bp, |
4405 | XSDM_REG_XSDM_PRTY_STS); | |
4406 | } | |
c9ee9206 VZ |
4407 | break; |
4408 | case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: | |
6bf07b8e | 4409 | if (print) { |
4293b9f5 | 4410 | _print_next_block((*par_num)++, "XCM"); |
6bf07b8e YM |
4411 | _print_parity(bp, XCM_REG_XCM_PRTY_STS); |
4412 | } | |
72fd0718 VZ |
4413 | break; |
4414 | case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: | |
6bf07b8e | 4415 | if (print) { |
4293b9f5 DK |
4416 | _print_next_block((*par_num)++, |
4417 | "XSEMI"); | |
6bf07b8e YM |
4418 | _print_parity(bp, |
4419 | XSEM_REG_XSEM_PRTY_STS_0); | |
4420 | _print_parity(bp, | |
4421 | XSEM_REG_XSEM_PRTY_STS_1); | |
4422 | } | |
72fd0718 VZ |
4423 | break; |
4424 | case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: | |
6bf07b8e | 4425 | if (print) { |
4293b9f5 | 4426 | _print_next_block((*par_num)++, |
c9ee9206 | 4427 | "DOORBELLQ"); |
6bf07b8e YM |
4428 | _print_parity(bp, |
4429 | DORQ_REG_DORQ_PRTY_STS); | |
4430 | } | |
c9ee9206 VZ |
4431 | break; |
4432 | case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: | |
6bf07b8e | 4433 | if (print) { |
4293b9f5 | 4434 | _print_next_block((*par_num)++, "NIG"); |
6bf07b8e YM |
4435 | if (CHIP_IS_E1x(bp)) { |
4436 | _print_parity(bp, | |
4437 | NIG_REG_NIG_PRTY_STS); | |
4438 | } else { | |
4439 | _print_parity(bp, | |
4440 | NIG_REG_NIG_PRTY_STS_0); | |
4441 | _print_parity(bp, | |
4442 | NIG_REG_NIG_PRTY_STS_1); | |
4443 | } | |
4444 | } | |
72fd0718 VZ |
4445 | break; |
4446 | case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: | |
c9ee9206 | 4447 | if (print) |
4293b9f5 | 4448 | _print_next_block((*par_num)++, |
c9ee9206 VZ |
4449 | "VAUX PCI CORE"); |
4450 | *global = true; | |
72fd0718 VZ |
4451 | break; |
4452 | case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: | |
6bf07b8e | 4453 | if (print) { |
4293b9f5 DK |
4454 | _print_next_block((*par_num)++, |
4455 | "DEBUG"); | |
6bf07b8e YM |
4456 | _print_parity(bp, DBG_REG_DBG_PRTY_STS); |
4457 | } | |
72fd0718 VZ |
4458 | break; |
4459 | case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: | |
6bf07b8e | 4460 | if (print) { |
4293b9f5 | 4461 | _print_next_block((*par_num)++, "USDM"); |
6bf07b8e YM |
4462 | _print_parity(bp, |
4463 | USDM_REG_USDM_PRTY_STS); | |
4464 | } | |
72fd0718 | 4465 | break; |
8736c826 | 4466 | case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR: |
6bf07b8e | 4467 | if (print) { |
4293b9f5 | 4468 | _print_next_block((*par_num)++, "UCM"); |
6bf07b8e YM |
4469 | _print_parity(bp, UCM_REG_UCM_PRTY_STS); |
4470 | } | |
8736c826 | 4471 | break; |
72fd0718 | 4472 | case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: |
6bf07b8e | 4473 | if (print) { |
4293b9f5 DK |
4474 | _print_next_block((*par_num)++, |
4475 | "USEMI"); | |
6bf07b8e YM |
4476 | _print_parity(bp, |
4477 | USEM_REG_USEM_PRTY_STS_0); | |
4478 | _print_parity(bp, | |
4479 | USEM_REG_USEM_PRTY_STS_1); | |
4480 | } | |
72fd0718 VZ |
4481 | break; |
4482 | case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: | |
6bf07b8e | 4483 | if (print) { |
4293b9f5 | 4484 | _print_next_block((*par_num)++, "UPB"); |
6bf07b8e YM |
4485 | _print_parity(bp, GRCBASE_UPB + |
4486 | PB_REG_PB_PRTY_STS); | |
4487 | } | |
72fd0718 VZ |
4488 | break; |
4489 | case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: | |
6bf07b8e | 4490 | if (print) { |
4293b9f5 | 4491 | _print_next_block((*par_num)++, "CSDM"); |
6bf07b8e YM |
4492 | _print_parity(bp, |
4493 | CSDM_REG_CSDM_PRTY_STS); | |
4494 | } | |
72fd0718 | 4495 | break; |
8736c826 | 4496 | case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR: |
6bf07b8e | 4497 | if (print) { |
4293b9f5 | 4498 | _print_next_block((*par_num)++, "CCM"); |
6bf07b8e YM |
4499 | _print_parity(bp, CCM_REG_CCM_PRTY_STS); |
4500 | } | |
8736c826 | 4501 | break; |
72fd0718 VZ |
4502 | } |
4503 | ||
4504 | /* Clear the bit */ | |
4505 | sig &= ~cur_bit; | |
4506 | } | |
4507 | } | |
4508 | ||
4293b9f5 | 4509 | return res; |
72fd0718 VZ |
4510 | } |
4511 | ||
4293b9f5 DK |
4512 | static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig, |
4513 | int *par_num, bool print) | |
72fd0718 | 4514 | { |
4293b9f5 DK |
4515 | u32 cur_bit; |
4516 | bool res; | |
4517 | int i; | |
4518 | ||
4519 | res = false; | |
4520 | ||
72fd0718 | 4521 | for (i = 0; sig; i++) { |
4293b9f5 | 4522 | cur_bit = (0x1UL << i); |
72fd0718 | 4523 | if (sig & cur_bit) { |
4293b9f5 DK |
4524 | res |= true; /* Each bit is real error! */ |
4525 | if (print) { | |
4526 | switch (cur_bit) { | |
4527 | case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: | |
4528 | _print_next_block((*par_num)++, | |
4529 | "CSEMI"); | |
6bf07b8e YM |
4530 | _print_parity(bp, |
4531 | CSEM_REG_CSEM_PRTY_STS_0); | |
4532 | _print_parity(bp, | |
4533 | CSEM_REG_CSEM_PRTY_STS_1); | |
4293b9f5 DK |
4534 | break; |
4535 | case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: | |
4536 | _print_next_block((*par_num)++, "PXP"); | |
6bf07b8e YM |
4537 | _print_parity(bp, PXP_REG_PXP_PRTY_STS); |
4538 | _print_parity(bp, | |
4539 | PXP2_REG_PXP2_PRTY_STS_0); | |
4540 | _print_parity(bp, | |
4541 | PXP2_REG_PXP2_PRTY_STS_1); | |
4293b9f5 DK |
4542 | break; |
4543 | case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: | |
4544 | _print_next_block((*par_num)++, | |
4545 | "PXPPCICLOCKCLIENT"); | |
4546 | break; | |
4547 | case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: | |
4548 | _print_next_block((*par_num)++, "CFC"); | |
6bf07b8e YM |
4549 | _print_parity(bp, |
4550 | CFC_REG_CFC_PRTY_STS); | |
4293b9f5 DK |
4551 | break; |
4552 | case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: | |
4553 | _print_next_block((*par_num)++, "CDU"); | |
6bf07b8e | 4554 | _print_parity(bp, CDU_REG_CDU_PRTY_STS); |
4293b9f5 DK |
4555 | break; |
4556 | case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: | |
4557 | _print_next_block((*par_num)++, "DMAE"); | |
6bf07b8e YM |
4558 | _print_parity(bp, |
4559 | DMAE_REG_DMAE_PRTY_STS); | |
4293b9f5 DK |
4560 | break; |
4561 | case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: | |
4562 | _print_next_block((*par_num)++, "IGU"); | |
6bf07b8e YM |
4563 | if (CHIP_IS_E1x(bp)) |
4564 | _print_parity(bp, | |
4565 | HC_REG_HC_PRTY_STS); | |
4566 | else | |
4567 | _print_parity(bp, | |
4568 | IGU_REG_IGU_PRTY_STS); | |
4293b9f5 DK |
4569 | break; |
4570 | case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: | |
4571 | _print_next_block((*par_num)++, "MISC"); | |
6bf07b8e YM |
4572 | _print_parity(bp, |
4573 | MISC_REG_MISC_PRTY_STS); | |
4293b9f5 | 4574 | break; |
6bf07b8e | 4575 | } |
72fd0718 VZ |
4576 | } |
4577 | ||
4578 | /* Clear the bit */ | |
4579 | sig &= ~cur_bit; | |
4580 | } | |
4581 | } | |
4582 | ||
4293b9f5 | 4583 | return res; |
72fd0718 VZ |
4584 | } |
4585 | ||
4293b9f5 DK |
4586 | static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig, |
4587 | int *par_num, bool *global, | |
4588 | bool print) | |
72fd0718 | 4589 | { |
4293b9f5 DK |
4590 | bool res = false; |
4591 | u32 cur_bit; | |
4592 | int i; | |
4593 | ||
72fd0718 | 4594 | for (i = 0; sig; i++) { |
4293b9f5 | 4595 | cur_bit = (0x1UL << i); |
72fd0718 VZ |
4596 | if (sig & cur_bit) { |
4597 | switch (cur_bit) { | |
4598 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: | |
c9ee9206 | 4599 | if (print) |
4293b9f5 DK |
4600 | _print_next_block((*par_num)++, |
4601 | "MCP ROM"); | |
c9ee9206 | 4602 | *global = true; |
4293b9f5 | 4603 | res |= true; |
72fd0718 VZ |
4604 | break; |
4605 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: | |
c9ee9206 | 4606 | if (print) |
4293b9f5 | 4607 | _print_next_block((*par_num)++, |
c9ee9206 VZ |
4608 | "MCP UMP RX"); |
4609 | *global = true; | |
4293b9f5 | 4610 | res |= true; |
72fd0718 VZ |
4611 | break; |
4612 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: | |
c9ee9206 | 4613 | if (print) |
4293b9f5 | 4614 | _print_next_block((*par_num)++, |
c9ee9206 VZ |
4615 | "MCP UMP TX"); |
4616 | *global = true; | |
4293b9f5 | 4617 | res |= true; |
72fd0718 VZ |
4618 | break; |
4619 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: | |
c9ee9206 | 4620 | if (print) |
4293b9f5 | 4621 | _print_next_block((*par_num)++, |
c9ee9206 | 4622 | "MCP SCPAD"); |
4293b9f5 DK |
4623 | /* clear latched SCPAD PATIRY from MCP */ |
4624 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, | |
4625 | 1UL << 10); | |
72fd0718 VZ |
4626 | break; |
4627 | } | |
4628 | ||
4629 | /* Clear the bit */ | |
4630 | sig &= ~cur_bit; | |
4631 | } | |
4632 | } | |
4633 | ||
4293b9f5 | 4634 | return res; |
72fd0718 VZ |
4635 | } |
4636 | ||
4293b9f5 DK |
4637 | static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig, |
4638 | int *par_num, bool print) | |
8736c826 | 4639 | { |
4293b9f5 DK |
4640 | u32 cur_bit; |
4641 | bool res; | |
4642 | int i; | |
4643 | ||
4644 | res = false; | |
4645 | ||
8736c826 | 4646 | for (i = 0; sig; i++) { |
4293b9f5 | 4647 | cur_bit = (0x1UL << i); |
8736c826 | 4648 | if (sig & cur_bit) { |
4293b9f5 DK |
4649 | res |= true; /* Each bit is real error! */ |
4650 | if (print) { | |
4651 | switch (cur_bit) { | |
4652 | case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR: | |
4653 | _print_next_block((*par_num)++, | |
4654 | "PGLUE_B"); | |
6bf07b8e | 4655 | _print_parity(bp, |
4293b9f5 DK |
4656 | PGLUE_B_REG_PGLUE_B_PRTY_STS); |
4657 | break; | |
4658 | case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR: | |
4659 | _print_next_block((*par_num)++, "ATC"); | |
6bf07b8e YM |
4660 | _print_parity(bp, |
4661 | ATC_REG_ATC_PRTY_STS); | |
4293b9f5 | 4662 | break; |
6bf07b8e | 4663 | } |
8736c826 | 4664 | } |
8736c826 VZ |
4665 | /* Clear the bit */ |
4666 | sig &= ~cur_bit; | |
4667 | } | |
4668 | } | |
4669 | ||
4293b9f5 | 4670 | return res; |
8736c826 VZ |
4671 | } |
4672 | ||
1191cb83 ED |
4673 | static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, |
4674 | u32 *sig) | |
72fd0718 | 4675 | { |
4293b9f5 DK |
4676 | bool res = false; |
4677 | ||
8736c826 VZ |
4678 | if ((sig[0] & HW_PRTY_ASSERT_SET_0) || |
4679 | (sig[1] & HW_PRTY_ASSERT_SET_1) || | |
4680 | (sig[2] & HW_PRTY_ASSERT_SET_2) || | |
4681 | (sig[3] & HW_PRTY_ASSERT_SET_3) || | |
4682 | (sig[4] & HW_PRTY_ASSERT_SET_4)) { | |
72fd0718 | 4683 | int par_num = 0; |
51c1a580 MS |
4684 | DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n" |
4685 | "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n", | |
8736c826 VZ |
4686 | sig[0] & HW_PRTY_ASSERT_SET_0, |
4687 | sig[1] & HW_PRTY_ASSERT_SET_1, | |
4688 | sig[2] & HW_PRTY_ASSERT_SET_2, | |
4689 | sig[3] & HW_PRTY_ASSERT_SET_3, | |
4690 | sig[4] & HW_PRTY_ASSERT_SET_4); | |
c9ee9206 VZ |
4691 | if (print) |
4692 | netdev_err(bp->dev, | |
4693 | "Parity errors detected in blocks: "); | |
4293b9f5 DK |
4694 | res |= bnx2x_check_blocks_with_parity0(bp, |
4695 | sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print); | |
4696 | res |= bnx2x_check_blocks_with_parity1(bp, | |
4697 | sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print); | |
4698 | res |= bnx2x_check_blocks_with_parity2(bp, | |
4699 | sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print); | |
4700 | res |= bnx2x_check_blocks_with_parity3(bp, | |
4701 | sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print); | |
4702 | res |= bnx2x_check_blocks_with_parity4(bp, | |
4703 | sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print); | |
8736c826 | 4704 | |
c9ee9206 VZ |
4705 | if (print) |
4706 | pr_cont("\n"); | |
4293b9f5 | 4707 | } |
8736c826 | 4708 | |
4293b9f5 | 4709 | return res; |
72fd0718 VZ |
4710 | } |
4711 | ||
c9ee9206 VZ |
4712 | /** |
4713 | * bnx2x_chk_parity_attn - checks for parity attentions. | |
4714 | * | |
4715 | * @bp: driver handle | |
4716 | * @global: true if there was a global attention | |
4717 | * @print: show parity attention in syslog | |
4718 | */ | |
4719 | bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print) | |
877e9aa4 | 4720 | { |
8736c826 | 4721 | struct attn_route attn = { {0} }; |
72fd0718 VZ |
4722 | int port = BP_PORT(bp); |
4723 | ||
4724 | attn.sig[0] = REG_RD(bp, | |
4725 | MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + | |
4726 | port*4); | |
4727 | attn.sig[1] = REG_RD(bp, | |
4728 | MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + | |
4729 | port*4); | |
4730 | attn.sig[2] = REG_RD(bp, | |
4731 | MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + | |
4732 | port*4); | |
4733 | attn.sig[3] = REG_RD(bp, | |
4734 | MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + | |
4735 | port*4); | |
0a5ccb75 YM |
4736 | /* Since MCP attentions can't be disabled inside the block, we need to |
4737 | * read AEU registers to see whether they're currently disabled | |
4738 | */ | |
4739 | attn.sig[3] &= ((REG_RD(bp, | |
4740 | !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0 | |
4741 | : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) & | |
4742 | MISC_AEU_ENABLE_MCP_PRTY_BITS) | | |
4743 | ~MISC_AEU_ENABLE_MCP_PRTY_BITS); | |
72fd0718 | 4744 | |
8736c826 VZ |
4745 | if (!CHIP_IS_E1x(bp)) |
4746 | attn.sig[4] = REG_RD(bp, | |
4747 | MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + | |
4748 | port*4); | |
4749 | ||
4750 | return bnx2x_parity_attn(bp, global, print, attn.sig); | |
72fd0718 VZ |
4751 | } |
4752 | ||
1191cb83 | 4753 | static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn) |
f2e0899f DK |
4754 | { |
4755 | u32 val; | |
4756 | if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { | |
4757 | ||
4758 | val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); | |
4759 | BNX2X_ERR("PGLUE hw attention 0x%x\n", val); | |
4760 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) | |
51c1a580 | 4761 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n"); |
f2e0899f | 4762 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) |
51c1a580 | 4763 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n"); |
f2e0899f | 4764 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) |
51c1a580 | 4765 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n"); |
f2e0899f | 4766 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) |
51c1a580 | 4767 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n"); |
f2e0899f DK |
4768 | if (val & |
4769 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) | |
51c1a580 | 4770 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n"); |
f2e0899f DK |
4771 | if (val & |
4772 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) | |
51c1a580 | 4773 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n"); |
f2e0899f | 4774 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) |
51c1a580 | 4775 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n"); |
f2e0899f | 4776 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) |
51c1a580 | 4777 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n"); |
f2e0899f | 4778 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) |
51c1a580 | 4779 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n"); |
f2e0899f DK |
4780 | } |
4781 | if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { | |
4782 | val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR); | |
4783 | BNX2X_ERR("ATC hw attention 0x%x\n", val); | |
4784 | if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) | |
4785 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); | |
4786 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) | |
51c1a580 | 4787 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n"); |
f2e0899f | 4788 | if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) |
51c1a580 | 4789 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n"); |
f2e0899f | 4790 | if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) |
51c1a580 | 4791 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n"); |
f2e0899f DK |
4792 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) |
4793 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); | |
4794 | if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) | |
51c1a580 | 4795 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n"); |
f2e0899f DK |
4796 | } |
4797 | ||
4798 | if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4799 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { | |
4800 | BNX2X_ERR("FATAL parity attention set4 0x%x\n", | |
4801 | (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4802 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); | |
4803 | } | |
f2e0899f DK |
4804 | } |
4805 | ||
72fd0718 VZ |
4806 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
4807 | { | |
4808 | struct attn_route attn, *group_mask; | |
34f80b04 | 4809 | int port = BP_PORT(bp); |
877e9aa4 | 4810 | int index; |
a2fbb9ea ET |
4811 | u32 reg_addr; |
4812 | u32 val; | |
3fcaf2e5 | 4813 | u32 aeu_mask; |
c9ee9206 | 4814 | bool global = false; |
a2fbb9ea ET |
4815 | |
4816 | /* need to take HW lock because MCP or other port might also | |
4817 | try to handle this event */ | |
4a37fb66 | 4818 | bnx2x_acquire_alr(bp); |
a2fbb9ea | 4819 | |
c9ee9206 VZ |
4820 | if (bnx2x_chk_parity_attn(bp, &global, true)) { |
4821 | #ifndef BNX2X_STOP_ON_ERROR | |
72fd0718 | 4822 | bp->recovery_state = BNX2X_RECOVERY_INIT; |
7be08a72 | 4823 | schedule_delayed_work(&bp->sp_rtnl_task, 0); |
72fd0718 VZ |
4824 | /* Disable HW interrupts */ |
4825 | bnx2x_int_disable(bp); | |
72fd0718 VZ |
4826 | /* In case of parity errors don't handle attentions so that |
4827 | * other function would "see" parity errors. | |
4828 | */ | |
c9ee9206 VZ |
4829 | #else |
4830 | bnx2x_panic(); | |
4831 | #endif | |
4832 | bnx2x_release_alr(bp); | |
72fd0718 VZ |
4833 | return; |
4834 | } | |
4835 | ||
a2fbb9ea ET |
4836 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
4837 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); | |
4838 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); | |
4839 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); | |
619c5cb6 | 4840 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
4841 | attn.sig[4] = |
4842 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); | |
4843 | else | |
4844 | attn.sig[4] = 0; | |
4845 | ||
4846 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n", | |
4847 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); | |
a2fbb9ea ET |
4848 | |
4849 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { | |
4850 | if (deasserted & (1 << index)) { | |
72fd0718 | 4851 | group_mask = &bp->attn_group[index]; |
a2fbb9ea | 4852 | |
51c1a580 | 4853 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n", |
f2e0899f DK |
4854 | index, |
4855 | group_mask->sig[0], group_mask->sig[1], | |
4856 | group_mask->sig[2], group_mask->sig[3], | |
4857 | group_mask->sig[4]); | |
a2fbb9ea | 4858 | |
f2e0899f DK |
4859 | bnx2x_attn_int_deasserted4(bp, |
4860 | attn.sig[4] & group_mask->sig[4]); | |
877e9aa4 | 4861 | bnx2x_attn_int_deasserted3(bp, |
72fd0718 | 4862 | attn.sig[3] & group_mask->sig[3]); |
877e9aa4 | 4863 | bnx2x_attn_int_deasserted1(bp, |
72fd0718 | 4864 | attn.sig[1] & group_mask->sig[1]); |
877e9aa4 | 4865 | bnx2x_attn_int_deasserted2(bp, |
72fd0718 | 4866 | attn.sig[2] & group_mask->sig[2]); |
877e9aa4 | 4867 | bnx2x_attn_int_deasserted0(bp, |
72fd0718 | 4868 | attn.sig[0] & group_mask->sig[0]); |
a2fbb9ea ET |
4869 | } |
4870 | } | |
4871 | ||
4a37fb66 | 4872 | bnx2x_release_alr(bp); |
a2fbb9ea | 4873 | |
f2e0899f DK |
4874 | if (bp->common.int_block == INT_BLOCK_HC) |
4875 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
4876 | COMMAND_REG_ATTN_BITS_CLR); | |
4877 | else | |
4878 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); | |
a2fbb9ea ET |
4879 | |
4880 | val = ~deasserted; | |
f2e0899f DK |
4881 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val, |
4882 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
5c862848 | 4883 | REG_WR(bp, reg_addr, val); |
a2fbb9ea | 4884 | |
a2fbb9ea | 4885 | if (~bp->attn_state & deasserted) |
3fcaf2e5 | 4886 | BNX2X_ERR("IGU ERROR\n"); |
a2fbb9ea ET |
4887 | |
4888 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
4889 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
4890 | ||
3fcaf2e5 EG |
4891 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
4892 | aeu_mask = REG_RD(bp, reg_addr); | |
4893 | ||
4894 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", | |
4895 | aeu_mask, deasserted); | |
72fd0718 | 4896 | aeu_mask |= (deasserted & 0x3ff); |
3fcaf2e5 | 4897 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 4898 | |
3fcaf2e5 EG |
4899 | REG_WR(bp, reg_addr, aeu_mask); |
4900 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea ET |
4901 | |
4902 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); | |
4903 | bp->attn_state &= ~deasserted; | |
4904 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); | |
4905 | } | |
4906 | ||
4907 | static void bnx2x_attn_int(struct bnx2x *bp) | |
4908 | { | |
4909 | /* read local copy of bits */ | |
68d59484 EG |
4910 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
4911 | attn_bits); | |
4912 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. | |
4913 | attn_bits_ack); | |
a2fbb9ea ET |
4914 | u32 attn_state = bp->attn_state; |
4915 | ||
4916 | /* look for changed bits */ | |
4917 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; | |
4918 | u32 deasserted = ~attn_bits & attn_ack & attn_state; | |
4919 | ||
4920 | DP(NETIF_MSG_HW, | |
4921 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", | |
4922 | attn_bits, attn_ack, asserted, deasserted); | |
4923 | ||
4924 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) | |
34f80b04 | 4925 | BNX2X_ERR("BAD attention state\n"); |
a2fbb9ea ET |
4926 | |
4927 | /* handle bits that were raised */ | |
4928 | if (asserted) | |
4929 | bnx2x_attn_int_asserted(bp, asserted); | |
4930 | ||
4931 | if (deasserted) | |
4932 | bnx2x_attn_int_deasserted(bp, deasserted); | |
4933 | } | |
4934 | ||
619c5cb6 VZ |
4935 | void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
4936 | u16 index, u8 op, u8 update) | |
4937 | { | |
dc1ba591 AE |
4938 | u32 igu_addr = bp->igu_base_addr; |
4939 | igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; | |
619c5cb6 VZ |
4940 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, |
4941 | igu_addr); | |
4942 | } | |
4943 | ||
1191cb83 | 4944 | static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod) |
523224a3 DK |
4945 | { |
4946 | /* No memory barriers */ | |
4947 | storm_memset_eq_prod(bp, prod, BP_FUNC(bp)); | |
4948 | mmiowb(); /* keep prod updates ordered */ | |
4949 | } | |
4950 | ||
523224a3 DK |
4951 | static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid, |
4952 | union event_ring_elem *elem) | |
4953 | { | |
619c5cb6 VZ |
4954 | u8 err = elem->message.error; |
4955 | ||
523224a3 | 4956 | if (!bp->cnic_eth_dev.starting_cid || |
c3a8ce61 VZ |
4957 | (cid < bp->cnic_eth_dev.starting_cid && |
4958 | cid != bp->cnic_eth_dev.iscsi_l2_cid)) | |
523224a3 DK |
4959 | return 1; |
4960 | ||
4961 | DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid); | |
4962 | ||
619c5cb6 VZ |
4963 | if (unlikely(err)) { |
4964 | ||
523224a3 DK |
4965 | BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n", |
4966 | cid); | |
823e1d90 | 4967 | bnx2x_panic_dump(bp, false); |
523224a3 | 4968 | } |
619c5cb6 | 4969 | bnx2x_cnic_cfc_comp(bp, cid, err); |
523224a3 DK |
4970 | return 0; |
4971 | } | |
523224a3 | 4972 | |
1191cb83 | 4973 | static void bnx2x_handle_mcast_eqe(struct bnx2x *bp) |
619c5cb6 VZ |
4974 | { |
4975 | struct bnx2x_mcast_ramrod_params rparam; | |
4976 | int rc; | |
4977 | ||
4978 | memset(&rparam, 0, sizeof(rparam)); | |
4979 | ||
4980 | rparam.mcast_obj = &bp->mcast_obj; | |
4981 | ||
4982 | netif_addr_lock_bh(bp->dev); | |
4983 | ||
4984 | /* Clear pending state for the last command */ | |
4985 | bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw); | |
4986 | ||
4987 | /* If there are pending mcast commands - send them */ | |
4988 | if (bp->mcast_obj.check_pending(&bp->mcast_obj)) { | |
4989 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); | |
4990 | if (rc < 0) | |
4991 | BNX2X_ERR("Failed to send pending mcast commands: %d\n", | |
4992 | rc); | |
4993 | } | |
4994 | ||
4995 | netif_addr_unlock_bh(bp->dev); | |
4996 | } | |
4997 | ||
1191cb83 ED |
4998 | static void bnx2x_handle_classification_eqe(struct bnx2x *bp, |
4999 | union event_ring_elem *elem) | |
619c5cb6 VZ |
5000 | { |
5001 | unsigned long ramrod_flags = 0; | |
5002 | int rc = 0; | |
5003 | u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK; | |
5004 | struct bnx2x_vlan_mac_obj *vlan_mac_obj; | |
5005 | ||
5006 | /* Always push next commands out, don't wait here */ | |
5007 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
5008 | ||
86564c3f YM |
5009 | switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo) |
5010 | >> BNX2X_SWCID_SHIFT) { | |
619c5cb6 | 5011 | case BNX2X_FILTER_MAC_PENDING: |
51c1a580 | 5012 | DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n"); |
55c11941 | 5013 | if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp))) |
619c5cb6 VZ |
5014 | vlan_mac_obj = &bp->iscsi_l2_mac_obj; |
5015 | else | |
15192a8c | 5016 | vlan_mac_obj = &bp->sp_objs[cid].mac_obj; |
619c5cb6 VZ |
5017 | |
5018 | break; | |
619c5cb6 | 5019 | case BNX2X_FILTER_MCAST_PENDING: |
51c1a580 | 5020 | DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n"); |
619c5cb6 VZ |
5021 | /* This is only relevant for 57710 where multicast MACs are |
5022 | * configured as unicast MACs using the same ramrod. | |
5023 | */ | |
5024 | bnx2x_handle_mcast_eqe(bp); | |
5025 | return; | |
5026 | default: | |
5027 | BNX2X_ERR("Unsupported classification command: %d\n", | |
5028 | elem->message.data.eth_event.echo); | |
5029 | return; | |
5030 | } | |
5031 | ||
5032 | rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags); | |
5033 | ||
5034 | if (rc < 0) | |
5035 | BNX2X_ERR("Failed to schedule new commands: %d\n", rc); | |
5036 | else if (rc > 0) | |
5037 | DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n"); | |
619c5cb6 VZ |
5038 | } |
5039 | ||
619c5cb6 | 5040 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start); |
619c5cb6 | 5041 | |
1191cb83 | 5042 | static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp) |
619c5cb6 VZ |
5043 | { |
5044 | netif_addr_lock_bh(bp->dev); | |
5045 | ||
5046 | clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
5047 | ||
5048 | /* Send rx_mode command again if was requested */ | |
5049 | if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state)) | |
5050 | bnx2x_set_storm_rx_mode(bp); | |
619c5cb6 VZ |
5051 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, |
5052 | &bp->sp_state)) | |
5053 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
5054 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, | |
5055 | &bp->sp_state)) | |
5056 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
619c5cb6 VZ |
5057 | |
5058 | netif_addr_unlock_bh(bp->dev); | |
5059 | } | |
5060 | ||
1191cb83 | 5061 | static void bnx2x_after_afex_vif_lists(struct bnx2x *bp, |
a3348722 BW |
5062 | union event_ring_elem *elem) |
5063 | { | |
5064 | if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) { | |
5065 | DP(BNX2X_MSG_SP, | |
5066 | "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n", | |
5067 | elem->message.data.vif_list_event.func_bit_map); | |
5068 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK, | |
5069 | elem->message.data.vif_list_event.func_bit_map); | |
5070 | } else if (elem->message.data.vif_list_event.echo == | |
5071 | VIF_LIST_RULE_SET) { | |
5072 | DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n"); | |
5073 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0); | |
5074 | } | |
5075 | } | |
5076 | ||
5077 | /* called with rtnl_lock */ | |
1191cb83 | 5078 | static void bnx2x_after_function_update(struct bnx2x *bp) |
a3348722 BW |
5079 | { |
5080 | int q, rc; | |
5081 | struct bnx2x_fastpath *fp; | |
5082 | struct bnx2x_queue_state_params queue_params = {NULL}; | |
5083 | struct bnx2x_queue_update_params *q_update_params = | |
5084 | &queue_params.params.update; | |
5085 | ||
2de67439 | 5086 | /* Send Q update command with afex vlan removal values for all Qs */ |
a3348722 BW |
5087 | queue_params.cmd = BNX2X_Q_CMD_UPDATE; |
5088 | ||
5089 | /* set silent vlan removal values according to vlan mode */ | |
5090 | __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG, | |
5091 | &q_update_params->update_flags); | |
5092 | __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, | |
5093 | &q_update_params->update_flags); | |
5094 | __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags); | |
5095 | ||
5096 | /* in access mode mark mask and value are 0 to strip all vlans */ | |
5097 | if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) { | |
5098 | q_update_params->silent_removal_value = 0; | |
5099 | q_update_params->silent_removal_mask = 0; | |
5100 | } else { | |
5101 | q_update_params->silent_removal_value = | |
5102 | (bp->afex_def_vlan_tag & VLAN_VID_MASK); | |
5103 | q_update_params->silent_removal_mask = VLAN_VID_MASK; | |
5104 | } | |
5105 | ||
5106 | for_each_eth_queue(bp, q) { | |
5107 | /* Set the appropriate Queue object */ | |
5108 | fp = &bp->fp[q]; | |
15192a8c | 5109 | queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a3348722 BW |
5110 | |
5111 | /* send the ramrod */ | |
5112 | rc = bnx2x_queue_state_change(bp, &queue_params); | |
5113 | if (rc < 0) | |
5114 | BNX2X_ERR("Failed to config silent vlan rem for Q %d\n", | |
5115 | q); | |
5116 | } | |
5117 | ||
fea75645 | 5118 | if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) { |
65565884 | 5119 | fp = &bp->fp[FCOE_IDX(bp)]; |
15192a8c | 5120 | queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
a3348722 BW |
5121 | |
5122 | /* clear pending completion bit */ | |
5123 | __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags); | |
5124 | ||
5125 | /* mark latest Q bit */ | |
5126 | smp_mb__before_clear_bit(); | |
5127 | set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state); | |
5128 | smp_mb__after_clear_bit(); | |
5129 | ||
5130 | /* send Q update ramrod for FCoE Q */ | |
5131 | rc = bnx2x_queue_state_change(bp, &queue_params); | |
5132 | if (rc < 0) | |
5133 | BNX2X_ERR("Failed to config silent vlan rem for Q %d\n", | |
5134 | q); | |
5135 | } else { | |
5136 | /* If no FCoE ring - ACK MCP now */ | |
5137 | bnx2x_link_report(bp); | |
5138 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
5139 | } | |
a3348722 BW |
5140 | } |
5141 | ||
1191cb83 | 5142 | static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj( |
619c5cb6 VZ |
5143 | struct bnx2x *bp, u32 cid) |
5144 | { | |
94f05b0f | 5145 | DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid); |
55c11941 MS |
5146 | |
5147 | if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp))) | |
15192a8c | 5148 | return &bnx2x_fcoe_sp_obj(bp, q_obj); |
619c5cb6 | 5149 | else |
15192a8c | 5150 | return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj; |
619c5cb6 VZ |
5151 | } |
5152 | ||
523224a3 DK |
5153 | static void bnx2x_eq_int(struct bnx2x *bp) |
5154 | { | |
5155 | u16 hw_cons, sw_cons, sw_prod; | |
5156 | union event_ring_elem *elem; | |
55c11941 | 5157 | u8 echo; |
523224a3 DK |
5158 | u32 cid; |
5159 | u8 opcode; | |
fd1fc79d | 5160 | int rc, spqe_cnt = 0; |
619c5cb6 VZ |
5161 | struct bnx2x_queue_sp_obj *q_obj; |
5162 | struct bnx2x_func_sp_obj *f_obj = &bp->func_obj; | |
5163 | struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw; | |
523224a3 DK |
5164 | |
5165 | hw_cons = le16_to_cpu(*bp->eq_cons_sb); | |
5166 | ||
5167 | /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256. | |
16a5fd92 | 5168 | * when we get the next-page we need to adjust so the loop |
523224a3 DK |
5169 | * condition below will be met. The next element is the size of a |
5170 | * regular element and hence incrementing by 1 | |
5171 | */ | |
5172 | if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) | |
5173 | hw_cons++; | |
5174 | ||
25985edc | 5175 | /* This function may never run in parallel with itself for a |
523224a3 DK |
5176 | * specific bp, thus there is no need in "paired" read memory |
5177 | * barrier here. | |
5178 | */ | |
5179 | sw_cons = bp->eq_cons; | |
5180 | sw_prod = bp->eq_prod; | |
5181 | ||
d6cae238 | 5182 | DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n", |
6e30dd4e | 5183 | hw_cons, sw_cons, atomic_read(&bp->eq_spq_left)); |
523224a3 DK |
5184 | |
5185 | for (; sw_cons != hw_cons; | |
5186 | sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { | |
5187 | ||
523224a3 DK |
5188 | elem = &bp->eq_ring[EQ_DESC(sw_cons)]; |
5189 | ||
fd1fc79d AE |
5190 | rc = bnx2x_iov_eq_sp_event(bp, elem); |
5191 | if (!rc) { | |
5192 | DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n", | |
5193 | rc); | |
5194 | goto next_spqe; | |
5195 | } | |
523224a3 | 5196 | |
86564c3f YM |
5197 | /* elem CID originates from FW; actually LE */ |
5198 | cid = SW_CID((__force __le32) | |
5199 | elem->message.data.cfc_del_event.cid); | |
5200 | opcode = elem->message.opcode; | |
523224a3 DK |
5201 | |
5202 | /* handle eq element */ | |
5203 | switch (opcode) { | |
fd1fc79d AE |
5204 | case EVENT_RING_OPCODE_VF_PF_CHANNEL: |
5205 | DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n"); | |
5206 | bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event); | |
5207 | continue; | |
5208 | ||
523224a3 | 5209 | case EVENT_RING_OPCODE_STAT_QUERY: |
51c1a580 MS |
5210 | DP(BNX2X_MSG_SP | BNX2X_MSG_STATS, |
5211 | "got statistics comp event %d\n", | |
619c5cb6 | 5212 | bp->stats_comp++); |
523224a3 | 5213 | /* nothing to do with stats comp */ |
d6cae238 | 5214 | goto next_spqe; |
523224a3 DK |
5215 | |
5216 | case EVENT_RING_OPCODE_CFC_DEL: | |
5217 | /* handle according to cid range */ | |
5218 | /* | |
5219 | * we may want to verify here that the bp state is | |
5220 | * HALTING | |
5221 | */ | |
d6cae238 | 5222 | DP(BNX2X_MSG_SP, |
523224a3 | 5223 | "got delete ramrod for MULTI[%d]\n", cid); |
55c11941 MS |
5224 | |
5225 | if (CNIC_LOADED(bp) && | |
5226 | !bnx2x_cnic_handle_cfc_del(bp, cid, elem)) | |
523224a3 | 5227 | goto next_spqe; |
55c11941 | 5228 | |
619c5cb6 VZ |
5229 | q_obj = bnx2x_cid_to_q_obj(bp, cid); |
5230 | ||
5231 | if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL)) | |
5232 | break; | |
5233 | ||
523224a3 | 5234 | goto next_spqe; |
e4901dde VZ |
5235 | |
5236 | case EVENT_RING_OPCODE_STOP_TRAFFIC: | |
51c1a580 | 5237 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n"); |
6ffa39f2 | 5238 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED); |
6debea87 DK |
5239 | if (f_obj->complete_cmd(bp, f_obj, |
5240 | BNX2X_F_CMD_TX_STOP)) | |
5241 | break; | |
e4901dde | 5242 | goto next_spqe; |
619c5cb6 | 5243 | |
e4901dde | 5244 | case EVENT_RING_OPCODE_START_TRAFFIC: |
51c1a580 | 5245 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n"); |
6ffa39f2 | 5246 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED); |
6debea87 DK |
5247 | if (f_obj->complete_cmd(bp, f_obj, |
5248 | BNX2X_F_CMD_TX_START)) | |
5249 | break; | |
e4901dde | 5250 | goto next_spqe; |
55c11941 | 5251 | |
a3348722 | 5252 | case EVENT_RING_OPCODE_FUNCTION_UPDATE: |
55c11941 MS |
5253 | echo = elem->message.data.function_update_event.echo; |
5254 | if (echo == SWITCH_UPDATE) { | |
5255 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, | |
5256 | "got FUNC_SWITCH_UPDATE ramrod\n"); | |
5257 | if (f_obj->complete_cmd( | |
5258 | bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE)) | |
5259 | break; | |
a3348722 | 5260 | |
55c11941 MS |
5261 | } else { |
5262 | DP(BNX2X_MSG_SP | BNX2X_MSG_MCP, | |
5263 | "AFEX: ramrod completed FUNCTION_UPDATE\n"); | |
5264 | f_obj->complete_cmd(bp, f_obj, | |
5265 | BNX2X_F_CMD_AFEX_UPDATE); | |
5266 | ||
5267 | /* We will perform the Queues update from | |
5268 | * sp_rtnl task as all Queue SP operations | |
5269 | * should run under rtnl_lock. | |
5270 | */ | |
5271 | smp_mb__before_clear_bit(); | |
5272 | set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, | |
5273 | &bp->sp_rtnl_state); | |
5274 | smp_mb__after_clear_bit(); | |
5275 | ||
5276 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
5277 | } | |
a3348722 | 5278 | |
a3348722 BW |
5279 | goto next_spqe; |
5280 | ||
5281 | case EVENT_RING_OPCODE_AFEX_VIF_LISTS: | |
5282 | f_obj->complete_cmd(bp, f_obj, | |
5283 | BNX2X_F_CMD_AFEX_VIFLISTS); | |
5284 | bnx2x_after_afex_vif_lists(bp, elem); | |
5285 | goto next_spqe; | |
619c5cb6 | 5286 | case EVENT_RING_OPCODE_FUNCTION_START: |
51c1a580 MS |
5287 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
5288 | "got FUNC_START ramrod\n"); | |
619c5cb6 VZ |
5289 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START)) |
5290 | break; | |
5291 | ||
5292 | goto next_spqe; | |
5293 | ||
5294 | case EVENT_RING_OPCODE_FUNCTION_STOP: | |
51c1a580 MS |
5295 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
5296 | "got FUNC_STOP ramrod\n"); | |
619c5cb6 VZ |
5297 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP)) |
5298 | break; | |
5299 | ||
5300 | goto next_spqe; | |
523224a3 DK |
5301 | } |
5302 | ||
5303 | switch (opcode | bp->state) { | |
619c5cb6 VZ |
5304 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
5305 | BNX2X_STATE_OPEN): | |
5306 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | | |
523224a3 | 5307 | BNX2X_STATE_OPENING_WAIT4_PORT): |
619c5cb6 VZ |
5308 | cid = elem->message.data.eth_event.echo & |
5309 | BNX2X_SWCID_MASK; | |
d6cae238 | 5310 | DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n", |
619c5cb6 VZ |
5311 | cid); |
5312 | rss_raw->clear_pending(rss_raw); | |
523224a3 DK |
5313 | break; |
5314 | ||
619c5cb6 VZ |
5315 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN): |
5316 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG): | |
5317 | case (EVENT_RING_OPCODE_SET_MAC | | |
523224a3 | 5318 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
619c5cb6 VZ |
5319 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
5320 | BNX2X_STATE_OPEN): | |
5321 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
5322 | BNX2X_STATE_DIAG): | |
5323 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
5324 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 5325 | DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n"); |
619c5cb6 | 5326 | bnx2x_handle_classification_eqe(bp, elem); |
523224a3 DK |
5327 | break; |
5328 | ||
619c5cb6 VZ |
5329 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
5330 | BNX2X_STATE_OPEN): | |
5331 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
5332 | BNX2X_STATE_DIAG): | |
5333 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
5334 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 5335 | DP(BNX2X_MSG_SP, "got mcast ramrod\n"); |
619c5cb6 | 5336 | bnx2x_handle_mcast_eqe(bp); |
523224a3 DK |
5337 | break; |
5338 | ||
619c5cb6 VZ |
5339 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
5340 | BNX2X_STATE_OPEN): | |
5341 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
5342 | BNX2X_STATE_DIAG): | |
5343 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
523224a3 | 5344 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
d6cae238 | 5345 | DP(BNX2X_MSG_SP, "got rx_mode ramrod\n"); |
619c5cb6 | 5346 | bnx2x_handle_rx_mode_eqe(bp); |
523224a3 DK |
5347 | break; |
5348 | default: | |
5349 | /* unknown event log error and continue */ | |
619c5cb6 VZ |
5350 | BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n", |
5351 | elem->message.opcode, bp->state); | |
523224a3 DK |
5352 | } |
5353 | next_spqe: | |
5354 | spqe_cnt++; | |
5355 | } /* for */ | |
5356 | ||
8fe23fbd | 5357 | smp_mb__before_atomic_inc(); |
6e30dd4e | 5358 | atomic_add(spqe_cnt, &bp->eq_spq_left); |
523224a3 DK |
5359 | |
5360 | bp->eq_cons = sw_cons; | |
5361 | bp->eq_prod = sw_prod; | |
5362 | /* Make sure that above mem writes were issued towards the memory */ | |
5363 | smp_wmb(); | |
5364 | ||
5365 | /* update producer */ | |
5366 | bnx2x_update_eq_prod(bp, bp->eq_prod); | |
5367 | } | |
5368 | ||
a2fbb9ea ET |
5369 | static void bnx2x_sp_task(struct work_struct *work) |
5370 | { | |
1cf167f2 | 5371 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
a2fbb9ea | 5372 | |
fd1fc79d | 5373 | DP(BNX2X_MSG_SP, "sp task invoked\n"); |
a2fbb9ea | 5374 | |
16a5fd92 | 5375 | /* make sure the atomic interrupt_occurred has been written */ |
fd1fc79d AE |
5376 | smp_rmb(); |
5377 | if (atomic_read(&bp->interrupt_occurred)) { | |
a2fbb9ea | 5378 | |
fd1fc79d AE |
5379 | /* what work needs to be performed? */ |
5380 | u16 status = bnx2x_update_dsb_idx(bp); | |
cdaa7cb8 | 5381 | |
fd1fc79d AE |
5382 | DP(BNX2X_MSG_SP, "status %x\n", status); |
5383 | DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n"); | |
5384 | atomic_set(&bp->interrupt_occurred, 0); | |
5385 | ||
5386 | /* HW attentions */ | |
5387 | if (status & BNX2X_DEF_SB_ATT_IDX) { | |
5388 | bnx2x_attn_int(bp); | |
5389 | status &= ~BNX2X_DEF_SB_ATT_IDX; | |
5390 | } | |
5391 | ||
5392 | /* SP events: STAT_QUERY and others */ | |
5393 | if (status & BNX2X_DEF_SB_IDX) { | |
5394 | struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp); | |
523224a3 | 5395 | |
55c11941 | 5396 | if (FCOE_INIT(bp) && |
fd1fc79d AE |
5397 | (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) { |
5398 | /* Prevent local bottom-halves from running as | |
5399 | * we are going to change the local NAPI list. | |
5400 | */ | |
5401 | local_bh_disable(); | |
5402 | napi_schedule(&bnx2x_fcoe(bp, napi)); | |
5403 | local_bh_enable(); | |
5404 | } | |
5405 | ||
5406 | /* Handle EQ completions */ | |
5407 | bnx2x_eq_int(bp); | |
5408 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, | |
5409 | le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1); | |
5410 | ||
5411 | status &= ~BNX2X_DEF_SB_IDX; | |
019dbb4c | 5412 | } |
55c11941 | 5413 | |
fd1fc79d AE |
5414 | /* if status is non zero then perhaps something went wrong */ |
5415 | if (unlikely(status)) | |
5416 | DP(BNX2X_MSG_SP, | |
5417 | "got an unknown interrupt! (status 0x%x)\n", status); | |
523224a3 | 5418 | |
fd1fc79d AE |
5419 | /* ack status block only if something was actually handled */ |
5420 | bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID, | |
5421 | le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1); | |
cdaa7cb8 VZ |
5422 | } |
5423 | ||
fd1fc79d AE |
5424 | /* must be called after the EQ processing (since eq leads to sriov |
5425 | * ramrod completion flows). | |
5426 | * This flow may have been scheduled by the arrival of a ramrod | |
5427 | * completion, or by the sriov code rescheduling itself. | |
5428 | */ | |
5429 | bnx2x_iov_sp_task(bp); | |
a3348722 BW |
5430 | |
5431 | /* afex - poll to check if VIFSET_ACK should be sent to MFW */ | |
5432 | if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, | |
5433 | &bp->sp_state)) { | |
5434 | bnx2x_link_report(bp); | |
5435 | bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0); | |
5436 | } | |
a2fbb9ea ET |
5437 | } |
5438 | ||
9f6c9258 | 5439 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
a2fbb9ea ET |
5440 | { |
5441 | struct net_device *dev = dev_instance; | |
5442 | struct bnx2x *bp = netdev_priv(dev); | |
5443 | ||
523224a3 DK |
5444 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, |
5445 | IGU_INT_DISABLE, 0); | |
a2fbb9ea ET |
5446 | |
5447 | #ifdef BNX2X_STOP_ON_ERROR | |
5448 | if (unlikely(bp->panic)) | |
5449 | return IRQ_HANDLED; | |
5450 | #endif | |
5451 | ||
55c11941 | 5452 | if (CNIC_LOADED(bp)) { |
993ac7b5 MC |
5453 | struct cnic_ops *c_ops; |
5454 | ||
5455 | rcu_read_lock(); | |
5456 | c_ops = rcu_dereference(bp->cnic_ops); | |
5457 | if (c_ops) | |
5458 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
5459 | rcu_read_unlock(); | |
5460 | } | |
55c11941 | 5461 | |
fd1fc79d AE |
5462 | /* schedule sp task to perform default status block work, ack |
5463 | * attentions and enable interrupts. | |
5464 | */ | |
5465 | bnx2x_schedule_sp_task(bp); | |
a2fbb9ea ET |
5466 | |
5467 | return IRQ_HANDLED; | |
5468 | } | |
5469 | ||
5470 | /* end of slow path */ | |
5471 | ||
619c5cb6 VZ |
5472 | void bnx2x_drv_pulse(struct bnx2x *bp) |
5473 | { | |
5474 | SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb, | |
5475 | bp->fw_drv_pulse_wr_seq); | |
5476 | } | |
5477 | ||
a2fbb9ea ET |
5478 | static void bnx2x_timer(unsigned long data) |
5479 | { | |
5480 | struct bnx2x *bp = (struct bnx2x *) data; | |
5481 | ||
5482 | if (!netif_running(bp->dev)) | |
5483 | return; | |
5484 | ||
67c431a5 AE |
5485 | if (IS_PF(bp) && |
5486 | !BP_NOMCP(bp)) { | |
f2e0899f | 5487 | int mb_idx = BP_FW_MB_IDX(bp); |
4c868664 EG |
5488 | u16 drv_pulse; |
5489 | u16 mcp_pulse; | |
a2fbb9ea ET |
5490 | |
5491 | ++bp->fw_drv_pulse_wr_seq; | |
5492 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; | |
a2fbb9ea | 5493 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
619c5cb6 | 5494 | bnx2x_drv_pulse(bp); |
a2fbb9ea | 5495 | |
f2e0899f | 5496 | mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) & |
a2fbb9ea ET |
5497 | MCP_PULSE_SEQ_MASK); |
5498 | /* The delta between driver pulse and mcp response | |
4c868664 EG |
5499 | * should not get too big. If the MFW is more than 5 pulses |
5500 | * behind, we should worry about it enough to generate an error | |
5501 | * log. | |
a2fbb9ea | 5502 | */ |
4c868664 EG |
5503 | if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5) |
5504 | BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n", | |
a2fbb9ea | 5505 | drv_pulse, mcp_pulse); |
a2fbb9ea ET |
5506 | } |
5507 | ||
f34d28ea | 5508 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a | 5509 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
a2fbb9ea | 5510 | |
abc5a021 | 5511 | /* sample pf vf bulletin board for new posts from pf */ |
37173488 YM |
5512 | if (IS_VF(bp)) |
5513 | bnx2x_timer_sriov(bp); | |
78c3bcc5 | 5514 | |
a2fbb9ea ET |
5515 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
5516 | } | |
5517 | ||
5518 | /* end of Statistics */ | |
5519 | ||
5520 | /* nic init */ | |
5521 | ||
5522 | /* | |
5523 | * nic init service functions | |
5524 | */ | |
5525 | ||
1191cb83 | 5526 | static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len) |
a2fbb9ea | 5527 | { |
523224a3 DK |
5528 | u32 i; |
5529 | if (!(len%4) && !(addr%4)) | |
5530 | for (i = 0; i < len; i += 4) | |
5531 | REG_WR(bp, addr + i, fill); | |
5532 | else | |
5533 | for (i = 0; i < len; i++) | |
5534 | REG_WR8(bp, addr + i, fill); | |
34f80b04 EG |
5535 | } |
5536 | ||
523224a3 | 5537 | /* helper: writes FP SP data to FW - data_size in dwords */ |
1191cb83 ED |
5538 | static void bnx2x_wr_fp_sb_data(struct bnx2x *bp, |
5539 | int fw_sb_id, | |
5540 | u32 *sb_data_p, | |
5541 | u32 data_size) | |
34f80b04 | 5542 | { |
a2fbb9ea | 5543 | int index; |
523224a3 DK |
5544 | for (index = 0; index < data_size; index++) |
5545 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
5546 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + | |
5547 | sizeof(u32)*index, | |
5548 | *(sb_data_p + index)); | |
5549 | } | |
a2fbb9ea | 5550 | |
1191cb83 | 5551 | static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id) |
523224a3 DK |
5552 | { |
5553 | u32 *sb_data_p; | |
5554 | u32 data_size = 0; | |
f2e0899f | 5555 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 | 5556 | struct hc_status_block_data_e1x sb_data_e1x; |
a2fbb9ea | 5557 | |
523224a3 | 5558 | /* disable the function first */ |
619c5cb6 | 5559 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 5560 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 5561 | sb_data_e2.common.state = SB_DISABLED; |
f2e0899f DK |
5562 | sb_data_e2.common.p_func.vf_valid = false; |
5563 | sb_data_p = (u32 *)&sb_data_e2; | |
5564 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
5565 | } else { | |
5566 | memset(&sb_data_e1x, 0, | |
5567 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 5568 | sb_data_e1x.common.state = SB_DISABLED; |
f2e0899f DK |
5569 | sb_data_e1x.common.p_func.vf_valid = false; |
5570 | sb_data_p = (u32 *)&sb_data_e1x; | |
5571 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
5572 | } | |
523224a3 | 5573 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
a2fbb9ea | 5574 | |
523224a3 DK |
5575 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
5576 | CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0, | |
5577 | CSTORM_STATUS_BLOCK_SIZE); | |
5578 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5579 | CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0, | |
5580 | CSTORM_SYNC_BLOCK_SIZE); | |
5581 | } | |
34f80b04 | 5582 | |
523224a3 | 5583 | /* helper: writes SP SB data to FW */ |
1191cb83 | 5584 | static void bnx2x_wr_sp_sb_data(struct bnx2x *bp, |
523224a3 DK |
5585 | struct hc_sp_status_block_data *sp_sb_data) |
5586 | { | |
5587 | int func = BP_FUNC(bp); | |
5588 | int i; | |
5589 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
5590 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
5591 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
5592 | i*sizeof(u32), | |
5593 | *((u32 *)sp_sb_data + i)); | |
34f80b04 EG |
5594 | } |
5595 | ||
1191cb83 | 5596 | static void bnx2x_zero_sp_sb(struct bnx2x *bp) |
34f80b04 EG |
5597 | { |
5598 | int func = BP_FUNC(bp); | |
523224a3 DK |
5599 | struct hc_sp_status_block_data sp_sb_data; |
5600 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
a2fbb9ea | 5601 | |
619c5cb6 | 5602 | sp_sb_data.state = SB_DISABLED; |
523224a3 DK |
5603 | sp_sb_data.p_func.vf_valid = false; |
5604 | ||
5605 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); | |
5606 | ||
5607 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5608 | CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0, | |
5609 | CSTORM_SP_STATUS_BLOCK_SIZE); | |
5610 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
5611 | CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0, | |
5612 | CSTORM_SP_SYNC_BLOCK_SIZE); | |
523224a3 DK |
5613 | } |
5614 | ||
1191cb83 | 5615 | static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, |
523224a3 DK |
5616 | int igu_sb_id, int igu_seg_id) |
5617 | { | |
5618 | hc_sm->igu_sb_id = igu_sb_id; | |
5619 | hc_sm->igu_seg_id = igu_seg_id; | |
5620 | hc_sm->timer_value = 0xFF; | |
5621 | hc_sm->time_to_expire = 0xFFFFFFFF; | |
a2fbb9ea ET |
5622 | } |
5623 | ||
150966ad | 5624 | /* allocates state machine ids. */ |
1191cb83 | 5625 | static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data) |
150966ad AE |
5626 | { |
5627 | /* zero out state machine indices */ | |
5628 | /* rx indices */ | |
5629 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
5630 | ||
5631 | /* tx indices */ | |
5632 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
5633 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID; | |
5634 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID; | |
5635 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID; | |
5636 | ||
5637 | /* map indices */ | |
5638 | /* rx indices */ | |
5639 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |= | |
5640 | SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5641 | ||
5642 | /* tx indices */ | |
5643 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |= | |
5644 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5645 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |= | |
5646 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5647 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |= | |
5648 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5649 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |= | |
5650 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5651 | } | |
5652 | ||
b93288d5 | 5653 | void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid, |
523224a3 | 5654 | u8 vf_valid, int fw_sb_id, int igu_sb_id) |
a2fbb9ea | 5655 | { |
523224a3 DK |
5656 | int igu_seg_id; |
5657 | ||
f2e0899f | 5658 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
5659 | struct hc_status_block_data_e1x sb_data_e1x; |
5660 | struct hc_status_block_sm *hc_sm_p; | |
523224a3 DK |
5661 | int data_size; |
5662 | u32 *sb_data_p; | |
5663 | ||
f2e0899f DK |
5664 | if (CHIP_INT_MODE_IS_BC(bp)) |
5665 | igu_seg_id = HC_SEG_ACCESS_NORM; | |
5666 | else | |
5667 | igu_seg_id = IGU_SEG_ACCESS_NORM; | |
523224a3 DK |
5668 | |
5669 | bnx2x_zero_fp_sb(bp, fw_sb_id); | |
5670 | ||
619c5cb6 | 5671 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 5672 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 5673 | sb_data_e2.common.state = SB_ENABLED; |
f2e0899f DK |
5674 | sb_data_e2.common.p_func.pf_id = BP_FUNC(bp); |
5675 | sb_data_e2.common.p_func.vf_id = vfid; | |
5676 | sb_data_e2.common.p_func.vf_valid = vf_valid; | |
5677 | sb_data_e2.common.p_func.vnic_id = BP_VN(bp); | |
5678 | sb_data_e2.common.same_igu_sb_1b = true; | |
5679 | sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping); | |
5680 | sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping); | |
5681 | hc_sm_p = sb_data_e2.common.state_machine; | |
f2e0899f DK |
5682 | sb_data_p = (u32 *)&sb_data_e2; |
5683 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
150966ad | 5684 | bnx2x_map_sb_state_machines(sb_data_e2.index_data); |
f2e0899f DK |
5685 | } else { |
5686 | memset(&sb_data_e1x, 0, | |
5687 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 5688 | sb_data_e1x.common.state = SB_ENABLED; |
f2e0899f DK |
5689 | sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp); |
5690 | sb_data_e1x.common.p_func.vf_id = 0xff; | |
5691 | sb_data_e1x.common.p_func.vf_valid = false; | |
5692 | sb_data_e1x.common.p_func.vnic_id = BP_VN(bp); | |
5693 | sb_data_e1x.common.same_igu_sb_1b = true; | |
5694 | sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping); | |
5695 | sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping); | |
5696 | hc_sm_p = sb_data_e1x.common.state_machine; | |
f2e0899f DK |
5697 | sb_data_p = (u32 *)&sb_data_e1x; |
5698 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
150966ad | 5699 | bnx2x_map_sb_state_machines(sb_data_e1x.index_data); |
f2e0899f | 5700 | } |
523224a3 DK |
5701 | |
5702 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], | |
5703 | igu_sb_id, igu_seg_id); | |
5704 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], | |
5705 | igu_sb_id, igu_seg_id); | |
5706 | ||
51c1a580 | 5707 | DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id); |
523224a3 | 5708 | |
86564c3f | 5709 | /* write indices to HW - PCI guarantees endianity of regpairs */ |
523224a3 DK |
5710 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
5711 | } | |
5712 | ||
619c5cb6 | 5713 | static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id, |
523224a3 DK |
5714 | u16 tx_usec, u16 rx_usec) |
5715 | { | |
6383c0b3 | 5716 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS, |
523224a3 | 5717 | false, rx_usec); |
6383c0b3 AE |
5718 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, |
5719 | HC_INDEX_ETH_TX_CQ_CONS_COS0, false, | |
5720 | tx_usec); | |
5721 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5722 | HC_INDEX_ETH_TX_CQ_CONS_COS1, false, | |
5723 | tx_usec); | |
5724 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5725 | HC_INDEX_ETH_TX_CQ_CONS_COS2, false, | |
5726 | tx_usec); | |
523224a3 | 5727 | } |
f2e0899f | 5728 | |
523224a3 DK |
5729 | static void bnx2x_init_def_sb(struct bnx2x *bp) |
5730 | { | |
5731 | struct host_sp_status_block *def_sb = bp->def_status_blk; | |
5732 | dma_addr_t mapping = bp->def_status_blk_mapping; | |
5733 | int igu_sp_sb_index; | |
5734 | int igu_seg_id; | |
34f80b04 EG |
5735 | int port = BP_PORT(bp); |
5736 | int func = BP_FUNC(bp); | |
f2eaeb58 | 5737 | int reg_offset, reg_offset_en5; |
a2fbb9ea | 5738 | u64 section; |
523224a3 DK |
5739 | int index; |
5740 | struct hc_sp_status_block_data sp_sb_data; | |
5741 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
5742 | ||
f2e0899f DK |
5743 | if (CHIP_INT_MODE_IS_BC(bp)) { |
5744 | igu_sp_sb_index = DEF_SB_IGU_ID; | |
5745 | igu_seg_id = HC_SEG_ACCESS_DEF; | |
5746 | } else { | |
5747 | igu_sp_sb_index = bp->igu_dsb_id; | |
5748 | igu_seg_id = IGU_SEG_ACCESS_DEF; | |
5749 | } | |
a2fbb9ea ET |
5750 | |
5751 | /* ATTN */ | |
523224a3 | 5752 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
a2fbb9ea | 5753 | atten_status_block); |
523224a3 | 5754 | def_sb->atten_status_block.status_block_id = igu_sp_sb_index; |
a2fbb9ea | 5755 | |
49d66772 ET |
5756 | bp->attn_state = 0; |
5757 | ||
a2fbb9ea ET |
5758 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
5759 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
f2eaeb58 DK |
5760 | reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 : |
5761 | MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0); | |
34f80b04 | 5762 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
523224a3 DK |
5763 | int sindex; |
5764 | /* take care of sig[0]..sig[4] */ | |
5765 | for (sindex = 0; sindex < 4; sindex++) | |
5766 | bp->attn_group[index].sig[sindex] = | |
5767 | REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index); | |
f2e0899f | 5768 | |
619c5cb6 | 5769 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
5770 | /* |
5771 | * enable5 is separate from the rest of the registers, | |
5772 | * and therefore the address skip is 4 | |
5773 | * and not 16 between the different groups | |
5774 | */ | |
5775 | bp->attn_group[index].sig[4] = REG_RD(bp, | |
f2eaeb58 | 5776 | reg_offset_en5 + 0x4*index); |
f2e0899f DK |
5777 | else |
5778 | bp->attn_group[index].sig[4] = 0; | |
a2fbb9ea ET |
5779 | } |
5780 | ||
f2e0899f DK |
5781 | if (bp->common.int_block == INT_BLOCK_HC) { |
5782 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : | |
5783 | HC_REG_ATTN_MSG0_ADDR_L); | |
5784 | ||
5785 | REG_WR(bp, reg_offset, U64_LO(section)); | |
5786 | REG_WR(bp, reg_offset + 4, U64_HI(section)); | |
619c5cb6 | 5787 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
5788 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); |
5789 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); | |
5790 | } | |
a2fbb9ea | 5791 | |
523224a3 DK |
5792 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
5793 | sp_sb); | |
a2fbb9ea | 5794 | |
523224a3 | 5795 | bnx2x_zero_sp_sb(bp); |
a2fbb9ea | 5796 | |
86564c3f | 5797 | /* PCI guarantees endianity of regpairs */ |
619c5cb6 | 5798 | sp_sb_data.state = SB_ENABLED; |
523224a3 DK |
5799 | sp_sb_data.host_sb_addr.lo = U64_LO(section); |
5800 | sp_sb_data.host_sb_addr.hi = U64_HI(section); | |
5801 | sp_sb_data.igu_sb_id = igu_sp_sb_index; | |
5802 | sp_sb_data.igu_seg_id = igu_seg_id; | |
5803 | sp_sb_data.p_func.pf_id = func; | |
f2e0899f | 5804 | sp_sb_data.p_func.vnic_id = BP_VN(bp); |
523224a3 | 5805 | sp_sb_data.p_func.vf_id = 0xff; |
a2fbb9ea | 5806 | |
523224a3 | 5807 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
49d66772 | 5808 | |
523224a3 | 5809 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); |
a2fbb9ea ET |
5810 | } |
5811 | ||
9f6c9258 | 5812 | void bnx2x_update_coalesce(struct bnx2x *bp) |
a2fbb9ea | 5813 | { |
a2fbb9ea ET |
5814 | int i; |
5815 | ||
ec6ba945 | 5816 | for_each_eth_queue(bp, i) |
523224a3 | 5817 | bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id, |
423cfa7e | 5818 | bp->tx_ticks, bp->rx_ticks); |
a2fbb9ea ET |
5819 | } |
5820 | ||
a2fbb9ea ET |
5821 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
5822 | { | |
a2fbb9ea | 5823 | spin_lock_init(&bp->spq_lock); |
6e30dd4e | 5824 | atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING); |
a2fbb9ea | 5825 | |
a2fbb9ea | 5826 | bp->spq_prod_idx = 0; |
a2fbb9ea ET |
5827 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
5828 | bp->spq_prod_bd = bp->spq; | |
5829 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; | |
a2fbb9ea ET |
5830 | } |
5831 | ||
523224a3 | 5832 | static void bnx2x_init_eq_ring(struct bnx2x *bp) |
a2fbb9ea ET |
5833 | { |
5834 | int i; | |
523224a3 DK |
5835 | for (i = 1; i <= NUM_EQ_PAGES; i++) { |
5836 | union event_ring_elem *elem = | |
5837 | &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1]; | |
a2fbb9ea | 5838 | |
523224a3 DK |
5839 | elem->next_page.addr.hi = |
5840 | cpu_to_le32(U64_HI(bp->eq_mapping + | |
5841 | BCM_PAGE_SIZE * (i % NUM_EQ_PAGES))); | |
5842 | elem->next_page.addr.lo = | |
5843 | cpu_to_le32(U64_LO(bp->eq_mapping + | |
5844 | BCM_PAGE_SIZE*(i % NUM_EQ_PAGES))); | |
a2fbb9ea | 5845 | } |
523224a3 DK |
5846 | bp->eq_cons = 0; |
5847 | bp->eq_prod = NUM_EQ_DESC; | |
5848 | bp->eq_cons_sb = BNX2X_EQ_INDEX; | |
16a5fd92 | 5849 | /* we want a warning message before it gets wrought... */ |
6e30dd4e VZ |
5850 | atomic_set(&bp->eq_spq_left, |
5851 | min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1); | |
a2fbb9ea ET |
5852 | } |
5853 | ||
619c5cb6 | 5854 | /* called with netif_addr_lock_bh() */ |
924d75ab YM |
5855 | int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id, |
5856 | unsigned long rx_mode_flags, | |
5857 | unsigned long rx_accept_flags, | |
5858 | unsigned long tx_accept_flags, | |
5859 | unsigned long ramrod_flags) | |
ab532cf3 | 5860 | { |
619c5cb6 VZ |
5861 | struct bnx2x_rx_mode_ramrod_params ramrod_param; |
5862 | int rc; | |
5863 | ||
5864 | memset(&ramrod_param, 0, sizeof(ramrod_param)); | |
5865 | ||
5866 | /* Prepare ramrod parameters */ | |
5867 | ramrod_param.cid = 0; | |
5868 | ramrod_param.cl_id = cl_id; | |
5869 | ramrod_param.rx_mode_obj = &bp->rx_mode_obj; | |
5870 | ramrod_param.func_id = BP_FUNC(bp); | |
ab532cf3 | 5871 | |
619c5cb6 VZ |
5872 | ramrod_param.pstate = &bp->sp_state; |
5873 | ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING; | |
ab532cf3 | 5874 | |
619c5cb6 VZ |
5875 | ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata); |
5876 | ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata); | |
5877 | ||
5878 | set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
5879 | ||
5880 | ramrod_param.ramrod_flags = ramrod_flags; | |
5881 | ramrod_param.rx_mode_flags = rx_mode_flags; | |
5882 | ||
5883 | ramrod_param.rx_accept_flags = rx_accept_flags; | |
5884 | ramrod_param.tx_accept_flags = tx_accept_flags; | |
5885 | ||
5886 | rc = bnx2x_config_rx_mode(bp, &ramrod_param); | |
5887 | if (rc < 0) { | |
5888 | BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode); | |
924d75ab | 5889 | return rc; |
619c5cb6 | 5890 | } |
924d75ab YM |
5891 | |
5892 | return 0; | |
a2fbb9ea ET |
5893 | } |
5894 | ||
86564c3f YM |
5895 | static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode, |
5896 | unsigned long *rx_accept_flags, | |
5897 | unsigned long *tx_accept_flags) | |
471de716 | 5898 | { |
924d75ab YM |
5899 | /* Clear the flags first */ |
5900 | *rx_accept_flags = 0; | |
5901 | *tx_accept_flags = 0; | |
619c5cb6 | 5902 | |
924d75ab | 5903 | switch (rx_mode) { |
619c5cb6 VZ |
5904 | case BNX2X_RX_MODE_NONE: |
5905 | /* | |
5906 | * 'drop all' supersedes any accept flags that may have been | |
5907 | * passed to the function. | |
5908 | */ | |
5909 | break; | |
5910 | case BNX2X_RX_MODE_NORMAL: | |
924d75ab YM |
5911 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); |
5912 | __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags); | |
5913 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5914 | |
5915 | /* internal switching mode */ | |
924d75ab YM |
5916 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
5917 | __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags); | |
5918 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5919 | |
5920 | break; | |
5921 | case BNX2X_RX_MODE_ALLMULTI: | |
924d75ab YM |
5922 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); |
5923 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags); | |
5924 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5925 | |
5926 | /* internal switching mode */ | |
924d75ab YM |
5927 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
5928 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags); | |
5929 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5930 | |
5931 | break; | |
5932 | case BNX2X_RX_MODE_PROMISC: | |
16a5fd92 | 5933 | /* According to definition of SI mode, iface in promisc mode |
619c5cb6 VZ |
5934 | * should receive matched and unmatched (in resolution of port) |
5935 | * unicast packets. | |
5936 | */ | |
924d75ab YM |
5937 | __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags); |
5938 | __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags); | |
5939 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags); | |
5940 | __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags); | |
619c5cb6 VZ |
5941 | |
5942 | /* internal switching mode */ | |
924d75ab YM |
5943 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags); |
5944 | __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags); | |
619c5cb6 VZ |
5945 | |
5946 | if (IS_MF_SI(bp)) | |
924d75ab | 5947 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags); |
619c5cb6 | 5948 | else |
924d75ab | 5949 | __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags); |
619c5cb6 VZ |
5950 | |
5951 | break; | |
5952 | default: | |
924d75ab YM |
5953 | BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode); |
5954 | return -EINVAL; | |
619c5cb6 | 5955 | } |
de832a55 | 5956 | |
924d75ab | 5957 | /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */ |
619c5cb6 | 5958 | if (bp->rx_mode != BNX2X_RX_MODE_NONE) { |
924d75ab YM |
5959 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags); |
5960 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags); | |
34f80b04 EG |
5961 | } |
5962 | ||
924d75ab YM |
5963 | return 0; |
5964 | } | |
5965 | ||
5966 | /* called with netif_addr_lock_bh() */ | |
5967 | int bnx2x_set_storm_rx_mode(struct bnx2x *bp) | |
5968 | { | |
5969 | unsigned long rx_mode_flags = 0, ramrod_flags = 0; | |
5970 | unsigned long rx_accept_flags = 0, tx_accept_flags = 0; | |
5971 | int rc; | |
5972 | ||
5973 | if (!NO_FCOE(bp)) | |
5974 | /* Configure rx_mode of FCoE Queue */ | |
5975 | __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags); | |
5976 | ||
5977 | rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags, | |
5978 | &tx_accept_flags); | |
5979 | if (rc) | |
5980 | return rc; | |
5981 | ||
619c5cb6 VZ |
5982 | __set_bit(RAMROD_RX, &ramrod_flags); |
5983 | __set_bit(RAMROD_TX, &ramrod_flags); | |
5984 | ||
924d75ab YM |
5985 | return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, |
5986 | rx_accept_flags, tx_accept_flags, | |
5987 | ramrod_flags); | |
619c5cb6 VZ |
5988 | } |
5989 | ||
5990 | static void bnx2x_init_internal_common(struct bnx2x *bp) | |
5991 | { | |
5992 | int i; | |
5993 | ||
0793f83f DK |
5994 | if (IS_MF_SI(bp)) |
5995 | /* | |
5996 | * In switch independent mode, the TSTORM needs to accept | |
5997 | * packets that failed classification, since approximate match | |
5998 | * mac addresses aren't written to NIG LLH | |
5999 | */ | |
6000 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
6001 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2); | |
619c5cb6 VZ |
6002 | else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */ |
6003 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
6004 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0); | |
0793f83f | 6005 | |
523224a3 DK |
6006 | /* Zero this manually as its initialization is |
6007 | currently missing in the initTool */ | |
6008 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) | |
ca00392c | 6009 | REG_WR(bp, BAR_USTRORM_INTMEM + |
523224a3 | 6010 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
619c5cb6 | 6011 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6012 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET, |
6013 | CHIP_INT_MODE_IS_BC(bp) ? | |
6014 | HC_IGU_BC_MODE : HC_IGU_NBC_MODE); | |
6015 | } | |
523224a3 | 6016 | } |
8a1c38d1 | 6017 | |
471de716 EG |
6018 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
6019 | { | |
6020 | switch (load_code) { | |
6021 | case FW_MSG_CODE_DRV_LOAD_COMMON: | |
f2e0899f | 6022 | case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: |
471de716 EG |
6023 | bnx2x_init_internal_common(bp); |
6024 | /* no break */ | |
6025 | ||
6026 | case FW_MSG_CODE_DRV_LOAD_PORT: | |
619c5cb6 | 6027 | /* nothing to do */ |
471de716 EG |
6028 | /* no break */ |
6029 | ||
6030 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: | |
523224a3 DK |
6031 | /* internal memory per function is |
6032 | initialized inside bnx2x_pf_init */ | |
471de716 EG |
6033 | break; |
6034 | ||
6035 | default: | |
6036 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); | |
6037 | break; | |
6038 | } | |
6039 | } | |
6040 | ||
619c5cb6 | 6041 | static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp) |
523224a3 | 6042 | { |
55c11941 | 6043 | return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp); |
619c5cb6 | 6044 | } |
523224a3 | 6045 | |
619c5cb6 VZ |
6046 | static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp) |
6047 | { | |
55c11941 | 6048 | return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp); |
619c5cb6 VZ |
6049 | } |
6050 | ||
1191cb83 | 6051 | static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp) |
619c5cb6 VZ |
6052 | { |
6053 | if (CHIP_IS_E1x(fp->bp)) | |
6054 | return BP_L_ID(fp->bp) + fp->index; | |
6055 | else /* We want Client ID to be the same as IGU SB ID for 57712 */ | |
6056 | return bnx2x_fp_igu_sb_id(fp); | |
6057 | } | |
6058 | ||
6383c0b3 | 6059 | static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx) |
619c5cb6 VZ |
6060 | { |
6061 | struct bnx2x_fastpath *fp = &bp->fp[fp_idx]; | |
6383c0b3 | 6062 | u8 cos; |
619c5cb6 | 6063 | unsigned long q_type = 0; |
6383c0b3 | 6064 | u32 cids[BNX2X_MULTI_TX_COS] = { 0 }; |
f233cafe | 6065 | fp->rx_queue = fp_idx; |
b3b83c3f | 6066 | fp->cid = fp_idx; |
619c5cb6 VZ |
6067 | fp->cl_id = bnx2x_fp_cl_id(fp); |
6068 | fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp); | |
6069 | fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp); | |
523224a3 | 6070 | /* qZone id equals to FW (per path) client id */ |
619c5cb6 VZ |
6071 | fp->cl_qzone_id = bnx2x_fp_qzone_id(fp); |
6072 | ||
523224a3 | 6073 | /* init shortcut */ |
619c5cb6 | 6074 | fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp); |
7a752993 | 6075 | |
16a5fd92 | 6076 | /* Setup SB indices */ |
523224a3 | 6077 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
523224a3 | 6078 | |
619c5cb6 VZ |
6079 | /* Configure Queue State object */ |
6080 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); | |
6081 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); | |
6383c0b3 AE |
6082 | |
6083 | BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS); | |
6084 | ||
6085 | /* init tx data */ | |
6086 | for_each_cos_in_tx_queue(fp, cos) { | |
65565884 MS |
6087 | bnx2x_init_txdata(bp, fp->txdata_ptr[cos], |
6088 | CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp), | |
6089 | FP_COS_TO_TXQ(fp, cos, bp), | |
6090 | BNX2X_TX_SB_INDEX_BASE + cos, fp); | |
6091 | cids[cos] = fp->txdata_ptr[cos]->cid; | |
6383c0b3 AE |
6092 | } |
6093 | ||
ad5afc89 AE |
6094 | /* nothing more for vf to do here */ |
6095 | if (IS_VF(bp)) | |
6096 | return; | |
6097 | ||
6098 | bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false, | |
6099 | fp->fw_sb_id, fp->igu_sb_id); | |
6100 | bnx2x_update_fpsb_idx(fp); | |
15192a8c BW |
6101 | bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids, |
6102 | fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata), | |
6383c0b3 | 6103 | bnx2x_sp_mapping(bp, q_rdata), q_type); |
619c5cb6 VZ |
6104 | |
6105 | /** | |
6106 | * Configure classification DBs: Always enable Tx switching | |
6107 | */ | |
6108 | bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX); | |
6109 | ||
ad5afc89 AE |
6110 | DP(NETIF_MSG_IFUP, |
6111 | "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n", | |
6112 | fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id, | |
6113 | fp->igu_sb_id); | |
523224a3 DK |
6114 | } |
6115 | ||
1191cb83 ED |
6116 | static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata) |
6117 | { | |
6118 | int i; | |
6119 | ||
6120 | for (i = 1; i <= NUM_TX_RINGS; i++) { | |
6121 | struct eth_tx_next_bd *tx_next_bd = | |
6122 | &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd; | |
6123 | ||
6124 | tx_next_bd->addr_hi = | |
6125 | cpu_to_le32(U64_HI(txdata->tx_desc_mapping + | |
6126 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); | |
6127 | tx_next_bd->addr_lo = | |
6128 | cpu_to_le32(U64_LO(txdata->tx_desc_mapping + | |
6129 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); | |
6130 | } | |
6131 | ||
639d65b8 YM |
6132 | *txdata->tx_cons_sb = cpu_to_le16(0); |
6133 | ||
1191cb83 ED |
6134 | SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1); |
6135 | txdata->tx_db.data.zero_fill1 = 0; | |
6136 | txdata->tx_db.data.prod = 0; | |
6137 | ||
6138 | txdata->tx_pkt_prod = 0; | |
6139 | txdata->tx_pkt_cons = 0; | |
6140 | txdata->tx_bd_prod = 0; | |
6141 | txdata->tx_bd_cons = 0; | |
6142 | txdata->tx_pkt = 0; | |
6143 | } | |
6144 | ||
55c11941 MS |
6145 | static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp) |
6146 | { | |
6147 | int i; | |
6148 | ||
6149 | for_each_tx_queue_cnic(bp, i) | |
6150 | bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]); | |
6151 | } | |
d76a6111 | 6152 | |
1191cb83 ED |
6153 | static void bnx2x_init_tx_rings(struct bnx2x *bp) |
6154 | { | |
6155 | int i; | |
6156 | u8 cos; | |
6157 | ||
55c11941 | 6158 | for_each_eth_queue(bp, i) |
1191cb83 | 6159 | for_each_cos_in_tx_queue(&bp->fp[i], cos) |
65565884 | 6160 | bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]); |
1191cb83 ED |
6161 | } |
6162 | ||
55c11941 | 6163 | void bnx2x_nic_init_cnic(struct bnx2x *bp) |
a2fbb9ea | 6164 | { |
ec6ba945 VZ |
6165 | if (!NO_FCOE(bp)) |
6166 | bnx2x_init_fcoe_fp(bp); | |
523224a3 DK |
6167 | |
6168 | bnx2x_init_sb(bp, bp->cnic_sb_mapping, | |
6169 | BNX2X_VF_ID_INVALID, false, | |
619c5cb6 | 6170 | bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp)); |
523224a3 | 6171 | |
55c11941 MS |
6172 | /* ensure status block indices were read */ |
6173 | rmb(); | |
6174 | bnx2x_init_rx_rings_cnic(bp); | |
6175 | bnx2x_init_tx_rings_cnic(bp); | |
6176 | ||
6177 | /* flush all */ | |
6178 | mb(); | |
6179 | mmiowb(); | |
6180 | } | |
a2fbb9ea | 6181 | |
ecf01c22 | 6182 | void bnx2x_pre_irq_nic_init(struct bnx2x *bp) |
55c11941 MS |
6183 | { |
6184 | int i; | |
6185 | ||
ecf01c22 | 6186 | /* Setup NIC internals and enable interrupts */ |
55c11941 MS |
6187 | for_each_eth_queue(bp, i) |
6188 | bnx2x_init_eth_fp(bp, i); | |
ad5afc89 AE |
6189 | |
6190 | /* ensure status block indices were read */ | |
6191 | rmb(); | |
6192 | bnx2x_init_rx_rings(bp); | |
6193 | bnx2x_init_tx_rings(bp); | |
6194 | ||
ecf01c22 YM |
6195 | if (IS_PF(bp)) { |
6196 | /* Initialize MOD_ABS interrupts */ | |
6197 | bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id, | |
6198 | bp->common.shmem_base, | |
6199 | bp->common.shmem2_base, BP_PORT(bp)); | |
ad5afc89 | 6200 | |
ecf01c22 YM |
6201 | /* initialize the default status block and sp ring */ |
6202 | bnx2x_init_def_sb(bp); | |
6203 | bnx2x_update_dsb_idx(bp); | |
6204 | bnx2x_init_sp_ring(bp); | |
3cdeec22 YM |
6205 | } else { |
6206 | bnx2x_memset_stats(bp); | |
ecf01c22 YM |
6207 | } |
6208 | } | |
16119785 | 6209 | |
ecf01c22 YM |
6210 | void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code) |
6211 | { | |
523224a3 | 6212 | bnx2x_init_eq_ring(bp); |
471de716 | 6213 | bnx2x_init_internal(bp, load_code); |
523224a3 | 6214 | bnx2x_pf_init(bp); |
0ef00459 EG |
6215 | bnx2x_stats_init(bp); |
6216 | ||
0ef00459 EG |
6217 | /* flush all before enabling interrupts */ |
6218 | mb(); | |
6219 | mmiowb(); | |
6220 | ||
615f8fd9 | 6221 | bnx2x_int_enable(bp); |
eb8da205 EG |
6222 | |
6223 | /* Check for SPIO5 */ | |
6224 | bnx2x_attn_int_deasserted0(bp, | |
6225 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & | |
6226 | AEU_INPUTS_ATTN_BITS_SPIO5); | |
a2fbb9ea ET |
6227 | } |
6228 | ||
ecf01c22 | 6229 | /* gzip service functions */ |
a2fbb9ea ET |
6230 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
6231 | { | |
1a983142 FT |
6232 | bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE, |
6233 | &bp->gunzip_mapping, GFP_KERNEL); | |
a2fbb9ea ET |
6234 | if (bp->gunzip_buf == NULL) |
6235 | goto gunzip_nomem1; | |
6236 | ||
6237 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); | |
6238 | if (bp->strm == NULL) | |
6239 | goto gunzip_nomem2; | |
6240 | ||
7ab24bfd | 6241 | bp->strm->workspace = vmalloc(zlib_inflate_workspacesize()); |
a2fbb9ea ET |
6242 | if (bp->strm->workspace == NULL) |
6243 | goto gunzip_nomem3; | |
6244 | ||
6245 | return 0; | |
6246 | ||
6247 | gunzip_nomem3: | |
6248 | kfree(bp->strm); | |
6249 | bp->strm = NULL; | |
6250 | ||
6251 | gunzip_nomem2: | |
1a983142 FT |
6252 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
6253 | bp->gunzip_mapping); | |
a2fbb9ea ET |
6254 | bp->gunzip_buf = NULL; |
6255 | ||
6256 | gunzip_nomem1: | |
51c1a580 | 6257 | BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n"); |
a2fbb9ea ET |
6258 | return -ENOMEM; |
6259 | } | |
6260 | ||
6261 | static void bnx2x_gunzip_end(struct bnx2x *bp) | |
6262 | { | |
b3b83c3f | 6263 | if (bp->strm) { |
7ab24bfd | 6264 | vfree(bp->strm->workspace); |
b3b83c3f DK |
6265 | kfree(bp->strm); |
6266 | bp->strm = NULL; | |
6267 | } | |
a2fbb9ea ET |
6268 | |
6269 | if (bp->gunzip_buf) { | |
1a983142 FT |
6270 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
6271 | bp->gunzip_mapping); | |
a2fbb9ea ET |
6272 | bp->gunzip_buf = NULL; |
6273 | } | |
6274 | } | |
6275 | ||
94a78b79 | 6276 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
a2fbb9ea ET |
6277 | { |
6278 | int n, rc; | |
6279 | ||
6280 | /* check gzip header */ | |
94a78b79 VZ |
6281 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
6282 | BNX2X_ERR("Bad gzip header\n"); | |
a2fbb9ea | 6283 | return -EINVAL; |
94a78b79 | 6284 | } |
a2fbb9ea ET |
6285 | |
6286 | n = 10; | |
6287 | ||
34f80b04 | 6288 | #define FNAME 0x8 |
a2fbb9ea ET |
6289 | |
6290 | if (zbuf[3] & FNAME) | |
6291 | while ((zbuf[n++] != 0) && (n < len)); | |
6292 | ||
94a78b79 | 6293 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
a2fbb9ea ET |
6294 | bp->strm->avail_in = len - n; |
6295 | bp->strm->next_out = bp->gunzip_buf; | |
6296 | bp->strm->avail_out = FW_BUF_SIZE; | |
6297 | ||
6298 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); | |
6299 | if (rc != Z_OK) | |
6300 | return rc; | |
6301 | ||
6302 | rc = zlib_inflate(bp->strm, Z_FINISH); | |
6303 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) | |
7995c64e JP |
6304 | netdev_err(bp->dev, "Firmware decompression error: %s\n", |
6305 | bp->strm->msg); | |
a2fbb9ea ET |
6306 | |
6307 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); | |
6308 | if (bp->gunzip_outlen & 0x3) | |
51c1a580 MS |
6309 | netdev_err(bp->dev, |
6310 | "Firmware decompression error: gunzip_outlen (%d) not aligned\n", | |
cdaa7cb8 | 6311 | bp->gunzip_outlen); |
a2fbb9ea ET |
6312 | bp->gunzip_outlen >>= 2; |
6313 | ||
6314 | zlib_inflateEnd(bp->strm); | |
6315 | ||
6316 | if (rc == Z_STREAM_END) | |
6317 | return 0; | |
6318 | ||
6319 | return rc; | |
6320 | } | |
6321 | ||
6322 | /* nic load/unload */ | |
6323 | ||
6324 | /* | |
34f80b04 | 6325 | * General service functions |
a2fbb9ea ET |
6326 | */ |
6327 | ||
6328 | /* send a NIG loopback debug packet */ | |
6329 | static void bnx2x_lb_pckt(struct bnx2x *bp) | |
6330 | { | |
a2fbb9ea | 6331 | u32 wb_write[3]; |
a2fbb9ea ET |
6332 | |
6333 | /* Ethernet source and destination addresses */ | |
a2fbb9ea ET |
6334 | wb_write[0] = 0x55555555; |
6335 | wb_write[1] = 0x55555555; | |
34f80b04 | 6336 | wb_write[2] = 0x20; /* SOP */ |
a2fbb9ea | 6337 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
6338 | |
6339 | /* NON-IP protocol */ | |
a2fbb9ea ET |
6340 | wb_write[0] = 0x09000000; |
6341 | wb_write[1] = 0x55555555; | |
34f80b04 | 6342 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
a2fbb9ea | 6343 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
6344 | } |
6345 | ||
6346 | /* some of the internal memories | |
6347 | * are not directly readable from the driver | |
6348 | * to test them we send debug packets | |
6349 | */ | |
6350 | static int bnx2x_int_mem_test(struct bnx2x *bp) | |
6351 | { | |
6352 | int factor; | |
6353 | int count, i; | |
6354 | u32 val = 0; | |
6355 | ||
ad8d3948 | 6356 | if (CHIP_REV_IS_FPGA(bp)) |
a2fbb9ea | 6357 | factor = 120; |
ad8d3948 EG |
6358 | else if (CHIP_REV_IS_EMUL(bp)) |
6359 | factor = 200; | |
6360 | else | |
a2fbb9ea | 6361 | factor = 1; |
a2fbb9ea | 6362 | |
a2fbb9ea ET |
6363 | /* Disable inputs of parser neighbor blocks */ |
6364 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
6365 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
6366 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 6367 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
6368 | |
6369 | /* Write 0 to parser credits for CFC search request */ | |
6370 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
6371 | ||
6372 | /* send Ethernet packet */ | |
6373 | bnx2x_lb_pckt(bp); | |
6374 | ||
6375 | /* TODO do i reset NIG statistic? */ | |
6376 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
6377 | count = 1000 * factor; | |
6378 | while (count) { | |
34f80b04 | 6379 | |
a2fbb9ea ET |
6380 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
6381 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
6382 | if (val == 0x10) |
6383 | break; | |
6384 | ||
639d65b8 | 6385 | usleep_range(10000, 20000); |
a2fbb9ea ET |
6386 | count--; |
6387 | } | |
6388 | if (val != 0x10) { | |
6389 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
6390 | return -1; | |
6391 | } | |
6392 | ||
6393 | /* Wait until PRS register shows 1 packet */ | |
6394 | count = 1000 * factor; | |
6395 | while (count) { | |
6396 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
a2fbb9ea ET |
6397 | if (val == 1) |
6398 | break; | |
6399 | ||
639d65b8 | 6400 | usleep_range(10000, 20000); |
a2fbb9ea ET |
6401 | count--; |
6402 | } | |
6403 | if (val != 0x1) { | |
6404 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6405 | return -2; | |
6406 | } | |
6407 | ||
6408 | /* Reset and init BRB, PRS */ | |
34f80b04 | 6409 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
a2fbb9ea | 6410 | msleep(50); |
34f80b04 | 6411 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
a2fbb9ea | 6412 | msleep(50); |
619c5cb6 VZ |
6413 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
6414 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
a2fbb9ea ET |
6415 | |
6416 | DP(NETIF_MSG_HW, "part2\n"); | |
6417 | ||
6418 | /* Disable inputs of parser neighbor blocks */ | |
6419 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
6420 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
6421 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 6422 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
6423 | |
6424 | /* Write 0 to parser credits for CFC search request */ | |
6425 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
6426 | ||
6427 | /* send 10 Ethernet packets */ | |
6428 | for (i = 0; i < 10; i++) | |
6429 | bnx2x_lb_pckt(bp); | |
6430 | ||
6431 | /* Wait until NIG register shows 10 + 1 | |
6432 | packets of size 11*0x10 = 0xb0 */ | |
6433 | count = 1000 * factor; | |
6434 | while (count) { | |
34f80b04 | 6435 | |
a2fbb9ea ET |
6436 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
6437 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
6438 | if (val == 0xb0) |
6439 | break; | |
6440 | ||
639d65b8 | 6441 | usleep_range(10000, 20000); |
a2fbb9ea ET |
6442 | count--; |
6443 | } | |
6444 | if (val != 0xb0) { | |
6445 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
6446 | return -3; | |
6447 | } | |
6448 | ||
6449 | /* Wait until PRS register shows 2 packets */ | |
6450 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
6451 | if (val != 2) | |
6452 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6453 | ||
6454 | /* Write 1 to parser credits for CFC search request */ | |
6455 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); | |
6456 | ||
6457 | /* Wait until PRS register shows 3 packets */ | |
6458 | msleep(10 * factor); | |
6459 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
6460 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
6461 | if (val != 3) | |
6462 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
6463 | ||
6464 | /* clear NIG EOP FIFO */ | |
6465 | for (i = 0; i < 11; i++) | |
6466 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); | |
6467 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); | |
6468 | if (val != 1) { | |
6469 | BNX2X_ERR("clear of NIG failed\n"); | |
6470 | return -4; | |
6471 | } | |
6472 | ||
6473 | /* Reset and init BRB, PRS, NIG */ | |
6474 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); | |
6475 | msleep(50); | |
6476 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); | |
6477 | msleep(50); | |
619c5cb6 VZ |
6478 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
6479 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
55c11941 MS |
6480 | if (!CNIC_SUPPORT(bp)) |
6481 | /* set NIC mode */ | |
6482 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
a2fbb9ea ET |
6483 | |
6484 | /* Enable inputs of parser neighbor blocks */ | |
6485 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); | |
6486 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); | |
6487 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); | |
3196a88a | 6488 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
a2fbb9ea ET |
6489 | |
6490 | DP(NETIF_MSG_HW, "done\n"); | |
6491 | ||
6492 | return 0; /* OK */ | |
6493 | } | |
6494 | ||
4a33bc03 | 6495 | static void bnx2x_enable_blocks_attention(struct bnx2x *bp) |
a2fbb9ea | 6496 | { |
b343d002 YM |
6497 | u32 val; |
6498 | ||
a2fbb9ea | 6499 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
619c5cb6 | 6500 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6501 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40); |
6502 | else | |
6503 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); | |
a2fbb9ea ET |
6504 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
6505 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
f2e0899f DK |
6506 | /* |
6507 | * mask read length error interrupts in brb for parser | |
6508 | * (parsing unit and 'checksum and crc' unit) | |
6509 | * these errors are legal (PU reads fixed length and CAC can cause | |
6510 | * read length error on truncated packets) | |
6511 | */ | |
6512 | REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00); | |
a2fbb9ea ET |
6513 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
6514 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); | |
6515 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); | |
6516 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); | |
6517 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); | |
34f80b04 EG |
6518 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
6519 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
6520 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
6521 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); | |
6522 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); | |
34f80b04 EG |
6523 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
6524 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
6525 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
6526 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); | |
6527 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); | |
6528 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); | |
34f80b04 EG |
6529 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
6530 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ | |
f85582f8 | 6531 | |
b343d002 YM |
6532 | val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT | |
6533 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF | | |
6534 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN; | |
6535 | if (!CHIP_IS_E1x(bp)) | |
6536 | val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED | | |
6537 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED; | |
6538 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val); | |
6539 | ||
a2fbb9ea ET |
6540 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
6541 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); | |
6542 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); | |
34f80b04 | 6543 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
619c5cb6 VZ |
6544 | |
6545 | if (!CHIP_IS_E1x(bp)) | |
6546 | /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ | |
6547 | REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); | |
6548 | ||
a2fbb9ea ET |
6549 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
6550 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); | |
34f80b04 | 6551 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
4a33bc03 | 6552 | REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */ |
a2fbb9ea ET |
6553 | } |
6554 | ||
81f75bbf EG |
6555 | static void bnx2x_reset_common(struct bnx2x *bp) |
6556 | { | |
619c5cb6 VZ |
6557 | u32 val = 0x1400; |
6558 | ||
81f75bbf EG |
6559 | /* reset_common */ |
6560 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
6561 | 0xd3ffff7f); | |
619c5cb6 VZ |
6562 | |
6563 | if (CHIP_IS_E3(bp)) { | |
6564 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
6565 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
6566 | } | |
6567 | ||
6568 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val); | |
6569 | } | |
6570 | ||
6571 | static void bnx2x_setup_dmae(struct bnx2x *bp) | |
6572 | { | |
6573 | bp->dmae_ready = 0; | |
6574 | spin_lock_init(&bp->dmae_lock); | |
81f75bbf EG |
6575 | } |
6576 | ||
573f2035 EG |
6577 | static void bnx2x_init_pxp(struct bnx2x *bp) |
6578 | { | |
6579 | u16 devctl; | |
6580 | int r_order, w_order; | |
6581 | ||
2a80eebc | 6582 | pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl); |
573f2035 EG |
6583 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
6584 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); | |
6585 | if (bp->mrrs == -1) | |
6586 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); | |
6587 | else { | |
6588 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); | |
6589 | r_order = bp->mrrs; | |
6590 | } | |
6591 | ||
6592 | bnx2x_init_pxp_arb(bp, r_order, w_order); | |
6593 | } | |
fd4ef40d EG |
6594 | |
6595 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) | |
6596 | { | |
2145a920 | 6597 | int is_required; |
fd4ef40d | 6598 | u32 val; |
2145a920 | 6599 | int port; |
fd4ef40d | 6600 | |
2145a920 VZ |
6601 | if (BP_NOMCP(bp)) |
6602 | return; | |
6603 | ||
6604 | is_required = 0; | |
fd4ef40d EG |
6605 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
6606 | SHARED_HW_CFG_FAN_FAILURE_MASK; | |
6607 | ||
6608 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) | |
6609 | is_required = 1; | |
6610 | ||
6611 | /* | |
6612 | * The fan failure mechanism is usually related to the PHY type since | |
6613 | * the power consumption of the board is affected by the PHY. Currently, | |
6614 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. | |
6615 | */ | |
6616 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) | |
6617 | for (port = PORT_0; port < PORT_MAX; port++) { | |
fd4ef40d | 6618 | is_required |= |
d90d96ba YR |
6619 | bnx2x_fan_failure_det_req( |
6620 | bp, | |
6621 | bp->common.shmem_base, | |
a22f0788 | 6622 | bp->common.shmem2_base, |
d90d96ba | 6623 | port); |
fd4ef40d EG |
6624 | } |
6625 | ||
6626 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); | |
6627 | ||
6628 | if (is_required == 0) | |
6629 | return; | |
6630 | ||
6631 | /* Fan failure is indicated by SPIO 5 */ | |
d6d99a3f | 6632 | bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z); |
fd4ef40d EG |
6633 | |
6634 | /* set to active low mode */ | |
6635 | val = REG_RD(bp, MISC_REG_SPIO_INT); | |
d6d99a3f | 6636 | val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS); |
fd4ef40d EG |
6637 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
6638 | ||
6639 | /* enable interrupt to signal the IGU */ | |
6640 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
d6d99a3f | 6641 | val |= MISC_SPIO_SPIO5; |
fd4ef40d EG |
6642 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
6643 | } | |
6644 | ||
c9ee9206 | 6645 | void bnx2x_pf_disable(struct bnx2x *bp) |
f2e0899f DK |
6646 | { |
6647 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
6648 | val &= ~IGU_PF_CONF_FUNC_EN; | |
6649 | ||
6650 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
6651 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
6652 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0); | |
6653 | } | |
6654 | ||
1191cb83 | 6655 | static void bnx2x__common_init_phy(struct bnx2x *bp) |
619c5cb6 VZ |
6656 | { |
6657 | u32 shmem_base[2], shmem2_base[2]; | |
b884d95b YR |
6658 | /* Avoid common init in case MFW supports LFA */ |
6659 | if (SHMEM2_RD(bp, size) > | |
6660 | (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)])) | |
6661 | return; | |
619c5cb6 VZ |
6662 | shmem_base[0] = bp->common.shmem_base; |
6663 | shmem2_base[0] = bp->common.shmem2_base; | |
6664 | if (!CHIP_IS_E1x(bp)) { | |
6665 | shmem_base[1] = | |
6666 | SHMEM2_RD(bp, other_shmem_base_addr); | |
6667 | shmem2_base[1] = | |
6668 | SHMEM2_RD(bp, other_shmem2_base_addr); | |
6669 | } | |
6670 | bnx2x_acquire_phy_lock(bp); | |
6671 | bnx2x_common_init_phy(bp, shmem_base, shmem2_base, | |
6672 | bp->common.chip_id); | |
6673 | bnx2x_release_phy_lock(bp); | |
6674 | } | |
6675 | ||
6676 | /** | |
6677 | * bnx2x_init_hw_common - initialize the HW at the COMMON phase. | |
6678 | * | |
6679 | * @bp: driver handle | |
6680 | */ | |
6681 | static int bnx2x_init_hw_common(struct bnx2x *bp) | |
a2fbb9ea | 6682 | { |
619c5cb6 | 6683 | u32 val; |
a2fbb9ea | 6684 | |
51c1a580 | 6685 | DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp)); |
a2fbb9ea | 6686 | |
2031bd3a | 6687 | /* |
2de67439 | 6688 | * take the RESET lock to protect undi_unload flow from accessing |
2031bd3a DK |
6689 | * registers while we're resetting the chip |
6690 | */ | |
7a06a122 | 6691 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6692 | |
81f75bbf | 6693 | bnx2x_reset_common(bp); |
34f80b04 | 6694 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
a2fbb9ea | 6695 | |
619c5cb6 VZ |
6696 | val = 0xfffc; |
6697 | if (CHIP_IS_E3(bp)) { | |
6698 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
6699 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
6700 | } | |
6701 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val); | |
6702 | ||
7a06a122 | 6703 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6704 | |
619c5cb6 | 6705 | bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON); |
a2fbb9ea | 6706 | |
619c5cb6 VZ |
6707 | if (!CHIP_IS_E1x(bp)) { |
6708 | u8 abs_func_id; | |
f2e0899f DK |
6709 | |
6710 | /** | |
6711 | * 4-port mode or 2-port mode we need to turn of master-enable | |
6712 | * for everyone, after that, turn it back on for self. | |
6713 | * so, we disregard multi-function or not, and always disable | |
6714 | * for all functions on the given path, this means 0,2,4,6 for | |
6715 | * path 0 and 1,3,5,7 for path 1 | |
6716 | */ | |
619c5cb6 VZ |
6717 | for (abs_func_id = BP_PATH(bp); |
6718 | abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) { | |
6719 | if (abs_func_id == BP_ABS_FUNC(bp)) { | |
f2e0899f DK |
6720 | REG_WR(bp, |
6721 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, | |
6722 | 1); | |
6723 | continue; | |
6724 | } | |
6725 | ||
619c5cb6 | 6726 | bnx2x_pretend_func(bp, abs_func_id); |
f2e0899f DK |
6727 | /* clear pf enable */ |
6728 | bnx2x_pf_disable(bp); | |
6729 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6730 | } | |
6731 | } | |
a2fbb9ea | 6732 | |
619c5cb6 | 6733 | bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON); |
34f80b04 EG |
6734 | if (CHIP_IS_E1(bp)) { |
6735 | /* enable HW interrupt from PXP on USDM overflow | |
6736 | bit 16 on INT_MASK_0 */ | |
6737 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); | |
6738 | } | |
a2fbb9ea | 6739 | |
619c5cb6 | 6740 | bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON); |
34f80b04 | 6741 | bnx2x_init_pxp(bp); |
a2fbb9ea ET |
6742 | |
6743 | #ifdef __BIG_ENDIAN | |
34f80b04 EG |
6744 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
6745 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); | |
6746 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); | |
6747 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); | |
6748 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); | |
8badd27a EG |
6749 | /* make sure this value is 0 */ |
6750 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); | |
34f80b04 EG |
6751 | |
6752 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ | |
6753 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); | |
6754 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); | |
6755 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); | |
6756 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); | |
a2fbb9ea ET |
6757 | #endif |
6758 | ||
523224a3 DK |
6759 | bnx2x_ilt_init_page_size(bp, INITOP_SET); |
6760 | ||
34f80b04 EG |
6761 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
6762 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); | |
a2fbb9ea | 6763 | |
34f80b04 EG |
6764 | /* let the HW do it's magic ... */ |
6765 | msleep(100); | |
6766 | /* finish PXP init */ | |
6767 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); | |
6768 | if (val != 1) { | |
6769 | BNX2X_ERR("PXP2 CFG failed\n"); | |
6770 | return -EBUSY; | |
6771 | } | |
6772 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); | |
6773 | if (val != 1) { | |
6774 | BNX2X_ERR("PXP2 RD_INIT failed\n"); | |
6775 | return -EBUSY; | |
6776 | } | |
a2fbb9ea | 6777 | |
f2e0899f DK |
6778 | /* Timers bug workaround E2 only. We need to set the entire ILT to |
6779 | * have entries with value "0" and valid bit on. | |
6780 | * This needs to be done by the first PF that is loaded in a path | |
6781 | * (i.e. common phase) | |
6782 | */ | |
619c5cb6 VZ |
6783 | if (!CHIP_IS_E1x(bp)) { |
6784 | /* In E2 there is a bug in the timers block that can cause function 6 / 7 | |
6785 | * (i.e. vnic3) to start even if it is marked as "scan-off". | |
6786 | * This occurs when a different function (func2,3) is being marked | |
6787 | * as "scan-off". Real-life scenario for example: if a driver is being | |
6788 | * load-unloaded while func6,7 are down. This will cause the timer to access | |
6789 | * the ilt, translate to a logical address and send a request to read/write. | |
6790 | * Since the ilt for the function that is down is not valid, this will cause | |
6791 | * a translation error which is unrecoverable. | |
6792 | * The Workaround is intended to make sure that when this happens nothing fatal | |
6793 | * will occur. The workaround: | |
6794 | * 1. First PF driver which loads on a path will: | |
6795 | * a. After taking the chip out of reset, by using pretend, | |
6796 | * it will write "0" to the following registers of | |
6797 | * the other vnics. | |
6798 | * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
6799 | * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); | |
6800 | * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); | |
6801 | * And for itself it will write '1' to | |
6802 | * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable | |
6803 | * dmae-operations (writing to pram for example.) | |
6804 | * note: can be done for only function 6,7 but cleaner this | |
6805 | * way. | |
6806 | * b. Write zero+valid to the entire ILT. | |
6807 | * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of | |
6808 | * VNIC3 (of that port). The range allocated will be the | |
6809 | * entire ILT. This is needed to prevent ILT range error. | |
6810 | * 2. Any PF driver load flow: | |
6811 | * a. ILT update with the physical addresses of the allocated | |
6812 | * logical pages. | |
6813 | * b. Wait 20msec. - note that this timeout is needed to make | |
6814 | * sure there are no requests in one of the PXP internal | |
6815 | * queues with "old" ILT addresses. | |
6816 | * c. PF enable in the PGLC. | |
6817 | * d. Clear the was_error of the PF in the PGLC. (could have | |
2de67439 | 6818 | * occurred while driver was down) |
619c5cb6 VZ |
6819 | * e. PF enable in the CFC (WEAK + STRONG) |
6820 | * f. Timers scan enable | |
6821 | * 3. PF driver unload flow: | |
6822 | * a. Clear the Timers scan_en. | |
6823 | * b. Polling for scan_on=0 for that PF. | |
6824 | * c. Clear the PF enable bit in the PXP. | |
6825 | * d. Clear the PF enable in the CFC (WEAK + STRONG) | |
6826 | * e. Write zero+valid to all ILT entries (The valid bit must | |
6827 | * stay set) | |
6828 | * f. If this is VNIC 3 of a port then also init | |
6829 | * first_timers_ilt_entry to zero and last_timers_ilt_entry | |
16a5fd92 | 6830 | * to the last entry in the ILT. |
619c5cb6 VZ |
6831 | * |
6832 | * Notes: | |
6833 | * Currently the PF error in the PGLC is non recoverable. | |
6834 | * In the future the there will be a recovery routine for this error. | |
6835 | * Currently attention is masked. | |
6836 | * Having an MCP lock on the load/unload process does not guarantee that | |
6837 | * there is no Timer disable during Func6/7 enable. This is because the | |
6838 | * Timers scan is currently being cleared by the MCP on FLR. | |
6839 | * Step 2.d can be done only for PF6/7 and the driver can also check if | |
6840 | * there is error before clearing it. But the flow above is simpler and | |
6841 | * more general. | |
6842 | * All ILT entries are written by zero+valid and not just PF6/7 | |
6843 | * ILT entries since in the future the ILT entries allocation for | |
6844 | * PF-s might be dynamic. | |
6845 | */ | |
f2e0899f DK |
6846 | struct ilt_client_info ilt_cli; |
6847 | struct bnx2x_ilt ilt; | |
6848 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
6849 | memset(&ilt, 0, sizeof(struct bnx2x_ilt)); | |
6850 | ||
b595076a | 6851 | /* initialize dummy TM client */ |
f2e0899f DK |
6852 | ilt_cli.start = 0; |
6853 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
6854 | ilt_cli.client_num = ILT_CLIENT_TM; | |
6855 | ||
6856 | /* Step 1: set zeroes to all ilt page entries with valid bit on | |
6857 | * Step 2: set the timers first/last ilt entry to point | |
6858 | * to the entire range to prevent ILT range error for 3rd/4th | |
2de67439 | 6859 | * vnic (this code assumes existence of the vnic) |
f2e0899f DK |
6860 | * |
6861 | * both steps performed by call to bnx2x_ilt_client_init_op() | |
6862 | * with dummy TM client | |
6863 | * | |
6864 | * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT | |
6865 | * and his brother are split registers | |
6866 | */ | |
6867 | bnx2x_pretend_func(bp, (BP_PATH(bp) + 6)); | |
6868 | bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR); | |
6869 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6870 | ||
6871 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN); | |
6872 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN); | |
6873 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); | |
6874 | } | |
6875 | ||
34f80b04 EG |
6876 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
6877 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); | |
a2fbb9ea | 6878 | |
619c5cb6 | 6879 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6880 | int factor = CHIP_REV_IS_EMUL(bp) ? 1000 : |
6881 | (CHIP_REV_IS_FPGA(bp) ? 400 : 0); | |
619c5cb6 | 6882 | bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON); |
f2e0899f | 6883 | |
619c5cb6 | 6884 | bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON); |
f2e0899f DK |
6885 | |
6886 | /* let the HW do it's magic ... */ | |
6887 | do { | |
6888 | msleep(200); | |
6889 | val = REG_RD(bp, ATC_REG_ATC_INIT_DONE); | |
6890 | } while (factor-- && (val != 1)); | |
6891 | ||
6892 | if (val != 1) { | |
6893 | BNX2X_ERR("ATC_INIT failed\n"); | |
6894 | return -EBUSY; | |
6895 | } | |
6896 | } | |
6897 | ||
619c5cb6 | 6898 | bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON); |
a2fbb9ea | 6899 | |
b56e9670 AE |
6900 | bnx2x_iov_init_dmae(bp); |
6901 | ||
34f80b04 EG |
6902 | /* clean the DMAE memory */ |
6903 | bp->dmae_ready = 1; | |
619c5cb6 VZ |
6904 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1); |
6905 | ||
6906 | bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON); | |
6907 | ||
6908 | bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON); | |
6909 | ||
6910 | bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON); | |
a2fbb9ea | 6911 | |
619c5cb6 | 6912 | bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON); |
a2fbb9ea | 6913 | |
34f80b04 EG |
6914 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
6915 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); | |
6916 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); | |
6917 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); | |
6918 | ||
619c5cb6 | 6919 | bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON); |
37b091ba | 6920 | |
523224a3 DK |
6921 | /* QM queues pointers table */ |
6922 | bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET); | |
6923 | ||
34f80b04 EG |
6924 | /* soft reset pulse */ |
6925 | REG_WR(bp, QM_REG_SOFT_RESET, 1); | |
6926 | REG_WR(bp, QM_REG_SOFT_RESET, 0); | |
a2fbb9ea | 6927 | |
55c11941 MS |
6928 | if (CNIC_SUPPORT(bp)) |
6929 | bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON); | |
a2fbb9ea | 6930 | |
619c5cb6 | 6931 | bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON); |
b9871bcf | 6932 | |
619c5cb6 | 6933 | if (!CHIP_REV_IS_SLOW(bp)) |
34f80b04 EG |
6934 | /* enable hw interrupt from doorbell Q */ |
6935 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); | |
a2fbb9ea | 6936 | |
619c5cb6 | 6937 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
f2e0899f | 6938 | |
619c5cb6 | 6939 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
26c8fa4d | 6940 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
619c5cb6 | 6941 | |
f2e0899f | 6942 | if (!CHIP_IS_E1(bp)) |
619c5cb6 | 6943 | REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan); |
f85582f8 | 6944 | |
a3348722 BW |
6945 | if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) { |
6946 | if (IS_MF_AFEX(bp)) { | |
6947 | /* configure that VNTag and VLAN headers must be | |
6948 | * received in afex mode | |
6949 | */ | |
6950 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE); | |
6951 | REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA); | |
6952 | REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6); | |
6953 | REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926); | |
6954 | REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4); | |
6955 | } else { | |
6956 | /* Bit-map indicating which L2 hdrs may appear | |
6957 | * after the basic Ethernet header | |
6958 | */ | |
6959 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, | |
6960 | bp->path_has_ovlan ? 7 : 6); | |
6961 | } | |
6962 | } | |
a2fbb9ea | 6963 | |
619c5cb6 VZ |
6964 | bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON); |
6965 | bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON); | |
6966 | bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON); | |
6967 | bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON); | |
a2fbb9ea | 6968 | |
619c5cb6 VZ |
6969 | if (!CHIP_IS_E1x(bp)) { |
6970 | /* reset VFC memories */ | |
6971 | REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6972 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6973 | VFC_MEMORIES_RST_REG_RAM_RST); | |
6974 | REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6975 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6976 | VFC_MEMORIES_RST_REG_RAM_RST); | |
a2fbb9ea | 6977 | |
619c5cb6 VZ |
6978 | msleep(20); |
6979 | } | |
a2fbb9ea | 6980 | |
619c5cb6 VZ |
6981 | bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON); |
6982 | bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON); | |
6983 | bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON); | |
6984 | bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON); | |
f2e0899f | 6985 | |
34f80b04 EG |
6986 | /* sync semi rtc */ |
6987 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
6988 | 0x80000000); | |
6989 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, | |
6990 | 0x80000000); | |
a2fbb9ea | 6991 | |
619c5cb6 VZ |
6992 | bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON); |
6993 | bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON); | |
6994 | bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON); | |
a2fbb9ea | 6995 | |
a3348722 BW |
6996 | if (!CHIP_IS_E1x(bp)) { |
6997 | if (IS_MF_AFEX(bp)) { | |
6998 | /* configure that VNTag and VLAN headers must be | |
6999 | * sent in afex mode | |
7000 | */ | |
7001 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE); | |
7002 | REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA); | |
7003 | REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6); | |
7004 | REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926); | |
7005 | REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4); | |
7006 | } else { | |
7007 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, | |
7008 | bp->path_has_ovlan ? 7 : 6); | |
7009 | } | |
7010 | } | |
f2e0899f | 7011 | |
34f80b04 | 7012 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
f85582f8 | 7013 | |
619c5cb6 VZ |
7014 | bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON); |
7015 | ||
55c11941 MS |
7016 | if (CNIC_SUPPORT(bp)) { |
7017 | REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672); | |
7018 | REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); | |
7019 | REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b); | |
7020 | REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a); | |
7021 | REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116); | |
7022 | REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b); | |
7023 | REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf); | |
7024 | REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); | |
7025 | REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f); | |
7026 | REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7); | |
7027 | } | |
34f80b04 | 7028 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
a2fbb9ea | 7029 | |
34f80b04 EG |
7030 | if (sizeof(union cdu_context) != 1024) |
7031 | /* we currently assume that a context is 1024 bytes */ | |
51c1a580 MS |
7032 | dev_alert(&bp->pdev->dev, |
7033 | "please adjust the size of cdu_context(%ld)\n", | |
7034 | (long)sizeof(union cdu_context)); | |
a2fbb9ea | 7035 | |
619c5cb6 | 7036 | bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON); |
34f80b04 EG |
7037 | val = (4 << 24) + (0 << 12) + 1024; |
7038 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); | |
a2fbb9ea | 7039 | |
619c5cb6 | 7040 | bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON); |
34f80b04 | 7041 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
8d9c5f34 EG |
7042 | /* enable context validation interrupt from CFC */ |
7043 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
7044 | ||
7045 | /* set the thresholds to prevent CFC/CDU race */ | |
7046 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); | |
a2fbb9ea | 7047 | |
619c5cb6 | 7048 | bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON); |
f2e0899f | 7049 | |
619c5cb6 | 7050 | if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp)) |
f2e0899f DK |
7051 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36); |
7052 | ||
619c5cb6 VZ |
7053 | bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON); |
7054 | bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON); | |
a2fbb9ea | 7055 | |
34f80b04 EG |
7056 | /* Reset PCIE errors for debug */ |
7057 | REG_WR(bp, 0x2814, 0xffffffff); | |
7058 | REG_WR(bp, 0x3820, 0xffffffff); | |
a2fbb9ea | 7059 | |
619c5cb6 | 7060 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7061 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, |
7062 | (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | | |
7063 | PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); | |
7064 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, | |
7065 | (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | | |
7066 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | | |
7067 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); | |
7068 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, | |
7069 | (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | | |
7070 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | | |
7071 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); | |
7072 | } | |
7073 | ||
619c5cb6 | 7074 | bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON); |
f2e0899f | 7075 | if (!CHIP_IS_E1(bp)) { |
619c5cb6 VZ |
7076 | /* in E3 this done in per-port section */ |
7077 | if (!CHIP_IS_E3(bp)) | |
7078 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
f2e0899f | 7079 | } |
619c5cb6 VZ |
7080 | if (CHIP_IS_E1H(bp)) |
7081 | /* not applicable for E2 (and above ...) */ | |
7082 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp)); | |
34f80b04 EG |
7083 | |
7084 | if (CHIP_REV_IS_SLOW(bp)) | |
7085 | msleep(200); | |
7086 | ||
7087 | /* finish CFC init */ | |
7088 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); | |
7089 | if (val != 1) { | |
7090 | BNX2X_ERR("CFC LL_INIT failed\n"); | |
7091 | return -EBUSY; | |
7092 | } | |
7093 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); | |
7094 | if (val != 1) { | |
7095 | BNX2X_ERR("CFC AC_INIT failed\n"); | |
7096 | return -EBUSY; | |
7097 | } | |
7098 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); | |
7099 | if (val != 1) { | |
7100 | BNX2X_ERR("CFC CAM_INIT failed\n"); | |
7101 | return -EBUSY; | |
7102 | } | |
7103 | REG_WR(bp, CFC_REG_DEBUG0, 0); | |
f1410647 | 7104 | |
f2e0899f DK |
7105 | if (CHIP_IS_E1(bp)) { |
7106 | /* read NIG statistic | |
7107 | to see if this is our first up since powerup */ | |
7108 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); | |
7109 | val = *bnx2x_sp(bp, wb_data[0]); | |
34f80b04 | 7110 | |
f2e0899f DK |
7111 | /* do internal memory self test */ |
7112 | if ((val == 0) && bnx2x_int_mem_test(bp)) { | |
7113 | BNX2X_ERR("internal mem self test failed\n"); | |
7114 | return -EBUSY; | |
7115 | } | |
34f80b04 EG |
7116 | } |
7117 | ||
fd4ef40d EG |
7118 | bnx2x_setup_fan_failure_detection(bp); |
7119 | ||
34f80b04 EG |
7120 | /* clear PXP2 attentions */ |
7121 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); | |
a2fbb9ea | 7122 | |
4a33bc03 | 7123 | bnx2x_enable_blocks_attention(bp); |
c9ee9206 | 7124 | bnx2x_enable_blocks_parity(bp); |
a2fbb9ea | 7125 | |
6bbca910 | 7126 | if (!BP_NOMCP(bp)) { |
619c5cb6 VZ |
7127 | if (CHIP_IS_E1x(bp)) |
7128 | bnx2x__common_init_phy(bp); | |
6bbca910 YR |
7129 | } else |
7130 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); | |
7131 | ||
34f80b04 EG |
7132 | return 0; |
7133 | } | |
a2fbb9ea | 7134 | |
619c5cb6 VZ |
7135 | /** |
7136 | * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase. | |
7137 | * | |
7138 | * @bp: driver handle | |
7139 | */ | |
7140 | static int bnx2x_init_hw_common_chip(struct bnx2x *bp) | |
7141 | { | |
7142 | int rc = bnx2x_init_hw_common(bp); | |
7143 | ||
7144 | if (rc) | |
7145 | return rc; | |
7146 | ||
7147 | /* In E2 2-PORT mode, same ext phy is used for the two paths */ | |
7148 | if (!BP_NOMCP(bp)) | |
7149 | bnx2x__common_init_phy(bp); | |
7150 | ||
7151 | return 0; | |
7152 | } | |
7153 | ||
523224a3 | 7154 | static int bnx2x_init_hw_port(struct bnx2x *bp) |
34f80b04 EG |
7155 | { |
7156 | int port = BP_PORT(bp); | |
619c5cb6 | 7157 | int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; |
1c06328c | 7158 | u32 low, high; |
4293b9f5 | 7159 | u32 val, reg; |
a2fbb9ea | 7160 | |
51c1a580 | 7161 | DP(NETIF_MSG_HW, "starting port init port %d\n", port); |
34f80b04 EG |
7162 | |
7163 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); | |
a2fbb9ea | 7164 | |
619c5cb6 VZ |
7165 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
7166 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); | |
7167 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
ca00392c | 7168 | |
f2e0899f DK |
7169 | /* Timers bug workaround: disables the pf_master bit in pglue at |
7170 | * common phase, we need to enable it here before any dmae access are | |
7171 | * attempted. Therefore we manually added the enable-master to the | |
7172 | * port phase (it also happens in the function phase) | |
7173 | */ | |
619c5cb6 | 7174 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7175 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
7176 | ||
619c5cb6 VZ |
7177 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
7178 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
7179 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); | |
7180 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
7181 | ||
7182 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
7183 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
7184 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
7185 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
a2fbb9ea | 7186 | |
523224a3 DK |
7187 | /* QM cid (connection) count */ |
7188 | bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET); | |
a2fbb9ea | 7189 | |
55c11941 MS |
7190 | if (CNIC_SUPPORT(bp)) { |
7191 | bnx2x_init_block(bp, BLOCK_TM, init_phase); | |
7192 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20); | |
7193 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); | |
7194 | } | |
cdaa7cb8 | 7195 | |
619c5cb6 | 7196 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
f2e0899f | 7197 | |
2b674047 DK |
7198 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
7199 | ||
f2e0899f | 7200 | if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) { |
619c5cb6 VZ |
7201 | |
7202 | if (IS_MF(bp)) | |
7203 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); | |
7204 | else if (bp->dev->mtu > 4096) { | |
7205 | if (bp->flags & ONE_PORT_FLAG) | |
7206 | low = 160; | |
7207 | else { | |
7208 | val = bp->dev->mtu; | |
7209 | /* (24*1024 + val*4)/256 */ | |
7210 | low = 96 + (val/64) + | |
7211 | ((val % 64) ? 1 : 0); | |
7212 | } | |
7213 | } else | |
7214 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); | |
7215 | high = low + 56; /* 14*1024/256 */ | |
f2e0899f DK |
7216 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
7217 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); | |
1c06328c | 7218 | } |
1c06328c | 7219 | |
619c5cb6 VZ |
7220 | if (CHIP_MODE_IS_4_PORT(bp)) |
7221 | REG_WR(bp, (BP_PORT(bp) ? | |
7222 | BRB1_REG_MAC_GUARANTIED_1 : | |
7223 | BRB1_REG_MAC_GUARANTIED_0), 40); | |
1c06328c | 7224 | |
619c5cb6 | 7225 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
a3348722 BW |
7226 | if (CHIP_IS_E3B0(bp)) { |
7227 | if (IS_MF_AFEX(bp)) { | |
7228 | /* configure headers for AFEX mode */ | |
7229 | REG_WR(bp, BP_PORT(bp) ? | |
7230 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : | |
7231 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE); | |
7232 | REG_WR(bp, BP_PORT(bp) ? | |
7233 | PRS_REG_HDRS_AFTER_TAG_0_PORT_1 : | |
7234 | PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6); | |
7235 | REG_WR(bp, BP_PORT(bp) ? | |
7236 | PRS_REG_MUST_HAVE_HDRS_PORT_1 : | |
7237 | PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA); | |
7238 | } else { | |
7239 | /* Ovlan exists only if we are in multi-function + | |
7240 | * switch-dependent mode, in switch-independent there | |
7241 | * is no ovlan headers | |
7242 | */ | |
7243 | REG_WR(bp, BP_PORT(bp) ? | |
7244 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : | |
7245 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, | |
7246 | (bp->path_has_ovlan ? 7 : 6)); | |
7247 | } | |
7248 | } | |
356e2385 | 7249 | |
619c5cb6 VZ |
7250 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
7251 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
7252 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
7253 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
356e2385 | 7254 | |
619c5cb6 VZ |
7255 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
7256 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
7257 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
7258 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
34f80b04 | 7259 | |
619c5cb6 VZ |
7260 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
7261 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
a2fbb9ea | 7262 | |
619c5cb6 VZ |
7263 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
7264 | ||
7265 | if (CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
7266 | /* configure PBF to work without PAUSE mtu 9000 */ |
7267 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); | |
a2fbb9ea | 7268 | |
f2e0899f DK |
7269 | /* update threshold */ |
7270 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); | |
7271 | /* update init credit */ | |
7272 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); | |
a2fbb9ea | 7273 | |
f2e0899f DK |
7274 | /* probe changes */ |
7275 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); | |
7276 | udelay(50); | |
7277 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); | |
7278 | } | |
a2fbb9ea | 7279 | |
55c11941 MS |
7280 | if (CNIC_SUPPORT(bp)) |
7281 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); | |
7282 | ||
619c5cb6 VZ |
7283 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
7284 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); | |
34f80b04 EG |
7285 | |
7286 | if (CHIP_IS_E1(bp)) { | |
7287 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
7288 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
7289 | } | |
619c5cb6 | 7290 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
34f80b04 | 7291 | |
619c5cb6 | 7292 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 7293 | |
619c5cb6 | 7294 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
34f80b04 | 7295 | /* init aeu_mask_attn_func_0/1: |
16a5fd92 YM |
7296 | * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use |
7297 | * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF | |
34f80b04 | 7298 | * bits 4-7 are used for "per vn group attention" */ |
e4901dde VZ |
7299 | val = IS_MF(bp) ? 0xF7 : 0x7; |
7300 | /* Enable DCBX attention for all but E1 */ | |
7301 | val |= CHIP_IS_E1(bp) ? 0 : 0x10; | |
7302 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); | |
34f80b04 | 7303 | |
4293b9f5 DK |
7304 | /* SCPAD_PARITY should NOT trigger close the gates */ |
7305 | reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0; | |
7306 | REG_WR(bp, reg, | |
7307 | REG_RD(bp, reg) & | |
7308 | ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY); | |
7309 | ||
7310 | reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0; | |
7311 | REG_WR(bp, reg, | |
7312 | REG_RD(bp, reg) & | |
7313 | ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY); | |
7314 | ||
619c5cb6 VZ |
7315 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
7316 | ||
7317 | if (!CHIP_IS_E1x(bp)) { | |
7318 | /* Bit-map indicating which L2 hdrs may appear after the | |
7319 | * basic Ethernet header | |
7320 | */ | |
a3348722 BW |
7321 | if (IS_MF_AFEX(bp)) |
7322 | REG_WR(bp, BP_PORT(bp) ? | |
7323 | NIG_REG_P1_HDRS_AFTER_BASIC : | |
7324 | NIG_REG_P0_HDRS_AFTER_BASIC, 0xE); | |
7325 | else | |
7326 | REG_WR(bp, BP_PORT(bp) ? | |
7327 | NIG_REG_P1_HDRS_AFTER_BASIC : | |
7328 | NIG_REG_P0_HDRS_AFTER_BASIC, | |
7329 | IS_MF_SD(bp) ? 7 : 6); | |
619c5cb6 VZ |
7330 | |
7331 | if (CHIP_IS_E3(bp)) | |
7332 | REG_WR(bp, BP_PORT(bp) ? | |
7333 | NIG_REG_LLH1_MF_MODE : | |
7334 | NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
7335 | } | |
7336 | if (!CHIP_IS_E3(bp)) | |
7337 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); | |
34f80b04 | 7338 | |
f2e0899f | 7339 | if (!CHIP_IS_E1(bp)) { |
fb3bff17 | 7340 | /* 0x2 disable mf_ov, 0x1 enable */ |
34f80b04 | 7341 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
0793f83f | 7342 | (IS_MF_SD(bp) ? 0x1 : 0x2)); |
34f80b04 | 7343 | |
619c5cb6 | 7344 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7345 | val = 0; |
7346 | switch (bp->mf_mode) { | |
7347 | case MULTI_FUNCTION_SD: | |
7348 | val = 1; | |
7349 | break; | |
7350 | case MULTI_FUNCTION_SI: | |
a3348722 | 7351 | case MULTI_FUNCTION_AFEX: |
f2e0899f DK |
7352 | val = 2; |
7353 | break; | |
7354 | } | |
7355 | ||
7356 | REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE : | |
7357 | NIG_REG_LLH0_CLS_TYPE), val); | |
7358 | } | |
1c06328c EG |
7359 | { |
7360 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); | |
7361 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); | |
7362 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); | |
7363 | } | |
34f80b04 EG |
7364 | } |
7365 | ||
619c5cb6 VZ |
7366 | /* If SPIO5 is set to generate interrupts, enable it for this port */ |
7367 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
d6d99a3f | 7368 | if (val & MISC_SPIO_SPIO5) { |
4d295db0 EG |
7369 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
7370 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
7371 | val = REG_RD(bp, reg_addr); | |
f1410647 | 7372 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
4d295db0 | 7373 | REG_WR(bp, reg_addr, val); |
f1410647 | 7374 | } |
a2fbb9ea | 7375 | |
34f80b04 EG |
7376 | return 0; |
7377 | } | |
7378 | ||
34f80b04 EG |
7379 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
7380 | { | |
7381 | int reg; | |
32d68de1 | 7382 | u32 wb_write[2]; |
34f80b04 | 7383 | |
f2e0899f | 7384 | if (CHIP_IS_E1(bp)) |
34f80b04 | 7385 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
f2e0899f DK |
7386 | else |
7387 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; | |
34f80b04 | 7388 | |
32d68de1 YM |
7389 | wb_write[0] = ONCHIP_ADDR1(addr); |
7390 | wb_write[1] = ONCHIP_ADDR2(addr); | |
7391 | REG_WR_DMAE(bp, reg, wb_write, 2); | |
34f80b04 EG |
7392 | } |
7393 | ||
b56e9670 | 7394 | void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf) |
1191cb83 ED |
7395 | { |
7396 | u32 data, ctl, cnt = 100; | |
7397 | u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA; | |
7398 | u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL; | |
7399 | u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4; | |
7400 | u32 sb_bit = 1 << (idu_sb_id%32); | |
b56e9670 | 7401 | u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT; |
1191cb83 ED |
7402 | u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id; |
7403 | ||
7404 | /* Not supported in BC mode */ | |
7405 | if (CHIP_INT_MODE_IS_BC(bp)) | |
7406 | return; | |
7407 | ||
7408 | data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup | |
7409 | << IGU_REGULAR_CLEANUP_TYPE_SHIFT) | | |
7410 | IGU_REGULAR_CLEANUP_SET | | |
7411 | IGU_REGULAR_BCLEANUP; | |
7412 | ||
7413 | ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT | | |
7414 | func_encode << IGU_CTRL_REG_FID_SHIFT | | |
7415 | IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT; | |
7416 | ||
7417 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", | |
7418 | data, igu_addr_data); | |
7419 | REG_WR(bp, igu_addr_data, data); | |
7420 | mmiowb(); | |
7421 | barrier(); | |
7422 | DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", | |
7423 | ctl, igu_addr_ctl); | |
7424 | REG_WR(bp, igu_addr_ctl, ctl); | |
7425 | mmiowb(); | |
7426 | barrier(); | |
7427 | ||
7428 | /* wait for clean up to finish */ | |
7429 | while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt) | |
7430 | msleep(20); | |
7431 | ||
1191cb83 ED |
7432 | if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) { |
7433 | DP(NETIF_MSG_HW, | |
7434 | "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n", | |
7435 | idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt); | |
7436 | } | |
7437 | } | |
7438 | ||
7439 | static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id) | |
f2e0899f | 7440 | { |
619c5cb6 | 7441 | bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/); |
f2e0899f DK |
7442 | } |
7443 | ||
1191cb83 | 7444 | static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func) |
f2e0899f DK |
7445 | { |
7446 | u32 i, base = FUNC_ILT_BASE(func); | |
7447 | for (i = base; i < base + ILT_PER_FUNC; i++) | |
7448 | bnx2x_ilt_wr(bp, i, 0); | |
7449 | } | |
7450 | ||
910cc727 | 7451 | static void bnx2x_init_searcher(struct bnx2x *bp) |
55c11941 MS |
7452 | { |
7453 | int port = BP_PORT(bp); | |
7454 | bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM); | |
7455 | /* T1 hash bits value determines the T1 number of entries */ | |
7456 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS); | |
7457 | } | |
7458 | ||
7459 | static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend) | |
7460 | { | |
7461 | int rc; | |
7462 | struct bnx2x_func_state_params func_params = {NULL}; | |
7463 | struct bnx2x_func_switch_update_params *switch_update_params = | |
7464 | &func_params.params.switch_update; | |
7465 | ||
7466 | /* Prepare parameters for function state transitions */ | |
7467 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
7468 | __set_bit(RAMROD_RETRY, &func_params.ramrod_flags); | |
7469 | ||
7470 | func_params.f_obj = &bp->func_obj; | |
7471 | func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE; | |
7472 | ||
7473 | /* Function parameters */ | |
7474 | switch_update_params->suspend = suspend; | |
7475 | ||
7476 | rc = bnx2x_func_state_change(bp, &func_params); | |
7477 | ||
7478 | return rc; | |
7479 | } | |
7480 | ||
910cc727 | 7481 | static int bnx2x_reset_nic_mode(struct bnx2x *bp) |
55c11941 MS |
7482 | { |
7483 | int rc, i, port = BP_PORT(bp); | |
7484 | int vlan_en = 0, mac_en[NUM_MACS]; | |
7485 | ||
55c11941 MS |
7486 | /* Close input from network */ |
7487 | if (bp->mf_mode == SINGLE_FUNCTION) { | |
7488 | bnx2x_set_rx_filter(&bp->link_params, 0); | |
7489 | } else { | |
7490 | vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7491 | NIG_REG_LLH0_FUNC_EN); | |
7492 | REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7493 | NIG_REG_LLH0_FUNC_EN, 0); | |
7494 | for (i = 0; i < NUM_MACS; i++) { | |
7495 | mac_en[i] = REG_RD(bp, port ? | |
7496 | (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7497 | 4 * i) : | |
7498 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + | |
7499 | 4 * i)); | |
7500 | REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7501 | 4 * i) : | |
7502 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0); | |
7503 | } | |
7504 | } | |
7505 | ||
7506 | /* Close BMC to host */ | |
7507 | REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE : | |
7508 | NIG_REG_P1_TX_MNG_HOST_ENABLE, 0); | |
7509 | ||
7510 | /* Suspend Tx switching to the PF. Completion of this ramrod | |
7511 | * further guarantees that all the packets of that PF / child | |
7512 | * VFs in BRB were processed by the Parser, so it is safe to | |
7513 | * change the NIC_MODE register. | |
7514 | */ | |
7515 | rc = bnx2x_func_switch_update(bp, 1); | |
7516 | if (rc) { | |
7517 | BNX2X_ERR("Can't suspend tx-switching!\n"); | |
7518 | return rc; | |
7519 | } | |
7520 | ||
7521 | /* Change NIC_MODE register */ | |
7522 | REG_WR(bp, PRS_REG_NIC_MODE, 0); | |
7523 | ||
7524 | /* Open input from network */ | |
7525 | if (bp->mf_mode == SINGLE_FUNCTION) { | |
7526 | bnx2x_set_rx_filter(&bp->link_params, 1); | |
7527 | } else { | |
7528 | REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN : | |
7529 | NIG_REG_LLH0_FUNC_EN, vlan_en); | |
7530 | for (i = 0; i < NUM_MACS; i++) { | |
7531 | REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE + | |
7532 | 4 * i) : | |
7533 | (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), | |
7534 | mac_en[i]); | |
7535 | } | |
7536 | } | |
7537 | ||
7538 | /* Enable BMC to host */ | |
7539 | REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE : | |
7540 | NIG_REG_P1_TX_MNG_HOST_ENABLE, 1); | |
7541 | ||
7542 | /* Resume Tx switching to the PF */ | |
7543 | rc = bnx2x_func_switch_update(bp, 0); | |
7544 | if (rc) { | |
7545 | BNX2X_ERR("Can't resume tx-switching!\n"); | |
7546 | return rc; | |
7547 | } | |
7548 | ||
7549 | DP(NETIF_MSG_IFUP, "NIC MODE disabled\n"); | |
7550 | return 0; | |
7551 | } | |
7552 | ||
7553 | int bnx2x_init_hw_func_cnic(struct bnx2x *bp) | |
7554 | { | |
7555 | int rc; | |
7556 | ||
7557 | bnx2x_ilt_init_op_cnic(bp, INITOP_SET); | |
7558 | ||
7559 | if (CONFIGURE_NIC_MODE(bp)) { | |
16a5fd92 | 7560 | /* Configure searcher as part of function hw init */ |
55c11941 MS |
7561 | bnx2x_init_searcher(bp); |
7562 | ||
7563 | /* Reset NIC mode */ | |
7564 | rc = bnx2x_reset_nic_mode(bp); | |
7565 | if (rc) | |
7566 | BNX2X_ERR("Can't change NIC mode!\n"); | |
7567 | return rc; | |
7568 | } | |
7569 | ||
7570 | return 0; | |
7571 | } | |
7572 | ||
523224a3 | 7573 | static int bnx2x_init_hw_func(struct bnx2x *bp) |
34f80b04 EG |
7574 | { |
7575 | int port = BP_PORT(bp); | |
7576 | int func = BP_FUNC(bp); | |
619c5cb6 | 7577 | int init_phase = PHASE_PF0 + func; |
523224a3 DK |
7578 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
7579 | u16 cdu_ilt_start; | |
8badd27a | 7580 | u32 addr, val; |
f4a66897 | 7581 | u32 main_mem_base, main_mem_size, main_mem_prty_clr; |
89db4ad8 | 7582 | int i, main_mem_width, rc; |
34f80b04 | 7583 | |
51c1a580 | 7584 | DP(NETIF_MSG_HW, "starting func init func %d\n", func); |
34f80b04 | 7585 | |
619c5cb6 | 7586 | /* FLR cleanup - hmmm */ |
89db4ad8 AE |
7587 | if (!CHIP_IS_E1x(bp)) { |
7588 | rc = bnx2x_pf_flr_clnup(bp); | |
04c46736 YM |
7589 | if (rc) { |
7590 | bnx2x_fw_dump(bp); | |
89db4ad8 | 7591 | return rc; |
04c46736 | 7592 | } |
89db4ad8 | 7593 | } |
619c5cb6 | 7594 | |
8badd27a | 7595 | /* set MSI reconfigure capability */ |
f2e0899f DK |
7596 | if (bp->common.int_block == INT_BLOCK_HC) { |
7597 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); | |
7598 | val = REG_RD(bp, addr); | |
7599 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; | |
7600 | REG_WR(bp, addr, val); | |
7601 | } | |
8badd27a | 7602 | |
619c5cb6 VZ |
7603 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
7604 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
7605 | ||
523224a3 DK |
7606 | ilt = BP_ILT(bp); |
7607 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; | |
37b091ba | 7608 | |
290ca2bb AE |
7609 | if (IS_SRIOV(bp)) |
7610 | cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS; | |
7611 | cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start); | |
7612 | ||
7613 | /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes | |
7614 | * those of the VFs, so start line should be reset | |
7615 | */ | |
7616 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; | |
523224a3 | 7617 | for (i = 0; i < L2_ILT_LINES(bp); i++) { |
a052997e | 7618 | ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt; |
523224a3 | 7619 | ilt->lines[cdu_ilt_start + i].page_mapping = |
a052997e MS |
7620 | bp->context[i].cxt_mapping; |
7621 | ilt->lines[cdu_ilt_start + i].size = bp->context[i].size; | |
37b091ba | 7622 | } |
290ca2bb | 7623 | |
523224a3 | 7624 | bnx2x_ilt_init_op(bp, INITOP_SET); |
f85582f8 | 7625 | |
55c11941 MS |
7626 | if (!CONFIGURE_NIC_MODE(bp)) { |
7627 | bnx2x_init_searcher(bp); | |
7628 | REG_WR(bp, PRS_REG_NIC_MODE, 0); | |
7629 | DP(NETIF_MSG_IFUP, "NIC MODE disabled\n"); | |
7630 | } else { | |
7631 | /* Set NIC mode */ | |
7632 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
6bf07b8e | 7633 | DP(NETIF_MSG_IFUP, "NIC MODE configured\n"); |
55c11941 | 7634 | } |
37b091ba | 7635 | |
619c5cb6 | 7636 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7637 | u32 pf_conf = IGU_PF_CONF_FUNC_EN; |
7638 | ||
7639 | /* Turn on a single ISR mode in IGU if driver is going to use | |
7640 | * INT#x or MSI | |
7641 | */ | |
7642 | if (!(bp->flags & USING_MSIX_FLAG)) | |
7643 | pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; | |
7644 | /* | |
7645 | * Timers workaround bug: function init part. | |
7646 | * Need to wait 20msec after initializing ILT, | |
7647 | * needed to make sure there are no requests in | |
7648 | * one of the PXP internal queues with "old" ILT addresses | |
7649 | */ | |
7650 | msleep(20); | |
7651 | /* | |
7652 | * Master enable - Due to WB DMAE writes performed before this | |
7653 | * register is re-initialized as part of the regular function | |
7654 | * init | |
7655 | */ | |
7656 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
7657 | /* Enable the function in IGU */ | |
7658 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf); | |
7659 | } | |
7660 | ||
523224a3 | 7661 | bp->dmae_ready = 1; |
34f80b04 | 7662 | |
619c5cb6 | 7663 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
523224a3 | 7664 | |
619c5cb6 | 7665 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7666 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); |
7667 | ||
619c5cb6 VZ |
7668 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
7669 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
7670 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); | |
7671 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); | |
7672 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); | |
7673 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
7674 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
7675 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
7676 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
7677 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); | |
7678 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
7679 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
7680 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
7681 | ||
7682 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
7683 | REG_WR(bp, QM_REG_PF_EN, 1); |
7684 | ||
619c5cb6 VZ |
7685 | if (!CHIP_IS_E1x(bp)) { |
7686 | REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7687 | REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7688 | REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7689 | REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
7690 | } | |
7691 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
7692 | ||
7693 | bnx2x_init_block(bp, BLOCK_TM, init_phase); | |
7694 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); | |
c19d65c9 | 7695 | REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */ |
b56e9670 AE |
7696 | |
7697 | bnx2x_iov_init_dq(bp); | |
7698 | ||
619c5cb6 VZ |
7699 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
7700 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); | |
7701 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); | |
7702 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
7703 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
7704 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
7705 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); | |
7706 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
7707 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); | |
7708 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
7709 | REG_WR(bp, PBF_REG_DISABLE_PF, 0); |
7710 | ||
619c5cb6 | 7711 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
523224a3 | 7712 | |
619c5cb6 | 7713 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
34f80b04 | 7714 | |
619c5cb6 | 7715 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
7716 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1); |
7717 | ||
fb3bff17 | 7718 | if (IS_MF(bp)) { |
34f80b04 | 7719 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
fb3bff17 | 7720 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov); |
34f80b04 EG |
7721 | } |
7722 | ||
619c5cb6 | 7723 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
523224a3 | 7724 | |
34f80b04 | 7725 | /* HC init per function */ |
f2e0899f DK |
7726 | if (bp->common.int_block == INT_BLOCK_HC) { |
7727 | if (CHIP_IS_E1H(bp)) { | |
7728 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
7729 | ||
7730 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
7731 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
7732 | } | |
619c5cb6 | 7733 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
f2e0899f DK |
7734 | |
7735 | } else { | |
7736 | int num_segs, sb_idx, prod_offset; | |
7737 | ||
34f80b04 EG |
7738 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
7739 | ||
619c5cb6 | 7740 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7741 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
7742 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
7743 | } | |
7744 | ||
619c5cb6 | 7745 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 7746 | |
619c5cb6 | 7747 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
7748 | int dsb_idx = 0; |
7749 | /** | |
7750 | * Producer memory: | |
7751 | * E2 mode: address 0-135 match to the mapping memory; | |
7752 | * 136 - PF0 default prod; 137 - PF1 default prod; | |
7753 | * 138 - PF2 default prod; 139 - PF3 default prod; | |
7754 | * 140 - PF0 attn prod; 141 - PF1 attn prod; | |
7755 | * 142 - PF2 attn prod; 143 - PF3 attn prod; | |
7756 | * 144-147 reserved. | |
7757 | * | |
7758 | * E1.5 mode - In backward compatible mode; | |
7759 | * for non default SB; each even line in the memory | |
7760 | * holds the U producer and each odd line hold | |
7761 | * the C producer. The first 128 producers are for | |
7762 | * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 | |
7763 | * producers are for the DSB for each PF. | |
7764 | * Each PF has five segments: (the order inside each | |
7765 | * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; | |
7766 | * 132-135 C prods; 136-139 X prods; 140-143 T prods; | |
7767 | * 144-147 attn prods; | |
7768 | */ | |
7769 | /* non-default-status-blocks */ | |
7770 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
7771 | IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; | |
7772 | for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) { | |
7773 | prod_offset = (bp->igu_base_sb + sb_idx) * | |
7774 | num_segs; | |
7775 | ||
7776 | for (i = 0; i < num_segs; i++) { | |
7777 | addr = IGU_REG_PROD_CONS_MEMORY + | |
7778 | (prod_offset + i) * 4; | |
7779 | REG_WR(bp, addr, 0); | |
7780 | } | |
7781 | /* send consumer update with value 0 */ | |
7782 | bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx, | |
7783 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7784 | bnx2x_igu_clear_sb(bp, | |
7785 | bp->igu_base_sb + sb_idx); | |
7786 | } | |
7787 | ||
7788 | /* default-status-blocks */ | |
7789 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
7790 | IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; | |
7791 | ||
7792 | if (CHIP_MODE_IS_4_PORT(bp)) | |
7793 | dsb_idx = BP_FUNC(bp); | |
7794 | else | |
3395a033 | 7795 | dsb_idx = BP_VN(bp); |
f2e0899f DK |
7796 | |
7797 | prod_offset = (CHIP_INT_MODE_IS_BC(bp) ? | |
7798 | IGU_BC_BASE_DSB_PROD + dsb_idx : | |
7799 | IGU_NORM_BASE_DSB_PROD + dsb_idx); | |
7800 | ||
3395a033 DK |
7801 | /* |
7802 | * igu prods come in chunks of E1HVN_MAX (4) - | |
7803 | * does not matters what is the current chip mode | |
7804 | */ | |
f2e0899f DK |
7805 | for (i = 0; i < (num_segs * E1HVN_MAX); |
7806 | i += E1HVN_MAX) { | |
7807 | addr = IGU_REG_PROD_CONS_MEMORY + | |
7808 | (prod_offset + i)*4; | |
7809 | REG_WR(bp, addr, 0); | |
7810 | } | |
7811 | /* send consumer update with 0 */ | |
7812 | if (CHIP_INT_MODE_IS_BC(bp)) { | |
7813 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7814 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7815 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7816 | CSTORM_ID, 0, IGU_INT_NOP, 1); | |
7817 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7818 | XSTORM_ID, 0, IGU_INT_NOP, 1); | |
7819 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7820 | TSTORM_ID, 0, IGU_INT_NOP, 1); | |
7821 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7822 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
7823 | } else { | |
7824 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7825 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
7826 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
7827 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
7828 | } | |
7829 | bnx2x_igu_clear_sb(bp, bp->igu_dsb_id); | |
7830 | ||
16a5fd92 | 7831 | /* !!! These should become driver const once |
f2e0899f DK |
7832 | rf-tool supports split-68 const */ |
7833 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); | |
7834 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); | |
7835 | REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); | |
7836 | REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); | |
7837 | REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); | |
7838 | REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); | |
7839 | } | |
34f80b04 | 7840 | } |
34f80b04 | 7841 | |
c14423fe | 7842 | /* Reset PCIE errors for debug */ |
a2fbb9ea ET |
7843 | REG_WR(bp, 0x2114, 0xffffffff); |
7844 | REG_WR(bp, 0x2120, 0xffffffff); | |
523224a3 | 7845 | |
f4a66897 VZ |
7846 | if (CHIP_IS_E1x(bp)) { |
7847 | main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ | |
7848 | main_mem_base = HC_REG_MAIN_MEMORY + | |
7849 | BP_PORT(bp) * (main_mem_size * 4); | |
7850 | main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; | |
7851 | main_mem_width = 8; | |
7852 | ||
7853 | val = REG_RD(bp, main_mem_prty_clr); | |
7854 | if (val) | |
51c1a580 MS |
7855 | DP(NETIF_MSG_HW, |
7856 | "Hmmm... Parity errors in HC block during function init (0x%x)!\n", | |
7857 | val); | |
f4a66897 VZ |
7858 | |
7859 | /* Clear "false" parity errors in MSI-X table */ | |
7860 | for (i = main_mem_base; | |
7861 | i < main_mem_base + main_mem_size * 4; | |
7862 | i += main_mem_width) { | |
7863 | bnx2x_read_dmae(bp, i, main_mem_width / 4); | |
7864 | bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), | |
7865 | i, main_mem_width / 4); | |
7866 | } | |
7867 | /* Clear HC parity attention */ | |
7868 | REG_RD(bp, main_mem_prty_clr); | |
7869 | } | |
7870 | ||
619c5cb6 VZ |
7871 | #ifdef BNX2X_STOP_ON_ERROR |
7872 | /* Enable STORMs SP logging */ | |
7873 | REG_WR8(bp, BAR_USTRORM_INTMEM + | |
7874 | USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7875 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
7876 | TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7877 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
7878 | CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7879 | REG_WR8(bp, BAR_XSTRORM_INTMEM + | |
7880 | XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
7881 | #endif | |
7882 | ||
b7737c9b | 7883 | bnx2x_phy_probe(&bp->link_params); |
f85582f8 | 7884 | |
34f80b04 EG |
7885 | return 0; |
7886 | } | |
7887 | ||
55c11941 MS |
7888 | void bnx2x_free_mem_cnic(struct bnx2x *bp) |
7889 | { | |
7890 | bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE); | |
7891 | ||
7892 | if (!CHIP_IS_E1x(bp)) | |
7893 | BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping, | |
7894 | sizeof(struct host_hc_status_block_e2)); | |
7895 | else | |
7896 | BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping, | |
7897 | sizeof(struct host_hc_status_block_e1x)); | |
7898 | ||
7899 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); | |
7900 | } | |
7901 | ||
9f6c9258 | 7902 | void bnx2x_free_mem(struct bnx2x *bp) |
a2fbb9ea | 7903 | { |
a052997e MS |
7904 | int i; |
7905 | ||
619c5cb6 VZ |
7906 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
7907 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); | |
7908 | ||
b4cddbd6 AE |
7909 | if (IS_VF(bp)) |
7910 | return; | |
7911 | ||
7912 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, | |
7913 | sizeof(struct host_sp_status_block)); | |
7914 | ||
a2fbb9ea | 7915 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
34f80b04 | 7916 | sizeof(struct bnx2x_slowpath)); |
a2fbb9ea | 7917 | |
a052997e MS |
7918 | for (i = 0; i < L2_ILT_LINES(bp); i++) |
7919 | BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping, | |
7920 | bp->context[i].size); | |
523224a3 DK |
7921 | bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE); |
7922 | ||
7923 | BNX2X_FREE(bp->ilt->lines); | |
f85582f8 | 7924 | |
7a9b2557 | 7925 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
a2fbb9ea | 7926 | |
523224a3 DK |
7927 | BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping, |
7928 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
580d9d08 | 7929 | |
05952246 YM |
7930 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); |
7931 | ||
580d9d08 | 7932 | bnx2x_iov_free_mem(bp); |
619c5cb6 VZ |
7933 | } |
7934 | ||
55c11941 | 7935 | int bnx2x_alloc_mem_cnic(struct bnx2x *bp) |
a2fbb9ea | 7936 | { |
619c5cb6 VZ |
7937 | if (!CHIP_IS_E1x(bp)) |
7938 | /* size = the status block + ramrod buffers */ | |
f2e0899f DK |
7939 | BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, |
7940 | sizeof(struct host_hc_status_block_e2)); | |
7941 | else | |
55c11941 MS |
7942 | BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, |
7943 | &bp->cnic_sb_mapping, | |
7944 | sizeof(struct | |
7945 | host_hc_status_block_e1x)); | |
8badd27a | 7946 | |
2f7a3122 | 7947 | if (CONFIGURE_NIC_MODE(bp) && !bp->t2) |
16a5fd92 | 7948 | /* allocate searcher T2 table, as it wasn't allocated before */ |
55c11941 MS |
7949 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); |
7950 | ||
7951 | /* write address to which L5 should insert its values */ | |
7952 | bp->cnic_eth_dev.addr_drv_info_to_mcp = | |
7953 | &bp->slowpath->drv_info_to_mcp; | |
7954 | ||
7955 | if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC)) | |
7956 | goto alloc_mem_err; | |
7957 | ||
7958 | return 0; | |
7959 | ||
7960 | alloc_mem_err: | |
7961 | bnx2x_free_mem_cnic(bp); | |
7962 | BNX2X_ERR("Can't allocate memory\n"); | |
7963 | return -ENOMEM; | |
7964 | } | |
7965 | ||
7966 | int bnx2x_alloc_mem(struct bnx2x *bp) | |
7967 | { | |
7968 | int i, allocated, context_size; | |
a2fbb9ea | 7969 | |
2f7a3122 | 7970 | if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) |
55c11941 MS |
7971 | /* allocate searcher T2 table */ |
7972 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); | |
8badd27a | 7973 | |
523224a3 DK |
7974 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
7975 | sizeof(struct host_sp_status_block)); | |
a2fbb9ea | 7976 | |
523224a3 DK |
7977 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
7978 | sizeof(struct bnx2x_slowpath)); | |
a2fbb9ea | 7979 | |
a052997e MS |
7980 | /* Allocate memory for CDU context: |
7981 | * This memory is allocated separately and not in the generic ILT | |
7982 | * functions because CDU differs in few aspects: | |
7983 | * 1. There are multiple entities allocating memory for context - | |
7984 | * 'regular' driver, CNIC and SRIOV driver. Each separately controls | |
7985 | * its own ILT lines. | |
7986 | * 2. Since CDU page-size is not a single 4KB page (which is the case | |
7987 | * for the other ILT clients), to be efficient we want to support | |
7988 | * allocation of sub-page-size in the last entry. | |
7989 | * 3. Context pointers are used by the driver to pass to FW / update | |
7990 | * the context (for the other ILT clients the pointers are used just to | |
7991 | * free the memory during unload). | |
7992 | */ | |
7993 | context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp); | |
65abd74d | 7994 | |
a052997e MS |
7995 | for (i = 0, allocated = 0; allocated < context_size; i++) { |
7996 | bp->context[i].size = min(CDU_ILT_PAGE_SZ, | |
7997 | (context_size - allocated)); | |
7998 | BNX2X_PCI_ALLOC(bp->context[i].vcxt, | |
7999 | &bp->context[i].cxt_mapping, | |
8000 | bp->context[i].size); | |
8001 | allocated += bp->context[i].size; | |
8002 | } | |
523224a3 | 8003 | BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); |
65abd74d | 8004 | |
523224a3 DK |
8005 | if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) |
8006 | goto alloc_mem_err; | |
65abd74d | 8007 | |
67c431a5 AE |
8008 | if (bnx2x_iov_alloc_mem(bp)) |
8009 | goto alloc_mem_err; | |
8010 | ||
9f6c9258 DK |
8011 | /* Slow path ring */ |
8012 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); | |
65abd74d | 8013 | |
523224a3 DK |
8014 | /* EQ */ |
8015 | BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, | |
8016 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
ab532cf3 | 8017 | |
9f6c9258 | 8018 | return 0; |
e1510706 | 8019 | |
9f6c9258 DK |
8020 | alloc_mem_err: |
8021 | bnx2x_free_mem(bp); | |
51c1a580 | 8022 | BNX2X_ERR("Can't allocate memory\n"); |
9f6c9258 | 8023 | return -ENOMEM; |
65abd74d YG |
8024 | } |
8025 | ||
a2fbb9ea ET |
8026 | /* |
8027 | * Init service functions | |
8028 | */ | |
a2fbb9ea | 8029 | |
619c5cb6 VZ |
8030 | int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac, |
8031 | struct bnx2x_vlan_mac_obj *obj, bool set, | |
8032 | int mac_type, unsigned long *ramrod_flags) | |
a2fbb9ea | 8033 | { |
619c5cb6 VZ |
8034 | int rc; |
8035 | struct bnx2x_vlan_mac_ramrod_params ramrod_param; | |
a2fbb9ea | 8036 | |
619c5cb6 | 8037 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
a2fbb9ea | 8038 | |
619c5cb6 VZ |
8039 | /* Fill general parameters */ |
8040 | ramrod_param.vlan_mac_obj = obj; | |
8041 | ramrod_param.ramrod_flags = *ramrod_flags; | |
a2fbb9ea | 8042 | |
619c5cb6 VZ |
8043 | /* Fill a user request section if needed */ |
8044 | if (!test_bit(RAMROD_CONT, ramrod_flags)) { | |
8045 | memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); | |
a2fbb9ea | 8046 | |
619c5cb6 | 8047 | __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); |
e3553b29 | 8048 | |
619c5cb6 VZ |
8049 | /* Set the command: ADD or DEL */ |
8050 | if (set) | |
8051 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD; | |
8052 | else | |
8053 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL; | |
a2fbb9ea ET |
8054 | } |
8055 | ||
619c5cb6 | 8056 | rc = bnx2x_config_vlan_mac(bp, &ramrod_param); |
7b5342d9 YM |
8057 | |
8058 | if (rc == -EEXIST) { | |
8059 | DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc); | |
8060 | /* do not treat adding same MAC as error */ | |
8061 | rc = 0; | |
8062 | } else if (rc < 0) | |
619c5cb6 | 8063 | BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); |
7b5342d9 | 8064 | |
619c5cb6 | 8065 | return rc; |
a2fbb9ea ET |
8066 | } |
8067 | ||
619c5cb6 VZ |
8068 | int bnx2x_del_all_macs(struct bnx2x *bp, |
8069 | struct bnx2x_vlan_mac_obj *mac_obj, | |
8070 | int mac_type, bool wait_for_comp) | |
e665bfda | 8071 | { |
619c5cb6 VZ |
8072 | int rc; |
8073 | unsigned long ramrod_flags = 0, vlan_mac_flags = 0; | |
0793f83f | 8074 | |
619c5cb6 VZ |
8075 | /* Wait for completion of requested */ |
8076 | if (wait_for_comp) | |
8077 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
0793f83f | 8078 | |
619c5cb6 VZ |
8079 | /* Set the mac type of addresses we want to clear */ |
8080 | __set_bit(mac_type, &vlan_mac_flags); | |
0793f83f | 8081 | |
619c5cb6 VZ |
8082 | rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags); |
8083 | if (rc < 0) | |
8084 | BNX2X_ERR("Failed to delete MACs: %d\n", rc); | |
0793f83f | 8085 | |
619c5cb6 | 8086 | return rc; |
0793f83f DK |
8087 | } |
8088 | ||
619c5cb6 | 8089 | int bnx2x_set_eth_mac(struct bnx2x *bp, bool set) |
523224a3 | 8090 | { |
a3348722 BW |
8091 | if (is_zero_ether_addr(bp->dev->dev_addr) && |
8092 | (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) { | |
51c1a580 MS |
8093 | DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN, |
8094 | "Ignoring Zero MAC for STORAGE SD mode\n"); | |
614c76df DK |
8095 | return 0; |
8096 | } | |
614c76df | 8097 | |
f8f4f61a DK |
8098 | if (IS_PF(bp)) { |
8099 | unsigned long ramrod_flags = 0; | |
0793f83f | 8100 | |
f8f4f61a DK |
8101 | DP(NETIF_MSG_IFUP, "Adding Eth MAC\n"); |
8102 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
8103 | return bnx2x_set_mac_one(bp, bp->dev->dev_addr, | |
8104 | &bp->sp_objs->mac_obj, set, | |
8105 | BNX2X_ETH_MAC, &ramrod_flags); | |
8106 | } else { /* vf */ | |
8107 | return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, | |
8108 | bp->fp->index, true); | |
8109 | } | |
e665bfda | 8110 | } |
6e30dd4e | 8111 | |
619c5cb6 | 8112 | int bnx2x_setup_leading(struct bnx2x *bp) |
ec6ba945 | 8113 | { |
60cad4e6 AE |
8114 | if (IS_PF(bp)) |
8115 | return bnx2x_setup_queue(bp, &bp->fp[0], true); | |
8116 | else /* VF */ | |
8117 | return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true); | |
993ac7b5 | 8118 | } |
a2fbb9ea | 8119 | |
d6214d7a | 8120 | /** |
e8920674 | 8121 | * bnx2x_set_int_mode - configure interrupt mode |
d6214d7a | 8122 | * |
e8920674 | 8123 | * @bp: driver handle |
d6214d7a | 8124 | * |
e8920674 | 8125 | * In case of MSI-X it will also try to enable MSI-X. |
d6214d7a | 8126 | */ |
1ab4434c | 8127 | int bnx2x_set_int_mode(struct bnx2x *bp) |
ca00392c | 8128 | { |
1ab4434c AE |
8129 | int rc = 0; |
8130 | ||
60cad4e6 AE |
8131 | if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) { |
8132 | BNX2X_ERR("VF not loaded since interrupt mode not msix\n"); | |
1ab4434c | 8133 | return -EINVAL; |
60cad4e6 | 8134 | } |
1ab4434c | 8135 | |
9ee3d37b | 8136 | switch (int_mode) { |
1ab4434c AE |
8137 | case BNX2X_INT_MODE_MSIX: |
8138 | /* attempt to enable msix */ | |
8139 | rc = bnx2x_enable_msix(bp); | |
8140 | ||
8141 | /* msix attained */ | |
8142 | if (!rc) | |
8143 | return 0; | |
8144 | ||
8145 | /* vfs use only msix */ | |
8146 | if (rc && IS_VF(bp)) | |
8147 | return rc; | |
8148 | ||
8149 | /* failed to enable multiple MSI-X */ | |
8150 | BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n", | |
8151 | bp->num_queues, | |
8152 | 1 + bp->num_cnic_queues); | |
8153 | ||
8154 | /* falling through... */ | |
8155 | case BNX2X_INT_MODE_MSI: | |
d6214d7a | 8156 | bnx2x_enable_msi(bp); |
1ab4434c | 8157 | |
d6214d7a | 8158 | /* falling through... */ |
1ab4434c | 8159 | case BNX2X_INT_MODE_INTX: |
55c11941 MS |
8160 | bp->num_ethernet_queues = 1; |
8161 | bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues; | |
51c1a580 | 8162 | BNX2X_DEV_INFO("set number of queues to 1\n"); |
ca00392c | 8163 | break; |
d6214d7a | 8164 | default: |
1ab4434c AE |
8165 | BNX2X_DEV_INFO("unknown value in int_mode module parameter\n"); |
8166 | return -EINVAL; | |
9f6c9258 | 8167 | } |
1ab4434c | 8168 | return 0; |
a2fbb9ea ET |
8169 | } |
8170 | ||
1ab4434c | 8171 | /* must be called prior to any HW initializations */ |
c2bff63f DK |
8172 | static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp) |
8173 | { | |
290ca2bb AE |
8174 | if (IS_SRIOV(bp)) |
8175 | return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS; | |
c2bff63f DK |
8176 | return L2_ILT_LINES(bp); |
8177 | } | |
8178 | ||
523224a3 DK |
8179 | void bnx2x_ilt_set_info(struct bnx2x *bp) |
8180 | { | |
8181 | struct ilt_client_info *ilt_client; | |
8182 | struct bnx2x_ilt *ilt = BP_ILT(bp); | |
8183 | u16 line = 0; | |
8184 | ||
8185 | ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp)); | |
8186 | DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line); | |
8187 | ||
8188 | /* CDU */ | |
8189 | ilt_client = &ilt->clients[ILT_CLIENT_CDU]; | |
8190 | ilt_client->client_num = ILT_CLIENT_CDU; | |
8191 | ilt_client->page_size = CDU_ILT_PAGE_SZ; | |
8192 | ilt_client->flags = ILT_CLIENT_SKIP_MEM; | |
8193 | ilt_client->start = line; | |
619c5cb6 | 8194 | line += bnx2x_cid_ilt_lines(bp); |
55c11941 MS |
8195 | |
8196 | if (CNIC_SUPPORT(bp)) | |
8197 | line += CNIC_ILT_LINES; | |
523224a3 DK |
8198 | ilt_client->end = line - 1; |
8199 | ||
51c1a580 | 8200 | DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", |
523224a3 DK |
8201 | ilt_client->start, |
8202 | ilt_client->end, | |
8203 | ilt_client->page_size, | |
8204 | ilt_client->flags, | |
8205 | ilog2(ilt_client->page_size >> 12)); | |
8206 | ||
8207 | /* QM */ | |
8208 | if (QM_INIT(bp->qm_cid_count)) { | |
8209 | ilt_client = &ilt->clients[ILT_CLIENT_QM]; | |
8210 | ilt_client->client_num = ILT_CLIENT_QM; | |
8211 | ilt_client->page_size = QM_ILT_PAGE_SZ; | |
8212 | ilt_client->flags = 0; | |
8213 | ilt_client->start = line; | |
8214 | ||
8215 | /* 4 bytes for each cid */ | |
8216 | line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4, | |
8217 | QM_ILT_PAGE_SZ); | |
8218 | ||
8219 | ilt_client->end = line - 1; | |
8220 | ||
51c1a580 MS |
8221 | DP(NETIF_MSG_IFUP, |
8222 | "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
523224a3 DK |
8223 | ilt_client->start, |
8224 | ilt_client->end, | |
8225 | ilt_client->page_size, | |
8226 | ilt_client->flags, | |
8227 | ilog2(ilt_client->page_size >> 12)); | |
523224a3 | 8228 | } |
523224a3 | 8229 | |
55c11941 MS |
8230 | if (CNIC_SUPPORT(bp)) { |
8231 | /* SRC */ | |
8232 | ilt_client = &ilt->clients[ILT_CLIENT_SRC]; | |
8233 | ilt_client->client_num = ILT_CLIENT_SRC; | |
8234 | ilt_client->page_size = SRC_ILT_PAGE_SZ; | |
8235 | ilt_client->flags = 0; | |
8236 | ilt_client->start = line; | |
8237 | line += SRC_ILT_LINES; | |
8238 | ilt_client->end = line - 1; | |
523224a3 | 8239 | |
55c11941 MS |
8240 | DP(NETIF_MSG_IFUP, |
8241 | "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
8242 | ilt_client->start, | |
8243 | ilt_client->end, | |
8244 | ilt_client->page_size, | |
8245 | ilt_client->flags, | |
8246 | ilog2(ilt_client->page_size >> 12)); | |
9f6c9258 | 8247 | |
55c11941 MS |
8248 | /* TM */ |
8249 | ilt_client = &ilt->clients[ILT_CLIENT_TM]; | |
8250 | ilt_client->client_num = ILT_CLIENT_TM; | |
8251 | ilt_client->page_size = TM_ILT_PAGE_SZ; | |
8252 | ilt_client->flags = 0; | |
8253 | ilt_client->start = line; | |
8254 | line += TM_ILT_LINES; | |
8255 | ilt_client->end = line - 1; | |
523224a3 | 8256 | |
55c11941 MS |
8257 | DP(NETIF_MSG_IFUP, |
8258 | "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
8259 | ilt_client->start, | |
8260 | ilt_client->end, | |
8261 | ilt_client->page_size, | |
8262 | ilt_client->flags, | |
8263 | ilog2(ilt_client->page_size >> 12)); | |
8264 | } | |
9f6c9258 | 8265 | |
619c5cb6 | 8266 | BUG_ON(line > ILT_MAX_LINES); |
523224a3 | 8267 | } |
f85582f8 | 8268 | |
619c5cb6 VZ |
8269 | /** |
8270 | * bnx2x_pf_q_prep_init - prepare INIT transition parameters | |
8271 | * | |
8272 | * @bp: driver handle | |
8273 | * @fp: pointer to fastpath | |
8274 | * @init_params: pointer to parameters structure | |
8275 | * | |
8276 | * parameters configured: | |
8277 | * - HC configuration | |
8278 | * - Queue's CDU context | |
8279 | */ | |
1191cb83 | 8280 | static void bnx2x_pf_q_prep_init(struct bnx2x *bp, |
619c5cb6 | 8281 | struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params) |
a2fbb9ea | 8282 | { |
6383c0b3 | 8283 | u8 cos; |
a052997e MS |
8284 | int cxt_index, cxt_offset; |
8285 | ||
619c5cb6 VZ |
8286 | /* FCoE Queue uses Default SB, thus has no HC capabilities */ |
8287 | if (!IS_FCOE_FP(fp)) { | |
8288 | __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags); | |
8289 | __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags); | |
8290 | ||
16a5fd92 | 8291 | /* If HC is supported, enable host coalescing in the transition |
619c5cb6 VZ |
8292 | * to INIT state. |
8293 | */ | |
8294 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags); | |
8295 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags); | |
8296 | ||
8297 | /* HC rate */ | |
8298 | init_params->rx.hc_rate = bp->rx_ticks ? | |
8299 | (1000000 / bp->rx_ticks) : 0; | |
8300 | init_params->tx.hc_rate = bp->tx_ticks ? | |
8301 | (1000000 / bp->tx_ticks) : 0; | |
8302 | ||
8303 | /* FW SB ID */ | |
8304 | init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = | |
8305 | fp->fw_sb_id; | |
8306 | ||
8307 | /* | |
8308 | * CQ index among the SB indices: FCoE clients uses the default | |
8309 | * SB, therefore it's different. | |
8310 | */ | |
6383c0b3 AE |
8311 | init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
8312 | init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS; | |
619c5cb6 VZ |
8313 | } |
8314 | ||
6383c0b3 AE |
8315 | /* set maximum number of COSs supported by this queue */ |
8316 | init_params->max_cos = fp->max_cos; | |
8317 | ||
51c1a580 | 8318 | DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n", |
6383c0b3 AE |
8319 | fp->index, init_params->max_cos); |
8320 | ||
8321 | /* set the context pointers queue object */ | |
a052997e | 8322 | for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) { |
65565884 MS |
8323 | cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS; |
8324 | cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index * | |
a052997e | 8325 | ILT_PAGE_CIDS); |
6383c0b3 | 8326 | init_params->cxts[cos] = |
a052997e MS |
8327 | &bp->context[cxt_index].vcxt[cxt_offset].eth; |
8328 | } | |
619c5cb6 VZ |
8329 | } |
8330 | ||
910cc727 | 8331 | static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
6383c0b3 AE |
8332 | struct bnx2x_queue_state_params *q_params, |
8333 | struct bnx2x_queue_setup_tx_only_params *tx_only_params, | |
8334 | int tx_index, bool leading) | |
8335 | { | |
8336 | memset(tx_only_params, 0, sizeof(*tx_only_params)); | |
8337 | ||
8338 | /* Set the command */ | |
8339 | q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; | |
8340 | ||
8341 | /* Set tx-only QUEUE flags: don't zero statistics */ | |
8342 | tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false); | |
8343 | ||
8344 | /* choose the index of the cid to send the slow path on */ | |
8345 | tx_only_params->cid_index = tx_index; | |
8346 | ||
8347 | /* Set general TX_ONLY_SETUP parameters */ | |
8348 | bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index); | |
8349 | ||
8350 | /* Set Tx TX_ONLY_SETUP parameters */ | |
8351 | bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index); | |
8352 | ||
51c1a580 MS |
8353 | DP(NETIF_MSG_IFUP, |
8354 | "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 |
8355 | tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX], |
8356 | q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id, | |
8357 | tx_only_params->gen_params.spcl_id, tx_only_params->flags); | |
8358 | ||
8359 | /* send the ramrod */ | |
8360 | return bnx2x_queue_state_change(bp, q_params); | |
8361 | } | |
8362 | ||
619c5cb6 VZ |
8363 | /** |
8364 | * bnx2x_setup_queue - setup queue | |
8365 | * | |
8366 | * @bp: driver handle | |
8367 | * @fp: pointer to fastpath | |
8368 | * @leading: is leading | |
8369 | * | |
8370 | * This function performs 2 steps in a Queue state machine | |
8371 | * actually: 1) RESET->INIT 2) INIT->SETUP | |
8372 | */ | |
8373 | ||
8374 | int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp, | |
8375 | bool leading) | |
8376 | { | |
3b603066 | 8377 | struct bnx2x_queue_state_params q_params = {NULL}; |
619c5cb6 VZ |
8378 | struct bnx2x_queue_setup_params *setup_params = |
8379 | &q_params.params.setup; | |
6383c0b3 AE |
8380 | struct bnx2x_queue_setup_tx_only_params *tx_only_params = |
8381 | &q_params.params.tx_only; | |
a2fbb9ea | 8382 | int rc; |
6383c0b3 AE |
8383 | u8 tx_index; |
8384 | ||
51c1a580 | 8385 | DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index); |
a2fbb9ea | 8386 | |
ec6ba945 VZ |
8387 | /* reset IGU state skip FCoE L2 queue */ |
8388 | if (!IS_FCOE_FP(fp)) | |
8389 | bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, | |
523224a3 | 8390 | IGU_INT_ENABLE, 0); |
a2fbb9ea | 8391 | |
15192a8c | 8392 | q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
619c5cb6 VZ |
8393 | /* We want to wait for completion in this context */ |
8394 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 8395 | |
619c5cb6 VZ |
8396 | /* Prepare the INIT parameters */ |
8397 | bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init); | |
ec6ba945 | 8398 | |
619c5cb6 VZ |
8399 | /* Set the command */ |
8400 | q_params.cmd = BNX2X_Q_CMD_INIT; | |
8401 | ||
8402 | /* Change the state to INIT */ | |
8403 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8404 | if (rc) { | |
6383c0b3 | 8405 | BNX2X_ERR("Queue(%d) INIT failed\n", fp->index); |
619c5cb6 VZ |
8406 | return rc; |
8407 | } | |
ec6ba945 | 8408 | |
51c1a580 | 8409 | DP(NETIF_MSG_IFUP, "init complete\n"); |
6383c0b3 | 8410 | |
619c5cb6 VZ |
8411 | /* Now move the Queue to the SETUP state... */ |
8412 | memset(setup_params, 0, sizeof(*setup_params)); | |
a2fbb9ea | 8413 | |
619c5cb6 VZ |
8414 | /* Set QUEUE flags */ |
8415 | setup_params->flags = bnx2x_get_q_flags(bp, fp, leading); | |
523224a3 | 8416 | |
619c5cb6 | 8417 | /* Set general SETUP parameters */ |
6383c0b3 AE |
8418 | bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params, |
8419 | FIRST_TX_COS_INDEX); | |
619c5cb6 | 8420 | |
6383c0b3 | 8421 | bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params, |
619c5cb6 VZ |
8422 | &setup_params->rxq_params); |
8423 | ||
6383c0b3 AE |
8424 | bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params, |
8425 | FIRST_TX_COS_INDEX); | |
619c5cb6 VZ |
8426 | |
8427 | /* Set the command */ | |
8428 | q_params.cmd = BNX2X_Q_CMD_SETUP; | |
8429 | ||
55c11941 MS |
8430 | if (IS_FCOE_FP(fp)) |
8431 | bp->fcoe_init = true; | |
8432 | ||
619c5cb6 VZ |
8433 | /* Change the state to SETUP */ |
8434 | rc = bnx2x_queue_state_change(bp, &q_params); | |
6383c0b3 AE |
8435 | if (rc) { |
8436 | BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index); | |
8437 | return rc; | |
8438 | } | |
8439 | ||
8440 | /* loop through the relevant tx-only indices */ | |
8441 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
8442 | tx_index < fp->max_cos; | |
8443 | tx_index++) { | |
8444 | ||
8445 | /* prepare and send tx-only ramrod*/ | |
8446 | rc = bnx2x_setup_tx_only(bp, fp, &q_params, | |
8447 | tx_only_params, tx_index, leading); | |
8448 | if (rc) { | |
8449 | BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n", | |
8450 | fp->index, tx_index); | |
8451 | return rc; | |
8452 | } | |
8453 | } | |
523224a3 | 8454 | |
34f80b04 | 8455 | return rc; |
a2fbb9ea ET |
8456 | } |
8457 | ||
619c5cb6 | 8458 | static int bnx2x_stop_queue(struct bnx2x *bp, int index) |
a2fbb9ea | 8459 | { |
619c5cb6 | 8460 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
6383c0b3 | 8461 | struct bnx2x_fp_txdata *txdata; |
3b603066 | 8462 | struct bnx2x_queue_state_params q_params = {NULL}; |
6383c0b3 AE |
8463 | int rc, tx_index; |
8464 | ||
51c1a580 | 8465 | DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid); |
a2fbb9ea | 8466 | |
15192a8c | 8467 | q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; |
619c5cb6 VZ |
8468 | /* We want to wait for completion in this context */ |
8469 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 8470 | |
6383c0b3 AE |
8471 | /* close tx-only connections */ |
8472 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
8473 | tx_index < fp->max_cos; | |
8474 | tx_index++){ | |
8475 | ||
8476 | /* ascertain this is a normal queue*/ | |
65565884 | 8477 | txdata = fp->txdata_ptr[tx_index]; |
6383c0b3 | 8478 | |
51c1a580 | 8479 | DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n", |
6383c0b3 AE |
8480 | txdata->txq_index); |
8481 | ||
8482 | /* send halt terminate on tx-only connection */ | |
8483 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; | |
8484 | memset(&q_params.params.terminate, 0, | |
8485 | sizeof(q_params.params.terminate)); | |
8486 | q_params.params.terminate.cid_index = tx_index; | |
8487 | ||
8488 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8489 | if (rc) | |
8490 | return rc; | |
8491 | ||
8492 | /* send halt terminate on tx-only connection */ | |
8493 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; | |
8494 | memset(&q_params.params.cfc_del, 0, | |
8495 | sizeof(q_params.params.cfc_del)); | |
8496 | q_params.params.cfc_del.cid_index = tx_index; | |
8497 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8498 | if (rc) | |
8499 | return rc; | |
8500 | } | |
8501 | /* Stop the primary connection: */ | |
8502 | /* ...halt the connection */ | |
619c5cb6 VZ |
8503 | q_params.cmd = BNX2X_Q_CMD_HALT; |
8504 | rc = bnx2x_queue_state_change(bp, &q_params); | |
8505 | if (rc) | |
da5a662a | 8506 | return rc; |
a2fbb9ea | 8507 | |
6383c0b3 | 8508 | /* ...terminate the connection */ |
619c5cb6 | 8509 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; |
6383c0b3 AE |
8510 | memset(&q_params.params.terminate, 0, |
8511 | sizeof(q_params.params.terminate)); | |
8512 | q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 VZ |
8513 | rc = bnx2x_queue_state_change(bp, &q_params); |
8514 | if (rc) | |
523224a3 | 8515 | return rc; |
6383c0b3 | 8516 | /* ...delete cfc entry */ |
619c5cb6 | 8517 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; |
6383c0b3 AE |
8518 | memset(&q_params.params.cfc_del, 0, |
8519 | sizeof(q_params.params.cfc_del)); | |
8520 | q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 | 8521 | return bnx2x_queue_state_change(bp, &q_params); |
523224a3 DK |
8522 | } |
8523 | ||
34f80b04 EG |
8524 | static void bnx2x_reset_func(struct bnx2x *bp) |
8525 | { | |
8526 | int port = BP_PORT(bp); | |
8527 | int func = BP_FUNC(bp); | |
f2e0899f | 8528 | int i; |
523224a3 DK |
8529 | |
8530 | /* Disable the function in the FW */ | |
8531 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); | |
8532 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); | |
8533 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); | |
8534 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); | |
8535 | ||
8536 | /* FP SBs */ | |
ec6ba945 | 8537 | for_each_eth_queue(bp, i) { |
523224a3 | 8538 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
619c5cb6 | 8539 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
6383c0b3 AE |
8540 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), |
8541 | SB_DISABLED); | |
523224a3 DK |
8542 | } |
8543 | ||
55c11941 MS |
8544 | if (CNIC_LOADED(bp)) |
8545 | /* CNIC SB */ | |
8546 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
8547 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET | |
8548 | (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED); | |
8549 | ||
523224a3 | 8550 | /* SP SB */ |
619c5cb6 | 8551 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
2de67439 YM |
8552 | CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), |
8553 | SB_DISABLED); | |
523224a3 DK |
8554 | |
8555 | for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) | |
8556 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), | |
8557 | 0); | |
34f80b04 EG |
8558 | |
8559 | /* Configure IGU */ | |
f2e0899f DK |
8560 | if (bp->common.int_block == INT_BLOCK_HC) { |
8561 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
8562 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
8563 | } else { | |
8564 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); | |
8565 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
8566 | } | |
34f80b04 | 8567 | |
55c11941 MS |
8568 | if (CNIC_LOADED(bp)) { |
8569 | /* Disable Timer scan */ | |
8570 | REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0); | |
8571 | /* | |
8572 | * Wait for at least 10ms and up to 2 second for the timers | |
8573 | * scan to complete | |
8574 | */ | |
8575 | for (i = 0; i < 200; i++) { | |
639d65b8 | 8576 | usleep_range(10000, 20000); |
55c11941 MS |
8577 | if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4)) |
8578 | break; | |
8579 | } | |
37b091ba | 8580 | } |
34f80b04 | 8581 | /* Clear ILT */ |
f2e0899f DK |
8582 | bnx2x_clear_func_ilt(bp, func); |
8583 | ||
8584 | /* Timers workaround bug for E2: if this is vnic-3, | |
8585 | * we need to set the entire ilt range for this timers. | |
8586 | */ | |
619c5cb6 | 8587 | if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) { |
f2e0899f DK |
8588 | struct ilt_client_info ilt_cli; |
8589 | /* use dummy TM client */ | |
8590 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
8591 | ilt_cli.start = 0; | |
8592 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
8593 | ilt_cli.client_num = ILT_CLIENT_TM; | |
8594 | ||
8595 | bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR); | |
8596 | } | |
8597 | ||
8598 | /* this assumes that reset_port() called before reset_func()*/ | |
619c5cb6 | 8599 | if (!CHIP_IS_E1x(bp)) |
f2e0899f | 8600 | bnx2x_pf_disable(bp); |
523224a3 DK |
8601 | |
8602 | bp->dmae_ready = 0; | |
34f80b04 EG |
8603 | } |
8604 | ||
8605 | static void bnx2x_reset_port(struct bnx2x *bp) | |
8606 | { | |
8607 | int port = BP_PORT(bp); | |
8608 | u32 val; | |
8609 | ||
619c5cb6 VZ |
8610 | /* Reset physical Link */ |
8611 | bnx2x__link_reset(bp); | |
8612 | ||
34f80b04 EG |
8613 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
8614 | ||
8615 | /* Do not rcv packets to BRB */ | |
8616 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); | |
8617 | /* Do not direct rcv packets that are not for MCP to the BRB */ | |
8618 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : | |
8619 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); | |
8620 | ||
8621 | /* Configure AEU */ | |
8622 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); | |
8623 | ||
8624 | msleep(100); | |
8625 | /* Check for BRB port occupancy */ | |
8626 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); | |
8627 | if (val) | |
8628 | DP(NETIF_MSG_IFDOWN, | |
33471629 | 8629 | "BRB1 is not empty %d blocks are occupied\n", val); |
34f80b04 EG |
8630 | |
8631 | /* TODO: Close Doorbell port? */ | |
8632 | } | |
8633 | ||
1191cb83 | 8634 | static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code) |
34f80b04 | 8635 | { |
3b603066 | 8636 | struct bnx2x_func_state_params func_params = {NULL}; |
34f80b04 | 8637 | |
619c5cb6 VZ |
8638 | /* Prepare parameters for function state transitions */ |
8639 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
34f80b04 | 8640 | |
619c5cb6 VZ |
8641 | func_params.f_obj = &bp->func_obj; |
8642 | func_params.cmd = BNX2X_F_CMD_HW_RESET; | |
34f80b04 | 8643 | |
619c5cb6 | 8644 | func_params.params.hw_init.load_phase = load_code; |
49d66772 | 8645 | |
619c5cb6 | 8646 | return bnx2x_func_state_change(bp, &func_params); |
34f80b04 EG |
8647 | } |
8648 | ||
1191cb83 | 8649 | static int bnx2x_func_stop(struct bnx2x *bp) |
ec6ba945 | 8650 | { |
3b603066 | 8651 | struct bnx2x_func_state_params func_params = {NULL}; |
619c5cb6 | 8652 | int rc; |
228241eb | 8653 | |
619c5cb6 VZ |
8654 | /* Prepare parameters for function state transitions */ |
8655 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
8656 | func_params.f_obj = &bp->func_obj; | |
8657 | func_params.cmd = BNX2X_F_CMD_STOP; | |
da5a662a | 8658 | |
619c5cb6 VZ |
8659 | /* |
8660 | * Try to stop the function the 'good way'. If fails (in case | |
8661 | * of a parity error during bnx2x_chip_cleanup()) and we are | |
8662 | * not in a debug mode, perform a state transaction in order to | |
8663 | * enable further HW_RESET transaction. | |
8664 | */ | |
8665 | rc = bnx2x_func_state_change(bp, &func_params); | |
8666 | if (rc) { | |
34f80b04 | 8667 | #ifdef BNX2X_STOP_ON_ERROR |
619c5cb6 | 8668 | return rc; |
34f80b04 | 8669 | #else |
51c1a580 | 8670 | BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n"); |
619c5cb6 VZ |
8671 | __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); |
8672 | return bnx2x_func_state_change(bp, &func_params); | |
34f80b04 | 8673 | #endif |
228241eb | 8674 | } |
a2fbb9ea | 8675 | |
619c5cb6 VZ |
8676 | return 0; |
8677 | } | |
523224a3 | 8678 | |
619c5cb6 VZ |
8679 | /** |
8680 | * bnx2x_send_unload_req - request unload mode from the MCP. | |
8681 | * | |
8682 | * @bp: driver handle | |
8683 | * @unload_mode: requested function's unload mode | |
8684 | * | |
8685 | * Return unload mode returned by the MCP: COMMON, PORT or FUNC. | |
8686 | */ | |
8687 | u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode) | |
8688 | { | |
8689 | u32 reset_code = 0; | |
8690 | int port = BP_PORT(bp); | |
3101c2bc | 8691 | |
619c5cb6 | 8692 | /* Select the UNLOAD request mode */ |
65abd74d YG |
8693 | if (unload_mode == UNLOAD_NORMAL) |
8694 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
8695 | ||
7d0446c2 | 8696 | else if (bp->flags & NO_WOL_FLAG) |
65abd74d | 8697 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
65abd74d | 8698 | |
7d0446c2 | 8699 | else if (bp->wol) { |
65abd74d YG |
8700 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
8701 | u8 *mac_addr = bp->dev->dev_addr; | |
29ed74c3 | 8702 | struct pci_dev *pdev = bp->pdev; |
65abd74d | 8703 | u32 val; |
f9977903 DK |
8704 | u16 pmc; |
8705 | ||
65abd74d | 8706 | /* The mac address is written to entries 1-4 to |
f9977903 DK |
8707 | * preserve entry 0 which is used by the PMF |
8708 | */ | |
3395a033 | 8709 | u8 entry = (BP_VN(bp) + 1)*8; |
65abd74d YG |
8710 | |
8711 | val = (mac_addr[0] << 8) | mac_addr[1]; | |
8712 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); | |
8713 | ||
8714 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | | |
8715 | (mac_addr[4] << 8) | mac_addr[5]; | |
8716 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); | |
8717 | ||
f9977903 | 8718 | /* Enable the PME and clear the status */ |
29ed74c3 | 8719 | pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc); |
f9977903 | 8720 | pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS; |
29ed74c3 | 8721 | pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc); |
f9977903 | 8722 | |
65abd74d YG |
8723 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
8724 | ||
8725 | } else | |
8726 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
da5a662a | 8727 | |
619c5cb6 VZ |
8728 | /* Send the request to the MCP */ |
8729 | if (!BP_NOMCP(bp)) | |
8730 | reset_code = bnx2x_fw_command(bp, reset_code, 0); | |
8731 | else { | |
8732 | int path = BP_PATH(bp); | |
8733 | ||
51c1a580 | 8734 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
8735 | path, load_count[path][0], load_count[path][1], |
8736 | load_count[path][2]); | |
8737 | load_count[path][0]--; | |
8738 | load_count[path][1 + port]--; | |
51c1a580 | 8739 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
8740 | path, load_count[path][0], load_count[path][1], |
8741 | load_count[path][2]); | |
8742 | if (load_count[path][0] == 0) | |
8743 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; | |
8744 | else if (load_count[path][1 + port] == 0) | |
8745 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; | |
8746 | else | |
8747 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; | |
8748 | } | |
8749 | ||
8750 | return reset_code; | |
8751 | } | |
8752 | ||
8753 | /** | |
8754 | * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP. | |
8755 | * | |
8756 | * @bp: driver handle | |
5d07d868 | 8757 | * @keep_link: true iff link should be kept up |
619c5cb6 | 8758 | */ |
5d07d868 | 8759 | void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link) |
619c5cb6 | 8760 | { |
5d07d868 YM |
8761 | u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0; |
8762 | ||
619c5cb6 VZ |
8763 | /* Report UNLOAD_DONE to MCP */ |
8764 | if (!BP_NOMCP(bp)) | |
5d07d868 | 8765 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param); |
619c5cb6 VZ |
8766 | } |
8767 | ||
1191cb83 | 8768 | static int bnx2x_func_wait_started(struct bnx2x *bp) |
6debea87 DK |
8769 | { |
8770 | int tout = 50; | |
8771 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; | |
8772 | ||
8773 | if (!bp->port.pmf) | |
8774 | return 0; | |
8775 | ||
8776 | /* | |
8777 | * (assumption: No Attention from MCP at this stage) | |
16a5fd92 | 8778 | * PMF probably in the middle of TX disable/enable transaction |
6debea87 | 8779 | * 1. Sync IRS for default SB |
16a5fd92 YM |
8780 | * 2. Sync SP queue - this guarantees us that attention handling started |
8781 | * 3. Wait, that TX disable/enable transaction completes | |
6debea87 | 8782 | * |
16a5fd92 YM |
8783 | * 1+2 guarantee that if DCBx attention was scheduled it already changed |
8784 | * pending bit of transaction from STARTED-->TX_STOPPED, if we already | |
8785 | * received completion for the transaction the state is TX_STOPPED. | |
6debea87 DK |
8786 | * State will return to STARTED after completion of TX_STOPPED-->STARTED |
8787 | * transaction. | |
8788 | */ | |
8789 | ||
8790 | /* make sure default SB ISR is done */ | |
8791 | if (msix) | |
8792 | synchronize_irq(bp->msix_table[0].vector); | |
8793 | else | |
8794 | synchronize_irq(bp->pdev->irq); | |
8795 | ||
8796 | flush_workqueue(bnx2x_wq); | |
8797 | ||
8798 | while (bnx2x_func_get_state(bp, &bp->func_obj) != | |
8799 | BNX2X_F_STATE_STARTED && tout--) | |
8800 | msleep(20); | |
8801 | ||
8802 | if (bnx2x_func_get_state(bp, &bp->func_obj) != | |
8803 | BNX2X_F_STATE_STARTED) { | |
8804 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 | 8805 | BNX2X_ERR("Wrong function state\n"); |
6debea87 DK |
8806 | return -EBUSY; |
8807 | #else | |
8808 | /* | |
8809 | * Failed to complete the transaction in a "good way" | |
8810 | * Force both transactions with CLR bit | |
8811 | */ | |
3b603066 | 8812 | struct bnx2x_func_state_params func_params = {NULL}; |
6debea87 | 8813 | |
51c1a580 | 8814 | DP(NETIF_MSG_IFDOWN, |
6bf07b8e | 8815 | "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n"); |
6debea87 DK |
8816 | |
8817 | func_params.f_obj = &bp->func_obj; | |
8818 | __set_bit(RAMROD_DRV_CLR_ONLY, | |
8819 | &func_params.ramrod_flags); | |
8820 | ||
8821 | /* STARTED-->TX_ST0PPED */ | |
8822 | func_params.cmd = BNX2X_F_CMD_TX_STOP; | |
8823 | bnx2x_func_state_change(bp, &func_params); | |
8824 | ||
8825 | /* TX_ST0PPED-->STARTED */ | |
8826 | func_params.cmd = BNX2X_F_CMD_TX_START; | |
8827 | return bnx2x_func_state_change(bp, &func_params); | |
8828 | #endif | |
8829 | } | |
8830 | ||
8831 | return 0; | |
8832 | } | |
8833 | ||
5d07d868 | 8834 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link) |
619c5cb6 VZ |
8835 | { |
8836 | int port = BP_PORT(bp); | |
6383c0b3 AE |
8837 | int i, rc = 0; |
8838 | u8 cos; | |
3b603066 | 8839 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 VZ |
8840 | u32 reset_code; |
8841 | ||
8842 | /* Wait until tx fastpath tasks complete */ | |
8843 | for_each_tx_queue(bp, i) { | |
8844 | struct bnx2x_fastpath *fp = &bp->fp[i]; | |
8845 | ||
6383c0b3 | 8846 | for_each_cos_in_tx_queue(fp, cos) |
65565884 | 8847 | rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]); |
619c5cb6 VZ |
8848 | #ifdef BNX2X_STOP_ON_ERROR |
8849 | if (rc) | |
8850 | return; | |
8851 | #endif | |
8852 | } | |
8853 | ||
8854 | /* Give HW time to discard old tx messages */ | |
0926d499 | 8855 | usleep_range(1000, 2000); |
619c5cb6 VZ |
8856 | |
8857 | /* Clean all ETH MACs */ | |
15192a8c BW |
8858 | rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC, |
8859 | false); | |
619c5cb6 VZ |
8860 | if (rc < 0) |
8861 | BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc); | |
8862 | ||
8863 | /* Clean up UC list */ | |
15192a8c | 8864 | rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC, |
619c5cb6 VZ |
8865 | true); |
8866 | if (rc < 0) | |
51c1a580 MS |
8867 | BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n", |
8868 | rc); | |
619c5cb6 VZ |
8869 | |
8870 | /* Disable LLH */ | |
8871 | if (!CHIP_IS_E1(bp)) | |
8872 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
8873 | ||
8874 | /* Set "drop all" (stop Rx). | |
8875 | * We need to take a netif_addr_lock() here in order to prevent | |
8876 | * a race between the completion code and this code. | |
8877 | */ | |
8878 | netif_addr_lock_bh(bp->dev); | |
8879 | /* Schedule the rx_mode command */ | |
8880 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
8881 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
8882 | else | |
8883 | bnx2x_set_storm_rx_mode(bp); | |
8884 | ||
8885 | /* Cleanup multicast configuration */ | |
8886 | rparam.mcast_obj = &bp->mcast_obj; | |
8887 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
8888 | if (rc < 0) | |
8889 | BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc); | |
8890 | ||
8891 | netif_addr_unlock_bh(bp->dev); | |
8892 | ||
f1929b01 | 8893 | bnx2x_iov_chip_cleanup(bp); |
619c5cb6 | 8894 | |
6debea87 DK |
8895 | /* |
8896 | * Send the UNLOAD_REQUEST to the MCP. This will return if | |
8897 | * this function should perform FUNC, PORT or COMMON HW | |
8898 | * reset. | |
8899 | */ | |
8900 | reset_code = bnx2x_send_unload_req(bp, unload_mode); | |
8901 | ||
8902 | /* | |
8903 | * (assumption: No Attention from MCP at this stage) | |
16a5fd92 | 8904 | * PMF probably in the middle of TX disable/enable transaction |
6debea87 DK |
8905 | */ |
8906 | rc = bnx2x_func_wait_started(bp); | |
8907 | if (rc) { | |
8908 | BNX2X_ERR("bnx2x_func_wait_started failed\n"); | |
8909 | #ifdef BNX2X_STOP_ON_ERROR | |
8910 | return; | |
8911 | #endif | |
8912 | } | |
8913 | ||
34f80b04 | 8914 | /* Close multi and leading connections |
619c5cb6 VZ |
8915 | * Completions for ramrods are collected in a synchronous way |
8916 | */ | |
55c11941 | 8917 | for_each_eth_queue(bp, i) |
619c5cb6 | 8918 | if (bnx2x_stop_queue(bp, i)) |
523224a3 DK |
8919 | #ifdef BNX2X_STOP_ON_ERROR |
8920 | return; | |
8921 | #else | |
228241eb | 8922 | goto unload_error; |
523224a3 | 8923 | #endif |
55c11941 MS |
8924 | |
8925 | if (CNIC_LOADED(bp)) { | |
8926 | for_each_cnic_queue(bp, i) | |
8927 | if (bnx2x_stop_queue(bp, i)) | |
8928 | #ifdef BNX2X_STOP_ON_ERROR | |
8929 | return; | |
8930 | #else | |
8931 | goto unload_error; | |
8932 | #endif | |
8933 | } | |
8934 | ||
619c5cb6 VZ |
8935 | /* If SP settings didn't get completed so far - something |
8936 | * very wrong has happen. | |
8937 | */ | |
8938 | if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) | |
8939 | BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n"); | |
a2fbb9ea | 8940 | |
619c5cb6 VZ |
8941 | #ifndef BNX2X_STOP_ON_ERROR |
8942 | unload_error: | |
8943 | #endif | |
523224a3 | 8944 | rc = bnx2x_func_stop(bp); |
da5a662a | 8945 | if (rc) { |
523224a3 | 8946 | BNX2X_ERR("Function stop failed!\n"); |
da5a662a | 8947 | #ifdef BNX2X_STOP_ON_ERROR |
523224a3 | 8948 | return; |
523224a3 | 8949 | #endif |
34f80b04 | 8950 | } |
a2fbb9ea | 8951 | |
523224a3 DK |
8952 | /* Disable HW interrupts, NAPI */ |
8953 | bnx2x_netif_stop(bp, 1); | |
26614ba5 MS |
8954 | /* Delete all NAPI objects */ |
8955 | bnx2x_del_all_napi(bp); | |
55c11941 MS |
8956 | if (CNIC_LOADED(bp)) |
8957 | bnx2x_del_all_napi_cnic(bp); | |
523224a3 DK |
8958 | |
8959 | /* Release IRQs */ | |
d6214d7a | 8960 | bnx2x_free_irq(bp); |
523224a3 | 8961 | |
a2fbb9ea | 8962 | /* Reset the chip */ |
619c5cb6 VZ |
8963 | rc = bnx2x_reset_hw(bp, reset_code); |
8964 | if (rc) | |
8965 | BNX2X_ERR("HW_RESET failed\n"); | |
a2fbb9ea | 8966 | |
619c5cb6 | 8967 | /* Report UNLOAD_DONE to MCP */ |
5d07d868 | 8968 | bnx2x_send_unload_done(bp, keep_link); |
72fd0718 VZ |
8969 | } |
8970 | ||
9f6c9258 | 8971 | void bnx2x_disable_close_the_gate(struct bnx2x *bp) |
72fd0718 VZ |
8972 | { |
8973 | u32 val; | |
8974 | ||
51c1a580 | 8975 | DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n"); |
72fd0718 VZ |
8976 | |
8977 | if (CHIP_IS_E1(bp)) { | |
8978 | int port = BP_PORT(bp); | |
8979 | u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
8980 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
8981 | ||
8982 | val = REG_RD(bp, addr); | |
8983 | val &= ~(0x300); | |
8984 | REG_WR(bp, addr, val); | |
619c5cb6 | 8985 | } else { |
72fd0718 VZ |
8986 | val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK); |
8987 | val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | | |
8988 | MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); | |
8989 | REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val); | |
8990 | } | |
8991 | } | |
8992 | ||
72fd0718 VZ |
8993 | /* Close gates #2, #3 and #4: */ |
8994 | static void bnx2x_set_234_gates(struct bnx2x *bp, bool close) | |
8995 | { | |
c9ee9206 | 8996 | u32 val; |
72fd0718 VZ |
8997 | |
8998 | /* Gates #2 and #4a are closed/opened for "not E1" only */ | |
8999 | if (!CHIP_IS_E1(bp)) { | |
9000 | /* #4 */ | |
c9ee9206 | 9001 | REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close); |
72fd0718 | 9002 | /* #2 */ |
c9ee9206 | 9003 | REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); |
72fd0718 VZ |
9004 | } |
9005 | ||
9006 | /* #3 */ | |
c9ee9206 VZ |
9007 | if (CHIP_IS_E1x(bp)) { |
9008 | /* Prevent interrupts from HC on both ports */ | |
9009 | val = REG_RD(bp, HC_REG_CONFIG_1); | |
9010 | REG_WR(bp, HC_REG_CONFIG_1, | |
9011 | (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : | |
9012 | (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); | |
9013 | ||
9014 | val = REG_RD(bp, HC_REG_CONFIG_0); | |
9015 | REG_WR(bp, HC_REG_CONFIG_0, | |
9016 | (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : | |
9017 | (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); | |
9018 | } else { | |
d82603c6 | 9019 | /* Prevent incoming interrupts in IGU */ |
c9ee9206 VZ |
9020 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
9021 | ||
9022 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, | |
9023 | (!close) ? | |
9024 | (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : | |
9025 | (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); | |
9026 | } | |
72fd0718 | 9027 | |
51c1a580 | 9028 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n", |
72fd0718 VZ |
9029 | close ? "closing" : "opening"); |
9030 | mmiowb(); | |
9031 | } | |
9032 | ||
9033 | #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */ | |
9034 | ||
9035 | static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val) | |
9036 | { | |
9037 | /* Do some magic... */ | |
9038 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); | |
9039 | *magic_val = val & SHARED_MF_CLP_MAGIC; | |
9040 | MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); | |
9041 | } | |
9042 | ||
e8920674 DK |
9043 | /** |
9044 | * bnx2x_clp_reset_done - restore the value of the `magic' bit. | |
72fd0718 | 9045 | * |
e8920674 DK |
9046 | * @bp: driver handle |
9047 | * @magic_val: old value of the `magic' bit. | |
72fd0718 VZ |
9048 | */ |
9049 | static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val) | |
9050 | { | |
9051 | /* Restore the `magic' bit value... */ | |
72fd0718 VZ |
9052 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
9053 | MF_CFG_WR(bp, shared_mf_config.clp_mb, | |
9054 | (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); | |
9055 | } | |
9056 | ||
f85582f8 | 9057 | /** |
e8920674 | 9058 | * bnx2x_reset_mcp_prep - prepare for MCP reset. |
72fd0718 | 9059 | * |
e8920674 DK |
9060 | * @bp: driver handle |
9061 | * @magic_val: old value of 'magic' bit. | |
9062 | * | |
9063 | * Takes care of CLP configurations. | |
72fd0718 VZ |
9064 | */ |
9065 | static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val) | |
9066 | { | |
9067 | u32 shmem; | |
9068 | u32 validity_offset; | |
9069 | ||
51c1a580 | 9070 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n"); |
72fd0718 VZ |
9071 | |
9072 | /* Set `magic' bit in order to save MF config */ | |
9073 | if (!CHIP_IS_E1(bp)) | |
9074 | bnx2x_clp_reset_prep(bp, magic_val); | |
9075 | ||
9076 | /* Get shmem offset */ | |
9077 | shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
c55e771b BW |
9078 | validity_offset = |
9079 | offsetof(struct shmem_region, validity_map[BP_PORT(bp)]); | |
72fd0718 VZ |
9080 | |
9081 | /* Clear validity map flags */ | |
9082 | if (shmem > 0) | |
9083 | REG_WR(bp, shmem + validity_offset, 0); | |
9084 | } | |
9085 | ||
9086 | #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ | |
9087 | #define MCP_ONE_TIMEOUT 100 /* 100 ms */ | |
9088 | ||
e8920674 DK |
9089 | /** |
9090 | * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT | |
72fd0718 | 9091 | * |
e8920674 | 9092 | * @bp: driver handle |
72fd0718 | 9093 | */ |
1191cb83 | 9094 | static void bnx2x_mcp_wait_one(struct bnx2x *bp) |
72fd0718 VZ |
9095 | { |
9096 | /* special handling for emulation and FPGA, | |
9097 | wait 10 times longer */ | |
9098 | if (CHIP_REV_IS_SLOW(bp)) | |
9099 | msleep(MCP_ONE_TIMEOUT*10); | |
9100 | else | |
9101 | msleep(MCP_ONE_TIMEOUT); | |
9102 | } | |
9103 | ||
1b6e2ceb DK |
9104 | /* |
9105 | * initializes bp->common.shmem_base and waits for validity signature to appear | |
9106 | */ | |
9107 | static int bnx2x_init_shmem(struct bnx2x *bp) | |
72fd0718 | 9108 | { |
1b6e2ceb DK |
9109 | int cnt = 0; |
9110 | u32 val = 0; | |
72fd0718 | 9111 | |
1b6e2ceb DK |
9112 | do { |
9113 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
9114 | if (bp->common.shmem_base) { | |
9115 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); | |
9116 | if (val & SHR_MEM_VALIDITY_MB) | |
9117 | return 0; | |
9118 | } | |
72fd0718 | 9119 | |
1b6e2ceb | 9120 | bnx2x_mcp_wait_one(bp); |
72fd0718 | 9121 | |
1b6e2ceb | 9122 | } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); |
72fd0718 | 9123 | |
1b6e2ceb | 9124 | BNX2X_ERR("BAD MCP validity signature\n"); |
72fd0718 | 9125 | |
1b6e2ceb DK |
9126 | return -ENODEV; |
9127 | } | |
72fd0718 | 9128 | |
1b6e2ceb DK |
9129 | static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val) |
9130 | { | |
9131 | int rc = bnx2x_init_shmem(bp); | |
72fd0718 | 9132 | |
72fd0718 VZ |
9133 | /* Restore the `magic' bit value */ |
9134 | if (!CHIP_IS_E1(bp)) | |
9135 | bnx2x_clp_reset_done(bp, magic_val); | |
9136 | ||
9137 | return rc; | |
9138 | } | |
9139 | ||
9140 | static void bnx2x_pxp_prep(struct bnx2x *bp) | |
9141 | { | |
9142 | if (!CHIP_IS_E1(bp)) { | |
9143 | REG_WR(bp, PXP2_REG_RD_START_INIT, 0); | |
9144 | REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0); | |
72fd0718 VZ |
9145 | mmiowb(); |
9146 | } | |
9147 | } | |
9148 | ||
9149 | /* | |
9150 | * Reset the whole chip except for: | |
9151 | * - PCIE core | |
9152 | * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by | |
9153 | * one reset bit) | |
9154 | * - IGU | |
9155 | * - MISC (including AEU) | |
9156 | * - GRC | |
9157 | * - RBCN, RBCP | |
9158 | */ | |
c9ee9206 | 9159 | static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global) |
72fd0718 VZ |
9160 | { |
9161 | u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; | |
8736c826 | 9162 | u32 global_bits2, stay_reset2; |
c9ee9206 VZ |
9163 | |
9164 | /* | |
9165 | * Bits that have to be set in reset_mask2 if we want to reset 'global' | |
9166 | * (per chip) blocks. | |
9167 | */ | |
9168 | global_bits2 = | |
9169 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | | |
9170 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; | |
72fd0718 | 9171 | |
c55e771b BW |
9172 | /* Don't reset the following blocks. |
9173 | * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be | |
9174 | * reset, as in 4 port device they might still be owned | |
9175 | * by the MCP (there is only one leader per path). | |
9176 | */ | |
72fd0718 VZ |
9177 | not_reset_mask1 = |
9178 | MISC_REGISTERS_RESET_REG_1_RST_HC | | |
9179 | MISC_REGISTERS_RESET_REG_1_RST_PXPV | | |
9180 | MISC_REGISTERS_RESET_REG_1_RST_PXP; | |
9181 | ||
9182 | not_reset_mask2 = | |
c9ee9206 | 9183 | MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | |
72fd0718 VZ |
9184 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | |
9185 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | | |
9186 | MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | | |
9187 | MISC_REGISTERS_RESET_REG_2_RST_RBCN | | |
9188 | MISC_REGISTERS_RESET_REG_2_RST_GRC | | |
9189 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | | |
8736c826 VZ |
9190 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B | |
9191 | MISC_REGISTERS_RESET_REG_2_RST_ATC | | |
c55e771b BW |
9192 | MISC_REGISTERS_RESET_REG_2_PGLC | |
9193 | MISC_REGISTERS_RESET_REG_2_RST_BMAC0 | | |
9194 | MISC_REGISTERS_RESET_REG_2_RST_BMAC1 | | |
9195 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0 | | |
9196 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1 | | |
9197 | MISC_REGISTERS_RESET_REG_2_UMAC0 | | |
9198 | MISC_REGISTERS_RESET_REG_2_UMAC1; | |
72fd0718 | 9199 | |
8736c826 VZ |
9200 | /* |
9201 | * Keep the following blocks in reset: | |
9202 | * - all xxMACs are handled by the bnx2x_link code. | |
9203 | */ | |
9204 | stay_reset2 = | |
8736c826 VZ |
9205 | MISC_REGISTERS_RESET_REG_2_XMAC | |
9206 | MISC_REGISTERS_RESET_REG_2_XMAC_SOFT; | |
9207 | ||
9208 | /* Full reset masks according to the chip */ | |
72fd0718 VZ |
9209 | reset_mask1 = 0xffffffff; |
9210 | ||
9211 | if (CHIP_IS_E1(bp)) | |
9212 | reset_mask2 = 0xffff; | |
8736c826 | 9213 | else if (CHIP_IS_E1H(bp)) |
72fd0718 | 9214 | reset_mask2 = 0x1ffff; |
8736c826 VZ |
9215 | else if (CHIP_IS_E2(bp)) |
9216 | reset_mask2 = 0xfffff; | |
9217 | else /* CHIP_IS_E3 */ | |
9218 | reset_mask2 = 0x3ffffff; | |
c9ee9206 VZ |
9219 | |
9220 | /* Don't reset global blocks unless we need to */ | |
9221 | if (!global) | |
9222 | reset_mask2 &= ~global_bits2; | |
9223 | ||
9224 | /* | |
9225 | * In case of attention in the QM, we need to reset PXP | |
9226 | * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM | |
9227 | * because otherwise QM reset would release 'close the gates' shortly | |
9228 | * before resetting the PXP, then the PSWRQ would send a write | |
9229 | * request to PGLUE. Then when PXP is reset, PGLUE would try to | |
9230 | * read the payload data from PSWWR, but PSWWR would not | |
9231 | * respond. The write queue in PGLUE would stuck, dmae commands | |
9232 | * would not return. Therefore it's important to reset the second | |
9233 | * reset register (containing the | |
9234 | * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the | |
9235 | * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM | |
9236 | * bit). | |
9237 | */ | |
72fd0718 VZ |
9238 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
9239 | reset_mask2 & (~not_reset_mask2)); | |
9240 | ||
c9ee9206 VZ |
9241 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
9242 | reset_mask1 & (~not_reset_mask1)); | |
9243 | ||
72fd0718 VZ |
9244 | barrier(); |
9245 | mmiowb(); | |
9246 | ||
8736c826 VZ |
9247 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, |
9248 | reset_mask2 & (~stay_reset2)); | |
9249 | ||
9250 | barrier(); | |
9251 | mmiowb(); | |
9252 | ||
c9ee9206 | 9253 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1); |
72fd0718 VZ |
9254 | mmiowb(); |
9255 | } | |
9256 | ||
c9ee9206 VZ |
9257 | /** |
9258 | * bnx2x_er_poll_igu_vq - poll for pending writes bit. | |
9259 | * It should get cleared in no more than 1s. | |
9260 | * | |
9261 | * @bp: driver handle | |
9262 | * | |
9263 | * It should get cleared in no more than 1s. Returns 0 if | |
9264 | * pending writes bit gets cleared. | |
9265 | */ | |
9266 | static int bnx2x_er_poll_igu_vq(struct bnx2x *bp) | |
9267 | { | |
9268 | u32 cnt = 1000; | |
9269 | u32 pend_bits = 0; | |
9270 | ||
9271 | do { | |
9272 | pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS); | |
9273 | ||
9274 | if (pend_bits == 0) | |
9275 | break; | |
9276 | ||
0926d499 | 9277 | usleep_range(1000, 2000); |
c9ee9206 VZ |
9278 | } while (cnt-- > 0); |
9279 | ||
9280 | if (cnt <= 0) { | |
9281 | BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n", | |
9282 | pend_bits); | |
9283 | return -EBUSY; | |
9284 | } | |
9285 | ||
9286 | return 0; | |
9287 | } | |
9288 | ||
9289 | static int bnx2x_process_kill(struct bnx2x *bp, bool global) | |
72fd0718 VZ |
9290 | { |
9291 | int cnt = 1000; | |
9292 | u32 val = 0; | |
9293 | u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; | |
2de67439 | 9294 | u32 tags_63_32 = 0; |
72fd0718 VZ |
9295 | |
9296 | /* Empty the Tetris buffer, wait for 1s */ | |
9297 | do { | |
9298 | sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT); | |
9299 | blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT); | |
9300 | port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0); | |
9301 | port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1); | |
9302 | pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2); | |
c55e771b BW |
9303 | if (CHIP_IS_E3(bp)) |
9304 | tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32); | |
9305 | ||
72fd0718 VZ |
9306 | if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && |
9307 | ((port_is_idle_0 & 0x1) == 0x1) && | |
9308 | ((port_is_idle_1 & 0x1) == 0x1) && | |
c55e771b BW |
9309 | (pgl_exp_rom2 == 0xffffffff) && |
9310 | (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff))) | |
72fd0718 | 9311 | break; |
0926d499 | 9312 | usleep_range(1000, 2000); |
72fd0718 VZ |
9313 | } while (cnt-- > 0); |
9314 | ||
9315 | if (cnt <= 0) { | |
51c1a580 MS |
9316 | BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n"); |
9317 | 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 |
9318 | sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, |
9319 | pgl_exp_rom2); | |
9320 | return -EAGAIN; | |
9321 | } | |
9322 | ||
9323 | barrier(); | |
9324 | ||
9325 | /* Close gates #2, #3 and #4 */ | |
9326 | bnx2x_set_234_gates(bp, true); | |
9327 | ||
c9ee9206 VZ |
9328 | /* Poll for IGU VQs for 57712 and newer chips */ |
9329 | if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp)) | |
9330 | return -EAGAIN; | |
9331 | ||
72fd0718 VZ |
9332 | /* TBD: Indicate that "process kill" is in progress to MCP */ |
9333 | ||
9334 | /* Clear "unprepared" bit */ | |
9335 | REG_WR(bp, MISC_REG_UNPREPARED, 0); | |
9336 | barrier(); | |
9337 | ||
9338 | /* Make sure all is written to the chip before the reset */ | |
9339 | mmiowb(); | |
9340 | ||
9341 | /* Wait for 1ms to empty GLUE and PCI-E core queues, | |
9342 | * PSWHST, GRC and PSWRD Tetris buffer. | |
9343 | */ | |
0926d499 | 9344 | usleep_range(1000, 2000); |
72fd0718 VZ |
9345 | |
9346 | /* Prepare to chip reset: */ | |
9347 | /* MCP */ | |
c9ee9206 VZ |
9348 | if (global) |
9349 | bnx2x_reset_mcp_prep(bp, &val); | |
72fd0718 VZ |
9350 | |
9351 | /* PXP */ | |
9352 | bnx2x_pxp_prep(bp); | |
9353 | barrier(); | |
9354 | ||
9355 | /* reset the chip */ | |
c9ee9206 | 9356 | bnx2x_process_kill_chip_reset(bp, global); |
72fd0718 VZ |
9357 | barrier(); |
9358 | ||
9dcd9acd DK |
9359 | /* clear errors in PGB */ |
9360 | if (!CHIP_IS_E1x(bp)) | |
9361 | REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f); | |
9362 | ||
72fd0718 VZ |
9363 | /* Recover after reset: */ |
9364 | /* MCP */ | |
c9ee9206 | 9365 | if (global && bnx2x_reset_mcp_comp(bp, val)) |
72fd0718 VZ |
9366 | return -EAGAIN; |
9367 | ||
c9ee9206 VZ |
9368 | /* TBD: Add resetting the NO_MCP mode DB here */ |
9369 | ||
72fd0718 VZ |
9370 | /* Open the gates #2, #3 and #4 */ |
9371 | bnx2x_set_234_gates(bp, false); | |
9372 | ||
9373 | /* TBD: IGU/AEU preparation bring back the AEU/IGU to a | |
9374 | * reset state, re-enable attentions. */ | |
9375 | ||
a2fbb9ea ET |
9376 | return 0; |
9377 | } | |
9378 | ||
910cc727 | 9379 | static int bnx2x_leader_reset(struct bnx2x *bp) |
72fd0718 VZ |
9380 | { |
9381 | int rc = 0; | |
c9ee9206 | 9382 | bool global = bnx2x_reset_is_global(bp); |
95c6c616 AE |
9383 | u32 load_code; |
9384 | ||
9385 | /* if not going to reset MCP - load "fake" driver to reset HW while | |
9386 | * driver is owner of the HW | |
9387 | */ | |
9388 | if (!global && !BP_NOMCP(bp)) { | |
5d07d868 YM |
9389 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, |
9390 | DRV_MSG_CODE_LOAD_REQ_WITH_LFA); | |
95c6c616 AE |
9391 | if (!load_code) { |
9392 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9393 | rc = -EAGAIN; | |
9394 | goto exit_leader_reset; | |
9395 | } | |
9396 | if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) && | |
9397 | (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) { | |
9398 | BNX2X_ERR("MCP unexpected resp, aborting\n"); | |
9399 | rc = -EAGAIN; | |
9400 | goto exit_leader_reset2; | |
9401 | } | |
9402 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0); | |
9403 | if (!load_code) { | |
9404 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9405 | rc = -EAGAIN; | |
9406 | goto exit_leader_reset2; | |
9407 | } | |
9408 | } | |
c9ee9206 | 9409 | |
72fd0718 | 9410 | /* Try to recover after the failure */ |
c9ee9206 | 9411 | if (bnx2x_process_kill(bp, global)) { |
51c1a580 MS |
9412 | BNX2X_ERR("Something bad had happen on engine %d! Aii!\n", |
9413 | BP_PATH(bp)); | |
72fd0718 | 9414 | rc = -EAGAIN; |
95c6c616 | 9415 | goto exit_leader_reset2; |
72fd0718 VZ |
9416 | } |
9417 | ||
c9ee9206 VZ |
9418 | /* |
9419 | * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver | |
9420 | * state. | |
9421 | */ | |
72fd0718 | 9422 | bnx2x_set_reset_done(bp); |
c9ee9206 VZ |
9423 | if (global) |
9424 | bnx2x_clear_reset_global(bp); | |
72fd0718 | 9425 | |
95c6c616 AE |
9426 | exit_leader_reset2: |
9427 | /* unload "fake driver" if it was loaded */ | |
9428 | if (!global && !BP_NOMCP(bp)) { | |
9429 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0); | |
9430 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); | |
9431 | } | |
72fd0718 VZ |
9432 | exit_leader_reset: |
9433 | bp->is_leader = 0; | |
c9ee9206 VZ |
9434 | bnx2x_release_leader_lock(bp); |
9435 | smp_mb(); | |
72fd0718 VZ |
9436 | return rc; |
9437 | } | |
9438 | ||
1191cb83 | 9439 | static void bnx2x_recovery_failed(struct bnx2x *bp) |
c9ee9206 VZ |
9440 | { |
9441 | netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n"); | |
9442 | ||
9443 | /* Disconnect this device */ | |
9444 | netif_device_detach(bp->dev); | |
9445 | ||
9446 | /* | |
9447 | * Block ifup for all function on this engine until "process kill" | |
9448 | * or power cycle. | |
9449 | */ | |
9450 | bnx2x_set_reset_in_progress(bp); | |
9451 | ||
9452 | /* Shut down the power */ | |
9453 | bnx2x_set_power_state(bp, PCI_D3hot); | |
9454 | ||
9455 | bp->recovery_state = BNX2X_RECOVERY_FAILED; | |
9456 | ||
9457 | smp_mb(); | |
9458 | } | |
9459 | ||
9460 | /* | |
9461 | * Assumption: runs under rtnl lock. This together with the fact | |
6383c0b3 | 9462 | * that it's called only from bnx2x_sp_rtnl() ensure that it |
72fd0718 VZ |
9463 | * will never be called when netif_running(bp->dev) is false. |
9464 | */ | |
9465 | static void bnx2x_parity_recover(struct bnx2x *bp) | |
9466 | { | |
c9ee9206 | 9467 | bool global = false; |
7a752993 | 9468 | u32 error_recovered, error_unrecovered; |
95c6c616 | 9469 | bool is_parity; |
c9ee9206 | 9470 | |
72fd0718 VZ |
9471 | DP(NETIF_MSG_HW, "Handling parity\n"); |
9472 | while (1) { | |
9473 | switch (bp->recovery_state) { | |
9474 | case BNX2X_RECOVERY_INIT: | |
9475 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n"); | |
95c6c616 AE |
9476 | is_parity = bnx2x_chk_parity_attn(bp, &global, false); |
9477 | WARN_ON(!is_parity); | |
c9ee9206 | 9478 | |
72fd0718 | 9479 | /* Try to get a LEADER_LOCK HW lock */ |
c9ee9206 VZ |
9480 | if (bnx2x_trylock_leader_lock(bp)) { |
9481 | bnx2x_set_reset_in_progress(bp); | |
9482 | /* | |
9483 | * Check if there is a global attention and if | |
9484 | * there was a global attention, set the global | |
9485 | * reset bit. | |
9486 | */ | |
9487 | ||
9488 | if (global) | |
9489 | bnx2x_set_reset_global(bp); | |
9490 | ||
72fd0718 | 9491 | bp->is_leader = 1; |
c9ee9206 | 9492 | } |
72fd0718 VZ |
9493 | |
9494 | /* Stop the driver */ | |
9495 | /* If interface has been removed - break */ | |
5d07d868 | 9496 | if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false)) |
72fd0718 VZ |
9497 | return; |
9498 | ||
9499 | bp->recovery_state = BNX2X_RECOVERY_WAIT; | |
c9ee9206 | 9500 | |
c9ee9206 VZ |
9501 | /* Ensure "is_leader", MCP command sequence and |
9502 | * "recovery_state" update values are seen on other | |
9503 | * CPUs. | |
72fd0718 | 9504 | */ |
c9ee9206 | 9505 | smp_mb(); |
72fd0718 VZ |
9506 | break; |
9507 | ||
9508 | case BNX2X_RECOVERY_WAIT: | |
9509 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n"); | |
9510 | if (bp->is_leader) { | |
c9ee9206 | 9511 | int other_engine = BP_PATH(bp) ? 0 : 1; |
889b9af3 AE |
9512 | bool other_load_status = |
9513 | bnx2x_get_load_status(bp, other_engine); | |
9514 | bool load_status = | |
9515 | bnx2x_get_load_status(bp, BP_PATH(bp)); | |
c9ee9206 VZ |
9516 | global = bnx2x_reset_is_global(bp); |
9517 | ||
9518 | /* | |
9519 | * In case of a parity in a global block, let | |
9520 | * the first leader that performs a | |
9521 | * leader_reset() reset the global blocks in | |
9522 | * order to clear global attentions. Otherwise | |
16a5fd92 | 9523 | * the gates will remain closed for that |
c9ee9206 VZ |
9524 | * engine. |
9525 | */ | |
889b9af3 AE |
9526 | if (load_status || |
9527 | (global && other_load_status)) { | |
72fd0718 VZ |
9528 | /* Wait until all other functions get |
9529 | * down. | |
9530 | */ | |
7be08a72 | 9531 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
9532 | HZ/10); |
9533 | return; | |
9534 | } else { | |
9535 | /* If all other functions got down - | |
9536 | * try to bring the chip back to | |
9537 | * normal. In any case it's an exit | |
9538 | * point for a leader. | |
9539 | */ | |
c9ee9206 VZ |
9540 | if (bnx2x_leader_reset(bp)) { |
9541 | bnx2x_recovery_failed(bp); | |
72fd0718 VZ |
9542 | return; |
9543 | } | |
9544 | ||
c9ee9206 VZ |
9545 | /* If we are here, means that the |
9546 | * leader has succeeded and doesn't | |
9547 | * want to be a leader any more. Try | |
9548 | * to continue as a none-leader. | |
9549 | */ | |
9550 | break; | |
72fd0718 VZ |
9551 | } |
9552 | } else { /* non-leader */ | |
c9ee9206 | 9553 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) { |
72fd0718 VZ |
9554 | /* Try to get a LEADER_LOCK HW lock as |
9555 | * long as a former leader may have | |
9556 | * been unloaded by the user or | |
9557 | * released a leadership by another | |
9558 | * reason. | |
9559 | */ | |
c9ee9206 | 9560 | if (bnx2x_trylock_leader_lock(bp)) { |
72fd0718 VZ |
9561 | /* I'm a leader now! Restart a |
9562 | * switch case. | |
9563 | */ | |
9564 | bp->is_leader = 1; | |
9565 | break; | |
9566 | } | |
9567 | ||
7be08a72 | 9568 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
9569 | HZ/10); |
9570 | return; | |
9571 | ||
c9ee9206 VZ |
9572 | } else { |
9573 | /* | |
9574 | * If there was a global attention, wait | |
9575 | * for it to be cleared. | |
9576 | */ | |
9577 | if (bnx2x_reset_is_global(bp)) { | |
9578 | schedule_delayed_work( | |
7be08a72 AE |
9579 | &bp->sp_rtnl_task, |
9580 | HZ/10); | |
c9ee9206 VZ |
9581 | return; |
9582 | } | |
9583 | ||
7a752993 AE |
9584 | error_recovered = |
9585 | bp->eth_stats.recoverable_error; | |
9586 | error_unrecovered = | |
9587 | bp->eth_stats.unrecoverable_error; | |
95c6c616 AE |
9588 | bp->recovery_state = |
9589 | BNX2X_RECOVERY_NIC_LOADING; | |
9590 | if (bnx2x_nic_load(bp, LOAD_NORMAL)) { | |
7a752993 | 9591 | error_unrecovered++; |
95c6c616 | 9592 | netdev_err(bp->dev, |
51c1a580 | 9593 | "Recovery failed. Power cycle needed\n"); |
95c6c616 AE |
9594 | /* Disconnect this device */ |
9595 | netif_device_detach(bp->dev); | |
9596 | /* Shut down the power */ | |
9597 | bnx2x_set_power_state( | |
9598 | bp, PCI_D3hot); | |
9599 | smp_mb(); | |
9600 | } else { | |
c9ee9206 VZ |
9601 | bp->recovery_state = |
9602 | BNX2X_RECOVERY_DONE; | |
7a752993 | 9603 | error_recovered++; |
c9ee9206 VZ |
9604 | smp_mb(); |
9605 | } | |
7a752993 AE |
9606 | bp->eth_stats.recoverable_error = |
9607 | error_recovered; | |
9608 | bp->eth_stats.unrecoverable_error = | |
9609 | error_unrecovered; | |
c9ee9206 | 9610 | |
72fd0718 VZ |
9611 | return; |
9612 | } | |
9613 | } | |
9614 | default: | |
9615 | return; | |
9616 | } | |
9617 | } | |
9618 | } | |
9619 | ||
56ad3152 MS |
9620 | static int bnx2x_close(struct net_device *dev); |
9621 | ||
72fd0718 VZ |
9622 | /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is |
9623 | * scheduled on a general queue in order to prevent a dead lock. | |
9624 | */ | |
7be08a72 | 9625 | static void bnx2x_sp_rtnl_task(struct work_struct *work) |
34f80b04 | 9626 | { |
7be08a72 | 9627 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work); |
34f80b04 EG |
9628 | |
9629 | rtnl_lock(); | |
9630 | ||
8395be5e AE |
9631 | if (!netif_running(bp->dev)) { |
9632 | rtnl_unlock(); | |
9633 | return; | |
9634 | } | |
7be08a72 | 9635 | |
6bf07b8e | 9636 | if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) { |
7be08a72 | 9637 | #ifdef BNX2X_STOP_ON_ERROR |
6bf07b8e YM |
9638 | BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n" |
9639 | "you will need to reboot when done\n"); | |
9640 | goto sp_rtnl_not_reset; | |
7be08a72 | 9641 | #endif |
7be08a72 | 9642 | /* |
b1fb8740 VZ |
9643 | * Clear all pending SP commands as we are going to reset the |
9644 | * function anyway. | |
7be08a72 | 9645 | */ |
b1fb8740 VZ |
9646 | bp->sp_rtnl_state = 0; |
9647 | smp_mb(); | |
9648 | ||
72fd0718 | 9649 | bnx2x_parity_recover(bp); |
b1fb8740 | 9650 | |
8395be5e AE |
9651 | rtnl_unlock(); |
9652 | return; | |
b1fb8740 VZ |
9653 | } |
9654 | ||
9655 | if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) { | |
6bf07b8e YM |
9656 | #ifdef BNX2X_STOP_ON_ERROR |
9657 | BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n" | |
9658 | "you will need to reboot when done\n"); | |
9659 | goto sp_rtnl_not_reset; | |
9660 | #endif | |
9661 | ||
b1fb8740 VZ |
9662 | /* |
9663 | * Clear all pending SP commands as we are going to reset the | |
9664 | * function anyway. | |
9665 | */ | |
9666 | bp->sp_rtnl_state = 0; | |
9667 | smp_mb(); | |
9668 | ||
5d07d868 | 9669 | bnx2x_nic_unload(bp, UNLOAD_NORMAL, true); |
72fd0718 | 9670 | bnx2x_nic_load(bp, LOAD_NORMAL); |
b1fb8740 | 9671 | |
8395be5e AE |
9672 | rtnl_unlock(); |
9673 | return; | |
72fd0718 | 9674 | } |
b1fb8740 VZ |
9675 | #ifdef BNX2X_STOP_ON_ERROR |
9676 | sp_rtnl_not_reset: | |
9677 | #endif | |
9678 | if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state)) | |
9679 | bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos); | |
a3348722 BW |
9680 | if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state)) |
9681 | bnx2x_after_function_update(bp); | |
8304859a AE |
9682 | /* |
9683 | * in case of fan failure we need to reset id if the "stop on error" | |
9684 | * debug flag is set, since we trying to prevent permanent overheating | |
9685 | * damage | |
9686 | */ | |
9687 | if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) { | |
51c1a580 | 9688 | DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n"); |
8304859a AE |
9689 | netif_device_detach(bp->dev); |
9690 | bnx2x_close(bp->dev); | |
8395be5e AE |
9691 | rtnl_unlock(); |
9692 | return; | |
8304859a AE |
9693 | } |
9694 | ||
381ac16b AE |
9695 | if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) { |
9696 | DP(BNX2X_MSG_SP, | |
9697 | "sending set mcast vf pf channel message from rtnl sp-task\n"); | |
9698 | bnx2x_vfpf_set_mcast(bp->dev); | |
9699 | } | |
78c3bcc5 AE |
9700 | if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN, |
9701 | &bp->sp_rtnl_state)){ | |
9702 | if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) { | |
9703 | bnx2x_tx_disable(bp); | |
9704 | BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n"); | |
9705 | } | |
9706 | } | |
381ac16b | 9707 | |
8b09be5f YM |
9708 | if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) { |
9709 | DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n"); | |
9710 | bnx2x_set_rx_mode_inner(bp); | |
381ac16b AE |
9711 | } |
9712 | ||
3ec9f9ca AE |
9713 | if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN, |
9714 | &bp->sp_rtnl_state)) | |
9715 | bnx2x_pf_set_vfs_vlan(bp); | |
9716 | ||
6ffa39f2 | 9717 | if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) { |
07b4eb3b | 9718 | bnx2x_dcbx_stop_hw_tx(bp); |
07b4eb3b | 9719 | bnx2x_dcbx_resume_hw_tx(bp); |
6ffa39f2 | 9720 | } |
07b4eb3b | 9721 | |
8395be5e AE |
9722 | /* work which needs rtnl lock not-taken (as it takes the lock itself and |
9723 | * can be called from other contexts as well) | |
9724 | */ | |
34f80b04 | 9725 | rtnl_unlock(); |
8395be5e | 9726 | |
6411280a | 9727 | /* enable SR-IOV if applicable */ |
8395be5e | 9728 | if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, |
3c76feff AE |
9729 | &bp->sp_rtnl_state)) { |
9730 | bnx2x_disable_sriov(bp); | |
6411280a | 9731 | bnx2x_enable_sriov(bp); |
3c76feff | 9732 | } |
34f80b04 EG |
9733 | } |
9734 | ||
3deb8167 YR |
9735 | static void bnx2x_period_task(struct work_struct *work) |
9736 | { | |
9737 | struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work); | |
9738 | ||
9739 | if (!netif_running(bp->dev)) | |
9740 | goto period_task_exit; | |
9741 | ||
9742 | if (CHIP_REV_IS_SLOW(bp)) { | |
9743 | BNX2X_ERR("period task called on emulation, ignoring\n"); | |
9744 | goto period_task_exit; | |
9745 | } | |
9746 | ||
9747 | bnx2x_acquire_phy_lock(bp); | |
9748 | /* | |
9749 | * The barrier is needed to ensure the ordering between the writing to | |
9750 | * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and | |
9751 | * the reading here. | |
9752 | */ | |
9753 | smp_mb(); | |
9754 | if (bp->port.pmf) { | |
9755 | bnx2x_period_func(&bp->link_params, &bp->link_vars); | |
9756 | ||
9757 | /* Re-queue task in 1 sec */ | |
9758 | queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ); | |
9759 | } | |
9760 | ||
9761 | bnx2x_release_phy_lock(bp); | |
9762 | period_task_exit: | |
9763 | return; | |
9764 | } | |
9765 | ||
a2fbb9ea ET |
9766 | /* |
9767 | * Init service functions | |
9768 | */ | |
9769 | ||
b56e9670 | 9770 | u32 bnx2x_get_pretend_reg(struct bnx2x *bp) |
f2e0899f DK |
9771 | { |
9772 | u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; | |
9773 | u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; | |
9774 | return base + (BP_ABS_FUNC(bp)) * stride; | |
f1ef27ef EG |
9775 | } |
9776 | ||
1ef1d45a BW |
9777 | static void bnx2x_prev_unload_close_mac(struct bnx2x *bp, |
9778 | struct bnx2x_mac_vals *vals) | |
34f80b04 | 9779 | { |
452427b0 YM |
9780 | u32 val, base_addr, offset, mask, reset_reg; |
9781 | bool mac_stopped = false; | |
9782 | u8 port = BP_PORT(bp); | |
34f80b04 | 9783 | |
1ef1d45a BW |
9784 | /* reset addresses as they also mark which values were changed */ |
9785 | vals->bmac_addr = 0; | |
9786 | vals->umac_addr = 0; | |
9787 | vals->xmac_addr = 0; | |
9788 | vals->emac_addr = 0; | |
9789 | ||
452427b0 | 9790 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2); |
f16da43b | 9791 | |
452427b0 YM |
9792 | if (!CHIP_IS_E3(bp)) { |
9793 | val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4); | |
9794 | mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port; | |
9795 | if ((mask & reset_reg) && val) { | |
9796 | u32 wb_data[2]; | |
9797 | BNX2X_DEV_INFO("Disable bmac Rx\n"); | |
9798 | base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM | |
9799 | : NIG_REG_INGRESS_BMAC0_MEM; | |
9800 | offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL | |
9801 | : BIGMAC_REGISTER_BMAC_CONTROL; | |
7a06a122 | 9802 | |
452427b0 YM |
9803 | /* |
9804 | * use rd/wr since we cannot use dmae. This is safe | |
9805 | * since MCP won't access the bus due to the request | |
9806 | * to unload, and no function on the path can be | |
9807 | * loaded at this time. | |
9808 | */ | |
9809 | wb_data[0] = REG_RD(bp, base_addr + offset); | |
9810 | wb_data[1] = REG_RD(bp, base_addr + offset + 0x4); | |
1ef1d45a BW |
9811 | vals->bmac_addr = base_addr + offset; |
9812 | vals->bmac_val[0] = wb_data[0]; | |
9813 | vals->bmac_val[1] = wb_data[1]; | |
452427b0 | 9814 | wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE; |
1ef1d45a BW |
9815 | REG_WR(bp, vals->bmac_addr, wb_data[0]); |
9816 | REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]); | |
452427b0 YM |
9817 | } |
9818 | BNX2X_DEV_INFO("Disable emac Rx\n"); | |
1ef1d45a BW |
9819 | vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4; |
9820 | vals->emac_val = REG_RD(bp, vals->emac_addr); | |
9821 | REG_WR(bp, vals->emac_addr, 0); | |
452427b0 YM |
9822 | mac_stopped = true; |
9823 | } else { | |
9824 | if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) { | |
9825 | BNX2X_DEV_INFO("Disable xmac Rx\n"); | |
9826 | base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0; | |
9827 | val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI); | |
9828 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
9829 | val & ~(1 << 1)); | |
9830 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
9831 | val | (1 << 1)); | |
1ef1d45a BW |
9832 | vals->xmac_addr = base_addr + XMAC_REG_CTRL; |
9833 | vals->xmac_val = REG_RD(bp, vals->xmac_addr); | |
9834 | REG_WR(bp, vals->xmac_addr, 0); | |
452427b0 YM |
9835 | mac_stopped = true; |
9836 | } | |
9837 | mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port; | |
9838 | if (mask & reset_reg) { | |
9839 | BNX2X_DEV_INFO("Disable umac Rx\n"); | |
9840 | base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0; | |
1ef1d45a BW |
9841 | vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG; |
9842 | vals->umac_val = REG_RD(bp, vals->umac_addr); | |
9843 | REG_WR(bp, vals->umac_addr, 0); | |
452427b0 YM |
9844 | mac_stopped = true; |
9845 | } | |
9846 | } | |
9847 | ||
9848 | if (mac_stopped) | |
9849 | msleep(20); | |
452427b0 YM |
9850 | } |
9851 | ||
9852 | #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4)) | |
9853 | #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff) | |
9854 | #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff) | |
9855 | #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq)) | |
9856 | ||
91ebb929 YM |
9857 | #define BCM_5710_UNDI_FW_MF_MAJOR (0x07) |
9858 | #define BCM_5710_UNDI_FW_MF_MINOR (0x08) | |
9859 | #define BCM_5710_UNDI_FW_MF_VERS (0x05) | |
9860 | #define BNX2X_PREV_UNDI_MF_PORT(p) (0x1a150c + ((p) << 4)) | |
9861 | #define BNX2X_PREV_UNDI_MF_FUNC(f) (0x1a184c + ((f) << 4)) | |
9862 | static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp) | |
9863 | { | |
9864 | u8 major, minor, version; | |
9865 | u32 fw; | |
9866 | ||
9867 | /* Must check that FW is loaded */ | |
9868 | if (!(REG_RD(bp, MISC_REG_RESET_REG_1) & | |
9869 | MISC_REGISTERS_RESET_REG_1_RST_XSEM)) { | |
9870 | BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n"); | |
9871 | return false; | |
9872 | } | |
9873 | ||
9874 | /* Read Currently loaded FW version */ | |
9875 | fw = REG_RD(bp, XSEM_REG_PRAM); | |
9876 | major = fw & 0xff; | |
9877 | minor = (fw >> 0x8) & 0xff; | |
9878 | version = (fw >> 0x10) & 0xff; | |
9879 | BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n", | |
9880 | fw, major, minor, version); | |
9881 | ||
9882 | if (major > BCM_5710_UNDI_FW_MF_MAJOR) | |
9883 | return true; | |
9884 | ||
9885 | if ((major == BCM_5710_UNDI_FW_MF_MAJOR) && | |
9886 | (minor > BCM_5710_UNDI_FW_MF_MINOR)) | |
9887 | return true; | |
9888 | ||
9889 | if ((major == BCM_5710_UNDI_FW_MF_MAJOR) && | |
9890 | (minor == BCM_5710_UNDI_FW_MF_MINOR) && | |
9891 | (version >= BCM_5710_UNDI_FW_MF_VERS)) | |
9892 | return true; | |
9893 | ||
9894 | return false; | |
9895 | } | |
9896 | ||
9897 | static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp) | |
9898 | { | |
9899 | int i; | |
9900 | ||
9901 | /* Due to legacy (FW) code, the first function on each engine has a | |
9902 | * different offset macro from the rest of the functions. | |
9903 | * Setting this for all 8 functions is harmless regardless of whether | |
9904 | * this is actually a multi-function device. | |
9905 | */ | |
9906 | for (i = 0; i < 2; i++) | |
9907 | REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1); | |
9908 | ||
9909 | for (i = 2; i < 8; i++) | |
9910 | REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1); | |
9911 | ||
9912 | BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n"); | |
9913 | } | |
9914 | ||
1dd06ae8 | 9915 | static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc) |
452427b0 YM |
9916 | { |
9917 | u16 rcq, bd; | |
9918 | u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port)); | |
9919 | ||
9920 | rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc; | |
9921 | bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc; | |
9922 | ||
9923 | tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd); | |
9924 | REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg); | |
9925 | ||
9926 | BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n", | |
9927 | port, bd, rcq); | |
9928 | } | |
9929 | ||
0329aba1 | 9930 | static int bnx2x_prev_mcp_done(struct bnx2x *bp) |
452427b0 | 9931 | { |
5d07d868 YM |
9932 | u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, |
9933 | DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET); | |
452427b0 YM |
9934 | if (!rc) { |
9935 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9936 | return -EBUSY; | |
9937 | } | |
9938 | ||
9939 | return 0; | |
9940 | } | |
9941 | ||
c63da990 BW |
9942 | static struct bnx2x_prev_path_list * |
9943 | bnx2x_prev_path_get_entry(struct bnx2x *bp) | |
9944 | { | |
9945 | struct bnx2x_prev_path_list *tmp_list; | |
9946 | ||
9947 | list_for_each_entry(tmp_list, &bnx2x_prev_list, list) | |
9948 | if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot && | |
9949 | bp->pdev->bus->number == tmp_list->bus && | |
9950 | BP_PATH(bp) == tmp_list->path) | |
9951 | return tmp_list; | |
9952 | ||
9953 | return NULL; | |
9954 | } | |
9955 | ||
7fa6f340 YM |
9956 | static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp) |
9957 | { | |
9958 | struct bnx2x_prev_path_list *tmp_list; | |
9959 | int rc; | |
9960 | ||
9961 | rc = down_interruptible(&bnx2x_prev_sem); | |
9962 | if (rc) { | |
9963 | BNX2X_ERR("Received %d when tried to take lock\n", rc); | |
9964 | return rc; | |
9965 | } | |
9966 | ||
9967 | tmp_list = bnx2x_prev_path_get_entry(bp); | |
9968 | if (tmp_list) { | |
9969 | tmp_list->aer = 1; | |
9970 | rc = 0; | |
9971 | } else { | |
9972 | BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n", | |
9973 | BP_PATH(bp)); | |
9974 | } | |
9975 | ||
9976 | up(&bnx2x_prev_sem); | |
9977 | ||
9978 | return rc; | |
9979 | } | |
9980 | ||
0329aba1 | 9981 | static bool bnx2x_prev_is_path_marked(struct bnx2x *bp) |
452427b0 YM |
9982 | { |
9983 | struct bnx2x_prev_path_list *tmp_list; | |
b85d717c | 9984 | bool rc = false; |
452427b0 YM |
9985 | |
9986 | if (down_trylock(&bnx2x_prev_sem)) | |
9987 | return false; | |
9988 | ||
7fa6f340 YM |
9989 | tmp_list = bnx2x_prev_path_get_entry(bp); |
9990 | if (tmp_list) { | |
9991 | if (tmp_list->aer) { | |
9992 | DP(NETIF_MSG_HW, "Path %d was marked by AER\n", | |
9993 | BP_PATH(bp)); | |
9994 | } else { | |
452427b0 YM |
9995 | rc = true; |
9996 | BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n", | |
9997 | BP_PATH(bp)); | |
452427b0 YM |
9998 | } |
9999 | } | |
10000 | ||
10001 | up(&bnx2x_prev_sem); | |
10002 | ||
10003 | return rc; | |
10004 | } | |
10005 | ||
178135c1 DK |
10006 | bool bnx2x_port_after_undi(struct bnx2x *bp) |
10007 | { | |
10008 | struct bnx2x_prev_path_list *entry; | |
10009 | bool val; | |
10010 | ||
10011 | down(&bnx2x_prev_sem); | |
10012 | ||
10013 | entry = bnx2x_prev_path_get_entry(bp); | |
10014 | val = !!(entry && (entry->undi & (1 << BP_PORT(bp)))); | |
10015 | ||
10016 | up(&bnx2x_prev_sem); | |
10017 | ||
10018 | return val; | |
10019 | } | |
10020 | ||
c63da990 | 10021 | static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi) |
452427b0 YM |
10022 | { |
10023 | struct bnx2x_prev_path_list *tmp_list; | |
10024 | int rc; | |
10025 | ||
7fa6f340 YM |
10026 | rc = down_interruptible(&bnx2x_prev_sem); |
10027 | if (rc) { | |
10028 | BNX2X_ERR("Received %d when tried to take lock\n", rc); | |
10029 | return rc; | |
10030 | } | |
10031 | ||
10032 | /* Check whether the entry for this path already exists */ | |
10033 | tmp_list = bnx2x_prev_path_get_entry(bp); | |
10034 | if (tmp_list) { | |
10035 | if (!tmp_list->aer) { | |
10036 | BNX2X_ERR("Re-Marking the path.\n"); | |
10037 | } else { | |
10038 | DP(NETIF_MSG_HW, "Removing AER indication from path %d\n", | |
10039 | BP_PATH(bp)); | |
10040 | tmp_list->aer = 0; | |
10041 | } | |
10042 | up(&bnx2x_prev_sem); | |
10043 | return 0; | |
10044 | } | |
10045 | up(&bnx2x_prev_sem); | |
10046 | ||
10047 | /* Create an entry for this path and add it */ | |
ea4b3857 | 10048 | tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL); |
452427b0 YM |
10049 | if (!tmp_list) { |
10050 | BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n"); | |
10051 | return -ENOMEM; | |
10052 | } | |
10053 | ||
10054 | tmp_list->bus = bp->pdev->bus->number; | |
10055 | tmp_list->slot = PCI_SLOT(bp->pdev->devfn); | |
10056 | tmp_list->path = BP_PATH(bp); | |
7fa6f340 | 10057 | tmp_list->aer = 0; |
c63da990 | 10058 | tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0; |
452427b0 YM |
10059 | |
10060 | rc = down_interruptible(&bnx2x_prev_sem); | |
10061 | if (rc) { | |
10062 | BNX2X_ERR("Received %d when tried to take lock\n", rc); | |
10063 | kfree(tmp_list); | |
10064 | } else { | |
7fa6f340 YM |
10065 | DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n", |
10066 | BP_PATH(bp)); | |
452427b0 YM |
10067 | list_add(&tmp_list->list, &bnx2x_prev_list); |
10068 | up(&bnx2x_prev_sem); | |
10069 | } | |
10070 | ||
10071 | return rc; | |
10072 | } | |
10073 | ||
0329aba1 | 10074 | static int bnx2x_do_flr(struct bnx2x *bp) |
452427b0 | 10075 | { |
452427b0 YM |
10076 | struct pci_dev *dev = bp->pdev; |
10077 | ||
8eee694c YM |
10078 | if (CHIP_IS_E1x(bp)) { |
10079 | BNX2X_DEV_INFO("FLR not supported in E1/E1H\n"); | |
10080 | return -EINVAL; | |
10081 | } | |
10082 | ||
10083 | /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */ | |
10084 | if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) { | |
10085 | BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n", | |
10086 | bp->common.bc_ver); | |
10087 | return -EINVAL; | |
10088 | } | |
452427b0 | 10089 | |
8903b9eb CL |
10090 | if (!pci_wait_for_pending_transaction(dev)) |
10091 | dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n"); | |
452427b0 | 10092 | |
8eee694c | 10093 | BNX2X_DEV_INFO("Initiating FLR\n"); |
452427b0 YM |
10094 | bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0); |
10095 | ||
10096 | return 0; | |
10097 | } | |
10098 | ||
0329aba1 | 10099 | static int bnx2x_prev_unload_uncommon(struct bnx2x *bp) |
452427b0 YM |
10100 | { |
10101 | int rc; | |
10102 | ||
10103 | BNX2X_DEV_INFO("Uncommon unload Flow\n"); | |
10104 | ||
10105 | /* Test if previous unload process was already finished for this path */ | |
10106 | if (bnx2x_prev_is_path_marked(bp)) | |
10107 | return bnx2x_prev_mcp_done(bp); | |
10108 | ||
04c46736 YM |
10109 | BNX2X_DEV_INFO("Path is unmarked\n"); |
10110 | ||
452427b0 YM |
10111 | /* If function has FLR capabilities, and existing FW version matches |
10112 | * the one required, then FLR will be sufficient to clean any residue | |
10113 | * left by previous driver | |
10114 | */ | |
91ebb929 | 10115 | rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false); |
8eee694c YM |
10116 | |
10117 | if (!rc) { | |
10118 | /* fw version is good */ | |
10119 | BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n"); | |
10120 | rc = bnx2x_do_flr(bp); | |
10121 | } | |
10122 | ||
10123 | if (!rc) { | |
10124 | /* FLR was performed */ | |
10125 | BNX2X_DEV_INFO("FLR successful\n"); | |
10126 | return 0; | |
10127 | } | |
10128 | ||
10129 | BNX2X_DEV_INFO("Could not FLR\n"); | |
452427b0 YM |
10130 | |
10131 | /* Close the MCP request, return failure*/ | |
10132 | rc = bnx2x_prev_mcp_done(bp); | |
10133 | if (!rc) | |
10134 | rc = BNX2X_PREV_WAIT_NEEDED; | |
10135 | ||
10136 | return rc; | |
10137 | } | |
10138 | ||
0329aba1 | 10139 | static int bnx2x_prev_unload_common(struct bnx2x *bp) |
452427b0 YM |
10140 | { |
10141 | u32 reset_reg, tmp_reg = 0, rc; | |
c63da990 | 10142 | bool prev_undi = false; |
1ef1d45a BW |
10143 | struct bnx2x_mac_vals mac_vals; |
10144 | ||
452427b0 YM |
10145 | /* It is possible a previous function received 'common' answer, |
10146 | * but hasn't loaded yet, therefore creating a scenario of | |
10147 | * multiple functions receiving 'common' on the same path. | |
10148 | */ | |
10149 | BNX2X_DEV_INFO("Common unload Flow\n"); | |
10150 | ||
1ef1d45a BW |
10151 | memset(&mac_vals, 0, sizeof(mac_vals)); |
10152 | ||
452427b0 YM |
10153 | if (bnx2x_prev_is_path_marked(bp)) |
10154 | return bnx2x_prev_mcp_done(bp); | |
10155 | ||
10156 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1); | |
10157 | ||
10158 | /* Reset should be performed after BRB is emptied */ | |
10159 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) { | |
10160 | u32 timer_count = 1000; | |
452427b0 YM |
10161 | |
10162 | /* Close the MAC Rx to prevent BRB from filling up */ | |
1ef1d45a BW |
10163 | bnx2x_prev_unload_close_mac(bp, &mac_vals); |
10164 | ||
10165 | /* close LLH filters towards the BRB */ | |
10166 | bnx2x_set_rx_filter(&bp->link_params, 0); | |
452427b0 YM |
10167 | |
10168 | /* Check if the UNDI driver was previously loaded | |
34f80b04 EG |
10169 | * UNDI driver initializes CID offset for normal bell to 0x7 |
10170 | */ | |
452427b0 YM |
10171 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) { |
10172 | tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST); | |
10173 | if (tmp_reg == 0x7) { | |
10174 | BNX2X_DEV_INFO("UNDI previously loaded\n"); | |
10175 | prev_undi = true; | |
10176 | /* clear the UNDI indication */ | |
10177 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); | |
a74801c5 YM |
10178 | /* clear possible idle check errors */ |
10179 | REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0); | |
34f80b04 | 10180 | } |
452427b0 | 10181 | } |
d46f7c4d DK |
10182 | if (!CHIP_IS_E1x(bp)) |
10183 | /* block FW from writing to host */ | |
10184 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
10185 | ||
452427b0 YM |
10186 | /* wait until BRB is empty */ |
10187 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); | |
10188 | while (timer_count) { | |
10189 | u32 prev_brb = tmp_reg; | |
34f80b04 | 10190 | |
452427b0 YM |
10191 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); |
10192 | if (!tmp_reg) | |
10193 | break; | |
619c5cb6 | 10194 | |
452427b0 | 10195 | BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg); |
619c5cb6 | 10196 | |
452427b0 YM |
10197 | /* reset timer as long as BRB actually gets emptied */ |
10198 | if (prev_brb > tmp_reg) | |
10199 | timer_count = 1000; | |
10200 | else | |
10201 | timer_count--; | |
da5a662a | 10202 | |
91ebb929 YM |
10203 | /* New UNDI FW supports MF and contains better |
10204 | * cleaning methods - might be redundant but harmless. | |
10205 | */ | |
10206 | if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) { | |
10207 | bnx2x_prev_unload_undi_mf(bp); | |
10208 | } else if (prev_undi) { | |
10209 | /* If UNDI resides in memory, | |
10210 | * manually increment it | |
10211 | */ | |
452427b0 | 10212 | bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1); |
91ebb929 | 10213 | } |
452427b0 | 10214 | udelay(10); |
7a06a122 | 10215 | } |
452427b0 YM |
10216 | |
10217 | if (!timer_count) | |
10218 | BNX2X_ERR("Failed to empty BRB, hope for the best\n"); | |
34f80b04 | 10219 | } |
f16da43b | 10220 | |
452427b0 YM |
10221 | /* No packets are in the pipeline, path is ready for reset */ |
10222 | bnx2x_reset_common(bp); | |
10223 | ||
1ef1d45a BW |
10224 | if (mac_vals.xmac_addr) |
10225 | REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val); | |
10226 | if (mac_vals.umac_addr) | |
10227 | REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val); | |
10228 | if (mac_vals.emac_addr) | |
10229 | REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val); | |
10230 | if (mac_vals.bmac_addr) { | |
10231 | REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]); | |
10232 | REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]); | |
10233 | } | |
10234 | ||
c63da990 | 10235 | rc = bnx2x_prev_mark_path(bp, prev_undi); |
452427b0 YM |
10236 | if (rc) { |
10237 | bnx2x_prev_mcp_done(bp); | |
10238 | return rc; | |
10239 | } | |
10240 | ||
10241 | return bnx2x_prev_mcp_done(bp); | |
10242 | } | |
10243 | ||
24f06716 AE |
10244 | /* previous driver DMAE transaction may have occurred when pre-boot stage ended |
10245 | * and boot began, or when kdump kernel was loaded. Either case would invalidate | |
10246 | * the addresses of the transaction, resulting in was-error bit set in the pci | |
10247 | * causing all hw-to-host pcie transactions to timeout. If this happened we want | |
10248 | * to clear the interrupt which detected this from the pglueb and the was done | |
10249 | * bit | |
10250 | */ | |
0329aba1 | 10251 | static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp) |
24f06716 | 10252 | { |
4a25417c AE |
10253 | if (!CHIP_IS_E1x(bp)) { |
10254 | u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS); | |
10255 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) { | |
04c46736 YM |
10256 | DP(BNX2X_MSG_SP, |
10257 | "'was error' bit was found to be set in pglueb upon startup. Clearing\n"); | |
4a25417c AE |
10258 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, |
10259 | 1 << BP_FUNC(bp)); | |
10260 | } | |
24f06716 AE |
10261 | } |
10262 | } | |
10263 | ||
0329aba1 | 10264 | static int bnx2x_prev_unload(struct bnx2x *bp) |
452427b0 YM |
10265 | { |
10266 | int time_counter = 10; | |
10267 | u32 rc, fw, hw_lock_reg, hw_lock_val; | |
10268 | BNX2X_DEV_INFO("Entering Previous Unload Flow\n"); | |
10269 | ||
24f06716 AE |
10270 | /* clear hw from errors which may have resulted from an interrupted |
10271 | * dmae transaction. | |
10272 | */ | |
10273 | bnx2x_prev_interrupted_dmae(bp); | |
10274 | ||
10275 | /* Release previously held locks */ | |
452427b0 YM |
10276 | hw_lock_reg = (BP_FUNC(bp) <= 5) ? |
10277 | (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) : | |
10278 | (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8); | |
10279 | ||
3cdeec22 | 10280 | hw_lock_val = REG_RD(bp, hw_lock_reg); |
452427b0 YM |
10281 | if (hw_lock_val) { |
10282 | if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) { | |
10283 | BNX2X_DEV_INFO("Release Previously held NVRAM lock\n"); | |
10284 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, | |
10285 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp))); | |
10286 | } | |
10287 | ||
10288 | BNX2X_DEV_INFO("Release Previously held hw lock\n"); | |
10289 | REG_WR(bp, hw_lock_reg, 0xffffffff); | |
10290 | } else | |
10291 | BNX2X_DEV_INFO("No need to release hw/nvram locks\n"); | |
10292 | ||
10293 | if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) { | |
10294 | BNX2X_DEV_INFO("Release previously held alr\n"); | |
3cdeec22 | 10295 | bnx2x_release_alr(bp); |
452427b0 YM |
10296 | } |
10297 | ||
452427b0 | 10298 | do { |
7fa6f340 | 10299 | int aer = 0; |
452427b0 YM |
10300 | /* Lock MCP using an unload request */ |
10301 | fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0); | |
10302 | if (!fw) { | |
10303 | BNX2X_ERR("MCP response failure, aborting\n"); | |
10304 | rc = -EBUSY; | |
10305 | break; | |
10306 | } | |
10307 | ||
7fa6f340 YM |
10308 | rc = down_interruptible(&bnx2x_prev_sem); |
10309 | if (rc) { | |
10310 | BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n", | |
10311 | rc); | |
10312 | } else { | |
10313 | /* If Path is marked by EEH, ignore unload status */ | |
10314 | aer = !!(bnx2x_prev_path_get_entry(bp) && | |
10315 | bnx2x_prev_path_get_entry(bp)->aer); | |
60cde81f | 10316 | up(&bnx2x_prev_sem); |
7fa6f340 | 10317 | } |
7fa6f340 YM |
10318 | |
10319 | if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) { | |
452427b0 YM |
10320 | rc = bnx2x_prev_unload_common(bp); |
10321 | break; | |
10322 | } | |
10323 | ||
16a5fd92 | 10324 | /* non-common reply from MCP might require looping */ |
452427b0 YM |
10325 | rc = bnx2x_prev_unload_uncommon(bp); |
10326 | if (rc != BNX2X_PREV_WAIT_NEEDED) | |
10327 | break; | |
10328 | ||
10329 | msleep(20); | |
10330 | } while (--time_counter); | |
10331 | ||
10332 | if (!time_counter || rc) { | |
91ebb929 YM |
10333 | BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n"); |
10334 | rc = -EPROBE_DEFER; | |
452427b0 YM |
10335 | } |
10336 | ||
c63da990 | 10337 | /* Mark function if its port was used to boot from SAN */ |
178135c1 | 10338 | if (bnx2x_port_after_undi(bp)) |
c63da990 BW |
10339 | bp->link_params.feature_config_flags |= |
10340 | FEATURE_CONFIG_BOOT_FROM_SAN; | |
10341 | ||
452427b0 YM |
10342 | BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc); |
10343 | ||
10344 | return rc; | |
34f80b04 EG |
10345 | } |
10346 | ||
0329aba1 | 10347 | static void bnx2x_get_common_hwinfo(struct bnx2x *bp) |
34f80b04 | 10348 | { |
1d187b34 | 10349 | u32 val, val2, val3, val4, id, boot_mode; |
72ce58c3 | 10350 | u16 pmc; |
34f80b04 EG |
10351 | |
10352 | /* Get the chip revision id and number. */ | |
10353 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ | |
10354 | val = REG_RD(bp, MISC_REG_CHIP_NUM); | |
10355 | id = ((val & 0xffff) << 16); | |
10356 | val = REG_RD(bp, MISC_REG_CHIP_REV); | |
10357 | id |= ((val & 0xf) << 12); | |
f22fdf25 YM |
10358 | |
10359 | /* Metal is read from PCI regs, but we can't access >=0x400 from | |
10360 | * the configuration space (so we need to reg_rd) | |
10361 | */ | |
10362 | val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3); | |
10363 | id |= (((val >> 24) & 0xf) << 4); | |
5a40e08e | 10364 | val = REG_RD(bp, MISC_REG_BOND_ID); |
34f80b04 EG |
10365 | id |= (val & 0xf); |
10366 | bp->common.chip_id = id; | |
523224a3 | 10367 | |
7e8e02df BW |
10368 | /* force 57811 according to MISC register */ |
10369 | if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) { | |
10370 | if (CHIP_IS_57810(bp)) | |
10371 | bp->common.chip_id = (CHIP_NUM_57811 << 16) | | |
10372 | (bp->common.chip_id & 0x0000FFFF); | |
10373 | else if (CHIP_IS_57810_MF(bp)) | |
10374 | bp->common.chip_id = (CHIP_NUM_57811_MF << 16) | | |
10375 | (bp->common.chip_id & 0x0000FFFF); | |
10376 | bp->common.chip_id |= 0x1; | |
10377 | } | |
10378 | ||
523224a3 DK |
10379 | /* Set doorbell size */ |
10380 | bp->db_size = (1 << BNX2X_DB_SHIFT); | |
10381 | ||
619c5cb6 | 10382 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
10383 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR); |
10384 | if ((val & 1) == 0) | |
10385 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN); | |
10386 | else | |
10387 | val = (val >> 1) & 1; | |
10388 | BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" : | |
10389 | "2_PORT_MODE"); | |
10390 | bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE : | |
10391 | CHIP_2_PORT_MODE; | |
10392 | ||
10393 | if (CHIP_MODE_IS_4_PORT(bp)) | |
10394 | bp->pfid = (bp->pf_num >> 1); /* 0..3 */ | |
10395 | else | |
10396 | bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */ | |
10397 | } else { | |
10398 | bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */ | |
10399 | bp->pfid = bp->pf_num; /* 0..7 */ | |
10400 | } | |
10401 | ||
51c1a580 MS |
10402 | BNX2X_DEV_INFO("pf_id: %x", bp->pfid); |
10403 | ||
f2e0899f DK |
10404 | bp->link_params.chip_id = bp->common.chip_id; |
10405 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); | |
523224a3 | 10406 | |
1c06328c EG |
10407 | val = (REG_RD(bp, 0x2874) & 0x55); |
10408 | if ((bp->common.chip_id & 0x1) || | |
10409 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { | |
10410 | bp->flags |= ONE_PORT_FLAG; | |
10411 | BNX2X_DEV_INFO("single port device\n"); | |
10412 | } | |
10413 | ||
34f80b04 | 10414 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
754a2f52 | 10415 | bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE << |
34f80b04 EG |
10416 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
10417 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", | |
10418 | bp->common.flash_size, bp->common.flash_size); | |
10419 | ||
1b6e2ceb DK |
10420 | bnx2x_init_shmem(bp); |
10421 | ||
f2e0899f DK |
10422 | bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ? |
10423 | MISC_REG_GENERIC_CR_1 : | |
10424 | MISC_REG_GENERIC_CR_0)); | |
1b6e2ceb | 10425 | |
34f80b04 | 10426 | bp->link_params.shmem_base = bp->common.shmem_base; |
a22f0788 | 10427 | bp->link_params.shmem2_base = bp->common.shmem2_base; |
b884d95b YR |
10428 | if (SHMEM2_RD(bp, size) > |
10429 | (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)])) | |
10430 | bp->link_params.lfa_base = | |
10431 | REG_RD(bp, bp->common.shmem2_base + | |
10432 | (u32)offsetof(struct shmem2_region, | |
10433 | lfa_host_addr[BP_PORT(bp)])); | |
10434 | else | |
10435 | bp->link_params.lfa_base = 0; | |
2691d51d EG |
10436 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
10437 | bp->common.shmem_base, bp->common.shmem2_base); | |
34f80b04 | 10438 | |
f2e0899f | 10439 | if (!bp->common.shmem_base) { |
34f80b04 EG |
10440 | BNX2X_DEV_INFO("MCP not active\n"); |
10441 | bp->flags |= NO_MCP_FLAG; | |
10442 | return; | |
10443 | } | |
10444 | ||
34f80b04 | 10445 | bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config); |
35b19ba5 | 10446 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
34f80b04 EG |
10447 | |
10448 | bp->link_params.hw_led_mode = ((bp->common.hw_config & | |
10449 | SHARED_HW_CFG_LED_MODE_MASK) >> | |
10450 | SHARED_HW_CFG_LED_MODE_SHIFT); | |
10451 | ||
c2c8b03e EG |
10452 | bp->link_params.feature_config_flags = 0; |
10453 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); | |
10454 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) | |
10455 | bp->link_params.feature_config_flags |= | |
10456 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
10457 | else | |
10458 | bp->link_params.feature_config_flags &= | |
10459 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
10460 | ||
34f80b04 EG |
10461 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
10462 | bp->common.bc_ver = val; | |
10463 | BNX2X_DEV_INFO("bc_ver %X\n", val); | |
10464 | if (val < BNX2X_BC_VER) { | |
10465 | /* for now only warn | |
10466 | * later we might need to enforce this */ | |
51c1a580 MS |
10467 | BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n", |
10468 | BNX2X_BC_VER, val); | |
34f80b04 | 10469 | } |
4d295db0 | 10470 | bp->link_params.feature_config_flags |= |
a22f0788 | 10471 | (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ? |
f85582f8 DK |
10472 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
10473 | ||
a22f0788 YR |
10474 | bp->link_params.feature_config_flags |= |
10475 | (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ? | |
10476 | FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0; | |
a3348722 BW |
10477 | bp->link_params.feature_config_flags |= |
10478 | (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ? | |
10479 | FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0; | |
85242eea YR |
10480 | bp->link_params.feature_config_flags |= |
10481 | (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ? | |
10482 | FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0; | |
55386fe8 YR |
10483 | |
10484 | bp->link_params.feature_config_flags |= | |
10485 | (val >= REQ_BC_VER_4_MT_SUPPORTED) ? | |
10486 | FEATURE_CONFIG_MT_SUPPORT : 0; | |
10487 | ||
0e898dd7 BW |
10488 | bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ? |
10489 | BC_SUPPORTS_PFC_STATS : 0; | |
85242eea | 10490 | |
2e499d3c BW |
10491 | bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ? |
10492 | BC_SUPPORTS_FCOE_FEATURES : 0; | |
10493 | ||
9876879f BW |
10494 | bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ? |
10495 | BC_SUPPORTS_DCBX_MSG_NON_PMF : 0; | |
a6d3a5ba BW |
10496 | |
10497 | bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ? | |
10498 | BC_SUPPORTS_RMMOD_CMD : 0; | |
10499 | ||
1d187b34 BW |
10500 | boot_mode = SHMEM_RD(bp, |
10501 | dev_info.port_feature_config[BP_PORT(bp)].mba_config) & | |
10502 | PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK; | |
10503 | switch (boot_mode) { | |
10504 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE: | |
10505 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE; | |
10506 | break; | |
10507 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB: | |
10508 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI; | |
10509 | break; | |
10510 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT: | |
10511 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE; | |
10512 | break; | |
10513 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE: | |
10514 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE; | |
10515 | break; | |
10516 | } | |
10517 | ||
29ed74c3 | 10518 | pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc); |
f9a3ebbe DK |
10519 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
10520 | ||
72ce58c3 | 10521 | BNX2X_DEV_INFO("%sWoL capable\n", |
f5372251 | 10522 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
34f80b04 EG |
10523 | |
10524 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); | |
10525 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); | |
10526 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); | |
10527 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); | |
10528 | ||
cdaa7cb8 VZ |
10529 | dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n", |
10530 | val, val2, val3, val4); | |
34f80b04 EG |
10531 | } |
10532 | ||
f2e0899f DK |
10533 | #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) |
10534 | #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) | |
10535 | ||
0329aba1 | 10536 | static int bnx2x_get_igu_cam_info(struct bnx2x *bp) |
f2e0899f DK |
10537 | { |
10538 | int pfid = BP_FUNC(bp); | |
f2e0899f DK |
10539 | int igu_sb_id; |
10540 | u32 val; | |
6383c0b3 | 10541 | u8 fid, igu_sb_cnt = 0; |
f2e0899f DK |
10542 | |
10543 | bp->igu_base_sb = 0xff; | |
f2e0899f | 10544 | if (CHIP_INT_MODE_IS_BC(bp)) { |
3395a033 | 10545 | int vn = BP_VN(bp); |
6383c0b3 | 10546 | igu_sb_cnt = bp->igu_sb_cnt; |
f2e0899f DK |
10547 | bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) * |
10548 | FP_SB_MAX_E1x; | |
10549 | ||
10550 | bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x + | |
10551 | (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn); | |
10552 | ||
9b341bb1 | 10553 | return 0; |
f2e0899f DK |
10554 | } |
10555 | ||
10556 | /* IGU in normal mode - read CAM */ | |
10557 | for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; | |
10558 | igu_sb_id++) { | |
10559 | val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); | |
10560 | if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) | |
10561 | continue; | |
10562 | fid = IGU_FID(val); | |
10563 | if ((fid & IGU_FID_ENCODE_IS_PF)) { | |
10564 | if ((fid & IGU_FID_PF_NUM_MASK) != pfid) | |
10565 | continue; | |
10566 | if (IGU_VEC(val) == 0) | |
10567 | /* default status block */ | |
10568 | bp->igu_dsb_id = igu_sb_id; | |
10569 | else { | |
10570 | if (bp->igu_base_sb == 0xff) | |
10571 | bp->igu_base_sb = igu_sb_id; | |
6383c0b3 | 10572 | igu_sb_cnt++; |
f2e0899f DK |
10573 | } |
10574 | } | |
10575 | } | |
619c5cb6 | 10576 | |
6383c0b3 | 10577 | #ifdef CONFIG_PCI_MSI |
185d4c8b AE |
10578 | /* Due to new PF resource allocation by MFW T7.4 and above, it's |
10579 | * optional that number of CAM entries will not be equal to the value | |
10580 | * advertised in PCI. | |
10581 | * Driver should use the minimal value of both as the actual status | |
10582 | * block count | |
619c5cb6 | 10583 | */ |
185d4c8b | 10584 | bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt); |
6383c0b3 | 10585 | #endif |
619c5cb6 | 10586 | |
9b341bb1 | 10587 | if (igu_sb_cnt == 0) { |
f2e0899f | 10588 | BNX2X_ERR("CAM configuration error\n"); |
9b341bb1 BW |
10589 | return -EINVAL; |
10590 | } | |
10591 | ||
10592 | return 0; | |
f2e0899f DK |
10593 | } |
10594 | ||
1dd06ae8 | 10595 | static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg) |
a2fbb9ea | 10596 | { |
a22f0788 YR |
10597 | int cfg_size = 0, idx, port = BP_PORT(bp); |
10598 | ||
10599 | /* Aggregation of supported attributes of all external phys */ | |
10600 | bp->port.supported[0] = 0; | |
10601 | bp->port.supported[1] = 0; | |
b7737c9b YR |
10602 | switch (bp->link_params.num_phys) { |
10603 | case 1: | |
a22f0788 YR |
10604 | bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported; |
10605 | cfg_size = 1; | |
10606 | break; | |
b7737c9b | 10607 | case 2: |
a22f0788 YR |
10608 | bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported; |
10609 | cfg_size = 1; | |
10610 | break; | |
10611 | case 3: | |
10612 | if (bp->link_params.multi_phy_config & | |
10613 | PORT_HW_CFG_PHY_SWAPPED_ENABLED) { | |
10614 | bp->port.supported[1] = | |
10615 | bp->link_params.phy[EXT_PHY1].supported; | |
10616 | bp->port.supported[0] = | |
10617 | bp->link_params.phy[EXT_PHY2].supported; | |
10618 | } else { | |
10619 | bp->port.supported[0] = | |
10620 | bp->link_params.phy[EXT_PHY1].supported; | |
10621 | bp->port.supported[1] = | |
10622 | bp->link_params.phy[EXT_PHY2].supported; | |
10623 | } | |
10624 | cfg_size = 2; | |
10625 | break; | |
b7737c9b | 10626 | } |
a2fbb9ea | 10627 | |
a22f0788 | 10628 | if (!(bp->port.supported[0] || bp->port.supported[1])) { |
51c1a580 | 10629 | BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n", |
b7737c9b | 10630 | SHMEM_RD(bp, |
a22f0788 YR |
10631 | dev_info.port_hw_config[port].external_phy_config), |
10632 | SHMEM_RD(bp, | |
10633 | dev_info.port_hw_config[port].external_phy_config2)); | |
a2fbb9ea | 10634 | return; |
f85582f8 | 10635 | } |
a2fbb9ea | 10636 | |
619c5cb6 VZ |
10637 | if (CHIP_IS_E3(bp)) |
10638 | bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR); | |
10639 | else { | |
10640 | switch (switch_cfg) { | |
10641 | case SWITCH_CFG_1G: | |
10642 | bp->port.phy_addr = REG_RD( | |
10643 | bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); | |
10644 | break; | |
10645 | case SWITCH_CFG_10G: | |
10646 | bp->port.phy_addr = REG_RD( | |
10647 | bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); | |
10648 | break; | |
10649 | default: | |
10650 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", | |
10651 | bp->port.link_config[0]); | |
10652 | return; | |
10653 | } | |
a2fbb9ea | 10654 | } |
619c5cb6 | 10655 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
a22f0788 YR |
10656 | /* mask what we support according to speed_cap_mask per configuration */ |
10657 | for (idx = 0; idx < cfg_size; idx++) { | |
10658 | if (!(bp->link_params.speed_cap_mask[idx] & | |
c18487ee | 10659 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
a22f0788 | 10660 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half; |
a2fbb9ea | 10661 | |
a22f0788 | 10662 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10663 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
a22f0788 | 10664 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full; |
a2fbb9ea | 10665 | |
a22f0788 | 10666 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10667 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
a22f0788 | 10668 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half; |
a2fbb9ea | 10669 | |
a22f0788 | 10670 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10671 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
a22f0788 | 10672 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full; |
a2fbb9ea | 10673 | |
a22f0788 | 10674 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10675 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
a22f0788 | 10676 | bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half | |
f85582f8 | 10677 | SUPPORTED_1000baseT_Full); |
a2fbb9ea | 10678 | |
a22f0788 | 10679 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10680 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
a22f0788 | 10681 | bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full; |
a2fbb9ea | 10682 | |
a22f0788 | 10683 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 10684 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
a22f0788 | 10685 | bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full; |
b8e0d884 YR |
10686 | |
10687 | if (!(bp->link_params.speed_cap_mask[idx] & | |
10688 | PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) | |
10689 | bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full; | |
a22f0788 | 10690 | } |
a2fbb9ea | 10691 | |
a22f0788 YR |
10692 | BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0], |
10693 | bp->port.supported[1]); | |
a2fbb9ea ET |
10694 | } |
10695 | ||
0329aba1 | 10696 | static void bnx2x_link_settings_requested(struct bnx2x *bp) |
a2fbb9ea | 10697 | { |
a22f0788 YR |
10698 | u32 link_config, idx, cfg_size = 0; |
10699 | bp->port.advertising[0] = 0; | |
10700 | bp->port.advertising[1] = 0; | |
10701 | switch (bp->link_params.num_phys) { | |
10702 | case 1: | |
10703 | case 2: | |
10704 | cfg_size = 1; | |
10705 | break; | |
10706 | case 3: | |
10707 | cfg_size = 2; | |
10708 | break; | |
10709 | } | |
10710 | for (idx = 0; idx < cfg_size; idx++) { | |
10711 | bp->link_params.req_duplex[idx] = DUPLEX_FULL; | |
10712 | link_config = bp->port.link_config[idx]; | |
10713 | switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { | |
f85582f8 | 10714 | case PORT_FEATURE_LINK_SPEED_AUTO: |
a22f0788 YR |
10715 | if (bp->port.supported[idx] & SUPPORTED_Autoneg) { |
10716 | bp->link_params.req_line_speed[idx] = | |
10717 | SPEED_AUTO_NEG; | |
10718 | bp->port.advertising[idx] |= | |
10719 | bp->port.supported[idx]; | |
10bd1f24 MY |
10720 | if (bp->link_params.phy[EXT_PHY1].type == |
10721 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) | |
10722 | bp->port.advertising[idx] |= | |
10723 | (SUPPORTED_100baseT_Half | | |
10724 | SUPPORTED_100baseT_Full); | |
f85582f8 DK |
10725 | } else { |
10726 | /* force 10G, no AN */ | |
a22f0788 YR |
10727 | bp->link_params.req_line_speed[idx] = |
10728 | SPEED_10000; | |
10729 | bp->port.advertising[idx] |= | |
10730 | (ADVERTISED_10000baseT_Full | | |
f85582f8 | 10731 | ADVERTISED_FIBRE); |
a22f0788 | 10732 | continue; |
f85582f8 DK |
10733 | } |
10734 | break; | |
a2fbb9ea | 10735 | |
f85582f8 | 10736 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
a22f0788 YR |
10737 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) { |
10738 | bp->link_params.req_line_speed[idx] = | |
10739 | SPEED_10; | |
10740 | bp->port.advertising[idx] |= | |
10741 | (ADVERTISED_10baseT_Full | | |
f85582f8 DK |
10742 | ADVERTISED_TP); |
10743 | } else { | |
51c1a580 | 10744 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 | 10745 | link_config, |
a22f0788 | 10746 | bp->link_params.speed_cap_mask[idx]); |
f85582f8 DK |
10747 | return; |
10748 | } | |
10749 | break; | |
a2fbb9ea | 10750 | |
f85582f8 | 10751 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
a22f0788 YR |
10752 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) { |
10753 | bp->link_params.req_line_speed[idx] = | |
10754 | SPEED_10; | |
10755 | bp->link_params.req_duplex[idx] = | |
10756 | DUPLEX_HALF; | |
10757 | bp->port.advertising[idx] |= | |
10758 | (ADVERTISED_10baseT_Half | | |
f85582f8 DK |
10759 | ADVERTISED_TP); |
10760 | } else { | |
51c1a580 | 10761 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
10762 | link_config, |
10763 | bp->link_params.speed_cap_mask[idx]); | |
10764 | return; | |
10765 | } | |
10766 | break; | |
a2fbb9ea | 10767 | |
f85582f8 DK |
10768 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
10769 | if (bp->port.supported[idx] & | |
10770 | SUPPORTED_100baseT_Full) { | |
a22f0788 YR |
10771 | bp->link_params.req_line_speed[idx] = |
10772 | SPEED_100; | |
10773 | bp->port.advertising[idx] |= | |
10774 | (ADVERTISED_100baseT_Full | | |
f85582f8 DK |
10775 | ADVERTISED_TP); |
10776 | } else { | |
51c1a580 | 10777 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
10778 | link_config, |
10779 | bp->link_params.speed_cap_mask[idx]); | |
10780 | return; | |
10781 | } | |
10782 | break; | |
a2fbb9ea | 10783 | |
f85582f8 DK |
10784 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
10785 | if (bp->port.supported[idx] & | |
10786 | SUPPORTED_100baseT_Half) { | |
10787 | bp->link_params.req_line_speed[idx] = | |
10788 | SPEED_100; | |
10789 | bp->link_params.req_duplex[idx] = | |
10790 | DUPLEX_HALF; | |
a22f0788 YR |
10791 | bp->port.advertising[idx] |= |
10792 | (ADVERTISED_100baseT_Half | | |
f85582f8 DK |
10793 | ADVERTISED_TP); |
10794 | } else { | |
51c1a580 | 10795 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
10796 | link_config, |
10797 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
10798 | return; |
10799 | } | |
10800 | break; | |
a2fbb9ea | 10801 | |
f85582f8 | 10802 | case PORT_FEATURE_LINK_SPEED_1G: |
a22f0788 YR |
10803 | if (bp->port.supported[idx] & |
10804 | SUPPORTED_1000baseT_Full) { | |
10805 | bp->link_params.req_line_speed[idx] = | |
10806 | SPEED_1000; | |
10807 | bp->port.advertising[idx] |= | |
10808 | (ADVERTISED_1000baseT_Full | | |
f85582f8 DK |
10809 | ADVERTISED_TP); |
10810 | } else { | |
51c1a580 | 10811 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
10812 | link_config, |
10813 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
10814 | return; |
10815 | } | |
10816 | break; | |
a2fbb9ea | 10817 | |
f85582f8 | 10818 | case PORT_FEATURE_LINK_SPEED_2_5G: |
a22f0788 YR |
10819 | if (bp->port.supported[idx] & |
10820 | SUPPORTED_2500baseX_Full) { | |
10821 | bp->link_params.req_line_speed[idx] = | |
10822 | SPEED_2500; | |
10823 | bp->port.advertising[idx] |= | |
10824 | (ADVERTISED_2500baseX_Full | | |
34f80b04 | 10825 | ADVERTISED_TP); |
f85582f8 | 10826 | } else { |
51c1a580 | 10827 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 10828 | link_config, |
f85582f8 DK |
10829 | bp->link_params.speed_cap_mask[idx]); |
10830 | return; | |
10831 | } | |
10832 | break; | |
a2fbb9ea | 10833 | |
f85582f8 | 10834 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
a22f0788 YR |
10835 | if (bp->port.supported[idx] & |
10836 | SUPPORTED_10000baseT_Full) { | |
10837 | bp->link_params.req_line_speed[idx] = | |
10838 | SPEED_10000; | |
10839 | bp->port.advertising[idx] |= | |
10840 | (ADVERTISED_10000baseT_Full | | |
34f80b04 | 10841 | ADVERTISED_FIBRE); |
f85582f8 | 10842 | } else { |
51c1a580 | 10843 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 10844 | link_config, |
f85582f8 DK |
10845 | bp->link_params.speed_cap_mask[idx]); |
10846 | return; | |
10847 | } | |
10848 | break; | |
3c9ada22 YR |
10849 | case PORT_FEATURE_LINK_SPEED_20G: |
10850 | bp->link_params.req_line_speed[idx] = SPEED_20000; | |
a2fbb9ea | 10851 | |
3c9ada22 | 10852 | break; |
f85582f8 | 10853 | default: |
51c1a580 | 10854 | BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n", |
754a2f52 | 10855 | link_config); |
f85582f8 DK |
10856 | bp->link_params.req_line_speed[idx] = |
10857 | SPEED_AUTO_NEG; | |
10858 | bp->port.advertising[idx] = | |
10859 | bp->port.supported[idx]; | |
10860 | break; | |
10861 | } | |
a2fbb9ea | 10862 | |
a22f0788 | 10863 | bp->link_params.req_flow_ctrl[idx] = (link_config & |
34f80b04 | 10864 | PORT_FEATURE_FLOW_CONTROL_MASK); |
cd1dfce2 YM |
10865 | if (bp->link_params.req_flow_ctrl[idx] == |
10866 | BNX2X_FLOW_CTRL_AUTO) { | |
10867 | if (!(bp->port.supported[idx] & SUPPORTED_Autoneg)) | |
10868 | bp->link_params.req_flow_ctrl[idx] = | |
10869 | BNX2X_FLOW_CTRL_NONE; | |
10870 | else | |
10871 | bnx2x_set_requested_fc(bp); | |
a22f0788 | 10872 | } |
a2fbb9ea | 10873 | |
51c1a580 | 10874 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n", |
a22f0788 YR |
10875 | bp->link_params.req_line_speed[idx], |
10876 | bp->link_params.req_duplex[idx], | |
10877 | bp->link_params.req_flow_ctrl[idx], | |
10878 | bp->port.advertising[idx]); | |
10879 | } | |
a2fbb9ea ET |
10880 | } |
10881 | ||
0329aba1 | 10882 | static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi) |
e665bfda | 10883 | { |
86564c3f YM |
10884 | __be16 mac_hi_be = cpu_to_be16(mac_hi); |
10885 | __be32 mac_lo_be = cpu_to_be32(mac_lo); | |
10886 | memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be)); | |
10887 | memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be)); | |
e665bfda MC |
10888 | } |
10889 | ||
0329aba1 | 10890 | static void bnx2x_get_port_hwinfo(struct bnx2x *bp) |
a2fbb9ea | 10891 | { |
34f80b04 | 10892 | int port = BP_PORT(bp); |
589abe3a | 10893 | u32 config; |
c8c60d88 | 10894 | u32 ext_phy_type, ext_phy_config, eee_mode; |
a2fbb9ea | 10895 | |
c18487ee | 10896 | bp->link_params.bp = bp; |
34f80b04 | 10897 | bp->link_params.port = port; |
c18487ee | 10898 | |
c18487ee | 10899 | bp->link_params.lane_config = |
a2fbb9ea | 10900 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
4d295db0 | 10901 | |
a22f0788 | 10902 | bp->link_params.speed_cap_mask[0] = |
a2fbb9ea | 10903 | SHMEM_RD(bp, |
b0261926 YR |
10904 | dev_info.port_hw_config[port].speed_capability_mask) & |
10905 | PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK; | |
a22f0788 YR |
10906 | bp->link_params.speed_cap_mask[1] = |
10907 | SHMEM_RD(bp, | |
b0261926 YR |
10908 | dev_info.port_hw_config[port].speed_capability_mask2) & |
10909 | PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK; | |
a22f0788 | 10910 | bp->port.link_config[0] = |
a2fbb9ea ET |
10911 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
10912 | ||
a22f0788 YR |
10913 | bp->port.link_config[1] = |
10914 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2); | |
c2c8b03e | 10915 | |
a22f0788 YR |
10916 | bp->link_params.multi_phy_config = |
10917 | SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config); | |
3ce2c3f9 EG |
10918 | /* If the device is capable of WoL, set the default state according |
10919 | * to the HW | |
10920 | */ | |
4d295db0 | 10921 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
3ce2c3f9 EG |
10922 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
10923 | (config & PORT_FEATURE_WOL_ENABLED)); | |
10924 | ||
4ba7699b YM |
10925 | if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) == |
10926 | PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp)) | |
10927 | bp->flags |= NO_ISCSI_FLAG; | |
10928 | if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) == | |
10929 | PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp))) | |
10930 | bp->flags |= NO_FCOE_FLAG; | |
10931 | ||
51c1a580 | 10932 | BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n", |
c18487ee | 10933 | bp->link_params.lane_config, |
a22f0788 YR |
10934 | bp->link_params.speed_cap_mask[0], |
10935 | bp->port.link_config[0]); | |
a2fbb9ea | 10936 | |
a22f0788 | 10937 | bp->link_params.switch_cfg = (bp->port.link_config[0] & |
f85582f8 | 10938 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
b7737c9b | 10939 | bnx2x_phy_probe(&bp->link_params); |
c18487ee | 10940 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
a2fbb9ea ET |
10941 | |
10942 | bnx2x_link_settings_requested(bp); | |
10943 | ||
01cd4528 EG |
10944 | /* |
10945 | * If connected directly, work with the internal PHY, otherwise, work | |
10946 | * with the external PHY | |
10947 | */ | |
b7737c9b YR |
10948 | ext_phy_config = |
10949 | SHMEM_RD(bp, | |
10950 | dev_info.port_hw_config[port].external_phy_config); | |
10951 | ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config); | |
01cd4528 | 10952 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
b7737c9b | 10953 | bp->mdio.prtad = bp->port.phy_addr; |
01cd4528 EG |
10954 | |
10955 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && | |
10956 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) | |
10957 | bp->mdio.prtad = | |
b7737c9b | 10958 | XGXS_EXT_PHY_ADDR(ext_phy_config); |
5866df6d | 10959 | |
c8c60d88 YM |
10960 | /* Configure link feature according to nvram value */ |
10961 | eee_mode = (((SHMEM_RD(bp, dev_info. | |
10962 | port_feature_config[port].eee_power_mode)) & | |
10963 | PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >> | |
10964 | PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT); | |
10965 | if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) { | |
10966 | bp->link_params.eee_mode = EEE_MODE_ADV_LPI | | |
10967 | EEE_MODE_ENABLE_LPI | | |
10968 | EEE_MODE_OUTPUT_TIME; | |
10969 | } else { | |
10970 | bp->link_params.eee_mode = 0; | |
10971 | } | |
0793f83f | 10972 | } |
01cd4528 | 10973 | |
b306f5ed | 10974 | void bnx2x_get_iscsi_info(struct bnx2x *bp) |
2ba45142 | 10975 | { |
9e62e912 | 10976 | u32 no_flags = NO_ISCSI_FLAG; |
bf61ee14 | 10977 | int port = BP_PORT(bp); |
2ba45142 | 10978 | u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
bf61ee14 | 10979 | drv_lic_key[port].max_iscsi_conn); |
2ba45142 | 10980 | |
55c11941 MS |
10981 | if (!CNIC_SUPPORT(bp)) { |
10982 | bp->flags |= no_flags; | |
10983 | return; | |
10984 | } | |
10985 | ||
b306f5ed | 10986 | /* Get the number of maximum allowed iSCSI connections */ |
2ba45142 VZ |
10987 | bp->cnic_eth_dev.max_iscsi_conn = |
10988 | (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >> | |
10989 | BNX2X_MAX_ISCSI_INIT_CONN_SHIFT; | |
10990 | ||
b306f5ed DK |
10991 | BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n", |
10992 | bp->cnic_eth_dev.max_iscsi_conn); | |
10993 | ||
10994 | /* | |
10995 | * If maximum allowed number of connections is zero - | |
10996 | * disable the feature. | |
10997 | */ | |
10998 | if (!bp->cnic_eth_dev.max_iscsi_conn) | |
9e62e912 | 10999 | bp->flags |= no_flags; |
b306f5ed DK |
11000 | } |
11001 | ||
0329aba1 | 11002 | static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func) |
9e62e912 DK |
11003 | { |
11004 | /* Port info */ | |
11005 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
11006 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper); | |
11007 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
11008 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower); | |
11009 | ||
11010 | /* Node info */ | |
11011 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
11012 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper); | |
11013 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
11014 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower); | |
11015 | } | |
86800194 DK |
11016 | |
11017 | static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp) | |
11018 | { | |
11019 | u8 count = 0; | |
11020 | ||
11021 | if (IS_MF(bp)) { | |
11022 | u8 fid; | |
11023 | ||
11024 | /* iterate over absolute function ids for this path: */ | |
11025 | for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) { | |
11026 | if (IS_MF_SD(bp)) { | |
11027 | u32 cfg = MF_CFG_RD(bp, | |
11028 | func_mf_config[fid].config); | |
11029 | ||
11030 | if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) && | |
11031 | ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) == | |
11032 | FUNC_MF_CFG_PROTOCOL_FCOE)) | |
11033 | count++; | |
11034 | } else { | |
11035 | u32 cfg = MF_CFG_RD(bp, | |
11036 | func_ext_config[fid]. | |
11037 | func_cfg); | |
11038 | ||
11039 | if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) && | |
11040 | (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)) | |
11041 | count++; | |
11042 | } | |
11043 | } | |
11044 | } else { /* SF */ | |
11045 | int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1; | |
11046 | ||
11047 | for (port = 0; port < port_cnt; port++) { | |
11048 | u32 lic = SHMEM_RD(bp, | |
11049 | drv_lic_key[port].max_fcoe_conn) ^ | |
11050 | FW_ENCODE_32BIT_PATTERN; | |
11051 | if (lic) | |
11052 | count++; | |
11053 | } | |
11054 | } | |
11055 | ||
11056 | return count; | |
11057 | } | |
11058 | ||
0329aba1 | 11059 | static void bnx2x_get_fcoe_info(struct bnx2x *bp) |
b306f5ed DK |
11060 | { |
11061 | int port = BP_PORT(bp); | |
11062 | int func = BP_ABS_FUNC(bp); | |
b306f5ed DK |
11063 | u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
11064 | drv_lic_key[port].max_fcoe_conn); | |
86800194 | 11065 | u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp); |
b306f5ed | 11066 | |
55c11941 MS |
11067 | if (!CNIC_SUPPORT(bp)) { |
11068 | bp->flags |= NO_FCOE_FLAG; | |
11069 | return; | |
11070 | } | |
11071 | ||
b306f5ed | 11072 | /* Get the number of maximum allowed FCoE connections */ |
2ba45142 VZ |
11073 | bp->cnic_eth_dev.max_fcoe_conn = |
11074 | (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >> | |
11075 | BNX2X_MAX_FCOE_INIT_CONN_SHIFT; | |
11076 | ||
0eb43b4b BPG |
11077 | /* Calculate the number of maximum allowed FCoE tasks */ |
11078 | bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE; | |
86800194 DK |
11079 | |
11080 | /* check if FCoE resources must be shared between different functions */ | |
11081 | if (num_fcoe_func) | |
11082 | bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func; | |
0eb43b4b | 11083 | |
bf61ee14 VZ |
11084 | /* Read the WWN: */ |
11085 | if (!IS_MF(bp)) { | |
11086 | /* Port info */ | |
11087 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
11088 | SHMEM_RD(bp, | |
2de67439 | 11089 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
11090 | fcoe_wwn_port_name_upper); |
11091 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
11092 | SHMEM_RD(bp, | |
2de67439 | 11093 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
11094 | fcoe_wwn_port_name_lower); |
11095 | ||
11096 | /* Node info */ | |
11097 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
11098 | SHMEM_RD(bp, | |
2de67439 | 11099 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
11100 | fcoe_wwn_node_name_upper); |
11101 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
11102 | SHMEM_RD(bp, | |
2de67439 | 11103 | dev_info.port_hw_config[port]. |
bf61ee14 VZ |
11104 | fcoe_wwn_node_name_lower); |
11105 | } else if (!IS_MF_SD(bp)) { | |
bf61ee14 VZ |
11106 | /* |
11107 | * Read the WWN info only if the FCoE feature is enabled for | |
11108 | * this function. | |
11109 | */ | |
7b5342d9 | 11110 | if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp)) |
9e62e912 DK |
11111 | bnx2x_get_ext_wwn_info(bp, func); |
11112 | ||
382e513a | 11113 | } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) { |
9e62e912 | 11114 | bnx2x_get_ext_wwn_info(bp, func); |
382e513a | 11115 | } |
bf61ee14 | 11116 | |
b306f5ed | 11117 | BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn); |
2ba45142 | 11118 | |
bf61ee14 VZ |
11119 | /* |
11120 | * If maximum allowed number of connections is zero - | |
2ba45142 VZ |
11121 | * disable the feature. |
11122 | */ | |
2ba45142 VZ |
11123 | if (!bp->cnic_eth_dev.max_fcoe_conn) |
11124 | bp->flags |= NO_FCOE_FLAG; | |
11125 | } | |
b306f5ed | 11126 | |
0329aba1 | 11127 | static void bnx2x_get_cnic_info(struct bnx2x *bp) |
b306f5ed DK |
11128 | { |
11129 | /* | |
11130 | * iSCSI may be dynamically disabled but reading | |
11131 | * info here we will decrease memory usage by driver | |
11132 | * if the feature is disabled for good | |
11133 | */ | |
11134 | bnx2x_get_iscsi_info(bp); | |
11135 | bnx2x_get_fcoe_info(bp); | |
11136 | } | |
2ba45142 | 11137 | |
0329aba1 | 11138 | static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp) |
0793f83f DK |
11139 | { |
11140 | u32 val, val2; | |
11141 | int func = BP_ABS_FUNC(bp); | |
11142 | int port = BP_PORT(bp); | |
2ba45142 VZ |
11143 | u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac; |
11144 | u8 *fip_mac = bp->fip_mac; | |
0793f83f | 11145 | |
55c11941 MS |
11146 | if (IS_MF(bp)) { |
11147 | /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or | |
2ba45142 | 11148 | * FCoE MAC then the appropriate feature should be disabled. |
55c11941 MS |
11149 | * In non SD mode features configuration comes from struct |
11150 | * func_ext_config. | |
2ba45142 | 11151 | */ |
55c11941 | 11152 | if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) { |
0793f83f DK |
11153 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); |
11154 | if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { | |
11155 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
55c11941 | 11156 | iscsi_mac_addr_upper); |
0793f83f | 11157 | val = MF_CFG_RD(bp, func_ext_config[func]. |
55c11941 | 11158 | iscsi_mac_addr_lower); |
2ba45142 | 11159 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
55c11941 MS |
11160 | BNX2X_DEV_INFO |
11161 | ("Read iSCSI MAC: %pM\n", iscsi_mac); | |
11162 | } else { | |
2ba45142 | 11163 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
55c11941 | 11164 | } |
2ba45142 VZ |
11165 | |
11166 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { | |
11167 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
55c11941 | 11168 | fcoe_mac_addr_upper); |
2ba45142 | 11169 | val = MF_CFG_RD(bp, func_ext_config[func]. |
55c11941 | 11170 | fcoe_mac_addr_lower); |
2ba45142 | 11171 | bnx2x_set_mac_buf(fip_mac, val, val2); |
55c11941 MS |
11172 | BNX2X_DEV_INFO |
11173 | ("Read FCoE L2 MAC: %pM\n", fip_mac); | |
11174 | } else { | |
2ba45142 | 11175 | bp->flags |= NO_FCOE_FLAG; |
55c11941 | 11176 | } |
a3348722 BW |
11177 | |
11178 | bp->mf_ext_config = cfg; | |
11179 | ||
9e62e912 | 11180 | } else { /* SD MODE */ |
55c11941 MS |
11181 | if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) { |
11182 | /* use primary mac as iscsi mac */ | |
11183 | memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN); | |
11184 | ||
11185 | BNX2X_DEV_INFO("SD ISCSI MODE\n"); | |
11186 | BNX2X_DEV_INFO | |
11187 | ("Read iSCSI MAC: %pM\n", iscsi_mac); | |
11188 | } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) { | |
11189 | /* use primary mac as fip mac */ | |
11190 | memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN); | |
11191 | BNX2X_DEV_INFO("SD FCoE MODE\n"); | |
11192 | BNX2X_DEV_INFO | |
11193 | ("Read FIP MAC: %pM\n", fip_mac); | |
614c76df | 11194 | } |
0793f83f | 11195 | } |
a3348722 | 11196 | |
82594f8f YM |
11197 | /* If this is a storage-only interface, use SAN mac as |
11198 | * primary MAC. Notice that for SD this is already the case, | |
11199 | * as the SAN mac was copied from the primary MAC. | |
11200 | */ | |
11201 | if (IS_MF_FCOE_AFEX(bp)) | |
a3348722 | 11202 | memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN); |
0793f83f | 11203 | } else { |
0793f83f | 11204 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 11205 | iscsi_mac_upper); |
0793f83f | 11206 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 11207 | iscsi_mac_lower); |
2ba45142 | 11208 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
c03bd39c VZ |
11209 | |
11210 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
55c11941 | 11211 | fcoe_fip_mac_upper); |
c03bd39c | 11212 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
55c11941 | 11213 | fcoe_fip_mac_lower); |
c03bd39c | 11214 | bnx2x_set_mac_buf(fip_mac, val, val2); |
0793f83f DK |
11215 | } |
11216 | ||
55c11941 | 11217 | /* Disable iSCSI OOO if MAC configuration is invalid. */ |
426b9241 | 11218 | if (!is_valid_ether_addr(iscsi_mac)) { |
55c11941 | 11219 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
426b9241 DK |
11220 | memset(iscsi_mac, 0, ETH_ALEN); |
11221 | } | |
11222 | ||
55c11941 | 11223 | /* Disable FCoE if MAC configuration is invalid. */ |
426b9241 DK |
11224 | if (!is_valid_ether_addr(fip_mac)) { |
11225 | bp->flags |= NO_FCOE_FLAG; | |
11226 | memset(bp->fip_mac, 0, ETH_ALEN); | |
11227 | } | |
55c11941 MS |
11228 | } |
11229 | ||
0329aba1 | 11230 | static void bnx2x_get_mac_hwinfo(struct bnx2x *bp) |
55c11941 MS |
11231 | { |
11232 | u32 val, val2; | |
11233 | int func = BP_ABS_FUNC(bp); | |
11234 | int port = BP_PORT(bp); | |
11235 | ||
11236 | /* Zero primary MAC configuration */ | |
11237 | memset(bp->dev->dev_addr, 0, ETH_ALEN); | |
11238 | ||
11239 | if (BP_NOMCP(bp)) { | |
11240 | BNX2X_ERROR("warning: random MAC workaround active\n"); | |
11241 | eth_hw_addr_random(bp->dev); | |
11242 | } else if (IS_MF(bp)) { | |
11243 | val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); | |
11244 | val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); | |
11245 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && | |
11246 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) | |
11247 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
11248 | ||
11249 | if (CNIC_SUPPORT(bp)) | |
11250 | bnx2x_get_cnic_mac_hwinfo(bp); | |
11251 | } else { | |
11252 | /* in SF read MACs from port configuration */ | |
11253 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); | |
11254 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); | |
11255 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
11256 | ||
11257 | if (CNIC_SUPPORT(bp)) | |
11258 | bnx2x_get_cnic_mac_hwinfo(bp); | |
11259 | } | |
11260 | ||
3d7d562c YM |
11261 | if (!BP_NOMCP(bp)) { |
11262 | /* Read physical port identifier from shmem */ | |
11263 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); | |
11264 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); | |
11265 | bnx2x_set_mac_buf(bp->phys_port_id, val, val2); | |
11266 | bp->flags |= HAS_PHYS_PORT_ID; | |
11267 | } | |
11268 | ||
55c11941 | 11269 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
619c5cb6 | 11270 | |
614c76df | 11271 | if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr)) |
619c5cb6 | 11272 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
11273 | "bad Ethernet MAC address configuration: %pM\n" |
11274 | "change it manually before bringing up the appropriate network interface\n", | |
0f9dad10 | 11275 | bp->dev->dev_addr); |
7964211d | 11276 | } |
51c1a580 | 11277 | |
0329aba1 | 11278 | static bool bnx2x_get_dropless_info(struct bnx2x *bp) |
7964211d YM |
11279 | { |
11280 | int tmp; | |
11281 | u32 cfg; | |
51c1a580 | 11282 | |
aeeddb8b YM |
11283 | if (IS_VF(bp)) |
11284 | return 0; | |
11285 | ||
7964211d YM |
11286 | if (IS_MF(bp) && !CHIP_IS_E1x(bp)) { |
11287 | /* Take function: tmp = func */ | |
11288 | tmp = BP_ABS_FUNC(bp); | |
11289 | cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg); | |
11290 | cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING); | |
11291 | } else { | |
11292 | /* Take port: tmp = port */ | |
11293 | tmp = BP_PORT(bp); | |
11294 | cfg = SHMEM_RD(bp, | |
11295 | dev_info.port_hw_config[tmp].generic_features); | |
11296 | cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED); | |
11297 | } | |
11298 | return cfg; | |
34f80b04 EG |
11299 | } |
11300 | ||
0329aba1 | 11301 | static int bnx2x_get_hwinfo(struct bnx2x *bp) |
34f80b04 | 11302 | { |
0793f83f | 11303 | int /*abs*/func = BP_ABS_FUNC(bp); |
b8ee8328 | 11304 | int vn; |
0793f83f | 11305 | u32 val = 0; |
34f80b04 | 11306 | int rc = 0; |
a2fbb9ea | 11307 | |
34f80b04 | 11308 | bnx2x_get_common_hwinfo(bp); |
a2fbb9ea | 11309 | |
6383c0b3 AE |
11310 | /* |
11311 | * initialize IGU parameters | |
11312 | */ | |
f2e0899f DK |
11313 | if (CHIP_IS_E1x(bp)) { |
11314 | bp->common.int_block = INT_BLOCK_HC; | |
11315 | ||
11316 | bp->igu_dsb_id = DEF_SB_IGU_ID; | |
11317 | bp->igu_base_sb = 0; | |
f2e0899f DK |
11318 | } else { |
11319 | bp->common.int_block = INT_BLOCK_IGU; | |
7a06a122 | 11320 | |
16a5fd92 | 11321 | /* do not allow device reset during IGU info processing */ |
7a06a122 DK |
11322 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
11323 | ||
f2e0899f | 11324 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
619c5cb6 VZ |
11325 | |
11326 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { | |
11327 | int tout = 5000; | |
11328 | ||
11329 | BNX2X_DEV_INFO("FORCING Normal Mode\n"); | |
11330 | ||
11331 | val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); | |
11332 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val); | |
11333 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f); | |
11334 | ||
11335 | while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
11336 | tout--; | |
0926d499 | 11337 | usleep_range(1000, 2000); |
619c5cb6 VZ |
11338 | } |
11339 | ||
11340 | if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
11341 | dev_err(&bp->pdev->dev, | |
11342 | "FORCING Normal Mode failed!!!\n"); | |
9b341bb1 BW |
11343 | bnx2x_release_hw_lock(bp, |
11344 | HW_LOCK_RESOURCE_RESET); | |
619c5cb6 VZ |
11345 | return -EPERM; |
11346 | } | |
11347 | } | |
11348 | ||
f2e0899f | 11349 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
619c5cb6 | 11350 | BNX2X_DEV_INFO("IGU Backward Compatible Mode\n"); |
f2e0899f DK |
11351 | bp->common.int_block |= INT_BLOCK_MODE_BW_COMP; |
11352 | } else | |
619c5cb6 | 11353 | BNX2X_DEV_INFO("IGU Normal Mode\n"); |
523224a3 | 11354 | |
9b341bb1 | 11355 | rc = bnx2x_get_igu_cam_info(bp); |
7a06a122 | 11356 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
9b341bb1 BW |
11357 | if (rc) |
11358 | return rc; | |
f2e0899f | 11359 | } |
619c5cb6 VZ |
11360 | |
11361 | /* | |
11362 | * set base FW non-default (fast path) status block id, this value is | |
11363 | * used to initialize the fw_sb_id saved on the fp/queue structure to | |
11364 | * determine the id used by the FW. | |
11365 | */ | |
11366 | if (CHIP_IS_E1x(bp)) | |
11367 | bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp); | |
11368 | else /* | |
11369 | * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of | |
11370 | * the same queue are indicated on the same IGU SB). So we prefer | |
11371 | * FW and IGU SBs to be the same value. | |
11372 | */ | |
11373 | bp->base_fw_ndsb = bp->igu_base_sb; | |
11374 | ||
11375 | BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n" | |
11376 | "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb, | |
11377 | bp->igu_sb_cnt, bp->base_fw_ndsb); | |
f2e0899f DK |
11378 | |
11379 | /* | |
11380 | * Initialize MF configuration | |
11381 | */ | |
523224a3 | 11382 | |
fb3bff17 DK |
11383 | bp->mf_ov = 0; |
11384 | bp->mf_mode = 0; | |
3395a033 | 11385 | vn = BP_VN(bp); |
0793f83f | 11386 | |
f2e0899f | 11387 | if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) { |
619c5cb6 VZ |
11388 | BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n", |
11389 | bp->common.shmem2_base, SHMEM2_RD(bp, size), | |
11390 | (u32)offsetof(struct shmem2_region, mf_cfg_addr)); | |
11391 | ||
f2e0899f DK |
11392 | if (SHMEM2_HAS(bp, mf_cfg_addr)) |
11393 | bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr); | |
11394 | else | |
11395 | bp->common.mf_cfg_base = bp->common.shmem_base + | |
523224a3 DK |
11396 | offsetof(struct shmem_region, func_mb) + |
11397 | E1H_FUNC_MAX * sizeof(struct drv_func_mb); | |
0793f83f DK |
11398 | /* |
11399 | * get mf configuration: | |
16a5fd92 | 11400 | * 1. Existence of MF configuration |
0793f83f DK |
11401 | * 2. MAC address must be legal (check only upper bytes) |
11402 | * for Switch-Independent mode; | |
11403 | * OVLAN must be legal for Switch-Dependent mode | |
11404 | * 3. SF_MODE configures specific MF mode | |
11405 | */ | |
11406 | if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
11407 | /* get mf configuration */ | |
11408 | val = SHMEM_RD(bp, | |
11409 | dev_info.shared_feature_config.config); | |
11410 | val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK; | |
11411 | ||
11412 | switch (val) { | |
11413 | case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: | |
11414 | val = MF_CFG_RD(bp, func_mf_config[func]. | |
11415 | mac_upper); | |
11416 | /* check for legal mac (upper bytes)*/ | |
11417 | if (val != 0xffff) { | |
11418 | bp->mf_mode = MULTI_FUNCTION_SI; | |
11419 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11420 | func_mf_config[func].config); | |
11421 | } else | |
51c1a580 | 11422 | BNX2X_DEV_INFO("illegal MAC address for SI\n"); |
0793f83f | 11423 | break; |
a3348722 BW |
11424 | case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE: |
11425 | if ((!CHIP_IS_E1x(bp)) && | |
11426 | (MF_CFG_RD(bp, func_mf_config[func]. | |
11427 | mac_upper) != 0xffff) && | |
11428 | (SHMEM2_HAS(bp, | |
11429 | afex_driver_support))) { | |
11430 | bp->mf_mode = MULTI_FUNCTION_AFEX; | |
11431 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11432 | func_mf_config[func].config); | |
11433 | } else { | |
11434 | BNX2X_DEV_INFO("can not configure afex mode\n"); | |
11435 | } | |
11436 | break; | |
0793f83f DK |
11437 | case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: |
11438 | /* get OV configuration */ | |
11439 | val = MF_CFG_RD(bp, | |
11440 | func_mf_config[FUNC_0].e1hov_tag); | |
11441 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; | |
11442 | ||
11443 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { | |
11444 | bp->mf_mode = MULTI_FUNCTION_SD; | |
11445 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
11446 | func_mf_config[func].config); | |
11447 | } else | |
754a2f52 | 11448 | BNX2X_DEV_INFO("illegal OV for SD\n"); |
0793f83f | 11449 | break; |
3786b942 AE |
11450 | case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF: |
11451 | bp->mf_config[vn] = 0; | |
11452 | break; | |
0793f83f DK |
11453 | default: |
11454 | /* Unknown configuration: reset mf_config */ | |
11455 | bp->mf_config[vn] = 0; | |
51c1a580 | 11456 | BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val); |
0793f83f DK |
11457 | } |
11458 | } | |
a2fbb9ea | 11459 | |
2691d51d | 11460 | BNX2X_DEV_INFO("%s function mode\n", |
fb3bff17 | 11461 | IS_MF(bp) ? "multi" : "single"); |
2691d51d | 11462 | |
0793f83f DK |
11463 | switch (bp->mf_mode) { |
11464 | case MULTI_FUNCTION_SD: | |
11465 | val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
11466 | FUNC_MF_CFG_E1HOV_TAG_MASK; | |
2691d51d | 11467 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
fb3bff17 | 11468 | bp->mf_ov = val; |
619c5cb6 VZ |
11469 | bp->path_has_ovlan = true; |
11470 | ||
51c1a580 MS |
11471 | BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n", |
11472 | func, bp->mf_ov, bp->mf_ov); | |
2691d51d | 11473 | } else { |
619c5cb6 | 11474 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
11475 | "No valid MF OV for func %d, aborting\n", |
11476 | func); | |
619c5cb6 | 11477 | return -EPERM; |
34f80b04 | 11478 | } |
0793f83f | 11479 | break; |
a3348722 BW |
11480 | case MULTI_FUNCTION_AFEX: |
11481 | BNX2X_DEV_INFO("func %d is in MF afex mode\n", func); | |
11482 | break; | |
0793f83f | 11483 | case MULTI_FUNCTION_SI: |
51c1a580 MS |
11484 | BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n", |
11485 | func); | |
0793f83f DK |
11486 | break; |
11487 | default: | |
11488 | if (vn) { | |
619c5cb6 | 11489 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
11490 | "VN %d is in a single function mode, aborting\n", |
11491 | vn); | |
619c5cb6 | 11492 | return -EPERM; |
2691d51d | 11493 | } |
0793f83f | 11494 | break; |
34f80b04 | 11495 | } |
0793f83f | 11496 | |
619c5cb6 VZ |
11497 | /* check if other port on the path needs ovlan: |
11498 | * Since MF configuration is shared between ports | |
11499 | * Possible mixed modes are only | |
11500 | * {SF, SI} {SF, SD} {SD, SF} {SI, SF} | |
11501 | */ | |
11502 | if (CHIP_MODE_IS_4_PORT(bp) && | |
11503 | !bp->path_has_ovlan && | |
11504 | !IS_MF(bp) && | |
11505 | bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
11506 | u8 other_port = !BP_PORT(bp); | |
11507 | u8 other_func = BP_PATH(bp) + 2*other_port; | |
11508 | val = MF_CFG_RD(bp, | |
11509 | func_mf_config[other_func].e1hov_tag); | |
11510 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) | |
11511 | bp->path_has_ovlan = true; | |
11512 | } | |
34f80b04 | 11513 | } |
a2fbb9ea | 11514 | |
f2e0899f DK |
11515 | /* adjust igu_sb_cnt to MF for E1x */ |
11516 | if (CHIP_IS_E1x(bp) && IS_MF(bp)) | |
523224a3 DK |
11517 | bp->igu_sb_cnt /= E1HVN_MAX; |
11518 | ||
619c5cb6 VZ |
11519 | /* port info */ |
11520 | bnx2x_get_port_hwinfo(bp); | |
f2e0899f | 11521 | |
0793f83f DK |
11522 | /* Get MAC addresses */ |
11523 | bnx2x_get_mac_hwinfo(bp); | |
a2fbb9ea | 11524 | |
2ba45142 | 11525 | bnx2x_get_cnic_info(bp); |
2ba45142 | 11526 | |
34f80b04 EG |
11527 | return rc; |
11528 | } | |
11529 | ||
0329aba1 | 11530 | static void bnx2x_read_fwinfo(struct bnx2x *bp) |
34f24c7f VZ |
11531 | { |
11532 | int cnt, i, block_end, rodi; | |
fcdf95cb | 11533 | char vpd_start[BNX2X_VPD_LEN+1]; |
34f24c7f VZ |
11534 | char str_id_reg[VENDOR_ID_LEN+1]; |
11535 | char str_id_cap[VENDOR_ID_LEN+1]; | |
fcdf95cb BW |
11536 | char *vpd_data; |
11537 | char *vpd_extended_data = NULL; | |
34f24c7f VZ |
11538 | u8 len; |
11539 | ||
fcdf95cb | 11540 | cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start); |
34f24c7f VZ |
11541 | memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); |
11542 | ||
11543 | if (cnt < BNX2X_VPD_LEN) | |
11544 | goto out_not_found; | |
11545 | ||
fcdf95cb BW |
11546 | /* VPD RO tag should be first tag after identifier string, hence |
11547 | * we should be able to find it in first BNX2X_VPD_LEN chars | |
11548 | */ | |
11549 | i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN, | |
34f24c7f VZ |
11550 | PCI_VPD_LRDT_RO_DATA); |
11551 | if (i < 0) | |
11552 | goto out_not_found; | |
11553 | ||
34f24c7f | 11554 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + |
fcdf95cb | 11555 | pci_vpd_lrdt_size(&vpd_start[i]); |
34f24c7f VZ |
11556 | |
11557 | i += PCI_VPD_LRDT_TAG_SIZE; | |
11558 | ||
fcdf95cb BW |
11559 | if (block_end > BNX2X_VPD_LEN) { |
11560 | vpd_extended_data = kmalloc(block_end, GFP_KERNEL); | |
11561 | if (vpd_extended_data == NULL) | |
11562 | goto out_not_found; | |
11563 | ||
11564 | /* read rest of vpd image into vpd_extended_data */ | |
11565 | memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN); | |
11566 | cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN, | |
11567 | block_end - BNX2X_VPD_LEN, | |
11568 | vpd_extended_data + BNX2X_VPD_LEN); | |
11569 | if (cnt < (block_end - BNX2X_VPD_LEN)) | |
11570 | goto out_not_found; | |
11571 | vpd_data = vpd_extended_data; | |
11572 | } else | |
11573 | vpd_data = vpd_start; | |
11574 | ||
11575 | /* now vpd_data holds full vpd content in both cases */ | |
34f24c7f VZ |
11576 | |
11577 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
11578 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
11579 | if (rodi < 0) | |
11580 | goto out_not_found; | |
11581 | ||
11582 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
11583 | ||
11584 | if (len != VENDOR_ID_LEN) | |
11585 | goto out_not_found; | |
11586 | ||
11587 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
11588 | ||
11589 | /* vendor specific info */ | |
11590 | snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); | |
11591 | snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); | |
11592 | if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || | |
11593 | !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { | |
11594 | ||
11595 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
11596 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
11597 | if (rodi >= 0) { | |
11598 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
11599 | ||
11600 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
11601 | ||
11602 | if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { | |
11603 | memcpy(bp->fw_ver, &vpd_data[rodi], len); | |
11604 | bp->fw_ver[len] = ' '; | |
11605 | } | |
11606 | } | |
fcdf95cb | 11607 | kfree(vpd_extended_data); |
34f24c7f VZ |
11608 | return; |
11609 | } | |
11610 | out_not_found: | |
fcdf95cb | 11611 | kfree(vpd_extended_data); |
34f24c7f VZ |
11612 | return; |
11613 | } | |
11614 | ||
0329aba1 | 11615 | static void bnx2x_set_modes_bitmap(struct bnx2x *bp) |
619c5cb6 VZ |
11616 | { |
11617 | u32 flags = 0; | |
11618 | ||
11619 | if (CHIP_REV_IS_FPGA(bp)) | |
11620 | SET_FLAGS(flags, MODE_FPGA); | |
11621 | else if (CHIP_REV_IS_EMUL(bp)) | |
11622 | SET_FLAGS(flags, MODE_EMUL); | |
11623 | else | |
11624 | SET_FLAGS(flags, MODE_ASIC); | |
11625 | ||
11626 | if (CHIP_MODE_IS_4_PORT(bp)) | |
11627 | SET_FLAGS(flags, MODE_PORT4); | |
11628 | else | |
11629 | SET_FLAGS(flags, MODE_PORT2); | |
11630 | ||
11631 | if (CHIP_IS_E2(bp)) | |
11632 | SET_FLAGS(flags, MODE_E2); | |
11633 | else if (CHIP_IS_E3(bp)) { | |
11634 | SET_FLAGS(flags, MODE_E3); | |
11635 | if (CHIP_REV(bp) == CHIP_REV_Ax) | |
11636 | SET_FLAGS(flags, MODE_E3_A0); | |
6383c0b3 AE |
11637 | else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/ |
11638 | SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3); | |
619c5cb6 VZ |
11639 | } |
11640 | ||
11641 | if (IS_MF(bp)) { | |
11642 | SET_FLAGS(flags, MODE_MF); | |
11643 | switch (bp->mf_mode) { | |
11644 | case MULTI_FUNCTION_SD: | |
11645 | SET_FLAGS(flags, MODE_MF_SD); | |
11646 | break; | |
11647 | case MULTI_FUNCTION_SI: | |
11648 | SET_FLAGS(flags, MODE_MF_SI); | |
11649 | break; | |
a3348722 BW |
11650 | case MULTI_FUNCTION_AFEX: |
11651 | SET_FLAGS(flags, MODE_MF_AFEX); | |
11652 | break; | |
619c5cb6 VZ |
11653 | } |
11654 | } else | |
11655 | SET_FLAGS(flags, MODE_SF); | |
11656 | ||
11657 | #if defined(__LITTLE_ENDIAN) | |
11658 | SET_FLAGS(flags, MODE_LITTLE_ENDIAN); | |
11659 | #else /*(__BIG_ENDIAN)*/ | |
11660 | SET_FLAGS(flags, MODE_BIG_ENDIAN); | |
11661 | #endif | |
11662 | INIT_MODE_FLAGS(bp) = flags; | |
11663 | } | |
11664 | ||
0329aba1 | 11665 | static int bnx2x_init_bp(struct bnx2x *bp) |
34f80b04 | 11666 | { |
f2e0899f | 11667 | int func; |
34f80b04 EG |
11668 | int rc; |
11669 | ||
34f80b04 | 11670 | mutex_init(&bp->port.phy_mutex); |
c4ff7cbf | 11671 | mutex_init(&bp->fw_mb_mutex); |
bb7e95c8 | 11672 | spin_lock_init(&bp->stats_lock); |
507393eb | 11673 | sema_init(&bp->stats_sema, 1); |
55c11941 | 11674 | |
1cf167f2 | 11675 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
7be08a72 | 11676 | INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task); |
3deb8167 | 11677 | INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task); |
1ab4434c AE |
11678 | if (IS_PF(bp)) { |
11679 | rc = bnx2x_get_hwinfo(bp); | |
11680 | if (rc) | |
11681 | return rc; | |
11682 | } else { | |
e09b74d0 | 11683 | eth_zero_addr(bp->dev->dev_addr); |
1ab4434c | 11684 | } |
34f80b04 | 11685 | |
619c5cb6 VZ |
11686 | bnx2x_set_modes_bitmap(bp); |
11687 | ||
11688 | rc = bnx2x_alloc_mem_bp(bp); | |
11689 | if (rc) | |
11690 | return rc; | |
523224a3 | 11691 | |
34f24c7f | 11692 | bnx2x_read_fwinfo(bp); |
f2e0899f DK |
11693 | |
11694 | func = BP_FUNC(bp); | |
11695 | ||
34f80b04 | 11696 | /* need to reset chip if undi was active */ |
1ab4434c | 11697 | if (IS_PF(bp) && !BP_NOMCP(bp)) { |
452427b0 YM |
11698 | /* init fw_seq */ |
11699 | bp->fw_seq = | |
11700 | SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & | |
11701 | DRV_MSG_SEQ_NUMBER_MASK; | |
11702 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); | |
11703 | ||
91ebb929 YM |
11704 | rc = bnx2x_prev_unload(bp); |
11705 | if (rc) { | |
11706 | bnx2x_free_mem_bp(bp); | |
11707 | return rc; | |
11708 | } | |
452427b0 YM |
11709 | } |
11710 | ||
34f80b04 | 11711 | if (CHIP_REV_IS_FPGA(bp)) |
cdaa7cb8 | 11712 | dev_err(&bp->pdev->dev, "FPGA detected\n"); |
34f80b04 EG |
11713 | |
11714 | if (BP_NOMCP(bp) && (func == 0)) | |
51c1a580 | 11715 | dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n"); |
34f80b04 | 11716 | |
614c76df | 11717 | bp->disable_tpa = disable_tpa; |
a3348722 | 11718 | bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp); |
614c76df | 11719 | |
7a9b2557 | 11720 | /* Set TPA flags */ |
614c76df | 11721 | if (bp->disable_tpa) { |
621b4d66 | 11722 | bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
11723 | bp->dev->features &= ~NETIF_F_LRO; |
11724 | } else { | |
621b4d66 | 11725 | bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
11726 | bp->dev->features |= NETIF_F_LRO; |
11727 | } | |
11728 | ||
a18f5128 EG |
11729 | if (CHIP_IS_E1(bp)) |
11730 | bp->dropless_fc = 0; | |
11731 | else | |
7964211d | 11732 | bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp); |
a18f5128 | 11733 | |
8d5726c4 | 11734 | bp->mrrs = mrrs; |
7a9b2557 | 11735 | |
a3348722 | 11736 | bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL; |
1ab4434c AE |
11737 | if (IS_VF(bp)) |
11738 | bp->rx_ring_size = MAX_RX_AVAIL; | |
34f80b04 | 11739 | |
7d323bfd | 11740 | /* make sure that the numbers are in the right granularity */ |
523224a3 DK |
11741 | bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR; |
11742 | bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR; | |
34f80b04 | 11743 | |
fc543637 | 11744 | bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ; |
34f80b04 EG |
11745 | |
11746 | init_timer(&bp->timer); | |
11747 | bp->timer.expires = jiffies + bp->current_interval; | |
11748 | bp->timer.data = (unsigned long) bp; | |
11749 | bp->timer.function = bnx2x_timer; | |
11750 | ||
0370cf90 BW |
11751 | if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) && |
11752 | SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) && | |
11753 | SHMEM2_RD(bp, dcbx_lldp_params_offset) && | |
11754 | SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) { | |
11755 | bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON); | |
11756 | bnx2x_dcbx_init_params(bp); | |
11757 | } else { | |
11758 | bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF); | |
11759 | } | |
e4901dde | 11760 | |
619c5cb6 VZ |
11761 | if (CHIP_IS_E1x(bp)) |
11762 | bp->cnic_base_cl_id = FP_SB_MAX_E1x; | |
11763 | else | |
11764 | bp->cnic_base_cl_id = FP_SB_MAX_E2; | |
619c5cb6 | 11765 | |
6383c0b3 | 11766 | /* multiple tx priority */ |
1ab4434c AE |
11767 | if (IS_VF(bp)) |
11768 | bp->max_cos = 1; | |
11769 | else if (CHIP_IS_E1x(bp)) | |
6383c0b3 | 11770 | bp->max_cos = BNX2X_MULTI_TX_COS_E1X; |
1ab4434c | 11771 | else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) |
6383c0b3 | 11772 | bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0; |
1ab4434c | 11773 | else if (CHIP_IS_E3B0(bp)) |
6383c0b3 | 11774 | bp->max_cos = BNX2X_MULTI_TX_COS_E3B0; |
1ab4434c AE |
11775 | else |
11776 | BNX2X_ERR("unknown chip %x revision %x\n", | |
11777 | CHIP_NUM(bp), CHIP_REV(bp)); | |
11778 | BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos); | |
6383c0b3 | 11779 | |
55c11941 MS |
11780 | /* We need at least one default status block for slow-path events, |
11781 | * second status block for the L2 queue, and a third status block for | |
16a5fd92 | 11782 | * CNIC if supported. |
55c11941 | 11783 | */ |
60cad4e6 AE |
11784 | if (IS_VF(bp)) |
11785 | bp->min_msix_vec_cnt = 1; | |
11786 | else if (CNIC_SUPPORT(bp)) | |
55c11941 | 11787 | bp->min_msix_vec_cnt = 3; |
60cad4e6 | 11788 | else /* PF w/o cnic */ |
55c11941 MS |
11789 | bp->min_msix_vec_cnt = 2; |
11790 | BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt); | |
11791 | ||
5bb680d6 MS |
11792 | bp->dump_preset_idx = 1; |
11793 | ||
34f80b04 | 11794 | return rc; |
a2fbb9ea ET |
11795 | } |
11796 | ||
de0c62db DK |
11797 | /**************************************************************************** |
11798 | * General service functions | |
11799 | ****************************************************************************/ | |
a2fbb9ea | 11800 | |
619c5cb6 VZ |
11801 | /* |
11802 | * net_device service functions | |
11803 | */ | |
11804 | ||
bb2a0f7a | 11805 | /* called with rtnl_lock */ |
a2fbb9ea ET |
11806 | static int bnx2x_open(struct net_device *dev) |
11807 | { | |
11808 | struct bnx2x *bp = netdev_priv(dev); | |
8395be5e | 11809 | int rc; |
a2fbb9ea | 11810 | |
1355b704 MY |
11811 | bp->stats_init = true; |
11812 | ||
6eccabb3 EG |
11813 | netif_carrier_off(dev); |
11814 | ||
a2fbb9ea ET |
11815 | bnx2x_set_power_state(bp, PCI_D0); |
11816 | ||
ad5afc89 | 11817 | /* If parity had happen during the unload, then attentions |
c9ee9206 VZ |
11818 | * and/or RECOVERY_IN_PROGRES may still be set. In this case we |
11819 | * want the first function loaded on the current engine to | |
11820 | * complete the recovery. | |
ad5afc89 | 11821 | * Parity recovery is only relevant for PF driver. |
c9ee9206 | 11822 | */ |
ad5afc89 | 11823 | if (IS_PF(bp)) { |
1a6974b2 YM |
11824 | int other_engine = BP_PATH(bp) ? 0 : 1; |
11825 | bool other_load_status, load_status; | |
11826 | bool global = false; | |
11827 | ||
ad5afc89 AE |
11828 | other_load_status = bnx2x_get_load_status(bp, other_engine); |
11829 | load_status = bnx2x_get_load_status(bp, BP_PATH(bp)); | |
11830 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || | |
11831 | bnx2x_chk_parity_attn(bp, &global, true)) { | |
11832 | do { | |
11833 | /* If there are attentions and they are in a | |
11834 | * global blocks, set the GLOBAL_RESET bit | |
11835 | * regardless whether it will be this function | |
11836 | * that will complete the recovery or not. | |
11837 | */ | |
11838 | if (global) | |
11839 | bnx2x_set_reset_global(bp); | |
72fd0718 | 11840 | |
ad5afc89 AE |
11841 | /* Only the first function on the current |
11842 | * engine should try to recover in open. In case | |
11843 | * of attentions in global blocks only the first | |
11844 | * in the chip should try to recover. | |
11845 | */ | |
11846 | if ((!load_status && | |
11847 | (!global || !other_load_status)) && | |
11848 | bnx2x_trylock_leader_lock(bp) && | |
11849 | !bnx2x_leader_reset(bp)) { | |
11850 | netdev_info(bp->dev, | |
11851 | "Recovered in open\n"); | |
11852 | break; | |
11853 | } | |
72fd0718 | 11854 | |
ad5afc89 AE |
11855 | /* recovery has failed... */ |
11856 | bnx2x_set_power_state(bp, PCI_D3hot); | |
11857 | bp->recovery_state = BNX2X_RECOVERY_FAILED; | |
72fd0718 | 11858 | |
ad5afc89 AE |
11859 | BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n" |
11860 | "If you still see this message after a few retries then power cycle is required.\n"); | |
72fd0718 | 11861 | |
ad5afc89 AE |
11862 | return -EAGAIN; |
11863 | } while (0); | |
11864 | } | |
11865 | } | |
72fd0718 VZ |
11866 | |
11867 | bp->recovery_state = BNX2X_RECOVERY_DONE; | |
8395be5e AE |
11868 | rc = bnx2x_nic_load(bp, LOAD_OPEN); |
11869 | if (rc) | |
11870 | return rc; | |
9a8130bc | 11871 | return 0; |
a2fbb9ea ET |
11872 | } |
11873 | ||
bb2a0f7a | 11874 | /* called with rtnl_lock */ |
56ad3152 | 11875 | static int bnx2x_close(struct net_device *dev) |
a2fbb9ea | 11876 | { |
a2fbb9ea ET |
11877 | struct bnx2x *bp = netdev_priv(dev); |
11878 | ||
11879 | /* Unload the driver, release IRQs */ | |
5d07d868 | 11880 | bnx2x_nic_unload(bp, UNLOAD_CLOSE, false); |
c9ee9206 | 11881 | |
a2fbb9ea ET |
11882 | return 0; |
11883 | } | |
11884 | ||
1191cb83 ED |
11885 | static int bnx2x_init_mcast_macs_list(struct bnx2x *bp, |
11886 | struct bnx2x_mcast_ramrod_params *p) | |
6e30dd4e | 11887 | { |
619c5cb6 VZ |
11888 | int mc_count = netdev_mc_count(bp->dev); |
11889 | struct bnx2x_mcast_list_elem *mc_mac = | |
11890 | kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); | |
11891 | struct netdev_hw_addr *ha; | |
6e30dd4e | 11892 | |
619c5cb6 VZ |
11893 | if (!mc_mac) |
11894 | return -ENOMEM; | |
6e30dd4e | 11895 | |
619c5cb6 | 11896 | INIT_LIST_HEAD(&p->mcast_list); |
6e30dd4e | 11897 | |
619c5cb6 VZ |
11898 | netdev_for_each_mc_addr(ha, bp->dev) { |
11899 | mc_mac->mac = bnx2x_mc_addr(ha); | |
11900 | list_add_tail(&mc_mac->link, &p->mcast_list); | |
11901 | mc_mac++; | |
6e30dd4e | 11902 | } |
619c5cb6 VZ |
11903 | |
11904 | p->mcast_list_len = mc_count; | |
11905 | ||
11906 | return 0; | |
6e30dd4e VZ |
11907 | } |
11908 | ||
1191cb83 | 11909 | static void bnx2x_free_mcast_macs_list( |
619c5cb6 VZ |
11910 | struct bnx2x_mcast_ramrod_params *p) |
11911 | { | |
11912 | struct bnx2x_mcast_list_elem *mc_mac = | |
11913 | list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem, | |
11914 | link); | |
11915 | ||
11916 | WARN_ON(!mc_mac); | |
11917 | kfree(mc_mac); | |
11918 | } | |
11919 | ||
11920 | /** | |
11921 | * bnx2x_set_uc_list - configure a new unicast MACs list. | |
11922 | * | |
11923 | * @bp: driver handle | |
6e30dd4e | 11924 | * |
619c5cb6 | 11925 | * We will use zero (0) as a MAC type for these MACs. |
6e30dd4e | 11926 | */ |
1191cb83 | 11927 | static int bnx2x_set_uc_list(struct bnx2x *bp) |
6e30dd4e | 11928 | { |
619c5cb6 | 11929 | int rc; |
6e30dd4e | 11930 | struct net_device *dev = bp->dev; |
6e30dd4e | 11931 | struct netdev_hw_addr *ha; |
15192a8c | 11932 | struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj; |
619c5cb6 | 11933 | unsigned long ramrod_flags = 0; |
6e30dd4e | 11934 | |
619c5cb6 VZ |
11935 | /* First schedule a cleanup up of old configuration */ |
11936 | rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false); | |
11937 | if (rc < 0) { | |
11938 | BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc); | |
11939 | return rc; | |
11940 | } | |
6e30dd4e VZ |
11941 | |
11942 | netdev_for_each_uc_addr(ha, dev) { | |
619c5cb6 VZ |
11943 | rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, |
11944 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
7b5342d9 YM |
11945 | if (rc == -EEXIST) { |
11946 | DP(BNX2X_MSG_SP, | |
11947 | "Failed to schedule ADD operations: %d\n", rc); | |
11948 | /* do not treat adding same MAC as error */ | |
11949 | rc = 0; | |
11950 | ||
11951 | } else if (rc < 0) { | |
11952 | ||
619c5cb6 VZ |
11953 | BNX2X_ERR("Failed to schedule ADD operations: %d\n", |
11954 | rc); | |
11955 | return rc; | |
6e30dd4e VZ |
11956 | } |
11957 | } | |
11958 | ||
619c5cb6 VZ |
11959 | /* Execute the pending commands */ |
11960 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
11961 | return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */, | |
11962 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
6e30dd4e VZ |
11963 | } |
11964 | ||
1191cb83 | 11965 | static int bnx2x_set_mc_list(struct bnx2x *bp) |
6e30dd4e | 11966 | { |
619c5cb6 | 11967 | struct net_device *dev = bp->dev; |
3b603066 | 11968 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 | 11969 | int rc = 0; |
6e30dd4e | 11970 | |
619c5cb6 | 11971 | rparam.mcast_obj = &bp->mcast_obj; |
6e30dd4e | 11972 | |
619c5cb6 VZ |
11973 | /* first, clear all configured multicast MACs */ |
11974 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
11975 | if (rc < 0) { | |
51c1a580 | 11976 | BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc); |
619c5cb6 VZ |
11977 | return rc; |
11978 | } | |
6e30dd4e | 11979 | |
619c5cb6 VZ |
11980 | /* then, configure a new MACs list */ |
11981 | if (netdev_mc_count(dev)) { | |
11982 | rc = bnx2x_init_mcast_macs_list(bp, &rparam); | |
11983 | if (rc) { | |
51c1a580 MS |
11984 | BNX2X_ERR("Failed to create multicast MACs list: %d\n", |
11985 | rc); | |
619c5cb6 VZ |
11986 | return rc; |
11987 | } | |
6e30dd4e | 11988 | |
619c5cb6 VZ |
11989 | /* Now add the new MACs */ |
11990 | rc = bnx2x_config_mcast(bp, &rparam, | |
11991 | BNX2X_MCAST_CMD_ADD); | |
11992 | if (rc < 0) | |
51c1a580 MS |
11993 | BNX2X_ERR("Failed to set a new multicast configuration: %d\n", |
11994 | rc); | |
6e30dd4e | 11995 | |
619c5cb6 VZ |
11996 | bnx2x_free_mcast_macs_list(&rparam); |
11997 | } | |
6e30dd4e | 11998 | |
619c5cb6 | 11999 | return rc; |
6e30dd4e VZ |
12000 | } |
12001 | ||
619c5cb6 | 12002 | /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */ |
9f6c9258 | 12003 | void bnx2x_set_rx_mode(struct net_device *dev) |
34f80b04 EG |
12004 | { |
12005 | struct bnx2x *bp = netdev_priv(dev); | |
34f80b04 EG |
12006 | |
12007 | if (bp->state != BNX2X_STATE_OPEN) { | |
12008 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); | |
12009 | return; | |
8b09be5f YM |
12010 | } else { |
12011 | /* Schedule an SP task to handle rest of change */ | |
12012 | DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n"); | |
12013 | smp_mb__before_clear_bit(); | |
12014 | set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state); | |
12015 | smp_mb__after_clear_bit(); | |
12016 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
34f80b04 | 12017 | } |
8b09be5f YM |
12018 | } |
12019 | ||
12020 | void bnx2x_set_rx_mode_inner(struct bnx2x *bp) | |
12021 | { | |
12022 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; | |
34f80b04 | 12023 | |
619c5cb6 | 12024 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags); |
34f80b04 | 12025 | |
8b09be5f YM |
12026 | netif_addr_lock_bh(bp->dev); |
12027 | ||
12028 | if (bp->dev->flags & IFF_PROMISC) { | |
34f80b04 | 12029 | rx_mode = BNX2X_RX_MODE_PROMISC; |
8b09be5f YM |
12030 | } else if ((bp->dev->flags & IFF_ALLMULTI) || |
12031 | ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) && | |
12032 | CHIP_IS_E1(bp))) { | |
34f80b04 | 12033 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
8b09be5f | 12034 | } else { |
381ac16b AE |
12035 | if (IS_PF(bp)) { |
12036 | /* some multicasts */ | |
12037 | if (bnx2x_set_mc_list(bp) < 0) | |
12038 | rx_mode = BNX2X_RX_MODE_ALLMULTI; | |
34f80b04 | 12039 | |
8b09be5f YM |
12040 | /* release bh lock, as bnx2x_set_uc_list might sleep */ |
12041 | netif_addr_unlock_bh(bp->dev); | |
381ac16b AE |
12042 | if (bnx2x_set_uc_list(bp) < 0) |
12043 | rx_mode = BNX2X_RX_MODE_PROMISC; | |
8b09be5f | 12044 | netif_addr_lock_bh(bp->dev); |
381ac16b AE |
12045 | } else { |
12046 | /* configuring mcast to a vf involves sleeping (when we | |
8b09be5f | 12047 | * wait for the pf's response). |
381ac16b AE |
12048 | */ |
12049 | smp_mb__before_clear_bit(); | |
12050 | set_bit(BNX2X_SP_RTNL_VFPF_MCAST, | |
12051 | &bp->sp_rtnl_state); | |
12052 | smp_mb__after_clear_bit(); | |
12053 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
12054 | } | |
34f80b04 EG |
12055 | } |
12056 | ||
12057 | bp->rx_mode = rx_mode; | |
614c76df DK |
12058 | /* handle ISCSI SD mode */ |
12059 | if (IS_MF_ISCSI_SD(bp)) | |
12060 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
619c5cb6 VZ |
12061 | |
12062 | /* Schedule the rx_mode command */ | |
12063 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) { | |
12064 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
8b09be5f | 12065 | netif_addr_unlock_bh(bp->dev); |
619c5cb6 VZ |
12066 | return; |
12067 | } | |
12068 | ||
381ac16b AE |
12069 | if (IS_PF(bp)) { |
12070 | bnx2x_set_storm_rx_mode(bp); | |
8b09be5f | 12071 | netif_addr_unlock_bh(bp->dev); |
381ac16b | 12072 | } else { |
8b09be5f YM |
12073 | /* VF will need to request the PF to make this change, and so |
12074 | * the VF needs to release the bottom-half lock prior to the | |
12075 | * request (as it will likely require sleep on the VF side) | |
381ac16b | 12076 | */ |
8b09be5f YM |
12077 | netif_addr_unlock_bh(bp->dev); |
12078 | bnx2x_vfpf_storm_rx_mode(bp); | |
381ac16b | 12079 | } |
34f80b04 EG |
12080 | } |
12081 | ||
c18487ee | 12082 | /* called with rtnl_lock */ |
01cd4528 EG |
12083 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
12084 | int devad, u16 addr) | |
a2fbb9ea | 12085 | { |
01cd4528 EG |
12086 | struct bnx2x *bp = netdev_priv(netdev); |
12087 | u16 value; | |
12088 | int rc; | |
a2fbb9ea | 12089 | |
01cd4528 EG |
12090 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
12091 | prtad, devad, addr); | |
a2fbb9ea | 12092 | |
01cd4528 EG |
12093 | /* The HW expects different devad if CL22 is used */ |
12094 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
c18487ee | 12095 | |
01cd4528 | 12096 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 12097 | rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value); |
01cd4528 EG |
12098 | bnx2x_release_phy_lock(bp); |
12099 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); | |
a2fbb9ea | 12100 | |
01cd4528 EG |
12101 | if (!rc) |
12102 | rc = value; | |
12103 | return rc; | |
12104 | } | |
a2fbb9ea | 12105 | |
01cd4528 EG |
12106 | /* called with rtnl_lock */ |
12107 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, | |
12108 | u16 addr, u16 value) | |
12109 | { | |
12110 | struct bnx2x *bp = netdev_priv(netdev); | |
01cd4528 EG |
12111 | int rc; |
12112 | ||
51c1a580 MS |
12113 | DP(NETIF_MSG_LINK, |
12114 | "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n", | |
12115 | prtad, devad, addr, value); | |
01cd4528 | 12116 | |
01cd4528 EG |
12117 | /* The HW expects different devad if CL22 is used */ |
12118 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
a2fbb9ea | 12119 | |
01cd4528 | 12120 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 12121 | rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value); |
01cd4528 EG |
12122 | bnx2x_release_phy_lock(bp); |
12123 | return rc; | |
12124 | } | |
c18487ee | 12125 | |
01cd4528 EG |
12126 | /* called with rtnl_lock */ |
12127 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |
12128 | { | |
12129 | struct bnx2x *bp = netdev_priv(dev); | |
12130 | struct mii_ioctl_data *mdio = if_mii(ifr); | |
a2fbb9ea | 12131 | |
01cd4528 EG |
12132 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
12133 | mdio->phy_id, mdio->reg_num, mdio->val_in); | |
a2fbb9ea | 12134 | |
01cd4528 EG |
12135 | if (!netif_running(dev)) |
12136 | return -EAGAIN; | |
12137 | ||
12138 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); | |
a2fbb9ea ET |
12139 | } |
12140 | ||
257ddbda | 12141 | #ifdef CONFIG_NET_POLL_CONTROLLER |
a2fbb9ea ET |
12142 | static void poll_bnx2x(struct net_device *dev) |
12143 | { | |
12144 | struct bnx2x *bp = netdev_priv(dev); | |
14a15d61 | 12145 | int i; |
a2fbb9ea | 12146 | |
14a15d61 MS |
12147 | for_each_eth_queue(bp, i) { |
12148 | struct bnx2x_fastpath *fp = &bp->fp[i]; | |
12149 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); | |
12150 | } | |
a2fbb9ea ET |
12151 | } |
12152 | #endif | |
12153 | ||
614c76df DK |
12154 | static int bnx2x_validate_addr(struct net_device *dev) |
12155 | { | |
12156 | struct bnx2x *bp = netdev_priv(dev); | |
12157 | ||
e09b74d0 AE |
12158 | /* query the bulletin board for mac address configured by the PF */ |
12159 | if (IS_VF(bp)) | |
12160 | bnx2x_sample_bulletin(bp); | |
12161 | ||
51c1a580 MS |
12162 | if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) { |
12163 | BNX2X_ERR("Non-valid Ethernet address\n"); | |
614c76df | 12164 | return -EADDRNOTAVAIL; |
51c1a580 | 12165 | } |
614c76df DK |
12166 | return 0; |
12167 | } | |
12168 | ||
3d7d562c YM |
12169 | static int bnx2x_get_phys_port_id(struct net_device *netdev, |
12170 | struct netdev_phys_port_id *ppid) | |
12171 | { | |
12172 | struct bnx2x *bp = netdev_priv(netdev); | |
12173 | ||
12174 | if (!(bp->flags & HAS_PHYS_PORT_ID)) | |
12175 | return -EOPNOTSUPP; | |
12176 | ||
12177 | ppid->id_len = sizeof(bp->phys_port_id); | |
12178 | memcpy(ppid->id, bp->phys_port_id, ppid->id_len); | |
12179 | ||
12180 | return 0; | |
12181 | } | |
12182 | ||
c64213cd SH |
12183 | static const struct net_device_ops bnx2x_netdev_ops = { |
12184 | .ndo_open = bnx2x_open, | |
12185 | .ndo_stop = bnx2x_close, | |
12186 | .ndo_start_xmit = bnx2x_start_xmit, | |
8307fa3e | 12187 | .ndo_select_queue = bnx2x_select_queue, |
6e30dd4e | 12188 | .ndo_set_rx_mode = bnx2x_set_rx_mode, |
c64213cd | 12189 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
614c76df | 12190 | .ndo_validate_addr = bnx2x_validate_addr, |
c64213cd SH |
12191 | .ndo_do_ioctl = bnx2x_ioctl, |
12192 | .ndo_change_mtu = bnx2x_change_mtu, | |
66371c44 MM |
12193 | .ndo_fix_features = bnx2x_fix_features, |
12194 | .ndo_set_features = bnx2x_set_features, | |
c64213cd | 12195 | .ndo_tx_timeout = bnx2x_tx_timeout, |
257ddbda | 12196 | #ifdef CONFIG_NET_POLL_CONTROLLER |
c64213cd SH |
12197 | .ndo_poll_controller = poll_bnx2x, |
12198 | #endif | |
6383c0b3 | 12199 | .ndo_setup_tc = bnx2x_setup_tc, |
6411280a | 12200 | #ifdef CONFIG_BNX2X_SRIOV |
abc5a021 | 12201 | .ndo_set_vf_mac = bnx2x_set_vf_mac, |
3cdeec22 | 12202 | .ndo_set_vf_vlan = bnx2x_set_vf_vlan, |
3ec9f9ca | 12203 | .ndo_get_vf_config = bnx2x_get_vf_config, |
6411280a | 12204 | #endif |
55c11941 | 12205 | #ifdef NETDEV_FCOE_WWNN |
bf61ee14 VZ |
12206 | .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn, |
12207 | #endif | |
8f20aa57 | 12208 | |
e0d1095a | 12209 | #ifdef CONFIG_NET_RX_BUSY_POLL |
8b80cda5 | 12210 | .ndo_busy_poll = bnx2x_low_latency_recv, |
8f20aa57 | 12211 | #endif |
3d7d562c | 12212 | .ndo_get_phys_port_id = bnx2x_get_phys_port_id, |
c64213cd SH |
12213 | }; |
12214 | ||
1191cb83 | 12215 | static int bnx2x_set_coherency_mask(struct bnx2x *bp) |
619c5cb6 VZ |
12216 | { |
12217 | struct device *dev = &bp->pdev->dev; | |
12218 | ||
8ceafbfa LT |
12219 | if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 && |
12220 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) { | |
619c5cb6 VZ |
12221 | dev_err(dev, "System does not support DMA, aborting\n"); |
12222 | return -EIO; | |
12223 | } | |
12224 | ||
12225 | return 0; | |
12226 | } | |
12227 | ||
1ab4434c AE |
12228 | static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev, |
12229 | struct net_device *dev, unsigned long board_type) | |
a2fbb9ea | 12230 | { |
a2fbb9ea | 12231 | int rc; |
c22610d0 | 12232 | u32 pci_cfg_dword; |
65087cfe AE |
12233 | bool chip_is_e1x = (board_type == BCM57710 || |
12234 | board_type == BCM57711 || | |
12235 | board_type == BCM57711E); | |
a2fbb9ea ET |
12236 | |
12237 | SET_NETDEV_DEV(dev, &pdev->dev); | |
a2fbb9ea | 12238 | |
34f80b04 EG |
12239 | bp->dev = dev; |
12240 | bp->pdev = pdev; | |
a2fbb9ea ET |
12241 | |
12242 | rc = pci_enable_device(pdev); | |
12243 | if (rc) { | |
cdaa7cb8 VZ |
12244 | dev_err(&bp->pdev->dev, |
12245 | "Cannot enable PCI device, aborting\n"); | |
a2fbb9ea ET |
12246 | goto err_out; |
12247 | } | |
12248 | ||
12249 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | |
cdaa7cb8 VZ |
12250 | dev_err(&bp->pdev->dev, |
12251 | "Cannot find PCI device base address, aborting\n"); | |
a2fbb9ea ET |
12252 | rc = -ENODEV; |
12253 | goto err_out_disable; | |
12254 | } | |
12255 | ||
1ab4434c AE |
12256 | if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
12257 | dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n"); | |
a2fbb9ea ET |
12258 | rc = -ENODEV; |
12259 | goto err_out_disable; | |
12260 | } | |
12261 | ||
092a5fc9 YR |
12262 | pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword); |
12263 | if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) == | |
12264 | PCICFG_REVESION_ID_ERROR_VAL) { | |
12265 | pr_err("PCI device error, probably due to fan failure, aborting\n"); | |
12266 | rc = -ENODEV; | |
12267 | goto err_out_disable; | |
12268 | } | |
12269 | ||
34f80b04 EG |
12270 | if (atomic_read(&pdev->enable_cnt) == 1) { |
12271 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); | |
12272 | if (rc) { | |
cdaa7cb8 VZ |
12273 | dev_err(&bp->pdev->dev, |
12274 | "Cannot obtain PCI resources, aborting\n"); | |
34f80b04 EG |
12275 | goto err_out_disable; |
12276 | } | |
a2fbb9ea | 12277 | |
34f80b04 EG |
12278 | pci_set_master(pdev); |
12279 | pci_save_state(pdev); | |
12280 | } | |
a2fbb9ea | 12281 | |
1ab4434c | 12282 | if (IS_PF(bp)) { |
29ed74c3 | 12283 | if (!pdev->pm_cap) { |
1ab4434c AE |
12284 | dev_err(&bp->pdev->dev, |
12285 | "Cannot find power management capability, aborting\n"); | |
12286 | rc = -EIO; | |
12287 | goto err_out_release; | |
12288 | } | |
a2fbb9ea ET |
12289 | } |
12290 | ||
77c98e6a | 12291 | if (!pci_is_pcie(pdev)) { |
51c1a580 | 12292 | dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n"); |
a2fbb9ea ET |
12293 | rc = -EIO; |
12294 | goto err_out_release; | |
12295 | } | |
12296 | ||
619c5cb6 VZ |
12297 | rc = bnx2x_set_coherency_mask(bp); |
12298 | if (rc) | |
a2fbb9ea | 12299 | goto err_out_release; |
a2fbb9ea | 12300 | |
34f80b04 EG |
12301 | dev->mem_start = pci_resource_start(pdev, 0); |
12302 | dev->base_addr = dev->mem_start; | |
12303 | dev->mem_end = pci_resource_end(pdev, 0); | |
a2fbb9ea ET |
12304 | |
12305 | dev->irq = pdev->irq; | |
12306 | ||
275f165f | 12307 | bp->regview = pci_ioremap_bar(pdev, 0); |
a2fbb9ea | 12308 | if (!bp->regview) { |
cdaa7cb8 VZ |
12309 | dev_err(&bp->pdev->dev, |
12310 | "Cannot map register space, aborting\n"); | |
a2fbb9ea ET |
12311 | rc = -ENOMEM; |
12312 | goto err_out_release; | |
12313 | } | |
12314 | ||
c22610d0 AE |
12315 | /* In E1/E1H use pci device function given by kernel. |
12316 | * In E2/E3 read physical function from ME register since these chips | |
12317 | * support Physical Device Assignment where kernel BDF maybe arbitrary | |
12318 | * (depending on hypervisor). | |
12319 | */ | |
2de67439 | 12320 | if (chip_is_e1x) { |
c22610d0 | 12321 | bp->pf_num = PCI_FUNC(pdev->devfn); |
2de67439 YM |
12322 | } else { |
12323 | /* chip is E2/3*/ | |
c22610d0 AE |
12324 | pci_read_config_dword(bp->pdev, |
12325 | PCICFG_ME_REGISTER, &pci_cfg_dword); | |
12326 | bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >> | |
2de67439 | 12327 | ME_REG_ABS_PF_NUM_SHIFT); |
c22610d0 | 12328 | } |
51c1a580 | 12329 | BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num); |
c22610d0 | 12330 | |
34f80b04 EG |
12331 | /* clean indirect addresses */ |
12332 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
12333 | PCICFG_VENDOR_ID_OFFSET); | |
a5c53dbc DK |
12334 | /* |
12335 | * Clean the following indirect addresses for all functions since it | |
9f0096a1 DK |
12336 | * is not used by the driver. |
12337 | */ | |
1ab4434c AE |
12338 | if (IS_PF(bp)) { |
12339 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0); | |
12340 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0); | |
12341 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0); | |
12342 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0); | |
12343 | ||
12344 | if (chip_is_e1x) { | |
12345 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0); | |
12346 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0); | |
12347 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0); | |
12348 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0); | |
12349 | } | |
a5c53dbc | 12350 | |
1ab4434c AE |
12351 | /* Enable internal target-read (in case we are probed after PF |
12352 | * FLR). Must be done prior to any BAR read access. Only for | |
12353 | * 57712 and up | |
12354 | */ | |
12355 | if (!chip_is_e1x) | |
12356 | REG_WR(bp, | |
12357 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); | |
a5c53dbc | 12358 | } |
a2fbb9ea | 12359 | |
34f80b04 | 12360 | dev->watchdog_timeo = TX_TIMEOUT; |
a2fbb9ea | 12361 | |
c64213cd | 12362 | dev->netdev_ops = &bnx2x_netdev_ops; |
005a07ba | 12363 | bnx2x_set_ethtool_ops(bp, dev); |
5316bc0b | 12364 | |
01789349 JP |
12365 | dev->priv_flags |= IFF_UNICAST_FLT; |
12366 | ||
66371c44 | 12367 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
621b4d66 DK |
12368 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | |
12369 | NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO | | |
f646968f | 12370 | NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX; |
a848ade4 | 12371 | if (!CHIP_IS_E1x(bp)) { |
117401ee | 12372 | dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL | |
2e3bd6a4 | 12373 | NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT; |
a848ade4 DK |
12374 | dev->hw_enc_features = |
12375 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | | |
12376 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | | |
117401ee | 12377 | NETIF_F_GSO_IPIP | |
2e3bd6a4 | 12378 | NETIF_F_GSO_SIT | |
65bc0cfe | 12379 | NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL; |
a848ade4 | 12380 | } |
66371c44 MM |
12381 | |
12382 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
12383 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; | |
12384 | ||
f646968f | 12385 | dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX; |
edd31476 | 12386 | dev->features |= NETIF_F_HIGHDMA; |
a2fbb9ea | 12387 | |
538dd2e3 MB |
12388 | /* Add Loopback capability to the device */ |
12389 | dev->hw_features |= NETIF_F_LOOPBACK; | |
12390 | ||
98507672 | 12391 | #ifdef BCM_DCBNL |
785b9b1a SR |
12392 | dev->dcbnl_ops = &bnx2x_dcbnl_ops; |
12393 | #endif | |
12394 | ||
01cd4528 EG |
12395 | /* get_port_hwinfo() will set prtad and mmds properly */ |
12396 | bp->mdio.prtad = MDIO_PRTAD_NONE; | |
12397 | bp->mdio.mmds = 0; | |
12398 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; | |
12399 | bp->mdio.dev = dev; | |
12400 | bp->mdio.mdio_read = bnx2x_mdio_read; | |
12401 | bp->mdio.mdio_write = bnx2x_mdio_write; | |
12402 | ||
a2fbb9ea ET |
12403 | return 0; |
12404 | ||
a2fbb9ea | 12405 | err_out_release: |
34f80b04 EG |
12406 | if (atomic_read(&pdev->enable_cnt) == 1) |
12407 | pci_release_regions(pdev); | |
a2fbb9ea ET |
12408 | |
12409 | err_out_disable: | |
12410 | pci_disable_device(pdev); | |
a2fbb9ea ET |
12411 | |
12412 | err_out: | |
12413 | return rc; | |
12414 | } | |
12415 | ||
6891dd25 | 12416 | static int bnx2x_check_firmware(struct bnx2x *bp) |
94a78b79 | 12417 | { |
37f9ce62 | 12418 | const struct firmware *firmware = bp->firmware; |
94a78b79 VZ |
12419 | struct bnx2x_fw_file_hdr *fw_hdr; |
12420 | struct bnx2x_fw_file_section *sections; | |
94a78b79 | 12421 | u32 offset, len, num_ops; |
86564c3f | 12422 | __be16 *ops_offsets; |
94a78b79 | 12423 | int i; |
37f9ce62 | 12424 | const u8 *fw_ver; |
94a78b79 | 12425 | |
51c1a580 MS |
12426 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) { |
12427 | BNX2X_ERR("Wrong FW size\n"); | |
94a78b79 | 12428 | return -EINVAL; |
51c1a580 | 12429 | } |
94a78b79 VZ |
12430 | |
12431 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; | |
12432 | sections = (struct bnx2x_fw_file_section *)fw_hdr; | |
12433 | ||
12434 | /* Make sure none of the offsets and sizes make us read beyond | |
12435 | * the end of the firmware data */ | |
12436 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { | |
12437 | offset = be32_to_cpu(sections[i].offset); | |
12438 | len = be32_to_cpu(sections[i].len); | |
12439 | if (offset + len > firmware->size) { | |
51c1a580 | 12440 | BNX2X_ERR("Section %d length is out of bounds\n", i); |
94a78b79 VZ |
12441 | return -EINVAL; |
12442 | } | |
12443 | } | |
12444 | ||
12445 | /* Likewise for the init_ops offsets */ | |
12446 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); | |
86564c3f | 12447 | ops_offsets = (__force __be16 *)(firmware->data + offset); |
94a78b79 VZ |
12448 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); |
12449 | ||
12450 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { | |
12451 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { | |
51c1a580 | 12452 | BNX2X_ERR("Section offset %d is out of bounds\n", i); |
94a78b79 VZ |
12453 | return -EINVAL; |
12454 | } | |
12455 | } | |
12456 | ||
12457 | /* Check FW version */ | |
12458 | offset = be32_to_cpu(fw_hdr->fw_version.offset); | |
12459 | fw_ver = firmware->data + offset; | |
12460 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || | |
12461 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || | |
12462 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || | |
12463 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { | |
51c1a580 MS |
12464 | BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n", |
12465 | fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3], | |
12466 | BCM_5710_FW_MAJOR_VERSION, | |
94a78b79 VZ |
12467 | BCM_5710_FW_MINOR_VERSION, |
12468 | BCM_5710_FW_REVISION_VERSION, | |
12469 | BCM_5710_FW_ENGINEERING_VERSION); | |
ab6ad5a4 | 12470 | return -EINVAL; |
94a78b79 VZ |
12471 | } |
12472 | ||
12473 | return 0; | |
12474 | } | |
12475 | ||
1191cb83 | 12476 | static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12477 | { |
ab6ad5a4 EG |
12478 | const __be32 *source = (const __be32 *)_source; |
12479 | u32 *target = (u32 *)_target; | |
94a78b79 | 12480 | u32 i; |
94a78b79 VZ |
12481 | |
12482 | for (i = 0; i < n/4; i++) | |
12483 | target[i] = be32_to_cpu(source[i]); | |
12484 | } | |
12485 | ||
12486 | /* | |
12487 | Ops array is stored in the following format: | |
12488 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} | |
12489 | */ | |
1191cb83 | 12490 | static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12491 | { |
ab6ad5a4 EG |
12492 | const __be32 *source = (const __be32 *)_source; |
12493 | struct raw_op *target = (struct raw_op *)_target; | |
94a78b79 | 12494 | u32 i, j, tmp; |
94a78b79 | 12495 | |
ab6ad5a4 | 12496 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
94a78b79 VZ |
12497 | tmp = be32_to_cpu(source[j]); |
12498 | target[i].op = (tmp >> 24) & 0xff; | |
cdaa7cb8 VZ |
12499 | target[i].offset = tmp & 0xffffff; |
12500 | target[i].raw_data = be32_to_cpu(source[j + 1]); | |
94a78b79 VZ |
12501 | } |
12502 | } | |
ab6ad5a4 | 12503 | |
1aa8b471 | 12504 | /* IRO array is stored in the following format: |
523224a3 DK |
12505 | * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) } |
12506 | */ | |
1191cb83 | 12507 | static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n) |
523224a3 DK |
12508 | { |
12509 | const __be32 *source = (const __be32 *)_source; | |
12510 | struct iro *target = (struct iro *)_target; | |
12511 | u32 i, j, tmp; | |
12512 | ||
12513 | for (i = 0, j = 0; i < n/sizeof(struct iro); i++) { | |
12514 | target[i].base = be32_to_cpu(source[j]); | |
12515 | j++; | |
12516 | tmp = be32_to_cpu(source[j]); | |
12517 | target[i].m1 = (tmp >> 16) & 0xffff; | |
12518 | target[i].m2 = tmp & 0xffff; | |
12519 | j++; | |
12520 | tmp = be32_to_cpu(source[j]); | |
12521 | target[i].m3 = (tmp >> 16) & 0xffff; | |
12522 | target[i].size = tmp & 0xffff; | |
12523 | j++; | |
12524 | } | |
12525 | } | |
12526 | ||
1191cb83 | 12527 | static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 12528 | { |
ab6ad5a4 EG |
12529 | const __be16 *source = (const __be16 *)_source; |
12530 | u16 *target = (u16 *)_target; | |
94a78b79 | 12531 | u32 i; |
94a78b79 VZ |
12532 | |
12533 | for (i = 0; i < n/2; i++) | |
12534 | target[i] = be16_to_cpu(source[i]); | |
12535 | } | |
12536 | ||
7995c64e JP |
12537 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
12538 | do { \ | |
12539 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ | |
12540 | bp->arr = kmalloc(len, GFP_KERNEL); \ | |
e404decb | 12541 | if (!bp->arr) \ |
7995c64e | 12542 | goto lbl; \ |
7995c64e JP |
12543 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
12544 | (u8 *)bp->arr, len); \ | |
12545 | } while (0) | |
94a78b79 | 12546 | |
3b603066 | 12547 | static int bnx2x_init_firmware(struct bnx2x *bp) |
94a78b79 | 12548 | { |
c0ea452e | 12549 | const char *fw_file_name; |
94a78b79 | 12550 | struct bnx2x_fw_file_hdr *fw_hdr; |
45229b42 | 12551 | int rc; |
94a78b79 | 12552 | |
c0ea452e MS |
12553 | if (bp->firmware) |
12554 | return 0; | |
94a78b79 | 12555 | |
c0ea452e MS |
12556 | if (CHIP_IS_E1(bp)) |
12557 | fw_file_name = FW_FILE_NAME_E1; | |
12558 | else if (CHIP_IS_E1H(bp)) | |
12559 | fw_file_name = FW_FILE_NAME_E1H; | |
12560 | else if (!CHIP_IS_E1x(bp)) | |
12561 | fw_file_name = FW_FILE_NAME_E2; | |
12562 | else { | |
12563 | BNX2X_ERR("Unsupported chip revision\n"); | |
12564 | return -EINVAL; | |
12565 | } | |
12566 | BNX2X_DEV_INFO("Loading %s\n", fw_file_name); | |
94a78b79 | 12567 | |
c0ea452e MS |
12568 | rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); |
12569 | if (rc) { | |
12570 | BNX2X_ERR("Can't load firmware file %s\n", | |
12571 | fw_file_name); | |
12572 | goto request_firmware_exit; | |
12573 | } | |
eb2afd4a | 12574 | |
c0ea452e MS |
12575 | rc = bnx2x_check_firmware(bp); |
12576 | if (rc) { | |
12577 | BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); | |
12578 | goto request_firmware_exit; | |
94a78b79 VZ |
12579 | } |
12580 | ||
12581 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; | |
12582 | ||
12583 | /* Initialize the pointers to the init arrays */ | |
12584 | /* Blob */ | |
12585 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); | |
12586 | ||
12587 | /* Opcodes */ | |
12588 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); | |
12589 | ||
12590 | /* Offsets */ | |
ab6ad5a4 EG |
12591 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
12592 | be16_to_cpu_n); | |
94a78b79 VZ |
12593 | |
12594 | /* STORMs firmware */ | |
573f2035 EG |
12595 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
12596 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); | |
12597 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12598 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); | |
12599 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12600 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); | |
12601 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + | |
12602 | be32_to_cpu(fw_hdr->usem_pram_data.offset); | |
12603 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12604 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); | |
12605 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12606 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); | |
12607 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
12608 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); | |
12609 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + | |
12610 | be32_to_cpu(fw_hdr->csem_pram_data.offset); | |
523224a3 DK |
12611 | /* IRO */ |
12612 | BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro); | |
94a78b79 VZ |
12613 | |
12614 | return 0; | |
ab6ad5a4 | 12615 | |
523224a3 DK |
12616 | iro_alloc_err: |
12617 | kfree(bp->init_ops_offsets); | |
94a78b79 VZ |
12618 | init_offsets_alloc_err: |
12619 | kfree(bp->init_ops); | |
12620 | init_ops_alloc_err: | |
12621 | kfree(bp->init_data); | |
12622 | request_firmware_exit: | |
12623 | release_firmware(bp->firmware); | |
127d0a19 | 12624 | bp->firmware = NULL; |
94a78b79 VZ |
12625 | |
12626 | return rc; | |
12627 | } | |
12628 | ||
619c5cb6 VZ |
12629 | static void bnx2x_release_firmware(struct bnx2x *bp) |
12630 | { | |
12631 | kfree(bp->init_ops_offsets); | |
12632 | kfree(bp->init_ops); | |
12633 | kfree(bp->init_data); | |
12634 | release_firmware(bp->firmware); | |
eb2afd4a | 12635 | bp->firmware = NULL; |
619c5cb6 VZ |
12636 | } |
12637 | ||
619c5cb6 VZ |
12638 | static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = { |
12639 | .init_hw_cmn_chip = bnx2x_init_hw_common_chip, | |
12640 | .init_hw_cmn = bnx2x_init_hw_common, | |
12641 | .init_hw_port = bnx2x_init_hw_port, | |
12642 | .init_hw_func = bnx2x_init_hw_func, | |
12643 | ||
12644 | .reset_hw_cmn = bnx2x_reset_common, | |
12645 | .reset_hw_port = bnx2x_reset_port, | |
12646 | .reset_hw_func = bnx2x_reset_func, | |
12647 | ||
12648 | .gunzip_init = bnx2x_gunzip_init, | |
12649 | .gunzip_end = bnx2x_gunzip_end, | |
12650 | ||
12651 | .init_fw = bnx2x_init_firmware, | |
12652 | .release_fw = bnx2x_release_firmware, | |
12653 | }; | |
12654 | ||
12655 | void bnx2x__init_func_obj(struct bnx2x *bp) | |
12656 | { | |
12657 | /* Prepare DMAE related driver resources */ | |
12658 | bnx2x_setup_dmae(bp); | |
12659 | ||
12660 | bnx2x_init_func_obj(bp, &bp->func_obj, | |
12661 | bnx2x_sp(bp, func_rdata), | |
12662 | bnx2x_sp_mapping(bp, func_rdata), | |
a3348722 BW |
12663 | bnx2x_sp(bp, func_afex_rdata), |
12664 | bnx2x_sp_mapping(bp, func_afex_rdata), | |
619c5cb6 VZ |
12665 | &bnx2x_func_sp_drv); |
12666 | } | |
12667 | ||
12668 | /* must be called after sriov-enable */ | |
1191cb83 | 12669 | static int bnx2x_set_qm_cid_count(struct bnx2x *bp) |
523224a3 | 12670 | { |
37ae41a9 | 12671 | int cid_count = BNX2X_L2_MAX_CID(bp); |
94a78b79 | 12672 | |
290ca2bb AE |
12673 | if (IS_SRIOV(bp)) |
12674 | cid_count += BNX2X_VF_CIDS; | |
12675 | ||
55c11941 MS |
12676 | if (CNIC_SUPPORT(bp)) |
12677 | cid_count += CNIC_CID_MAX; | |
290ca2bb | 12678 | |
523224a3 DK |
12679 | return roundup(cid_count, QM_CID_ROUND); |
12680 | } | |
f85582f8 | 12681 | |
619c5cb6 | 12682 | /** |
6383c0b3 | 12683 | * bnx2x_get_num_none_def_sbs - return the number of none default SBs |
619c5cb6 VZ |
12684 | * |
12685 | * @dev: pci device | |
12686 | * | |
12687 | */ | |
60cad4e6 | 12688 | static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt) |
619c5cb6 | 12689 | { |
ae2104be | 12690 | int index; |
1ab4434c | 12691 | u16 control = 0; |
619c5cb6 | 12692 | |
6383c0b3 AE |
12693 | /* |
12694 | * If MSI-X is not supported - return number of SBs needed to support | |
12695 | * one fast path queue: one FP queue + SB for CNIC | |
12696 | */ | |
ae2104be | 12697 | if (!pdev->msix_cap) { |
1ab4434c | 12698 | dev_info(&pdev->dev, "no msix capability found\n"); |
55c11941 | 12699 | return 1 + cnic_cnt; |
1ab4434c AE |
12700 | } |
12701 | dev_info(&pdev->dev, "msix capability found\n"); | |
619c5cb6 | 12702 | |
6383c0b3 AE |
12703 | /* |
12704 | * The value in the PCI configuration space is the index of the last | |
12705 | * entry, namely one less than the actual size of the table, which is | |
12706 | * exactly what we want to return from this function: number of all SBs | |
12707 | * without the default SB. | |
1ab4434c | 12708 | * For VFs there is no default SB, then we return (index+1). |
6383c0b3 | 12709 | */ |
ae2104be | 12710 | pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control); |
619c5cb6 | 12711 | |
1ab4434c | 12712 | index = control & PCI_MSIX_FLAGS_QSIZE; |
4bd9b0ff | 12713 | |
60cad4e6 | 12714 | return index; |
1ab4434c | 12715 | } |
523224a3 | 12716 | |
1ab4434c AE |
12717 | static int set_max_cos_est(int chip_id) |
12718 | { | |
12719 | switch (chip_id) { | |
f2e0899f DK |
12720 | case BCM57710: |
12721 | case BCM57711: | |
12722 | case BCM57711E: | |
1ab4434c | 12723 | return BNX2X_MULTI_TX_COS_E1X; |
f2e0899f | 12724 | case BCM57712: |
619c5cb6 | 12725 | case BCM57712_MF: |
1ab4434c | 12726 | return BNX2X_MULTI_TX_COS_E2_E3A0; |
619c5cb6 VZ |
12727 | case BCM57800: |
12728 | case BCM57800_MF: | |
12729 | case BCM57810: | |
12730 | case BCM57810_MF: | |
c3def943 YM |
12731 | case BCM57840_4_10: |
12732 | case BCM57840_2_20: | |
1ab4434c | 12733 | case BCM57840_O: |
c3def943 | 12734 | case BCM57840_MFO: |
619c5cb6 | 12735 | case BCM57840_MF: |
7e8e02df BW |
12736 | case BCM57811: |
12737 | case BCM57811_MF: | |
1ab4434c | 12738 | return BNX2X_MULTI_TX_COS_E3B0; |
b1239723 YM |
12739 | case BCM57712_VF: |
12740 | case BCM57800_VF: | |
12741 | case BCM57810_VF: | |
12742 | case BCM57840_VF: | |
12743 | case BCM57811_VF: | |
1ab4434c | 12744 | return 1; |
f2e0899f | 12745 | default: |
1ab4434c | 12746 | pr_err("Unknown board_type (%d), aborting\n", chip_id); |
870634b0 | 12747 | return -ENODEV; |
f2e0899f | 12748 | } |
1ab4434c | 12749 | } |
f2e0899f | 12750 | |
1ab4434c AE |
12751 | static int set_is_vf(int chip_id) |
12752 | { | |
12753 | switch (chip_id) { | |
12754 | case BCM57712_VF: | |
12755 | case BCM57800_VF: | |
12756 | case BCM57810_VF: | |
12757 | case BCM57840_VF: | |
12758 | case BCM57811_VF: | |
12759 | return true; | |
12760 | default: | |
12761 | return false; | |
12762 | } | |
12763 | } | |
6383c0b3 | 12764 | |
1ab4434c AE |
12765 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev); |
12766 | ||
12767 | static int bnx2x_init_one(struct pci_dev *pdev, | |
12768 | const struct pci_device_id *ent) | |
12769 | { | |
12770 | struct net_device *dev = NULL; | |
12771 | struct bnx2x *bp; | |
b91e1a1a YM |
12772 | enum pcie_link_width pcie_width; |
12773 | enum pci_bus_speed pcie_speed; | |
1ab4434c AE |
12774 | int rc, max_non_def_sbs; |
12775 | int rx_count, tx_count, rss_count, doorbell_size; | |
12776 | int max_cos_est; | |
12777 | bool is_vf; | |
12778 | int cnic_cnt; | |
12779 | ||
12780 | /* An estimated maximum supported CoS number according to the chip | |
12781 | * version. | |
12782 | * We will try to roughly estimate the maximum number of CoSes this chip | |
12783 | * may support in order to minimize the memory allocated for Tx | |
12784 | * netdev_queue's. This number will be accurately calculated during the | |
12785 | * initialization of bp->max_cos based on the chip versions AND chip | |
12786 | * revision in the bnx2x_init_bp(). | |
12787 | */ | |
12788 | max_cos_est = set_max_cos_est(ent->driver_data); | |
12789 | if (max_cos_est < 0) | |
12790 | return max_cos_est; | |
12791 | is_vf = set_is_vf(ent->driver_data); | |
12792 | cnic_cnt = is_vf ? 0 : 1; | |
12793 | ||
60cad4e6 AE |
12794 | max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt); |
12795 | ||
12796 | /* add another SB for VF as it has no default SB */ | |
12797 | max_non_def_sbs += is_vf ? 1 : 0; | |
6383c0b3 AE |
12798 | |
12799 | /* Maximum number of RSS queues: one IGU SB goes to CNIC */ | |
60cad4e6 | 12800 | rss_count = max_non_def_sbs - cnic_cnt; |
1ab4434c AE |
12801 | |
12802 | if (rss_count < 1) | |
12803 | return -EINVAL; | |
6383c0b3 AE |
12804 | |
12805 | /* Maximum number of netdev Rx queues: RSS + FCoE L2 */ | |
55c11941 | 12806 | rx_count = rss_count + cnic_cnt; |
6383c0b3 | 12807 | |
1ab4434c | 12808 | /* Maximum number of netdev Tx queues: |
37ae41a9 | 12809 | * Maximum TSS queues * Maximum supported number of CoS + FCoE L2 |
6383c0b3 | 12810 | */ |
55c11941 | 12811 | tx_count = rss_count * max_cos_est + cnic_cnt; |
f85582f8 | 12812 | |
a2fbb9ea | 12813 | /* dev zeroed in init_etherdev */ |
6383c0b3 | 12814 | dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count); |
41de8d4c | 12815 | if (!dev) |
a2fbb9ea ET |
12816 | return -ENOMEM; |
12817 | ||
a2fbb9ea | 12818 | bp = netdev_priv(dev); |
a2fbb9ea | 12819 | |
1ab4434c AE |
12820 | bp->flags = 0; |
12821 | if (is_vf) | |
12822 | bp->flags |= IS_VF_FLAG; | |
12823 | ||
6383c0b3 | 12824 | bp->igu_sb_cnt = max_non_def_sbs; |
1ab4434c | 12825 | bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM; |
6383c0b3 | 12826 | bp->msg_enable = debug; |
55c11941 | 12827 | bp->cnic_support = cnic_cnt; |
4bd9b0ff | 12828 | bp->cnic_probe = bnx2x_cnic_probe; |
55c11941 | 12829 | |
6383c0b3 | 12830 | pci_set_drvdata(pdev, dev); |
523224a3 | 12831 | |
1ab4434c | 12832 | rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data); |
a2fbb9ea ET |
12833 | if (rc < 0) { |
12834 | free_netdev(dev); | |
12835 | return rc; | |
12836 | } | |
12837 | ||
1ab4434c AE |
12838 | BNX2X_DEV_INFO("This is a %s function\n", |
12839 | IS_PF(bp) ? "physical" : "virtual"); | |
55c11941 | 12840 | BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off"); |
1ab4434c | 12841 | BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs); |
60aa0509 | 12842 | BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n", |
2de67439 | 12843 | tx_count, rx_count); |
60aa0509 | 12844 | |
34f80b04 | 12845 | rc = bnx2x_init_bp(bp); |
693fc0d1 EG |
12846 | if (rc) |
12847 | goto init_one_exit; | |
12848 | ||
1ab4434c AE |
12849 | /* Map doorbells here as we need the real value of bp->max_cos which |
12850 | * is initialized in bnx2x_init_bp() to determine the number of | |
12851 | * l2 connections. | |
6383c0b3 | 12852 | */ |
1ab4434c | 12853 | if (IS_VF(bp)) { |
1d6f3cd8 | 12854 | bp->doorbells = bnx2x_vf_doorbells(bp); |
6411280a AE |
12855 | rc = bnx2x_vf_pci_alloc(bp); |
12856 | if (rc) | |
12857 | goto init_one_exit; | |
1ab4434c AE |
12858 | } else { |
12859 | doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT); | |
12860 | if (doorbell_size > pci_resource_len(pdev, 2)) { | |
12861 | dev_err(&bp->pdev->dev, | |
12862 | "Cannot map doorbells, bar size too small, aborting\n"); | |
12863 | rc = -ENOMEM; | |
12864 | goto init_one_exit; | |
12865 | } | |
12866 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), | |
12867 | doorbell_size); | |
37ae41a9 | 12868 | } |
6383c0b3 AE |
12869 | if (!bp->doorbells) { |
12870 | dev_err(&bp->pdev->dev, | |
12871 | "Cannot map doorbell space, aborting\n"); | |
12872 | rc = -ENOMEM; | |
12873 | goto init_one_exit; | |
12874 | } | |
12875 | ||
be1f1ffa AE |
12876 | if (IS_VF(bp)) { |
12877 | rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count); | |
12878 | if (rc) | |
12879 | goto init_one_exit; | |
12880 | } | |
12881 | ||
3c76feff AE |
12882 | /* Enable SRIOV if capability found in configuration space */ |
12883 | rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS); | |
290ca2bb AE |
12884 | if (rc) |
12885 | goto init_one_exit; | |
12886 | ||
523224a3 | 12887 | /* calc qm_cid_count */ |
6383c0b3 | 12888 | bp->qm_cid_count = bnx2x_set_qm_cid_count(bp); |
1ab4434c | 12889 | BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count); |
523224a3 | 12890 | |
55c11941 | 12891 | /* disable FCOE L2 queue for E1x*/ |
62ac0dc9 | 12892 | if (CHIP_IS_E1x(bp)) |
ec6ba945 VZ |
12893 | bp->flags |= NO_FCOE_FLAG; |
12894 | ||
0e8d2ec5 MS |
12895 | /* Set bp->num_queues for MSI-X mode*/ |
12896 | bnx2x_set_num_queues(bp); | |
12897 | ||
25985edc | 12898 | /* Configure interrupt mode: try to enable MSI-X/MSI if |
0e8d2ec5 | 12899 | * needed. |
d6214d7a | 12900 | */ |
1ab4434c AE |
12901 | rc = bnx2x_set_int_mode(bp); |
12902 | if (rc) { | |
12903 | dev_err(&pdev->dev, "Cannot set interrupts\n"); | |
12904 | goto init_one_exit; | |
12905 | } | |
04c46736 | 12906 | BNX2X_DEV_INFO("set interrupts successfully\n"); |
d6214d7a | 12907 | |
1ab4434c | 12908 | /* register the net device */ |
b340007f VZ |
12909 | rc = register_netdev(dev); |
12910 | if (rc) { | |
12911 | dev_err(&pdev->dev, "Cannot register net device\n"); | |
12912 | goto init_one_exit; | |
12913 | } | |
1ab4434c | 12914 | BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name); |
b340007f | 12915 | |
ec6ba945 VZ |
12916 | if (!NO_FCOE(bp)) { |
12917 | /* Add storage MAC address */ | |
12918 | rtnl_lock(); | |
12919 | dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
12920 | rtnl_unlock(); | |
12921 | } | |
b91e1a1a YM |
12922 | if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) || |
12923 | pcie_speed == PCI_SPEED_UNKNOWN || | |
12924 | pcie_width == PCIE_LNK_WIDTH_UNKNOWN) | |
12925 | BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n"); | |
12926 | else | |
12927 | BNX2X_DEV_INFO( | |
12928 | "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n", | |
ca1ee4b2 DK |
12929 | board_info[ent->driver_data].name, |
12930 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), | |
12931 | pcie_width, | |
b91e1a1a YM |
12932 | pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" : |
12933 | pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" : | |
12934 | pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" : | |
ca1ee4b2 DK |
12935 | "Unknown", |
12936 | dev->base_addr, bp->pdev->irq, dev->dev_addr); | |
c016201c | 12937 | |
a2fbb9ea | 12938 | return 0; |
34f80b04 EG |
12939 | |
12940 | init_one_exit: | |
12941 | if (bp->regview) | |
12942 | iounmap(bp->regview); | |
12943 | ||
1ab4434c | 12944 | if (IS_PF(bp) && bp->doorbells) |
34f80b04 EG |
12945 | iounmap(bp->doorbells); |
12946 | ||
12947 | free_netdev(dev); | |
12948 | ||
12949 | if (atomic_read(&pdev->enable_cnt) == 1) | |
12950 | pci_release_regions(pdev); | |
12951 | ||
12952 | pci_disable_device(pdev); | |
34f80b04 EG |
12953 | |
12954 | return rc; | |
a2fbb9ea ET |
12955 | } |
12956 | ||
b030ed2f YM |
12957 | static void __bnx2x_remove(struct pci_dev *pdev, |
12958 | struct net_device *dev, | |
12959 | struct bnx2x *bp, | |
12960 | bool remove_netdev) | |
a2fbb9ea | 12961 | { |
ec6ba945 VZ |
12962 | /* Delete storage MAC address */ |
12963 | if (!NO_FCOE(bp)) { | |
12964 | rtnl_lock(); | |
12965 | dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
12966 | rtnl_unlock(); | |
12967 | } | |
ec6ba945 | 12968 | |
98507672 SR |
12969 | #ifdef BCM_DCBNL |
12970 | /* Delete app tlvs from dcbnl */ | |
12971 | bnx2x_dcbnl_update_applist(bp, true); | |
12972 | #endif | |
12973 | ||
a6d3a5ba BW |
12974 | if (IS_PF(bp) && |
12975 | !BP_NOMCP(bp) && | |
12976 | (bp->flags & BC_SUPPORTS_RMMOD_CMD)) | |
12977 | bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0); | |
12978 | ||
b030ed2f YM |
12979 | /* Close the interface - either directly or implicitly */ |
12980 | if (remove_netdev) { | |
12981 | unregister_netdev(dev); | |
12982 | } else { | |
12983 | rtnl_lock(); | |
6ef5a92c | 12984 | dev_close(dev); |
b030ed2f YM |
12985 | rtnl_unlock(); |
12986 | } | |
a2fbb9ea | 12987 | |
78c3bcc5 AE |
12988 | bnx2x_iov_remove_one(bp); |
12989 | ||
084d6cbb | 12990 | /* Power on: we can't let PCI layer write to us while we are in D3 */ |
1ab4434c AE |
12991 | if (IS_PF(bp)) |
12992 | bnx2x_set_power_state(bp, PCI_D0); | |
084d6cbb | 12993 | |
d6214d7a DK |
12994 | /* Disable MSI/MSI-X */ |
12995 | bnx2x_disable_msi(bp); | |
f85582f8 | 12996 | |
084d6cbb | 12997 | /* Power off */ |
1ab4434c AE |
12998 | if (IS_PF(bp)) |
12999 | bnx2x_set_power_state(bp, PCI_D3hot); | |
084d6cbb | 13000 | |
72fd0718 | 13001 | /* Make sure RESET task is not scheduled before continuing */ |
7be08a72 | 13002 | cancel_delayed_work_sync(&bp->sp_rtnl_task); |
290ca2bb | 13003 | |
4513f925 AE |
13004 | /* send message via vfpf channel to release the resources of this vf */ |
13005 | if (IS_VF(bp)) | |
13006 | bnx2x_vfpf_release(bp); | |
72fd0718 | 13007 | |
b030ed2f YM |
13008 | /* Assumes no further PCIe PM changes will occur */ |
13009 | if (system_state == SYSTEM_POWER_OFF) { | |
13010 | pci_wake_from_d3(pdev, bp->wol); | |
13011 | pci_set_power_state(pdev, PCI_D3hot); | |
13012 | } | |
13013 | ||
a2fbb9ea ET |
13014 | if (bp->regview) |
13015 | iounmap(bp->regview); | |
13016 | ||
1ab4434c AE |
13017 | /* for vf doorbells are part of the regview and were unmapped along with |
13018 | * it. FW is only loaded by PF. | |
13019 | */ | |
13020 | if (IS_PF(bp)) { | |
13021 | if (bp->doorbells) | |
13022 | iounmap(bp->doorbells); | |
eb2afd4a | 13023 | |
1ab4434c AE |
13024 | bnx2x_release_firmware(bp); |
13025 | } | |
523224a3 DK |
13026 | bnx2x_free_mem_bp(bp); |
13027 | ||
b030ed2f YM |
13028 | if (remove_netdev) |
13029 | free_netdev(dev); | |
34f80b04 EG |
13030 | |
13031 | if (atomic_read(&pdev->enable_cnt) == 1) | |
13032 | pci_release_regions(pdev); | |
13033 | ||
a2fbb9ea | 13034 | pci_disable_device(pdev); |
a2fbb9ea ET |
13035 | } |
13036 | ||
b030ed2f YM |
13037 | static void bnx2x_remove_one(struct pci_dev *pdev) |
13038 | { | |
13039 | struct net_device *dev = pci_get_drvdata(pdev); | |
13040 | struct bnx2x *bp; | |
13041 | ||
13042 | if (!dev) { | |
13043 | dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n"); | |
13044 | return; | |
13045 | } | |
13046 | bp = netdev_priv(dev); | |
13047 | ||
13048 | __bnx2x_remove(pdev, dev, bp, true); | |
13049 | } | |
13050 | ||
f8ef6e44 YG |
13051 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
13052 | { | |
7fa6f340 | 13053 | bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT; |
f8ef6e44 YG |
13054 | |
13055 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
13056 | ||
55c11941 MS |
13057 | if (CNIC_LOADED(bp)) |
13058 | bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD); | |
13059 | ||
619c5cb6 VZ |
13060 | /* Stop Tx */ |
13061 | bnx2x_tx_disable(bp); | |
26614ba5 MS |
13062 | /* Delete all NAPI objects */ |
13063 | bnx2x_del_all_napi(bp); | |
55c11941 MS |
13064 | if (CNIC_LOADED(bp)) |
13065 | bnx2x_del_all_napi_cnic(bp); | |
7fa6f340 | 13066 | netdev_reset_tc(bp->dev); |
f8ef6e44 YG |
13067 | |
13068 | del_timer_sync(&bp->timer); | |
7fa6f340 YM |
13069 | cancel_delayed_work(&bp->sp_task); |
13070 | cancel_delayed_work(&bp->period_task); | |
619c5cb6 | 13071 | |
7fa6f340 YM |
13072 | spin_lock_bh(&bp->stats_lock); |
13073 | bp->stats_state = STATS_STATE_DISABLED; | |
13074 | spin_unlock_bh(&bp->stats_lock); | |
f8ef6e44 | 13075 | |
7fa6f340 | 13076 | bnx2x_save_statistics(bp); |
f8ef6e44 | 13077 | |
619c5cb6 VZ |
13078 | netif_carrier_off(bp->dev); |
13079 | ||
f8ef6e44 YG |
13080 | return 0; |
13081 | } | |
13082 | ||
493adb1f WX |
13083 | /** |
13084 | * bnx2x_io_error_detected - called when PCI error is detected | |
13085 | * @pdev: Pointer to PCI device | |
13086 | * @state: The current pci connection state | |
13087 | * | |
13088 | * This function is called after a PCI bus error affecting | |
13089 | * this device has been detected. | |
13090 | */ | |
13091 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, | |
13092 | pci_channel_state_t state) | |
13093 | { | |
13094 | struct net_device *dev = pci_get_drvdata(pdev); | |
13095 | struct bnx2x *bp = netdev_priv(dev); | |
13096 | ||
13097 | rtnl_lock(); | |
13098 | ||
7fa6f340 YM |
13099 | BNX2X_ERR("IO error detected\n"); |
13100 | ||
493adb1f WX |
13101 | netif_device_detach(dev); |
13102 | ||
07ce50e4 DN |
13103 | if (state == pci_channel_io_perm_failure) { |
13104 | rtnl_unlock(); | |
13105 | return PCI_ERS_RESULT_DISCONNECT; | |
13106 | } | |
13107 | ||
493adb1f | 13108 | if (netif_running(dev)) |
f8ef6e44 | 13109 | bnx2x_eeh_nic_unload(bp); |
493adb1f | 13110 | |
7fa6f340 YM |
13111 | bnx2x_prev_path_mark_eeh(bp); |
13112 | ||
493adb1f WX |
13113 | pci_disable_device(pdev); |
13114 | ||
13115 | rtnl_unlock(); | |
13116 | ||
13117 | /* Request a slot reset */ | |
13118 | return PCI_ERS_RESULT_NEED_RESET; | |
13119 | } | |
13120 | ||
13121 | /** | |
13122 | * bnx2x_io_slot_reset - called after the PCI bus has been reset | |
13123 | * @pdev: Pointer to PCI device | |
13124 | * | |
13125 | * Restart the card from scratch, as if from a cold-boot. | |
13126 | */ | |
13127 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) | |
13128 | { | |
13129 | struct net_device *dev = pci_get_drvdata(pdev); | |
13130 | struct bnx2x *bp = netdev_priv(dev); | |
7fa6f340 | 13131 | int i; |
493adb1f WX |
13132 | |
13133 | rtnl_lock(); | |
7fa6f340 | 13134 | BNX2X_ERR("IO slot reset initializing...\n"); |
493adb1f WX |
13135 | if (pci_enable_device(pdev)) { |
13136 | dev_err(&pdev->dev, | |
13137 | "Cannot re-enable PCI device after reset\n"); | |
13138 | rtnl_unlock(); | |
13139 | return PCI_ERS_RESULT_DISCONNECT; | |
13140 | } | |
13141 | ||
13142 | pci_set_master(pdev); | |
13143 | pci_restore_state(pdev); | |
70632d0a | 13144 | pci_save_state(pdev); |
493adb1f WX |
13145 | |
13146 | if (netif_running(dev)) | |
13147 | bnx2x_set_power_state(bp, PCI_D0); | |
13148 | ||
7fa6f340 YM |
13149 | if (netif_running(dev)) { |
13150 | BNX2X_ERR("IO slot reset --> driver unload\n"); | |
e68072ef YM |
13151 | |
13152 | /* MCP should have been reset; Need to wait for validity */ | |
13153 | bnx2x_init_shmem(bp); | |
13154 | ||
7fa6f340 YM |
13155 | if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) { |
13156 | u32 v; | |
13157 | ||
13158 | v = SHMEM2_RD(bp, | |
13159 | drv_capabilities_flag[BP_FW_MB_IDX(bp)]); | |
13160 | SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)], | |
13161 | v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2); | |
13162 | } | |
13163 | bnx2x_drain_tx_queues(bp); | |
13164 | bnx2x_send_unload_req(bp, UNLOAD_RECOVERY); | |
13165 | bnx2x_netif_stop(bp, 1); | |
13166 | bnx2x_free_irq(bp); | |
13167 | ||
13168 | /* Report UNLOAD_DONE to MCP */ | |
13169 | bnx2x_send_unload_done(bp, true); | |
13170 | ||
13171 | bp->sp_state = 0; | |
13172 | bp->port.pmf = 0; | |
13173 | ||
13174 | bnx2x_prev_unload(bp); | |
13175 | ||
16a5fd92 | 13176 | /* We should have reseted the engine, so It's fair to |
7fa6f340 YM |
13177 | * assume the FW will no longer write to the bnx2x driver. |
13178 | */ | |
13179 | bnx2x_squeeze_objects(bp); | |
13180 | bnx2x_free_skbs(bp); | |
13181 | for_each_rx_queue(bp, i) | |
13182 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); | |
13183 | bnx2x_free_fp_mem(bp); | |
13184 | bnx2x_free_mem(bp); | |
13185 | ||
13186 | bp->state = BNX2X_STATE_CLOSED; | |
13187 | } | |
13188 | ||
493adb1f WX |
13189 | rtnl_unlock(); |
13190 | ||
13191 | return PCI_ERS_RESULT_RECOVERED; | |
13192 | } | |
13193 | ||
13194 | /** | |
13195 | * bnx2x_io_resume - called when traffic can start flowing again | |
13196 | * @pdev: Pointer to PCI device | |
13197 | * | |
13198 | * This callback is called when the error recovery driver tells us that | |
13199 | * its OK to resume normal operation. | |
13200 | */ | |
13201 | static void bnx2x_io_resume(struct pci_dev *pdev) | |
13202 | { | |
13203 | struct net_device *dev = pci_get_drvdata(pdev); | |
13204 | struct bnx2x *bp = netdev_priv(dev); | |
13205 | ||
72fd0718 | 13206 | if (bp->recovery_state != BNX2X_RECOVERY_DONE) { |
51c1a580 | 13207 | netdev_err(bp->dev, "Handling parity error recovery. Try again later\n"); |
72fd0718 VZ |
13208 | return; |
13209 | } | |
13210 | ||
493adb1f WX |
13211 | rtnl_lock(); |
13212 | ||
7fa6f340 YM |
13213 | bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & |
13214 | DRV_MSG_SEQ_NUMBER_MASK; | |
13215 | ||
493adb1f | 13216 | if (netif_running(dev)) |
f8ef6e44 | 13217 | bnx2x_nic_load(bp, LOAD_NORMAL); |
493adb1f WX |
13218 | |
13219 | netif_device_attach(dev); | |
13220 | ||
13221 | rtnl_unlock(); | |
13222 | } | |
13223 | ||
3646f0e5 | 13224 | static const struct pci_error_handlers bnx2x_err_handler = { |
493adb1f | 13225 | .error_detected = bnx2x_io_error_detected, |
356e2385 EG |
13226 | .slot_reset = bnx2x_io_slot_reset, |
13227 | .resume = bnx2x_io_resume, | |
493adb1f WX |
13228 | }; |
13229 | ||
b030ed2f YM |
13230 | static void bnx2x_shutdown(struct pci_dev *pdev) |
13231 | { | |
13232 | struct net_device *dev = pci_get_drvdata(pdev); | |
13233 | struct bnx2x *bp; | |
13234 | ||
13235 | if (!dev) | |
13236 | return; | |
13237 | ||
13238 | bp = netdev_priv(dev); | |
13239 | if (!bp) | |
13240 | return; | |
13241 | ||
13242 | rtnl_lock(); | |
13243 | netif_device_detach(dev); | |
13244 | rtnl_unlock(); | |
13245 | ||
13246 | /* Don't remove the netdevice, as there are scenarios which will cause | |
13247 | * the kernel to hang, e.g., when trying to remove bnx2i while the | |
13248 | * rootfs is mounted from SAN. | |
13249 | */ | |
13250 | __bnx2x_remove(pdev, dev, bp, false); | |
13251 | } | |
13252 | ||
a2fbb9ea | 13253 | static struct pci_driver bnx2x_pci_driver = { |
493adb1f WX |
13254 | .name = DRV_MODULE_NAME, |
13255 | .id_table = bnx2x_pci_tbl, | |
13256 | .probe = bnx2x_init_one, | |
0329aba1 | 13257 | .remove = bnx2x_remove_one, |
493adb1f WX |
13258 | .suspend = bnx2x_suspend, |
13259 | .resume = bnx2x_resume, | |
13260 | .err_handler = &bnx2x_err_handler, | |
3c76feff AE |
13261 | #ifdef CONFIG_BNX2X_SRIOV |
13262 | .sriov_configure = bnx2x_sriov_configure, | |
13263 | #endif | |
b030ed2f | 13264 | .shutdown = bnx2x_shutdown, |
a2fbb9ea ET |
13265 | }; |
13266 | ||
13267 | static int __init bnx2x_init(void) | |
13268 | { | |
dd21ca6d SG |
13269 | int ret; |
13270 | ||
7995c64e | 13271 | pr_info("%s", version); |
938cf541 | 13272 | |
1cf167f2 EG |
13273 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
13274 | if (bnx2x_wq == NULL) { | |
7995c64e | 13275 | pr_err("Cannot create workqueue\n"); |
1cf167f2 EG |
13276 | return -ENOMEM; |
13277 | } | |
13278 | ||
dd21ca6d SG |
13279 | ret = pci_register_driver(&bnx2x_pci_driver); |
13280 | if (ret) { | |
7995c64e | 13281 | pr_err("Cannot register driver\n"); |
dd21ca6d SG |
13282 | destroy_workqueue(bnx2x_wq); |
13283 | } | |
13284 | return ret; | |
a2fbb9ea ET |
13285 | } |
13286 | ||
13287 | static void __exit bnx2x_cleanup(void) | |
13288 | { | |
452427b0 | 13289 | struct list_head *pos, *q; |
d76a6111 | 13290 | |
a2fbb9ea | 13291 | pci_unregister_driver(&bnx2x_pci_driver); |
1cf167f2 EG |
13292 | |
13293 | destroy_workqueue(bnx2x_wq); | |
452427b0 | 13294 | |
16a5fd92 | 13295 | /* Free globally allocated resources */ |
452427b0 YM |
13296 | list_for_each_safe(pos, q, &bnx2x_prev_list) { |
13297 | struct bnx2x_prev_path_list *tmp = | |
13298 | list_entry(pos, struct bnx2x_prev_path_list, list); | |
13299 | list_del(pos); | |
13300 | kfree(tmp); | |
13301 | } | |
a2fbb9ea ET |
13302 | } |
13303 | ||
3deb8167 YR |
13304 | void bnx2x_notify_link_changed(struct bnx2x *bp) |
13305 | { | |
13306 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1); | |
13307 | } | |
13308 | ||
a2fbb9ea ET |
13309 | module_init(bnx2x_init); |
13310 | module_exit(bnx2x_cleanup); | |
13311 | ||
619c5cb6 VZ |
13312 | /** |
13313 | * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s). | |
13314 | * | |
13315 | * @bp: driver handle | |
13316 | * @set: set or clear the CAM entry | |
13317 | * | |
16a5fd92 | 13318 | * This function will wait until the ramrod completion returns. |
619c5cb6 VZ |
13319 | * Return 0 if success, -ENODEV if ramrod doesn't return. |
13320 | */ | |
1191cb83 | 13321 | static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp) |
619c5cb6 VZ |
13322 | { |
13323 | unsigned long ramrod_flags = 0; | |
13324 | ||
13325 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
13326 | return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac, | |
13327 | &bp->iscsi_l2_mac_obj, true, | |
13328 | BNX2X_ISCSI_ETH_MAC, &ramrod_flags); | |
13329 | } | |
993ac7b5 MC |
13330 | |
13331 | /* count denotes the number of new completions we have seen */ | |
13332 | static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count) | |
13333 | { | |
13334 | struct eth_spe *spe; | |
a052997e | 13335 | int cxt_index, cxt_offset; |
993ac7b5 MC |
13336 | |
13337 | #ifdef BNX2X_STOP_ON_ERROR | |
13338 | if (unlikely(bp->panic)) | |
13339 | return; | |
13340 | #endif | |
13341 | ||
13342 | spin_lock_bh(&bp->spq_lock); | |
c2bff63f | 13343 | BUG_ON(bp->cnic_spq_pending < count); |
993ac7b5 MC |
13344 | bp->cnic_spq_pending -= count; |
13345 | ||
c2bff63f DK |
13346 | for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) { |
13347 | u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type) | |
13348 | & SPE_HDR_CONN_TYPE) >> | |
13349 | SPE_HDR_CONN_TYPE_SHIFT; | |
619c5cb6 VZ |
13350 | u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data) |
13351 | >> SPE_HDR_CMD_ID_SHIFT) & 0xff; | |
c2bff63f DK |
13352 | |
13353 | /* Set validation for iSCSI L2 client before sending SETUP | |
13354 | * ramrod | |
13355 | */ | |
13356 | if (type == ETH_CONNECTION_TYPE) { | |
a052997e | 13357 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) { |
37ae41a9 | 13358 | cxt_index = BNX2X_ISCSI_ETH_CID(bp) / |
a052997e | 13359 | ILT_PAGE_CIDS; |
37ae41a9 | 13360 | cxt_offset = BNX2X_ISCSI_ETH_CID(bp) - |
a052997e MS |
13361 | (cxt_index * ILT_PAGE_CIDS); |
13362 | bnx2x_set_ctx_validation(bp, | |
13363 | &bp->context[cxt_index]. | |
13364 | vcxt[cxt_offset].eth, | |
37ae41a9 | 13365 | BNX2X_ISCSI_ETH_CID(bp)); |
a052997e | 13366 | } |
c2bff63f DK |
13367 | } |
13368 | ||
619c5cb6 VZ |
13369 | /* |
13370 | * There may be not more than 8 L2, not more than 8 L5 SPEs | |
13371 | * and in the air. We also check that number of outstanding | |
6e30dd4e VZ |
13372 | * COMMON ramrods is not more than the EQ and SPQ can |
13373 | * accommodate. | |
c2bff63f | 13374 | */ |
6e30dd4e VZ |
13375 | if (type == ETH_CONNECTION_TYPE) { |
13376 | if (!atomic_read(&bp->cq_spq_left)) | |
13377 | break; | |
13378 | else | |
13379 | atomic_dec(&bp->cq_spq_left); | |
13380 | } else if (type == NONE_CONNECTION_TYPE) { | |
13381 | if (!atomic_read(&bp->eq_spq_left)) | |
c2bff63f DK |
13382 | break; |
13383 | else | |
6e30dd4e | 13384 | atomic_dec(&bp->eq_spq_left); |
ec6ba945 VZ |
13385 | } else if ((type == ISCSI_CONNECTION_TYPE) || |
13386 | (type == FCOE_CONNECTION_TYPE)) { | |
c2bff63f DK |
13387 | if (bp->cnic_spq_pending >= |
13388 | bp->cnic_eth_dev.max_kwqe_pending) | |
13389 | break; | |
13390 | else | |
13391 | bp->cnic_spq_pending++; | |
13392 | } else { | |
13393 | BNX2X_ERR("Unknown SPE type: %d\n", type); | |
13394 | bnx2x_panic(); | |
993ac7b5 | 13395 | break; |
c2bff63f | 13396 | } |
993ac7b5 MC |
13397 | |
13398 | spe = bnx2x_sp_get_next(bp); | |
13399 | *spe = *bp->cnic_kwq_cons; | |
13400 | ||
51c1a580 | 13401 | DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n", |
993ac7b5 MC |
13402 | bp->cnic_spq_pending, bp->cnic_kwq_pending, count); |
13403 | ||
13404 | if (bp->cnic_kwq_cons == bp->cnic_kwq_last) | |
13405 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
13406 | else | |
13407 | bp->cnic_kwq_cons++; | |
13408 | } | |
13409 | bnx2x_sp_prod_update(bp); | |
13410 | spin_unlock_bh(&bp->spq_lock); | |
13411 | } | |
13412 | ||
13413 | static int bnx2x_cnic_sp_queue(struct net_device *dev, | |
13414 | struct kwqe_16 *kwqes[], u32 count) | |
13415 | { | |
13416 | struct bnx2x *bp = netdev_priv(dev); | |
13417 | int i; | |
13418 | ||
13419 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 MS |
13420 | if (unlikely(bp->panic)) { |
13421 | BNX2X_ERR("Can't post to SP queue while panic\n"); | |
993ac7b5 | 13422 | return -EIO; |
51c1a580 | 13423 | } |
993ac7b5 MC |
13424 | #endif |
13425 | ||
95c6c616 AE |
13426 | if ((bp->recovery_state != BNX2X_RECOVERY_DONE) && |
13427 | (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) { | |
51c1a580 | 13428 | BNX2X_ERR("Handling parity error recovery. Try again later\n"); |
95c6c616 AE |
13429 | return -EAGAIN; |
13430 | } | |
13431 | ||
993ac7b5 MC |
13432 | spin_lock_bh(&bp->spq_lock); |
13433 | ||
13434 | for (i = 0; i < count; i++) { | |
13435 | struct eth_spe *spe = (struct eth_spe *)kwqes[i]; | |
13436 | ||
13437 | if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT) | |
13438 | break; | |
13439 | ||
13440 | *bp->cnic_kwq_prod = *spe; | |
13441 | ||
13442 | bp->cnic_kwq_pending++; | |
13443 | ||
51c1a580 | 13444 | DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n", |
993ac7b5 | 13445 | spe->hdr.conn_and_cmd_data, spe->hdr.type, |
523224a3 DK |
13446 | spe->data.update_data_addr.hi, |
13447 | spe->data.update_data_addr.lo, | |
993ac7b5 MC |
13448 | bp->cnic_kwq_pending); |
13449 | ||
13450 | if (bp->cnic_kwq_prod == bp->cnic_kwq_last) | |
13451 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
13452 | else | |
13453 | bp->cnic_kwq_prod++; | |
13454 | } | |
13455 | ||
13456 | spin_unlock_bh(&bp->spq_lock); | |
13457 | ||
13458 | if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending) | |
13459 | bnx2x_cnic_sp_post(bp, 0); | |
13460 | ||
13461 | return i; | |
13462 | } | |
13463 | ||
13464 | static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
13465 | { | |
13466 | struct cnic_ops *c_ops; | |
13467 | int rc = 0; | |
13468 | ||
13469 | mutex_lock(&bp->cnic_mutex); | |
13707f9e ED |
13470 | c_ops = rcu_dereference_protected(bp->cnic_ops, |
13471 | lockdep_is_held(&bp->cnic_mutex)); | |
993ac7b5 MC |
13472 | if (c_ops) |
13473 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
13474 | mutex_unlock(&bp->cnic_mutex); | |
13475 | ||
13476 | return rc; | |
13477 | } | |
13478 | ||
13479 | static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
13480 | { | |
13481 | struct cnic_ops *c_ops; | |
13482 | int rc = 0; | |
13483 | ||
13484 | rcu_read_lock(); | |
13485 | c_ops = rcu_dereference(bp->cnic_ops); | |
13486 | if (c_ops) | |
13487 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
13488 | rcu_read_unlock(); | |
13489 | ||
13490 | return rc; | |
13491 | } | |
13492 | ||
13493 | /* | |
13494 | * for commands that have no data | |
13495 | */ | |
9f6c9258 | 13496 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd) |
993ac7b5 MC |
13497 | { |
13498 | struct cnic_ctl_info ctl = {0}; | |
13499 | ||
13500 | ctl.cmd = cmd; | |
13501 | ||
13502 | return bnx2x_cnic_ctl_send(bp, &ctl); | |
13503 | } | |
13504 | ||
619c5cb6 | 13505 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err) |
993ac7b5 | 13506 | { |
619c5cb6 | 13507 | struct cnic_ctl_info ctl = {0}; |
993ac7b5 MC |
13508 | |
13509 | /* first we tell CNIC and only then we count this as a completion */ | |
13510 | ctl.cmd = CNIC_CTL_COMPLETION_CMD; | |
13511 | ctl.data.comp.cid = cid; | |
619c5cb6 | 13512 | ctl.data.comp.error = err; |
993ac7b5 MC |
13513 | |
13514 | bnx2x_cnic_ctl_send_bh(bp, &ctl); | |
c2bff63f | 13515 | bnx2x_cnic_sp_post(bp, 0); |
993ac7b5 MC |
13516 | } |
13517 | ||
619c5cb6 VZ |
13518 | /* Called with netif_addr_lock_bh() taken. |
13519 | * Sets an rx_mode config for an iSCSI ETH client. | |
13520 | * Doesn't block. | |
13521 | * Completion should be checked outside. | |
13522 | */ | |
13523 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start) | |
13524 | { | |
13525 | unsigned long accept_flags = 0, ramrod_flags = 0; | |
13526 | u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
13527 | int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED; | |
13528 | ||
13529 | if (start) { | |
13530 | /* Start accepting on iSCSI L2 ring. Accept all multicasts | |
13531 | * because it's the only way for UIO Queue to accept | |
13532 | * multicasts (in non-promiscuous mode only one Queue per | |
13533 | * function will receive multicast packets (leading in our | |
13534 | * case). | |
13535 | */ | |
13536 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags); | |
13537 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags); | |
13538 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags); | |
13539 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); | |
13540 | ||
13541 | /* Clear STOP_PENDING bit if START is requested */ | |
13542 | clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state); | |
13543 | ||
13544 | sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED; | |
13545 | } else | |
13546 | /* Clear START_PENDING bit if STOP is requested */ | |
13547 | clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state); | |
13548 | ||
13549 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
13550 | set_bit(sched_state, &bp->sp_state); | |
13551 | else { | |
13552 | __set_bit(RAMROD_RX, &ramrod_flags); | |
13553 | bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0, | |
13554 | ramrod_flags); | |
13555 | } | |
13556 | } | |
13557 | ||
993ac7b5 MC |
13558 | static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl) |
13559 | { | |
13560 | struct bnx2x *bp = netdev_priv(dev); | |
13561 | int rc = 0; | |
13562 | ||
13563 | switch (ctl->cmd) { | |
13564 | case DRV_CTL_CTXTBL_WR_CMD: { | |
13565 | u32 index = ctl->data.io.offset; | |
13566 | dma_addr_t addr = ctl->data.io.dma_addr; | |
13567 | ||
13568 | bnx2x_ilt_wr(bp, index, addr); | |
13569 | break; | |
13570 | } | |
13571 | ||
c2bff63f DK |
13572 | case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: { |
13573 | int count = ctl->data.credit.credit_count; | |
993ac7b5 MC |
13574 | |
13575 | bnx2x_cnic_sp_post(bp, count); | |
13576 | break; | |
13577 | } | |
13578 | ||
13579 | /* rtnl_lock is held. */ | |
13580 | case DRV_CTL_START_L2_CMD: { | |
619c5cb6 VZ |
13581 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
13582 | unsigned long sp_bits = 0; | |
13583 | ||
13584 | /* Configure the iSCSI classification object */ | |
13585 | bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj, | |
13586 | cp->iscsi_l2_client_id, | |
13587 | cp->iscsi_l2_cid, BP_FUNC(bp), | |
13588 | bnx2x_sp(bp, mac_rdata), | |
13589 | bnx2x_sp_mapping(bp, mac_rdata), | |
13590 | BNX2X_FILTER_MAC_PENDING, | |
13591 | &bp->sp_state, BNX2X_OBJ_TYPE_RX, | |
13592 | &bp->macs_pool); | |
ec6ba945 | 13593 | |
523224a3 | 13594 | /* Set iSCSI MAC address */ |
619c5cb6 VZ |
13595 | rc = bnx2x_set_iscsi_eth_mac_addr(bp); |
13596 | if (rc) | |
13597 | break; | |
523224a3 DK |
13598 | |
13599 | mmiowb(); | |
13600 | barrier(); | |
13601 | ||
619c5cb6 VZ |
13602 | /* Start accepting on iSCSI L2 ring */ |
13603 | ||
13604 | netif_addr_lock_bh(dev); | |
13605 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
13606 | netif_addr_unlock_bh(dev); | |
13607 | ||
13608 | /* bits to wait on */ | |
13609 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
13610 | __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits); | |
13611 | ||
13612 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
13613 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 | 13614 | |
993ac7b5 MC |
13615 | break; |
13616 | } | |
13617 | ||
13618 | /* rtnl_lock is held. */ | |
13619 | case DRV_CTL_STOP_L2_CMD: { | |
619c5cb6 | 13620 | unsigned long sp_bits = 0; |
993ac7b5 | 13621 | |
523224a3 | 13622 | /* Stop accepting on iSCSI L2 ring */ |
619c5cb6 VZ |
13623 | netif_addr_lock_bh(dev); |
13624 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
13625 | netif_addr_unlock_bh(dev); | |
13626 | ||
13627 | /* bits to wait on */ | |
13628 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
13629 | __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits); | |
13630 | ||
13631 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
13632 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 DK |
13633 | |
13634 | mmiowb(); | |
13635 | barrier(); | |
13636 | ||
13637 | /* Unset iSCSI L2 MAC */ | |
619c5cb6 VZ |
13638 | rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj, |
13639 | BNX2X_ISCSI_ETH_MAC, true); | |
993ac7b5 MC |
13640 | break; |
13641 | } | |
c2bff63f DK |
13642 | case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: { |
13643 | int count = ctl->data.credit.credit_count; | |
13644 | ||
13645 | smp_mb__before_atomic_inc(); | |
6e30dd4e | 13646 | atomic_add(count, &bp->cq_spq_left); |
c2bff63f DK |
13647 | smp_mb__after_atomic_inc(); |
13648 | break; | |
13649 | } | |
1d187b34 | 13650 | case DRV_CTL_ULP_REGISTER_CMD: { |
2e499d3c | 13651 | int ulp_type = ctl->data.register_data.ulp_type; |
1d187b34 BW |
13652 | |
13653 | if (CHIP_IS_E3(bp)) { | |
13654 | int idx = BP_FW_MB_IDX(bp); | |
2e499d3c BW |
13655 | u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); |
13656 | int path = BP_PATH(bp); | |
13657 | int port = BP_PORT(bp); | |
13658 | int i; | |
13659 | u32 scratch_offset; | |
13660 | u32 *host_addr; | |
1d187b34 | 13661 | |
2e499d3c | 13662 | /* first write capability to shmem2 */ |
1d187b34 BW |
13663 | if (ulp_type == CNIC_ULP_ISCSI) |
13664 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
13665 | else if (ulp_type == CNIC_ULP_FCOE) | |
13666 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
13667 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
2e499d3c BW |
13668 | |
13669 | if ((ulp_type != CNIC_ULP_FCOE) || | |
13670 | (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) || | |
13671 | (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES))) | |
13672 | break; | |
13673 | ||
13674 | /* if reached here - should write fcoe capabilities */ | |
13675 | scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr); | |
13676 | if (!scratch_offset) | |
13677 | break; | |
13678 | scratch_offset += offsetof(struct glob_ncsi_oem_data, | |
13679 | fcoe_features[path][port]); | |
13680 | host_addr = (u32 *) &(ctl->data.register_data. | |
13681 | fcoe_features); | |
13682 | for (i = 0; i < sizeof(struct fcoe_capabilities); | |
13683 | i += 4) | |
13684 | REG_WR(bp, scratch_offset + i, | |
13685 | *(host_addr + i/4)); | |
1d187b34 BW |
13686 | } |
13687 | break; | |
13688 | } | |
2e499d3c | 13689 | |
1d187b34 BW |
13690 | case DRV_CTL_ULP_UNREGISTER_CMD: { |
13691 | int ulp_type = ctl->data.ulp_type; | |
13692 | ||
13693 | if (CHIP_IS_E3(bp)) { | |
13694 | int idx = BP_FW_MB_IDX(bp); | |
13695 | u32 cap; | |
13696 | ||
13697 | cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); | |
13698 | if (ulp_type == CNIC_ULP_ISCSI) | |
13699 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
13700 | else if (ulp_type == CNIC_ULP_FCOE) | |
13701 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
13702 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
13703 | } | |
13704 | break; | |
13705 | } | |
993ac7b5 MC |
13706 | |
13707 | default: | |
13708 | BNX2X_ERR("unknown command %x\n", ctl->cmd); | |
13709 | rc = -EINVAL; | |
13710 | } | |
13711 | ||
13712 | return rc; | |
13713 | } | |
13714 | ||
9f6c9258 | 13715 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) |
993ac7b5 MC |
13716 | { |
13717 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13718 | ||
13719 | if (bp->flags & USING_MSIX_FLAG) { | |
13720 | cp->drv_state |= CNIC_DRV_STATE_USING_MSIX; | |
13721 | cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX; | |
13722 | cp->irq_arr[0].vector = bp->msix_table[1].vector; | |
13723 | } else { | |
13724 | cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX; | |
13725 | cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX; | |
13726 | } | |
619c5cb6 | 13727 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
13728 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb; |
13729 | else | |
13730 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; | |
13731 | ||
619c5cb6 VZ |
13732 | cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); |
13733 | cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); | |
993ac7b5 MC |
13734 | cp->irq_arr[1].status_blk = bp->def_status_blk; |
13735 | cp->irq_arr[1].status_blk_num = DEF_SB_ID; | |
523224a3 | 13736 | cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; |
993ac7b5 MC |
13737 | |
13738 | cp->num_irq = 2; | |
13739 | } | |
13740 | ||
37ae41a9 MS |
13741 | void bnx2x_setup_cnic_info(struct bnx2x *bp) |
13742 | { | |
13743 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13744 | ||
37ae41a9 MS |
13745 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
13746 | bnx2x_cid_ilt_lines(bp); | |
13747 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; | |
13748 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp); | |
13749 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp); | |
13750 | ||
f78afb35 MC |
13751 | DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n", |
13752 | BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid, | |
13753 | cp->iscsi_l2_cid); | |
13754 | ||
37ae41a9 MS |
13755 | if (NO_ISCSI_OOO(bp)) |
13756 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; | |
13757 | } | |
13758 | ||
993ac7b5 MC |
13759 | static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops, |
13760 | void *data) | |
13761 | { | |
13762 | struct bnx2x *bp = netdev_priv(dev); | |
13763 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
55c11941 MS |
13764 | int rc; |
13765 | ||
13766 | DP(NETIF_MSG_IFUP, "Register_cnic called\n"); | |
993ac7b5 | 13767 | |
51c1a580 MS |
13768 | if (ops == NULL) { |
13769 | BNX2X_ERR("NULL ops received\n"); | |
993ac7b5 | 13770 | return -EINVAL; |
51c1a580 | 13771 | } |
993ac7b5 | 13772 | |
55c11941 MS |
13773 | if (!CNIC_SUPPORT(bp)) { |
13774 | BNX2X_ERR("Can't register CNIC when not supported\n"); | |
13775 | return -EOPNOTSUPP; | |
13776 | } | |
13777 | ||
13778 | if (!CNIC_LOADED(bp)) { | |
13779 | rc = bnx2x_load_cnic(bp); | |
13780 | if (rc) { | |
13781 | BNX2X_ERR("CNIC-related load failed\n"); | |
13782 | return rc; | |
13783 | } | |
55c11941 MS |
13784 | } |
13785 | ||
13786 | bp->cnic_enabled = true; | |
13787 | ||
993ac7b5 MC |
13788 | bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL); |
13789 | if (!bp->cnic_kwq) | |
13790 | return -ENOMEM; | |
13791 | ||
13792 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
13793 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
13794 | bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT; | |
13795 | ||
13796 | bp->cnic_spq_pending = 0; | |
13797 | bp->cnic_kwq_pending = 0; | |
13798 | ||
13799 | bp->cnic_data = data; | |
13800 | ||
13801 | cp->num_irq = 0; | |
619c5cb6 | 13802 | cp->drv_state |= CNIC_DRV_STATE_REGD; |
523224a3 | 13803 | cp->iro_arr = bp->iro_arr; |
993ac7b5 | 13804 | |
993ac7b5 | 13805 | bnx2x_setup_cnic_irq_info(bp); |
c2bff63f | 13806 | |
993ac7b5 MC |
13807 | rcu_assign_pointer(bp->cnic_ops, ops); |
13808 | ||
13809 | return 0; | |
13810 | } | |
13811 | ||
13812 | static int bnx2x_unregister_cnic(struct net_device *dev) | |
13813 | { | |
13814 | struct bnx2x *bp = netdev_priv(dev); | |
13815 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13816 | ||
13817 | mutex_lock(&bp->cnic_mutex); | |
993ac7b5 | 13818 | cp->drv_state = 0; |
2cfa5a04 | 13819 | RCU_INIT_POINTER(bp->cnic_ops, NULL); |
993ac7b5 MC |
13820 | mutex_unlock(&bp->cnic_mutex); |
13821 | synchronize_rcu(); | |
fea75645 | 13822 | bp->cnic_enabled = false; |
993ac7b5 MC |
13823 | kfree(bp->cnic_kwq); |
13824 | bp->cnic_kwq = NULL; | |
13825 | ||
13826 | return 0; | |
13827 | } | |
13828 | ||
13829 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev) | |
13830 | { | |
13831 | struct bnx2x *bp = netdev_priv(dev); | |
13832 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
13833 | ||
2ba45142 VZ |
13834 | /* If both iSCSI and FCoE are disabled - return NULL in |
13835 | * order to indicate CNIC that it should not try to work | |
13836 | * with this device. | |
13837 | */ | |
13838 | if (NO_ISCSI(bp) && NO_FCOE(bp)) | |
13839 | return NULL; | |
13840 | ||
993ac7b5 MC |
13841 | cp->drv_owner = THIS_MODULE; |
13842 | cp->chip_id = CHIP_ID(bp); | |
13843 | cp->pdev = bp->pdev; | |
13844 | cp->io_base = bp->regview; | |
13845 | cp->io_base2 = bp->doorbells; | |
13846 | cp->max_kwqe_pending = 8; | |
523224a3 | 13847 | cp->ctx_blk_size = CDU_ILT_PAGE_SZ; |
c2bff63f DK |
13848 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
13849 | bnx2x_cid_ilt_lines(bp); | |
993ac7b5 | 13850 | cp->ctx_tbl_len = CNIC_ILT_LINES; |
c2bff63f | 13851 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; |
993ac7b5 MC |
13852 | cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue; |
13853 | cp->drv_ctl = bnx2x_drv_ctl; | |
13854 | cp->drv_register_cnic = bnx2x_register_cnic; | |
13855 | cp->drv_unregister_cnic = bnx2x_unregister_cnic; | |
37ae41a9 | 13856 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp); |
619c5cb6 VZ |
13857 | cp->iscsi_l2_client_id = |
13858 | bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
37ae41a9 | 13859 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp); |
c2bff63f | 13860 | |
2ba45142 VZ |
13861 | if (NO_ISCSI_OOO(bp)) |
13862 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; | |
13863 | ||
13864 | if (NO_ISCSI(bp)) | |
13865 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI; | |
13866 | ||
13867 | if (NO_FCOE(bp)) | |
13868 | cp->drv_state |= CNIC_DRV_STATE_NO_FCOE; | |
13869 | ||
51c1a580 MS |
13870 | BNX2X_DEV_INFO( |
13871 | "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n", | |
c2bff63f DK |
13872 | cp->ctx_blk_size, |
13873 | cp->ctx_tbl_offset, | |
13874 | cp->ctx_tbl_len, | |
13875 | cp->starting_cid); | |
993ac7b5 MC |
13876 | return cp; |
13877 | } | |
993ac7b5 | 13878 | |
6411280a | 13879 | u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp) |
9b176b6b | 13880 | { |
6411280a AE |
13881 | struct bnx2x *bp = fp->bp; |
13882 | u32 offset = BAR_USTRORM_INTMEM; | |
abc5a021 | 13883 | |
6411280a AE |
13884 | if (IS_VF(bp)) |
13885 | return bnx2x_vf_ustorm_prods_offset(bp, fp); | |
13886 | else if (!CHIP_IS_E1x(bp)) | |
13887 | offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id); | |
13888 | else | |
13889 | offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id); | |
8d9ac297 | 13890 | |
6411280a | 13891 | return offset; |
8d9ac297 | 13892 | } |
381ac16b | 13893 | |
6411280a AE |
13894 | /* called only on E1H or E2. |
13895 | * When pretending to be PF, the pretend value is the function number 0...7 | |
13896 | * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID | |
13897 | * combination | |
13898 | */ | |
13899 | int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val) | |
381ac16b | 13900 | { |
6411280a | 13901 | u32 pretend_reg; |
381ac16b | 13902 | |
23826850 | 13903 | if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX) |
6411280a | 13904 | return -1; |
381ac16b | 13905 | |
6411280a AE |
13906 | /* get my own pretend register */ |
13907 | pretend_reg = bnx2x_get_pretend_reg(bp); | |
13908 | REG_WR(bp, pretend_reg, pretend_func_val); | |
13909 | REG_RD(bp, pretend_reg); | |
381ac16b AE |
13910 | return 0; |
13911 | } |