]>
Commit | Line | Data |
---|---|---|
34f80b04 | 1 | /* bnx2x_main.c: Broadcom Everest network driver. |
a2fbb9ea | 2 | * |
85b26ea1 | 3 | * Copyright (c) 2007-2012 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" |
e4901dde | 62 | #include "bnx2x_dcb.h" |
042181f5 | 63 | #include "bnx2x_sp.h" |
a2fbb9ea | 64 | |
94a78b79 VZ |
65 | #include <linux/firmware.h> |
66 | #include "bnx2x_fw_file_hdr.h" | |
67 | /* FW files */ | |
45229b42 BH |
68 | #define FW_FILE_VERSION \ |
69 | __stringify(BCM_5710_FW_MAJOR_VERSION) "." \ | |
70 | __stringify(BCM_5710_FW_MINOR_VERSION) "." \ | |
71 | __stringify(BCM_5710_FW_REVISION_VERSION) "." \ | |
72 | __stringify(BCM_5710_FW_ENGINEERING_VERSION) | |
560131f3 DK |
73 | #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw" |
74 | #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw" | |
f2e0899f | 75 | #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw" |
94a78b79 | 76 | |
34f80b04 EG |
77 | /* Time in jiffies before concluding the transmitter is hung */ |
78 | #define TX_TIMEOUT (5*HZ) | |
a2fbb9ea | 79 | |
53a10565 | 80 | static char version[] __devinitdata = |
619c5cb6 | 81 | "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver " |
a2fbb9ea ET |
82 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
83 | ||
24e3fcef | 84 | MODULE_AUTHOR("Eliezer Tamir"); |
f2e0899f | 85 | MODULE_DESCRIPTION("Broadcom NetXtreme II " |
619c5cb6 VZ |
86 | "BCM57710/57711/57711E/" |
87 | "57712/57712_MF/57800/57800_MF/57810/57810_MF/" | |
88 | "57840/57840_MF Driver"); | |
a2fbb9ea ET |
89 | MODULE_LICENSE("GPL"); |
90 | MODULE_VERSION(DRV_MODULE_VERSION); | |
45229b42 BH |
91 | MODULE_FIRMWARE(FW_FILE_NAME_E1); |
92 | MODULE_FIRMWARE(FW_FILE_NAME_E1H); | |
f2e0899f | 93 | MODULE_FIRMWARE(FW_FILE_NAME_E2); |
a2fbb9ea | 94 | |
555f6c78 EG |
95 | static int multi_mode = 1; |
96 | module_param(multi_mode, int, 0); | |
ca00392c EG |
97 | MODULE_PARM_DESC(multi_mode, " Multi queue mode " |
98 | "(0 Disable; 1 Enable (default))"); | |
99 | ||
d6214d7a | 100 | int num_queues; |
54b9ddaa VZ |
101 | module_param(num_queues, int, 0); |
102 | MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1" | |
103 | " (default is as a number of CPUs)"); | |
555f6c78 | 104 | |
19680c48 | 105 | static int disable_tpa; |
19680c48 | 106 | module_param(disable_tpa, int, 0); |
9898f86d | 107 | MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); |
8badd27a | 108 | |
9ee3d37b DK |
109 | #define INT_MODE_INTx 1 |
110 | #define INT_MODE_MSI 2 | |
8badd27a EG |
111 | static int int_mode; |
112 | module_param(int_mode, int, 0); | |
619c5cb6 | 113 | MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X " |
cdaa7cb8 | 114 | "(1 INT#x; 2 MSI)"); |
8badd27a | 115 | |
a18f5128 EG |
116 | static int dropless_fc; |
117 | module_param(dropless_fc, int, 0); | |
118 | MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); | |
119 | ||
8d5726c4 EG |
120 | static int mrrs = -1; |
121 | module_param(mrrs, int, 0); | |
122 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); | |
123 | ||
9898f86d | 124 | static int debug; |
a2fbb9ea | 125 | module_param(debug, int, 0); |
9898f86d EG |
126 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
127 | ||
a2fbb9ea | 128 | |
619c5cb6 VZ |
129 | |
130 | struct workqueue_struct *bnx2x_wq; | |
ec6ba945 | 131 | |
a2fbb9ea ET |
132 | enum bnx2x_board_type { |
133 | BCM57710 = 0, | |
619c5cb6 VZ |
134 | BCM57711, |
135 | BCM57711E, | |
136 | BCM57712, | |
137 | BCM57712_MF, | |
138 | BCM57800, | |
139 | BCM57800_MF, | |
140 | BCM57810, | |
141 | BCM57810_MF, | |
142 | BCM57840, | |
143 | BCM57840_MF | |
a2fbb9ea ET |
144 | }; |
145 | ||
34f80b04 | 146 | /* indexed by board_type, above */ |
53a10565 | 147 | static struct { |
a2fbb9ea ET |
148 | char *name; |
149 | } board_info[] __devinitdata = { | |
619c5cb6 VZ |
150 | { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" }, |
151 | { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" }, | |
152 | { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" }, | |
153 | { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" }, | |
154 | { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" }, | |
155 | { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" }, | |
156 | { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" }, | |
157 | { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" }, | |
158 | { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" }, | |
159 | { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" }, | |
160 | { "Broadcom NetXtreme II BCM57840 10/20 Gigabit " | |
161 | "Ethernet Multi Function"} | |
a2fbb9ea ET |
162 | }; |
163 | ||
619c5cb6 VZ |
164 | #ifndef PCI_DEVICE_ID_NX2_57710 |
165 | #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710 | |
166 | #endif | |
167 | #ifndef PCI_DEVICE_ID_NX2_57711 | |
168 | #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711 | |
169 | #endif | |
170 | #ifndef PCI_DEVICE_ID_NX2_57711E | |
171 | #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E | |
172 | #endif | |
173 | #ifndef PCI_DEVICE_ID_NX2_57712 | |
174 | #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712 | |
175 | #endif | |
176 | #ifndef PCI_DEVICE_ID_NX2_57712_MF | |
177 | #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF | |
178 | #endif | |
179 | #ifndef PCI_DEVICE_ID_NX2_57800 | |
180 | #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800 | |
181 | #endif | |
182 | #ifndef PCI_DEVICE_ID_NX2_57800_MF | |
183 | #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF | |
184 | #endif | |
185 | #ifndef PCI_DEVICE_ID_NX2_57810 | |
186 | #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810 | |
187 | #endif | |
188 | #ifndef PCI_DEVICE_ID_NX2_57810_MF | |
189 | #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF | |
190 | #endif | |
191 | #ifndef PCI_DEVICE_ID_NX2_57840 | |
192 | #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840 | |
193 | #endif | |
194 | #ifndef PCI_DEVICE_ID_NX2_57840_MF | |
195 | #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF | |
196 | #endif | |
a3aa1884 | 197 | static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = { |
e4ed7113 EG |
198 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, |
199 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, | |
200 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E }, | |
f2e0899f | 201 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 }, |
619c5cb6 VZ |
202 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF }, |
203 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 }, | |
204 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF }, | |
205 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 }, | |
206 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF }, | |
207 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 }, | |
208 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF }, | |
a2fbb9ea ET |
209 | { 0 } |
210 | }; | |
211 | ||
212 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); | |
213 | ||
452427b0 YM |
214 | /* Global resources for unloading a previously loaded device */ |
215 | #define BNX2X_PREV_WAIT_NEEDED 1 | |
216 | static DEFINE_SEMAPHORE(bnx2x_prev_sem); | |
217 | static LIST_HEAD(bnx2x_prev_list); | |
a2fbb9ea ET |
218 | /**************************************************************************** |
219 | * General service functions | |
220 | ****************************************************************************/ | |
221 | ||
619c5cb6 VZ |
222 | static inline void __storm_memset_dma_mapping(struct bnx2x *bp, |
223 | u32 addr, dma_addr_t mapping) | |
224 | { | |
225 | REG_WR(bp, addr, U64_LO(mapping)); | |
226 | REG_WR(bp, addr + 4, U64_HI(mapping)); | |
227 | } | |
228 | ||
229 | static inline void storm_memset_spq_addr(struct bnx2x *bp, | |
230 | dma_addr_t mapping, u16 abs_fid) | |
231 | { | |
232 | u32 addr = XSEM_REG_FAST_MEMORY + | |
233 | XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid); | |
234 | ||
235 | __storm_memset_dma_mapping(bp, addr, mapping); | |
236 | } | |
237 | ||
238 | static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid, | |
239 | u16 pf_id) | |
523224a3 | 240 | { |
619c5cb6 VZ |
241 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid), |
242 | pf_id); | |
243 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid), | |
244 | pf_id); | |
245 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid), | |
246 | pf_id); | |
247 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid), | |
248 | pf_id); | |
523224a3 DK |
249 | } |
250 | ||
619c5cb6 VZ |
251 | static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid, |
252 | u8 enable) | |
253 | { | |
254 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid), | |
255 | enable); | |
256 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid), | |
257 | enable); | |
258 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid), | |
259 | enable); | |
260 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid), | |
261 | enable); | |
262 | } | |
523224a3 DK |
263 | |
264 | static inline void storm_memset_eq_data(struct bnx2x *bp, | |
265 | struct event_ring_data *eq_data, | |
266 | u16 pfid) | |
267 | { | |
268 | size_t size = sizeof(struct event_ring_data); | |
269 | ||
270 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid); | |
271 | ||
272 | __storm_memset_struct(bp, addr, size, (u32 *)eq_data); | |
273 | } | |
274 | ||
275 | static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod, | |
276 | u16 pfid) | |
277 | { | |
278 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid); | |
279 | REG_WR16(bp, addr, eq_prod); | |
280 | } | |
281 | ||
a2fbb9ea ET |
282 | /* used only at init |
283 | * locking is done by mcp | |
284 | */ | |
8d96286a | 285 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
a2fbb9ea ET |
286 | { |
287 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
288 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); | |
289 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
290 | PCICFG_VENDOR_ID_OFFSET); | |
291 | } | |
292 | ||
a2fbb9ea ET |
293 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
294 | { | |
295 | u32 val; | |
296 | ||
297 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); | |
298 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); | |
299 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
300 | PCICFG_VENDOR_ID_OFFSET); | |
301 | ||
302 | return val; | |
303 | } | |
a2fbb9ea | 304 | |
f2e0899f DK |
305 | #define DMAE_DP_SRC_GRC "grc src_addr [%08x]" |
306 | #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]" | |
307 | #define DMAE_DP_DST_GRC "grc dst_addr [%08x]" | |
308 | #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]" | |
309 | #define DMAE_DP_DST_NONE "dst_addr [none]" | |
310 | ||
8d96286a | 311 | static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, |
312 | int msglvl) | |
f2e0899f DK |
313 | { |
314 | u32 src_type = dmae->opcode & DMAE_COMMAND_SRC; | |
315 | ||
316 | switch (dmae->opcode & DMAE_COMMAND_DST) { | |
317 | case DMAE_CMD_DST_PCI: | |
318 | if (src_type == DMAE_CMD_SRC_PCI) | |
319 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
320 | "src [%x:%08x], len [%d*4], dst [%x:%08x]\n" | |
321 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
322 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
323 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
324 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
325 | dmae->comp_val); | |
326 | else | |
327 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
328 | "src [%08x], len [%d*4], dst [%x:%08x]\n" | |
329 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
330 | dmae->opcode, dmae->src_addr_lo >> 2, | |
331 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, | |
332 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
333 | dmae->comp_val); | |
334 | break; | |
335 | case DMAE_CMD_DST_GRC: | |
336 | if (src_type == DMAE_CMD_SRC_PCI) | |
337 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
338 | "src [%x:%08x], len [%d*4], dst_addr [%08x]\n" | |
339 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
340 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, | |
341 | dmae->len, dmae->dst_addr_lo >> 2, | |
342 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
343 | dmae->comp_val); | |
344 | else | |
345 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
346 | "src [%08x], len [%d*4], dst [%08x]\n" | |
347 | "comp_addr [%x:%08x], comp_val 0x%08x\n", | |
348 | dmae->opcode, dmae->src_addr_lo >> 2, | |
349 | dmae->len, dmae->dst_addr_lo >> 2, | |
350 | dmae->comp_addr_hi, dmae->comp_addr_lo, | |
351 | dmae->comp_val); | |
352 | break; | |
353 | default: | |
354 | if (src_type == DMAE_CMD_SRC_PCI) | |
355 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
f1deab50 JP |
356 | "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n" |
357 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
f2e0899f DK |
358 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
359 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
360 | dmae->comp_val); | |
361 | else | |
362 | DP(msglvl, "DMAE: opcode 0x%08x\n" | |
f1deab50 JP |
363 | "src_addr [%08x] len [%d * 4] dst_addr [none]\n" |
364 | "comp_addr [%x:%08x] comp_val 0x%08x\n", | |
f2e0899f DK |
365 | dmae->opcode, dmae->src_addr_lo >> 2, |
366 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, | |
367 | dmae->comp_val); | |
368 | break; | |
369 | } | |
370 | ||
371 | } | |
372 | ||
a2fbb9ea | 373 | /* copy command into DMAE command memory and set DMAE command go */ |
6c719d00 | 374 | void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx) |
a2fbb9ea ET |
375 | { |
376 | u32 cmd_offset; | |
377 | int i; | |
378 | ||
379 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); | |
380 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { | |
381 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); | |
a2fbb9ea ET |
382 | } |
383 | REG_WR(bp, dmae_reg_go_c[idx], 1); | |
384 | } | |
385 | ||
f2e0899f | 386 | u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type) |
a2fbb9ea | 387 | { |
f2e0899f DK |
388 | return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) | |
389 | DMAE_CMD_C_ENABLE); | |
390 | } | |
ad8d3948 | 391 | |
f2e0899f DK |
392 | u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode) |
393 | { | |
394 | return opcode & ~DMAE_CMD_SRC_RESET; | |
395 | } | |
ad8d3948 | 396 | |
f2e0899f DK |
397 | u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type, |
398 | bool with_comp, u8 comp_type) | |
399 | { | |
400 | u32 opcode = 0; | |
401 | ||
402 | opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) | | |
403 | (dst_type << DMAE_COMMAND_DST_SHIFT)); | |
ad8d3948 | 404 | |
f2e0899f DK |
405 | opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET); |
406 | ||
407 | opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0); | |
3395a033 DK |
408 | opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) | |
409 | (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT)); | |
f2e0899f | 410 | opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT); |
a2fbb9ea | 411 | |
a2fbb9ea | 412 | #ifdef __BIG_ENDIAN |
f2e0899f | 413 | opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP; |
a2fbb9ea | 414 | #else |
f2e0899f | 415 | opcode |= DMAE_CMD_ENDIANITY_DW_SWAP; |
a2fbb9ea | 416 | #endif |
f2e0899f DK |
417 | if (with_comp) |
418 | opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type); | |
419 | return opcode; | |
420 | } | |
421 | ||
8d96286a | 422 | static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, |
423 | struct dmae_command *dmae, | |
424 | u8 src_type, u8 dst_type) | |
f2e0899f DK |
425 | { |
426 | memset(dmae, 0, sizeof(struct dmae_command)); | |
427 | ||
428 | /* set the opcode */ | |
429 | dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type, | |
430 | true, DMAE_COMP_PCI); | |
431 | ||
432 | /* fill in the completion parameters */ | |
433 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); | |
434 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); | |
435 | dmae->comp_val = DMAE_COMP_VAL; | |
436 | } | |
437 | ||
438 | /* issue a dmae command over the init-channel and wailt for completion */ | |
8d96286a | 439 | static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, |
440 | struct dmae_command *dmae) | |
f2e0899f DK |
441 | { |
442 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); | |
5e374b5a | 443 | int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000; |
f2e0899f DK |
444 | int rc = 0; |
445 | ||
619c5cb6 VZ |
446 | /* |
447 | * Lock the dmae channel. Disable BHs to prevent a dead-lock | |
448 | * as long as this code is called both from syscall context and | |
449 | * from ndo_set_rx_mode() flow that may be called from BH. | |
450 | */ | |
6e30dd4e | 451 | spin_lock_bh(&bp->dmae_lock); |
5ff7b6d4 | 452 | |
f2e0899f | 453 | /* reset completion */ |
a2fbb9ea ET |
454 | *wb_comp = 0; |
455 | ||
f2e0899f DK |
456 | /* post the command on the channel used for initializations */ |
457 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); | |
a2fbb9ea | 458 | |
f2e0899f | 459 | /* wait for completion */ |
a2fbb9ea | 460 | udelay(5); |
f2e0899f | 461 | while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) { |
ad8d3948 | 462 | |
95c6c616 AE |
463 | if (!cnt || |
464 | (bp->recovery_state != BNX2X_RECOVERY_DONE && | |
465 | bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) { | |
c3eefaf6 | 466 | BNX2X_ERR("DMAE timeout!\n"); |
f2e0899f DK |
467 | rc = DMAE_TIMEOUT; |
468 | goto unlock; | |
a2fbb9ea | 469 | } |
ad8d3948 | 470 | cnt--; |
f2e0899f | 471 | udelay(50); |
a2fbb9ea | 472 | } |
f2e0899f DK |
473 | if (*wb_comp & DMAE_PCI_ERR_FLAG) { |
474 | BNX2X_ERR("DMAE PCI error!\n"); | |
475 | rc = DMAE_PCI_ERROR; | |
476 | } | |
477 | ||
f2e0899f | 478 | unlock: |
6e30dd4e | 479 | spin_unlock_bh(&bp->dmae_lock); |
f2e0899f DK |
480 | return rc; |
481 | } | |
482 | ||
483 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, | |
484 | u32 len32) | |
485 | { | |
486 | struct dmae_command dmae; | |
487 | ||
488 | if (!bp->dmae_ready) { | |
489 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
490 | ||
127a425e AE |
491 | if (CHIP_IS_E1(bp)) |
492 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); | |
493 | else | |
494 | bnx2x_init_str_wr(bp, dst_addr, data, len32); | |
f2e0899f DK |
495 | return; |
496 | } | |
497 | ||
498 | /* set opcode and fixed command fields */ | |
499 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC); | |
500 | ||
501 | /* fill in addresses and len */ | |
502 | dmae.src_addr_lo = U64_LO(dma_addr); | |
503 | dmae.src_addr_hi = U64_HI(dma_addr); | |
504 | dmae.dst_addr_lo = dst_addr >> 2; | |
505 | dmae.dst_addr_hi = 0; | |
506 | dmae.len = len32; | |
507 | ||
508 | bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF); | |
509 | ||
510 | /* issue the command and wait for completion */ | |
511 | bnx2x_issue_dmae_with_comp(bp, &dmae); | |
a2fbb9ea ET |
512 | } |
513 | ||
c18487ee | 514 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
a2fbb9ea | 515 | { |
5ff7b6d4 | 516 | struct dmae_command dmae; |
ad8d3948 EG |
517 | |
518 | if (!bp->dmae_ready) { | |
519 | u32 *data = bnx2x_sp(bp, wb_data[0]); | |
520 | int i; | |
521 | ||
51c1a580 | 522 | if (CHIP_IS_E1(bp)) |
127a425e AE |
523 | for (i = 0; i < len32; i++) |
524 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); | |
51c1a580 | 525 | else |
127a425e AE |
526 | for (i = 0; i < len32; i++) |
527 | data[i] = REG_RD(bp, src_addr + i*4); | |
528 | ||
ad8d3948 EG |
529 | return; |
530 | } | |
531 | ||
f2e0899f DK |
532 | /* set opcode and fixed command fields */ |
533 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI); | |
a2fbb9ea | 534 | |
f2e0899f | 535 | /* fill in addresses and len */ |
5ff7b6d4 EG |
536 | dmae.src_addr_lo = src_addr >> 2; |
537 | dmae.src_addr_hi = 0; | |
538 | dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); | |
539 | dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); | |
540 | dmae.len = len32; | |
ad8d3948 | 541 | |
f2e0899f | 542 | bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF); |
ad8d3948 | 543 | |
f2e0899f DK |
544 | /* issue the command and wait for completion */ |
545 | bnx2x_issue_dmae_with_comp(bp, &dmae); | |
ad8d3948 EG |
546 | } |
547 | ||
8d96286a | 548 | static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, |
549 | u32 addr, u32 len) | |
573f2035 | 550 | { |
02e3c6cb | 551 | int dmae_wr_max = DMAE_LEN32_WR_MAX(bp); |
573f2035 EG |
552 | int offset = 0; |
553 | ||
02e3c6cb | 554 | while (len > dmae_wr_max) { |
573f2035 | 555 | bnx2x_write_dmae(bp, phys_addr + offset, |
02e3c6cb VZ |
556 | addr + offset, dmae_wr_max); |
557 | offset += dmae_wr_max * 4; | |
558 | len -= dmae_wr_max; | |
573f2035 EG |
559 | } |
560 | ||
561 | bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len); | |
562 | } | |
563 | ||
ad8d3948 EG |
564 | /* used only for slowpath so not inlined */ |
565 | static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo) | |
566 | { | |
567 | u32 wb_write[2]; | |
568 | ||
569 | wb_write[0] = val_hi; | |
570 | wb_write[1] = val_lo; | |
571 | REG_WR_DMAE(bp, reg, wb_write, 2); | |
a2fbb9ea | 572 | } |
a2fbb9ea | 573 | |
ad8d3948 EG |
574 | #ifdef USE_WB_RD |
575 | static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg) | |
576 | { | |
577 | u32 wb_data[2]; | |
578 | ||
579 | REG_RD_DMAE(bp, reg, wb_data, 2); | |
580 | ||
581 | return HILO_U64(wb_data[0], wb_data[1]); | |
582 | } | |
583 | #endif | |
584 | ||
a2fbb9ea ET |
585 | static int bnx2x_mc_assert(struct bnx2x *bp) |
586 | { | |
a2fbb9ea | 587 | char last_idx; |
34f80b04 EG |
588 | int i, rc = 0; |
589 | u32 row0, row1, row2, row3; | |
590 | ||
591 | /* XSTORM */ | |
592 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + | |
593 | XSTORM_ASSERT_LIST_INDEX_OFFSET); | |
594 | if (last_idx) | |
595 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
596 | ||
597 | /* print the asserts */ | |
598 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
599 | ||
600 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
601 | XSTORM_ASSERT_LIST_OFFSET(i)); | |
602 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
603 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
604 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
605 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
606 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + | |
607 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
608 | ||
609 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 610 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
611 | i, row3, row2, row1, row0); |
612 | rc++; | |
613 | } else { | |
614 | break; | |
615 | } | |
616 | } | |
617 | ||
618 | /* TSTORM */ | |
619 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + | |
620 | TSTORM_ASSERT_LIST_INDEX_OFFSET); | |
621 | if (last_idx) | |
622 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
623 | ||
624 | /* print the asserts */ | |
625 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
626 | ||
627 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
628 | TSTORM_ASSERT_LIST_OFFSET(i)); | |
629 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
630 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
631 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
632 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
633 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + | |
634 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
635 | ||
636 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 637 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
638 | i, row3, row2, row1, row0); |
639 | rc++; | |
640 | } else { | |
641 | break; | |
642 | } | |
643 | } | |
644 | ||
645 | /* CSTORM */ | |
646 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + | |
647 | CSTORM_ASSERT_LIST_INDEX_OFFSET); | |
648 | if (last_idx) | |
649 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
650 | ||
651 | /* print the asserts */ | |
652 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
653 | ||
654 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
655 | CSTORM_ASSERT_LIST_OFFSET(i)); | |
656 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
657 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); | |
658 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
659 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); | |
660 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
661 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); | |
662 | ||
663 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 664 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
665 | i, row3, row2, row1, row0); |
666 | rc++; | |
667 | } else { | |
668 | break; | |
669 | } | |
670 | } | |
671 | ||
672 | /* USTORM */ | |
673 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + | |
674 | USTORM_ASSERT_LIST_INDEX_OFFSET); | |
675 | if (last_idx) | |
676 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); | |
677 | ||
678 | /* print the asserts */ | |
679 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { | |
680 | ||
681 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
682 | USTORM_ASSERT_LIST_OFFSET(i)); | |
683 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
684 | USTORM_ASSERT_LIST_OFFSET(i) + 4); | |
685 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
686 | USTORM_ASSERT_LIST_OFFSET(i) + 8); | |
687 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + | |
688 | USTORM_ASSERT_LIST_OFFSET(i) + 12); | |
689 | ||
690 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { | |
51c1a580 | 691 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n", |
34f80b04 EG |
692 | i, row3, row2, row1, row0); |
693 | rc++; | |
694 | } else { | |
695 | break; | |
a2fbb9ea ET |
696 | } |
697 | } | |
34f80b04 | 698 | |
a2fbb9ea ET |
699 | return rc; |
700 | } | |
c14423fe | 701 | |
7a25cc73 | 702 | void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl) |
a2fbb9ea | 703 | { |
7a25cc73 | 704 | u32 addr, val; |
a2fbb9ea | 705 | u32 mark, offset; |
4781bfad | 706 | __be32 data[9]; |
a2fbb9ea | 707 | int word; |
f2e0899f | 708 | u32 trace_shmem_base; |
2145a920 VZ |
709 | if (BP_NOMCP(bp)) { |
710 | BNX2X_ERR("NO MCP - can not dump\n"); | |
711 | return; | |
712 | } | |
7a25cc73 DK |
713 | netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n", |
714 | (bp->common.bc_ver & 0xff0000) >> 16, | |
715 | (bp->common.bc_ver & 0xff00) >> 8, | |
716 | (bp->common.bc_ver & 0xff)); | |
717 | ||
718 | val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER); | |
719 | if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER)) | |
51c1a580 | 720 | BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val); |
cdaa7cb8 | 721 | |
f2e0899f DK |
722 | if (BP_PATH(bp) == 0) |
723 | trace_shmem_base = bp->common.shmem_base; | |
724 | else | |
725 | trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr); | |
de128804 DK |
726 | addr = trace_shmem_base - 0x800; |
727 | ||
728 | /* validate TRCB signature */ | |
729 | mark = REG_RD(bp, addr); | |
730 | if (mark != MFW_TRACE_SIGNATURE) { | |
731 | BNX2X_ERR("Trace buffer signature is missing."); | |
732 | return ; | |
733 | } | |
734 | ||
735 | /* read cyclic buffer pointer */ | |
736 | addr += 4; | |
cdaa7cb8 | 737 | mark = REG_RD(bp, addr); |
f2e0899f DK |
738 | mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH) |
739 | + ((mark + 0x3) & ~0x3) - 0x08000000; | |
7a25cc73 | 740 | printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark); |
a2fbb9ea | 741 | |
7a25cc73 | 742 | printk("%s", lvl); |
f2e0899f | 743 | for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) { |
a2fbb9ea | 744 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 745 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 746 | data[8] = 0x0; |
7995c64e | 747 | pr_cont("%s", (char *)data); |
a2fbb9ea | 748 | } |
cdaa7cb8 | 749 | for (offset = addr + 4; offset <= mark; offset += 0x8*4) { |
a2fbb9ea | 750 | for (word = 0; word < 8; word++) |
cdaa7cb8 | 751 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
a2fbb9ea | 752 | data[8] = 0x0; |
7995c64e | 753 | pr_cont("%s", (char *)data); |
a2fbb9ea | 754 | } |
7a25cc73 DK |
755 | printk("%s" "end of fw dump\n", lvl); |
756 | } | |
757 | ||
758 | static inline void bnx2x_fw_dump(struct bnx2x *bp) | |
759 | { | |
760 | bnx2x_fw_dump_lvl(bp, KERN_ERR); | |
a2fbb9ea ET |
761 | } |
762 | ||
6c719d00 | 763 | void bnx2x_panic_dump(struct bnx2x *bp) |
a2fbb9ea ET |
764 | { |
765 | int i; | |
523224a3 DK |
766 | u16 j; |
767 | struct hc_sp_status_block_data sp_sb_data; | |
768 | int func = BP_FUNC(bp); | |
769 | #ifdef BNX2X_STOP_ON_ERROR | |
770 | u16 start = 0, end = 0; | |
6383c0b3 | 771 | u8 cos; |
523224a3 | 772 | #endif |
a2fbb9ea | 773 | |
66e855f3 | 774 | bp->stats_state = STATS_STATE_DISABLED; |
7a752993 | 775 | bp->eth_stats.unrecoverable_error++; |
66e855f3 YG |
776 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
777 | ||
a2fbb9ea ET |
778 | BNX2X_ERR("begin crash dump -----------------\n"); |
779 | ||
8440d2b6 EG |
780 | /* Indices */ |
781 | /* Common */ | |
51c1a580 | 782 | 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 |
783 | bp->def_idx, bp->def_att_idx, bp->attn_state, |
784 | bp->spq_prod_idx, bp->stats_counter); | |
523224a3 DK |
785 | BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n", |
786 | bp->def_status_blk->atten_status_block.attn_bits, | |
787 | bp->def_status_blk->atten_status_block.attn_bits_ack, | |
788 | bp->def_status_blk->atten_status_block.status_block_id, | |
789 | bp->def_status_blk->atten_status_block.attn_bits_index); | |
790 | BNX2X_ERR(" def ("); | |
791 | for (i = 0; i < HC_SP_SB_MAX_INDICES; i++) | |
792 | pr_cont("0x%x%s", | |
f1deab50 JP |
793 | bp->def_status_blk->sp_sb.index_values[i], |
794 | (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " "); | |
523224a3 DK |
795 | |
796 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
797 | *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
798 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
799 | i*sizeof(u32)); | |
800 | ||
f1deab50 | 801 | 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 |
802 | sp_sb_data.igu_sb_id, |
803 | sp_sb_data.igu_seg_id, | |
804 | sp_sb_data.p_func.pf_id, | |
805 | sp_sb_data.p_func.vnic_id, | |
806 | sp_sb_data.p_func.vf_id, | |
619c5cb6 VZ |
807 | sp_sb_data.p_func.vf_valid, |
808 | sp_sb_data.state); | |
523224a3 | 809 | |
8440d2b6 | 810 | |
ec6ba945 | 811 | for_each_eth_queue(bp, i) { |
a2fbb9ea | 812 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
523224a3 | 813 | int loop; |
f2e0899f | 814 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
815 | struct hc_status_block_data_e1x sb_data_e1x; |
816 | struct hc_status_block_sm *hc_sm_p = | |
619c5cb6 VZ |
817 | CHIP_IS_E1x(bp) ? |
818 | sb_data_e1x.common.state_machine : | |
819 | sb_data_e2.common.state_machine; | |
523224a3 | 820 | struct hc_index_data *hc_index_p = |
619c5cb6 VZ |
821 | CHIP_IS_E1x(bp) ? |
822 | sb_data_e1x.index_data : | |
823 | sb_data_e2.index_data; | |
6383c0b3 | 824 | u8 data_size, cos; |
523224a3 | 825 | u32 *sb_data_p; |
6383c0b3 | 826 | struct bnx2x_fp_txdata txdata; |
523224a3 DK |
827 | |
828 | /* Rx */ | |
51c1a580 | 829 | 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 | 830 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
523224a3 | 831 | fp->rx_comp_prod, |
66e855f3 | 832 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
51c1a580 | 833 | BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n", |
8440d2b6 | 834 | fp->rx_sge_prod, fp->last_max_sge, |
523224a3 | 835 | le16_to_cpu(fp->fp_hc_idx)); |
a2fbb9ea | 836 | |
523224a3 | 837 | /* Tx */ |
6383c0b3 AE |
838 | for_each_cos_in_tx_queue(fp, cos) |
839 | { | |
840 | txdata = fp->txdata[cos]; | |
51c1a580 | 841 | 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 |
842 | i, txdata.tx_pkt_prod, |
843 | txdata.tx_pkt_cons, txdata.tx_bd_prod, | |
844 | txdata.tx_bd_cons, | |
845 | le16_to_cpu(*txdata.tx_cons_sb)); | |
846 | } | |
523224a3 | 847 | |
619c5cb6 VZ |
848 | loop = CHIP_IS_E1x(bp) ? |
849 | HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2; | |
523224a3 DK |
850 | |
851 | /* host sb data */ | |
852 | ||
ec6ba945 VZ |
853 | #ifdef BCM_CNIC |
854 | if (IS_FCOE_FP(fp)) | |
855 | continue; | |
856 | #endif | |
523224a3 DK |
857 | BNX2X_ERR(" run indexes ("); |
858 | for (j = 0; j < HC_SB_MAX_SM; j++) | |
859 | pr_cont("0x%x%s", | |
860 | fp->sb_running_index[j], | |
861 | (j == HC_SB_MAX_SM - 1) ? ")" : " "); | |
862 | ||
863 | BNX2X_ERR(" indexes ("); | |
864 | for (j = 0; j < loop; j++) | |
865 | pr_cont("0x%x%s", | |
866 | fp->sb_index_values[j], | |
867 | (j == loop - 1) ? ")" : " "); | |
868 | /* fw sb data */ | |
619c5cb6 VZ |
869 | data_size = CHIP_IS_E1x(bp) ? |
870 | sizeof(struct hc_status_block_data_e1x) : | |
871 | sizeof(struct hc_status_block_data_e2); | |
523224a3 | 872 | data_size /= sizeof(u32); |
619c5cb6 VZ |
873 | sb_data_p = CHIP_IS_E1x(bp) ? |
874 | (u32 *)&sb_data_e1x : | |
875 | (u32 *)&sb_data_e2; | |
523224a3 DK |
876 | /* copy sb data in here */ |
877 | for (j = 0; j < data_size; j++) | |
878 | *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM + | |
879 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) + | |
880 | j * sizeof(u32)); | |
881 | ||
619c5cb6 | 882 | if (!CHIP_IS_E1x(bp)) { |
51c1a580 | 883 | 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 |
884 | sb_data_e2.common.p_func.pf_id, |
885 | sb_data_e2.common.p_func.vf_id, | |
886 | sb_data_e2.common.p_func.vf_valid, | |
887 | sb_data_e2.common.p_func.vnic_id, | |
619c5cb6 VZ |
888 | sb_data_e2.common.same_igu_sb_1b, |
889 | sb_data_e2.common.state); | |
f2e0899f | 890 | } else { |
51c1a580 | 891 | 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 |
892 | sb_data_e1x.common.p_func.pf_id, |
893 | sb_data_e1x.common.p_func.vf_id, | |
894 | sb_data_e1x.common.p_func.vf_valid, | |
895 | sb_data_e1x.common.p_func.vnic_id, | |
619c5cb6 VZ |
896 | sb_data_e1x.common.same_igu_sb_1b, |
897 | sb_data_e1x.common.state); | |
f2e0899f | 898 | } |
523224a3 DK |
899 | |
900 | /* SB_SMs data */ | |
901 | for (j = 0; j < HC_SB_MAX_SM; j++) { | |
51c1a580 MS |
902 | 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", |
903 | j, hc_sm_p[j].__flags, | |
904 | hc_sm_p[j].igu_sb_id, | |
905 | hc_sm_p[j].igu_seg_id, | |
906 | hc_sm_p[j].time_to_expire, | |
907 | hc_sm_p[j].timer_value); | |
523224a3 DK |
908 | } |
909 | ||
910 | /* Indecies data */ | |
911 | for (j = 0; j < loop; j++) { | |
51c1a580 | 912 | pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j, |
523224a3 DK |
913 | hc_index_p[j].flags, |
914 | hc_index_p[j].timeout); | |
915 | } | |
8440d2b6 | 916 | } |
a2fbb9ea | 917 | |
523224a3 | 918 | #ifdef BNX2X_STOP_ON_ERROR |
8440d2b6 EG |
919 | /* Rings */ |
920 | /* Rx */ | |
ec6ba945 | 921 | for_each_rx_queue(bp, i) { |
8440d2b6 | 922 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea ET |
923 | |
924 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); | |
925 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); | |
8440d2b6 | 926 | for (j = start; j != end; j = RX_BD(j + 1)) { |
a2fbb9ea ET |
927 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
928 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; | |
929 | ||
c3eefaf6 | 930 | BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
44151acb | 931 | i, j, rx_bd[1], rx_bd[0], sw_bd->data); |
a2fbb9ea ET |
932 | } |
933 | ||
3196a88a EG |
934 | start = RX_SGE(fp->rx_sge_prod); |
935 | end = RX_SGE(fp->last_max_sge); | |
8440d2b6 | 936 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
7a9b2557 VZ |
937 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
938 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; | |
939 | ||
c3eefaf6 EG |
940 | BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
941 | i, j, rx_sge[1], rx_sge[0], sw_page->page); | |
7a9b2557 VZ |
942 | } |
943 | ||
a2fbb9ea ET |
944 | start = RCQ_BD(fp->rx_comp_cons - 10); |
945 | end = RCQ_BD(fp->rx_comp_cons + 503); | |
8440d2b6 | 946 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
a2fbb9ea ET |
947 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
948 | ||
c3eefaf6 EG |
949 | BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n", |
950 | i, j, cqe[0], cqe[1], cqe[2], cqe[3]); | |
a2fbb9ea ET |
951 | } |
952 | } | |
953 | ||
8440d2b6 | 954 | /* Tx */ |
ec6ba945 | 955 | for_each_tx_queue(bp, i) { |
8440d2b6 | 956 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
6383c0b3 AE |
957 | for_each_cos_in_tx_queue(fp, cos) { |
958 | struct bnx2x_fp_txdata *txdata = &fp->txdata[cos]; | |
959 | ||
960 | start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10); | |
961 | end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245); | |
962 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
963 | struct sw_tx_bd *sw_bd = | |
964 | &txdata->tx_buf_ring[j]; | |
965 | ||
51c1a580 | 966 | BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n", |
6383c0b3 AE |
967 | i, cos, j, sw_bd->skb, |
968 | sw_bd->first_bd); | |
969 | } | |
8440d2b6 | 970 | |
6383c0b3 AE |
971 | start = TX_BD(txdata->tx_bd_cons - 10); |
972 | end = TX_BD(txdata->tx_bd_cons + 254); | |
973 | for (j = start; j != end; j = TX_BD(j + 1)) { | |
974 | u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j]; | |
8440d2b6 | 975 | |
51c1a580 | 976 | BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n", |
6383c0b3 AE |
977 | i, cos, j, tx_bd[0], tx_bd[1], |
978 | tx_bd[2], tx_bd[3]); | |
979 | } | |
8440d2b6 EG |
980 | } |
981 | } | |
523224a3 | 982 | #endif |
34f80b04 | 983 | bnx2x_fw_dump(bp); |
a2fbb9ea ET |
984 | bnx2x_mc_assert(bp); |
985 | BNX2X_ERR("end crash dump -----------------\n"); | |
a2fbb9ea ET |
986 | } |
987 | ||
619c5cb6 VZ |
988 | /* |
989 | * FLR Support for E2 | |
990 | * | |
991 | * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW | |
992 | * initialization. | |
993 | */ | |
994 | #define FLR_WAIT_USEC 10000 /* 10 miliseconds */ | |
89db4ad8 AE |
995 | #define FLR_WAIT_INTERVAL 50 /* usec */ |
996 | #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */ | |
619c5cb6 VZ |
997 | |
998 | struct pbf_pN_buf_regs { | |
999 | int pN; | |
1000 | u32 init_crd; | |
1001 | u32 crd; | |
1002 | u32 crd_freed; | |
1003 | }; | |
1004 | ||
1005 | struct pbf_pN_cmd_regs { | |
1006 | int pN; | |
1007 | u32 lines_occup; | |
1008 | u32 lines_freed; | |
1009 | }; | |
1010 | ||
1011 | static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp, | |
1012 | struct pbf_pN_buf_regs *regs, | |
1013 | u32 poll_count) | |
1014 | { | |
1015 | u32 init_crd, crd, crd_start, crd_freed, crd_freed_start; | |
1016 | u32 cur_cnt = poll_count; | |
1017 | ||
1018 | crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed); | |
1019 | crd = crd_start = REG_RD(bp, regs->crd); | |
1020 | init_crd = REG_RD(bp, regs->init_crd); | |
1021 | ||
1022 | DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd); | |
1023 | DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd); | |
1024 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed); | |
1025 | ||
1026 | while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) < | |
1027 | (init_crd - crd_start))) { | |
1028 | if (cur_cnt--) { | |
89db4ad8 | 1029 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1030 | crd = REG_RD(bp, regs->crd); |
1031 | crd_freed = REG_RD(bp, regs->crd_freed); | |
1032 | } else { | |
1033 | DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n", | |
1034 | regs->pN); | |
1035 | DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n", | |
1036 | regs->pN, crd); | |
1037 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n", | |
1038 | regs->pN, crd_freed); | |
1039 | break; | |
1040 | } | |
1041 | } | |
1042 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n", | |
89db4ad8 | 1043 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1044 | } |
1045 | ||
1046 | static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp, | |
1047 | struct pbf_pN_cmd_regs *regs, | |
1048 | u32 poll_count) | |
1049 | { | |
1050 | u32 occup, to_free, freed, freed_start; | |
1051 | u32 cur_cnt = poll_count; | |
1052 | ||
1053 | occup = to_free = REG_RD(bp, regs->lines_occup); | |
1054 | freed = freed_start = REG_RD(bp, regs->lines_freed); | |
1055 | ||
1056 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); | |
1057 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); | |
1058 | ||
1059 | while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) { | |
1060 | if (cur_cnt--) { | |
89db4ad8 | 1061 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1062 | occup = REG_RD(bp, regs->lines_occup); |
1063 | freed = REG_RD(bp, regs->lines_freed); | |
1064 | } else { | |
1065 | DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n", | |
1066 | regs->pN); | |
1067 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", | |
1068 | regs->pN, occup); | |
1069 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", | |
1070 | regs->pN, freed); | |
1071 | break; | |
1072 | } | |
1073 | } | |
1074 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n", | |
89db4ad8 | 1075 | poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN); |
619c5cb6 VZ |
1076 | } |
1077 | ||
1078 | static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg, | |
1079 | u32 expected, u32 poll_count) | |
1080 | { | |
1081 | u32 cur_cnt = poll_count; | |
1082 | u32 val; | |
1083 | ||
1084 | while ((val = REG_RD(bp, reg)) != expected && cur_cnt--) | |
89db4ad8 | 1085 | udelay(FLR_WAIT_INTERVAL); |
619c5cb6 VZ |
1086 | |
1087 | return val; | |
1088 | } | |
1089 | ||
1090 | static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg, | |
1091 | char *msg, u32 poll_cnt) | |
1092 | { | |
1093 | u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt); | |
1094 | if (val != 0) { | |
1095 | BNX2X_ERR("%s usage count=%d\n", msg, val); | |
1096 | return 1; | |
1097 | } | |
1098 | return 0; | |
1099 | } | |
1100 | ||
1101 | static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp) | |
1102 | { | |
1103 | /* adjust polling timeout */ | |
1104 | if (CHIP_REV_IS_EMUL(bp)) | |
1105 | return FLR_POLL_CNT * 2000; | |
1106 | ||
1107 | if (CHIP_REV_IS_FPGA(bp)) | |
1108 | return FLR_POLL_CNT * 120; | |
1109 | ||
1110 | return FLR_POLL_CNT; | |
1111 | } | |
1112 | ||
1113 | static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count) | |
1114 | { | |
1115 | struct pbf_pN_cmd_regs cmd_regs[] = { | |
1116 | {0, (CHIP_IS_E3B0(bp)) ? | |
1117 | PBF_REG_TQ_OCCUPANCY_Q0 : | |
1118 | PBF_REG_P0_TQ_OCCUPANCY, | |
1119 | (CHIP_IS_E3B0(bp)) ? | |
1120 | PBF_REG_TQ_LINES_FREED_CNT_Q0 : | |
1121 | PBF_REG_P0_TQ_LINES_FREED_CNT}, | |
1122 | {1, (CHIP_IS_E3B0(bp)) ? | |
1123 | PBF_REG_TQ_OCCUPANCY_Q1 : | |
1124 | PBF_REG_P1_TQ_OCCUPANCY, | |
1125 | (CHIP_IS_E3B0(bp)) ? | |
1126 | PBF_REG_TQ_LINES_FREED_CNT_Q1 : | |
1127 | PBF_REG_P1_TQ_LINES_FREED_CNT}, | |
1128 | {4, (CHIP_IS_E3B0(bp)) ? | |
1129 | PBF_REG_TQ_OCCUPANCY_LB_Q : | |
1130 | PBF_REG_P4_TQ_OCCUPANCY, | |
1131 | (CHIP_IS_E3B0(bp)) ? | |
1132 | PBF_REG_TQ_LINES_FREED_CNT_LB_Q : | |
1133 | PBF_REG_P4_TQ_LINES_FREED_CNT} | |
1134 | }; | |
1135 | ||
1136 | struct pbf_pN_buf_regs buf_regs[] = { | |
1137 | {0, (CHIP_IS_E3B0(bp)) ? | |
1138 | PBF_REG_INIT_CRD_Q0 : | |
1139 | PBF_REG_P0_INIT_CRD , | |
1140 | (CHIP_IS_E3B0(bp)) ? | |
1141 | PBF_REG_CREDIT_Q0 : | |
1142 | PBF_REG_P0_CREDIT, | |
1143 | (CHIP_IS_E3B0(bp)) ? | |
1144 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 : | |
1145 | PBF_REG_P0_INTERNAL_CRD_FREED_CNT}, | |
1146 | {1, (CHIP_IS_E3B0(bp)) ? | |
1147 | PBF_REG_INIT_CRD_Q1 : | |
1148 | PBF_REG_P1_INIT_CRD, | |
1149 | (CHIP_IS_E3B0(bp)) ? | |
1150 | PBF_REG_CREDIT_Q1 : | |
1151 | PBF_REG_P1_CREDIT, | |
1152 | (CHIP_IS_E3B0(bp)) ? | |
1153 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 : | |
1154 | PBF_REG_P1_INTERNAL_CRD_FREED_CNT}, | |
1155 | {4, (CHIP_IS_E3B0(bp)) ? | |
1156 | PBF_REG_INIT_CRD_LB_Q : | |
1157 | PBF_REG_P4_INIT_CRD, | |
1158 | (CHIP_IS_E3B0(bp)) ? | |
1159 | PBF_REG_CREDIT_LB_Q : | |
1160 | PBF_REG_P4_CREDIT, | |
1161 | (CHIP_IS_E3B0(bp)) ? | |
1162 | PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q : | |
1163 | PBF_REG_P4_INTERNAL_CRD_FREED_CNT}, | |
1164 | }; | |
1165 | ||
1166 | int i; | |
1167 | ||
1168 | /* Verify the command queues are flushed P0, P1, P4 */ | |
1169 | for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) | |
1170 | bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count); | |
1171 | ||
1172 | ||
1173 | /* Verify the transmission buffers are flushed P0, P1, P4 */ | |
1174 | for (i = 0; i < ARRAY_SIZE(buf_regs); i++) | |
1175 | bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count); | |
1176 | } | |
1177 | ||
1178 | #define OP_GEN_PARAM(param) \ | |
1179 | (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM) | |
1180 | ||
1181 | #define OP_GEN_TYPE(type) \ | |
1182 | (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE) | |
1183 | ||
1184 | #define OP_GEN_AGG_VECT(index) \ | |
1185 | (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX) | |
1186 | ||
1187 | ||
1188 | static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, | |
1189 | u32 poll_cnt) | |
1190 | { | |
1191 | struct sdm_op_gen op_gen = {0}; | |
1192 | ||
1193 | u32 comp_addr = BAR_CSTRORM_INTMEM + | |
1194 | CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func); | |
1195 | int ret = 0; | |
1196 | ||
1197 | if (REG_RD(bp, comp_addr)) { | |
89db4ad8 | 1198 | BNX2X_ERR("Cleanup complete was not 0 before sending\n"); |
619c5cb6 VZ |
1199 | return 1; |
1200 | } | |
1201 | ||
1202 | op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX); | |
1203 | op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE); | |
1204 | op_gen.command |= OP_GEN_AGG_VECT(clnup_func); | |
1205 | op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT; | |
1206 | ||
89db4ad8 | 1207 | DP(BNX2X_MSG_SP, "sending FW Final cleanup\n"); |
619c5cb6 VZ |
1208 | REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command); |
1209 | ||
1210 | if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) { | |
1211 | BNX2X_ERR("FW final cleanup did not succeed\n"); | |
51c1a580 MS |
1212 | DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n", |
1213 | (REG_RD(bp, comp_addr))); | |
619c5cb6 VZ |
1214 | ret = 1; |
1215 | } | |
1216 | /* Zero completion for nxt FLR */ | |
1217 | REG_WR(bp, comp_addr, 0); | |
1218 | ||
1219 | return ret; | |
1220 | } | |
1221 | ||
1222 | static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev) | |
1223 | { | |
1224 | int pos; | |
1225 | u16 status; | |
1226 | ||
77c98e6a | 1227 | pos = pci_pcie_cap(dev); |
619c5cb6 VZ |
1228 | if (!pos) |
1229 | return false; | |
1230 | ||
1231 | pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); | |
1232 | return status & PCI_EXP_DEVSTA_TRPND; | |
1233 | } | |
1234 | ||
1235 | /* PF FLR specific routines | |
1236 | */ | |
1237 | static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt) | |
1238 | { | |
1239 | ||
1240 | /* wait for CFC PF usage-counter to zero (includes all the VFs) */ | |
1241 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1242 | CFC_REG_NUM_LCIDS_INSIDE_PF, | |
1243 | "CFC PF usage counter timed out", | |
1244 | poll_cnt)) | |
1245 | return 1; | |
1246 | ||
1247 | ||
1248 | /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */ | |
1249 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1250 | DORQ_REG_PF_USAGE_CNT, | |
1251 | "DQ PF usage counter timed out", | |
1252 | poll_cnt)) | |
1253 | return 1; | |
1254 | ||
1255 | /* Wait for QM PF usage-counter to zero (until DQ cleanup) */ | |
1256 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1257 | QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp), | |
1258 | "QM PF usage counter timed out", | |
1259 | poll_cnt)) | |
1260 | return 1; | |
1261 | ||
1262 | /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */ | |
1263 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1264 | TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp), | |
1265 | "Timers VNIC usage counter timed out", | |
1266 | poll_cnt)) | |
1267 | return 1; | |
1268 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1269 | TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp), | |
1270 | "Timers NUM_SCANS usage counter timed out", | |
1271 | poll_cnt)) | |
1272 | return 1; | |
1273 | ||
1274 | /* Wait DMAE PF usage counter to zero */ | |
1275 | if (bnx2x_flr_clnup_poll_hw_counter(bp, | |
1276 | dmae_reg_go_c[INIT_DMAE_C(bp)], | |
1277 | "DMAE dommand register timed out", | |
1278 | poll_cnt)) | |
1279 | return 1; | |
1280 | ||
1281 | return 0; | |
1282 | } | |
1283 | ||
1284 | static void bnx2x_hw_enable_status(struct bnx2x *bp) | |
1285 | { | |
1286 | u32 val; | |
1287 | ||
1288 | val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF); | |
1289 | DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val); | |
1290 | ||
1291 | val = REG_RD(bp, PBF_REG_DISABLE_PF); | |
1292 | DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val); | |
1293 | ||
1294 | val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN); | |
1295 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val); | |
1296 | ||
1297 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN); | |
1298 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val); | |
1299 | ||
1300 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK); | |
1301 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val); | |
1302 | ||
1303 | val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR); | |
1304 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val); | |
1305 | ||
1306 | val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR); | |
1307 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val); | |
1308 | ||
1309 | val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); | |
1310 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", | |
1311 | val); | |
1312 | } | |
1313 | ||
1314 | static int bnx2x_pf_flr_clnup(struct bnx2x *bp) | |
1315 | { | |
1316 | u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp); | |
1317 | ||
1318 | DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp)); | |
1319 | ||
1320 | /* Re-enable PF target read access */ | |
1321 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); | |
1322 | ||
1323 | /* Poll HW usage counters */ | |
89db4ad8 | 1324 | DP(BNX2X_MSG_SP, "Polling usage counters\n"); |
619c5cb6 VZ |
1325 | if (bnx2x_poll_hw_usage_counters(bp, poll_cnt)) |
1326 | return -EBUSY; | |
1327 | ||
1328 | /* Zero the igu 'trailing edge' and 'leading edge' */ | |
1329 | ||
1330 | /* Send the FW cleanup command */ | |
1331 | if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt)) | |
1332 | return -EBUSY; | |
1333 | ||
1334 | /* ATC cleanup */ | |
1335 | ||
1336 | /* Verify TX hw is flushed */ | |
1337 | bnx2x_tx_hw_flushed(bp, poll_cnt); | |
1338 | ||
1339 | /* Wait 100ms (not adjusted according to platform) */ | |
1340 | msleep(100); | |
1341 | ||
1342 | /* Verify no pending pci transactions */ | |
1343 | if (bnx2x_is_pcie_pending(bp->pdev)) | |
1344 | BNX2X_ERR("PCIE Transactions still pending\n"); | |
1345 | ||
1346 | /* Debug */ | |
1347 | bnx2x_hw_enable_status(bp); | |
1348 | ||
1349 | /* | |
1350 | * Master enable - Due to WB DMAE writes performed before this | |
1351 | * register is re-initialized as part of the regular function init | |
1352 | */ | |
1353 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
1354 | ||
1355 | return 0; | |
1356 | } | |
1357 | ||
f2e0899f | 1358 | static void bnx2x_hc_int_enable(struct bnx2x *bp) |
a2fbb9ea | 1359 | { |
34f80b04 | 1360 | int port = BP_PORT(bp); |
a2fbb9ea ET |
1361 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
1362 | u32 val = REG_RD(bp, addr); | |
1363 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; | |
8badd27a | 1364 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
a2fbb9ea ET |
1365 | |
1366 | if (msix) { | |
8badd27a EG |
1367 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
1368 | HC_CONFIG_0_REG_INT_LINE_EN_0); | |
a2fbb9ea ET |
1369 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
1370 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
8badd27a EG |
1371 | } else if (msi) { |
1372 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; | |
1373 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
1374 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
1375 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
a2fbb9ea ET |
1376 | } else { |
1377 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
615f8fd9 | 1378 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
a2fbb9ea ET |
1379 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
1380 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
615f8fd9 | 1381 | |
a0fd065c | 1382 | if (!CHIP_IS_E1(bp)) { |
51c1a580 MS |
1383 | DP(NETIF_MSG_IFUP, |
1384 | "write %x to HC %d (addr 0x%x)\n", val, port, addr); | |
615f8fd9 | 1385 | |
a0fd065c | 1386 | REG_WR(bp, addr, val); |
615f8fd9 | 1387 | |
a0fd065c DK |
1388 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
1389 | } | |
a2fbb9ea ET |
1390 | } |
1391 | ||
a0fd065c DK |
1392 | if (CHIP_IS_E1(bp)) |
1393 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF); | |
1394 | ||
51c1a580 MS |
1395 | DP(NETIF_MSG_IFUP, |
1396 | "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr, | |
1397 | (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); | |
a2fbb9ea ET |
1398 | |
1399 | REG_WR(bp, addr, val); | |
37dbbf32 EG |
1400 | /* |
1401 | * Ensure that HC_CONFIG is written before leading/trailing edge config | |
1402 | */ | |
1403 | mmiowb(); | |
1404 | barrier(); | |
34f80b04 | 1405 | |
f2e0899f | 1406 | if (!CHIP_IS_E1(bp)) { |
34f80b04 | 1407 | /* init leading/trailing edge */ |
fb3bff17 | 1408 | if (IS_MF(bp)) { |
3395a033 | 1409 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
34f80b04 | 1410 | if (bp->port.pmf) |
4acac6a5 EG |
1411 | /* enable nig and gpio3 attention */ |
1412 | val |= 0x1100; | |
34f80b04 EG |
1413 | } else |
1414 | val = 0xffff; | |
1415 | ||
1416 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
1417 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
1418 | } | |
37dbbf32 EG |
1419 | |
1420 | /* Make sure that interrupts are indeed enabled from here on */ | |
1421 | mmiowb(); | |
a2fbb9ea ET |
1422 | } |
1423 | ||
f2e0899f DK |
1424 | static void bnx2x_igu_int_enable(struct bnx2x *bp) |
1425 | { | |
1426 | u32 val; | |
1427 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; | |
1428 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; | |
1429 | ||
1430 | val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
1431 | ||
1432 | if (msix) { | |
1433 | val &= ~(IGU_PF_CONF_INT_LINE_EN | | |
1434 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1435 | val |= (IGU_PF_CONF_FUNC_EN | | |
1436 | IGU_PF_CONF_MSI_MSIX_EN | | |
1437 | IGU_PF_CONF_ATTN_BIT_EN); | |
1438 | } else if (msi) { | |
1439 | val &= ~IGU_PF_CONF_INT_LINE_EN; | |
1440 | val |= (IGU_PF_CONF_FUNC_EN | | |
1441 | IGU_PF_CONF_MSI_MSIX_EN | | |
1442 | IGU_PF_CONF_ATTN_BIT_EN | | |
1443 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1444 | } else { | |
1445 | val &= ~IGU_PF_CONF_MSI_MSIX_EN; | |
1446 | val |= (IGU_PF_CONF_FUNC_EN | | |
1447 | IGU_PF_CONF_INT_LINE_EN | | |
1448 | IGU_PF_CONF_ATTN_BIT_EN | | |
1449 | IGU_PF_CONF_SINGLE_ISR_EN); | |
1450 | } | |
1451 | ||
51c1a580 | 1452 | DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n", |
f2e0899f DK |
1453 | val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
1454 | ||
1455 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1456 | ||
1457 | barrier(); | |
1458 | ||
1459 | /* init leading/trailing edge */ | |
1460 | if (IS_MF(bp)) { | |
3395a033 | 1461 | val = (0xee0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
1462 | if (bp->port.pmf) |
1463 | /* enable nig and gpio3 attention */ | |
1464 | val |= 0x1100; | |
1465 | } else | |
1466 | val = 0xffff; | |
1467 | ||
1468 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); | |
1469 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
1470 | ||
1471 | /* Make sure that interrupts are indeed enabled from here on */ | |
1472 | mmiowb(); | |
1473 | } | |
1474 | ||
1475 | void bnx2x_int_enable(struct bnx2x *bp) | |
1476 | { | |
1477 | if (bp->common.int_block == INT_BLOCK_HC) | |
1478 | bnx2x_hc_int_enable(bp); | |
1479 | else | |
1480 | bnx2x_igu_int_enable(bp); | |
1481 | } | |
1482 | ||
1483 | static void bnx2x_hc_int_disable(struct bnx2x *bp) | |
a2fbb9ea | 1484 | { |
34f80b04 | 1485 | int port = BP_PORT(bp); |
a2fbb9ea ET |
1486 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
1487 | u32 val = REG_RD(bp, addr); | |
1488 | ||
a0fd065c DK |
1489 | /* |
1490 | * in E1 we must use only PCI configuration space to disable | |
1491 | * MSI/MSIX capablility | |
1492 | * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block | |
1493 | */ | |
1494 | if (CHIP_IS_E1(bp)) { | |
1495 | /* Since IGU_PF_CONF_MSI_MSIX_EN still always on | |
1496 | * Use mask register to prevent from HC sending interrupts | |
1497 | * after we exit the function | |
1498 | */ | |
1499 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0); | |
1500 | ||
1501 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
1502 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
1503 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
1504 | } else | |
1505 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | | |
1506 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | | |
1507 | HC_CONFIG_0_REG_INT_LINE_EN_0 | | |
1508 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); | |
a2fbb9ea | 1509 | |
51c1a580 MS |
1510 | DP(NETIF_MSG_IFDOWN, |
1511 | "write %x to HC %d (addr 0x%x)\n", | |
a2fbb9ea ET |
1512 | val, port, addr); |
1513 | ||
8badd27a EG |
1514 | /* flush all outstanding writes */ |
1515 | mmiowb(); | |
1516 | ||
a2fbb9ea ET |
1517 | REG_WR(bp, addr, val); |
1518 | if (REG_RD(bp, addr) != val) | |
1519 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); | |
1520 | } | |
1521 | ||
f2e0899f DK |
1522 | static void bnx2x_igu_int_disable(struct bnx2x *bp) |
1523 | { | |
1524 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
1525 | ||
1526 | val &= ~(IGU_PF_CONF_MSI_MSIX_EN | | |
1527 | IGU_PF_CONF_INT_LINE_EN | | |
1528 | IGU_PF_CONF_ATTN_BIT_EN); | |
1529 | ||
51c1a580 | 1530 | DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val); |
f2e0899f DK |
1531 | |
1532 | /* flush all outstanding writes */ | |
1533 | mmiowb(); | |
1534 | ||
1535 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
1536 | if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val) | |
1537 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); | |
1538 | } | |
1539 | ||
6383c0b3 | 1540 | void bnx2x_int_disable(struct bnx2x *bp) |
f2e0899f DK |
1541 | { |
1542 | if (bp->common.int_block == INT_BLOCK_HC) | |
1543 | bnx2x_hc_int_disable(bp); | |
1544 | else | |
1545 | bnx2x_igu_int_disable(bp); | |
1546 | } | |
1547 | ||
9f6c9258 | 1548 | void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
a2fbb9ea | 1549 | { |
a2fbb9ea | 1550 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
8badd27a | 1551 | int i, offset; |
a2fbb9ea | 1552 | |
f8ef6e44 YG |
1553 | if (disable_hw) |
1554 | /* prevent the HW from sending interrupts */ | |
1555 | bnx2x_int_disable(bp); | |
a2fbb9ea ET |
1556 | |
1557 | /* make sure all ISRs are done */ | |
1558 | if (msix) { | |
8badd27a EG |
1559 | synchronize_irq(bp->msix_table[0].vector); |
1560 | offset = 1; | |
37b091ba MC |
1561 | #ifdef BCM_CNIC |
1562 | offset++; | |
1563 | #endif | |
ec6ba945 | 1564 | for_each_eth_queue(bp, i) |
754a2f52 | 1565 | synchronize_irq(bp->msix_table[offset++].vector); |
a2fbb9ea ET |
1566 | } else |
1567 | synchronize_irq(bp->pdev->irq); | |
1568 | ||
1569 | /* make sure sp_task is not running */ | |
1cf167f2 | 1570 | cancel_delayed_work(&bp->sp_task); |
3deb8167 | 1571 | cancel_delayed_work(&bp->period_task); |
1cf167f2 | 1572 | flush_workqueue(bnx2x_wq); |
a2fbb9ea ET |
1573 | } |
1574 | ||
34f80b04 | 1575 | /* fast path */ |
a2fbb9ea ET |
1576 | |
1577 | /* | |
34f80b04 | 1578 | * General service functions |
a2fbb9ea ET |
1579 | */ |
1580 | ||
72fd0718 VZ |
1581 | /* Return true if succeeded to acquire the lock */ |
1582 | static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource) | |
1583 | { | |
1584 | u32 lock_status; | |
1585 | u32 resource_bit = (1 << resource); | |
1586 | int func = BP_FUNC(bp); | |
1587 | u32 hw_lock_control_reg; | |
1588 | ||
51c1a580 MS |
1589 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1590 | "Trying to take a lock on resource %d\n", resource); | |
72fd0718 VZ |
1591 | |
1592 | /* Validating that the resource is within range */ | |
1593 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1594 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
72fd0718 VZ |
1595 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
1596 | resource, HW_LOCK_MAX_RESOURCE_VALUE); | |
0fdf4d09 | 1597 | return false; |
72fd0718 VZ |
1598 | } |
1599 | ||
1600 | if (func <= 5) | |
1601 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1602 | else | |
1603 | hw_lock_control_reg = | |
1604 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1605 | ||
1606 | /* Try to acquire the lock */ | |
1607 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); | |
1608 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
1609 | if (lock_status & resource_bit) | |
1610 | return true; | |
1611 | ||
51c1a580 MS |
1612 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, |
1613 | "Failed to get a lock on resource %d\n", resource); | |
72fd0718 VZ |
1614 | return false; |
1615 | } | |
1616 | ||
c9ee9206 VZ |
1617 | /** |
1618 | * bnx2x_get_leader_lock_resource - get the recovery leader resource id | |
1619 | * | |
1620 | * @bp: driver handle | |
1621 | * | |
1622 | * Returns the recovery leader resource id according to the engine this function | |
1623 | * belongs to. Currently only only 2 engines is supported. | |
1624 | */ | |
1625 | static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp) | |
1626 | { | |
1627 | if (BP_PATH(bp)) | |
1628 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_1; | |
1629 | else | |
1630 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_0; | |
1631 | } | |
1632 | ||
1633 | /** | |
1634 | * bnx2x_trylock_leader_lock- try to aquire a leader lock. | |
1635 | * | |
1636 | * @bp: driver handle | |
1637 | * | |
1638 | * Tries to aquire a leader lock for cuurent engine. | |
1639 | */ | |
1640 | static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp) | |
1641 | { | |
1642 | return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1643 | } | |
1644 | ||
993ac7b5 | 1645 | #ifdef BCM_CNIC |
619c5cb6 | 1646 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err); |
993ac7b5 | 1647 | #endif |
3196a88a | 1648 | |
619c5cb6 | 1649 | void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe) |
a2fbb9ea ET |
1650 | { |
1651 | struct bnx2x *bp = fp->bp; | |
1652 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
1653 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); | |
619c5cb6 VZ |
1654 | enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX; |
1655 | struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj; | |
a2fbb9ea | 1656 | |
34f80b04 | 1657 | DP(BNX2X_MSG_SP, |
a2fbb9ea | 1658 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
0626b899 | 1659 | fp->index, cid, command, bp->state, |
34f80b04 | 1660 | rr_cqe->ramrod_cqe.ramrod_type); |
a2fbb9ea | 1661 | |
619c5cb6 VZ |
1662 | switch (command) { |
1663 | case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE): | |
d6cae238 | 1664 | DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid); |
619c5cb6 VZ |
1665 | drv_cmd = BNX2X_Q_CMD_UPDATE; |
1666 | break; | |
d6cae238 | 1667 | |
619c5cb6 | 1668 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP): |
d6cae238 | 1669 | DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid); |
619c5cb6 | 1670 | drv_cmd = BNX2X_Q_CMD_SETUP; |
a2fbb9ea ET |
1671 | break; |
1672 | ||
6383c0b3 | 1673 | case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP): |
51c1a580 | 1674 | DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid); |
6383c0b3 AE |
1675 | drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; |
1676 | break; | |
1677 | ||
619c5cb6 | 1678 | case (RAMROD_CMD_ID_ETH_HALT): |
d6cae238 | 1679 | DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid); |
619c5cb6 | 1680 | drv_cmd = BNX2X_Q_CMD_HALT; |
a2fbb9ea ET |
1681 | break; |
1682 | ||
619c5cb6 | 1683 | case (RAMROD_CMD_ID_ETH_TERMINATE): |
d6cae238 | 1684 | DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid); |
619c5cb6 | 1685 | drv_cmd = BNX2X_Q_CMD_TERMINATE; |
a2fbb9ea ET |
1686 | break; |
1687 | ||
619c5cb6 | 1688 | case (RAMROD_CMD_ID_ETH_EMPTY): |
d6cae238 | 1689 | DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid); |
619c5cb6 | 1690 | drv_cmd = BNX2X_Q_CMD_EMPTY; |
993ac7b5 | 1691 | break; |
619c5cb6 VZ |
1692 | |
1693 | default: | |
1694 | BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n", | |
1695 | command, fp->index); | |
1696 | return; | |
523224a3 | 1697 | } |
3196a88a | 1698 | |
619c5cb6 VZ |
1699 | if ((drv_cmd != BNX2X_Q_CMD_MAX) && |
1700 | q_obj->complete_cmd(bp, q_obj, drv_cmd)) | |
1701 | /* q_obj->complete_cmd() failure means that this was | |
1702 | * an unexpected completion. | |
1703 | * | |
1704 | * In this case we don't want to increase the bp->spq_left | |
1705 | * because apparently we haven't sent this command the first | |
1706 | * place. | |
1707 | */ | |
1708 | #ifdef BNX2X_STOP_ON_ERROR | |
1709 | bnx2x_panic(); | |
1710 | #else | |
1711 | return; | |
1712 | #endif | |
1713 | ||
8fe23fbd | 1714 | smp_mb__before_atomic_inc(); |
6e30dd4e | 1715 | atomic_inc(&bp->cq_spq_left); |
619c5cb6 VZ |
1716 | /* push the change in bp->spq_left and towards the memory */ |
1717 | smp_mb__after_atomic_inc(); | |
49d66772 | 1718 | |
d6cae238 VZ |
1719 | DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left)); |
1720 | ||
523224a3 | 1721 | return; |
a2fbb9ea ET |
1722 | } |
1723 | ||
619c5cb6 VZ |
1724 | void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
1725 | u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod) | |
1726 | { | |
1727 | u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset; | |
1728 | ||
1729 | bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod, | |
1730 | start); | |
1731 | } | |
1732 | ||
9f6c9258 | 1733 | irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
a2fbb9ea | 1734 | { |
555f6c78 | 1735 | struct bnx2x *bp = netdev_priv(dev_instance); |
a2fbb9ea | 1736 | u16 status = bnx2x_ack_int(bp); |
34f80b04 | 1737 | u16 mask; |
ca00392c | 1738 | int i; |
6383c0b3 | 1739 | u8 cos; |
a2fbb9ea | 1740 | |
34f80b04 | 1741 | /* Return here if interrupt is shared and it's not for us */ |
a2fbb9ea ET |
1742 | if (unlikely(status == 0)) { |
1743 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); | |
1744 | return IRQ_NONE; | |
1745 | } | |
f5372251 | 1746 | DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status); |
a2fbb9ea | 1747 | |
3196a88a EG |
1748 | #ifdef BNX2X_STOP_ON_ERROR |
1749 | if (unlikely(bp->panic)) | |
1750 | return IRQ_HANDLED; | |
1751 | #endif | |
1752 | ||
ec6ba945 | 1753 | for_each_eth_queue(bp, i) { |
ca00392c | 1754 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
a2fbb9ea | 1755 | |
6383c0b3 | 1756 | mask = 0x2 << (fp->index + CNIC_PRESENT); |
ca00392c | 1757 | if (status & mask) { |
619c5cb6 | 1758 | /* Handle Rx or Tx according to SB id */ |
54b9ddaa | 1759 | prefetch(fp->rx_cons_sb); |
6383c0b3 AE |
1760 | for_each_cos_in_tx_queue(fp, cos) |
1761 | prefetch(fp->txdata[cos].tx_cons_sb); | |
523224a3 | 1762 | prefetch(&fp->sb_running_index[SM_RX_ID]); |
54b9ddaa | 1763 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
ca00392c EG |
1764 | status &= ~mask; |
1765 | } | |
a2fbb9ea ET |
1766 | } |
1767 | ||
993ac7b5 | 1768 | #ifdef BCM_CNIC |
523224a3 | 1769 | mask = 0x2; |
993ac7b5 MC |
1770 | if (status & (mask | 0x1)) { |
1771 | struct cnic_ops *c_ops = NULL; | |
1772 | ||
619c5cb6 VZ |
1773 | if (likely(bp->state == BNX2X_STATE_OPEN)) { |
1774 | rcu_read_lock(); | |
1775 | c_ops = rcu_dereference(bp->cnic_ops); | |
1776 | if (c_ops) | |
1777 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
1778 | rcu_read_unlock(); | |
1779 | } | |
993ac7b5 MC |
1780 | |
1781 | status &= ~mask; | |
1782 | } | |
1783 | #endif | |
a2fbb9ea | 1784 | |
34f80b04 | 1785 | if (unlikely(status & 0x1)) { |
1cf167f2 | 1786 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
a2fbb9ea ET |
1787 | |
1788 | status &= ~0x1; | |
1789 | if (!status) | |
1790 | return IRQ_HANDLED; | |
1791 | } | |
1792 | ||
cdaa7cb8 VZ |
1793 | if (unlikely(status)) |
1794 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", | |
34f80b04 | 1795 | status); |
a2fbb9ea | 1796 | |
c18487ee | 1797 | return IRQ_HANDLED; |
a2fbb9ea ET |
1798 | } |
1799 | ||
c18487ee YR |
1800 | /* Link */ |
1801 | ||
1802 | /* | |
1803 | * General service functions | |
1804 | */ | |
a2fbb9ea | 1805 | |
9f6c9258 | 1806 | int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1807 | { |
1808 | u32 lock_status; | |
1809 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1810 | int func = BP_FUNC(bp); |
1811 | u32 hw_lock_control_reg; | |
c18487ee | 1812 | int cnt; |
a2fbb9ea | 1813 | |
c18487ee YR |
1814 | /* Validating that the resource is within range */ |
1815 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1816 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1817 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1818 | return -EINVAL; | |
1819 | } | |
a2fbb9ea | 1820 | |
4a37fb66 YG |
1821 | if (func <= 5) { |
1822 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1823 | } else { | |
1824 | hw_lock_control_reg = | |
1825 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1826 | } | |
1827 | ||
c18487ee | 1828 | /* Validating that the resource is not already taken */ |
4a37fb66 | 1829 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 1830 | if (lock_status & resource_bit) { |
51c1a580 | 1831 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n", |
c18487ee YR |
1832 | lock_status, resource_bit); |
1833 | return -EEXIST; | |
1834 | } | |
a2fbb9ea | 1835 | |
46230476 EG |
1836 | /* Try for 5 second every 5ms */ |
1837 | for (cnt = 0; cnt < 1000; cnt++) { | |
c18487ee | 1838 | /* Try to acquire the lock */ |
4a37fb66 YG |
1839 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
1840 | lock_status = REG_RD(bp, hw_lock_control_reg); | |
c18487ee YR |
1841 | if (lock_status & resource_bit) |
1842 | return 0; | |
a2fbb9ea | 1843 | |
c18487ee | 1844 | msleep(5); |
a2fbb9ea | 1845 | } |
51c1a580 | 1846 | BNX2X_ERR("Timeout\n"); |
c18487ee YR |
1847 | return -EAGAIN; |
1848 | } | |
a2fbb9ea | 1849 | |
c9ee9206 VZ |
1850 | int bnx2x_release_leader_lock(struct bnx2x *bp) |
1851 | { | |
1852 | return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); | |
1853 | } | |
1854 | ||
9f6c9258 | 1855 | int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
c18487ee YR |
1856 | { |
1857 | u32 lock_status; | |
1858 | u32 resource_bit = (1 << resource); | |
4a37fb66 YG |
1859 | int func = BP_FUNC(bp); |
1860 | u32 hw_lock_control_reg; | |
a2fbb9ea | 1861 | |
c18487ee YR |
1862 | /* Validating that the resource is within range */ |
1863 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { | |
51c1a580 | 1864 | BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
c18487ee YR |
1865 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
1866 | return -EINVAL; | |
1867 | } | |
1868 | ||
4a37fb66 YG |
1869 | if (func <= 5) { |
1870 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); | |
1871 | } else { | |
1872 | hw_lock_control_reg = | |
1873 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); | |
1874 | } | |
1875 | ||
c18487ee | 1876 | /* Validating that the resource is currently taken */ |
4a37fb66 | 1877 | lock_status = REG_RD(bp, hw_lock_control_reg); |
c18487ee | 1878 | if (!(lock_status & resource_bit)) { |
51c1a580 | 1879 | BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n", |
c18487ee YR |
1880 | lock_status, resource_bit); |
1881 | return -EFAULT; | |
a2fbb9ea ET |
1882 | } |
1883 | ||
9f6c9258 DK |
1884 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
1885 | return 0; | |
c18487ee | 1886 | } |
a2fbb9ea | 1887 | |
9f6c9258 | 1888 | |
4acac6a5 EG |
1889 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
1890 | { | |
1891 | /* The GPIO should be swapped if swap register is set and active */ | |
1892 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
1893 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
1894 | int gpio_shift = gpio_num + | |
1895 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
1896 | u32 gpio_mask = (1 << gpio_shift); | |
1897 | u32 gpio_reg; | |
1898 | int value; | |
1899 | ||
1900 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
1901 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
1902 | return -EINVAL; | |
1903 | } | |
1904 | ||
1905 | /* read GPIO value */ | |
1906 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
1907 | ||
1908 | /* get the requested pin value */ | |
1909 | if ((gpio_reg & gpio_mask) == gpio_mask) | |
1910 | value = 1; | |
1911 | else | |
1912 | value = 0; | |
1913 | ||
1914 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); | |
1915 | ||
1916 | return value; | |
1917 | } | |
1918 | ||
17de50b7 | 1919 | int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
c18487ee YR |
1920 | { |
1921 | /* The GPIO should be swapped if swap register is set and active */ | |
1922 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
17de50b7 | 1923 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
c18487ee YR |
1924 | int gpio_shift = gpio_num + |
1925 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
1926 | u32 gpio_mask = (1 << gpio_shift); | |
1927 | u32 gpio_reg; | |
a2fbb9ea | 1928 | |
c18487ee YR |
1929 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
1930 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
1931 | return -EINVAL; | |
1932 | } | |
a2fbb9ea | 1933 | |
4a37fb66 | 1934 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
c18487ee YR |
1935 | /* read GPIO and mask except the float bits */ |
1936 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); | |
a2fbb9ea | 1937 | |
c18487ee YR |
1938 | switch (mode) { |
1939 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
51c1a580 MS |
1940 | DP(NETIF_MSG_LINK, |
1941 | "Set GPIO %d (shift %d) -> output low\n", | |
c18487ee YR |
1942 | gpio_num, gpio_shift); |
1943 | /* clear FLOAT and set CLR */ | |
1944 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
1945 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); | |
1946 | break; | |
a2fbb9ea | 1947 | |
c18487ee | 1948 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
51c1a580 MS |
1949 | DP(NETIF_MSG_LINK, |
1950 | "Set GPIO %d (shift %d) -> output high\n", | |
c18487ee YR |
1951 | gpio_num, gpio_shift); |
1952 | /* clear FLOAT and set SET */ | |
1953 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
1954 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); | |
1955 | break; | |
a2fbb9ea | 1956 | |
17de50b7 | 1957 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
51c1a580 MS |
1958 | DP(NETIF_MSG_LINK, |
1959 | "Set GPIO %d (shift %d) -> input\n", | |
c18487ee YR |
1960 | gpio_num, gpio_shift); |
1961 | /* set FLOAT */ | |
1962 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); | |
1963 | break; | |
a2fbb9ea | 1964 | |
c18487ee YR |
1965 | default: |
1966 | break; | |
a2fbb9ea ET |
1967 | } |
1968 | ||
c18487ee | 1969 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
4a37fb66 | 1970 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
f1410647 | 1971 | |
c18487ee | 1972 | return 0; |
a2fbb9ea ET |
1973 | } |
1974 | ||
0d40f0d4 YR |
1975 | int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode) |
1976 | { | |
1977 | u32 gpio_reg = 0; | |
1978 | int rc = 0; | |
1979 | ||
1980 | /* Any port swapping should be handled by caller. */ | |
1981 | ||
1982 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
1983 | /* read GPIO and mask except the float bits */ | |
1984 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); | |
1985 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
1986 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS); | |
1987 | gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS); | |
1988 | ||
1989 | switch (mode) { | |
1990 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: | |
1991 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins); | |
1992 | /* set CLR */ | |
1993 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS); | |
1994 | break; | |
1995 | ||
1996 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: | |
1997 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins); | |
1998 | /* set SET */ | |
1999 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS); | |
2000 | break; | |
2001 | ||
2002 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: | |
2003 | DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins); | |
2004 | /* set FLOAT */ | |
2005 | gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS); | |
2006 | break; | |
2007 | ||
2008 | default: | |
2009 | BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode); | |
2010 | rc = -EINVAL; | |
2011 | break; | |
2012 | } | |
2013 | ||
2014 | if (rc == 0) | |
2015 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); | |
2016 | ||
2017 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2018 | ||
2019 | return rc; | |
2020 | } | |
2021 | ||
4acac6a5 EG |
2022 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
2023 | { | |
2024 | /* The GPIO should be swapped if swap register is set and active */ | |
2025 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && | |
2026 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; | |
2027 | int gpio_shift = gpio_num + | |
2028 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); | |
2029 | u32 gpio_mask = (1 << gpio_shift); | |
2030 | u32 gpio_reg; | |
2031 | ||
2032 | if (gpio_num > MISC_REGISTERS_GPIO_3) { | |
2033 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); | |
2034 | return -EINVAL; | |
2035 | } | |
2036 | ||
2037 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2038 | /* read GPIO int */ | |
2039 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); | |
2040 | ||
2041 | switch (mode) { | |
2042 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: | |
51c1a580 MS |
2043 | DP(NETIF_MSG_LINK, |
2044 | "Clear GPIO INT %d (shift %d) -> output low\n", | |
2045 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2046 | /* clear SET and set CLR */ |
2047 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2048 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2049 | break; | |
2050 | ||
2051 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: | |
51c1a580 MS |
2052 | DP(NETIF_MSG_LINK, |
2053 | "Set GPIO INT %d (shift %d) -> output high\n", | |
2054 | gpio_num, gpio_shift); | |
4acac6a5 EG |
2055 | /* clear CLR and set SET */ |
2056 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); | |
2057 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); | |
2058 | break; | |
2059 | ||
2060 | default: | |
2061 | break; | |
2062 | } | |
2063 | ||
2064 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); | |
2065 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); | |
2066 | ||
2067 | return 0; | |
2068 | } | |
2069 | ||
c18487ee | 2070 | static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode) |
a2fbb9ea | 2071 | { |
c18487ee YR |
2072 | u32 spio_mask = (1 << spio_num); |
2073 | u32 spio_reg; | |
a2fbb9ea | 2074 | |
c18487ee YR |
2075 | if ((spio_num < MISC_REGISTERS_SPIO_4) || |
2076 | (spio_num > MISC_REGISTERS_SPIO_7)) { | |
2077 | BNX2X_ERR("Invalid SPIO %d\n", spio_num); | |
2078 | return -EINVAL; | |
a2fbb9ea ET |
2079 | } |
2080 | ||
4a37fb66 | 2081 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee YR |
2082 | /* read SPIO and mask except the float bits */ |
2083 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT); | |
a2fbb9ea | 2084 | |
c18487ee | 2085 | switch (mode) { |
6378c025 | 2086 | case MISC_REGISTERS_SPIO_OUTPUT_LOW: |
51c1a580 | 2087 | DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num); |
c18487ee YR |
2088 | /* clear FLOAT and set CLR */ |
2089 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); | |
2090 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS); | |
2091 | break; | |
a2fbb9ea | 2092 | |
6378c025 | 2093 | case MISC_REGISTERS_SPIO_OUTPUT_HIGH: |
51c1a580 | 2094 | DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num); |
c18487ee YR |
2095 | /* clear FLOAT and set SET */ |
2096 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); | |
2097 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS); | |
2098 | break; | |
a2fbb9ea | 2099 | |
c18487ee | 2100 | case MISC_REGISTERS_SPIO_INPUT_HI_Z: |
51c1a580 | 2101 | DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num); |
c18487ee YR |
2102 | /* set FLOAT */ |
2103 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); | |
2104 | break; | |
a2fbb9ea | 2105 | |
c18487ee YR |
2106 | default: |
2107 | break; | |
a2fbb9ea ET |
2108 | } |
2109 | ||
c18487ee | 2110 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
4a37fb66 | 2111 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
c18487ee | 2112 | |
a2fbb9ea ET |
2113 | return 0; |
2114 | } | |
2115 | ||
9f6c9258 | 2116 | void bnx2x_calc_fc_adv(struct bnx2x *bp) |
a2fbb9ea | 2117 | { |
a22f0788 | 2118 | u8 cfg_idx = bnx2x_get_link_cfg_idx(bp); |
ad33ea3a EG |
2119 | switch (bp->link_vars.ieee_fc & |
2120 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { | |
c18487ee | 2121 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
a22f0788 | 2122 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2123 | ADVERTISED_Pause); |
c18487ee | 2124 | break; |
356e2385 | 2125 | |
c18487ee | 2126 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
a22f0788 | 2127 | bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause | |
f85582f8 | 2128 | ADVERTISED_Pause); |
c18487ee | 2129 | break; |
356e2385 | 2130 | |
c18487ee | 2131 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
a22f0788 | 2132 | bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause; |
c18487ee | 2133 | break; |
356e2385 | 2134 | |
c18487ee | 2135 | default: |
a22f0788 | 2136 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
f85582f8 | 2137 | ADVERTISED_Pause); |
c18487ee YR |
2138 | break; |
2139 | } | |
2140 | } | |
f1410647 | 2141 | |
9f6c9258 | 2142 | u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
c18487ee | 2143 | { |
19680c48 EG |
2144 | if (!BP_NOMCP(bp)) { |
2145 | u8 rc; | |
a22f0788 YR |
2146 | int cfx_idx = bnx2x_get_link_cfg_idx(bp); |
2147 | u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx]; | |
1cb0c788 YR |
2148 | /* |
2149 | * Initialize link parameters structure variables | |
2150 | * It is recommended to turn off RX FC for jumbo frames | |
2151 | * for better performance | |
2152 | */ | |
2153 | if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000)) | |
c0700f90 | 2154 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; |
8c99e7b0 | 2155 | else |
c0700f90 | 2156 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
a2fbb9ea | 2157 | |
4a37fb66 | 2158 | bnx2x_acquire_phy_lock(bp); |
b5bf9068 | 2159 | |
a22f0788 | 2160 | if (load_mode == LOAD_DIAG) { |
1cb0c788 YR |
2161 | struct link_params *lp = &bp->link_params; |
2162 | lp->loopback_mode = LOOPBACK_XGXS; | |
2163 | /* do PHY loopback at 10G speed, if possible */ | |
2164 | if (lp->req_line_speed[cfx_idx] < SPEED_10000) { | |
2165 | if (lp->speed_cap_mask[cfx_idx] & | |
2166 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) | |
2167 | lp->req_line_speed[cfx_idx] = | |
2168 | SPEED_10000; | |
2169 | else | |
2170 | lp->req_line_speed[cfx_idx] = | |
2171 | SPEED_1000; | |
2172 | } | |
a22f0788 | 2173 | } |
b5bf9068 | 2174 | |
19680c48 | 2175 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
b5bf9068 | 2176 | |
4a37fb66 | 2177 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2178 | |
3c96c68b EG |
2179 | bnx2x_calc_fc_adv(bp); |
2180 | ||
b5bf9068 EG |
2181 | if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) { |
2182 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); | |
19680c48 | 2183 | bnx2x_link_report(bp); |
3deb8167 YR |
2184 | } else |
2185 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
a22f0788 | 2186 | bp->link_params.req_line_speed[cfx_idx] = req_line_speed; |
19680c48 EG |
2187 | return rc; |
2188 | } | |
f5372251 | 2189 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
19680c48 | 2190 | return -EINVAL; |
a2fbb9ea ET |
2191 | } |
2192 | ||
9f6c9258 | 2193 | void bnx2x_link_set(struct bnx2x *bp) |
a2fbb9ea | 2194 | { |
19680c48 | 2195 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2196 | bnx2x_acquire_phy_lock(bp); |
54c2fb78 | 2197 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
19680c48 | 2198 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
4a37fb66 | 2199 | bnx2x_release_phy_lock(bp); |
a2fbb9ea | 2200 | |
19680c48 EG |
2201 | bnx2x_calc_fc_adv(bp); |
2202 | } else | |
f5372251 | 2203 | BNX2X_ERR("Bootcode is missing - can not set link\n"); |
c18487ee | 2204 | } |
a2fbb9ea | 2205 | |
c18487ee YR |
2206 | static void bnx2x__link_reset(struct bnx2x *bp) |
2207 | { | |
19680c48 | 2208 | if (!BP_NOMCP(bp)) { |
4a37fb66 | 2209 | bnx2x_acquire_phy_lock(bp); |
589abe3a | 2210 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
4a37fb66 | 2211 | bnx2x_release_phy_lock(bp); |
19680c48 | 2212 | } else |
f5372251 | 2213 | BNX2X_ERR("Bootcode is missing - can not reset link\n"); |
c18487ee | 2214 | } |
a2fbb9ea | 2215 | |
a22f0788 | 2216 | u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes) |
c18487ee | 2217 | { |
2145a920 | 2218 | u8 rc = 0; |
a2fbb9ea | 2219 | |
2145a920 VZ |
2220 | if (!BP_NOMCP(bp)) { |
2221 | bnx2x_acquire_phy_lock(bp); | |
a22f0788 YR |
2222 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars, |
2223 | is_serdes); | |
2145a920 VZ |
2224 | bnx2x_release_phy_lock(bp); |
2225 | } else | |
2226 | BNX2X_ERR("Bootcode is missing - can not test link\n"); | |
a2fbb9ea | 2227 | |
c18487ee YR |
2228 | return rc; |
2229 | } | |
a2fbb9ea | 2230 | |
8a1c38d1 | 2231 | static void bnx2x_init_port_minmax(struct bnx2x *bp) |
34f80b04 | 2232 | { |
8a1c38d1 EG |
2233 | u32 r_param = bp->link_vars.line_speed / 8; |
2234 | u32 fair_periodic_timeout_usec; | |
2235 | u32 t_fair; | |
34f80b04 | 2236 | |
8a1c38d1 EG |
2237 | memset(&(bp->cmng.rs_vars), 0, |
2238 | sizeof(struct rate_shaping_vars_per_port)); | |
2239 | memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port)); | |
34f80b04 | 2240 | |
8a1c38d1 EG |
2241 | /* 100 usec in SDM ticks = 25 since each tick is 4 usec */ |
2242 | bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4; | |
34f80b04 | 2243 | |
8a1c38d1 EG |
2244 | /* this is the threshold below which no timer arming will occur |
2245 | 1.25 coefficient is for the threshold to be a little bigger | |
2246 | than the real time, to compensate for timer in-accuracy */ | |
2247 | bp->cmng.rs_vars.rs_threshold = | |
34f80b04 EG |
2248 | (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4; |
2249 | ||
8a1c38d1 EG |
2250 | /* resolution of fairness timer */ |
2251 | fair_periodic_timeout_usec = QM_ARB_BYTES / r_param; | |
2252 | /* for 10G it is 1000usec. for 1G it is 10000usec. */ | |
2253 | t_fair = T_FAIR_COEF / bp->link_vars.line_speed; | |
34f80b04 | 2254 | |
8a1c38d1 EG |
2255 | /* this is the threshold below which we won't arm the timer anymore */ |
2256 | bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES; | |
34f80b04 | 2257 | |
8a1c38d1 EG |
2258 | /* we multiply by 1e3/8 to get bytes/msec. |
2259 | We don't want the credits to pass a credit | |
2260 | of the t_fair*FAIR_MEM (algorithm resolution) */ | |
2261 | bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM; | |
2262 | /* since each tick is 4 usec */ | |
2263 | bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4; | |
34f80b04 EG |
2264 | } |
2265 | ||
2691d51d EG |
2266 | /* Calculates the sum of vn_min_rates. |
2267 | It's needed for further normalizing of the min_rates. | |
2268 | Returns: | |
2269 | sum of vn_min_rates. | |
2270 | or | |
2271 | 0 - if all the min_rates are 0. | |
2272 | In the later case fainess algorithm should be deactivated. | |
2273 | If not all min_rates are zero then those that are zeroes will be set to 1. | |
2274 | */ | |
2275 | static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp) | |
2276 | { | |
2277 | int all_zero = 1; | |
2691d51d EG |
2278 | int vn; |
2279 | ||
2280 | bp->vn_weight_sum = 0; | |
3395a033 | 2281 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
f2e0899f | 2282 | u32 vn_cfg = bp->mf_config[vn]; |
2691d51d EG |
2283 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
2284 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; | |
2285 | ||
2286 | /* Skip hidden vns */ | |
2287 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) | |
2288 | continue; | |
2289 | ||
2290 | /* If min rate is zero - set it to 1 */ | |
2291 | if (!vn_min_rate) | |
2292 | vn_min_rate = DEF_MIN_RATE; | |
2293 | else | |
2294 | all_zero = 0; | |
2295 | ||
2296 | bp->vn_weight_sum += vn_min_rate; | |
2297 | } | |
2298 | ||
30ae438b DK |
2299 | /* if ETS or all min rates are zeros - disable fairness */ |
2300 | if (BNX2X_IS_ETS_ENABLED(bp)) { | |
2301 | bp->cmng.flags.cmng_enables &= | |
2302 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; | |
2303 | DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n"); | |
2304 | } else if (all_zero) { | |
b015e3d1 EG |
2305 | bp->cmng.flags.cmng_enables &= |
2306 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; | |
2307 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" | |
2308 | " fairness will be disabled\n"); | |
2309 | } else | |
2310 | bp->cmng.flags.cmng_enables |= | |
2311 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; | |
2691d51d EG |
2312 | } |
2313 | ||
f2e0899f | 2314 | static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn) |
34f80b04 EG |
2315 | { |
2316 | struct rate_shaping_vars_per_vn m_rs_vn; | |
2317 | struct fairness_vars_per_vn m_fair_vn; | |
f2e0899f | 2318 | u32 vn_cfg = bp->mf_config[vn]; |
3395a033 | 2319 | int func = func_by_vn(bp, vn); |
34f80b04 EG |
2320 | u16 vn_min_rate, vn_max_rate; |
2321 | int i; | |
2322 | ||
2323 | /* If function is hidden - set min and max to zeroes */ | |
2324 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { | |
2325 | vn_min_rate = 0; | |
2326 | vn_max_rate = 0; | |
2327 | ||
2328 | } else { | |
faa6fcbb DK |
2329 | u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg); |
2330 | ||
34f80b04 EG |
2331 | vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
2332 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; | |
faa6fcbb DK |
2333 | /* If fairness is enabled (not all min rates are zeroes) and |
2334 | if current min rate is zero - set it to 1. | |
2335 | This is a requirement of the algorithm. */ | |
f2e0899f | 2336 | if (bp->vn_weight_sum && (vn_min_rate == 0)) |
34f80b04 | 2337 | vn_min_rate = DEF_MIN_RATE; |
faa6fcbb DK |
2338 | |
2339 | if (IS_MF_SI(bp)) | |
2340 | /* maxCfg in percents of linkspeed */ | |
2341 | vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100; | |
2342 | else | |
2343 | /* maxCfg is absolute in 100Mb units */ | |
2344 | vn_max_rate = maxCfg * 100; | |
34f80b04 | 2345 | } |
f85582f8 | 2346 | |
8a1c38d1 | 2347 | DP(NETIF_MSG_IFUP, |
b015e3d1 | 2348 | "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n", |
8a1c38d1 | 2349 | func, vn_min_rate, vn_max_rate, bp->vn_weight_sum); |
34f80b04 EG |
2350 | |
2351 | memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn)); | |
2352 | memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn)); | |
2353 | ||
2354 | /* global vn counter - maximal Mbps for this vn */ | |
2355 | m_rs_vn.vn_counter.rate = vn_max_rate; | |
2356 | ||
2357 | /* quota - number of bytes transmitted in this period */ | |
2358 | m_rs_vn.vn_counter.quota = | |
2359 | (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8; | |
2360 | ||
8a1c38d1 | 2361 | if (bp->vn_weight_sum) { |
34f80b04 EG |
2362 | /* credit for each period of the fairness algorithm: |
2363 | number of bytes in T_FAIR (the vn share the port rate). | |
8a1c38d1 EG |
2364 | vn_weight_sum should not be larger than 10000, thus |
2365 | T_FAIR_COEF / (8 * vn_weight_sum) will always be greater | |
2366 | than zero */ | |
34f80b04 | 2367 | m_fair_vn.vn_credit_delta = |
cdaa7cb8 VZ |
2368 | max_t(u32, (vn_min_rate * (T_FAIR_COEF / |
2369 | (8 * bp->vn_weight_sum))), | |
ff80ee02 DK |
2370 | (bp->cmng.fair_vars.fair_threshold + |
2371 | MIN_ABOVE_THRESH)); | |
cdaa7cb8 | 2372 | DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n", |
34f80b04 EG |
2373 | m_fair_vn.vn_credit_delta); |
2374 | } | |
2375 | ||
34f80b04 EG |
2376 | /* Store it to internal memory */ |
2377 | for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++) | |
2378 | REG_WR(bp, BAR_XSTRORM_INTMEM + | |
2379 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4, | |
2380 | ((u32 *)(&m_rs_vn))[i]); | |
2381 | ||
2382 | for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++) | |
2383 | REG_WR(bp, BAR_XSTRORM_INTMEM + | |
2384 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4, | |
2385 | ((u32 *)(&m_fair_vn))[i]); | |
2386 | } | |
f85582f8 | 2387 | |
523224a3 DK |
2388 | static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp) |
2389 | { | |
2390 | if (CHIP_REV_IS_SLOW(bp)) | |
2391 | return CMNG_FNS_NONE; | |
fb3bff17 | 2392 | if (IS_MF(bp)) |
523224a3 DK |
2393 | return CMNG_FNS_MINMAX; |
2394 | ||
2395 | return CMNG_FNS_NONE; | |
2396 | } | |
2397 | ||
2ae17f66 | 2398 | void bnx2x_read_mf_cfg(struct bnx2x *bp) |
523224a3 | 2399 | { |
0793f83f | 2400 | int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1); |
523224a3 DK |
2401 | |
2402 | if (BP_NOMCP(bp)) | |
2403 | return; /* what should be the default bvalue in this case */ | |
2404 | ||
0793f83f DK |
2405 | /* For 2 port configuration the absolute function number formula |
2406 | * is: | |
2407 | * abs_func = 2 * vn + BP_PORT + BP_PATH | |
2408 | * | |
2409 | * and there are 4 functions per port | |
2410 | * | |
2411 | * For 4 port configuration it is | |
2412 | * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH | |
2413 | * | |
2414 | * and there are 2 functions per port | |
2415 | */ | |
3395a033 | 2416 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) { |
0793f83f DK |
2417 | int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp); |
2418 | ||
2419 | if (func >= E1H_FUNC_MAX) | |
2420 | break; | |
2421 | ||
f2e0899f | 2422 | bp->mf_config[vn] = |
523224a3 DK |
2423 | MF_CFG_RD(bp, func_mf_config[func].config); |
2424 | } | |
2425 | } | |
2426 | ||
2427 | static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type) | |
2428 | { | |
2429 | ||
2430 | if (cmng_type == CMNG_FNS_MINMAX) { | |
2431 | int vn; | |
2432 | ||
2433 | /* clear cmng_enables */ | |
2434 | bp->cmng.flags.cmng_enables = 0; | |
2435 | ||
2436 | /* read mf conf from shmem */ | |
2437 | if (read_cfg) | |
2438 | bnx2x_read_mf_cfg(bp); | |
2439 | ||
2440 | /* Init rate shaping and fairness contexts */ | |
2441 | bnx2x_init_port_minmax(bp); | |
2442 | ||
2443 | /* vn_weight_sum and enable fairness if not 0 */ | |
2444 | bnx2x_calc_vn_weight_sum(bp); | |
2445 | ||
2446 | /* calculate and set min-max rate for each vn */ | |
c4154f25 | 2447 | if (bp->port.pmf) |
3395a033 | 2448 | for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) |
c4154f25 | 2449 | bnx2x_init_vn_minmax(bp, vn); |
523224a3 DK |
2450 | |
2451 | /* always enable rate shaping and fairness */ | |
2452 | bp->cmng.flags.cmng_enables |= | |
2453 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; | |
2454 | if (!bp->vn_weight_sum) | |
2455 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" | |
2456 | " fairness will be disabled\n"); | |
2457 | return; | |
2458 | } | |
2459 | ||
2460 | /* rate shaping and fairness are disabled */ | |
2461 | DP(NETIF_MSG_IFUP, | |
2462 | "rate shaping and fairness are disabled\n"); | |
2463 | } | |
34f80b04 | 2464 | |
c18487ee YR |
2465 | /* This function is called upon link interrupt */ |
2466 | static void bnx2x_link_attn(struct bnx2x *bp) | |
2467 | { | |
bb2a0f7a YG |
2468 | /* Make sure that we are synced with the current statistics */ |
2469 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2470 | ||
c18487ee | 2471 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
a2fbb9ea | 2472 | |
bb2a0f7a YG |
2473 | if (bp->link_vars.link_up) { |
2474 | ||
1c06328c | 2475 | /* dropless flow control */ |
f2e0899f | 2476 | if (!CHIP_IS_E1(bp) && bp->dropless_fc) { |
1c06328c EG |
2477 | int port = BP_PORT(bp); |
2478 | u32 pause_enabled = 0; | |
2479 | ||
2480 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) | |
2481 | pause_enabled = 1; | |
2482 | ||
2483 | REG_WR(bp, BAR_USTRORM_INTMEM + | |
ca00392c | 2484 | USTORM_ETH_PAUSE_ENABLED_OFFSET(port), |
1c06328c EG |
2485 | pause_enabled); |
2486 | } | |
2487 | ||
619c5cb6 | 2488 | if (bp->link_vars.mac_type != MAC_TYPE_EMAC) { |
bb2a0f7a YG |
2489 | struct host_port_stats *pstats; |
2490 | ||
2491 | pstats = bnx2x_sp(bp, port_stats); | |
619c5cb6 | 2492 | /* reset old mac stats */ |
bb2a0f7a YG |
2493 | memset(&(pstats->mac_stx[0]), 0, |
2494 | sizeof(struct mac_stx)); | |
2495 | } | |
f34d28ea | 2496 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a YG |
2497 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
2498 | } | |
2499 | ||
f2e0899f DK |
2500 | if (bp->link_vars.link_up && bp->link_vars.line_speed) { |
2501 | int cmng_fns = bnx2x_get_cmng_fns_mode(bp); | |
8a1c38d1 | 2502 | |
f2e0899f DK |
2503 | if (cmng_fns != CMNG_FNS_NONE) { |
2504 | bnx2x_cmng_fns_init(bp, false, cmng_fns); | |
2505 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
2506 | } else | |
2507 | /* rate shaping and fairness are disabled */ | |
2508 | DP(NETIF_MSG_IFUP, | |
2509 | "single function mode without fairness\n"); | |
34f80b04 | 2510 | } |
9fdc3e95 | 2511 | |
2ae17f66 VZ |
2512 | __bnx2x_link_report(bp); |
2513 | ||
9fdc3e95 DK |
2514 | if (IS_MF(bp)) |
2515 | bnx2x_link_sync_notify(bp); | |
c18487ee | 2516 | } |
a2fbb9ea | 2517 | |
9f6c9258 | 2518 | void bnx2x__link_status_update(struct bnx2x *bp) |
c18487ee | 2519 | { |
2ae17f66 | 2520 | if (bp->state != BNX2X_STATE_OPEN) |
c18487ee | 2521 | return; |
a2fbb9ea | 2522 | |
00253a8c DK |
2523 | /* read updated dcb configuration */ |
2524 | bnx2x_dcbx_pmf_update(bp); | |
2525 | ||
c18487ee | 2526 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); |
a2fbb9ea | 2527 | |
bb2a0f7a YG |
2528 | if (bp->link_vars.link_up) |
2529 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); | |
2530 | else | |
2531 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
2532 | ||
c18487ee YR |
2533 | /* indicate link status */ |
2534 | bnx2x_link_report(bp); | |
a2fbb9ea | 2535 | } |
a2fbb9ea | 2536 | |
34f80b04 EG |
2537 | static void bnx2x_pmf_update(struct bnx2x *bp) |
2538 | { | |
2539 | int port = BP_PORT(bp); | |
2540 | u32 val; | |
2541 | ||
2542 | bp->port.pmf = 1; | |
51c1a580 | 2543 | DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf); |
34f80b04 | 2544 | |
3deb8167 YR |
2545 | /* |
2546 | * We need the mb() to ensure the ordering between the writing to | |
2547 | * bp->port.pmf here and reading it from the bnx2x_periodic_task(). | |
2548 | */ | |
2549 | smp_mb(); | |
2550 | ||
2551 | /* queue a periodic task */ | |
2552 | queue_delayed_work(bnx2x_wq, &bp->period_task, 0); | |
2553 | ||
ef01854e DK |
2554 | bnx2x_dcbx_pmf_update(bp); |
2555 | ||
34f80b04 | 2556 | /* enable nig attention */ |
3395a033 | 2557 | val = (0xff0f | (1 << (BP_VN(bp) + 4))); |
f2e0899f DK |
2558 | if (bp->common.int_block == INT_BLOCK_HC) { |
2559 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); | |
2560 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); | |
619c5cb6 | 2561 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
2562 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); |
2563 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); | |
2564 | } | |
bb2a0f7a YG |
2565 | |
2566 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); | |
34f80b04 EG |
2567 | } |
2568 | ||
c18487ee | 2569 | /* end of Link */ |
a2fbb9ea ET |
2570 | |
2571 | /* slow path */ | |
2572 | ||
2573 | /* | |
2574 | * General service functions | |
2575 | */ | |
2576 | ||
2691d51d | 2577 | /* send the MCP a request, block until there is a reply */ |
a22f0788 | 2578 | u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param) |
2691d51d | 2579 | { |
f2e0899f | 2580 | int mb_idx = BP_FW_MB_IDX(bp); |
a5971d43 | 2581 | u32 seq; |
2691d51d EG |
2582 | u32 rc = 0; |
2583 | u32 cnt = 1; | |
2584 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; | |
2585 | ||
c4ff7cbf | 2586 | mutex_lock(&bp->fw_mb_mutex); |
a5971d43 | 2587 | seq = ++bp->fw_seq; |
f2e0899f DK |
2588 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param); |
2589 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq)); | |
2590 | ||
754a2f52 DK |
2591 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n", |
2592 | (command | seq), param); | |
2691d51d EG |
2593 | |
2594 | do { | |
2595 | /* let the FW do it's magic ... */ | |
2596 | msleep(delay); | |
2597 | ||
f2e0899f | 2598 | rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header); |
2691d51d | 2599 | |
c4ff7cbf EG |
2600 | /* Give the FW up to 5 second (500*10ms) */ |
2601 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); | |
2691d51d EG |
2602 | |
2603 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", | |
2604 | cnt*delay, rc, seq); | |
2605 | ||
2606 | /* is this a reply to our command? */ | |
2607 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) | |
2608 | rc &= FW_MSG_CODE_MASK; | |
2609 | else { | |
2610 | /* FW BUG! */ | |
2611 | BNX2X_ERR("FW failed to respond!\n"); | |
2612 | bnx2x_fw_dump(bp); | |
2613 | rc = 0; | |
2614 | } | |
c4ff7cbf | 2615 | mutex_unlock(&bp->fw_mb_mutex); |
2691d51d EG |
2616 | |
2617 | return rc; | |
2618 | } | |
2619 | ||
ec6ba945 | 2620 | |
619c5cb6 VZ |
2621 | void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p) |
2622 | { | |
2623 | if (CHIP_IS_E1x(bp)) { | |
2624 | struct tstorm_eth_function_common_config tcfg = {0}; | |
2625 | ||
2626 | storm_memset_func_cfg(bp, &tcfg, p->func_id); | |
2627 | } | |
2628 | ||
2629 | /* Enable the function in the FW */ | |
2630 | storm_memset_vf_to_pf(bp, p->func_id, p->pf_id); | |
2631 | storm_memset_func_en(bp, p->func_id, 1); | |
2632 | ||
2633 | /* spq */ | |
2634 | if (p->func_flgs & FUNC_FLG_SPQ) { | |
2635 | storm_memset_spq_addr(bp, p->spq_map, p->func_id); | |
2636 | REG_WR(bp, XSEM_REG_FAST_MEMORY + | |
2637 | XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod); | |
2638 | } | |
2639 | } | |
2640 | ||
6383c0b3 AE |
2641 | /** |
2642 | * bnx2x_get_tx_only_flags - Return common flags | |
2643 | * | |
2644 | * @bp device handle | |
2645 | * @fp queue handle | |
2646 | * @zero_stats TRUE if statistics zeroing is needed | |
2647 | * | |
2648 | * Return the flags that are common for the Tx-only and not normal connections. | |
2649 | */ | |
2650 | static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp, | |
2651 | struct bnx2x_fastpath *fp, | |
2652 | bool zero_stats) | |
28912902 | 2653 | { |
619c5cb6 VZ |
2654 | unsigned long flags = 0; |
2655 | ||
2656 | /* PF driver will always initialize the Queue to an ACTIVE state */ | |
2657 | __set_bit(BNX2X_Q_FLG_ACTIVE, &flags); | |
28912902 | 2658 | |
6383c0b3 AE |
2659 | /* tx only connections collect statistics (on the same index as the |
2660 | * parent connection). The statistics are zeroed when the parent | |
2661 | * connection is initialized. | |
2662 | */ | |
50f0a562 BW |
2663 | |
2664 | __set_bit(BNX2X_Q_FLG_STATS, &flags); | |
2665 | if (zero_stats) | |
2666 | __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags); | |
2667 | ||
6383c0b3 AE |
2668 | |
2669 | return flags; | |
2670 | } | |
2671 | ||
2672 | static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp, | |
2673 | struct bnx2x_fastpath *fp, | |
2674 | bool leading) | |
2675 | { | |
2676 | unsigned long flags = 0; | |
2677 | ||
619c5cb6 VZ |
2678 | /* calculate other queue flags */ |
2679 | if (IS_MF_SD(bp)) | |
2680 | __set_bit(BNX2X_Q_FLG_OV, &flags); | |
28912902 | 2681 | |
619c5cb6 VZ |
2682 | if (IS_FCOE_FP(fp)) |
2683 | __set_bit(BNX2X_Q_FLG_FCOE, &flags); | |
523224a3 | 2684 | |
f5219d8e | 2685 | if (!fp->disable_tpa) { |
619c5cb6 | 2686 | __set_bit(BNX2X_Q_FLG_TPA, &flags); |
f5219d8e | 2687 | __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags); |
621b4d66 DK |
2688 | if (fp->mode == TPA_MODE_GRO) |
2689 | __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags); | |
f5219d8e | 2690 | } |
619c5cb6 | 2691 | |
619c5cb6 VZ |
2692 | if (leading) { |
2693 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags); | |
2694 | __set_bit(BNX2X_Q_FLG_MCAST, &flags); | |
2695 | } | |
523224a3 | 2696 | |
619c5cb6 VZ |
2697 | /* Always set HW VLAN stripping */ |
2698 | __set_bit(BNX2X_Q_FLG_VLAN, &flags); | |
523224a3 | 2699 | |
6383c0b3 AE |
2700 | |
2701 | return flags | bnx2x_get_common_flags(bp, fp, true); | |
523224a3 DK |
2702 | } |
2703 | ||
619c5cb6 | 2704 | static void bnx2x_pf_q_prep_general(struct bnx2x *bp, |
6383c0b3 AE |
2705 | struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init, |
2706 | u8 cos) | |
619c5cb6 VZ |
2707 | { |
2708 | gen_init->stat_id = bnx2x_stats_id(fp); | |
2709 | gen_init->spcl_id = fp->cl_id; | |
2710 | ||
2711 | /* Always use mini-jumbo MTU for FCoE L2 ring */ | |
2712 | if (IS_FCOE_FP(fp)) | |
2713 | gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU; | |
2714 | else | |
2715 | gen_init->mtu = bp->dev->mtu; | |
6383c0b3 AE |
2716 | |
2717 | gen_init->cos = cos; | |
619c5cb6 VZ |
2718 | } |
2719 | ||
2720 | static void bnx2x_pf_rx_q_prep(struct bnx2x *bp, | |
523224a3 | 2721 | struct bnx2x_fastpath *fp, struct rxq_pause_params *pause, |
619c5cb6 | 2722 | struct bnx2x_rxq_setup_params *rxq_init) |
523224a3 | 2723 | { |
619c5cb6 | 2724 | u8 max_sge = 0; |
523224a3 DK |
2725 | u16 sge_sz = 0; |
2726 | u16 tpa_agg_size = 0; | |
2727 | ||
523224a3 | 2728 | if (!fp->disable_tpa) { |
dfacf138 DK |
2729 | pause->sge_th_lo = SGE_TH_LO(bp); |
2730 | pause->sge_th_hi = SGE_TH_HI(bp); | |
2731 | ||
2732 | /* validate SGE ring has enough to cross high threshold */ | |
2733 | WARN_ON(bp->dropless_fc && | |
2734 | pause->sge_th_hi + FW_PREFETCH_CNT > | |
2735 | MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES); | |
2736 | ||
523224a3 DK |
2737 | tpa_agg_size = min_t(u32, |
2738 | (min_t(u32, 8, MAX_SKB_FRAGS) * | |
2739 | SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff); | |
2740 | max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >> | |
2741 | SGE_PAGE_SHIFT; | |
2742 | max_sge = ((max_sge + PAGES_PER_SGE - 1) & | |
2743 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; | |
2744 | sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE, | |
2745 | 0xffff); | |
2746 | } | |
2747 | ||
2748 | /* pause - not for e1 */ | |
2749 | if (!CHIP_IS_E1(bp)) { | |
dfacf138 DK |
2750 | pause->bd_th_lo = BD_TH_LO(bp); |
2751 | pause->bd_th_hi = BD_TH_HI(bp); | |
2752 | ||
2753 | pause->rcq_th_lo = RCQ_TH_LO(bp); | |
2754 | pause->rcq_th_hi = RCQ_TH_HI(bp); | |
2755 | /* | |
2756 | * validate that rings have enough entries to cross | |
2757 | * high thresholds | |
2758 | */ | |
2759 | WARN_ON(bp->dropless_fc && | |
2760 | pause->bd_th_hi + FW_PREFETCH_CNT > | |
2761 | bp->rx_ring_size); | |
2762 | WARN_ON(bp->dropless_fc && | |
2763 | pause->rcq_th_hi + FW_PREFETCH_CNT > | |
2764 | NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT); | |
619c5cb6 | 2765 | |
523224a3 DK |
2766 | pause->pri_map = 1; |
2767 | } | |
2768 | ||
2769 | /* rxq setup */ | |
523224a3 DK |
2770 | rxq_init->dscr_map = fp->rx_desc_mapping; |
2771 | rxq_init->sge_map = fp->rx_sge_mapping; | |
2772 | rxq_init->rcq_map = fp->rx_comp_mapping; | |
2773 | rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE; | |
a8c94b91 | 2774 | |
619c5cb6 VZ |
2775 | /* This should be a maximum number of data bytes that may be |
2776 | * placed on the BD (not including paddings). | |
2777 | */ | |
e52fcb24 ED |
2778 | rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START - |
2779 | BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING; | |
a8c94b91 | 2780 | |
523224a3 | 2781 | rxq_init->cl_qzone_id = fp->cl_qzone_id; |
523224a3 DK |
2782 | rxq_init->tpa_agg_sz = tpa_agg_size; |
2783 | rxq_init->sge_buf_sz = sge_sz; | |
2784 | rxq_init->max_sges_pkt = max_sge; | |
619c5cb6 | 2785 | rxq_init->rss_engine_id = BP_FUNC(bp); |
259afa1f | 2786 | rxq_init->mcast_engine_id = BP_FUNC(bp); |
619c5cb6 VZ |
2787 | |
2788 | /* Maximum number or simultaneous TPA aggregation for this Queue. | |
2789 | * | |
2790 | * For PF Clients it should be the maximum avaliable number. | |
2791 | * VF driver(s) may want to define it to a smaller value. | |
2792 | */ | |
dfacf138 | 2793 | rxq_init->max_tpa_queues = MAX_AGG_QS(bp); |
619c5cb6 | 2794 | |
523224a3 DK |
2795 | rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
2796 | rxq_init->fw_sb_id = fp->fw_sb_id; | |
2797 | ||
ec6ba945 VZ |
2798 | if (IS_FCOE_FP(fp)) |
2799 | rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS; | |
2800 | else | |
6383c0b3 | 2801 | rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
523224a3 DK |
2802 | } |
2803 | ||
619c5cb6 | 2804 | static void bnx2x_pf_tx_q_prep(struct bnx2x *bp, |
6383c0b3 AE |
2805 | struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init, |
2806 | u8 cos) | |
523224a3 | 2807 | { |
6383c0b3 AE |
2808 | txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping; |
2809 | txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos; | |
523224a3 DK |
2810 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; |
2811 | txq_init->fw_sb_id = fp->fw_sb_id; | |
ec6ba945 | 2812 | |
619c5cb6 VZ |
2813 | /* |
2814 | * set the tss leading client id for TX classfication == | |
2815 | * leading RSS client id | |
2816 | */ | |
2817 | txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id); | |
2818 | ||
ec6ba945 VZ |
2819 | if (IS_FCOE_FP(fp)) { |
2820 | txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS; | |
2821 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE; | |
2822 | } | |
523224a3 DK |
2823 | } |
2824 | ||
8d96286a | 2825 | static void bnx2x_pf_init(struct bnx2x *bp) |
523224a3 DK |
2826 | { |
2827 | struct bnx2x_func_init_params func_init = {0}; | |
523224a3 DK |
2828 | struct event_ring_data eq_data = { {0} }; |
2829 | u16 flags; | |
2830 | ||
619c5cb6 | 2831 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
2832 | /* reset IGU PF statistics: MSIX + ATTN */ |
2833 | /* PF */ | |
2834 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
2835 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
2836 | (CHIP_MODE_IS_4_PORT(bp) ? | |
2837 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
2838 | /* ATTN */ | |
2839 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + | |
2840 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + | |
2841 | BNX2X_IGU_STAS_MSG_PF_CNT*4 + | |
2842 | (CHIP_MODE_IS_4_PORT(bp) ? | |
2843 | BP_FUNC(bp) : BP_VN(bp))*4, 0); | |
2844 | } | |
2845 | ||
523224a3 DK |
2846 | /* function setup flags */ |
2847 | flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); | |
2848 | ||
619c5cb6 VZ |
2849 | /* This flag is relevant for E1x only. |
2850 | * E2 doesn't have a TPA configuration in a function level. | |
523224a3 | 2851 | */ |
619c5cb6 | 2852 | flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; |
523224a3 DK |
2853 | |
2854 | func_init.func_flgs = flags; | |
2855 | func_init.pf_id = BP_FUNC(bp); | |
2856 | func_init.func_id = BP_FUNC(bp); | |
523224a3 DK |
2857 | func_init.spq_map = bp->spq_mapping; |
2858 | func_init.spq_prod = bp->spq_prod_idx; | |
2859 | ||
2860 | bnx2x_func_init(bp, &func_init); | |
2861 | ||
2862 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); | |
2863 | ||
2864 | /* | |
619c5cb6 VZ |
2865 | * Congestion management values depend on the link rate |
2866 | * There is no active link so initial link rate is set to 10 Gbps. | |
2867 | * When the link comes up The congestion management values are | |
2868 | * re-calculated according to the actual link rate. | |
2869 | */ | |
523224a3 DK |
2870 | bp->link_vars.line_speed = SPEED_10000; |
2871 | bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp)); | |
2872 | ||
2873 | /* Only the PMF sets the HW */ | |
2874 | if (bp->port.pmf) | |
2875 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
2876 | ||
523224a3 DK |
2877 | /* init Event Queue */ |
2878 | eq_data.base_addr.hi = U64_HI(bp->eq_mapping); | |
2879 | eq_data.base_addr.lo = U64_LO(bp->eq_mapping); | |
2880 | eq_data.producer = bp->eq_prod; | |
2881 | eq_data.index_id = HC_SP_INDEX_EQ_CONS; | |
2882 | eq_data.sb_id = DEF_SB_ID; | |
2883 | storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp)); | |
2884 | } | |
2885 | ||
2886 | ||
2887 | static void bnx2x_e1h_disable(struct bnx2x *bp) | |
2888 | { | |
2889 | int port = BP_PORT(bp); | |
2890 | ||
619c5cb6 | 2891 | bnx2x_tx_disable(bp); |
523224a3 DK |
2892 | |
2893 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
523224a3 DK |
2894 | } |
2895 | ||
2896 | static void bnx2x_e1h_enable(struct bnx2x *bp) | |
2897 | { | |
2898 | int port = BP_PORT(bp); | |
2899 | ||
2900 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); | |
2901 | ||
2902 | /* Tx queue should be only reenabled */ | |
2903 | netif_tx_wake_all_queues(bp->dev); | |
2904 | ||
2905 | /* | |
2906 | * Should not call netif_carrier_on since it will be called if the link | |
2907 | * is up when checking for link state | |
2908 | */ | |
2909 | } | |
2910 | ||
1d187b34 BW |
2911 | #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3 |
2912 | ||
2913 | static void bnx2x_drv_info_ether_stat(struct bnx2x *bp) | |
2914 | { | |
2915 | struct eth_stats_info *ether_stat = | |
2916 | &bp->slowpath->drv_info_to_mcp.ether_stat; | |
2917 | ||
2918 | /* leave last char as NULL */ | |
2919 | memcpy(ether_stat->version, DRV_MODULE_VERSION, | |
2920 | ETH_STAT_INFO_VERSION_LEN - 1); | |
2921 | ||
2922 | bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj, | |
2923 | DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED, | |
2924 | ether_stat->mac_local); | |
2925 | ||
2926 | ether_stat->mtu_size = bp->dev->mtu; | |
2927 | ||
2928 | if (bp->dev->features & NETIF_F_RXCSUM) | |
2929 | ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK; | |
2930 | if (bp->dev->features & NETIF_F_TSO) | |
2931 | ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK; | |
2932 | ether_stat->feature_flags |= bp->common.boot_mode; | |
2933 | ||
2934 | ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0; | |
2935 | ||
2936 | ether_stat->txq_size = bp->tx_ring_size; | |
2937 | ether_stat->rxq_size = bp->rx_ring_size; | |
2938 | } | |
2939 | ||
2940 | static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp) | |
2941 | { | |
f2fd5c34 | 2942 | #ifdef BCM_CNIC |
1d187b34 BW |
2943 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; |
2944 | struct fcoe_stats_info *fcoe_stat = | |
2945 | &bp->slowpath->drv_info_to_mcp.fcoe_stat; | |
2946 | ||
2947 | memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN); | |
2948 | ||
2949 | fcoe_stat->qos_priority = | |
2950 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE]; | |
2951 | ||
2952 | /* insert FCoE stats from ramrod response */ | |
2953 | if (!NO_FCOE(bp)) { | |
2954 | struct tstorm_per_queue_stats *fcoe_q_tstorm_stats = | |
2955 | &bp->fw_stats_data->queue_stats[FCOE_IDX]. | |
2956 | tstorm_queue_statistics; | |
2957 | ||
2958 | struct xstorm_per_queue_stats *fcoe_q_xstorm_stats = | |
2959 | &bp->fw_stats_data->queue_stats[FCOE_IDX]. | |
2960 | xstorm_queue_statistics; | |
2961 | ||
2962 | struct fcoe_statistics_params *fw_fcoe_stat = | |
2963 | &bp->fw_stats_data->fcoe; | |
2964 | ||
2965 | ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo, | |
2966 | fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt); | |
2967 | ||
2968 | ADD_64(fcoe_stat->rx_bytes_hi, | |
2969 | fcoe_q_tstorm_stats->rcv_ucast_bytes.hi, | |
2970 | fcoe_stat->rx_bytes_lo, | |
2971 | fcoe_q_tstorm_stats->rcv_ucast_bytes.lo); | |
2972 | ||
2973 | ADD_64(fcoe_stat->rx_bytes_hi, | |
2974 | fcoe_q_tstorm_stats->rcv_bcast_bytes.hi, | |
2975 | fcoe_stat->rx_bytes_lo, | |
2976 | fcoe_q_tstorm_stats->rcv_bcast_bytes.lo); | |
2977 | ||
2978 | ADD_64(fcoe_stat->rx_bytes_hi, | |
2979 | fcoe_q_tstorm_stats->rcv_mcast_bytes.hi, | |
2980 | fcoe_stat->rx_bytes_lo, | |
2981 | fcoe_q_tstorm_stats->rcv_mcast_bytes.lo); | |
2982 | ||
2983 | ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo, | |
2984 | fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt); | |
2985 | ||
2986 | ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo, | |
2987 | fcoe_q_tstorm_stats->rcv_ucast_pkts); | |
2988 | ||
2989 | ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo, | |
2990 | fcoe_q_tstorm_stats->rcv_bcast_pkts); | |
2991 | ||
2992 | ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo, | |
f33f1fcc | 2993 | fcoe_q_tstorm_stats->rcv_mcast_pkts); |
1d187b34 BW |
2994 | |
2995 | ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo, | |
2996 | fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt); | |
2997 | ||
2998 | ADD_64(fcoe_stat->tx_bytes_hi, | |
2999 | fcoe_q_xstorm_stats->ucast_bytes_sent.hi, | |
3000 | fcoe_stat->tx_bytes_lo, | |
3001 | fcoe_q_xstorm_stats->ucast_bytes_sent.lo); | |
3002 | ||
3003 | ADD_64(fcoe_stat->tx_bytes_hi, | |
3004 | fcoe_q_xstorm_stats->bcast_bytes_sent.hi, | |
3005 | fcoe_stat->tx_bytes_lo, | |
3006 | fcoe_q_xstorm_stats->bcast_bytes_sent.lo); | |
3007 | ||
3008 | ADD_64(fcoe_stat->tx_bytes_hi, | |
3009 | fcoe_q_xstorm_stats->mcast_bytes_sent.hi, | |
3010 | fcoe_stat->tx_bytes_lo, | |
3011 | fcoe_q_xstorm_stats->mcast_bytes_sent.lo); | |
3012 | ||
3013 | ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo, | |
3014 | fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt); | |
3015 | ||
3016 | ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo, | |
3017 | fcoe_q_xstorm_stats->ucast_pkts_sent); | |
3018 | ||
3019 | ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo, | |
3020 | fcoe_q_xstorm_stats->bcast_pkts_sent); | |
3021 | ||
3022 | ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo, | |
3023 | fcoe_q_xstorm_stats->mcast_pkts_sent); | |
3024 | } | |
3025 | ||
1d187b34 BW |
3026 | /* ask L5 driver to add data to the struct */ |
3027 | bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD); | |
3028 | #endif | |
3029 | } | |
3030 | ||
3031 | static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp) | |
3032 | { | |
f2fd5c34 | 3033 | #ifdef BCM_CNIC |
1d187b34 BW |
3034 | struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app; |
3035 | struct iscsi_stats_info *iscsi_stat = | |
3036 | &bp->slowpath->drv_info_to_mcp.iscsi_stat; | |
3037 | ||
3038 | memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN); | |
3039 | ||
3040 | iscsi_stat->qos_priority = | |
3041 | app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI]; | |
3042 | ||
1d187b34 BW |
3043 | /* ask L5 driver to add data to the struct */ |
3044 | bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD); | |
3045 | #endif | |
3046 | } | |
3047 | ||
0793f83f DK |
3048 | /* called due to MCP event (on pmf): |
3049 | * reread new bandwidth configuration | |
3050 | * configure FW | |
3051 | * notify others function about the change | |
3052 | */ | |
3053 | static inline void bnx2x_config_mf_bw(struct bnx2x *bp) | |
3054 | { | |
3055 | if (bp->link_vars.link_up) { | |
3056 | bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX); | |
3057 | bnx2x_link_sync_notify(bp); | |
3058 | } | |
3059 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); | |
3060 | } | |
3061 | ||
3062 | static inline void bnx2x_set_mf_bw(struct bnx2x *bp) | |
3063 | { | |
3064 | bnx2x_config_mf_bw(bp); | |
3065 | bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0); | |
3066 | } | |
3067 | ||
1d187b34 BW |
3068 | static void bnx2x_handle_drv_info_req(struct bnx2x *bp) |
3069 | { | |
3070 | enum drv_info_opcode op_code; | |
3071 | u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control); | |
3072 | ||
3073 | /* if drv_info version supported by MFW doesn't match - send NACK */ | |
3074 | if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) { | |
3075 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3076 | return; | |
3077 | } | |
3078 | ||
3079 | op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >> | |
3080 | DRV_INFO_CONTROL_OP_CODE_SHIFT; | |
3081 | ||
3082 | memset(&bp->slowpath->drv_info_to_mcp, 0, | |
3083 | sizeof(union drv_info_to_mcp)); | |
3084 | ||
3085 | switch (op_code) { | |
3086 | case ETH_STATS_OPCODE: | |
3087 | bnx2x_drv_info_ether_stat(bp); | |
3088 | break; | |
3089 | case FCOE_STATS_OPCODE: | |
3090 | bnx2x_drv_info_fcoe_stat(bp); | |
3091 | break; | |
3092 | case ISCSI_STATS_OPCODE: | |
3093 | bnx2x_drv_info_iscsi_stat(bp); | |
3094 | break; | |
3095 | default: | |
3096 | /* if op code isn't supported - send NACK */ | |
3097 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0); | |
3098 | return; | |
3099 | } | |
3100 | ||
3101 | /* if we got drv_info attn from MFW then these fields are defined in | |
3102 | * shmem2 for sure | |
3103 | */ | |
3104 | SHMEM2_WR(bp, drv_info_host_addr_lo, | |
3105 | U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3106 | SHMEM2_WR(bp, drv_info_host_addr_hi, | |
3107 | U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp))); | |
3108 | ||
3109 | bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0); | |
3110 | } | |
3111 | ||
523224a3 DK |
3112 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
3113 | { | |
3114 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); | |
3115 | ||
3116 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { | |
3117 | ||
3118 | /* | |
3119 | * This is the only place besides the function initialization | |
3120 | * where the bp->flags can change so it is done without any | |
3121 | * locks | |
3122 | */ | |
f2e0899f | 3123 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
51c1a580 | 3124 | DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n"); |
523224a3 DK |
3125 | bp->flags |= MF_FUNC_DIS; |
3126 | ||
3127 | bnx2x_e1h_disable(bp); | |
3128 | } else { | |
51c1a580 | 3129 | DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n"); |
523224a3 DK |
3130 | bp->flags &= ~MF_FUNC_DIS; |
3131 | ||
3132 | bnx2x_e1h_enable(bp); | |
3133 | } | |
3134 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; | |
3135 | } | |
3136 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { | |
0793f83f | 3137 | bnx2x_config_mf_bw(bp); |
523224a3 DK |
3138 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
3139 | } | |
3140 | ||
3141 | /* Report results to MCP */ | |
3142 | if (dcc_event) | |
3143 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0); | |
3144 | else | |
3145 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0); | |
3146 | } | |
3147 | ||
3148 | /* must be called under the spq lock */ | |
3149 | static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp) | |
3150 | { | |
3151 | struct eth_spe *next_spe = bp->spq_prod_bd; | |
3152 | ||
3153 | if (bp->spq_prod_bd == bp->spq_last_bd) { | |
3154 | bp->spq_prod_bd = bp->spq; | |
3155 | bp->spq_prod_idx = 0; | |
51c1a580 | 3156 | DP(BNX2X_MSG_SP, "end of spq\n"); |
523224a3 DK |
3157 | } else { |
3158 | bp->spq_prod_bd++; | |
3159 | bp->spq_prod_idx++; | |
3160 | } | |
3161 | return next_spe; | |
3162 | } | |
3163 | ||
3164 | /* must be called under the spq lock */ | |
28912902 MC |
3165 | static inline void bnx2x_sp_prod_update(struct bnx2x *bp) |
3166 | { | |
3167 | int func = BP_FUNC(bp); | |
3168 | ||
53e51e2f VZ |
3169 | /* |
3170 | * Make sure that BD data is updated before writing the producer: | |
3171 | * BD data is written to the memory, the producer is read from the | |
3172 | * memory, thus we need a full memory barrier to ensure the ordering. | |
3173 | */ | |
3174 | mb(); | |
28912902 | 3175 | |
523224a3 | 3176 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
f85582f8 | 3177 | bp->spq_prod_idx); |
28912902 MC |
3178 | mmiowb(); |
3179 | } | |
3180 | ||
619c5cb6 VZ |
3181 | /** |
3182 | * bnx2x_is_contextless_ramrod - check if the current command ends on EQ | |
3183 | * | |
3184 | * @cmd: command to check | |
3185 | * @cmd_type: command type | |
3186 | */ | |
3187 | static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type) | |
3188 | { | |
3189 | if ((cmd_type == NONE_CONNECTION_TYPE) || | |
6383c0b3 | 3190 | (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) || |
619c5cb6 VZ |
3191 | (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || |
3192 | (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || | |
3193 | (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || | |
3194 | (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || | |
3195 | (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) | |
3196 | return true; | |
3197 | else | |
3198 | return false; | |
3199 | ||
3200 | } | |
3201 | ||
3202 | ||
3203 | /** | |
3204 | * bnx2x_sp_post - place a single command on an SP ring | |
3205 | * | |
3206 | * @bp: driver handle | |
3207 | * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) | |
3208 | * @cid: SW CID the command is related to | |
3209 | * @data_hi: command private data address (high 32 bits) | |
3210 | * @data_lo: command private data address (low 32 bits) | |
3211 | * @cmd_type: command type (e.g. NONE, ETH) | |
3212 | * | |
3213 | * SP data is handled as if it's always an address pair, thus data fields are | |
3214 | * not swapped to little endian in upper functions. Instead this function swaps | |
3215 | * data as if it's two u32 fields. | |
3216 | */ | |
9f6c9258 | 3217 | int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
619c5cb6 | 3218 | u32 data_hi, u32 data_lo, int cmd_type) |
a2fbb9ea | 3219 | { |
28912902 | 3220 | struct eth_spe *spe; |
523224a3 | 3221 | u16 type; |
619c5cb6 | 3222 | bool common = bnx2x_is_contextless_ramrod(command, cmd_type); |
a2fbb9ea | 3223 | |
a2fbb9ea | 3224 | #ifdef BNX2X_STOP_ON_ERROR |
51c1a580 MS |
3225 | if (unlikely(bp->panic)) { |
3226 | BNX2X_ERR("Can't post SP when there is panic\n"); | |
a2fbb9ea | 3227 | return -EIO; |
51c1a580 | 3228 | } |
a2fbb9ea ET |
3229 | #endif |
3230 | ||
34f80b04 | 3231 | spin_lock_bh(&bp->spq_lock); |
a2fbb9ea | 3232 | |
6e30dd4e VZ |
3233 | if (common) { |
3234 | if (!atomic_read(&bp->eq_spq_left)) { | |
3235 | BNX2X_ERR("BUG! EQ ring full!\n"); | |
3236 | spin_unlock_bh(&bp->spq_lock); | |
3237 | bnx2x_panic(); | |
3238 | return -EBUSY; | |
3239 | } | |
3240 | } else if (!atomic_read(&bp->cq_spq_left)) { | |
3241 | BNX2X_ERR("BUG! SPQ ring full!\n"); | |
3242 | spin_unlock_bh(&bp->spq_lock); | |
3243 | bnx2x_panic(); | |
3244 | return -EBUSY; | |
a2fbb9ea | 3245 | } |
f1410647 | 3246 | |
28912902 MC |
3247 | spe = bnx2x_sp_get_next(bp); |
3248 | ||
a2fbb9ea | 3249 | /* CID needs port number to be encoded int it */ |
28912902 | 3250 | spe->hdr.conn_and_cmd_data = |
cdaa7cb8 VZ |
3251 | cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) | |
3252 | HW_CID(bp, cid)); | |
523224a3 | 3253 | |
619c5cb6 | 3254 | type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE; |
a2fbb9ea | 3255 | |
523224a3 DK |
3256 | type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) & |
3257 | SPE_HDR_FUNCTION_ID); | |
a2fbb9ea | 3258 | |
523224a3 DK |
3259 | spe->hdr.type = cpu_to_le16(type); |
3260 | ||
3261 | spe->data.update_data_addr.hi = cpu_to_le32(data_hi); | |
3262 | spe->data.update_data_addr.lo = cpu_to_le32(data_lo); | |
3263 | ||
d6cae238 VZ |
3264 | /* |
3265 | * It's ok if the actual decrement is issued towards the memory | |
3266 | * somewhere between the spin_lock and spin_unlock. Thus no | |
3267 | * more explict memory barrier is needed. | |
3268 | */ | |
3269 | if (common) | |
3270 | atomic_dec(&bp->eq_spq_left); | |
3271 | else | |
3272 | atomic_dec(&bp->cq_spq_left); | |
6e30dd4e | 3273 | |
a2fbb9ea | 3274 | |
51c1a580 MS |
3275 | DP(BNX2X_MSG_SP, |
3276 | "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 |
3277 | bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping), |
3278 | (u32)(U64_LO(bp->spq_mapping) + | |
d6cae238 | 3279 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, common, |
6e30dd4e VZ |
3280 | HW_CID(bp, cid), data_hi, data_lo, type, |
3281 | atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left)); | |
cdaa7cb8 | 3282 | |
28912902 | 3283 | bnx2x_sp_prod_update(bp); |
34f80b04 | 3284 | spin_unlock_bh(&bp->spq_lock); |
a2fbb9ea ET |
3285 | return 0; |
3286 | } | |
3287 | ||
3288 | /* acquire split MCP access lock register */ | |
4a37fb66 | 3289 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
a2fbb9ea | 3290 | { |
72fd0718 | 3291 | u32 j, val; |
34f80b04 | 3292 | int rc = 0; |
a2fbb9ea ET |
3293 | |
3294 | might_sleep(); | |
72fd0718 | 3295 | for (j = 0; j < 1000; j++) { |
a2fbb9ea ET |
3296 | val = (1UL << 31); |
3297 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); | |
3298 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); | |
3299 | if (val & (1L << 31)) | |
3300 | break; | |
3301 | ||
3302 | msleep(5); | |
3303 | } | |
a2fbb9ea | 3304 | if (!(val & (1L << 31))) { |
19680c48 | 3305 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
a2fbb9ea ET |
3306 | rc = -EBUSY; |
3307 | } | |
3308 | ||
3309 | return rc; | |
3310 | } | |
3311 | ||
4a37fb66 YG |
3312 | /* release split MCP access lock register */ |
3313 | static void bnx2x_release_alr(struct bnx2x *bp) | |
a2fbb9ea | 3314 | { |
72fd0718 | 3315 | REG_WR(bp, GRCBASE_MCP + 0x9c, 0); |
a2fbb9ea ET |
3316 | } |
3317 | ||
523224a3 DK |
3318 | #define BNX2X_DEF_SB_ATT_IDX 0x0001 |
3319 | #define BNX2X_DEF_SB_IDX 0x0002 | |
3320 | ||
a2fbb9ea ET |
3321 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
3322 | { | |
523224a3 | 3323 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
a2fbb9ea ET |
3324 | u16 rc = 0; |
3325 | ||
3326 | barrier(); /* status block is written to by the chip */ | |
a2fbb9ea ET |
3327 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
3328 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; | |
523224a3 | 3329 | rc |= BNX2X_DEF_SB_ATT_IDX; |
a2fbb9ea | 3330 | } |
523224a3 DK |
3331 | |
3332 | if (bp->def_idx != def_sb->sp_sb.running_index) { | |
3333 | bp->def_idx = def_sb->sp_sb.running_index; | |
3334 | rc |= BNX2X_DEF_SB_IDX; | |
a2fbb9ea | 3335 | } |
523224a3 DK |
3336 | |
3337 | /* Do not reorder: indecies reading should complete before handling */ | |
3338 | barrier(); | |
a2fbb9ea ET |
3339 | return rc; |
3340 | } | |
3341 | ||
3342 | /* | |
3343 | * slow path service functions | |
3344 | */ | |
3345 | ||
3346 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) | |
3347 | { | |
34f80b04 | 3348 | int port = BP_PORT(bp); |
a2fbb9ea ET |
3349 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
3350 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
877e9aa4 ET |
3351 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
3352 | NIG_REG_MASK_INTERRUPT_PORT0; | |
3fcaf2e5 | 3353 | u32 aeu_mask; |
87942b46 | 3354 | u32 nig_mask = 0; |
f2e0899f | 3355 | u32 reg_addr; |
a2fbb9ea | 3356 | |
a2fbb9ea ET |
3357 | if (bp->attn_state & asserted) |
3358 | BNX2X_ERR("IGU ERROR\n"); | |
3359 | ||
3fcaf2e5 EG |
3360 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
3361 | aeu_mask = REG_RD(bp, aeu_addr); | |
3362 | ||
a2fbb9ea | 3363 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
3fcaf2e5 | 3364 | aeu_mask, asserted); |
72fd0718 | 3365 | aeu_mask &= ~(asserted & 0x3ff); |
3fcaf2e5 | 3366 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 3367 | |
3fcaf2e5 EG |
3368 | REG_WR(bp, aeu_addr, aeu_mask); |
3369 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea | 3370 | |
3fcaf2e5 | 3371 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
a2fbb9ea | 3372 | bp->attn_state |= asserted; |
3fcaf2e5 | 3373 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
a2fbb9ea ET |
3374 | |
3375 | if (asserted & ATTN_HARD_WIRED_MASK) { | |
3376 | if (asserted & ATTN_NIG_FOR_FUNC) { | |
a2fbb9ea | 3377 | |
a5e9a7cf EG |
3378 | bnx2x_acquire_phy_lock(bp); |
3379 | ||
877e9aa4 | 3380 | /* save nig interrupt mask */ |
87942b46 | 3381 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
a2fbb9ea | 3382 | |
361c391e YR |
3383 | /* If nig_mask is not set, no need to call the update |
3384 | * function. | |
3385 | */ | |
3386 | if (nig_mask) { | |
3387 | REG_WR(bp, nig_int_mask_addr, 0); | |
3388 | ||
3389 | bnx2x_link_attn(bp); | |
3390 | } | |
a2fbb9ea ET |
3391 | |
3392 | /* handle unicore attn? */ | |
3393 | } | |
3394 | if (asserted & ATTN_SW_TIMER_4_FUNC) | |
3395 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); | |
3396 | ||
3397 | if (asserted & GPIO_2_FUNC) | |
3398 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); | |
3399 | ||
3400 | if (asserted & GPIO_3_FUNC) | |
3401 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); | |
3402 | ||
3403 | if (asserted & GPIO_4_FUNC) | |
3404 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); | |
3405 | ||
3406 | if (port == 0) { | |
3407 | if (asserted & ATTN_GENERAL_ATTN_1) { | |
3408 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); | |
3409 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); | |
3410 | } | |
3411 | if (asserted & ATTN_GENERAL_ATTN_2) { | |
3412 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); | |
3413 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); | |
3414 | } | |
3415 | if (asserted & ATTN_GENERAL_ATTN_3) { | |
3416 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); | |
3417 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); | |
3418 | } | |
3419 | } else { | |
3420 | if (asserted & ATTN_GENERAL_ATTN_4) { | |
3421 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); | |
3422 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); | |
3423 | } | |
3424 | if (asserted & ATTN_GENERAL_ATTN_5) { | |
3425 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); | |
3426 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); | |
3427 | } | |
3428 | if (asserted & ATTN_GENERAL_ATTN_6) { | |
3429 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); | |
3430 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); | |
3431 | } | |
3432 | } | |
3433 | ||
3434 | } /* if hardwired */ | |
3435 | ||
f2e0899f DK |
3436 | if (bp->common.int_block == INT_BLOCK_HC) |
3437 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
3438 | COMMAND_REG_ATTN_BITS_SET); | |
3439 | else | |
3440 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); | |
3441 | ||
3442 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted, | |
3443 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
3444 | REG_WR(bp, reg_addr, asserted); | |
a2fbb9ea ET |
3445 | |
3446 | /* now set back the mask */ | |
a5e9a7cf | 3447 | if (asserted & ATTN_NIG_FOR_FUNC) { |
87942b46 | 3448 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
a5e9a7cf EG |
3449 | bnx2x_release_phy_lock(bp); |
3450 | } | |
a2fbb9ea ET |
3451 | } |
3452 | ||
fd4ef40d EG |
3453 | static inline void bnx2x_fan_failure(struct bnx2x *bp) |
3454 | { | |
3455 | int port = BP_PORT(bp); | |
b7737c9b | 3456 | u32 ext_phy_config; |
fd4ef40d | 3457 | /* mark the failure */ |
b7737c9b YR |
3458 | ext_phy_config = |
3459 | SHMEM_RD(bp, | |
3460 | dev_info.port_hw_config[port].external_phy_config); | |
3461 | ||
3462 | ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; | |
3463 | ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; | |
fd4ef40d | 3464 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
b7737c9b | 3465 | ext_phy_config); |
fd4ef40d EG |
3466 | |
3467 | /* log the failure */ | |
51c1a580 MS |
3468 | netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n" |
3469 | "Please contact OEM Support for assistance\n"); | |
8304859a AE |
3470 | |
3471 | /* | |
3472 | * Scheudle device reset (unload) | |
3473 | * This is due to some boards consuming sufficient power when driver is | |
3474 | * up to overheat if fan fails. | |
3475 | */ | |
3476 | smp_mb__before_clear_bit(); | |
3477 | set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state); | |
3478 | smp_mb__after_clear_bit(); | |
3479 | schedule_delayed_work(&bp->sp_rtnl_task, 0); | |
3480 | ||
fd4ef40d | 3481 | } |
ab6ad5a4 | 3482 | |
877e9aa4 | 3483 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
a2fbb9ea | 3484 | { |
34f80b04 | 3485 | int port = BP_PORT(bp); |
877e9aa4 | 3486 | int reg_offset; |
d90d96ba | 3487 | u32 val; |
877e9aa4 | 3488 | |
34f80b04 EG |
3489 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
3490 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
877e9aa4 | 3491 | |
34f80b04 | 3492 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
877e9aa4 ET |
3493 | |
3494 | val = REG_RD(bp, reg_offset); | |
3495 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; | |
3496 | REG_WR(bp, reg_offset, val); | |
3497 | ||
3498 | BNX2X_ERR("SPIO5 hw attention\n"); | |
3499 | ||
fd4ef40d | 3500 | /* Fan failure attention */ |
d90d96ba | 3501 | bnx2x_hw_reset_phy(&bp->link_params); |
fd4ef40d | 3502 | bnx2x_fan_failure(bp); |
877e9aa4 | 3503 | } |
34f80b04 | 3504 | |
3deb8167 | 3505 | if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) { |
589abe3a EG |
3506 | bnx2x_acquire_phy_lock(bp); |
3507 | bnx2x_handle_module_detect_int(&bp->link_params); | |
3508 | bnx2x_release_phy_lock(bp); | |
3509 | } | |
3510 | ||
34f80b04 EG |
3511 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
3512 | ||
3513 | val = REG_RD(bp, reg_offset); | |
3514 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); | |
3515 | REG_WR(bp, reg_offset, val); | |
3516 | ||
3517 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", | |
0fc5d009 | 3518 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
34f80b04 EG |
3519 | bnx2x_panic(); |
3520 | } | |
877e9aa4 ET |
3521 | } |
3522 | ||
3523 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) | |
3524 | { | |
3525 | u32 val; | |
3526 | ||
0626b899 | 3527 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
877e9aa4 ET |
3528 | |
3529 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); | |
3530 | BNX2X_ERR("DB hw attention 0x%x\n", val); | |
3531 | /* DORQ discard attention */ | |
3532 | if (val & 0x2) | |
3533 | BNX2X_ERR("FATAL error from DORQ\n"); | |
3534 | } | |
34f80b04 EG |
3535 | |
3536 | if (attn & HW_INTERRUT_ASSERT_SET_1) { | |
3537 | ||
3538 | int port = BP_PORT(bp); | |
3539 | int reg_offset; | |
3540 | ||
3541 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : | |
3542 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); | |
3543 | ||
3544 | val = REG_RD(bp, reg_offset); | |
3545 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); | |
3546 | REG_WR(bp, reg_offset, val); | |
3547 | ||
3548 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", | |
0fc5d009 | 3549 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
34f80b04 EG |
3550 | bnx2x_panic(); |
3551 | } | |
877e9aa4 ET |
3552 | } |
3553 | ||
3554 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) | |
3555 | { | |
3556 | u32 val; | |
3557 | ||
3558 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { | |
3559 | ||
3560 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); | |
3561 | BNX2X_ERR("CFC hw attention 0x%x\n", val); | |
3562 | /* CFC error attention */ | |
3563 | if (val & 0x2) | |
3564 | BNX2X_ERR("FATAL error from CFC\n"); | |
3565 | } | |
3566 | ||
3567 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { | |
877e9aa4 | 3568 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
619c5cb6 | 3569 | BNX2X_ERR("PXP hw attention-0 0x%x\n", val); |
877e9aa4 ET |
3570 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
3571 | if (val & 0x18000) | |
3572 | BNX2X_ERR("FATAL error from PXP\n"); | |
619c5cb6 VZ |
3573 | |
3574 | if (!CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
3575 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1); |
3576 | BNX2X_ERR("PXP hw attention-1 0x%x\n", val); | |
3577 | } | |
877e9aa4 | 3578 | } |
34f80b04 EG |
3579 | |
3580 | if (attn & HW_INTERRUT_ASSERT_SET_2) { | |
3581 | ||
3582 | int port = BP_PORT(bp); | |
3583 | int reg_offset; | |
3584 | ||
3585 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : | |
3586 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); | |
3587 | ||
3588 | val = REG_RD(bp, reg_offset); | |
3589 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); | |
3590 | REG_WR(bp, reg_offset, val); | |
3591 | ||
3592 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", | |
0fc5d009 | 3593 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
34f80b04 EG |
3594 | bnx2x_panic(); |
3595 | } | |
877e9aa4 ET |
3596 | } |
3597 | ||
3598 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) | |
3599 | { | |
34f80b04 EG |
3600 | u32 val; |
3601 | ||
877e9aa4 ET |
3602 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
3603 | ||
34f80b04 EG |
3604 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
3605 | int func = BP_FUNC(bp); | |
3606 | ||
3607 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
f2e0899f DK |
3608 | bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp, |
3609 | func_mf_config[BP_ABS_FUNC(bp)].config); | |
3610 | val = SHMEM_RD(bp, | |
3611 | func_mb[BP_FW_MB_IDX(bp)].drv_status); | |
2691d51d EG |
3612 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
3613 | bnx2x_dcc_event(bp, | |
3614 | (val & DRV_STATUS_DCC_EVENT_MASK)); | |
0793f83f DK |
3615 | |
3616 | if (val & DRV_STATUS_SET_MF_BW) | |
3617 | bnx2x_set_mf_bw(bp); | |
3618 | ||
1d187b34 BW |
3619 | if (val & DRV_STATUS_DRV_INFO_REQ) |
3620 | bnx2x_handle_drv_info_req(bp); | |
2691d51d | 3621 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
34f80b04 EG |
3622 | bnx2x_pmf_update(bp); |
3623 | ||
e4901dde | 3624 | if (bp->port.pmf && |
785b9b1a SR |
3625 | (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) && |
3626 | bp->dcbx_enabled > 0) | |
e4901dde VZ |
3627 | /* start dcbx state machine */ |
3628 | bnx2x_dcbx_set_params(bp, | |
3629 | BNX2X_DCBX_STATE_NEG_RECEIVED); | |
3deb8167 YR |
3630 | if (bp->link_vars.periodic_flags & |
3631 | PERIODIC_FLAGS_LINK_EVENT) { | |
3632 | /* sync with link */ | |
3633 | bnx2x_acquire_phy_lock(bp); | |
3634 | bp->link_vars.periodic_flags &= | |
3635 | ~PERIODIC_FLAGS_LINK_EVENT; | |
3636 | bnx2x_release_phy_lock(bp); | |
3637 | if (IS_MF(bp)) | |
3638 | bnx2x_link_sync_notify(bp); | |
3639 | bnx2x_link_report(bp); | |
3640 | } | |
3641 | /* Always call it here: bnx2x_link_report() will | |
3642 | * prevent the link indication duplication. | |
3643 | */ | |
3644 | bnx2x__link_status_update(bp); | |
34f80b04 | 3645 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
877e9aa4 ET |
3646 | |
3647 | BNX2X_ERR("MC assert!\n"); | |
d6cae238 | 3648 | bnx2x_mc_assert(bp); |
877e9aa4 ET |
3649 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
3650 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); | |
3651 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); | |
3652 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); | |
3653 | bnx2x_panic(); | |
3654 | ||
3655 | } else if (attn & BNX2X_MCP_ASSERT) { | |
3656 | ||
3657 | BNX2X_ERR("MCP assert!\n"); | |
3658 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); | |
34f80b04 | 3659 | bnx2x_fw_dump(bp); |
877e9aa4 ET |
3660 | |
3661 | } else | |
3662 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); | |
3663 | } | |
3664 | ||
3665 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { | |
34f80b04 EG |
3666 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
3667 | if (attn & BNX2X_GRC_TIMEOUT) { | |
f2e0899f DK |
3668 | val = CHIP_IS_E1(bp) ? 0 : |
3669 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN); | |
34f80b04 EG |
3670 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
3671 | } | |
3672 | if (attn & BNX2X_GRC_RSV) { | |
f2e0899f DK |
3673 | val = CHIP_IS_E1(bp) ? 0 : |
3674 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN); | |
34f80b04 EG |
3675 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
3676 | } | |
877e9aa4 | 3677 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
877e9aa4 ET |
3678 | } |
3679 | } | |
3680 | ||
c9ee9206 VZ |
3681 | /* |
3682 | * Bits map: | |
3683 | * 0-7 - Engine0 load counter. | |
3684 | * 8-15 - Engine1 load counter. | |
3685 | * 16 - Engine0 RESET_IN_PROGRESS bit. | |
3686 | * 17 - Engine1 RESET_IN_PROGRESS bit. | |
3687 | * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function | |
3688 | * on the engine | |
3689 | * 19 - Engine1 ONE_IS_LOADED. | |
3690 | * 20 - Chip reset flow bit. When set none-leader must wait for both engines | |
3691 | * leader to complete (check for both RESET_IN_PROGRESS bits and not for | |
3692 | * just the one belonging to its engine). | |
3693 | * | |
3694 | */ | |
3695 | #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 | |
3696 | ||
3697 | #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff | |
3698 | #define BNX2X_PATH0_LOAD_CNT_SHIFT 0 | |
3699 | #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 | |
3700 | #define BNX2X_PATH1_LOAD_CNT_SHIFT 8 | |
3701 | #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 | |
3702 | #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 | |
3703 | #define BNX2X_GLOBAL_RESET_BIT 0x00040000 | |
3704 | ||
3705 | /* | |
3706 | * Set the GLOBAL_RESET bit. | |
3707 | * | |
3708 | * Should be run under rtnl lock | |
3709 | */ | |
3710 | void bnx2x_set_reset_global(struct bnx2x *bp) | |
3711 | { | |
f16da43b AE |
3712 | u32 val; |
3713 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
3714 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 3715 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT); |
f16da43b | 3716 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 VZ |
3717 | } |
3718 | ||
3719 | /* | |
3720 | * Clear the GLOBAL_RESET bit. | |
3721 | * | |
3722 | * Should be run under rtnl lock | |
3723 | */ | |
3724 | static inline void bnx2x_clear_reset_global(struct bnx2x *bp) | |
3725 | { | |
f16da43b AE |
3726 | u32 val; |
3727 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
3728 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 3729 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT)); |
f16da43b | 3730 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
c9ee9206 | 3731 | } |
f85582f8 | 3732 | |
72fd0718 | 3733 | /* |
c9ee9206 VZ |
3734 | * Checks the GLOBAL_RESET bit. |
3735 | * | |
72fd0718 VZ |
3736 | * should be run under rtnl lock |
3737 | */ | |
c9ee9206 VZ |
3738 | static inline bool bnx2x_reset_is_global(struct bnx2x *bp) |
3739 | { | |
3740 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
3741 | ||
3742 | DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val); | |
3743 | return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false; | |
3744 | } | |
3745 | ||
3746 | /* | |
3747 | * Clear RESET_IN_PROGRESS bit for the current engine. | |
3748 | * | |
3749 | * Should be run under rtnl lock | |
3750 | */ | |
72fd0718 VZ |
3751 | static inline void bnx2x_set_reset_done(struct bnx2x *bp) |
3752 | { | |
f16da43b | 3753 | u32 val; |
c9ee9206 VZ |
3754 | u32 bit = BP_PATH(bp) ? |
3755 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
3756 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
3757 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
3758 | |
3759 | /* Clear the bit */ | |
3760 | val &= ~bit; | |
3761 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
3762 | |
3763 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
72fd0718 VZ |
3764 | } |
3765 | ||
3766 | /* | |
c9ee9206 VZ |
3767 | * Set RESET_IN_PROGRESS for the current engine. |
3768 | * | |
72fd0718 VZ |
3769 | * should be run under rtnl lock |
3770 | */ | |
c9ee9206 | 3771 | void bnx2x_set_reset_in_progress(struct bnx2x *bp) |
72fd0718 | 3772 | { |
f16da43b | 3773 | u32 val; |
c9ee9206 VZ |
3774 | u32 bit = BP_PATH(bp) ? |
3775 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
f16da43b AE |
3776 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
3777 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 VZ |
3778 | |
3779 | /* Set the bit */ | |
3780 | val |= bit; | |
3781 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 3782 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
3783 | } |
3784 | ||
3785 | /* | |
c9ee9206 | 3786 | * Checks the RESET_IN_PROGRESS bit for the given engine. |
72fd0718 VZ |
3787 | * should be run under rtnl lock |
3788 | */ | |
c9ee9206 | 3789 | bool bnx2x_reset_is_done(struct bnx2x *bp, int engine) |
72fd0718 | 3790 | { |
c9ee9206 VZ |
3791 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
3792 | u32 bit = engine ? | |
3793 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; | |
3794 | ||
3795 | /* return false if bit is set */ | |
3796 | return (val & bit) ? false : true; | |
72fd0718 VZ |
3797 | } |
3798 | ||
3799 | /* | |
889b9af3 | 3800 | * set pf load for the current pf. |
c9ee9206 | 3801 | * |
72fd0718 VZ |
3802 | * should be run under rtnl lock |
3803 | */ | |
889b9af3 | 3804 | void bnx2x_set_pf_load(struct bnx2x *bp) |
72fd0718 | 3805 | { |
f16da43b | 3806 | u32 val1, val; |
c9ee9206 VZ |
3807 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
3808 | BNX2X_PATH0_LOAD_CNT_MASK; | |
3809 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
3810 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 3811 | |
f16da43b AE |
3812 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
3813 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
3814 | ||
51c1a580 | 3815 | DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 3816 | |
c9ee9206 VZ |
3817 | /* get the current counter value */ |
3818 | val1 = (val & mask) >> shift; | |
3819 | ||
889b9af3 AE |
3820 | /* set bit of that PF */ |
3821 | val1 |= (1 << bp->pf_num); | |
c9ee9206 VZ |
3822 | |
3823 | /* clear the old value */ | |
3824 | val &= ~mask; | |
3825 | ||
3826 | /* set the new one */ | |
3827 | val |= ((val1 << shift) & mask); | |
3828 | ||
3829 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b | 3830 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
3831 | } |
3832 | ||
c9ee9206 | 3833 | /** |
889b9af3 | 3834 | * bnx2x_clear_pf_load - clear pf load mark |
c9ee9206 VZ |
3835 | * |
3836 | * @bp: driver handle | |
3837 | * | |
3838 | * Should be run under rtnl lock. | |
3839 | * Decrements the load counter for the current engine. Returns | |
889b9af3 | 3840 | * whether other functions are still loaded |
72fd0718 | 3841 | */ |
889b9af3 | 3842 | bool bnx2x_clear_pf_load(struct bnx2x *bp) |
72fd0718 | 3843 | { |
f16da43b | 3844 | u32 val1, val; |
c9ee9206 VZ |
3845 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
3846 | BNX2X_PATH0_LOAD_CNT_MASK; | |
3847 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
3848 | BNX2X_PATH0_LOAD_CNT_SHIFT; | |
72fd0718 | 3849 | |
f16da43b AE |
3850 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
3851 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
51c1a580 | 3852 | DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val); |
72fd0718 | 3853 | |
c9ee9206 VZ |
3854 | /* get the current counter value */ |
3855 | val1 = (val & mask) >> shift; | |
3856 | ||
889b9af3 AE |
3857 | /* clear bit of that PF */ |
3858 | val1 &= ~(1 << bp->pf_num); | |
c9ee9206 VZ |
3859 | |
3860 | /* clear the old value */ | |
3861 | val &= ~mask; | |
3862 | ||
3863 | /* set the new one */ | |
3864 | val |= ((val1 << shift) & mask); | |
3865 | ||
3866 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); | |
f16da43b AE |
3867 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
3868 | return val1 != 0; | |
72fd0718 VZ |
3869 | } |
3870 | ||
3871 | /* | |
889b9af3 | 3872 | * Read the load status for the current engine. |
c9ee9206 | 3873 | * |
72fd0718 VZ |
3874 | * should be run under rtnl lock |
3875 | */ | |
889b9af3 | 3876 | static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine) |
72fd0718 | 3877 | { |
c9ee9206 VZ |
3878 | u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK : |
3879 | BNX2X_PATH0_LOAD_CNT_MASK); | |
3880 | u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT : | |
3881 | BNX2X_PATH0_LOAD_CNT_SHIFT); | |
3882 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
3883 | ||
51c1a580 | 3884 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val); |
c9ee9206 VZ |
3885 | |
3886 | val = (val & mask) >> shift; | |
3887 | ||
51c1a580 MS |
3888 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n", |
3889 | engine, val); | |
c9ee9206 | 3890 | |
889b9af3 | 3891 | return val != 0; |
72fd0718 VZ |
3892 | } |
3893 | ||
c9ee9206 | 3894 | /* |
889b9af3 | 3895 | * Reset the load status for the current engine. |
c9ee9206 | 3896 | */ |
889b9af3 | 3897 | static inline void bnx2x_clear_load_status(struct bnx2x *bp) |
72fd0718 | 3898 | { |
f16da43b | 3899 | u32 val; |
c9ee9206 | 3900 | u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
f16da43b AE |
3901 | BNX2X_PATH0_LOAD_CNT_MASK); |
3902 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); | |
3903 | val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); | |
c9ee9206 | 3904 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask)); |
f16da43b | 3905 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG); |
72fd0718 VZ |
3906 | } |
3907 | ||
3908 | static inline void _print_next_block(int idx, const char *blk) | |
3909 | { | |
f1deab50 | 3910 | pr_cont("%s%s", idx ? ", " : "", blk); |
72fd0718 VZ |
3911 | } |
3912 | ||
c9ee9206 VZ |
3913 | static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num, |
3914 | bool print) | |
72fd0718 VZ |
3915 | { |
3916 | int i = 0; | |
3917 | u32 cur_bit = 0; | |
3918 | for (i = 0; sig; i++) { | |
3919 | cur_bit = ((u32)0x1 << i); | |
3920 | if (sig & cur_bit) { | |
3921 | switch (cur_bit) { | |
3922 | case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: | |
c9ee9206 VZ |
3923 | if (print) |
3924 | _print_next_block(par_num++, "BRB"); | |
72fd0718 VZ |
3925 | break; |
3926 | case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: | |
c9ee9206 VZ |
3927 | if (print) |
3928 | _print_next_block(par_num++, "PARSER"); | |
72fd0718 VZ |
3929 | break; |
3930 | case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: | |
c9ee9206 VZ |
3931 | if (print) |
3932 | _print_next_block(par_num++, "TSDM"); | |
72fd0718 VZ |
3933 | break; |
3934 | case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: | |
c9ee9206 VZ |
3935 | if (print) |
3936 | _print_next_block(par_num++, | |
3937 | "SEARCHER"); | |
3938 | break; | |
3939 | case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: | |
3940 | if (print) | |
3941 | _print_next_block(par_num++, "TCM"); | |
72fd0718 VZ |
3942 | break; |
3943 | case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
3944 | if (print) |
3945 | _print_next_block(par_num++, "TSEMI"); | |
3946 | break; | |
3947 | case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: | |
3948 | if (print) | |
3949 | _print_next_block(par_num++, "XPB"); | |
72fd0718 VZ |
3950 | break; |
3951 | } | |
3952 | ||
3953 | /* Clear the bit */ | |
3954 | sig &= ~cur_bit; | |
3955 | } | |
3956 | } | |
3957 | ||
3958 | return par_num; | |
3959 | } | |
3960 | ||
c9ee9206 VZ |
3961 | static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num, |
3962 | bool *global, bool print) | |
72fd0718 VZ |
3963 | { |
3964 | int i = 0; | |
3965 | u32 cur_bit = 0; | |
3966 | for (i = 0; sig; i++) { | |
3967 | cur_bit = ((u32)0x1 << i); | |
3968 | if (sig & cur_bit) { | |
3969 | switch (cur_bit) { | |
c9ee9206 VZ |
3970 | case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: |
3971 | if (print) | |
3972 | _print_next_block(par_num++, "PBF"); | |
72fd0718 VZ |
3973 | break; |
3974 | case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: | |
c9ee9206 VZ |
3975 | if (print) |
3976 | _print_next_block(par_num++, "QM"); | |
3977 | break; | |
3978 | case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: | |
3979 | if (print) | |
3980 | _print_next_block(par_num++, "TM"); | |
72fd0718 VZ |
3981 | break; |
3982 | case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: | |
c9ee9206 VZ |
3983 | if (print) |
3984 | _print_next_block(par_num++, "XSDM"); | |
3985 | break; | |
3986 | case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: | |
3987 | if (print) | |
3988 | _print_next_block(par_num++, "XCM"); | |
72fd0718 VZ |
3989 | break; |
3990 | case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
3991 | if (print) |
3992 | _print_next_block(par_num++, "XSEMI"); | |
72fd0718 VZ |
3993 | break; |
3994 | case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: | |
c9ee9206 VZ |
3995 | if (print) |
3996 | _print_next_block(par_num++, | |
3997 | "DOORBELLQ"); | |
3998 | break; | |
3999 | case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: | |
4000 | if (print) | |
4001 | _print_next_block(par_num++, "NIG"); | |
72fd0718 VZ |
4002 | break; |
4003 | case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: | |
c9ee9206 VZ |
4004 | if (print) |
4005 | _print_next_block(par_num++, | |
4006 | "VAUX PCI CORE"); | |
4007 | *global = true; | |
72fd0718 VZ |
4008 | break; |
4009 | case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: | |
c9ee9206 VZ |
4010 | if (print) |
4011 | _print_next_block(par_num++, "DEBUG"); | |
72fd0718 VZ |
4012 | break; |
4013 | case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: | |
c9ee9206 VZ |
4014 | if (print) |
4015 | _print_next_block(par_num++, "USDM"); | |
72fd0718 | 4016 | break; |
8736c826 VZ |
4017 | case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR: |
4018 | if (print) | |
4019 | _print_next_block(par_num++, "UCM"); | |
4020 | break; | |
72fd0718 | 4021 | case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: |
c9ee9206 VZ |
4022 | if (print) |
4023 | _print_next_block(par_num++, "USEMI"); | |
72fd0718 VZ |
4024 | break; |
4025 | case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: | |
c9ee9206 VZ |
4026 | if (print) |
4027 | _print_next_block(par_num++, "UPB"); | |
72fd0718 VZ |
4028 | break; |
4029 | case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: | |
c9ee9206 VZ |
4030 | if (print) |
4031 | _print_next_block(par_num++, "CSDM"); | |
72fd0718 | 4032 | break; |
8736c826 VZ |
4033 | case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR: |
4034 | if (print) | |
4035 | _print_next_block(par_num++, "CCM"); | |
4036 | break; | |
72fd0718 VZ |
4037 | } |
4038 | ||
4039 | /* Clear the bit */ | |
4040 | sig &= ~cur_bit; | |
4041 | } | |
4042 | } | |
4043 | ||
4044 | return par_num; | |
4045 | } | |
4046 | ||
c9ee9206 VZ |
4047 | static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num, |
4048 | bool print) | |
72fd0718 VZ |
4049 | { |
4050 | int i = 0; | |
4051 | u32 cur_bit = 0; | |
4052 | for (i = 0; sig; i++) { | |
4053 | cur_bit = ((u32)0x1 << i); | |
4054 | if (sig & cur_bit) { | |
4055 | switch (cur_bit) { | |
4056 | case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: | |
c9ee9206 VZ |
4057 | if (print) |
4058 | _print_next_block(par_num++, "CSEMI"); | |
72fd0718 VZ |
4059 | break; |
4060 | case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: | |
c9ee9206 VZ |
4061 | if (print) |
4062 | _print_next_block(par_num++, "PXP"); | |
72fd0718 VZ |
4063 | break; |
4064 | case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: | |
c9ee9206 VZ |
4065 | if (print) |
4066 | _print_next_block(par_num++, | |
72fd0718 VZ |
4067 | "PXPPCICLOCKCLIENT"); |
4068 | break; | |
4069 | case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: | |
c9ee9206 VZ |
4070 | if (print) |
4071 | _print_next_block(par_num++, "CFC"); | |
72fd0718 VZ |
4072 | break; |
4073 | case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: | |
c9ee9206 VZ |
4074 | if (print) |
4075 | _print_next_block(par_num++, "CDU"); | |
4076 | break; | |
4077 | case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: | |
4078 | if (print) | |
4079 | _print_next_block(par_num++, "DMAE"); | |
72fd0718 VZ |
4080 | break; |
4081 | case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: | |
c9ee9206 VZ |
4082 | if (print) |
4083 | _print_next_block(par_num++, "IGU"); | |
72fd0718 VZ |
4084 | break; |
4085 | case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: | |
c9ee9206 VZ |
4086 | if (print) |
4087 | _print_next_block(par_num++, "MISC"); | |
72fd0718 VZ |
4088 | break; |
4089 | } | |
4090 | ||
4091 | /* Clear the bit */ | |
4092 | sig &= ~cur_bit; | |
4093 | } | |
4094 | } | |
4095 | ||
4096 | return par_num; | |
4097 | } | |
4098 | ||
c9ee9206 VZ |
4099 | static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num, |
4100 | bool *global, bool print) | |
72fd0718 VZ |
4101 | { |
4102 | int i = 0; | |
4103 | u32 cur_bit = 0; | |
4104 | for (i = 0; sig; i++) { | |
4105 | cur_bit = ((u32)0x1 << i); | |
4106 | if (sig & cur_bit) { | |
4107 | switch (cur_bit) { | |
4108 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: | |
c9ee9206 VZ |
4109 | if (print) |
4110 | _print_next_block(par_num++, "MCP ROM"); | |
4111 | *global = true; | |
72fd0718 VZ |
4112 | break; |
4113 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: | |
c9ee9206 VZ |
4114 | if (print) |
4115 | _print_next_block(par_num++, | |
4116 | "MCP UMP RX"); | |
4117 | *global = true; | |
72fd0718 VZ |
4118 | break; |
4119 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: | |
c9ee9206 VZ |
4120 | if (print) |
4121 | _print_next_block(par_num++, | |
4122 | "MCP UMP TX"); | |
4123 | *global = true; | |
72fd0718 VZ |
4124 | break; |
4125 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: | |
c9ee9206 VZ |
4126 | if (print) |
4127 | _print_next_block(par_num++, | |
4128 | "MCP SCPAD"); | |
4129 | *global = true; | |
72fd0718 VZ |
4130 | break; |
4131 | } | |
4132 | ||
4133 | /* Clear the bit */ | |
4134 | sig &= ~cur_bit; | |
4135 | } | |
4136 | } | |
4137 | ||
4138 | return par_num; | |
4139 | } | |
4140 | ||
8736c826 VZ |
4141 | static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num, |
4142 | bool print) | |
4143 | { | |
4144 | int i = 0; | |
4145 | u32 cur_bit = 0; | |
4146 | for (i = 0; sig; i++) { | |
4147 | cur_bit = ((u32)0x1 << i); | |
4148 | if (sig & cur_bit) { | |
4149 | switch (cur_bit) { | |
4150 | case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR: | |
4151 | if (print) | |
4152 | _print_next_block(par_num++, "PGLUE_B"); | |
4153 | break; | |
4154 | case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR: | |
4155 | if (print) | |
4156 | _print_next_block(par_num++, "ATC"); | |
4157 | break; | |
4158 | } | |
4159 | ||
4160 | /* Clear the bit */ | |
4161 | sig &= ~cur_bit; | |
4162 | } | |
4163 | } | |
4164 | ||
4165 | return par_num; | |
4166 | } | |
4167 | ||
c9ee9206 | 4168 | static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, |
8736c826 | 4169 | u32 *sig) |
72fd0718 | 4170 | { |
8736c826 VZ |
4171 | if ((sig[0] & HW_PRTY_ASSERT_SET_0) || |
4172 | (sig[1] & HW_PRTY_ASSERT_SET_1) || | |
4173 | (sig[2] & HW_PRTY_ASSERT_SET_2) || | |
4174 | (sig[3] & HW_PRTY_ASSERT_SET_3) || | |
4175 | (sig[4] & HW_PRTY_ASSERT_SET_4)) { | |
72fd0718 | 4176 | int par_num = 0; |
51c1a580 MS |
4177 | DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n" |
4178 | "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n", | |
8736c826 VZ |
4179 | sig[0] & HW_PRTY_ASSERT_SET_0, |
4180 | sig[1] & HW_PRTY_ASSERT_SET_1, | |
4181 | sig[2] & HW_PRTY_ASSERT_SET_2, | |
4182 | sig[3] & HW_PRTY_ASSERT_SET_3, | |
4183 | sig[4] & HW_PRTY_ASSERT_SET_4); | |
c9ee9206 VZ |
4184 | if (print) |
4185 | netdev_err(bp->dev, | |
4186 | "Parity errors detected in blocks: "); | |
4187 | par_num = bnx2x_check_blocks_with_parity0( | |
8736c826 | 4188 | sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print); |
c9ee9206 | 4189 | par_num = bnx2x_check_blocks_with_parity1( |
8736c826 | 4190 | sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print); |
c9ee9206 | 4191 | par_num = bnx2x_check_blocks_with_parity2( |
8736c826 | 4192 | sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print); |
c9ee9206 | 4193 | par_num = bnx2x_check_blocks_with_parity3( |
8736c826 VZ |
4194 | sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print); |
4195 | par_num = bnx2x_check_blocks_with_parity4( | |
4196 | sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print); | |
4197 | ||
c9ee9206 VZ |
4198 | if (print) |
4199 | pr_cont("\n"); | |
8736c826 | 4200 | |
72fd0718 VZ |
4201 | return true; |
4202 | } else | |
4203 | return false; | |
4204 | } | |
4205 | ||
c9ee9206 VZ |
4206 | /** |
4207 | * bnx2x_chk_parity_attn - checks for parity attentions. | |
4208 | * | |
4209 | * @bp: driver handle | |
4210 | * @global: true if there was a global attention | |
4211 | * @print: show parity attention in syslog | |
4212 | */ | |
4213 | bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print) | |
877e9aa4 | 4214 | { |
8736c826 | 4215 | struct attn_route attn = { {0} }; |
72fd0718 VZ |
4216 | int port = BP_PORT(bp); |
4217 | ||
4218 | attn.sig[0] = REG_RD(bp, | |
4219 | MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + | |
4220 | port*4); | |
4221 | attn.sig[1] = REG_RD(bp, | |
4222 | MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + | |
4223 | port*4); | |
4224 | attn.sig[2] = REG_RD(bp, | |
4225 | MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + | |
4226 | port*4); | |
4227 | attn.sig[3] = REG_RD(bp, | |
4228 | MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + | |
4229 | port*4); | |
4230 | ||
8736c826 VZ |
4231 | if (!CHIP_IS_E1x(bp)) |
4232 | attn.sig[4] = REG_RD(bp, | |
4233 | MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + | |
4234 | port*4); | |
4235 | ||
4236 | return bnx2x_parity_attn(bp, global, print, attn.sig); | |
72fd0718 VZ |
4237 | } |
4238 | ||
f2e0899f DK |
4239 | |
4240 | static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn) | |
4241 | { | |
4242 | u32 val; | |
4243 | if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { | |
4244 | ||
4245 | val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); | |
4246 | BNX2X_ERR("PGLUE hw attention 0x%x\n", val); | |
4247 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) | |
51c1a580 | 4248 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n"); |
f2e0899f | 4249 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) |
51c1a580 | 4250 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n"); |
f2e0899f | 4251 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) |
51c1a580 | 4252 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n"); |
f2e0899f | 4253 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) |
51c1a580 | 4254 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n"); |
f2e0899f DK |
4255 | if (val & |
4256 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) | |
51c1a580 | 4257 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n"); |
f2e0899f DK |
4258 | if (val & |
4259 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) | |
51c1a580 | 4260 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n"); |
f2e0899f | 4261 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) |
51c1a580 | 4262 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n"); |
f2e0899f | 4263 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) |
51c1a580 | 4264 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n"); |
f2e0899f | 4265 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) |
51c1a580 | 4266 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n"); |
f2e0899f DK |
4267 | } |
4268 | if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { | |
4269 | val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR); | |
4270 | BNX2X_ERR("ATC hw attention 0x%x\n", val); | |
4271 | if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) | |
4272 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); | |
4273 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) | |
51c1a580 | 4274 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n"); |
f2e0899f | 4275 | if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) |
51c1a580 | 4276 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n"); |
f2e0899f | 4277 | if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) |
51c1a580 | 4278 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n"); |
f2e0899f DK |
4279 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) |
4280 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); | |
4281 | if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) | |
51c1a580 | 4282 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n"); |
f2e0899f DK |
4283 | } |
4284 | ||
4285 | if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4286 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { | |
4287 | BNX2X_ERR("FATAL parity attention set4 0x%x\n", | |
4288 | (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | | |
4289 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); | |
4290 | } | |
4291 | ||
4292 | } | |
4293 | ||
72fd0718 VZ |
4294 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
4295 | { | |
4296 | struct attn_route attn, *group_mask; | |
34f80b04 | 4297 | int port = BP_PORT(bp); |
877e9aa4 | 4298 | int index; |
a2fbb9ea ET |
4299 | u32 reg_addr; |
4300 | u32 val; | |
3fcaf2e5 | 4301 | u32 aeu_mask; |
c9ee9206 | 4302 | bool global = false; |
a2fbb9ea ET |
4303 | |
4304 | /* need to take HW lock because MCP or other port might also | |
4305 | try to handle this event */ | |
4a37fb66 | 4306 | bnx2x_acquire_alr(bp); |
a2fbb9ea | 4307 | |
c9ee9206 VZ |
4308 | if (bnx2x_chk_parity_attn(bp, &global, true)) { |
4309 | #ifndef BNX2X_STOP_ON_ERROR | |
72fd0718 | 4310 | bp->recovery_state = BNX2X_RECOVERY_INIT; |
7be08a72 | 4311 | schedule_delayed_work(&bp->sp_rtnl_task, 0); |
72fd0718 VZ |
4312 | /* Disable HW interrupts */ |
4313 | bnx2x_int_disable(bp); | |
72fd0718 VZ |
4314 | /* In case of parity errors don't handle attentions so that |
4315 | * other function would "see" parity errors. | |
4316 | */ | |
c9ee9206 VZ |
4317 | #else |
4318 | bnx2x_panic(); | |
4319 | #endif | |
4320 | bnx2x_release_alr(bp); | |
72fd0718 VZ |
4321 | return; |
4322 | } | |
4323 | ||
a2fbb9ea ET |
4324 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
4325 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); | |
4326 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); | |
4327 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); | |
619c5cb6 | 4328 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
4329 | attn.sig[4] = |
4330 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); | |
4331 | else | |
4332 | attn.sig[4] = 0; | |
4333 | ||
4334 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n", | |
4335 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); | |
a2fbb9ea ET |
4336 | |
4337 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { | |
4338 | if (deasserted & (1 << index)) { | |
72fd0718 | 4339 | group_mask = &bp->attn_group[index]; |
a2fbb9ea | 4340 | |
51c1a580 | 4341 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n", |
f2e0899f DK |
4342 | index, |
4343 | group_mask->sig[0], group_mask->sig[1], | |
4344 | group_mask->sig[2], group_mask->sig[3], | |
4345 | group_mask->sig[4]); | |
a2fbb9ea | 4346 | |
f2e0899f DK |
4347 | bnx2x_attn_int_deasserted4(bp, |
4348 | attn.sig[4] & group_mask->sig[4]); | |
877e9aa4 | 4349 | bnx2x_attn_int_deasserted3(bp, |
72fd0718 | 4350 | attn.sig[3] & group_mask->sig[3]); |
877e9aa4 | 4351 | bnx2x_attn_int_deasserted1(bp, |
72fd0718 | 4352 | attn.sig[1] & group_mask->sig[1]); |
877e9aa4 | 4353 | bnx2x_attn_int_deasserted2(bp, |
72fd0718 | 4354 | attn.sig[2] & group_mask->sig[2]); |
877e9aa4 | 4355 | bnx2x_attn_int_deasserted0(bp, |
72fd0718 | 4356 | attn.sig[0] & group_mask->sig[0]); |
a2fbb9ea ET |
4357 | } |
4358 | } | |
4359 | ||
4a37fb66 | 4360 | bnx2x_release_alr(bp); |
a2fbb9ea | 4361 | |
f2e0899f DK |
4362 | if (bp->common.int_block == INT_BLOCK_HC) |
4363 | reg_addr = (HC_REG_COMMAND_REG + port*32 + | |
4364 | COMMAND_REG_ATTN_BITS_CLR); | |
4365 | else | |
4366 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); | |
a2fbb9ea ET |
4367 | |
4368 | val = ~deasserted; | |
f2e0899f DK |
4369 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val, |
4370 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); | |
5c862848 | 4371 | REG_WR(bp, reg_addr, val); |
a2fbb9ea | 4372 | |
a2fbb9ea | 4373 | if (~bp->attn_state & deasserted) |
3fcaf2e5 | 4374 | BNX2X_ERR("IGU ERROR\n"); |
a2fbb9ea ET |
4375 | |
4376 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
4377 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
4378 | ||
3fcaf2e5 EG |
4379 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
4380 | aeu_mask = REG_RD(bp, reg_addr); | |
4381 | ||
4382 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", | |
4383 | aeu_mask, deasserted); | |
72fd0718 | 4384 | aeu_mask |= (deasserted & 0x3ff); |
3fcaf2e5 | 4385 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
a2fbb9ea | 4386 | |
3fcaf2e5 EG |
4387 | REG_WR(bp, reg_addr, aeu_mask); |
4388 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); | |
a2fbb9ea ET |
4389 | |
4390 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); | |
4391 | bp->attn_state &= ~deasserted; | |
4392 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); | |
4393 | } | |
4394 | ||
4395 | static void bnx2x_attn_int(struct bnx2x *bp) | |
4396 | { | |
4397 | /* read local copy of bits */ | |
68d59484 EG |
4398 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
4399 | attn_bits); | |
4400 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. | |
4401 | attn_bits_ack); | |
a2fbb9ea ET |
4402 | u32 attn_state = bp->attn_state; |
4403 | ||
4404 | /* look for changed bits */ | |
4405 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; | |
4406 | u32 deasserted = ~attn_bits & attn_ack & attn_state; | |
4407 | ||
4408 | DP(NETIF_MSG_HW, | |
4409 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", | |
4410 | attn_bits, attn_ack, asserted, deasserted); | |
4411 | ||
4412 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) | |
34f80b04 | 4413 | BNX2X_ERR("BAD attention state\n"); |
a2fbb9ea ET |
4414 | |
4415 | /* handle bits that were raised */ | |
4416 | if (asserted) | |
4417 | bnx2x_attn_int_asserted(bp, asserted); | |
4418 | ||
4419 | if (deasserted) | |
4420 | bnx2x_attn_int_deasserted(bp, deasserted); | |
4421 | } | |
4422 | ||
619c5cb6 VZ |
4423 | void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
4424 | u16 index, u8 op, u8 update) | |
4425 | { | |
4426 | u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; | |
4427 | ||
4428 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, | |
4429 | igu_addr); | |
4430 | } | |
4431 | ||
523224a3 DK |
4432 | static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod) |
4433 | { | |
4434 | /* No memory barriers */ | |
4435 | storm_memset_eq_prod(bp, prod, BP_FUNC(bp)); | |
4436 | mmiowb(); /* keep prod updates ordered */ | |
4437 | } | |
4438 | ||
4439 | #ifdef BCM_CNIC | |
4440 | static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid, | |
4441 | union event_ring_elem *elem) | |
4442 | { | |
619c5cb6 VZ |
4443 | u8 err = elem->message.error; |
4444 | ||
523224a3 | 4445 | if (!bp->cnic_eth_dev.starting_cid || |
c3a8ce61 VZ |
4446 | (cid < bp->cnic_eth_dev.starting_cid && |
4447 | cid != bp->cnic_eth_dev.iscsi_l2_cid)) | |
523224a3 DK |
4448 | return 1; |
4449 | ||
4450 | DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid); | |
4451 | ||
619c5cb6 VZ |
4452 | if (unlikely(err)) { |
4453 | ||
523224a3 DK |
4454 | BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n", |
4455 | cid); | |
4456 | bnx2x_panic_dump(bp); | |
4457 | } | |
619c5cb6 | 4458 | bnx2x_cnic_cfc_comp(bp, cid, err); |
523224a3 DK |
4459 | return 0; |
4460 | } | |
4461 | #endif | |
4462 | ||
619c5cb6 VZ |
4463 | static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp) |
4464 | { | |
4465 | struct bnx2x_mcast_ramrod_params rparam; | |
4466 | int rc; | |
4467 | ||
4468 | memset(&rparam, 0, sizeof(rparam)); | |
4469 | ||
4470 | rparam.mcast_obj = &bp->mcast_obj; | |
4471 | ||
4472 | netif_addr_lock_bh(bp->dev); | |
4473 | ||
4474 | /* Clear pending state for the last command */ | |
4475 | bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw); | |
4476 | ||
4477 | /* If there are pending mcast commands - send them */ | |
4478 | if (bp->mcast_obj.check_pending(&bp->mcast_obj)) { | |
4479 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); | |
4480 | if (rc < 0) | |
4481 | BNX2X_ERR("Failed to send pending mcast commands: %d\n", | |
4482 | rc); | |
4483 | } | |
4484 | ||
4485 | netif_addr_unlock_bh(bp->dev); | |
4486 | } | |
4487 | ||
4488 | static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp, | |
4489 | union event_ring_elem *elem) | |
4490 | { | |
4491 | unsigned long ramrod_flags = 0; | |
4492 | int rc = 0; | |
4493 | u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK; | |
4494 | struct bnx2x_vlan_mac_obj *vlan_mac_obj; | |
4495 | ||
4496 | /* Always push next commands out, don't wait here */ | |
4497 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
4498 | ||
4499 | switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) { | |
4500 | case BNX2X_FILTER_MAC_PENDING: | |
51c1a580 | 4501 | DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n"); |
619c5cb6 VZ |
4502 | #ifdef BCM_CNIC |
4503 | if (cid == BNX2X_ISCSI_ETH_CID) | |
4504 | vlan_mac_obj = &bp->iscsi_l2_mac_obj; | |
4505 | else | |
4506 | #endif | |
4507 | vlan_mac_obj = &bp->fp[cid].mac_obj; | |
4508 | ||
4509 | break; | |
619c5cb6 | 4510 | case BNX2X_FILTER_MCAST_PENDING: |
51c1a580 | 4511 | DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n"); |
619c5cb6 VZ |
4512 | /* This is only relevant for 57710 where multicast MACs are |
4513 | * configured as unicast MACs using the same ramrod. | |
4514 | */ | |
4515 | bnx2x_handle_mcast_eqe(bp); | |
4516 | return; | |
4517 | default: | |
4518 | BNX2X_ERR("Unsupported classification command: %d\n", | |
4519 | elem->message.data.eth_event.echo); | |
4520 | return; | |
4521 | } | |
4522 | ||
4523 | rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags); | |
4524 | ||
4525 | if (rc < 0) | |
4526 | BNX2X_ERR("Failed to schedule new commands: %d\n", rc); | |
4527 | else if (rc > 0) | |
4528 | DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n"); | |
4529 | ||
4530 | } | |
4531 | ||
4532 | #ifdef BCM_CNIC | |
4533 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start); | |
4534 | #endif | |
4535 | ||
4536 | static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp) | |
4537 | { | |
4538 | netif_addr_lock_bh(bp->dev); | |
4539 | ||
4540 | clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
4541 | ||
4542 | /* Send rx_mode command again if was requested */ | |
4543 | if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state)) | |
4544 | bnx2x_set_storm_rx_mode(bp); | |
4545 | #ifdef BCM_CNIC | |
4546 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, | |
4547 | &bp->sp_state)) | |
4548 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
4549 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, | |
4550 | &bp->sp_state)) | |
4551 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
4552 | #endif | |
4553 | ||
4554 | netif_addr_unlock_bh(bp->dev); | |
4555 | } | |
4556 | ||
4557 | static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj( | |
4558 | struct bnx2x *bp, u32 cid) | |
4559 | { | |
94f05b0f | 4560 | DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid); |
619c5cb6 VZ |
4561 | #ifdef BCM_CNIC |
4562 | if (cid == BNX2X_FCOE_ETH_CID) | |
4563 | return &bnx2x_fcoe(bp, q_obj); | |
4564 | else | |
4565 | #endif | |
6383c0b3 | 4566 | return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj); |
619c5cb6 VZ |
4567 | } |
4568 | ||
523224a3 DK |
4569 | static void bnx2x_eq_int(struct bnx2x *bp) |
4570 | { | |
4571 | u16 hw_cons, sw_cons, sw_prod; | |
4572 | union event_ring_elem *elem; | |
4573 | u32 cid; | |
4574 | u8 opcode; | |
4575 | int spqe_cnt = 0; | |
619c5cb6 VZ |
4576 | struct bnx2x_queue_sp_obj *q_obj; |
4577 | struct bnx2x_func_sp_obj *f_obj = &bp->func_obj; | |
4578 | struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw; | |
523224a3 DK |
4579 | |
4580 | hw_cons = le16_to_cpu(*bp->eq_cons_sb); | |
4581 | ||
4582 | /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256. | |
4583 | * when we get the the next-page we nned to adjust so the loop | |
4584 | * condition below will be met. The next element is the size of a | |
4585 | * regular element and hence incrementing by 1 | |
4586 | */ | |
4587 | if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) | |
4588 | hw_cons++; | |
4589 | ||
25985edc | 4590 | /* This function may never run in parallel with itself for a |
523224a3 DK |
4591 | * specific bp, thus there is no need in "paired" read memory |
4592 | * barrier here. | |
4593 | */ | |
4594 | sw_cons = bp->eq_cons; | |
4595 | sw_prod = bp->eq_prod; | |
4596 | ||
d6cae238 | 4597 | DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n", |
6e30dd4e | 4598 | hw_cons, sw_cons, atomic_read(&bp->eq_spq_left)); |
523224a3 DK |
4599 | |
4600 | for (; sw_cons != hw_cons; | |
4601 | sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { | |
4602 | ||
4603 | ||
4604 | elem = &bp->eq_ring[EQ_DESC(sw_cons)]; | |
4605 | ||
4606 | cid = SW_CID(elem->message.data.cfc_del_event.cid); | |
4607 | opcode = elem->message.opcode; | |
4608 | ||
4609 | ||
4610 | /* handle eq element */ | |
4611 | switch (opcode) { | |
4612 | case EVENT_RING_OPCODE_STAT_QUERY: | |
51c1a580 MS |
4613 | DP(BNX2X_MSG_SP | BNX2X_MSG_STATS, |
4614 | "got statistics comp event %d\n", | |
619c5cb6 | 4615 | bp->stats_comp++); |
523224a3 | 4616 | /* nothing to do with stats comp */ |
d6cae238 | 4617 | goto next_spqe; |
523224a3 DK |
4618 | |
4619 | case EVENT_RING_OPCODE_CFC_DEL: | |
4620 | /* handle according to cid range */ | |
4621 | /* | |
4622 | * we may want to verify here that the bp state is | |
4623 | * HALTING | |
4624 | */ | |
d6cae238 | 4625 | DP(BNX2X_MSG_SP, |
523224a3 DK |
4626 | "got delete ramrod for MULTI[%d]\n", cid); |
4627 | #ifdef BCM_CNIC | |
4628 | if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem)) | |
4629 | goto next_spqe; | |
4630 | #endif | |
619c5cb6 VZ |
4631 | q_obj = bnx2x_cid_to_q_obj(bp, cid); |
4632 | ||
4633 | if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL)) | |
4634 | break; | |
4635 | ||
4636 | ||
523224a3 DK |
4637 | |
4638 | goto next_spqe; | |
e4901dde VZ |
4639 | |
4640 | case EVENT_RING_OPCODE_STOP_TRAFFIC: | |
51c1a580 | 4641 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n"); |
6debea87 DK |
4642 | if (f_obj->complete_cmd(bp, f_obj, |
4643 | BNX2X_F_CMD_TX_STOP)) | |
4644 | break; | |
e4901dde VZ |
4645 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED); |
4646 | goto next_spqe; | |
619c5cb6 | 4647 | |
e4901dde | 4648 | case EVENT_RING_OPCODE_START_TRAFFIC: |
51c1a580 | 4649 | DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n"); |
6debea87 DK |
4650 | if (f_obj->complete_cmd(bp, f_obj, |
4651 | BNX2X_F_CMD_TX_START)) | |
4652 | break; | |
e4901dde VZ |
4653 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED); |
4654 | goto next_spqe; | |
619c5cb6 | 4655 | case EVENT_RING_OPCODE_FUNCTION_START: |
51c1a580 MS |
4656 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
4657 | "got FUNC_START ramrod\n"); | |
619c5cb6 VZ |
4658 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START)) |
4659 | break; | |
4660 | ||
4661 | goto next_spqe; | |
4662 | ||
4663 | case EVENT_RING_OPCODE_FUNCTION_STOP: | |
51c1a580 MS |
4664 | DP(BNX2X_MSG_SP | NETIF_MSG_IFUP, |
4665 | "got FUNC_STOP ramrod\n"); | |
619c5cb6 VZ |
4666 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP)) |
4667 | break; | |
4668 | ||
4669 | goto next_spqe; | |
523224a3 DK |
4670 | } |
4671 | ||
4672 | switch (opcode | bp->state) { | |
619c5cb6 VZ |
4673 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
4674 | BNX2X_STATE_OPEN): | |
4675 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | | |
523224a3 | 4676 | BNX2X_STATE_OPENING_WAIT4_PORT): |
619c5cb6 VZ |
4677 | cid = elem->message.data.eth_event.echo & |
4678 | BNX2X_SWCID_MASK; | |
d6cae238 | 4679 | DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n", |
619c5cb6 VZ |
4680 | cid); |
4681 | rss_raw->clear_pending(rss_raw); | |
523224a3 DK |
4682 | break; |
4683 | ||
619c5cb6 VZ |
4684 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN): |
4685 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG): | |
4686 | case (EVENT_RING_OPCODE_SET_MAC | | |
523224a3 | 4687 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
619c5cb6 VZ |
4688 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
4689 | BNX2X_STATE_OPEN): | |
4690 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
4691 | BNX2X_STATE_DIAG): | |
4692 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | | |
4693 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 4694 | DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n"); |
619c5cb6 | 4695 | bnx2x_handle_classification_eqe(bp, elem); |
523224a3 DK |
4696 | break; |
4697 | ||
619c5cb6 VZ |
4698 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
4699 | BNX2X_STATE_OPEN): | |
4700 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
4701 | BNX2X_STATE_DIAG): | |
4702 | case (EVENT_RING_OPCODE_MULTICAST_RULES | | |
4703 | BNX2X_STATE_CLOSING_WAIT4_HALT): | |
d6cae238 | 4704 | DP(BNX2X_MSG_SP, "got mcast ramrod\n"); |
619c5cb6 | 4705 | bnx2x_handle_mcast_eqe(bp); |
523224a3 DK |
4706 | break; |
4707 | ||
619c5cb6 VZ |
4708 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
4709 | BNX2X_STATE_OPEN): | |
4710 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
4711 | BNX2X_STATE_DIAG): | |
4712 | case (EVENT_RING_OPCODE_FILTERS_RULES | | |
523224a3 | 4713 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
d6cae238 | 4714 | DP(BNX2X_MSG_SP, "got rx_mode ramrod\n"); |
619c5cb6 | 4715 | bnx2x_handle_rx_mode_eqe(bp); |
523224a3 DK |
4716 | break; |
4717 | default: | |
4718 | /* unknown event log error and continue */ | |
619c5cb6 VZ |
4719 | BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n", |
4720 | elem->message.opcode, bp->state); | |
523224a3 DK |
4721 | } |
4722 | next_spqe: | |
4723 | spqe_cnt++; | |
4724 | } /* for */ | |
4725 | ||
8fe23fbd | 4726 | smp_mb__before_atomic_inc(); |
6e30dd4e | 4727 | atomic_add(spqe_cnt, &bp->eq_spq_left); |
523224a3 DK |
4728 | |
4729 | bp->eq_cons = sw_cons; | |
4730 | bp->eq_prod = sw_prod; | |
4731 | /* Make sure that above mem writes were issued towards the memory */ | |
4732 | smp_wmb(); | |
4733 | ||
4734 | /* update producer */ | |
4735 | bnx2x_update_eq_prod(bp, bp->eq_prod); | |
4736 | } | |
4737 | ||
a2fbb9ea ET |
4738 | static void bnx2x_sp_task(struct work_struct *work) |
4739 | { | |
1cf167f2 | 4740 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
a2fbb9ea ET |
4741 | u16 status; |
4742 | ||
a2fbb9ea | 4743 | status = bnx2x_update_dsb_idx(bp); |
34f80b04 EG |
4744 | /* if (status == 0) */ |
4745 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ | |
a2fbb9ea | 4746 | |
51c1a580 | 4747 | DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status); |
a2fbb9ea | 4748 | |
877e9aa4 | 4749 | /* HW attentions */ |
523224a3 | 4750 | if (status & BNX2X_DEF_SB_ATT_IDX) { |
a2fbb9ea | 4751 | bnx2x_attn_int(bp); |
523224a3 | 4752 | status &= ~BNX2X_DEF_SB_ATT_IDX; |
cdaa7cb8 VZ |
4753 | } |
4754 | ||
523224a3 DK |
4755 | /* SP events: STAT_QUERY and others */ |
4756 | if (status & BNX2X_DEF_SB_IDX) { | |
ec6ba945 VZ |
4757 | #ifdef BCM_CNIC |
4758 | struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp); | |
523224a3 | 4759 | |
ec6ba945 | 4760 | if ((!NO_FCOE(bp)) && |
019dbb4c VZ |
4761 | (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) { |
4762 | /* | |
4763 | * Prevent local bottom-halves from running as | |
4764 | * we are going to change the local NAPI list. | |
4765 | */ | |
4766 | local_bh_disable(); | |
ec6ba945 | 4767 | napi_schedule(&bnx2x_fcoe(bp, napi)); |
019dbb4c VZ |
4768 | local_bh_enable(); |
4769 | } | |
ec6ba945 | 4770 | #endif |
523224a3 DK |
4771 | /* Handle EQ completions */ |
4772 | bnx2x_eq_int(bp); | |
4773 | ||
4774 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, | |
4775 | le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1); | |
4776 | ||
4777 | status &= ~BNX2X_DEF_SB_IDX; | |
cdaa7cb8 VZ |
4778 | } |
4779 | ||
4780 | if (unlikely(status)) | |
51c1a580 | 4781 | DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n", |
cdaa7cb8 | 4782 | status); |
a2fbb9ea | 4783 | |
523224a3 DK |
4784 | bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID, |
4785 | le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1); | |
a2fbb9ea ET |
4786 | } |
4787 | ||
9f6c9258 | 4788 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
a2fbb9ea ET |
4789 | { |
4790 | struct net_device *dev = dev_instance; | |
4791 | struct bnx2x *bp = netdev_priv(dev); | |
4792 | ||
523224a3 DK |
4793 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, |
4794 | IGU_INT_DISABLE, 0); | |
a2fbb9ea ET |
4795 | |
4796 | #ifdef BNX2X_STOP_ON_ERROR | |
4797 | if (unlikely(bp->panic)) | |
4798 | return IRQ_HANDLED; | |
4799 | #endif | |
4800 | ||
993ac7b5 MC |
4801 | #ifdef BCM_CNIC |
4802 | { | |
4803 | struct cnic_ops *c_ops; | |
4804 | ||
4805 | rcu_read_lock(); | |
4806 | c_ops = rcu_dereference(bp->cnic_ops); | |
4807 | if (c_ops) | |
4808 | c_ops->cnic_handler(bp->cnic_data, NULL); | |
4809 | rcu_read_unlock(); | |
4810 | } | |
4811 | #endif | |
1cf167f2 | 4812 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
a2fbb9ea ET |
4813 | |
4814 | return IRQ_HANDLED; | |
4815 | } | |
4816 | ||
4817 | /* end of slow path */ | |
4818 | ||
619c5cb6 VZ |
4819 | |
4820 | void bnx2x_drv_pulse(struct bnx2x *bp) | |
4821 | { | |
4822 | SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb, | |
4823 | bp->fw_drv_pulse_wr_seq); | |
4824 | } | |
4825 | ||
4826 | ||
a2fbb9ea ET |
4827 | static void bnx2x_timer(unsigned long data) |
4828 | { | |
4829 | struct bnx2x *bp = (struct bnx2x *) data; | |
4830 | ||
4831 | if (!netif_running(bp->dev)) | |
4832 | return; | |
4833 | ||
34f80b04 | 4834 | if (!BP_NOMCP(bp)) { |
f2e0899f | 4835 | int mb_idx = BP_FW_MB_IDX(bp); |
a2fbb9ea ET |
4836 | u32 drv_pulse; |
4837 | u32 mcp_pulse; | |
4838 | ||
4839 | ++bp->fw_drv_pulse_wr_seq; | |
4840 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; | |
4841 | /* TBD - add SYSTEM_TIME */ | |
4842 | drv_pulse = bp->fw_drv_pulse_wr_seq; | |
619c5cb6 | 4843 | bnx2x_drv_pulse(bp); |
a2fbb9ea | 4844 | |
f2e0899f | 4845 | mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) & |
a2fbb9ea ET |
4846 | MCP_PULSE_SEQ_MASK); |
4847 | /* The delta between driver pulse and mcp response | |
4848 | * should be 1 (before mcp response) or 0 (after mcp response) | |
4849 | */ | |
4850 | if ((drv_pulse != mcp_pulse) && | |
4851 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { | |
4852 | /* someone lost a heartbeat... */ | |
4853 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", | |
4854 | drv_pulse, mcp_pulse); | |
4855 | } | |
4856 | } | |
4857 | ||
f34d28ea | 4858 | if (bp->state == BNX2X_STATE_OPEN) |
bb2a0f7a | 4859 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
a2fbb9ea | 4860 | |
a2fbb9ea ET |
4861 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
4862 | } | |
4863 | ||
4864 | /* end of Statistics */ | |
4865 | ||
4866 | /* nic init */ | |
4867 | ||
4868 | /* | |
4869 | * nic init service functions | |
4870 | */ | |
4871 | ||
523224a3 | 4872 | static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len) |
a2fbb9ea | 4873 | { |
523224a3 DK |
4874 | u32 i; |
4875 | if (!(len%4) && !(addr%4)) | |
4876 | for (i = 0; i < len; i += 4) | |
4877 | REG_WR(bp, addr + i, fill); | |
4878 | else | |
4879 | for (i = 0; i < len; i++) | |
4880 | REG_WR8(bp, addr + i, fill); | |
34f80b04 | 4881 | |
34f80b04 EG |
4882 | } |
4883 | ||
523224a3 DK |
4884 | /* helper: writes FP SP data to FW - data_size in dwords */ |
4885 | static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp, | |
4886 | int fw_sb_id, | |
4887 | u32 *sb_data_p, | |
4888 | u32 data_size) | |
34f80b04 | 4889 | { |
a2fbb9ea | 4890 | int index; |
523224a3 DK |
4891 | for (index = 0; index < data_size; index++) |
4892 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
4893 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + | |
4894 | sizeof(u32)*index, | |
4895 | *(sb_data_p + index)); | |
4896 | } | |
a2fbb9ea | 4897 | |
523224a3 DK |
4898 | static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id) |
4899 | { | |
4900 | u32 *sb_data_p; | |
4901 | u32 data_size = 0; | |
f2e0899f | 4902 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 | 4903 | struct hc_status_block_data_e1x sb_data_e1x; |
a2fbb9ea | 4904 | |
523224a3 | 4905 | /* disable the function first */ |
619c5cb6 | 4906 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 4907 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 4908 | sb_data_e2.common.state = SB_DISABLED; |
f2e0899f DK |
4909 | sb_data_e2.common.p_func.vf_valid = false; |
4910 | sb_data_p = (u32 *)&sb_data_e2; | |
4911 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
4912 | } else { | |
4913 | memset(&sb_data_e1x, 0, | |
4914 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 4915 | sb_data_e1x.common.state = SB_DISABLED; |
f2e0899f DK |
4916 | sb_data_e1x.common.p_func.vf_valid = false; |
4917 | sb_data_p = (u32 *)&sb_data_e1x; | |
4918 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
4919 | } | |
523224a3 | 4920 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
a2fbb9ea | 4921 | |
523224a3 DK |
4922 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
4923 | CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0, | |
4924 | CSTORM_STATUS_BLOCK_SIZE); | |
4925 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
4926 | CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0, | |
4927 | CSTORM_SYNC_BLOCK_SIZE); | |
4928 | } | |
34f80b04 | 4929 | |
523224a3 DK |
4930 | /* helper: writes SP SB data to FW */ |
4931 | static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp, | |
4932 | struct hc_sp_status_block_data *sp_sb_data) | |
4933 | { | |
4934 | int func = BP_FUNC(bp); | |
4935 | int i; | |
4936 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) | |
4937 | REG_WR(bp, BAR_CSTRORM_INTMEM + | |
4938 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + | |
4939 | i*sizeof(u32), | |
4940 | *((u32 *)sp_sb_data + i)); | |
34f80b04 EG |
4941 | } |
4942 | ||
523224a3 | 4943 | static inline void bnx2x_zero_sp_sb(struct bnx2x *bp) |
34f80b04 EG |
4944 | { |
4945 | int func = BP_FUNC(bp); | |
523224a3 DK |
4946 | struct hc_sp_status_block_data sp_sb_data; |
4947 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
a2fbb9ea | 4948 | |
619c5cb6 | 4949 | sp_sb_data.state = SB_DISABLED; |
523224a3 DK |
4950 | sp_sb_data.p_func.vf_valid = false; |
4951 | ||
4952 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); | |
4953 | ||
4954 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
4955 | CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0, | |
4956 | CSTORM_SP_STATUS_BLOCK_SIZE); | |
4957 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + | |
4958 | CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0, | |
4959 | CSTORM_SP_SYNC_BLOCK_SIZE); | |
4960 | ||
4961 | } | |
4962 | ||
4963 | ||
4964 | static inline | |
4965 | void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, | |
4966 | int igu_sb_id, int igu_seg_id) | |
4967 | { | |
4968 | hc_sm->igu_sb_id = igu_sb_id; | |
4969 | hc_sm->igu_seg_id = igu_seg_id; | |
4970 | hc_sm->timer_value = 0xFF; | |
4971 | hc_sm->time_to_expire = 0xFFFFFFFF; | |
a2fbb9ea ET |
4972 | } |
4973 | ||
150966ad AE |
4974 | |
4975 | /* allocates state machine ids. */ | |
4976 | static inline | |
4977 | void bnx2x_map_sb_state_machines(struct hc_index_data *index_data) | |
4978 | { | |
4979 | /* zero out state machine indices */ | |
4980 | /* rx indices */ | |
4981 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
4982 | ||
4983 | /* tx indices */ | |
4984 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID; | |
4985 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID; | |
4986 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID; | |
4987 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID; | |
4988 | ||
4989 | /* map indices */ | |
4990 | /* rx indices */ | |
4991 | index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |= | |
4992 | SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
4993 | ||
4994 | /* tx indices */ | |
4995 | index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |= | |
4996 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
4997 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |= | |
4998 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
4999 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |= | |
5000 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5001 | index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |= | |
5002 | SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT; | |
5003 | } | |
5004 | ||
8d96286a | 5005 | static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid, |
523224a3 | 5006 | u8 vf_valid, int fw_sb_id, int igu_sb_id) |
a2fbb9ea | 5007 | { |
523224a3 DK |
5008 | int igu_seg_id; |
5009 | ||
f2e0899f | 5010 | struct hc_status_block_data_e2 sb_data_e2; |
523224a3 DK |
5011 | struct hc_status_block_data_e1x sb_data_e1x; |
5012 | struct hc_status_block_sm *hc_sm_p; | |
523224a3 DK |
5013 | int data_size; |
5014 | u32 *sb_data_p; | |
5015 | ||
f2e0899f DK |
5016 | if (CHIP_INT_MODE_IS_BC(bp)) |
5017 | igu_seg_id = HC_SEG_ACCESS_NORM; | |
5018 | else | |
5019 | igu_seg_id = IGU_SEG_ACCESS_NORM; | |
523224a3 DK |
5020 | |
5021 | bnx2x_zero_fp_sb(bp, fw_sb_id); | |
5022 | ||
619c5cb6 | 5023 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f | 5024 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
619c5cb6 | 5025 | sb_data_e2.common.state = SB_ENABLED; |
f2e0899f DK |
5026 | sb_data_e2.common.p_func.pf_id = BP_FUNC(bp); |
5027 | sb_data_e2.common.p_func.vf_id = vfid; | |
5028 | sb_data_e2.common.p_func.vf_valid = vf_valid; | |
5029 | sb_data_e2.common.p_func.vnic_id = BP_VN(bp); | |
5030 | sb_data_e2.common.same_igu_sb_1b = true; | |
5031 | sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping); | |
5032 | sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping); | |
5033 | hc_sm_p = sb_data_e2.common.state_machine; | |
f2e0899f DK |
5034 | sb_data_p = (u32 *)&sb_data_e2; |
5035 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); | |
150966ad | 5036 | bnx2x_map_sb_state_machines(sb_data_e2.index_data); |
f2e0899f DK |
5037 | } else { |
5038 | memset(&sb_data_e1x, 0, | |
5039 | sizeof(struct hc_status_block_data_e1x)); | |
619c5cb6 | 5040 | sb_data_e1x.common.state = SB_ENABLED; |
f2e0899f DK |
5041 | sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp); |
5042 | sb_data_e1x.common.p_func.vf_id = 0xff; | |
5043 | sb_data_e1x.common.p_func.vf_valid = false; | |
5044 | sb_data_e1x.common.p_func.vnic_id = BP_VN(bp); | |
5045 | sb_data_e1x.common.same_igu_sb_1b = true; | |
5046 | sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping); | |
5047 | sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping); | |
5048 | hc_sm_p = sb_data_e1x.common.state_machine; | |
f2e0899f DK |
5049 | sb_data_p = (u32 *)&sb_data_e1x; |
5050 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); | |
150966ad | 5051 | bnx2x_map_sb_state_machines(sb_data_e1x.index_data); |
f2e0899f | 5052 | } |
523224a3 DK |
5053 | |
5054 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], | |
5055 | igu_sb_id, igu_seg_id); | |
5056 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], | |
5057 | igu_sb_id, igu_seg_id); | |
5058 | ||
51c1a580 | 5059 | DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id); |
523224a3 DK |
5060 | |
5061 | /* write indecies to HW */ | |
5062 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); | |
5063 | } | |
5064 | ||
619c5cb6 | 5065 | static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id, |
523224a3 DK |
5066 | u16 tx_usec, u16 rx_usec) |
5067 | { | |
6383c0b3 | 5068 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS, |
523224a3 | 5069 | false, rx_usec); |
6383c0b3 AE |
5070 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, |
5071 | HC_INDEX_ETH_TX_CQ_CONS_COS0, false, | |
5072 | tx_usec); | |
5073 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5074 | HC_INDEX_ETH_TX_CQ_CONS_COS1, false, | |
5075 | tx_usec); | |
5076 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, | |
5077 | HC_INDEX_ETH_TX_CQ_CONS_COS2, false, | |
5078 | tx_usec); | |
523224a3 | 5079 | } |
f2e0899f | 5080 | |
523224a3 DK |
5081 | static void bnx2x_init_def_sb(struct bnx2x *bp) |
5082 | { | |
5083 | struct host_sp_status_block *def_sb = bp->def_status_blk; | |
5084 | dma_addr_t mapping = bp->def_status_blk_mapping; | |
5085 | int igu_sp_sb_index; | |
5086 | int igu_seg_id; | |
34f80b04 EG |
5087 | int port = BP_PORT(bp); |
5088 | int func = BP_FUNC(bp); | |
f2eaeb58 | 5089 | int reg_offset, reg_offset_en5; |
a2fbb9ea | 5090 | u64 section; |
523224a3 DK |
5091 | int index; |
5092 | struct hc_sp_status_block_data sp_sb_data; | |
5093 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); | |
5094 | ||
f2e0899f DK |
5095 | if (CHIP_INT_MODE_IS_BC(bp)) { |
5096 | igu_sp_sb_index = DEF_SB_IGU_ID; | |
5097 | igu_seg_id = HC_SEG_ACCESS_DEF; | |
5098 | } else { | |
5099 | igu_sp_sb_index = bp->igu_dsb_id; | |
5100 | igu_seg_id = IGU_SEG_ACCESS_DEF; | |
5101 | } | |
a2fbb9ea ET |
5102 | |
5103 | /* ATTN */ | |
523224a3 | 5104 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
a2fbb9ea | 5105 | atten_status_block); |
523224a3 | 5106 | def_sb->atten_status_block.status_block_id = igu_sp_sb_index; |
a2fbb9ea | 5107 | |
49d66772 ET |
5108 | bp->attn_state = 0; |
5109 | ||
a2fbb9ea ET |
5110 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
5111 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
f2eaeb58 DK |
5112 | reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 : |
5113 | MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0); | |
34f80b04 | 5114 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
523224a3 DK |
5115 | int sindex; |
5116 | /* take care of sig[0]..sig[4] */ | |
5117 | for (sindex = 0; sindex < 4; sindex++) | |
5118 | bp->attn_group[index].sig[sindex] = | |
5119 | REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index); | |
f2e0899f | 5120 | |
619c5cb6 | 5121 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
5122 | /* |
5123 | * enable5 is separate from the rest of the registers, | |
5124 | * and therefore the address skip is 4 | |
5125 | * and not 16 between the different groups | |
5126 | */ | |
5127 | bp->attn_group[index].sig[4] = REG_RD(bp, | |
f2eaeb58 | 5128 | reg_offset_en5 + 0x4*index); |
f2e0899f DK |
5129 | else |
5130 | bp->attn_group[index].sig[4] = 0; | |
a2fbb9ea ET |
5131 | } |
5132 | ||
f2e0899f DK |
5133 | if (bp->common.int_block == INT_BLOCK_HC) { |
5134 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : | |
5135 | HC_REG_ATTN_MSG0_ADDR_L); | |
5136 | ||
5137 | REG_WR(bp, reg_offset, U64_LO(section)); | |
5138 | REG_WR(bp, reg_offset + 4, U64_HI(section)); | |
619c5cb6 | 5139 | } else if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
5140 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); |
5141 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); | |
5142 | } | |
a2fbb9ea | 5143 | |
523224a3 DK |
5144 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
5145 | sp_sb); | |
a2fbb9ea | 5146 | |
523224a3 | 5147 | bnx2x_zero_sp_sb(bp); |
a2fbb9ea | 5148 | |
619c5cb6 | 5149 | sp_sb_data.state = SB_ENABLED; |
523224a3 DK |
5150 | sp_sb_data.host_sb_addr.lo = U64_LO(section); |
5151 | sp_sb_data.host_sb_addr.hi = U64_HI(section); | |
5152 | sp_sb_data.igu_sb_id = igu_sp_sb_index; | |
5153 | sp_sb_data.igu_seg_id = igu_seg_id; | |
5154 | sp_sb_data.p_func.pf_id = func; | |
f2e0899f | 5155 | sp_sb_data.p_func.vnic_id = BP_VN(bp); |
523224a3 | 5156 | sp_sb_data.p_func.vf_id = 0xff; |
a2fbb9ea | 5157 | |
523224a3 | 5158 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
49d66772 | 5159 | |
523224a3 | 5160 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); |
a2fbb9ea ET |
5161 | } |
5162 | ||
9f6c9258 | 5163 | void bnx2x_update_coalesce(struct bnx2x *bp) |
a2fbb9ea | 5164 | { |
a2fbb9ea ET |
5165 | int i; |
5166 | ||
ec6ba945 | 5167 | for_each_eth_queue(bp, i) |
523224a3 | 5168 | bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id, |
423cfa7e | 5169 | bp->tx_ticks, bp->rx_ticks); |
a2fbb9ea ET |
5170 | } |
5171 | ||
a2fbb9ea ET |
5172 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
5173 | { | |
a2fbb9ea | 5174 | spin_lock_init(&bp->spq_lock); |
6e30dd4e | 5175 | atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING); |
a2fbb9ea | 5176 | |
a2fbb9ea | 5177 | bp->spq_prod_idx = 0; |
a2fbb9ea ET |
5178 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
5179 | bp->spq_prod_bd = bp->spq; | |
5180 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; | |
a2fbb9ea ET |
5181 | } |
5182 | ||
523224a3 | 5183 | static void bnx2x_init_eq_ring(struct bnx2x *bp) |
a2fbb9ea ET |
5184 | { |
5185 | int i; | |
523224a3 DK |
5186 | for (i = 1; i <= NUM_EQ_PAGES; i++) { |
5187 | union event_ring_elem *elem = | |
5188 | &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1]; | |
a2fbb9ea | 5189 | |
523224a3 DK |
5190 | elem->next_page.addr.hi = |
5191 | cpu_to_le32(U64_HI(bp->eq_mapping + | |
5192 | BCM_PAGE_SIZE * (i % NUM_EQ_PAGES))); | |
5193 | elem->next_page.addr.lo = | |
5194 | cpu_to_le32(U64_LO(bp->eq_mapping + | |
5195 | BCM_PAGE_SIZE*(i % NUM_EQ_PAGES))); | |
a2fbb9ea | 5196 | } |
523224a3 DK |
5197 | bp->eq_cons = 0; |
5198 | bp->eq_prod = NUM_EQ_DESC; | |
5199 | bp->eq_cons_sb = BNX2X_EQ_INDEX; | |
6e30dd4e VZ |
5200 | /* we want a warning message before it gets rought... */ |
5201 | atomic_set(&bp->eq_spq_left, | |
5202 | min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1); | |
a2fbb9ea ET |
5203 | } |
5204 | ||
619c5cb6 VZ |
5205 | |
5206 | /* called with netif_addr_lock_bh() */ | |
5207 | void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id, | |
5208 | unsigned long rx_mode_flags, | |
5209 | unsigned long rx_accept_flags, | |
5210 | unsigned long tx_accept_flags, | |
5211 | unsigned long ramrod_flags) | |
ab532cf3 | 5212 | { |
619c5cb6 VZ |
5213 | struct bnx2x_rx_mode_ramrod_params ramrod_param; |
5214 | int rc; | |
5215 | ||
5216 | memset(&ramrod_param, 0, sizeof(ramrod_param)); | |
5217 | ||
5218 | /* Prepare ramrod parameters */ | |
5219 | ramrod_param.cid = 0; | |
5220 | ramrod_param.cl_id = cl_id; | |
5221 | ramrod_param.rx_mode_obj = &bp->rx_mode_obj; | |
5222 | ramrod_param.func_id = BP_FUNC(bp); | |
ab532cf3 | 5223 | |
619c5cb6 VZ |
5224 | ramrod_param.pstate = &bp->sp_state; |
5225 | ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING; | |
ab532cf3 | 5226 | |
619c5cb6 VZ |
5227 | ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata); |
5228 | ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata); | |
5229 | ||
5230 | set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); | |
5231 | ||
5232 | ramrod_param.ramrod_flags = ramrod_flags; | |
5233 | ramrod_param.rx_mode_flags = rx_mode_flags; | |
5234 | ||
5235 | ramrod_param.rx_accept_flags = rx_accept_flags; | |
5236 | ramrod_param.tx_accept_flags = tx_accept_flags; | |
5237 | ||
5238 | rc = bnx2x_config_rx_mode(bp, &ramrod_param); | |
5239 | if (rc < 0) { | |
5240 | BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode); | |
5241 | return; | |
5242 | } | |
a2fbb9ea ET |
5243 | } |
5244 | ||
619c5cb6 VZ |
5245 | /* called with netif_addr_lock_bh() */ |
5246 | void bnx2x_set_storm_rx_mode(struct bnx2x *bp) | |
471de716 | 5247 | { |
619c5cb6 VZ |
5248 | unsigned long rx_mode_flags = 0, ramrod_flags = 0; |
5249 | unsigned long rx_accept_flags = 0, tx_accept_flags = 0; | |
471de716 | 5250 | |
619c5cb6 VZ |
5251 | #ifdef BCM_CNIC |
5252 | if (!NO_FCOE(bp)) | |
5253 | ||
5254 | /* Configure rx_mode of FCoE Queue */ | |
5255 | __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags); | |
5256 | #endif | |
5257 | ||
5258 | switch (bp->rx_mode) { | |
5259 | case BNX2X_RX_MODE_NONE: | |
5260 | /* | |
5261 | * 'drop all' supersedes any accept flags that may have been | |
5262 | * passed to the function. | |
5263 | */ | |
5264 | break; | |
5265 | case BNX2X_RX_MODE_NORMAL: | |
5266 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); | |
5267 | __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags); | |
5268 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); | |
5269 | ||
5270 | /* internal switching mode */ | |
5271 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); | |
5272 | __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags); | |
5273 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); | |
5274 | ||
5275 | break; | |
5276 | case BNX2X_RX_MODE_ALLMULTI: | |
5277 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); | |
5278 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); | |
5279 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); | |
5280 | ||
5281 | /* internal switching mode */ | |
5282 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); | |
5283 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); | |
5284 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); | |
5285 | ||
5286 | break; | |
5287 | case BNX2X_RX_MODE_PROMISC: | |
5288 | /* According to deffinition of SI mode, iface in promisc mode | |
5289 | * should receive matched and unmatched (in resolution of port) | |
5290 | * unicast packets. | |
5291 | */ | |
5292 | __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags); | |
5293 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); | |
5294 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); | |
5295 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); | |
5296 | ||
5297 | /* internal switching mode */ | |
5298 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); | |
5299 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); | |
5300 | ||
5301 | if (IS_MF_SI(bp)) | |
5302 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags); | |
5303 | else | |
5304 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); | |
5305 | ||
5306 | break; | |
5307 | default: | |
5308 | BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode); | |
5309 | return; | |
5310 | } | |
de832a55 | 5311 | |
619c5cb6 VZ |
5312 | if (bp->rx_mode != BNX2X_RX_MODE_NONE) { |
5313 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags); | |
5314 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags); | |
34f80b04 EG |
5315 | } |
5316 | ||
619c5cb6 VZ |
5317 | __set_bit(RAMROD_RX, &ramrod_flags); |
5318 | __set_bit(RAMROD_TX, &ramrod_flags); | |
5319 | ||
5320 | bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags, | |
5321 | tx_accept_flags, ramrod_flags); | |
5322 | } | |
5323 | ||
5324 | static void bnx2x_init_internal_common(struct bnx2x *bp) | |
5325 | { | |
5326 | int i; | |
5327 | ||
0793f83f DK |
5328 | if (IS_MF_SI(bp)) |
5329 | /* | |
5330 | * In switch independent mode, the TSTORM needs to accept | |
5331 | * packets that failed classification, since approximate match | |
5332 | * mac addresses aren't written to NIG LLH | |
5333 | */ | |
5334 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
5335 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2); | |
619c5cb6 VZ |
5336 | else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */ |
5337 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
5338 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0); | |
0793f83f | 5339 | |
523224a3 DK |
5340 | /* Zero this manually as its initialization is |
5341 | currently missing in the initTool */ | |
5342 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) | |
ca00392c | 5343 | REG_WR(bp, BAR_USTRORM_INTMEM + |
523224a3 | 5344 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
619c5cb6 | 5345 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
5346 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET, |
5347 | CHIP_INT_MODE_IS_BC(bp) ? | |
5348 | HC_IGU_BC_MODE : HC_IGU_NBC_MODE); | |
5349 | } | |
523224a3 | 5350 | } |
8a1c38d1 | 5351 | |
471de716 EG |
5352 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
5353 | { | |
5354 | switch (load_code) { | |
5355 | case FW_MSG_CODE_DRV_LOAD_COMMON: | |
f2e0899f | 5356 | case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: |
471de716 EG |
5357 | bnx2x_init_internal_common(bp); |
5358 | /* no break */ | |
5359 | ||
5360 | case FW_MSG_CODE_DRV_LOAD_PORT: | |
619c5cb6 | 5361 | /* nothing to do */ |
471de716 EG |
5362 | /* no break */ |
5363 | ||
5364 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: | |
523224a3 DK |
5365 | /* internal memory per function is |
5366 | initialized inside bnx2x_pf_init */ | |
471de716 EG |
5367 | break; |
5368 | ||
5369 | default: | |
5370 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); | |
5371 | break; | |
5372 | } | |
5373 | } | |
5374 | ||
619c5cb6 | 5375 | static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp) |
523224a3 | 5376 | { |
6383c0b3 | 5377 | return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT; |
619c5cb6 | 5378 | } |
523224a3 | 5379 | |
619c5cb6 VZ |
5380 | static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp) |
5381 | { | |
6383c0b3 | 5382 | return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT; |
619c5cb6 VZ |
5383 | } |
5384 | ||
5385 | static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp) | |
5386 | { | |
5387 | if (CHIP_IS_E1x(fp->bp)) | |
5388 | return BP_L_ID(fp->bp) + fp->index; | |
5389 | else /* We want Client ID to be the same as IGU SB ID for 57712 */ | |
5390 | return bnx2x_fp_igu_sb_id(fp); | |
5391 | } | |
5392 | ||
6383c0b3 | 5393 | static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx) |
619c5cb6 VZ |
5394 | { |
5395 | struct bnx2x_fastpath *fp = &bp->fp[fp_idx]; | |
6383c0b3 | 5396 | u8 cos; |
619c5cb6 | 5397 | unsigned long q_type = 0; |
6383c0b3 | 5398 | u32 cids[BNX2X_MULTI_TX_COS] = { 0 }; |
f233cafe | 5399 | fp->rx_queue = fp_idx; |
b3b83c3f | 5400 | fp->cid = fp_idx; |
619c5cb6 VZ |
5401 | fp->cl_id = bnx2x_fp_cl_id(fp); |
5402 | fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp); | |
5403 | fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp); | |
523224a3 | 5404 | /* qZone id equals to FW (per path) client id */ |
619c5cb6 VZ |
5405 | fp->cl_qzone_id = bnx2x_fp_qzone_id(fp); |
5406 | ||
523224a3 | 5407 | /* init shortcut */ |
619c5cb6 | 5408 | fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp); |
7a752993 | 5409 | |
523224a3 DK |
5410 | /* Setup SB indicies */ |
5411 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; | |
523224a3 | 5412 | |
619c5cb6 VZ |
5413 | /* Configure Queue State object */ |
5414 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); | |
5415 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); | |
6383c0b3 AE |
5416 | |
5417 | BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS); | |
5418 | ||
5419 | /* init tx data */ | |
5420 | for_each_cos_in_tx_queue(fp, cos) { | |
5421 | bnx2x_init_txdata(bp, &fp->txdata[cos], | |
5422 | CID_COS_TO_TX_ONLY_CID(fp->cid, cos), | |
5423 | FP_COS_TO_TXQ(fp, cos), | |
5424 | BNX2X_TX_SB_INDEX_BASE + cos); | |
5425 | cids[cos] = fp->txdata[cos].cid; | |
5426 | } | |
5427 | ||
5428 | bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos, | |
5429 | BP_FUNC(bp), bnx2x_sp(bp, q_rdata), | |
5430 | bnx2x_sp_mapping(bp, q_rdata), q_type); | |
619c5cb6 VZ |
5431 | |
5432 | /** | |
5433 | * Configure classification DBs: Always enable Tx switching | |
5434 | */ | |
5435 | bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX); | |
5436 | ||
51c1a580 | 5437 | DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n", |
619c5cb6 | 5438 | fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id, |
523224a3 DK |
5439 | fp->igu_sb_id); |
5440 | bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false, | |
5441 | fp->fw_sb_id, fp->igu_sb_id); | |
5442 | ||
5443 | bnx2x_update_fpsb_idx(fp); | |
5444 | } | |
5445 | ||
9f6c9258 | 5446 | void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
a2fbb9ea ET |
5447 | { |
5448 | int i; | |
5449 | ||
ec6ba945 | 5450 | for_each_eth_queue(bp, i) |
6383c0b3 | 5451 | bnx2x_init_eth_fp(bp, i); |
37b091ba | 5452 | #ifdef BCM_CNIC |
ec6ba945 VZ |
5453 | if (!NO_FCOE(bp)) |
5454 | bnx2x_init_fcoe_fp(bp); | |
523224a3 DK |
5455 | |
5456 | bnx2x_init_sb(bp, bp->cnic_sb_mapping, | |
5457 | BNX2X_VF_ID_INVALID, false, | |
619c5cb6 | 5458 | bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp)); |
523224a3 | 5459 | |
37b091ba | 5460 | #endif |
a2fbb9ea | 5461 | |
020c7e3f YR |
5462 | /* Initialize MOD_ABS interrupts */ |
5463 | bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id, | |
5464 | bp->common.shmem_base, bp->common.shmem2_base, | |
5465 | BP_PORT(bp)); | |
16119785 EG |
5466 | /* ensure status block indices were read */ |
5467 | rmb(); | |
5468 | ||
523224a3 | 5469 | bnx2x_init_def_sb(bp); |
5c862848 | 5470 | bnx2x_update_dsb_idx(bp); |
a2fbb9ea | 5471 | bnx2x_init_rx_rings(bp); |
523224a3 | 5472 | bnx2x_init_tx_rings(bp); |
a2fbb9ea | 5473 | bnx2x_init_sp_ring(bp); |
523224a3 | 5474 | bnx2x_init_eq_ring(bp); |
471de716 | 5475 | bnx2x_init_internal(bp, load_code); |
523224a3 | 5476 | bnx2x_pf_init(bp); |
0ef00459 EG |
5477 | bnx2x_stats_init(bp); |
5478 | ||
0ef00459 EG |
5479 | /* flush all before enabling interrupts */ |
5480 | mb(); | |
5481 | mmiowb(); | |
5482 | ||
615f8fd9 | 5483 | bnx2x_int_enable(bp); |
eb8da205 EG |
5484 | |
5485 | /* Check for SPIO5 */ | |
5486 | bnx2x_attn_int_deasserted0(bp, | |
5487 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & | |
5488 | AEU_INPUTS_ATTN_BITS_SPIO5); | |
a2fbb9ea ET |
5489 | } |
5490 | ||
5491 | /* end of nic init */ | |
5492 | ||
5493 | /* | |
5494 | * gzip service functions | |
5495 | */ | |
5496 | ||
5497 | static int bnx2x_gunzip_init(struct bnx2x *bp) | |
5498 | { | |
1a983142 FT |
5499 | bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE, |
5500 | &bp->gunzip_mapping, GFP_KERNEL); | |
a2fbb9ea ET |
5501 | if (bp->gunzip_buf == NULL) |
5502 | goto gunzip_nomem1; | |
5503 | ||
5504 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); | |
5505 | if (bp->strm == NULL) | |
5506 | goto gunzip_nomem2; | |
5507 | ||
7ab24bfd | 5508 | bp->strm->workspace = vmalloc(zlib_inflate_workspacesize()); |
a2fbb9ea ET |
5509 | if (bp->strm->workspace == NULL) |
5510 | goto gunzip_nomem3; | |
5511 | ||
5512 | return 0; | |
5513 | ||
5514 | gunzip_nomem3: | |
5515 | kfree(bp->strm); | |
5516 | bp->strm = NULL; | |
5517 | ||
5518 | gunzip_nomem2: | |
1a983142 FT |
5519 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
5520 | bp->gunzip_mapping); | |
a2fbb9ea ET |
5521 | bp->gunzip_buf = NULL; |
5522 | ||
5523 | gunzip_nomem1: | |
51c1a580 | 5524 | BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n"); |
a2fbb9ea ET |
5525 | return -ENOMEM; |
5526 | } | |
5527 | ||
5528 | static void bnx2x_gunzip_end(struct bnx2x *bp) | |
5529 | { | |
b3b83c3f | 5530 | if (bp->strm) { |
7ab24bfd | 5531 | vfree(bp->strm->workspace); |
b3b83c3f DK |
5532 | kfree(bp->strm); |
5533 | bp->strm = NULL; | |
5534 | } | |
a2fbb9ea ET |
5535 | |
5536 | if (bp->gunzip_buf) { | |
1a983142 FT |
5537 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
5538 | bp->gunzip_mapping); | |
a2fbb9ea ET |
5539 | bp->gunzip_buf = NULL; |
5540 | } | |
5541 | } | |
5542 | ||
94a78b79 | 5543 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
a2fbb9ea ET |
5544 | { |
5545 | int n, rc; | |
5546 | ||
5547 | /* check gzip header */ | |
94a78b79 VZ |
5548 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
5549 | BNX2X_ERR("Bad gzip header\n"); | |
a2fbb9ea | 5550 | return -EINVAL; |
94a78b79 | 5551 | } |
a2fbb9ea ET |
5552 | |
5553 | n = 10; | |
5554 | ||
34f80b04 | 5555 | #define FNAME 0x8 |
a2fbb9ea ET |
5556 | |
5557 | if (zbuf[3] & FNAME) | |
5558 | while ((zbuf[n++] != 0) && (n < len)); | |
5559 | ||
94a78b79 | 5560 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
a2fbb9ea ET |
5561 | bp->strm->avail_in = len - n; |
5562 | bp->strm->next_out = bp->gunzip_buf; | |
5563 | bp->strm->avail_out = FW_BUF_SIZE; | |
5564 | ||
5565 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); | |
5566 | if (rc != Z_OK) | |
5567 | return rc; | |
5568 | ||
5569 | rc = zlib_inflate(bp->strm, Z_FINISH); | |
5570 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) | |
7995c64e JP |
5571 | netdev_err(bp->dev, "Firmware decompression error: %s\n", |
5572 | bp->strm->msg); | |
a2fbb9ea ET |
5573 | |
5574 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); | |
5575 | if (bp->gunzip_outlen & 0x3) | |
51c1a580 MS |
5576 | netdev_err(bp->dev, |
5577 | "Firmware decompression error: gunzip_outlen (%d) not aligned\n", | |
cdaa7cb8 | 5578 | bp->gunzip_outlen); |
a2fbb9ea ET |
5579 | bp->gunzip_outlen >>= 2; |
5580 | ||
5581 | zlib_inflateEnd(bp->strm); | |
5582 | ||
5583 | if (rc == Z_STREAM_END) | |
5584 | return 0; | |
5585 | ||
5586 | return rc; | |
5587 | } | |
5588 | ||
5589 | /* nic load/unload */ | |
5590 | ||
5591 | /* | |
34f80b04 | 5592 | * General service functions |
a2fbb9ea ET |
5593 | */ |
5594 | ||
5595 | /* send a NIG loopback debug packet */ | |
5596 | static void bnx2x_lb_pckt(struct bnx2x *bp) | |
5597 | { | |
a2fbb9ea | 5598 | u32 wb_write[3]; |
a2fbb9ea ET |
5599 | |
5600 | /* Ethernet source and destination addresses */ | |
a2fbb9ea ET |
5601 | wb_write[0] = 0x55555555; |
5602 | wb_write[1] = 0x55555555; | |
34f80b04 | 5603 | wb_write[2] = 0x20; /* SOP */ |
a2fbb9ea | 5604 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
5605 | |
5606 | /* NON-IP protocol */ | |
a2fbb9ea ET |
5607 | wb_write[0] = 0x09000000; |
5608 | wb_write[1] = 0x55555555; | |
34f80b04 | 5609 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
a2fbb9ea | 5610 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
a2fbb9ea ET |
5611 | } |
5612 | ||
5613 | /* some of the internal memories | |
5614 | * are not directly readable from the driver | |
5615 | * to test them we send debug packets | |
5616 | */ | |
5617 | static int bnx2x_int_mem_test(struct bnx2x *bp) | |
5618 | { | |
5619 | int factor; | |
5620 | int count, i; | |
5621 | u32 val = 0; | |
5622 | ||
ad8d3948 | 5623 | if (CHIP_REV_IS_FPGA(bp)) |
a2fbb9ea | 5624 | factor = 120; |
ad8d3948 EG |
5625 | else if (CHIP_REV_IS_EMUL(bp)) |
5626 | factor = 200; | |
5627 | else | |
a2fbb9ea | 5628 | factor = 1; |
a2fbb9ea | 5629 | |
a2fbb9ea ET |
5630 | /* Disable inputs of parser neighbor blocks */ |
5631 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
5632 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
5633 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 5634 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
5635 | |
5636 | /* Write 0 to parser credits for CFC search request */ | |
5637 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
5638 | ||
5639 | /* send Ethernet packet */ | |
5640 | bnx2x_lb_pckt(bp); | |
5641 | ||
5642 | /* TODO do i reset NIG statistic? */ | |
5643 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
5644 | count = 1000 * factor; | |
5645 | while (count) { | |
34f80b04 | 5646 | |
a2fbb9ea ET |
5647 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
5648 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
5649 | if (val == 0x10) |
5650 | break; | |
5651 | ||
5652 | msleep(10); | |
5653 | count--; | |
5654 | } | |
5655 | if (val != 0x10) { | |
5656 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
5657 | return -1; | |
5658 | } | |
5659 | ||
5660 | /* Wait until PRS register shows 1 packet */ | |
5661 | count = 1000 * factor; | |
5662 | while (count) { | |
5663 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
a2fbb9ea ET |
5664 | if (val == 1) |
5665 | break; | |
5666 | ||
5667 | msleep(10); | |
5668 | count--; | |
5669 | } | |
5670 | if (val != 0x1) { | |
5671 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
5672 | return -2; | |
5673 | } | |
5674 | ||
5675 | /* Reset and init BRB, PRS */ | |
34f80b04 | 5676 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
a2fbb9ea | 5677 | msleep(50); |
34f80b04 | 5678 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
a2fbb9ea | 5679 | msleep(50); |
619c5cb6 VZ |
5680 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
5681 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
a2fbb9ea ET |
5682 | |
5683 | DP(NETIF_MSG_HW, "part2\n"); | |
5684 | ||
5685 | /* Disable inputs of parser neighbor blocks */ | |
5686 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); | |
5687 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); | |
5688 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); | |
3196a88a | 5689 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
a2fbb9ea ET |
5690 | |
5691 | /* Write 0 to parser credits for CFC search request */ | |
5692 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); | |
5693 | ||
5694 | /* send 10 Ethernet packets */ | |
5695 | for (i = 0; i < 10; i++) | |
5696 | bnx2x_lb_pckt(bp); | |
5697 | ||
5698 | /* Wait until NIG register shows 10 + 1 | |
5699 | packets of size 11*0x10 = 0xb0 */ | |
5700 | count = 1000 * factor; | |
5701 | while (count) { | |
34f80b04 | 5702 | |
a2fbb9ea ET |
5703 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
5704 | val = *bnx2x_sp(bp, wb_data[0]); | |
a2fbb9ea ET |
5705 | if (val == 0xb0) |
5706 | break; | |
5707 | ||
5708 | msleep(10); | |
5709 | count--; | |
5710 | } | |
5711 | if (val != 0xb0) { | |
5712 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); | |
5713 | return -3; | |
5714 | } | |
5715 | ||
5716 | /* Wait until PRS register shows 2 packets */ | |
5717 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
5718 | if (val != 2) | |
5719 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
5720 | ||
5721 | /* Write 1 to parser credits for CFC search request */ | |
5722 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); | |
5723 | ||
5724 | /* Wait until PRS register shows 3 packets */ | |
5725 | msleep(10 * factor); | |
5726 | /* Wait until NIG register shows 1 packet of size 0x10 */ | |
5727 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); | |
5728 | if (val != 3) | |
5729 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); | |
5730 | ||
5731 | /* clear NIG EOP FIFO */ | |
5732 | for (i = 0; i < 11; i++) | |
5733 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); | |
5734 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); | |
5735 | if (val != 1) { | |
5736 | BNX2X_ERR("clear of NIG failed\n"); | |
5737 | return -4; | |
5738 | } | |
5739 | ||
5740 | /* Reset and init BRB, PRS, NIG */ | |
5741 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); | |
5742 | msleep(50); | |
5743 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); | |
5744 | msleep(50); | |
619c5cb6 VZ |
5745 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
5746 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); | |
37b091ba | 5747 | #ifndef BCM_CNIC |
a2fbb9ea ET |
5748 | /* set NIC mode */ |
5749 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
5750 | #endif | |
5751 | ||
5752 | /* Enable inputs of parser neighbor blocks */ | |
5753 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); | |
5754 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); | |
5755 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); | |
3196a88a | 5756 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
a2fbb9ea ET |
5757 | |
5758 | DP(NETIF_MSG_HW, "done\n"); | |
5759 | ||
5760 | return 0; /* OK */ | |
5761 | } | |
5762 | ||
4a33bc03 | 5763 | static void bnx2x_enable_blocks_attention(struct bnx2x *bp) |
a2fbb9ea ET |
5764 | { |
5765 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); | |
619c5cb6 | 5766 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
5767 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40); |
5768 | else | |
5769 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); | |
a2fbb9ea ET |
5770 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
5771 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
f2e0899f DK |
5772 | /* |
5773 | * mask read length error interrupts in brb for parser | |
5774 | * (parsing unit and 'checksum and crc' unit) | |
5775 | * these errors are legal (PU reads fixed length and CAC can cause | |
5776 | * read length error on truncated packets) | |
5777 | */ | |
5778 | REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00); | |
a2fbb9ea ET |
5779 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
5780 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); | |
5781 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); | |
5782 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); | |
5783 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); | |
34f80b04 EG |
5784 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
5785 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
5786 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
5787 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); | |
5788 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); | |
34f80b04 EG |
5789 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
5790 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ | |
a2fbb9ea ET |
5791 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
5792 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); | |
5793 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); | |
5794 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); | |
34f80b04 EG |
5795 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
5796 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ | |
f85582f8 | 5797 | |
34f80b04 EG |
5798 | if (CHIP_REV_IS_FPGA(bp)) |
5799 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); | |
619c5cb6 | 5800 | else if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
5801 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, |
5802 | (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF | |
5803 | | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT | |
5804 | | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN | |
5805 | | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED | |
5806 | | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED)); | |
34f80b04 EG |
5807 | else |
5808 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); | |
a2fbb9ea ET |
5809 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
5810 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); | |
5811 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); | |
34f80b04 | 5812 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
619c5cb6 VZ |
5813 | |
5814 | if (!CHIP_IS_E1x(bp)) | |
5815 | /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ | |
5816 | REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); | |
5817 | ||
a2fbb9ea ET |
5818 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
5819 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); | |
34f80b04 | 5820 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
4a33bc03 | 5821 | REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */ |
a2fbb9ea ET |
5822 | } |
5823 | ||
81f75bbf EG |
5824 | static void bnx2x_reset_common(struct bnx2x *bp) |
5825 | { | |
619c5cb6 VZ |
5826 | u32 val = 0x1400; |
5827 | ||
81f75bbf EG |
5828 | /* reset_common */ |
5829 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
5830 | 0xd3ffff7f); | |
619c5cb6 VZ |
5831 | |
5832 | if (CHIP_IS_E3(bp)) { | |
5833 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
5834 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
5835 | } | |
5836 | ||
5837 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val); | |
5838 | } | |
5839 | ||
5840 | static void bnx2x_setup_dmae(struct bnx2x *bp) | |
5841 | { | |
5842 | bp->dmae_ready = 0; | |
5843 | spin_lock_init(&bp->dmae_lock); | |
81f75bbf EG |
5844 | } |
5845 | ||
573f2035 EG |
5846 | static void bnx2x_init_pxp(struct bnx2x *bp) |
5847 | { | |
5848 | u16 devctl; | |
5849 | int r_order, w_order; | |
5850 | ||
5851 | pci_read_config_word(bp->pdev, | |
b6c2f86e | 5852 | pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl); |
573f2035 EG |
5853 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
5854 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); | |
5855 | if (bp->mrrs == -1) | |
5856 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); | |
5857 | else { | |
5858 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); | |
5859 | r_order = bp->mrrs; | |
5860 | } | |
5861 | ||
5862 | bnx2x_init_pxp_arb(bp, r_order, w_order); | |
5863 | } | |
fd4ef40d EG |
5864 | |
5865 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) | |
5866 | { | |
2145a920 | 5867 | int is_required; |
fd4ef40d | 5868 | u32 val; |
2145a920 | 5869 | int port; |
fd4ef40d | 5870 | |
2145a920 VZ |
5871 | if (BP_NOMCP(bp)) |
5872 | return; | |
5873 | ||
5874 | is_required = 0; | |
fd4ef40d EG |
5875 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
5876 | SHARED_HW_CFG_FAN_FAILURE_MASK; | |
5877 | ||
5878 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) | |
5879 | is_required = 1; | |
5880 | ||
5881 | /* | |
5882 | * The fan failure mechanism is usually related to the PHY type since | |
5883 | * the power consumption of the board is affected by the PHY. Currently, | |
5884 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. | |
5885 | */ | |
5886 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) | |
5887 | for (port = PORT_0; port < PORT_MAX; port++) { | |
fd4ef40d | 5888 | is_required |= |
d90d96ba YR |
5889 | bnx2x_fan_failure_det_req( |
5890 | bp, | |
5891 | bp->common.shmem_base, | |
a22f0788 | 5892 | bp->common.shmem2_base, |
d90d96ba | 5893 | port); |
fd4ef40d EG |
5894 | } |
5895 | ||
5896 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); | |
5897 | ||
5898 | if (is_required == 0) | |
5899 | return; | |
5900 | ||
5901 | /* Fan failure is indicated by SPIO 5 */ | |
5902 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, | |
5903 | MISC_REGISTERS_SPIO_INPUT_HI_Z); | |
5904 | ||
5905 | /* set to active low mode */ | |
5906 | val = REG_RD(bp, MISC_REG_SPIO_INT); | |
5907 | val |= ((1 << MISC_REGISTERS_SPIO_5) << | |
cdaa7cb8 | 5908 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
fd4ef40d EG |
5909 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
5910 | ||
5911 | /* enable interrupt to signal the IGU */ | |
5912 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
5913 | val |= (1 << MISC_REGISTERS_SPIO_5); | |
5914 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); | |
5915 | } | |
5916 | ||
f2e0899f DK |
5917 | static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num) |
5918 | { | |
5919 | u32 offset = 0; | |
5920 | ||
5921 | if (CHIP_IS_E1(bp)) | |
5922 | return; | |
5923 | if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX)) | |
5924 | return; | |
5925 | ||
5926 | switch (BP_ABS_FUNC(bp)) { | |
5927 | case 0: | |
5928 | offset = PXP2_REG_PGL_PRETEND_FUNC_F0; | |
5929 | break; | |
5930 | case 1: | |
5931 | offset = PXP2_REG_PGL_PRETEND_FUNC_F1; | |
5932 | break; | |
5933 | case 2: | |
5934 | offset = PXP2_REG_PGL_PRETEND_FUNC_F2; | |
5935 | break; | |
5936 | case 3: | |
5937 | offset = PXP2_REG_PGL_PRETEND_FUNC_F3; | |
5938 | break; | |
5939 | case 4: | |
5940 | offset = PXP2_REG_PGL_PRETEND_FUNC_F4; | |
5941 | break; | |
5942 | case 5: | |
5943 | offset = PXP2_REG_PGL_PRETEND_FUNC_F5; | |
5944 | break; | |
5945 | case 6: | |
5946 | offset = PXP2_REG_PGL_PRETEND_FUNC_F6; | |
5947 | break; | |
5948 | case 7: | |
5949 | offset = PXP2_REG_PGL_PRETEND_FUNC_F7; | |
5950 | break; | |
5951 | default: | |
5952 | return; | |
5953 | } | |
5954 | ||
5955 | REG_WR(bp, offset, pretend_func_num); | |
5956 | REG_RD(bp, offset); | |
5957 | DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num); | |
5958 | } | |
5959 | ||
c9ee9206 | 5960 | void bnx2x_pf_disable(struct bnx2x *bp) |
f2e0899f DK |
5961 | { |
5962 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); | |
5963 | val &= ~IGU_PF_CONF_FUNC_EN; | |
5964 | ||
5965 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); | |
5966 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
5967 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0); | |
5968 | } | |
5969 | ||
619c5cb6 VZ |
5970 | static inline void bnx2x__common_init_phy(struct bnx2x *bp) |
5971 | { | |
5972 | u32 shmem_base[2], shmem2_base[2]; | |
5973 | shmem_base[0] = bp->common.shmem_base; | |
5974 | shmem2_base[0] = bp->common.shmem2_base; | |
5975 | if (!CHIP_IS_E1x(bp)) { | |
5976 | shmem_base[1] = | |
5977 | SHMEM2_RD(bp, other_shmem_base_addr); | |
5978 | shmem2_base[1] = | |
5979 | SHMEM2_RD(bp, other_shmem2_base_addr); | |
5980 | } | |
5981 | bnx2x_acquire_phy_lock(bp); | |
5982 | bnx2x_common_init_phy(bp, shmem_base, shmem2_base, | |
5983 | bp->common.chip_id); | |
5984 | bnx2x_release_phy_lock(bp); | |
5985 | } | |
5986 | ||
5987 | /** | |
5988 | * bnx2x_init_hw_common - initialize the HW at the COMMON phase. | |
5989 | * | |
5990 | * @bp: driver handle | |
5991 | */ | |
5992 | static int bnx2x_init_hw_common(struct bnx2x *bp) | |
a2fbb9ea | 5993 | { |
619c5cb6 | 5994 | u32 val; |
a2fbb9ea | 5995 | |
51c1a580 | 5996 | DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp)); |
a2fbb9ea | 5997 | |
2031bd3a DK |
5998 | /* |
5999 | * take the UNDI lock to protect undi_unload flow from accessing | |
6000 | * registers while we're resetting the chip | |
6001 | */ | |
7a06a122 | 6002 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6003 | |
81f75bbf | 6004 | bnx2x_reset_common(bp); |
34f80b04 | 6005 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
a2fbb9ea | 6006 | |
619c5cb6 VZ |
6007 | val = 0xfffc; |
6008 | if (CHIP_IS_E3(bp)) { | |
6009 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; | |
6010 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; | |
6011 | } | |
6012 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val); | |
6013 | ||
7a06a122 | 6014 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
2031bd3a | 6015 | |
619c5cb6 | 6016 | bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON); |
a2fbb9ea | 6017 | |
619c5cb6 VZ |
6018 | if (!CHIP_IS_E1x(bp)) { |
6019 | u8 abs_func_id; | |
f2e0899f DK |
6020 | |
6021 | /** | |
6022 | * 4-port mode or 2-port mode we need to turn of master-enable | |
6023 | * for everyone, after that, turn it back on for self. | |
6024 | * so, we disregard multi-function or not, and always disable | |
6025 | * for all functions on the given path, this means 0,2,4,6 for | |
6026 | * path 0 and 1,3,5,7 for path 1 | |
6027 | */ | |
619c5cb6 VZ |
6028 | for (abs_func_id = BP_PATH(bp); |
6029 | abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) { | |
6030 | if (abs_func_id == BP_ABS_FUNC(bp)) { | |
f2e0899f DK |
6031 | REG_WR(bp, |
6032 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, | |
6033 | 1); | |
6034 | continue; | |
6035 | } | |
6036 | ||
619c5cb6 | 6037 | bnx2x_pretend_func(bp, abs_func_id); |
f2e0899f DK |
6038 | /* clear pf enable */ |
6039 | bnx2x_pf_disable(bp); | |
6040 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6041 | } | |
6042 | } | |
a2fbb9ea | 6043 | |
619c5cb6 | 6044 | bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON); |
34f80b04 EG |
6045 | if (CHIP_IS_E1(bp)) { |
6046 | /* enable HW interrupt from PXP on USDM overflow | |
6047 | bit 16 on INT_MASK_0 */ | |
6048 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); | |
6049 | } | |
a2fbb9ea | 6050 | |
619c5cb6 | 6051 | bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON); |
34f80b04 | 6052 | bnx2x_init_pxp(bp); |
a2fbb9ea ET |
6053 | |
6054 | #ifdef __BIG_ENDIAN | |
34f80b04 EG |
6055 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
6056 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); | |
6057 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); | |
6058 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); | |
6059 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); | |
8badd27a EG |
6060 | /* make sure this value is 0 */ |
6061 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); | |
34f80b04 EG |
6062 | |
6063 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ | |
6064 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); | |
6065 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); | |
6066 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); | |
6067 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); | |
a2fbb9ea ET |
6068 | #endif |
6069 | ||
523224a3 DK |
6070 | bnx2x_ilt_init_page_size(bp, INITOP_SET); |
6071 | ||
34f80b04 EG |
6072 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
6073 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); | |
a2fbb9ea | 6074 | |
34f80b04 EG |
6075 | /* let the HW do it's magic ... */ |
6076 | msleep(100); | |
6077 | /* finish PXP init */ | |
6078 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); | |
6079 | if (val != 1) { | |
6080 | BNX2X_ERR("PXP2 CFG failed\n"); | |
6081 | return -EBUSY; | |
6082 | } | |
6083 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); | |
6084 | if (val != 1) { | |
6085 | BNX2X_ERR("PXP2 RD_INIT failed\n"); | |
6086 | return -EBUSY; | |
6087 | } | |
a2fbb9ea | 6088 | |
f2e0899f DK |
6089 | /* Timers bug workaround E2 only. We need to set the entire ILT to |
6090 | * have entries with value "0" and valid bit on. | |
6091 | * This needs to be done by the first PF that is loaded in a path | |
6092 | * (i.e. common phase) | |
6093 | */ | |
619c5cb6 VZ |
6094 | if (!CHIP_IS_E1x(bp)) { |
6095 | /* In E2 there is a bug in the timers block that can cause function 6 / 7 | |
6096 | * (i.e. vnic3) to start even if it is marked as "scan-off". | |
6097 | * This occurs when a different function (func2,3) is being marked | |
6098 | * as "scan-off". Real-life scenario for example: if a driver is being | |
6099 | * load-unloaded while func6,7 are down. This will cause the timer to access | |
6100 | * the ilt, translate to a logical address and send a request to read/write. | |
6101 | * Since the ilt for the function that is down is not valid, this will cause | |
6102 | * a translation error which is unrecoverable. | |
6103 | * The Workaround is intended to make sure that when this happens nothing fatal | |
6104 | * will occur. The workaround: | |
6105 | * 1. First PF driver which loads on a path will: | |
6106 | * a. After taking the chip out of reset, by using pretend, | |
6107 | * it will write "0" to the following registers of | |
6108 | * the other vnics. | |
6109 | * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); | |
6110 | * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); | |
6111 | * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); | |
6112 | * And for itself it will write '1' to | |
6113 | * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable | |
6114 | * dmae-operations (writing to pram for example.) | |
6115 | * note: can be done for only function 6,7 but cleaner this | |
6116 | * way. | |
6117 | * b. Write zero+valid to the entire ILT. | |
6118 | * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of | |
6119 | * VNIC3 (of that port). The range allocated will be the | |
6120 | * entire ILT. This is needed to prevent ILT range error. | |
6121 | * 2. Any PF driver load flow: | |
6122 | * a. ILT update with the physical addresses of the allocated | |
6123 | * logical pages. | |
6124 | * b. Wait 20msec. - note that this timeout is needed to make | |
6125 | * sure there are no requests in one of the PXP internal | |
6126 | * queues with "old" ILT addresses. | |
6127 | * c. PF enable in the PGLC. | |
6128 | * d. Clear the was_error of the PF in the PGLC. (could have | |
6129 | * occured while driver was down) | |
6130 | * e. PF enable in the CFC (WEAK + STRONG) | |
6131 | * f. Timers scan enable | |
6132 | * 3. PF driver unload flow: | |
6133 | * a. Clear the Timers scan_en. | |
6134 | * b. Polling for scan_on=0 for that PF. | |
6135 | * c. Clear the PF enable bit in the PXP. | |
6136 | * d. Clear the PF enable in the CFC (WEAK + STRONG) | |
6137 | * e. Write zero+valid to all ILT entries (The valid bit must | |
6138 | * stay set) | |
6139 | * f. If this is VNIC 3 of a port then also init | |
6140 | * first_timers_ilt_entry to zero and last_timers_ilt_entry | |
6141 | * to the last enrty in the ILT. | |
6142 | * | |
6143 | * Notes: | |
6144 | * Currently the PF error in the PGLC is non recoverable. | |
6145 | * In the future the there will be a recovery routine for this error. | |
6146 | * Currently attention is masked. | |
6147 | * Having an MCP lock on the load/unload process does not guarantee that | |
6148 | * there is no Timer disable during Func6/7 enable. This is because the | |
6149 | * Timers scan is currently being cleared by the MCP on FLR. | |
6150 | * Step 2.d can be done only for PF6/7 and the driver can also check if | |
6151 | * there is error before clearing it. But the flow above is simpler and | |
6152 | * more general. | |
6153 | * All ILT entries are written by zero+valid and not just PF6/7 | |
6154 | * ILT entries since in the future the ILT entries allocation for | |
6155 | * PF-s might be dynamic. | |
6156 | */ | |
f2e0899f DK |
6157 | struct ilt_client_info ilt_cli; |
6158 | struct bnx2x_ilt ilt; | |
6159 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
6160 | memset(&ilt, 0, sizeof(struct bnx2x_ilt)); | |
6161 | ||
b595076a | 6162 | /* initialize dummy TM client */ |
f2e0899f DK |
6163 | ilt_cli.start = 0; |
6164 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
6165 | ilt_cli.client_num = ILT_CLIENT_TM; | |
6166 | ||
6167 | /* Step 1: set zeroes to all ilt page entries with valid bit on | |
6168 | * Step 2: set the timers first/last ilt entry to point | |
6169 | * to the entire range to prevent ILT range error for 3rd/4th | |
619c5cb6 | 6170 | * vnic (this code assumes existance of the vnic) |
f2e0899f DK |
6171 | * |
6172 | * both steps performed by call to bnx2x_ilt_client_init_op() | |
6173 | * with dummy TM client | |
6174 | * | |
6175 | * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT | |
6176 | * and his brother are split registers | |
6177 | */ | |
6178 | bnx2x_pretend_func(bp, (BP_PATH(bp) + 6)); | |
6179 | bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR); | |
6180 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); | |
6181 | ||
6182 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN); | |
6183 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN); | |
6184 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); | |
6185 | } | |
6186 | ||
6187 | ||
34f80b04 EG |
6188 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
6189 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); | |
a2fbb9ea | 6190 | |
619c5cb6 | 6191 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6192 | int factor = CHIP_REV_IS_EMUL(bp) ? 1000 : |
6193 | (CHIP_REV_IS_FPGA(bp) ? 400 : 0); | |
619c5cb6 | 6194 | bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON); |
f2e0899f | 6195 | |
619c5cb6 | 6196 | bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON); |
f2e0899f DK |
6197 | |
6198 | /* let the HW do it's magic ... */ | |
6199 | do { | |
6200 | msleep(200); | |
6201 | val = REG_RD(bp, ATC_REG_ATC_INIT_DONE); | |
6202 | } while (factor-- && (val != 1)); | |
6203 | ||
6204 | if (val != 1) { | |
6205 | BNX2X_ERR("ATC_INIT failed\n"); | |
6206 | return -EBUSY; | |
6207 | } | |
6208 | } | |
6209 | ||
619c5cb6 | 6210 | bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON); |
a2fbb9ea | 6211 | |
34f80b04 EG |
6212 | /* clean the DMAE memory */ |
6213 | bp->dmae_ready = 1; | |
619c5cb6 VZ |
6214 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1); |
6215 | ||
6216 | bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON); | |
6217 | ||
6218 | bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON); | |
6219 | ||
6220 | bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON); | |
a2fbb9ea | 6221 | |
619c5cb6 | 6222 | bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON); |
a2fbb9ea | 6223 | |
34f80b04 EG |
6224 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
6225 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); | |
6226 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); | |
6227 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); | |
6228 | ||
619c5cb6 | 6229 | bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON); |
37b091ba | 6230 | |
f85582f8 | 6231 | |
523224a3 DK |
6232 | /* QM queues pointers table */ |
6233 | bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET); | |
6234 | ||
34f80b04 EG |
6235 | /* soft reset pulse */ |
6236 | REG_WR(bp, QM_REG_SOFT_RESET, 1); | |
6237 | REG_WR(bp, QM_REG_SOFT_RESET, 0); | |
a2fbb9ea | 6238 | |
37b091ba | 6239 | #ifdef BCM_CNIC |
619c5cb6 | 6240 | bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON); |
a2fbb9ea | 6241 | #endif |
a2fbb9ea | 6242 | |
619c5cb6 | 6243 | bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON); |
523224a3 | 6244 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT); |
619c5cb6 | 6245 | if (!CHIP_REV_IS_SLOW(bp)) |
34f80b04 EG |
6246 | /* enable hw interrupt from doorbell Q */ |
6247 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); | |
a2fbb9ea | 6248 | |
619c5cb6 | 6249 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
f2e0899f | 6250 | |
619c5cb6 | 6251 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
26c8fa4d | 6252 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
619c5cb6 | 6253 | |
f2e0899f | 6254 | if (!CHIP_IS_E1(bp)) |
619c5cb6 | 6255 | REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan); |
f85582f8 | 6256 | |
619c5cb6 VZ |
6257 | if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) |
6258 | /* Bit-map indicating which L2 hdrs may appear | |
6259 | * after the basic Ethernet header | |
6260 | */ | |
6261 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, | |
6262 | bp->path_has_ovlan ? 7 : 6); | |
a2fbb9ea | 6263 | |
619c5cb6 VZ |
6264 | bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON); |
6265 | bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON); | |
6266 | bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON); | |
6267 | bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON); | |
a2fbb9ea | 6268 | |
619c5cb6 VZ |
6269 | if (!CHIP_IS_E1x(bp)) { |
6270 | /* reset VFC memories */ | |
6271 | REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6272 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6273 | VFC_MEMORIES_RST_REG_RAM_RST); | |
6274 | REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, | |
6275 | VFC_MEMORIES_RST_REG_CAM_RST | | |
6276 | VFC_MEMORIES_RST_REG_RAM_RST); | |
a2fbb9ea | 6277 | |
619c5cb6 VZ |
6278 | msleep(20); |
6279 | } | |
a2fbb9ea | 6280 | |
619c5cb6 VZ |
6281 | bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON); |
6282 | bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON); | |
6283 | bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON); | |
6284 | bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON); | |
f2e0899f | 6285 | |
34f80b04 EG |
6286 | /* sync semi rtc */ |
6287 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, | |
6288 | 0x80000000); | |
6289 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, | |
6290 | 0x80000000); | |
a2fbb9ea | 6291 | |
619c5cb6 VZ |
6292 | bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON); |
6293 | bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON); | |
6294 | bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON); | |
a2fbb9ea | 6295 | |
619c5cb6 VZ |
6296 | if (!CHIP_IS_E1x(bp)) |
6297 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, | |
6298 | bp->path_has_ovlan ? 7 : 6); | |
f2e0899f | 6299 | |
34f80b04 | 6300 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
f85582f8 | 6301 | |
619c5cb6 VZ |
6302 | bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON); |
6303 | ||
37b091ba MC |
6304 | #ifdef BCM_CNIC |
6305 | REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672); | |
6306 | REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); | |
6307 | REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b); | |
6308 | REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a); | |
6309 | REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116); | |
6310 | REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b); | |
6311 | REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf); | |
6312 | REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); | |
6313 | REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f); | |
6314 | REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7); | |
6315 | #endif | |
34f80b04 | 6316 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
a2fbb9ea | 6317 | |
34f80b04 EG |
6318 | if (sizeof(union cdu_context) != 1024) |
6319 | /* we currently assume that a context is 1024 bytes */ | |
51c1a580 MS |
6320 | dev_alert(&bp->pdev->dev, |
6321 | "please adjust the size of cdu_context(%ld)\n", | |
6322 | (long)sizeof(union cdu_context)); | |
a2fbb9ea | 6323 | |
619c5cb6 | 6324 | bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON); |
34f80b04 EG |
6325 | val = (4 << 24) + (0 << 12) + 1024; |
6326 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); | |
a2fbb9ea | 6327 | |
619c5cb6 | 6328 | bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON); |
34f80b04 | 6329 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
8d9c5f34 EG |
6330 | /* enable context validation interrupt from CFC */ |
6331 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); | |
6332 | ||
6333 | /* set the thresholds to prevent CFC/CDU race */ | |
6334 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); | |
a2fbb9ea | 6335 | |
619c5cb6 | 6336 | bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON); |
f2e0899f | 6337 | |
619c5cb6 | 6338 | if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp)) |
f2e0899f DK |
6339 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36); |
6340 | ||
619c5cb6 VZ |
6341 | bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON); |
6342 | bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON); | |
a2fbb9ea | 6343 | |
34f80b04 EG |
6344 | /* Reset PCIE errors for debug */ |
6345 | REG_WR(bp, 0x2814, 0xffffffff); | |
6346 | REG_WR(bp, 0x3820, 0xffffffff); | |
a2fbb9ea | 6347 | |
619c5cb6 | 6348 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6349 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, |
6350 | (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | | |
6351 | PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); | |
6352 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, | |
6353 | (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | | |
6354 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | | |
6355 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); | |
6356 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, | |
6357 | (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | | |
6358 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | | |
6359 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); | |
6360 | } | |
6361 | ||
619c5cb6 | 6362 | bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON); |
f2e0899f | 6363 | if (!CHIP_IS_E1(bp)) { |
619c5cb6 VZ |
6364 | /* in E3 this done in per-port section */ |
6365 | if (!CHIP_IS_E3(bp)) | |
6366 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
f2e0899f | 6367 | } |
619c5cb6 VZ |
6368 | if (CHIP_IS_E1H(bp)) |
6369 | /* not applicable for E2 (and above ...) */ | |
6370 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp)); | |
34f80b04 EG |
6371 | |
6372 | if (CHIP_REV_IS_SLOW(bp)) | |
6373 | msleep(200); | |
6374 | ||
6375 | /* finish CFC init */ | |
6376 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); | |
6377 | if (val != 1) { | |
6378 | BNX2X_ERR("CFC LL_INIT failed\n"); | |
6379 | return -EBUSY; | |
6380 | } | |
6381 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); | |
6382 | if (val != 1) { | |
6383 | BNX2X_ERR("CFC AC_INIT failed\n"); | |
6384 | return -EBUSY; | |
6385 | } | |
6386 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); | |
6387 | if (val != 1) { | |
6388 | BNX2X_ERR("CFC CAM_INIT failed\n"); | |
6389 | return -EBUSY; | |
6390 | } | |
6391 | REG_WR(bp, CFC_REG_DEBUG0, 0); | |
f1410647 | 6392 | |
f2e0899f DK |
6393 | if (CHIP_IS_E1(bp)) { |
6394 | /* read NIG statistic | |
6395 | to see if this is our first up since powerup */ | |
6396 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); | |
6397 | val = *bnx2x_sp(bp, wb_data[0]); | |
34f80b04 | 6398 | |
f2e0899f DK |
6399 | /* do internal memory self test */ |
6400 | if ((val == 0) && bnx2x_int_mem_test(bp)) { | |
6401 | BNX2X_ERR("internal mem self test failed\n"); | |
6402 | return -EBUSY; | |
6403 | } | |
34f80b04 EG |
6404 | } |
6405 | ||
fd4ef40d EG |
6406 | bnx2x_setup_fan_failure_detection(bp); |
6407 | ||
34f80b04 EG |
6408 | /* clear PXP2 attentions */ |
6409 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); | |
a2fbb9ea | 6410 | |
4a33bc03 | 6411 | bnx2x_enable_blocks_attention(bp); |
c9ee9206 | 6412 | bnx2x_enable_blocks_parity(bp); |
a2fbb9ea | 6413 | |
6bbca910 | 6414 | if (!BP_NOMCP(bp)) { |
619c5cb6 VZ |
6415 | if (CHIP_IS_E1x(bp)) |
6416 | bnx2x__common_init_phy(bp); | |
6bbca910 YR |
6417 | } else |
6418 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); | |
6419 | ||
34f80b04 EG |
6420 | return 0; |
6421 | } | |
a2fbb9ea | 6422 | |
619c5cb6 VZ |
6423 | /** |
6424 | * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase. | |
6425 | * | |
6426 | * @bp: driver handle | |
6427 | */ | |
6428 | static int bnx2x_init_hw_common_chip(struct bnx2x *bp) | |
6429 | { | |
6430 | int rc = bnx2x_init_hw_common(bp); | |
6431 | ||
6432 | if (rc) | |
6433 | return rc; | |
6434 | ||
6435 | /* In E2 2-PORT mode, same ext phy is used for the two paths */ | |
6436 | if (!BP_NOMCP(bp)) | |
6437 | bnx2x__common_init_phy(bp); | |
6438 | ||
6439 | return 0; | |
6440 | } | |
6441 | ||
523224a3 | 6442 | static int bnx2x_init_hw_port(struct bnx2x *bp) |
34f80b04 EG |
6443 | { |
6444 | int port = BP_PORT(bp); | |
619c5cb6 | 6445 | int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; |
1c06328c | 6446 | u32 low, high; |
34f80b04 | 6447 | u32 val; |
a2fbb9ea | 6448 | |
619c5cb6 VZ |
6449 | bnx2x__link_reset(bp); |
6450 | ||
51c1a580 | 6451 | DP(NETIF_MSG_HW, "starting port init port %d\n", port); |
34f80b04 EG |
6452 | |
6453 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); | |
a2fbb9ea | 6454 | |
619c5cb6 VZ |
6455 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
6456 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); | |
6457 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
ca00392c | 6458 | |
f2e0899f DK |
6459 | /* Timers bug workaround: disables the pf_master bit in pglue at |
6460 | * common phase, we need to enable it here before any dmae access are | |
6461 | * attempted. Therefore we manually added the enable-master to the | |
6462 | * port phase (it also happens in the function phase) | |
6463 | */ | |
619c5cb6 | 6464 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6465 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
6466 | ||
619c5cb6 VZ |
6467 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
6468 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
6469 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); | |
6470 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
6471 | ||
6472 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
6473 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
6474 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
6475 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
a2fbb9ea | 6476 | |
523224a3 DK |
6477 | /* QM cid (connection) count */ |
6478 | bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET); | |
a2fbb9ea | 6479 | |
523224a3 | 6480 | #ifdef BCM_CNIC |
619c5cb6 | 6481 | bnx2x_init_block(bp, BLOCK_TM, init_phase); |
37b091ba MC |
6482 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20); |
6483 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); | |
a2fbb9ea | 6484 | #endif |
cdaa7cb8 | 6485 | |
619c5cb6 | 6486 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
f2e0899f DK |
6487 | |
6488 | if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) { | |
619c5cb6 VZ |
6489 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
6490 | ||
6491 | if (IS_MF(bp)) | |
6492 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); | |
6493 | else if (bp->dev->mtu > 4096) { | |
6494 | if (bp->flags & ONE_PORT_FLAG) | |
6495 | low = 160; | |
6496 | else { | |
6497 | val = bp->dev->mtu; | |
6498 | /* (24*1024 + val*4)/256 */ | |
6499 | low = 96 + (val/64) + | |
6500 | ((val % 64) ? 1 : 0); | |
6501 | } | |
6502 | } else | |
6503 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); | |
6504 | high = low + 56; /* 14*1024/256 */ | |
f2e0899f DK |
6505 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
6506 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); | |
1c06328c | 6507 | } |
1c06328c | 6508 | |
619c5cb6 VZ |
6509 | if (CHIP_MODE_IS_4_PORT(bp)) |
6510 | REG_WR(bp, (BP_PORT(bp) ? | |
6511 | BRB1_REG_MAC_GUARANTIED_1 : | |
6512 | BRB1_REG_MAC_GUARANTIED_0), 40); | |
1c06328c | 6513 | |
ca00392c | 6514 | |
619c5cb6 VZ |
6515 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
6516 | if (CHIP_IS_E3B0(bp)) | |
6517 | /* Ovlan exists only if we are in multi-function + | |
6518 | * switch-dependent mode, in switch-independent there | |
6519 | * is no ovlan headers | |
6520 | */ | |
6521 | REG_WR(bp, BP_PORT(bp) ? | |
6522 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : | |
6523 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, | |
6524 | (bp->path_has_ovlan ? 7 : 6)); | |
356e2385 | 6525 | |
619c5cb6 VZ |
6526 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
6527 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
6528 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
6529 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
356e2385 | 6530 | |
619c5cb6 VZ |
6531 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
6532 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
6533 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
6534 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
34f80b04 | 6535 | |
619c5cb6 VZ |
6536 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
6537 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
a2fbb9ea | 6538 | |
619c5cb6 VZ |
6539 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
6540 | ||
6541 | if (CHIP_IS_E1x(bp)) { | |
f2e0899f DK |
6542 | /* configure PBF to work without PAUSE mtu 9000 */ |
6543 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); | |
a2fbb9ea | 6544 | |
f2e0899f DK |
6545 | /* update threshold */ |
6546 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); | |
6547 | /* update init credit */ | |
6548 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); | |
a2fbb9ea | 6549 | |
f2e0899f DK |
6550 | /* probe changes */ |
6551 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); | |
6552 | udelay(50); | |
6553 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); | |
6554 | } | |
a2fbb9ea | 6555 | |
37b091ba | 6556 | #ifdef BCM_CNIC |
619c5cb6 | 6557 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); |
a2fbb9ea | 6558 | #endif |
619c5cb6 VZ |
6559 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
6560 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); | |
34f80b04 EG |
6561 | |
6562 | if (CHIP_IS_E1(bp)) { | |
6563 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
6564 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
6565 | } | |
619c5cb6 | 6566 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
34f80b04 | 6567 | |
619c5cb6 | 6568 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 6569 | |
619c5cb6 | 6570 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
34f80b04 EG |
6571 | /* init aeu_mask_attn_func_0/1: |
6572 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use | |
6573 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF | |
6574 | * bits 4-7 are used for "per vn group attention" */ | |
e4901dde VZ |
6575 | val = IS_MF(bp) ? 0xF7 : 0x7; |
6576 | /* Enable DCBX attention for all but E1 */ | |
6577 | val |= CHIP_IS_E1(bp) ? 0 : 0x10; | |
6578 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); | |
34f80b04 | 6579 | |
619c5cb6 VZ |
6580 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
6581 | ||
6582 | if (!CHIP_IS_E1x(bp)) { | |
6583 | /* Bit-map indicating which L2 hdrs may appear after the | |
6584 | * basic Ethernet header | |
6585 | */ | |
6586 | REG_WR(bp, BP_PORT(bp) ? | |
6587 | NIG_REG_P1_HDRS_AFTER_BASIC : | |
6588 | NIG_REG_P0_HDRS_AFTER_BASIC, | |
6589 | IS_MF_SD(bp) ? 7 : 6); | |
6590 | ||
6591 | if (CHIP_IS_E3(bp)) | |
6592 | REG_WR(bp, BP_PORT(bp) ? | |
6593 | NIG_REG_LLH1_MF_MODE : | |
6594 | NIG_REG_LLH_MF_MODE, IS_MF(bp)); | |
6595 | } | |
6596 | if (!CHIP_IS_E3(bp)) | |
6597 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); | |
34f80b04 | 6598 | |
f2e0899f | 6599 | if (!CHIP_IS_E1(bp)) { |
fb3bff17 | 6600 | /* 0x2 disable mf_ov, 0x1 enable */ |
34f80b04 | 6601 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
0793f83f | 6602 | (IS_MF_SD(bp) ? 0x1 : 0x2)); |
34f80b04 | 6603 | |
619c5cb6 | 6604 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6605 | val = 0; |
6606 | switch (bp->mf_mode) { | |
6607 | case MULTI_FUNCTION_SD: | |
6608 | val = 1; | |
6609 | break; | |
6610 | case MULTI_FUNCTION_SI: | |
6611 | val = 2; | |
6612 | break; | |
6613 | } | |
6614 | ||
6615 | REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE : | |
6616 | NIG_REG_LLH0_CLS_TYPE), val); | |
6617 | } | |
1c06328c EG |
6618 | { |
6619 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); | |
6620 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); | |
6621 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); | |
6622 | } | |
34f80b04 EG |
6623 | } |
6624 | ||
619c5cb6 VZ |
6625 | |
6626 | /* If SPIO5 is set to generate interrupts, enable it for this port */ | |
6627 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); | |
6628 | if (val & (1 << MISC_REGISTERS_SPIO_5)) { | |
4d295db0 EG |
6629 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
6630 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); | |
6631 | val = REG_RD(bp, reg_addr); | |
f1410647 | 6632 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
4d295db0 | 6633 | REG_WR(bp, reg_addr, val); |
f1410647 | 6634 | } |
a2fbb9ea | 6635 | |
34f80b04 EG |
6636 | return 0; |
6637 | } | |
6638 | ||
34f80b04 EG |
6639 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
6640 | { | |
6641 | int reg; | |
6642 | ||
f2e0899f | 6643 | if (CHIP_IS_E1(bp)) |
34f80b04 | 6644 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
f2e0899f DK |
6645 | else |
6646 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; | |
34f80b04 EG |
6647 | |
6648 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); | |
6649 | } | |
6650 | ||
f2e0899f DK |
6651 | static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id) |
6652 | { | |
619c5cb6 | 6653 | bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/); |
f2e0899f DK |
6654 | } |
6655 | ||
6656 | static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func) | |
6657 | { | |
6658 | u32 i, base = FUNC_ILT_BASE(func); | |
6659 | for (i = base; i < base + ILT_PER_FUNC; i++) | |
6660 | bnx2x_ilt_wr(bp, i, 0); | |
6661 | } | |
6662 | ||
523224a3 | 6663 | static int bnx2x_init_hw_func(struct bnx2x *bp) |
34f80b04 EG |
6664 | { |
6665 | int port = BP_PORT(bp); | |
6666 | int func = BP_FUNC(bp); | |
619c5cb6 | 6667 | int init_phase = PHASE_PF0 + func; |
523224a3 DK |
6668 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
6669 | u16 cdu_ilt_start; | |
8badd27a | 6670 | u32 addr, val; |
f4a66897 | 6671 | u32 main_mem_base, main_mem_size, main_mem_prty_clr; |
89db4ad8 | 6672 | int i, main_mem_width, rc; |
34f80b04 | 6673 | |
51c1a580 | 6674 | DP(NETIF_MSG_HW, "starting func init func %d\n", func); |
34f80b04 | 6675 | |
619c5cb6 | 6676 | /* FLR cleanup - hmmm */ |
89db4ad8 AE |
6677 | if (!CHIP_IS_E1x(bp)) { |
6678 | rc = bnx2x_pf_flr_clnup(bp); | |
6679 | if (rc) | |
6680 | return rc; | |
6681 | } | |
619c5cb6 | 6682 | |
8badd27a | 6683 | /* set MSI reconfigure capability */ |
f2e0899f DK |
6684 | if (bp->common.int_block == INT_BLOCK_HC) { |
6685 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); | |
6686 | val = REG_RD(bp, addr); | |
6687 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; | |
6688 | REG_WR(bp, addr, val); | |
6689 | } | |
8badd27a | 6690 | |
619c5cb6 VZ |
6691 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
6692 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); | |
6693 | ||
523224a3 DK |
6694 | ilt = BP_ILT(bp); |
6695 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; | |
37b091ba | 6696 | |
523224a3 DK |
6697 | for (i = 0; i < L2_ILT_LINES(bp); i++) { |
6698 | ilt->lines[cdu_ilt_start + i].page = | |
6699 | bp->context.vcxt + (ILT_PAGE_CIDS * i); | |
6700 | ilt->lines[cdu_ilt_start + i].page_mapping = | |
6701 | bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i); | |
6702 | /* cdu ilt pages are allocated manually so there's no need to | |
6703 | set the size */ | |
37b091ba | 6704 | } |
523224a3 | 6705 | bnx2x_ilt_init_op(bp, INITOP_SET); |
f85582f8 | 6706 | |
523224a3 DK |
6707 | #ifdef BCM_CNIC |
6708 | bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM); | |
37b091ba | 6709 | |
523224a3 DK |
6710 | /* T1 hash bits value determines the T1 number of entries */ |
6711 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS); | |
6712 | #endif | |
37b091ba | 6713 | |
523224a3 DK |
6714 | #ifndef BCM_CNIC |
6715 | /* set NIC mode */ | |
6716 | REG_WR(bp, PRS_REG_NIC_MODE, 1); | |
6717 | #endif /* BCM_CNIC */ | |
37b091ba | 6718 | |
619c5cb6 | 6719 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6720 | u32 pf_conf = IGU_PF_CONF_FUNC_EN; |
6721 | ||
6722 | /* Turn on a single ISR mode in IGU if driver is going to use | |
6723 | * INT#x or MSI | |
6724 | */ | |
6725 | if (!(bp->flags & USING_MSIX_FLAG)) | |
6726 | pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; | |
6727 | /* | |
6728 | * Timers workaround bug: function init part. | |
6729 | * Need to wait 20msec after initializing ILT, | |
6730 | * needed to make sure there are no requests in | |
6731 | * one of the PXP internal queues with "old" ILT addresses | |
6732 | */ | |
6733 | msleep(20); | |
6734 | /* | |
6735 | * Master enable - Due to WB DMAE writes performed before this | |
6736 | * register is re-initialized as part of the regular function | |
6737 | * init | |
6738 | */ | |
6739 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); | |
6740 | /* Enable the function in IGU */ | |
6741 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf); | |
6742 | } | |
6743 | ||
523224a3 | 6744 | bp->dmae_ready = 1; |
34f80b04 | 6745 | |
619c5cb6 | 6746 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
523224a3 | 6747 | |
619c5cb6 | 6748 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6749 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); |
6750 | ||
619c5cb6 VZ |
6751 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
6752 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); | |
6753 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); | |
6754 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); | |
6755 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); | |
6756 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); | |
6757 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); | |
6758 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); | |
6759 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); | |
6760 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); | |
6761 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); | |
6762 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); | |
6763 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); | |
6764 | ||
6765 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
6766 | REG_WR(bp, QM_REG_PF_EN, 1); |
6767 | ||
619c5cb6 VZ |
6768 | if (!CHIP_IS_E1x(bp)) { |
6769 | REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
6770 | REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
6771 | REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
6772 | REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); | |
6773 | } | |
6774 | bnx2x_init_block(bp, BLOCK_QM, init_phase); | |
6775 | ||
6776 | bnx2x_init_block(bp, BLOCK_TM, init_phase); | |
6777 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); | |
6778 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); | |
6779 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); | |
6780 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); | |
6781 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); | |
6782 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); | |
6783 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); | |
6784 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); | |
6785 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); | |
6786 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); | |
6787 | if (!CHIP_IS_E1x(bp)) | |
f2e0899f DK |
6788 | REG_WR(bp, PBF_REG_DISABLE_PF, 0); |
6789 | ||
619c5cb6 | 6790 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
523224a3 | 6791 | |
619c5cb6 | 6792 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
34f80b04 | 6793 | |
619c5cb6 | 6794 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6795 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1); |
6796 | ||
fb3bff17 | 6797 | if (IS_MF(bp)) { |
34f80b04 | 6798 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
fb3bff17 | 6799 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov); |
34f80b04 EG |
6800 | } |
6801 | ||
619c5cb6 | 6802 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
523224a3 | 6803 | |
34f80b04 | 6804 | /* HC init per function */ |
f2e0899f DK |
6805 | if (bp->common.int_block == INT_BLOCK_HC) { |
6806 | if (CHIP_IS_E1H(bp)) { | |
6807 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); | |
6808 | ||
6809 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
6810 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
6811 | } | |
619c5cb6 | 6812 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
f2e0899f DK |
6813 | |
6814 | } else { | |
6815 | int num_segs, sb_idx, prod_offset; | |
6816 | ||
34f80b04 EG |
6817 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
6818 | ||
619c5cb6 | 6819 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6820 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
6821 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
6822 | } | |
6823 | ||
619c5cb6 | 6824 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
f2e0899f | 6825 | |
619c5cb6 | 6826 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
6827 | int dsb_idx = 0; |
6828 | /** | |
6829 | * Producer memory: | |
6830 | * E2 mode: address 0-135 match to the mapping memory; | |
6831 | * 136 - PF0 default prod; 137 - PF1 default prod; | |
6832 | * 138 - PF2 default prod; 139 - PF3 default prod; | |
6833 | * 140 - PF0 attn prod; 141 - PF1 attn prod; | |
6834 | * 142 - PF2 attn prod; 143 - PF3 attn prod; | |
6835 | * 144-147 reserved. | |
6836 | * | |
6837 | * E1.5 mode - In backward compatible mode; | |
6838 | * for non default SB; each even line in the memory | |
6839 | * holds the U producer and each odd line hold | |
6840 | * the C producer. The first 128 producers are for | |
6841 | * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 | |
6842 | * producers are for the DSB for each PF. | |
6843 | * Each PF has five segments: (the order inside each | |
6844 | * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; | |
6845 | * 132-135 C prods; 136-139 X prods; 140-143 T prods; | |
6846 | * 144-147 attn prods; | |
6847 | */ | |
6848 | /* non-default-status-blocks */ | |
6849 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
6850 | IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; | |
6851 | for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) { | |
6852 | prod_offset = (bp->igu_base_sb + sb_idx) * | |
6853 | num_segs; | |
6854 | ||
6855 | for (i = 0; i < num_segs; i++) { | |
6856 | addr = IGU_REG_PROD_CONS_MEMORY + | |
6857 | (prod_offset + i) * 4; | |
6858 | REG_WR(bp, addr, 0); | |
6859 | } | |
6860 | /* send consumer update with value 0 */ | |
6861 | bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx, | |
6862 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
6863 | bnx2x_igu_clear_sb(bp, | |
6864 | bp->igu_base_sb + sb_idx); | |
6865 | } | |
6866 | ||
6867 | /* default-status-blocks */ | |
6868 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? | |
6869 | IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; | |
6870 | ||
6871 | if (CHIP_MODE_IS_4_PORT(bp)) | |
6872 | dsb_idx = BP_FUNC(bp); | |
6873 | else | |
3395a033 | 6874 | dsb_idx = BP_VN(bp); |
f2e0899f DK |
6875 | |
6876 | prod_offset = (CHIP_INT_MODE_IS_BC(bp) ? | |
6877 | IGU_BC_BASE_DSB_PROD + dsb_idx : | |
6878 | IGU_NORM_BASE_DSB_PROD + dsb_idx); | |
6879 | ||
3395a033 DK |
6880 | /* |
6881 | * igu prods come in chunks of E1HVN_MAX (4) - | |
6882 | * does not matters what is the current chip mode | |
6883 | */ | |
f2e0899f DK |
6884 | for (i = 0; i < (num_segs * E1HVN_MAX); |
6885 | i += E1HVN_MAX) { | |
6886 | addr = IGU_REG_PROD_CONS_MEMORY + | |
6887 | (prod_offset + i)*4; | |
6888 | REG_WR(bp, addr, 0); | |
6889 | } | |
6890 | /* send consumer update with 0 */ | |
6891 | if (CHIP_INT_MODE_IS_BC(bp)) { | |
6892 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6893 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
6894 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6895 | CSTORM_ID, 0, IGU_INT_NOP, 1); | |
6896 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6897 | XSTORM_ID, 0, IGU_INT_NOP, 1); | |
6898 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6899 | TSTORM_ID, 0, IGU_INT_NOP, 1); | |
6900 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6901 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
6902 | } else { | |
6903 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6904 | USTORM_ID, 0, IGU_INT_NOP, 1); | |
6905 | bnx2x_ack_sb(bp, bp->igu_dsb_id, | |
6906 | ATTENTION_ID, 0, IGU_INT_NOP, 1); | |
6907 | } | |
6908 | bnx2x_igu_clear_sb(bp, bp->igu_dsb_id); | |
6909 | ||
6910 | /* !!! these should become driver const once | |
6911 | rf-tool supports split-68 const */ | |
6912 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); | |
6913 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); | |
6914 | REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); | |
6915 | REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); | |
6916 | REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); | |
6917 | REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); | |
6918 | } | |
34f80b04 | 6919 | } |
34f80b04 | 6920 | |
c14423fe | 6921 | /* Reset PCIE errors for debug */ |
a2fbb9ea ET |
6922 | REG_WR(bp, 0x2114, 0xffffffff); |
6923 | REG_WR(bp, 0x2120, 0xffffffff); | |
523224a3 | 6924 | |
f4a66897 VZ |
6925 | if (CHIP_IS_E1x(bp)) { |
6926 | main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ | |
6927 | main_mem_base = HC_REG_MAIN_MEMORY + | |
6928 | BP_PORT(bp) * (main_mem_size * 4); | |
6929 | main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; | |
6930 | main_mem_width = 8; | |
6931 | ||
6932 | val = REG_RD(bp, main_mem_prty_clr); | |
6933 | if (val) | |
51c1a580 MS |
6934 | DP(NETIF_MSG_HW, |
6935 | "Hmmm... Parity errors in HC block during function init (0x%x)!\n", | |
6936 | val); | |
f4a66897 VZ |
6937 | |
6938 | /* Clear "false" parity errors in MSI-X table */ | |
6939 | for (i = main_mem_base; | |
6940 | i < main_mem_base + main_mem_size * 4; | |
6941 | i += main_mem_width) { | |
6942 | bnx2x_read_dmae(bp, i, main_mem_width / 4); | |
6943 | bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), | |
6944 | i, main_mem_width / 4); | |
6945 | } | |
6946 | /* Clear HC parity attention */ | |
6947 | REG_RD(bp, main_mem_prty_clr); | |
6948 | } | |
6949 | ||
619c5cb6 VZ |
6950 | #ifdef BNX2X_STOP_ON_ERROR |
6951 | /* Enable STORMs SP logging */ | |
6952 | REG_WR8(bp, BAR_USTRORM_INTMEM + | |
6953 | USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
6954 | REG_WR8(bp, BAR_TSTRORM_INTMEM + | |
6955 | TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
6956 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
6957 | CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
6958 | REG_WR8(bp, BAR_XSTRORM_INTMEM + | |
6959 | XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); | |
6960 | #endif | |
6961 | ||
b7737c9b | 6962 | bnx2x_phy_probe(&bp->link_params); |
f85582f8 | 6963 | |
34f80b04 EG |
6964 | return 0; |
6965 | } | |
6966 | ||
a2fbb9ea | 6967 | |
9f6c9258 | 6968 | void bnx2x_free_mem(struct bnx2x *bp) |
a2fbb9ea | 6969 | { |
a2fbb9ea | 6970 | /* fastpath */ |
b3b83c3f | 6971 | bnx2x_free_fp_mem(bp); |
a2fbb9ea ET |
6972 | /* end of fastpath */ |
6973 | ||
6974 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, | |
523224a3 | 6975 | sizeof(struct host_sp_status_block)); |
a2fbb9ea | 6976 | |
619c5cb6 VZ |
6977 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
6978 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); | |
6979 | ||
a2fbb9ea | 6980 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
34f80b04 | 6981 | sizeof(struct bnx2x_slowpath)); |
a2fbb9ea | 6982 | |
523224a3 DK |
6983 | BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping, |
6984 | bp->context.size); | |
6985 | ||
6986 | bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE); | |
6987 | ||
6988 | BNX2X_FREE(bp->ilt->lines); | |
f85582f8 | 6989 | |
37b091ba | 6990 | #ifdef BCM_CNIC |
619c5cb6 | 6991 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
6992 | BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping, |
6993 | sizeof(struct host_hc_status_block_e2)); | |
6994 | else | |
6995 | BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping, | |
6996 | sizeof(struct host_hc_status_block_e1x)); | |
f85582f8 | 6997 | |
523224a3 | 6998 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); |
a2fbb9ea | 6999 | #endif |
f85582f8 | 7000 | |
7a9b2557 | 7001 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
a2fbb9ea | 7002 | |
523224a3 DK |
7003 | BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping, |
7004 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
619c5cb6 VZ |
7005 | } |
7006 | ||
7007 | static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp) | |
7008 | { | |
7009 | int num_groups; | |
50f0a562 | 7010 | int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1; |
619c5cb6 | 7011 | |
50f0a562 BW |
7012 | /* number of queues for statistics is number of eth queues + FCoE */ |
7013 | u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats; | |
619c5cb6 VZ |
7014 | |
7015 | /* Total number of FW statistics requests = | |
50f0a562 BW |
7016 | * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats + |
7017 | * num of queues | |
7018 | */ | |
7019 | bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats; | |
523224a3 | 7020 | |
619c5cb6 VZ |
7021 | |
7022 | /* Request is built from stats_query_header and an array of | |
7023 | * stats_query_cmd_group each of which contains | |
7024 | * STATS_QUERY_CMD_COUNT rules. The real number or requests is | |
7025 | * configured in the stats_query_header. | |
7026 | */ | |
50f0a562 BW |
7027 | num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) + |
7028 | (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0); | |
619c5cb6 VZ |
7029 | |
7030 | bp->fw_stats_req_sz = sizeof(struct stats_query_header) + | |
7031 | num_groups * sizeof(struct stats_query_cmd_group); | |
7032 | ||
7033 | /* Data for statistics requests + stats_conter | |
7034 | * | |
7035 | * stats_counter holds per-STORM counters that are incremented | |
7036 | * when STORM has finished with the current request. | |
50f0a562 BW |
7037 | * |
7038 | * memory for FCoE offloaded statistics are counted anyway, | |
7039 | * even if they will not be sent. | |
619c5cb6 VZ |
7040 | */ |
7041 | bp->fw_stats_data_sz = sizeof(struct per_port_stats) + | |
7042 | sizeof(struct per_pf_stats) + | |
50f0a562 | 7043 | sizeof(struct fcoe_statistics_params) + |
619c5cb6 VZ |
7044 | sizeof(struct per_queue_stats) * num_queue_stats + |
7045 | sizeof(struct stats_counter); | |
7046 | ||
7047 | BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping, | |
7048 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); | |
7049 | ||
7050 | /* Set shortcuts */ | |
7051 | bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats; | |
7052 | bp->fw_stats_req_mapping = bp->fw_stats_mapping; | |
7053 | ||
7054 | bp->fw_stats_data = (struct bnx2x_fw_stats_data *) | |
7055 | ((u8 *)bp->fw_stats + bp->fw_stats_req_sz); | |
7056 | ||
7057 | bp->fw_stats_data_mapping = bp->fw_stats_mapping + | |
7058 | bp->fw_stats_req_sz; | |
7059 | return 0; | |
7060 | ||
7061 | alloc_mem_err: | |
7062 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, | |
7063 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); | |
51c1a580 | 7064 | BNX2X_ERR("Can't allocate memory\n"); |
619c5cb6 | 7065 | return -ENOMEM; |
a2fbb9ea ET |
7066 | } |
7067 | ||
f2e0899f | 7068 | |
9f6c9258 | 7069 | int bnx2x_alloc_mem(struct bnx2x *bp) |
a2fbb9ea | 7070 | { |
523224a3 | 7071 | #ifdef BCM_CNIC |
619c5cb6 VZ |
7072 | if (!CHIP_IS_E1x(bp)) |
7073 | /* size = the status block + ramrod buffers */ | |
f2e0899f DK |
7074 | BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, |
7075 | sizeof(struct host_hc_status_block_e2)); | |
7076 | else | |
7077 | BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping, | |
7078 | sizeof(struct host_hc_status_block_e1x)); | |
8badd27a | 7079 | |
523224a3 DK |
7080 | /* allocate searcher T2 table */ |
7081 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); | |
7082 | #endif | |
a2fbb9ea | 7083 | |
8badd27a | 7084 | |
523224a3 DK |
7085 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
7086 | sizeof(struct host_sp_status_block)); | |
a2fbb9ea | 7087 | |
523224a3 DK |
7088 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
7089 | sizeof(struct bnx2x_slowpath)); | |
a2fbb9ea | 7090 | |
82fa848c MY |
7091 | #ifdef BCM_CNIC |
7092 | /* write address to which L5 should insert its values */ | |
7093 | bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp; | |
7094 | #endif | |
7095 | ||
619c5cb6 VZ |
7096 | /* Allocated memory for FW statistics */ |
7097 | if (bnx2x_alloc_fw_stats_mem(bp)) | |
7098 | goto alloc_mem_err; | |
7099 | ||
6383c0b3 | 7100 | bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp); |
f85582f8 | 7101 | |
523224a3 DK |
7102 | BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping, |
7103 | bp->context.size); | |
65abd74d | 7104 | |
523224a3 | 7105 | BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); |
65abd74d | 7106 | |
523224a3 DK |
7107 | if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) |
7108 | goto alloc_mem_err; | |
65abd74d | 7109 | |
9f6c9258 DK |
7110 | /* Slow path ring */ |
7111 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); | |
65abd74d | 7112 | |
523224a3 DK |
7113 | /* EQ */ |
7114 | BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, | |
7115 | BCM_PAGE_SIZE * NUM_EQ_PAGES); | |
ab532cf3 | 7116 | |
b3b83c3f DK |
7117 | |
7118 | /* fastpath */ | |
7119 | /* need to be done at the end, since it's self adjusting to amount | |
7120 | * of memory available for RSS queues | |
7121 | */ | |
7122 | if (bnx2x_alloc_fp_mem(bp)) | |
7123 | goto alloc_mem_err; | |
9f6c9258 | 7124 | return 0; |
e1510706 | 7125 | |
9f6c9258 DK |
7126 | alloc_mem_err: |
7127 | bnx2x_free_mem(bp); | |
51c1a580 | 7128 | BNX2X_ERR("Can't allocate memory\n"); |
9f6c9258 | 7129 | return -ENOMEM; |
65abd74d YG |
7130 | } |
7131 | ||
a2fbb9ea ET |
7132 | /* |
7133 | * Init service functions | |
7134 | */ | |
a2fbb9ea | 7135 | |
619c5cb6 VZ |
7136 | int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac, |
7137 | struct bnx2x_vlan_mac_obj *obj, bool set, | |
7138 | int mac_type, unsigned long *ramrod_flags) | |
a2fbb9ea | 7139 | { |
619c5cb6 VZ |
7140 | int rc; |
7141 | struct bnx2x_vlan_mac_ramrod_params ramrod_param; | |
a2fbb9ea | 7142 | |
619c5cb6 | 7143 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
a2fbb9ea | 7144 | |
619c5cb6 VZ |
7145 | /* Fill general parameters */ |
7146 | ramrod_param.vlan_mac_obj = obj; | |
7147 | ramrod_param.ramrod_flags = *ramrod_flags; | |
a2fbb9ea | 7148 | |
619c5cb6 VZ |
7149 | /* Fill a user request section if needed */ |
7150 | if (!test_bit(RAMROD_CONT, ramrod_flags)) { | |
7151 | memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); | |
a2fbb9ea | 7152 | |
619c5cb6 | 7153 | __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); |
e3553b29 | 7154 | |
619c5cb6 VZ |
7155 | /* Set the command: ADD or DEL */ |
7156 | if (set) | |
7157 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD; | |
7158 | else | |
7159 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL; | |
a2fbb9ea ET |
7160 | } |
7161 | ||
619c5cb6 VZ |
7162 | rc = bnx2x_config_vlan_mac(bp, &ramrod_param); |
7163 | if (rc < 0) | |
7164 | BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); | |
7165 | return rc; | |
a2fbb9ea ET |
7166 | } |
7167 | ||
619c5cb6 VZ |
7168 | int bnx2x_del_all_macs(struct bnx2x *bp, |
7169 | struct bnx2x_vlan_mac_obj *mac_obj, | |
7170 | int mac_type, bool wait_for_comp) | |
e665bfda | 7171 | { |
619c5cb6 VZ |
7172 | int rc; |
7173 | unsigned long ramrod_flags = 0, vlan_mac_flags = 0; | |
0793f83f | 7174 | |
619c5cb6 VZ |
7175 | /* Wait for completion of requested */ |
7176 | if (wait_for_comp) | |
7177 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
0793f83f | 7178 | |
619c5cb6 VZ |
7179 | /* Set the mac type of addresses we want to clear */ |
7180 | __set_bit(mac_type, &vlan_mac_flags); | |
0793f83f | 7181 | |
619c5cb6 VZ |
7182 | rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags); |
7183 | if (rc < 0) | |
7184 | BNX2X_ERR("Failed to delete MACs: %d\n", rc); | |
0793f83f | 7185 | |
619c5cb6 | 7186 | return rc; |
0793f83f DK |
7187 | } |
7188 | ||
619c5cb6 | 7189 | int bnx2x_set_eth_mac(struct bnx2x *bp, bool set) |
523224a3 | 7190 | { |
619c5cb6 | 7191 | unsigned long ramrod_flags = 0; |
e665bfda | 7192 | |
614c76df | 7193 | #ifdef BCM_CNIC |
9e62e912 | 7194 | if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) { |
51c1a580 MS |
7195 | DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN, |
7196 | "Ignoring Zero MAC for STORAGE SD mode\n"); | |
614c76df DK |
7197 | return 0; |
7198 | } | |
7199 | #endif | |
7200 | ||
619c5cb6 | 7201 | DP(NETIF_MSG_IFUP, "Adding Eth MAC\n"); |
0793f83f | 7202 | |
619c5cb6 VZ |
7203 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
7204 | /* Eth MAC is set on RSS leading client (fp[0]) */ | |
7205 | return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set, | |
7206 | BNX2X_ETH_MAC, &ramrod_flags); | |
e665bfda | 7207 | } |
6e30dd4e | 7208 | |
619c5cb6 | 7209 | int bnx2x_setup_leading(struct bnx2x *bp) |
ec6ba945 | 7210 | { |
619c5cb6 | 7211 | return bnx2x_setup_queue(bp, &bp->fp[0], 1); |
993ac7b5 | 7212 | } |
a2fbb9ea | 7213 | |
d6214d7a | 7214 | /** |
e8920674 | 7215 | * bnx2x_set_int_mode - configure interrupt mode |
d6214d7a | 7216 | * |
e8920674 | 7217 | * @bp: driver handle |
d6214d7a | 7218 | * |
e8920674 | 7219 | * In case of MSI-X it will also try to enable MSI-X. |
d6214d7a | 7220 | */ |
9ee3d37b | 7221 | static void __devinit bnx2x_set_int_mode(struct bnx2x *bp) |
ca00392c | 7222 | { |
9ee3d37b | 7223 | switch (int_mode) { |
d6214d7a DK |
7224 | case INT_MODE_MSI: |
7225 | bnx2x_enable_msi(bp); | |
7226 | /* falling through... */ | |
7227 | case INT_MODE_INTx: | |
6383c0b3 | 7228 | bp->num_queues = 1 + NON_ETH_CONTEXT_USE; |
51c1a580 | 7229 | BNX2X_DEV_INFO("set number of queues to 1\n"); |
ca00392c | 7230 | break; |
d6214d7a DK |
7231 | default: |
7232 | /* Set number of queues according to bp->multi_mode value */ | |
7233 | bnx2x_set_num_queues(bp); | |
ca00392c | 7234 | |
51c1a580 | 7235 | BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues); |
ca00392c | 7236 | |
d6214d7a DK |
7237 | /* if we can't use MSI-X we only need one fp, |
7238 | * so try to enable MSI-X with the requested number of fp's | |
7239 | * and fallback to MSI or legacy INTx with one fp | |
7240 | */ | |
9ee3d37b | 7241 | if (bnx2x_enable_msix(bp)) { |
d6214d7a | 7242 | /* failed to enable MSI-X */ |
51c1a580 MS |
7243 | BNX2X_DEV_INFO("Failed to enable MSI-X (%d), set number of queues to %d\n", |
7244 | bp->num_queues, 1 + NON_ETH_CONTEXT_USE); | |
7245 | ||
6383c0b3 | 7246 | bp->num_queues = 1 + NON_ETH_CONTEXT_USE; |
d6214d7a | 7247 | |
9ee3d37b | 7248 | /* Try to enable MSI */ |
d6214d7a DK |
7249 | if (!(bp->flags & DISABLE_MSI_FLAG)) |
7250 | bnx2x_enable_msi(bp); | |
7251 | } | |
9f6c9258 DK |
7252 | break; |
7253 | } | |
a2fbb9ea ET |
7254 | } |
7255 | ||
c2bff63f DK |
7256 | /* must be called prioir to any HW initializations */ |
7257 | static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp) | |
7258 | { | |
7259 | return L2_ILT_LINES(bp); | |
7260 | } | |
7261 | ||
523224a3 DK |
7262 | void bnx2x_ilt_set_info(struct bnx2x *bp) |
7263 | { | |
7264 | struct ilt_client_info *ilt_client; | |
7265 | struct bnx2x_ilt *ilt = BP_ILT(bp); | |
7266 | u16 line = 0; | |
7267 | ||
7268 | ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp)); | |
7269 | DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line); | |
7270 | ||
7271 | /* CDU */ | |
7272 | ilt_client = &ilt->clients[ILT_CLIENT_CDU]; | |
7273 | ilt_client->client_num = ILT_CLIENT_CDU; | |
7274 | ilt_client->page_size = CDU_ILT_PAGE_SZ; | |
7275 | ilt_client->flags = ILT_CLIENT_SKIP_MEM; | |
7276 | ilt_client->start = line; | |
619c5cb6 | 7277 | line += bnx2x_cid_ilt_lines(bp); |
523224a3 DK |
7278 | #ifdef BCM_CNIC |
7279 | line += CNIC_ILT_LINES; | |
7280 | #endif | |
7281 | ilt_client->end = line - 1; | |
7282 | ||
51c1a580 | 7283 | DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", |
523224a3 DK |
7284 | ilt_client->start, |
7285 | ilt_client->end, | |
7286 | ilt_client->page_size, | |
7287 | ilt_client->flags, | |
7288 | ilog2(ilt_client->page_size >> 12)); | |
7289 | ||
7290 | /* QM */ | |
7291 | if (QM_INIT(bp->qm_cid_count)) { | |
7292 | ilt_client = &ilt->clients[ILT_CLIENT_QM]; | |
7293 | ilt_client->client_num = ILT_CLIENT_QM; | |
7294 | ilt_client->page_size = QM_ILT_PAGE_SZ; | |
7295 | ilt_client->flags = 0; | |
7296 | ilt_client->start = line; | |
7297 | ||
7298 | /* 4 bytes for each cid */ | |
7299 | line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4, | |
7300 | QM_ILT_PAGE_SZ); | |
7301 | ||
7302 | ilt_client->end = line - 1; | |
7303 | ||
51c1a580 MS |
7304 | DP(NETIF_MSG_IFUP, |
7305 | "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
523224a3 DK |
7306 | ilt_client->start, |
7307 | ilt_client->end, | |
7308 | ilt_client->page_size, | |
7309 | ilt_client->flags, | |
7310 | ilog2(ilt_client->page_size >> 12)); | |
7311 | ||
7312 | } | |
7313 | /* SRC */ | |
7314 | ilt_client = &ilt->clients[ILT_CLIENT_SRC]; | |
7315 | #ifdef BCM_CNIC | |
7316 | ilt_client->client_num = ILT_CLIENT_SRC; | |
7317 | ilt_client->page_size = SRC_ILT_PAGE_SZ; | |
7318 | ilt_client->flags = 0; | |
7319 | ilt_client->start = line; | |
7320 | line += SRC_ILT_LINES; | |
7321 | ilt_client->end = line - 1; | |
7322 | ||
51c1a580 MS |
7323 | DP(NETIF_MSG_IFUP, |
7324 | "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
523224a3 DK |
7325 | ilt_client->start, |
7326 | ilt_client->end, | |
7327 | ilt_client->page_size, | |
7328 | ilt_client->flags, | |
7329 | ilog2(ilt_client->page_size >> 12)); | |
7330 | ||
7331 | #else | |
7332 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); | |
7333 | #endif | |
9f6c9258 | 7334 | |
523224a3 DK |
7335 | /* TM */ |
7336 | ilt_client = &ilt->clients[ILT_CLIENT_TM]; | |
7337 | #ifdef BCM_CNIC | |
7338 | ilt_client->client_num = ILT_CLIENT_TM; | |
7339 | ilt_client->page_size = TM_ILT_PAGE_SZ; | |
7340 | ilt_client->flags = 0; | |
7341 | ilt_client->start = line; | |
7342 | line += TM_ILT_LINES; | |
7343 | ilt_client->end = line - 1; | |
7344 | ||
51c1a580 MS |
7345 | DP(NETIF_MSG_IFUP, |
7346 | "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n", | |
523224a3 DK |
7347 | ilt_client->start, |
7348 | ilt_client->end, | |
7349 | ilt_client->page_size, | |
7350 | ilt_client->flags, | |
7351 | ilog2(ilt_client->page_size >> 12)); | |
9f6c9258 | 7352 | |
523224a3 DK |
7353 | #else |
7354 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); | |
7355 | #endif | |
619c5cb6 | 7356 | BUG_ON(line > ILT_MAX_LINES); |
523224a3 | 7357 | } |
f85582f8 | 7358 | |
619c5cb6 VZ |
7359 | /** |
7360 | * bnx2x_pf_q_prep_init - prepare INIT transition parameters | |
7361 | * | |
7362 | * @bp: driver handle | |
7363 | * @fp: pointer to fastpath | |
7364 | * @init_params: pointer to parameters structure | |
7365 | * | |
7366 | * parameters configured: | |
7367 | * - HC configuration | |
7368 | * - Queue's CDU context | |
7369 | */ | |
7370 | static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp, | |
7371 | struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params) | |
a2fbb9ea | 7372 | { |
6383c0b3 AE |
7373 | |
7374 | u8 cos; | |
619c5cb6 VZ |
7375 | /* FCoE Queue uses Default SB, thus has no HC capabilities */ |
7376 | if (!IS_FCOE_FP(fp)) { | |
7377 | __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags); | |
7378 | __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags); | |
7379 | ||
7380 | /* If HC is supporterd, enable host coalescing in the transition | |
7381 | * to INIT state. | |
7382 | */ | |
7383 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags); | |
7384 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags); | |
7385 | ||
7386 | /* HC rate */ | |
7387 | init_params->rx.hc_rate = bp->rx_ticks ? | |
7388 | (1000000 / bp->rx_ticks) : 0; | |
7389 | init_params->tx.hc_rate = bp->tx_ticks ? | |
7390 | (1000000 / bp->tx_ticks) : 0; | |
7391 | ||
7392 | /* FW SB ID */ | |
7393 | init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = | |
7394 | fp->fw_sb_id; | |
7395 | ||
7396 | /* | |
7397 | * CQ index among the SB indices: FCoE clients uses the default | |
7398 | * SB, therefore it's different. | |
7399 | */ | |
6383c0b3 AE |
7400 | init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS; |
7401 | init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS; | |
619c5cb6 VZ |
7402 | } |
7403 | ||
6383c0b3 AE |
7404 | /* set maximum number of COSs supported by this queue */ |
7405 | init_params->max_cos = fp->max_cos; | |
7406 | ||
51c1a580 | 7407 | DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n", |
6383c0b3 AE |
7408 | fp->index, init_params->max_cos); |
7409 | ||
7410 | /* set the context pointers queue object */ | |
7411 | for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) | |
7412 | init_params->cxts[cos] = | |
7413 | &bp->context.vcxt[fp->txdata[cos].cid].eth; | |
619c5cb6 VZ |
7414 | } |
7415 | ||
6383c0b3 AE |
7416 | int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
7417 | struct bnx2x_queue_state_params *q_params, | |
7418 | struct bnx2x_queue_setup_tx_only_params *tx_only_params, | |
7419 | int tx_index, bool leading) | |
7420 | { | |
7421 | memset(tx_only_params, 0, sizeof(*tx_only_params)); | |
7422 | ||
7423 | /* Set the command */ | |
7424 | q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY; | |
7425 | ||
7426 | /* Set tx-only QUEUE flags: don't zero statistics */ | |
7427 | tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false); | |
7428 | ||
7429 | /* choose the index of the cid to send the slow path on */ | |
7430 | tx_only_params->cid_index = tx_index; | |
7431 | ||
7432 | /* Set general TX_ONLY_SETUP parameters */ | |
7433 | bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index); | |
7434 | ||
7435 | /* Set Tx TX_ONLY_SETUP parameters */ | |
7436 | bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index); | |
7437 | ||
51c1a580 MS |
7438 | DP(NETIF_MSG_IFUP, |
7439 | "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 |
7440 | tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX], |
7441 | q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id, | |
7442 | tx_only_params->gen_params.spcl_id, tx_only_params->flags); | |
7443 | ||
7444 | /* send the ramrod */ | |
7445 | return bnx2x_queue_state_change(bp, q_params); | |
7446 | } | |
7447 | ||
7448 | ||
619c5cb6 VZ |
7449 | /** |
7450 | * bnx2x_setup_queue - setup queue | |
7451 | * | |
7452 | * @bp: driver handle | |
7453 | * @fp: pointer to fastpath | |
7454 | * @leading: is leading | |
7455 | * | |
7456 | * This function performs 2 steps in a Queue state machine | |
7457 | * actually: 1) RESET->INIT 2) INIT->SETUP | |
7458 | */ | |
7459 | ||
7460 | int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp, | |
7461 | bool leading) | |
7462 | { | |
3b603066 | 7463 | struct bnx2x_queue_state_params q_params = {NULL}; |
619c5cb6 VZ |
7464 | struct bnx2x_queue_setup_params *setup_params = |
7465 | &q_params.params.setup; | |
6383c0b3 AE |
7466 | struct bnx2x_queue_setup_tx_only_params *tx_only_params = |
7467 | &q_params.params.tx_only; | |
a2fbb9ea | 7468 | int rc; |
6383c0b3 AE |
7469 | u8 tx_index; |
7470 | ||
51c1a580 | 7471 | DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index); |
a2fbb9ea | 7472 | |
ec6ba945 VZ |
7473 | /* reset IGU state skip FCoE L2 queue */ |
7474 | if (!IS_FCOE_FP(fp)) | |
7475 | bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, | |
523224a3 | 7476 | IGU_INT_ENABLE, 0); |
a2fbb9ea | 7477 | |
619c5cb6 VZ |
7478 | q_params.q_obj = &fp->q_obj; |
7479 | /* We want to wait for completion in this context */ | |
7480 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 7481 | |
619c5cb6 VZ |
7482 | /* Prepare the INIT parameters */ |
7483 | bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init); | |
ec6ba945 | 7484 | |
619c5cb6 VZ |
7485 | /* Set the command */ |
7486 | q_params.cmd = BNX2X_Q_CMD_INIT; | |
7487 | ||
7488 | /* Change the state to INIT */ | |
7489 | rc = bnx2x_queue_state_change(bp, &q_params); | |
7490 | if (rc) { | |
6383c0b3 | 7491 | BNX2X_ERR("Queue(%d) INIT failed\n", fp->index); |
619c5cb6 VZ |
7492 | return rc; |
7493 | } | |
ec6ba945 | 7494 | |
51c1a580 | 7495 | DP(NETIF_MSG_IFUP, "init complete\n"); |
6383c0b3 AE |
7496 | |
7497 | ||
619c5cb6 VZ |
7498 | /* Now move the Queue to the SETUP state... */ |
7499 | memset(setup_params, 0, sizeof(*setup_params)); | |
a2fbb9ea | 7500 | |
619c5cb6 VZ |
7501 | /* Set QUEUE flags */ |
7502 | setup_params->flags = bnx2x_get_q_flags(bp, fp, leading); | |
523224a3 | 7503 | |
619c5cb6 | 7504 | /* Set general SETUP parameters */ |
6383c0b3 AE |
7505 | bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params, |
7506 | FIRST_TX_COS_INDEX); | |
619c5cb6 | 7507 | |
6383c0b3 | 7508 | bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params, |
619c5cb6 VZ |
7509 | &setup_params->rxq_params); |
7510 | ||
6383c0b3 AE |
7511 | bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params, |
7512 | FIRST_TX_COS_INDEX); | |
619c5cb6 VZ |
7513 | |
7514 | /* Set the command */ | |
7515 | q_params.cmd = BNX2X_Q_CMD_SETUP; | |
7516 | ||
7517 | /* Change the state to SETUP */ | |
7518 | rc = bnx2x_queue_state_change(bp, &q_params); | |
6383c0b3 AE |
7519 | if (rc) { |
7520 | BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index); | |
7521 | return rc; | |
7522 | } | |
7523 | ||
7524 | /* loop through the relevant tx-only indices */ | |
7525 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
7526 | tx_index < fp->max_cos; | |
7527 | tx_index++) { | |
7528 | ||
7529 | /* prepare and send tx-only ramrod*/ | |
7530 | rc = bnx2x_setup_tx_only(bp, fp, &q_params, | |
7531 | tx_only_params, tx_index, leading); | |
7532 | if (rc) { | |
7533 | BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n", | |
7534 | fp->index, tx_index); | |
7535 | return rc; | |
7536 | } | |
7537 | } | |
523224a3 | 7538 | |
34f80b04 | 7539 | return rc; |
a2fbb9ea ET |
7540 | } |
7541 | ||
619c5cb6 | 7542 | static int bnx2x_stop_queue(struct bnx2x *bp, int index) |
a2fbb9ea | 7543 | { |
619c5cb6 | 7544 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
6383c0b3 | 7545 | struct bnx2x_fp_txdata *txdata; |
3b603066 | 7546 | struct bnx2x_queue_state_params q_params = {NULL}; |
6383c0b3 AE |
7547 | int rc, tx_index; |
7548 | ||
51c1a580 | 7549 | DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid); |
a2fbb9ea | 7550 | |
619c5cb6 VZ |
7551 | q_params.q_obj = &fp->q_obj; |
7552 | /* We want to wait for completion in this context */ | |
7553 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); | |
a2fbb9ea | 7554 | |
6383c0b3 AE |
7555 | |
7556 | /* close tx-only connections */ | |
7557 | for (tx_index = FIRST_TX_ONLY_COS_INDEX; | |
7558 | tx_index < fp->max_cos; | |
7559 | tx_index++){ | |
7560 | ||
7561 | /* ascertain this is a normal queue*/ | |
7562 | txdata = &fp->txdata[tx_index]; | |
7563 | ||
51c1a580 | 7564 | DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n", |
6383c0b3 AE |
7565 | txdata->txq_index); |
7566 | ||
7567 | /* send halt terminate on tx-only connection */ | |
7568 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; | |
7569 | memset(&q_params.params.terminate, 0, | |
7570 | sizeof(q_params.params.terminate)); | |
7571 | q_params.params.terminate.cid_index = tx_index; | |
7572 | ||
7573 | rc = bnx2x_queue_state_change(bp, &q_params); | |
7574 | if (rc) | |
7575 | return rc; | |
7576 | ||
7577 | /* send halt terminate on tx-only connection */ | |
7578 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; | |
7579 | memset(&q_params.params.cfc_del, 0, | |
7580 | sizeof(q_params.params.cfc_del)); | |
7581 | q_params.params.cfc_del.cid_index = tx_index; | |
7582 | rc = bnx2x_queue_state_change(bp, &q_params); | |
7583 | if (rc) | |
7584 | return rc; | |
7585 | } | |
7586 | /* Stop the primary connection: */ | |
7587 | /* ...halt the connection */ | |
619c5cb6 VZ |
7588 | q_params.cmd = BNX2X_Q_CMD_HALT; |
7589 | rc = bnx2x_queue_state_change(bp, &q_params); | |
7590 | if (rc) | |
da5a662a | 7591 | return rc; |
a2fbb9ea | 7592 | |
6383c0b3 | 7593 | /* ...terminate the connection */ |
619c5cb6 | 7594 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; |
6383c0b3 AE |
7595 | memset(&q_params.params.terminate, 0, |
7596 | sizeof(q_params.params.terminate)); | |
7597 | q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 VZ |
7598 | rc = bnx2x_queue_state_change(bp, &q_params); |
7599 | if (rc) | |
523224a3 | 7600 | return rc; |
6383c0b3 | 7601 | /* ...delete cfc entry */ |
619c5cb6 | 7602 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; |
6383c0b3 AE |
7603 | memset(&q_params.params.cfc_del, 0, |
7604 | sizeof(q_params.params.cfc_del)); | |
7605 | q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX; | |
619c5cb6 | 7606 | return bnx2x_queue_state_change(bp, &q_params); |
523224a3 DK |
7607 | } |
7608 | ||
7609 | ||
34f80b04 EG |
7610 | static void bnx2x_reset_func(struct bnx2x *bp) |
7611 | { | |
7612 | int port = BP_PORT(bp); | |
7613 | int func = BP_FUNC(bp); | |
f2e0899f | 7614 | int i; |
523224a3 DK |
7615 | |
7616 | /* Disable the function in the FW */ | |
7617 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); | |
7618 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); | |
7619 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); | |
7620 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); | |
7621 | ||
7622 | /* FP SBs */ | |
ec6ba945 | 7623 | for_each_eth_queue(bp, i) { |
523224a3 | 7624 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
619c5cb6 | 7625 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
6383c0b3 AE |
7626 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), |
7627 | SB_DISABLED); | |
523224a3 DK |
7628 | } |
7629 | ||
619c5cb6 VZ |
7630 | #ifdef BCM_CNIC |
7631 | /* CNIC SB */ | |
7632 | REG_WR8(bp, BAR_CSTRORM_INTMEM + | |
7633 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)), | |
7634 | SB_DISABLED); | |
7635 | #endif | |
523224a3 | 7636 | /* SP SB */ |
619c5cb6 | 7637 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
6383c0b3 AE |
7638 | CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), |
7639 | SB_DISABLED); | |
523224a3 DK |
7640 | |
7641 | for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) | |
7642 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), | |
7643 | 0); | |
34f80b04 EG |
7644 | |
7645 | /* Configure IGU */ | |
f2e0899f DK |
7646 | if (bp->common.int_block == INT_BLOCK_HC) { |
7647 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); | |
7648 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); | |
7649 | } else { | |
7650 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); | |
7651 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); | |
7652 | } | |
34f80b04 | 7653 | |
37b091ba MC |
7654 | #ifdef BCM_CNIC |
7655 | /* Disable Timer scan */ | |
7656 | REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0); | |
7657 | /* | |
7658 | * Wait for at least 10ms and up to 2 second for the timers scan to | |
7659 | * complete | |
7660 | */ | |
7661 | for (i = 0; i < 200; i++) { | |
7662 | msleep(10); | |
7663 | if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4)) | |
7664 | break; | |
7665 | } | |
7666 | #endif | |
34f80b04 | 7667 | /* Clear ILT */ |
f2e0899f DK |
7668 | bnx2x_clear_func_ilt(bp, func); |
7669 | ||
7670 | /* Timers workaround bug for E2: if this is vnic-3, | |
7671 | * we need to set the entire ilt range for this timers. | |
7672 | */ | |
619c5cb6 | 7673 | if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) { |
f2e0899f DK |
7674 | struct ilt_client_info ilt_cli; |
7675 | /* use dummy TM client */ | |
7676 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); | |
7677 | ilt_cli.start = 0; | |
7678 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; | |
7679 | ilt_cli.client_num = ILT_CLIENT_TM; | |
7680 | ||
7681 | bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR); | |
7682 | } | |
7683 | ||
7684 | /* this assumes that reset_port() called before reset_func()*/ | |
619c5cb6 | 7685 | if (!CHIP_IS_E1x(bp)) |
f2e0899f | 7686 | bnx2x_pf_disable(bp); |
523224a3 DK |
7687 | |
7688 | bp->dmae_ready = 0; | |
34f80b04 EG |
7689 | } |
7690 | ||
7691 | static void bnx2x_reset_port(struct bnx2x *bp) | |
7692 | { | |
7693 | int port = BP_PORT(bp); | |
7694 | u32 val; | |
7695 | ||
619c5cb6 VZ |
7696 | /* Reset physical Link */ |
7697 | bnx2x__link_reset(bp); | |
7698 | ||
34f80b04 EG |
7699 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
7700 | ||
7701 | /* Do not rcv packets to BRB */ | |
7702 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); | |
7703 | /* Do not direct rcv packets that are not for MCP to the BRB */ | |
7704 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : | |
7705 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); | |
7706 | ||
7707 | /* Configure AEU */ | |
7708 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); | |
7709 | ||
7710 | msleep(100); | |
7711 | /* Check for BRB port occupancy */ | |
7712 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); | |
7713 | if (val) | |
7714 | DP(NETIF_MSG_IFDOWN, | |
33471629 | 7715 | "BRB1 is not empty %d blocks are occupied\n", val); |
34f80b04 EG |
7716 | |
7717 | /* TODO: Close Doorbell port? */ | |
7718 | } | |
7719 | ||
619c5cb6 | 7720 | static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code) |
34f80b04 | 7721 | { |
3b603066 | 7722 | struct bnx2x_func_state_params func_params = {NULL}; |
34f80b04 | 7723 | |
619c5cb6 VZ |
7724 | /* Prepare parameters for function state transitions */ |
7725 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
34f80b04 | 7726 | |
619c5cb6 VZ |
7727 | func_params.f_obj = &bp->func_obj; |
7728 | func_params.cmd = BNX2X_F_CMD_HW_RESET; | |
34f80b04 | 7729 | |
619c5cb6 | 7730 | func_params.params.hw_init.load_phase = load_code; |
49d66772 | 7731 | |
619c5cb6 | 7732 | return bnx2x_func_state_change(bp, &func_params); |
34f80b04 EG |
7733 | } |
7734 | ||
619c5cb6 | 7735 | static inline int bnx2x_func_stop(struct bnx2x *bp) |
ec6ba945 | 7736 | { |
3b603066 | 7737 | struct bnx2x_func_state_params func_params = {NULL}; |
619c5cb6 | 7738 | int rc; |
228241eb | 7739 | |
619c5cb6 VZ |
7740 | /* Prepare parameters for function state transitions */ |
7741 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); | |
7742 | func_params.f_obj = &bp->func_obj; | |
7743 | func_params.cmd = BNX2X_F_CMD_STOP; | |
da5a662a | 7744 | |
619c5cb6 VZ |
7745 | /* |
7746 | * Try to stop the function the 'good way'. If fails (in case | |
7747 | * of a parity error during bnx2x_chip_cleanup()) and we are | |
7748 | * not in a debug mode, perform a state transaction in order to | |
7749 | * enable further HW_RESET transaction. | |
7750 | */ | |
7751 | rc = bnx2x_func_state_change(bp, &func_params); | |
7752 | if (rc) { | |
34f80b04 | 7753 | #ifdef BNX2X_STOP_ON_ERROR |
619c5cb6 | 7754 | return rc; |
34f80b04 | 7755 | #else |
51c1a580 | 7756 | BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n"); |
619c5cb6 VZ |
7757 | __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); |
7758 | return bnx2x_func_state_change(bp, &func_params); | |
34f80b04 | 7759 | #endif |
228241eb | 7760 | } |
a2fbb9ea | 7761 | |
619c5cb6 VZ |
7762 | return 0; |
7763 | } | |
523224a3 | 7764 | |
619c5cb6 VZ |
7765 | /** |
7766 | * bnx2x_send_unload_req - request unload mode from the MCP. | |
7767 | * | |
7768 | * @bp: driver handle | |
7769 | * @unload_mode: requested function's unload mode | |
7770 | * | |
7771 | * Return unload mode returned by the MCP: COMMON, PORT or FUNC. | |
7772 | */ | |
7773 | u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode) | |
7774 | { | |
7775 | u32 reset_code = 0; | |
7776 | int port = BP_PORT(bp); | |
3101c2bc | 7777 | |
619c5cb6 | 7778 | /* Select the UNLOAD request mode */ |
65abd74d YG |
7779 | if (unload_mode == UNLOAD_NORMAL) |
7780 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
7781 | ||
7d0446c2 | 7782 | else if (bp->flags & NO_WOL_FLAG) |
65abd74d | 7783 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
65abd74d | 7784 | |
7d0446c2 | 7785 | else if (bp->wol) { |
65abd74d YG |
7786 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
7787 | u8 *mac_addr = bp->dev->dev_addr; | |
7788 | u32 val; | |
f9977903 DK |
7789 | u16 pmc; |
7790 | ||
65abd74d | 7791 | /* The mac address is written to entries 1-4 to |
f9977903 DK |
7792 | * preserve entry 0 which is used by the PMF |
7793 | */ | |
3395a033 | 7794 | u8 entry = (BP_VN(bp) + 1)*8; |
65abd74d YG |
7795 | |
7796 | val = (mac_addr[0] << 8) | mac_addr[1]; | |
7797 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); | |
7798 | ||
7799 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | | |
7800 | (mac_addr[4] << 8) | mac_addr[5]; | |
7801 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); | |
7802 | ||
f9977903 DK |
7803 | /* Enable the PME and clear the status */ |
7804 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc); | |
7805 | pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS; | |
7806 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc); | |
7807 | ||
65abd74d YG |
7808 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
7809 | ||
7810 | } else | |
7811 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; | |
da5a662a | 7812 | |
619c5cb6 VZ |
7813 | /* Send the request to the MCP */ |
7814 | if (!BP_NOMCP(bp)) | |
7815 | reset_code = bnx2x_fw_command(bp, reset_code, 0); | |
7816 | else { | |
7817 | int path = BP_PATH(bp); | |
7818 | ||
51c1a580 | 7819 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
7820 | path, load_count[path][0], load_count[path][1], |
7821 | load_count[path][2]); | |
7822 | load_count[path][0]--; | |
7823 | load_count[path][1 + port]--; | |
51c1a580 | 7824 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n", |
619c5cb6 VZ |
7825 | path, load_count[path][0], load_count[path][1], |
7826 | load_count[path][2]); | |
7827 | if (load_count[path][0] == 0) | |
7828 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; | |
7829 | else if (load_count[path][1 + port] == 0) | |
7830 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; | |
7831 | else | |
7832 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; | |
7833 | } | |
7834 | ||
7835 | return reset_code; | |
7836 | } | |
7837 | ||
7838 | /** | |
7839 | * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP. | |
7840 | * | |
7841 | * @bp: driver handle | |
7842 | */ | |
7843 | void bnx2x_send_unload_done(struct bnx2x *bp) | |
7844 | { | |
7845 | /* Report UNLOAD_DONE to MCP */ | |
7846 | if (!BP_NOMCP(bp)) | |
7847 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); | |
7848 | } | |
7849 | ||
6debea87 DK |
7850 | static inline int bnx2x_func_wait_started(struct bnx2x *bp) |
7851 | { | |
7852 | int tout = 50; | |
7853 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; | |
7854 | ||
7855 | if (!bp->port.pmf) | |
7856 | return 0; | |
7857 | ||
7858 | /* | |
7859 | * (assumption: No Attention from MCP at this stage) | |
7860 | * PMF probably in the middle of TXdisable/enable transaction | |
7861 | * 1. Sync IRS for default SB | |
7862 | * 2. Sync SP queue - this guarantes us that attention handling started | |
7863 | * 3. Wait, that TXdisable/enable transaction completes | |
7864 | * | |
7865 | * 1+2 guranty that if DCBx attention was scheduled it already changed | |
7866 | * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy | |
7867 | * received complettion for the transaction the state is TX_STOPPED. | |
7868 | * State will return to STARTED after completion of TX_STOPPED-->STARTED | |
7869 | * transaction. | |
7870 | */ | |
7871 | ||
7872 | /* make sure default SB ISR is done */ | |
7873 | if (msix) | |
7874 | synchronize_irq(bp->msix_table[0].vector); | |
7875 | else | |
7876 | synchronize_irq(bp->pdev->irq); | |
7877 | ||
7878 | flush_workqueue(bnx2x_wq); | |
7879 | ||
7880 | while (bnx2x_func_get_state(bp, &bp->func_obj) != | |
7881 | BNX2X_F_STATE_STARTED && tout--) | |
7882 | msleep(20); | |
7883 | ||
7884 | if (bnx2x_func_get_state(bp, &bp->func_obj) != | |
7885 | BNX2X_F_STATE_STARTED) { | |
7886 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 | 7887 | BNX2X_ERR("Wrong function state\n"); |
6debea87 DK |
7888 | return -EBUSY; |
7889 | #else | |
7890 | /* | |
7891 | * Failed to complete the transaction in a "good way" | |
7892 | * Force both transactions with CLR bit | |
7893 | */ | |
3b603066 | 7894 | struct bnx2x_func_state_params func_params = {NULL}; |
6debea87 | 7895 | |
51c1a580 MS |
7896 | DP(NETIF_MSG_IFDOWN, |
7897 | "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n"); | |
6debea87 DK |
7898 | |
7899 | func_params.f_obj = &bp->func_obj; | |
7900 | __set_bit(RAMROD_DRV_CLR_ONLY, | |
7901 | &func_params.ramrod_flags); | |
7902 | ||
7903 | /* STARTED-->TX_ST0PPED */ | |
7904 | func_params.cmd = BNX2X_F_CMD_TX_STOP; | |
7905 | bnx2x_func_state_change(bp, &func_params); | |
7906 | ||
7907 | /* TX_ST0PPED-->STARTED */ | |
7908 | func_params.cmd = BNX2X_F_CMD_TX_START; | |
7909 | return bnx2x_func_state_change(bp, &func_params); | |
7910 | #endif | |
7911 | } | |
7912 | ||
7913 | return 0; | |
7914 | } | |
7915 | ||
619c5cb6 VZ |
7916 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode) |
7917 | { | |
7918 | int port = BP_PORT(bp); | |
6383c0b3 AE |
7919 | int i, rc = 0; |
7920 | u8 cos; | |
3b603066 | 7921 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 VZ |
7922 | u32 reset_code; |
7923 | ||
7924 | /* Wait until tx fastpath tasks complete */ | |
7925 | for_each_tx_queue(bp, i) { | |
7926 | struct bnx2x_fastpath *fp = &bp->fp[i]; | |
7927 | ||
6383c0b3 AE |
7928 | for_each_cos_in_tx_queue(fp, cos) |
7929 | rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]); | |
619c5cb6 VZ |
7930 | #ifdef BNX2X_STOP_ON_ERROR |
7931 | if (rc) | |
7932 | return; | |
7933 | #endif | |
7934 | } | |
7935 | ||
7936 | /* Give HW time to discard old tx messages */ | |
7937 | usleep_range(1000, 1000); | |
7938 | ||
7939 | /* Clean all ETH MACs */ | |
7940 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false); | |
7941 | if (rc < 0) | |
7942 | BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc); | |
7943 | ||
7944 | /* Clean up UC list */ | |
7945 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC, | |
7946 | true); | |
7947 | if (rc < 0) | |
51c1a580 MS |
7948 | BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n", |
7949 | rc); | |
619c5cb6 VZ |
7950 | |
7951 | /* Disable LLH */ | |
7952 | if (!CHIP_IS_E1(bp)) | |
7953 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); | |
7954 | ||
7955 | /* Set "drop all" (stop Rx). | |
7956 | * We need to take a netif_addr_lock() here in order to prevent | |
7957 | * a race between the completion code and this code. | |
7958 | */ | |
7959 | netif_addr_lock_bh(bp->dev); | |
7960 | /* Schedule the rx_mode command */ | |
7961 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
7962 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
7963 | else | |
7964 | bnx2x_set_storm_rx_mode(bp); | |
7965 | ||
7966 | /* Cleanup multicast configuration */ | |
7967 | rparam.mcast_obj = &bp->mcast_obj; | |
7968 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
7969 | if (rc < 0) | |
7970 | BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc); | |
7971 | ||
7972 | netif_addr_unlock_bh(bp->dev); | |
7973 | ||
7974 | ||
6debea87 DK |
7975 | |
7976 | /* | |
7977 | * Send the UNLOAD_REQUEST to the MCP. This will return if | |
7978 | * this function should perform FUNC, PORT or COMMON HW | |
7979 | * reset. | |
7980 | */ | |
7981 | reset_code = bnx2x_send_unload_req(bp, unload_mode); | |
7982 | ||
7983 | /* | |
7984 | * (assumption: No Attention from MCP at this stage) | |
7985 | * PMF probably in the middle of TXdisable/enable transaction | |
7986 | */ | |
7987 | rc = bnx2x_func_wait_started(bp); | |
7988 | if (rc) { | |
7989 | BNX2X_ERR("bnx2x_func_wait_started failed\n"); | |
7990 | #ifdef BNX2X_STOP_ON_ERROR | |
7991 | return; | |
7992 | #endif | |
7993 | } | |
7994 | ||
34f80b04 | 7995 | /* Close multi and leading connections |
619c5cb6 VZ |
7996 | * Completions for ramrods are collected in a synchronous way |
7997 | */ | |
523224a3 | 7998 | for_each_queue(bp, i) |
619c5cb6 | 7999 | if (bnx2x_stop_queue(bp, i)) |
523224a3 DK |
8000 | #ifdef BNX2X_STOP_ON_ERROR |
8001 | return; | |
8002 | #else | |
228241eb | 8003 | goto unload_error; |
523224a3 | 8004 | #endif |
619c5cb6 VZ |
8005 | /* If SP settings didn't get completed so far - something |
8006 | * very wrong has happen. | |
8007 | */ | |
8008 | if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) | |
8009 | BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n"); | |
a2fbb9ea | 8010 | |
619c5cb6 VZ |
8011 | #ifndef BNX2X_STOP_ON_ERROR |
8012 | unload_error: | |
8013 | #endif | |
523224a3 | 8014 | rc = bnx2x_func_stop(bp); |
da5a662a | 8015 | if (rc) { |
523224a3 | 8016 | BNX2X_ERR("Function stop failed!\n"); |
da5a662a | 8017 | #ifdef BNX2X_STOP_ON_ERROR |
523224a3 | 8018 | return; |
523224a3 | 8019 | #endif |
34f80b04 | 8020 | } |
a2fbb9ea | 8021 | |
523224a3 DK |
8022 | /* Disable HW interrupts, NAPI */ |
8023 | bnx2x_netif_stop(bp, 1); | |
8024 | ||
8025 | /* Release IRQs */ | |
d6214d7a | 8026 | bnx2x_free_irq(bp); |
523224a3 | 8027 | |
a2fbb9ea | 8028 | /* Reset the chip */ |
619c5cb6 VZ |
8029 | rc = bnx2x_reset_hw(bp, reset_code); |
8030 | if (rc) | |
8031 | BNX2X_ERR("HW_RESET failed\n"); | |
a2fbb9ea | 8032 | |
356e2385 | 8033 | |
619c5cb6 VZ |
8034 | /* Report UNLOAD_DONE to MCP */ |
8035 | bnx2x_send_unload_done(bp); | |
72fd0718 VZ |
8036 | } |
8037 | ||
9f6c9258 | 8038 | void bnx2x_disable_close_the_gate(struct bnx2x *bp) |
72fd0718 VZ |
8039 | { |
8040 | u32 val; | |
8041 | ||
51c1a580 | 8042 | DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n"); |
72fd0718 VZ |
8043 | |
8044 | if (CHIP_IS_E1(bp)) { | |
8045 | int port = BP_PORT(bp); | |
8046 | u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : | |
8047 | MISC_REG_AEU_MASK_ATTN_FUNC_0; | |
8048 | ||
8049 | val = REG_RD(bp, addr); | |
8050 | val &= ~(0x300); | |
8051 | REG_WR(bp, addr, val); | |
619c5cb6 | 8052 | } else { |
72fd0718 VZ |
8053 | val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK); |
8054 | val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | | |
8055 | MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); | |
8056 | REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val); | |
8057 | } | |
8058 | } | |
8059 | ||
72fd0718 VZ |
8060 | /* Close gates #2, #3 and #4: */ |
8061 | static void bnx2x_set_234_gates(struct bnx2x *bp, bool close) | |
8062 | { | |
c9ee9206 | 8063 | u32 val; |
72fd0718 VZ |
8064 | |
8065 | /* Gates #2 and #4a are closed/opened for "not E1" only */ | |
8066 | if (!CHIP_IS_E1(bp)) { | |
8067 | /* #4 */ | |
c9ee9206 | 8068 | REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close); |
72fd0718 | 8069 | /* #2 */ |
c9ee9206 | 8070 | REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); |
72fd0718 VZ |
8071 | } |
8072 | ||
8073 | /* #3 */ | |
c9ee9206 VZ |
8074 | if (CHIP_IS_E1x(bp)) { |
8075 | /* Prevent interrupts from HC on both ports */ | |
8076 | val = REG_RD(bp, HC_REG_CONFIG_1); | |
8077 | REG_WR(bp, HC_REG_CONFIG_1, | |
8078 | (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : | |
8079 | (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); | |
8080 | ||
8081 | val = REG_RD(bp, HC_REG_CONFIG_0); | |
8082 | REG_WR(bp, HC_REG_CONFIG_0, | |
8083 | (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : | |
8084 | (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); | |
8085 | } else { | |
8086 | /* Prevent incomming interrupts in IGU */ | |
8087 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); | |
8088 | ||
8089 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, | |
8090 | (!close) ? | |
8091 | (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : | |
8092 | (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); | |
8093 | } | |
72fd0718 | 8094 | |
51c1a580 | 8095 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n", |
72fd0718 VZ |
8096 | close ? "closing" : "opening"); |
8097 | mmiowb(); | |
8098 | } | |
8099 | ||
8100 | #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */ | |
8101 | ||
8102 | static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val) | |
8103 | { | |
8104 | /* Do some magic... */ | |
8105 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); | |
8106 | *magic_val = val & SHARED_MF_CLP_MAGIC; | |
8107 | MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); | |
8108 | } | |
8109 | ||
e8920674 DK |
8110 | /** |
8111 | * bnx2x_clp_reset_done - restore the value of the `magic' bit. | |
72fd0718 | 8112 | * |
e8920674 DK |
8113 | * @bp: driver handle |
8114 | * @magic_val: old value of the `magic' bit. | |
72fd0718 VZ |
8115 | */ |
8116 | static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val) | |
8117 | { | |
8118 | /* Restore the `magic' bit value... */ | |
72fd0718 VZ |
8119 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
8120 | MF_CFG_WR(bp, shared_mf_config.clp_mb, | |
8121 | (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); | |
8122 | } | |
8123 | ||
f85582f8 | 8124 | /** |
e8920674 | 8125 | * bnx2x_reset_mcp_prep - prepare for MCP reset. |
72fd0718 | 8126 | * |
e8920674 DK |
8127 | * @bp: driver handle |
8128 | * @magic_val: old value of 'magic' bit. | |
8129 | * | |
8130 | * Takes care of CLP configurations. | |
72fd0718 VZ |
8131 | */ |
8132 | static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val) | |
8133 | { | |
8134 | u32 shmem; | |
8135 | u32 validity_offset; | |
8136 | ||
51c1a580 | 8137 | DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n"); |
72fd0718 VZ |
8138 | |
8139 | /* Set `magic' bit in order to save MF config */ | |
8140 | if (!CHIP_IS_E1(bp)) | |
8141 | bnx2x_clp_reset_prep(bp, magic_val); | |
8142 | ||
8143 | /* Get shmem offset */ | |
8144 | shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
8145 | validity_offset = offsetof(struct shmem_region, validity_map[0]); | |
8146 | ||
8147 | /* Clear validity map flags */ | |
8148 | if (shmem > 0) | |
8149 | REG_WR(bp, shmem + validity_offset, 0); | |
8150 | } | |
8151 | ||
8152 | #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ | |
8153 | #define MCP_ONE_TIMEOUT 100 /* 100 ms */ | |
8154 | ||
e8920674 DK |
8155 | /** |
8156 | * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT | |
72fd0718 | 8157 | * |
e8920674 | 8158 | * @bp: driver handle |
72fd0718 VZ |
8159 | */ |
8160 | static inline void bnx2x_mcp_wait_one(struct bnx2x *bp) | |
8161 | { | |
8162 | /* special handling for emulation and FPGA, | |
8163 | wait 10 times longer */ | |
8164 | if (CHIP_REV_IS_SLOW(bp)) | |
8165 | msleep(MCP_ONE_TIMEOUT*10); | |
8166 | else | |
8167 | msleep(MCP_ONE_TIMEOUT); | |
8168 | } | |
8169 | ||
1b6e2ceb DK |
8170 | /* |
8171 | * initializes bp->common.shmem_base and waits for validity signature to appear | |
8172 | */ | |
8173 | static int bnx2x_init_shmem(struct bnx2x *bp) | |
72fd0718 | 8174 | { |
1b6e2ceb DK |
8175 | int cnt = 0; |
8176 | u32 val = 0; | |
72fd0718 | 8177 | |
1b6e2ceb DK |
8178 | do { |
8179 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); | |
8180 | if (bp->common.shmem_base) { | |
8181 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); | |
8182 | if (val & SHR_MEM_VALIDITY_MB) | |
8183 | return 0; | |
8184 | } | |
72fd0718 | 8185 | |
1b6e2ceb | 8186 | bnx2x_mcp_wait_one(bp); |
72fd0718 | 8187 | |
1b6e2ceb | 8188 | } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); |
72fd0718 | 8189 | |
1b6e2ceb | 8190 | BNX2X_ERR("BAD MCP validity signature\n"); |
72fd0718 | 8191 | |
1b6e2ceb DK |
8192 | return -ENODEV; |
8193 | } | |
72fd0718 | 8194 | |
1b6e2ceb DK |
8195 | static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val) |
8196 | { | |
8197 | int rc = bnx2x_init_shmem(bp); | |
72fd0718 | 8198 | |
72fd0718 VZ |
8199 | /* Restore the `magic' bit value */ |
8200 | if (!CHIP_IS_E1(bp)) | |
8201 | bnx2x_clp_reset_done(bp, magic_val); | |
8202 | ||
8203 | return rc; | |
8204 | } | |
8205 | ||
8206 | static void bnx2x_pxp_prep(struct bnx2x *bp) | |
8207 | { | |
8208 | if (!CHIP_IS_E1(bp)) { | |
8209 | REG_WR(bp, PXP2_REG_RD_START_INIT, 0); | |
8210 | REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0); | |
72fd0718 VZ |
8211 | mmiowb(); |
8212 | } | |
8213 | } | |
8214 | ||
8215 | /* | |
8216 | * Reset the whole chip except for: | |
8217 | * - PCIE core | |
8218 | * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by | |
8219 | * one reset bit) | |
8220 | * - IGU | |
8221 | * - MISC (including AEU) | |
8222 | * - GRC | |
8223 | * - RBCN, RBCP | |
8224 | */ | |
c9ee9206 | 8225 | static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global) |
72fd0718 VZ |
8226 | { |
8227 | u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; | |
8736c826 | 8228 | u32 global_bits2, stay_reset2; |
c9ee9206 VZ |
8229 | |
8230 | /* | |
8231 | * Bits that have to be set in reset_mask2 if we want to reset 'global' | |
8232 | * (per chip) blocks. | |
8233 | */ | |
8234 | global_bits2 = | |
8235 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | | |
8236 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; | |
72fd0718 | 8237 | |
8736c826 | 8238 | /* Don't reset the following blocks */ |
72fd0718 VZ |
8239 | not_reset_mask1 = |
8240 | MISC_REGISTERS_RESET_REG_1_RST_HC | | |
8241 | MISC_REGISTERS_RESET_REG_1_RST_PXPV | | |
8242 | MISC_REGISTERS_RESET_REG_1_RST_PXP; | |
8243 | ||
8244 | not_reset_mask2 = | |
c9ee9206 | 8245 | MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | |
72fd0718 VZ |
8246 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | |
8247 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | | |
8248 | MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | | |
8249 | MISC_REGISTERS_RESET_REG_2_RST_RBCN | | |
8250 | MISC_REGISTERS_RESET_REG_2_RST_GRC | | |
8251 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | | |
8736c826 VZ |
8252 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B | |
8253 | MISC_REGISTERS_RESET_REG_2_RST_ATC | | |
8254 | MISC_REGISTERS_RESET_REG_2_PGLC; | |
72fd0718 | 8255 | |
8736c826 VZ |
8256 | /* |
8257 | * Keep the following blocks in reset: | |
8258 | * - all xxMACs are handled by the bnx2x_link code. | |
8259 | */ | |
8260 | stay_reset2 = | |
8261 | MISC_REGISTERS_RESET_REG_2_RST_BMAC0 | | |
8262 | MISC_REGISTERS_RESET_REG_2_RST_BMAC1 | | |
8263 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0 | | |
8264 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1 | | |
8265 | MISC_REGISTERS_RESET_REG_2_UMAC0 | | |
8266 | MISC_REGISTERS_RESET_REG_2_UMAC1 | | |
8267 | MISC_REGISTERS_RESET_REG_2_XMAC | | |
8268 | MISC_REGISTERS_RESET_REG_2_XMAC_SOFT; | |
8269 | ||
8270 | /* Full reset masks according to the chip */ | |
72fd0718 VZ |
8271 | reset_mask1 = 0xffffffff; |
8272 | ||
8273 | if (CHIP_IS_E1(bp)) | |
8274 | reset_mask2 = 0xffff; | |
8736c826 | 8275 | else if (CHIP_IS_E1H(bp)) |
72fd0718 | 8276 | reset_mask2 = 0x1ffff; |
8736c826 VZ |
8277 | else if (CHIP_IS_E2(bp)) |
8278 | reset_mask2 = 0xfffff; | |
8279 | else /* CHIP_IS_E3 */ | |
8280 | reset_mask2 = 0x3ffffff; | |
c9ee9206 VZ |
8281 | |
8282 | /* Don't reset global blocks unless we need to */ | |
8283 | if (!global) | |
8284 | reset_mask2 &= ~global_bits2; | |
8285 | ||
8286 | /* | |
8287 | * In case of attention in the QM, we need to reset PXP | |
8288 | * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM | |
8289 | * because otherwise QM reset would release 'close the gates' shortly | |
8290 | * before resetting the PXP, then the PSWRQ would send a write | |
8291 | * request to PGLUE. Then when PXP is reset, PGLUE would try to | |
8292 | * read the payload data from PSWWR, but PSWWR would not | |
8293 | * respond. The write queue in PGLUE would stuck, dmae commands | |
8294 | * would not return. Therefore it's important to reset the second | |
8295 | * reset register (containing the | |
8296 | * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the | |
8297 | * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM | |
8298 | * bit). | |
8299 | */ | |
72fd0718 VZ |
8300 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
8301 | reset_mask2 & (~not_reset_mask2)); | |
8302 | ||
c9ee9206 VZ |
8303 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
8304 | reset_mask1 & (~not_reset_mask1)); | |
8305 | ||
72fd0718 VZ |
8306 | barrier(); |
8307 | mmiowb(); | |
8308 | ||
8736c826 VZ |
8309 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, |
8310 | reset_mask2 & (~stay_reset2)); | |
8311 | ||
8312 | barrier(); | |
8313 | mmiowb(); | |
8314 | ||
c9ee9206 | 8315 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1); |
72fd0718 VZ |
8316 | mmiowb(); |
8317 | } | |
8318 | ||
c9ee9206 VZ |
8319 | /** |
8320 | * bnx2x_er_poll_igu_vq - poll for pending writes bit. | |
8321 | * It should get cleared in no more than 1s. | |
8322 | * | |
8323 | * @bp: driver handle | |
8324 | * | |
8325 | * It should get cleared in no more than 1s. Returns 0 if | |
8326 | * pending writes bit gets cleared. | |
8327 | */ | |
8328 | static int bnx2x_er_poll_igu_vq(struct bnx2x *bp) | |
8329 | { | |
8330 | u32 cnt = 1000; | |
8331 | u32 pend_bits = 0; | |
8332 | ||
8333 | do { | |
8334 | pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS); | |
8335 | ||
8336 | if (pend_bits == 0) | |
8337 | break; | |
8338 | ||
8339 | usleep_range(1000, 1000); | |
8340 | } while (cnt-- > 0); | |
8341 | ||
8342 | if (cnt <= 0) { | |
8343 | BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n", | |
8344 | pend_bits); | |
8345 | return -EBUSY; | |
8346 | } | |
8347 | ||
8348 | return 0; | |
8349 | } | |
8350 | ||
8351 | static int bnx2x_process_kill(struct bnx2x *bp, bool global) | |
72fd0718 VZ |
8352 | { |
8353 | int cnt = 1000; | |
8354 | u32 val = 0; | |
8355 | u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; | |
8356 | ||
8357 | ||
8358 | /* Empty the Tetris buffer, wait for 1s */ | |
8359 | do { | |
8360 | sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT); | |
8361 | blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT); | |
8362 | port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0); | |
8363 | port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1); | |
8364 | pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2); | |
8365 | if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && | |
8366 | ((port_is_idle_0 & 0x1) == 0x1) && | |
8367 | ((port_is_idle_1 & 0x1) == 0x1) && | |
8368 | (pgl_exp_rom2 == 0xffffffff)) | |
8369 | break; | |
c9ee9206 | 8370 | usleep_range(1000, 1000); |
72fd0718 VZ |
8371 | } while (cnt-- > 0); |
8372 | ||
8373 | if (cnt <= 0) { | |
51c1a580 MS |
8374 | BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n"); |
8375 | 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 |
8376 | sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, |
8377 | pgl_exp_rom2); | |
8378 | return -EAGAIN; | |
8379 | } | |
8380 | ||
8381 | barrier(); | |
8382 | ||
8383 | /* Close gates #2, #3 and #4 */ | |
8384 | bnx2x_set_234_gates(bp, true); | |
8385 | ||
c9ee9206 VZ |
8386 | /* Poll for IGU VQs for 57712 and newer chips */ |
8387 | if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp)) | |
8388 | return -EAGAIN; | |
8389 | ||
8390 | ||
72fd0718 VZ |
8391 | /* TBD: Indicate that "process kill" is in progress to MCP */ |
8392 | ||
8393 | /* Clear "unprepared" bit */ | |
8394 | REG_WR(bp, MISC_REG_UNPREPARED, 0); | |
8395 | barrier(); | |
8396 | ||
8397 | /* Make sure all is written to the chip before the reset */ | |
8398 | mmiowb(); | |
8399 | ||
8400 | /* Wait for 1ms to empty GLUE and PCI-E core queues, | |
8401 | * PSWHST, GRC and PSWRD Tetris buffer. | |
8402 | */ | |
c9ee9206 | 8403 | usleep_range(1000, 1000); |
72fd0718 VZ |
8404 | |
8405 | /* Prepare to chip reset: */ | |
8406 | /* MCP */ | |
c9ee9206 VZ |
8407 | if (global) |
8408 | bnx2x_reset_mcp_prep(bp, &val); | |
72fd0718 VZ |
8409 | |
8410 | /* PXP */ | |
8411 | bnx2x_pxp_prep(bp); | |
8412 | barrier(); | |
8413 | ||
8414 | /* reset the chip */ | |
c9ee9206 | 8415 | bnx2x_process_kill_chip_reset(bp, global); |
72fd0718 VZ |
8416 | barrier(); |
8417 | ||
8418 | /* Recover after reset: */ | |
8419 | /* MCP */ | |
c9ee9206 | 8420 | if (global && bnx2x_reset_mcp_comp(bp, val)) |
72fd0718 VZ |
8421 | return -EAGAIN; |
8422 | ||
c9ee9206 VZ |
8423 | /* TBD: Add resetting the NO_MCP mode DB here */ |
8424 | ||
72fd0718 VZ |
8425 | /* PXP */ |
8426 | bnx2x_pxp_prep(bp); | |
8427 | ||
8428 | /* Open the gates #2, #3 and #4 */ | |
8429 | bnx2x_set_234_gates(bp, false); | |
8430 | ||
8431 | /* TBD: IGU/AEU preparation bring back the AEU/IGU to a | |
8432 | * reset state, re-enable attentions. */ | |
8433 | ||
a2fbb9ea ET |
8434 | return 0; |
8435 | } | |
8436 | ||
c9ee9206 | 8437 | int bnx2x_leader_reset(struct bnx2x *bp) |
72fd0718 VZ |
8438 | { |
8439 | int rc = 0; | |
c9ee9206 | 8440 | bool global = bnx2x_reset_is_global(bp); |
95c6c616 AE |
8441 | u32 load_code; |
8442 | ||
8443 | /* if not going to reset MCP - load "fake" driver to reset HW while | |
8444 | * driver is owner of the HW | |
8445 | */ | |
8446 | if (!global && !BP_NOMCP(bp)) { | |
8447 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0); | |
8448 | if (!load_code) { | |
8449 | BNX2X_ERR("MCP response failure, aborting\n"); | |
8450 | rc = -EAGAIN; | |
8451 | goto exit_leader_reset; | |
8452 | } | |
8453 | if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) && | |
8454 | (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) { | |
8455 | BNX2X_ERR("MCP unexpected resp, aborting\n"); | |
8456 | rc = -EAGAIN; | |
8457 | goto exit_leader_reset2; | |
8458 | } | |
8459 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0); | |
8460 | if (!load_code) { | |
8461 | BNX2X_ERR("MCP response failure, aborting\n"); | |
8462 | rc = -EAGAIN; | |
8463 | goto exit_leader_reset2; | |
8464 | } | |
8465 | } | |
c9ee9206 | 8466 | |
72fd0718 | 8467 | /* Try to recover after the failure */ |
c9ee9206 | 8468 | if (bnx2x_process_kill(bp, global)) { |
51c1a580 MS |
8469 | BNX2X_ERR("Something bad had happen on engine %d! Aii!\n", |
8470 | BP_PATH(bp)); | |
72fd0718 | 8471 | rc = -EAGAIN; |
95c6c616 | 8472 | goto exit_leader_reset2; |
72fd0718 VZ |
8473 | } |
8474 | ||
c9ee9206 VZ |
8475 | /* |
8476 | * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver | |
8477 | * state. | |
8478 | */ | |
72fd0718 | 8479 | bnx2x_set_reset_done(bp); |
c9ee9206 VZ |
8480 | if (global) |
8481 | bnx2x_clear_reset_global(bp); | |
72fd0718 | 8482 | |
95c6c616 AE |
8483 | exit_leader_reset2: |
8484 | /* unload "fake driver" if it was loaded */ | |
8485 | if (!global && !BP_NOMCP(bp)) { | |
8486 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0); | |
8487 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); | |
8488 | } | |
72fd0718 VZ |
8489 | exit_leader_reset: |
8490 | bp->is_leader = 0; | |
c9ee9206 VZ |
8491 | bnx2x_release_leader_lock(bp); |
8492 | smp_mb(); | |
72fd0718 VZ |
8493 | return rc; |
8494 | } | |
8495 | ||
c9ee9206 VZ |
8496 | static inline void bnx2x_recovery_failed(struct bnx2x *bp) |
8497 | { | |
8498 | netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n"); | |
8499 | ||
8500 | /* Disconnect this device */ | |
8501 | netif_device_detach(bp->dev); | |
8502 | ||
8503 | /* | |
8504 | * Block ifup for all function on this engine until "process kill" | |
8505 | * or power cycle. | |
8506 | */ | |
8507 | bnx2x_set_reset_in_progress(bp); | |
8508 | ||
8509 | /* Shut down the power */ | |
8510 | bnx2x_set_power_state(bp, PCI_D3hot); | |
8511 | ||
8512 | bp->recovery_state = BNX2X_RECOVERY_FAILED; | |
8513 | ||
8514 | smp_mb(); | |
8515 | } | |
8516 | ||
8517 | /* | |
8518 | * Assumption: runs under rtnl lock. This together with the fact | |
6383c0b3 | 8519 | * that it's called only from bnx2x_sp_rtnl() ensure that it |
72fd0718 VZ |
8520 | * will never be called when netif_running(bp->dev) is false. |
8521 | */ | |
8522 | static void bnx2x_parity_recover(struct bnx2x *bp) | |
8523 | { | |
c9ee9206 | 8524 | bool global = false; |
7a752993 | 8525 | u32 error_recovered, error_unrecovered; |
95c6c616 | 8526 | bool is_parity; |
c9ee9206 | 8527 | |
72fd0718 VZ |
8528 | DP(NETIF_MSG_HW, "Handling parity\n"); |
8529 | while (1) { | |
8530 | switch (bp->recovery_state) { | |
8531 | case BNX2X_RECOVERY_INIT: | |
8532 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n"); | |
95c6c616 AE |
8533 | is_parity = bnx2x_chk_parity_attn(bp, &global, false); |
8534 | WARN_ON(!is_parity); | |
c9ee9206 | 8535 | |
72fd0718 | 8536 | /* Try to get a LEADER_LOCK HW lock */ |
c9ee9206 VZ |
8537 | if (bnx2x_trylock_leader_lock(bp)) { |
8538 | bnx2x_set_reset_in_progress(bp); | |
8539 | /* | |
8540 | * Check if there is a global attention and if | |
8541 | * there was a global attention, set the global | |
8542 | * reset bit. | |
8543 | */ | |
8544 | ||
8545 | if (global) | |
8546 | bnx2x_set_reset_global(bp); | |
8547 | ||
72fd0718 | 8548 | bp->is_leader = 1; |
c9ee9206 | 8549 | } |
72fd0718 VZ |
8550 | |
8551 | /* Stop the driver */ | |
8552 | /* If interface has been removed - break */ | |
8553 | if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY)) | |
8554 | return; | |
8555 | ||
8556 | bp->recovery_state = BNX2X_RECOVERY_WAIT; | |
c9ee9206 | 8557 | |
c9ee9206 VZ |
8558 | /* Ensure "is_leader", MCP command sequence and |
8559 | * "recovery_state" update values are seen on other | |
8560 | * CPUs. | |
72fd0718 | 8561 | */ |
c9ee9206 | 8562 | smp_mb(); |
72fd0718 VZ |
8563 | break; |
8564 | ||
8565 | case BNX2X_RECOVERY_WAIT: | |
8566 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n"); | |
8567 | if (bp->is_leader) { | |
c9ee9206 | 8568 | int other_engine = BP_PATH(bp) ? 0 : 1; |
889b9af3 AE |
8569 | bool other_load_status = |
8570 | bnx2x_get_load_status(bp, other_engine); | |
8571 | bool load_status = | |
8572 | bnx2x_get_load_status(bp, BP_PATH(bp)); | |
c9ee9206 VZ |
8573 | global = bnx2x_reset_is_global(bp); |
8574 | ||
8575 | /* | |
8576 | * In case of a parity in a global block, let | |
8577 | * the first leader that performs a | |
8578 | * leader_reset() reset the global blocks in | |
8579 | * order to clear global attentions. Otherwise | |
8580 | * the the gates will remain closed for that | |
8581 | * engine. | |
8582 | */ | |
889b9af3 AE |
8583 | if (load_status || |
8584 | (global && other_load_status)) { | |
72fd0718 VZ |
8585 | /* Wait until all other functions get |
8586 | * down. | |
8587 | */ | |
7be08a72 | 8588 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
8589 | HZ/10); |
8590 | return; | |
8591 | } else { | |
8592 | /* If all other functions got down - | |
8593 | * try to bring the chip back to | |
8594 | * normal. In any case it's an exit | |
8595 | * point for a leader. | |
8596 | */ | |
c9ee9206 VZ |
8597 | if (bnx2x_leader_reset(bp)) { |
8598 | bnx2x_recovery_failed(bp); | |
72fd0718 VZ |
8599 | return; |
8600 | } | |
8601 | ||
c9ee9206 VZ |
8602 | /* If we are here, means that the |
8603 | * leader has succeeded and doesn't | |
8604 | * want to be a leader any more. Try | |
8605 | * to continue as a none-leader. | |
8606 | */ | |
8607 | break; | |
72fd0718 VZ |
8608 | } |
8609 | } else { /* non-leader */ | |
c9ee9206 | 8610 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) { |
72fd0718 VZ |
8611 | /* Try to get a LEADER_LOCK HW lock as |
8612 | * long as a former leader may have | |
8613 | * been unloaded by the user or | |
8614 | * released a leadership by another | |
8615 | * reason. | |
8616 | */ | |
c9ee9206 | 8617 | if (bnx2x_trylock_leader_lock(bp)) { |
72fd0718 VZ |
8618 | /* I'm a leader now! Restart a |
8619 | * switch case. | |
8620 | */ | |
8621 | bp->is_leader = 1; | |
8622 | break; | |
8623 | } | |
8624 | ||
7be08a72 | 8625 | schedule_delayed_work(&bp->sp_rtnl_task, |
72fd0718 VZ |
8626 | HZ/10); |
8627 | return; | |
8628 | ||
c9ee9206 VZ |
8629 | } else { |
8630 | /* | |
8631 | * If there was a global attention, wait | |
8632 | * for it to be cleared. | |
8633 | */ | |
8634 | if (bnx2x_reset_is_global(bp)) { | |
8635 | schedule_delayed_work( | |
7be08a72 AE |
8636 | &bp->sp_rtnl_task, |
8637 | HZ/10); | |
c9ee9206 VZ |
8638 | return; |
8639 | } | |
8640 | ||
7a752993 AE |
8641 | error_recovered = |
8642 | bp->eth_stats.recoverable_error; | |
8643 | error_unrecovered = | |
8644 | bp->eth_stats.unrecoverable_error; | |
95c6c616 AE |
8645 | bp->recovery_state = |
8646 | BNX2X_RECOVERY_NIC_LOADING; | |
8647 | if (bnx2x_nic_load(bp, LOAD_NORMAL)) { | |
7a752993 | 8648 | error_unrecovered++; |
95c6c616 | 8649 | netdev_err(bp->dev, |
51c1a580 | 8650 | "Recovery failed. Power cycle needed\n"); |
95c6c616 AE |
8651 | /* Disconnect this device */ |
8652 | netif_device_detach(bp->dev); | |
8653 | /* Shut down the power */ | |
8654 | bnx2x_set_power_state( | |
8655 | bp, PCI_D3hot); | |
8656 | smp_mb(); | |
8657 | } else { | |
c9ee9206 VZ |
8658 | bp->recovery_state = |
8659 | BNX2X_RECOVERY_DONE; | |
7a752993 | 8660 | error_recovered++; |
c9ee9206 VZ |
8661 | smp_mb(); |
8662 | } | |
7a752993 AE |
8663 | bp->eth_stats.recoverable_error = |
8664 | error_recovered; | |
8665 | bp->eth_stats.unrecoverable_error = | |
8666 | error_unrecovered; | |
c9ee9206 | 8667 | |
72fd0718 VZ |
8668 | return; |
8669 | } | |
8670 | } | |
8671 | default: | |
8672 | return; | |
8673 | } | |
8674 | } | |
8675 | } | |
8676 | ||
56ad3152 MS |
8677 | static int bnx2x_close(struct net_device *dev); |
8678 | ||
72fd0718 VZ |
8679 | /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is |
8680 | * scheduled on a general queue in order to prevent a dead lock. | |
8681 | */ | |
7be08a72 | 8682 | static void bnx2x_sp_rtnl_task(struct work_struct *work) |
34f80b04 | 8683 | { |
7be08a72 | 8684 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work); |
34f80b04 EG |
8685 | |
8686 | rtnl_lock(); | |
8687 | ||
8688 | if (!netif_running(bp->dev)) | |
7be08a72 AE |
8689 | goto sp_rtnl_exit; |
8690 | ||
8691 | /* if stop on error is defined no recovery flows should be executed */ | |
8692 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 | 8693 | BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n" |
7be08a72 | 8694 | "you will need to reboot when done\n"); |
b1fb8740 | 8695 | goto sp_rtnl_not_reset; |
7be08a72 | 8696 | #endif |
34f80b04 | 8697 | |
7be08a72 AE |
8698 | if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) { |
8699 | /* | |
b1fb8740 VZ |
8700 | * Clear all pending SP commands as we are going to reset the |
8701 | * function anyway. | |
7be08a72 | 8702 | */ |
b1fb8740 VZ |
8703 | bp->sp_rtnl_state = 0; |
8704 | smp_mb(); | |
8705 | ||
72fd0718 | 8706 | bnx2x_parity_recover(bp); |
b1fb8740 VZ |
8707 | |
8708 | goto sp_rtnl_exit; | |
8709 | } | |
8710 | ||
8711 | if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) { | |
8712 | /* | |
8713 | * Clear all pending SP commands as we are going to reset the | |
8714 | * function anyway. | |
8715 | */ | |
8716 | bp->sp_rtnl_state = 0; | |
8717 | smp_mb(); | |
8718 | ||
72fd0718 VZ |
8719 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
8720 | bnx2x_nic_load(bp, LOAD_NORMAL); | |
b1fb8740 VZ |
8721 | |
8722 | goto sp_rtnl_exit; | |
72fd0718 | 8723 | } |
b1fb8740 VZ |
8724 | #ifdef BNX2X_STOP_ON_ERROR |
8725 | sp_rtnl_not_reset: | |
8726 | #endif | |
8727 | if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state)) | |
8728 | bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos); | |
34f80b04 | 8729 | |
8304859a AE |
8730 | /* |
8731 | * in case of fan failure we need to reset id if the "stop on error" | |
8732 | * debug flag is set, since we trying to prevent permanent overheating | |
8733 | * damage | |
8734 | */ | |
8735 | if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) { | |
51c1a580 | 8736 | DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n"); |
8304859a AE |
8737 | netif_device_detach(bp->dev); |
8738 | bnx2x_close(bp->dev); | |
8739 | } | |
8740 | ||
7be08a72 | 8741 | sp_rtnl_exit: |
34f80b04 EG |
8742 | rtnl_unlock(); |
8743 | } | |
8744 | ||
a2fbb9ea ET |
8745 | /* end of nic load/unload */ |
8746 | ||
3deb8167 YR |
8747 | static void bnx2x_period_task(struct work_struct *work) |
8748 | { | |
8749 | struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work); | |
8750 | ||
8751 | if (!netif_running(bp->dev)) | |
8752 | goto period_task_exit; | |
8753 | ||
8754 | if (CHIP_REV_IS_SLOW(bp)) { | |
8755 | BNX2X_ERR("period task called on emulation, ignoring\n"); | |
8756 | goto period_task_exit; | |
8757 | } | |
8758 | ||
8759 | bnx2x_acquire_phy_lock(bp); | |
8760 | /* | |
8761 | * The barrier is needed to ensure the ordering between the writing to | |
8762 | * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and | |
8763 | * the reading here. | |
8764 | */ | |
8765 | smp_mb(); | |
8766 | if (bp->port.pmf) { | |
8767 | bnx2x_period_func(&bp->link_params, &bp->link_vars); | |
8768 | ||
8769 | /* Re-queue task in 1 sec */ | |
8770 | queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ); | |
8771 | } | |
8772 | ||
8773 | bnx2x_release_phy_lock(bp); | |
8774 | period_task_exit: | |
8775 | return; | |
8776 | } | |
8777 | ||
a2fbb9ea ET |
8778 | /* |
8779 | * Init service functions | |
8780 | */ | |
8781 | ||
8d96286a | 8782 | static u32 bnx2x_get_pretend_reg(struct bnx2x *bp) |
f2e0899f DK |
8783 | { |
8784 | u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; | |
8785 | u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; | |
8786 | return base + (BP_ABS_FUNC(bp)) * stride; | |
f1ef27ef EG |
8787 | } |
8788 | ||
f2e0899f | 8789 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp) |
f1ef27ef | 8790 | { |
f2e0899f | 8791 | u32 reg = bnx2x_get_pretend_reg(bp); |
f1ef27ef EG |
8792 | |
8793 | /* Flush all outstanding writes */ | |
8794 | mmiowb(); | |
8795 | ||
8796 | /* Pretend to be function 0 */ | |
8797 | REG_WR(bp, reg, 0); | |
f2e0899f | 8798 | REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */ |
f1ef27ef EG |
8799 | |
8800 | /* From now we are in the "like-E1" mode */ | |
8801 | bnx2x_int_disable(bp); | |
8802 | ||
8803 | /* Flush all outstanding writes */ | |
8804 | mmiowb(); | |
8805 | ||
f2e0899f DK |
8806 | /* Restore the original function */ |
8807 | REG_WR(bp, reg, BP_ABS_FUNC(bp)); | |
8808 | REG_RD(bp, reg); | |
f1ef27ef EG |
8809 | } |
8810 | ||
f2e0899f | 8811 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp) |
f1ef27ef | 8812 | { |
f2e0899f | 8813 | if (CHIP_IS_E1(bp)) |
f1ef27ef | 8814 | bnx2x_int_disable(bp); |
f2e0899f DK |
8815 | else |
8816 | bnx2x_undi_int_disable_e1h(bp); | |
f1ef27ef EG |
8817 | } |
8818 | ||
452427b0 | 8819 | static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp) |
34f80b04 | 8820 | { |
452427b0 YM |
8821 | u32 val, base_addr, offset, mask, reset_reg; |
8822 | bool mac_stopped = false; | |
8823 | u8 port = BP_PORT(bp); | |
34f80b04 | 8824 | |
452427b0 | 8825 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2); |
f16da43b | 8826 | |
452427b0 YM |
8827 | if (!CHIP_IS_E3(bp)) { |
8828 | val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4); | |
8829 | mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port; | |
8830 | if ((mask & reset_reg) && val) { | |
8831 | u32 wb_data[2]; | |
8832 | BNX2X_DEV_INFO("Disable bmac Rx\n"); | |
8833 | base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM | |
8834 | : NIG_REG_INGRESS_BMAC0_MEM; | |
8835 | offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL | |
8836 | : BIGMAC_REGISTER_BMAC_CONTROL; | |
7a06a122 | 8837 | |
452427b0 YM |
8838 | /* |
8839 | * use rd/wr since we cannot use dmae. This is safe | |
8840 | * since MCP won't access the bus due to the request | |
8841 | * to unload, and no function on the path can be | |
8842 | * loaded at this time. | |
8843 | */ | |
8844 | wb_data[0] = REG_RD(bp, base_addr + offset); | |
8845 | wb_data[1] = REG_RD(bp, base_addr + offset + 0x4); | |
8846 | wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE; | |
8847 | REG_WR(bp, base_addr + offset, wb_data[0]); | |
8848 | REG_WR(bp, base_addr + offset + 0x4, wb_data[1]); | |
8849 | ||
8850 | } | |
8851 | BNX2X_DEV_INFO("Disable emac Rx\n"); | |
8852 | REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0); | |
8853 | ||
8854 | mac_stopped = true; | |
8855 | } else { | |
8856 | if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) { | |
8857 | BNX2X_DEV_INFO("Disable xmac Rx\n"); | |
8858 | base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0; | |
8859 | val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI); | |
8860 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
8861 | val & ~(1 << 1)); | |
8862 | REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI, | |
8863 | val | (1 << 1)); | |
8864 | REG_WR(bp, base_addr + XMAC_REG_CTRL, 0); | |
8865 | mac_stopped = true; | |
8866 | } | |
8867 | mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port; | |
8868 | if (mask & reset_reg) { | |
8869 | BNX2X_DEV_INFO("Disable umac Rx\n"); | |
8870 | base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0; | |
8871 | REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0); | |
8872 | mac_stopped = true; | |
8873 | } | |
8874 | } | |
8875 | ||
8876 | if (mac_stopped) | |
8877 | msleep(20); | |
8878 | ||
8879 | } | |
8880 | ||
8881 | #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4)) | |
8882 | #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff) | |
8883 | #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff) | |
8884 | #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq)) | |
8885 | ||
8886 | static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, | |
8887 | u8 inc) | |
8888 | { | |
8889 | u16 rcq, bd; | |
8890 | u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port)); | |
8891 | ||
8892 | rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc; | |
8893 | bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc; | |
8894 | ||
8895 | tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd); | |
8896 | REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg); | |
8897 | ||
8898 | BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n", | |
8899 | port, bd, rcq); | |
8900 | } | |
8901 | ||
8902 | static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp) | |
8903 | { | |
8904 | u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); | |
8905 | if (!rc) { | |
8906 | BNX2X_ERR("MCP response failure, aborting\n"); | |
8907 | return -EBUSY; | |
8908 | } | |
8909 | ||
8910 | return 0; | |
8911 | } | |
8912 | ||
8913 | static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp) | |
8914 | { | |
8915 | struct bnx2x_prev_path_list *tmp_list; | |
8916 | int rc = false; | |
8917 | ||
8918 | if (down_trylock(&bnx2x_prev_sem)) | |
8919 | return false; | |
8920 | ||
8921 | list_for_each_entry(tmp_list, &bnx2x_prev_list, list) { | |
8922 | if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot && | |
8923 | bp->pdev->bus->number == tmp_list->bus && | |
8924 | BP_PATH(bp) == tmp_list->path) { | |
8925 | rc = true; | |
8926 | BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n", | |
8927 | BP_PATH(bp)); | |
8928 | break; | |
8929 | } | |
8930 | } | |
8931 | ||
8932 | up(&bnx2x_prev_sem); | |
8933 | ||
8934 | return rc; | |
8935 | } | |
8936 | ||
8937 | static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp) | |
8938 | { | |
8939 | struct bnx2x_prev_path_list *tmp_list; | |
8940 | int rc; | |
8941 | ||
8942 | tmp_list = (struct bnx2x_prev_path_list *) | |
8943 | kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL); | |
8944 | if (!tmp_list) { | |
8945 | BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n"); | |
8946 | return -ENOMEM; | |
8947 | } | |
8948 | ||
8949 | tmp_list->bus = bp->pdev->bus->number; | |
8950 | tmp_list->slot = PCI_SLOT(bp->pdev->devfn); | |
8951 | tmp_list->path = BP_PATH(bp); | |
8952 | ||
8953 | rc = down_interruptible(&bnx2x_prev_sem); | |
8954 | if (rc) { | |
8955 | BNX2X_ERR("Received %d when tried to take lock\n", rc); | |
8956 | kfree(tmp_list); | |
8957 | } else { | |
8958 | BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n", | |
8959 | BP_PATH(bp)); | |
8960 | list_add(&tmp_list->list, &bnx2x_prev_list); | |
8961 | up(&bnx2x_prev_sem); | |
8962 | } | |
8963 | ||
8964 | return rc; | |
8965 | } | |
8966 | ||
8967 | static bool __devinit bnx2x_can_flr(struct bnx2x *bp) | |
8968 | { | |
8969 | int pos; | |
8970 | u32 cap; | |
8971 | struct pci_dev *dev = bp->pdev; | |
8972 | ||
8973 | pos = pci_pcie_cap(dev); | |
8974 | if (!pos) | |
8975 | return false; | |
8976 | ||
8977 | pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap); | |
8978 | if (!(cap & PCI_EXP_DEVCAP_FLR)) | |
8979 | return false; | |
8980 | ||
8981 | return true; | |
8982 | } | |
8983 | ||
8984 | static int __devinit bnx2x_do_flr(struct bnx2x *bp) | |
8985 | { | |
8986 | int i, pos; | |
8987 | u16 status; | |
8988 | struct pci_dev *dev = bp->pdev; | |
8989 | ||
8990 | /* probe the capability first */ | |
8991 | if (bnx2x_can_flr(bp)) | |
8992 | return -ENOTTY; | |
8993 | ||
8994 | pos = pci_pcie_cap(dev); | |
8995 | if (!pos) | |
8996 | return -ENOTTY; | |
8997 | ||
8998 | /* Wait for Transaction Pending bit clean */ | |
8999 | for (i = 0; i < 4; i++) { | |
9000 | if (i) | |
9001 | msleep((1 << (i - 1)) * 100); | |
9002 | ||
9003 | pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); | |
9004 | if (!(status & PCI_EXP_DEVSTA_TRPND)) | |
9005 | goto clear; | |
9006 | } | |
9007 | ||
9008 | dev_err(&dev->dev, | |
9009 | "transaction is not cleared; proceeding with reset anyway\n"); | |
9010 | ||
9011 | clear: | |
9012 | if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) { | |
9013 | BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n", | |
9014 | bp->common.bc_ver); | |
9015 | return -EINVAL; | |
9016 | } | |
9017 | ||
9018 | bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0); | |
9019 | ||
9020 | return 0; | |
9021 | } | |
9022 | ||
9023 | static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp) | |
9024 | { | |
9025 | int rc; | |
9026 | ||
9027 | BNX2X_DEV_INFO("Uncommon unload Flow\n"); | |
9028 | ||
9029 | /* Test if previous unload process was already finished for this path */ | |
9030 | if (bnx2x_prev_is_path_marked(bp)) | |
9031 | return bnx2x_prev_mcp_done(bp); | |
9032 | ||
9033 | /* If function has FLR capabilities, and existing FW version matches | |
9034 | * the one required, then FLR will be sufficient to clean any residue | |
9035 | * left by previous driver | |
9036 | */ | |
9037 | if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp)) | |
9038 | return bnx2x_do_flr(bp); | |
9039 | ||
9040 | /* Close the MCP request, return failure*/ | |
9041 | rc = bnx2x_prev_mcp_done(bp); | |
9042 | if (!rc) | |
9043 | rc = BNX2X_PREV_WAIT_NEEDED; | |
9044 | ||
9045 | return rc; | |
9046 | } | |
9047 | ||
9048 | static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp) | |
9049 | { | |
9050 | u32 reset_reg, tmp_reg = 0, rc; | |
9051 | /* It is possible a previous function received 'common' answer, | |
9052 | * but hasn't loaded yet, therefore creating a scenario of | |
9053 | * multiple functions receiving 'common' on the same path. | |
9054 | */ | |
9055 | BNX2X_DEV_INFO("Common unload Flow\n"); | |
9056 | ||
9057 | if (bnx2x_prev_is_path_marked(bp)) | |
9058 | return bnx2x_prev_mcp_done(bp); | |
9059 | ||
9060 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1); | |
9061 | ||
9062 | /* Reset should be performed after BRB is emptied */ | |
9063 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) { | |
9064 | u32 timer_count = 1000; | |
9065 | bool prev_undi = false; | |
9066 | ||
9067 | /* Close the MAC Rx to prevent BRB from filling up */ | |
9068 | bnx2x_prev_unload_close_mac(bp); | |
9069 | ||
9070 | /* Check if the UNDI driver was previously loaded | |
34f80b04 EG |
9071 | * UNDI driver initializes CID offset for normal bell to 0x7 |
9072 | */ | |
452427b0 YM |
9073 | reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1); |
9074 | if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) { | |
9075 | tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST); | |
9076 | if (tmp_reg == 0x7) { | |
9077 | BNX2X_DEV_INFO("UNDI previously loaded\n"); | |
9078 | prev_undi = true; | |
9079 | /* clear the UNDI indication */ | |
9080 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); | |
34f80b04 | 9081 | } |
452427b0 YM |
9082 | } |
9083 | /* wait until BRB is empty */ | |
9084 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); | |
9085 | while (timer_count) { | |
9086 | u32 prev_brb = tmp_reg; | |
34f80b04 | 9087 | |
452427b0 YM |
9088 | tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS); |
9089 | if (!tmp_reg) | |
9090 | break; | |
619c5cb6 | 9091 | |
452427b0 | 9092 | BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg); |
619c5cb6 | 9093 | |
452427b0 YM |
9094 | /* reset timer as long as BRB actually gets emptied */ |
9095 | if (prev_brb > tmp_reg) | |
9096 | timer_count = 1000; | |
9097 | else | |
9098 | timer_count--; | |
da5a662a | 9099 | |
452427b0 YM |
9100 | /* If UNDI resides in memory, manually increment it */ |
9101 | if (prev_undi) | |
9102 | bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1); | |
da5a662a | 9103 | |
452427b0 | 9104 | udelay(10); |
7a06a122 | 9105 | } |
452427b0 YM |
9106 | |
9107 | if (!timer_count) | |
9108 | BNX2X_ERR("Failed to empty BRB, hope for the best\n"); | |
9109 | ||
34f80b04 | 9110 | } |
f16da43b | 9111 | |
452427b0 YM |
9112 | /* No packets are in the pipeline, path is ready for reset */ |
9113 | bnx2x_reset_common(bp); | |
9114 | ||
9115 | rc = bnx2x_prev_mark_path(bp); | |
9116 | if (rc) { | |
9117 | bnx2x_prev_mcp_done(bp); | |
9118 | return rc; | |
9119 | } | |
9120 | ||
9121 | return bnx2x_prev_mcp_done(bp); | |
9122 | } | |
9123 | ||
9124 | static int __devinit bnx2x_prev_unload(struct bnx2x *bp) | |
9125 | { | |
9126 | int time_counter = 10; | |
9127 | u32 rc, fw, hw_lock_reg, hw_lock_val; | |
9128 | BNX2X_DEV_INFO("Entering Previous Unload Flow\n"); | |
9129 | ||
9130 | /* Release previously held locks */ | |
9131 | hw_lock_reg = (BP_FUNC(bp) <= 5) ? | |
9132 | (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) : | |
9133 | (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8); | |
9134 | ||
9135 | hw_lock_val = (REG_RD(bp, hw_lock_reg)); | |
9136 | if (hw_lock_val) { | |
9137 | if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) { | |
9138 | BNX2X_DEV_INFO("Release Previously held NVRAM lock\n"); | |
9139 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, | |
9140 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp))); | |
9141 | } | |
9142 | ||
9143 | BNX2X_DEV_INFO("Release Previously held hw lock\n"); | |
9144 | REG_WR(bp, hw_lock_reg, 0xffffffff); | |
9145 | } else | |
9146 | BNX2X_DEV_INFO("No need to release hw/nvram locks\n"); | |
9147 | ||
9148 | if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) { | |
9149 | BNX2X_DEV_INFO("Release previously held alr\n"); | |
9150 | REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0); | |
9151 | } | |
9152 | ||
9153 | ||
9154 | do { | |
9155 | /* Lock MCP using an unload request */ | |
9156 | fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0); | |
9157 | if (!fw) { | |
9158 | BNX2X_ERR("MCP response failure, aborting\n"); | |
9159 | rc = -EBUSY; | |
9160 | break; | |
9161 | } | |
9162 | ||
9163 | if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) { | |
9164 | rc = bnx2x_prev_unload_common(bp); | |
9165 | break; | |
9166 | } | |
9167 | ||
9168 | /* non-common reply from MCP night require looping */ | |
9169 | rc = bnx2x_prev_unload_uncommon(bp); | |
9170 | if (rc != BNX2X_PREV_WAIT_NEEDED) | |
9171 | break; | |
9172 | ||
9173 | msleep(20); | |
9174 | } while (--time_counter); | |
9175 | ||
9176 | if (!time_counter || rc) { | |
9177 | BNX2X_ERR("Failed unloading previous driver, aborting\n"); | |
9178 | rc = -EBUSY; | |
9179 | } | |
9180 | ||
9181 | BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc); | |
9182 | ||
9183 | return rc; | |
34f80b04 EG |
9184 | } |
9185 | ||
9186 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) | |
9187 | { | |
1d187b34 | 9188 | u32 val, val2, val3, val4, id, boot_mode; |
72ce58c3 | 9189 | u16 pmc; |
34f80b04 EG |
9190 | |
9191 | /* Get the chip revision id and number. */ | |
9192 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ | |
9193 | val = REG_RD(bp, MISC_REG_CHIP_NUM); | |
9194 | id = ((val & 0xffff) << 16); | |
9195 | val = REG_RD(bp, MISC_REG_CHIP_REV); | |
9196 | id |= ((val & 0xf) << 12); | |
9197 | val = REG_RD(bp, MISC_REG_CHIP_METAL); | |
9198 | id |= ((val & 0xff) << 4); | |
5a40e08e | 9199 | val = REG_RD(bp, MISC_REG_BOND_ID); |
34f80b04 EG |
9200 | id |= (val & 0xf); |
9201 | bp->common.chip_id = id; | |
523224a3 DK |
9202 | |
9203 | /* Set doorbell size */ | |
9204 | bp->db_size = (1 << BNX2X_DB_SHIFT); | |
9205 | ||
619c5cb6 | 9206 | if (!CHIP_IS_E1x(bp)) { |
f2e0899f DK |
9207 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR); |
9208 | if ((val & 1) == 0) | |
9209 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN); | |
9210 | else | |
9211 | val = (val >> 1) & 1; | |
9212 | BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" : | |
9213 | "2_PORT_MODE"); | |
9214 | bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE : | |
9215 | CHIP_2_PORT_MODE; | |
9216 | ||
9217 | if (CHIP_MODE_IS_4_PORT(bp)) | |
9218 | bp->pfid = (bp->pf_num >> 1); /* 0..3 */ | |
9219 | else | |
9220 | bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */ | |
9221 | } else { | |
9222 | bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */ | |
9223 | bp->pfid = bp->pf_num; /* 0..7 */ | |
9224 | } | |
9225 | ||
51c1a580 MS |
9226 | BNX2X_DEV_INFO("pf_id: %x", bp->pfid); |
9227 | ||
f2e0899f DK |
9228 | bp->link_params.chip_id = bp->common.chip_id; |
9229 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); | |
523224a3 | 9230 | |
1c06328c EG |
9231 | val = (REG_RD(bp, 0x2874) & 0x55); |
9232 | if ((bp->common.chip_id & 0x1) || | |
9233 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { | |
9234 | bp->flags |= ONE_PORT_FLAG; | |
9235 | BNX2X_DEV_INFO("single port device\n"); | |
9236 | } | |
9237 | ||
34f80b04 | 9238 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
754a2f52 | 9239 | bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE << |
34f80b04 EG |
9240 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
9241 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", | |
9242 | bp->common.flash_size, bp->common.flash_size); | |
9243 | ||
1b6e2ceb DK |
9244 | bnx2x_init_shmem(bp); |
9245 | ||
619c5cb6 VZ |
9246 | |
9247 | ||
f2e0899f DK |
9248 | bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ? |
9249 | MISC_REG_GENERIC_CR_1 : | |
9250 | MISC_REG_GENERIC_CR_0)); | |
1b6e2ceb | 9251 | |
34f80b04 | 9252 | bp->link_params.shmem_base = bp->common.shmem_base; |
a22f0788 | 9253 | bp->link_params.shmem2_base = bp->common.shmem2_base; |
2691d51d EG |
9254 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
9255 | bp->common.shmem_base, bp->common.shmem2_base); | |
34f80b04 | 9256 | |
f2e0899f | 9257 | if (!bp->common.shmem_base) { |
34f80b04 EG |
9258 | BNX2X_DEV_INFO("MCP not active\n"); |
9259 | bp->flags |= NO_MCP_FLAG; | |
9260 | return; | |
9261 | } | |
9262 | ||
34f80b04 | 9263 | bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config); |
35b19ba5 | 9264 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
34f80b04 EG |
9265 | |
9266 | bp->link_params.hw_led_mode = ((bp->common.hw_config & | |
9267 | SHARED_HW_CFG_LED_MODE_MASK) >> | |
9268 | SHARED_HW_CFG_LED_MODE_SHIFT); | |
9269 | ||
c2c8b03e EG |
9270 | bp->link_params.feature_config_flags = 0; |
9271 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); | |
9272 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) | |
9273 | bp->link_params.feature_config_flags |= | |
9274 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
9275 | else | |
9276 | bp->link_params.feature_config_flags &= | |
9277 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; | |
9278 | ||
34f80b04 EG |
9279 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
9280 | bp->common.bc_ver = val; | |
9281 | BNX2X_DEV_INFO("bc_ver %X\n", val); | |
9282 | if (val < BNX2X_BC_VER) { | |
9283 | /* for now only warn | |
9284 | * later we might need to enforce this */ | |
51c1a580 MS |
9285 | BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n", |
9286 | BNX2X_BC_VER, val); | |
34f80b04 | 9287 | } |
4d295db0 | 9288 | bp->link_params.feature_config_flags |= |
a22f0788 | 9289 | (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ? |
f85582f8 DK |
9290 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
9291 | ||
a22f0788 YR |
9292 | bp->link_params.feature_config_flags |= |
9293 | (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ? | |
9294 | FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0; | |
72ce58c3 | 9295 | |
85242eea YR |
9296 | bp->link_params.feature_config_flags |= |
9297 | (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ? | |
9298 | FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0; | |
0e898dd7 BW |
9299 | bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ? |
9300 | BC_SUPPORTS_PFC_STATS : 0; | |
85242eea | 9301 | |
1d187b34 BW |
9302 | boot_mode = SHMEM_RD(bp, |
9303 | dev_info.port_feature_config[BP_PORT(bp)].mba_config) & | |
9304 | PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK; | |
9305 | switch (boot_mode) { | |
9306 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE: | |
9307 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE; | |
9308 | break; | |
9309 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB: | |
9310 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI; | |
9311 | break; | |
9312 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT: | |
9313 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE; | |
9314 | break; | |
9315 | case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE: | |
9316 | bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE; | |
9317 | break; | |
9318 | } | |
9319 | ||
f9a3ebbe DK |
9320 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
9321 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; | |
9322 | ||
72ce58c3 | 9323 | BNX2X_DEV_INFO("%sWoL capable\n", |
f5372251 | 9324 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
34f80b04 EG |
9325 | |
9326 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); | |
9327 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); | |
9328 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); | |
9329 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); | |
9330 | ||
cdaa7cb8 VZ |
9331 | dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n", |
9332 | val, val2, val3, val4); | |
34f80b04 EG |
9333 | } |
9334 | ||
f2e0899f DK |
9335 | #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) |
9336 | #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) | |
9337 | ||
9338 | static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp) | |
9339 | { | |
9340 | int pfid = BP_FUNC(bp); | |
f2e0899f DK |
9341 | int igu_sb_id; |
9342 | u32 val; | |
6383c0b3 | 9343 | u8 fid, igu_sb_cnt = 0; |
f2e0899f DK |
9344 | |
9345 | bp->igu_base_sb = 0xff; | |
f2e0899f | 9346 | if (CHIP_INT_MODE_IS_BC(bp)) { |
3395a033 | 9347 | int vn = BP_VN(bp); |
6383c0b3 | 9348 | igu_sb_cnt = bp->igu_sb_cnt; |
f2e0899f DK |
9349 | bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) * |
9350 | FP_SB_MAX_E1x; | |
9351 | ||
9352 | bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x + | |
9353 | (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn); | |
9354 | ||
9355 | return; | |
9356 | } | |
9357 | ||
9358 | /* IGU in normal mode - read CAM */ | |
9359 | for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; | |
9360 | igu_sb_id++) { | |
9361 | val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); | |
9362 | if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) | |
9363 | continue; | |
9364 | fid = IGU_FID(val); | |
9365 | if ((fid & IGU_FID_ENCODE_IS_PF)) { | |
9366 | if ((fid & IGU_FID_PF_NUM_MASK) != pfid) | |
9367 | continue; | |
9368 | if (IGU_VEC(val) == 0) | |
9369 | /* default status block */ | |
9370 | bp->igu_dsb_id = igu_sb_id; | |
9371 | else { | |
9372 | if (bp->igu_base_sb == 0xff) | |
9373 | bp->igu_base_sb = igu_sb_id; | |
6383c0b3 | 9374 | igu_sb_cnt++; |
f2e0899f DK |
9375 | } |
9376 | } | |
9377 | } | |
619c5cb6 | 9378 | |
6383c0b3 AE |
9379 | #ifdef CONFIG_PCI_MSI |
9380 | /* | |
9381 | * It's expected that number of CAM entries for this functions is equal | |
9382 | * to the number evaluated based on the MSI-X table size. We want a | |
9383 | * harsh warning if these values are different! | |
619c5cb6 | 9384 | */ |
6383c0b3 AE |
9385 | WARN_ON(bp->igu_sb_cnt != igu_sb_cnt); |
9386 | #endif | |
619c5cb6 | 9387 | |
6383c0b3 | 9388 | if (igu_sb_cnt == 0) |
f2e0899f DK |
9389 | BNX2X_ERR("CAM configuration error\n"); |
9390 | } | |
9391 | ||
34f80b04 EG |
9392 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
9393 | u32 switch_cfg) | |
a2fbb9ea | 9394 | { |
a22f0788 YR |
9395 | int cfg_size = 0, idx, port = BP_PORT(bp); |
9396 | ||
9397 | /* Aggregation of supported attributes of all external phys */ | |
9398 | bp->port.supported[0] = 0; | |
9399 | bp->port.supported[1] = 0; | |
b7737c9b YR |
9400 | switch (bp->link_params.num_phys) { |
9401 | case 1: | |
a22f0788 YR |
9402 | bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported; |
9403 | cfg_size = 1; | |
9404 | break; | |
b7737c9b | 9405 | case 2: |
a22f0788 YR |
9406 | bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported; |
9407 | cfg_size = 1; | |
9408 | break; | |
9409 | case 3: | |
9410 | if (bp->link_params.multi_phy_config & | |
9411 | PORT_HW_CFG_PHY_SWAPPED_ENABLED) { | |
9412 | bp->port.supported[1] = | |
9413 | bp->link_params.phy[EXT_PHY1].supported; | |
9414 | bp->port.supported[0] = | |
9415 | bp->link_params.phy[EXT_PHY2].supported; | |
9416 | } else { | |
9417 | bp->port.supported[0] = | |
9418 | bp->link_params.phy[EXT_PHY1].supported; | |
9419 | bp->port.supported[1] = | |
9420 | bp->link_params.phy[EXT_PHY2].supported; | |
9421 | } | |
9422 | cfg_size = 2; | |
9423 | break; | |
b7737c9b | 9424 | } |
a2fbb9ea | 9425 | |
a22f0788 | 9426 | if (!(bp->port.supported[0] || bp->port.supported[1])) { |
51c1a580 | 9427 | BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n", |
b7737c9b | 9428 | SHMEM_RD(bp, |
a22f0788 YR |
9429 | dev_info.port_hw_config[port].external_phy_config), |
9430 | SHMEM_RD(bp, | |
9431 | dev_info.port_hw_config[port].external_phy_config2)); | |
a2fbb9ea | 9432 | return; |
f85582f8 | 9433 | } |
a2fbb9ea | 9434 | |
619c5cb6 VZ |
9435 | if (CHIP_IS_E3(bp)) |
9436 | bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR); | |
9437 | else { | |
9438 | switch (switch_cfg) { | |
9439 | case SWITCH_CFG_1G: | |
9440 | bp->port.phy_addr = REG_RD( | |
9441 | bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); | |
9442 | break; | |
9443 | case SWITCH_CFG_10G: | |
9444 | bp->port.phy_addr = REG_RD( | |
9445 | bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); | |
9446 | break; | |
9447 | default: | |
9448 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", | |
9449 | bp->port.link_config[0]); | |
9450 | return; | |
9451 | } | |
a2fbb9ea | 9452 | } |
619c5cb6 | 9453 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
a22f0788 YR |
9454 | /* mask what we support according to speed_cap_mask per configuration */ |
9455 | for (idx = 0; idx < cfg_size; idx++) { | |
9456 | if (!(bp->link_params.speed_cap_mask[idx] & | |
c18487ee | 9457 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
a22f0788 | 9458 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half; |
a2fbb9ea | 9459 | |
a22f0788 | 9460 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9461 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
a22f0788 | 9462 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full; |
a2fbb9ea | 9463 | |
a22f0788 | 9464 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9465 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
a22f0788 | 9466 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half; |
a2fbb9ea | 9467 | |
a22f0788 | 9468 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9469 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
a22f0788 | 9470 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full; |
a2fbb9ea | 9471 | |
a22f0788 | 9472 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9473 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
a22f0788 | 9474 | bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half | |
f85582f8 | 9475 | SUPPORTED_1000baseT_Full); |
a2fbb9ea | 9476 | |
a22f0788 | 9477 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9478 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
a22f0788 | 9479 | bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full; |
a2fbb9ea | 9480 | |
a22f0788 | 9481 | if (!(bp->link_params.speed_cap_mask[idx] & |
c18487ee | 9482 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
a22f0788 YR |
9483 | bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full; |
9484 | ||
9485 | } | |
a2fbb9ea | 9486 | |
a22f0788 YR |
9487 | BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0], |
9488 | bp->port.supported[1]); | |
a2fbb9ea ET |
9489 | } |
9490 | ||
34f80b04 | 9491 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
a2fbb9ea | 9492 | { |
a22f0788 YR |
9493 | u32 link_config, idx, cfg_size = 0; |
9494 | bp->port.advertising[0] = 0; | |
9495 | bp->port.advertising[1] = 0; | |
9496 | switch (bp->link_params.num_phys) { | |
9497 | case 1: | |
9498 | case 2: | |
9499 | cfg_size = 1; | |
9500 | break; | |
9501 | case 3: | |
9502 | cfg_size = 2; | |
9503 | break; | |
9504 | } | |
9505 | for (idx = 0; idx < cfg_size; idx++) { | |
9506 | bp->link_params.req_duplex[idx] = DUPLEX_FULL; | |
9507 | link_config = bp->port.link_config[idx]; | |
9508 | switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { | |
f85582f8 | 9509 | case PORT_FEATURE_LINK_SPEED_AUTO: |
a22f0788 YR |
9510 | if (bp->port.supported[idx] & SUPPORTED_Autoneg) { |
9511 | bp->link_params.req_line_speed[idx] = | |
9512 | SPEED_AUTO_NEG; | |
9513 | bp->port.advertising[idx] |= | |
9514 | bp->port.supported[idx]; | |
10bd1f24 MY |
9515 | if (bp->link_params.phy[EXT_PHY1].type == |
9516 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) | |
9517 | bp->port.advertising[idx] |= | |
9518 | (SUPPORTED_100baseT_Half | | |
9519 | SUPPORTED_100baseT_Full); | |
f85582f8 DK |
9520 | } else { |
9521 | /* force 10G, no AN */ | |
a22f0788 YR |
9522 | bp->link_params.req_line_speed[idx] = |
9523 | SPEED_10000; | |
9524 | bp->port.advertising[idx] |= | |
9525 | (ADVERTISED_10000baseT_Full | | |
f85582f8 | 9526 | ADVERTISED_FIBRE); |
a22f0788 | 9527 | continue; |
f85582f8 DK |
9528 | } |
9529 | break; | |
a2fbb9ea | 9530 | |
f85582f8 | 9531 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
a22f0788 YR |
9532 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) { |
9533 | bp->link_params.req_line_speed[idx] = | |
9534 | SPEED_10; | |
9535 | bp->port.advertising[idx] |= | |
9536 | (ADVERTISED_10baseT_Full | | |
f85582f8 DK |
9537 | ADVERTISED_TP); |
9538 | } else { | |
51c1a580 | 9539 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 | 9540 | link_config, |
a22f0788 | 9541 | bp->link_params.speed_cap_mask[idx]); |
f85582f8 DK |
9542 | return; |
9543 | } | |
9544 | break; | |
a2fbb9ea | 9545 | |
f85582f8 | 9546 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
a22f0788 YR |
9547 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) { |
9548 | bp->link_params.req_line_speed[idx] = | |
9549 | SPEED_10; | |
9550 | bp->link_params.req_duplex[idx] = | |
9551 | DUPLEX_HALF; | |
9552 | bp->port.advertising[idx] |= | |
9553 | (ADVERTISED_10baseT_Half | | |
f85582f8 DK |
9554 | ADVERTISED_TP); |
9555 | } else { | |
51c1a580 | 9556 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
9557 | link_config, |
9558 | bp->link_params.speed_cap_mask[idx]); | |
9559 | return; | |
9560 | } | |
9561 | break; | |
a2fbb9ea | 9562 | |
f85582f8 DK |
9563 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
9564 | if (bp->port.supported[idx] & | |
9565 | SUPPORTED_100baseT_Full) { | |
a22f0788 YR |
9566 | bp->link_params.req_line_speed[idx] = |
9567 | SPEED_100; | |
9568 | bp->port.advertising[idx] |= | |
9569 | (ADVERTISED_100baseT_Full | | |
f85582f8 DK |
9570 | ADVERTISED_TP); |
9571 | } else { | |
51c1a580 | 9572 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
f85582f8 DK |
9573 | link_config, |
9574 | bp->link_params.speed_cap_mask[idx]); | |
9575 | return; | |
9576 | } | |
9577 | break; | |
a2fbb9ea | 9578 | |
f85582f8 DK |
9579 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
9580 | if (bp->port.supported[idx] & | |
9581 | SUPPORTED_100baseT_Half) { | |
9582 | bp->link_params.req_line_speed[idx] = | |
9583 | SPEED_100; | |
9584 | bp->link_params.req_duplex[idx] = | |
9585 | DUPLEX_HALF; | |
a22f0788 YR |
9586 | bp->port.advertising[idx] |= |
9587 | (ADVERTISED_100baseT_Half | | |
f85582f8 DK |
9588 | ADVERTISED_TP); |
9589 | } else { | |
51c1a580 | 9590 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
9591 | link_config, |
9592 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
9593 | return; |
9594 | } | |
9595 | break; | |
a2fbb9ea | 9596 | |
f85582f8 | 9597 | case PORT_FEATURE_LINK_SPEED_1G: |
a22f0788 YR |
9598 | if (bp->port.supported[idx] & |
9599 | SUPPORTED_1000baseT_Full) { | |
9600 | bp->link_params.req_line_speed[idx] = | |
9601 | SPEED_1000; | |
9602 | bp->port.advertising[idx] |= | |
9603 | (ADVERTISED_1000baseT_Full | | |
f85582f8 DK |
9604 | ADVERTISED_TP); |
9605 | } else { | |
51c1a580 | 9606 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 YR |
9607 | link_config, |
9608 | bp->link_params.speed_cap_mask[idx]); | |
f85582f8 DK |
9609 | return; |
9610 | } | |
9611 | break; | |
a2fbb9ea | 9612 | |
f85582f8 | 9613 | case PORT_FEATURE_LINK_SPEED_2_5G: |
a22f0788 YR |
9614 | if (bp->port.supported[idx] & |
9615 | SUPPORTED_2500baseX_Full) { | |
9616 | bp->link_params.req_line_speed[idx] = | |
9617 | SPEED_2500; | |
9618 | bp->port.advertising[idx] |= | |
9619 | (ADVERTISED_2500baseX_Full | | |
34f80b04 | 9620 | ADVERTISED_TP); |
f85582f8 | 9621 | } else { |
51c1a580 | 9622 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 9623 | link_config, |
f85582f8 DK |
9624 | bp->link_params.speed_cap_mask[idx]); |
9625 | return; | |
9626 | } | |
9627 | break; | |
a2fbb9ea | 9628 | |
f85582f8 | 9629 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
a22f0788 YR |
9630 | if (bp->port.supported[idx] & |
9631 | SUPPORTED_10000baseT_Full) { | |
9632 | bp->link_params.req_line_speed[idx] = | |
9633 | SPEED_10000; | |
9634 | bp->port.advertising[idx] |= | |
9635 | (ADVERTISED_10000baseT_Full | | |
34f80b04 | 9636 | ADVERTISED_FIBRE); |
f85582f8 | 9637 | } else { |
51c1a580 | 9638 | BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n", |
a22f0788 | 9639 | link_config, |
f85582f8 DK |
9640 | bp->link_params.speed_cap_mask[idx]); |
9641 | return; | |
9642 | } | |
9643 | break; | |
3c9ada22 YR |
9644 | case PORT_FEATURE_LINK_SPEED_20G: |
9645 | bp->link_params.req_line_speed[idx] = SPEED_20000; | |
a2fbb9ea | 9646 | |
3c9ada22 | 9647 | break; |
f85582f8 | 9648 | default: |
51c1a580 | 9649 | BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n", |
754a2f52 | 9650 | link_config); |
f85582f8 DK |
9651 | bp->link_params.req_line_speed[idx] = |
9652 | SPEED_AUTO_NEG; | |
9653 | bp->port.advertising[idx] = | |
9654 | bp->port.supported[idx]; | |
9655 | break; | |
9656 | } | |
a2fbb9ea | 9657 | |
a22f0788 | 9658 | bp->link_params.req_flow_ctrl[idx] = (link_config & |
34f80b04 | 9659 | PORT_FEATURE_FLOW_CONTROL_MASK); |
a22f0788 YR |
9660 | if ((bp->link_params.req_flow_ctrl[idx] == |
9661 | BNX2X_FLOW_CTRL_AUTO) && | |
9662 | !(bp->port.supported[idx] & SUPPORTED_Autoneg)) { | |
9663 | bp->link_params.req_flow_ctrl[idx] = | |
9664 | BNX2X_FLOW_CTRL_NONE; | |
9665 | } | |
a2fbb9ea | 9666 | |
51c1a580 | 9667 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n", |
a22f0788 YR |
9668 | bp->link_params.req_line_speed[idx], |
9669 | bp->link_params.req_duplex[idx], | |
9670 | bp->link_params.req_flow_ctrl[idx], | |
9671 | bp->port.advertising[idx]); | |
9672 | } | |
a2fbb9ea ET |
9673 | } |
9674 | ||
e665bfda MC |
9675 | static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi) |
9676 | { | |
9677 | mac_hi = cpu_to_be16(mac_hi); | |
9678 | mac_lo = cpu_to_be32(mac_lo); | |
9679 | memcpy(mac_buf, &mac_hi, sizeof(mac_hi)); | |
9680 | memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo)); | |
9681 | } | |
9682 | ||
34f80b04 | 9683 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
a2fbb9ea | 9684 | { |
34f80b04 | 9685 | int port = BP_PORT(bp); |
589abe3a | 9686 | u32 config; |
6f38ad93 | 9687 | u32 ext_phy_type, ext_phy_config; |
a2fbb9ea | 9688 | |
c18487ee | 9689 | bp->link_params.bp = bp; |
34f80b04 | 9690 | bp->link_params.port = port; |
c18487ee | 9691 | |
c18487ee | 9692 | bp->link_params.lane_config = |
a2fbb9ea | 9693 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
4d295db0 | 9694 | |
a22f0788 | 9695 | bp->link_params.speed_cap_mask[0] = |
a2fbb9ea ET |
9696 | SHMEM_RD(bp, |
9697 | dev_info.port_hw_config[port].speed_capability_mask); | |
a22f0788 YR |
9698 | bp->link_params.speed_cap_mask[1] = |
9699 | SHMEM_RD(bp, | |
9700 | dev_info.port_hw_config[port].speed_capability_mask2); | |
9701 | bp->port.link_config[0] = | |
a2fbb9ea ET |
9702 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
9703 | ||
a22f0788 YR |
9704 | bp->port.link_config[1] = |
9705 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2); | |
c2c8b03e | 9706 | |
a22f0788 YR |
9707 | bp->link_params.multi_phy_config = |
9708 | SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config); | |
3ce2c3f9 EG |
9709 | /* If the device is capable of WoL, set the default state according |
9710 | * to the HW | |
9711 | */ | |
4d295db0 | 9712 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
3ce2c3f9 EG |
9713 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
9714 | (config & PORT_FEATURE_WOL_ENABLED)); | |
9715 | ||
51c1a580 | 9716 | BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n", |
c18487ee | 9717 | bp->link_params.lane_config, |
a22f0788 YR |
9718 | bp->link_params.speed_cap_mask[0], |
9719 | bp->port.link_config[0]); | |
a2fbb9ea | 9720 | |
a22f0788 | 9721 | bp->link_params.switch_cfg = (bp->port.link_config[0] & |
f85582f8 | 9722 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
b7737c9b | 9723 | bnx2x_phy_probe(&bp->link_params); |
c18487ee | 9724 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
a2fbb9ea ET |
9725 | |
9726 | bnx2x_link_settings_requested(bp); | |
9727 | ||
01cd4528 EG |
9728 | /* |
9729 | * If connected directly, work with the internal PHY, otherwise, work | |
9730 | * with the external PHY | |
9731 | */ | |
b7737c9b YR |
9732 | ext_phy_config = |
9733 | SHMEM_RD(bp, | |
9734 | dev_info.port_hw_config[port].external_phy_config); | |
9735 | ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config); | |
01cd4528 | 9736 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
b7737c9b | 9737 | bp->mdio.prtad = bp->port.phy_addr; |
01cd4528 EG |
9738 | |
9739 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && | |
9740 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) | |
9741 | bp->mdio.prtad = | |
b7737c9b | 9742 | XGXS_EXT_PHY_ADDR(ext_phy_config); |
5866df6d YR |
9743 | |
9744 | /* | |
9745 | * Check if hw lock is required to access MDC/MDIO bus to the PHY(s) | |
9746 | * In MF mode, it is set to cover self test cases | |
9747 | */ | |
9748 | if (IS_MF(bp)) | |
9749 | bp->port.need_hw_lock = 1; | |
9750 | else | |
9751 | bp->port.need_hw_lock = bnx2x_hw_lock_required(bp, | |
9752 | bp->common.shmem_base, | |
9753 | bp->common.shmem2_base); | |
0793f83f | 9754 | } |
01cd4528 | 9755 | |
b306f5ed | 9756 | void bnx2x_get_iscsi_info(struct bnx2x *bp) |
2ba45142 | 9757 | { |
9e62e912 | 9758 | u32 no_flags = NO_ISCSI_FLAG; |
7185bb33 | 9759 | #ifdef BCM_CNIC |
bf61ee14 | 9760 | int port = BP_PORT(bp); |
bf61ee14 | 9761 | |
2ba45142 | 9762 | u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
bf61ee14 | 9763 | drv_lic_key[port].max_iscsi_conn); |
2ba45142 | 9764 | |
b306f5ed | 9765 | /* Get the number of maximum allowed iSCSI connections */ |
2ba45142 VZ |
9766 | bp->cnic_eth_dev.max_iscsi_conn = |
9767 | (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >> | |
9768 | BNX2X_MAX_ISCSI_INIT_CONN_SHIFT; | |
9769 | ||
b306f5ed DK |
9770 | BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n", |
9771 | bp->cnic_eth_dev.max_iscsi_conn); | |
9772 | ||
9773 | /* | |
9774 | * If maximum allowed number of connections is zero - | |
9775 | * disable the feature. | |
9776 | */ | |
9777 | if (!bp->cnic_eth_dev.max_iscsi_conn) | |
9e62e912 | 9778 | bp->flags |= no_flags; |
7185bb33 | 9779 | #else |
9e62e912 | 9780 | bp->flags |= no_flags; |
7185bb33 | 9781 | #endif |
b306f5ed DK |
9782 | } |
9783 | ||
9e62e912 DK |
9784 | #ifdef BCM_CNIC |
9785 | static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func) | |
9786 | { | |
9787 | /* Port info */ | |
9788 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
9789 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper); | |
9790 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
9791 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower); | |
9792 | ||
9793 | /* Node info */ | |
9794 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
9795 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper); | |
9796 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
9797 | MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower); | |
9798 | } | |
9799 | #endif | |
b306f5ed DK |
9800 | static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp) |
9801 | { | |
7185bb33 | 9802 | #ifdef BCM_CNIC |
b306f5ed DK |
9803 | int port = BP_PORT(bp); |
9804 | int func = BP_ABS_FUNC(bp); | |
9805 | ||
9806 | u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, | |
9807 | drv_lic_key[port].max_fcoe_conn); | |
9808 | ||
9809 | /* Get the number of maximum allowed FCoE connections */ | |
2ba45142 VZ |
9810 | bp->cnic_eth_dev.max_fcoe_conn = |
9811 | (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >> | |
9812 | BNX2X_MAX_FCOE_INIT_CONN_SHIFT; | |
9813 | ||
bf61ee14 VZ |
9814 | /* Read the WWN: */ |
9815 | if (!IS_MF(bp)) { | |
9816 | /* Port info */ | |
9817 | bp->cnic_eth_dev.fcoe_wwn_port_name_hi = | |
9818 | SHMEM_RD(bp, | |
9819 | dev_info.port_hw_config[port]. | |
9820 | fcoe_wwn_port_name_upper); | |
9821 | bp->cnic_eth_dev.fcoe_wwn_port_name_lo = | |
9822 | SHMEM_RD(bp, | |
9823 | dev_info.port_hw_config[port]. | |
9824 | fcoe_wwn_port_name_lower); | |
9825 | ||
9826 | /* Node info */ | |
9827 | bp->cnic_eth_dev.fcoe_wwn_node_name_hi = | |
9828 | SHMEM_RD(bp, | |
9829 | dev_info.port_hw_config[port]. | |
9830 | fcoe_wwn_node_name_upper); | |
9831 | bp->cnic_eth_dev.fcoe_wwn_node_name_lo = | |
9832 | SHMEM_RD(bp, | |
9833 | dev_info.port_hw_config[port]. | |
9834 | fcoe_wwn_node_name_lower); | |
9835 | } else if (!IS_MF_SD(bp)) { | |
9836 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); | |
9837 | ||
9838 | /* | |
9839 | * Read the WWN info only if the FCoE feature is enabled for | |
9840 | * this function. | |
9841 | */ | |
9e62e912 DK |
9842 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) |
9843 | bnx2x_get_ext_wwn_info(bp, func); | |
9844 | ||
9845 | } else if (IS_MF_FCOE_SD(bp)) | |
9846 | bnx2x_get_ext_wwn_info(bp, func); | |
bf61ee14 | 9847 | |
b306f5ed | 9848 | BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn); |
2ba45142 | 9849 | |
bf61ee14 VZ |
9850 | /* |
9851 | * If maximum allowed number of connections is zero - | |
2ba45142 VZ |
9852 | * disable the feature. |
9853 | */ | |
2ba45142 VZ |
9854 | if (!bp->cnic_eth_dev.max_fcoe_conn) |
9855 | bp->flags |= NO_FCOE_FLAG; | |
7185bb33 DK |
9856 | #else |
9857 | bp->flags |= NO_FCOE_FLAG; | |
9858 | #endif | |
2ba45142 | 9859 | } |
b306f5ed DK |
9860 | |
9861 | static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp) | |
9862 | { | |
9863 | /* | |
9864 | * iSCSI may be dynamically disabled but reading | |
9865 | * info here we will decrease memory usage by driver | |
9866 | * if the feature is disabled for good | |
9867 | */ | |
9868 | bnx2x_get_iscsi_info(bp); | |
9869 | bnx2x_get_fcoe_info(bp); | |
9870 | } | |
2ba45142 | 9871 | |
0793f83f DK |
9872 | static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp) |
9873 | { | |
9874 | u32 val, val2; | |
9875 | int func = BP_ABS_FUNC(bp); | |
9876 | int port = BP_PORT(bp); | |
2ba45142 VZ |
9877 | #ifdef BCM_CNIC |
9878 | u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac; | |
9879 | u8 *fip_mac = bp->fip_mac; | |
9880 | #endif | |
0793f83f | 9881 | |
619c5cb6 VZ |
9882 | /* Zero primary MAC configuration */ |
9883 | memset(bp->dev->dev_addr, 0, ETH_ALEN); | |
9884 | ||
0793f83f DK |
9885 | if (BP_NOMCP(bp)) { |
9886 | BNX2X_ERROR("warning: random MAC workaround active\n"); | |
7ce5d222 | 9887 | eth_hw_addr_random(bp->dev); |
0793f83f DK |
9888 | } else if (IS_MF(bp)) { |
9889 | val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); | |
9890 | val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); | |
9891 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && | |
9892 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) | |
9893 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
37b091ba MC |
9894 | |
9895 | #ifdef BCM_CNIC | |
614c76df DK |
9896 | /* |
9897 | * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or | |
2ba45142 | 9898 | * FCoE MAC then the appropriate feature should be disabled. |
9e62e912 DK |
9899 | * |
9900 | * In non SD mode features configuration comes from | |
9901 | * struct func_ext_config. | |
2ba45142 | 9902 | */ |
9e62e912 | 9903 | if (!IS_MF_SD(bp)) { |
0793f83f DK |
9904 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); |
9905 | if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { | |
9906 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
9907 | iscsi_mac_addr_upper); | |
9908 | val = MF_CFG_RD(bp, func_ext_config[func]. | |
9909 | iscsi_mac_addr_lower); | |
2ba45142 | 9910 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
0f9dad10 JP |
9911 | BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n", |
9912 | iscsi_mac); | |
2ba45142 VZ |
9913 | } else |
9914 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; | |
9915 | ||
9916 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { | |
9917 | val2 = MF_CFG_RD(bp, func_ext_config[func]. | |
9918 | fcoe_mac_addr_upper); | |
9919 | val = MF_CFG_RD(bp, func_ext_config[func]. | |
9920 | fcoe_mac_addr_lower); | |
2ba45142 | 9921 | bnx2x_set_mac_buf(fip_mac, val, val2); |
614c76df | 9922 | BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n", |
0f9dad10 | 9923 | fip_mac); |
2ba45142 | 9924 | |
2ba45142 VZ |
9925 | } else |
9926 | bp->flags |= NO_FCOE_FLAG; | |
9e62e912 DK |
9927 | } else { /* SD MODE */ |
9928 | if (IS_MF_STORAGE_SD(bp)) { | |
9929 | if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) { | |
9930 | /* use primary mac as iscsi mac */ | |
9931 | memcpy(iscsi_mac, bp->dev->dev_addr, | |
9932 | ETH_ALEN); | |
9933 | ||
9934 | BNX2X_DEV_INFO("SD ISCSI MODE\n"); | |
9935 | BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n", | |
9936 | iscsi_mac); | |
9937 | } else { /* FCoE */ | |
9938 | memcpy(fip_mac, bp->dev->dev_addr, | |
9939 | ETH_ALEN); | |
9940 | BNX2X_DEV_INFO("SD FCoE MODE\n"); | |
9941 | BNX2X_DEV_INFO("Read FIP MAC: %pM\n", | |
9942 | fip_mac); | |
9943 | } | |
614c76df DK |
9944 | /* Zero primary MAC configuration */ |
9945 | memset(bp->dev->dev_addr, 0, ETH_ALEN); | |
614c76df | 9946 | } |
0793f83f | 9947 | } |
37b091ba | 9948 | #endif |
0793f83f DK |
9949 | } else { |
9950 | /* in SF read MACs from port configuration */ | |
9951 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); | |
9952 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); | |
9953 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); | |
9954 | ||
9955 | #ifdef BCM_CNIC | |
9956 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
9957 | iscsi_mac_upper); | |
9958 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
9959 | iscsi_mac_lower); | |
2ba45142 | 9960 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
c03bd39c VZ |
9961 | |
9962 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
9963 | fcoe_fip_mac_upper); | |
9964 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. | |
9965 | fcoe_fip_mac_lower); | |
9966 | bnx2x_set_mac_buf(fip_mac, val, val2); | |
0793f83f DK |
9967 | #endif |
9968 | } | |
9969 | ||
9970 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); | |
9971 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); | |
9972 | ||
ec6ba945 | 9973 | #ifdef BCM_CNIC |
426b9241 DK |
9974 | /* Disable iSCSI if MAC configuration is |
9975 | * invalid. | |
9976 | */ | |
9977 | if (!is_valid_ether_addr(iscsi_mac)) { | |
9978 | bp->flags |= NO_ISCSI_FLAG; | |
9979 | memset(iscsi_mac, 0, ETH_ALEN); | |
9980 | } | |
9981 | ||
9982 | /* Disable FCoE if MAC configuration is | |
9983 | * invalid. | |
9984 | */ | |
9985 | if (!is_valid_ether_addr(fip_mac)) { | |
9986 | bp->flags |= NO_FCOE_FLAG; | |
9987 | memset(bp->fip_mac, 0, ETH_ALEN); | |
9988 | } | |
ec6ba945 | 9989 | #endif |
619c5cb6 | 9990 | |
614c76df | 9991 | if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr)) |
619c5cb6 | 9992 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
9993 | "bad Ethernet MAC address configuration: %pM\n" |
9994 | "change it manually before bringing up the appropriate network interface\n", | |
0f9dad10 | 9995 | bp->dev->dev_addr); |
51c1a580 MS |
9996 | |
9997 | ||
34f80b04 EG |
9998 | } |
9999 | ||
10000 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) | |
10001 | { | |
0793f83f | 10002 | int /*abs*/func = BP_ABS_FUNC(bp); |
b8ee8328 | 10003 | int vn; |
0793f83f | 10004 | u32 val = 0; |
34f80b04 | 10005 | int rc = 0; |
a2fbb9ea | 10006 | |
34f80b04 | 10007 | bnx2x_get_common_hwinfo(bp); |
a2fbb9ea | 10008 | |
6383c0b3 AE |
10009 | /* |
10010 | * initialize IGU parameters | |
10011 | */ | |
f2e0899f DK |
10012 | if (CHIP_IS_E1x(bp)) { |
10013 | bp->common.int_block = INT_BLOCK_HC; | |
10014 | ||
10015 | bp->igu_dsb_id = DEF_SB_IGU_ID; | |
10016 | bp->igu_base_sb = 0; | |
f2e0899f DK |
10017 | } else { |
10018 | bp->common.int_block = INT_BLOCK_IGU; | |
7a06a122 DK |
10019 | |
10020 | /* do not allow device reset during IGU info preocessing */ | |
10021 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET); | |
10022 | ||
f2e0899f | 10023 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
619c5cb6 VZ |
10024 | |
10025 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { | |
10026 | int tout = 5000; | |
10027 | ||
10028 | BNX2X_DEV_INFO("FORCING Normal Mode\n"); | |
10029 | ||
10030 | val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); | |
10031 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val); | |
10032 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f); | |
10033 | ||
10034 | while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
10035 | tout--; | |
10036 | usleep_range(1000, 1000); | |
10037 | } | |
10038 | ||
10039 | if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) { | |
10040 | dev_err(&bp->pdev->dev, | |
10041 | "FORCING Normal Mode failed!!!\n"); | |
10042 | return -EPERM; | |
10043 | } | |
10044 | } | |
10045 | ||
f2e0899f | 10046 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
619c5cb6 | 10047 | BNX2X_DEV_INFO("IGU Backward Compatible Mode\n"); |
f2e0899f DK |
10048 | bp->common.int_block |= INT_BLOCK_MODE_BW_COMP; |
10049 | } else | |
619c5cb6 | 10050 | BNX2X_DEV_INFO("IGU Normal Mode\n"); |
523224a3 | 10051 | |
f2e0899f DK |
10052 | bnx2x_get_igu_cam_info(bp); |
10053 | ||
7a06a122 | 10054 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET); |
f2e0899f | 10055 | } |
619c5cb6 VZ |
10056 | |
10057 | /* | |
10058 | * set base FW non-default (fast path) status block id, this value is | |
10059 | * used to initialize the fw_sb_id saved on the fp/queue structure to | |
10060 | * determine the id used by the FW. | |
10061 | */ | |
10062 | if (CHIP_IS_E1x(bp)) | |
10063 | bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp); | |
10064 | else /* | |
10065 | * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of | |
10066 | * the same queue are indicated on the same IGU SB). So we prefer | |
10067 | * FW and IGU SBs to be the same value. | |
10068 | */ | |
10069 | bp->base_fw_ndsb = bp->igu_base_sb; | |
10070 | ||
10071 | BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n" | |
10072 | "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb, | |
10073 | bp->igu_sb_cnt, bp->base_fw_ndsb); | |
f2e0899f DK |
10074 | |
10075 | /* | |
10076 | * Initialize MF configuration | |
10077 | */ | |
523224a3 | 10078 | |
fb3bff17 DK |
10079 | bp->mf_ov = 0; |
10080 | bp->mf_mode = 0; | |
3395a033 | 10081 | vn = BP_VN(bp); |
0793f83f | 10082 | |
f2e0899f | 10083 | if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) { |
619c5cb6 VZ |
10084 | BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n", |
10085 | bp->common.shmem2_base, SHMEM2_RD(bp, size), | |
10086 | (u32)offsetof(struct shmem2_region, mf_cfg_addr)); | |
10087 | ||
f2e0899f DK |
10088 | if (SHMEM2_HAS(bp, mf_cfg_addr)) |
10089 | bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr); | |
10090 | else | |
10091 | bp->common.mf_cfg_base = bp->common.shmem_base + | |
523224a3 DK |
10092 | offsetof(struct shmem_region, func_mb) + |
10093 | E1H_FUNC_MAX * sizeof(struct drv_func_mb); | |
0793f83f DK |
10094 | /* |
10095 | * get mf configuration: | |
25985edc | 10096 | * 1. existence of MF configuration |
0793f83f DK |
10097 | * 2. MAC address must be legal (check only upper bytes) |
10098 | * for Switch-Independent mode; | |
10099 | * OVLAN must be legal for Switch-Dependent mode | |
10100 | * 3. SF_MODE configures specific MF mode | |
10101 | */ | |
10102 | if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
10103 | /* get mf configuration */ | |
10104 | val = SHMEM_RD(bp, | |
10105 | dev_info.shared_feature_config.config); | |
10106 | val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK; | |
10107 | ||
10108 | switch (val) { | |
10109 | case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: | |
10110 | val = MF_CFG_RD(bp, func_mf_config[func]. | |
10111 | mac_upper); | |
10112 | /* check for legal mac (upper bytes)*/ | |
10113 | if (val != 0xffff) { | |
10114 | bp->mf_mode = MULTI_FUNCTION_SI; | |
10115 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
10116 | func_mf_config[func].config); | |
10117 | } else | |
51c1a580 | 10118 | BNX2X_DEV_INFO("illegal MAC address for SI\n"); |
0793f83f DK |
10119 | break; |
10120 | case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: | |
10121 | /* get OV configuration */ | |
10122 | val = MF_CFG_RD(bp, | |
10123 | func_mf_config[FUNC_0].e1hov_tag); | |
10124 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; | |
10125 | ||
10126 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { | |
10127 | bp->mf_mode = MULTI_FUNCTION_SD; | |
10128 | bp->mf_config[vn] = MF_CFG_RD(bp, | |
10129 | func_mf_config[func].config); | |
10130 | } else | |
754a2f52 | 10131 | BNX2X_DEV_INFO("illegal OV for SD\n"); |
0793f83f DK |
10132 | break; |
10133 | default: | |
10134 | /* Unknown configuration: reset mf_config */ | |
10135 | bp->mf_config[vn] = 0; | |
51c1a580 | 10136 | BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val); |
0793f83f DK |
10137 | } |
10138 | } | |
a2fbb9ea | 10139 | |
2691d51d | 10140 | BNX2X_DEV_INFO("%s function mode\n", |
fb3bff17 | 10141 | IS_MF(bp) ? "multi" : "single"); |
2691d51d | 10142 | |
0793f83f DK |
10143 | switch (bp->mf_mode) { |
10144 | case MULTI_FUNCTION_SD: | |
10145 | val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & | |
10146 | FUNC_MF_CFG_E1HOV_TAG_MASK; | |
2691d51d | 10147 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
fb3bff17 | 10148 | bp->mf_ov = val; |
619c5cb6 VZ |
10149 | bp->path_has_ovlan = true; |
10150 | ||
51c1a580 MS |
10151 | BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n", |
10152 | func, bp->mf_ov, bp->mf_ov); | |
2691d51d | 10153 | } else { |
619c5cb6 | 10154 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
10155 | "No valid MF OV for func %d, aborting\n", |
10156 | func); | |
619c5cb6 | 10157 | return -EPERM; |
34f80b04 | 10158 | } |
0793f83f DK |
10159 | break; |
10160 | case MULTI_FUNCTION_SI: | |
51c1a580 MS |
10161 | BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n", |
10162 | func); | |
0793f83f DK |
10163 | break; |
10164 | default: | |
10165 | if (vn) { | |
619c5cb6 | 10166 | dev_err(&bp->pdev->dev, |
51c1a580 MS |
10167 | "VN %d is in a single function mode, aborting\n", |
10168 | vn); | |
619c5cb6 | 10169 | return -EPERM; |
2691d51d | 10170 | } |
0793f83f | 10171 | break; |
34f80b04 | 10172 | } |
0793f83f | 10173 | |
619c5cb6 VZ |
10174 | /* check if other port on the path needs ovlan: |
10175 | * Since MF configuration is shared between ports | |
10176 | * Possible mixed modes are only | |
10177 | * {SF, SI} {SF, SD} {SD, SF} {SI, SF} | |
10178 | */ | |
10179 | if (CHIP_MODE_IS_4_PORT(bp) && | |
10180 | !bp->path_has_ovlan && | |
10181 | !IS_MF(bp) && | |
10182 | bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { | |
10183 | u8 other_port = !BP_PORT(bp); | |
10184 | u8 other_func = BP_PATH(bp) + 2*other_port; | |
10185 | val = MF_CFG_RD(bp, | |
10186 | func_mf_config[other_func].e1hov_tag); | |
10187 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) | |
10188 | bp->path_has_ovlan = true; | |
10189 | } | |
34f80b04 | 10190 | } |
a2fbb9ea | 10191 | |
f2e0899f DK |
10192 | /* adjust igu_sb_cnt to MF for E1x */ |
10193 | if (CHIP_IS_E1x(bp) && IS_MF(bp)) | |
523224a3 DK |
10194 | bp->igu_sb_cnt /= E1HVN_MAX; |
10195 | ||
619c5cb6 VZ |
10196 | /* port info */ |
10197 | bnx2x_get_port_hwinfo(bp); | |
f2e0899f | 10198 | |
0793f83f DK |
10199 | /* Get MAC addresses */ |
10200 | bnx2x_get_mac_hwinfo(bp); | |
a2fbb9ea | 10201 | |
2ba45142 | 10202 | bnx2x_get_cnic_info(bp); |
2ba45142 | 10203 | |
34f80b04 EG |
10204 | return rc; |
10205 | } | |
10206 | ||
34f24c7f VZ |
10207 | static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp) |
10208 | { | |
10209 | int cnt, i, block_end, rodi; | |
fcdf95cb | 10210 | char vpd_start[BNX2X_VPD_LEN+1]; |
34f24c7f VZ |
10211 | char str_id_reg[VENDOR_ID_LEN+1]; |
10212 | char str_id_cap[VENDOR_ID_LEN+1]; | |
fcdf95cb BW |
10213 | char *vpd_data; |
10214 | char *vpd_extended_data = NULL; | |
34f24c7f VZ |
10215 | u8 len; |
10216 | ||
fcdf95cb | 10217 | cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start); |
34f24c7f VZ |
10218 | memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); |
10219 | ||
10220 | if (cnt < BNX2X_VPD_LEN) | |
10221 | goto out_not_found; | |
10222 | ||
fcdf95cb BW |
10223 | /* VPD RO tag should be first tag after identifier string, hence |
10224 | * we should be able to find it in first BNX2X_VPD_LEN chars | |
10225 | */ | |
10226 | i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN, | |
34f24c7f VZ |
10227 | PCI_VPD_LRDT_RO_DATA); |
10228 | if (i < 0) | |
10229 | goto out_not_found; | |
10230 | ||
34f24c7f | 10231 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + |
fcdf95cb | 10232 | pci_vpd_lrdt_size(&vpd_start[i]); |
34f24c7f VZ |
10233 | |
10234 | i += PCI_VPD_LRDT_TAG_SIZE; | |
10235 | ||
fcdf95cb BW |
10236 | if (block_end > BNX2X_VPD_LEN) { |
10237 | vpd_extended_data = kmalloc(block_end, GFP_KERNEL); | |
10238 | if (vpd_extended_data == NULL) | |
10239 | goto out_not_found; | |
10240 | ||
10241 | /* read rest of vpd image into vpd_extended_data */ | |
10242 | memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN); | |
10243 | cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN, | |
10244 | block_end - BNX2X_VPD_LEN, | |
10245 | vpd_extended_data + BNX2X_VPD_LEN); | |
10246 | if (cnt < (block_end - BNX2X_VPD_LEN)) | |
10247 | goto out_not_found; | |
10248 | vpd_data = vpd_extended_data; | |
10249 | } else | |
10250 | vpd_data = vpd_start; | |
10251 | ||
10252 | /* now vpd_data holds full vpd content in both cases */ | |
34f24c7f VZ |
10253 | |
10254 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
10255 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
10256 | if (rodi < 0) | |
10257 | goto out_not_found; | |
10258 | ||
10259 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
10260 | ||
10261 | if (len != VENDOR_ID_LEN) | |
10262 | goto out_not_found; | |
10263 | ||
10264 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
10265 | ||
10266 | /* vendor specific info */ | |
10267 | snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); | |
10268 | snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); | |
10269 | if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || | |
10270 | !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { | |
10271 | ||
10272 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, | |
10273 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
10274 | if (rodi >= 0) { | |
10275 | len = pci_vpd_info_field_size(&vpd_data[rodi]); | |
10276 | ||
10277 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; | |
10278 | ||
10279 | if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { | |
10280 | memcpy(bp->fw_ver, &vpd_data[rodi], len); | |
10281 | bp->fw_ver[len] = ' '; | |
10282 | } | |
10283 | } | |
fcdf95cb | 10284 | kfree(vpd_extended_data); |
34f24c7f VZ |
10285 | return; |
10286 | } | |
10287 | out_not_found: | |
fcdf95cb | 10288 | kfree(vpd_extended_data); |
34f24c7f VZ |
10289 | return; |
10290 | } | |
10291 | ||
619c5cb6 VZ |
10292 | static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp) |
10293 | { | |
10294 | u32 flags = 0; | |
10295 | ||
10296 | if (CHIP_REV_IS_FPGA(bp)) | |
10297 | SET_FLAGS(flags, MODE_FPGA); | |
10298 | else if (CHIP_REV_IS_EMUL(bp)) | |
10299 | SET_FLAGS(flags, MODE_EMUL); | |
10300 | else | |
10301 | SET_FLAGS(flags, MODE_ASIC); | |
10302 | ||
10303 | if (CHIP_MODE_IS_4_PORT(bp)) | |
10304 | SET_FLAGS(flags, MODE_PORT4); | |
10305 | else | |
10306 | SET_FLAGS(flags, MODE_PORT2); | |
10307 | ||
10308 | if (CHIP_IS_E2(bp)) | |
10309 | SET_FLAGS(flags, MODE_E2); | |
10310 | else if (CHIP_IS_E3(bp)) { | |
10311 | SET_FLAGS(flags, MODE_E3); | |
10312 | if (CHIP_REV(bp) == CHIP_REV_Ax) | |
10313 | SET_FLAGS(flags, MODE_E3_A0); | |
6383c0b3 AE |
10314 | else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/ |
10315 | SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3); | |
619c5cb6 VZ |
10316 | } |
10317 | ||
10318 | if (IS_MF(bp)) { | |
10319 | SET_FLAGS(flags, MODE_MF); | |
10320 | switch (bp->mf_mode) { | |
10321 | case MULTI_FUNCTION_SD: | |
10322 | SET_FLAGS(flags, MODE_MF_SD); | |
10323 | break; | |
10324 | case MULTI_FUNCTION_SI: | |
10325 | SET_FLAGS(flags, MODE_MF_SI); | |
10326 | break; | |
10327 | } | |
10328 | } else | |
10329 | SET_FLAGS(flags, MODE_SF); | |
10330 | ||
10331 | #if defined(__LITTLE_ENDIAN) | |
10332 | SET_FLAGS(flags, MODE_LITTLE_ENDIAN); | |
10333 | #else /*(__BIG_ENDIAN)*/ | |
10334 | SET_FLAGS(flags, MODE_BIG_ENDIAN); | |
10335 | #endif | |
10336 | INIT_MODE_FLAGS(bp) = flags; | |
10337 | } | |
10338 | ||
34f80b04 EG |
10339 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
10340 | { | |
f2e0899f | 10341 | int func; |
34f80b04 EG |
10342 | int rc; |
10343 | ||
34f80b04 | 10344 | mutex_init(&bp->port.phy_mutex); |
c4ff7cbf | 10345 | mutex_init(&bp->fw_mb_mutex); |
bb7e95c8 | 10346 | spin_lock_init(&bp->stats_lock); |
993ac7b5 MC |
10347 | #ifdef BCM_CNIC |
10348 | mutex_init(&bp->cnic_mutex); | |
10349 | #endif | |
a2fbb9ea | 10350 | |
1cf167f2 | 10351 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
7be08a72 | 10352 | INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task); |
3deb8167 | 10353 | INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task); |
34f80b04 | 10354 | rc = bnx2x_get_hwinfo(bp); |
619c5cb6 VZ |
10355 | if (rc) |
10356 | return rc; | |
34f80b04 | 10357 | |
619c5cb6 VZ |
10358 | bnx2x_set_modes_bitmap(bp); |
10359 | ||
10360 | rc = bnx2x_alloc_mem_bp(bp); | |
10361 | if (rc) | |
10362 | return rc; | |
523224a3 | 10363 | |
34f24c7f | 10364 | bnx2x_read_fwinfo(bp); |
f2e0899f DK |
10365 | |
10366 | func = BP_FUNC(bp); | |
10367 | ||
34f80b04 | 10368 | /* need to reset chip if undi was active */ |
452427b0 YM |
10369 | if (!BP_NOMCP(bp)) { |
10370 | /* init fw_seq */ | |
10371 | bp->fw_seq = | |
10372 | SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & | |
10373 | DRV_MSG_SEQ_NUMBER_MASK; | |
10374 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); | |
10375 | ||
10376 | bnx2x_prev_unload(bp); | |
10377 | } | |
10378 | ||
34f80b04 EG |
10379 | |
10380 | if (CHIP_REV_IS_FPGA(bp)) | |
cdaa7cb8 | 10381 | dev_err(&bp->pdev->dev, "FPGA detected\n"); |
34f80b04 EG |
10382 | |
10383 | if (BP_NOMCP(bp) && (func == 0)) | |
51c1a580 | 10384 | dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n"); |
34f80b04 | 10385 | |
555f6c78 | 10386 | bp->multi_mode = multi_mode; |
555f6c78 | 10387 | |
614c76df DK |
10388 | bp->disable_tpa = disable_tpa; |
10389 | ||
10390 | #ifdef BCM_CNIC | |
9e62e912 | 10391 | bp->disable_tpa |= IS_MF_STORAGE_SD(bp); |
614c76df DK |
10392 | #endif |
10393 | ||
7a9b2557 | 10394 | /* Set TPA flags */ |
614c76df | 10395 | if (bp->disable_tpa) { |
621b4d66 | 10396 | bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
10397 | bp->dev->features &= ~NETIF_F_LRO; |
10398 | } else { | |
621b4d66 | 10399 | bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); |
7a9b2557 VZ |
10400 | bp->dev->features |= NETIF_F_LRO; |
10401 | } | |
10402 | ||
a18f5128 EG |
10403 | if (CHIP_IS_E1(bp)) |
10404 | bp->dropless_fc = 0; | |
10405 | else | |
10406 | bp->dropless_fc = dropless_fc; | |
10407 | ||
8d5726c4 | 10408 | bp->mrrs = mrrs; |
7a9b2557 | 10409 | |
34f80b04 | 10410 | bp->tx_ring_size = MAX_TX_AVAIL; |
34f80b04 | 10411 | |
7d323bfd | 10412 | /* make sure that the numbers are in the right granularity */ |
523224a3 DK |
10413 | bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR; |
10414 | bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR; | |
34f80b04 | 10415 | |
fc543637 | 10416 | bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ; |
34f80b04 EG |
10417 | |
10418 | init_timer(&bp->timer); | |
10419 | bp->timer.expires = jiffies + bp->current_interval; | |
10420 | bp->timer.data = (unsigned long) bp; | |
10421 | bp->timer.function = bnx2x_timer; | |
10422 | ||
785b9b1a | 10423 | bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON); |
e4901dde VZ |
10424 | bnx2x_dcbx_init_params(bp); |
10425 | ||
619c5cb6 VZ |
10426 | #ifdef BCM_CNIC |
10427 | if (CHIP_IS_E1x(bp)) | |
10428 | bp->cnic_base_cl_id = FP_SB_MAX_E1x; | |
10429 | else | |
10430 | bp->cnic_base_cl_id = FP_SB_MAX_E2; | |
10431 | #endif | |
10432 | ||
6383c0b3 AE |
10433 | /* multiple tx priority */ |
10434 | if (CHIP_IS_E1x(bp)) | |
10435 | bp->max_cos = BNX2X_MULTI_TX_COS_E1X; | |
10436 | if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) | |
10437 | bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0; | |
10438 | if (CHIP_IS_E3B0(bp)) | |
10439 | bp->max_cos = BNX2X_MULTI_TX_COS_E3B0; | |
10440 | ||
fe603b4d DK |
10441 | bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu); |
10442 | ||
34f80b04 | 10443 | return rc; |
a2fbb9ea ET |
10444 | } |
10445 | ||
a2fbb9ea | 10446 | |
de0c62db DK |
10447 | /**************************************************************************** |
10448 | * General service functions | |
10449 | ****************************************************************************/ | |
a2fbb9ea | 10450 | |
619c5cb6 VZ |
10451 | /* |
10452 | * net_device service functions | |
10453 | */ | |
10454 | ||
bb2a0f7a | 10455 | /* called with rtnl_lock */ |
a2fbb9ea ET |
10456 | static int bnx2x_open(struct net_device *dev) |
10457 | { | |
10458 | struct bnx2x *bp = netdev_priv(dev); | |
c9ee9206 VZ |
10459 | bool global = false; |
10460 | int other_engine = BP_PATH(bp) ? 0 : 1; | |
889b9af3 | 10461 | bool other_load_status, load_status; |
a2fbb9ea | 10462 | |
1355b704 MY |
10463 | bp->stats_init = true; |
10464 | ||
6eccabb3 EG |
10465 | netif_carrier_off(dev); |
10466 | ||
a2fbb9ea ET |
10467 | bnx2x_set_power_state(bp, PCI_D0); |
10468 | ||
889b9af3 AE |
10469 | other_load_status = bnx2x_get_load_status(bp, other_engine); |
10470 | load_status = bnx2x_get_load_status(bp, BP_PATH(bp)); | |
c9ee9206 VZ |
10471 | |
10472 | /* | |
10473 | * If parity had happen during the unload, then attentions | |
10474 | * and/or RECOVERY_IN_PROGRES may still be set. In this case we | |
10475 | * want the first function loaded on the current engine to | |
10476 | * complete the recovery. | |
10477 | */ | |
10478 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || | |
10479 | bnx2x_chk_parity_attn(bp, &global, true)) | |
72fd0718 | 10480 | do { |
c9ee9206 VZ |
10481 | /* |
10482 | * If there are attentions and they are in a global | |
10483 | * blocks, set the GLOBAL_RESET bit regardless whether | |
10484 | * it will be this function that will complete the | |
10485 | * recovery or not. | |
72fd0718 | 10486 | */ |
c9ee9206 VZ |
10487 | if (global) |
10488 | bnx2x_set_reset_global(bp); | |
72fd0718 | 10489 | |
c9ee9206 VZ |
10490 | /* |
10491 | * Only the first function on the current engine should | |
10492 | * try to recover in open. In case of attentions in | |
10493 | * global blocks only the first in the chip should try | |
10494 | * to recover. | |
72fd0718 | 10495 | */ |
889b9af3 AE |
10496 | if ((!load_status && |
10497 | (!global || !other_load_status)) && | |
c9ee9206 VZ |
10498 | bnx2x_trylock_leader_lock(bp) && |
10499 | !bnx2x_leader_reset(bp)) { | |
10500 | netdev_info(bp->dev, "Recovered in open\n"); | |
72fd0718 VZ |
10501 | break; |
10502 | } | |
10503 | ||
c9ee9206 | 10504 | /* recovery has failed... */ |
72fd0718 | 10505 | bnx2x_set_power_state(bp, PCI_D3hot); |
c9ee9206 | 10506 | bp->recovery_state = BNX2X_RECOVERY_FAILED; |
72fd0718 | 10507 | |
51c1a580 MS |
10508 | BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n" |
10509 | "If you still see this message after a few retries then power cycle is required.\n"); | |
72fd0718 VZ |
10510 | |
10511 | return -EAGAIN; | |
10512 | } while (0); | |
72fd0718 VZ |
10513 | |
10514 | bp->recovery_state = BNX2X_RECOVERY_DONE; | |
bb2a0f7a | 10515 | return bnx2x_nic_load(bp, LOAD_OPEN); |
a2fbb9ea ET |
10516 | } |
10517 | ||
bb2a0f7a | 10518 | /* called with rtnl_lock */ |
56ad3152 | 10519 | static int bnx2x_close(struct net_device *dev) |
a2fbb9ea | 10520 | { |
a2fbb9ea ET |
10521 | struct bnx2x *bp = netdev_priv(dev); |
10522 | ||
10523 | /* Unload the driver, release IRQs */ | |
bb2a0f7a | 10524 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
c9ee9206 VZ |
10525 | |
10526 | /* Power off */ | |
d3dbfee0 | 10527 | bnx2x_set_power_state(bp, PCI_D3hot); |
a2fbb9ea ET |
10528 | |
10529 | return 0; | |
10530 | } | |
10531 | ||
619c5cb6 VZ |
10532 | static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp, |
10533 | struct bnx2x_mcast_ramrod_params *p) | |
6e30dd4e | 10534 | { |
619c5cb6 VZ |
10535 | int mc_count = netdev_mc_count(bp->dev); |
10536 | struct bnx2x_mcast_list_elem *mc_mac = | |
10537 | kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); | |
10538 | struct netdev_hw_addr *ha; | |
6e30dd4e | 10539 | |
619c5cb6 VZ |
10540 | if (!mc_mac) |
10541 | return -ENOMEM; | |
6e30dd4e | 10542 | |
619c5cb6 | 10543 | INIT_LIST_HEAD(&p->mcast_list); |
6e30dd4e | 10544 | |
619c5cb6 VZ |
10545 | netdev_for_each_mc_addr(ha, bp->dev) { |
10546 | mc_mac->mac = bnx2x_mc_addr(ha); | |
10547 | list_add_tail(&mc_mac->link, &p->mcast_list); | |
10548 | mc_mac++; | |
6e30dd4e | 10549 | } |
619c5cb6 VZ |
10550 | |
10551 | p->mcast_list_len = mc_count; | |
10552 | ||
10553 | return 0; | |
6e30dd4e VZ |
10554 | } |
10555 | ||
619c5cb6 VZ |
10556 | static inline void bnx2x_free_mcast_macs_list( |
10557 | struct bnx2x_mcast_ramrod_params *p) | |
10558 | { | |
10559 | struct bnx2x_mcast_list_elem *mc_mac = | |
10560 | list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem, | |
10561 | link); | |
10562 | ||
10563 | WARN_ON(!mc_mac); | |
10564 | kfree(mc_mac); | |
10565 | } | |
10566 | ||
10567 | /** | |
10568 | * bnx2x_set_uc_list - configure a new unicast MACs list. | |
10569 | * | |
10570 | * @bp: driver handle | |
6e30dd4e | 10571 | * |
619c5cb6 | 10572 | * We will use zero (0) as a MAC type for these MACs. |
6e30dd4e | 10573 | */ |
619c5cb6 | 10574 | static inline int bnx2x_set_uc_list(struct bnx2x *bp) |
6e30dd4e | 10575 | { |
619c5cb6 | 10576 | int rc; |
6e30dd4e | 10577 | struct net_device *dev = bp->dev; |
6e30dd4e | 10578 | struct netdev_hw_addr *ha; |
619c5cb6 VZ |
10579 | struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj; |
10580 | unsigned long ramrod_flags = 0; | |
6e30dd4e | 10581 | |
619c5cb6 VZ |
10582 | /* First schedule a cleanup up of old configuration */ |
10583 | rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false); | |
10584 | if (rc < 0) { | |
10585 | BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc); | |
10586 | return rc; | |
10587 | } | |
6e30dd4e VZ |
10588 | |
10589 | netdev_for_each_uc_addr(ha, dev) { | |
619c5cb6 VZ |
10590 | rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, |
10591 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
10592 | if (rc < 0) { | |
10593 | BNX2X_ERR("Failed to schedule ADD operations: %d\n", | |
10594 | rc); | |
10595 | return rc; | |
6e30dd4e VZ |
10596 | } |
10597 | } | |
10598 | ||
619c5cb6 VZ |
10599 | /* Execute the pending commands */ |
10600 | __set_bit(RAMROD_CONT, &ramrod_flags); | |
10601 | return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */, | |
10602 | BNX2X_UC_LIST_MAC, &ramrod_flags); | |
6e30dd4e VZ |
10603 | } |
10604 | ||
619c5cb6 | 10605 | static inline int bnx2x_set_mc_list(struct bnx2x *bp) |
6e30dd4e | 10606 | { |
619c5cb6 | 10607 | struct net_device *dev = bp->dev; |
3b603066 | 10608 | struct bnx2x_mcast_ramrod_params rparam = {NULL}; |
619c5cb6 | 10609 | int rc = 0; |
6e30dd4e | 10610 | |
619c5cb6 | 10611 | rparam.mcast_obj = &bp->mcast_obj; |
6e30dd4e | 10612 | |
619c5cb6 VZ |
10613 | /* first, clear all configured multicast MACs */ |
10614 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); | |
10615 | if (rc < 0) { | |
51c1a580 | 10616 | BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc); |
619c5cb6 VZ |
10617 | return rc; |
10618 | } | |
6e30dd4e | 10619 | |
619c5cb6 VZ |
10620 | /* then, configure a new MACs list */ |
10621 | if (netdev_mc_count(dev)) { | |
10622 | rc = bnx2x_init_mcast_macs_list(bp, &rparam); | |
10623 | if (rc) { | |
51c1a580 MS |
10624 | BNX2X_ERR("Failed to create multicast MACs list: %d\n", |
10625 | rc); | |
619c5cb6 VZ |
10626 | return rc; |
10627 | } | |
6e30dd4e | 10628 | |
619c5cb6 VZ |
10629 | /* Now add the new MACs */ |
10630 | rc = bnx2x_config_mcast(bp, &rparam, | |
10631 | BNX2X_MCAST_CMD_ADD); | |
10632 | if (rc < 0) | |
51c1a580 MS |
10633 | BNX2X_ERR("Failed to set a new multicast configuration: %d\n", |
10634 | rc); | |
6e30dd4e | 10635 | |
619c5cb6 VZ |
10636 | bnx2x_free_mcast_macs_list(&rparam); |
10637 | } | |
6e30dd4e | 10638 | |
619c5cb6 | 10639 | return rc; |
6e30dd4e VZ |
10640 | } |
10641 | ||
6e30dd4e | 10642 | |
619c5cb6 | 10643 | /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */ |
9f6c9258 | 10644 | void bnx2x_set_rx_mode(struct net_device *dev) |
34f80b04 EG |
10645 | { |
10646 | struct bnx2x *bp = netdev_priv(dev); | |
10647 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; | |
34f80b04 EG |
10648 | |
10649 | if (bp->state != BNX2X_STATE_OPEN) { | |
10650 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); | |
10651 | return; | |
10652 | } | |
10653 | ||
619c5cb6 | 10654 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags); |
34f80b04 EG |
10655 | |
10656 | if (dev->flags & IFF_PROMISC) | |
10657 | rx_mode = BNX2X_RX_MODE_PROMISC; | |
619c5cb6 VZ |
10658 | else if ((dev->flags & IFF_ALLMULTI) || |
10659 | ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) && | |
10660 | CHIP_IS_E1(bp))) | |
34f80b04 | 10661 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
6e30dd4e VZ |
10662 | else { |
10663 | /* some multicasts */ | |
619c5cb6 | 10664 | if (bnx2x_set_mc_list(bp) < 0) |
6e30dd4e | 10665 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
34f80b04 | 10666 | |
619c5cb6 | 10667 | if (bnx2x_set_uc_list(bp) < 0) |
6e30dd4e | 10668 | rx_mode = BNX2X_RX_MODE_PROMISC; |
34f80b04 EG |
10669 | } |
10670 | ||
10671 | bp->rx_mode = rx_mode; | |
614c76df DK |
10672 | #ifdef BCM_CNIC |
10673 | /* handle ISCSI SD mode */ | |
10674 | if (IS_MF_ISCSI_SD(bp)) | |
10675 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
10676 | #endif | |
619c5cb6 VZ |
10677 | |
10678 | /* Schedule the rx_mode command */ | |
10679 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) { | |
10680 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); | |
10681 | return; | |
10682 | } | |
10683 | ||
34f80b04 EG |
10684 | bnx2x_set_storm_rx_mode(bp); |
10685 | } | |
10686 | ||
c18487ee | 10687 | /* called with rtnl_lock */ |
01cd4528 EG |
10688 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
10689 | int devad, u16 addr) | |
a2fbb9ea | 10690 | { |
01cd4528 EG |
10691 | struct bnx2x *bp = netdev_priv(netdev); |
10692 | u16 value; | |
10693 | int rc; | |
a2fbb9ea | 10694 | |
01cd4528 EG |
10695 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
10696 | prtad, devad, addr); | |
a2fbb9ea | 10697 | |
01cd4528 EG |
10698 | /* The HW expects different devad if CL22 is used */ |
10699 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
c18487ee | 10700 | |
01cd4528 | 10701 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 10702 | rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value); |
01cd4528 EG |
10703 | bnx2x_release_phy_lock(bp); |
10704 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); | |
a2fbb9ea | 10705 | |
01cd4528 EG |
10706 | if (!rc) |
10707 | rc = value; | |
10708 | return rc; | |
10709 | } | |
a2fbb9ea | 10710 | |
01cd4528 EG |
10711 | /* called with rtnl_lock */ |
10712 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, | |
10713 | u16 addr, u16 value) | |
10714 | { | |
10715 | struct bnx2x *bp = netdev_priv(netdev); | |
01cd4528 EG |
10716 | int rc; |
10717 | ||
51c1a580 MS |
10718 | DP(NETIF_MSG_LINK, |
10719 | "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n", | |
10720 | prtad, devad, addr, value); | |
01cd4528 | 10721 | |
01cd4528 EG |
10722 | /* The HW expects different devad if CL22 is used */ |
10723 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; | |
a2fbb9ea | 10724 | |
01cd4528 | 10725 | bnx2x_acquire_phy_lock(bp); |
e10bc84d | 10726 | rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value); |
01cd4528 EG |
10727 | bnx2x_release_phy_lock(bp); |
10728 | return rc; | |
10729 | } | |
c18487ee | 10730 | |
01cd4528 EG |
10731 | /* called with rtnl_lock */ |
10732 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |
10733 | { | |
10734 | struct bnx2x *bp = netdev_priv(dev); | |
10735 | struct mii_ioctl_data *mdio = if_mii(ifr); | |
a2fbb9ea | 10736 | |
01cd4528 EG |
10737 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
10738 | mdio->phy_id, mdio->reg_num, mdio->val_in); | |
a2fbb9ea | 10739 | |
01cd4528 EG |
10740 | if (!netif_running(dev)) |
10741 | return -EAGAIN; | |
10742 | ||
10743 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); | |
a2fbb9ea ET |
10744 | } |
10745 | ||
257ddbda | 10746 | #ifdef CONFIG_NET_POLL_CONTROLLER |
a2fbb9ea ET |
10747 | static void poll_bnx2x(struct net_device *dev) |
10748 | { | |
10749 | struct bnx2x *bp = netdev_priv(dev); | |
10750 | ||
10751 | disable_irq(bp->pdev->irq); | |
10752 | bnx2x_interrupt(bp->pdev->irq, dev); | |
10753 | enable_irq(bp->pdev->irq); | |
10754 | } | |
10755 | #endif | |
10756 | ||
614c76df DK |
10757 | static int bnx2x_validate_addr(struct net_device *dev) |
10758 | { | |
10759 | struct bnx2x *bp = netdev_priv(dev); | |
10760 | ||
51c1a580 MS |
10761 | if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) { |
10762 | BNX2X_ERR("Non-valid Ethernet address\n"); | |
614c76df | 10763 | return -EADDRNOTAVAIL; |
51c1a580 | 10764 | } |
614c76df DK |
10765 | return 0; |
10766 | } | |
10767 | ||
c64213cd SH |
10768 | static const struct net_device_ops bnx2x_netdev_ops = { |
10769 | .ndo_open = bnx2x_open, | |
10770 | .ndo_stop = bnx2x_close, | |
10771 | .ndo_start_xmit = bnx2x_start_xmit, | |
8307fa3e | 10772 | .ndo_select_queue = bnx2x_select_queue, |
6e30dd4e | 10773 | .ndo_set_rx_mode = bnx2x_set_rx_mode, |
c64213cd | 10774 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
614c76df | 10775 | .ndo_validate_addr = bnx2x_validate_addr, |
c64213cd SH |
10776 | .ndo_do_ioctl = bnx2x_ioctl, |
10777 | .ndo_change_mtu = bnx2x_change_mtu, | |
66371c44 MM |
10778 | .ndo_fix_features = bnx2x_fix_features, |
10779 | .ndo_set_features = bnx2x_set_features, | |
c64213cd | 10780 | .ndo_tx_timeout = bnx2x_tx_timeout, |
257ddbda | 10781 | #ifdef CONFIG_NET_POLL_CONTROLLER |
c64213cd SH |
10782 | .ndo_poll_controller = poll_bnx2x, |
10783 | #endif | |
6383c0b3 AE |
10784 | .ndo_setup_tc = bnx2x_setup_tc, |
10785 | ||
bf61ee14 VZ |
10786 | #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC) |
10787 | .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn, | |
10788 | #endif | |
c64213cd SH |
10789 | }; |
10790 | ||
619c5cb6 VZ |
10791 | static inline int bnx2x_set_coherency_mask(struct bnx2x *bp) |
10792 | { | |
10793 | struct device *dev = &bp->pdev->dev; | |
10794 | ||
10795 | if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { | |
10796 | bp->flags |= USING_DAC_FLAG; | |
10797 | if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { | |
51c1a580 | 10798 | dev_err(dev, "dma_set_coherent_mask failed, aborting\n"); |
619c5cb6 VZ |
10799 | return -EIO; |
10800 | } | |
10801 | } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) { | |
10802 | dev_err(dev, "System does not support DMA, aborting\n"); | |
10803 | return -EIO; | |
10804 | } | |
10805 | ||
10806 | return 0; | |
10807 | } | |
10808 | ||
34f80b04 | 10809 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
619c5cb6 VZ |
10810 | struct net_device *dev, |
10811 | unsigned long board_type) | |
a2fbb9ea ET |
10812 | { |
10813 | struct bnx2x *bp; | |
10814 | int rc; | |
c22610d0 | 10815 | u32 pci_cfg_dword; |
65087cfe AE |
10816 | bool chip_is_e1x = (board_type == BCM57710 || |
10817 | board_type == BCM57711 || | |
10818 | board_type == BCM57711E); | |
a2fbb9ea ET |
10819 | |
10820 | SET_NETDEV_DEV(dev, &pdev->dev); | |
10821 | bp = netdev_priv(dev); | |
10822 | ||
34f80b04 EG |
10823 | bp->dev = dev; |
10824 | bp->pdev = pdev; | |
a2fbb9ea | 10825 | bp->flags = 0; |
a2fbb9ea ET |
10826 | |
10827 | rc = pci_enable_device(pdev); | |
10828 | if (rc) { | |
cdaa7cb8 VZ |
10829 | dev_err(&bp->pdev->dev, |
10830 | "Cannot enable PCI device, aborting\n"); | |
a2fbb9ea ET |
10831 | goto err_out; |
10832 | } | |
10833 | ||
10834 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | |
cdaa7cb8 VZ |
10835 | dev_err(&bp->pdev->dev, |
10836 | "Cannot find PCI device base address, aborting\n"); | |
a2fbb9ea ET |
10837 | rc = -ENODEV; |
10838 | goto err_out_disable; | |
10839 | } | |
10840 | ||
10841 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { | |
cdaa7cb8 VZ |
10842 | dev_err(&bp->pdev->dev, "Cannot find second PCI device" |
10843 | " base address, aborting\n"); | |
a2fbb9ea ET |
10844 | rc = -ENODEV; |
10845 | goto err_out_disable; | |
10846 | } | |
10847 | ||
34f80b04 EG |
10848 | if (atomic_read(&pdev->enable_cnt) == 1) { |
10849 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); | |
10850 | if (rc) { | |
cdaa7cb8 VZ |
10851 | dev_err(&bp->pdev->dev, |
10852 | "Cannot obtain PCI resources, aborting\n"); | |
34f80b04 EG |
10853 | goto err_out_disable; |
10854 | } | |
a2fbb9ea | 10855 | |
34f80b04 EG |
10856 | pci_set_master(pdev); |
10857 | pci_save_state(pdev); | |
10858 | } | |
a2fbb9ea ET |
10859 | |
10860 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
10861 | if (bp->pm_cap == 0) { | |
cdaa7cb8 VZ |
10862 | dev_err(&bp->pdev->dev, |
10863 | "Cannot find power management capability, aborting\n"); | |
a2fbb9ea ET |
10864 | rc = -EIO; |
10865 | goto err_out_release; | |
10866 | } | |
10867 | ||
77c98e6a | 10868 | if (!pci_is_pcie(pdev)) { |
51c1a580 | 10869 | dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n"); |
a2fbb9ea ET |
10870 | rc = -EIO; |
10871 | goto err_out_release; | |
10872 | } | |
10873 | ||
619c5cb6 VZ |
10874 | rc = bnx2x_set_coherency_mask(bp); |
10875 | if (rc) | |
a2fbb9ea | 10876 | goto err_out_release; |
a2fbb9ea | 10877 | |
34f80b04 EG |
10878 | dev->mem_start = pci_resource_start(pdev, 0); |
10879 | dev->base_addr = dev->mem_start; | |
10880 | dev->mem_end = pci_resource_end(pdev, 0); | |
a2fbb9ea ET |
10881 | |
10882 | dev->irq = pdev->irq; | |
10883 | ||
275f165f | 10884 | bp->regview = pci_ioremap_bar(pdev, 0); |
a2fbb9ea | 10885 | if (!bp->regview) { |
cdaa7cb8 VZ |
10886 | dev_err(&bp->pdev->dev, |
10887 | "Cannot map register space, aborting\n"); | |
a2fbb9ea ET |
10888 | rc = -ENOMEM; |
10889 | goto err_out_release; | |
10890 | } | |
10891 | ||
c22610d0 AE |
10892 | /* In E1/E1H use pci device function given by kernel. |
10893 | * In E2/E3 read physical function from ME register since these chips | |
10894 | * support Physical Device Assignment where kernel BDF maybe arbitrary | |
10895 | * (depending on hypervisor). | |
10896 | */ | |
10897 | if (chip_is_e1x) | |
10898 | bp->pf_num = PCI_FUNC(pdev->devfn); | |
10899 | else {/* chip is E2/3*/ | |
10900 | pci_read_config_dword(bp->pdev, | |
10901 | PCICFG_ME_REGISTER, &pci_cfg_dword); | |
10902 | bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >> | |
10903 | ME_REG_ABS_PF_NUM_SHIFT); | |
10904 | } | |
51c1a580 | 10905 | BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num); |
c22610d0 | 10906 | |
a2fbb9ea ET |
10907 | bnx2x_set_power_state(bp, PCI_D0); |
10908 | ||
34f80b04 EG |
10909 | /* clean indirect addresses */ |
10910 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, | |
10911 | PCICFG_VENDOR_ID_OFFSET); | |
a5c53dbc DK |
10912 | /* |
10913 | * Clean the following indirect addresses for all functions since it | |
9f0096a1 DK |
10914 | * is not used by the driver. |
10915 | */ | |
10916 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0); | |
10917 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0); | |
10918 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0); | |
10919 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0); | |
a5c53dbc | 10920 | |
65087cfe | 10921 | if (chip_is_e1x) { |
a5c53dbc DK |
10922 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0); |
10923 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0); | |
10924 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0); | |
10925 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0); | |
10926 | } | |
a2fbb9ea | 10927 | |
2189400b | 10928 | /* |
619c5cb6 | 10929 | * Enable internal target-read (in case we are probed after PF FLR). |
2189400b | 10930 | * Must be done prior to any BAR read access. Only for 57712 and up |
619c5cb6 | 10931 | */ |
65087cfe | 10932 | if (!chip_is_e1x) |
2189400b | 10933 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); |
619c5cb6 | 10934 | |
72fd0718 | 10935 | /* Reset the load counter */ |
889b9af3 | 10936 | bnx2x_clear_load_status(bp); |
72fd0718 | 10937 | |
34f80b04 | 10938 | dev->watchdog_timeo = TX_TIMEOUT; |
a2fbb9ea | 10939 | |
c64213cd | 10940 | dev->netdev_ops = &bnx2x_netdev_ops; |
de0c62db | 10941 | bnx2x_set_ethtool_ops(dev); |
5316bc0b | 10942 | |
01789349 JP |
10943 | dev->priv_flags |= IFF_UNICAST_FLT; |
10944 | ||
66371c44 | 10945 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
621b4d66 DK |
10946 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | |
10947 | NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO | | |
10948 | NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX; | |
66371c44 MM |
10949 | |
10950 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
10951 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; | |
10952 | ||
10953 | dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX; | |
5316bc0b | 10954 | if (bp->flags & USING_DAC_FLAG) |
66371c44 | 10955 | dev->features |= NETIF_F_HIGHDMA; |
a2fbb9ea | 10956 | |
538dd2e3 MB |
10957 | /* Add Loopback capability to the device */ |
10958 | dev->hw_features |= NETIF_F_LOOPBACK; | |
10959 | ||
98507672 | 10960 | #ifdef BCM_DCBNL |
785b9b1a SR |
10961 | dev->dcbnl_ops = &bnx2x_dcbnl_ops; |
10962 | #endif | |
10963 | ||
01cd4528 EG |
10964 | /* get_port_hwinfo() will set prtad and mmds properly */ |
10965 | bp->mdio.prtad = MDIO_PRTAD_NONE; | |
10966 | bp->mdio.mmds = 0; | |
10967 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; | |
10968 | bp->mdio.dev = dev; | |
10969 | bp->mdio.mdio_read = bnx2x_mdio_read; | |
10970 | bp->mdio.mdio_write = bnx2x_mdio_write; | |
10971 | ||
a2fbb9ea ET |
10972 | return 0; |
10973 | ||
a2fbb9ea | 10974 | err_out_release: |
34f80b04 EG |
10975 | if (atomic_read(&pdev->enable_cnt) == 1) |
10976 | pci_release_regions(pdev); | |
a2fbb9ea ET |
10977 | |
10978 | err_out_disable: | |
10979 | pci_disable_device(pdev); | |
10980 | pci_set_drvdata(pdev, NULL); | |
10981 | ||
10982 | err_out: | |
10983 | return rc; | |
10984 | } | |
10985 | ||
37f9ce62 EG |
10986 | static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp, |
10987 | int *width, int *speed) | |
25047950 ET |
10988 | { |
10989 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); | |
10990 | ||
37f9ce62 | 10991 | *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
25047950 | 10992 | |
37f9ce62 EG |
10993 | /* return value of 1=2.5GHz 2=5GHz */ |
10994 | *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; | |
25047950 | 10995 | } |
37f9ce62 | 10996 | |
6891dd25 | 10997 | static int bnx2x_check_firmware(struct bnx2x *bp) |
94a78b79 | 10998 | { |
37f9ce62 | 10999 | const struct firmware *firmware = bp->firmware; |
94a78b79 VZ |
11000 | struct bnx2x_fw_file_hdr *fw_hdr; |
11001 | struct bnx2x_fw_file_section *sections; | |
94a78b79 | 11002 | u32 offset, len, num_ops; |
37f9ce62 | 11003 | u16 *ops_offsets; |
94a78b79 | 11004 | int i; |
37f9ce62 | 11005 | const u8 *fw_ver; |
94a78b79 | 11006 | |
51c1a580 MS |
11007 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) { |
11008 | BNX2X_ERR("Wrong FW size\n"); | |
94a78b79 | 11009 | return -EINVAL; |
51c1a580 | 11010 | } |
94a78b79 VZ |
11011 | |
11012 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; | |
11013 | sections = (struct bnx2x_fw_file_section *)fw_hdr; | |
11014 | ||
11015 | /* Make sure none of the offsets and sizes make us read beyond | |
11016 | * the end of the firmware data */ | |
11017 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { | |
11018 | offset = be32_to_cpu(sections[i].offset); | |
11019 | len = be32_to_cpu(sections[i].len); | |
11020 | if (offset + len > firmware->size) { | |
51c1a580 | 11021 | BNX2X_ERR("Section %d length is out of bounds\n", i); |
94a78b79 VZ |
11022 | return -EINVAL; |
11023 | } | |
11024 | } | |
11025 | ||
11026 | /* Likewise for the init_ops offsets */ | |
11027 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); | |
11028 | ops_offsets = (u16 *)(firmware->data + offset); | |
11029 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); | |
11030 | ||
11031 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { | |
11032 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { | |
51c1a580 | 11033 | BNX2X_ERR("Section offset %d is out of bounds\n", i); |
94a78b79 VZ |
11034 | return -EINVAL; |
11035 | } | |
11036 | } | |
11037 | ||
11038 | /* Check FW version */ | |
11039 | offset = be32_to_cpu(fw_hdr->fw_version.offset); | |
11040 | fw_ver = firmware->data + offset; | |
11041 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || | |
11042 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || | |
11043 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || | |
11044 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { | |
51c1a580 MS |
11045 | BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n", |
11046 | fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3], | |
11047 | BCM_5710_FW_MAJOR_VERSION, | |
94a78b79 VZ |
11048 | BCM_5710_FW_MINOR_VERSION, |
11049 | BCM_5710_FW_REVISION_VERSION, | |
11050 | BCM_5710_FW_ENGINEERING_VERSION); | |
ab6ad5a4 | 11051 | return -EINVAL; |
94a78b79 VZ |
11052 | } |
11053 | ||
11054 | return 0; | |
11055 | } | |
11056 | ||
ab6ad5a4 | 11057 | static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 11058 | { |
ab6ad5a4 EG |
11059 | const __be32 *source = (const __be32 *)_source; |
11060 | u32 *target = (u32 *)_target; | |
94a78b79 | 11061 | u32 i; |
94a78b79 VZ |
11062 | |
11063 | for (i = 0; i < n/4; i++) | |
11064 | target[i] = be32_to_cpu(source[i]); | |
11065 | } | |
11066 | ||
11067 | /* | |
11068 | Ops array is stored in the following format: | |
11069 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} | |
11070 | */ | |
ab6ad5a4 | 11071 | static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 11072 | { |
ab6ad5a4 EG |
11073 | const __be32 *source = (const __be32 *)_source; |
11074 | struct raw_op *target = (struct raw_op *)_target; | |
94a78b79 | 11075 | u32 i, j, tmp; |
94a78b79 | 11076 | |
ab6ad5a4 | 11077 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
94a78b79 VZ |
11078 | tmp = be32_to_cpu(source[j]); |
11079 | target[i].op = (tmp >> 24) & 0xff; | |
cdaa7cb8 VZ |
11080 | target[i].offset = tmp & 0xffffff; |
11081 | target[i].raw_data = be32_to_cpu(source[j + 1]); | |
94a78b79 VZ |
11082 | } |
11083 | } | |
ab6ad5a4 | 11084 | |
523224a3 DK |
11085 | /** |
11086 | * IRO array is stored in the following format: | |
11087 | * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) } | |
11088 | */ | |
11089 | static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n) | |
11090 | { | |
11091 | const __be32 *source = (const __be32 *)_source; | |
11092 | struct iro *target = (struct iro *)_target; | |
11093 | u32 i, j, tmp; | |
11094 | ||
11095 | for (i = 0, j = 0; i < n/sizeof(struct iro); i++) { | |
11096 | target[i].base = be32_to_cpu(source[j]); | |
11097 | j++; | |
11098 | tmp = be32_to_cpu(source[j]); | |
11099 | target[i].m1 = (tmp >> 16) & 0xffff; | |
11100 | target[i].m2 = tmp & 0xffff; | |
11101 | j++; | |
11102 | tmp = be32_to_cpu(source[j]); | |
11103 | target[i].m3 = (tmp >> 16) & 0xffff; | |
11104 | target[i].size = tmp & 0xffff; | |
11105 | j++; | |
11106 | } | |
11107 | } | |
11108 | ||
ab6ad5a4 | 11109 | static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
94a78b79 | 11110 | { |
ab6ad5a4 EG |
11111 | const __be16 *source = (const __be16 *)_source; |
11112 | u16 *target = (u16 *)_target; | |
94a78b79 | 11113 | u32 i; |
94a78b79 VZ |
11114 | |
11115 | for (i = 0; i < n/2; i++) | |
11116 | target[i] = be16_to_cpu(source[i]); | |
11117 | } | |
11118 | ||
7995c64e JP |
11119 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
11120 | do { \ | |
11121 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ | |
11122 | bp->arr = kmalloc(len, GFP_KERNEL); \ | |
e404decb | 11123 | if (!bp->arr) \ |
7995c64e | 11124 | goto lbl; \ |
7995c64e JP |
11125 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
11126 | (u8 *)bp->arr, len); \ | |
11127 | } while (0) | |
94a78b79 | 11128 | |
3b603066 | 11129 | static int bnx2x_init_firmware(struct bnx2x *bp) |
94a78b79 | 11130 | { |
c0ea452e | 11131 | const char *fw_file_name; |
94a78b79 | 11132 | struct bnx2x_fw_file_hdr *fw_hdr; |
45229b42 | 11133 | int rc; |
94a78b79 | 11134 | |
c0ea452e MS |
11135 | if (bp->firmware) |
11136 | return 0; | |
94a78b79 | 11137 | |
c0ea452e MS |
11138 | if (CHIP_IS_E1(bp)) |
11139 | fw_file_name = FW_FILE_NAME_E1; | |
11140 | else if (CHIP_IS_E1H(bp)) | |
11141 | fw_file_name = FW_FILE_NAME_E1H; | |
11142 | else if (!CHIP_IS_E1x(bp)) | |
11143 | fw_file_name = FW_FILE_NAME_E2; | |
11144 | else { | |
11145 | BNX2X_ERR("Unsupported chip revision\n"); | |
11146 | return -EINVAL; | |
11147 | } | |
11148 | BNX2X_DEV_INFO("Loading %s\n", fw_file_name); | |
94a78b79 | 11149 | |
c0ea452e MS |
11150 | rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); |
11151 | if (rc) { | |
11152 | BNX2X_ERR("Can't load firmware file %s\n", | |
11153 | fw_file_name); | |
11154 | goto request_firmware_exit; | |
11155 | } | |
eb2afd4a | 11156 | |
c0ea452e MS |
11157 | rc = bnx2x_check_firmware(bp); |
11158 | if (rc) { | |
11159 | BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); | |
11160 | goto request_firmware_exit; | |
94a78b79 VZ |
11161 | } |
11162 | ||
11163 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; | |
11164 | ||
11165 | /* Initialize the pointers to the init arrays */ | |
11166 | /* Blob */ | |
11167 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); | |
11168 | ||
11169 | /* Opcodes */ | |
11170 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); | |
11171 | ||
11172 | /* Offsets */ | |
ab6ad5a4 EG |
11173 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
11174 | be16_to_cpu_n); | |
94a78b79 VZ |
11175 | |
11176 | /* STORMs firmware */ | |
573f2035 EG |
11177 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
11178 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); | |
11179 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + | |
11180 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); | |
11181 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
11182 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); | |
11183 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + | |
11184 | be32_to_cpu(fw_hdr->usem_pram_data.offset); | |
11185 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
11186 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); | |
11187 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + | |
11188 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); | |
11189 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + | |
11190 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); | |
11191 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + | |
11192 | be32_to_cpu(fw_hdr->csem_pram_data.offset); | |
523224a3 DK |
11193 | /* IRO */ |
11194 | BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro); | |
94a78b79 VZ |
11195 | |
11196 | return 0; | |
ab6ad5a4 | 11197 | |
523224a3 DK |
11198 | iro_alloc_err: |
11199 | kfree(bp->init_ops_offsets); | |
94a78b79 VZ |
11200 | init_offsets_alloc_err: |
11201 | kfree(bp->init_ops); | |
11202 | init_ops_alloc_err: | |
11203 | kfree(bp->init_data); | |
11204 | request_firmware_exit: | |
11205 | release_firmware(bp->firmware); | |
127d0a19 | 11206 | bp->firmware = NULL; |
94a78b79 VZ |
11207 | |
11208 | return rc; | |
11209 | } | |
11210 | ||
619c5cb6 VZ |
11211 | static void bnx2x_release_firmware(struct bnx2x *bp) |
11212 | { | |
11213 | kfree(bp->init_ops_offsets); | |
11214 | kfree(bp->init_ops); | |
11215 | kfree(bp->init_data); | |
11216 | release_firmware(bp->firmware); | |
eb2afd4a | 11217 | bp->firmware = NULL; |
619c5cb6 VZ |
11218 | } |
11219 | ||
11220 | ||
11221 | static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = { | |
11222 | .init_hw_cmn_chip = bnx2x_init_hw_common_chip, | |
11223 | .init_hw_cmn = bnx2x_init_hw_common, | |
11224 | .init_hw_port = bnx2x_init_hw_port, | |
11225 | .init_hw_func = bnx2x_init_hw_func, | |
11226 | ||
11227 | .reset_hw_cmn = bnx2x_reset_common, | |
11228 | .reset_hw_port = bnx2x_reset_port, | |
11229 | .reset_hw_func = bnx2x_reset_func, | |
11230 | ||
11231 | .gunzip_init = bnx2x_gunzip_init, | |
11232 | .gunzip_end = bnx2x_gunzip_end, | |
11233 | ||
11234 | .init_fw = bnx2x_init_firmware, | |
11235 | .release_fw = bnx2x_release_firmware, | |
11236 | }; | |
11237 | ||
11238 | void bnx2x__init_func_obj(struct bnx2x *bp) | |
11239 | { | |
11240 | /* Prepare DMAE related driver resources */ | |
11241 | bnx2x_setup_dmae(bp); | |
11242 | ||
11243 | bnx2x_init_func_obj(bp, &bp->func_obj, | |
11244 | bnx2x_sp(bp, func_rdata), | |
11245 | bnx2x_sp_mapping(bp, func_rdata), | |
11246 | &bnx2x_func_sp_drv); | |
11247 | } | |
11248 | ||
11249 | /* must be called after sriov-enable */ | |
6383c0b3 | 11250 | static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp) |
523224a3 | 11251 | { |
6383c0b3 | 11252 | int cid_count = BNX2X_L2_CID_COUNT(bp); |
94a78b79 | 11253 | |
523224a3 DK |
11254 | #ifdef BCM_CNIC |
11255 | cid_count += CNIC_CID_MAX; | |
11256 | #endif | |
11257 | return roundup(cid_count, QM_CID_ROUND); | |
11258 | } | |
f85582f8 | 11259 | |
619c5cb6 | 11260 | /** |
6383c0b3 | 11261 | * bnx2x_get_num_none_def_sbs - return the number of none default SBs |
619c5cb6 VZ |
11262 | * |
11263 | * @dev: pci device | |
11264 | * | |
11265 | */ | |
6383c0b3 | 11266 | static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev) |
619c5cb6 VZ |
11267 | { |
11268 | int pos; | |
11269 | u16 control; | |
11270 | ||
11271 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); | |
6383c0b3 AE |
11272 | |
11273 | /* | |
11274 | * If MSI-X is not supported - return number of SBs needed to support | |
11275 | * one fast path queue: one FP queue + SB for CNIC | |
11276 | */ | |
619c5cb6 | 11277 | if (!pos) |
6383c0b3 | 11278 | return 1 + CNIC_PRESENT; |
619c5cb6 | 11279 | |
6383c0b3 AE |
11280 | /* |
11281 | * The value in the PCI configuration space is the index of the last | |
11282 | * entry, namely one less than the actual size of the table, which is | |
11283 | * exactly what we want to return from this function: number of all SBs | |
11284 | * without the default SB. | |
11285 | */ | |
619c5cb6 | 11286 | pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control); |
6383c0b3 | 11287 | return control & PCI_MSIX_FLAGS_QSIZE; |
619c5cb6 VZ |
11288 | } |
11289 | ||
a2fbb9ea ET |
11290 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
11291 | const struct pci_device_id *ent) | |
11292 | { | |
a2fbb9ea ET |
11293 | struct net_device *dev = NULL; |
11294 | struct bnx2x *bp; | |
37f9ce62 | 11295 | int pcie_width, pcie_speed; |
6383c0b3 AE |
11296 | int rc, max_non_def_sbs; |
11297 | int rx_count, tx_count, rss_count; | |
11298 | /* | |
11299 | * An estimated maximum supported CoS number according to the chip | |
11300 | * version. | |
11301 | * We will try to roughly estimate the maximum number of CoSes this chip | |
11302 | * may support in order to minimize the memory allocated for Tx | |
11303 | * netdev_queue's. This number will be accurately calculated during the | |
11304 | * initialization of bp->max_cos based on the chip versions AND chip | |
11305 | * revision in the bnx2x_init_bp(). | |
11306 | */ | |
11307 | u8 max_cos_est = 0; | |
523224a3 | 11308 | |
f2e0899f DK |
11309 | switch (ent->driver_data) { |
11310 | case BCM57710: | |
11311 | case BCM57711: | |
11312 | case BCM57711E: | |
6383c0b3 AE |
11313 | max_cos_est = BNX2X_MULTI_TX_COS_E1X; |
11314 | break; | |
11315 | ||
f2e0899f | 11316 | case BCM57712: |
619c5cb6 | 11317 | case BCM57712_MF: |
6383c0b3 AE |
11318 | max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0; |
11319 | break; | |
11320 | ||
619c5cb6 VZ |
11321 | case BCM57800: |
11322 | case BCM57800_MF: | |
11323 | case BCM57810: | |
11324 | case BCM57810_MF: | |
11325 | case BCM57840: | |
11326 | case BCM57840_MF: | |
6383c0b3 | 11327 | max_cos_est = BNX2X_MULTI_TX_COS_E3B0; |
f2e0899f | 11328 | break; |
a2fbb9ea | 11329 | |
f2e0899f DK |
11330 | default: |
11331 | pr_err("Unknown board_type (%ld), aborting\n", | |
11332 | ent->driver_data); | |
870634b0 | 11333 | return -ENODEV; |
f2e0899f DK |
11334 | } |
11335 | ||
6383c0b3 AE |
11336 | max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev); |
11337 | ||
11338 | /* !!! FIXME !!! | |
11339 | * Do not allow the maximum SB count to grow above 16 | |
11340 | * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48. | |
11341 | * We will use the FP_SB_MAX_E1x macro for this matter. | |
11342 | */ | |
11343 | max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs); | |
11344 | ||
11345 | WARN_ON(!max_non_def_sbs); | |
11346 | ||
11347 | /* Maximum number of RSS queues: one IGU SB goes to CNIC */ | |
11348 | rss_count = max_non_def_sbs - CNIC_PRESENT; | |
11349 | ||
11350 | /* Maximum number of netdev Rx queues: RSS + FCoE L2 */ | |
11351 | rx_count = rss_count + FCOE_PRESENT; | |
11352 | ||
11353 | /* | |
11354 | * Maximum number of netdev Tx queues: | |
11355 | * Maximum TSS queues * Maximum supported number of CoS + FCoE L2 | |
11356 | */ | |
11357 | tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT; | |
f85582f8 | 11358 | |
a2fbb9ea | 11359 | /* dev zeroed in init_etherdev */ |
6383c0b3 | 11360 | dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count); |
41de8d4c | 11361 | if (!dev) |
a2fbb9ea ET |
11362 | return -ENOMEM; |
11363 | ||
a2fbb9ea | 11364 | bp = netdev_priv(dev); |
a2fbb9ea | 11365 | |
51c1a580 | 11366 | BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n", |
6383c0b3 | 11367 | tx_count, rx_count); |
df4770de | 11368 | |
6383c0b3 AE |
11369 | bp->igu_sb_cnt = max_non_def_sbs; |
11370 | bp->msg_enable = debug; | |
11371 | pci_set_drvdata(pdev, dev); | |
523224a3 | 11372 | |
619c5cb6 | 11373 | rc = bnx2x_init_dev(pdev, dev, ent->driver_data); |
a2fbb9ea ET |
11374 | if (rc < 0) { |
11375 | free_netdev(dev); | |
11376 | return rc; | |
11377 | } | |
11378 | ||
51c1a580 | 11379 | BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs); |
619c5cb6 | 11380 | |
34f80b04 | 11381 | rc = bnx2x_init_bp(bp); |
693fc0d1 EG |
11382 | if (rc) |
11383 | goto init_one_exit; | |
11384 | ||
6383c0b3 AE |
11385 | /* |
11386 | * Map doorbels here as we need the real value of bp->max_cos which | |
11387 | * is initialized in bnx2x_init_bp(). | |
11388 | */ | |
11389 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), | |
11390 | min_t(u64, BNX2X_DB_SIZE(bp), | |
11391 | pci_resource_len(pdev, 2))); | |
11392 | if (!bp->doorbells) { | |
11393 | dev_err(&bp->pdev->dev, | |
11394 | "Cannot map doorbell space, aborting\n"); | |
11395 | rc = -ENOMEM; | |
11396 | goto init_one_exit; | |
11397 | } | |
11398 | ||
523224a3 | 11399 | /* calc qm_cid_count */ |
6383c0b3 | 11400 | bp->qm_cid_count = bnx2x_set_qm_cid_count(bp); |
523224a3 | 11401 | |
ec6ba945 | 11402 | #ifdef BCM_CNIC |
62ac0dc9 DK |
11403 | /* disable FCOE L2 queue for E1x */ |
11404 | if (CHIP_IS_E1x(bp)) | |
ec6ba945 VZ |
11405 | bp->flags |= NO_FCOE_FLAG; |
11406 | ||
11407 | #endif | |
11408 | ||
25985edc | 11409 | /* Configure interrupt mode: try to enable MSI-X/MSI if |
d6214d7a DK |
11410 | * needed, set bp->num_queues appropriately. |
11411 | */ | |
11412 | bnx2x_set_int_mode(bp); | |
11413 | ||
11414 | /* Add all NAPI objects */ | |
11415 | bnx2x_add_all_napi(bp); | |
11416 | ||
b340007f VZ |
11417 | rc = register_netdev(dev); |
11418 | if (rc) { | |
11419 | dev_err(&pdev->dev, "Cannot register net device\n"); | |
11420 | goto init_one_exit; | |
11421 | } | |
11422 | ||
ec6ba945 VZ |
11423 | #ifdef BCM_CNIC |
11424 | if (!NO_FCOE(bp)) { | |
11425 | /* Add storage MAC address */ | |
11426 | rtnl_lock(); | |
11427 | dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
11428 | rtnl_unlock(); | |
11429 | } | |
11430 | #endif | |
11431 | ||
37f9ce62 | 11432 | bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed); |
d6214d7a | 11433 | |
51c1a580 MS |
11434 | BNX2X_DEV_INFO( |
11435 | "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n", | |
94f05b0f JP |
11436 | board_info[ent->driver_data].name, |
11437 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), | |
11438 | pcie_width, | |
11439 | ((!CHIP_IS_E2(bp) && pcie_speed == 2) || | |
11440 | (CHIP_IS_E2(bp) && pcie_speed == 1)) ? | |
11441 | "5GHz (Gen2)" : "2.5GHz", | |
11442 | dev->base_addr, bp->pdev->irq, dev->dev_addr); | |
c016201c | 11443 | |
a2fbb9ea | 11444 | return 0; |
34f80b04 EG |
11445 | |
11446 | init_one_exit: | |
11447 | if (bp->regview) | |
11448 | iounmap(bp->regview); | |
11449 | ||
11450 | if (bp->doorbells) | |
11451 | iounmap(bp->doorbells); | |
11452 | ||
11453 | free_netdev(dev); | |
11454 | ||
11455 | if (atomic_read(&pdev->enable_cnt) == 1) | |
11456 | pci_release_regions(pdev); | |
11457 | ||
11458 | pci_disable_device(pdev); | |
11459 | pci_set_drvdata(pdev, NULL); | |
11460 | ||
11461 | return rc; | |
a2fbb9ea ET |
11462 | } |
11463 | ||
11464 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) | |
11465 | { | |
11466 | struct net_device *dev = pci_get_drvdata(pdev); | |
228241eb ET |
11467 | struct bnx2x *bp; |
11468 | ||
11469 | if (!dev) { | |
cdaa7cb8 | 11470 | dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n"); |
228241eb ET |
11471 | return; |
11472 | } | |
228241eb | 11473 | bp = netdev_priv(dev); |
a2fbb9ea | 11474 | |
ec6ba945 VZ |
11475 | #ifdef BCM_CNIC |
11476 | /* Delete storage MAC address */ | |
11477 | if (!NO_FCOE(bp)) { | |
11478 | rtnl_lock(); | |
11479 | dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); | |
11480 | rtnl_unlock(); | |
11481 | } | |
11482 | #endif | |
11483 | ||
98507672 SR |
11484 | #ifdef BCM_DCBNL |
11485 | /* Delete app tlvs from dcbnl */ | |
11486 | bnx2x_dcbnl_update_applist(bp, true); | |
11487 | #endif | |
11488 | ||
a2fbb9ea ET |
11489 | unregister_netdev(dev); |
11490 | ||
d6214d7a DK |
11491 | /* Delete all NAPI objects */ |
11492 | bnx2x_del_all_napi(bp); | |
11493 | ||
084d6cbb VZ |
11494 | /* Power on: we can't let PCI layer write to us while we are in D3 */ |
11495 | bnx2x_set_power_state(bp, PCI_D0); | |
11496 | ||
d6214d7a DK |
11497 | /* Disable MSI/MSI-X */ |
11498 | bnx2x_disable_msi(bp); | |
f85582f8 | 11499 | |
084d6cbb VZ |
11500 | /* Power off */ |
11501 | bnx2x_set_power_state(bp, PCI_D3hot); | |
11502 | ||
72fd0718 | 11503 | /* Make sure RESET task is not scheduled before continuing */ |
7be08a72 | 11504 | cancel_delayed_work_sync(&bp->sp_rtnl_task); |
72fd0718 | 11505 | |
a2fbb9ea ET |
11506 | if (bp->regview) |
11507 | iounmap(bp->regview); | |
11508 | ||
11509 | if (bp->doorbells) | |
11510 | iounmap(bp->doorbells); | |
11511 | ||
eb2afd4a DK |
11512 | bnx2x_release_firmware(bp); |
11513 | ||
523224a3 DK |
11514 | bnx2x_free_mem_bp(bp); |
11515 | ||
a2fbb9ea | 11516 | free_netdev(dev); |
34f80b04 EG |
11517 | |
11518 | if (atomic_read(&pdev->enable_cnt) == 1) | |
11519 | pci_release_regions(pdev); | |
11520 | ||
a2fbb9ea ET |
11521 | pci_disable_device(pdev); |
11522 | pci_set_drvdata(pdev, NULL); | |
11523 | } | |
11524 | ||
f8ef6e44 YG |
11525 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
11526 | { | |
11527 | int i; | |
11528 | ||
11529 | bp->state = BNX2X_STATE_ERROR; | |
11530 | ||
11531 | bp->rx_mode = BNX2X_RX_MODE_NONE; | |
11532 | ||
619c5cb6 VZ |
11533 | #ifdef BCM_CNIC |
11534 | bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD); | |
11535 | #endif | |
11536 | /* Stop Tx */ | |
11537 | bnx2x_tx_disable(bp); | |
11538 | ||
f8ef6e44 YG |
11539 | bnx2x_netif_stop(bp, 0); |
11540 | ||
11541 | del_timer_sync(&bp->timer); | |
619c5cb6 VZ |
11542 | |
11543 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); | |
f8ef6e44 YG |
11544 | |
11545 | /* Release IRQs */ | |
d6214d7a | 11546 | bnx2x_free_irq(bp); |
f8ef6e44 | 11547 | |
f8ef6e44 YG |
11548 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
11549 | bnx2x_free_skbs(bp); | |
523224a3 | 11550 | |
ec6ba945 | 11551 | for_each_rx_queue(bp, i) |
f8ef6e44 | 11552 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
d6214d7a | 11553 | |
f8ef6e44 YG |
11554 | bnx2x_free_mem(bp); |
11555 | ||
11556 | bp->state = BNX2X_STATE_CLOSED; | |
11557 | ||
619c5cb6 VZ |
11558 | netif_carrier_off(bp->dev); |
11559 | ||
f8ef6e44 YG |
11560 | return 0; |
11561 | } | |
11562 | ||
11563 | static void bnx2x_eeh_recover(struct bnx2x *bp) | |
11564 | { | |
11565 | u32 val; | |
11566 | ||
11567 | mutex_init(&bp->port.phy_mutex); | |
11568 | ||
f8ef6e44 YG |
11569 | |
11570 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); | |
11571 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) | |
11572 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) | |
11573 | BNX2X_ERR("BAD MCP validity signature\n"); | |
f8ef6e44 YG |
11574 | } |
11575 | ||
493adb1f WX |
11576 | /** |
11577 | * bnx2x_io_error_detected - called when PCI error is detected | |
11578 | * @pdev: Pointer to PCI device | |
11579 | * @state: The current pci connection state | |
11580 | * | |
11581 | * This function is called after a PCI bus error affecting | |
11582 | * this device has been detected. | |
11583 | */ | |
11584 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, | |
11585 | pci_channel_state_t state) | |
11586 | { | |
11587 | struct net_device *dev = pci_get_drvdata(pdev); | |
11588 | struct bnx2x *bp = netdev_priv(dev); | |
11589 | ||
11590 | rtnl_lock(); | |
11591 | ||
11592 | netif_device_detach(dev); | |
11593 | ||
07ce50e4 DN |
11594 | if (state == pci_channel_io_perm_failure) { |
11595 | rtnl_unlock(); | |
11596 | return PCI_ERS_RESULT_DISCONNECT; | |
11597 | } | |
11598 | ||
493adb1f | 11599 | if (netif_running(dev)) |
f8ef6e44 | 11600 | bnx2x_eeh_nic_unload(bp); |
493adb1f WX |
11601 | |
11602 | pci_disable_device(pdev); | |
11603 | ||
11604 | rtnl_unlock(); | |
11605 | ||
11606 | /* Request a slot reset */ | |
11607 | return PCI_ERS_RESULT_NEED_RESET; | |
11608 | } | |
11609 | ||
11610 | /** | |
11611 | * bnx2x_io_slot_reset - called after the PCI bus has been reset | |
11612 | * @pdev: Pointer to PCI device | |
11613 | * | |
11614 | * Restart the card from scratch, as if from a cold-boot. | |
11615 | */ | |
11616 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) | |
11617 | { | |
11618 | struct net_device *dev = pci_get_drvdata(pdev); | |
11619 | struct bnx2x *bp = netdev_priv(dev); | |
11620 | ||
11621 | rtnl_lock(); | |
11622 | ||
11623 | if (pci_enable_device(pdev)) { | |
11624 | dev_err(&pdev->dev, | |
11625 | "Cannot re-enable PCI device after reset\n"); | |
11626 | rtnl_unlock(); | |
11627 | return PCI_ERS_RESULT_DISCONNECT; | |
11628 | } | |
11629 | ||
11630 | pci_set_master(pdev); | |
11631 | pci_restore_state(pdev); | |
11632 | ||
11633 | if (netif_running(dev)) | |
11634 | bnx2x_set_power_state(bp, PCI_D0); | |
11635 | ||
11636 | rtnl_unlock(); | |
11637 | ||
11638 | return PCI_ERS_RESULT_RECOVERED; | |
11639 | } | |
11640 | ||
11641 | /** | |
11642 | * bnx2x_io_resume - called when traffic can start flowing again | |
11643 | * @pdev: Pointer to PCI device | |
11644 | * | |
11645 | * This callback is called when the error recovery driver tells us that | |
11646 | * its OK to resume normal operation. | |
11647 | */ | |
11648 | static void bnx2x_io_resume(struct pci_dev *pdev) | |
11649 | { | |
11650 | struct net_device *dev = pci_get_drvdata(pdev); | |
11651 | struct bnx2x *bp = netdev_priv(dev); | |
11652 | ||
72fd0718 | 11653 | if (bp->recovery_state != BNX2X_RECOVERY_DONE) { |
51c1a580 | 11654 | netdev_err(bp->dev, "Handling parity error recovery. Try again later\n"); |
72fd0718 VZ |
11655 | return; |
11656 | } | |
11657 | ||
493adb1f WX |
11658 | rtnl_lock(); |
11659 | ||
f8ef6e44 YG |
11660 | bnx2x_eeh_recover(bp); |
11661 | ||
493adb1f | 11662 | if (netif_running(dev)) |
f8ef6e44 | 11663 | bnx2x_nic_load(bp, LOAD_NORMAL); |
493adb1f WX |
11664 | |
11665 | netif_device_attach(dev); | |
11666 | ||
11667 | rtnl_unlock(); | |
11668 | } | |
11669 | ||
11670 | static struct pci_error_handlers bnx2x_err_handler = { | |
11671 | .error_detected = bnx2x_io_error_detected, | |
356e2385 EG |
11672 | .slot_reset = bnx2x_io_slot_reset, |
11673 | .resume = bnx2x_io_resume, | |
493adb1f WX |
11674 | }; |
11675 | ||
a2fbb9ea | 11676 | static struct pci_driver bnx2x_pci_driver = { |
493adb1f WX |
11677 | .name = DRV_MODULE_NAME, |
11678 | .id_table = bnx2x_pci_tbl, | |
11679 | .probe = bnx2x_init_one, | |
11680 | .remove = __devexit_p(bnx2x_remove_one), | |
11681 | .suspend = bnx2x_suspend, | |
11682 | .resume = bnx2x_resume, | |
11683 | .err_handler = &bnx2x_err_handler, | |
a2fbb9ea ET |
11684 | }; |
11685 | ||
11686 | static int __init bnx2x_init(void) | |
11687 | { | |
dd21ca6d SG |
11688 | int ret; |
11689 | ||
7995c64e | 11690 | pr_info("%s", version); |
938cf541 | 11691 | |
1cf167f2 EG |
11692 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
11693 | if (bnx2x_wq == NULL) { | |
7995c64e | 11694 | pr_err("Cannot create workqueue\n"); |
1cf167f2 EG |
11695 | return -ENOMEM; |
11696 | } | |
11697 | ||
dd21ca6d SG |
11698 | ret = pci_register_driver(&bnx2x_pci_driver); |
11699 | if (ret) { | |
7995c64e | 11700 | pr_err("Cannot register driver\n"); |
dd21ca6d SG |
11701 | destroy_workqueue(bnx2x_wq); |
11702 | } | |
11703 | return ret; | |
a2fbb9ea ET |
11704 | } |
11705 | ||
11706 | static void __exit bnx2x_cleanup(void) | |
11707 | { | |
452427b0 | 11708 | struct list_head *pos, *q; |
a2fbb9ea | 11709 | pci_unregister_driver(&bnx2x_pci_driver); |
1cf167f2 EG |
11710 | |
11711 | destroy_workqueue(bnx2x_wq); | |
452427b0 YM |
11712 | |
11713 | /* Free globablly allocated resources */ | |
11714 | list_for_each_safe(pos, q, &bnx2x_prev_list) { | |
11715 | struct bnx2x_prev_path_list *tmp = | |
11716 | list_entry(pos, struct bnx2x_prev_path_list, list); | |
11717 | list_del(pos); | |
11718 | kfree(tmp); | |
11719 | } | |
a2fbb9ea ET |
11720 | } |
11721 | ||
3deb8167 YR |
11722 | void bnx2x_notify_link_changed(struct bnx2x *bp) |
11723 | { | |
11724 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1); | |
11725 | } | |
11726 | ||
a2fbb9ea ET |
11727 | module_init(bnx2x_init); |
11728 | module_exit(bnx2x_cleanup); | |
11729 | ||
993ac7b5 | 11730 | #ifdef BCM_CNIC |
619c5cb6 VZ |
11731 | /** |
11732 | * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s). | |
11733 | * | |
11734 | * @bp: driver handle | |
11735 | * @set: set or clear the CAM entry | |
11736 | * | |
11737 | * This function will wait until the ramdord completion returns. | |
11738 | * Return 0 if success, -ENODEV if ramrod doesn't return. | |
11739 | */ | |
11740 | static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp) | |
11741 | { | |
11742 | unsigned long ramrod_flags = 0; | |
11743 | ||
11744 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | |
11745 | return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac, | |
11746 | &bp->iscsi_l2_mac_obj, true, | |
11747 | BNX2X_ISCSI_ETH_MAC, &ramrod_flags); | |
11748 | } | |
993ac7b5 MC |
11749 | |
11750 | /* count denotes the number of new completions we have seen */ | |
11751 | static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count) | |
11752 | { | |
11753 | struct eth_spe *spe; | |
11754 | ||
11755 | #ifdef BNX2X_STOP_ON_ERROR | |
11756 | if (unlikely(bp->panic)) | |
11757 | return; | |
11758 | #endif | |
11759 | ||
11760 | spin_lock_bh(&bp->spq_lock); | |
c2bff63f | 11761 | BUG_ON(bp->cnic_spq_pending < count); |
993ac7b5 MC |
11762 | bp->cnic_spq_pending -= count; |
11763 | ||
993ac7b5 | 11764 | |
c2bff63f DK |
11765 | for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) { |
11766 | u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type) | |
11767 | & SPE_HDR_CONN_TYPE) >> | |
11768 | SPE_HDR_CONN_TYPE_SHIFT; | |
619c5cb6 VZ |
11769 | u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data) |
11770 | >> SPE_HDR_CMD_ID_SHIFT) & 0xff; | |
c2bff63f DK |
11771 | |
11772 | /* Set validation for iSCSI L2 client before sending SETUP | |
11773 | * ramrod | |
11774 | */ | |
11775 | if (type == ETH_CONNECTION_TYPE) { | |
c2bff63f | 11776 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) |
619c5cb6 VZ |
11777 | bnx2x_set_ctx_validation(bp, &bp->context. |
11778 | vcxt[BNX2X_ISCSI_ETH_CID].eth, | |
11779 | BNX2X_ISCSI_ETH_CID); | |
c2bff63f DK |
11780 | } |
11781 | ||
619c5cb6 VZ |
11782 | /* |
11783 | * There may be not more than 8 L2, not more than 8 L5 SPEs | |
11784 | * and in the air. We also check that number of outstanding | |
6e30dd4e VZ |
11785 | * COMMON ramrods is not more than the EQ and SPQ can |
11786 | * accommodate. | |
c2bff63f | 11787 | */ |
6e30dd4e VZ |
11788 | if (type == ETH_CONNECTION_TYPE) { |
11789 | if (!atomic_read(&bp->cq_spq_left)) | |
11790 | break; | |
11791 | else | |
11792 | atomic_dec(&bp->cq_spq_left); | |
11793 | } else if (type == NONE_CONNECTION_TYPE) { | |
11794 | if (!atomic_read(&bp->eq_spq_left)) | |
c2bff63f DK |
11795 | break; |
11796 | else | |
6e30dd4e | 11797 | atomic_dec(&bp->eq_spq_left); |
ec6ba945 VZ |
11798 | } else if ((type == ISCSI_CONNECTION_TYPE) || |
11799 | (type == FCOE_CONNECTION_TYPE)) { | |
c2bff63f DK |
11800 | if (bp->cnic_spq_pending >= |
11801 | bp->cnic_eth_dev.max_kwqe_pending) | |
11802 | break; | |
11803 | else | |
11804 | bp->cnic_spq_pending++; | |
11805 | } else { | |
11806 | BNX2X_ERR("Unknown SPE type: %d\n", type); | |
11807 | bnx2x_panic(); | |
993ac7b5 | 11808 | break; |
c2bff63f | 11809 | } |
993ac7b5 MC |
11810 | |
11811 | spe = bnx2x_sp_get_next(bp); | |
11812 | *spe = *bp->cnic_kwq_cons; | |
11813 | ||
51c1a580 | 11814 | DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n", |
993ac7b5 MC |
11815 | bp->cnic_spq_pending, bp->cnic_kwq_pending, count); |
11816 | ||
11817 | if (bp->cnic_kwq_cons == bp->cnic_kwq_last) | |
11818 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
11819 | else | |
11820 | bp->cnic_kwq_cons++; | |
11821 | } | |
11822 | bnx2x_sp_prod_update(bp); | |
11823 | spin_unlock_bh(&bp->spq_lock); | |
11824 | } | |
11825 | ||
11826 | static int bnx2x_cnic_sp_queue(struct net_device *dev, | |
11827 | struct kwqe_16 *kwqes[], u32 count) | |
11828 | { | |
11829 | struct bnx2x *bp = netdev_priv(dev); | |
11830 | int i; | |
11831 | ||
11832 | #ifdef BNX2X_STOP_ON_ERROR | |
51c1a580 MS |
11833 | if (unlikely(bp->panic)) { |
11834 | BNX2X_ERR("Can't post to SP queue while panic\n"); | |
993ac7b5 | 11835 | return -EIO; |
51c1a580 | 11836 | } |
993ac7b5 MC |
11837 | #endif |
11838 | ||
95c6c616 AE |
11839 | if ((bp->recovery_state != BNX2X_RECOVERY_DONE) && |
11840 | (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) { | |
51c1a580 | 11841 | BNX2X_ERR("Handling parity error recovery. Try again later\n"); |
95c6c616 AE |
11842 | return -EAGAIN; |
11843 | } | |
11844 | ||
993ac7b5 MC |
11845 | spin_lock_bh(&bp->spq_lock); |
11846 | ||
11847 | for (i = 0; i < count; i++) { | |
11848 | struct eth_spe *spe = (struct eth_spe *)kwqes[i]; | |
11849 | ||
11850 | if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT) | |
11851 | break; | |
11852 | ||
11853 | *bp->cnic_kwq_prod = *spe; | |
11854 | ||
11855 | bp->cnic_kwq_pending++; | |
11856 | ||
51c1a580 | 11857 | DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n", |
993ac7b5 | 11858 | spe->hdr.conn_and_cmd_data, spe->hdr.type, |
523224a3 DK |
11859 | spe->data.update_data_addr.hi, |
11860 | spe->data.update_data_addr.lo, | |
993ac7b5 MC |
11861 | bp->cnic_kwq_pending); |
11862 | ||
11863 | if (bp->cnic_kwq_prod == bp->cnic_kwq_last) | |
11864 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
11865 | else | |
11866 | bp->cnic_kwq_prod++; | |
11867 | } | |
11868 | ||
11869 | spin_unlock_bh(&bp->spq_lock); | |
11870 | ||
11871 | if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending) | |
11872 | bnx2x_cnic_sp_post(bp, 0); | |
11873 | ||
11874 | return i; | |
11875 | } | |
11876 | ||
11877 | static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
11878 | { | |
11879 | struct cnic_ops *c_ops; | |
11880 | int rc = 0; | |
11881 | ||
11882 | mutex_lock(&bp->cnic_mutex); | |
13707f9e ED |
11883 | c_ops = rcu_dereference_protected(bp->cnic_ops, |
11884 | lockdep_is_held(&bp->cnic_mutex)); | |
993ac7b5 MC |
11885 | if (c_ops) |
11886 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
11887 | mutex_unlock(&bp->cnic_mutex); | |
11888 | ||
11889 | return rc; | |
11890 | } | |
11891 | ||
11892 | static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl) | |
11893 | { | |
11894 | struct cnic_ops *c_ops; | |
11895 | int rc = 0; | |
11896 | ||
11897 | rcu_read_lock(); | |
11898 | c_ops = rcu_dereference(bp->cnic_ops); | |
11899 | if (c_ops) | |
11900 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); | |
11901 | rcu_read_unlock(); | |
11902 | ||
11903 | return rc; | |
11904 | } | |
11905 | ||
11906 | /* | |
11907 | * for commands that have no data | |
11908 | */ | |
9f6c9258 | 11909 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd) |
993ac7b5 MC |
11910 | { |
11911 | struct cnic_ctl_info ctl = {0}; | |
11912 | ||
11913 | ctl.cmd = cmd; | |
11914 | ||
11915 | return bnx2x_cnic_ctl_send(bp, &ctl); | |
11916 | } | |
11917 | ||
619c5cb6 | 11918 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err) |
993ac7b5 | 11919 | { |
619c5cb6 | 11920 | struct cnic_ctl_info ctl = {0}; |
993ac7b5 MC |
11921 | |
11922 | /* first we tell CNIC and only then we count this as a completion */ | |
11923 | ctl.cmd = CNIC_CTL_COMPLETION_CMD; | |
11924 | ctl.data.comp.cid = cid; | |
619c5cb6 | 11925 | ctl.data.comp.error = err; |
993ac7b5 MC |
11926 | |
11927 | bnx2x_cnic_ctl_send_bh(bp, &ctl); | |
c2bff63f | 11928 | bnx2x_cnic_sp_post(bp, 0); |
993ac7b5 MC |
11929 | } |
11930 | ||
619c5cb6 VZ |
11931 | |
11932 | /* Called with netif_addr_lock_bh() taken. | |
11933 | * Sets an rx_mode config for an iSCSI ETH client. | |
11934 | * Doesn't block. | |
11935 | * Completion should be checked outside. | |
11936 | */ | |
11937 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start) | |
11938 | { | |
11939 | unsigned long accept_flags = 0, ramrod_flags = 0; | |
11940 | u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
11941 | int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED; | |
11942 | ||
11943 | if (start) { | |
11944 | /* Start accepting on iSCSI L2 ring. Accept all multicasts | |
11945 | * because it's the only way for UIO Queue to accept | |
11946 | * multicasts (in non-promiscuous mode only one Queue per | |
11947 | * function will receive multicast packets (leading in our | |
11948 | * case). | |
11949 | */ | |
11950 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags); | |
11951 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags); | |
11952 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags); | |
11953 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); | |
11954 | ||
11955 | /* Clear STOP_PENDING bit if START is requested */ | |
11956 | clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state); | |
11957 | ||
11958 | sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED; | |
11959 | } else | |
11960 | /* Clear START_PENDING bit if STOP is requested */ | |
11961 | clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state); | |
11962 | ||
11963 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) | |
11964 | set_bit(sched_state, &bp->sp_state); | |
11965 | else { | |
11966 | __set_bit(RAMROD_RX, &ramrod_flags); | |
11967 | bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0, | |
11968 | ramrod_flags); | |
11969 | } | |
11970 | } | |
11971 | ||
11972 | ||
993ac7b5 MC |
11973 | static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl) |
11974 | { | |
11975 | struct bnx2x *bp = netdev_priv(dev); | |
11976 | int rc = 0; | |
11977 | ||
11978 | switch (ctl->cmd) { | |
11979 | case DRV_CTL_CTXTBL_WR_CMD: { | |
11980 | u32 index = ctl->data.io.offset; | |
11981 | dma_addr_t addr = ctl->data.io.dma_addr; | |
11982 | ||
11983 | bnx2x_ilt_wr(bp, index, addr); | |
11984 | break; | |
11985 | } | |
11986 | ||
c2bff63f DK |
11987 | case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: { |
11988 | int count = ctl->data.credit.credit_count; | |
993ac7b5 MC |
11989 | |
11990 | bnx2x_cnic_sp_post(bp, count); | |
11991 | break; | |
11992 | } | |
11993 | ||
11994 | /* rtnl_lock is held. */ | |
11995 | case DRV_CTL_START_L2_CMD: { | |
619c5cb6 VZ |
11996 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
11997 | unsigned long sp_bits = 0; | |
11998 | ||
11999 | /* Configure the iSCSI classification object */ | |
12000 | bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj, | |
12001 | cp->iscsi_l2_client_id, | |
12002 | cp->iscsi_l2_cid, BP_FUNC(bp), | |
12003 | bnx2x_sp(bp, mac_rdata), | |
12004 | bnx2x_sp_mapping(bp, mac_rdata), | |
12005 | BNX2X_FILTER_MAC_PENDING, | |
12006 | &bp->sp_state, BNX2X_OBJ_TYPE_RX, | |
12007 | &bp->macs_pool); | |
ec6ba945 | 12008 | |
523224a3 | 12009 | /* Set iSCSI MAC address */ |
619c5cb6 VZ |
12010 | rc = bnx2x_set_iscsi_eth_mac_addr(bp); |
12011 | if (rc) | |
12012 | break; | |
523224a3 DK |
12013 | |
12014 | mmiowb(); | |
12015 | barrier(); | |
12016 | ||
619c5cb6 VZ |
12017 | /* Start accepting on iSCSI L2 ring */ |
12018 | ||
12019 | netif_addr_lock_bh(dev); | |
12020 | bnx2x_set_iscsi_eth_rx_mode(bp, true); | |
12021 | netif_addr_unlock_bh(dev); | |
12022 | ||
12023 | /* bits to wait on */ | |
12024 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
12025 | __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits); | |
12026 | ||
12027 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
12028 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 | 12029 | |
993ac7b5 MC |
12030 | break; |
12031 | } | |
12032 | ||
12033 | /* rtnl_lock is held. */ | |
12034 | case DRV_CTL_STOP_L2_CMD: { | |
619c5cb6 | 12035 | unsigned long sp_bits = 0; |
993ac7b5 | 12036 | |
523224a3 | 12037 | /* Stop accepting on iSCSI L2 ring */ |
619c5cb6 VZ |
12038 | netif_addr_lock_bh(dev); |
12039 | bnx2x_set_iscsi_eth_rx_mode(bp, false); | |
12040 | netif_addr_unlock_bh(dev); | |
12041 | ||
12042 | /* bits to wait on */ | |
12043 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); | |
12044 | __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits); | |
12045 | ||
12046 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) | |
12047 | BNX2X_ERR("rx_mode completion timed out!\n"); | |
523224a3 DK |
12048 | |
12049 | mmiowb(); | |
12050 | barrier(); | |
12051 | ||
12052 | /* Unset iSCSI L2 MAC */ | |
619c5cb6 VZ |
12053 | rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj, |
12054 | BNX2X_ISCSI_ETH_MAC, true); | |
993ac7b5 MC |
12055 | break; |
12056 | } | |
c2bff63f DK |
12057 | case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: { |
12058 | int count = ctl->data.credit.credit_count; | |
12059 | ||
12060 | smp_mb__before_atomic_inc(); | |
6e30dd4e | 12061 | atomic_add(count, &bp->cq_spq_left); |
c2bff63f DK |
12062 | smp_mb__after_atomic_inc(); |
12063 | break; | |
12064 | } | |
1d187b34 BW |
12065 | case DRV_CTL_ULP_REGISTER_CMD: { |
12066 | int ulp_type = ctl->data.ulp_type; | |
12067 | ||
12068 | if (CHIP_IS_E3(bp)) { | |
12069 | int idx = BP_FW_MB_IDX(bp); | |
12070 | u32 cap; | |
12071 | ||
12072 | cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); | |
12073 | if (ulp_type == CNIC_ULP_ISCSI) | |
12074 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
12075 | else if (ulp_type == CNIC_ULP_FCOE) | |
12076 | cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
12077 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
12078 | } | |
12079 | break; | |
12080 | } | |
12081 | case DRV_CTL_ULP_UNREGISTER_CMD: { | |
12082 | int ulp_type = ctl->data.ulp_type; | |
12083 | ||
12084 | if (CHIP_IS_E3(bp)) { | |
12085 | int idx = BP_FW_MB_IDX(bp); | |
12086 | u32 cap; | |
12087 | ||
12088 | cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]); | |
12089 | if (ulp_type == CNIC_ULP_ISCSI) | |
12090 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI; | |
12091 | else if (ulp_type == CNIC_ULP_FCOE) | |
12092 | cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE; | |
12093 | SHMEM2_WR(bp, drv_capabilities_flag[idx], cap); | |
12094 | } | |
12095 | break; | |
12096 | } | |
993ac7b5 MC |
12097 | |
12098 | default: | |
12099 | BNX2X_ERR("unknown command %x\n", ctl->cmd); | |
12100 | rc = -EINVAL; | |
12101 | } | |
12102 | ||
12103 | return rc; | |
12104 | } | |
12105 | ||
9f6c9258 | 12106 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) |
993ac7b5 MC |
12107 | { |
12108 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
12109 | ||
12110 | if (bp->flags & USING_MSIX_FLAG) { | |
12111 | cp->drv_state |= CNIC_DRV_STATE_USING_MSIX; | |
12112 | cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX; | |
12113 | cp->irq_arr[0].vector = bp->msix_table[1].vector; | |
12114 | } else { | |
12115 | cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX; | |
12116 | cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX; | |
12117 | } | |
619c5cb6 | 12118 | if (!CHIP_IS_E1x(bp)) |
f2e0899f DK |
12119 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb; |
12120 | else | |
12121 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; | |
12122 | ||
619c5cb6 VZ |
12123 | cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); |
12124 | cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); | |
993ac7b5 MC |
12125 | cp->irq_arr[1].status_blk = bp->def_status_blk; |
12126 | cp->irq_arr[1].status_blk_num = DEF_SB_ID; | |
523224a3 | 12127 | cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; |
993ac7b5 MC |
12128 | |
12129 | cp->num_irq = 2; | |
12130 | } | |
12131 | ||
12132 | static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops, | |
12133 | void *data) | |
12134 | { | |
12135 | struct bnx2x *bp = netdev_priv(dev); | |
12136 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
12137 | ||
51c1a580 MS |
12138 | if (ops == NULL) { |
12139 | BNX2X_ERR("NULL ops received\n"); | |
993ac7b5 | 12140 | return -EINVAL; |
51c1a580 | 12141 | } |
993ac7b5 | 12142 | |
993ac7b5 MC |
12143 | bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL); |
12144 | if (!bp->cnic_kwq) | |
12145 | return -ENOMEM; | |
12146 | ||
12147 | bp->cnic_kwq_cons = bp->cnic_kwq; | |
12148 | bp->cnic_kwq_prod = bp->cnic_kwq; | |
12149 | bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT; | |
12150 | ||
12151 | bp->cnic_spq_pending = 0; | |
12152 | bp->cnic_kwq_pending = 0; | |
12153 | ||
12154 | bp->cnic_data = data; | |
12155 | ||
12156 | cp->num_irq = 0; | |
619c5cb6 | 12157 | cp->drv_state |= CNIC_DRV_STATE_REGD; |
523224a3 | 12158 | cp->iro_arr = bp->iro_arr; |
993ac7b5 | 12159 | |
993ac7b5 | 12160 | bnx2x_setup_cnic_irq_info(bp); |
c2bff63f | 12161 | |
993ac7b5 MC |
12162 | rcu_assign_pointer(bp->cnic_ops, ops); |
12163 | ||
12164 | return 0; | |
12165 | } | |
12166 | ||
12167 | static int bnx2x_unregister_cnic(struct net_device *dev) | |
12168 | { | |
12169 | struct bnx2x *bp = netdev_priv(dev); | |
12170 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
12171 | ||
12172 | mutex_lock(&bp->cnic_mutex); | |
993ac7b5 | 12173 | cp->drv_state = 0; |
2cfa5a04 | 12174 | RCU_INIT_POINTER(bp->cnic_ops, NULL); |
993ac7b5 MC |
12175 | mutex_unlock(&bp->cnic_mutex); |
12176 | synchronize_rcu(); | |
12177 | kfree(bp->cnic_kwq); | |
12178 | bp->cnic_kwq = NULL; | |
12179 | ||
12180 | return 0; | |
12181 | } | |
12182 | ||
12183 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev) | |
12184 | { | |
12185 | struct bnx2x *bp = netdev_priv(dev); | |
12186 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; | |
12187 | ||
2ba45142 VZ |
12188 | /* If both iSCSI and FCoE are disabled - return NULL in |
12189 | * order to indicate CNIC that it should not try to work | |
12190 | * with this device. | |
12191 | */ | |
12192 | if (NO_ISCSI(bp) && NO_FCOE(bp)) | |
12193 | return NULL; | |
12194 | ||
993ac7b5 MC |
12195 | cp->drv_owner = THIS_MODULE; |
12196 | cp->chip_id = CHIP_ID(bp); | |
12197 | cp->pdev = bp->pdev; | |
12198 | cp->io_base = bp->regview; | |
12199 | cp->io_base2 = bp->doorbells; | |
12200 | cp->max_kwqe_pending = 8; | |
523224a3 | 12201 | cp->ctx_blk_size = CDU_ILT_PAGE_SZ; |
c2bff63f DK |
12202 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
12203 | bnx2x_cid_ilt_lines(bp); | |
993ac7b5 | 12204 | cp->ctx_tbl_len = CNIC_ILT_LINES; |
c2bff63f | 12205 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; |
993ac7b5 MC |
12206 | cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue; |
12207 | cp->drv_ctl = bnx2x_drv_ctl; | |
12208 | cp->drv_register_cnic = bnx2x_register_cnic; | |
12209 | cp->drv_unregister_cnic = bnx2x_unregister_cnic; | |
ec6ba945 | 12210 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID; |
619c5cb6 VZ |
12211 | cp->iscsi_l2_client_id = |
12212 | bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); | |
c2bff63f DK |
12213 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID; |
12214 | ||
2ba45142 VZ |
12215 | if (NO_ISCSI_OOO(bp)) |
12216 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; | |
12217 | ||
12218 | if (NO_ISCSI(bp)) | |
12219 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI; | |
12220 | ||
12221 | if (NO_FCOE(bp)) | |
12222 | cp->drv_state |= CNIC_DRV_STATE_NO_FCOE; | |
12223 | ||
51c1a580 MS |
12224 | BNX2X_DEV_INFO( |
12225 | "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n", | |
c2bff63f DK |
12226 | cp->ctx_blk_size, |
12227 | cp->ctx_tbl_offset, | |
12228 | cp->ctx_tbl_len, | |
12229 | cp->starting_cid); | |
993ac7b5 MC |
12230 | return cp; |
12231 | } | |
12232 | EXPORT_SYMBOL(bnx2x_cnic_probe); | |
12233 | ||
12234 | #endif /* BCM_CNIC */ | |
94a78b79 | 12235 |