blob: 57fac3db9bde19e742dae064b9bf4a8356fd8c2b [file] [log] [blame]
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001/* bnx2x_main.c: Broadcom Everest network driver.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002 *
Dmitry Kravkov5de92402011-05-04 23:51:13 +00003 * Copyright (c) 2007-2011 Broadcom Corporation
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004 *
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 *
Eilon Greenstein24e3fce2008-06-12 14:30:28 -07009 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
Eilon Greensteinca003922009-08-12 22:53:28 -070013 * Slowpath and fastpath rework by Vladislav Zolotarov
Eliezer Tamirc14423f2008-02-28 11:49:42 -080014 * Statistics and Link management by Yitchak Gertner
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020015 *
16 */
17
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020018#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/kernel.h>
21#include <linux/device.h> /* for dev_info() */
22#include <linux/timer.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
25#include <linux/slab.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020026#include <linux/interrupt.h>
27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/dma-mapping.h>
33#include <linux/bitops.h>
34#include <linux/irq.h>
35#include <linux/delay.h>
36#include <asm/byteorder.h>
37#include <linux/time.h>
38#include <linux/ethtool.h>
39#include <linux/mii.h>
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080040#include <linux/if_vlan.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020041#include <net/ip.h>
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030042#include <net/ipv6.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020043#include <net/tcp.h>
44#include <net/checksum.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070045#include <net/ip6_checksum.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020046#include <linux/workqueue.h>
47#include <linux/crc32.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070048#include <linux/crc32c.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020049#include <linux/prefetch.h>
50#include <linux/zlib.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020051#include <linux/io.h>
Ben Hutchings45229b42009-11-07 11:53:39 +000052#include <linux/stringify.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020053
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020054#include "bnx2x.h"
55#include "bnx2x_init.h"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070056#include "bnx2x_init_ops.h"
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000057#include "bnx2x_cmn.h"
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000058#include "bnx2x_dcb.h"
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000059#include "bnx2x_sp.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020060
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070061#include <linux/firmware.h>
62#include "bnx2x_fw_file_hdr.h"
63/* FW files */
Ben Hutchings45229b42009-11-07 11:53:39 +000064#define FW_FILE_VERSION \
65 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
66 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
67 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
68 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
Dmitry Kravkov560131f2010-10-06 03:18:47 +000069#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
70#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000071#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070072
Eilon Greenstein34f80b02008-06-23 20:33:01 -070073/* Time in jiffies before concluding the transmitter is hung */
74#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020075
Andrew Morton53a10562008-02-09 23:16:41 -080076static char version[] __devinitdata =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030077 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020078 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
79
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070080MODULE_AUTHOR("Eliezer Tamir");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000081MODULE_DESCRIPTION("Broadcom NetXtreme II "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030082 "BCM57710/57711/57711E/"
83 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
84 "57840/57840_MF Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020085MODULE_LICENSE("GPL");
86MODULE_VERSION(DRV_MODULE_VERSION);
Ben Hutchings45229b42009-11-07 11:53:39 +000087MODULE_FIRMWARE(FW_FILE_NAME_E1);
88MODULE_FIRMWARE(FW_FILE_NAME_E1H);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000089MODULE_FIRMWARE(FW_FILE_NAME_E2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020090
Eilon Greenstein555f6c72009-02-12 08:36:11 +000091static int multi_mode = 1;
92module_param(multi_mode, int, 0);
Eilon Greensteinca003922009-08-12 22:53:28 -070093MODULE_PARM_DESC(multi_mode, " Multi queue mode "
94 "(0 Disable; 1 Enable (default))");
95
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000096int num_queues;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +000097module_param(num_queues, int, 0);
98MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
99 " (default is as a number of CPUs)");
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000100
Eilon Greenstein19680c42008-08-13 15:47:33 -0700101static int disable_tpa;
Eilon Greenstein19680c42008-08-13 15:47:33 -0700102module_param(disable_tpa, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000103MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000104
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +0000105#define INT_MODE_INTx 1
106#define INT_MODE_MSI 2
Eilon Greenstein8badd272009-02-12 08:36:15 +0000107static int int_mode;
108module_param(int_mode, int, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300109MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000110 "(1 INT#x; 2 MSI)");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000111
Eilon Greensteina18f5122009-08-12 08:23:26 +0000112static int dropless_fc;
113module_param(dropless_fc, int, 0);
114MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
115
Eilon Greenstein9898f862009-02-12 08:38:27 +0000116static int poll;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200117module_param(poll, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000118MODULE_PARM_DESC(poll, " Use polling (for debug)");
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000119
120static int mrrs = -1;
121module_param(mrrs, int, 0);
122MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
123
Eilon Greenstein9898f862009-02-12 08:38:27 +0000124static int debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200125module_param(debug, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000126MODULE_PARM_DESC(debug, " Default debug msglevel");
127
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200128
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300129
130struct workqueue_struct *bnx2x_wq;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000131
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200132enum bnx2x_board_type {
133 BCM57710 = 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300134 BCM57711,
135 BCM57711E,
136 BCM57712,
137 BCM57712_MF,
138 BCM57800,
139 BCM57800_MF,
140 BCM57810,
141 BCM57810_MF,
142 BCM57840,
143 BCM57840_MF
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200144};
145
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700146/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800147static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200148 char *name;
149} board_info[] __devinitdata = {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300150 { "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"}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200162};
163
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300164#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
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000197static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000198 { 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 },
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000201 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300202 { 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 },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200209 { 0 }
210};
211
212MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
213
214/****************************************************************************
215* General service functions
216****************************************************************************/
217
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300218static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
219 u32 addr, dma_addr_t mapping)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000220{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300221 REG_WR(bp, addr, U64_LO(mapping));
222 REG_WR(bp, addr + 4, U64_HI(mapping));
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000223}
224
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300225static inline void storm_memset_spq_addr(struct bnx2x *bp,
226 dma_addr_t mapping, u16 abs_fid)
227{
228 u32 addr = XSEM_REG_FAST_MEMORY +
229 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
230
231 __storm_memset_dma_mapping(bp, addr, mapping);
232}
233
234static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
235 u16 pf_id)
236{
237 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
238 pf_id);
239 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
240 pf_id);
241 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
242 pf_id);
243 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
244 pf_id);
245}
246
247static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
248 u8 enable)
249{
250 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
251 enable);
252 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
253 enable);
254 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
255 enable);
256 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
257 enable);
258}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000259
260static inline void storm_memset_eq_data(struct bnx2x *bp,
261 struct event_ring_data *eq_data,
262 u16 pfid)
263{
264 size_t size = sizeof(struct event_ring_data);
265
266 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
267
268 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
269}
270
271static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
272 u16 pfid)
273{
274 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
275 REG_WR16(bp, addr, eq_prod);
276}
277
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200278/* used only at init
279 * locking is done by mcp
280 */
stephen hemminger8d962862010-10-21 07:50:56 +0000281static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200282{
283 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
284 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
285 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
286 PCICFG_VENDOR_ID_OFFSET);
287}
288
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200289static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
290{
291 u32 val;
292
293 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
294 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
295 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
296 PCICFG_VENDOR_ID_OFFSET);
297
298 return val;
299}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200300
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000301#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
302#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
303#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
304#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
305#define DMAE_DP_DST_NONE "dst_addr [none]"
306
stephen hemminger8d962862010-10-21 07:50:56 +0000307static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
308 int msglvl)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000309{
310 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
311
312 switch (dmae->opcode & DMAE_COMMAND_DST) {
313 case DMAE_CMD_DST_PCI:
314 if (src_type == DMAE_CMD_SRC_PCI)
315 DP(msglvl, "DMAE: opcode 0x%08x\n"
316 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
317 "comp_addr [%x:%08x], comp_val 0x%08x\n",
318 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
319 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
320 dmae->comp_addr_hi, dmae->comp_addr_lo,
321 dmae->comp_val);
322 else
323 DP(msglvl, "DMAE: opcode 0x%08x\n"
324 "src [%08x], len [%d*4], dst [%x:%08x]\n"
325 "comp_addr [%x:%08x], comp_val 0x%08x\n",
326 dmae->opcode, dmae->src_addr_lo >> 2,
327 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
328 dmae->comp_addr_hi, dmae->comp_addr_lo,
329 dmae->comp_val);
330 break;
331 case DMAE_CMD_DST_GRC:
332 if (src_type == DMAE_CMD_SRC_PCI)
333 DP(msglvl, "DMAE: opcode 0x%08x\n"
334 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
335 "comp_addr [%x:%08x], comp_val 0x%08x\n",
336 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
337 dmae->len, dmae->dst_addr_lo >> 2,
338 dmae->comp_addr_hi, dmae->comp_addr_lo,
339 dmae->comp_val);
340 else
341 DP(msglvl, "DMAE: opcode 0x%08x\n"
342 "src [%08x], len [%d*4], dst [%08x]\n"
343 "comp_addr [%x:%08x], comp_val 0x%08x\n",
344 dmae->opcode, dmae->src_addr_lo >> 2,
345 dmae->len, dmae->dst_addr_lo >> 2,
346 dmae->comp_addr_hi, dmae->comp_addr_lo,
347 dmae->comp_val);
348 break;
349 default:
350 if (src_type == DMAE_CMD_SRC_PCI)
351 DP(msglvl, "DMAE: opcode 0x%08x\n"
352 DP_LEVEL "src_addr [%x:%08x] len [%d * 4] "
353 "dst_addr [none]\n"
354 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
355 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
356 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
357 dmae->comp_val);
358 else
359 DP(msglvl, "DMAE: opcode 0x%08x\n"
360 DP_LEVEL "src_addr [%08x] len [%d * 4] "
361 "dst_addr [none]\n"
362 DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
363 dmae->opcode, dmae->src_addr_lo >> 2,
364 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
365 dmae->comp_val);
366 break;
367 }
368
369}
370
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200371/* copy command into DMAE command memory and set DMAE command go */
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000372void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200373{
374 u32 cmd_offset;
375 int i;
376
377 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
378 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
379 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
380
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700381 DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
382 idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200383 }
384 REG_WR(bp, dmae_reg_go_c[idx], 1);
385}
386
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000387u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
388{
389 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
390 DMAE_CMD_C_ENABLE);
391}
392
393u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
394{
395 return opcode & ~DMAE_CMD_SRC_RESET;
396}
397
398u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
399 bool with_comp, u8 comp_type)
400{
401 u32 opcode = 0;
402
403 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
404 (dst_type << DMAE_COMMAND_DST_SHIFT));
405
406 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
407
408 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
409 opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) |
410 (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
411 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
412
413#ifdef __BIG_ENDIAN
414 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
415#else
416 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
417#endif
418 if (with_comp)
419 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
420 return opcode;
421}
422
stephen hemminger8d962862010-10-21 07:50:56 +0000423static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
424 struct dmae_command *dmae,
425 u8 src_type, u8 dst_type)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000426{
427 memset(dmae, 0, sizeof(struct dmae_command));
428
429 /* set the opcode */
430 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
431 true, DMAE_COMP_PCI);
432
433 /* fill in the completion parameters */
434 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
435 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
436 dmae->comp_val = DMAE_COMP_VAL;
437}
438
439/* issue a dmae command over the init-channel and wailt for completion */
stephen hemminger8d962862010-10-21 07:50:56 +0000440static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
441 struct dmae_command *dmae)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000442{
443 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Dmitry Kravkov5e374b52011-05-22 10:09:19 +0000444 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000445 int rc = 0;
446
447 DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
448 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
449 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
450
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300451 /*
452 * Lock the dmae channel. Disable BHs to prevent a dead-lock
453 * as long as this code is called both from syscall context and
454 * from ndo_set_rx_mode() flow that may be called from BH.
455 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800456 spin_lock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000457
458 /* reset completion */
459 *wb_comp = 0;
460
461 /* post the command on the channel used for initializations */
462 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
463
464 /* wait for completion */
465 udelay(5);
466 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
467 DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
468
469 if (!cnt) {
470 BNX2X_ERR("DMAE timeout!\n");
471 rc = DMAE_TIMEOUT;
472 goto unlock;
473 }
474 cnt--;
475 udelay(50);
476 }
477 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
478 BNX2X_ERR("DMAE PCI error!\n");
479 rc = DMAE_PCI_ERROR;
480 }
481
482 DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
483 bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
484 bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
485
486unlock:
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800487 spin_unlock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000488 return rc;
489}
490
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700491void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
492 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200493{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000494 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700495
496 if (!bp->dmae_ready) {
497 u32 *data = bnx2x_sp(bp, wb_data[0]);
498
499 DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
500 " using indirect\n", dst_addr, len32);
501 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
502 return;
503 }
504
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000505 /* set opcode and fixed command fields */
506 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200507
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000508 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000509 dmae.src_addr_lo = U64_LO(dma_addr);
510 dmae.src_addr_hi = U64_HI(dma_addr);
511 dmae.dst_addr_lo = dst_addr >> 2;
512 dmae.dst_addr_hi = 0;
513 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200514
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000515 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200516
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000517 /* issue the command and wait for completion */
518 bnx2x_issue_dmae_with_comp(bp, &dmae);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200519}
520
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700521void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200522{
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000523 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700524
525 if (!bp->dmae_ready) {
526 u32 *data = bnx2x_sp(bp, wb_data[0]);
527 int i;
528
529 DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
530 " using indirect\n", src_addr, len32);
531 for (i = 0; i < len32; i++)
532 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
533 return;
534 }
535
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000536 /* set opcode and fixed command fields */
537 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200538
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000539 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000540 dmae.src_addr_lo = src_addr >> 2;
541 dmae.src_addr_hi = 0;
542 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
543 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
544 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200545
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000546 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200547
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000548 /* issue the command and wait for completion */
549 bnx2x_issue_dmae_with_comp(bp, &dmae);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200550}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200551
stephen hemminger8d962862010-10-21 07:50:56 +0000552static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
553 u32 addr, u32 len)
Eilon Greenstein573f2032009-08-12 08:24:14 +0000554{
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000555 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
Eilon Greenstein573f2032009-08-12 08:24:14 +0000556 int offset = 0;
557
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000558 while (len > dmae_wr_max) {
Eilon Greenstein573f2032009-08-12 08:24:14 +0000559 bnx2x_write_dmae(bp, phys_addr + offset,
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000560 addr + offset, dmae_wr_max);
561 offset += dmae_wr_max * 4;
562 len -= dmae_wr_max;
Eilon Greenstein573f2032009-08-12 08:24:14 +0000563 }
564
565 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
566}
567
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700568/* used only for slowpath so not inlined */
569static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
570{
571 u32 wb_write[2];
572
573 wb_write[0] = val_hi;
574 wb_write[1] = val_lo;
575 REG_WR_DMAE(bp, reg, wb_write, 2);
576}
577
578#ifdef USE_WB_RD
579static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
580{
581 u32 wb_data[2];
582
583 REG_RD_DMAE(bp, reg, wb_data, 2);
584
585 return HILO_U64(wb_data[0], wb_data[1]);
586}
587#endif
588
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200589static int bnx2x_mc_assert(struct bnx2x *bp)
590{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200591 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700592 int i, rc = 0;
593 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200594
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700595 /* XSTORM */
596 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
597 XSTORM_ASSERT_LIST_INDEX_OFFSET);
598 if (last_idx)
599 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200600
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700601 /* print the asserts */
602 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200603
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700604 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
605 XSTORM_ASSERT_LIST_OFFSET(i));
606 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
607 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
608 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
609 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
610 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
611 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200612
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700613 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
614 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
615 " 0x%08x 0x%08x 0x%08x\n",
616 i, row3, row2, row1, row0);
617 rc++;
618 } else {
619 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200620 }
621 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700622
623 /* TSTORM */
624 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
625 TSTORM_ASSERT_LIST_INDEX_OFFSET);
626 if (last_idx)
627 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
628
629 /* print the asserts */
630 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
631
632 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
633 TSTORM_ASSERT_LIST_OFFSET(i));
634 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
635 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
636 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
637 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
638 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
639 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
640
641 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
642 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
643 " 0x%08x 0x%08x 0x%08x\n",
644 i, row3, row2, row1, row0);
645 rc++;
646 } else {
647 break;
648 }
649 }
650
651 /* CSTORM */
652 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
653 CSTORM_ASSERT_LIST_INDEX_OFFSET);
654 if (last_idx)
655 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
656
657 /* print the asserts */
658 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
659
660 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
661 CSTORM_ASSERT_LIST_OFFSET(i));
662 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
663 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
664 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
665 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
666 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
667 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
668
669 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
670 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
671 " 0x%08x 0x%08x 0x%08x\n",
672 i, row3, row2, row1, row0);
673 rc++;
674 } else {
675 break;
676 }
677 }
678
679 /* USTORM */
680 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
681 USTORM_ASSERT_LIST_INDEX_OFFSET);
682 if (last_idx)
683 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
684
685 /* print the asserts */
686 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
687
688 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
689 USTORM_ASSERT_LIST_OFFSET(i));
690 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
691 USTORM_ASSERT_LIST_OFFSET(i) + 4);
692 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
693 USTORM_ASSERT_LIST_OFFSET(i) + 8);
694 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
695 USTORM_ASSERT_LIST_OFFSET(i) + 12);
696
697 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
698 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
699 " 0x%08x 0x%08x 0x%08x\n",
700 i, row3, row2, row1, row0);
701 rc++;
702 } else {
703 break;
704 }
705 }
706
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200707 return rc;
708}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800709
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000710void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200711{
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000712 u32 addr, val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200713 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000714 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200715 int word;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000716 u32 trace_shmem_base;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +0000717 if (BP_NOMCP(bp)) {
718 BNX2X_ERR("NO MCP - can not dump\n");
719 return;
720 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000721 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
722 (bp->common.bc_ver & 0xff0000) >> 16,
723 (bp->common.bc_ver & 0xff00) >> 8,
724 (bp->common.bc_ver & 0xff));
725
726 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
727 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
728 printk("%s" "MCP PC at 0x%x\n", lvl, val);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000729
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000730 if (BP_PATH(bp) == 0)
731 trace_shmem_base = bp->common.shmem_base;
732 else
733 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
734 addr = trace_shmem_base - 0x0800 + 4;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000735 mark = REG_RD(bp, addr);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000736 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
737 + ((mark + 0x3) & ~0x3) - 0x08000000;
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000738 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200739
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000740 printk("%s", lvl);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000741 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200742 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000743 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200744 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000745 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200746 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000747 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200748 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000749 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200750 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000751 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200752 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000753 printk("%s" "end of fw dump\n", lvl);
754}
755
756static inline void bnx2x_fw_dump(struct bnx2x *bp)
757{
758 bnx2x_fw_dump_lvl(bp, KERN_ERR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200759}
760
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000761void bnx2x_panic_dump(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200762{
763 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000764 u16 j;
765 struct hc_sp_status_block_data sp_sb_data;
766 int func = BP_FUNC(bp);
767#ifdef BNX2X_STOP_ON_ERROR
768 u16 start = 0, end = 0;
769#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200770
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700771 bp->stats_state = STATS_STATE_DISABLED;
772 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
773
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200774 BNX2X_ERR("begin crash dump -----------------\n");
775
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000776 /* Indices */
777 /* Common */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000778 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300779 " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
780 bp->def_idx, bp->def_att_idx, bp->attn_state,
781 bp->spq_prod_idx, bp->stats_counter);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000782 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
783 bp->def_status_blk->atten_status_block.attn_bits,
784 bp->def_status_blk->atten_status_block.attn_bits_ack,
785 bp->def_status_blk->atten_status_block.status_block_id,
786 bp->def_status_blk->atten_status_block.attn_bits_index);
787 BNX2X_ERR(" def (");
788 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
789 pr_cont("0x%x%s",
790 bp->def_status_blk->sp_sb.index_values[i],
791 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000792
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000793 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
794 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
795 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
796 i*sizeof(u32));
797
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300798 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) "
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000799 "pf_id(0x%x) vnic_id(0x%x) "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300800 "vf_id(0x%x) vf_valid (0x%x) "
801 "state(0x%x)\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000802 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,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300807 sp_sb_data.p_func.vf_valid,
808 sp_sb_data.state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000809
810
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000811 for_each_eth_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000812 struct bnx2x_fastpath *fp = &bp->fp[i];
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000813 int loop;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000814 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000815 struct hc_status_block_data_e1x sb_data_e1x;
816 struct hc_status_block_sm *hc_sm_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300817 CHIP_IS_E1x(bp) ?
818 sb_data_e1x.common.state_machine :
819 sb_data_e2.common.state_machine;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000820 struct hc_index_data *hc_index_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300821 CHIP_IS_E1x(bp) ?
822 sb_data_e1x.index_data :
823 sb_data_e2.index_data;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000824 int data_size;
825 u32 *sb_data_p;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000826
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000827 /* Rx */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000828 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000829 " rx_comp_prod(0x%x)"
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000830 " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000831 i, fp->rx_bd_prod, fp->rx_bd_cons,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000832 fp->rx_comp_prod,
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000833 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000834 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000835 " fp_hc_idx(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000836 fp->rx_sge_prod, fp->last_max_sge,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000837 le16_to_cpu(fp->fp_hc_idx));
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000838
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000839 /* Tx */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000840 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
841 " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
842 " *tx_cons_sb(0x%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200843 i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700844 fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000845
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300846 loop = CHIP_IS_E1x(bp) ?
847 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000848
849 /* host sb data */
850
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000851#ifdef BCM_CNIC
852 if (IS_FCOE_FP(fp))
853 continue;
854#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000855 BNX2X_ERR(" run indexes (");
856 for (j = 0; j < HC_SB_MAX_SM; j++)
857 pr_cont("0x%x%s",
858 fp->sb_running_index[j],
859 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
860
861 BNX2X_ERR(" indexes (");
862 for (j = 0; j < loop; j++)
863 pr_cont("0x%x%s",
864 fp->sb_index_values[j],
865 (j == loop - 1) ? ")" : " ");
866 /* fw sb data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300867 data_size = CHIP_IS_E1x(bp) ?
868 sizeof(struct hc_status_block_data_e1x) :
869 sizeof(struct hc_status_block_data_e2);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000870 data_size /= sizeof(u32);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300871 sb_data_p = CHIP_IS_E1x(bp) ?
872 (u32 *)&sb_data_e1x :
873 (u32 *)&sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000874 /* copy sb data in here */
875 for (j = 0; j < data_size; j++)
876 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
877 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
878 j * sizeof(u32));
879
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300880 if (!CHIP_IS_E1x(bp)) {
881 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
882 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
883 "state(0x%x)\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000884 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,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300888 sb_data_e2.common.same_igu_sb_1b,
889 sb_data_e2.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000890 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300891 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
892 "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
893 "state(0x%x)\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000894 sb_data_e1x.common.p_func.pf_id,
895 sb_data_e1x.common.p_func.vf_id,
896 sb_data_e1x.common.p_func.vf_valid,
897 sb_data_e1x.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300898 sb_data_e1x.common.same_igu_sb_1b,
899 sb_data_e1x.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000900 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000901
902 /* SB_SMs data */
903 for (j = 0; j < HC_SB_MAX_SM; j++) {
904 pr_cont("SM[%d] __flags (0x%x) "
905 "igu_sb_id (0x%x) igu_seg_id(0x%x) "
906 "time_to_expire (0x%x) "
907 "timer_value(0x%x)\n", j,
908 hc_sm_p[j].__flags,
909 hc_sm_p[j].igu_sb_id,
910 hc_sm_p[j].igu_seg_id,
911 hc_sm_p[j].time_to_expire,
912 hc_sm_p[j].timer_value);
913 }
914
915 /* Indecies data */
916 for (j = 0; j < loop; j++) {
917 pr_cont("INDEX[%d] flags (0x%x) "
918 "timeout (0x%x)\n", j,
919 hc_index_p[j].flags,
920 hc_index_p[j].timeout);
921 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000922 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200923
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000924#ifdef BNX2X_STOP_ON_ERROR
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000925 /* Rings */
926 /* Rx */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000927 for_each_rx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000928 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200929
930 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
931 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000932 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200933 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
934 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
935
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000936 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
937 i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200938 }
939
Eilon Greenstein3196a882008-08-13 15:58:49 -0700940 start = RX_SGE(fp->rx_sge_prod);
941 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000942 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700943 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
944 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
945
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000946 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
947 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700948 }
949
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200950 start = RCQ_BD(fp->rx_comp_cons - 10);
951 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000952 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200953 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
954
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000955 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
956 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200957 }
958 }
959
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000960 /* Tx */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000961 for_each_tx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000962 struct bnx2x_fastpath *fp = &bp->fp[i];
963
964 start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
965 end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
966 for (j = start; j != end; j = TX_BD(j + 1)) {
967 struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
968
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000969 BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
970 i, j, sw_bd->skb, sw_bd->first_bd);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000971 }
972
973 start = TX_BD(fp->tx_bd_cons - 10);
974 end = TX_BD(fp->tx_bd_cons + 254);
975 for (j = start; j != end; j = TX_BD(j + 1)) {
976 u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
977
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +0000978 BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
979 i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000980 }
981 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000982#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700983 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200984 bnx2x_mc_assert(bp);
985 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200986}
987
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300988/*
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 */
995#define FLR_WAIT_INTERAVAL 50 /* usec */
996#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */
997
998struct pbf_pN_buf_regs {
999 int pN;
1000 u32 init_crd;
1001 u32 crd;
1002 u32 crd_freed;
1003};
1004
1005struct pbf_pN_cmd_regs {
1006 int pN;
1007 u32 lines_occup;
1008 u32 lines_freed;
1009};
1010
1011static 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--) {
1029 udelay(FLR_WAIT_INTERAVAL);
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",
1043 poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
1044}
1045
1046static 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--) {
1061 udelay(FLR_WAIT_INTERAVAL);
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",
1075 poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
1076}
1077
1078static 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--)
1085 udelay(FLR_WAIT_INTERAVAL);
1086
1087 return val;
1088}
1089
1090static 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
1101static 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
1113static 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
1188static 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)) {
1198 BNX2X_ERR("Cleanup complete is not 0\n");
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
1207 DP(BNX2X_MSG_SP, "FW Final cleanup\n");
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");
1212 ret = 1;
1213 }
1214 /* Zero completion for nxt FLR */
1215 REG_WR(bp, comp_addr, 0);
1216
1217 return ret;
1218}
1219
1220static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
1221{
1222 int pos;
1223 u16 status;
1224
1225 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1226 if (!pos)
1227 return false;
1228
1229 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
1230 return status & PCI_EXP_DEVSTA_TRPND;
1231}
1232
1233/* PF FLR specific routines
1234*/
1235static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1236{
1237
1238 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1239 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1240 CFC_REG_NUM_LCIDS_INSIDE_PF,
1241 "CFC PF usage counter timed out",
1242 poll_cnt))
1243 return 1;
1244
1245
1246 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1247 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1248 DORQ_REG_PF_USAGE_CNT,
1249 "DQ PF usage counter timed out",
1250 poll_cnt))
1251 return 1;
1252
1253 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1254 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1255 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1256 "QM PF usage counter timed out",
1257 poll_cnt))
1258 return 1;
1259
1260 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1261 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1262 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1263 "Timers VNIC usage counter timed out",
1264 poll_cnt))
1265 return 1;
1266 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1267 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1268 "Timers NUM_SCANS usage counter timed out",
1269 poll_cnt))
1270 return 1;
1271
1272 /* Wait DMAE PF usage counter to zero */
1273 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1274 dmae_reg_go_c[INIT_DMAE_C(bp)],
1275 "DMAE dommand register timed out",
1276 poll_cnt))
1277 return 1;
1278
1279 return 0;
1280}
1281
1282static void bnx2x_hw_enable_status(struct bnx2x *bp)
1283{
1284 u32 val;
1285
1286 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1287 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1288
1289 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1290 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1291
1292 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1293 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1294
1295 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1296 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1297
1298 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1299 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1300
1301 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1302 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1303
1304 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1305 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1306
1307 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1308 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1309 val);
1310}
1311
1312static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1313{
1314 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1315
1316 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1317
1318 /* Re-enable PF target read access */
1319 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1320
1321 /* Poll HW usage counters */
1322 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1323 return -EBUSY;
1324
1325 /* Zero the igu 'trailing edge' and 'leading edge' */
1326
1327 /* Send the FW cleanup command */
1328 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1329 return -EBUSY;
1330
1331 /* ATC cleanup */
1332
1333 /* Verify TX hw is flushed */
1334 bnx2x_tx_hw_flushed(bp, poll_cnt);
1335
1336 /* Wait 100ms (not adjusted according to platform) */
1337 msleep(100);
1338
1339 /* Verify no pending pci transactions */
1340 if (bnx2x_is_pcie_pending(bp->pdev))
1341 BNX2X_ERR("PCIE Transactions still pending\n");
1342
1343 /* Debug */
1344 bnx2x_hw_enable_status(bp);
1345
1346 /*
1347 * Master enable - Due to WB DMAE writes performed before this
1348 * register is re-initialized as part of the regular function init
1349 */
1350 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1351
1352 return 0;
1353}
1354
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001355static void bnx2x_hc_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001356{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001357 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001358 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1359 u32 val = REG_RD(bp, addr);
1360 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001361 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001362
1363 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001364 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1365 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001366 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1367 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eilon Greenstein8badd272009-02-12 08:36:15 +00001368 } else if (msi) {
1369 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1370 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1371 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1372 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001373 } else {
1374 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001375 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001376 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1377 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001378
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001379 if (!CHIP_IS_E1(bp)) {
1380 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1381 val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001382
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001383 REG_WR(bp, addr, val);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001384
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001385 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1386 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001387 }
1388
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001389 if (CHIP_IS_E1(bp))
1390 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1391
Eilon Greenstein8badd272009-02-12 08:36:15 +00001392 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
1393 val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001394
1395 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001396 /*
1397 * Ensure that HC_CONFIG is written before leading/trailing edge config
1398 */
1399 mmiowb();
1400 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001401
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001402 if (!CHIP_IS_E1(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001403 /* init leading/trailing edge */
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00001404 if (IS_MF(bp)) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001405 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001406 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001407 /* enable nig and gpio3 attention */
1408 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001409 } else
1410 val = 0xffff;
1411
1412 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1413 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1414 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001415
1416 /* Make sure that interrupts are indeed enabled from here on */
1417 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001418}
1419
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001420static void bnx2x_igu_int_enable(struct bnx2x *bp)
1421{
1422 u32 val;
1423 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
1424 int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
1425
1426 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1427
1428 if (msix) {
1429 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1430 IGU_PF_CONF_SINGLE_ISR_EN);
1431 val |= (IGU_PF_CONF_FUNC_EN |
1432 IGU_PF_CONF_MSI_MSIX_EN |
1433 IGU_PF_CONF_ATTN_BIT_EN);
1434 } else if (msi) {
1435 val &= ~IGU_PF_CONF_INT_LINE_EN;
1436 val |= (IGU_PF_CONF_FUNC_EN |
1437 IGU_PF_CONF_MSI_MSIX_EN |
1438 IGU_PF_CONF_ATTN_BIT_EN |
1439 IGU_PF_CONF_SINGLE_ISR_EN);
1440 } else {
1441 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
1442 val |= (IGU_PF_CONF_FUNC_EN |
1443 IGU_PF_CONF_INT_LINE_EN |
1444 IGU_PF_CONF_ATTN_BIT_EN |
1445 IGU_PF_CONF_SINGLE_ISR_EN);
1446 }
1447
1448 DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
1449 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1450
1451 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1452
1453 barrier();
1454
1455 /* init leading/trailing edge */
1456 if (IS_MF(bp)) {
1457 val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
1458 if (bp->port.pmf)
1459 /* enable nig and gpio3 attention */
1460 val |= 0x1100;
1461 } else
1462 val = 0xffff;
1463
1464 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1465 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1466
1467 /* Make sure that interrupts are indeed enabled from here on */
1468 mmiowb();
1469}
1470
1471void bnx2x_int_enable(struct bnx2x *bp)
1472{
1473 if (bp->common.int_block == INT_BLOCK_HC)
1474 bnx2x_hc_int_enable(bp);
1475 else
1476 bnx2x_igu_int_enable(bp);
1477}
1478
1479static void bnx2x_hc_int_disable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001480{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001481 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001482 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1483 u32 val = REG_RD(bp, addr);
1484
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001485 /*
1486 * in E1 we must use only PCI configuration space to disable
1487 * MSI/MSIX capablility
1488 * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
1489 */
1490 if (CHIP_IS_E1(bp)) {
1491 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
1492 * Use mask register to prevent from HC sending interrupts
1493 * after we exit the function
1494 */
1495 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
1496
1497 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1498 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1499 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
1500 } else
1501 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1502 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1503 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1504 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001505
1506 DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
1507 val, port, addr);
1508
Eilon Greenstein8badd272009-02-12 08:36:15 +00001509 /* flush all outstanding writes */
1510 mmiowb();
1511
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001512 REG_WR(bp, addr, val);
1513 if (REG_RD(bp, addr) != val)
1514 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1515}
1516
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001517static void bnx2x_igu_int_disable(struct bnx2x *bp)
1518{
1519 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1520
1521 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
1522 IGU_PF_CONF_INT_LINE_EN |
1523 IGU_PF_CONF_ATTN_BIT_EN);
1524
1525 DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
1526
1527 /* flush all outstanding writes */
1528 mmiowb();
1529
1530 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1531 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
1532 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1533}
1534
stephen hemminger8d962862010-10-21 07:50:56 +00001535static void bnx2x_int_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001536{
1537 if (bp->common.int_block == INT_BLOCK_HC)
1538 bnx2x_hc_int_disable(bp);
1539 else
1540 bnx2x_igu_int_disable(bp);
1541}
1542
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001543void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001544{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001545 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001546 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001547
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07001548 if (disable_hw)
1549 /* prevent the HW from sending interrupts */
1550 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001551
1552 /* make sure all ISRs are done */
1553 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001554 synchronize_irq(bp->msix_table[0].vector);
1555 offset = 1;
Michael Chan37b091b2009-10-10 13:46:55 +00001556#ifdef BCM_CNIC
1557 offset++;
1558#endif
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001559 for_each_eth_queue(bp, i)
Eilon Greenstein8badd272009-02-12 08:36:15 +00001560 synchronize_irq(bp->msix_table[i + offset].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001561 } else
1562 synchronize_irq(bp->pdev->irq);
1563
1564 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001565 cancel_delayed_work(&bp->sp_task);
1566 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001567}
1568
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001569/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001570
1571/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001572 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001573 */
1574
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001575/* Return true if succeeded to acquire the lock */
1576static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1577{
1578 u32 lock_status;
1579 u32 resource_bit = (1 << resource);
1580 int func = BP_FUNC(bp);
1581 u32 hw_lock_control_reg;
1582
1583 DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
1584
1585 /* Validating that the resource is within range */
1586 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1587 DP(NETIF_MSG_HW,
1588 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1589 resource, HW_LOCK_MAX_RESOURCE_VALUE);
Eric Dumazet0fdf4d02010-08-26 22:03:53 -07001590 return false;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001591 }
1592
1593 if (func <= 5)
1594 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1595 else
1596 hw_lock_control_reg =
1597 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1598
1599 /* Try to acquire the lock */
1600 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1601 lock_status = REG_RD(bp, hw_lock_control_reg);
1602 if (lock_status & resource_bit)
1603 return true;
1604
1605 DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
1606 return false;
1607}
1608
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001609/**
1610 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1611 *
1612 * @bp: driver handle
1613 *
1614 * Returns the recovery leader resource id according to the engine this function
1615 * belongs to. Currently only only 2 engines is supported.
1616 */
1617static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
1618{
1619 if (BP_PATH(bp))
1620 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1621 else
1622 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1623}
1624
1625/**
1626 * bnx2x_trylock_leader_lock- try to aquire a leader lock.
1627 *
1628 * @bp: driver handle
1629 *
1630 * Tries to aquire a leader lock for cuurent engine.
1631 */
1632static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
1633{
1634 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1635}
1636
Michael Chan993ac7b2009-10-10 13:46:56 +00001637#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001638static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
Michael Chan993ac7b2009-10-10 13:46:56 +00001639#endif
Eilon Greenstein3196a882008-08-13 15:58:49 -07001640
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001641void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001642{
1643 struct bnx2x *bp = fp->bp;
1644 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1645 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001646 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
1647 struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001648
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001649 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001650 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001651 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001652 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001653
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001654 switch (command) {
1655 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
1656 DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid);
1657 drv_cmd = BNX2X_Q_CMD_UPDATE;
1658 break;
1659 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001660 DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001661 drv_cmd = BNX2X_Q_CMD_SETUP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001662 break;
1663
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001664 case (RAMROD_CMD_ID_ETH_HALT):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001665 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001666 drv_cmd = BNX2X_Q_CMD_HALT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001667 break;
1668
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001669 case (RAMROD_CMD_ID_ETH_TERMINATE):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001670 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001671 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1672 break;
1673
1674 case (RAMROD_CMD_ID_ETH_EMPTY):
1675 DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid);
1676 drv_cmd = BNX2X_Q_CMD_EMPTY;
Eliezer Tamir49d66772008-02-28 11:53:13 -08001677 break;
1678
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001679 default:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001680 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1681 command, fp->index);
1682 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001683 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001684
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001685 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1686 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1687 /* q_obj->complete_cmd() failure means that this was
1688 * an unexpected completion.
1689 *
1690 * In this case we don't want to increase the bp->spq_left
1691 * because apparently we haven't sent this command the first
1692 * place.
1693 */
1694#ifdef BNX2X_STOP_ON_ERROR
1695 bnx2x_panic();
1696#else
1697 return;
1698#endif
1699
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00001700 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08001701 atomic_inc(&bp->cq_spq_left);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001702 /* push the change in bp->spq_left and towards the memory */
1703 smp_mb__after_atomic_inc();
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001704
1705 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001706}
1707
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001708void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
1709 u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
1710{
1711 u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
1712
1713 bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
1714 start);
1715}
1716
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001717irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001718{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001719 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001720 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001721 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -07001722 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001723
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001724 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001725 if (unlikely(status == 0)) {
1726 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1727 return IRQ_NONE;
1728 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001729 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001730
Eilon Greenstein3196a882008-08-13 15:58:49 -07001731#ifdef BNX2X_STOP_ON_ERROR
1732 if (unlikely(bp->panic))
1733 return IRQ_HANDLED;
1734#endif
1735
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001736 for_each_eth_queue(bp, i) {
Eilon Greensteinca003922009-08-12 22:53:28 -07001737 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001738
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001739 mask = 0x2 << (fp->index + CNIC_CONTEXT_USE);
Eilon Greensteinca003922009-08-12 22:53:28 -07001740 if (status & mask) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001741 /* Handle Rx or Tx according to SB id */
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001742 prefetch(fp->rx_cons_sb);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001743 prefetch(fp->tx_cons_sb);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001744 prefetch(&fp->sb_running_index[SM_RX_ID]);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001745 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eilon Greensteinca003922009-08-12 22:53:28 -07001746 status &= ~mask;
1747 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001748 }
1749
Michael Chan993ac7b2009-10-10 13:46:56 +00001750#ifdef BCM_CNIC
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001751 mask = 0x2;
Michael Chan993ac7b2009-10-10 13:46:56 +00001752 if (status & (mask | 0x1)) {
1753 struct cnic_ops *c_ops = NULL;
1754
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001755 if (likely(bp->state == BNX2X_STATE_OPEN)) {
1756 rcu_read_lock();
1757 c_ops = rcu_dereference(bp->cnic_ops);
1758 if (c_ops)
1759 c_ops->cnic_handler(bp->cnic_data, NULL);
1760 rcu_read_unlock();
1761 }
Michael Chan993ac7b2009-10-10 13:46:56 +00001762
1763 status &= ~mask;
1764 }
1765#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001766
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001767 if (unlikely(status & 0x1)) {
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001768 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001769
1770 status &= ~0x1;
1771 if (!status)
1772 return IRQ_HANDLED;
1773 }
1774
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001775 if (unlikely(status))
1776 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001777 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001778
1779 return IRQ_HANDLED;
1780}
1781
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001782/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001783
1784/*
1785 * General service functions
1786 */
1787
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001788int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001789{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001790 u32 lock_status;
1791 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001792 int func = BP_FUNC(bp);
1793 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001794 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001795
1796 /* Validating that the resource is within range */
1797 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1798 DP(NETIF_MSG_HW,
1799 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1800 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1801 return -EINVAL;
1802 }
1803
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001804 if (func <= 5) {
1805 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1806 } else {
1807 hw_lock_control_reg =
1808 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1809 }
1810
Eliezer Tamirf1410642008-02-28 11:51:50 -08001811 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001812 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001813 if (lock_status & resource_bit) {
1814 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1815 lock_status, resource_bit);
1816 return -EEXIST;
1817 }
1818
Eilon Greenstein46230472008-08-25 15:23:30 -07001819 /* Try for 5 second every 5ms */
1820 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001821 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001822 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1823 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001824 if (lock_status & resource_bit)
1825 return 0;
1826
1827 msleep(5);
1828 }
1829 DP(NETIF_MSG_HW, "Timeout\n");
1830 return -EAGAIN;
1831}
1832
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001833int bnx2x_release_leader_lock(struct bnx2x *bp)
1834{
1835 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1836}
1837
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001838int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001839{
1840 u32 lock_status;
1841 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001842 int func = BP_FUNC(bp);
1843 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001844
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001845 DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
1846
Eliezer Tamirf1410642008-02-28 11:51:50 -08001847 /* Validating that the resource is within range */
1848 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
1849 DP(NETIF_MSG_HW,
1850 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1851 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1852 return -EINVAL;
1853 }
1854
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001855 if (func <= 5) {
1856 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1857 } else {
1858 hw_lock_control_reg =
1859 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1860 }
1861
Eliezer Tamirf1410642008-02-28 11:51:50 -08001862 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001863 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001864 if (!(lock_status & resource_bit)) {
1865 DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
1866 lock_status, resource_bit);
1867 return -EFAULT;
1868 }
1869
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001870 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001871 return 0;
1872}
1873
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001874
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001875int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
1876{
1877 /* The GPIO should be swapped if swap register is set and active */
1878 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1879 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1880 int gpio_shift = gpio_num +
1881 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1882 u32 gpio_mask = (1 << gpio_shift);
1883 u32 gpio_reg;
1884 int value;
1885
1886 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1887 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1888 return -EINVAL;
1889 }
1890
1891 /* read GPIO value */
1892 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
1893
1894 /* get the requested pin value */
1895 if ((gpio_reg & gpio_mask) == gpio_mask)
1896 value = 1;
1897 else
1898 value = 0;
1899
1900 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
1901
1902 return value;
1903}
1904
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001905int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001906{
1907 /* The GPIO should be swapped if swap register is set and active */
1908 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001909 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001910 int gpio_shift = gpio_num +
1911 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1912 u32 gpio_mask = (1 << gpio_shift);
1913 u32 gpio_reg;
1914
1915 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1916 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1917 return -EINVAL;
1918 }
1919
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001920 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001921 /* read GPIO and mask except the float bits */
1922 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
1923
1924 switch (mode) {
1925 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
1926 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
1927 gpio_num, gpio_shift);
1928 /* clear FLOAT and set CLR */
1929 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1930 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
1931 break;
1932
1933 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
1934 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
1935 gpio_num, gpio_shift);
1936 /* clear FLOAT and set SET */
1937 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1938 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
1939 break;
1940
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001941 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Eliezer Tamirf1410642008-02-28 11:51:50 -08001942 DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
1943 gpio_num, gpio_shift);
1944 /* set FLOAT */
1945 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
1946 break;
1947
1948 default:
1949 break;
1950 }
1951
1952 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001953 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001954
1955 return 0;
1956}
1957
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001958int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
1959{
1960 /* The GPIO should be swapped if swap register is set and active */
1961 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
1962 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
1963 int gpio_shift = gpio_num +
1964 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
1965 u32 gpio_mask = (1 << gpio_shift);
1966 u32 gpio_reg;
1967
1968 if (gpio_num > MISC_REGISTERS_GPIO_3) {
1969 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
1970 return -EINVAL;
1971 }
1972
1973 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
1974 /* read GPIO int */
1975 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
1976
1977 switch (mode) {
1978 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
1979 DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
1980 "output low\n", gpio_num, gpio_shift);
1981 /* clear SET and set CLR */
1982 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1983 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1984 break;
1985
1986 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
1987 DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
1988 "output high\n", gpio_num, gpio_shift);
1989 /* clear CLR and set SET */
1990 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
1991 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
1992 break;
1993
1994 default:
1995 break;
1996 }
1997
1998 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
1999 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2000
2001 return 0;
2002}
2003
Eliezer Tamirf1410642008-02-28 11:51:50 -08002004static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
2005{
2006 u32 spio_mask = (1 << spio_num);
2007 u32 spio_reg;
2008
2009 if ((spio_num < MISC_REGISTERS_SPIO_4) ||
2010 (spio_num > MISC_REGISTERS_SPIO_7)) {
2011 BNX2X_ERR("Invalid SPIO %d\n", spio_num);
2012 return -EINVAL;
2013 }
2014
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002015 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002016 /* read SPIO and mask except the float bits */
2017 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
2018
2019 switch (mode) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07002020 case MISC_REGISTERS_SPIO_OUTPUT_LOW:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002021 DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
2022 /* clear FLOAT and set CLR */
2023 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2024 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
2025 break;
2026
Eilon Greenstein6378c022008-08-13 15:59:25 -07002027 case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
Eliezer Tamirf1410642008-02-28 11:51:50 -08002028 DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
2029 /* clear FLOAT and set SET */
2030 spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2031 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
2032 break;
2033
2034 case MISC_REGISTERS_SPIO_INPUT_HI_Z:
2035 DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
2036 /* set FLOAT */
2037 spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
2038 break;
2039
2040 default:
2041 break;
2042 }
2043
2044 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002045 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002046
2047 return 0;
2048}
2049
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002050void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002051{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002052 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002053 switch (bp->link_vars.ieee_fc &
2054 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002055 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002056 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002057 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002058 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002059
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002060 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002061 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002062 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002063 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002064
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002065 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002066 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002067 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002068
Eliezer Tamirf1410642008-02-28 11:51:50 -08002069 default:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002070 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002071 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002072 break;
2073 }
2074}
2075
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002076u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002077{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002078 if (!BP_NOMCP(bp)) {
2079 u8 rc;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002080 int cfx_idx = bnx2x_get_link_cfg_idx(bp);
2081 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
Eilon Greenstein19680c42008-08-13 15:47:33 -07002082 /* Initialize link parameters structure variables */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002083 /* It is recommended to turn off RX FC for jumbo frames
2084 for better performance */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002085 if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000))
David S. Millerc0700f92008-12-16 23:53:20 -08002086 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002087 else
David S. Millerc0700f92008-12-16 23:53:20 -08002088 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002089
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002090 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002091
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002092 if (load_mode == LOAD_DIAG) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002093 bp->link_params.loopback_mode = LOOPBACK_XGXS;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002094 bp->link_params.req_line_speed[cfx_idx] = SPEED_10000;
2095 }
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002096
Eilon Greenstein19680c42008-08-13 15:47:33 -07002097 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002098
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002099 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002100
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002101 bnx2x_calc_fc_adv(bp);
2102
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002103 if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
2104 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002105 bnx2x_link_report(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002106 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002107 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
Eilon Greenstein19680c42008-08-13 15:47:33 -07002108 return rc;
2109 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002110 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002111 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002112}
2113
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002114void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002115{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002116 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002117 bnx2x_acquire_phy_lock(bp);
Yaniv Rosner54c2fb72010-09-01 09:51:23 +00002118 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002119 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002120 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002121
Eilon Greenstein19680c42008-08-13 15:47:33 -07002122 bnx2x_calc_fc_adv(bp);
2123 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002124 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002125}
2126
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002127static void bnx2x__link_reset(struct bnx2x *bp)
2128{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002129 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002130 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002131 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002132 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002133 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002134 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002135}
2136
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002137u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002138{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002139 u8 rc = 0;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002140
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002141 if (!BP_NOMCP(bp)) {
2142 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002143 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2144 is_serdes);
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002145 bnx2x_release_phy_lock(bp);
2146 } else
2147 BNX2X_ERR("Bootcode is missing - can not test link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002148
2149 return rc;
2150}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002151
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002152static void bnx2x_init_port_minmax(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002153{
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002154 u32 r_param = bp->link_vars.line_speed / 8;
2155 u32 fair_periodic_timeout_usec;
2156 u32 t_fair;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002157
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002158 memset(&(bp->cmng.rs_vars), 0,
2159 sizeof(struct rate_shaping_vars_per_port));
2160 memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002161
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002162 /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
2163 bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002164
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002165 /* this is the threshold below which no timer arming will occur
2166 1.25 coefficient is for the threshold to be a little bigger
2167 than the real time, to compensate for timer in-accuracy */
2168 bp->cmng.rs_vars.rs_threshold =
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002169 (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
2170
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002171 /* resolution of fairness timer */
2172 fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
2173 /* for 10G it is 1000usec. for 1G it is 10000usec. */
2174 t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002175
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002176 /* this is the threshold below which we won't arm the timer anymore */
2177 bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002178
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002179 /* we multiply by 1e3/8 to get bytes/msec.
2180 We don't want the credits to pass a credit
2181 of the t_fair*FAIR_MEM (algorithm resolution) */
2182 bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
2183 /* since each tick is 4 usec */
2184 bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002185}
2186
Eilon Greenstein2691d512009-08-12 08:22:08 +00002187/* Calculates the sum of vn_min_rates.
2188 It's needed for further normalizing of the min_rates.
2189 Returns:
2190 sum of vn_min_rates.
2191 or
2192 0 - if all the min_rates are 0.
2193 In the later case fainess algorithm should be deactivated.
2194 If not all min_rates are zero then those that are zeroes will be set to 1.
2195 */
2196static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
2197{
2198 int all_zero = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002199 int vn;
2200
2201 bp->vn_weight_sum = 0;
2202 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002203 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein2691d512009-08-12 08:22:08 +00002204 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2205 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2206
2207 /* Skip hidden vns */
2208 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
2209 continue;
2210
2211 /* If min rate is zero - set it to 1 */
2212 if (!vn_min_rate)
2213 vn_min_rate = DEF_MIN_RATE;
2214 else
2215 all_zero = 0;
2216
2217 bp->vn_weight_sum += vn_min_rate;
2218 }
2219
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002220 /* if ETS or all min rates are zeros - disable fairness */
2221 if (BNX2X_IS_ETS_ENABLED(bp)) {
2222 bp->cmng.flags.cmng_enables &=
2223 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2224 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2225 } else if (all_zero) {
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002226 bp->cmng.flags.cmng_enables &=
2227 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2228 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2229 " fairness will be disabled\n");
2230 } else
2231 bp->cmng.flags.cmng_enables |=
2232 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002233}
2234
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002235static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002236{
2237 struct rate_shaping_vars_per_vn m_rs_vn;
2238 struct fairness_vars_per_vn m_fair_vn;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002239 u32 vn_cfg = bp->mf_config[vn];
2240 int func = 2*vn + BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002241 u16 vn_min_rate, vn_max_rate;
2242 int i;
2243
2244 /* If function is hidden - set min and max to zeroes */
2245 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
2246 vn_min_rate = 0;
2247 vn_max_rate = 0;
2248
2249 } else {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002250 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2251
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002252 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2253 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002254 /* If fairness is enabled (not all min rates are zeroes) and
2255 if current min rate is zero - set it to 1.
2256 This is a requirement of the algorithm. */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002257 if (bp->vn_weight_sum && (vn_min_rate == 0))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002258 vn_min_rate = DEF_MIN_RATE;
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002259
2260 if (IS_MF_SI(bp))
2261 /* maxCfg in percents of linkspeed */
2262 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
2263 else
2264 /* maxCfg is absolute in 100Mb units */
2265 vn_max_rate = maxCfg * 100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002266 }
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002267
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002268 DP(NETIF_MSG_IFUP,
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002269 "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002270 func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002271
2272 memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
2273 memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
2274
2275 /* global vn counter - maximal Mbps for this vn */
2276 m_rs_vn.vn_counter.rate = vn_max_rate;
2277
2278 /* quota - number of bytes transmitted in this period */
2279 m_rs_vn.vn_counter.quota =
2280 (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
2281
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002282 if (bp->vn_weight_sum) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002283 /* credit for each period of the fairness algorithm:
2284 number of bytes in T_FAIR (the vn share the port rate).
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002285 vn_weight_sum should not be larger than 10000, thus
2286 T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
2287 than zero */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002288 m_fair_vn.vn_credit_delta =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002289 max_t(u32, (vn_min_rate * (T_FAIR_COEF /
2290 (8 * bp->vn_weight_sum))),
Dmitry Kravkovff80ee02011-02-28 03:37:11 +00002291 (bp->cmng.fair_vars.fair_threshold +
2292 MIN_ABOVE_THRESH));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002293 DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002294 m_fair_vn.vn_credit_delta);
2295 }
2296
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002297 /* Store it to internal memory */
2298 for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
2299 REG_WR(bp, BAR_XSTRORM_INTMEM +
2300 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
2301 ((u32 *)(&m_rs_vn))[i]);
2302
2303 for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
2304 REG_WR(bp, BAR_XSTRORM_INTMEM +
2305 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
2306 ((u32 *)(&m_fair_vn))[i]);
2307}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002308
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002309static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2310{
2311 if (CHIP_REV_IS_SLOW(bp))
2312 return CMNG_FNS_NONE;
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00002313 if (IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002314 return CMNG_FNS_MINMAX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002315
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002316 return CMNG_FNS_NONE;
2317}
2318
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002319void bnx2x_read_mf_cfg(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002320{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002321 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002322
2323 if (BP_NOMCP(bp))
2324 return; /* what should be the default bvalue in this case */
2325
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002326 /* For 2 port configuration the absolute function number formula
2327 * is:
2328 * abs_func = 2 * vn + BP_PORT + BP_PATH
2329 *
2330 * and there are 4 functions per port
2331 *
2332 * For 4 port configuration it is
2333 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2334 *
2335 * and there are 2 functions per port
2336 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002337 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002338 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2339
2340 if (func >= E1H_FUNC_MAX)
2341 break;
2342
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002343 bp->mf_config[vn] =
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002344 MF_CFG_RD(bp, func_mf_config[func].config);
2345 }
2346}
2347
2348static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2349{
2350
2351 if (cmng_type == CMNG_FNS_MINMAX) {
2352 int vn;
2353
2354 /* clear cmng_enables */
2355 bp->cmng.flags.cmng_enables = 0;
2356
2357 /* read mf conf from shmem */
2358 if (read_cfg)
2359 bnx2x_read_mf_cfg(bp);
2360
2361 /* Init rate shaping and fairness contexts */
2362 bnx2x_init_port_minmax(bp);
2363
2364 /* vn_weight_sum and enable fairness if not 0 */
2365 bnx2x_calc_vn_weight_sum(bp);
2366
2367 /* calculate and set min-max rate for each vn */
Dmitry Kravkovc4154f22011-03-06 10:49:25 +00002368 if (bp->port.pmf)
2369 for (vn = VN_0; vn < E1HVN_MAX; vn++)
2370 bnx2x_init_vn_minmax(bp, vn);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002371
2372 /* always enable rate shaping and fairness */
2373 bp->cmng.flags.cmng_enables |=
2374 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
2375 if (!bp->vn_weight_sum)
2376 DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
2377 " fairness will be disabled\n");
2378 return;
2379 }
2380
2381 /* rate shaping and fairness are disabled */
2382 DP(NETIF_MSG_IFUP,
2383 "rate shaping and fairness are disabled\n");
2384}
2385
2386static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
2387{
2388 int port = BP_PORT(bp);
2389 int func;
2390 int vn;
2391
2392 /* Set the attention towards other drivers on the same port */
2393 for (vn = VN_0; vn < E1HVN_MAX; vn++) {
2394 if (vn == BP_E1HVN(bp))
2395 continue;
2396
2397 func = ((vn << 1) | port);
2398 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
2399 (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
2400 }
2401}
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +00002402
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002403/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002404static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002405{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002406 /* Make sure that we are synced with the current statistics */
2407 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2408
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002409 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002410
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002411 if (bp->link_vars.link_up) {
2412
Eilon Greenstein1c063282009-02-12 08:36:43 +00002413 /* dropless flow control */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002414 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
Eilon Greenstein1c063282009-02-12 08:36:43 +00002415 int port = BP_PORT(bp);
2416 u32 pause_enabled = 0;
2417
2418 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2419 pause_enabled = 1;
2420
2421 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07002422 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
Eilon Greenstein1c063282009-02-12 08:36:43 +00002423 pause_enabled);
2424 }
2425
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002426 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002427 struct host_port_stats *pstats;
2428
2429 pstats = bnx2x_sp(bp, port_stats);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002430 /* reset old mac stats */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002431 memset(&(pstats->mac_stx[0]), 0,
2432 sizeof(struct mac_stx));
2433 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002434 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002435 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2436 }
2437
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002438 if (bp->link_vars.link_up && bp->link_vars.line_speed) {
2439 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002440
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002441 if (cmng_fns != CMNG_FNS_NONE) {
2442 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2443 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2444 } else
2445 /* rate shaping and fairness are disabled */
2446 DP(NETIF_MSG_IFUP,
2447 "single function mode without fairness\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002448 }
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002449
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002450 __bnx2x_link_report(bp);
2451
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002452 if (IS_MF(bp))
2453 bnx2x_link_sync_notify(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002454}
2455
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002456void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002457{
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002458 if (bp->state != BNX2X_STATE_OPEN)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002459 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002460
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002461 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2462
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002463 if (bp->link_vars.link_up)
2464 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2465 else
2466 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2467
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002468 /* indicate link status */
2469 bnx2x_link_report(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002470}
2471
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002472static void bnx2x_pmf_update(struct bnx2x *bp)
2473{
2474 int port = BP_PORT(bp);
2475 u32 val;
2476
2477 bp->port.pmf = 1;
2478 DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
2479
Dmitry Kravkovef018542011-06-14 01:33:57 +00002480 bnx2x_dcbx_pmf_update(bp);
2481
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002482 /* enable nig attention */
2483 val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002484 if (bp->common.int_block == INT_BLOCK_HC) {
2485 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2486 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002487 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002488 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2489 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2490 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002491
2492 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002493}
2494
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002495/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002496
2497/* slow path */
2498
2499/*
2500 * General service functions
2501 */
2502
Eilon Greenstein2691d512009-08-12 08:22:08 +00002503/* send the MCP a request, block until there is a reply */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002504u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002505{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002506 int mb_idx = BP_FW_MB_IDX(bp);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002507 u32 seq;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002508 u32 rc = 0;
2509 u32 cnt = 1;
2510 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2511
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002512 mutex_lock(&bp->fw_mb_mutex);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002513 seq = ++bp->fw_seq;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002514 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2515 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2516
Eilon Greenstein2691d512009-08-12 08:22:08 +00002517 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
2518
2519 do {
2520 /* let the FW do it's magic ... */
2521 msleep(delay);
2522
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002523 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002524
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002525 /* Give the FW up to 5 second (500*10ms) */
2526 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002527
2528 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2529 cnt*delay, rc, seq);
2530
2531 /* is this a reply to our command? */
2532 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2533 rc &= FW_MSG_CODE_MASK;
2534 else {
2535 /* FW BUG! */
2536 BNX2X_ERR("FW failed to respond!\n");
2537 bnx2x_fw_dump(bp);
2538 rc = 0;
2539 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002540 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002541
2542 return rc;
2543}
2544
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002545static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
2546{
2547#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002548 /* Statistics are not supported for CNIC Clients at the moment */
2549 if (IS_FCOE_FP(fp))
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002550 return false;
2551#endif
2552 return true;
2553}
2554
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002555void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002556{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002557 if (CHIP_IS_E1x(bp)) {
2558 struct tstorm_eth_function_common_config tcfg = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002559
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002560 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2561 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002562
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002563 /* Enable the function in the FW */
2564 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2565 storm_memset_func_en(bp, p->func_id, 1);
2566
2567 /* spq */
2568 if (p->func_flgs & FUNC_FLG_SPQ) {
2569 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2570 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2571 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2572 }
2573}
2574
2575static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2576 struct bnx2x_fastpath *fp,
2577 bool leading)
2578{
2579 unsigned long flags = 0;
2580
2581 /* PF driver will always initialize the Queue to an ACTIVE state */
2582 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2583
2584 /* calculate other queue flags */
2585 if (IS_MF_SD(bp))
2586 __set_bit(BNX2X_Q_FLG_OV, &flags);
2587
2588 if (IS_FCOE_FP(fp))
2589 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002590
2591 if (!fp->disable_tpa)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002592 __set_bit(BNX2X_Q_FLG_TPA, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002593
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002594 if (stat_counter_valid(bp, fp)) {
2595 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2596 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2597 }
2598
2599 if (leading) {
2600 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2601 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2602 }
2603
2604 /* Always set HW VLAN stripping */
2605 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002606
2607 return flags;
2608}
2609
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002610static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2611 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002612{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002613 gen_init->stat_id = bnx2x_stats_id(fp);
2614 gen_init->spcl_id = fp->cl_id;
2615
2616 /* Always use mini-jumbo MTU for FCoE L2 ring */
2617 if (IS_FCOE_FP(fp))
2618 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2619 else
2620 gen_init->mtu = bp->dev->mtu;
2621}
2622
2623static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2624 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2625 struct bnx2x_rxq_setup_params *rxq_init)
2626{
2627 u8 max_sge = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002628 u16 sge_sz = 0;
2629 u16 tpa_agg_size = 0;
2630
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002631 if (!fp->disable_tpa) {
2632 pause->sge_th_hi = 250;
2633 pause->sge_th_lo = 150;
2634 tpa_agg_size = min_t(u32,
2635 (min_t(u32, 8, MAX_SKB_FRAGS) *
2636 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2637 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2638 SGE_PAGE_SHIFT;
2639 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2640 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2641 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2642 0xffff);
2643 }
2644
2645 /* pause - not for e1 */
2646 if (!CHIP_IS_E1(bp)) {
2647 pause->bd_th_hi = 350;
2648 pause->bd_th_lo = 250;
2649 pause->rcq_th_hi = 350;
2650 pause->rcq_th_lo = 250;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002651
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002652 pause->pri_map = 1;
2653 }
2654
2655 /* rxq setup */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002656 rxq_init->dscr_map = fp->rx_desc_mapping;
2657 rxq_init->sge_map = fp->rx_sge_mapping;
2658 rxq_init->rcq_map = fp->rx_comp_mapping;
2659 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08002660
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002661 /* This should be a maximum number of data bytes that may be
2662 * placed on the BD (not including paddings).
2663 */
2664 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
2665 IP_HEADER_ALIGNMENT_PADDING;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08002666
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002667 rxq_init->cl_qzone_id = fp->cl_qzone_id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002668 rxq_init->tpa_agg_sz = tpa_agg_size;
2669 rxq_init->sge_buf_sz = sge_sz;
2670 rxq_init->max_sges_pkt = max_sge;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002671 rxq_init->rss_engine_id = BP_FUNC(bp);
2672
2673 /* Maximum number or simultaneous TPA aggregation for this Queue.
2674 *
2675 * For PF Clients it should be the maximum avaliable number.
2676 * VF driver(s) may want to define it to a smaller value.
2677 */
2678 rxq_init->max_tpa_queues =
2679 (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
2680 ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
2681
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002682 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2683 rxq_init->fw_sb_id = fp->fw_sb_id;
2684
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002685 if (IS_FCOE_FP(fp))
2686 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2687 else
2688 rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002689}
2690
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002691static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2692 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002693{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002694 txq_init->dscr_map = fp->tx_desc_mapping;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002695 txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
2696 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2697 txq_init->fw_sb_id = fp->fw_sb_id;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002698
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002699 /*
2700 * set the tss leading client id for TX classfication ==
2701 * leading RSS client id
2702 */
2703 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2704
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002705 if (IS_FCOE_FP(fp)) {
2706 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2707 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2708 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002709}
2710
stephen hemminger8d962862010-10-21 07:50:56 +00002711static void bnx2x_pf_init(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002712{
2713 struct bnx2x_func_init_params func_init = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002714 struct event_ring_data eq_data = { {0} };
2715 u16 flags;
2716
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002717 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002718 /* reset IGU PF statistics: MSIX + ATTN */
2719 /* PF */
2720 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2721 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2722 (CHIP_MODE_IS_4_PORT(bp) ?
2723 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2724 /* ATTN */
2725 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2726 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2727 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2728 (CHIP_MODE_IS_4_PORT(bp) ?
2729 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2730 }
2731
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002732 /* function setup flags */
2733 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2734
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002735 /* This flag is relevant for E1x only.
2736 * E2 doesn't have a TPA configuration in a function level.
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002737 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002738 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002739
2740 func_init.func_flgs = flags;
2741 func_init.pf_id = BP_FUNC(bp);
2742 func_init.func_id = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002743 func_init.spq_map = bp->spq_mapping;
2744 func_init.spq_prod = bp->spq_prod_idx;
2745
2746 bnx2x_func_init(bp, &func_init);
2747
2748 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2749
2750 /*
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002751 * Congestion management values depend on the link rate
2752 * There is no active link so initial link rate is set to 10 Gbps.
2753 * When the link comes up The congestion management values are
2754 * re-calculated according to the actual link rate.
2755 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002756 bp->link_vars.line_speed = SPEED_10000;
2757 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2758
2759 /* Only the PMF sets the HW */
2760 if (bp->port.pmf)
2761 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2762
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002763 /* init Event Queue */
2764 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2765 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2766 eq_data.producer = bp->eq_prod;
2767 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2768 eq_data.sb_id = DEF_SB_ID;
2769 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2770}
2771
2772
Eilon Greenstein2691d512009-08-12 08:22:08 +00002773static void bnx2x_e1h_disable(struct bnx2x *bp)
2774{
2775 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002776
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002777 bnx2x_tx_disable(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002778
2779 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002780}
2781
2782static void bnx2x_e1h_enable(struct bnx2x *bp)
2783{
2784 int port = BP_PORT(bp);
2785
2786 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2787
Eilon Greenstein2691d512009-08-12 08:22:08 +00002788 /* Tx queue should be only reenabled */
2789 netif_tx_wake_all_queues(bp->dev);
2790
Eilon Greenstein061bc702009-10-15 00:18:47 -07002791 /*
2792 * Should not call netif_carrier_on since it will be called if the link
2793 * is up when checking for link state
2794 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00002795}
2796
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002797/* called due to MCP event (on pmf):
2798 * reread new bandwidth configuration
2799 * configure FW
2800 * notify others function about the change
2801 */
2802static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2803{
2804 if (bp->link_vars.link_up) {
2805 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2806 bnx2x_link_sync_notify(bp);
2807 }
2808 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2809}
2810
2811static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2812{
2813 bnx2x_config_mf_bw(bp);
2814 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2815}
2816
Eilon Greenstein2691d512009-08-12 08:22:08 +00002817static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2818{
Eilon Greenstein2691d512009-08-12 08:22:08 +00002819 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002820
2821 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2822
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002823 /*
2824 * This is the only place besides the function initialization
2825 * where the bp->flags can change so it is done without any
2826 * locks
2827 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002828 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
Eilon Greenstein2691d512009-08-12 08:22:08 +00002829 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002830 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002831
2832 bnx2x_e1h_disable(bp);
2833 } else {
2834 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002835 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002836
2837 bnx2x_e1h_enable(bp);
2838 }
2839 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2840 }
2841 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002842 bnx2x_config_mf_bw(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002843 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2844 }
2845
2846 /* Report results to MCP */
2847 if (dcc_event)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002848 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002849 else
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002850 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002851}
2852
Michael Chan28912902009-10-10 13:46:53 +00002853/* must be called under the spq lock */
2854static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2855{
2856 struct eth_spe *next_spe = bp->spq_prod_bd;
2857
2858 if (bp->spq_prod_bd == bp->spq_last_bd) {
2859 bp->spq_prod_bd = bp->spq;
2860 bp->spq_prod_idx = 0;
2861 DP(NETIF_MSG_TIMER, "end of spq\n");
2862 } else {
2863 bp->spq_prod_bd++;
2864 bp->spq_prod_idx++;
2865 }
2866 return next_spe;
2867}
2868
2869/* must be called under the spq lock */
2870static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2871{
2872 int func = BP_FUNC(bp);
2873
2874 /* Make sure that BD data is updated before writing the producer */
2875 wmb();
2876
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002877 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002878 bp->spq_prod_idx);
Michael Chan28912902009-10-10 13:46:53 +00002879 mmiowb();
2880}
2881
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002882/**
2883 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
2884 *
2885 * @cmd: command to check
2886 * @cmd_type: command type
2887 */
2888static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
2889{
2890 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2891 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2892 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2893 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2894 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2895 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
2896 return true;
2897 else
2898 return false;
2899
2900}
2901
2902
2903/**
2904 * bnx2x_sp_post - place a single command on an SP ring
2905 *
2906 * @bp: driver handle
2907 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2908 * @cid: SW CID the command is related to
2909 * @data_hi: command private data address (high 32 bits)
2910 * @data_lo: command private data address (low 32 bits)
2911 * @cmd_type: command type (e.g. NONE, ETH)
2912 *
2913 * SP data is handled as if it's always an address pair, thus data fields are
2914 * not swapped to little endian in upper functions. Instead this function swaps
2915 * data as if it's two u32 fields.
2916 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002917int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002918 u32 data_hi, u32 data_lo, int cmd_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002919{
Michael Chan28912902009-10-10 13:46:53 +00002920 struct eth_spe *spe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002921 u16 type;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002922 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002923
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002924#ifdef BNX2X_STOP_ON_ERROR
2925 if (unlikely(bp->panic))
2926 return -EIO;
2927#endif
2928
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002929 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002930
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002931 if (common) {
2932 if (!atomic_read(&bp->eq_spq_left)) {
2933 BNX2X_ERR("BUG! EQ ring full!\n");
2934 spin_unlock_bh(&bp->spq_lock);
2935 bnx2x_panic();
2936 return -EBUSY;
2937 }
2938 } else if (!atomic_read(&bp->cq_spq_left)) {
2939 BNX2X_ERR("BUG! SPQ ring full!\n");
2940 spin_unlock_bh(&bp->spq_lock);
2941 bnx2x_panic();
2942 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002943 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08002944
Michael Chan28912902009-10-10 13:46:53 +00002945 spe = bnx2x_sp_get_next(bp);
2946
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002947 /* CID needs port number to be encoded int it */
Michael Chan28912902009-10-10 13:46:53 +00002948 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002949 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
2950 HW_CID(bp, cid));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002951
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002952 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002953
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002954 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
2955 SPE_HDR_FUNCTION_ID);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002956
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002957 spe->hdr.type = cpu_to_le16(type);
2958
2959 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
2960 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
2961
2962 /* stats ramrod has it's own slot on the spq */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002963 if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002964 /*
2965 * It's ok if the actual decrement is issued towards the memory
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002966 * somewhere between the spin_lock and spin_unlock. Thus no
2967 * more explict memory barrier is needed.
2968 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002969 if (common)
2970 atomic_dec(&bp->eq_spq_left);
2971 else
2972 atomic_dec(&bp->cq_spq_left);
2973 }
2974
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002975
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002976 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002977 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002978 "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002979 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
2980 (u32)(U64_LO(bp->spq_mapping) +
2981 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002982 HW_CID(bp, cid), data_hi, data_lo, type,
2983 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002984
Michael Chan28912902009-10-10 13:46:53 +00002985 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002986 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002987 return 0;
2988}
2989
2990/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002991static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002992{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002993 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002994 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002995
2996 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002997 for (j = 0; j < 1000; j++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002998 val = (1UL << 31);
2999 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3000 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3001 if (val & (1L << 31))
3002 break;
3003
3004 msleep(5);
3005 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003006 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07003007 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003008 rc = -EBUSY;
3009 }
3010
3011 return rc;
3012}
3013
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003014/* release split MCP access lock register */
3015static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003016{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003017 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003018}
3019
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003020#define BNX2X_DEF_SB_ATT_IDX 0x0001
3021#define BNX2X_DEF_SB_IDX 0x0002
3022
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003023static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3024{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003025 struct host_sp_status_block *def_sb = bp->def_status_blk;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003026 u16 rc = 0;
3027
3028 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003029 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3030 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003031 rc |= BNX2X_DEF_SB_ATT_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003032 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003033
3034 if (bp->def_idx != def_sb->sp_sb.running_index) {
3035 bp->def_idx = def_sb->sp_sb.running_index;
3036 rc |= BNX2X_DEF_SB_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003037 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003038
3039 /* Do not reorder: indecies reading should complete before handling */
3040 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003041 return rc;
3042}
3043
3044/*
3045 * slow path service functions
3046 */
3047
3048static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3049{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003050 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003051 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3052 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003053 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3054 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003055 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00003056 u32 nig_mask = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003057 u32 reg_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003058
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003059 if (bp->attn_state & asserted)
3060 BNX2X_ERR("IGU ERROR\n");
3061
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003062 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3063 aeu_mask = REG_RD(bp, aeu_addr);
3064
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003065 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003066 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003067 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003068 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003069
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003070 REG_WR(bp, aeu_addr, aeu_mask);
3071 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003072
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003073 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003074 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003075 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003076
3077 if (asserted & ATTN_HARD_WIRED_MASK) {
3078 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003079
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003080 bnx2x_acquire_phy_lock(bp);
3081
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003082 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00003083 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003084
Yaniv Rosner361c3912011-06-14 01:33:19 +00003085 /* If nig_mask is not set, no need to call the update
3086 * function.
3087 */
3088 if (nig_mask) {
3089 REG_WR(bp, nig_int_mask_addr, 0);
3090
3091 bnx2x_link_attn(bp);
3092 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003093
3094 /* handle unicore attn? */
3095 }
3096 if (asserted & ATTN_SW_TIMER_4_FUNC)
3097 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3098
3099 if (asserted & GPIO_2_FUNC)
3100 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3101
3102 if (asserted & GPIO_3_FUNC)
3103 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3104
3105 if (asserted & GPIO_4_FUNC)
3106 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3107
3108 if (port == 0) {
3109 if (asserted & ATTN_GENERAL_ATTN_1) {
3110 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3111 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3112 }
3113 if (asserted & ATTN_GENERAL_ATTN_2) {
3114 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3115 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3116 }
3117 if (asserted & ATTN_GENERAL_ATTN_3) {
3118 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3119 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3120 }
3121 } else {
3122 if (asserted & ATTN_GENERAL_ATTN_4) {
3123 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3124 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3125 }
3126 if (asserted & ATTN_GENERAL_ATTN_5) {
3127 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3128 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3129 }
3130 if (asserted & ATTN_GENERAL_ATTN_6) {
3131 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3132 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3133 }
3134 }
3135
3136 } /* if hardwired */
3137
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003138 if (bp->common.int_block == INT_BLOCK_HC)
3139 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3140 COMMAND_REG_ATTN_BITS_SET);
3141 else
3142 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3143
3144 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3145 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3146 REG_WR(bp, reg_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003147
3148 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003149 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00003150 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003151 bnx2x_release_phy_lock(bp);
3152 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003153}
3154
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003155static inline void bnx2x_fan_failure(struct bnx2x *bp)
3156{
3157 int port = BP_PORT(bp);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003158 u32 ext_phy_config;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003159 /* mark the failure */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003160 ext_phy_config =
3161 SHMEM_RD(bp,
3162 dev_info.port_hw_config[port].external_phy_config);
3163
3164 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3165 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003166 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003167 ext_phy_config);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003168
3169 /* log the failure */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003170 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
3171 " the driver to shutdown the card to prevent permanent"
3172 " damage. Please contact OEM Support for assistance\n");
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003173}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003174
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003175static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3176{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003177 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003178 int reg_offset;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003179 u32 val;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003180
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003181 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3182 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003183
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003184 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003185
3186 val = REG_RD(bp, reg_offset);
3187 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3188 REG_WR(bp, reg_offset, val);
3189
3190 BNX2X_ERR("SPIO5 hw attention\n");
3191
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003192 /* Fan failure attention */
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003193 bnx2x_hw_reset_phy(&bp->link_params);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003194 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003195 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003196
Eilon Greenstein589abe32009-02-12 08:36:55 +00003197 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
3198 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
3199 bnx2x_acquire_phy_lock(bp);
3200 bnx2x_handle_module_detect_int(&bp->link_params);
3201 bnx2x_release_phy_lock(bp);
3202 }
3203
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003204 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3205
3206 val = REG_RD(bp, reg_offset);
3207 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3208 REG_WR(bp, reg_offset, val);
3209
3210 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003211 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003212 bnx2x_panic();
3213 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003214}
3215
3216static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3217{
3218 u32 val;
3219
Eilon Greenstein0626b892009-02-12 08:38:14 +00003220 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003221
3222 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3223 BNX2X_ERR("DB hw attention 0x%x\n", val);
3224 /* DORQ discard attention */
3225 if (val & 0x2)
3226 BNX2X_ERR("FATAL error from DORQ\n");
3227 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003228
3229 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3230
3231 int port = BP_PORT(bp);
3232 int reg_offset;
3233
3234 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3235 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3236
3237 val = REG_RD(bp, reg_offset);
3238 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3239 REG_WR(bp, reg_offset, val);
3240
3241 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003242 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003243 bnx2x_panic();
3244 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003245}
3246
3247static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3248{
3249 u32 val;
3250
3251 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3252
3253 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3254 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3255 /* CFC error attention */
3256 if (val & 0x2)
3257 BNX2X_ERR("FATAL error from CFC\n");
3258 }
3259
3260 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003261 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003262 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003263 /* RQ_USDMDP_FIFO_OVERFLOW */
3264 if (val & 0x18000)
3265 BNX2X_ERR("FATAL error from PXP\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003266
3267 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003268 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3269 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3270 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003271 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003272
3273 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3274
3275 int port = BP_PORT(bp);
3276 int reg_offset;
3277
3278 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3279 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3280
3281 val = REG_RD(bp, reg_offset);
3282 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3283 REG_WR(bp, reg_offset, val);
3284
3285 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003286 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003287 bnx2x_panic();
3288 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003289}
3290
3291static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3292{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003293 u32 val;
3294
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003295 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3296
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003297 if (attn & BNX2X_PMF_LINK_ASSERT) {
3298 int func = BP_FUNC(bp);
3299
3300 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003301 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3302 func_mf_config[BP_ABS_FUNC(bp)].config);
3303 val = SHMEM_RD(bp,
3304 func_mb[BP_FW_MB_IDX(bp)].drv_status);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003305 if (val & DRV_STATUS_DCC_EVENT_MASK)
3306 bnx2x_dcc_event(bp,
3307 (val & DRV_STATUS_DCC_EVENT_MASK));
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003308
3309 if (val & DRV_STATUS_SET_MF_BW)
3310 bnx2x_set_mf_bw(bp);
3311
Eilon Greenstein2691d512009-08-12 08:22:08 +00003312 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003313 bnx2x_pmf_update(bp);
3314
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00003315 /* Always call it here: bnx2x_link_report() will
3316 * prevent the link indication duplication.
3317 */
3318 bnx2x__link_status_update(bp);
3319
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003320 if (bp->port.pmf &&
Shmulik Ravid785b9b12010-12-30 06:27:03 +00003321 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3322 bp->dcbx_enabled > 0)
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003323 /* start dcbx state machine */
3324 bnx2x_dcbx_set_params(bp,
3325 BNX2X_DCBX_STATE_NEG_RECEIVED);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003326 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003327
3328 BNX2X_ERR("MC assert!\n");
3329 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3330 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3331 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3332 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3333 bnx2x_panic();
3334
3335 } else if (attn & BNX2X_MCP_ASSERT) {
3336
3337 BNX2X_ERR("MCP assert!\n");
3338 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003339 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003340
3341 } else
3342 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3343 }
3344
3345 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003346 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3347 if (attn & BNX2X_GRC_TIMEOUT) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003348 val = CHIP_IS_E1(bp) ? 0 :
3349 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003350 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3351 }
3352 if (attn & BNX2X_GRC_RSV) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003353 val = CHIP_IS_E1(bp) ? 0 :
3354 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003355 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3356 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003357 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003358 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003359}
3360
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003361/*
3362 * Bits map:
3363 * 0-7 - Engine0 load counter.
3364 * 8-15 - Engine1 load counter.
3365 * 16 - Engine0 RESET_IN_PROGRESS bit.
3366 * 17 - Engine1 RESET_IN_PROGRESS bit.
3367 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3368 * on the engine
3369 * 19 - Engine1 ONE_IS_LOADED.
3370 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3371 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3372 * just the one belonging to its engine).
3373 *
3374 */
3375#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3376
3377#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3378#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3379#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3380#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3381#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3382#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3383#define BNX2X_GLOBAL_RESET_BIT 0x00040000
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00003384
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003385/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003386 * Set the GLOBAL_RESET bit.
3387 *
3388 * Should be run under rtnl lock
3389 */
3390void bnx2x_set_reset_global(struct bnx2x *bp)
3391{
3392 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3393
3394 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3395 barrier();
3396 mmiowb();
3397}
3398
3399/*
3400 * Clear the GLOBAL_RESET bit.
3401 *
3402 * Should be run under rtnl lock
3403 */
3404static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3405{
3406 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3407
3408 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3409 barrier();
3410 mmiowb();
3411}
3412
3413/*
3414 * Checks the GLOBAL_RESET bit.
3415 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003416 * should be run under rtnl lock
3417 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003418static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3419{
3420 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3421
3422 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3423 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3424}
3425
3426/*
3427 * Clear RESET_IN_PROGRESS bit for the current engine.
3428 *
3429 * Should be run under rtnl lock
3430 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003431static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3432{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003433 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3434 u32 bit = BP_PATH(bp) ?
3435 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3436
3437 /* Clear the bit */
3438 val &= ~bit;
3439 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003440 barrier();
3441 mmiowb();
3442}
3443
3444/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003445 * Set RESET_IN_PROGRESS for the current engine.
3446 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003447 * should be run under rtnl lock
3448 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003449void bnx2x_set_reset_in_progress(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003450{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003451 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3452 u32 bit = BP_PATH(bp) ?
3453 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3454
3455 /* Set the bit */
3456 val |= bit;
3457 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003458 barrier();
3459 mmiowb();
3460}
3461
3462/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003463 * Checks the RESET_IN_PROGRESS bit for the given engine.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003464 * should be run under rtnl lock
3465 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003466bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003467{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003468 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3469 u32 bit = engine ?
3470 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3471
3472 /* return false if bit is set */
3473 return (val & bit) ? false : true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003474}
3475
3476/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003477 * Increment the load counter for the current engine.
3478 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003479 * should be run under rtnl lock
3480 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003481void bnx2x_inc_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003482{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003483 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3484 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3485 BNX2X_PATH0_LOAD_CNT_MASK;
3486 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3487 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003488
3489 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3490
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003491 /* get the current counter value */
3492 val1 = (val & mask) >> shift;
3493
3494 /* increment... */
3495 val1++;
3496
3497 /* clear the old value */
3498 val &= ~mask;
3499
3500 /* set the new one */
3501 val |= ((val1 << shift) & mask);
3502
3503 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003504 barrier();
3505 mmiowb();
3506}
3507
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003508/**
3509 * bnx2x_dec_load_cnt - decrement the load counter
3510 *
3511 * @bp: driver handle
3512 *
3513 * Should be run under rtnl lock.
3514 * Decrements the load counter for the current engine. Returns
3515 * the new counter value.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003516 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003517u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003518{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003519 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3520 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3521 BNX2X_PATH0_LOAD_CNT_MASK;
3522 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3523 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003524
3525 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3526
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003527 /* get the current counter value */
3528 val1 = (val & mask) >> shift;
3529
3530 /* decrement... */
3531 val1--;
3532
3533 /* clear the old value */
3534 val &= ~mask;
3535
3536 /* set the new one */
3537 val |= ((val1 << shift) & mask);
3538
3539 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003540 barrier();
3541 mmiowb();
3542
3543 return val1;
3544}
3545
3546/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003547 * Read the load counter for the current engine.
3548 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003549 * should be run under rtnl lock
3550 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003551static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003552{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003553 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3554 BNX2X_PATH0_LOAD_CNT_MASK);
3555 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3556 BNX2X_PATH0_LOAD_CNT_SHIFT);
3557 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3558
3559 DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
3560
3561 val = (val & mask) >> shift;
3562
3563 DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
3564
3565 return val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003566}
3567
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003568/*
3569 * Reset the load counter for the current engine.
3570 *
3571 * should be run under rtnl lock
3572 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003573static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
3574{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003575 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3576 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3577 BNX2X_PATH0_LOAD_CNT_MASK);
3578
3579 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003580}
3581
3582static inline void _print_next_block(int idx, const char *blk)
3583{
3584 if (idx)
3585 pr_cont(", ");
3586 pr_cont("%s", blk);
3587}
3588
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003589static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3590 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003591{
3592 int i = 0;
3593 u32 cur_bit = 0;
3594 for (i = 0; sig; i++) {
3595 cur_bit = ((u32)0x1 << i);
3596 if (sig & cur_bit) {
3597 switch (cur_bit) {
3598 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003599 if (print)
3600 _print_next_block(par_num++, "BRB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003601 break;
3602 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003603 if (print)
3604 _print_next_block(par_num++, "PARSER");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003605 break;
3606 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003607 if (print)
3608 _print_next_block(par_num++, "TSDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003609 break;
3610 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003611 if (print)
3612 _print_next_block(par_num++,
3613 "SEARCHER");
3614 break;
3615 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3616 if (print)
3617 _print_next_block(par_num++, "TCM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003618 break;
3619 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003620 if (print)
3621 _print_next_block(par_num++, "TSEMI");
3622 break;
3623 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3624 if (print)
3625 _print_next_block(par_num++, "XPB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003626 break;
3627 }
3628
3629 /* Clear the bit */
3630 sig &= ~cur_bit;
3631 }
3632 }
3633
3634 return par_num;
3635}
3636
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003637static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3638 bool *global, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003639{
3640 int i = 0;
3641 u32 cur_bit = 0;
3642 for (i = 0; sig; i++) {
3643 cur_bit = ((u32)0x1 << i);
3644 if (sig & cur_bit) {
3645 switch (cur_bit) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003646 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3647 if (print)
3648 _print_next_block(par_num++, "PBF");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003649 break;
3650 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003651 if (print)
3652 _print_next_block(par_num++, "QM");
3653 break;
3654 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3655 if (print)
3656 _print_next_block(par_num++, "TM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003657 break;
3658 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003659 if (print)
3660 _print_next_block(par_num++, "XSDM");
3661 break;
3662 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3663 if (print)
3664 _print_next_block(par_num++, "XCM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003665 break;
3666 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003667 if (print)
3668 _print_next_block(par_num++, "XSEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003669 break;
3670 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003671 if (print)
3672 _print_next_block(par_num++,
3673 "DOORBELLQ");
3674 break;
3675 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3676 if (print)
3677 _print_next_block(par_num++, "NIG");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003678 break;
3679 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003680 if (print)
3681 _print_next_block(par_num++,
3682 "VAUX PCI CORE");
3683 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003684 break;
3685 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003686 if (print)
3687 _print_next_block(par_num++, "DEBUG");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003688 break;
3689 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003690 if (print)
3691 _print_next_block(par_num++, "USDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003692 break;
3693 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003694 if (print)
3695 _print_next_block(par_num++, "USEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003696 break;
3697 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003698 if (print)
3699 _print_next_block(par_num++, "UPB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003700 break;
3701 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003702 if (print)
3703 _print_next_block(par_num++, "CSDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003704 break;
3705 }
3706
3707 /* Clear the bit */
3708 sig &= ~cur_bit;
3709 }
3710 }
3711
3712 return par_num;
3713}
3714
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003715static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3716 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003717{
3718 int i = 0;
3719 u32 cur_bit = 0;
3720 for (i = 0; sig; i++) {
3721 cur_bit = ((u32)0x1 << i);
3722 if (sig & cur_bit) {
3723 switch (cur_bit) {
3724 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003725 if (print)
3726 _print_next_block(par_num++, "CSEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003727 break;
3728 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003729 if (print)
3730 _print_next_block(par_num++, "PXP");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003731 break;
3732 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003733 if (print)
3734 _print_next_block(par_num++,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003735 "PXPPCICLOCKCLIENT");
3736 break;
3737 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003738 if (print)
3739 _print_next_block(par_num++, "CFC");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003740 break;
3741 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003742 if (print)
3743 _print_next_block(par_num++, "CDU");
3744 break;
3745 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3746 if (print)
3747 _print_next_block(par_num++, "DMAE");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003748 break;
3749 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003750 if (print)
3751 _print_next_block(par_num++, "IGU");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003752 break;
3753 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003754 if (print)
3755 _print_next_block(par_num++, "MISC");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003756 break;
3757 }
3758
3759 /* Clear the bit */
3760 sig &= ~cur_bit;
3761 }
3762 }
3763
3764 return par_num;
3765}
3766
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003767static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
3768 bool *global, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003769{
3770 int i = 0;
3771 u32 cur_bit = 0;
3772 for (i = 0; sig; i++) {
3773 cur_bit = ((u32)0x1 << i);
3774 if (sig & cur_bit) {
3775 switch (cur_bit) {
3776 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003777 if (print)
3778 _print_next_block(par_num++, "MCP ROM");
3779 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003780 break;
3781 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003782 if (print)
3783 _print_next_block(par_num++,
3784 "MCP UMP RX");
3785 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003786 break;
3787 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003788 if (print)
3789 _print_next_block(par_num++,
3790 "MCP UMP TX");
3791 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003792 break;
3793 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003794 if (print)
3795 _print_next_block(par_num++,
3796 "MCP SCPAD");
3797 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003798 break;
3799 }
3800
3801 /* Clear the bit */
3802 sig &= ~cur_bit;
3803 }
3804 }
3805
3806 return par_num;
3807}
3808
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003809static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
3810 u32 sig0, u32 sig1, u32 sig2, u32 sig3)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003811{
3812 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
3813 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
3814 int par_num = 0;
3815 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
3816 "[0]:0x%08x [1]:0x%08x "
3817 "[2]:0x%08x [3]:0x%08x\n",
3818 sig0 & HW_PRTY_ASSERT_SET_0,
3819 sig1 & HW_PRTY_ASSERT_SET_1,
3820 sig2 & HW_PRTY_ASSERT_SET_2,
3821 sig3 & HW_PRTY_ASSERT_SET_3);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003822 if (print)
3823 netdev_err(bp->dev,
3824 "Parity errors detected in blocks: ");
3825 par_num = bnx2x_check_blocks_with_parity0(
3826 sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
3827 par_num = bnx2x_check_blocks_with_parity1(
3828 sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
3829 par_num = bnx2x_check_blocks_with_parity2(
3830 sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
3831 par_num = bnx2x_check_blocks_with_parity3(
3832 sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
3833 if (print)
3834 pr_cont("\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003835 return true;
3836 } else
3837 return false;
3838}
3839
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003840/**
3841 * bnx2x_chk_parity_attn - checks for parity attentions.
3842 *
3843 * @bp: driver handle
3844 * @global: true if there was a global attention
3845 * @print: show parity attention in syslog
3846 */
3847bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003848{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003849 struct attn_route attn;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003850 int port = BP_PORT(bp);
3851
3852 attn.sig[0] = REG_RD(bp,
3853 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
3854 port*4);
3855 attn.sig[1] = REG_RD(bp,
3856 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
3857 port*4);
3858 attn.sig[2] = REG_RD(bp,
3859 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
3860 port*4);
3861 attn.sig[3] = REG_RD(bp,
3862 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
3863 port*4);
3864
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003865 return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
3866 attn.sig[2], attn.sig[3]);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003867}
3868
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003869
3870static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
3871{
3872 u32 val;
3873 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3874
3875 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3876 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
3877 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3878 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3879 "ADDRESS_ERROR\n");
3880 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
3881 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3882 "INCORRECT_RCV_BEHAVIOR\n");
3883 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
3884 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3885 "WAS_ERROR_ATTN\n");
3886 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
3887 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3888 "VF_LENGTH_VIOLATION_ATTN\n");
3889 if (val &
3890 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
3891 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3892 "VF_GRC_SPACE_VIOLATION_ATTN\n");
3893 if (val &
3894 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
3895 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3896 "VF_MSIX_BAR_VIOLATION_ATTN\n");
3897 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
3898 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3899 "TCPL_ERROR_ATTN\n");
3900 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
3901 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3902 "TCPL_IN_TWO_RCBS_ATTN\n");
3903 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
3904 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3905 "CSSNOOP_FIFO_OVERFLOW\n");
3906 }
3907 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
3908 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
3909 BNX2X_ERR("ATC hw attention 0x%x\n", val);
3910 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
3911 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
3912 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
3913 BNX2X_ERR("ATC_ATC_INT_STS_REG"
3914 "_ATC_TCPL_TO_NOT_PEND\n");
3915 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
3916 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3917 "ATC_GPA_MULTIPLE_HITS\n");
3918 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
3919 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3920 "ATC_RCPL_TO_EMPTY_CNT\n");
3921 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
3922 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
3923 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
3924 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3925 "ATC_IREQ_LESS_THAN_STU\n");
3926 }
3927
3928 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3929 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
3930 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
3931 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3932 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
3933 }
3934
3935}
3936
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003937static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
3938{
3939 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003940 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003941 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003942 u32 reg_addr;
3943 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003944 u32 aeu_mask;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003945 bool global = false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003946
3947 /* need to take HW lock because MCP or other port might also
3948 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003949 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003950
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003951 if (bnx2x_chk_parity_attn(bp, &global, true)) {
3952#ifndef BNX2X_STOP_ON_ERROR
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003953 bp->recovery_state = BNX2X_RECOVERY_INIT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003954 schedule_delayed_work(&bp->reset_task, 0);
3955 /* Disable HW interrupts */
3956 bnx2x_int_disable(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003957 /* In case of parity errors don't handle attentions so that
3958 * other function would "see" parity errors.
3959 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003960#else
3961 bnx2x_panic();
3962#endif
3963 bnx2x_release_alr(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003964 return;
3965 }
3966
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003967 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
3968 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
3969 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
3970 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003971 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003972 attn.sig[4] =
3973 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
3974 else
3975 attn.sig[4] = 0;
3976
3977 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
3978 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003979
3980 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
3981 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003982 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003983
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003984 DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
3985 "%08x %08x %08x\n",
3986 index,
3987 group_mask->sig[0], group_mask->sig[1],
3988 group_mask->sig[2], group_mask->sig[3],
3989 group_mask->sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003990
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003991 bnx2x_attn_int_deasserted4(bp,
3992 attn.sig[4] & group_mask->sig[4]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003993 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003994 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003995 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003996 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003997 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003998 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003999 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004000 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004001 }
4002 }
4003
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004004 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004005
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004006 if (bp->common.int_block == INT_BLOCK_HC)
4007 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4008 COMMAND_REG_ATTN_BITS_CLR);
4009 else
4010 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004011
4012 val = ~deasserted;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004013 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4014 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004015 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004016
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004017 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004018 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004019
4020 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4021 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4022
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004023 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4024 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004025
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004026 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4027 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004028 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004029 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4030
4031 REG_WR(bp, reg_addr, aeu_mask);
4032 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004033
4034 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4035 bp->attn_state &= ~deasserted;
4036 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4037}
4038
4039static void bnx2x_attn_int(struct bnx2x *bp)
4040{
4041 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08004042 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4043 attn_bits);
4044 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4045 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004046 u32 attn_state = bp->attn_state;
4047
4048 /* look for changed bits */
4049 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4050 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4051
4052 DP(NETIF_MSG_HW,
4053 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4054 attn_bits, attn_ack, asserted, deasserted);
4055
4056 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004057 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004058
4059 /* handle bits that were raised */
4060 if (asserted)
4061 bnx2x_attn_int_asserted(bp, asserted);
4062
4063 if (deasserted)
4064 bnx2x_attn_int_deasserted(bp, deasserted);
4065}
4066
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004067void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4068 u16 index, u8 op, u8 update)
4069{
4070 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4071
4072 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4073 igu_addr);
4074}
4075
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004076static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4077{
4078 /* No memory barriers */
4079 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4080 mmiowb(); /* keep prod updates ordered */
4081}
4082
4083#ifdef BCM_CNIC
4084static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4085 union event_ring_elem *elem)
4086{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004087 u8 err = elem->message.error;
4088
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004089 if (!bp->cnic_eth_dev.starting_cid ||
Vladislav Zolotarovc3a8ce62011-05-22 10:08:09 +00004090 (cid < bp->cnic_eth_dev.starting_cid &&
4091 cid != bp->cnic_eth_dev.iscsi_l2_cid))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004092 return 1;
4093
4094 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4095
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004096 if (unlikely(err)) {
4097
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004098 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4099 cid);
4100 bnx2x_panic_dump(bp);
4101 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004102 bnx2x_cnic_cfc_comp(bp, cid, err);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004103 return 0;
4104}
4105#endif
4106
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004107static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4108{
4109 struct bnx2x_mcast_ramrod_params rparam;
4110 int rc;
4111
4112 memset(&rparam, 0, sizeof(rparam));
4113
4114 rparam.mcast_obj = &bp->mcast_obj;
4115
4116 netif_addr_lock_bh(bp->dev);
4117
4118 /* Clear pending state for the last command */
4119 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4120
4121 /* If there are pending mcast commands - send them */
4122 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4123 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4124 if (rc < 0)
4125 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4126 rc);
4127 }
4128
4129 netif_addr_unlock_bh(bp->dev);
4130}
4131
4132static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4133 union event_ring_elem *elem)
4134{
4135 unsigned long ramrod_flags = 0;
4136 int rc = 0;
4137 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4138 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4139
4140 /* Always push next commands out, don't wait here */
4141 __set_bit(RAMROD_CONT, &ramrod_flags);
4142
4143 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4144 case BNX2X_FILTER_MAC_PENDING:
4145#ifdef BCM_CNIC
4146 if (cid == BNX2X_ISCSI_ETH_CID)
4147 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4148 else
4149#endif
4150 vlan_mac_obj = &bp->fp[cid].mac_obj;
4151
4152 break;
4153 vlan_mac_obj = &bp->fp[cid].mac_obj;
4154
4155 case BNX2X_FILTER_MCAST_PENDING:
4156 /* This is only relevant for 57710 where multicast MACs are
4157 * configured as unicast MACs using the same ramrod.
4158 */
4159 bnx2x_handle_mcast_eqe(bp);
4160 return;
4161 default:
4162 BNX2X_ERR("Unsupported classification command: %d\n",
4163 elem->message.data.eth_event.echo);
4164 return;
4165 }
4166
4167 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4168
4169 if (rc < 0)
4170 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4171 else if (rc > 0)
4172 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4173
4174}
4175
4176#ifdef BCM_CNIC
4177static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4178#endif
4179
4180static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4181{
4182 netif_addr_lock_bh(bp->dev);
4183
4184 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4185
4186 /* Send rx_mode command again if was requested */
4187 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4188 bnx2x_set_storm_rx_mode(bp);
4189#ifdef BCM_CNIC
4190 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4191 &bp->sp_state))
4192 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4193 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4194 &bp->sp_state))
4195 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4196#endif
4197
4198 netif_addr_unlock_bh(bp->dev);
4199}
4200
4201static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4202 struct bnx2x *bp, u32 cid)
4203{
4204#ifdef BCM_CNIC
4205 if (cid == BNX2X_FCOE_ETH_CID)
4206 return &bnx2x_fcoe(bp, q_obj);
4207 else
4208#endif
4209 return &bnx2x_fp(bp, cid, q_obj);
4210}
4211
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004212static void bnx2x_eq_int(struct bnx2x *bp)
4213{
4214 u16 hw_cons, sw_cons, sw_prod;
4215 union event_ring_elem *elem;
4216 u32 cid;
4217 u8 opcode;
4218 int spqe_cnt = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004219 struct bnx2x_queue_sp_obj *q_obj;
4220 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4221 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004222
4223 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4224
4225 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4226 * when we get the the next-page we nned to adjust so the loop
4227 * condition below will be met. The next element is the size of a
4228 * regular element and hence incrementing by 1
4229 */
4230 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4231 hw_cons++;
4232
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004233 /* This function may never run in parallel with itself for a
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004234 * specific bp, thus there is no need in "paired" read memory
4235 * barrier here.
4236 */
4237 sw_cons = bp->eq_cons;
4238 sw_prod = bp->eq_prod;
4239
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004240 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
4241 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004242
4243 for (; sw_cons != hw_cons;
4244 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4245
4246
4247 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4248
4249 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4250 opcode = elem->message.opcode;
4251
4252
4253 /* handle eq element */
4254 switch (opcode) {
4255 case EVENT_RING_OPCODE_STAT_QUERY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004256 DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
4257 bp->stats_comp++);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004258 /* nothing to do with stats comp */
4259 continue;
4260
4261 case EVENT_RING_OPCODE_CFC_DEL:
4262 /* handle according to cid range */
4263 /*
4264 * we may want to verify here that the bp state is
4265 * HALTING
4266 */
4267 DP(NETIF_MSG_IFDOWN,
4268 "got delete ramrod for MULTI[%d]\n", cid);
4269#ifdef BCM_CNIC
4270 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4271 goto next_spqe;
4272#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004273 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4274
4275 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4276 break;
4277
4278
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004279
4280 goto next_spqe;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004281
4282 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4283 DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
4284 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4285 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004286
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004287 case EVENT_RING_OPCODE_START_TRAFFIC:
4288 DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
4289 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4290 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004291 case EVENT_RING_OPCODE_FUNCTION_START:
4292 DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
4293 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4294 break;
4295
4296 goto next_spqe;
4297
4298 case EVENT_RING_OPCODE_FUNCTION_STOP:
4299 DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
4300 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4301 break;
4302
4303 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004304 }
4305
4306 switch (opcode | bp->state) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004307 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4308 BNX2X_STATE_OPEN):
4309 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004310 BNX2X_STATE_OPENING_WAIT4_PORT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004311 cid = elem->message.data.eth_event.echo &
4312 BNX2X_SWCID_MASK;
4313 DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
4314 cid);
4315 rss_raw->clear_pending(rss_raw);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004316 break;
4317
4318 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4319 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004320 case (EVENT_RING_OPCODE_SET_MAC |
4321 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004322 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4323 BNX2X_STATE_OPEN):
4324 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4325 BNX2X_STATE_DIAG):
4326 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4327 BNX2X_STATE_CLOSING_WAIT4_HALT):
4328 DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
4329 bnx2x_handle_classification_eqe(bp, elem);
4330 break;
4331
4332 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4333 BNX2X_STATE_OPEN):
4334 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4335 BNX2X_STATE_DIAG):
4336 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4337 BNX2X_STATE_CLOSING_WAIT4_HALT):
4338 DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
4339 bnx2x_handle_mcast_eqe(bp);
4340 break;
4341
4342 case (EVENT_RING_OPCODE_FILTERS_RULES |
4343 BNX2X_STATE_OPEN):
4344 case (EVENT_RING_OPCODE_FILTERS_RULES |
4345 BNX2X_STATE_DIAG):
4346 case (EVENT_RING_OPCODE_FILTERS_RULES |
4347 BNX2X_STATE_CLOSING_WAIT4_HALT):
4348 DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
4349 bnx2x_handle_rx_mode_eqe(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004350 break;
4351 default:
4352 /* unknown event log error and continue */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004353 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4354 elem->message.opcode, bp->state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004355 }
4356next_spqe:
4357 spqe_cnt++;
4358 } /* for */
4359
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00004360 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004361 atomic_add(spqe_cnt, &bp->eq_spq_left);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004362
4363 bp->eq_cons = sw_cons;
4364 bp->eq_prod = sw_prod;
4365 /* Make sure that above mem writes were issued towards the memory */
4366 smp_wmb();
4367
4368 /* update producer */
4369 bnx2x_update_eq_prod(bp, bp->eq_prod);
4370}
4371
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004372static void bnx2x_sp_task(struct work_struct *work)
4373{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08004374 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004375 u16 status;
4376
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004377 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004378/* if (status == 0) */
4379/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004380
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004381 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004382
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004383 /* HW attentions */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004384 if (status & BNX2X_DEF_SB_ATT_IDX) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004385 bnx2x_attn_int(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004386 status &= ~BNX2X_DEF_SB_ATT_IDX;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004387 }
4388
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004389 /* SP events: STAT_QUERY and others */
4390 if (status & BNX2X_DEF_SB_IDX) {
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004391#ifdef BCM_CNIC
4392 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004393
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004394 if ((!NO_FCOE(bp)) &&
4395 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
4396 napi_schedule(&bnx2x_fcoe(bp, napi));
4397#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004398 /* Handle EQ completions */
4399 bnx2x_eq_int(bp);
4400
4401 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4402 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4403
4404 status &= ~BNX2X_DEF_SB_IDX;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004405 }
4406
4407 if (unlikely(status))
4408 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
4409 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004410
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004411 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4412 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004413}
4414
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004415irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004416{
4417 struct net_device *dev = dev_instance;
4418 struct bnx2x *bp = netdev_priv(dev);
4419
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004420 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4421 IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004422
4423#ifdef BNX2X_STOP_ON_ERROR
4424 if (unlikely(bp->panic))
4425 return IRQ_HANDLED;
4426#endif
4427
Michael Chan993ac7b2009-10-10 13:46:56 +00004428#ifdef BCM_CNIC
4429 {
4430 struct cnic_ops *c_ops;
4431
4432 rcu_read_lock();
4433 c_ops = rcu_dereference(bp->cnic_ops);
4434 if (c_ops)
4435 c_ops->cnic_handler(bp->cnic_data, NULL);
4436 rcu_read_unlock();
4437 }
4438#endif
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08004439 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004440
4441 return IRQ_HANDLED;
4442}
4443
4444/* end of slow path */
4445
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004446
4447void bnx2x_drv_pulse(struct bnx2x *bp)
4448{
4449 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4450 bp->fw_drv_pulse_wr_seq);
4451}
4452
4453
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004454static void bnx2x_timer(unsigned long data)
4455{
4456 struct bnx2x *bp = (struct bnx2x *) data;
4457
4458 if (!netif_running(bp->dev))
4459 return;
4460
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004461 if (poll) {
4462 struct bnx2x_fastpath *fp = &bp->fp[0];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004463
Eilon Greenstein7961f792009-03-02 07:59:31 +00004464 bnx2x_tx_int(fp);
David S. Millerb8ee8322011-04-17 16:56:12 -07004465 bnx2x_rx_int(fp, 1000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004466 }
4467
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004468 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004469 int mb_idx = BP_FW_MB_IDX(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004470 u32 drv_pulse;
4471 u32 mcp_pulse;
4472
4473 ++bp->fw_drv_pulse_wr_seq;
4474 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4475 /* TBD - add SYSTEM_TIME */
4476 drv_pulse = bp->fw_drv_pulse_wr_seq;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004477 bnx2x_drv_pulse(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004478
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004479 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004480 MCP_PULSE_SEQ_MASK);
4481 /* The delta between driver pulse and mcp response
4482 * should be 1 (before mcp response) or 0 (after mcp response)
4483 */
4484 if ((drv_pulse != mcp_pulse) &&
4485 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4486 /* someone lost a heartbeat... */
4487 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4488 drv_pulse, mcp_pulse);
4489 }
4490 }
4491
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07004492 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004493 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004494
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004495 mod_timer(&bp->timer, jiffies + bp->current_interval);
4496}
4497
4498/* end of Statistics */
4499
4500/* nic init */
4501
4502/*
4503 * nic init service functions
4504 */
4505
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004506static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004507{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004508 u32 i;
4509 if (!(len%4) && !(addr%4))
4510 for (i = 0; i < len; i += 4)
4511 REG_WR(bp, addr + i, fill);
4512 else
4513 for (i = 0; i < len; i++)
4514 REG_WR8(bp, addr + i, fill);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004515
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004516}
4517
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004518/* helper: writes FP SP data to FW - data_size in dwords */
4519static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4520 int fw_sb_id,
4521 u32 *sb_data_p,
4522 u32 data_size)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004523{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004524 int index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004525 for (index = 0; index < data_size; index++)
4526 REG_WR(bp, BAR_CSTRORM_INTMEM +
4527 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4528 sizeof(u32)*index,
4529 *(sb_data_p + index));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004530}
4531
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004532static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4533{
4534 u32 *sb_data_p;
4535 u32 data_size = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004536 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004537 struct hc_status_block_data_e1x sb_data_e1x;
4538
4539 /* disable the function first */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004540 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004541 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004542 sb_data_e2.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004543 sb_data_e2.common.p_func.vf_valid = false;
4544 sb_data_p = (u32 *)&sb_data_e2;
4545 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4546 } else {
4547 memset(&sb_data_e1x, 0,
4548 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004549 sb_data_e1x.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004550 sb_data_e1x.common.p_func.vf_valid = false;
4551 sb_data_p = (u32 *)&sb_data_e1x;
4552 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4553 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004554 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4555
4556 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4557 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4558 CSTORM_STATUS_BLOCK_SIZE);
4559 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4560 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4561 CSTORM_SYNC_BLOCK_SIZE);
4562}
4563
4564/* helper: writes SP SB data to FW */
4565static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4566 struct hc_sp_status_block_data *sp_sb_data)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004567{
4568 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004569 int i;
4570 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4571 REG_WR(bp, BAR_CSTRORM_INTMEM +
4572 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4573 i*sizeof(u32),
4574 *((u32 *)sp_sb_data + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004575}
4576
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004577static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4578{
4579 int func = BP_FUNC(bp);
4580 struct hc_sp_status_block_data sp_sb_data;
4581 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4582
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004583 sp_sb_data.state = SB_DISABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004584 sp_sb_data.p_func.vf_valid = false;
4585
4586 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4587
4588 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4589 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4590 CSTORM_SP_STATUS_BLOCK_SIZE);
4591 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4592 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4593 CSTORM_SP_SYNC_BLOCK_SIZE);
4594
4595}
4596
4597
4598static inline
4599void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4600 int igu_sb_id, int igu_seg_id)
4601{
4602 hc_sm->igu_sb_id = igu_sb_id;
4603 hc_sm->igu_seg_id = igu_seg_id;
4604 hc_sm->timer_value = 0xFF;
4605 hc_sm->time_to_expire = 0xFFFFFFFF;
4606}
4607
stephen hemminger8d962862010-10-21 07:50:56 +00004608static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004609 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4610{
4611 int igu_seg_id;
4612
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004613 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004614 struct hc_status_block_data_e1x sb_data_e1x;
4615 struct hc_status_block_sm *hc_sm_p;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004616 int data_size;
4617 u32 *sb_data_p;
4618
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004619 if (CHIP_INT_MODE_IS_BC(bp))
4620 igu_seg_id = HC_SEG_ACCESS_NORM;
4621 else
4622 igu_seg_id = IGU_SEG_ACCESS_NORM;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004623
4624 bnx2x_zero_fp_sb(bp, fw_sb_id);
4625
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004626 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004627 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004628 sb_data_e2.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004629 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4630 sb_data_e2.common.p_func.vf_id = vfid;
4631 sb_data_e2.common.p_func.vf_valid = vf_valid;
4632 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4633 sb_data_e2.common.same_igu_sb_1b = true;
4634 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4635 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4636 hc_sm_p = sb_data_e2.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004637 sb_data_p = (u32 *)&sb_data_e2;
4638 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4639 } else {
4640 memset(&sb_data_e1x, 0,
4641 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004642 sb_data_e1x.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004643 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4644 sb_data_e1x.common.p_func.vf_id = 0xff;
4645 sb_data_e1x.common.p_func.vf_valid = false;
4646 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4647 sb_data_e1x.common.same_igu_sb_1b = true;
4648 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4649 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4650 hc_sm_p = sb_data_e1x.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004651 sb_data_p = (u32 *)&sb_data_e1x;
4652 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4653 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004654
4655 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4656 igu_sb_id, igu_seg_id);
4657 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4658 igu_sb_id, igu_seg_id);
4659
4660 DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
4661
4662 /* write indecies to HW */
4663 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4664}
4665
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004666static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004667 u16 tx_usec, u16 rx_usec)
4668{
4669 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX,
4670 false, rx_usec);
4671 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX,
4672 false, tx_usec);
4673}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004674
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004675static void bnx2x_init_def_sb(struct bnx2x *bp)
4676{
4677 struct host_sp_status_block *def_sb = bp->def_status_blk;
4678 dma_addr_t mapping = bp->def_status_blk_mapping;
4679 int igu_sp_sb_index;
4680 int igu_seg_id;
4681 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004682 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004683 int reg_offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004684 u64 section;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004685 int index;
4686 struct hc_sp_status_block_data sp_sb_data;
4687 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4688
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004689 if (CHIP_INT_MODE_IS_BC(bp)) {
4690 igu_sp_sb_index = DEF_SB_IGU_ID;
4691 igu_seg_id = HC_SEG_ACCESS_DEF;
4692 } else {
4693 igu_sp_sb_index = bp->igu_dsb_id;
4694 igu_seg_id = IGU_SEG_ACCESS_DEF;
4695 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004696
4697 /* ATTN */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004698 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004699 atten_status_block);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004700 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004701
Eliezer Tamir49d66772008-02-28 11:53:13 -08004702 bp->attn_state = 0;
4703
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004704 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4705 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004706 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004707 int sindex;
4708 /* take care of sig[0]..sig[4] */
4709 for (sindex = 0; sindex < 4; sindex++)
4710 bp->attn_group[index].sig[sindex] =
4711 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004712
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004713 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004714 /*
4715 * enable5 is separate from the rest of the registers,
4716 * and therefore the address skip is 4
4717 * and not 16 between the different groups
4718 */
4719 bp->attn_group[index].sig[4] = REG_RD(bp,
4720 reg_offset + 0x10 + 0x4*index);
4721 else
4722 bp->attn_group[index].sig[4] = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004723 }
4724
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004725 if (bp->common.int_block == INT_BLOCK_HC) {
4726 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4727 HC_REG_ATTN_MSG0_ADDR_L);
4728
4729 REG_WR(bp, reg_offset, U64_LO(section));
4730 REG_WR(bp, reg_offset + 4, U64_HI(section));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004731 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004732 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
4733 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
4734 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004735
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004736 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4737 sp_sb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004738
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004739 bnx2x_zero_sp_sb(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004740
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004741 sp_sb_data.state = SB_ENABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004742 sp_sb_data.host_sb_addr.lo = U64_LO(section);
4743 sp_sb_data.host_sb_addr.hi = U64_HI(section);
4744 sp_sb_data.igu_sb_id = igu_sp_sb_index;
4745 sp_sb_data.igu_seg_id = igu_seg_id;
4746 sp_sb_data.p_func.pf_id = func;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004747 sp_sb_data.p_func.vnic_id = BP_VN(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004748 sp_sb_data.p_func.vf_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004749
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004750 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004751
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004752 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004753}
4754
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004755void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004756{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004757 int i;
4758
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004759 for_each_eth_queue(bp, i)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004760 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
Ariel Elior423cfa7e2011-03-14 13:43:22 -07004761 bp->tx_ticks, bp->rx_ticks);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004762}
4763
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004764static void bnx2x_init_sp_ring(struct bnx2x *bp)
4765{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004766 spin_lock_init(&bp->spq_lock);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004767 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004768
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004769 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004770 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4771 bp->spq_prod_bd = bp->spq;
4772 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004773}
4774
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004775static void bnx2x_init_eq_ring(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004776{
4777 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004778 for (i = 1; i <= NUM_EQ_PAGES; i++) {
4779 union event_ring_elem *elem =
4780 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004781
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004782 elem->next_page.addr.hi =
4783 cpu_to_le32(U64_HI(bp->eq_mapping +
4784 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
4785 elem->next_page.addr.lo =
4786 cpu_to_le32(U64_LO(bp->eq_mapping +
4787 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004788 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004789 bp->eq_cons = 0;
4790 bp->eq_prod = NUM_EQ_DESC;
4791 bp->eq_cons_sb = BNX2X_EQ_INDEX;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004792 /* we want a warning message before it gets rought... */
4793 atomic_set(&bp->eq_spq_left,
4794 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004795}
4796
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004797
4798/* called with netif_addr_lock_bh() */
4799void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
4800 unsigned long rx_mode_flags,
4801 unsigned long rx_accept_flags,
4802 unsigned long tx_accept_flags,
4803 unsigned long ramrod_flags)
Tom Herbertab532cf2011-02-16 10:27:02 +00004804{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004805 struct bnx2x_rx_mode_ramrod_params ramrod_param;
4806 int rc;
Tom Herbertab532cf2011-02-16 10:27:02 +00004807
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004808 memset(&ramrod_param, 0, sizeof(ramrod_param));
Tom Herbertab532cf2011-02-16 10:27:02 +00004809
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004810 /* Prepare ramrod parameters */
4811 ramrod_param.cid = 0;
4812 ramrod_param.cl_id = cl_id;
4813 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
4814 ramrod_param.func_id = BP_FUNC(bp);
4815
4816 ramrod_param.pstate = &bp->sp_state;
4817 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
4818
4819 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
4820 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
4821
4822 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4823
4824 ramrod_param.ramrod_flags = ramrod_flags;
4825 ramrod_param.rx_mode_flags = rx_mode_flags;
4826
4827 ramrod_param.rx_accept_flags = rx_accept_flags;
4828 ramrod_param.tx_accept_flags = tx_accept_flags;
4829
4830 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
4831 if (rc < 0) {
4832 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
4833 return;
4834 }
4835}
4836
4837/* called with netif_addr_lock_bh() */
4838void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4839{
4840 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
4841 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
4842
4843#ifdef BCM_CNIC
4844 if (!NO_FCOE(bp))
4845
4846 /* Configure rx_mode of FCoE Queue */
4847 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
4848#endif
4849
4850 switch (bp->rx_mode) {
4851 case BNX2X_RX_MODE_NONE:
4852 /*
4853 * 'drop all' supersedes any accept flags that may have been
4854 * passed to the function.
4855 */
4856 break;
4857 case BNX2X_RX_MODE_NORMAL:
4858 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4859 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
4860 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4861
4862 /* internal switching mode */
4863 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4864 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
4865 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4866
4867 break;
4868 case BNX2X_RX_MODE_ALLMULTI:
4869 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4870 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4871 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4872
4873 /* internal switching mode */
4874 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4875 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4876 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4877
4878 break;
4879 case BNX2X_RX_MODE_PROMISC:
4880 /* According to deffinition of SI mode, iface in promisc mode
4881 * should receive matched and unmatched (in resolution of port)
4882 * unicast packets.
4883 */
4884 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
4885 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4886 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4887 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4888
4889 /* internal switching mode */
4890 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4891 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4892
4893 if (IS_MF_SI(bp))
4894 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
4895 else
4896 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4897
4898 break;
4899 default:
4900 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
4901 return;
4902 }
4903
4904 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
4905 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
4906 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
4907 }
4908
4909 __set_bit(RAMROD_RX, &ramrod_flags);
4910 __set_bit(RAMROD_TX, &ramrod_flags);
4911
4912 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
4913 tx_accept_flags, ramrod_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004914}
4915
Eilon Greenstein471de712008-08-13 15:49:35 -07004916static void bnx2x_init_internal_common(struct bnx2x *bp)
4917{
4918 int i;
4919
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004920 if (IS_MF_SI(bp))
4921 /*
4922 * In switch independent mode, the TSTORM needs to accept
4923 * packets that failed classification, since approximate match
4924 * mac addresses aren't written to NIG LLH
4925 */
4926 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4927 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004928 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
4929 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4930 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004931
Eilon Greenstein471de712008-08-13 15:49:35 -07004932 /* Zero this manually as its initialization is
4933 currently missing in the initTool */
4934 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4935 REG_WR(bp, BAR_USTRORM_INTMEM +
4936 USTORM_AGG_DATA_OFFSET + i * 4, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004937 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004938 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
4939 CHIP_INT_MODE_IS_BC(bp) ?
4940 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
4941 }
Eilon Greenstein471de712008-08-13 15:49:35 -07004942}
4943
Eilon Greenstein471de712008-08-13 15:49:35 -07004944static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
4945{
4946 switch (load_code) {
4947 case FW_MSG_CODE_DRV_LOAD_COMMON:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004948 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
Eilon Greenstein471de712008-08-13 15:49:35 -07004949 bnx2x_init_internal_common(bp);
4950 /* no break */
4951
4952 case FW_MSG_CODE_DRV_LOAD_PORT:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004953 /* nothing to do */
Eilon Greenstein471de712008-08-13 15:49:35 -07004954 /* no break */
4955
4956 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004957 /* internal memory per function is
4958 initialized inside bnx2x_pf_init */
Eilon Greenstein471de712008-08-13 15:49:35 -07004959 break;
4960
4961 default:
4962 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
4963 break;
4964 }
4965}
4966
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004967static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
4968{
4969 return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE;
4970}
4971
4972static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
4973{
4974 return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE;
4975}
4976
4977static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
4978{
4979 if (CHIP_IS_E1x(fp->bp))
4980 return BP_L_ID(fp->bp) + fp->index;
4981 else /* We want Client ID to be the same as IGU SB ID for 57712 */
4982 return bnx2x_fp_igu_sb_id(fp);
4983}
4984
4985static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004986{
4987 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004988 unsigned long q_type = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004989
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00004990 fp->cid = fp_idx;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004991 fp->cl_id = bnx2x_fp_cl_id(fp);
4992 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
4993 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004994 /* qZone id equals to FW (per path) client id */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004995 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
4996
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004997 /* init shortcut */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004998 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004999 /* Setup SB indicies */
5000 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5001 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
5002
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005003 /* Configure Queue State object */
5004 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5005 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5006 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp),
5007 bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata),
5008 q_type);
5009
5010 /**
5011 * Configure classification DBs: Always enable Tx switching
5012 */
5013 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5014
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005015 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
5016 "cl_id %d fw_sb %d igu_sb %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005017 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005018 fp->igu_sb_id);
5019 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5020 fp->fw_sb_id, fp->igu_sb_id);
5021
5022 bnx2x_update_fpsb_idx(fp);
5023}
5024
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005025void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005026{
5027 int i;
5028
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005029 for_each_eth_queue(bp, i)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005030 bnx2x_init_fp(bp, i);
Michael Chan37b091b2009-10-10 13:46:55 +00005031#ifdef BCM_CNIC
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005032 if (!NO_FCOE(bp))
5033 bnx2x_init_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005034
5035 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5036 BNX2X_VF_ID_INVALID, false,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005037 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005038
Michael Chan37b091b2009-10-10 13:46:55 +00005039#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005040
Yaniv Rosner020c7e32011-05-31 21:28:43 +00005041 /* Initialize MOD_ABS interrupts */
5042 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5043 bp->common.shmem_base, bp->common.shmem2_base,
5044 BP_PORT(bp));
Eilon Greenstein16119782009-03-02 07:59:27 +00005045 /* ensure status block indices were read */
5046 rmb();
5047
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005048 bnx2x_init_def_sb(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005049 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005050 bnx2x_init_rx_rings(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005051 bnx2x_init_tx_rings(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005052 bnx2x_init_sp_ring(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005053 bnx2x_init_eq_ring(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07005054 bnx2x_init_internal(bp, load_code);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005055 bnx2x_pf_init(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005056 bnx2x_stats_init(bp);
5057
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005058 /* flush all before enabling interrupts */
5059 mb();
5060 mmiowb();
5061
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08005062 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00005063
5064 /* Check for SPIO5 */
5065 bnx2x_attn_int_deasserted0(bp,
5066 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5067 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005068}
5069
5070/* end of nic init */
5071
5072/*
5073 * gzip service functions
5074 */
5075
5076static int bnx2x_gunzip_init(struct bnx2x *bp)
5077{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005078 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5079 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005080 if (bp->gunzip_buf == NULL)
5081 goto gunzip_nomem1;
5082
5083 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5084 if (bp->strm == NULL)
5085 goto gunzip_nomem2;
5086
5087 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5088 GFP_KERNEL);
5089 if (bp->strm->workspace == NULL)
5090 goto gunzip_nomem3;
5091
5092 return 0;
5093
5094gunzip_nomem3:
5095 kfree(bp->strm);
5096 bp->strm = NULL;
5097
5098gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005099 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5100 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005101 bp->gunzip_buf = NULL;
5102
5103gunzip_nomem1:
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005104 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
5105 " un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005106 return -ENOMEM;
5107}
5108
5109static void bnx2x_gunzip_end(struct bnx2x *bp)
5110{
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00005111 if (bp->strm) {
5112 kfree(bp->strm->workspace);
5113 kfree(bp->strm);
5114 bp->strm = NULL;
5115 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005116
5117 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005118 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5119 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005120 bp->gunzip_buf = NULL;
5121 }
5122}
5123
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005124static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005125{
5126 int n, rc;
5127
5128 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005129 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5130 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005131 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005132 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005133
5134 n = 10;
5135
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005136#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005137
5138 if (zbuf[3] & FNAME)
5139 while ((zbuf[n++] != 0) && (n < len));
5140
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005141 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005142 bp->strm->avail_in = len - n;
5143 bp->strm->next_out = bp->gunzip_buf;
5144 bp->strm->avail_out = FW_BUF_SIZE;
5145
5146 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5147 if (rc != Z_OK)
5148 return rc;
5149
5150 rc = zlib_inflate(bp->strm, Z_FINISH);
5151 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00005152 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5153 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005154
5155 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5156 if (bp->gunzip_outlen & 0x3)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005157 netdev_err(bp->dev, "Firmware decompression error:"
5158 " gunzip_outlen (%d) not aligned\n",
5159 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005160 bp->gunzip_outlen >>= 2;
5161
5162 zlib_inflateEnd(bp->strm);
5163
5164 if (rc == Z_STREAM_END)
5165 return 0;
5166
5167 return rc;
5168}
5169
5170/* nic load/unload */
5171
5172/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005173 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005174 */
5175
5176/* send a NIG loopback debug packet */
5177static void bnx2x_lb_pckt(struct bnx2x *bp)
5178{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005179 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005180
5181 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005182 wb_write[0] = 0x55555555;
5183 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005184 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005185 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005186
5187 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005188 wb_write[0] = 0x09000000;
5189 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005190 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005191 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005192}
5193
5194/* some of the internal memories
5195 * are not directly readable from the driver
5196 * to test them we send debug packets
5197 */
5198static int bnx2x_int_mem_test(struct bnx2x *bp)
5199{
5200 int factor;
5201 int count, i;
5202 u32 val = 0;
5203
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005204 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005205 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005206 else if (CHIP_REV_IS_EMUL(bp))
5207 factor = 200;
5208 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005209 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005210
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005211 /* Disable inputs of parser neighbor blocks */
5212 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5213 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5214 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005215 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005216
5217 /* Write 0 to parser credits for CFC search request */
5218 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5219
5220 /* send Ethernet packet */
5221 bnx2x_lb_pckt(bp);
5222
5223 /* TODO do i reset NIG statistic? */
5224 /* Wait until NIG register shows 1 packet of size 0x10 */
5225 count = 1000 * factor;
5226 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005227
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005228 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5229 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005230 if (val == 0x10)
5231 break;
5232
5233 msleep(10);
5234 count--;
5235 }
5236 if (val != 0x10) {
5237 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5238 return -1;
5239 }
5240
5241 /* Wait until PRS register shows 1 packet */
5242 count = 1000 * factor;
5243 while (count) {
5244 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005245 if (val == 1)
5246 break;
5247
5248 msleep(10);
5249 count--;
5250 }
5251 if (val != 0x1) {
5252 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5253 return -2;
5254 }
5255
5256 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005257 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005258 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005259 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005260 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005261 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5262 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005263
5264 DP(NETIF_MSG_HW, "part2\n");
5265
5266 /* Disable inputs of parser neighbor blocks */
5267 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5268 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5269 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005270 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005271
5272 /* Write 0 to parser credits for CFC search request */
5273 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5274
5275 /* send 10 Ethernet packets */
5276 for (i = 0; i < 10; i++)
5277 bnx2x_lb_pckt(bp);
5278
5279 /* Wait until NIG register shows 10 + 1
5280 packets of size 11*0x10 = 0xb0 */
5281 count = 1000 * factor;
5282 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005283
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005284 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5285 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005286 if (val == 0xb0)
5287 break;
5288
5289 msleep(10);
5290 count--;
5291 }
5292 if (val != 0xb0) {
5293 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5294 return -3;
5295 }
5296
5297 /* Wait until PRS register shows 2 packets */
5298 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5299 if (val != 2)
5300 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5301
5302 /* Write 1 to parser credits for CFC search request */
5303 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5304
5305 /* Wait until PRS register shows 3 packets */
5306 msleep(10 * factor);
5307 /* Wait until NIG register shows 1 packet of size 0x10 */
5308 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5309 if (val != 3)
5310 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5311
5312 /* clear NIG EOP FIFO */
5313 for (i = 0; i < 11; i++)
5314 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5315 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5316 if (val != 1) {
5317 BNX2X_ERR("clear of NIG failed\n");
5318 return -4;
5319 }
5320
5321 /* Reset and init BRB, PRS, NIG */
5322 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5323 msleep(50);
5324 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5325 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005326 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5327 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00005328#ifndef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005329 /* set NIC mode */
5330 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5331#endif
5332
5333 /* Enable inputs of parser neighbor blocks */
5334 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5335 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5336 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005337 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005338
5339 DP(NETIF_MSG_HW, "done\n");
5340
5341 return 0; /* OK */
5342}
5343
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005344static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005345{
5346 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005347 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005348 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5349 else
5350 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005351 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5352 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005353 /*
5354 * mask read length error interrupts in brb for parser
5355 * (parsing unit and 'checksum and crc' unit)
5356 * these errors are legal (PU reads fixed length and CAC can cause
5357 * read length error on truncated packets)
5358 */
5359 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005360 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5361 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5362 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5363 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5364 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005365/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5366/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005367 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5368 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5369 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005370/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5371/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005372 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5373 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5374 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5375 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005376/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5377/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005378
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005379 if (CHIP_REV_IS_FPGA(bp))
5380 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005381 else if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005382 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5383 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5384 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5385 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5386 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5387 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005388 else
5389 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005390 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5391 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5392 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005393/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005394
5395 if (!CHIP_IS_E1x(bp))
5396 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5397 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5398
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005399 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5400 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005401/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005402 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005403}
5404
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005405static void bnx2x_reset_common(struct bnx2x *bp)
5406{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005407 u32 val = 0x1400;
5408
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005409 /* reset_common */
5410 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5411 0xd3ffff7f);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005412
5413 if (CHIP_IS_E3(bp)) {
5414 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5415 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5416 }
5417
5418 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5419}
5420
5421static void bnx2x_setup_dmae(struct bnx2x *bp)
5422{
5423 bp->dmae_ready = 0;
5424 spin_lock_init(&bp->dmae_lock);
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005425}
5426
Eilon Greenstein573f2032009-08-12 08:24:14 +00005427static void bnx2x_init_pxp(struct bnx2x *bp)
5428{
5429 u16 devctl;
5430 int r_order, w_order;
5431
5432 pci_read_config_word(bp->pdev,
5433 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5434 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5435 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5436 if (bp->mrrs == -1)
5437 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5438 else {
5439 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5440 r_order = bp->mrrs;
5441 }
5442
5443 bnx2x_init_pxp_arb(bp, r_order, w_order);
5444}
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005445
5446static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5447{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005448 int is_required;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005449 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005450 int port;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005451
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005452 if (BP_NOMCP(bp))
5453 return;
5454
5455 is_required = 0;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005456 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5457 SHARED_HW_CFG_FAN_FAILURE_MASK;
5458
5459 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5460 is_required = 1;
5461
5462 /*
5463 * The fan failure mechanism is usually related to the PHY type since
5464 * the power consumption of the board is affected by the PHY. Currently,
5465 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5466 */
5467 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5468 for (port = PORT_0; port < PORT_MAX; port++) {
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005469 is_required |=
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00005470 bnx2x_fan_failure_det_req(
5471 bp,
5472 bp->common.shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005473 bp->common.shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00005474 port);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005475 }
5476
5477 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5478
5479 if (is_required == 0)
5480 return;
5481
5482 /* Fan failure is indicated by SPIO 5 */
5483 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5484 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5485
5486 /* set to active low mode */
5487 val = REG_RD(bp, MISC_REG_SPIO_INT);
5488 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005489 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005490 REG_WR(bp, MISC_REG_SPIO_INT, val);
5491
5492 /* enable interrupt to signal the IGU */
5493 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5494 val |= (1 << MISC_REGISTERS_SPIO_5);
5495 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5496}
5497
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005498static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5499{
5500 u32 offset = 0;
5501
5502 if (CHIP_IS_E1(bp))
5503 return;
5504 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5505 return;
5506
5507 switch (BP_ABS_FUNC(bp)) {
5508 case 0:
5509 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5510 break;
5511 case 1:
5512 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5513 break;
5514 case 2:
5515 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5516 break;
5517 case 3:
5518 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5519 break;
5520 case 4:
5521 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5522 break;
5523 case 5:
5524 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5525 break;
5526 case 6:
5527 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5528 break;
5529 case 7:
5530 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5531 break;
5532 default:
5533 return;
5534 }
5535
5536 REG_WR(bp, offset, pretend_func_num);
5537 REG_RD(bp, offset);
5538 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5539}
5540
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00005541void bnx2x_pf_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005542{
5543 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5544 val &= ~IGU_PF_CONF_FUNC_EN;
5545
5546 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5547 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5548 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5549}
5550
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005551static inline void bnx2x__common_init_phy(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005552{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005553 u32 shmem_base[2], shmem2_base[2];
5554 shmem_base[0] = bp->common.shmem_base;
5555 shmem2_base[0] = bp->common.shmem2_base;
5556 if (!CHIP_IS_E1x(bp)) {
5557 shmem_base[1] =
5558 SHMEM2_RD(bp, other_shmem_base_addr);
5559 shmem2_base[1] =
5560 SHMEM2_RD(bp, other_shmem2_base_addr);
5561 }
5562 bnx2x_acquire_phy_lock(bp);
5563 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5564 bp->common.chip_id);
5565 bnx2x_release_phy_lock(bp);
5566}
5567
5568/**
5569 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5570 *
5571 * @bp: driver handle
5572 */
5573static int bnx2x_init_hw_common(struct bnx2x *bp)
5574{
5575 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005576
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005577 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005578
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005579 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005580 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005581
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005582 val = 0xfffc;
5583 if (CHIP_IS_E3(bp)) {
5584 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5585 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5586 }
5587 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005588
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005589 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5590
5591 if (!CHIP_IS_E1x(bp)) {
5592 u8 abs_func_id;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005593
5594 /**
5595 * 4-port mode or 2-port mode we need to turn of master-enable
5596 * for everyone, after that, turn it back on for self.
5597 * so, we disregard multi-function or not, and always disable
5598 * for all functions on the given path, this means 0,2,4,6 for
5599 * path 0 and 1,3,5,7 for path 1
5600 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005601 for (abs_func_id = BP_PATH(bp);
5602 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5603 if (abs_func_id == BP_ABS_FUNC(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005604 REG_WR(bp,
5605 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5606 1);
5607 continue;
5608 }
5609
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005610 bnx2x_pretend_func(bp, abs_func_id);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005611 /* clear pf enable */
5612 bnx2x_pf_disable(bp);
5613 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5614 }
5615 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005616
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005617 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005618 if (CHIP_IS_E1(bp)) {
5619 /* enable HW interrupt from PXP on USDM overflow
5620 bit 16 on INT_MASK_0 */
5621 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005622 }
5623
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005624 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005625 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005626
5627#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005628 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5629 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5630 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5631 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5632 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005633 /* make sure this value is 0 */
5634 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005635
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005636/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5637 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5638 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5639 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5640 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005641#endif
5642
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005643 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5644
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005645 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5646 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005647
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005648 /* let the HW do it's magic ... */
5649 msleep(100);
5650 /* finish PXP init */
5651 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5652 if (val != 1) {
5653 BNX2X_ERR("PXP2 CFG failed\n");
5654 return -EBUSY;
5655 }
5656 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5657 if (val != 1) {
5658 BNX2X_ERR("PXP2 RD_INIT failed\n");
5659 return -EBUSY;
5660 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005661
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005662 /* Timers bug workaround E2 only. We need to set the entire ILT to
5663 * have entries with value "0" and valid bit on.
5664 * This needs to be done by the first PF that is loaded in a path
5665 * (i.e. common phase)
5666 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005667 if (!CHIP_IS_E1x(bp)) {
5668/* In E2 there is a bug in the timers block that can cause function 6 / 7
5669 * (i.e. vnic3) to start even if it is marked as "scan-off".
5670 * This occurs when a different function (func2,3) is being marked
5671 * as "scan-off". Real-life scenario for example: if a driver is being
5672 * load-unloaded while func6,7 are down. This will cause the timer to access
5673 * the ilt, translate to a logical address and send a request to read/write.
5674 * Since the ilt for the function that is down is not valid, this will cause
5675 * a translation error which is unrecoverable.
5676 * The Workaround is intended to make sure that when this happens nothing fatal
5677 * will occur. The workaround:
5678 * 1. First PF driver which loads on a path will:
5679 * a. After taking the chip out of reset, by using pretend,
5680 * it will write "0" to the following registers of
5681 * the other vnics.
5682 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5683 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
5684 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
5685 * And for itself it will write '1' to
5686 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
5687 * dmae-operations (writing to pram for example.)
5688 * note: can be done for only function 6,7 but cleaner this
5689 * way.
5690 * b. Write zero+valid to the entire ILT.
5691 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
5692 * VNIC3 (of that port). The range allocated will be the
5693 * entire ILT. This is needed to prevent ILT range error.
5694 * 2. Any PF driver load flow:
5695 * a. ILT update with the physical addresses of the allocated
5696 * logical pages.
5697 * b. Wait 20msec. - note that this timeout is needed to make
5698 * sure there are no requests in one of the PXP internal
5699 * queues with "old" ILT addresses.
5700 * c. PF enable in the PGLC.
5701 * d. Clear the was_error of the PF in the PGLC. (could have
5702 * occured while driver was down)
5703 * e. PF enable in the CFC (WEAK + STRONG)
5704 * f. Timers scan enable
5705 * 3. PF driver unload flow:
5706 * a. Clear the Timers scan_en.
5707 * b. Polling for scan_on=0 for that PF.
5708 * c. Clear the PF enable bit in the PXP.
5709 * d. Clear the PF enable in the CFC (WEAK + STRONG)
5710 * e. Write zero+valid to all ILT entries (The valid bit must
5711 * stay set)
5712 * f. If this is VNIC 3 of a port then also init
5713 * first_timers_ilt_entry to zero and last_timers_ilt_entry
5714 * to the last enrty in the ILT.
5715 *
5716 * Notes:
5717 * Currently the PF error in the PGLC is non recoverable.
5718 * In the future the there will be a recovery routine for this error.
5719 * Currently attention is masked.
5720 * Having an MCP lock on the load/unload process does not guarantee that
5721 * there is no Timer disable during Func6/7 enable. This is because the
5722 * Timers scan is currently being cleared by the MCP on FLR.
5723 * Step 2.d can be done only for PF6/7 and the driver can also check if
5724 * there is error before clearing it. But the flow above is simpler and
5725 * more general.
5726 * All ILT entries are written by zero+valid and not just PF6/7
5727 * ILT entries since in the future the ILT entries allocation for
5728 * PF-s might be dynamic.
5729 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005730 struct ilt_client_info ilt_cli;
5731 struct bnx2x_ilt ilt;
5732 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5733 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5734
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04005735 /* initialize dummy TM client */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005736 ilt_cli.start = 0;
5737 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5738 ilt_cli.client_num = ILT_CLIENT_TM;
5739
5740 /* Step 1: set zeroes to all ilt page entries with valid bit on
5741 * Step 2: set the timers first/last ilt entry to point
5742 * to the entire range to prevent ILT range error for 3rd/4th
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005743 * vnic (this code assumes existance of the vnic)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005744 *
5745 * both steps performed by call to bnx2x_ilt_client_init_op()
5746 * with dummy TM client
5747 *
5748 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
5749 * and his brother are split registers
5750 */
5751 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
5752 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
5753 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5754
5755 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
5756 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
5757 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
5758 }
5759
5760
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005761 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5762 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005763
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005764 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005765 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
5766 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005767 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005768
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005769 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005770
5771 /* let the HW do it's magic ... */
5772 do {
5773 msleep(200);
5774 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
5775 } while (factor-- && (val != 1));
5776
5777 if (val != 1) {
5778 BNX2X_ERR("ATC_INIT failed\n");
5779 return -EBUSY;
5780 }
5781 }
5782
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005783 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005784
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005785 /* clean the DMAE memory */
5786 bp->dmae_ready = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005787 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005788
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005789 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
5790
5791 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
5792
5793 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
5794
5795 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005796
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005797 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5798 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5799 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5800 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5801
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005802 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00005803
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005804
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005805 /* QM queues pointers table */
5806 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
Michael Chan37b091b2009-10-10 13:46:55 +00005807
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005808 /* soft reset pulse */
5809 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5810 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005811
Michael Chan37b091b2009-10-10 13:46:55 +00005812#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005813 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005814#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005815
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005816 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005817 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005818 if (!CHIP_REV_IS_SLOW(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005819 /* enable hw interrupt from doorbell Q */
5820 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005821
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005822 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005823
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005824 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005825 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005826
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005827 if (!CHIP_IS_E1(bp))
5828 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
5829
5830 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
5831 /* Bit-map indicating which L2 hdrs may appear
5832 * after the basic Ethernet header
5833 */
5834 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
5835 bp->path_has_ovlan ? 7 : 6);
5836
5837 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
5838 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
5839 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
5840 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
5841
5842 if (!CHIP_IS_E1x(bp)) {
5843 /* reset VFC memories */
5844 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5845 VFC_MEMORIES_RST_REG_CAM_RST |
5846 VFC_MEMORIES_RST_REG_RAM_RST);
5847 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5848 VFC_MEMORIES_RST_REG_CAM_RST |
5849 VFC_MEMORIES_RST_REG_RAM_RST);
5850
5851 msleep(20);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005852 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005853
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005854 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
5855 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
5856 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
5857 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005858
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005859 /* sync semi rtc */
5860 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5861 0x80000000);
5862 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5863 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005864
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005865 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
5866 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
5867 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005868
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005869 if (!CHIP_IS_E1x(bp))
5870 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
5871 bp->path_has_ovlan ? 7 : 6);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005872
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005873 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005874
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005875 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
5876
Michael Chan37b091b2009-10-10 13:46:55 +00005877#ifdef BCM_CNIC
5878 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
5879 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
5880 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
5881 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
5882 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
5883 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
5884 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
5885 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
5886 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
5887 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
5888#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005889 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005890
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005891 if (sizeof(union cdu_context) != 1024)
5892 /* we currently assume that a context is 1024 bytes */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005893 dev_alert(&bp->pdev->dev, "please adjust the size "
5894 "of cdu_context(%ld)\n",
Joe Perches7995c642010-02-17 15:01:52 +00005895 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005896
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005897 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005898 val = (4 << 24) + (0 << 12) + 1024;
5899 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005900
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005901 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005902 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005903 /* enable context validation interrupt from CFC */
5904 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5905
5906 /* set the thresholds to prevent CFC/CDU race */
5907 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005908
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005909 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005910
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005911 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005912 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
5913
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005914 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
5915 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005916
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005917 /* Reset PCIE errors for debug */
5918 REG_WR(bp, 0x2814, 0xffffffff);
5919 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005920
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005921 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005922 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
5923 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
5924 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
5925 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
5926 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
5927 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
5928 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
5929 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
5930 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
5931 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
5932 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
5933 }
5934
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005935 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005936 if (!CHIP_IS_E1(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005937 /* in E3 this done in per-port section */
5938 if (!CHIP_IS_E3(bp))
5939 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
5940 }
5941 if (CHIP_IS_E1H(bp))
5942 /* not applicable for E2 (and above ...) */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08005943 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005944
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005945 if (CHIP_REV_IS_SLOW(bp))
5946 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005947
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005948 /* finish CFC init */
5949 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5950 if (val != 1) {
5951 BNX2X_ERR("CFC LL_INIT failed\n");
5952 return -EBUSY;
5953 }
5954 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5955 if (val != 1) {
5956 BNX2X_ERR("CFC AC_INIT failed\n");
5957 return -EBUSY;
5958 }
5959 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5960 if (val != 1) {
5961 BNX2X_ERR("CFC CAM_INIT failed\n");
5962 return -EBUSY;
5963 }
5964 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005965
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005966 if (CHIP_IS_E1(bp)) {
5967 /* read NIG statistic
5968 to see if this is our first up since powerup */
5969 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5970 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005971
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005972 /* do internal memory self test */
5973 if ((val == 0) && bnx2x_int_mem_test(bp)) {
5974 BNX2X_ERR("internal mem self test failed\n");
5975 return -EBUSY;
5976 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005977 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005978
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005979 bnx2x_setup_fan_failure_detection(bp);
5980
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005981 /* clear PXP2 attentions */
5982 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005983
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005984 bnx2x_enable_blocks_attention(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00005985 bnx2x_enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005986
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005987 if (!BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005988 if (CHIP_IS_E1x(bp))
5989 bnx2x__common_init_phy(bp);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005990 } else
5991 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5992
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005993 return 0;
5994}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005995
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005996/**
5997 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
5998 *
5999 * @bp: driver handle
6000 */
6001static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6002{
6003 int rc = bnx2x_init_hw_common(bp);
6004
6005 if (rc)
6006 return rc;
6007
6008 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6009 if (!BP_NOMCP(bp))
6010 bnx2x__common_init_phy(bp);
6011
6012 return 0;
6013}
6014
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006015static int bnx2x_init_hw_port(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006016{
6017 int port = BP_PORT(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006018 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
Eilon Greenstein1c063282009-02-12 08:36:43 +00006019 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006020 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006021
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006022 bnx2x__link_reset(bp);
6023
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006024 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006025
6026 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006027
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006028 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6029 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6030 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
Eilon Greensteinca003922009-08-12 22:53:28 -07006031
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006032 /* Timers bug workaround: disables the pf_master bit in pglue at
6033 * common phase, we need to enable it here before any dmae access are
6034 * attempted. Therefore we manually added the enable-master to the
6035 * port phase (it also happens in the function phase)
6036 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006037 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006038 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6039
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006040 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6041 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6042 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6043 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6044
6045 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6046 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6047 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6048 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006049
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006050 /* QM cid (connection) count */
6051 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006052
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006053#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006054 bnx2x_init_block(bp, BLOCK_TM, init_phase);
Michael Chan37b091b2009-10-10 13:46:55 +00006055 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6056 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006057#endif
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006058
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006059 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Eilon Greenstein1c063282009-02-12 08:36:43 +00006060
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006061 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006062 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6063
6064 if (IS_MF(bp))
6065 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6066 else if (bp->dev->mtu > 4096) {
6067 if (bp->flags & ONE_PORT_FLAG)
6068 low = 160;
6069 else {
6070 val = bp->dev->mtu;
6071 /* (24*1024 + val*4)/256 */
6072 low = 96 + (val/64) +
6073 ((val % 64) ? 1 : 0);
6074 }
6075 } else
6076 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6077 high = low + 56; /* 14*1024/256 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006078 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6079 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6080 }
6081
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006082 if (CHIP_MODE_IS_4_PORT(bp))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006083 REG_WR(bp, (BP_PORT(bp) ?
6084 BRB1_REG_MAC_GUARANTIED_1 :
6085 BRB1_REG_MAC_GUARANTIED_0), 40);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006086
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006087
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006088 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6089 if (CHIP_IS_E3B0(bp))
6090 /* Ovlan exists only if we are in multi-function +
6091 * switch-dependent mode, in switch-independent there
6092 * is no ovlan headers
6093 */
6094 REG_WR(bp, BP_PORT(bp) ?
6095 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6096 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6097 (bp->path_has_ovlan ? 7 : 6));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006098
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006099 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6100 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6101 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6102 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6103
6104 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6105 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6106 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6107 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6108
6109 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6110 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6111
6112 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6113
6114 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006115 /* configure PBF to work without PAUSE mtu 9000 */
6116 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006117
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006118 /* update threshold */
6119 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6120 /* update init credit */
6121 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006122
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006123 /* probe changes */
6124 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6125 udelay(50);
6126 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6127 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006128
Michael Chan37b091b2009-10-10 13:46:55 +00006129#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006130 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006131#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006132 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6133 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006134
6135 if (CHIP_IS_E1(bp)) {
6136 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6137 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6138 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006139 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006140
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006141 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006142
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006143 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006144 /* init aeu_mask_attn_func_0/1:
6145 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6146 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6147 * bits 4-7 are used for "per vn group attention" */
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00006148 val = IS_MF(bp) ? 0xF7 : 0x7;
6149 /* Enable DCBX attention for all but E1 */
6150 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6151 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006152
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006153 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006154
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006155 if (!CHIP_IS_E1x(bp)) {
6156 /* Bit-map indicating which L2 hdrs may appear after the
6157 * basic Ethernet header
6158 */
6159 REG_WR(bp, BP_PORT(bp) ?
6160 NIG_REG_P1_HDRS_AFTER_BASIC :
6161 NIG_REG_P0_HDRS_AFTER_BASIC,
6162 IS_MF_SD(bp) ? 7 : 6);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006163
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006164 if (CHIP_IS_E3(bp))
6165 REG_WR(bp, BP_PORT(bp) ?
6166 NIG_REG_LLH1_MF_MODE :
6167 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6168 }
6169 if (!CHIP_IS_E3(bp))
6170 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006171
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006172 if (!CHIP_IS_E1(bp)) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006173 /* 0x2 disable mf_ov, 0x1 enable */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006174 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006175 (IS_MF_SD(bp) ? 0x1 : 0x2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006176
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006177 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006178 val = 0;
6179 switch (bp->mf_mode) {
6180 case MULTI_FUNCTION_SD:
6181 val = 1;
6182 break;
6183 case MULTI_FUNCTION_SI:
6184 val = 2;
6185 break;
6186 }
6187
6188 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6189 NIG_REG_LLH0_CLS_TYPE), val);
6190 }
Eilon Greenstein1c063282009-02-12 08:36:43 +00006191 {
6192 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6193 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6194 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6195 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006196 }
6197
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006198
6199 /* If SPIO5 is set to generate interrupts, enable it for this port */
6200 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6201 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006202 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6203 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6204 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006205 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006206 REG_WR(bp, reg_addr, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006207 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006208
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006209 return 0;
6210}
6211
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006212static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6213{
6214 int reg;
6215
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006216 if (CHIP_IS_E1(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006217 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006218 else
6219 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006220
6221 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6222}
6223
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006224static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6225{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006226 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006227}
6228
6229static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6230{
6231 u32 i, base = FUNC_ILT_BASE(func);
6232 for (i = base; i < base + ILT_PER_FUNC; i++)
6233 bnx2x_ilt_wr(bp, i, 0);
6234}
6235
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006236static int bnx2x_init_hw_func(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006237{
6238 int port = BP_PORT(bp);
6239 int func = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006240 int init_phase = PHASE_PF0 + func;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006241 struct bnx2x_ilt *ilt = BP_ILT(bp);
6242 u16 cdu_ilt_start;
Eilon Greenstein8badd272009-02-12 08:36:15 +00006243 u32 addr, val;
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00006244 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6245 int i, main_mem_width;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006246
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006247 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006248
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006249 /* FLR cleanup - hmmm */
6250 if (!CHIP_IS_E1x(bp))
6251 bnx2x_pf_flr_clnup(bp);
6252
Eilon Greenstein8badd272009-02-12 08:36:15 +00006253 /* set MSI reconfigure capability */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006254 if (bp->common.int_block == INT_BLOCK_HC) {
6255 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6256 val = REG_RD(bp, addr);
6257 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6258 REG_WR(bp, addr, val);
6259 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006260
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006261 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6262 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6263
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006264 ilt = BP_ILT(bp);
6265 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006266
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006267 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6268 ilt->lines[cdu_ilt_start + i].page =
6269 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6270 ilt->lines[cdu_ilt_start + i].page_mapping =
6271 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6272 /* cdu ilt pages are allocated manually so there's no need to
6273 set the size */
6274 }
6275 bnx2x_ilt_init_op(bp, INITOP_SET);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006276
Michael Chan37b091b2009-10-10 13:46:55 +00006277#ifdef BCM_CNIC
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006278 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
Michael Chan37b091b2009-10-10 13:46:55 +00006279
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006280 /* T1 hash bits value determines the T1 number of entries */
6281 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
Michael Chan37b091b2009-10-10 13:46:55 +00006282#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006283
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006284#ifndef BCM_CNIC
6285 /* set NIC mode */
6286 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6287#endif /* BCM_CNIC */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006288
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006289 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006290 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6291
6292 /* Turn on a single ISR mode in IGU if driver is going to use
6293 * INT#x or MSI
6294 */
6295 if (!(bp->flags & USING_MSIX_FLAG))
6296 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6297 /*
6298 * Timers workaround bug: function init part.
6299 * Need to wait 20msec after initializing ILT,
6300 * needed to make sure there are no requests in
6301 * one of the PXP internal queues with "old" ILT addresses
6302 */
6303 msleep(20);
6304 /*
6305 * Master enable - Due to WB DMAE writes performed before this
6306 * register is re-initialized as part of the regular function
6307 * init
6308 */
6309 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6310 /* Enable the function in IGU */
6311 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6312 }
6313
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006314 bp->dmae_ready = 1;
6315
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006316 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006317
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006318 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006319 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6320
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006321 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6322 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6323 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6324 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6325 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6326 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6327 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6328 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6329 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6330 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6331 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6332 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6333 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006334
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006335 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006336 REG_WR(bp, QM_REG_PF_EN, 1);
6337
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006338 if (!CHIP_IS_E1x(bp)) {
6339 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6340 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6341 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6342 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6343 }
6344 bnx2x_init_block(bp, BLOCK_QM, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006345
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006346 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6347 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6348 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6349 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6350 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6351 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6352 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6353 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6354 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6355 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6356 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6357 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006358 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6359
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006360 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006361
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006362 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006363
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006364 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006365 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6366
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006367 if (IS_MF(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006368 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006369 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006370 }
6371
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006372 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006373
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006374 /* HC init per function */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006375 if (bp->common.int_block == INT_BLOCK_HC) {
6376 if (CHIP_IS_E1H(bp)) {
6377 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6378
6379 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6380 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6381 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006382 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006383
6384 } else {
6385 int num_segs, sb_idx, prod_offset;
6386
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006387 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6388
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006389 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006390 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6391 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6392 }
6393
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006394 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006395
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006396 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006397 int dsb_idx = 0;
6398 /**
6399 * Producer memory:
6400 * E2 mode: address 0-135 match to the mapping memory;
6401 * 136 - PF0 default prod; 137 - PF1 default prod;
6402 * 138 - PF2 default prod; 139 - PF3 default prod;
6403 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6404 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6405 * 144-147 reserved.
6406 *
6407 * E1.5 mode - In backward compatible mode;
6408 * for non default SB; each even line in the memory
6409 * holds the U producer and each odd line hold
6410 * the C producer. The first 128 producers are for
6411 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6412 * producers are for the DSB for each PF.
6413 * Each PF has five segments: (the order inside each
6414 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6415 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6416 * 144-147 attn prods;
6417 */
6418 /* non-default-status-blocks */
6419 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6420 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6421 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6422 prod_offset = (bp->igu_base_sb + sb_idx) *
6423 num_segs;
6424
6425 for (i = 0; i < num_segs; i++) {
6426 addr = IGU_REG_PROD_CONS_MEMORY +
6427 (prod_offset + i) * 4;
6428 REG_WR(bp, addr, 0);
6429 }
6430 /* send consumer update with value 0 */
6431 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6432 USTORM_ID, 0, IGU_INT_NOP, 1);
6433 bnx2x_igu_clear_sb(bp,
6434 bp->igu_base_sb + sb_idx);
6435 }
6436
6437 /* default-status-blocks */
6438 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6439 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6440
6441 if (CHIP_MODE_IS_4_PORT(bp))
6442 dsb_idx = BP_FUNC(bp);
6443 else
6444 dsb_idx = BP_E1HVN(bp);
6445
6446 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6447 IGU_BC_BASE_DSB_PROD + dsb_idx :
6448 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6449
6450 for (i = 0; i < (num_segs * E1HVN_MAX);
6451 i += E1HVN_MAX) {
6452 addr = IGU_REG_PROD_CONS_MEMORY +
6453 (prod_offset + i)*4;
6454 REG_WR(bp, addr, 0);
6455 }
6456 /* send consumer update with 0 */
6457 if (CHIP_INT_MODE_IS_BC(bp)) {
6458 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6459 USTORM_ID, 0, IGU_INT_NOP, 1);
6460 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6461 CSTORM_ID, 0, IGU_INT_NOP, 1);
6462 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6463 XSTORM_ID, 0, IGU_INT_NOP, 1);
6464 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6465 TSTORM_ID, 0, IGU_INT_NOP, 1);
6466 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6467 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6468 } else {
6469 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6470 USTORM_ID, 0, IGU_INT_NOP, 1);
6471 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6472 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6473 }
6474 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6475
6476 /* !!! these should become driver const once
6477 rf-tool supports split-68 const */
6478 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6479 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6480 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6481 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6482 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6483 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6484 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006485 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006486
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006487 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006488 REG_WR(bp, 0x2114, 0xffffffff);
6489 REG_WR(bp, 0x2120, 0xffffffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006490
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00006491 if (CHIP_IS_E1x(bp)) {
6492 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6493 main_mem_base = HC_REG_MAIN_MEMORY +
6494 BP_PORT(bp) * (main_mem_size * 4);
6495 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6496 main_mem_width = 8;
6497
6498 val = REG_RD(bp, main_mem_prty_clr);
6499 if (val)
6500 DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
6501 "block during "
6502 "function init (0x%x)!\n", val);
6503
6504 /* Clear "false" parity errors in MSI-X table */
6505 for (i = main_mem_base;
6506 i < main_mem_base + main_mem_size * 4;
6507 i += main_mem_width) {
6508 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6509 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6510 i, main_mem_width / 4);
6511 }
6512 /* Clear HC parity attention */
6513 REG_RD(bp, main_mem_prty_clr);
6514 }
6515
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006516#ifdef BNX2X_STOP_ON_ERROR
6517 /* Enable STORMs SP logging */
6518 REG_WR8(bp, BAR_USTRORM_INTMEM +
6519 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6520 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6521 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6522 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6523 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6524 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6525 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6526#endif
6527
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006528 bnx2x_phy_probe(&bp->link_params);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006529
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006530 return 0;
6531}
6532
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006533
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006534void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006535{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006536 /* fastpath */
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006537 bnx2x_free_fp_mem(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006538 /* end of fastpath */
6539
6540 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006541 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006542
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006543 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6544 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6545
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006546 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006547 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006548
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006549 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6550 bp->context.size);
6551
6552 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6553
6554 BNX2X_FREE(bp->ilt->lines);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006555
Michael Chan37b091b2009-10-10 13:46:55 +00006556#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006557 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006558 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6559 sizeof(struct host_hc_status_block_e2));
6560 else
6561 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6562 sizeof(struct host_hc_status_block_e1x));
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006563
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006564 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006565#endif
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006566
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006567 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006568
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006569 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6570 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006571}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006572
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006573static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6574{
6575 int num_groups;
6576
6577 /* number of eth_queues */
6578 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
6579
6580 /* Total number of FW statistics requests =
6581 * 1 for port stats + 1 for PF stats + num_eth_queues */
6582 bp->fw_stats_num = 2 + num_queue_stats;
6583
6584
6585 /* Request is built from stats_query_header and an array of
6586 * stats_query_cmd_group each of which contains
6587 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6588 * configured in the stats_query_header.
6589 */
6590 num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
6591 (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6592
6593 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6594 num_groups * sizeof(struct stats_query_cmd_group);
6595
6596 /* Data for statistics requests + stats_conter
6597 *
6598 * stats_counter holds per-STORM counters that are incremented
6599 * when STORM has finished with the current request.
6600 */
6601 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6602 sizeof(struct per_pf_stats) +
6603 sizeof(struct per_queue_stats) * num_queue_stats +
6604 sizeof(struct stats_counter);
6605
6606 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6607 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6608
6609 /* Set shortcuts */
6610 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6611 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6612
6613 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6614 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6615
6616 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6617 bp->fw_stats_req_sz;
6618 return 0;
6619
6620alloc_mem_err:
6621 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6622 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6623 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006624}
6625
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006626
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006627int bnx2x_alloc_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006628{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006629#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006630 if (!CHIP_IS_E1x(bp))
6631 /* size = the status block + ramrod buffers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006632 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6633 sizeof(struct host_hc_status_block_e2));
6634 else
6635 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6636 sizeof(struct host_hc_status_block_e1x));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006637
6638 /* allocate searcher T2 table */
6639 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
6640#endif
6641
6642
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006643 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006644 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006645
6646 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6647 sizeof(struct bnx2x_slowpath));
6648
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006649 /* Allocated memory for FW statistics */
6650 if (bnx2x_alloc_fw_stats_mem(bp))
6651 goto alloc_mem_err;
6652
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006653 bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006654
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006655 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
6656 bp->context.size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006657
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006658 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006659
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006660 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
6661 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006662
6663 /* Slow path ring */
6664 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6665
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006666 /* EQ */
6667 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
6668 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Tom Herbertab532cf2011-02-16 10:27:02 +00006669
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006670
6671 /* fastpath */
6672 /* need to be done at the end, since it's self adjusting to amount
6673 * of memory available for RSS queues
6674 */
6675 if (bnx2x_alloc_fp_mem(bp))
6676 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006677 return 0;
6678
6679alloc_mem_err:
6680 bnx2x_free_mem(bp);
6681 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006682}
6683
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006684/*
6685 * Init service functions
6686 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006687
6688int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
6689 struct bnx2x_vlan_mac_obj *obj, bool set,
6690 int mac_type, unsigned long *ramrod_flags)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006691{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006692 int rc;
6693 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006694
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006695 memset(&ramrod_param, 0, sizeof(ramrod_param));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006696
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006697 /* Fill general parameters */
6698 ramrod_param.vlan_mac_obj = obj;
6699 ramrod_param.ramrod_flags = *ramrod_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006700
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006701 /* Fill a user request section if needed */
6702 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
6703 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006704
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006705 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006706
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006707 /* Set the command: ADD or DEL */
6708 if (set)
6709 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
6710 else
6711 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006712 }
6713
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006714 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
6715 if (rc < 0)
6716 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
6717 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006718}
6719
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006720int bnx2x_del_all_macs(struct bnx2x *bp,
6721 struct bnx2x_vlan_mac_obj *mac_obj,
6722 int mac_type, bool wait_for_comp)
Michael Chane665bfd2009-10-10 13:46:54 +00006723{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006724 int rc;
6725 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
6726
6727 /* Wait for completion of requested */
6728 if (wait_for_comp)
6729 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6730
6731 /* Set the mac type of addresses we want to clear */
6732 __set_bit(mac_type, &vlan_mac_flags);
6733
6734 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
6735 if (rc < 0)
6736 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
6737
6738 return rc;
Michael Chane665bfd2009-10-10 13:46:54 +00006739}
6740
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006741int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006742{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006743 unsigned long ramrod_flags = 0;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006744
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006745 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006746
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006747 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6748 /* Eth MAC is set on RSS leading client (fp[0]) */
6749 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
6750 BNX2X_ETH_MAC, &ramrod_flags);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006751}
6752
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006753int bnx2x_setup_leading(struct bnx2x *bp)
Michael Chane665bfd2009-10-10 13:46:54 +00006754{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006755 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006756}
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08006757
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006758/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00006759 * bnx2x_set_int_mode - configure interrupt mode
6760 *
6761 * @bp: driver handle
6762 *
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006763 * In case of MSI-X it will also try to enable MSI-X.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006764 */
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006765static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006766{
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006767 switch (int_mode) {
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006768 case INT_MODE_MSI:
6769 bnx2x_enable_msi(bp);
6770 /* falling through... */
6771 case INT_MODE_INTx:
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006772 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006773 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
Eilon Greensteinca003922009-08-12 22:53:28 -07006774 break;
Eilon Greensteinca003922009-08-12 22:53:28 -07006775 default:
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006776 /* Set number of queues according to bp->multi_mode value */
6777 bnx2x_set_num_queues(bp);
6778
6779 DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
6780 bp->num_queues);
6781
6782 /* if we can't use MSI-X we only need one fp,
6783 * so try to enable MSI-X with the requested number of fp's
6784 * and fallback to MSI or legacy INTx with one fp
6785 */
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006786 if (bnx2x_enable_msix(bp)) {
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006787 /* failed to enable MSI-X */
6788 if (bp->multi_mode)
6789 DP(NETIF_MSG_IFUP,
6790 "Multi requested but failed to "
6791 "enable MSI-X (%d), "
6792 "set number of queues to %d\n",
6793 bp->num_queues,
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006794 1 + NONE_ETH_CONTEXT_USE);
6795 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006796
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006797 /* Try to enable MSI */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006798 if (!(bp->flags & DISABLE_MSI_FLAG))
6799 bnx2x_enable_msi(bp);
6800 }
Eilon Greensteinca003922009-08-12 22:53:28 -07006801 break;
6802 }
Eilon Greensteinca003922009-08-12 22:53:28 -07006803}
6804
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00006805/* must be called prioir to any HW initializations */
6806static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
6807{
6808 return L2_ILT_LINES(bp);
6809}
6810
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006811void bnx2x_ilt_set_info(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006812{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006813 struct ilt_client_info *ilt_client;
6814 struct bnx2x_ilt *ilt = BP_ILT(bp);
6815 u16 line = 0;
6816
6817 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
6818 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
6819
6820 /* CDU */
6821 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
6822 ilt_client->client_num = ILT_CLIENT_CDU;
6823 ilt_client->page_size = CDU_ILT_PAGE_SZ;
6824 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
6825 ilt_client->start = line;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006826 line += bnx2x_cid_ilt_lines(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006827#ifdef BCM_CNIC
6828 line += CNIC_ILT_LINES;
6829#endif
6830 ilt_client->end = line - 1;
6831
6832 DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
6833 "flags 0x%x, hw psz %d\n",
6834 ilt_client->start,
6835 ilt_client->end,
6836 ilt_client->page_size,
6837 ilt_client->flags,
6838 ilog2(ilt_client->page_size >> 12));
6839
6840 /* QM */
6841 if (QM_INIT(bp->qm_cid_count)) {
6842 ilt_client = &ilt->clients[ILT_CLIENT_QM];
6843 ilt_client->client_num = ILT_CLIENT_QM;
6844 ilt_client->page_size = QM_ILT_PAGE_SZ;
6845 ilt_client->flags = 0;
6846 ilt_client->start = line;
6847
6848 /* 4 bytes for each cid */
6849 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
6850 QM_ILT_PAGE_SZ);
6851
6852 ilt_client->end = line - 1;
6853
6854 DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
6855 "flags 0x%x, hw psz %d\n",
6856 ilt_client->start,
6857 ilt_client->end,
6858 ilt_client->page_size,
6859 ilt_client->flags,
6860 ilog2(ilt_client->page_size >> 12));
6861
6862 }
6863 /* SRC */
6864 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
6865#ifdef BCM_CNIC
6866 ilt_client->client_num = ILT_CLIENT_SRC;
6867 ilt_client->page_size = SRC_ILT_PAGE_SZ;
6868 ilt_client->flags = 0;
6869 ilt_client->start = line;
6870 line += SRC_ILT_LINES;
6871 ilt_client->end = line - 1;
6872
6873 DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
6874 "flags 0x%x, hw psz %d\n",
6875 ilt_client->start,
6876 ilt_client->end,
6877 ilt_client->page_size,
6878 ilt_client->flags,
6879 ilog2(ilt_client->page_size >> 12));
6880
6881#else
6882 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6883#endif
6884
6885 /* TM */
6886 ilt_client = &ilt->clients[ILT_CLIENT_TM];
6887#ifdef BCM_CNIC
6888 ilt_client->client_num = ILT_CLIENT_TM;
6889 ilt_client->page_size = TM_ILT_PAGE_SZ;
6890 ilt_client->flags = 0;
6891 ilt_client->start = line;
6892 line += TM_ILT_LINES;
6893 ilt_client->end = line - 1;
6894
6895 DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
6896 "flags 0x%x, hw psz %d\n",
6897 ilt_client->start,
6898 ilt_client->end,
6899 ilt_client->page_size,
6900 ilt_client->flags,
6901 ilog2(ilt_client->page_size >> 12));
6902
6903#else
6904 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6905#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006906 BUG_ON(line > ILT_MAX_LINES);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006907}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006908
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006909/**
6910 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
6911 *
6912 * @bp: driver handle
6913 * @fp: pointer to fastpath
6914 * @init_params: pointer to parameters structure
6915 *
6916 * parameters configured:
6917 * - HC configuration
6918 * - Queue's CDU context
6919 */
6920static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
6921 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006922{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006923 /* FCoE Queue uses Default SB, thus has no HC capabilities */
6924 if (!IS_FCOE_FP(fp)) {
6925 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
6926 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
6927
6928 /* If HC is supporterd, enable host coalescing in the transition
6929 * to INIT state.
6930 */
6931 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
6932 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
6933
6934 /* HC rate */
6935 init_params->rx.hc_rate = bp->rx_ticks ?
6936 (1000000 / bp->rx_ticks) : 0;
6937 init_params->tx.hc_rate = bp->tx_ticks ?
6938 (1000000 / bp->tx_ticks) : 0;
6939
6940 /* FW SB ID */
6941 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
6942 fp->fw_sb_id;
6943
6944 /*
6945 * CQ index among the SB indices: FCoE clients uses the default
6946 * SB, therefore it's different.
6947 */
6948 init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
6949 init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
6950 }
6951
6952 init_params->cxt = &bp->context.vcxt[fp->cid].eth;
6953}
6954
6955/**
6956 * bnx2x_setup_queue - setup queue
6957 *
6958 * @bp: driver handle
6959 * @fp: pointer to fastpath
6960 * @leading: is leading
6961 *
6962 * This function performs 2 steps in a Queue state machine
6963 * actually: 1) RESET->INIT 2) INIT->SETUP
6964 */
6965
6966int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6967 bool leading)
6968{
6969 struct bnx2x_queue_state_params q_params = {0};
6970 struct bnx2x_queue_setup_params *setup_params =
6971 &q_params.params.setup;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006972 int rc;
6973
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006974 /* reset IGU state skip FCoE L2 queue */
6975 if (!IS_FCOE_FP(fp))
6976 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006977 IGU_INT_ENABLE, 0);
6978
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006979 q_params.q_obj = &fp->q_obj;
6980 /* We want to wait for completion in this context */
6981 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006982
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006983 /* Prepare the INIT parameters */
6984 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006985
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006986 /* Set the command */
6987 q_params.cmd = BNX2X_Q_CMD_INIT;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006988
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006989 /* Change the state to INIT */
6990 rc = bnx2x_queue_state_change(bp, &q_params);
6991 if (rc) {
6992 BNX2X_ERR("Queue INIT failed\n");
6993 return rc;
6994 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006995
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006996 /* Now move the Queue to the SETUP state... */
6997 memset(setup_params, 0, sizeof(*setup_params));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006998
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006999 /* Set QUEUE flags */
7000 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007001
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007002 /* Set general SETUP parameters */
7003 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params);
7004
7005 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause,
7006 &setup_params->rxq_params);
7007
7008 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params);
7009
7010 /* Set the command */
7011 q_params.cmd = BNX2X_Q_CMD_SETUP;
7012
7013 /* Change the state to SETUP */
7014 rc = bnx2x_queue_state_change(bp, &q_params);
7015 if (rc)
7016 BNX2X_ERR("Queue SETUP failed\n");
7017
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007018 return rc;
7019}
7020
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007021static int bnx2x_stop_queue(struct bnx2x *bp, int index)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007022{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007023 struct bnx2x_fastpath *fp = &bp->fp[index];
7024 struct bnx2x_queue_state_params q_params = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007025 int rc;
7026
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007027 q_params.q_obj = &fp->q_obj;
7028 /* We want to wait for completion in this context */
7029 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007030
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007031 /* halt the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007032 q_params.cmd = BNX2X_Q_CMD_HALT;
7033 rc = bnx2x_queue_state_change(bp, &q_params);
7034 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007035 return rc;
7036
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007037 /* terminate the connection */
7038 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7039 rc = bnx2x_queue_state_change(bp, &q_params);
7040 if (rc)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007041 return rc;
7042
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007043 /* delete cfc entry */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007044 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7045 return bnx2x_queue_state_change(bp, &q_params);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007046}
7047
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007048
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007049static void bnx2x_reset_func(struct bnx2x *bp)
7050{
7051 int port = BP_PORT(bp);
7052 int func = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007053 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007054
7055 /* Disable the function in the FW */
7056 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7057 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7058 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7059 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7060
7061 /* FP SBs */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007062 for_each_eth_queue(bp, i) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007063 struct bnx2x_fastpath *fp = &bp->fp[i];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007064 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7065 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7066 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007067 }
7068
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007069#ifdef BCM_CNIC
7070 /* CNIC SB */
7071 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7072 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7073 SB_DISABLED);
7074#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007075 /* SP SB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007076 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7077 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7078 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007079
7080 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7081 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7082 0);
Eliezer Tamir49d66772008-02-28 11:53:13 -08007083
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007084 /* Configure IGU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007085 if (bp->common.int_block == INT_BLOCK_HC) {
7086 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7087 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7088 } else {
7089 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7090 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7091 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007092
Michael Chan37b091b2009-10-10 13:46:55 +00007093#ifdef BCM_CNIC
7094 /* Disable Timer scan */
7095 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7096 /*
7097 * Wait for at least 10ms and up to 2 second for the timers scan to
7098 * complete
7099 */
7100 for (i = 0; i < 200; i++) {
7101 msleep(10);
7102 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7103 break;
7104 }
7105#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007106 /* Clear ILT */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007107 bnx2x_clear_func_ilt(bp, func);
7108
7109 /* Timers workaround bug for E2: if this is vnic-3,
7110 * we need to set the entire ilt range for this timers.
7111 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007112 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007113 struct ilt_client_info ilt_cli;
7114 /* use dummy TM client */
7115 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7116 ilt_cli.start = 0;
7117 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7118 ilt_cli.client_num = ILT_CLIENT_TM;
7119
7120 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7121 }
7122
7123 /* this assumes that reset_port() called before reset_func()*/
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007124 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007125 bnx2x_pf_disable(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007126
7127 bp->dmae_ready = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007128}
7129
7130static void bnx2x_reset_port(struct bnx2x *bp)
7131{
7132 int port = BP_PORT(bp);
7133 u32 val;
7134
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007135 /* Reset physical Link */
7136 bnx2x__link_reset(bp);
7137
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007138 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7139
7140 /* Do not rcv packets to BRB */
7141 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7142 /* Do not direct rcv packets that are not for MCP to the BRB */
7143 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7144 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7145
7146 /* Configure AEU */
7147 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7148
7149 msleep(100);
7150 /* Check for BRB port occupancy */
7151 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7152 if (val)
7153 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07007154 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007155
7156 /* TODO: Close Doorbell port? */
7157}
7158
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007159static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007160{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007161 struct bnx2x_func_state_params func_params = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007162
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007163 /* Prepare parameters for function state transitions */
7164 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007165
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007166 func_params.f_obj = &bp->func_obj;
7167 func_params.cmd = BNX2X_F_CMD_HW_RESET;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007168
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007169 func_params.params.hw_init.load_phase = load_code;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007170
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007171 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007172}
7173
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007174static inline int bnx2x_func_stop(struct bnx2x *bp)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007175{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007176 struct bnx2x_func_state_params func_params = {0};
7177 int rc;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007178
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007179 /* Prepare parameters for function state transitions */
7180 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7181 func_params.f_obj = &bp->func_obj;
7182 func_params.cmd = BNX2X_F_CMD_STOP;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007183
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007184 /*
7185 * Try to stop the function the 'good way'. If fails (in case
7186 * of a parity error during bnx2x_chip_cleanup()) and we are
7187 * not in a debug mode, perform a state transaction in order to
7188 * enable further HW_RESET transaction.
7189 */
7190 rc = bnx2x_func_state_change(bp, &func_params);
7191 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007192#ifdef BNX2X_STOP_ON_ERROR
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007193 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007194#else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007195 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
7196 "transaction\n");
7197 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7198 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007199#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07007200 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007201
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007202 return 0;
7203}
Yitchak Gertner65abd742008-08-25 15:26:24 -07007204
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007205/**
7206 * bnx2x_send_unload_req - request unload mode from the MCP.
7207 *
7208 * @bp: driver handle
7209 * @unload_mode: requested function's unload mode
7210 *
7211 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7212 */
7213u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7214{
7215 u32 reset_code = 0;
7216 int port = BP_PORT(bp);
7217
7218 /* Select the UNLOAD request mode */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007219 if (unload_mode == UNLOAD_NORMAL)
7220 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007221
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00007222 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007223 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007224
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00007225 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007226 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007227 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007228 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007229 /* The mac address is written to entries 1-4 to
7230 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007231 u8 entry = (BP_E1HVN(bp) + 1)*8;
7232
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007233 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007234 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007235
7236 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7237 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007238 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007239
7240 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007241
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007242 } else
7243 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7244
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007245 /* Send the request to the MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007246 if (!BP_NOMCP(bp))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007247 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007248 else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007249 int path = BP_PATH(bp);
7250
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007251 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007252 "%d, %d, %d\n",
7253 path, load_count[path][0], load_count[path][1],
7254 load_count[path][2]);
7255 load_count[path][0]--;
7256 load_count[path][1 + port]--;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007257 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007258 "%d, %d, %d\n",
7259 path, load_count[path][0], load_count[path][1],
7260 load_count[path][2]);
7261 if (load_count[path][0] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007262 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007263 else if (load_count[path][1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007264 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7265 else
7266 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7267 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007268
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007269 return reset_code;
7270}
7271
7272/**
7273 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7274 *
7275 * @bp: driver handle
7276 */
7277void bnx2x_send_unload_done(struct bnx2x *bp)
7278{
7279 /* Report UNLOAD_DONE to MCP */
7280 if (!BP_NOMCP(bp))
7281 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7282}
7283
7284void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7285{
7286 int port = BP_PORT(bp);
7287 int i, rc;
7288 struct bnx2x_mcast_ramrod_params rparam = {0};
7289 u32 reset_code;
7290
7291 /* Wait until tx fastpath tasks complete */
7292 for_each_tx_queue(bp, i) {
7293 struct bnx2x_fastpath *fp = &bp->fp[i];
7294
7295 rc = bnx2x_clean_tx_queue(bp, fp);
7296#ifdef BNX2X_STOP_ON_ERROR
7297 if (rc)
7298 return;
7299#endif
7300 }
7301
7302 /* Give HW time to discard old tx messages */
7303 usleep_range(1000, 1000);
7304
7305 /* Clean all ETH MACs */
7306 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7307 if (rc < 0)
7308 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7309
7310 /* Clean up UC list */
7311 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7312 true);
7313 if (rc < 0)
7314 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
7315 "%d\n", rc);
7316
7317 /* Disable LLH */
7318 if (!CHIP_IS_E1(bp))
7319 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7320
7321 /* Set "drop all" (stop Rx).
7322 * We need to take a netif_addr_lock() here in order to prevent
7323 * a race between the completion code and this code.
7324 */
7325 netif_addr_lock_bh(bp->dev);
7326 /* Schedule the rx_mode command */
7327 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7328 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7329 else
7330 bnx2x_set_storm_rx_mode(bp);
7331
7332 /* Cleanup multicast configuration */
7333 rparam.mcast_obj = &bp->mcast_obj;
7334 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7335 if (rc < 0)
7336 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7337
7338 netif_addr_unlock_bh(bp->dev);
7339
7340
7341 /* Close multi and leading connections
7342 * Completions for ramrods are collected in a synchronous way
7343 */
7344 for_each_queue(bp, i)
7345 if (bnx2x_stop_queue(bp, i))
7346#ifdef BNX2X_STOP_ON_ERROR
7347 return;
7348#else
7349 goto unload_error;
7350#endif
7351 /* If SP settings didn't get completed so far - something
7352 * very wrong has happen.
7353 */
7354 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7355 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7356
7357#ifndef BNX2X_STOP_ON_ERROR
7358unload_error:
7359#endif
7360 rc = bnx2x_func_stop(bp);
7361 if (rc) {
7362 BNX2X_ERR("Function stop failed!\n");
7363#ifdef BNX2X_STOP_ON_ERROR
7364 return;
7365#endif
7366 }
7367
7368 /*
7369 * Send the UNLOAD_REQUEST to the MCP. This will return if
7370 * this function should perform FUNC, PORT or COMMON HW
7371 * reset.
7372 */
7373 reset_code = bnx2x_send_unload_req(bp, unload_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007374
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007375 /* Disable HW interrupts, NAPI */
7376 bnx2x_netif_stop(bp, 1);
7377
7378 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00007379 bnx2x_free_irq(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007380
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007381 /* Reset the chip */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007382 rc = bnx2x_reset_hw(bp, reset_code);
7383 if (rc)
7384 BNX2X_ERR("HW_RESET failed\n");
7385
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007386
7387 /* Report UNLOAD_DONE to MCP */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007388 bnx2x_send_unload_done(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007389}
7390
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00007391void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007392{
7393 u32 val;
7394
7395 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
7396
7397 if (CHIP_IS_E1(bp)) {
7398 int port = BP_PORT(bp);
7399 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7400 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7401
7402 val = REG_RD(bp, addr);
7403 val &= ~(0x300);
7404 REG_WR(bp, addr, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007405 } else {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007406 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7407 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7408 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7409 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7410 }
7411}
7412
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007413/* Close gates #2, #3 and #4: */
7414static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7415{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007416 u32 val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007417
7418 /* Gates #2 and #4a are closed/opened for "not E1" only */
7419 if (!CHIP_IS_E1(bp)) {
7420 /* #4 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007421 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007422 /* #2 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007423 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007424 }
7425
7426 /* #3 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007427 if (CHIP_IS_E1x(bp)) {
7428 /* Prevent interrupts from HC on both ports */
7429 val = REG_RD(bp, HC_REG_CONFIG_1);
7430 REG_WR(bp, HC_REG_CONFIG_1,
7431 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7432 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7433
7434 val = REG_RD(bp, HC_REG_CONFIG_0);
7435 REG_WR(bp, HC_REG_CONFIG_0,
7436 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
7437 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
7438 } else {
7439 /* Prevent incomming interrupts in IGU */
7440 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
7441
7442 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
7443 (!close) ?
7444 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
7445 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
7446 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007447
7448 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
7449 close ? "closing" : "opening");
7450 mmiowb();
7451}
7452
7453#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
7454
7455static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
7456{
7457 /* Do some magic... */
7458 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7459 *magic_val = val & SHARED_MF_CLP_MAGIC;
7460 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
7461}
7462
Dmitry Kravkove8920672011-05-04 23:52:40 +00007463/**
7464 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007465 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007466 * @bp: driver handle
7467 * @magic_val: old value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007468 */
7469static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
7470{
7471 /* Restore the `magic' bit value... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007472 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7473 MF_CFG_WR(bp, shared_mf_config.clp_mb,
7474 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
7475}
7476
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007477/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00007478 * bnx2x_reset_mcp_prep - prepare for MCP reset.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007479 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007480 * @bp: driver handle
7481 * @magic_val: old value of 'magic' bit.
7482 *
7483 * Takes care of CLP configurations.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007484 */
7485static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
7486{
7487 u32 shmem;
7488 u32 validity_offset;
7489
7490 DP(NETIF_MSG_HW, "Starting\n");
7491
7492 /* Set `magic' bit in order to save MF config */
7493 if (!CHIP_IS_E1(bp))
7494 bnx2x_clp_reset_prep(bp, magic_val);
7495
7496 /* Get shmem offset */
7497 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7498 validity_offset = offsetof(struct shmem_region, validity_map[0]);
7499
7500 /* Clear validity map flags */
7501 if (shmem > 0)
7502 REG_WR(bp, shmem + validity_offset, 0);
7503}
7504
7505#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
7506#define MCP_ONE_TIMEOUT 100 /* 100 ms */
7507
Dmitry Kravkove8920672011-05-04 23:52:40 +00007508/**
7509 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007510 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007511 * @bp: driver handle
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007512 */
7513static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
7514{
7515 /* special handling for emulation and FPGA,
7516 wait 10 times longer */
7517 if (CHIP_REV_IS_SLOW(bp))
7518 msleep(MCP_ONE_TIMEOUT*10);
7519 else
7520 msleep(MCP_ONE_TIMEOUT);
7521}
7522
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007523/*
7524 * initializes bp->common.shmem_base and waits for validity signature to appear
7525 */
7526static int bnx2x_init_shmem(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007527{
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007528 int cnt = 0;
7529 u32 val = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007530
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007531 do {
7532 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7533 if (bp->common.shmem_base) {
7534 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7535 if (val & SHR_MEM_VALIDITY_MB)
7536 return 0;
7537 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007538
7539 bnx2x_mcp_wait_one(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007540
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007541 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007542
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007543 BNX2X_ERR("BAD MCP validity signature\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007544
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007545 return -ENODEV;
7546}
7547
7548static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
7549{
7550 int rc = bnx2x_init_shmem(bp);
7551
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007552 /* Restore the `magic' bit value */
7553 if (!CHIP_IS_E1(bp))
7554 bnx2x_clp_reset_done(bp, magic_val);
7555
7556 return rc;
7557}
7558
7559static void bnx2x_pxp_prep(struct bnx2x *bp)
7560{
7561 if (!CHIP_IS_E1(bp)) {
7562 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
7563 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007564 mmiowb();
7565 }
7566}
7567
7568/*
7569 * Reset the whole chip except for:
7570 * - PCIE core
7571 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
7572 * one reset bit)
7573 * - IGU
7574 * - MISC (including AEU)
7575 * - GRC
7576 * - RBCN, RBCP
7577 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007578static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007579{
7580 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007581 u32 global_bits2;
7582
7583 /*
7584 * Bits that have to be set in reset_mask2 if we want to reset 'global'
7585 * (per chip) blocks.
7586 */
7587 global_bits2 =
7588 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
7589 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007590
7591 not_reset_mask1 =
7592 MISC_REGISTERS_RESET_REG_1_RST_HC |
7593 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
7594 MISC_REGISTERS_RESET_REG_1_RST_PXP;
7595
7596 not_reset_mask2 =
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007597 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007598 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
7599 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
7600 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
7601 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
7602 MISC_REGISTERS_RESET_REG_2_RST_GRC |
7603 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
7604 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
7605
7606 reset_mask1 = 0xffffffff;
7607
7608 if (CHIP_IS_E1(bp))
7609 reset_mask2 = 0xffff;
7610 else
7611 reset_mask2 = 0x1ffff;
7612
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007613 if (CHIP_IS_E3(bp)) {
7614 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
7615 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
7616 }
7617
7618 /* Don't reset global blocks unless we need to */
7619 if (!global)
7620 reset_mask2 &= ~global_bits2;
7621
7622 /*
7623 * In case of attention in the QM, we need to reset PXP
7624 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
7625 * because otherwise QM reset would release 'close the gates' shortly
7626 * before resetting the PXP, then the PSWRQ would send a write
7627 * request to PGLUE. Then when PXP is reset, PGLUE would try to
7628 * read the payload data from PSWWR, but PSWWR would not
7629 * respond. The write queue in PGLUE would stuck, dmae commands
7630 * would not return. Therefore it's important to reset the second
7631 * reset register (containing the
7632 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
7633 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
7634 * bit).
7635 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007636 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7637 reset_mask2 & (~not_reset_mask2));
7638
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007639 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7640 reset_mask1 & (~not_reset_mask1));
7641
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007642 barrier();
7643 mmiowb();
7644
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007645 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007646 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007647 mmiowb();
7648}
7649
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007650/**
7651 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
7652 * It should get cleared in no more than 1s.
7653 *
7654 * @bp: driver handle
7655 *
7656 * It should get cleared in no more than 1s. Returns 0 if
7657 * pending writes bit gets cleared.
7658 */
7659static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
7660{
7661 u32 cnt = 1000;
7662 u32 pend_bits = 0;
7663
7664 do {
7665 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
7666
7667 if (pend_bits == 0)
7668 break;
7669
7670 usleep_range(1000, 1000);
7671 } while (cnt-- > 0);
7672
7673 if (cnt <= 0) {
7674 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
7675 pend_bits);
7676 return -EBUSY;
7677 }
7678
7679 return 0;
7680}
7681
7682static int bnx2x_process_kill(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007683{
7684 int cnt = 1000;
7685 u32 val = 0;
7686 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
7687
7688
7689 /* Empty the Tetris buffer, wait for 1s */
7690 do {
7691 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
7692 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
7693 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
7694 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
7695 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
7696 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
7697 ((port_is_idle_0 & 0x1) == 0x1) &&
7698 ((port_is_idle_1 & 0x1) == 0x1) &&
7699 (pgl_exp_rom2 == 0xffffffff))
7700 break;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007701 usleep_range(1000, 1000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007702 } while (cnt-- > 0);
7703
7704 if (cnt <= 0) {
7705 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
7706 " are still"
7707 " outstanding read requests after 1s!\n");
7708 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
7709 " port_is_idle_0=0x%08x,"
7710 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
7711 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
7712 pgl_exp_rom2);
7713 return -EAGAIN;
7714 }
7715
7716 barrier();
7717
7718 /* Close gates #2, #3 and #4 */
7719 bnx2x_set_234_gates(bp, true);
7720
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007721 /* Poll for IGU VQs for 57712 and newer chips */
7722 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
7723 return -EAGAIN;
7724
7725
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007726 /* TBD: Indicate that "process kill" is in progress to MCP */
7727
7728 /* Clear "unprepared" bit */
7729 REG_WR(bp, MISC_REG_UNPREPARED, 0);
7730 barrier();
7731
7732 /* Make sure all is written to the chip before the reset */
7733 mmiowb();
7734
7735 /* Wait for 1ms to empty GLUE and PCI-E core queues,
7736 * PSWHST, GRC and PSWRD Tetris buffer.
7737 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007738 usleep_range(1000, 1000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007739
7740 /* Prepare to chip reset: */
7741 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007742 if (global)
7743 bnx2x_reset_mcp_prep(bp, &val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007744
7745 /* PXP */
7746 bnx2x_pxp_prep(bp);
7747 barrier();
7748
7749 /* reset the chip */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007750 bnx2x_process_kill_chip_reset(bp, global);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007751 barrier();
7752
7753 /* Recover after reset: */
7754 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007755 if (global && bnx2x_reset_mcp_comp(bp, val))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007756 return -EAGAIN;
7757
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007758 /* TBD: Add resetting the NO_MCP mode DB here */
7759
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007760 /* PXP */
7761 bnx2x_pxp_prep(bp);
7762
7763 /* Open the gates #2, #3 and #4 */
7764 bnx2x_set_234_gates(bp, false);
7765
7766 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
7767 * reset state, re-enable attentions. */
7768
7769 return 0;
7770}
7771
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007772int bnx2x_leader_reset(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007773{
7774 int rc = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007775 bool global = bnx2x_reset_is_global(bp);
7776
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007777 /* Try to recover after the failure */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007778 if (bnx2x_process_kill(bp, global)) {
7779 netdev_err(bp->dev, "Something bad had happen on engine %d! "
7780 "Aii!\n", BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007781 rc = -EAGAIN;
7782 goto exit_leader_reset;
7783 }
7784
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007785 /*
7786 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
7787 * state.
7788 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007789 bnx2x_set_reset_done(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007790 if (global)
7791 bnx2x_clear_reset_global(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007792
7793exit_leader_reset:
7794 bp->is_leader = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007795 bnx2x_release_leader_lock(bp);
7796 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007797 return rc;
7798}
7799
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007800static inline void bnx2x_recovery_failed(struct bnx2x *bp)
7801{
7802 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
7803
7804 /* Disconnect this device */
7805 netif_device_detach(bp->dev);
7806
7807 /*
7808 * Block ifup for all function on this engine until "process kill"
7809 * or power cycle.
7810 */
7811 bnx2x_set_reset_in_progress(bp);
7812
7813 /* Shut down the power */
7814 bnx2x_set_power_state(bp, PCI_D3hot);
7815
7816 bp->recovery_state = BNX2X_RECOVERY_FAILED;
7817
7818 smp_mb();
7819}
7820
7821/*
7822 * Assumption: runs under rtnl lock. This together with the fact
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007823 * that it's called only from bnx2x_reset_task() ensure that it
7824 * will never be called when netif_running(bp->dev) is false.
7825 */
7826static void bnx2x_parity_recover(struct bnx2x *bp)
7827{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007828 bool global = false;
7829
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007830 DP(NETIF_MSG_HW, "Handling parity\n");
7831 while (1) {
7832 switch (bp->recovery_state) {
7833 case BNX2X_RECOVERY_INIT:
7834 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007835 bnx2x_chk_parity_attn(bp, &global, false);
7836
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007837 /* Try to get a LEADER_LOCK HW lock */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007838 if (bnx2x_trylock_leader_lock(bp)) {
7839 bnx2x_set_reset_in_progress(bp);
7840 /*
7841 * Check if there is a global attention and if
7842 * there was a global attention, set the global
7843 * reset bit.
7844 */
7845
7846 if (global)
7847 bnx2x_set_reset_global(bp);
7848
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007849 bp->is_leader = 1;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007850 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007851
7852 /* Stop the driver */
7853 /* If interface has been removed - break */
7854 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
7855 return;
7856
7857 bp->recovery_state = BNX2X_RECOVERY_WAIT;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007858
7859 /*
7860 * Reset MCP command sequence number and MCP mail box
7861 * sequence as we are going to reset the MCP.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007862 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007863 if (global) {
7864 bp->fw_seq = 0;
7865 bp->fw_drv_pulse_wr_seq = 0;
7866 }
7867
7868 /* Ensure "is_leader", MCP command sequence and
7869 * "recovery_state" update values are seen on other
7870 * CPUs.
7871 */
7872 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007873 break;
7874
7875 case BNX2X_RECOVERY_WAIT:
7876 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
7877 if (bp->is_leader) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007878 int other_engine = BP_PATH(bp) ? 0 : 1;
7879 u32 other_load_counter =
7880 bnx2x_get_load_cnt(bp, other_engine);
7881 u32 load_counter =
7882 bnx2x_get_load_cnt(bp, BP_PATH(bp));
7883 global = bnx2x_reset_is_global(bp);
7884
7885 /*
7886 * In case of a parity in a global block, let
7887 * the first leader that performs a
7888 * leader_reset() reset the global blocks in
7889 * order to clear global attentions. Otherwise
7890 * the the gates will remain closed for that
7891 * engine.
7892 */
7893 if (load_counter ||
7894 (global && other_load_counter)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007895 /* Wait until all other functions get
7896 * down.
7897 */
7898 schedule_delayed_work(&bp->reset_task,
7899 HZ/10);
7900 return;
7901 } else {
7902 /* If all other functions got down -
7903 * try to bring the chip back to
7904 * normal. In any case it's an exit
7905 * point for a leader.
7906 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007907 if (bnx2x_leader_reset(bp)) {
7908 bnx2x_recovery_failed(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007909 return;
7910 }
7911
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007912 /* If we are here, means that the
7913 * leader has succeeded and doesn't
7914 * want to be a leader any more. Try
7915 * to continue as a none-leader.
7916 */
7917 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007918 }
7919 } else { /* non-leader */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007920 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007921 /* Try to get a LEADER_LOCK HW lock as
7922 * long as a former leader may have
7923 * been unloaded by the user or
7924 * released a leadership by another
7925 * reason.
7926 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007927 if (bnx2x_trylock_leader_lock(bp)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007928 /* I'm a leader now! Restart a
7929 * switch case.
7930 */
7931 bp->is_leader = 1;
7932 break;
7933 }
7934
7935 schedule_delayed_work(&bp->reset_task,
7936 HZ/10);
7937 return;
7938
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007939 } else {
7940 /*
7941 * If there was a global attention, wait
7942 * for it to be cleared.
7943 */
7944 if (bnx2x_reset_is_global(bp)) {
7945 schedule_delayed_work(
7946 &bp->reset_task, HZ/10);
7947 return;
7948 }
7949
7950 if (bnx2x_nic_load(bp, LOAD_NORMAL))
7951 bnx2x_recovery_failed(bp);
7952 else {
7953 bp->recovery_state =
7954 BNX2X_RECOVERY_DONE;
7955 smp_mb();
7956 }
7957
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007958 return;
7959 }
7960 }
7961 default:
7962 return;
7963 }
7964 }
7965}
7966
7967/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
7968 * scheduled on a general queue in order to prevent a dead lock.
7969 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007970static void bnx2x_reset_task(struct work_struct *work)
7971{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007972 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007973
7974#ifdef BNX2X_STOP_ON_ERROR
7975 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7976 " so reset not done to allow debug dump,\n"
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007977 KERN_ERR " you will need to reboot when done\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007978 return;
7979#endif
7980
7981 rtnl_lock();
7982
7983 if (!netif_running(bp->dev))
7984 goto reset_task_exit;
7985
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007986 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
7987 bnx2x_parity_recover(bp);
7988 else {
7989 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7990 bnx2x_nic_load(bp, LOAD_NORMAL);
7991 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007992
7993reset_task_exit:
7994 rtnl_unlock();
7995}
7996
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007997/* end of nic load/unload */
7998
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007999/*
8000 * Init service functions
8001 */
8002
stephen hemminger8d962862010-10-21 07:50:56 +00008003static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008004{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008005 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8006 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8007 return base + (BP_ABS_FUNC(bp)) * stride;
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008008}
8009
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008010static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008011{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008012 u32 reg = bnx2x_get_pretend_reg(bp);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008013
8014 /* Flush all outstanding writes */
8015 mmiowb();
8016
8017 /* Pretend to be function 0 */
8018 REG_WR(bp, reg, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008019 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008020
8021 /* From now we are in the "like-E1" mode */
8022 bnx2x_int_disable(bp);
8023
8024 /* Flush all outstanding writes */
8025 mmiowb();
8026
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008027 /* Restore the original function */
8028 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8029 REG_RD(bp, reg);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008030}
8031
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008032static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008033{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008034 if (CHIP_IS_E1(bp))
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008035 bnx2x_int_disable(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008036 else
8037 bnx2x_undi_int_disable_e1h(bp);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008038}
8039
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008040static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008041{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008042 u32 val;
8043
8044 /* Check if there is any driver already loaded */
8045 val = REG_RD(bp, MISC_REG_UNPREPARED);
8046 if (val == 0x1) {
8047 /* Check if it is the UNDI driver
8048 * UNDI driver initializes CID offset for normal bell to 0x7
8049 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008050 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008051 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8052 if (val == 0x7) {
8053 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008054 /* save our pf_num */
8055 int orig_pf_num = bp->pf_num;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008056 int port;
8057 u32 swap_en, swap_val, value;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008058
Eilon Greensteinb4661732009-01-14 06:43:56 +00008059 /* clear the UNDI indication */
8060 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8061
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008062 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8063
8064 /* try unload UNDI on port 0 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008065 bp->pf_num = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008066 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008067 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008068 DRV_MSG_SEQ_NUMBER_MASK);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008069 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008070
8071 /* if UNDI is loaded on the other port */
8072 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8073
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008074 /* send "DONE" for previous unload */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008075 bnx2x_fw_command(bp,
8076 DRV_MSG_CODE_UNLOAD_DONE, 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008077
8078 /* unload UNDI on port 1 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008079 bp->pf_num = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008080 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008081 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008082 DRV_MSG_SEQ_NUMBER_MASK);
8083 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008084
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008085 bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008086 }
8087
Eilon Greensteinb4661732009-01-14 06:43:56 +00008088 /* now it's safe to release the lock */
8089 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8090
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008091 bnx2x_undi_int_disable(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008092 port = BP_PORT(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008093
8094 /* close input traffic and wait for it */
8095 /* Do not rcv packets to BRB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008096 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8097 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008098 /* Do not direct rcv packets that are not for MCP to
8099 * the BRB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008100 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8101 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008102 /* clear AEU */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008103 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8104 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008105 msleep(10);
8106
8107 /* save NIG port swap info */
8108 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8109 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008110 /* reset device */
8111 REG_WR(bp,
8112 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008113 0xd3ffffff);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008114
8115 value = 0x1400;
8116 if (CHIP_IS_E3(bp)) {
8117 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8118 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8119 }
8120
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008121 REG_WR(bp,
8122 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008123 value);
8124
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008125 /* take the NIG out of reset and restore swap values */
8126 REG_WR(bp,
8127 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8128 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8129 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8130 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8131
8132 /* send unload done to the MCP */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008133 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008134
8135 /* restore our func and fw_seq */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008136 bp->pf_num = orig_pf_num;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008137 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008138 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008139 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00008140 } else
8141 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008142 }
8143}
8144
8145static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8146{
8147 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008148 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008149
8150 /* Get the chip revision id and number. */
8151 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8152 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8153 id = ((val & 0xffff) << 16);
8154 val = REG_RD(bp, MISC_REG_CHIP_REV);
8155 id |= ((val & 0xf) << 12);
8156 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8157 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00008158 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008159 id |= (val & 0xf);
8160 bp->common.chip_id = id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008161
8162 /* Set doorbell size */
8163 bp->db_size = (1 << BNX2X_DB_SHIFT);
8164
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008165 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008166 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
8167 if ((val & 1) == 0)
8168 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
8169 else
8170 val = (val >> 1) & 1;
8171 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
8172 "2_PORT_MODE");
8173 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
8174 CHIP_2_PORT_MODE;
8175
8176 if (CHIP_MODE_IS_4_PORT(bp))
8177 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
8178 else
8179 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
8180 } else {
8181 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
8182 bp->pfid = bp->pf_num; /* 0..7 */
8183 }
8184
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008185 bp->link_params.chip_id = bp->common.chip_id;
8186 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008187
Eilon Greenstein1c063282009-02-12 08:36:43 +00008188 val = (REG_RD(bp, 0x2874) & 0x55);
8189 if ((bp->common.chip_id & 0x1) ||
8190 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8191 bp->flags |= ONE_PORT_FLAG;
8192 BNX2X_DEV_INFO("single port device\n");
8193 }
8194
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008195 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
8196 bp->common.flash_size = (NVRAM_1MB_SIZE <<
8197 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8198 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8199 bp->common.flash_size, bp->common.flash_size);
8200
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00008201 bnx2x_init_shmem(bp);
8202
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008203
8204
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008205 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
8206 MISC_REG_GENERIC_CR_1 :
8207 MISC_REG_GENERIC_CR_0));
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00008208
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008209 bp->link_params.shmem_base = bp->common.shmem_base;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008210 bp->link_params.shmem2_base = bp->common.shmem2_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008211 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8212 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008213
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008214 if (!bp->common.shmem_base) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008215 BNX2X_DEV_INFO("MCP not active\n");
8216 bp->flags |= NO_MCP_FLAG;
8217 return;
8218 }
8219
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008220 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00008221 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008222
8223 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8224 SHARED_HW_CFG_LED_MODE_MASK) >>
8225 SHARED_HW_CFG_LED_MODE_SHIFT);
8226
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008227 bp->link_params.feature_config_flags = 0;
8228 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8229 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8230 bp->link_params.feature_config_flags |=
8231 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8232 else
8233 bp->link_params.feature_config_flags &=
8234 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8235
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008236 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8237 bp->common.bc_ver = val;
8238 BNX2X_DEV_INFO("bc_ver %X\n", val);
8239 if (val < BNX2X_BC_VER) {
8240 /* for now only warn
8241 * later we might need to enforce this */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008242 BNX2X_ERR("This driver needs bc_ver %X but found %X, "
8243 "please upgrade BC\n", BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008244 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008245 bp->link_params.feature_config_flags |=
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008246 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008247 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
8248
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008249 bp->link_params.feature_config_flags |=
8250 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8251 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008252
Dmitry Kravkovf9a3ebb2011-05-04 23:49:11 +00008253 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8254 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8255
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008256 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +00008257 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008258
8259 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8260 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8261 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8262 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8263
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008264 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
8265 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008266}
8267
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008268#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8269#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8270
8271static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
8272{
8273 int pfid = BP_FUNC(bp);
8274 int vn = BP_E1HVN(bp);
8275 int igu_sb_id;
8276 u32 val;
8277 u8 fid;
8278
8279 bp->igu_base_sb = 0xff;
8280 bp->igu_sb_cnt = 0;
8281 if (CHIP_INT_MODE_IS_BC(bp)) {
8282 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008283 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008284
8285 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
8286 FP_SB_MAX_E1x;
8287
8288 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
8289 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
8290
8291 return;
8292 }
8293
8294 /* IGU in normal mode - read CAM */
8295 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
8296 igu_sb_id++) {
8297 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8298 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
8299 continue;
8300 fid = IGU_FID(val);
8301 if ((fid & IGU_FID_ENCODE_IS_PF)) {
8302 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
8303 continue;
8304 if (IGU_VEC(val) == 0)
8305 /* default status block */
8306 bp->igu_dsb_id = igu_sb_id;
8307 else {
8308 if (bp->igu_base_sb == 0xff)
8309 bp->igu_base_sb = igu_sb_id;
8310 bp->igu_sb_cnt++;
8311 }
8312 }
8313 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008314
8315 /* It's expected that number of CAM entries for this
8316 * functions is equal to the MSI-X table size (which was a
8317 * used during bp->l2_cid_count value calculation.
8318 * We want a harsh warning if these values are different!
8319 */
8320 WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8321
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008322 if (bp->igu_sb_cnt == 0)
8323 BNX2X_ERR("CAM configuration error\n");
8324}
8325
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008326static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8327 u32 switch_cfg)
8328{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008329 int cfg_size = 0, idx, port = BP_PORT(bp);
8330
8331 /* Aggregation of supported attributes of all external phys */
8332 bp->port.supported[0] = 0;
8333 bp->port.supported[1] = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008334 switch (bp->link_params.num_phys) {
8335 case 1:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008336 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
8337 cfg_size = 1;
8338 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008339 case 2:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008340 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
8341 cfg_size = 1;
8342 break;
8343 case 3:
8344 if (bp->link_params.multi_phy_config &
8345 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8346 bp->port.supported[1] =
8347 bp->link_params.phy[EXT_PHY1].supported;
8348 bp->port.supported[0] =
8349 bp->link_params.phy[EXT_PHY2].supported;
8350 } else {
8351 bp->port.supported[0] =
8352 bp->link_params.phy[EXT_PHY1].supported;
8353 bp->port.supported[1] =
8354 bp->link_params.phy[EXT_PHY2].supported;
8355 }
8356 cfg_size = 2;
8357 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008358 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008359
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008360 if (!(bp->port.supported[0] || bp->port.supported[1])) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008361 BNX2X_ERR("NVRAM config error. BAD phy config."
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008362 "PHY1 config 0x%x, PHY2 config 0x%x\n",
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008363 SHMEM_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008364 dev_info.port_hw_config[port].external_phy_config),
8365 SHMEM_RD(bp,
8366 dev_info.port_hw_config[port].external_phy_config2));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008367 return;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008368 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008369
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008370 if (CHIP_IS_E3(bp))
8371 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
8372 else {
8373 switch (switch_cfg) {
8374 case SWITCH_CFG_1G:
8375 bp->port.phy_addr = REG_RD(
8376 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
8377 break;
8378 case SWITCH_CFG_10G:
8379 bp->port.phy_addr = REG_RD(
8380 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
8381 break;
8382 default:
8383 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
8384 bp->port.link_config[0]);
8385 return;
8386 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008387 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008388 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008389 /* mask what we support according to speed_cap_mask per configuration */
8390 for (idx = 0; idx < cfg_size; idx++) {
8391 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008392 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008393 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008394
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008395 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008396 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008397 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008398
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008399 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008400 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008401 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008402
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008403 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008404 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008405 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008406
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008407 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008408 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008409 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008410 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008411
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008412 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008413 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008414 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008415
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008416 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008417 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008418 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008419
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008420 }
8421
8422 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
8423 bp->port.supported[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008424}
8425
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008426static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008427{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008428 u32 link_config, idx, cfg_size = 0;
8429 bp->port.advertising[0] = 0;
8430 bp->port.advertising[1] = 0;
8431 switch (bp->link_params.num_phys) {
8432 case 1:
8433 case 2:
8434 cfg_size = 1;
8435 break;
8436 case 3:
8437 cfg_size = 2;
8438 break;
8439 }
8440 for (idx = 0; idx < cfg_size; idx++) {
8441 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
8442 link_config = bp->port.link_config[idx];
8443 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008444 case PORT_FEATURE_LINK_SPEED_AUTO:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008445 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
8446 bp->link_params.req_line_speed[idx] =
8447 SPEED_AUTO_NEG;
8448 bp->port.advertising[idx] |=
8449 bp->port.supported[idx];
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008450 } else {
8451 /* force 10G, no AN */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008452 bp->link_params.req_line_speed[idx] =
8453 SPEED_10000;
8454 bp->port.advertising[idx] |=
8455 (ADVERTISED_10000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008456 ADVERTISED_FIBRE);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008457 continue;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008458 }
8459 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008460
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008461 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008462 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
8463 bp->link_params.req_line_speed[idx] =
8464 SPEED_10;
8465 bp->port.advertising[idx] |=
8466 (ADVERTISED_10baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008467 ADVERTISED_TP);
8468 } else {
8469 BNX2X_ERROR("NVRAM config error. "
8470 "Invalid link_config 0x%x"
8471 " speed_cap_mask 0x%x\n",
8472 link_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008473 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008474 return;
8475 }
8476 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008477
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008478 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008479 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
8480 bp->link_params.req_line_speed[idx] =
8481 SPEED_10;
8482 bp->link_params.req_duplex[idx] =
8483 DUPLEX_HALF;
8484 bp->port.advertising[idx] |=
8485 (ADVERTISED_10baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008486 ADVERTISED_TP);
8487 } else {
8488 BNX2X_ERROR("NVRAM config error. "
8489 "Invalid link_config 0x%x"
8490 " speed_cap_mask 0x%x\n",
8491 link_config,
8492 bp->link_params.speed_cap_mask[idx]);
8493 return;
8494 }
8495 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008496
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008497 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8498 if (bp->port.supported[idx] &
8499 SUPPORTED_100baseT_Full) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008500 bp->link_params.req_line_speed[idx] =
8501 SPEED_100;
8502 bp->port.advertising[idx] |=
8503 (ADVERTISED_100baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008504 ADVERTISED_TP);
8505 } else {
8506 BNX2X_ERROR("NVRAM config error. "
8507 "Invalid link_config 0x%x"
8508 " speed_cap_mask 0x%x\n",
8509 link_config,
8510 bp->link_params.speed_cap_mask[idx]);
8511 return;
8512 }
8513 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008514
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008515 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8516 if (bp->port.supported[idx] &
8517 SUPPORTED_100baseT_Half) {
8518 bp->link_params.req_line_speed[idx] =
8519 SPEED_100;
8520 bp->link_params.req_duplex[idx] =
8521 DUPLEX_HALF;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008522 bp->port.advertising[idx] |=
8523 (ADVERTISED_100baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008524 ADVERTISED_TP);
8525 } else {
8526 BNX2X_ERROR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008527 "Invalid link_config 0x%x"
8528 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008529 link_config,
8530 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008531 return;
8532 }
8533 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008534
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008535 case PORT_FEATURE_LINK_SPEED_1G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008536 if (bp->port.supported[idx] &
8537 SUPPORTED_1000baseT_Full) {
8538 bp->link_params.req_line_speed[idx] =
8539 SPEED_1000;
8540 bp->port.advertising[idx] |=
8541 (ADVERTISED_1000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008542 ADVERTISED_TP);
8543 } else {
8544 BNX2X_ERROR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008545 "Invalid link_config 0x%x"
8546 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008547 link_config,
8548 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008549 return;
8550 }
8551 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008552
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008553 case PORT_FEATURE_LINK_SPEED_2_5G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008554 if (bp->port.supported[idx] &
8555 SUPPORTED_2500baseX_Full) {
8556 bp->link_params.req_line_speed[idx] =
8557 SPEED_2500;
8558 bp->port.advertising[idx] |=
8559 (ADVERTISED_2500baseX_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008560 ADVERTISED_TP);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008561 } else {
8562 BNX2X_ERROR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008563 "Invalid link_config 0x%x"
8564 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008565 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008566 bp->link_params.speed_cap_mask[idx]);
8567 return;
8568 }
8569 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008570
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008571 case PORT_FEATURE_LINK_SPEED_10G_CX4:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008572 if (bp->port.supported[idx] &
8573 SUPPORTED_10000baseT_Full) {
8574 bp->link_params.req_line_speed[idx] =
8575 SPEED_10000;
8576 bp->port.advertising[idx] |=
8577 (ADVERTISED_10000baseT_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008578 ADVERTISED_FIBRE);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008579 } else {
8580 BNX2X_ERROR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008581 "Invalid link_config 0x%x"
8582 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008583 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008584 bp->link_params.speed_cap_mask[idx]);
8585 return;
8586 }
8587 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008588
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008589 default:
8590 BNX2X_ERROR("NVRAM config error. "
8591 "BAD link speed link_config 0x%x\n",
8592 link_config);
8593 bp->link_params.req_line_speed[idx] =
8594 SPEED_AUTO_NEG;
8595 bp->port.advertising[idx] =
8596 bp->port.supported[idx];
8597 break;
8598 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008599
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008600 bp->link_params.req_flow_ctrl[idx] = (link_config &
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008601 PORT_FEATURE_FLOW_CONTROL_MASK);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008602 if ((bp->link_params.req_flow_ctrl[idx] ==
8603 BNX2X_FLOW_CTRL_AUTO) &&
8604 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
8605 bp->link_params.req_flow_ctrl[idx] =
8606 BNX2X_FLOW_CTRL_NONE;
8607 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008608
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008609 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
8610 " 0x%x advertising 0x%x\n",
8611 bp->link_params.req_line_speed[idx],
8612 bp->link_params.req_duplex[idx],
8613 bp->link_params.req_flow_ctrl[idx],
8614 bp->port.advertising[idx]);
8615 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008616}
8617
Michael Chane665bfd2009-10-10 13:46:54 +00008618static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
8619{
8620 mac_hi = cpu_to_be16(mac_hi);
8621 mac_lo = cpu_to_be32(mac_lo);
8622 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
8623 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
8624}
8625
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008626static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008627{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008628 int port = BP_PORT(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00008629 u32 config;
Joe Perches6f38ad92010-11-14 17:04:31 +00008630 u32 ext_phy_type, ext_phy_config;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008631
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008632 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008633 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008634
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008635 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008636 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008637
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008638 bp->link_params.speed_cap_mask[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008639 SHMEM_RD(bp,
8640 dev_info.port_hw_config[port].speed_capability_mask);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008641 bp->link_params.speed_cap_mask[1] =
8642 SHMEM_RD(bp,
8643 dev_info.port_hw_config[port].speed_capability_mask2);
8644 bp->port.link_config[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008645 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8646
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008647 bp->port.link_config[1] =
8648 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008649
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008650 bp->link_params.multi_phy_config =
8651 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008652 /* If the device is capable of WoL, set the default state according
8653 * to the HW
8654 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008655 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008656 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8657 (config & PORT_FEATURE_WOL_ENABLED));
8658
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008659 BNX2X_DEV_INFO("lane_config 0x%08x "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008660 "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008661 bp->link_params.lane_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008662 bp->link_params.speed_cap_mask[0],
8663 bp->port.link_config[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008664
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008665 bp->link_params.switch_cfg = (bp->port.link_config[0] &
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008666 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008667 bnx2x_phy_probe(&bp->link_params);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008668 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008669
8670 bnx2x_link_settings_requested(bp);
8671
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008672 /*
8673 * If connected directly, work with the internal PHY, otherwise, work
8674 * with the external PHY
8675 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008676 ext_phy_config =
8677 SHMEM_RD(bp,
8678 dev_info.port_hw_config[port].external_phy_config);
8679 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008680 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008681 bp->mdio.prtad = bp->port.phy_addr;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008682
8683 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
8684 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
8685 bp->mdio.prtad =
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008686 XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner5866df62011-01-30 04:15:07 +00008687
8688 /*
8689 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
8690 * In MF mode, it is set to cover self test cases
8691 */
8692 if (IS_MF(bp))
8693 bp->port.need_hw_lock = 1;
8694 else
8695 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
8696 bp->common.shmem_base,
8697 bp->common.shmem2_base);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008698}
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008699
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008700#ifdef BCM_CNIC
8701static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
8702{
8703 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8704 drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
8705 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8706 drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
8707
8708 /* Get the number of maximum allowed iSCSI and FCoE connections */
8709 bp->cnic_eth_dev.max_iscsi_conn =
8710 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
8711 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
8712
8713 bp->cnic_eth_dev.max_fcoe_conn =
8714 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
8715 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
8716
8717 BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
8718 bp->cnic_eth_dev.max_iscsi_conn,
8719 bp->cnic_eth_dev.max_fcoe_conn);
8720
8721 /* If mamimum allowed number of connections is zero -
8722 * disable the feature.
8723 */
8724 if (!bp->cnic_eth_dev.max_iscsi_conn)
8725 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8726
8727 if (!bp->cnic_eth_dev.max_fcoe_conn)
8728 bp->flags |= NO_FCOE_FLAG;
8729}
8730#endif
8731
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008732static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
8733{
8734 u32 val, val2;
8735 int func = BP_ABS_FUNC(bp);
8736 int port = BP_PORT(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008737#ifdef BCM_CNIC
8738 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
8739 u8 *fip_mac = bp->fip_mac;
8740#endif
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008741
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008742 /* Zero primary MAC configuration */
8743 memset(bp->dev->dev_addr, 0, ETH_ALEN);
8744
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008745 if (BP_NOMCP(bp)) {
8746 BNX2X_ERROR("warning: random MAC workaround active\n");
8747 random_ether_addr(bp->dev->dev_addr);
8748 } else if (IS_MF(bp)) {
8749 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
8750 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
8751 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8752 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
8753 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8754
8755#ifdef BCM_CNIC
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008756 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
8757 * FCoE MAC then the appropriate feature should be disabled.
8758 */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008759 if (IS_MF_SI(bp)) {
8760 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
8761 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
8762 val2 = MF_CFG_RD(bp, func_ext_config[func].
8763 iscsi_mac_addr_upper);
8764 val = MF_CFG_RD(bp, func_ext_config[func].
8765 iscsi_mac_addr_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008766 bnx2x_set_mac_buf(iscsi_mac, val, val2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008767 BNX2X_DEV_INFO("Read iSCSI MAC: "
8768 BNX2X_MAC_FMT"\n",
8769 BNX2X_MAC_PRN_LIST(iscsi_mac));
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008770 } else
8771 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8772
8773 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
8774 val2 = MF_CFG_RD(bp, func_ext_config[func].
8775 fcoe_mac_addr_upper);
8776 val = MF_CFG_RD(bp, func_ext_config[func].
8777 fcoe_mac_addr_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008778 bnx2x_set_mac_buf(fip_mac, val, val2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008779 BNX2X_DEV_INFO("Read FCoE L2 MAC to "
8780 BNX2X_MAC_FMT"\n",
8781 BNX2X_MAC_PRN_LIST(fip_mac));
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008782
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008783 } else
8784 bp->flags |= NO_FCOE_FLAG;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008785 }
8786#endif
8787 } else {
8788 /* in SF read MACs from port configuration */
8789 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8790 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8791 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8792
8793#ifdef BCM_CNIC
8794 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
8795 iscsi_mac_upper);
8796 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
8797 iscsi_mac_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008798 bnx2x_set_mac_buf(iscsi_mac, val, val2);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008799#endif
8800 }
8801
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008802 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8803 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +00008804
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008805#ifdef BCM_CNIC
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008806 /* Set the FCoE MAC in modes other then MF_SI */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008807 if (!CHIP_IS_E1x(bp)) {
8808 if (IS_MF_SD(bp))
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008809 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
8810 else if (!IS_MF(bp))
8811 memcpy(fip_mac, iscsi_mac, ETH_ALEN);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008812 }
Dmitry Kravkov426b9242011-05-04 23:49:53 +00008813
8814 /* Disable iSCSI if MAC configuration is
8815 * invalid.
8816 */
8817 if (!is_valid_ether_addr(iscsi_mac)) {
8818 bp->flags |= NO_ISCSI_FLAG;
8819 memset(iscsi_mac, 0, ETH_ALEN);
8820 }
8821
8822 /* Disable FCoE if MAC configuration is
8823 * invalid.
8824 */
8825 if (!is_valid_ether_addr(fip_mac)) {
8826 bp->flags |= NO_FCOE_FLAG;
8827 memset(bp->fip_mac, 0, ETH_ALEN);
8828 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008829#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008830
8831 if (!is_valid_ether_addr(bp->dev->dev_addr))
8832 dev_err(&bp->pdev->dev,
8833 "bad Ethernet MAC address configuration: "
8834 BNX2X_MAC_FMT", change it manually before bringing up "
8835 "the appropriate network interface\n",
8836 BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008837}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008838
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008839static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8840{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008841 int /*abs*/func = BP_ABS_FUNC(bp);
David S. Millerb8ee8322011-04-17 16:56:12 -07008842 int vn;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008843 u32 val = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008844 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008845
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008846 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008847
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008848 if (CHIP_IS_E1x(bp)) {
8849 bp->common.int_block = INT_BLOCK_HC;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008850
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008851 bp->igu_dsb_id = DEF_SB_IGU_ID;
8852 bp->igu_base_sb = 0;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008853 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8854 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008855 } else {
8856 bp->common.int_block = INT_BLOCK_IGU;
8857 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008858
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008859 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008860 int tout = 5000;
8861
8862 BNX2X_DEV_INFO("FORCING Normal Mode\n");
8863
8864 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
8865 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
8866 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
8867
8868 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8869 tout--;
8870 usleep_range(1000, 1000);
8871 }
8872
8873 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8874 dev_err(&bp->pdev->dev,
8875 "FORCING Normal Mode failed!!!\n");
8876 return -EPERM;
8877 }
8878 }
8879
8880 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8881 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008882 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
8883 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008884 BNX2X_DEV_INFO("IGU Normal Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008885
8886 bnx2x_get_igu_cam_info(bp);
8887
8888 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008889
8890 /*
8891 * set base FW non-default (fast path) status block id, this value is
8892 * used to initialize the fw_sb_id saved on the fp/queue structure to
8893 * determine the id used by the FW.
8894 */
8895 if (CHIP_IS_E1x(bp))
8896 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
8897 else /*
8898 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
8899 * the same queue are indicated on the same IGU SB). So we prefer
8900 * FW and IGU SBs to be the same value.
8901 */
8902 bp->base_fw_ndsb = bp->igu_base_sb;
8903
8904 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
8905 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
8906 bp->igu_sb_cnt, bp->base_fw_ndsb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008907
8908 /*
8909 * Initialize MF configuration
8910 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008911
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008912 bp->mf_ov = 0;
8913 bp->mf_mode = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008914 vn = BP_E1HVN(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008915
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008916 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008917 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
8918 bp->common.shmem2_base, SHMEM2_RD(bp, size),
8919 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
8920
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008921 if (SHMEM2_HAS(bp, mf_cfg_addr))
8922 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
8923 else
8924 bp->common.mf_cfg_base = bp->common.shmem_base +
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008925 offsetof(struct shmem_region, func_mb) +
8926 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008927 /*
8928 * get mf configuration:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008929 * 1. existence of MF configuration
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008930 * 2. MAC address must be legal (check only upper bytes)
8931 * for Switch-Independent mode;
8932 * OVLAN must be legal for Switch-Dependent mode
8933 * 3. SF_MODE configures specific MF mode
8934 */
8935 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
8936 /* get mf configuration */
8937 val = SHMEM_RD(bp,
8938 dev_info.shared_feature_config.config);
8939 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008940
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008941 switch (val) {
8942 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
8943 val = MF_CFG_RD(bp, func_mf_config[func].
8944 mac_upper);
8945 /* check for legal mac (upper bytes)*/
8946 if (val != 0xffff) {
8947 bp->mf_mode = MULTI_FUNCTION_SI;
8948 bp->mf_config[vn] = MF_CFG_RD(bp,
8949 func_mf_config[func].config);
8950 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008951 BNX2X_DEV_INFO("illegal MAC address "
8952 "for SI\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008953 break;
8954 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
8955 /* get OV configuration */
8956 val = MF_CFG_RD(bp,
8957 func_mf_config[FUNC_0].e1hov_tag);
8958 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
8959
8960 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
8961 bp->mf_mode = MULTI_FUNCTION_SD;
8962 bp->mf_config[vn] = MF_CFG_RD(bp,
8963 func_mf_config[func].config);
8964 } else
8965 DP(NETIF_MSG_PROBE, "illegal OV for "
8966 "SD\n");
8967 break;
8968 default:
8969 /* Unknown configuration: reset mf_config */
8970 bp->mf_config[vn] = 0;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008971 DP(NETIF_MSG_PROBE, "Unknown MF mode 0x%x\n",
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008972 val);
8973 }
8974 }
8975
Eilon Greenstein2691d512009-08-12 08:22:08 +00008976 BNX2X_DEV_INFO("%s function mode\n",
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008977 IS_MF(bp) ? "multi" : "single");
Eilon Greenstein2691d512009-08-12 08:22:08 +00008978
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008979 switch (bp->mf_mode) {
8980 case MULTI_FUNCTION_SD:
8981 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
8982 FUNC_MF_CFG_E1HOV_TAG_MASK;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008983 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008984 bp->mf_ov = val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008985 bp->path_has_ovlan = true;
8986
8987 BNX2X_DEV_INFO("MF OV for func %d is %d "
8988 "(0x%04x)\n", func, bp->mf_ov,
8989 bp->mf_ov);
Eilon Greenstein2691d512009-08-12 08:22:08 +00008990 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008991 dev_err(&bp->pdev->dev,
8992 "No valid MF OV for func %d, "
8993 "aborting\n", func);
8994 return -EPERM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008995 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008996 break;
8997 case MULTI_FUNCTION_SI:
8998 BNX2X_DEV_INFO("func %d is in MF "
8999 "switch-independent mode\n", func);
9000 break;
9001 default:
9002 if (vn) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009003 dev_err(&bp->pdev->dev,
9004 "VN %d is in a single function mode, "
9005 "aborting\n", vn);
9006 return -EPERM;
Eilon Greenstein2691d512009-08-12 08:22:08 +00009007 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009008 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009009 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009010
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009011 /* check if other port on the path needs ovlan:
9012 * Since MF configuration is shared between ports
9013 * Possible mixed modes are only
9014 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
9015 */
9016 if (CHIP_MODE_IS_4_PORT(bp) &&
9017 !bp->path_has_ovlan &&
9018 !IS_MF(bp) &&
9019 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9020 u8 other_port = !BP_PORT(bp);
9021 u8 other_func = BP_PATH(bp) + 2*other_port;
9022 val = MF_CFG_RD(bp,
9023 func_mf_config[other_func].e1hov_tag);
9024 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
9025 bp->path_has_ovlan = true;
9026 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009027 }
9028
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009029 /* adjust igu_sb_cnt to MF for E1x */
9030 if (CHIP_IS_E1x(bp) && IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009031 bp->igu_sb_cnt /= E1HVN_MAX;
9032
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009033 /* port info */
9034 bnx2x_get_port_hwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009035
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009036 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009037 bp->fw_seq =
9038 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
9039 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009040 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
9041 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009042
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009043 /* Get MAC addresses */
9044 bnx2x_get_mac_hwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009045
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00009046#ifdef BCM_CNIC
9047 bnx2x_get_cnic_info(bp);
9048#endif
9049
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009050 /* Get current FW pulse sequence */
9051 if (!BP_NOMCP(bp)) {
9052 int mb_idx = BP_FW_MB_IDX(bp);
9053
9054 bp->fw_drv_pulse_wr_seq =
9055 (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
9056 DRV_PULSE_SEQ_MASK);
9057 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
9058 }
9059
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009060 return rc;
9061}
9062
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00009063static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
9064{
9065 int cnt, i, block_end, rodi;
9066 char vpd_data[BNX2X_VPD_LEN+1];
9067 char str_id_reg[VENDOR_ID_LEN+1];
9068 char str_id_cap[VENDOR_ID_LEN+1];
9069 u8 len;
9070
9071 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
9072 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
9073
9074 if (cnt < BNX2X_VPD_LEN)
9075 goto out_not_found;
9076
9077 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
9078 PCI_VPD_LRDT_RO_DATA);
9079 if (i < 0)
9080 goto out_not_found;
9081
9082
9083 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
9084 pci_vpd_lrdt_size(&vpd_data[i]);
9085
9086 i += PCI_VPD_LRDT_TAG_SIZE;
9087
9088 if (block_end > BNX2X_VPD_LEN)
9089 goto out_not_found;
9090
9091 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9092 PCI_VPD_RO_KEYWORD_MFR_ID);
9093 if (rodi < 0)
9094 goto out_not_found;
9095
9096 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9097
9098 if (len != VENDOR_ID_LEN)
9099 goto out_not_found;
9100
9101 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9102
9103 /* vendor specific info */
9104 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
9105 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
9106 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
9107 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
9108
9109 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9110 PCI_VPD_RO_KEYWORD_VENDOR0);
9111 if (rodi >= 0) {
9112 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9113
9114 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9115
9116 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
9117 memcpy(bp->fw_ver, &vpd_data[rodi], len);
9118 bp->fw_ver[len] = ' ';
9119 }
9120 }
9121 return;
9122 }
9123out_not_found:
9124 return;
9125}
9126
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009127static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
9128{
9129 u32 flags = 0;
9130
9131 if (CHIP_REV_IS_FPGA(bp))
9132 SET_FLAGS(flags, MODE_FPGA);
9133 else if (CHIP_REV_IS_EMUL(bp))
9134 SET_FLAGS(flags, MODE_EMUL);
9135 else
9136 SET_FLAGS(flags, MODE_ASIC);
9137
9138 if (CHIP_MODE_IS_4_PORT(bp))
9139 SET_FLAGS(flags, MODE_PORT4);
9140 else
9141 SET_FLAGS(flags, MODE_PORT2);
9142
9143 if (CHIP_IS_E2(bp))
9144 SET_FLAGS(flags, MODE_E2);
9145 else if (CHIP_IS_E3(bp)) {
9146 SET_FLAGS(flags, MODE_E3);
9147 if (CHIP_REV(bp) == CHIP_REV_Ax)
9148 SET_FLAGS(flags, MODE_E3_A0);
9149 else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
9150 SET_FLAGS(flags, MODE_E3_B0);
9151 SET_FLAGS(flags, MODE_COS_BC);
9152 }
9153 }
9154
9155 if (IS_MF(bp)) {
9156 SET_FLAGS(flags, MODE_MF);
9157 switch (bp->mf_mode) {
9158 case MULTI_FUNCTION_SD:
9159 SET_FLAGS(flags, MODE_MF_SD);
9160 break;
9161 case MULTI_FUNCTION_SI:
9162 SET_FLAGS(flags, MODE_MF_SI);
9163 break;
9164 }
9165 } else
9166 SET_FLAGS(flags, MODE_SF);
9167
9168#if defined(__LITTLE_ENDIAN)
9169 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
9170#else /*(__BIG_ENDIAN)*/
9171 SET_FLAGS(flags, MODE_BIG_ENDIAN);
9172#endif
9173 INIT_MODE_FLAGS(bp) = flags;
9174}
9175
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009176static int __devinit bnx2x_init_bp(struct bnx2x *bp)
9177{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009178 int func;
Eilon Greenstein87942b42009-02-12 08:36:49 +00009179 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009180 int rc;
9181
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009182 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07009183 mutex_init(&bp->fw_mb_mutex);
David S. Millerbb7e95c2010-07-27 21:01:35 -07009184 spin_lock_init(&bp->stats_lock);
Michael Chan993ac7b2009-10-10 13:46:56 +00009185#ifdef BCM_CNIC
9186 mutex_init(&bp->cnic_mutex);
9187#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009188
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08009189 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009190 INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009191
9192 rc = bnx2x_get_hwinfo(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009193 if (rc)
9194 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009195
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009196 bnx2x_set_modes_bitmap(bp);
9197
9198 rc = bnx2x_alloc_mem_bp(bp);
9199 if (rc)
9200 return rc;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009201
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00009202 bnx2x_read_fwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009203
9204 func = BP_FUNC(bp);
9205
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009206 /* need to reset chip if undi was active */
9207 if (!BP_NOMCP(bp))
9208 bnx2x_undi_unload(bp);
9209
9210 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009211 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009212
9213 if (BP_NOMCP(bp) && (func == 0))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009214 dev_err(&bp->pdev->dev, "MCP disabled, "
9215 "must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009216
Eilon Greenstein555f6c72009-02-12 08:36:11 +00009217 bp->multi_mode = multi_mode;
Eilon Greenstein555f6c72009-02-12 08:36:11 +00009218
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009219 /* Set TPA flags */
9220 if (disable_tpa) {
9221 bp->flags &= ~TPA_ENABLE_FLAG;
9222 bp->dev->features &= ~NETIF_F_LRO;
9223 } else {
9224 bp->flags |= TPA_ENABLE_FLAG;
9225 bp->dev->features |= NETIF_F_LRO;
9226 }
Dmitry Kravkov5d7cd492010-07-27 12:32:19 +00009227 bp->disable_tpa = disable_tpa;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009228
Eilon Greensteina18f5122009-08-12 08:23:26 +00009229 if (CHIP_IS_E1(bp))
9230 bp->dropless_fc = 0;
9231 else
9232 bp->dropless_fc = dropless_fc;
9233
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00009234 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009235
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009236 bp->tx_ring_size = MAX_TX_AVAIL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009237
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00009238 /* make sure that the numbers are in the right granularity */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009239 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
9240 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009241
Eilon Greenstein87942b42009-02-12 08:36:49 +00009242 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9243 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009244
9245 init_timer(&bp->timer);
9246 bp->timer.expires = jiffies + bp->current_interval;
9247 bp->timer.data = (unsigned long) bp;
9248 bp->timer.function = bnx2x_timer;
9249
Shmulik Ravid785b9b12010-12-30 06:27:03 +00009250 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00009251 bnx2x_dcbx_init_params(bp);
9252
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009253#ifdef BCM_CNIC
9254 if (CHIP_IS_E1x(bp))
9255 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
9256 else
9257 bp->cnic_base_cl_id = FP_SB_MAX_E2;
9258#endif
9259
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009260 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009261}
9262
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009263
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00009264/****************************************************************************
9265* General service functions
9266****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009267
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009268/*
9269 * net_device service functions
9270 */
9271
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009272/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009273static int bnx2x_open(struct net_device *dev)
9274{
9275 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009276 bool global = false;
9277 int other_engine = BP_PATH(bp) ? 0 : 1;
9278 u32 other_load_counter, load_counter;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009279
Eilon Greenstein6eccabb2009-01-22 03:37:48 +00009280 netif_carrier_off(dev);
9281
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009282 bnx2x_set_power_state(bp, PCI_D0);
9283
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009284 other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
9285 load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009286
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009287 /*
9288 * If parity had happen during the unload, then attentions
9289 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
9290 * want the first function loaded on the current engine to
9291 * complete the recovery.
9292 */
9293 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
9294 bnx2x_chk_parity_attn(bp, &global, true))
9295 do {
9296 /*
9297 * If there are attentions and they are in a global
9298 * blocks, set the GLOBAL_RESET bit regardless whether
9299 * it will be this function that will complete the
9300 * recovery or not.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009301 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009302 if (global)
9303 bnx2x_set_reset_global(bp);
9304
9305 /*
9306 * Only the first function on the current engine should
9307 * try to recover in open. In case of attentions in
9308 * global blocks only the first in the chip should try
9309 * to recover.
9310 */
9311 if ((!load_counter &&
9312 (!global || !other_load_counter)) &&
9313 bnx2x_trylock_leader_lock(bp) &&
9314 !bnx2x_leader_reset(bp)) {
9315 netdev_info(bp->dev, "Recovered in open\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009316 break;
9317 }
9318
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009319 /* recovery has failed... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009320 bnx2x_set_power_state(bp, PCI_D3hot);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009321 bp->recovery_state = BNX2X_RECOVERY_FAILED;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009322
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009323 netdev_err(bp->dev, "Recovery flow hasn't been properly"
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009324 " completed yet. Try again later. If u still see this"
9325 " message after a few retries then power cycle is"
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009326 " required.\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009327
9328 return -EAGAIN;
9329 } while (0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009330
9331 bp->recovery_state = BNX2X_RECOVERY_DONE;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009332 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009333}
9334
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009335/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009336static int bnx2x_close(struct net_device *dev)
9337{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009338 struct bnx2x *bp = netdev_priv(dev);
9339
9340 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009341 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009342
9343 /* Power off */
Vladislav Zolotarovd3dbfee2010-04-19 01:14:49 +00009344 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009345
9346 return 0;
9347}
9348
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009349static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
9350 struct bnx2x_mcast_ramrod_params *p)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009351{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009352 int mc_count = netdev_mc_count(bp->dev);
9353 struct bnx2x_mcast_list_elem *mc_mac =
9354 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009355 struct netdev_hw_addr *ha;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009356
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009357 if (!mc_mac)
9358 return -ENOMEM;
9359
9360 INIT_LIST_HEAD(&p->mcast_list);
9361
9362 netdev_for_each_mc_addr(ha, bp->dev) {
9363 mc_mac->mac = bnx2x_mc_addr(ha);
9364 list_add_tail(&mc_mac->link, &p->mcast_list);
9365 mc_mac++;
9366 }
9367
9368 p->mcast_list_len = mc_count;
9369
9370 return 0;
9371}
9372
9373static inline void bnx2x_free_mcast_macs_list(
9374 struct bnx2x_mcast_ramrod_params *p)
9375{
9376 struct bnx2x_mcast_list_elem *mc_mac =
9377 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
9378 link);
9379
9380 WARN_ON(!mc_mac);
9381 kfree(mc_mac);
9382}
9383
9384/**
9385 * bnx2x_set_uc_list - configure a new unicast MACs list.
9386 *
9387 * @bp: driver handle
9388 *
9389 * We will use zero (0) as a MAC type for these MACs.
9390 */
9391static inline int bnx2x_set_uc_list(struct bnx2x *bp)
9392{
9393 int rc;
9394 struct net_device *dev = bp->dev;
9395 struct netdev_hw_addr *ha;
9396 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
9397 unsigned long ramrod_flags = 0;
9398
9399 /* First schedule a cleanup up of old configuration */
9400 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
9401 if (rc < 0) {
9402 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
9403 return rc;
9404 }
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009405
9406 netdev_for_each_uc_addr(ha, dev) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009407 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
9408 BNX2X_UC_LIST_MAC, &ramrod_flags);
9409 if (rc < 0) {
9410 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
9411 rc);
9412 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009413 }
9414 }
9415
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009416 /* Execute the pending commands */
9417 __set_bit(RAMROD_CONT, &ramrod_flags);
9418 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
9419 BNX2X_UC_LIST_MAC, &ramrod_flags);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009420}
9421
9422static inline int bnx2x_set_mc_list(struct bnx2x *bp)
9423{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009424 struct net_device *dev = bp->dev;
9425 struct bnx2x_mcast_ramrod_params rparam = {0};
9426 int rc = 0;
9427
9428 rparam.mcast_obj = &bp->mcast_obj;
9429
9430 /* first, clear all configured multicast MACs */
9431 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9432 if (rc < 0) {
9433 BNX2X_ERR("Failed to clear multicast "
9434 "configuration: %d\n", rc);
9435 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009436 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009437
9438 /* then, configure a new MACs list */
9439 if (netdev_mc_count(dev)) {
9440 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
9441 if (rc) {
9442 BNX2X_ERR("Failed to create multicast MACs "
9443 "list: %d\n", rc);
9444 return rc;
9445 }
9446
9447 /* Now add the new MACs */
9448 rc = bnx2x_config_mcast(bp, &rparam,
9449 BNX2X_MCAST_CMD_ADD);
9450 if (rc < 0)
9451 BNX2X_ERR("Failed to set a new multicast "
9452 "configuration: %d\n", rc);
9453
9454 bnx2x_free_mcast_macs_list(&rparam);
9455 }
9456
9457 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009458}
9459
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009460
9461/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009462void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009463{
9464 struct bnx2x *bp = netdev_priv(dev);
9465 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009466
9467 if (bp->state != BNX2X_STATE_OPEN) {
9468 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
9469 return;
9470 }
9471
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009472 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009473
9474 if (dev->flags & IFF_PROMISC)
9475 rx_mode = BNX2X_RX_MODE_PROMISC;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009476 else if ((dev->flags & IFF_ALLMULTI) ||
9477 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
9478 CHIP_IS_E1(bp)))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009479 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009480 else {
9481 /* some multicasts */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009482 if (bnx2x_set_mc_list(bp) < 0)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009483 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009484
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009485 if (bnx2x_set_uc_list(bp) < 0)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009486 rx_mode = BNX2X_RX_MODE_PROMISC;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009487 }
9488
9489 bp->rx_mode = rx_mode;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009490
9491 /* Schedule the rx_mode command */
9492 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
9493 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9494 return;
9495 }
9496
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009497 bnx2x_set_storm_rx_mode(bp);
9498}
9499
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009500/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009501static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
9502 int devad, u16 addr)
9503{
9504 struct bnx2x *bp = netdev_priv(netdev);
9505 u16 value;
9506 int rc;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009507
9508 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
9509 prtad, devad, addr);
9510
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009511 /* The HW expects different devad if CL22 is used */
9512 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9513
9514 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009515 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009516 bnx2x_release_phy_lock(bp);
9517 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
9518
9519 if (!rc)
9520 rc = value;
9521 return rc;
9522}
9523
9524/* called with rtnl_lock */
9525static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
9526 u16 addr, u16 value)
9527{
9528 struct bnx2x *bp = netdev_priv(netdev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009529 int rc;
9530
9531 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
9532 " value 0x%x\n", prtad, devad, addr, value);
9533
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009534 /* The HW expects different devad if CL22 is used */
9535 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9536
9537 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009538 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009539 bnx2x_release_phy_lock(bp);
9540 return rc;
9541}
9542
9543/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009544static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
9545{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009546 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009547 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009548
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009549 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
9550 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009551
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009552 if (!netif_running(dev))
9553 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009554
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009555 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009556}
9557
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00009558#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009559static void poll_bnx2x(struct net_device *dev)
9560{
9561 struct bnx2x *bp = netdev_priv(dev);
9562
9563 disable_irq(bp->pdev->irq);
9564 bnx2x_interrupt(bp->pdev->irq, dev);
9565 enable_irq(bp->pdev->irq);
9566}
9567#endif
9568
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009569static const struct net_device_ops bnx2x_netdev_ops = {
9570 .ndo_open = bnx2x_open,
9571 .ndo_stop = bnx2x_close,
9572 .ndo_start_xmit = bnx2x_start_xmit,
Vladislav Zolotarov8307fa32010-12-13 05:44:09 +00009573 .ndo_select_queue = bnx2x_select_queue,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009574 .ndo_set_rx_mode = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009575 .ndo_set_mac_address = bnx2x_change_mac_addr,
9576 .ndo_validate_addr = eth_validate_addr,
9577 .ndo_do_ioctl = bnx2x_ioctl,
9578 .ndo_change_mtu = bnx2x_change_mtu,
Michał Mirosław66371c42011-04-12 09:38:23 +00009579 .ndo_fix_features = bnx2x_fix_features,
9580 .ndo_set_features = bnx2x_set_features,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009581 .ndo_tx_timeout = bnx2x_tx_timeout,
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00009582#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009583 .ndo_poll_controller = poll_bnx2x,
9584#endif
9585};
9586
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009587static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
9588{
9589 struct device *dev = &bp->pdev->dev;
9590
9591 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
9592 bp->flags |= USING_DAC_FLAG;
9593 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
9594 dev_err(dev, "dma_set_coherent_mask failed, "
9595 "aborting\n");
9596 return -EIO;
9597 }
9598 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
9599 dev_err(dev, "System does not support DMA, aborting\n");
9600 return -EIO;
9601 }
9602
9603 return 0;
9604}
9605
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009606static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009607 struct net_device *dev,
9608 unsigned long board_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009609{
9610 struct bnx2x *bp;
9611 int rc;
9612
9613 SET_NETDEV_DEV(dev, &pdev->dev);
9614 bp = netdev_priv(dev);
9615
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009616 bp->dev = dev;
9617 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009618 bp->flags = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009619 bp->pf_num = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009620
9621 rc = pci_enable_device(pdev);
9622 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009623 dev_err(&bp->pdev->dev,
9624 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009625 goto err_out;
9626 }
9627
9628 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009629 dev_err(&bp->pdev->dev,
9630 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009631 rc = -ENODEV;
9632 goto err_out_disable;
9633 }
9634
9635 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009636 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
9637 " base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009638 rc = -ENODEV;
9639 goto err_out_disable;
9640 }
9641
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009642 if (atomic_read(&pdev->enable_cnt) == 1) {
9643 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
9644 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009645 dev_err(&bp->pdev->dev,
9646 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009647 goto err_out_disable;
9648 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009649
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009650 pci_set_master(pdev);
9651 pci_save_state(pdev);
9652 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009653
9654 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
9655 if (bp->pm_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009656 dev_err(&bp->pdev->dev,
9657 "Cannot find power management capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009658 rc = -EIO;
9659 goto err_out_release;
9660 }
9661
9662 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
9663 if (bp->pcie_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009664 dev_err(&bp->pdev->dev,
9665 "Cannot find PCI Express capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009666 rc = -EIO;
9667 goto err_out_release;
9668 }
9669
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009670 rc = bnx2x_set_coherency_mask(bp);
9671 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009672 goto err_out_release;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009673
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009674 dev->mem_start = pci_resource_start(pdev, 0);
9675 dev->base_addr = dev->mem_start;
9676 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009677
9678 dev->irq = pdev->irq;
9679
Arjan van de Ven275f1652008-10-20 21:42:39 -07009680 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009681 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009682 dev_err(&bp->pdev->dev,
9683 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009684 rc = -ENOMEM;
9685 goto err_out_release;
9686 }
9687
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009688 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009689 min_t(u64, BNX2X_DB_SIZE(bp),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009690 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009691 if (!bp->doorbells) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009692 dev_err(&bp->pdev->dev,
9693 "Cannot map doorbell space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009694 rc = -ENOMEM;
9695 goto err_out_unmap;
9696 }
9697
9698 bnx2x_set_power_state(bp, PCI_D0);
9699
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009700 /* clean indirect addresses */
9701 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
9702 PCICFG_VENDOR_ID_OFFSET);
9703 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
9704 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
9705 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
9706 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009707
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009708 /**
9709 * Enable internal target-read (in case we are probed after PF FLR).
9710 * Must be done prior to any BAR read access
9711 */
9712 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
9713
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009714 /* Reset the load counter */
9715 bnx2x_clear_load_cnt(bp);
9716
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009717 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009718
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009719 dev->netdev_ops = &bnx2x_netdev_ops;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00009720 bnx2x_set_ethtool_ops(dev);
Michał Mirosław66371c42011-04-12 09:38:23 +00009721
9722 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9723 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
9724 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
9725
9726 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9727 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
9728
9729 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009730 if (bp->flags & USING_DAC_FLAG)
9731 dev->features |= NETIF_F_HIGHDMA;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009732
Mahesh Bandewar538dd2e2011-05-13 15:08:49 +00009733 /* Add Loopback capability to the device */
9734 dev->hw_features |= NETIF_F_LOOPBACK;
9735
Shmulik Ravid98507672011-02-28 12:19:55 -08009736#ifdef BCM_DCBNL
Shmulik Ravid785b9b12010-12-30 06:27:03 +00009737 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
9738#endif
9739
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009740 /* get_port_hwinfo() will set prtad and mmds properly */
9741 bp->mdio.prtad = MDIO_PRTAD_NONE;
9742 bp->mdio.mmds = 0;
9743 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9744 bp->mdio.dev = dev;
9745 bp->mdio.mdio_read = bnx2x_mdio_read;
9746 bp->mdio.mdio_write = bnx2x_mdio_write;
9747
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009748 return 0;
9749
9750err_out_unmap:
9751 if (bp->regview) {
9752 iounmap(bp->regview);
9753 bp->regview = NULL;
9754 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009755 if (bp->doorbells) {
9756 iounmap(bp->doorbells);
9757 bp->doorbells = NULL;
9758 }
9759
9760err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009761 if (atomic_read(&pdev->enable_cnt) == 1)
9762 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009763
9764err_out_disable:
9765 pci_disable_device(pdev);
9766 pci_set_drvdata(pdev, NULL);
9767
9768err_out:
9769 return rc;
9770}
9771
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009772static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
9773 int *width, int *speed)
Eliezer Tamir25047952008-02-28 11:50:16 -08009774{
9775 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
9776
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009777 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
9778
9779 /* return value of 1=2.5GHz 2=5GHz */
9780 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
Eliezer Tamir25047952008-02-28 11:50:16 -08009781}
9782
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009783static int bnx2x_check_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009784{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009785 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009786 struct bnx2x_fw_file_hdr *fw_hdr;
9787 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009788 u32 offset, len, num_ops;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009789 u16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009790 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009791 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009792
9793 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
9794 return -EINVAL;
9795
9796 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
9797 sections = (struct bnx2x_fw_file_section *)fw_hdr;
9798
9799 /* Make sure none of the offsets and sizes make us read beyond
9800 * the end of the firmware data */
9801 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
9802 offset = be32_to_cpu(sections[i].offset);
9803 len = be32_to_cpu(sections[i].len);
9804 if (offset + len > firmware->size) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009805 dev_err(&bp->pdev->dev,
9806 "Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009807 return -EINVAL;
9808 }
9809 }
9810
9811 /* Likewise for the init_ops offsets */
9812 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
9813 ops_offsets = (u16 *)(firmware->data + offset);
9814 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
9815
9816 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
9817 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009818 dev_err(&bp->pdev->dev,
9819 "Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009820 return -EINVAL;
9821 }
9822 }
9823
9824 /* Check FW version */
9825 offset = be32_to_cpu(fw_hdr->fw_version.offset);
9826 fw_ver = firmware->data + offset;
9827 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
9828 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
9829 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
9830 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009831 dev_err(&bp->pdev->dev,
9832 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009833 fw_ver[0], fw_ver[1], fw_ver[2],
9834 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
9835 BCM_5710_FW_MINOR_VERSION,
9836 BCM_5710_FW_REVISION_VERSION,
9837 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009838 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009839 }
9840
9841 return 0;
9842}
9843
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009844static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009845{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009846 const __be32 *source = (const __be32 *)_source;
9847 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009848 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009849
9850 for (i = 0; i < n/4; i++)
9851 target[i] = be32_to_cpu(source[i]);
9852}
9853
9854/*
9855 Ops array is stored in the following format:
9856 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
9857 */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009858static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009859{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009860 const __be32 *source = (const __be32 *)_source;
9861 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009862 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009863
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009864 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009865 tmp = be32_to_cpu(source[j]);
9866 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009867 target[i].offset = tmp & 0xffffff;
9868 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009869 }
9870}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009871
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009872/**
9873 * IRO array is stored in the following format:
9874 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
9875 */
9876static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
9877{
9878 const __be32 *source = (const __be32 *)_source;
9879 struct iro *target = (struct iro *)_target;
9880 u32 i, j, tmp;
9881
9882 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
9883 target[i].base = be32_to_cpu(source[j]);
9884 j++;
9885 tmp = be32_to_cpu(source[j]);
9886 target[i].m1 = (tmp >> 16) & 0xffff;
9887 target[i].m2 = tmp & 0xffff;
9888 j++;
9889 tmp = be32_to_cpu(source[j]);
9890 target[i].m3 = (tmp >> 16) & 0xffff;
9891 target[i].size = tmp & 0xffff;
9892 j++;
9893 }
9894}
9895
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009896static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009897{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009898 const __be16 *source = (const __be16 *)_source;
9899 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009900 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009901
9902 for (i = 0; i < n/2; i++)
9903 target[i] = be16_to_cpu(source[i]);
9904}
9905
Joe Perches7995c642010-02-17 15:01:52 +00009906#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
9907do { \
9908 u32 len = be32_to_cpu(fw_hdr->arr.len); \
9909 bp->arr = kmalloc(len, GFP_KERNEL); \
9910 if (!bp->arr) { \
9911 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
9912 goto lbl; \
9913 } \
9914 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
9915 (u8 *)bp->arr, len); \
9916} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009917
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009918int bnx2x_init_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009919{
Ben Hutchings45229b42009-11-07 11:53:39 +00009920 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009921 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +00009922 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009923
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009924 if (CHIP_IS_E1(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00009925 fw_file_name = FW_FILE_NAME_E1;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009926 else if (CHIP_IS_E1H(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00009927 fw_file_name = FW_FILE_NAME_E1H;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009928 else if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009929 fw_file_name = FW_FILE_NAME_E2;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009930 else {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009931 BNX2X_ERR("Unsupported chip revision\n");
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009932 return -EINVAL;
9933 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009934
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009935 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009936
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009937 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009938 if (rc) {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009939 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009940 goto request_firmware_exit;
9941 }
9942
9943 rc = bnx2x_check_firmware(bp);
9944 if (rc) {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009945 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009946 goto request_firmware_exit;
9947 }
9948
9949 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
9950
9951 /* Initialize the pointers to the init arrays */
9952 /* Blob */
9953 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
9954
9955 /* Opcodes */
9956 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
9957
9958 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009959 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
9960 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009961
9962 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +00009963 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9964 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
9965 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
9966 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
9967 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9968 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
9969 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
9970 be32_to_cpu(fw_hdr->usem_pram_data.offset);
9971 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9972 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
9973 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
9974 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
9975 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9976 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
9977 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
9978 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009979 /* IRO */
9980 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009981
9982 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009983
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009984iro_alloc_err:
9985 kfree(bp->init_ops_offsets);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009986init_offsets_alloc_err:
9987 kfree(bp->init_ops);
9988init_ops_alloc_err:
9989 kfree(bp->init_data);
9990request_firmware_exit:
9991 release_firmware(bp->firmware);
9992
9993 return rc;
9994}
9995
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009996static void bnx2x_release_firmware(struct bnx2x *bp)
9997{
9998 kfree(bp->init_ops_offsets);
9999 kfree(bp->init_ops);
10000 kfree(bp->init_data);
10001 release_firmware(bp->firmware);
10002}
10003
10004
10005static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
10006 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
10007 .init_hw_cmn = bnx2x_init_hw_common,
10008 .init_hw_port = bnx2x_init_hw_port,
10009 .init_hw_func = bnx2x_init_hw_func,
10010
10011 .reset_hw_cmn = bnx2x_reset_common,
10012 .reset_hw_port = bnx2x_reset_port,
10013 .reset_hw_func = bnx2x_reset_func,
10014
10015 .gunzip_init = bnx2x_gunzip_init,
10016 .gunzip_end = bnx2x_gunzip_end,
10017
10018 .init_fw = bnx2x_init_firmware,
10019 .release_fw = bnx2x_release_firmware,
10020};
10021
10022void bnx2x__init_func_obj(struct bnx2x *bp)
10023{
10024 /* Prepare DMAE related driver resources */
10025 bnx2x_setup_dmae(bp);
10026
10027 bnx2x_init_func_obj(bp, &bp->func_obj,
10028 bnx2x_sp(bp, func_rdata),
10029 bnx2x_sp_mapping(bp, func_rdata),
10030 &bnx2x_func_sp_drv);
10031}
10032
10033/* must be called after sriov-enable */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010034static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count)
10035{
10036 int cid_count = L2_FP_COUNT(l2_cid_count);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070010037
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010038#ifdef BCM_CNIC
10039 cid_count += CNIC_CID_MAX;
10040#endif
10041 return roundup(cid_count, QM_CID_ROUND);
10042}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010043
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010044/**
10045 * bnx2x_pci_msix_table_size - get the size of the MSI-X table.
10046 *
10047 * @dev: pci device
10048 *
10049 */
10050static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev)
10051{
10052 int pos;
10053 u16 control;
10054
10055 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
10056 if (!pos)
10057 return 0;
10058
10059 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
10060 return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
10061}
10062
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010063static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10064 const struct pci_device_id *ent)
10065{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010066 struct net_device *dev = NULL;
10067 struct bnx2x *bp;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000010068 int pcie_width, pcie_speed;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010069 int rc, cid_count;
10070
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010071 switch (ent->driver_data) {
10072 case BCM57710:
10073 case BCM57711:
10074 case BCM57711E:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010075 case BCM57712:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010076 case BCM57712_MF:
10077 case BCM57800:
10078 case BCM57800_MF:
10079 case BCM57810:
10080 case BCM57810_MF:
10081 case BCM57840:
10082 case BCM57840_MF:
10083 /* The size requested for the MSI-X table corresponds to the
10084 * actual amount of avaliable IGU/HC status blocks. It includes
10085 * the default SB vector but we want cid_count to contain the
10086 * amount of only non-default SBs, that's what '-1' stands for.
10087 */
10088 cid_count = bnx2x_pci_msix_table_size(pdev) - 1;
10089
10090 /* do not allow initial cid_count grow above 16
10091 * since Special CIDs starts from this number
10092 * use old FP_SB_MAX_E1x define for this matter
10093 */
10094 cid_count = min_t(int, FP_SB_MAX_E1x, cid_count);
10095
10096 WARN_ON(!cid_count);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010097 break;
10098
10099 default:
10100 pr_err("Unknown board_type (%ld), aborting\n",
10101 ent->driver_data);
Vasiliy Kulikov870634b2010-11-14 10:08:34 +000010102 return -ENODEV;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010103 }
10104
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010105 cid_count += FCOE_CONTEXT_USE;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010106
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010107 /* dev zeroed in init_etherdev */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010108 dev = alloc_etherdev_mq(sizeof(*bp), cid_count);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010109 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010110 dev_err(&pdev->dev, "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010111 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010112 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010113
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010114 /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring,
10115 * so update a cid_count after a netdev allocation.
10116 */
10117 cid_count += CNIC_CONTEXT_USE;
10118
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010119 bp = netdev_priv(dev);
Joe Perches7995c642010-02-17 15:01:52 +000010120 bp->msg_enable = debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010121
Eilon Greensteindf4770de2009-08-12 08:23:28 +000010122 pci_set_drvdata(pdev, dev);
10123
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010124 bp->l2_cid_count = cid_count;
10125
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010126 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010127 if (rc < 0) {
10128 free_netdev(dev);
10129 return rc;
10130 }
10131
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010132 BNX2X_DEV_INFO("cid_count=%d\n", cid_count);
10133
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010134 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000010135 if (rc)
10136 goto init_one_exit;
10137
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010138 /* calc qm_cid_count */
10139 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count);
10140
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010141#ifdef BCM_CNIC
10142 /* disable FCOE L2 queue for E1x*/
10143 if (CHIP_IS_E1x(bp))
10144 bp->flags |= NO_FCOE_FLAG;
10145
10146#endif
10147
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010148 /* Configure interrupt mode: try to enable MSI-X/MSI if
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010149 * needed, set bp->num_queues appropriately.
10150 */
10151 bnx2x_set_int_mode(bp);
10152
10153 /* Add all NAPI objects */
10154 bnx2x_add_all_napi(bp);
10155
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080010156 rc = register_netdev(dev);
10157 if (rc) {
10158 dev_err(&pdev->dev, "Cannot register net device\n");
10159 goto init_one_exit;
10160 }
10161
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010162#ifdef BCM_CNIC
10163 if (!NO_FCOE(bp)) {
10164 /* Add storage MAC address */
10165 rtnl_lock();
10166 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10167 rtnl_unlock();
10168 }
10169#endif
10170
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000010171 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010172
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010173 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
10174 " IRQ %d, ", board_info[ent->driver_data].name,
10175 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010176 pcie_width,
10177 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
10178 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
10179 "5GHz (Gen2)" : "2.5GHz",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010180 dev->base_addr, bp->pdev->irq);
10181 pr_cont("node addr %pM\n", dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000010182
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010183 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010184
10185init_one_exit:
10186 if (bp->regview)
10187 iounmap(bp->regview);
10188
10189 if (bp->doorbells)
10190 iounmap(bp->doorbells);
10191
10192 free_netdev(dev);
10193
10194 if (atomic_read(&pdev->enable_cnt) == 1)
10195 pci_release_regions(pdev);
10196
10197 pci_disable_device(pdev);
10198 pci_set_drvdata(pdev, NULL);
10199
10200 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010201}
10202
10203static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10204{
10205 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080010206 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010207
Eliezer Tamir228241e2008-02-28 11:56:57 -080010208 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010209 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
Eliezer Tamir228241e2008-02-28 11:56:57 -080010210 return;
10211 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080010212 bp = netdev_priv(dev);
10213
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010214#ifdef BCM_CNIC
10215 /* Delete storage MAC address */
10216 if (!NO_FCOE(bp)) {
10217 rtnl_lock();
10218 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10219 rtnl_unlock();
10220 }
10221#endif
10222
Shmulik Ravid98507672011-02-28 12:19:55 -080010223#ifdef BCM_DCBNL
10224 /* Delete app tlvs from dcbnl */
10225 bnx2x_dcbnl_update_applist(bp, true);
10226#endif
10227
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010228 unregister_netdev(dev);
10229
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010230 /* Delete all NAPI objects */
10231 bnx2x_del_all_napi(bp);
10232
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000010233 /* Power on: we can't let PCI layer write to us while we are in D3 */
10234 bnx2x_set_power_state(bp, PCI_D0);
10235
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010236 /* Disable MSI/MSI-X */
10237 bnx2x_disable_msi(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010238
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000010239 /* Power off */
10240 bnx2x_set_power_state(bp, PCI_D3hot);
10241
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010242 /* Make sure RESET task is not scheduled before continuing */
10243 cancel_delayed_work_sync(&bp->reset_task);
10244
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010245 if (bp->regview)
10246 iounmap(bp->regview);
10247
10248 if (bp->doorbells)
10249 iounmap(bp->doorbells);
10250
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010251 bnx2x_free_mem_bp(bp);
10252
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010253 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010254
10255 if (atomic_read(&pdev->enable_cnt) == 1)
10256 pci_release_regions(pdev);
10257
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010258 pci_disable_device(pdev);
10259 pci_set_drvdata(pdev, NULL);
10260}
10261
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010262static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
10263{
10264 int i;
10265
10266 bp->state = BNX2X_STATE_ERROR;
10267
10268 bp->rx_mode = BNX2X_RX_MODE_NONE;
10269
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010270#ifdef BCM_CNIC
10271 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
10272#endif
10273 /* Stop Tx */
10274 bnx2x_tx_disable(bp);
10275
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010276 bnx2x_netif_stop(bp, 0);
10277
10278 del_timer_sync(&bp->timer);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010279
10280 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010281
10282 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010283 bnx2x_free_irq(bp);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010284
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010285 /* Free SKBs, SGEs, TPA pool and driver internals */
10286 bnx2x_free_skbs(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010287
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010288 for_each_rx_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010289 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010290
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010291 bnx2x_free_mem(bp);
10292
10293 bp->state = BNX2X_STATE_CLOSED;
10294
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010295 netif_carrier_off(bp->dev);
10296
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010297 return 0;
10298}
10299
10300static void bnx2x_eeh_recover(struct bnx2x *bp)
10301{
10302 u32 val;
10303
10304 mutex_init(&bp->port.phy_mutex);
10305
10306 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
10307 bp->link_params.shmem_base = bp->common.shmem_base;
10308 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
10309
10310 if (!bp->common.shmem_base ||
10311 (bp->common.shmem_base < 0xA0000) ||
10312 (bp->common.shmem_base >= 0xC0000)) {
10313 BNX2X_DEV_INFO("MCP not active\n");
10314 bp->flags |= NO_MCP_FLAG;
10315 return;
10316 }
10317
10318 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
10319 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10320 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10321 BNX2X_ERR("BAD MCP validity signature\n");
10322
10323 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010324 bp->fw_seq =
10325 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10326 DRV_MSG_SEQ_NUMBER_MASK);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010327 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10328 }
10329}
10330
Wendy Xiong493adb12008-06-23 20:36:22 -070010331/**
10332 * bnx2x_io_error_detected - called when PCI error is detected
10333 * @pdev: Pointer to PCI device
10334 * @state: The current pci connection state
10335 *
10336 * This function is called after a PCI bus error affecting
10337 * this device has been detected.
10338 */
10339static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
10340 pci_channel_state_t state)
10341{
10342 struct net_device *dev = pci_get_drvdata(pdev);
10343 struct bnx2x *bp = netdev_priv(dev);
10344
10345 rtnl_lock();
10346
10347 netif_device_detach(dev);
10348
Dean Nelson07ce50e2009-07-31 09:13:25 +000010349 if (state == pci_channel_io_perm_failure) {
10350 rtnl_unlock();
10351 return PCI_ERS_RESULT_DISCONNECT;
10352 }
10353
Wendy Xiong493adb12008-06-23 20:36:22 -070010354 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010355 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070010356
10357 pci_disable_device(pdev);
10358
10359 rtnl_unlock();
10360
10361 /* Request a slot reset */
10362 return PCI_ERS_RESULT_NEED_RESET;
10363}
10364
10365/**
10366 * bnx2x_io_slot_reset - called after the PCI bus has been reset
10367 * @pdev: Pointer to PCI device
10368 *
10369 * Restart the card from scratch, as if from a cold-boot.
10370 */
10371static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
10372{
10373 struct net_device *dev = pci_get_drvdata(pdev);
10374 struct bnx2x *bp = netdev_priv(dev);
10375
10376 rtnl_lock();
10377
10378 if (pci_enable_device(pdev)) {
10379 dev_err(&pdev->dev,
10380 "Cannot re-enable PCI device after reset\n");
10381 rtnl_unlock();
10382 return PCI_ERS_RESULT_DISCONNECT;
10383 }
10384
10385 pci_set_master(pdev);
10386 pci_restore_state(pdev);
10387
10388 if (netif_running(dev))
10389 bnx2x_set_power_state(bp, PCI_D0);
10390
10391 rtnl_unlock();
10392
10393 return PCI_ERS_RESULT_RECOVERED;
10394}
10395
10396/**
10397 * bnx2x_io_resume - called when traffic can start flowing again
10398 * @pdev: Pointer to PCI device
10399 *
10400 * This callback is called when the error recovery driver tells us that
10401 * its OK to resume normal operation.
10402 */
10403static void bnx2x_io_resume(struct pci_dev *pdev)
10404{
10405 struct net_device *dev = pci_get_drvdata(pdev);
10406 struct bnx2x *bp = netdev_priv(dev);
10407
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010408 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010409 printk(KERN_ERR "Handling parity error recovery. "
10410 "Try again later\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010411 return;
10412 }
10413
Wendy Xiong493adb12008-06-23 20:36:22 -070010414 rtnl_lock();
10415
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010416 bnx2x_eeh_recover(bp);
10417
Wendy Xiong493adb12008-06-23 20:36:22 -070010418 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010419 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070010420
10421 netif_device_attach(dev);
10422
10423 rtnl_unlock();
10424}
10425
10426static struct pci_error_handlers bnx2x_err_handler = {
10427 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000010428 .slot_reset = bnx2x_io_slot_reset,
10429 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070010430};
10431
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010432static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070010433 .name = DRV_MODULE_NAME,
10434 .id_table = bnx2x_pci_tbl,
10435 .probe = bnx2x_init_one,
10436 .remove = __devexit_p(bnx2x_remove_one),
10437 .suspend = bnx2x_suspend,
10438 .resume = bnx2x_resume,
10439 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010440};
10441
10442static int __init bnx2x_init(void)
10443{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010444 int ret;
10445
Joe Perches7995c642010-02-17 15:01:52 +000010446 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +000010447
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010448 bnx2x_wq = create_singlethread_workqueue("bnx2x");
10449 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +000010450 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010451 return -ENOMEM;
10452 }
10453
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010454 ret = pci_register_driver(&bnx2x_pci_driver);
10455 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +000010456 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010457 destroy_workqueue(bnx2x_wq);
10458 }
10459 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010460}
10461
10462static void __exit bnx2x_cleanup(void)
10463{
10464 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010465
10466 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010467}
10468
10469module_init(bnx2x_init);
10470module_exit(bnx2x_cleanup);
10471
Michael Chan993ac7b2009-10-10 13:46:56 +000010472#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010473/**
10474 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
10475 *
10476 * @bp: driver handle
10477 * @set: set or clear the CAM entry
10478 *
10479 * This function will wait until the ramdord completion returns.
10480 * Return 0 if success, -ENODEV if ramrod doesn't return.
10481 */
10482static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
10483{
10484 unsigned long ramrod_flags = 0;
10485
10486 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
10487 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
10488 &bp->iscsi_l2_mac_obj, true,
10489 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
10490}
Michael Chan993ac7b2009-10-10 13:46:56 +000010491
10492/* count denotes the number of new completions we have seen */
10493static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
10494{
10495 struct eth_spe *spe;
10496
10497#ifdef BNX2X_STOP_ON_ERROR
10498 if (unlikely(bp->panic))
10499 return;
10500#endif
10501
10502 spin_lock_bh(&bp->spq_lock);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010503 BUG_ON(bp->cnic_spq_pending < count);
Michael Chan993ac7b2009-10-10 13:46:56 +000010504 bp->cnic_spq_pending -= count;
10505
Michael Chan993ac7b2009-10-10 13:46:56 +000010506
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010507 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
10508 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
10509 & SPE_HDR_CONN_TYPE) >>
10510 SPE_HDR_CONN_TYPE_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010511 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
10512 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010513
10514 /* Set validation for iSCSI L2 client before sending SETUP
10515 * ramrod
10516 */
10517 if (type == ETH_CONNECTION_TYPE) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010518 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010519 bnx2x_set_ctx_validation(bp, &bp->context.
10520 vcxt[BNX2X_ISCSI_ETH_CID].eth,
10521 BNX2X_ISCSI_ETH_CID);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010522 }
10523
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010524 /*
10525 * There may be not more than 8 L2, not more than 8 L5 SPEs
10526 * and in the air. We also check that number of outstanding
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010527 * COMMON ramrods is not more than the EQ and SPQ can
10528 * accommodate.
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010529 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010530 if (type == ETH_CONNECTION_TYPE) {
10531 if (!atomic_read(&bp->cq_spq_left))
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010532 break;
10533 else
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010534 atomic_dec(&bp->cq_spq_left);
10535 } else if (type == NONE_CONNECTION_TYPE) {
10536 if (!atomic_read(&bp->eq_spq_left))
10537 break;
10538 else
10539 atomic_dec(&bp->eq_spq_left);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010540 } else if ((type == ISCSI_CONNECTION_TYPE) ||
10541 (type == FCOE_CONNECTION_TYPE)) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010542 if (bp->cnic_spq_pending >=
10543 bp->cnic_eth_dev.max_kwqe_pending)
10544 break;
10545 else
10546 bp->cnic_spq_pending++;
10547 } else {
10548 BNX2X_ERR("Unknown SPE type: %d\n", type);
10549 bnx2x_panic();
Michael Chan993ac7b2009-10-10 13:46:56 +000010550 break;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010551 }
Michael Chan993ac7b2009-10-10 13:46:56 +000010552
10553 spe = bnx2x_sp_get_next(bp);
10554 *spe = *bp->cnic_kwq_cons;
10555
Michael Chan993ac7b2009-10-10 13:46:56 +000010556 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
10557 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
10558
10559 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
10560 bp->cnic_kwq_cons = bp->cnic_kwq;
10561 else
10562 bp->cnic_kwq_cons++;
10563 }
10564 bnx2x_sp_prod_update(bp);
10565 spin_unlock_bh(&bp->spq_lock);
10566}
10567
10568static int bnx2x_cnic_sp_queue(struct net_device *dev,
10569 struct kwqe_16 *kwqes[], u32 count)
10570{
10571 struct bnx2x *bp = netdev_priv(dev);
10572 int i;
10573
10574#ifdef BNX2X_STOP_ON_ERROR
10575 if (unlikely(bp->panic))
10576 return -EIO;
10577#endif
10578
10579 spin_lock_bh(&bp->spq_lock);
10580
10581 for (i = 0; i < count; i++) {
10582 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
10583
10584 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
10585 break;
10586
10587 *bp->cnic_kwq_prod = *spe;
10588
10589 bp->cnic_kwq_pending++;
10590
10591 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
10592 spe->hdr.conn_and_cmd_data, spe->hdr.type,
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010593 spe->data.update_data_addr.hi,
10594 spe->data.update_data_addr.lo,
Michael Chan993ac7b2009-10-10 13:46:56 +000010595 bp->cnic_kwq_pending);
10596
10597 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
10598 bp->cnic_kwq_prod = bp->cnic_kwq;
10599 else
10600 bp->cnic_kwq_prod++;
10601 }
10602
10603 spin_unlock_bh(&bp->spq_lock);
10604
10605 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
10606 bnx2x_cnic_sp_post(bp, 0);
10607
10608 return i;
10609}
10610
10611static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10612{
10613 struct cnic_ops *c_ops;
10614 int rc = 0;
10615
10616 mutex_lock(&bp->cnic_mutex);
Eric Dumazet13707f92011-01-26 19:28:23 +000010617 c_ops = rcu_dereference_protected(bp->cnic_ops,
10618 lockdep_is_held(&bp->cnic_mutex));
Michael Chan993ac7b2009-10-10 13:46:56 +000010619 if (c_ops)
10620 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10621 mutex_unlock(&bp->cnic_mutex);
10622
10623 return rc;
10624}
10625
10626static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10627{
10628 struct cnic_ops *c_ops;
10629 int rc = 0;
10630
10631 rcu_read_lock();
10632 c_ops = rcu_dereference(bp->cnic_ops);
10633 if (c_ops)
10634 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10635 rcu_read_unlock();
10636
10637 return rc;
10638}
10639
10640/*
10641 * for commands that have no data
10642 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000010643int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +000010644{
10645 struct cnic_ctl_info ctl = {0};
10646
10647 ctl.cmd = cmd;
10648
10649 return bnx2x_cnic_ctl_send(bp, &ctl);
10650}
10651
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010652static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
Michael Chan993ac7b2009-10-10 13:46:56 +000010653{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010654 struct cnic_ctl_info ctl = {0};
Michael Chan993ac7b2009-10-10 13:46:56 +000010655
10656 /* first we tell CNIC and only then we count this as a completion */
10657 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
10658 ctl.data.comp.cid = cid;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010659 ctl.data.comp.error = err;
Michael Chan993ac7b2009-10-10 13:46:56 +000010660
10661 bnx2x_cnic_ctl_send_bh(bp, &ctl);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010662 bnx2x_cnic_sp_post(bp, 0);
Michael Chan993ac7b2009-10-10 13:46:56 +000010663}
10664
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010665
10666/* Called with netif_addr_lock_bh() taken.
10667 * Sets an rx_mode config for an iSCSI ETH client.
10668 * Doesn't block.
10669 * Completion should be checked outside.
10670 */
10671static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
10672{
10673 unsigned long accept_flags = 0, ramrod_flags = 0;
10674 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
10675 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
10676
10677 if (start) {
10678 /* Start accepting on iSCSI L2 ring. Accept all multicasts
10679 * because it's the only way for UIO Queue to accept
10680 * multicasts (in non-promiscuous mode only one Queue per
10681 * function will receive multicast packets (leading in our
10682 * case).
10683 */
10684 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
10685 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
10686 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
10687 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
10688
10689 /* Clear STOP_PENDING bit if START is requested */
10690 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
10691
10692 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
10693 } else
10694 /* Clear START_PENDING bit if STOP is requested */
10695 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
10696
10697 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
10698 set_bit(sched_state, &bp->sp_state);
10699 else {
10700 __set_bit(RAMROD_RX, &ramrod_flags);
10701 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
10702 ramrod_flags);
10703 }
10704}
10705
10706
Michael Chan993ac7b2009-10-10 13:46:56 +000010707static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
10708{
10709 struct bnx2x *bp = netdev_priv(dev);
10710 int rc = 0;
10711
10712 switch (ctl->cmd) {
10713 case DRV_CTL_CTXTBL_WR_CMD: {
10714 u32 index = ctl->data.io.offset;
10715 dma_addr_t addr = ctl->data.io.dma_addr;
10716
10717 bnx2x_ilt_wr(bp, index, addr);
10718 break;
10719 }
10720
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010721 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
10722 int count = ctl->data.credit.credit_count;
Michael Chan993ac7b2009-10-10 13:46:56 +000010723
10724 bnx2x_cnic_sp_post(bp, count);
10725 break;
10726 }
10727
10728 /* rtnl_lock is held. */
10729 case DRV_CTL_START_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010730 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10731 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000010732
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010733 /* Configure the iSCSI classification object */
10734 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
10735 cp->iscsi_l2_client_id,
10736 cp->iscsi_l2_cid, BP_FUNC(bp),
10737 bnx2x_sp(bp, mac_rdata),
10738 bnx2x_sp_mapping(bp, mac_rdata),
10739 BNX2X_FILTER_MAC_PENDING,
10740 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
10741 &bp->macs_pool);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010742
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010743 /* Set iSCSI MAC address */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010744 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
10745 if (rc)
10746 break;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010747
10748 mmiowb();
10749 barrier();
10750
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010751 /* Start accepting on iSCSI L2 ring */
10752
10753 netif_addr_lock_bh(dev);
10754 bnx2x_set_iscsi_eth_rx_mode(bp, true);
10755 netif_addr_unlock_bh(dev);
10756
10757 /* bits to wait on */
10758 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10759 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
10760
10761 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10762 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010763
Michael Chan993ac7b2009-10-10 13:46:56 +000010764 break;
10765 }
10766
10767 /* rtnl_lock is held. */
10768 case DRV_CTL_STOP_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010769 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000010770
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010771 /* Stop accepting on iSCSI L2 ring */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010772 netif_addr_lock_bh(dev);
10773 bnx2x_set_iscsi_eth_rx_mode(bp, false);
10774 netif_addr_unlock_bh(dev);
10775
10776 /* bits to wait on */
10777 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10778 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
10779
10780 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10781 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010782
10783 mmiowb();
10784 barrier();
10785
10786 /* Unset iSCSI L2 MAC */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010787 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
10788 BNX2X_ISCSI_ETH_MAC, true);
Michael Chan993ac7b2009-10-10 13:46:56 +000010789 break;
10790 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010791 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
10792 int count = ctl->data.credit.credit_count;
10793
10794 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010795 atomic_add(count, &bp->cq_spq_left);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010796 smp_mb__after_atomic_inc();
10797 break;
10798 }
Michael Chan993ac7b2009-10-10 13:46:56 +000010799
10800 default:
10801 BNX2X_ERR("unknown command %x\n", ctl->cmd);
10802 rc = -EINVAL;
10803 }
10804
10805 return rc;
10806}
10807
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000010808void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +000010809{
10810 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10811
10812 if (bp->flags & USING_MSIX_FLAG) {
10813 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
10814 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
10815 cp->irq_arr[0].vector = bp->msix_table[1].vector;
10816 } else {
10817 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
10818 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
10819 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010820 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010821 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
10822 else
10823 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
10824
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010825 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
10826 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000010827 cp->irq_arr[1].status_blk = bp->def_status_blk;
10828 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010829 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
Michael Chan993ac7b2009-10-10 13:46:56 +000010830
10831 cp->num_irq = 2;
10832}
10833
10834static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
10835 void *data)
10836{
10837 struct bnx2x *bp = netdev_priv(dev);
10838 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10839
10840 if (ops == NULL)
10841 return -EINVAL;
10842
Michael Chan993ac7b2009-10-10 13:46:56 +000010843 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
10844 if (!bp->cnic_kwq)
10845 return -ENOMEM;
10846
10847 bp->cnic_kwq_cons = bp->cnic_kwq;
10848 bp->cnic_kwq_prod = bp->cnic_kwq;
10849 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
10850
10851 bp->cnic_spq_pending = 0;
10852 bp->cnic_kwq_pending = 0;
10853
10854 bp->cnic_data = data;
10855
10856 cp->num_irq = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010857 cp->drv_state |= CNIC_DRV_STATE_REGD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010858 cp->iro_arr = bp->iro_arr;
Michael Chan993ac7b2009-10-10 13:46:56 +000010859
Michael Chan993ac7b2009-10-10 13:46:56 +000010860 bnx2x_setup_cnic_irq_info(bp);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010861
Michael Chan993ac7b2009-10-10 13:46:56 +000010862 rcu_assign_pointer(bp->cnic_ops, ops);
10863
10864 return 0;
10865}
10866
10867static int bnx2x_unregister_cnic(struct net_device *dev)
10868{
10869 struct bnx2x *bp = netdev_priv(dev);
10870 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10871
10872 mutex_lock(&bp->cnic_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +000010873 cp->drv_state = 0;
10874 rcu_assign_pointer(bp->cnic_ops, NULL);
10875 mutex_unlock(&bp->cnic_mutex);
10876 synchronize_rcu();
10877 kfree(bp->cnic_kwq);
10878 bp->cnic_kwq = NULL;
10879
10880 return 0;
10881}
10882
10883struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
10884{
10885 struct bnx2x *bp = netdev_priv(dev);
10886 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10887
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010888 /* If both iSCSI and FCoE are disabled - return NULL in
10889 * order to indicate CNIC that it should not try to work
10890 * with this device.
10891 */
10892 if (NO_ISCSI(bp) && NO_FCOE(bp))
10893 return NULL;
10894
Michael Chan993ac7b2009-10-10 13:46:56 +000010895 cp->drv_owner = THIS_MODULE;
10896 cp->chip_id = CHIP_ID(bp);
10897 cp->pdev = bp->pdev;
10898 cp->io_base = bp->regview;
10899 cp->io_base2 = bp->doorbells;
10900 cp->max_kwqe_pending = 8;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010901 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010902 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
10903 bnx2x_cid_ilt_lines(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000010904 cp->ctx_tbl_len = CNIC_ILT_LINES;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010905 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
Michael Chan993ac7b2009-10-10 13:46:56 +000010906 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
10907 cp->drv_ctl = bnx2x_drv_ctl;
10908 cp->drv_register_cnic = bnx2x_register_cnic;
10909 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010910 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010911 cp->iscsi_l2_client_id =
10912 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010913 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
Michael Chan993ac7b2009-10-10 13:46:56 +000010914
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010915 if (NO_ISCSI_OOO(bp))
10916 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
10917
10918 if (NO_ISCSI(bp))
10919 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
10920
10921 if (NO_FCOE(bp))
10922 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
10923
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010924 DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
10925 "starting cid %d\n",
10926 cp->ctx_blk_size,
10927 cp->ctx_tbl_offset,
10928 cp->ctx_tbl_len,
10929 cp->starting_cid);
Michael Chan993ac7b2009-10-10 13:46:56 +000010930 return cp;
10931}
10932EXPORT_SYMBOL(bnx2x_cnic_probe);
10933
10934#endif /* BCM_CNIC */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070010935