blob: 6237e4aba82f18828e21a433c4cee36e46cde616 [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)
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001560 synchronize_irq(bp->msix_table[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
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00002517 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2518 (command | seq), param);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002519
2520 do {
2521 /* let the FW do it's magic ... */
2522 msleep(delay);
2523
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002524 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002525
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002526 /* Give the FW up to 5 second (500*10ms) */
2527 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002528
2529 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2530 cnt*delay, rc, seq);
2531
2532 /* is this a reply to our command? */
2533 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2534 rc &= FW_MSG_CODE_MASK;
2535 else {
2536 /* FW BUG! */
2537 BNX2X_ERR("FW failed to respond!\n");
2538 bnx2x_fw_dump(bp);
2539 rc = 0;
2540 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002541 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002542
2543 return rc;
2544}
2545
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002546static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
2547{
2548#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002549 /* Statistics are not supported for CNIC Clients at the moment */
2550 if (IS_FCOE_FP(fp))
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002551 return false;
2552#endif
2553 return true;
2554}
2555
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002556void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002557{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002558 if (CHIP_IS_E1x(bp)) {
2559 struct tstorm_eth_function_common_config tcfg = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002560
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002561 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2562 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002563
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002564 /* Enable the function in the FW */
2565 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2566 storm_memset_func_en(bp, p->func_id, 1);
2567
2568 /* spq */
2569 if (p->func_flgs & FUNC_FLG_SPQ) {
2570 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2571 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2572 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2573 }
2574}
2575
2576static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2577 struct bnx2x_fastpath *fp,
2578 bool leading)
2579{
2580 unsigned long flags = 0;
2581
2582 /* PF driver will always initialize the Queue to an ACTIVE state */
2583 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2584
2585 /* calculate other queue flags */
2586 if (IS_MF_SD(bp))
2587 __set_bit(BNX2X_Q_FLG_OV, &flags);
2588
2589 if (IS_FCOE_FP(fp))
2590 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002591
2592 if (!fp->disable_tpa)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002593 __set_bit(BNX2X_Q_FLG_TPA, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002594
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002595 if (stat_counter_valid(bp, fp)) {
2596 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2597 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2598 }
2599
2600 if (leading) {
2601 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
2602 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
2603 }
2604
2605 /* Always set HW VLAN stripping */
2606 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002607
2608 return flags;
2609}
2610
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002611static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
2612 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002613{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002614 gen_init->stat_id = bnx2x_stats_id(fp);
2615 gen_init->spcl_id = fp->cl_id;
2616
2617 /* Always use mini-jumbo MTU for FCoE L2 ring */
2618 if (IS_FCOE_FP(fp))
2619 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
2620 else
2621 gen_init->mtu = bp->dev->mtu;
2622}
2623
2624static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
2625 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
2626 struct bnx2x_rxq_setup_params *rxq_init)
2627{
2628 u8 max_sge = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002629 u16 sge_sz = 0;
2630 u16 tpa_agg_size = 0;
2631
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002632 if (!fp->disable_tpa) {
2633 pause->sge_th_hi = 250;
2634 pause->sge_th_lo = 150;
2635 tpa_agg_size = min_t(u32,
2636 (min_t(u32, 8, MAX_SKB_FRAGS) *
2637 SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
2638 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
2639 SGE_PAGE_SHIFT;
2640 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
2641 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
2642 sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
2643 0xffff);
2644 }
2645
2646 /* pause - not for e1 */
2647 if (!CHIP_IS_E1(bp)) {
2648 pause->bd_th_hi = 350;
2649 pause->bd_th_lo = 250;
2650 pause->rcq_th_hi = 350;
2651 pause->rcq_th_lo = 250;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002652
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002653 pause->pri_map = 1;
2654 }
2655
2656 /* rxq setup */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002657 rxq_init->dscr_map = fp->rx_desc_mapping;
2658 rxq_init->sge_map = fp->rx_sge_mapping;
2659 rxq_init->rcq_map = fp->rx_comp_mapping;
2660 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08002661
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002662 /* This should be a maximum number of data bytes that may be
2663 * placed on the BD (not including paddings).
2664 */
2665 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
2666 IP_HEADER_ALIGNMENT_PADDING;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08002667
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002668 rxq_init->cl_qzone_id = fp->cl_qzone_id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002669 rxq_init->tpa_agg_sz = tpa_agg_size;
2670 rxq_init->sge_buf_sz = sge_sz;
2671 rxq_init->max_sges_pkt = max_sge;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002672 rxq_init->rss_engine_id = BP_FUNC(bp);
2673
2674 /* Maximum number or simultaneous TPA aggregation for this Queue.
2675 *
2676 * For PF Clients it should be the maximum avaliable number.
2677 * VF driver(s) may want to define it to a smaller value.
2678 */
2679 rxq_init->max_tpa_queues =
2680 (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
2681 ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
2682
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002683 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
2684 rxq_init->fw_sb_id = fp->fw_sb_id;
2685
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002686 if (IS_FCOE_FP(fp))
2687 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
2688 else
2689 rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002690}
2691
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002692static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
2693 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002694{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002695 txq_init->dscr_map = fp->tx_desc_mapping;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002696 txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
2697 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
2698 txq_init->fw_sb_id = fp->fw_sb_id;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002699
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002700 /*
2701 * set the tss leading client id for TX classfication ==
2702 * leading RSS client id
2703 */
2704 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
2705
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002706 if (IS_FCOE_FP(fp)) {
2707 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
2708 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
2709 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002710}
2711
stephen hemminger8d962862010-10-21 07:50:56 +00002712static void bnx2x_pf_init(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002713{
2714 struct bnx2x_func_init_params func_init = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002715 struct event_ring_data eq_data = { {0} };
2716 u16 flags;
2717
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002718 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002719 /* reset IGU PF statistics: MSIX + ATTN */
2720 /* PF */
2721 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2722 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2723 (CHIP_MODE_IS_4_PORT(bp) ?
2724 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2725 /* ATTN */
2726 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
2727 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
2728 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
2729 (CHIP_MODE_IS_4_PORT(bp) ?
2730 BP_FUNC(bp) : BP_VN(bp))*4, 0);
2731 }
2732
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002733 /* function setup flags */
2734 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
2735
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002736 /* This flag is relevant for E1x only.
2737 * E2 doesn't have a TPA configuration in a function level.
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002738 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002739 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002740
2741 func_init.func_flgs = flags;
2742 func_init.pf_id = BP_FUNC(bp);
2743 func_init.func_id = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002744 func_init.spq_map = bp->spq_mapping;
2745 func_init.spq_prod = bp->spq_prod_idx;
2746
2747 bnx2x_func_init(bp, &func_init);
2748
2749 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
2750
2751 /*
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002752 * Congestion management values depend on the link rate
2753 * There is no active link so initial link rate is set to 10 Gbps.
2754 * When the link comes up The congestion management values are
2755 * re-calculated according to the actual link rate.
2756 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002757 bp->link_vars.line_speed = SPEED_10000;
2758 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
2759
2760 /* Only the PMF sets the HW */
2761 if (bp->port.pmf)
2762 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2763
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002764 /* init Event Queue */
2765 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
2766 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
2767 eq_data.producer = bp->eq_prod;
2768 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
2769 eq_data.sb_id = DEF_SB_ID;
2770 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
2771}
2772
2773
Eilon Greenstein2691d512009-08-12 08:22:08 +00002774static void bnx2x_e1h_disable(struct bnx2x *bp)
2775{
2776 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002777
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002778 bnx2x_tx_disable(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002779
2780 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002781}
2782
2783static void bnx2x_e1h_enable(struct bnx2x *bp)
2784{
2785 int port = BP_PORT(bp);
2786
2787 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
2788
Eilon Greenstein2691d512009-08-12 08:22:08 +00002789 /* Tx queue should be only reenabled */
2790 netif_tx_wake_all_queues(bp->dev);
2791
Eilon Greenstein061bc702009-10-15 00:18:47 -07002792 /*
2793 * Should not call netif_carrier_on since it will be called if the link
2794 * is up when checking for link state
2795 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00002796}
2797
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002798/* called due to MCP event (on pmf):
2799 * reread new bandwidth configuration
2800 * configure FW
2801 * notify others function about the change
2802 */
2803static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
2804{
2805 if (bp->link_vars.link_up) {
2806 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
2807 bnx2x_link_sync_notify(bp);
2808 }
2809 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2810}
2811
2812static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
2813{
2814 bnx2x_config_mf_bw(bp);
2815 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
2816}
2817
Eilon Greenstein2691d512009-08-12 08:22:08 +00002818static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
2819{
Eilon Greenstein2691d512009-08-12 08:22:08 +00002820 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002821
2822 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
2823
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002824 /*
2825 * This is the only place besides the function initialization
2826 * where the bp->flags can change so it is done without any
2827 * locks
2828 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002829 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
Eilon Greenstein2691d512009-08-12 08:22:08 +00002830 DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002831 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002832
2833 bnx2x_e1h_disable(bp);
2834 } else {
2835 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002836 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002837
2838 bnx2x_e1h_enable(bp);
2839 }
2840 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
2841 }
2842 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002843 bnx2x_config_mf_bw(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002844 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
2845 }
2846
2847 /* Report results to MCP */
2848 if (dcc_event)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002849 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002850 else
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002851 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002852}
2853
Michael Chan28912902009-10-10 13:46:53 +00002854/* must be called under the spq lock */
2855static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
2856{
2857 struct eth_spe *next_spe = bp->spq_prod_bd;
2858
2859 if (bp->spq_prod_bd == bp->spq_last_bd) {
2860 bp->spq_prod_bd = bp->spq;
2861 bp->spq_prod_idx = 0;
2862 DP(NETIF_MSG_TIMER, "end of spq\n");
2863 } else {
2864 bp->spq_prod_bd++;
2865 bp->spq_prod_idx++;
2866 }
2867 return next_spe;
2868}
2869
2870/* must be called under the spq lock */
2871static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
2872{
2873 int func = BP_FUNC(bp);
2874
2875 /* Make sure that BD data is updated before writing the producer */
2876 wmb();
2877
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002878 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002879 bp->spq_prod_idx);
Michael Chan28912902009-10-10 13:46:53 +00002880 mmiowb();
2881}
2882
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002883/**
2884 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
2885 *
2886 * @cmd: command to check
2887 * @cmd_type: command type
2888 */
2889static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
2890{
2891 if ((cmd_type == NONE_CONNECTION_TYPE) ||
2892 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
2893 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
2894 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
2895 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
2896 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
2897 return true;
2898 else
2899 return false;
2900
2901}
2902
2903
2904/**
2905 * bnx2x_sp_post - place a single command on an SP ring
2906 *
2907 * @bp: driver handle
2908 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
2909 * @cid: SW CID the command is related to
2910 * @data_hi: command private data address (high 32 bits)
2911 * @data_lo: command private data address (low 32 bits)
2912 * @cmd_type: command type (e.g. NONE, ETH)
2913 *
2914 * SP data is handled as if it's always an address pair, thus data fields are
2915 * not swapped to little endian in upper functions. Instead this function swaps
2916 * data as if it's two u32 fields.
2917 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002918int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002919 u32 data_hi, u32 data_lo, int cmd_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002920{
Michael Chan28912902009-10-10 13:46:53 +00002921 struct eth_spe *spe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002922 u16 type;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002923 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002924
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002925#ifdef BNX2X_STOP_ON_ERROR
2926 if (unlikely(bp->panic))
2927 return -EIO;
2928#endif
2929
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002930 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002931
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002932 if (common) {
2933 if (!atomic_read(&bp->eq_spq_left)) {
2934 BNX2X_ERR("BUG! EQ ring full!\n");
2935 spin_unlock_bh(&bp->spq_lock);
2936 bnx2x_panic();
2937 return -EBUSY;
2938 }
2939 } else if (!atomic_read(&bp->cq_spq_left)) {
2940 BNX2X_ERR("BUG! SPQ ring full!\n");
2941 spin_unlock_bh(&bp->spq_lock);
2942 bnx2x_panic();
2943 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002944 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08002945
Michael Chan28912902009-10-10 13:46:53 +00002946 spe = bnx2x_sp_get_next(bp);
2947
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002948 /* CID needs port number to be encoded int it */
Michael Chan28912902009-10-10 13:46:53 +00002949 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002950 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
2951 HW_CID(bp, cid));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002952
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002953 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002954
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002955 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
2956 SPE_HDR_FUNCTION_ID);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002957
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002958 spe->hdr.type = cpu_to_le16(type);
2959
2960 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
2961 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
2962
2963 /* stats ramrod has it's own slot on the spq */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002964 if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002965 /*
2966 * It's ok if the actual decrement is issued towards the memory
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002967 * somewhere between the spin_lock and spin_unlock. Thus no
2968 * more explict memory barrier is needed.
2969 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002970 if (common)
2971 atomic_dec(&bp->eq_spq_left);
2972 else
2973 atomic_dec(&bp->cq_spq_left);
2974 }
2975
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002976
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002977 DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002978 "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002979 "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002980 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
2981 (u32)(U64_LO(bp->spq_mapping) +
2982 (void *)bp->spq_prod_bd - (void *)bp->spq), command,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08002983 HW_CID(bp, cid), data_hi, data_lo, type,
2984 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00002985
Michael Chan28912902009-10-10 13:46:53 +00002986 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002987 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002988 return 0;
2989}
2990
2991/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002992static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002993{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002994 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002995 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002996
2997 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00002998 for (j = 0; j < 1000; j++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002999 val = (1UL << 31);
3000 REG_WR(bp, GRCBASE_MCP + 0x9c, val);
3001 val = REG_RD(bp, GRCBASE_MCP + 0x9c);
3002 if (val & (1L << 31))
3003 break;
3004
3005 msleep(5);
3006 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003007 if (!(val & (1L << 31))) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07003008 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003009 rc = -EBUSY;
3010 }
3011
3012 return rc;
3013}
3014
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003015/* release split MCP access lock register */
3016static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003017{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003018 REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003019}
3020
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003021#define BNX2X_DEF_SB_ATT_IDX 0x0001
3022#define BNX2X_DEF_SB_IDX 0x0002
3023
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003024static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
3025{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003026 struct host_sp_status_block *def_sb = bp->def_status_blk;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003027 u16 rc = 0;
3028
3029 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003030 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3031 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003032 rc |= BNX2X_DEF_SB_ATT_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003033 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003034
3035 if (bp->def_idx != def_sb->sp_sb.running_index) {
3036 bp->def_idx = def_sb->sp_sb.running_index;
3037 rc |= BNX2X_DEF_SB_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003038 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003039
3040 /* Do not reorder: indecies reading should complete before handling */
3041 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003042 return rc;
3043}
3044
3045/*
3046 * slow path service functions
3047 */
3048
3049static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3050{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003051 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003052 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3053 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003054 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3055 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003056 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00003057 u32 nig_mask = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003058 u32 reg_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003059
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003060 if (bp->attn_state & asserted)
3061 BNX2X_ERR("IGU ERROR\n");
3062
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003063 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3064 aeu_mask = REG_RD(bp, aeu_addr);
3065
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003066 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003067 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003068 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003069 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003070
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003071 REG_WR(bp, aeu_addr, aeu_mask);
3072 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003073
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003074 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003075 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003076 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003077
3078 if (asserted & ATTN_HARD_WIRED_MASK) {
3079 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003080
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003081 bnx2x_acquire_phy_lock(bp);
3082
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003083 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00003084 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003085
Yaniv Rosner361c3912011-06-14 01:33:19 +00003086 /* If nig_mask is not set, no need to call the update
3087 * function.
3088 */
3089 if (nig_mask) {
3090 REG_WR(bp, nig_int_mask_addr, 0);
3091
3092 bnx2x_link_attn(bp);
3093 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003094
3095 /* handle unicore attn? */
3096 }
3097 if (asserted & ATTN_SW_TIMER_4_FUNC)
3098 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3099
3100 if (asserted & GPIO_2_FUNC)
3101 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3102
3103 if (asserted & GPIO_3_FUNC)
3104 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3105
3106 if (asserted & GPIO_4_FUNC)
3107 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3108
3109 if (port == 0) {
3110 if (asserted & ATTN_GENERAL_ATTN_1) {
3111 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3112 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3113 }
3114 if (asserted & ATTN_GENERAL_ATTN_2) {
3115 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3116 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3117 }
3118 if (asserted & ATTN_GENERAL_ATTN_3) {
3119 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3120 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3121 }
3122 } else {
3123 if (asserted & ATTN_GENERAL_ATTN_4) {
3124 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3125 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3126 }
3127 if (asserted & ATTN_GENERAL_ATTN_5) {
3128 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3129 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3130 }
3131 if (asserted & ATTN_GENERAL_ATTN_6) {
3132 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3133 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3134 }
3135 }
3136
3137 } /* if hardwired */
3138
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003139 if (bp->common.int_block == INT_BLOCK_HC)
3140 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3141 COMMAND_REG_ATTN_BITS_SET);
3142 else
3143 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3144
3145 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3146 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3147 REG_WR(bp, reg_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003148
3149 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003150 if (asserted & ATTN_NIG_FOR_FUNC) {
Eilon Greenstein87942b42009-02-12 08:36:49 +00003151 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003152 bnx2x_release_phy_lock(bp);
3153 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003154}
3155
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003156static inline void bnx2x_fan_failure(struct bnx2x *bp)
3157{
3158 int port = BP_PORT(bp);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003159 u32 ext_phy_config;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003160 /* mark the failure */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003161 ext_phy_config =
3162 SHMEM_RD(bp,
3163 dev_info.port_hw_config[port].external_phy_config);
3164
3165 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3166 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003167 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003168 ext_phy_config);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003169
3170 /* log the failure */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003171 netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
3172 " the driver to shutdown the card to prevent permanent"
3173 " damage. Please contact OEM Support for assistance\n");
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003174}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003175
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003176static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
3177{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003178 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003179 int reg_offset;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003180 u32 val;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003181
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003182 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3183 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003184
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003185 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003186
3187 val = REG_RD(bp, reg_offset);
3188 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3189 REG_WR(bp, reg_offset, val);
3190
3191 BNX2X_ERR("SPIO5 hw attention\n");
3192
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003193 /* Fan failure attention */
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003194 bnx2x_hw_reset_phy(&bp->link_params);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00003195 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003196 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003197
Eilon Greenstein589abe32009-02-12 08:36:55 +00003198 if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
3199 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
3200 bnx2x_acquire_phy_lock(bp);
3201 bnx2x_handle_module_detect_int(&bp->link_params);
3202 bnx2x_release_phy_lock(bp);
3203 }
3204
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003205 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3206
3207 val = REG_RD(bp, reg_offset);
3208 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3209 REG_WR(bp, reg_offset, val);
3210
3211 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003212 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003213 bnx2x_panic();
3214 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003215}
3216
3217static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
3218{
3219 u32 val;
3220
Eilon Greenstein0626b892009-02-12 08:38:14 +00003221 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003222
3223 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3224 BNX2X_ERR("DB hw attention 0x%x\n", val);
3225 /* DORQ discard attention */
3226 if (val & 0x2)
3227 BNX2X_ERR("FATAL error from DORQ\n");
3228 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003229
3230 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3231
3232 int port = BP_PORT(bp);
3233 int reg_offset;
3234
3235 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3236 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3237
3238 val = REG_RD(bp, reg_offset);
3239 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3240 REG_WR(bp, reg_offset, val);
3241
3242 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003243 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003244 bnx2x_panic();
3245 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003246}
3247
3248static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
3249{
3250 u32 val;
3251
3252 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3253
3254 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3255 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3256 /* CFC error attention */
3257 if (val & 0x2)
3258 BNX2X_ERR("FATAL error from CFC\n");
3259 }
3260
3261 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003262 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003263 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003264 /* RQ_USDMDP_FIFO_OVERFLOW */
3265 if (val & 0x18000)
3266 BNX2X_ERR("FATAL error from PXP\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003267
3268 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003269 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3270 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3271 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003272 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003273
3274 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3275
3276 int port = BP_PORT(bp);
3277 int reg_offset;
3278
3279 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3280 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3281
3282 val = REG_RD(bp, reg_offset);
3283 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3284 REG_WR(bp, reg_offset, val);
3285
3286 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003287 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003288 bnx2x_panic();
3289 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003290}
3291
3292static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
3293{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003294 u32 val;
3295
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003296 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3297
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003298 if (attn & BNX2X_PMF_LINK_ASSERT) {
3299 int func = BP_FUNC(bp);
3300
3301 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003302 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3303 func_mf_config[BP_ABS_FUNC(bp)].config);
3304 val = SHMEM_RD(bp,
3305 func_mb[BP_FW_MB_IDX(bp)].drv_status);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003306 if (val & DRV_STATUS_DCC_EVENT_MASK)
3307 bnx2x_dcc_event(bp,
3308 (val & DRV_STATUS_DCC_EVENT_MASK));
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003309
3310 if (val & DRV_STATUS_SET_MF_BW)
3311 bnx2x_set_mf_bw(bp);
3312
Eilon Greenstein2691d512009-08-12 08:22:08 +00003313 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003314 bnx2x_pmf_update(bp);
3315
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00003316 /* Always call it here: bnx2x_link_report() will
3317 * prevent the link indication duplication.
3318 */
3319 bnx2x__link_status_update(bp);
3320
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003321 if (bp->port.pmf &&
Shmulik Ravid785b9b12010-12-30 06:27:03 +00003322 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3323 bp->dcbx_enabled > 0)
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003324 /* start dcbx state machine */
3325 bnx2x_dcbx_set_params(bp,
3326 BNX2X_DCBX_STATE_NEG_RECEIVED);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003327 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003328
3329 BNX2X_ERR("MC assert!\n");
3330 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
3331 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
3332 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
3333 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
3334 bnx2x_panic();
3335
3336 } else if (attn & BNX2X_MCP_ASSERT) {
3337
3338 BNX2X_ERR("MCP assert!\n");
3339 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003340 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003341
3342 } else
3343 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
3344 }
3345
3346 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003347 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
3348 if (attn & BNX2X_GRC_TIMEOUT) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003349 val = CHIP_IS_E1(bp) ? 0 :
3350 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003351 BNX2X_ERR("GRC time-out 0x%08x\n", val);
3352 }
3353 if (attn & BNX2X_GRC_RSV) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003354 val = CHIP_IS_E1(bp) ? 0 :
3355 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003356 BNX2X_ERR("GRC reserved 0x%08x\n", val);
3357 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003358 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003359 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003360}
3361
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003362/*
3363 * Bits map:
3364 * 0-7 - Engine0 load counter.
3365 * 8-15 - Engine1 load counter.
3366 * 16 - Engine0 RESET_IN_PROGRESS bit.
3367 * 17 - Engine1 RESET_IN_PROGRESS bit.
3368 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
3369 * on the engine
3370 * 19 - Engine1 ONE_IS_LOADED.
3371 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
3372 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
3373 * just the one belonging to its engine).
3374 *
3375 */
3376#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
3377
3378#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
3379#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
3380#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
3381#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
3382#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
3383#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
3384#define BNX2X_GLOBAL_RESET_BIT 0x00040000
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00003385
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003386/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003387 * Set the GLOBAL_RESET bit.
3388 *
3389 * Should be run under rtnl lock
3390 */
3391void bnx2x_set_reset_global(struct bnx2x *bp)
3392{
3393 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3394
3395 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
3396 barrier();
3397 mmiowb();
3398}
3399
3400/*
3401 * Clear the GLOBAL_RESET bit.
3402 *
3403 * Should be run under rtnl lock
3404 */
3405static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
3406{
3407 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3408
3409 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
3410 barrier();
3411 mmiowb();
3412}
3413
3414/*
3415 * Checks the GLOBAL_RESET bit.
3416 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003417 * should be run under rtnl lock
3418 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003419static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
3420{
3421 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3422
3423 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
3424 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
3425}
3426
3427/*
3428 * Clear RESET_IN_PROGRESS bit for the current engine.
3429 *
3430 * Should be run under rtnl lock
3431 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003432static inline void bnx2x_set_reset_done(struct bnx2x *bp)
3433{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003434 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3435 u32 bit = BP_PATH(bp) ?
3436 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3437
3438 /* Clear the bit */
3439 val &= ~bit;
3440 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003441 barrier();
3442 mmiowb();
3443}
3444
3445/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003446 * Set RESET_IN_PROGRESS for the current engine.
3447 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003448 * should be run under rtnl lock
3449 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003450void bnx2x_set_reset_in_progress(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003451{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003452 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3453 u32 bit = BP_PATH(bp) ?
3454 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3455
3456 /* Set the bit */
3457 val |= bit;
3458 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003459 barrier();
3460 mmiowb();
3461}
3462
3463/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003464 * Checks the RESET_IN_PROGRESS bit for the given engine.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003465 * should be run under rtnl lock
3466 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003467bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003468{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003469 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3470 u32 bit = engine ?
3471 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
3472
3473 /* return false if bit is set */
3474 return (val & bit) ? false : true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003475}
3476
3477/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003478 * Increment the load counter for the current engine.
3479 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003480 * should be run under rtnl lock
3481 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003482void bnx2x_inc_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003483{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003484 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3485 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3486 BNX2X_PATH0_LOAD_CNT_MASK;
3487 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3488 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003489
3490 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3491
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003492 /* get the current counter value */
3493 val1 = (val & mask) >> shift;
3494
3495 /* increment... */
3496 val1++;
3497
3498 /* clear the old value */
3499 val &= ~mask;
3500
3501 /* set the new one */
3502 val |= ((val1 << shift) & mask);
3503
3504 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003505 barrier();
3506 mmiowb();
3507}
3508
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003509/**
3510 * bnx2x_dec_load_cnt - decrement the load counter
3511 *
3512 * @bp: driver handle
3513 *
3514 * Should be run under rtnl lock.
3515 * Decrements the load counter for the current engine. Returns
3516 * the new counter value.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003517 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003518u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003519{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003520 u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3521 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3522 BNX2X_PATH0_LOAD_CNT_MASK;
3523 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3524 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003525
3526 DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
3527
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003528 /* get the current counter value */
3529 val1 = (val & mask) >> shift;
3530
3531 /* decrement... */
3532 val1--;
3533
3534 /* clear the old value */
3535 val &= ~mask;
3536
3537 /* set the new one */
3538 val |= ((val1 << shift) & mask);
3539
3540 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003541 barrier();
3542 mmiowb();
3543
3544 return val1;
3545}
3546
3547/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003548 * Read the load counter for the current engine.
3549 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003550 * should be run under rtnl lock
3551 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003552static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003553{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003554 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
3555 BNX2X_PATH0_LOAD_CNT_MASK);
3556 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
3557 BNX2X_PATH0_LOAD_CNT_SHIFT);
3558 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3559
3560 DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
3561
3562 val = (val & mask) >> shift;
3563
3564 DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
3565
3566 return val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003567}
3568
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003569/*
3570 * Reset the load counter for the current engine.
3571 *
3572 * should be run under rtnl lock
3573 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003574static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
3575{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003576 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
3577 u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
3578 BNX2X_PATH0_LOAD_CNT_MASK);
3579
3580 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003581}
3582
3583static inline void _print_next_block(int idx, const char *blk)
3584{
3585 if (idx)
3586 pr_cont(", ");
3587 pr_cont("%s", blk);
3588}
3589
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003590static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
3591 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003592{
3593 int i = 0;
3594 u32 cur_bit = 0;
3595 for (i = 0; sig; i++) {
3596 cur_bit = ((u32)0x1 << i);
3597 if (sig & cur_bit) {
3598 switch (cur_bit) {
3599 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003600 if (print)
3601 _print_next_block(par_num++, "BRB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003602 break;
3603 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003604 if (print)
3605 _print_next_block(par_num++, "PARSER");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003606 break;
3607 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003608 if (print)
3609 _print_next_block(par_num++, "TSDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003610 break;
3611 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003612 if (print)
3613 _print_next_block(par_num++,
3614 "SEARCHER");
3615 break;
3616 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
3617 if (print)
3618 _print_next_block(par_num++, "TCM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003619 break;
3620 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003621 if (print)
3622 _print_next_block(par_num++, "TSEMI");
3623 break;
3624 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
3625 if (print)
3626 _print_next_block(par_num++, "XPB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003627 break;
3628 }
3629
3630 /* Clear the bit */
3631 sig &= ~cur_bit;
3632 }
3633 }
3634
3635 return par_num;
3636}
3637
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003638static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
3639 bool *global, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003640{
3641 int i = 0;
3642 u32 cur_bit = 0;
3643 for (i = 0; sig; i++) {
3644 cur_bit = ((u32)0x1 << i);
3645 if (sig & cur_bit) {
3646 switch (cur_bit) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003647 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
3648 if (print)
3649 _print_next_block(par_num++, "PBF");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003650 break;
3651 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003652 if (print)
3653 _print_next_block(par_num++, "QM");
3654 break;
3655 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
3656 if (print)
3657 _print_next_block(par_num++, "TM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003658 break;
3659 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003660 if (print)
3661 _print_next_block(par_num++, "XSDM");
3662 break;
3663 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
3664 if (print)
3665 _print_next_block(par_num++, "XCM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003666 break;
3667 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003668 if (print)
3669 _print_next_block(par_num++, "XSEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003670 break;
3671 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003672 if (print)
3673 _print_next_block(par_num++,
3674 "DOORBELLQ");
3675 break;
3676 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
3677 if (print)
3678 _print_next_block(par_num++, "NIG");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003679 break;
3680 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003681 if (print)
3682 _print_next_block(par_num++,
3683 "VAUX PCI CORE");
3684 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003685 break;
3686 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003687 if (print)
3688 _print_next_block(par_num++, "DEBUG");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003689 break;
3690 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003691 if (print)
3692 _print_next_block(par_num++, "USDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003693 break;
3694 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003695 if (print)
3696 _print_next_block(par_num++, "USEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003697 break;
3698 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003699 if (print)
3700 _print_next_block(par_num++, "UPB");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003701 break;
3702 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003703 if (print)
3704 _print_next_block(par_num++, "CSDM");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003705 break;
3706 }
3707
3708 /* Clear the bit */
3709 sig &= ~cur_bit;
3710 }
3711 }
3712
3713 return par_num;
3714}
3715
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003716static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
3717 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003718{
3719 int i = 0;
3720 u32 cur_bit = 0;
3721 for (i = 0; sig; i++) {
3722 cur_bit = ((u32)0x1 << i);
3723 if (sig & cur_bit) {
3724 switch (cur_bit) {
3725 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003726 if (print)
3727 _print_next_block(par_num++, "CSEMI");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003728 break;
3729 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003730 if (print)
3731 _print_next_block(par_num++, "PXP");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003732 break;
3733 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003734 if (print)
3735 _print_next_block(par_num++,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003736 "PXPPCICLOCKCLIENT");
3737 break;
3738 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003739 if (print)
3740 _print_next_block(par_num++, "CFC");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003741 break;
3742 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003743 if (print)
3744 _print_next_block(par_num++, "CDU");
3745 break;
3746 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
3747 if (print)
3748 _print_next_block(par_num++, "DMAE");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003749 break;
3750 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003751 if (print)
3752 _print_next_block(par_num++, "IGU");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003753 break;
3754 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003755 if (print)
3756 _print_next_block(par_num++, "MISC");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003757 break;
3758 }
3759
3760 /* Clear the bit */
3761 sig &= ~cur_bit;
3762 }
3763 }
3764
3765 return par_num;
3766}
3767
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003768static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
3769 bool *global, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003770{
3771 int i = 0;
3772 u32 cur_bit = 0;
3773 for (i = 0; sig; i++) {
3774 cur_bit = ((u32)0x1 << i);
3775 if (sig & cur_bit) {
3776 switch (cur_bit) {
3777 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003778 if (print)
3779 _print_next_block(par_num++, "MCP ROM");
3780 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003781 break;
3782 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003783 if (print)
3784 _print_next_block(par_num++,
3785 "MCP UMP RX");
3786 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003787 break;
3788 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003789 if (print)
3790 _print_next_block(par_num++,
3791 "MCP UMP TX");
3792 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003793 break;
3794 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003795 if (print)
3796 _print_next_block(par_num++,
3797 "MCP SCPAD");
3798 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003799 break;
3800 }
3801
3802 /* Clear the bit */
3803 sig &= ~cur_bit;
3804 }
3805 }
3806
3807 return par_num;
3808}
3809
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003810static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
3811 u32 sig0, u32 sig1, u32 sig2, u32 sig3)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003812{
3813 if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
3814 (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
3815 int par_num = 0;
3816 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
3817 "[0]:0x%08x [1]:0x%08x "
3818 "[2]:0x%08x [3]:0x%08x\n",
3819 sig0 & HW_PRTY_ASSERT_SET_0,
3820 sig1 & HW_PRTY_ASSERT_SET_1,
3821 sig2 & HW_PRTY_ASSERT_SET_2,
3822 sig3 & HW_PRTY_ASSERT_SET_3);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003823 if (print)
3824 netdev_err(bp->dev,
3825 "Parity errors detected in blocks: ");
3826 par_num = bnx2x_check_blocks_with_parity0(
3827 sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
3828 par_num = bnx2x_check_blocks_with_parity1(
3829 sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
3830 par_num = bnx2x_check_blocks_with_parity2(
3831 sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
3832 par_num = bnx2x_check_blocks_with_parity3(
3833 sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
3834 if (print)
3835 pr_cont("\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003836 return true;
3837 } else
3838 return false;
3839}
3840
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003841/**
3842 * bnx2x_chk_parity_attn - checks for parity attentions.
3843 *
3844 * @bp: driver handle
3845 * @global: true if there was a global attention
3846 * @print: show parity attention in syslog
3847 */
3848bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003849{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003850 struct attn_route attn;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003851 int port = BP_PORT(bp);
3852
3853 attn.sig[0] = REG_RD(bp,
3854 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
3855 port*4);
3856 attn.sig[1] = REG_RD(bp,
3857 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
3858 port*4);
3859 attn.sig[2] = REG_RD(bp,
3860 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
3861 port*4);
3862 attn.sig[3] = REG_RD(bp,
3863 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
3864 port*4);
3865
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003866 return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
3867 attn.sig[2], attn.sig[3]);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003868}
3869
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003870
3871static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
3872{
3873 u32 val;
3874 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
3875
3876 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
3877 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
3878 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
3879 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3880 "ADDRESS_ERROR\n");
3881 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
3882 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3883 "INCORRECT_RCV_BEHAVIOR\n");
3884 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
3885 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3886 "WAS_ERROR_ATTN\n");
3887 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
3888 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3889 "VF_LENGTH_VIOLATION_ATTN\n");
3890 if (val &
3891 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
3892 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3893 "VF_GRC_SPACE_VIOLATION_ATTN\n");
3894 if (val &
3895 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
3896 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3897 "VF_MSIX_BAR_VIOLATION_ATTN\n");
3898 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
3899 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3900 "TCPL_ERROR_ATTN\n");
3901 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
3902 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3903 "TCPL_IN_TWO_RCBS_ATTN\n");
3904 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
3905 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
3906 "CSSNOOP_FIFO_OVERFLOW\n");
3907 }
3908 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
3909 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
3910 BNX2X_ERR("ATC hw attention 0x%x\n", val);
3911 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
3912 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
3913 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
3914 BNX2X_ERR("ATC_ATC_INT_STS_REG"
3915 "_ATC_TCPL_TO_NOT_PEND\n");
3916 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
3917 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3918 "ATC_GPA_MULTIPLE_HITS\n");
3919 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
3920 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3921 "ATC_RCPL_TO_EMPTY_CNT\n");
3922 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
3923 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
3924 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
3925 BNX2X_ERR("ATC_ATC_INT_STS_REG_"
3926 "ATC_IREQ_LESS_THAN_STU\n");
3927 }
3928
3929 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3930 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
3931 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
3932 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
3933 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
3934 }
3935
3936}
3937
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003938static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
3939{
3940 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003941 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003942 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003943 u32 reg_addr;
3944 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003945 u32 aeu_mask;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003946 bool global = false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003947
3948 /* need to take HW lock because MCP or other port might also
3949 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003950 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003951
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003952 if (bnx2x_chk_parity_attn(bp, &global, true)) {
3953#ifndef BNX2X_STOP_ON_ERROR
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003954 bp->recovery_state = BNX2X_RECOVERY_INIT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003955 schedule_delayed_work(&bp->reset_task, 0);
3956 /* Disable HW interrupts */
3957 bnx2x_int_disable(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003958 /* In case of parity errors don't handle attentions so that
3959 * other function would "see" parity errors.
3960 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00003961#else
3962 bnx2x_panic();
3963#endif
3964 bnx2x_release_alr(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003965 return;
3966 }
3967
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003968 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
3969 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
3970 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
3971 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003972 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003973 attn.sig[4] =
3974 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
3975 else
3976 attn.sig[4] = 0;
3977
3978 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
3979 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003980
3981 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
3982 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003983 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003984
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003985 DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
3986 "%08x %08x %08x\n",
3987 index,
3988 group_mask->sig[0], group_mask->sig[1],
3989 group_mask->sig[2], group_mask->sig[3],
3990 group_mask->sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003991
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003992 bnx2x_attn_int_deasserted4(bp,
3993 attn.sig[4] & group_mask->sig[4]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003994 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003995 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003996 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003997 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003998 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003999 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004000 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004001 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004002 }
4003 }
4004
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004005 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004006
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004007 if (bp->common.int_block == INT_BLOCK_HC)
4008 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4009 COMMAND_REG_ATTN_BITS_CLR);
4010 else
4011 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004012
4013 val = ~deasserted;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004014 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4015 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004016 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004017
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004018 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004019 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004020
4021 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4022 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4023
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004024 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4025 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004026
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004027 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4028 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004029 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004030 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4031
4032 REG_WR(bp, reg_addr, aeu_mask);
4033 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004034
4035 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4036 bp->attn_state &= ~deasserted;
4037 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4038}
4039
4040static void bnx2x_attn_int(struct bnx2x *bp)
4041{
4042 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08004043 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4044 attn_bits);
4045 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4046 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004047 u32 attn_state = bp->attn_state;
4048
4049 /* look for changed bits */
4050 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4051 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4052
4053 DP(NETIF_MSG_HW,
4054 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4055 attn_bits, attn_ack, asserted, deasserted);
4056
4057 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004058 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004059
4060 /* handle bits that were raised */
4061 if (asserted)
4062 bnx2x_attn_int_asserted(bp, asserted);
4063
4064 if (deasserted)
4065 bnx2x_attn_int_deasserted(bp, deasserted);
4066}
4067
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004068void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4069 u16 index, u8 op, u8 update)
4070{
4071 u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
4072
4073 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4074 igu_addr);
4075}
4076
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004077static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
4078{
4079 /* No memory barriers */
4080 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4081 mmiowb(); /* keep prod updates ordered */
4082}
4083
4084#ifdef BCM_CNIC
4085static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4086 union event_ring_elem *elem)
4087{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004088 u8 err = elem->message.error;
4089
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004090 if (!bp->cnic_eth_dev.starting_cid ||
Vladislav Zolotarovc3a8ce62011-05-22 10:08:09 +00004091 (cid < bp->cnic_eth_dev.starting_cid &&
4092 cid != bp->cnic_eth_dev.iscsi_l2_cid))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004093 return 1;
4094
4095 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4096
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004097 if (unlikely(err)) {
4098
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004099 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4100 cid);
4101 bnx2x_panic_dump(bp);
4102 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004103 bnx2x_cnic_cfc_comp(bp, cid, err);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004104 return 0;
4105}
4106#endif
4107
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004108static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
4109{
4110 struct bnx2x_mcast_ramrod_params rparam;
4111 int rc;
4112
4113 memset(&rparam, 0, sizeof(rparam));
4114
4115 rparam.mcast_obj = &bp->mcast_obj;
4116
4117 netif_addr_lock_bh(bp->dev);
4118
4119 /* Clear pending state for the last command */
4120 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4121
4122 /* If there are pending mcast commands - send them */
4123 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4124 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4125 if (rc < 0)
4126 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4127 rc);
4128 }
4129
4130 netif_addr_unlock_bh(bp->dev);
4131}
4132
4133static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4134 union event_ring_elem *elem)
4135{
4136 unsigned long ramrod_flags = 0;
4137 int rc = 0;
4138 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4139 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4140
4141 /* Always push next commands out, don't wait here */
4142 __set_bit(RAMROD_CONT, &ramrod_flags);
4143
4144 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
4145 case BNX2X_FILTER_MAC_PENDING:
4146#ifdef BCM_CNIC
4147 if (cid == BNX2X_ISCSI_ETH_CID)
4148 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4149 else
4150#endif
4151 vlan_mac_obj = &bp->fp[cid].mac_obj;
4152
4153 break;
4154 vlan_mac_obj = &bp->fp[cid].mac_obj;
4155
4156 case BNX2X_FILTER_MCAST_PENDING:
4157 /* This is only relevant for 57710 where multicast MACs are
4158 * configured as unicast MACs using the same ramrod.
4159 */
4160 bnx2x_handle_mcast_eqe(bp);
4161 return;
4162 default:
4163 BNX2X_ERR("Unsupported classification command: %d\n",
4164 elem->message.data.eth_event.echo);
4165 return;
4166 }
4167
4168 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4169
4170 if (rc < 0)
4171 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4172 else if (rc > 0)
4173 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
4174
4175}
4176
4177#ifdef BCM_CNIC
4178static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
4179#endif
4180
4181static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
4182{
4183 netif_addr_lock_bh(bp->dev);
4184
4185 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4186
4187 /* Send rx_mode command again if was requested */
4188 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
4189 bnx2x_set_storm_rx_mode(bp);
4190#ifdef BCM_CNIC
4191 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
4192 &bp->sp_state))
4193 bnx2x_set_iscsi_eth_rx_mode(bp, true);
4194 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
4195 &bp->sp_state))
4196 bnx2x_set_iscsi_eth_rx_mode(bp, false);
4197#endif
4198
4199 netif_addr_unlock_bh(bp->dev);
4200}
4201
4202static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
4203 struct bnx2x *bp, u32 cid)
4204{
4205#ifdef BCM_CNIC
4206 if (cid == BNX2X_FCOE_ETH_CID)
4207 return &bnx2x_fcoe(bp, q_obj);
4208 else
4209#endif
4210 return &bnx2x_fp(bp, cid, q_obj);
4211}
4212
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004213static void bnx2x_eq_int(struct bnx2x *bp)
4214{
4215 u16 hw_cons, sw_cons, sw_prod;
4216 union event_ring_elem *elem;
4217 u32 cid;
4218 u8 opcode;
4219 int spqe_cnt = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004220 struct bnx2x_queue_sp_obj *q_obj;
4221 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
4222 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004223
4224 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
4225
4226 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
4227 * when we get the the next-page we nned to adjust so the loop
4228 * condition below will be met. The next element is the size of a
4229 * regular element and hence incrementing by 1
4230 */
4231 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
4232 hw_cons++;
4233
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004234 /* This function may never run in parallel with itself for a
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004235 * specific bp, thus there is no need in "paired" read memory
4236 * barrier here.
4237 */
4238 sw_cons = bp->eq_cons;
4239 sw_prod = bp->eq_prod;
4240
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004241 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
4242 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004243
4244 for (; sw_cons != hw_cons;
4245 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
4246
4247
4248 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
4249
4250 cid = SW_CID(elem->message.data.cfc_del_event.cid);
4251 opcode = elem->message.opcode;
4252
4253
4254 /* handle eq element */
4255 switch (opcode) {
4256 case EVENT_RING_OPCODE_STAT_QUERY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004257 DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
4258 bp->stats_comp++);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004259 /* nothing to do with stats comp */
4260 continue;
4261
4262 case EVENT_RING_OPCODE_CFC_DEL:
4263 /* handle according to cid range */
4264 /*
4265 * we may want to verify here that the bp state is
4266 * HALTING
4267 */
4268 DP(NETIF_MSG_IFDOWN,
4269 "got delete ramrod for MULTI[%d]\n", cid);
4270#ifdef BCM_CNIC
4271 if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
4272 goto next_spqe;
4273#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004274 q_obj = bnx2x_cid_to_q_obj(bp, cid);
4275
4276 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
4277 break;
4278
4279
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004280
4281 goto next_spqe;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004282
4283 case EVENT_RING_OPCODE_STOP_TRAFFIC:
4284 DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
4285 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
4286 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004287
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004288 case EVENT_RING_OPCODE_START_TRAFFIC:
4289 DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
4290 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
4291 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004292 case EVENT_RING_OPCODE_FUNCTION_START:
4293 DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
4294 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
4295 break;
4296
4297 goto next_spqe;
4298
4299 case EVENT_RING_OPCODE_FUNCTION_STOP:
4300 DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
4301 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
4302 break;
4303
4304 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004305 }
4306
4307 switch (opcode | bp->state) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004308 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
4309 BNX2X_STATE_OPEN):
4310 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004311 BNX2X_STATE_OPENING_WAIT4_PORT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004312 cid = elem->message.data.eth_event.echo &
4313 BNX2X_SWCID_MASK;
4314 DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
4315 cid);
4316 rss_raw->clear_pending(rss_raw);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004317 break;
4318
4319 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
4320 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004321 case (EVENT_RING_OPCODE_SET_MAC |
4322 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004323 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4324 BNX2X_STATE_OPEN):
4325 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4326 BNX2X_STATE_DIAG):
4327 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
4328 BNX2X_STATE_CLOSING_WAIT4_HALT):
4329 DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
4330 bnx2x_handle_classification_eqe(bp, elem);
4331 break;
4332
4333 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4334 BNX2X_STATE_OPEN):
4335 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4336 BNX2X_STATE_DIAG):
4337 case (EVENT_RING_OPCODE_MULTICAST_RULES |
4338 BNX2X_STATE_CLOSING_WAIT4_HALT):
4339 DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
4340 bnx2x_handle_mcast_eqe(bp);
4341 break;
4342
4343 case (EVENT_RING_OPCODE_FILTERS_RULES |
4344 BNX2X_STATE_OPEN):
4345 case (EVENT_RING_OPCODE_FILTERS_RULES |
4346 BNX2X_STATE_DIAG):
4347 case (EVENT_RING_OPCODE_FILTERS_RULES |
4348 BNX2X_STATE_CLOSING_WAIT4_HALT):
4349 DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
4350 bnx2x_handle_rx_mode_eqe(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004351 break;
4352 default:
4353 /* unknown event log error and continue */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004354 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
4355 elem->message.opcode, bp->state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004356 }
4357next_spqe:
4358 spqe_cnt++;
4359 } /* for */
4360
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00004361 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004362 atomic_add(spqe_cnt, &bp->eq_spq_left);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004363
4364 bp->eq_cons = sw_cons;
4365 bp->eq_prod = sw_prod;
4366 /* Make sure that above mem writes were issued towards the memory */
4367 smp_wmb();
4368
4369 /* update producer */
4370 bnx2x_update_eq_prod(bp, bp->eq_prod);
4371}
4372
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004373static void bnx2x_sp_task(struct work_struct *work)
4374{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08004375 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004376 u16 status;
4377
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004378 status = bnx2x_update_dsb_idx(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004379/* if (status == 0) */
4380/* BNX2X_ERR("spurious slowpath interrupt!\n"); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004381
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004382 DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004383
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004384 /* HW attentions */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004385 if (status & BNX2X_DEF_SB_ATT_IDX) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004386 bnx2x_attn_int(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004387 status &= ~BNX2X_DEF_SB_ATT_IDX;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004388 }
4389
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004390 /* SP events: STAT_QUERY and others */
4391 if (status & BNX2X_DEF_SB_IDX) {
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004392#ifdef BCM_CNIC
4393 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004394
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004395 if ((!NO_FCOE(bp)) &&
4396 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
4397 napi_schedule(&bnx2x_fcoe(bp, napi));
4398#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004399 /* Handle EQ completions */
4400 bnx2x_eq_int(bp);
4401
4402 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
4403 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
4404
4405 status &= ~BNX2X_DEF_SB_IDX;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00004406 }
4407
4408 if (unlikely(status))
4409 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
4410 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004411
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004412 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
4413 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004414}
4415
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004416irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004417{
4418 struct net_device *dev = dev_instance;
4419 struct bnx2x *bp = netdev_priv(dev);
4420
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004421 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
4422 IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004423
4424#ifdef BNX2X_STOP_ON_ERROR
4425 if (unlikely(bp->panic))
4426 return IRQ_HANDLED;
4427#endif
4428
Michael Chan993ac7b2009-10-10 13:46:56 +00004429#ifdef BCM_CNIC
4430 {
4431 struct cnic_ops *c_ops;
4432
4433 rcu_read_lock();
4434 c_ops = rcu_dereference(bp->cnic_ops);
4435 if (c_ops)
4436 c_ops->cnic_handler(bp->cnic_data, NULL);
4437 rcu_read_unlock();
4438 }
4439#endif
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08004440 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004441
4442 return IRQ_HANDLED;
4443}
4444
4445/* end of slow path */
4446
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004447
4448void bnx2x_drv_pulse(struct bnx2x *bp)
4449{
4450 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
4451 bp->fw_drv_pulse_wr_seq);
4452}
4453
4454
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004455static void bnx2x_timer(unsigned long data)
4456{
4457 struct bnx2x *bp = (struct bnx2x *) data;
4458
4459 if (!netif_running(bp->dev))
4460 return;
4461
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004462 if (poll) {
4463 struct bnx2x_fastpath *fp = &bp->fp[0];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004464
Eilon Greenstein7961f792009-03-02 07:59:31 +00004465 bnx2x_tx_int(fp);
David S. Millerb8ee8322011-04-17 16:56:12 -07004466 bnx2x_rx_int(fp, 1000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004467 }
4468
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004469 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004470 int mb_idx = BP_FW_MB_IDX(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004471 u32 drv_pulse;
4472 u32 mcp_pulse;
4473
4474 ++bp->fw_drv_pulse_wr_seq;
4475 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
4476 /* TBD - add SYSTEM_TIME */
4477 drv_pulse = bp->fw_drv_pulse_wr_seq;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004478 bnx2x_drv_pulse(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004479
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004480 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004481 MCP_PULSE_SEQ_MASK);
4482 /* The delta between driver pulse and mcp response
4483 * should be 1 (before mcp response) or 0 (after mcp response)
4484 */
4485 if ((drv_pulse != mcp_pulse) &&
4486 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
4487 /* someone lost a heartbeat... */
4488 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
4489 drv_pulse, mcp_pulse);
4490 }
4491 }
4492
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07004493 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07004494 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004495
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004496 mod_timer(&bp->timer, jiffies + bp->current_interval);
4497}
4498
4499/* end of Statistics */
4500
4501/* nic init */
4502
4503/*
4504 * nic init service functions
4505 */
4506
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004507static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004508{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004509 u32 i;
4510 if (!(len%4) && !(addr%4))
4511 for (i = 0; i < len; i += 4)
4512 REG_WR(bp, addr + i, fill);
4513 else
4514 for (i = 0; i < len; i++)
4515 REG_WR8(bp, addr + i, fill);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004516
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004517}
4518
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004519/* helper: writes FP SP data to FW - data_size in dwords */
4520static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
4521 int fw_sb_id,
4522 u32 *sb_data_p,
4523 u32 data_size)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004524{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004525 int index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004526 for (index = 0; index < data_size; index++)
4527 REG_WR(bp, BAR_CSTRORM_INTMEM +
4528 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
4529 sizeof(u32)*index,
4530 *(sb_data_p + index));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004531}
4532
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004533static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
4534{
4535 u32 *sb_data_p;
4536 u32 data_size = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004537 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004538 struct hc_status_block_data_e1x sb_data_e1x;
4539
4540 /* disable the function first */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004541 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004542 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004543 sb_data_e2.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004544 sb_data_e2.common.p_func.vf_valid = false;
4545 sb_data_p = (u32 *)&sb_data_e2;
4546 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4547 } else {
4548 memset(&sb_data_e1x, 0,
4549 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004550 sb_data_e1x.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004551 sb_data_e1x.common.p_func.vf_valid = false;
4552 sb_data_p = (u32 *)&sb_data_e1x;
4553 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4554 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004555 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4556
4557 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4558 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
4559 CSTORM_STATUS_BLOCK_SIZE);
4560 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4561 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
4562 CSTORM_SYNC_BLOCK_SIZE);
4563}
4564
4565/* helper: writes SP SB data to FW */
4566static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
4567 struct hc_sp_status_block_data *sp_sb_data)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004568{
4569 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004570 int i;
4571 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
4572 REG_WR(bp, BAR_CSTRORM_INTMEM +
4573 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
4574 i*sizeof(u32),
4575 *((u32 *)sp_sb_data + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004576}
4577
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004578static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
4579{
4580 int func = BP_FUNC(bp);
4581 struct hc_sp_status_block_data sp_sb_data;
4582 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4583
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004584 sp_sb_data.state = SB_DISABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004585 sp_sb_data.p_func.vf_valid = false;
4586
4587 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
4588
4589 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4590 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
4591 CSTORM_SP_STATUS_BLOCK_SIZE);
4592 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
4593 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
4594 CSTORM_SP_SYNC_BLOCK_SIZE);
4595
4596}
4597
4598
4599static inline
4600void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
4601 int igu_sb_id, int igu_seg_id)
4602{
4603 hc_sm->igu_sb_id = igu_sb_id;
4604 hc_sm->igu_seg_id = igu_seg_id;
4605 hc_sm->timer_value = 0xFF;
4606 hc_sm->time_to_expire = 0xFFFFFFFF;
4607}
4608
stephen hemminger8d962862010-10-21 07:50:56 +00004609static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004610 u8 vf_valid, int fw_sb_id, int igu_sb_id)
4611{
4612 int igu_seg_id;
4613
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004614 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004615 struct hc_status_block_data_e1x sb_data_e1x;
4616 struct hc_status_block_sm *hc_sm_p;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004617 int data_size;
4618 u32 *sb_data_p;
4619
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004620 if (CHIP_INT_MODE_IS_BC(bp))
4621 igu_seg_id = HC_SEG_ACCESS_NORM;
4622 else
4623 igu_seg_id = IGU_SEG_ACCESS_NORM;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004624
4625 bnx2x_zero_fp_sb(bp, fw_sb_id);
4626
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004627 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004628 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004629 sb_data_e2.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004630 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
4631 sb_data_e2.common.p_func.vf_id = vfid;
4632 sb_data_e2.common.p_func.vf_valid = vf_valid;
4633 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
4634 sb_data_e2.common.same_igu_sb_1b = true;
4635 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
4636 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
4637 hc_sm_p = sb_data_e2.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004638 sb_data_p = (u32 *)&sb_data_e2;
4639 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
4640 } else {
4641 memset(&sb_data_e1x, 0,
4642 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004643 sb_data_e1x.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004644 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
4645 sb_data_e1x.common.p_func.vf_id = 0xff;
4646 sb_data_e1x.common.p_func.vf_valid = false;
4647 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
4648 sb_data_e1x.common.same_igu_sb_1b = true;
4649 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
4650 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
4651 hc_sm_p = sb_data_e1x.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004652 sb_data_p = (u32 *)&sb_data_e1x;
4653 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
4654 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004655
4656 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
4657 igu_sb_id, igu_seg_id);
4658 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
4659 igu_sb_id, igu_seg_id);
4660
4661 DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
4662
4663 /* write indecies to HW */
4664 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
4665}
4666
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004667static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004668 u16 tx_usec, u16 rx_usec)
4669{
4670 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX,
4671 false, rx_usec);
4672 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX,
4673 false, tx_usec);
4674}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004675
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004676static void bnx2x_init_def_sb(struct bnx2x *bp)
4677{
4678 struct host_sp_status_block *def_sb = bp->def_status_blk;
4679 dma_addr_t mapping = bp->def_status_blk_mapping;
4680 int igu_sp_sb_index;
4681 int igu_seg_id;
4682 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004683 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004684 int reg_offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004685 u64 section;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004686 int index;
4687 struct hc_sp_status_block_data sp_sb_data;
4688 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
4689
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004690 if (CHIP_INT_MODE_IS_BC(bp)) {
4691 igu_sp_sb_index = DEF_SB_IGU_ID;
4692 igu_seg_id = HC_SEG_ACCESS_DEF;
4693 } else {
4694 igu_sp_sb_index = bp->igu_dsb_id;
4695 igu_seg_id = IGU_SEG_ACCESS_DEF;
4696 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004697
4698 /* ATTN */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004699 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004700 atten_status_block);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004701 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004702
Eliezer Tamir49d66772008-02-28 11:53:13 -08004703 bp->attn_state = 0;
4704
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004705 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4706 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004707 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004708 int sindex;
4709 /* take care of sig[0]..sig[4] */
4710 for (sindex = 0; sindex < 4; sindex++)
4711 bp->attn_group[index].sig[sindex] =
4712 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004713
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004714 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004715 /*
4716 * enable5 is separate from the rest of the registers,
4717 * and therefore the address skip is 4
4718 * and not 16 between the different groups
4719 */
4720 bp->attn_group[index].sig[4] = REG_RD(bp,
4721 reg_offset + 0x10 + 0x4*index);
4722 else
4723 bp->attn_group[index].sig[4] = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004724 }
4725
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004726 if (bp->common.int_block == INT_BLOCK_HC) {
4727 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
4728 HC_REG_ATTN_MSG0_ADDR_L);
4729
4730 REG_WR(bp, reg_offset, U64_LO(section));
4731 REG_WR(bp, reg_offset + 4, U64_HI(section));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004732 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004733 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
4734 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
4735 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004736
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004737 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
4738 sp_sb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004739
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004740 bnx2x_zero_sp_sb(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004741
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004742 sp_sb_data.state = SB_ENABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004743 sp_sb_data.host_sb_addr.lo = U64_LO(section);
4744 sp_sb_data.host_sb_addr.hi = U64_HI(section);
4745 sp_sb_data.igu_sb_id = igu_sp_sb_index;
4746 sp_sb_data.igu_seg_id = igu_seg_id;
4747 sp_sb_data.p_func.pf_id = func;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004748 sp_sb_data.p_func.vnic_id = BP_VN(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004749 sp_sb_data.p_func.vf_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004750
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004751 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004752
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004753 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004754}
4755
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00004756void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004757{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004758 int i;
4759
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00004760 for_each_eth_queue(bp, i)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004761 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
Ariel Elior423cfa7e2011-03-14 13:43:22 -07004762 bp->tx_ticks, bp->rx_ticks);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004763}
4764
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004765static void bnx2x_init_sp_ring(struct bnx2x *bp)
4766{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004767 spin_lock_init(&bp->spq_lock);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004768 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004769
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004770 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004771 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
4772 bp->spq_prod_bd = bp->spq;
4773 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004774}
4775
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004776static void bnx2x_init_eq_ring(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004777{
4778 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004779 for (i = 1; i <= NUM_EQ_PAGES; i++) {
4780 union event_ring_elem *elem =
4781 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004782
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004783 elem->next_page.addr.hi =
4784 cpu_to_le32(U64_HI(bp->eq_mapping +
4785 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
4786 elem->next_page.addr.lo =
4787 cpu_to_le32(U64_LO(bp->eq_mapping +
4788 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004789 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004790 bp->eq_cons = 0;
4791 bp->eq_prod = NUM_EQ_DESC;
4792 bp->eq_cons_sb = BNX2X_EQ_INDEX;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08004793 /* we want a warning message before it gets rought... */
4794 atomic_set(&bp->eq_spq_left,
4795 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004796}
4797
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004798
4799/* called with netif_addr_lock_bh() */
4800void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
4801 unsigned long rx_mode_flags,
4802 unsigned long rx_accept_flags,
4803 unsigned long tx_accept_flags,
4804 unsigned long ramrod_flags)
Tom Herbertab532cf2011-02-16 10:27:02 +00004805{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004806 struct bnx2x_rx_mode_ramrod_params ramrod_param;
4807 int rc;
Tom Herbertab532cf2011-02-16 10:27:02 +00004808
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004809 memset(&ramrod_param, 0, sizeof(ramrod_param));
Tom Herbertab532cf2011-02-16 10:27:02 +00004810
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004811 /* Prepare ramrod parameters */
4812 ramrod_param.cid = 0;
4813 ramrod_param.cl_id = cl_id;
4814 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
4815 ramrod_param.func_id = BP_FUNC(bp);
4816
4817 ramrod_param.pstate = &bp->sp_state;
4818 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
4819
4820 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
4821 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
4822
4823 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4824
4825 ramrod_param.ramrod_flags = ramrod_flags;
4826 ramrod_param.rx_mode_flags = rx_mode_flags;
4827
4828 ramrod_param.rx_accept_flags = rx_accept_flags;
4829 ramrod_param.tx_accept_flags = tx_accept_flags;
4830
4831 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
4832 if (rc < 0) {
4833 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
4834 return;
4835 }
4836}
4837
4838/* called with netif_addr_lock_bh() */
4839void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
4840{
4841 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
4842 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
4843
4844#ifdef BCM_CNIC
4845 if (!NO_FCOE(bp))
4846
4847 /* Configure rx_mode of FCoE Queue */
4848 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
4849#endif
4850
4851 switch (bp->rx_mode) {
4852 case BNX2X_RX_MODE_NONE:
4853 /*
4854 * 'drop all' supersedes any accept flags that may have been
4855 * passed to the function.
4856 */
4857 break;
4858 case BNX2X_RX_MODE_NORMAL:
4859 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4860 __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
4861 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4862
4863 /* internal switching mode */
4864 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4865 __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
4866 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4867
4868 break;
4869 case BNX2X_RX_MODE_ALLMULTI:
4870 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4871 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4872 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4873
4874 /* internal switching mode */
4875 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4876 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4877 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4878
4879 break;
4880 case BNX2X_RX_MODE_PROMISC:
4881 /* According to deffinition of SI mode, iface in promisc mode
4882 * should receive matched and unmatched (in resolution of port)
4883 * unicast packets.
4884 */
4885 __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
4886 __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
4887 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
4888 __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
4889
4890 /* internal switching mode */
4891 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
4892 __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
4893
4894 if (IS_MF_SI(bp))
4895 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
4896 else
4897 __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
4898
4899 break;
4900 default:
4901 BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
4902 return;
4903 }
4904
4905 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
4906 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
4907 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
4908 }
4909
4910 __set_bit(RAMROD_RX, &ramrod_flags);
4911 __set_bit(RAMROD_TX, &ramrod_flags);
4912
4913 bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
4914 tx_accept_flags, ramrod_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004915}
4916
Eilon Greenstein471de712008-08-13 15:49:35 -07004917static void bnx2x_init_internal_common(struct bnx2x *bp)
4918{
4919 int i;
4920
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004921 if (IS_MF_SI(bp))
4922 /*
4923 * In switch independent mode, the TSTORM needs to accept
4924 * packets that failed classification, since approximate match
4925 * mac addresses aren't written to NIG LLH
4926 */
4927 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4928 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004929 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
4930 REG_WR8(bp, BAR_TSTRORM_INTMEM +
4931 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004932
Eilon Greenstein471de712008-08-13 15:49:35 -07004933 /* Zero this manually as its initialization is
4934 currently missing in the initTool */
4935 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
4936 REG_WR(bp, BAR_USTRORM_INTMEM +
4937 USTORM_AGG_DATA_OFFSET + i * 4, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004938 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004939 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
4940 CHIP_INT_MODE_IS_BC(bp) ?
4941 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
4942 }
Eilon Greenstein471de712008-08-13 15:49:35 -07004943}
4944
Eilon Greenstein471de712008-08-13 15:49:35 -07004945static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
4946{
4947 switch (load_code) {
4948 case FW_MSG_CODE_DRV_LOAD_COMMON:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004949 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
Eilon Greenstein471de712008-08-13 15:49:35 -07004950 bnx2x_init_internal_common(bp);
4951 /* no break */
4952
4953 case FW_MSG_CODE_DRV_LOAD_PORT:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004954 /* nothing to do */
Eilon Greenstein471de712008-08-13 15:49:35 -07004955 /* no break */
4956
4957 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004958 /* internal memory per function is
4959 initialized inside bnx2x_pf_init */
Eilon Greenstein471de712008-08-13 15:49:35 -07004960 break;
4961
4962 default:
4963 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
4964 break;
4965 }
4966}
4967
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004968static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
4969{
4970 return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE;
4971}
4972
4973static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
4974{
4975 return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE;
4976}
4977
4978static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
4979{
4980 if (CHIP_IS_E1x(fp->bp))
4981 return BP_L_ID(fp->bp) + fp->index;
4982 else /* We want Client ID to be the same as IGU SB ID for 57712 */
4983 return bnx2x_fp_igu_sb_id(fp);
4984}
4985
4986static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004987{
4988 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004989 unsigned long q_type = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004990
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00004991 fp->cid = fp_idx;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004992 fp->cl_id = bnx2x_fp_cl_id(fp);
4993 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
4994 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004995 /* qZone id equals to FW (per path) client id */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004996 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
4997
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004998 /* init shortcut */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004999 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005000 /* Setup SB indicies */
5001 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
5002 fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
5003
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005004 /* Configure Queue State object */
5005 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
5006 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
5007 bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp),
5008 bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata),
5009 q_type);
5010
5011 /**
5012 * Configure classification DBs: Always enable Tx switching
5013 */
5014 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
5015
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005016 DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
5017 "cl_id %d fw_sb %d igu_sb %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005018 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005019 fp->igu_sb_id);
5020 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
5021 fp->fw_sb_id, fp->igu_sb_id);
5022
5023 bnx2x_update_fpsb_idx(fp);
5024}
5025
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005026void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005027{
5028 int i;
5029
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005030 for_each_eth_queue(bp, i)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005031 bnx2x_init_fp(bp, i);
Michael Chan37b091b2009-10-10 13:46:55 +00005032#ifdef BCM_CNIC
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005033 if (!NO_FCOE(bp))
5034 bnx2x_init_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005035
5036 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
5037 BNX2X_VF_ID_INVALID, false,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005038 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005039
Michael Chan37b091b2009-10-10 13:46:55 +00005040#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005041
Yaniv Rosner020c7e32011-05-31 21:28:43 +00005042 /* Initialize MOD_ABS interrupts */
5043 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
5044 bp->common.shmem_base, bp->common.shmem2_base,
5045 BP_PORT(bp));
Eilon Greenstein16119782009-03-02 07:59:27 +00005046 /* ensure status block indices were read */
5047 rmb();
5048
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005049 bnx2x_init_def_sb(bp);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005050 bnx2x_update_dsb_idx(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005051 bnx2x_init_rx_rings(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005052 bnx2x_init_tx_rings(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005053 bnx2x_init_sp_ring(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005054 bnx2x_init_eq_ring(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07005055 bnx2x_init_internal(bp, load_code);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005056 bnx2x_pf_init(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005057 bnx2x_stats_init(bp);
5058
Eilon Greenstein0ef00452009-01-14 21:31:08 -08005059 /* flush all before enabling interrupts */
5060 mb();
5061 mmiowb();
5062
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08005063 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00005064
5065 /* Check for SPIO5 */
5066 bnx2x_attn_int_deasserted0(bp,
5067 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
5068 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005069}
5070
5071/* end of nic init */
5072
5073/*
5074 * gzip service functions
5075 */
5076
5077static int bnx2x_gunzip_init(struct bnx2x *bp)
5078{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005079 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
5080 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005081 if (bp->gunzip_buf == NULL)
5082 goto gunzip_nomem1;
5083
5084 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
5085 if (bp->strm == NULL)
5086 goto gunzip_nomem2;
5087
5088 bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
5089 GFP_KERNEL);
5090 if (bp->strm->workspace == NULL)
5091 goto gunzip_nomem3;
5092
5093 return 0;
5094
5095gunzip_nomem3:
5096 kfree(bp->strm);
5097 bp->strm = NULL;
5098
5099gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005100 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5101 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005102 bp->gunzip_buf = NULL;
5103
5104gunzip_nomem1:
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005105 netdev_err(bp->dev, "Cannot allocate firmware buffer for"
5106 " un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005107 return -ENOMEM;
5108}
5109
5110static void bnx2x_gunzip_end(struct bnx2x *bp)
5111{
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00005112 if (bp->strm) {
5113 kfree(bp->strm->workspace);
5114 kfree(bp->strm);
5115 bp->strm = NULL;
5116 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005117
5118 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00005119 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
5120 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005121 bp->gunzip_buf = NULL;
5122 }
5123}
5124
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005125static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005126{
5127 int n, rc;
5128
5129 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005130 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
5131 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005132 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005133 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005134
5135 n = 10;
5136
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005137#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005138
5139 if (zbuf[3] & FNAME)
5140 while ((zbuf[n++] != 0) && (n < len));
5141
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07005142 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005143 bp->strm->avail_in = len - n;
5144 bp->strm->next_out = bp->gunzip_buf;
5145 bp->strm->avail_out = FW_BUF_SIZE;
5146
5147 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
5148 if (rc != Z_OK)
5149 return rc;
5150
5151 rc = zlib_inflate(bp->strm, Z_FINISH);
5152 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00005153 netdev_err(bp->dev, "Firmware decompression error: %s\n",
5154 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005155
5156 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
5157 if (bp->gunzip_outlen & 0x3)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005158 netdev_err(bp->dev, "Firmware decompression error:"
5159 " gunzip_outlen (%d) not aligned\n",
5160 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005161 bp->gunzip_outlen >>= 2;
5162
5163 zlib_inflateEnd(bp->strm);
5164
5165 if (rc == Z_STREAM_END)
5166 return 0;
5167
5168 return rc;
5169}
5170
5171/* nic load/unload */
5172
5173/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005174 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005175 */
5176
5177/* send a NIG loopback debug packet */
5178static void bnx2x_lb_pckt(struct bnx2x *bp)
5179{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005180 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005181
5182 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005183 wb_write[0] = 0x55555555;
5184 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005185 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005186 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005187
5188 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005189 wb_write[0] = 0x09000000;
5190 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005191 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005192 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005193}
5194
5195/* some of the internal memories
5196 * are not directly readable from the driver
5197 * to test them we send debug packets
5198 */
5199static int bnx2x_int_mem_test(struct bnx2x *bp)
5200{
5201 int factor;
5202 int count, i;
5203 u32 val = 0;
5204
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005205 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005206 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07005207 else if (CHIP_REV_IS_EMUL(bp))
5208 factor = 200;
5209 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005210 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005211
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005212 /* Disable inputs of parser neighbor blocks */
5213 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5214 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5215 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005216 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005217
5218 /* Write 0 to parser credits for CFC search request */
5219 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5220
5221 /* send Ethernet packet */
5222 bnx2x_lb_pckt(bp);
5223
5224 /* TODO do i reset NIG statistic? */
5225 /* Wait until NIG register shows 1 packet of size 0x10 */
5226 count = 1000 * factor;
5227 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005228
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005229 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5230 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005231 if (val == 0x10)
5232 break;
5233
5234 msleep(10);
5235 count--;
5236 }
5237 if (val != 0x10) {
5238 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5239 return -1;
5240 }
5241
5242 /* Wait until PRS register shows 1 packet */
5243 count = 1000 * factor;
5244 while (count) {
5245 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005246 if (val == 1)
5247 break;
5248
5249 msleep(10);
5250 count--;
5251 }
5252 if (val != 0x1) {
5253 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5254 return -2;
5255 }
5256
5257 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005258 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005259 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005260 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005261 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005262 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5263 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005264
5265 DP(NETIF_MSG_HW, "part2\n");
5266
5267 /* Disable inputs of parser neighbor blocks */
5268 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
5269 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
5270 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005271 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005272
5273 /* Write 0 to parser credits for CFC search request */
5274 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
5275
5276 /* send 10 Ethernet packets */
5277 for (i = 0; i < 10; i++)
5278 bnx2x_lb_pckt(bp);
5279
5280 /* Wait until NIG register shows 10 + 1
5281 packets of size 11*0x10 = 0xb0 */
5282 count = 1000 * factor;
5283 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005284
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005285 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5286 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005287 if (val == 0xb0)
5288 break;
5289
5290 msleep(10);
5291 count--;
5292 }
5293 if (val != 0xb0) {
5294 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
5295 return -3;
5296 }
5297
5298 /* Wait until PRS register shows 2 packets */
5299 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5300 if (val != 2)
5301 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5302
5303 /* Write 1 to parser credits for CFC search request */
5304 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
5305
5306 /* Wait until PRS register shows 3 packets */
5307 msleep(10 * factor);
5308 /* Wait until NIG register shows 1 packet of size 0x10 */
5309 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
5310 if (val != 3)
5311 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
5312
5313 /* clear NIG EOP FIFO */
5314 for (i = 0; i < 11; i++)
5315 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
5316 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
5317 if (val != 1) {
5318 BNX2X_ERR("clear of NIG failed\n");
5319 return -4;
5320 }
5321
5322 /* Reset and init BRB, PRS, NIG */
5323 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
5324 msleep(50);
5325 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
5326 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005327 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
5328 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00005329#ifndef BCM_CNIC
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005330 /* set NIC mode */
5331 REG_WR(bp, PRS_REG_NIC_MODE, 1);
5332#endif
5333
5334 /* Enable inputs of parser neighbor blocks */
5335 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
5336 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
5337 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005338 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005339
5340 DP(NETIF_MSG_HW, "done\n");
5341
5342 return 0; /* OK */
5343}
5344
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005345static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005346{
5347 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005348 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005349 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
5350 else
5351 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005352 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
5353 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005354 /*
5355 * mask read length error interrupts in brb for parser
5356 * (parsing unit and 'checksum and crc' unit)
5357 * these errors are legal (PU reads fixed length and CAC can cause
5358 * read length error on truncated packets)
5359 */
5360 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005361 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
5362 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
5363 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
5364 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
5365 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005366/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
5367/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005368 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
5369 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
5370 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005371/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
5372/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005373 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
5374 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
5375 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
5376 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005377/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
5378/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005379
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005380 if (CHIP_REV_IS_FPGA(bp))
5381 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005382 else if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005383 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
5384 (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
5385 | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
5386 | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
5387 | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
5388 | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005389 else
5390 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005391 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
5392 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
5393 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005394/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005395
5396 if (!CHIP_IS_E1x(bp))
5397 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
5398 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
5399
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005400 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
5401 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005402/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005403 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005404}
5405
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005406static void bnx2x_reset_common(struct bnx2x *bp)
5407{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005408 u32 val = 0x1400;
5409
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005410 /* reset_common */
5411 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5412 0xd3ffff7f);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005413
5414 if (CHIP_IS_E3(bp)) {
5415 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5416 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5417 }
5418
5419 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
5420}
5421
5422static void bnx2x_setup_dmae(struct bnx2x *bp)
5423{
5424 bp->dmae_ready = 0;
5425 spin_lock_init(&bp->dmae_lock);
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005426}
5427
Eilon Greenstein573f2032009-08-12 08:24:14 +00005428static void bnx2x_init_pxp(struct bnx2x *bp)
5429{
5430 u16 devctl;
5431 int r_order, w_order;
5432
5433 pci_read_config_word(bp->pdev,
5434 bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
5435 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
5436 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
5437 if (bp->mrrs == -1)
5438 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
5439 else {
5440 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
5441 r_order = bp->mrrs;
5442 }
5443
5444 bnx2x_init_pxp_arb(bp, r_order, w_order);
5445}
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005446
5447static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
5448{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005449 int is_required;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005450 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005451 int port;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005452
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00005453 if (BP_NOMCP(bp))
5454 return;
5455
5456 is_required = 0;
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005457 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
5458 SHARED_HW_CFG_FAN_FAILURE_MASK;
5459
5460 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
5461 is_required = 1;
5462
5463 /*
5464 * The fan failure mechanism is usually related to the PHY type since
5465 * the power consumption of the board is affected by the PHY. Currently,
5466 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
5467 */
5468 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
5469 for (port = PORT_0; port < PORT_MAX; port++) {
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005470 is_required |=
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00005471 bnx2x_fan_failure_det_req(
5472 bp,
5473 bp->common.shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005474 bp->common.shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00005475 port);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005476 }
5477
5478 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
5479
5480 if (is_required == 0)
5481 return;
5482
5483 /* Fan failure is indicated by SPIO 5 */
5484 bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
5485 MISC_REGISTERS_SPIO_INPUT_HI_Z);
5486
5487 /* set to active low mode */
5488 val = REG_RD(bp, MISC_REG_SPIO_INT);
5489 val |= ((1 << MISC_REGISTERS_SPIO_5) <<
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005490 MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005491 REG_WR(bp, MISC_REG_SPIO_INT, val);
5492
5493 /* enable interrupt to signal the IGU */
5494 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
5495 val |= (1 << MISC_REGISTERS_SPIO_5);
5496 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
5497}
5498
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005499static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
5500{
5501 u32 offset = 0;
5502
5503 if (CHIP_IS_E1(bp))
5504 return;
5505 if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
5506 return;
5507
5508 switch (BP_ABS_FUNC(bp)) {
5509 case 0:
5510 offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
5511 break;
5512 case 1:
5513 offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
5514 break;
5515 case 2:
5516 offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
5517 break;
5518 case 3:
5519 offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
5520 break;
5521 case 4:
5522 offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
5523 break;
5524 case 5:
5525 offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
5526 break;
5527 case 6:
5528 offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
5529 break;
5530 case 7:
5531 offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
5532 break;
5533 default:
5534 return;
5535 }
5536
5537 REG_WR(bp, offset, pretend_func_num);
5538 REG_RD(bp, offset);
5539 DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
5540}
5541
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00005542void bnx2x_pf_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005543{
5544 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
5545 val &= ~IGU_PF_CONF_FUNC_EN;
5546
5547 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
5548 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5549 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
5550}
5551
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005552static inline void bnx2x__common_init_phy(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005553{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005554 u32 shmem_base[2], shmem2_base[2];
5555 shmem_base[0] = bp->common.shmem_base;
5556 shmem2_base[0] = bp->common.shmem2_base;
5557 if (!CHIP_IS_E1x(bp)) {
5558 shmem_base[1] =
5559 SHMEM2_RD(bp, other_shmem_base_addr);
5560 shmem2_base[1] =
5561 SHMEM2_RD(bp, other_shmem2_base_addr);
5562 }
5563 bnx2x_acquire_phy_lock(bp);
5564 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
5565 bp->common.chip_id);
5566 bnx2x_release_phy_lock(bp);
5567}
5568
5569/**
5570 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
5571 *
5572 * @bp: driver handle
5573 */
5574static int bnx2x_init_hw_common(struct bnx2x *bp)
5575{
5576 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005577
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005578 DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005579
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00005580 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005581 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005582
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005583 val = 0xfffc;
5584 if (CHIP_IS_E3(bp)) {
5585 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
5586 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
5587 }
5588 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005589
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005590 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
5591
5592 if (!CHIP_IS_E1x(bp)) {
5593 u8 abs_func_id;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005594
5595 /**
5596 * 4-port mode or 2-port mode we need to turn of master-enable
5597 * for everyone, after that, turn it back on for self.
5598 * so, we disregard multi-function or not, and always disable
5599 * for all functions on the given path, this means 0,2,4,6 for
5600 * path 0 and 1,3,5,7 for path 1
5601 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005602 for (abs_func_id = BP_PATH(bp);
5603 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
5604 if (abs_func_id == BP_ABS_FUNC(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005605 REG_WR(bp,
5606 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
5607 1);
5608 continue;
5609 }
5610
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005611 bnx2x_pretend_func(bp, abs_func_id);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005612 /* clear pf enable */
5613 bnx2x_pf_disable(bp);
5614 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5615 }
5616 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005617
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005618 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005619 if (CHIP_IS_E1(bp)) {
5620 /* enable HW interrupt from PXP on USDM overflow
5621 bit 16 on INT_MASK_0 */
5622 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005623 }
5624
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005625 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005626 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005627
5628#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005629 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
5630 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
5631 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
5632 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
5633 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00005634 /* make sure this value is 0 */
5635 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005636
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005637/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
5638 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
5639 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
5640 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
5641 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005642#endif
5643
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005644 bnx2x_ilt_init_page_size(bp, INITOP_SET);
5645
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005646 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
5647 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005648
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005649 /* let the HW do it's magic ... */
5650 msleep(100);
5651 /* finish PXP init */
5652 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
5653 if (val != 1) {
5654 BNX2X_ERR("PXP2 CFG failed\n");
5655 return -EBUSY;
5656 }
5657 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
5658 if (val != 1) {
5659 BNX2X_ERR("PXP2 RD_INIT failed\n");
5660 return -EBUSY;
5661 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005662
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005663 /* Timers bug workaround E2 only. We need to set the entire ILT to
5664 * have entries with value "0" and valid bit on.
5665 * This needs to be done by the first PF that is loaded in a path
5666 * (i.e. common phase)
5667 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005668 if (!CHIP_IS_E1x(bp)) {
5669/* In E2 there is a bug in the timers block that can cause function 6 / 7
5670 * (i.e. vnic3) to start even if it is marked as "scan-off".
5671 * This occurs when a different function (func2,3) is being marked
5672 * as "scan-off". Real-life scenario for example: if a driver is being
5673 * load-unloaded while func6,7 are down. This will cause the timer to access
5674 * the ilt, translate to a logical address and send a request to read/write.
5675 * Since the ilt for the function that is down is not valid, this will cause
5676 * a translation error which is unrecoverable.
5677 * The Workaround is intended to make sure that when this happens nothing fatal
5678 * will occur. The workaround:
5679 * 1. First PF driver which loads on a path will:
5680 * a. After taking the chip out of reset, by using pretend,
5681 * it will write "0" to the following registers of
5682 * the other vnics.
5683 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
5684 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
5685 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
5686 * And for itself it will write '1' to
5687 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
5688 * dmae-operations (writing to pram for example.)
5689 * note: can be done for only function 6,7 but cleaner this
5690 * way.
5691 * b. Write zero+valid to the entire ILT.
5692 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
5693 * VNIC3 (of that port). The range allocated will be the
5694 * entire ILT. This is needed to prevent ILT range error.
5695 * 2. Any PF driver load flow:
5696 * a. ILT update with the physical addresses of the allocated
5697 * logical pages.
5698 * b. Wait 20msec. - note that this timeout is needed to make
5699 * sure there are no requests in one of the PXP internal
5700 * queues with "old" ILT addresses.
5701 * c. PF enable in the PGLC.
5702 * d. Clear the was_error of the PF in the PGLC. (could have
5703 * occured while driver was down)
5704 * e. PF enable in the CFC (WEAK + STRONG)
5705 * f. Timers scan enable
5706 * 3. PF driver unload flow:
5707 * a. Clear the Timers scan_en.
5708 * b. Polling for scan_on=0 for that PF.
5709 * c. Clear the PF enable bit in the PXP.
5710 * d. Clear the PF enable in the CFC (WEAK + STRONG)
5711 * e. Write zero+valid to all ILT entries (The valid bit must
5712 * stay set)
5713 * f. If this is VNIC 3 of a port then also init
5714 * first_timers_ilt_entry to zero and last_timers_ilt_entry
5715 * to the last enrty in the ILT.
5716 *
5717 * Notes:
5718 * Currently the PF error in the PGLC is non recoverable.
5719 * In the future the there will be a recovery routine for this error.
5720 * Currently attention is masked.
5721 * Having an MCP lock on the load/unload process does not guarantee that
5722 * there is no Timer disable during Func6/7 enable. This is because the
5723 * Timers scan is currently being cleared by the MCP on FLR.
5724 * Step 2.d can be done only for PF6/7 and the driver can also check if
5725 * there is error before clearing it. But the flow above is simpler and
5726 * more general.
5727 * All ILT entries are written by zero+valid and not just PF6/7
5728 * ILT entries since in the future the ILT entries allocation for
5729 * PF-s might be dynamic.
5730 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005731 struct ilt_client_info ilt_cli;
5732 struct bnx2x_ilt ilt;
5733 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
5734 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
5735
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04005736 /* initialize dummy TM client */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005737 ilt_cli.start = 0;
5738 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
5739 ilt_cli.client_num = ILT_CLIENT_TM;
5740
5741 /* Step 1: set zeroes to all ilt page entries with valid bit on
5742 * Step 2: set the timers first/last ilt entry to point
5743 * to the entire range to prevent ILT range error for 3rd/4th
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005744 * vnic (this code assumes existance of the vnic)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005745 *
5746 * both steps performed by call to bnx2x_ilt_client_init_op()
5747 * with dummy TM client
5748 *
5749 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
5750 * and his brother are split registers
5751 */
5752 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
5753 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
5754 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
5755
5756 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
5757 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
5758 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
5759 }
5760
5761
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005762 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
5763 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005764
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005765 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005766 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
5767 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005768 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005769
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005770 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005771
5772 /* let the HW do it's magic ... */
5773 do {
5774 msleep(200);
5775 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
5776 } while (factor-- && (val != 1));
5777
5778 if (val != 1) {
5779 BNX2X_ERR("ATC_INIT failed\n");
5780 return -EBUSY;
5781 }
5782 }
5783
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005784 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005785
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005786 /* clean the DMAE memory */
5787 bp->dmae_ready = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005788 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005789
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005790 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
5791
5792 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
5793
5794 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
5795
5796 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005797
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005798 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
5799 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
5800 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
5801 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
5802
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005803 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00005804
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005805
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005806 /* QM queues pointers table */
5807 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
Michael Chan37b091b2009-10-10 13:46:55 +00005808
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005809 /* soft reset pulse */
5810 REG_WR(bp, QM_REG_SOFT_RESET, 1);
5811 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005812
Michael Chan37b091b2009-10-10 13:46:55 +00005813#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005814 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005815#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005816
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005817 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005818 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005819 if (!CHIP_REV_IS_SLOW(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005820 /* enable hw interrupt from doorbell Q */
5821 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005822
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005823 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005824
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005825 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08005826 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005827
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005828 if (!CHIP_IS_E1(bp))
5829 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
5830
5831 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
5832 /* Bit-map indicating which L2 hdrs may appear
5833 * after the basic Ethernet header
5834 */
5835 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
5836 bp->path_has_ovlan ? 7 : 6);
5837
5838 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
5839 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
5840 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
5841 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
5842
5843 if (!CHIP_IS_E1x(bp)) {
5844 /* reset VFC memories */
5845 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5846 VFC_MEMORIES_RST_REG_CAM_RST |
5847 VFC_MEMORIES_RST_REG_RAM_RST);
5848 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
5849 VFC_MEMORIES_RST_REG_CAM_RST |
5850 VFC_MEMORIES_RST_REG_RAM_RST);
5851
5852 msleep(20);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005853 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005854
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005855 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
5856 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
5857 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
5858 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005859
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005860 /* sync semi rtc */
5861 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
5862 0x80000000);
5863 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
5864 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005865
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005866 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
5867 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
5868 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005869
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005870 if (!CHIP_IS_E1x(bp))
5871 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
5872 bp->path_has_ovlan ? 7 : 6);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005873
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005874 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00005875
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005876 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
5877
Michael Chan37b091b2009-10-10 13:46:55 +00005878#ifdef BCM_CNIC
5879 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
5880 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
5881 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
5882 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
5883 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
5884 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
5885 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
5886 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
5887 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
5888 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
5889#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005890 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005891
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005892 if (sizeof(union cdu_context) != 1024)
5893 /* we currently assume that a context is 1024 bytes */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005894 dev_alert(&bp->pdev->dev, "please adjust the size "
5895 "of cdu_context(%ld)\n",
Joe Perches7995c642010-02-17 15:01:52 +00005896 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005897
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005898 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005899 val = (4 << 24) + (0 << 12) + 1024;
5900 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005901
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005902 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005903 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08005904 /* enable context validation interrupt from CFC */
5905 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
5906
5907 /* set the thresholds to prevent CFC/CDU race */
5908 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005909
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005910 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005911
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005912 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005913 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
5914
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005915 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
5916 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005917
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005918 /* Reset PCIE errors for debug */
5919 REG_WR(bp, 0x2814, 0xffffffff);
5920 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005921
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005922 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005923 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
5924 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
5925 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
5926 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
5927 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
5928 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
5929 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
5930 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
5931 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
5932 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
5933 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
5934 }
5935
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005936 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005937 if (!CHIP_IS_E1(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005938 /* in E3 this done in per-port section */
5939 if (!CHIP_IS_E3(bp))
5940 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
5941 }
5942 if (CHIP_IS_E1H(bp))
5943 /* not applicable for E2 (and above ...) */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08005944 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005945
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005946 if (CHIP_REV_IS_SLOW(bp))
5947 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005948
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005949 /* finish CFC init */
5950 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
5951 if (val != 1) {
5952 BNX2X_ERR("CFC LL_INIT failed\n");
5953 return -EBUSY;
5954 }
5955 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
5956 if (val != 1) {
5957 BNX2X_ERR("CFC AC_INIT failed\n");
5958 return -EBUSY;
5959 }
5960 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
5961 if (val != 1) {
5962 BNX2X_ERR("CFC CAM_INIT failed\n");
5963 return -EBUSY;
5964 }
5965 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005966
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005967 if (CHIP_IS_E1(bp)) {
5968 /* read NIG statistic
5969 to see if this is our first up since powerup */
5970 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
5971 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005972
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005973 /* do internal memory self test */
5974 if ((val == 0) && bnx2x_int_mem_test(bp)) {
5975 BNX2X_ERR("internal mem self test failed\n");
5976 return -EBUSY;
5977 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005978 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005979
Eilon Greensteinfd4ef40d2009-07-21 05:47:27 +00005980 bnx2x_setup_fan_failure_detection(bp);
5981
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005982 /* clear PXP2 attentions */
5983 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005984
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00005985 bnx2x_enable_blocks_attention(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00005986 bnx2x_enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005987
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005988 if (!BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005989 if (CHIP_IS_E1x(bp))
5990 bnx2x__common_init_phy(bp);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005991 } else
5992 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
5993
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005994 return 0;
5995}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005996
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005997/**
5998 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
5999 *
6000 * @bp: driver handle
6001 */
6002static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
6003{
6004 int rc = bnx2x_init_hw_common(bp);
6005
6006 if (rc)
6007 return rc;
6008
6009 /* In E2 2-PORT mode, same ext phy is used for the two paths */
6010 if (!BP_NOMCP(bp))
6011 bnx2x__common_init_phy(bp);
6012
6013 return 0;
6014}
6015
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006016static int bnx2x_init_hw_port(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006017{
6018 int port = BP_PORT(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006019 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
Eilon Greenstein1c063282009-02-12 08:36:43 +00006020 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006021 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006022
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006023 bnx2x__link_reset(bp);
6024
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006025 DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006026
6027 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006028
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006029 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6030 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6031 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
Eilon Greensteinca003922009-08-12 22:53:28 -07006032
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006033 /* Timers bug workaround: disables the pf_master bit in pglue at
6034 * common phase, we need to enable it here before any dmae access are
6035 * attempted. Therefore we manually added the enable-master to the
6036 * port phase (it also happens in the function phase)
6037 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006038 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006039 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6040
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006041 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6042 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6043 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
6044 bnx2x_init_block(bp, BLOCK_QM, init_phase);
6045
6046 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6047 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6048 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6049 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006050
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006051 /* QM cid (connection) count */
6052 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006053
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006054#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006055 bnx2x_init_block(bp, BLOCK_TM, init_phase);
Michael Chan37b091b2009-10-10 13:46:55 +00006056 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
6057 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006058#endif
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006059
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006060 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Eilon Greenstein1c063282009-02-12 08:36:43 +00006061
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006062 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006063 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6064
6065 if (IS_MF(bp))
6066 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
6067 else if (bp->dev->mtu > 4096) {
6068 if (bp->flags & ONE_PORT_FLAG)
6069 low = 160;
6070 else {
6071 val = bp->dev->mtu;
6072 /* (24*1024 + val*4)/256 */
6073 low = 96 + (val/64) +
6074 ((val % 64) ? 1 : 0);
6075 }
6076 } else
6077 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
6078 high = low + 56; /* 14*1024/256 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006079 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
6080 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
6081 }
6082
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006083 if (CHIP_MODE_IS_4_PORT(bp))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006084 REG_WR(bp, (BP_PORT(bp) ?
6085 BRB1_REG_MAC_GUARANTIED_1 :
6086 BRB1_REG_MAC_GUARANTIED_0), 40);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006087
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006088
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006089 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6090 if (CHIP_IS_E3B0(bp))
6091 /* Ovlan exists only if we are in multi-function +
6092 * switch-dependent mode, in switch-independent there
6093 * is no ovlan headers
6094 */
6095 REG_WR(bp, BP_PORT(bp) ?
6096 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
6097 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
6098 (bp->path_has_ovlan ? 7 : 6));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006099
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006100 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6101 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6102 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6103 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6104
6105 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6106 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6107 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6108 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
6109
6110 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6111 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6112
6113 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6114
6115 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006116 /* configure PBF to work without PAUSE mtu 9000 */
6117 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006118
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006119 /* update threshold */
6120 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
6121 /* update init credit */
6122 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006123
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006124 /* probe changes */
6125 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
6126 udelay(50);
6127 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
6128 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006129
Michael Chan37b091b2009-10-10 13:46:55 +00006130#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006131 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006132#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006133 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
6134 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006135
6136 if (CHIP_IS_E1(bp)) {
6137 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6138 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6139 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006140 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006141
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006142 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006143
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006144 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006145 /* init aeu_mask_attn_func_0/1:
6146 * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
6147 * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
6148 * bits 4-7 are used for "per vn group attention" */
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00006149 val = IS_MF(bp) ? 0xF7 : 0x7;
6150 /* Enable DCBX attention for all but E1 */
6151 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
6152 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006153
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006154 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
Eilon Greenstein356e2382009-02-12 08:38:32 +00006155
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006156 if (!CHIP_IS_E1x(bp)) {
6157 /* Bit-map indicating which L2 hdrs may appear after the
6158 * basic Ethernet header
6159 */
6160 REG_WR(bp, BP_PORT(bp) ?
6161 NIG_REG_P1_HDRS_AFTER_BASIC :
6162 NIG_REG_P0_HDRS_AFTER_BASIC,
6163 IS_MF_SD(bp) ? 7 : 6);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006164
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006165 if (CHIP_IS_E3(bp))
6166 REG_WR(bp, BP_PORT(bp) ?
6167 NIG_REG_LLH1_MF_MODE :
6168 NIG_REG_LLH_MF_MODE, IS_MF(bp));
6169 }
6170 if (!CHIP_IS_E3(bp))
6171 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006172
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006173 if (!CHIP_IS_E1(bp)) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006174 /* 0x2 disable mf_ov, 0x1 enable */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006175 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006176 (IS_MF_SD(bp) ? 0x1 : 0x2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006177
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006178 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006179 val = 0;
6180 switch (bp->mf_mode) {
6181 case MULTI_FUNCTION_SD:
6182 val = 1;
6183 break;
6184 case MULTI_FUNCTION_SI:
6185 val = 2;
6186 break;
6187 }
6188
6189 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
6190 NIG_REG_LLH0_CLS_TYPE), val);
6191 }
Eilon Greenstein1c063282009-02-12 08:36:43 +00006192 {
6193 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
6194 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
6195 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
6196 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006197 }
6198
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006199
6200 /* If SPIO5 is set to generate interrupts, enable it for this port */
6201 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
6202 if (val & (1 << MISC_REGISTERS_SPIO_5)) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006203 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
6204 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
6205 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006206 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006207 REG_WR(bp, reg_addr, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08006208 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006209
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006210 return 0;
6211}
6212
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006213static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
6214{
6215 int reg;
6216
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006217 if (CHIP_IS_E1(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006218 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006219 else
6220 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006221
6222 bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
6223}
6224
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006225static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
6226{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006227 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006228}
6229
6230static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
6231{
6232 u32 i, base = FUNC_ILT_BASE(func);
6233 for (i = base; i < base + ILT_PER_FUNC; i++)
6234 bnx2x_ilt_wr(bp, i, 0);
6235}
6236
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006237static int bnx2x_init_hw_func(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006238{
6239 int port = BP_PORT(bp);
6240 int func = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006241 int init_phase = PHASE_PF0 + func;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006242 struct bnx2x_ilt *ilt = BP_ILT(bp);
6243 u16 cdu_ilt_start;
Eilon Greenstein8badd272009-02-12 08:36:15 +00006244 u32 addr, val;
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00006245 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
6246 int i, main_mem_width;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006247
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006248 DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006249
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006250 /* FLR cleanup - hmmm */
6251 if (!CHIP_IS_E1x(bp))
6252 bnx2x_pf_flr_clnup(bp);
6253
Eilon Greenstein8badd272009-02-12 08:36:15 +00006254 /* set MSI reconfigure capability */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006255 if (bp->common.int_block == INT_BLOCK_HC) {
6256 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
6257 val = REG_RD(bp, addr);
6258 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
6259 REG_WR(bp, addr, val);
6260 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00006261
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006262 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
6263 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
6264
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006265 ilt = BP_ILT(bp);
6266 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006267
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006268 for (i = 0; i < L2_ILT_LINES(bp); i++) {
6269 ilt->lines[cdu_ilt_start + i].page =
6270 bp->context.vcxt + (ILT_PAGE_CIDS * i);
6271 ilt->lines[cdu_ilt_start + i].page_mapping =
6272 bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
6273 /* cdu ilt pages are allocated manually so there's no need to
6274 set the size */
6275 }
6276 bnx2x_ilt_init_op(bp, INITOP_SET);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006277
Michael Chan37b091b2009-10-10 13:46:55 +00006278#ifdef BCM_CNIC
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006279 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
Michael Chan37b091b2009-10-10 13:46:55 +00006280
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006281 /* T1 hash bits value determines the T1 number of entries */
6282 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
Michael Chan37b091b2009-10-10 13:46:55 +00006283#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006284
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006285#ifndef BCM_CNIC
6286 /* set NIC mode */
6287 REG_WR(bp, PRS_REG_NIC_MODE, 1);
6288#endif /* BCM_CNIC */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006289
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006290 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006291 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
6292
6293 /* Turn on a single ISR mode in IGU if driver is going to use
6294 * INT#x or MSI
6295 */
6296 if (!(bp->flags & USING_MSIX_FLAG))
6297 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
6298 /*
6299 * Timers workaround bug: function init part.
6300 * Need to wait 20msec after initializing ILT,
6301 * needed to make sure there are no requests in
6302 * one of the PXP internal queues with "old" ILT addresses
6303 */
6304 msleep(20);
6305 /*
6306 * Master enable - Due to WB DMAE writes performed before this
6307 * register is re-initialized as part of the regular function
6308 * init
6309 */
6310 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
6311 /* Enable the function in IGU */
6312 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
6313 }
6314
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006315 bp->dmae_ready = 1;
6316
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006317 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006318
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006319 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006320 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
6321
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006322 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
6323 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
6324 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
6325 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
6326 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
6327 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
6328 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
6329 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
6330 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
6331 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
6332 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
6333 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
6334 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006335
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006336 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006337 REG_WR(bp, QM_REG_PF_EN, 1);
6338
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006339 if (!CHIP_IS_E1x(bp)) {
6340 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6341 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6342 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6343 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
6344 }
6345 bnx2x_init_block(bp, BLOCK_QM, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006346
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006347 bnx2x_init_block(bp, BLOCK_TM, init_phase);
6348 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
6349 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
6350 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
6351 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
6352 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
6353 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
6354 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
6355 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
6356 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
6357 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
6358 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006359 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
6360
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006361 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006362
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006363 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006364
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006365 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006366 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
6367
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006368 if (IS_MF(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006369 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00006370 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006371 }
6372
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006373 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006374
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006375 /* HC init per function */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006376 if (bp->common.int_block == INT_BLOCK_HC) {
6377 if (CHIP_IS_E1H(bp)) {
6378 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6379
6380 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
6381 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
6382 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006383 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006384
6385 } else {
6386 int num_segs, sb_idx, prod_offset;
6387
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006388 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
6389
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006390 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006391 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
6392 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
6393 }
6394
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006395 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006396
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006397 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006398 int dsb_idx = 0;
6399 /**
6400 * Producer memory:
6401 * E2 mode: address 0-135 match to the mapping memory;
6402 * 136 - PF0 default prod; 137 - PF1 default prod;
6403 * 138 - PF2 default prod; 139 - PF3 default prod;
6404 * 140 - PF0 attn prod; 141 - PF1 attn prod;
6405 * 142 - PF2 attn prod; 143 - PF3 attn prod;
6406 * 144-147 reserved.
6407 *
6408 * E1.5 mode - In backward compatible mode;
6409 * for non default SB; each even line in the memory
6410 * holds the U producer and each odd line hold
6411 * the C producer. The first 128 producers are for
6412 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
6413 * producers are for the DSB for each PF.
6414 * Each PF has five segments: (the order inside each
6415 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
6416 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
6417 * 144-147 attn prods;
6418 */
6419 /* non-default-status-blocks */
6420 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6421 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
6422 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
6423 prod_offset = (bp->igu_base_sb + sb_idx) *
6424 num_segs;
6425
6426 for (i = 0; i < num_segs; i++) {
6427 addr = IGU_REG_PROD_CONS_MEMORY +
6428 (prod_offset + i) * 4;
6429 REG_WR(bp, addr, 0);
6430 }
6431 /* send consumer update with value 0 */
6432 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
6433 USTORM_ID, 0, IGU_INT_NOP, 1);
6434 bnx2x_igu_clear_sb(bp,
6435 bp->igu_base_sb + sb_idx);
6436 }
6437
6438 /* default-status-blocks */
6439 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
6440 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
6441
6442 if (CHIP_MODE_IS_4_PORT(bp))
6443 dsb_idx = BP_FUNC(bp);
6444 else
6445 dsb_idx = BP_E1HVN(bp);
6446
6447 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
6448 IGU_BC_BASE_DSB_PROD + dsb_idx :
6449 IGU_NORM_BASE_DSB_PROD + dsb_idx);
6450
6451 for (i = 0; i < (num_segs * E1HVN_MAX);
6452 i += E1HVN_MAX) {
6453 addr = IGU_REG_PROD_CONS_MEMORY +
6454 (prod_offset + i)*4;
6455 REG_WR(bp, addr, 0);
6456 }
6457 /* send consumer update with 0 */
6458 if (CHIP_INT_MODE_IS_BC(bp)) {
6459 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6460 USTORM_ID, 0, IGU_INT_NOP, 1);
6461 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6462 CSTORM_ID, 0, IGU_INT_NOP, 1);
6463 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6464 XSTORM_ID, 0, IGU_INT_NOP, 1);
6465 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6466 TSTORM_ID, 0, IGU_INT_NOP, 1);
6467 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6468 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6469 } else {
6470 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6471 USTORM_ID, 0, IGU_INT_NOP, 1);
6472 bnx2x_ack_sb(bp, bp->igu_dsb_id,
6473 ATTENTION_ID, 0, IGU_INT_NOP, 1);
6474 }
6475 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
6476
6477 /* !!! these should become driver const once
6478 rf-tool supports split-68 const */
6479 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
6480 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
6481 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
6482 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
6483 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
6484 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
6485 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006486 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006487
Eliezer Tamirc14423f2008-02-28 11:49:42 -08006488 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006489 REG_WR(bp, 0x2114, 0xffffffff);
6490 REG_WR(bp, 0x2120, 0xffffffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006491
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00006492 if (CHIP_IS_E1x(bp)) {
6493 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
6494 main_mem_base = HC_REG_MAIN_MEMORY +
6495 BP_PORT(bp) * (main_mem_size * 4);
6496 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
6497 main_mem_width = 8;
6498
6499 val = REG_RD(bp, main_mem_prty_clr);
6500 if (val)
6501 DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
6502 "block during "
6503 "function init (0x%x)!\n", val);
6504
6505 /* Clear "false" parity errors in MSI-X table */
6506 for (i = main_mem_base;
6507 i < main_mem_base + main_mem_size * 4;
6508 i += main_mem_width) {
6509 bnx2x_read_dmae(bp, i, main_mem_width / 4);
6510 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
6511 i, main_mem_width / 4);
6512 }
6513 /* Clear HC parity attention */
6514 REG_RD(bp, main_mem_prty_clr);
6515 }
6516
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006517#ifdef BNX2X_STOP_ON_ERROR
6518 /* Enable STORMs SP logging */
6519 REG_WR8(bp, BAR_USTRORM_INTMEM +
6520 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6521 REG_WR8(bp, BAR_TSTRORM_INTMEM +
6522 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6523 REG_WR8(bp, BAR_CSTRORM_INTMEM +
6524 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6525 REG_WR8(bp, BAR_XSTRORM_INTMEM +
6526 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
6527#endif
6528
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006529 bnx2x_phy_probe(&bp->link_params);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006530
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006531 return 0;
6532}
6533
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006534
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006535void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006536{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006537 /* fastpath */
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006538 bnx2x_free_fp_mem(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006539 /* end of fastpath */
6540
6541 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006542 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006543
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006544 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6545 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6546
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006547 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006548 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006549
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006550 BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
6551 bp->context.size);
6552
6553 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
6554
6555 BNX2X_FREE(bp->ilt->lines);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006556
Michael Chan37b091b2009-10-10 13:46:55 +00006557#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006558 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006559 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
6560 sizeof(struct host_hc_status_block_e2));
6561 else
6562 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
6563 sizeof(struct host_hc_status_block_e1x));
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006564
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006565 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006566#endif
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006567
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07006568 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006569
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006570 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
6571 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006572}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006573
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006574static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
6575{
6576 int num_groups;
6577
6578 /* number of eth_queues */
6579 u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
6580
6581 /* Total number of FW statistics requests =
6582 * 1 for port stats + 1 for PF stats + num_eth_queues */
6583 bp->fw_stats_num = 2 + num_queue_stats;
6584
6585
6586 /* Request is built from stats_query_header and an array of
6587 * stats_query_cmd_group each of which contains
6588 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
6589 * configured in the stats_query_header.
6590 */
6591 num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
6592 (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
6593
6594 bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
6595 num_groups * sizeof(struct stats_query_cmd_group);
6596
6597 /* Data for statistics requests + stats_conter
6598 *
6599 * stats_counter holds per-STORM counters that are incremented
6600 * when STORM has finished with the current request.
6601 */
6602 bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
6603 sizeof(struct per_pf_stats) +
6604 sizeof(struct per_queue_stats) * num_queue_stats +
6605 sizeof(struct stats_counter);
6606
6607 BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
6608 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6609
6610 /* Set shortcuts */
6611 bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
6612 bp->fw_stats_req_mapping = bp->fw_stats_mapping;
6613
6614 bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
6615 ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
6616
6617 bp->fw_stats_data_mapping = bp->fw_stats_mapping +
6618 bp->fw_stats_req_sz;
6619 return 0;
6620
6621alloc_mem_err:
6622 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
6623 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
6624 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006625}
6626
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006627
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00006628int bnx2x_alloc_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006629{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006630#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006631 if (!CHIP_IS_E1x(bp))
6632 /* size = the status block + ramrod buffers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006633 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
6634 sizeof(struct host_hc_status_block_e2));
6635 else
6636 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
6637 sizeof(struct host_hc_status_block_e1x));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006638
6639 /* allocate searcher T2 table */
6640 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
6641#endif
6642
6643
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006644 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006645 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006646
6647 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
6648 sizeof(struct bnx2x_slowpath));
6649
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006650 /* Allocated memory for FW statistics */
6651 if (bnx2x_alloc_fw_stats_mem(bp))
6652 goto alloc_mem_err;
6653
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006654 bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006655
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006656 BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
6657 bp->context.size);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006658
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006659 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006660
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006661 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
6662 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006663
6664 /* Slow path ring */
6665 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
6666
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006667 /* EQ */
6668 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
6669 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Tom Herbertab532cf2011-02-16 10:27:02 +00006670
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006671
6672 /* fastpath */
6673 /* need to be done at the end, since it's self adjusting to amount
6674 * of memory available for RSS queues
6675 */
6676 if (bnx2x_alloc_fp_mem(bp))
6677 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006678 return 0;
6679
6680alloc_mem_err:
6681 bnx2x_free_mem(bp);
6682 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006683}
6684
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006685/*
6686 * Init service functions
6687 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006688
6689int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
6690 struct bnx2x_vlan_mac_obj *obj, bool set,
6691 int mac_type, unsigned long *ramrod_flags)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006692{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006693 int rc;
6694 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006695
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006696 memset(&ramrod_param, 0, sizeof(ramrod_param));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006697
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006698 /* Fill general parameters */
6699 ramrod_param.vlan_mac_obj = obj;
6700 ramrod_param.ramrod_flags = *ramrod_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006701
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006702 /* Fill a user request section if needed */
6703 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
6704 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006705
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006706 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006707
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006708 /* Set the command: ADD or DEL */
6709 if (set)
6710 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
6711 else
6712 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006713 }
6714
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006715 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
6716 if (rc < 0)
6717 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
6718 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006719}
6720
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006721int bnx2x_del_all_macs(struct bnx2x *bp,
6722 struct bnx2x_vlan_mac_obj *mac_obj,
6723 int mac_type, bool wait_for_comp)
Michael Chane665bfd2009-10-10 13:46:54 +00006724{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006725 int rc;
6726 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
6727
6728 /* Wait for completion of requested */
6729 if (wait_for_comp)
6730 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6731
6732 /* Set the mac type of addresses we want to clear */
6733 __set_bit(mac_type, &vlan_mac_flags);
6734
6735 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
6736 if (rc < 0)
6737 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
6738
6739 return rc;
Michael Chane665bfd2009-10-10 13:46:54 +00006740}
6741
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006742int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006743{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006744 unsigned long ramrod_flags = 0;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006745
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006746 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006747
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006748 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
6749 /* Eth MAC is set on RSS leading client (fp[0]) */
6750 return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
6751 BNX2X_ETH_MAC, &ramrod_flags);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08006752}
6753
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006754int bnx2x_setup_leading(struct bnx2x *bp)
Michael Chane665bfd2009-10-10 13:46:54 +00006755{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006756 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006757}
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08006758
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006759/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00006760 * bnx2x_set_int_mode - configure interrupt mode
6761 *
6762 * @bp: driver handle
6763 *
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006764 * In case of MSI-X it will also try to enable MSI-X.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006765 */
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006766static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006767{
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006768 switch (int_mode) {
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006769 case INT_MODE_MSI:
6770 bnx2x_enable_msi(bp);
6771 /* falling through... */
6772 case INT_MODE_INTx:
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006773 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006774 DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
Eilon Greensteinca003922009-08-12 22:53:28 -07006775 break;
Eilon Greensteinca003922009-08-12 22:53:28 -07006776 default:
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006777 /* Set number of queues according to bp->multi_mode value */
6778 bnx2x_set_num_queues(bp);
6779
6780 DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
6781 bp->num_queues);
6782
6783 /* if we can't use MSI-X we only need one fp,
6784 * so try to enable MSI-X with the requested number of fp's
6785 * and fallback to MSI or legacy INTx with one fp
6786 */
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006787 if (bnx2x_enable_msix(bp)) {
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006788 /* failed to enable MSI-X */
6789 if (bp->multi_mode)
6790 DP(NETIF_MSG_IFUP,
6791 "Multi requested but failed to "
6792 "enable MSI-X (%d), "
6793 "set number of queues to %d\n",
6794 bp->num_queues,
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006795 1 + NONE_ETH_CONTEXT_USE);
6796 bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006797
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00006798 /* Try to enable MSI */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00006799 if (!(bp->flags & DISABLE_MSI_FLAG))
6800 bnx2x_enable_msi(bp);
6801 }
Eilon Greensteinca003922009-08-12 22:53:28 -07006802 break;
6803 }
Eilon Greensteinca003922009-08-12 22:53:28 -07006804}
6805
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00006806/* must be called prioir to any HW initializations */
6807static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
6808{
6809 return L2_ILT_LINES(bp);
6810}
6811
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006812void bnx2x_ilt_set_info(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006813{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006814 struct ilt_client_info *ilt_client;
6815 struct bnx2x_ilt *ilt = BP_ILT(bp);
6816 u16 line = 0;
6817
6818 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
6819 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
6820
6821 /* CDU */
6822 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
6823 ilt_client->client_num = ILT_CLIENT_CDU;
6824 ilt_client->page_size = CDU_ILT_PAGE_SZ;
6825 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
6826 ilt_client->start = line;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006827 line += bnx2x_cid_ilt_lines(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006828#ifdef BCM_CNIC
6829 line += CNIC_ILT_LINES;
6830#endif
6831 ilt_client->end = line - 1;
6832
6833 DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
6834 "flags 0x%x, hw psz %d\n",
6835 ilt_client->start,
6836 ilt_client->end,
6837 ilt_client->page_size,
6838 ilt_client->flags,
6839 ilog2(ilt_client->page_size >> 12));
6840
6841 /* QM */
6842 if (QM_INIT(bp->qm_cid_count)) {
6843 ilt_client = &ilt->clients[ILT_CLIENT_QM];
6844 ilt_client->client_num = ILT_CLIENT_QM;
6845 ilt_client->page_size = QM_ILT_PAGE_SZ;
6846 ilt_client->flags = 0;
6847 ilt_client->start = line;
6848
6849 /* 4 bytes for each cid */
6850 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
6851 QM_ILT_PAGE_SZ);
6852
6853 ilt_client->end = line - 1;
6854
6855 DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
6856 "flags 0x%x, hw psz %d\n",
6857 ilt_client->start,
6858 ilt_client->end,
6859 ilt_client->page_size,
6860 ilt_client->flags,
6861 ilog2(ilt_client->page_size >> 12));
6862
6863 }
6864 /* SRC */
6865 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
6866#ifdef BCM_CNIC
6867 ilt_client->client_num = ILT_CLIENT_SRC;
6868 ilt_client->page_size = SRC_ILT_PAGE_SZ;
6869 ilt_client->flags = 0;
6870 ilt_client->start = line;
6871 line += SRC_ILT_LINES;
6872 ilt_client->end = line - 1;
6873
6874 DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
6875 "flags 0x%x, hw psz %d\n",
6876 ilt_client->start,
6877 ilt_client->end,
6878 ilt_client->page_size,
6879 ilt_client->flags,
6880 ilog2(ilt_client->page_size >> 12));
6881
6882#else
6883 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6884#endif
6885
6886 /* TM */
6887 ilt_client = &ilt->clients[ILT_CLIENT_TM];
6888#ifdef BCM_CNIC
6889 ilt_client->client_num = ILT_CLIENT_TM;
6890 ilt_client->page_size = TM_ILT_PAGE_SZ;
6891 ilt_client->flags = 0;
6892 ilt_client->start = line;
6893 line += TM_ILT_LINES;
6894 ilt_client->end = line - 1;
6895
6896 DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
6897 "flags 0x%x, hw psz %d\n",
6898 ilt_client->start,
6899 ilt_client->end,
6900 ilt_client->page_size,
6901 ilt_client->flags,
6902 ilog2(ilt_client->page_size >> 12));
6903
6904#else
6905 ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
6906#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006907 BUG_ON(line > ILT_MAX_LINES);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006908}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006909
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006910/**
6911 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
6912 *
6913 * @bp: driver handle
6914 * @fp: pointer to fastpath
6915 * @init_params: pointer to parameters structure
6916 *
6917 * parameters configured:
6918 * - HC configuration
6919 * - Queue's CDU context
6920 */
6921static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
6922 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006923{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006924 /* FCoE Queue uses Default SB, thus has no HC capabilities */
6925 if (!IS_FCOE_FP(fp)) {
6926 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
6927 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
6928
6929 /* If HC is supporterd, enable host coalescing in the transition
6930 * to INIT state.
6931 */
6932 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
6933 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
6934
6935 /* HC rate */
6936 init_params->rx.hc_rate = bp->rx_ticks ?
6937 (1000000 / bp->rx_ticks) : 0;
6938 init_params->tx.hc_rate = bp->tx_ticks ?
6939 (1000000 / bp->tx_ticks) : 0;
6940
6941 /* FW SB ID */
6942 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
6943 fp->fw_sb_id;
6944
6945 /*
6946 * CQ index among the SB indices: FCoE clients uses the default
6947 * SB, therefore it's different.
6948 */
6949 init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
6950 init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
6951 }
6952
6953 init_params->cxt = &bp->context.vcxt[fp->cid].eth;
6954}
6955
6956/**
6957 * bnx2x_setup_queue - setup queue
6958 *
6959 * @bp: driver handle
6960 * @fp: pointer to fastpath
6961 * @leading: is leading
6962 *
6963 * This function performs 2 steps in a Queue state machine
6964 * actually: 1) RESET->INIT 2) INIT->SETUP
6965 */
6966
6967int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6968 bool leading)
6969{
6970 struct bnx2x_queue_state_params q_params = {0};
6971 struct bnx2x_queue_setup_params *setup_params =
6972 &q_params.params.setup;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006973 int rc;
6974
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006975 /* reset IGU state skip FCoE L2 queue */
6976 if (!IS_FCOE_FP(fp))
6977 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006978 IGU_INT_ENABLE, 0);
6979
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006980 q_params.q_obj = &fp->q_obj;
6981 /* We want to wait for completion in this context */
6982 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006983
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006984 /* Prepare the INIT parameters */
6985 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006986
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006987 /* Set the command */
6988 q_params.cmd = BNX2X_Q_CMD_INIT;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006989
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006990 /* Change the state to INIT */
6991 rc = bnx2x_queue_state_change(bp, &q_params);
6992 if (rc) {
6993 BNX2X_ERR("Queue INIT failed\n");
6994 return rc;
6995 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006996
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006997 /* Now move the Queue to the SETUP state... */
6998 memset(setup_params, 0, sizeof(*setup_params));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006999
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007000 /* Set QUEUE flags */
7001 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007002
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007003 /* Set general SETUP parameters */
7004 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params);
7005
7006 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause,
7007 &setup_params->rxq_params);
7008
7009 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params);
7010
7011 /* Set the command */
7012 q_params.cmd = BNX2X_Q_CMD_SETUP;
7013
7014 /* Change the state to SETUP */
7015 rc = bnx2x_queue_state_change(bp, &q_params);
7016 if (rc)
7017 BNX2X_ERR("Queue SETUP failed\n");
7018
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007019 return rc;
7020}
7021
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007022static int bnx2x_stop_queue(struct bnx2x *bp, int index)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007023{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007024 struct bnx2x_fastpath *fp = &bp->fp[index];
7025 struct bnx2x_queue_state_params q_params = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007026 int rc;
7027
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007028 q_params.q_obj = &fp->q_obj;
7029 /* We want to wait for completion in this context */
7030 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007031
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007032 /* halt the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007033 q_params.cmd = BNX2X_Q_CMD_HALT;
7034 rc = bnx2x_queue_state_change(bp, &q_params);
7035 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007036 return rc;
7037
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007038 /* terminate the connection */
7039 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
7040 rc = bnx2x_queue_state_change(bp, &q_params);
7041 if (rc)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007042 return rc;
7043
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007044 /* delete cfc entry */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007045 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
7046 return bnx2x_queue_state_change(bp, &q_params);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007047}
7048
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007049
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007050static void bnx2x_reset_func(struct bnx2x *bp)
7051{
7052 int port = BP_PORT(bp);
7053 int func = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007054 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007055
7056 /* Disable the function in the FW */
7057 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
7058 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
7059 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
7060 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
7061
7062 /* FP SBs */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007063 for_each_eth_queue(bp, i) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007064 struct bnx2x_fastpath *fp = &bp->fp[i];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007065 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7066 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
7067 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007068 }
7069
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007070#ifdef BCM_CNIC
7071 /* CNIC SB */
7072 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7073 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
7074 SB_DISABLED);
7075#endif
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007076 /* SP SB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007077 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7078 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
7079 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007080
7081 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
7082 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
7083 0);
Eliezer Tamir49d66772008-02-28 11:53:13 -08007084
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007085 /* Configure IGU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007086 if (bp->common.int_block == INT_BLOCK_HC) {
7087 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7088 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7089 } else {
7090 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7091 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7092 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007093
Michael Chan37b091b2009-10-10 13:46:55 +00007094#ifdef BCM_CNIC
7095 /* Disable Timer scan */
7096 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
7097 /*
7098 * Wait for at least 10ms and up to 2 second for the timers scan to
7099 * complete
7100 */
7101 for (i = 0; i < 200; i++) {
7102 msleep(10);
7103 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
7104 break;
7105 }
7106#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007107 /* Clear ILT */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007108 bnx2x_clear_func_ilt(bp, func);
7109
7110 /* Timers workaround bug for E2: if this is vnic-3,
7111 * we need to set the entire ilt range for this timers.
7112 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007113 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007114 struct ilt_client_info ilt_cli;
7115 /* use dummy TM client */
7116 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7117 ilt_cli.start = 0;
7118 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7119 ilt_cli.client_num = ILT_CLIENT_TM;
7120
7121 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
7122 }
7123
7124 /* this assumes that reset_port() called before reset_func()*/
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007125 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007126 bnx2x_pf_disable(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007127
7128 bp->dmae_ready = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007129}
7130
7131static void bnx2x_reset_port(struct bnx2x *bp)
7132{
7133 int port = BP_PORT(bp);
7134 u32 val;
7135
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007136 /* Reset physical Link */
7137 bnx2x__link_reset(bp);
7138
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007139 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
7140
7141 /* Do not rcv packets to BRB */
7142 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
7143 /* Do not direct rcv packets that are not for MCP to the BRB */
7144 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
7145 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
7146
7147 /* Configure AEU */
7148 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
7149
7150 msleep(100);
7151 /* Check for BRB port occupancy */
7152 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
7153 if (val)
7154 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07007155 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007156
7157 /* TODO: Close Doorbell port? */
7158}
7159
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007160static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007161{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007162 struct bnx2x_func_state_params func_params = {0};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007163
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007164 /* Prepare parameters for function state transitions */
7165 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007166
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007167 func_params.f_obj = &bp->func_obj;
7168 func_params.cmd = BNX2X_F_CMD_HW_RESET;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007169
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007170 func_params.params.hw_init.load_phase = load_code;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007171
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007172 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007173}
7174
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007175static inline int bnx2x_func_stop(struct bnx2x *bp)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007176{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007177 struct bnx2x_func_state_params func_params = {0};
7178 int rc;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007179
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007180 /* Prepare parameters for function state transitions */
7181 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7182 func_params.f_obj = &bp->func_obj;
7183 func_params.cmd = BNX2X_F_CMD_STOP;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00007184
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007185 /*
7186 * Try to stop the function the 'good way'. If fails (in case
7187 * of a parity error during bnx2x_chip_cleanup()) and we are
7188 * not in a debug mode, perform a state transaction in order to
7189 * enable further HW_RESET transaction.
7190 */
7191 rc = bnx2x_func_state_change(bp, &func_params);
7192 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007193#ifdef BNX2X_STOP_ON_ERROR
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007194 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007195#else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007196 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
7197 "transaction\n");
7198 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
7199 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007200#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07007201 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007202
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007203 return 0;
7204}
Yitchak Gertner65abd742008-08-25 15:26:24 -07007205
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007206/**
7207 * bnx2x_send_unload_req - request unload mode from the MCP.
7208 *
7209 * @bp: driver handle
7210 * @unload_mode: requested function's unload mode
7211 *
7212 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
7213 */
7214u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
7215{
7216 u32 reset_code = 0;
7217 int port = BP_PORT(bp);
7218
7219 /* Select the UNLOAD request mode */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007220 if (unload_mode == UNLOAD_NORMAL)
7221 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007222
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00007223 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007224 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007225
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00007226 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007227 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007228 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007229 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007230 /* The mac address is written to entries 1-4 to
7231 preserve entry 0 which is used by the PMF */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07007232 u8 entry = (BP_E1HVN(bp) + 1)*8;
7233
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007234 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007235 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007236
7237 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
7238 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07007239 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007240
7241 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08007242
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007243 } else
7244 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
7245
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007246 /* Send the request to the MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007247 if (!BP_NOMCP(bp))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007248 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007249 else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007250 int path = BP_PATH(bp);
7251
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007252 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007253 "%d, %d, %d\n",
7254 path, load_count[path][0], load_count[path][1],
7255 load_count[path][2]);
7256 load_count[path][0]--;
7257 load_count[path][1 + port]--;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007258 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007259 "%d, %d, %d\n",
7260 path, load_count[path][0], load_count[path][1],
7261 load_count[path][2]);
7262 if (load_count[path][0] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007263 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007264 else if (load_count[path][1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007265 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
7266 else
7267 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
7268 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007269
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007270 return reset_code;
7271}
7272
7273/**
7274 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
7275 *
7276 * @bp: driver handle
7277 */
7278void bnx2x_send_unload_done(struct bnx2x *bp)
7279{
7280 /* Report UNLOAD_DONE to MCP */
7281 if (!BP_NOMCP(bp))
7282 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
7283}
7284
7285void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
7286{
7287 int port = BP_PORT(bp);
7288 int i, rc;
7289 struct bnx2x_mcast_ramrod_params rparam = {0};
7290 u32 reset_code;
7291
7292 /* Wait until tx fastpath tasks complete */
7293 for_each_tx_queue(bp, i) {
7294 struct bnx2x_fastpath *fp = &bp->fp[i];
7295
7296 rc = bnx2x_clean_tx_queue(bp, fp);
7297#ifdef BNX2X_STOP_ON_ERROR
7298 if (rc)
7299 return;
7300#endif
7301 }
7302
7303 /* Give HW time to discard old tx messages */
7304 usleep_range(1000, 1000);
7305
7306 /* Clean all ETH MACs */
7307 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
7308 if (rc < 0)
7309 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
7310
7311 /* Clean up UC list */
7312 rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
7313 true);
7314 if (rc < 0)
7315 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
7316 "%d\n", rc);
7317
7318 /* Disable LLH */
7319 if (!CHIP_IS_E1(bp))
7320 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
7321
7322 /* Set "drop all" (stop Rx).
7323 * We need to take a netif_addr_lock() here in order to prevent
7324 * a race between the completion code and this code.
7325 */
7326 netif_addr_lock_bh(bp->dev);
7327 /* Schedule the rx_mode command */
7328 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
7329 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
7330 else
7331 bnx2x_set_storm_rx_mode(bp);
7332
7333 /* Cleanup multicast configuration */
7334 rparam.mcast_obj = &bp->mcast_obj;
7335 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
7336 if (rc < 0)
7337 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
7338
7339 netif_addr_unlock_bh(bp->dev);
7340
7341
7342 /* Close multi and leading connections
7343 * Completions for ramrods are collected in a synchronous way
7344 */
7345 for_each_queue(bp, i)
7346 if (bnx2x_stop_queue(bp, i))
7347#ifdef BNX2X_STOP_ON_ERROR
7348 return;
7349#else
7350 goto unload_error;
7351#endif
7352 /* If SP settings didn't get completed so far - something
7353 * very wrong has happen.
7354 */
7355 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
7356 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
7357
7358#ifndef BNX2X_STOP_ON_ERROR
7359unload_error:
7360#endif
7361 rc = bnx2x_func_stop(bp);
7362 if (rc) {
7363 BNX2X_ERR("Function stop failed!\n");
7364#ifdef BNX2X_STOP_ON_ERROR
7365 return;
7366#endif
7367 }
7368
7369 /*
7370 * Send the UNLOAD_REQUEST to the MCP. This will return if
7371 * this function should perform FUNC, PORT or COMMON HW
7372 * reset.
7373 */
7374 reset_code = bnx2x_send_unload_req(bp, unload_mode);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007375
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007376 /* Disable HW interrupts, NAPI */
7377 bnx2x_netif_stop(bp, 1);
7378
7379 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00007380 bnx2x_free_irq(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007381
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007382 /* Reset the chip */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007383 rc = bnx2x_reset_hw(bp, reset_code);
7384 if (rc)
7385 BNX2X_ERR("HW_RESET failed\n");
7386
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007387
7388 /* Report UNLOAD_DONE to MCP */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007389 bnx2x_send_unload_done(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007390}
7391
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00007392void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007393{
7394 u32 val;
7395
7396 DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
7397
7398 if (CHIP_IS_E1(bp)) {
7399 int port = BP_PORT(bp);
7400 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
7401 MISC_REG_AEU_MASK_ATTN_FUNC_0;
7402
7403 val = REG_RD(bp, addr);
7404 val &= ~(0x300);
7405 REG_WR(bp, addr, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007406 } else {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007407 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
7408 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
7409 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
7410 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
7411 }
7412}
7413
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007414/* Close gates #2, #3 and #4: */
7415static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
7416{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007417 u32 val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007418
7419 /* Gates #2 and #4a are closed/opened for "not E1" only */
7420 if (!CHIP_IS_E1(bp)) {
7421 /* #4 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007422 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007423 /* #2 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007424 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007425 }
7426
7427 /* #3 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007428 if (CHIP_IS_E1x(bp)) {
7429 /* Prevent interrupts from HC on both ports */
7430 val = REG_RD(bp, HC_REG_CONFIG_1);
7431 REG_WR(bp, HC_REG_CONFIG_1,
7432 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
7433 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
7434
7435 val = REG_RD(bp, HC_REG_CONFIG_0);
7436 REG_WR(bp, HC_REG_CONFIG_0,
7437 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
7438 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
7439 } else {
7440 /* Prevent incomming interrupts in IGU */
7441 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
7442
7443 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
7444 (!close) ?
7445 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
7446 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
7447 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007448
7449 DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
7450 close ? "closing" : "opening");
7451 mmiowb();
7452}
7453
7454#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
7455
7456static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
7457{
7458 /* Do some magic... */
7459 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7460 *magic_val = val & SHARED_MF_CLP_MAGIC;
7461 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
7462}
7463
Dmitry Kravkove8920672011-05-04 23:52:40 +00007464/**
7465 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007466 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007467 * @bp: driver handle
7468 * @magic_val: old value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007469 */
7470static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
7471{
7472 /* Restore the `magic' bit value... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007473 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
7474 MF_CFG_WR(bp, shared_mf_config.clp_mb,
7475 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
7476}
7477
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007478/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00007479 * bnx2x_reset_mcp_prep - prepare for MCP reset.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007480 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007481 * @bp: driver handle
7482 * @magic_val: old value of 'magic' bit.
7483 *
7484 * Takes care of CLP configurations.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007485 */
7486static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
7487{
7488 u32 shmem;
7489 u32 validity_offset;
7490
7491 DP(NETIF_MSG_HW, "Starting\n");
7492
7493 /* Set `magic' bit in order to save MF config */
7494 if (!CHIP_IS_E1(bp))
7495 bnx2x_clp_reset_prep(bp, magic_val);
7496
7497 /* Get shmem offset */
7498 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7499 validity_offset = offsetof(struct shmem_region, validity_map[0]);
7500
7501 /* Clear validity map flags */
7502 if (shmem > 0)
7503 REG_WR(bp, shmem + validity_offset, 0);
7504}
7505
7506#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
7507#define MCP_ONE_TIMEOUT 100 /* 100 ms */
7508
Dmitry Kravkove8920672011-05-04 23:52:40 +00007509/**
7510 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007511 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00007512 * @bp: driver handle
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007513 */
7514static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
7515{
7516 /* special handling for emulation and FPGA,
7517 wait 10 times longer */
7518 if (CHIP_REV_IS_SLOW(bp))
7519 msleep(MCP_ONE_TIMEOUT*10);
7520 else
7521 msleep(MCP_ONE_TIMEOUT);
7522}
7523
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007524/*
7525 * initializes bp->common.shmem_base and waits for validity signature to appear
7526 */
7527static int bnx2x_init_shmem(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007528{
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007529 int cnt = 0;
7530 u32 val = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007531
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007532 do {
7533 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
7534 if (bp->common.shmem_base) {
7535 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
7536 if (val & SHR_MEM_VALIDITY_MB)
7537 return 0;
7538 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007539
7540 bnx2x_mcp_wait_one(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007541
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007542 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007543
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007544 BNX2X_ERR("BAD MCP validity signature\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007545
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00007546 return -ENODEV;
7547}
7548
7549static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
7550{
7551 int rc = bnx2x_init_shmem(bp);
7552
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007553 /* Restore the `magic' bit value */
7554 if (!CHIP_IS_E1(bp))
7555 bnx2x_clp_reset_done(bp, magic_val);
7556
7557 return rc;
7558}
7559
7560static void bnx2x_pxp_prep(struct bnx2x *bp)
7561{
7562 if (!CHIP_IS_E1(bp)) {
7563 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
7564 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007565 mmiowb();
7566 }
7567}
7568
7569/*
7570 * Reset the whole chip except for:
7571 * - PCIE core
7572 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
7573 * one reset bit)
7574 * - IGU
7575 * - MISC (including AEU)
7576 * - GRC
7577 * - RBCN, RBCP
7578 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007579static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007580{
7581 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007582 u32 global_bits2;
7583
7584 /*
7585 * Bits that have to be set in reset_mask2 if we want to reset 'global'
7586 * (per chip) blocks.
7587 */
7588 global_bits2 =
7589 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
7590 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007591
7592 not_reset_mask1 =
7593 MISC_REGISTERS_RESET_REG_1_RST_HC |
7594 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
7595 MISC_REGISTERS_RESET_REG_1_RST_PXP;
7596
7597 not_reset_mask2 =
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007598 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007599 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
7600 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
7601 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
7602 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
7603 MISC_REGISTERS_RESET_REG_2_RST_GRC |
7604 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
7605 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
7606
7607 reset_mask1 = 0xffffffff;
7608
7609 if (CHIP_IS_E1(bp))
7610 reset_mask2 = 0xffff;
7611 else
7612 reset_mask2 = 0x1ffff;
7613
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007614 if (CHIP_IS_E3(bp)) {
7615 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
7616 reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
7617 }
7618
7619 /* Don't reset global blocks unless we need to */
7620 if (!global)
7621 reset_mask2 &= ~global_bits2;
7622
7623 /*
7624 * In case of attention in the QM, we need to reset PXP
7625 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
7626 * because otherwise QM reset would release 'close the gates' shortly
7627 * before resetting the PXP, then the PSWRQ would send a write
7628 * request to PGLUE. Then when PXP is reset, PGLUE would try to
7629 * read the payload data from PSWWR, but PSWWR would not
7630 * respond. The write queue in PGLUE would stuck, dmae commands
7631 * would not return. Therefore it's important to reset the second
7632 * reset register (containing the
7633 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
7634 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
7635 * bit).
7636 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007637 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7638 reset_mask2 & (~not_reset_mask2));
7639
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007640 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7641 reset_mask1 & (~not_reset_mask1));
7642
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007643 barrier();
7644 mmiowb();
7645
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007646 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007647 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007648 mmiowb();
7649}
7650
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007651/**
7652 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
7653 * It should get cleared in no more than 1s.
7654 *
7655 * @bp: driver handle
7656 *
7657 * It should get cleared in no more than 1s. Returns 0 if
7658 * pending writes bit gets cleared.
7659 */
7660static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
7661{
7662 u32 cnt = 1000;
7663 u32 pend_bits = 0;
7664
7665 do {
7666 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
7667
7668 if (pend_bits == 0)
7669 break;
7670
7671 usleep_range(1000, 1000);
7672 } while (cnt-- > 0);
7673
7674 if (cnt <= 0) {
7675 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
7676 pend_bits);
7677 return -EBUSY;
7678 }
7679
7680 return 0;
7681}
7682
7683static int bnx2x_process_kill(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007684{
7685 int cnt = 1000;
7686 u32 val = 0;
7687 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
7688
7689
7690 /* Empty the Tetris buffer, wait for 1s */
7691 do {
7692 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
7693 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
7694 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
7695 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
7696 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
7697 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
7698 ((port_is_idle_0 & 0x1) == 0x1) &&
7699 ((port_is_idle_1 & 0x1) == 0x1) &&
7700 (pgl_exp_rom2 == 0xffffffff))
7701 break;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007702 usleep_range(1000, 1000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007703 } while (cnt-- > 0);
7704
7705 if (cnt <= 0) {
7706 DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
7707 " are still"
7708 " outstanding read requests after 1s!\n");
7709 DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
7710 " port_is_idle_0=0x%08x,"
7711 " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
7712 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
7713 pgl_exp_rom2);
7714 return -EAGAIN;
7715 }
7716
7717 barrier();
7718
7719 /* Close gates #2, #3 and #4 */
7720 bnx2x_set_234_gates(bp, true);
7721
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007722 /* Poll for IGU VQs for 57712 and newer chips */
7723 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
7724 return -EAGAIN;
7725
7726
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007727 /* TBD: Indicate that "process kill" is in progress to MCP */
7728
7729 /* Clear "unprepared" bit */
7730 REG_WR(bp, MISC_REG_UNPREPARED, 0);
7731 barrier();
7732
7733 /* Make sure all is written to the chip before the reset */
7734 mmiowb();
7735
7736 /* Wait for 1ms to empty GLUE and PCI-E core queues,
7737 * PSWHST, GRC and PSWRD Tetris buffer.
7738 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007739 usleep_range(1000, 1000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007740
7741 /* Prepare to chip reset: */
7742 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007743 if (global)
7744 bnx2x_reset_mcp_prep(bp, &val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007745
7746 /* PXP */
7747 bnx2x_pxp_prep(bp);
7748 barrier();
7749
7750 /* reset the chip */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007751 bnx2x_process_kill_chip_reset(bp, global);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007752 barrier();
7753
7754 /* Recover after reset: */
7755 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007756 if (global && bnx2x_reset_mcp_comp(bp, val))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007757 return -EAGAIN;
7758
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007759 /* TBD: Add resetting the NO_MCP mode DB here */
7760
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007761 /* PXP */
7762 bnx2x_pxp_prep(bp);
7763
7764 /* Open the gates #2, #3 and #4 */
7765 bnx2x_set_234_gates(bp, false);
7766
7767 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
7768 * reset state, re-enable attentions. */
7769
7770 return 0;
7771}
7772
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007773int bnx2x_leader_reset(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007774{
7775 int rc = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007776 bool global = bnx2x_reset_is_global(bp);
7777
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007778 /* Try to recover after the failure */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007779 if (bnx2x_process_kill(bp, global)) {
7780 netdev_err(bp->dev, "Something bad had happen on engine %d! "
7781 "Aii!\n", BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007782 rc = -EAGAIN;
7783 goto exit_leader_reset;
7784 }
7785
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007786 /*
7787 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
7788 * state.
7789 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007790 bnx2x_set_reset_done(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007791 if (global)
7792 bnx2x_clear_reset_global(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007793
7794exit_leader_reset:
7795 bp->is_leader = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007796 bnx2x_release_leader_lock(bp);
7797 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007798 return rc;
7799}
7800
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007801static inline void bnx2x_recovery_failed(struct bnx2x *bp)
7802{
7803 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
7804
7805 /* Disconnect this device */
7806 netif_device_detach(bp->dev);
7807
7808 /*
7809 * Block ifup for all function on this engine until "process kill"
7810 * or power cycle.
7811 */
7812 bnx2x_set_reset_in_progress(bp);
7813
7814 /* Shut down the power */
7815 bnx2x_set_power_state(bp, PCI_D3hot);
7816
7817 bp->recovery_state = BNX2X_RECOVERY_FAILED;
7818
7819 smp_mb();
7820}
7821
7822/*
7823 * Assumption: runs under rtnl lock. This together with the fact
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007824 * that it's called only from bnx2x_reset_task() ensure that it
7825 * will never be called when netif_running(bp->dev) is false.
7826 */
7827static void bnx2x_parity_recover(struct bnx2x *bp)
7828{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007829 bool global = false;
7830
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007831 DP(NETIF_MSG_HW, "Handling parity\n");
7832 while (1) {
7833 switch (bp->recovery_state) {
7834 case BNX2X_RECOVERY_INIT:
7835 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007836 bnx2x_chk_parity_attn(bp, &global, false);
7837
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007838 /* Try to get a LEADER_LOCK HW lock */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007839 if (bnx2x_trylock_leader_lock(bp)) {
7840 bnx2x_set_reset_in_progress(bp);
7841 /*
7842 * Check if there is a global attention and if
7843 * there was a global attention, set the global
7844 * reset bit.
7845 */
7846
7847 if (global)
7848 bnx2x_set_reset_global(bp);
7849
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007850 bp->is_leader = 1;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007851 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007852
7853 /* Stop the driver */
7854 /* If interface has been removed - break */
7855 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
7856 return;
7857
7858 bp->recovery_state = BNX2X_RECOVERY_WAIT;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007859
7860 /*
7861 * Reset MCP command sequence number and MCP mail box
7862 * sequence as we are going to reset the MCP.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007863 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007864 if (global) {
7865 bp->fw_seq = 0;
7866 bp->fw_drv_pulse_wr_seq = 0;
7867 }
7868
7869 /* Ensure "is_leader", MCP command sequence and
7870 * "recovery_state" update values are seen on other
7871 * CPUs.
7872 */
7873 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007874 break;
7875
7876 case BNX2X_RECOVERY_WAIT:
7877 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
7878 if (bp->is_leader) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007879 int other_engine = BP_PATH(bp) ? 0 : 1;
7880 u32 other_load_counter =
7881 bnx2x_get_load_cnt(bp, other_engine);
7882 u32 load_counter =
7883 bnx2x_get_load_cnt(bp, BP_PATH(bp));
7884 global = bnx2x_reset_is_global(bp);
7885
7886 /*
7887 * In case of a parity in a global block, let
7888 * the first leader that performs a
7889 * leader_reset() reset the global blocks in
7890 * order to clear global attentions. Otherwise
7891 * the the gates will remain closed for that
7892 * engine.
7893 */
7894 if (load_counter ||
7895 (global && other_load_counter)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007896 /* Wait until all other functions get
7897 * down.
7898 */
7899 schedule_delayed_work(&bp->reset_task,
7900 HZ/10);
7901 return;
7902 } else {
7903 /* If all other functions got down -
7904 * try to bring the chip back to
7905 * normal. In any case it's an exit
7906 * point for a leader.
7907 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007908 if (bnx2x_leader_reset(bp)) {
7909 bnx2x_recovery_failed(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007910 return;
7911 }
7912
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007913 /* If we are here, means that the
7914 * leader has succeeded and doesn't
7915 * want to be a leader any more. Try
7916 * to continue as a none-leader.
7917 */
7918 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007919 }
7920 } else { /* non-leader */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007921 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007922 /* Try to get a LEADER_LOCK HW lock as
7923 * long as a former leader may have
7924 * been unloaded by the user or
7925 * released a leadership by another
7926 * reason.
7927 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007928 if (bnx2x_trylock_leader_lock(bp)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007929 /* I'm a leader now! Restart a
7930 * switch case.
7931 */
7932 bp->is_leader = 1;
7933 break;
7934 }
7935
7936 schedule_delayed_work(&bp->reset_task,
7937 HZ/10);
7938 return;
7939
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007940 } else {
7941 /*
7942 * If there was a global attention, wait
7943 * for it to be cleared.
7944 */
7945 if (bnx2x_reset_is_global(bp)) {
7946 schedule_delayed_work(
7947 &bp->reset_task, HZ/10);
7948 return;
7949 }
7950
7951 if (bnx2x_nic_load(bp, LOAD_NORMAL))
7952 bnx2x_recovery_failed(bp);
7953 else {
7954 bp->recovery_state =
7955 BNX2X_RECOVERY_DONE;
7956 smp_mb();
7957 }
7958
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007959 return;
7960 }
7961 }
7962 default:
7963 return;
7964 }
7965 }
7966}
7967
7968/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
7969 * scheduled on a general queue in order to prevent a dead lock.
7970 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007971static void bnx2x_reset_task(struct work_struct *work)
7972{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007973 struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007974
7975#ifdef BNX2X_STOP_ON_ERROR
7976 BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
7977 " so reset not done to allow debug dump,\n"
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007978 KERN_ERR " you will need to reboot when done\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007979 return;
7980#endif
7981
7982 rtnl_lock();
7983
7984 if (!netif_running(bp->dev))
7985 goto reset_task_exit;
7986
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00007987 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
7988 bnx2x_parity_recover(bp);
7989 else {
7990 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
7991 bnx2x_nic_load(bp, LOAD_NORMAL);
7992 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007993
7994reset_task_exit:
7995 rtnl_unlock();
7996}
7997
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007998/* end of nic load/unload */
7999
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008000/*
8001 * Init service functions
8002 */
8003
stephen hemminger8d962862010-10-21 07:50:56 +00008004static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008005{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008006 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
8007 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
8008 return base + (BP_ABS_FUNC(bp)) * stride;
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008009}
8010
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008011static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008012{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008013 u32 reg = bnx2x_get_pretend_reg(bp);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008014
8015 /* Flush all outstanding writes */
8016 mmiowb();
8017
8018 /* Pretend to be function 0 */
8019 REG_WR(bp, reg, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008020 REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008021
8022 /* From now we are in the "like-E1" mode */
8023 bnx2x_int_disable(bp);
8024
8025 /* Flush all outstanding writes */
8026 mmiowb();
8027
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008028 /* Restore the original function */
8029 REG_WR(bp, reg, BP_ABS_FUNC(bp));
8030 REG_RD(bp, reg);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008031}
8032
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008033static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008034{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008035 if (CHIP_IS_E1(bp))
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008036 bnx2x_int_disable(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008037 else
8038 bnx2x_undi_int_disable_e1h(bp);
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00008039}
8040
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008041static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008042{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008043 u32 val;
8044
8045 /* Check if there is any driver already loaded */
8046 val = REG_RD(bp, MISC_REG_UNPREPARED);
8047 if (val == 0x1) {
8048 /* Check if it is the UNDI driver
8049 * UNDI driver initializes CID offset for normal bell to 0x7
8050 */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07008051 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008052 val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
8053 if (val == 0x7) {
8054 u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008055 /* save our pf_num */
8056 int orig_pf_num = bp->pf_num;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008057 int port;
8058 u32 swap_en, swap_val, value;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008059
Eilon Greensteinb4661732009-01-14 06:43:56 +00008060 /* clear the UNDI indication */
8061 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
8062
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008063 BNX2X_DEV_INFO("UNDI is active! reset device\n");
8064
8065 /* try unload UNDI on port 0 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008066 bp->pf_num = 0;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008067 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008068 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008069 DRV_MSG_SEQ_NUMBER_MASK);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008070 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008071
8072 /* if UNDI is loaded on the other port */
8073 if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
8074
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008075 /* send "DONE" for previous unload */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008076 bnx2x_fw_command(bp,
8077 DRV_MSG_CODE_UNLOAD_DONE, 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008078
8079 /* unload UNDI on port 1 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008080 bp->pf_num = 1;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008081 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008082 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008083 DRV_MSG_SEQ_NUMBER_MASK);
8084 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008085
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008086 bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008087 }
8088
Eilon Greensteinb4661732009-01-14 06:43:56 +00008089 /* now it's safe to release the lock */
8090 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
8091
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008092 bnx2x_undi_int_disable(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008093 port = BP_PORT(bp);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008094
8095 /* close input traffic and wait for it */
8096 /* Do not rcv packets to BRB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008097 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
8098 NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008099 /* Do not direct rcv packets that are not for MCP to
8100 * the BRB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008101 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8102 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008103 /* clear AEU */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008104 REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8105 MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008106 msleep(10);
8107
8108 /* save NIG port swap info */
8109 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8110 swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008111 /* reset device */
8112 REG_WR(bp,
8113 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008114 0xd3ffffff);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008115
8116 value = 0x1400;
8117 if (CHIP_IS_E3(bp)) {
8118 value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
8119 value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
8120 }
8121
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008122 REG_WR(bp,
8123 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008124 value);
8125
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008126 /* take the NIG out of reset and restore swap values */
8127 REG_WR(bp,
8128 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
8129 MISC_REGISTERS_RESET_REG_1_RST_NIG);
8130 REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
8131 REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
8132
8133 /* send unload done to the MCP */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008134 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008135
8136 /* restore our func and fw_seq */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008137 bp->pf_num = orig_pf_num;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008138 bp->fw_seq =
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008139 (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008140 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greensteinb4661732009-01-14 06:43:56 +00008141 } else
8142 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008143 }
8144}
8145
8146static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
8147{
8148 u32 val, val2, val3, val4, id;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008149 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008150
8151 /* Get the chip revision id and number. */
8152 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
8153 val = REG_RD(bp, MISC_REG_CHIP_NUM);
8154 id = ((val & 0xffff) << 16);
8155 val = REG_RD(bp, MISC_REG_CHIP_REV);
8156 id |= ((val & 0xf) << 12);
8157 val = REG_RD(bp, MISC_REG_CHIP_METAL);
8158 id |= ((val & 0xff) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +00008159 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008160 id |= (val & 0xf);
8161 bp->common.chip_id = id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008162
8163 /* Set doorbell size */
8164 bp->db_size = (1 << BNX2X_DB_SHIFT);
8165
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008166 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008167 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
8168 if ((val & 1) == 0)
8169 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
8170 else
8171 val = (val >> 1) & 1;
8172 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
8173 "2_PORT_MODE");
8174 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
8175 CHIP_2_PORT_MODE;
8176
8177 if (CHIP_MODE_IS_4_PORT(bp))
8178 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
8179 else
8180 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
8181 } else {
8182 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
8183 bp->pfid = bp->pf_num; /* 0..7 */
8184 }
8185
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008186 bp->link_params.chip_id = bp->common.chip_id;
8187 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008188
Eilon Greenstein1c063282009-02-12 08:36:43 +00008189 val = (REG_RD(bp, 0x2874) & 0x55);
8190 if ((bp->common.chip_id & 0x1) ||
8191 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
8192 bp->flags |= ONE_PORT_FLAG;
8193 BNX2X_DEV_INFO("single port device\n");
8194 }
8195
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008196 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008197 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008198 (val & MCPR_NVM_CFG4_FLASH_SIZE));
8199 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
8200 bp->common.flash_size, bp->common.flash_size);
8201
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00008202 bnx2x_init_shmem(bp);
8203
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008204
8205
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008206 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
8207 MISC_REG_GENERIC_CR_1 :
8208 MISC_REG_GENERIC_CR_0));
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00008209
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008210 bp->link_params.shmem_base = bp->common.shmem_base;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008211 bp->link_params.shmem2_base = bp->common.shmem2_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008212 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
8213 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008214
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008215 if (!bp->common.shmem_base) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008216 BNX2X_DEV_INFO("MCP not active\n");
8217 bp->flags |= NO_MCP_FLAG;
8218 return;
8219 }
8220
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008221 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +00008222 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008223
8224 bp->link_params.hw_led_mode = ((bp->common.hw_config &
8225 SHARED_HW_CFG_LED_MODE_MASK) >>
8226 SHARED_HW_CFG_LED_MODE_SHIFT);
8227
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008228 bp->link_params.feature_config_flags = 0;
8229 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
8230 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
8231 bp->link_params.feature_config_flags |=
8232 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8233 else
8234 bp->link_params.feature_config_flags &=
8235 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
8236
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008237 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
8238 bp->common.bc_ver = val;
8239 BNX2X_DEV_INFO("bc_ver %X\n", val);
8240 if (val < BNX2X_BC_VER) {
8241 /* for now only warn
8242 * later we might need to enforce this */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008243 BNX2X_ERR("This driver needs bc_ver %X but found %X, "
8244 "please upgrade BC\n", BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008245 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008246 bp->link_params.feature_config_flags |=
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008247 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008248 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
8249
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008250 bp->link_params.feature_config_flags |=
8251 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
8252 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008253
Dmitry Kravkovf9a3ebb2011-05-04 23:49:11 +00008254 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
8255 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
8256
Eilon Greenstein72ce58c2008-08-13 15:52:46 -07008257 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +00008258 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008259
8260 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
8261 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
8262 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
8263 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
8264
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008265 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
8266 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008267}
8268
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008269#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
8270#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
8271
8272static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
8273{
8274 int pfid = BP_FUNC(bp);
8275 int vn = BP_E1HVN(bp);
8276 int igu_sb_id;
8277 u32 val;
8278 u8 fid;
8279
8280 bp->igu_base_sb = 0xff;
8281 bp->igu_sb_cnt = 0;
8282 if (CHIP_INT_MODE_IS_BC(bp)) {
8283 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008284 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008285
8286 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
8287 FP_SB_MAX_E1x;
8288
8289 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
8290 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
8291
8292 return;
8293 }
8294
8295 /* IGU in normal mode - read CAM */
8296 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
8297 igu_sb_id++) {
8298 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
8299 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
8300 continue;
8301 fid = IGU_FID(val);
8302 if ((fid & IGU_FID_ENCODE_IS_PF)) {
8303 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
8304 continue;
8305 if (IGU_VEC(val) == 0)
8306 /* default status block */
8307 bp->igu_dsb_id = igu_sb_id;
8308 else {
8309 if (bp->igu_base_sb == 0xff)
8310 bp->igu_base_sb = igu_sb_id;
8311 bp->igu_sb_cnt++;
8312 }
8313 }
8314 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008315
8316 /* It's expected that number of CAM entries for this
8317 * functions is equal to the MSI-X table size (which was a
8318 * used during bp->l2_cid_count value calculation.
8319 * We want a harsh warning if these values are different!
8320 */
8321 WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
8322
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008323 if (bp->igu_sb_cnt == 0)
8324 BNX2X_ERR("CAM configuration error\n");
8325}
8326
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008327static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
8328 u32 switch_cfg)
8329{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008330 int cfg_size = 0, idx, port = BP_PORT(bp);
8331
8332 /* Aggregation of supported attributes of all external phys */
8333 bp->port.supported[0] = 0;
8334 bp->port.supported[1] = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008335 switch (bp->link_params.num_phys) {
8336 case 1:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008337 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
8338 cfg_size = 1;
8339 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008340 case 2:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008341 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
8342 cfg_size = 1;
8343 break;
8344 case 3:
8345 if (bp->link_params.multi_phy_config &
8346 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
8347 bp->port.supported[1] =
8348 bp->link_params.phy[EXT_PHY1].supported;
8349 bp->port.supported[0] =
8350 bp->link_params.phy[EXT_PHY2].supported;
8351 } else {
8352 bp->port.supported[0] =
8353 bp->link_params.phy[EXT_PHY1].supported;
8354 bp->port.supported[1] =
8355 bp->link_params.phy[EXT_PHY2].supported;
8356 }
8357 cfg_size = 2;
8358 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008359 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008360
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008361 if (!(bp->port.supported[0] || bp->port.supported[1])) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008362 BNX2X_ERR("NVRAM config error. BAD phy config."
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008363 "PHY1 config 0x%x, PHY2 config 0x%x\n",
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008364 SHMEM_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008365 dev_info.port_hw_config[port].external_phy_config),
8366 SHMEM_RD(bp,
8367 dev_info.port_hw_config[port].external_phy_config2));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008368 return;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008369 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008370
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008371 if (CHIP_IS_E3(bp))
8372 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
8373 else {
8374 switch (switch_cfg) {
8375 case SWITCH_CFG_1G:
8376 bp->port.phy_addr = REG_RD(
8377 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
8378 break;
8379 case SWITCH_CFG_10G:
8380 bp->port.phy_addr = REG_RD(
8381 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
8382 break;
8383 default:
8384 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
8385 bp->port.link_config[0]);
8386 return;
8387 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008388 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008389 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008390 /* mask what we support according to speed_cap_mask per configuration */
8391 for (idx = 0; idx < cfg_size; idx++) {
8392 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008393 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008394 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008395
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008396 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008397 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008398 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008399
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008400 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008401 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008402 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008403
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008404 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008405 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008406 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008407
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008408 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008409 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008410 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008411 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008412
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008413 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008414 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008415 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008416
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008417 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008418 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008419 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008420
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008421 }
8422
8423 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
8424 bp->port.supported[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008425}
8426
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008427static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008428{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008429 u32 link_config, idx, cfg_size = 0;
8430 bp->port.advertising[0] = 0;
8431 bp->port.advertising[1] = 0;
8432 switch (bp->link_params.num_phys) {
8433 case 1:
8434 case 2:
8435 cfg_size = 1;
8436 break;
8437 case 3:
8438 cfg_size = 2;
8439 break;
8440 }
8441 for (idx = 0; idx < cfg_size; idx++) {
8442 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
8443 link_config = bp->port.link_config[idx];
8444 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008445 case PORT_FEATURE_LINK_SPEED_AUTO:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008446 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
8447 bp->link_params.req_line_speed[idx] =
8448 SPEED_AUTO_NEG;
8449 bp->port.advertising[idx] |=
8450 bp->port.supported[idx];
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008451 } else {
8452 /* force 10G, no AN */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008453 bp->link_params.req_line_speed[idx] =
8454 SPEED_10000;
8455 bp->port.advertising[idx] |=
8456 (ADVERTISED_10000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008457 ADVERTISED_FIBRE);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008458 continue;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008459 }
8460 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008461
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008462 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008463 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
8464 bp->link_params.req_line_speed[idx] =
8465 SPEED_10;
8466 bp->port.advertising[idx] |=
8467 (ADVERTISED_10baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008468 ADVERTISED_TP);
8469 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008470 BNX2X_ERR("NVRAM config error. "
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008471 "Invalid link_config 0x%x"
8472 " speed_cap_mask 0x%x\n",
8473 link_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008474 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008475 return;
8476 }
8477 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008478
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008479 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008480 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
8481 bp->link_params.req_line_speed[idx] =
8482 SPEED_10;
8483 bp->link_params.req_duplex[idx] =
8484 DUPLEX_HALF;
8485 bp->port.advertising[idx] |=
8486 (ADVERTISED_10baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008487 ADVERTISED_TP);
8488 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008489 BNX2X_ERR("NVRAM config error. "
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008490 "Invalid link_config 0x%x"
8491 " speed_cap_mask 0x%x\n",
8492 link_config,
8493 bp->link_params.speed_cap_mask[idx]);
8494 return;
8495 }
8496 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008497
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008498 case PORT_FEATURE_LINK_SPEED_100M_FULL:
8499 if (bp->port.supported[idx] &
8500 SUPPORTED_100baseT_Full) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008501 bp->link_params.req_line_speed[idx] =
8502 SPEED_100;
8503 bp->port.advertising[idx] |=
8504 (ADVERTISED_100baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008505 ADVERTISED_TP);
8506 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008507 BNX2X_ERR("NVRAM config error. "
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008508 "Invalid link_config 0x%x"
8509 " speed_cap_mask 0x%x\n",
8510 link_config,
8511 bp->link_params.speed_cap_mask[idx]);
8512 return;
8513 }
8514 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008515
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008516 case PORT_FEATURE_LINK_SPEED_100M_HALF:
8517 if (bp->port.supported[idx] &
8518 SUPPORTED_100baseT_Half) {
8519 bp->link_params.req_line_speed[idx] =
8520 SPEED_100;
8521 bp->link_params.req_duplex[idx] =
8522 DUPLEX_HALF;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008523 bp->port.advertising[idx] |=
8524 (ADVERTISED_100baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008525 ADVERTISED_TP);
8526 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008527 BNX2X_ERR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008528 "Invalid link_config 0x%x"
8529 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008530 link_config,
8531 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008532 return;
8533 }
8534 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008535
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008536 case PORT_FEATURE_LINK_SPEED_1G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008537 if (bp->port.supported[idx] &
8538 SUPPORTED_1000baseT_Full) {
8539 bp->link_params.req_line_speed[idx] =
8540 SPEED_1000;
8541 bp->port.advertising[idx] |=
8542 (ADVERTISED_1000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008543 ADVERTISED_TP);
8544 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008545 BNX2X_ERR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008546 "Invalid link_config 0x%x"
8547 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008548 link_config,
8549 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008550 return;
8551 }
8552 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008553
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008554 case PORT_FEATURE_LINK_SPEED_2_5G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008555 if (bp->port.supported[idx] &
8556 SUPPORTED_2500baseX_Full) {
8557 bp->link_params.req_line_speed[idx] =
8558 SPEED_2500;
8559 bp->port.advertising[idx] |=
8560 (ADVERTISED_2500baseX_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008561 ADVERTISED_TP);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008562 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008563 BNX2X_ERR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008564 "Invalid link_config 0x%x"
8565 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008566 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008567 bp->link_params.speed_cap_mask[idx]);
8568 return;
8569 }
8570 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008571
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008572 case PORT_FEATURE_LINK_SPEED_10G_CX4:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008573 if (bp->port.supported[idx] &
8574 SUPPORTED_10000baseT_Full) {
8575 bp->link_params.req_line_speed[idx] =
8576 SPEED_10000;
8577 bp->port.advertising[idx] |=
8578 (ADVERTISED_10000baseT_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008579 ADVERTISED_FIBRE);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008580 } else {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008581 BNX2X_ERR("NVRAM config error. "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00008582 "Invalid link_config 0x%x"
8583 " speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008584 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008585 bp->link_params.speed_cap_mask[idx]);
8586 return;
8587 }
8588 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008589
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008590 default:
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008591 BNX2X_ERR("NVRAM config error. "
8592 "BAD link speed link_config 0x%x\n",
8593 link_config);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008594 bp->link_params.req_line_speed[idx] =
8595 SPEED_AUTO_NEG;
8596 bp->port.advertising[idx] =
8597 bp->port.supported[idx];
8598 break;
8599 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008600
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008601 bp->link_params.req_flow_ctrl[idx] = (link_config &
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008602 PORT_FEATURE_FLOW_CONTROL_MASK);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008603 if ((bp->link_params.req_flow_ctrl[idx] ==
8604 BNX2X_FLOW_CTRL_AUTO) &&
8605 !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
8606 bp->link_params.req_flow_ctrl[idx] =
8607 BNX2X_FLOW_CTRL_NONE;
8608 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008609
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008610 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
8611 " 0x%x advertising 0x%x\n",
8612 bp->link_params.req_line_speed[idx],
8613 bp->link_params.req_duplex[idx],
8614 bp->link_params.req_flow_ctrl[idx],
8615 bp->port.advertising[idx]);
8616 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008617}
8618
Michael Chane665bfd2009-10-10 13:46:54 +00008619static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
8620{
8621 mac_hi = cpu_to_be16(mac_hi);
8622 mac_lo = cpu_to_be32(mac_lo);
8623 memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
8624 memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
8625}
8626
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008627static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008628{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008629 int port = BP_PORT(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +00008630 u32 config;
Joe Perches6f38ad92010-11-14 17:04:31 +00008631 u32 ext_phy_type, ext_phy_config;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008632
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008633 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008634 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008635
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008636 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008637 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008638
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008639 bp->link_params.speed_cap_mask[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008640 SHMEM_RD(bp,
8641 dev_info.port_hw_config[port].speed_capability_mask);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008642 bp->link_params.speed_cap_mask[1] =
8643 SHMEM_RD(bp,
8644 dev_info.port_hw_config[port].speed_capability_mask2);
8645 bp->port.link_config[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008646 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
8647
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008648 bp->port.link_config[1] =
8649 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00008650
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008651 bp->link_params.multi_phy_config =
8652 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008653 /* If the device is capable of WoL, set the default state according
8654 * to the HW
8655 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008656 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +00008657 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
8658 (config & PORT_FEATURE_WOL_ENABLED));
8659
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008660 BNX2X_DEV_INFO("lane_config 0x%08x "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008661 "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008662 bp->link_params.lane_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008663 bp->link_params.speed_cap_mask[0],
8664 bp->port.link_config[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008665
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008666 bp->link_params.switch_cfg = (bp->port.link_config[0] &
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008667 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008668 bnx2x_phy_probe(&bp->link_params);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008669 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008670
8671 bnx2x_link_settings_requested(bp);
8672
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008673 /*
8674 * If connected directly, work with the internal PHY, otherwise, work
8675 * with the external PHY
8676 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008677 ext_phy_config =
8678 SHMEM_RD(bp,
8679 dev_info.port_hw_config[port].external_phy_config);
8680 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008681 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008682 bp->mdio.prtad = bp->port.phy_addr;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008683
8684 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
8685 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
8686 bp->mdio.prtad =
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008687 XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner5866df62011-01-30 04:15:07 +00008688
8689 /*
8690 * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
8691 * In MF mode, it is set to cover self test cases
8692 */
8693 if (IS_MF(bp))
8694 bp->port.need_hw_lock = 1;
8695 else
8696 bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
8697 bp->common.shmem_base,
8698 bp->common.shmem2_base);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008699}
Eilon Greenstein01cd4522009-08-12 08:23:08 +00008700
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008701#ifdef BCM_CNIC
8702static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
8703{
8704 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8705 drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
8706 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
8707 drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
8708
8709 /* Get the number of maximum allowed iSCSI and FCoE connections */
8710 bp->cnic_eth_dev.max_iscsi_conn =
8711 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
8712 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
8713
8714 bp->cnic_eth_dev.max_fcoe_conn =
8715 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
8716 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
8717
8718 BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
8719 bp->cnic_eth_dev.max_iscsi_conn,
8720 bp->cnic_eth_dev.max_fcoe_conn);
8721
8722 /* If mamimum allowed number of connections is zero -
8723 * disable the feature.
8724 */
8725 if (!bp->cnic_eth_dev.max_iscsi_conn)
8726 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8727
8728 if (!bp->cnic_eth_dev.max_fcoe_conn)
8729 bp->flags |= NO_FCOE_FLAG;
8730}
8731#endif
8732
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008733static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
8734{
8735 u32 val, val2;
8736 int func = BP_ABS_FUNC(bp);
8737 int port = BP_PORT(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008738#ifdef BCM_CNIC
8739 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
8740 u8 *fip_mac = bp->fip_mac;
8741#endif
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008742
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008743 /* Zero primary MAC configuration */
8744 memset(bp->dev->dev_addr, 0, ETH_ALEN);
8745
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008746 if (BP_NOMCP(bp)) {
8747 BNX2X_ERROR("warning: random MAC workaround active\n");
8748 random_ether_addr(bp->dev->dev_addr);
8749 } else if (IS_MF(bp)) {
8750 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
8751 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
8752 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
8753 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
8754 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8755
8756#ifdef BCM_CNIC
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008757 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
8758 * FCoE MAC then the appropriate feature should be disabled.
8759 */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008760 if (IS_MF_SI(bp)) {
8761 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
8762 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
8763 val2 = MF_CFG_RD(bp, func_ext_config[func].
8764 iscsi_mac_addr_upper);
8765 val = MF_CFG_RD(bp, func_ext_config[func].
8766 iscsi_mac_addr_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008767 bnx2x_set_mac_buf(iscsi_mac, val, val2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008768 BNX2X_DEV_INFO("Read iSCSI MAC: "
8769 BNX2X_MAC_FMT"\n",
8770 BNX2X_MAC_PRN_LIST(iscsi_mac));
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008771 } else
8772 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
8773
8774 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
8775 val2 = MF_CFG_RD(bp, func_ext_config[func].
8776 fcoe_mac_addr_upper);
8777 val = MF_CFG_RD(bp, func_ext_config[func].
8778 fcoe_mac_addr_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008779 bnx2x_set_mac_buf(fip_mac, val, val2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008780 BNX2X_DEV_INFO("Read FCoE L2 MAC to "
8781 BNX2X_MAC_FMT"\n",
8782 BNX2X_MAC_PRN_LIST(fip_mac));
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008783
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008784 } else
8785 bp->flags |= NO_FCOE_FLAG;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008786 }
8787#endif
8788 } else {
8789 /* in SF read MACs from port configuration */
8790 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
8791 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
8792 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
8793
8794#ifdef BCM_CNIC
8795 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
8796 iscsi_mac_upper);
8797 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
8798 iscsi_mac_lower);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008799 bnx2x_set_mac_buf(iscsi_mac, val, val2);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008800#endif
8801 }
8802
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07008803 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
8804 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +00008805
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008806#ifdef BCM_CNIC
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008807 /* Set the FCoE MAC in modes other then MF_SI */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008808 if (!CHIP_IS_E1x(bp)) {
8809 if (IS_MF_SD(bp))
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00008810 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
8811 else if (!IS_MF(bp))
8812 memcpy(fip_mac, iscsi_mac, ETH_ALEN);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008813 }
Dmitry Kravkov426b9242011-05-04 23:49:53 +00008814
8815 /* Disable iSCSI if MAC configuration is
8816 * invalid.
8817 */
8818 if (!is_valid_ether_addr(iscsi_mac)) {
8819 bp->flags |= NO_ISCSI_FLAG;
8820 memset(iscsi_mac, 0, ETH_ALEN);
8821 }
8822
8823 /* Disable FCoE if MAC configuration is
8824 * invalid.
8825 */
8826 if (!is_valid_ether_addr(fip_mac)) {
8827 bp->flags |= NO_FCOE_FLAG;
8828 memset(bp->fip_mac, 0, ETH_ALEN);
8829 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008830#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008831
8832 if (!is_valid_ether_addr(bp->dev->dev_addr))
8833 dev_err(&bp->pdev->dev,
8834 "bad Ethernet MAC address configuration: "
8835 BNX2X_MAC_FMT", change it manually before bringing up "
8836 "the appropriate network interface\n",
8837 BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008838}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008839
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008840static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
8841{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008842 int /*abs*/func = BP_ABS_FUNC(bp);
David S. Millerb8ee8322011-04-17 16:56:12 -07008843 int vn;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008844 u32 val = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008845 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008846
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008847 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008848
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008849 if (CHIP_IS_E1x(bp)) {
8850 bp->common.int_block = INT_BLOCK_HC;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008851
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008852 bp->igu_dsb_id = DEF_SB_IGU_ID;
8853 bp->igu_base_sb = 0;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008854 bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
8855 NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008856 } else {
8857 bp->common.int_block = INT_BLOCK_IGU;
8858 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008859
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008860 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008861 int tout = 5000;
8862
8863 BNX2X_DEV_INFO("FORCING Normal Mode\n");
8864
8865 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
8866 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
8867 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
8868
8869 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8870 tout--;
8871 usleep_range(1000, 1000);
8872 }
8873
8874 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
8875 dev_err(&bp->pdev->dev,
8876 "FORCING Normal Mode failed!!!\n");
8877 return -EPERM;
8878 }
8879 }
8880
8881 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
8882 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008883 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
8884 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008885 BNX2X_DEV_INFO("IGU Normal Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008886
8887 bnx2x_get_igu_cam_info(bp);
8888
8889 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008890
8891 /*
8892 * set base FW non-default (fast path) status block id, this value is
8893 * used to initialize the fw_sb_id saved on the fp/queue structure to
8894 * determine the id used by the FW.
8895 */
8896 if (CHIP_IS_E1x(bp))
8897 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
8898 else /*
8899 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
8900 * the same queue are indicated on the same IGU SB). So we prefer
8901 * FW and IGU SBs to be the same value.
8902 */
8903 bp->base_fw_ndsb = bp->igu_base_sb;
8904
8905 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
8906 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
8907 bp->igu_sb_cnt, bp->base_fw_ndsb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008908
8909 /*
8910 * Initialize MF configuration
8911 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008912
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008913 bp->mf_ov = 0;
8914 bp->mf_mode = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008915 vn = BP_E1HVN(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008916
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008917 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008918 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
8919 bp->common.shmem2_base, SHMEM2_RD(bp, size),
8920 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
8921
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008922 if (SHMEM2_HAS(bp, mf_cfg_addr))
8923 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
8924 else
8925 bp->common.mf_cfg_base = bp->common.shmem_base +
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008926 offsetof(struct shmem_region, func_mb) +
8927 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008928 /*
8929 * get mf configuration:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008930 * 1. existence of MF configuration
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008931 * 2. MAC address must be legal (check only upper bytes)
8932 * for Switch-Independent mode;
8933 * OVLAN must be legal for Switch-Dependent mode
8934 * 3. SF_MODE configures specific MF mode
8935 */
8936 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
8937 /* get mf configuration */
8938 val = SHMEM_RD(bp,
8939 dev_info.shared_feature_config.config);
8940 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008941
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008942 switch (val) {
8943 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
8944 val = MF_CFG_RD(bp, func_mf_config[func].
8945 mac_upper);
8946 /* check for legal mac (upper bytes)*/
8947 if (val != 0xffff) {
8948 bp->mf_mode = MULTI_FUNCTION_SI;
8949 bp->mf_config[vn] = MF_CFG_RD(bp,
8950 func_mf_config[func].config);
8951 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008952 BNX2X_DEV_INFO("illegal MAC address "
8953 "for SI\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008954 break;
8955 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
8956 /* get OV configuration */
8957 val = MF_CFG_RD(bp,
8958 func_mf_config[FUNC_0].e1hov_tag);
8959 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
8960
8961 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
8962 bp->mf_mode = MULTI_FUNCTION_SD;
8963 bp->mf_config[vn] = MF_CFG_RD(bp,
8964 func_mf_config[func].config);
8965 } else
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008966 BNX2X_DEV_INFO("illegal OV for SD\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008967 break;
8968 default:
8969 /* Unknown configuration: reset mf_config */
8970 bp->mf_config[vn] = 0;
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00008971 BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008972 }
8973 }
8974
Eilon Greenstein2691d512009-08-12 08:22:08 +00008975 BNX2X_DEV_INFO("%s function mode\n",
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008976 IS_MF(bp) ? "multi" : "single");
Eilon Greenstein2691d512009-08-12 08:22:08 +00008977
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008978 switch (bp->mf_mode) {
8979 case MULTI_FUNCTION_SD:
8980 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
8981 FUNC_MF_CFG_E1HOV_TAG_MASK;
Eilon Greenstein2691d512009-08-12 08:22:08 +00008982 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00008983 bp->mf_ov = val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008984 bp->path_has_ovlan = true;
8985
8986 BNX2X_DEV_INFO("MF OV for func %d is %d "
8987 "(0x%04x)\n", func, bp->mf_ov,
8988 bp->mf_ov);
Eilon Greenstein2691d512009-08-12 08:22:08 +00008989 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008990 dev_err(&bp->pdev->dev,
8991 "No valid MF OV for func %d, "
8992 "aborting\n", func);
8993 return -EPERM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008994 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008995 break;
8996 case MULTI_FUNCTION_SI:
8997 BNX2X_DEV_INFO("func %d is in MF "
8998 "switch-independent mode\n", func);
8999 break;
9000 default:
9001 if (vn) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009002 dev_err(&bp->pdev->dev,
9003 "VN %d is in a single function mode, "
9004 "aborting\n", vn);
9005 return -EPERM;
Eilon Greenstein2691d512009-08-12 08:22:08 +00009006 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009007 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009008 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009009
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009010 /* check if other port on the path needs ovlan:
9011 * Since MF configuration is shared between ports
9012 * Possible mixed modes are only
9013 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
9014 */
9015 if (CHIP_MODE_IS_4_PORT(bp) &&
9016 !bp->path_has_ovlan &&
9017 !IS_MF(bp) &&
9018 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
9019 u8 other_port = !BP_PORT(bp);
9020 u8 other_func = BP_PATH(bp) + 2*other_port;
9021 val = MF_CFG_RD(bp,
9022 func_mf_config[other_func].e1hov_tag);
9023 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
9024 bp->path_has_ovlan = true;
9025 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009026 }
9027
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009028 /* adjust igu_sb_cnt to MF for E1x */
9029 if (CHIP_IS_E1x(bp) && IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009030 bp->igu_sb_cnt /= E1HVN_MAX;
9031
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009032 /* port info */
9033 bnx2x_get_port_hwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009034
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009035 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009036 bp->fw_seq =
9037 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
9038 DRV_MSG_SEQ_NUMBER_MASK);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009039 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
9040 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009041
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08009042 /* Get MAC addresses */
9043 bnx2x_get_mac_hwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009044
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +00009045#ifdef BCM_CNIC
9046 bnx2x_get_cnic_info(bp);
9047#endif
9048
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009049 /* Get current FW pulse sequence */
9050 if (!BP_NOMCP(bp)) {
9051 int mb_idx = BP_FW_MB_IDX(bp);
9052
9053 bp->fw_drv_pulse_wr_seq =
9054 (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
9055 DRV_PULSE_SEQ_MASK);
9056 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
9057 }
9058
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009059 return rc;
9060}
9061
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00009062static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
9063{
9064 int cnt, i, block_end, rodi;
9065 char vpd_data[BNX2X_VPD_LEN+1];
9066 char str_id_reg[VENDOR_ID_LEN+1];
9067 char str_id_cap[VENDOR_ID_LEN+1];
9068 u8 len;
9069
9070 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
9071 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
9072
9073 if (cnt < BNX2X_VPD_LEN)
9074 goto out_not_found;
9075
9076 i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
9077 PCI_VPD_LRDT_RO_DATA);
9078 if (i < 0)
9079 goto out_not_found;
9080
9081
9082 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
9083 pci_vpd_lrdt_size(&vpd_data[i]);
9084
9085 i += PCI_VPD_LRDT_TAG_SIZE;
9086
9087 if (block_end > BNX2X_VPD_LEN)
9088 goto out_not_found;
9089
9090 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9091 PCI_VPD_RO_KEYWORD_MFR_ID);
9092 if (rodi < 0)
9093 goto out_not_found;
9094
9095 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9096
9097 if (len != VENDOR_ID_LEN)
9098 goto out_not_found;
9099
9100 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9101
9102 /* vendor specific info */
9103 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
9104 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
9105 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
9106 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
9107
9108 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
9109 PCI_VPD_RO_KEYWORD_VENDOR0);
9110 if (rodi >= 0) {
9111 len = pci_vpd_info_field_size(&vpd_data[rodi]);
9112
9113 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
9114
9115 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
9116 memcpy(bp->fw_ver, &vpd_data[rodi], len);
9117 bp->fw_ver[len] = ' ';
9118 }
9119 }
9120 return;
9121 }
9122out_not_found:
9123 return;
9124}
9125
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009126static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
9127{
9128 u32 flags = 0;
9129
9130 if (CHIP_REV_IS_FPGA(bp))
9131 SET_FLAGS(flags, MODE_FPGA);
9132 else if (CHIP_REV_IS_EMUL(bp))
9133 SET_FLAGS(flags, MODE_EMUL);
9134 else
9135 SET_FLAGS(flags, MODE_ASIC);
9136
9137 if (CHIP_MODE_IS_4_PORT(bp))
9138 SET_FLAGS(flags, MODE_PORT4);
9139 else
9140 SET_FLAGS(flags, MODE_PORT2);
9141
9142 if (CHIP_IS_E2(bp))
9143 SET_FLAGS(flags, MODE_E2);
9144 else if (CHIP_IS_E3(bp)) {
9145 SET_FLAGS(flags, MODE_E3);
9146 if (CHIP_REV(bp) == CHIP_REV_Ax)
9147 SET_FLAGS(flags, MODE_E3_A0);
9148 else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
9149 SET_FLAGS(flags, MODE_E3_B0);
9150 SET_FLAGS(flags, MODE_COS_BC);
9151 }
9152 }
9153
9154 if (IS_MF(bp)) {
9155 SET_FLAGS(flags, MODE_MF);
9156 switch (bp->mf_mode) {
9157 case MULTI_FUNCTION_SD:
9158 SET_FLAGS(flags, MODE_MF_SD);
9159 break;
9160 case MULTI_FUNCTION_SI:
9161 SET_FLAGS(flags, MODE_MF_SI);
9162 break;
9163 }
9164 } else
9165 SET_FLAGS(flags, MODE_SF);
9166
9167#if defined(__LITTLE_ENDIAN)
9168 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
9169#else /*(__BIG_ENDIAN)*/
9170 SET_FLAGS(flags, MODE_BIG_ENDIAN);
9171#endif
9172 INIT_MODE_FLAGS(bp) = flags;
9173}
9174
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009175static int __devinit bnx2x_init_bp(struct bnx2x *bp)
9176{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009177 int func;
Eilon Greenstein87942b42009-02-12 08:36:49 +00009178 int timer_interval;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009179 int rc;
9180
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009181 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07009182 mutex_init(&bp->fw_mb_mutex);
David S. Millerbb7e95c2010-07-27 21:01:35 -07009183 spin_lock_init(&bp->stats_lock);
Michael Chan993ac7b2009-10-10 13:46:56 +00009184#ifdef BCM_CNIC
9185 mutex_init(&bp->cnic_mutex);
9186#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009187
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08009188 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009189 INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009190
9191 rc = bnx2x_get_hwinfo(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009192 if (rc)
9193 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009194
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009195 bnx2x_set_modes_bitmap(bp);
9196
9197 rc = bnx2x_alloc_mem_bp(bp);
9198 if (rc)
9199 return rc;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009200
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00009201 bnx2x_read_fwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009202
9203 func = BP_FUNC(bp);
9204
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009205 /* need to reset chip if undi was active */
9206 if (!BP_NOMCP(bp))
9207 bnx2x_undi_unload(bp);
9208
9209 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009210 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009211
9212 if (BP_NOMCP(bp) && (func == 0))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009213 dev_err(&bp->pdev->dev, "MCP disabled, "
9214 "must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009215
Eilon Greenstein555f6c72009-02-12 08:36:11 +00009216 bp->multi_mode = multi_mode;
Eilon Greenstein555f6c72009-02-12 08:36:11 +00009217
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009218 /* Set TPA flags */
9219 if (disable_tpa) {
9220 bp->flags &= ~TPA_ENABLE_FLAG;
9221 bp->dev->features &= ~NETIF_F_LRO;
9222 } else {
9223 bp->flags |= TPA_ENABLE_FLAG;
9224 bp->dev->features |= NETIF_F_LRO;
9225 }
Dmitry Kravkov5d7cd492010-07-27 12:32:19 +00009226 bp->disable_tpa = disable_tpa;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009227
Eilon Greensteina18f5122009-08-12 08:23:26 +00009228 if (CHIP_IS_E1(bp))
9229 bp->dropless_fc = 0;
9230 else
9231 bp->dropless_fc = dropless_fc;
9232
Eilon Greenstein8d5726c2009-02-12 08:37:19 +00009233 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07009234
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009235 bp->tx_ring_size = MAX_TX_AVAIL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009236
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00009237 /* make sure that the numbers are in the right granularity */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009238 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
9239 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009240
Eilon Greenstein87942b42009-02-12 08:36:49 +00009241 timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
9242 bp->current_interval = (poll ? poll : timer_interval);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009243
9244 init_timer(&bp->timer);
9245 bp->timer.expires = jiffies + bp->current_interval;
9246 bp->timer.data = (unsigned long) bp;
9247 bp->timer.function = bnx2x_timer;
9248
Shmulik Ravid785b9b12010-12-30 06:27:03 +00009249 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00009250 bnx2x_dcbx_init_params(bp);
9251
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009252#ifdef BCM_CNIC
9253 if (CHIP_IS_E1x(bp))
9254 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
9255 else
9256 bp->cnic_base_cl_id = FP_SB_MAX_E2;
9257#endif
9258
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009259 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009260}
9261
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009262
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00009263/****************************************************************************
9264* General service functions
9265****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009266
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009267/*
9268 * net_device service functions
9269 */
9270
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009271/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009272static int bnx2x_open(struct net_device *dev)
9273{
9274 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009275 bool global = false;
9276 int other_engine = BP_PATH(bp) ? 0 : 1;
9277 u32 other_load_counter, load_counter;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009278
Eilon Greenstein6eccabb2009-01-22 03:37:48 +00009279 netif_carrier_off(dev);
9280
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009281 bnx2x_set_power_state(bp, PCI_D0);
9282
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009283 other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
9284 load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009285
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009286 /*
9287 * If parity had happen during the unload, then attentions
9288 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
9289 * want the first function loaded on the current engine to
9290 * complete the recovery.
9291 */
9292 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
9293 bnx2x_chk_parity_attn(bp, &global, true))
9294 do {
9295 /*
9296 * If there are attentions and they are in a global
9297 * blocks, set the GLOBAL_RESET bit regardless whether
9298 * it will be this function that will complete the
9299 * recovery or not.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009300 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009301 if (global)
9302 bnx2x_set_reset_global(bp);
9303
9304 /*
9305 * Only the first function on the current engine should
9306 * try to recover in open. In case of attentions in
9307 * global blocks only the first in the chip should try
9308 * to recover.
9309 */
9310 if ((!load_counter &&
9311 (!global || !other_load_counter)) &&
9312 bnx2x_trylock_leader_lock(bp) &&
9313 !bnx2x_leader_reset(bp)) {
9314 netdev_info(bp->dev, "Recovered in open\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009315 break;
9316 }
9317
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009318 /* recovery has failed... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009319 bnx2x_set_power_state(bp, PCI_D3hot);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009320 bp->recovery_state = BNX2X_RECOVERY_FAILED;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009321
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009322 netdev_err(bp->dev, "Recovery flow hasn't been properly"
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009323 " completed yet. Try again later. If u still see this"
9324 " message after a few retries then power cycle is"
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009325 " required.\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009326
9327 return -EAGAIN;
9328 } while (0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009329
9330 bp->recovery_state = BNX2X_RECOVERY_DONE;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009331 return bnx2x_nic_load(bp, LOAD_OPEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009332}
9333
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009334/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009335static int bnx2x_close(struct net_device *dev)
9336{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009337 struct bnx2x *bp = netdev_priv(dev);
9338
9339 /* Unload the driver, release IRQs */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07009340 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009341
9342 /* Power off */
Vladislav Zolotarovd3dbfee2010-04-19 01:14:49 +00009343 bnx2x_set_power_state(bp, PCI_D3hot);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009344
9345 return 0;
9346}
9347
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009348static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
9349 struct bnx2x_mcast_ramrod_params *p)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009350{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009351 int mc_count = netdev_mc_count(bp->dev);
9352 struct bnx2x_mcast_list_elem *mc_mac =
9353 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009354 struct netdev_hw_addr *ha;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009355
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009356 if (!mc_mac)
9357 return -ENOMEM;
9358
9359 INIT_LIST_HEAD(&p->mcast_list);
9360
9361 netdev_for_each_mc_addr(ha, bp->dev) {
9362 mc_mac->mac = bnx2x_mc_addr(ha);
9363 list_add_tail(&mc_mac->link, &p->mcast_list);
9364 mc_mac++;
9365 }
9366
9367 p->mcast_list_len = mc_count;
9368
9369 return 0;
9370}
9371
9372static inline void bnx2x_free_mcast_macs_list(
9373 struct bnx2x_mcast_ramrod_params *p)
9374{
9375 struct bnx2x_mcast_list_elem *mc_mac =
9376 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
9377 link);
9378
9379 WARN_ON(!mc_mac);
9380 kfree(mc_mac);
9381}
9382
9383/**
9384 * bnx2x_set_uc_list - configure a new unicast MACs list.
9385 *
9386 * @bp: driver handle
9387 *
9388 * We will use zero (0) as a MAC type for these MACs.
9389 */
9390static inline int bnx2x_set_uc_list(struct bnx2x *bp)
9391{
9392 int rc;
9393 struct net_device *dev = bp->dev;
9394 struct netdev_hw_addr *ha;
9395 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
9396 unsigned long ramrod_flags = 0;
9397
9398 /* First schedule a cleanup up of old configuration */
9399 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
9400 if (rc < 0) {
9401 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
9402 return rc;
9403 }
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009404
9405 netdev_for_each_uc_addr(ha, dev) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009406 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
9407 BNX2X_UC_LIST_MAC, &ramrod_flags);
9408 if (rc < 0) {
9409 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
9410 rc);
9411 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009412 }
9413 }
9414
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009415 /* Execute the pending commands */
9416 __set_bit(RAMROD_CONT, &ramrod_flags);
9417 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
9418 BNX2X_UC_LIST_MAC, &ramrod_flags);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009419}
9420
9421static inline int bnx2x_set_mc_list(struct bnx2x *bp)
9422{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009423 struct net_device *dev = bp->dev;
9424 struct bnx2x_mcast_ramrod_params rparam = {0};
9425 int rc = 0;
9426
9427 rparam.mcast_obj = &bp->mcast_obj;
9428
9429 /* first, clear all configured multicast MACs */
9430 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9431 if (rc < 0) {
9432 BNX2X_ERR("Failed to clear multicast "
9433 "configuration: %d\n", rc);
9434 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009435 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009436
9437 /* then, configure a new MACs list */
9438 if (netdev_mc_count(dev)) {
9439 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
9440 if (rc) {
9441 BNX2X_ERR("Failed to create multicast MACs "
9442 "list: %d\n", rc);
9443 return rc;
9444 }
9445
9446 /* Now add the new MACs */
9447 rc = bnx2x_config_mcast(bp, &rparam,
9448 BNX2X_MCAST_CMD_ADD);
9449 if (rc < 0)
9450 BNX2X_ERR("Failed to set a new multicast "
9451 "configuration: %d\n", rc);
9452
9453 bnx2x_free_mcast_macs_list(&rparam);
9454 }
9455
9456 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009457}
9458
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009459
9460/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009461void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009462{
9463 struct bnx2x *bp = netdev_priv(dev);
9464 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009465
9466 if (bp->state != BNX2X_STATE_OPEN) {
9467 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
9468 return;
9469 }
9470
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009471 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009472
9473 if (dev->flags & IFF_PROMISC)
9474 rx_mode = BNX2X_RX_MODE_PROMISC;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009475 else if ((dev->flags & IFF_ALLMULTI) ||
9476 ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
9477 CHIP_IS_E1(bp)))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009478 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009479 else {
9480 /* some multicasts */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009481 if (bnx2x_set_mc_list(bp) < 0)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009482 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009483
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009484 if (bnx2x_set_uc_list(bp) < 0)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009485 rx_mode = BNX2X_RX_MODE_PROMISC;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009486 }
9487
9488 bp->rx_mode = rx_mode;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009489
9490 /* Schedule the rx_mode command */
9491 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
9492 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9493 return;
9494 }
9495
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009496 bnx2x_set_storm_rx_mode(bp);
9497}
9498
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009499/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009500static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
9501 int devad, u16 addr)
9502{
9503 struct bnx2x *bp = netdev_priv(netdev);
9504 u16 value;
9505 int rc;
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009506
9507 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
9508 prtad, devad, addr);
9509
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009510 /* The HW expects different devad if CL22 is used */
9511 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9512
9513 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009514 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009515 bnx2x_release_phy_lock(bp);
9516 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
9517
9518 if (!rc)
9519 rc = value;
9520 return rc;
9521}
9522
9523/* called with rtnl_lock */
9524static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
9525 u16 addr, u16 value)
9526{
9527 struct bnx2x *bp = netdev_priv(netdev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009528 int rc;
9529
9530 DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
9531 " value 0x%x\n", prtad, devad, addr, value);
9532
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009533 /* The HW expects different devad if CL22 is used */
9534 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
9535
9536 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009537 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009538 bnx2x_release_phy_lock(bp);
9539 return rc;
9540}
9541
9542/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009543static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
9544{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009545 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009546 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009547
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009548 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
9549 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009550
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009551 if (!netif_running(dev))
9552 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07009553
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009554 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009555}
9556
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00009557#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009558static void poll_bnx2x(struct net_device *dev)
9559{
9560 struct bnx2x *bp = netdev_priv(dev);
9561
9562 disable_irq(bp->pdev->irq);
9563 bnx2x_interrupt(bp->pdev->irq, dev);
9564 enable_irq(bp->pdev->irq);
9565}
9566#endif
9567
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009568static const struct net_device_ops bnx2x_netdev_ops = {
9569 .ndo_open = bnx2x_open,
9570 .ndo_stop = bnx2x_close,
9571 .ndo_start_xmit = bnx2x_start_xmit,
Vladislav Zolotarov8307fa32010-12-13 05:44:09 +00009572 .ndo_select_queue = bnx2x_select_queue,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08009573 .ndo_set_rx_mode = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009574 .ndo_set_mac_address = bnx2x_change_mac_addr,
9575 .ndo_validate_addr = eth_validate_addr,
9576 .ndo_do_ioctl = bnx2x_ioctl,
9577 .ndo_change_mtu = bnx2x_change_mtu,
Michał Mirosław66371c42011-04-12 09:38:23 +00009578 .ndo_fix_features = bnx2x_fix_features,
9579 .ndo_set_features = bnx2x_set_features,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009580 .ndo_tx_timeout = bnx2x_tx_timeout,
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +00009581#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009582 .ndo_poll_controller = poll_bnx2x,
9583#endif
9584};
9585
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009586static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
9587{
9588 struct device *dev = &bp->pdev->dev;
9589
9590 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
9591 bp->flags |= USING_DAC_FLAG;
9592 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
9593 dev_err(dev, "dma_set_coherent_mask failed, "
9594 "aborting\n");
9595 return -EIO;
9596 }
9597 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
9598 dev_err(dev, "System does not support DMA, aborting\n");
9599 return -EIO;
9600 }
9601
9602 return 0;
9603}
9604
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009605static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009606 struct net_device *dev,
9607 unsigned long board_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009608{
9609 struct bnx2x *bp;
9610 int rc;
9611
9612 SET_NETDEV_DEV(dev, &pdev->dev);
9613 bp = netdev_priv(dev);
9614
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009615 bp->dev = dev;
9616 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009617 bp->flags = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009618 bp->pf_num = PCI_FUNC(pdev->devfn);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009619
9620 rc = pci_enable_device(pdev);
9621 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009622 dev_err(&bp->pdev->dev,
9623 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009624 goto err_out;
9625 }
9626
9627 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009628 dev_err(&bp->pdev->dev,
9629 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009630 rc = -ENODEV;
9631 goto err_out_disable;
9632 }
9633
9634 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009635 dev_err(&bp->pdev->dev, "Cannot find second PCI device"
9636 " base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009637 rc = -ENODEV;
9638 goto err_out_disable;
9639 }
9640
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009641 if (atomic_read(&pdev->enable_cnt) == 1) {
9642 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
9643 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009644 dev_err(&bp->pdev->dev,
9645 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009646 goto err_out_disable;
9647 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009648
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009649 pci_set_master(pdev);
9650 pci_save_state(pdev);
9651 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009652
9653 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
9654 if (bp->pm_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009655 dev_err(&bp->pdev->dev,
9656 "Cannot find power management capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009657 rc = -EIO;
9658 goto err_out_release;
9659 }
9660
9661 bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
9662 if (bp->pcie_cap == 0) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009663 dev_err(&bp->pdev->dev,
9664 "Cannot find PCI Express capability, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009665 rc = -EIO;
9666 goto err_out_release;
9667 }
9668
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009669 rc = bnx2x_set_coherency_mask(bp);
9670 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009671 goto err_out_release;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009672
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009673 dev->mem_start = pci_resource_start(pdev, 0);
9674 dev->base_addr = dev->mem_start;
9675 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009676
9677 dev->irq = pdev->irq;
9678
Arjan van de Ven275f1652008-10-20 21:42:39 -07009679 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009680 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009681 dev_err(&bp->pdev->dev,
9682 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009683 rc = -ENOMEM;
9684 goto err_out_release;
9685 }
9686
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009687 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009688 min_t(u64, BNX2X_DB_SIZE(bp),
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009689 pci_resource_len(pdev, 2)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009690 if (!bp->doorbells) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009691 dev_err(&bp->pdev->dev,
9692 "Cannot map doorbell space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009693 rc = -ENOMEM;
9694 goto err_out_unmap;
9695 }
9696
9697 bnx2x_set_power_state(bp, PCI_D0);
9698
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009699 /* clean indirect addresses */
9700 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
9701 PCICFG_VENDOR_ID_OFFSET);
9702 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
9703 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
9704 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
9705 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009706
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009707 /**
9708 * Enable internal target-read (in case we are probed after PF FLR).
9709 * Must be done prior to any BAR read access
9710 */
9711 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
9712
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009713 /* Reset the load counter */
9714 bnx2x_clear_load_cnt(bp);
9715
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009716 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009717
Stephen Hemmingerc64213c2008-11-21 17:36:04 -08009718 dev->netdev_ops = &bnx2x_netdev_ops;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00009719 bnx2x_set_ethtool_ops(dev);
Michał Mirosław66371c42011-04-12 09:38:23 +00009720
9721 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9722 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
9723 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
9724
9725 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
9726 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
9727
9728 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009729 if (bp->flags & USING_DAC_FLAG)
9730 dev->features |= NETIF_F_HIGHDMA;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009731
Mahesh Bandewar538dd2e2011-05-13 15:08:49 +00009732 /* Add Loopback capability to the device */
9733 dev->hw_features |= NETIF_F_LOOPBACK;
9734
Shmulik Ravid98507672011-02-28 12:19:55 -08009735#ifdef BCM_DCBNL
Shmulik Ravid785b9b12010-12-30 06:27:03 +00009736 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
9737#endif
9738
Eilon Greenstein01cd4522009-08-12 08:23:08 +00009739 /* get_port_hwinfo() will set prtad and mmds properly */
9740 bp->mdio.prtad = MDIO_PRTAD_NONE;
9741 bp->mdio.mmds = 0;
9742 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
9743 bp->mdio.dev = dev;
9744 bp->mdio.mdio_read = bnx2x_mdio_read;
9745 bp->mdio.mdio_write = bnx2x_mdio_write;
9746
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009747 return 0;
9748
9749err_out_unmap:
9750 if (bp->regview) {
9751 iounmap(bp->regview);
9752 bp->regview = NULL;
9753 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009754 if (bp->doorbells) {
9755 iounmap(bp->doorbells);
9756 bp->doorbells = NULL;
9757 }
9758
9759err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009760 if (atomic_read(&pdev->enable_cnt) == 1)
9761 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009762
9763err_out_disable:
9764 pci_disable_device(pdev);
9765 pci_set_drvdata(pdev, NULL);
9766
9767err_out:
9768 return rc;
9769}
9770
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009771static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
9772 int *width, int *speed)
Eliezer Tamir25047952008-02-28 11:50:16 -08009773{
9774 u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
9775
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009776 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
9777
9778 /* return value of 1=2.5GHz 2=5GHz */
9779 *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
Eliezer Tamir25047952008-02-28 11:50:16 -08009780}
9781
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009782static int bnx2x_check_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009783{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009784 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009785 struct bnx2x_fw_file_hdr *fw_hdr;
9786 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009787 u32 offset, len, num_ops;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009788 u16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009789 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +00009790 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009791
9792 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
9793 return -EINVAL;
9794
9795 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
9796 sections = (struct bnx2x_fw_file_section *)fw_hdr;
9797
9798 /* Make sure none of the offsets and sizes make us read beyond
9799 * the end of the firmware data */
9800 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
9801 offset = be32_to_cpu(sections[i].offset);
9802 len = be32_to_cpu(sections[i].len);
9803 if (offset + len > firmware->size) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009804 dev_err(&bp->pdev->dev,
9805 "Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009806 return -EINVAL;
9807 }
9808 }
9809
9810 /* Likewise for the init_ops offsets */
9811 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
9812 ops_offsets = (u16 *)(firmware->data + offset);
9813 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
9814
9815 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
9816 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009817 dev_err(&bp->pdev->dev,
9818 "Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009819 return -EINVAL;
9820 }
9821 }
9822
9823 /* Check FW version */
9824 offset = be32_to_cpu(fw_hdr->fw_version.offset);
9825 fw_ver = firmware->data + offset;
9826 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
9827 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
9828 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
9829 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009830 dev_err(&bp->pdev->dev,
9831 "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009832 fw_ver[0], fw_ver[1], fw_ver[2],
9833 fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
9834 BCM_5710_FW_MINOR_VERSION,
9835 BCM_5710_FW_REVISION_VERSION,
9836 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009837 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009838 }
9839
9840 return 0;
9841}
9842
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009843static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009844{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009845 const __be32 *source = (const __be32 *)_source;
9846 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009847 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009848
9849 for (i = 0; i < n/4; i++)
9850 target[i] = be32_to_cpu(source[i]);
9851}
9852
9853/*
9854 Ops array is stored in the following format:
9855 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
9856 */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009857static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009858{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009859 const __be32 *source = (const __be32 *)_source;
9860 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009861 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009862
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009863 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009864 tmp = be32_to_cpu(source[j]);
9865 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009866 target[i].offset = tmp & 0xffffff;
9867 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009868 }
9869}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009870
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009871/**
9872 * IRO array is stored in the following format:
9873 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
9874 */
9875static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
9876{
9877 const __be32 *source = (const __be32 *)_source;
9878 struct iro *target = (struct iro *)_target;
9879 u32 i, j, tmp;
9880
9881 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
9882 target[i].base = be32_to_cpu(source[j]);
9883 j++;
9884 tmp = be32_to_cpu(source[j]);
9885 target[i].m1 = (tmp >> 16) & 0xffff;
9886 target[i].m2 = tmp & 0xffff;
9887 j++;
9888 tmp = be32_to_cpu(source[j]);
9889 target[i].m3 = (tmp >> 16) & 0xffff;
9890 target[i].size = tmp & 0xffff;
9891 j++;
9892 }
9893}
9894
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009895static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009896{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009897 const __be16 *source = (const __be16 *)_source;
9898 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009899 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009900
9901 for (i = 0; i < n/2; i++)
9902 target[i] = be16_to_cpu(source[i]);
9903}
9904
Joe Perches7995c642010-02-17 15:01:52 +00009905#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
9906do { \
9907 u32 len = be32_to_cpu(fw_hdr->arr.len); \
9908 bp->arr = kmalloc(len, GFP_KERNEL); \
9909 if (!bp->arr) { \
9910 pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
9911 goto lbl; \
9912 } \
9913 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
9914 (u8 *)bp->arr, len); \
9915} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009916
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009917int bnx2x_init_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009918{
Ben Hutchings45229b42009-11-07 11:53:39 +00009919 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009920 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +00009921 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009922
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009923 if (CHIP_IS_E1(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00009924 fw_file_name = FW_FILE_NAME_E1;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009925 else if (CHIP_IS_E1H(bp))
Ben Hutchings45229b42009-11-07 11:53:39 +00009926 fw_file_name = FW_FILE_NAME_E1H;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009927 else if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009928 fw_file_name = FW_FILE_NAME_E2;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009929 else {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009930 BNX2X_ERR("Unsupported chip revision\n");
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00009931 return -EINVAL;
9932 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009933
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009934 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009935
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009936 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009937 if (rc) {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009938 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009939 goto request_firmware_exit;
9940 }
9941
9942 rc = bnx2x_check_firmware(bp);
9943 if (rc) {
Dmitry Kravkov6891dd22010-08-03 21:49:40 +00009944 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009945 goto request_firmware_exit;
9946 }
9947
9948 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
9949
9950 /* Initialize the pointers to the init arrays */
9951 /* Blob */
9952 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
9953
9954 /* Opcodes */
9955 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
9956
9957 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009958 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
9959 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009960
9961 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +00009962 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9963 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
9964 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
9965 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
9966 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9967 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
9968 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
9969 be32_to_cpu(fw_hdr->usem_pram_data.offset);
9970 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9971 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
9972 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
9973 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
9974 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
9975 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
9976 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
9977 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009978 /* IRO */
9979 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009980
9981 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00009982
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009983iro_alloc_err:
9984 kfree(bp->init_ops_offsets);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07009985init_offsets_alloc_err:
9986 kfree(bp->init_ops);
9987init_ops_alloc_err:
9988 kfree(bp->init_data);
9989request_firmware_exit:
9990 release_firmware(bp->firmware);
9991
9992 return rc;
9993}
9994
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009995static void bnx2x_release_firmware(struct bnx2x *bp)
9996{
9997 kfree(bp->init_ops_offsets);
9998 kfree(bp->init_ops);
9999 kfree(bp->init_data);
10000 release_firmware(bp->firmware);
10001}
10002
10003
10004static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
10005 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
10006 .init_hw_cmn = bnx2x_init_hw_common,
10007 .init_hw_port = bnx2x_init_hw_port,
10008 .init_hw_func = bnx2x_init_hw_func,
10009
10010 .reset_hw_cmn = bnx2x_reset_common,
10011 .reset_hw_port = bnx2x_reset_port,
10012 .reset_hw_func = bnx2x_reset_func,
10013
10014 .gunzip_init = bnx2x_gunzip_init,
10015 .gunzip_end = bnx2x_gunzip_end,
10016
10017 .init_fw = bnx2x_init_firmware,
10018 .release_fw = bnx2x_release_firmware,
10019};
10020
10021void bnx2x__init_func_obj(struct bnx2x *bp)
10022{
10023 /* Prepare DMAE related driver resources */
10024 bnx2x_setup_dmae(bp);
10025
10026 bnx2x_init_func_obj(bp, &bp->func_obj,
10027 bnx2x_sp(bp, func_rdata),
10028 bnx2x_sp_mapping(bp, func_rdata),
10029 &bnx2x_func_sp_drv);
10030}
10031
10032/* must be called after sriov-enable */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010033static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count)
10034{
10035 int cid_count = L2_FP_COUNT(l2_cid_count);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070010036
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010037#ifdef BCM_CNIC
10038 cid_count += CNIC_CID_MAX;
10039#endif
10040 return roundup(cid_count, QM_CID_ROUND);
10041}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010042
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010043/**
10044 * bnx2x_pci_msix_table_size - get the size of the MSI-X table.
10045 *
10046 * @dev: pci device
10047 *
10048 */
10049static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev)
10050{
10051 int pos;
10052 u16 control;
10053
10054 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
10055 if (!pos)
10056 return 0;
10057
10058 pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
10059 return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
10060}
10061
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010062static int __devinit bnx2x_init_one(struct pci_dev *pdev,
10063 const struct pci_device_id *ent)
10064{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010065 struct net_device *dev = NULL;
10066 struct bnx2x *bp;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000010067 int pcie_width, pcie_speed;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010068 int rc, cid_count;
10069
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010070 switch (ent->driver_data) {
10071 case BCM57710:
10072 case BCM57711:
10073 case BCM57711E:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010074 case BCM57712:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010075 case BCM57712_MF:
10076 case BCM57800:
10077 case BCM57800_MF:
10078 case BCM57810:
10079 case BCM57810_MF:
10080 case BCM57840:
10081 case BCM57840_MF:
10082 /* The size requested for the MSI-X table corresponds to the
10083 * actual amount of avaliable IGU/HC status blocks. It includes
10084 * the default SB vector but we want cid_count to contain the
10085 * amount of only non-default SBs, that's what '-1' stands for.
10086 */
10087 cid_count = bnx2x_pci_msix_table_size(pdev) - 1;
10088
10089 /* do not allow initial cid_count grow above 16
10090 * since Special CIDs starts from this number
10091 * use old FP_SB_MAX_E1x define for this matter
10092 */
10093 cid_count = min_t(int, FP_SB_MAX_E1x, cid_count);
10094
10095 WARN_ON(!cid_count);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010096 break;
10097
10098 default:
10099 pr_err("Unknown board_type (%ld), aborting\n",
10100 ent->driver_data);
Vasiliy Kulikov870634b2010-11-14 10:08:34 +000010101 return -ENODEV;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010102 }
10103
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010104 cid_count += FCOE_CONTEXT_USE;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010105
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010106 /* dev zeroed in init_etherdev */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010107 dev = alloc_etherdev_mq(sizeof(*bp), cid_count);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010108 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010109 dev_err(&pdev->dev, "Cannot allocate net device\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010110 return -ENOMEM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010111 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010112
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010113 /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring,
10114 * so update a cid_count after a netdev allocation.
10115 */
10116 cid_count += CNIC_CONTEXT_USE;
10117
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010118 bp = netdev_priv(dev);
Joe Perches7995c642010-02-17 15:01:52 +000010119 bp->msg_enable = debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010120
Eilon Greensteindf4770de2009-08-12 08:23:28 +000010121 pci_set_drvdata(pdev, dev);
10122
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010123 bp->l2_cid_count = cid_count;
10124
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010125 rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010126 if (rc < 0) {
10127 free_netdev(dev);
10128 return rc;
10129 }
10130
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010131 BNX2X_DEV_INFO("cid_count=%d\n", cid_count);
10132
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010133 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000010134 if (rc)
10135 goto init_one_exit;
10136
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010137 /* calc qm_cid_count */
10138 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count);
10139
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010140#ifdef BCM_CNIC
10141 /* disable FCOE L2 queue for E1x*/
10142 if (CHIP_IS_E1x(bp))
10143 bp->flags |= NO_FCOE_FLAG;
10144
10145#endif
10146
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010147 /* Configure interrupt mode: try to enable MSI-X/MSI if
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010148 * needed, set bp->num_queues appropriately.
10149 */
10150 bnx2x_set_int_mode(bp);
10151
10152 /* Add all NAPI objects */
10153 bnx2x_add_all_napi(bp);
10154
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080010155 rc = register_netdev(dev);
10156 if (rc) {
10157 dev_err(&pdev->dev, "Cannot register net device\n");
10158 goto init_one_exit;
10159 }
10160
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010161#ifdef BCM_CNIC
10162 if (!NO_FCOE(bp)) {
10163 /* Add storage MAC address */
10164 rtnl_lock();
10165 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10166 rtnl_unlock();
10167 }
10168#endif
10169
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000010170 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010171
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010172 netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
10173 " IRQ %d, ", board_info[ent->driver_data].name,
10174 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010175 pcie_width,
10176 ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
10177 (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
10178 "5GHz (Gen2)" : "2.5GHz",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010179 dev->base_addr, bp->pdev->irq);
10180 pr_cont("node addr %pM\n", dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000010181
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010182 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010183
10184init_one_exit:
10185 if (bp->regview)
10186 iounmap(bp->regview);
10187
10188 if (bp->doorbells)
10189 iounmap(bp->doorbells);
10190
10191 free_netdev(dev);
10192
10193 if (atomic_read(&pdev->enable_cnt) == 1)
10194 pci_release_regions(pdev);
10195
10196 pci_disable_device(pdev);
10197 pci_set_drvdata(pdev, NULL);
10198
10199 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010200}
10201
10202static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10203{
10204 struct net_device *dev = pci_get_drvdata(pdev);
Eliezer Tamir228241e2008-02-28 11:56:57 -080010205 struct bnx2x *bp;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010206
Eliezer Tamir228241e2008-02-28 11:56:57 -080010207 if (!dev) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010208 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
Eliezer Tamir228241e2008-02-28 11:56:57 -080010209 return;
10210 }
Eliezer Tamir228241e2008-02-28 11:56:57 -080010211 bp = netdev_priv(dev);
10212
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010213#ifdef BCM_CNIC
10214 /* Delete storage MAC address */
10215 if (!NO_FCOE(bp)) {
10216 rtnl_lock();
10217 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
10218 rtnl_unlock();
10219 }
10220#endif
10221
Shmulik Ravid98507672011-02-28 12:19:55 -080010222#ifdef BCM_DCBNL
10223 /* Delete app tlvs from dcbnl */
10224 bnx2x_dcbnl_update_applist(bp, true);
10225#endif
10226
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010227 unregister_netdev(dev);
10228
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010229 /* Delete all NAPI objects */
10230 bnx2x_del_all_napi(bp);
10231
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000010232 /* Power on: we can't let PCI layer write to us while we are in D3 */
10233 bnx2x_set_power_state(bp, PCI_D0);
10234
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010235 /* Disable MSI/MSI-X */
10236 bnx2x_disable_msi(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010237
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000010238 /* Power off */
10239 bnx2x_set_power_state(bp, PCI_D3hot);
10240
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010241 /* Make sure RESET task is not scheduled before continuing */
10242 cancel_delayed_work_sync(&bp->reset_task);
10243
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010244 if (bp->regview)
10245 iounmap(bp->regview);
10246
10247 if (bp->doorbells)
10248 iounmap(bp->doorbells);
10249
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010250 bnx2x_free_mem_bp(bp);
10251
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010252 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010253
10254 if (atomic_read(&pdev->enable_cnt) == 1)
10255 pci_release_regions(pdev);
10256
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010257 pci_disable_device(pdev);
10258 pci_set_drvdata(pdev, NULL);
10259}
10260
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010261static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
10262{
10263 int i;
10264
10265 bp->state = BNX2X_STATE_ERROR;
10266
10267 bp->rx_mode = BNX2X_RX_MODE_NONE;
10268
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010269#ifdef BCM_CNIC
10270 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
10271#endif
10272 /* Stop Tx */
10273 bnx2x_tx_disable(bp);
10274
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010275 bnx2x_netif_stop(bp, 0);
10276
10277 del_timer_sync(&bp->timer);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010278
10279 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010280
10281 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010282 bnx2x_free_irq(bp);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010283
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010284 /* Free SKBs, SGEs, TPA pool and driver internals */
10285 bnx2x_free_skbs(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010286
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010287 for_each_rx_queue(bp, i)
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010288 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000010289
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010290 bnx2x_free_mem(bp);
10291
10292 bp->state = BNX2X_STATE_CLOSED;
10293
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010294 netif_carrier_off(bp->dev);
10295
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010296 return 0;
10297}
10298
10299static void bnx2x_eeh_recover(struct bnx2x *bp)
10300{
10301 u32 val;
10302
10303 mutex_init(&bp->port.phy_mutex);
10304
10305 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
10306 bp->link_params.shmem_base = bp->common.shmem_base;
10307 BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
10308
10309 if (!bp->common.shmem_base ||
10310 (bp->common.shmem_base < 0xA0000) ||
10311 (bp->common.shmem_base >= 0xC0000)) {
10312 BNX2X_DEV_INFO("MCP not active\n");
10313 bp->flags |= NO_MCP_FLAG;
10314 return;
10315 }
10316
10317 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
10318 if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10319 != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
10320 BNX2X_ERR("BAD MCP validity signature\n");
10321
10322 if (!BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010323 bp->fw_seq =
10324 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
10325 DRV_MSG_SEQ_NUMBER_MASK);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010326 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
10327 }
10328}
10329
Wendy Xiong493adb12008-06-23 20:36:22 -070010330/**
10331 * bnx2x_io_error_detected - called when PCI error is detected
10332 * @pdev: Pointer to PCI device
10333 * @state: The current pci connection state
10334 *
10335 * This function is called after a PCI bus error affecting
10336 * this device has been detected.
10337 */
10338static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
10339 pci_channel_state_t state)
10340{
10341 struct net_device *dev = pci_get_drvdata(pdev);
10342 struct bnx2x *bp = netdev_priv(dev);
10343
10344 rtnl_lock();
10345
10346 netif_device_detach(dev);
10347
Dean Nelson07ce50e2009-07-31 09:13:25 +000010348 if (state == pci_channel_io_perm_failure) {
10349 rtnl_unlock();
10350 return PCI_ERS_RESULT_DISCONNECT;
10351 }
10352
Wendy Xiong493adb12008-06-23 20:36:22 -070010353 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010354 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070010355
10356 pci_disable_device(pdev);
10357
10358 rtnl_unlock();
10359
10360 /* Request a slot reset */
10361 return PCI_ERS_RESULT_NEED_RESET;
10362}
10363
10364/**
10365 * bnx2x_io_slot_reset - called after the PCI bus has been reset
10366 * @pdev: Pointer to PCI device
10367 *
10368 * Restart the card from scratch, as if from a cold-boot.
10369 */
10370static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
10371{
10372 struct net_device *dev = pci_get_drvdata(pdev);
10373 struct bnx2x *bp = netdev_priv(dev);
10374
10375 rtnl_lock();
10376
10377 if (pci_enable_device(pdev)) {
10378 dev_err(&pdev->dev,
10379 "Cannot re-enable PCI device after reset\n");
10380 rtnl_unlock();
10381 return PCI_ERS_RESULT_DISCONNECT;
10382 }
10383
10384 pci_set_master(pdev);
10385 pci_restore_state(pdev);
10386
10387 if (netif_running(dev))
10388 bnx2x_set_power_state(bp, PCI_D0);
10389
10390 rtnl_unlock();
10391
10392 return PCI_ERS_RESULT_RECOVERED;
10393}
10394
10395/**
10396 * bnx2x_io_resume - called when traffic can start flowing again
10397 * @pdev: Pointer to PCI device
10398 *
10399 * This callback is called when the error recovery driver tells us that
10400 * its OK to resume normal operation.
10401 */
10402static void bnx2x_io_resume(struct pci_dev *pdev)
10403{
10404 struct net_device *dev = pci_get_drvdata(pdev);
10405 struct bnx2x *bp = netdev_priv(dev);
10406
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010407 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010408 netdev_err(bp->dev, "Handling parity error recovery. "
10409 "Try again later\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000010410 return;
10411 }
10412
Wendy Xiong493adb12008-06-23 20:36:22 -070010413 rtnl_lock();
10414
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010415 bnx2x_eeh_recover(bp);
10416
Wendy Xiong493adb12008-06-23 20:36:22 -070010417 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070010418 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070010419
10420 netif_device_attach(dev);
10421
10422 rtnl_unlock();
10423}
10424
10425static struct pci_error_handlers bnx2x_err_handler = {
10426 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000010427 .slot_reset = bnx2x_io_slot_reset,
10428 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070010429};
10430
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010431static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070010432 .name = DRV_MODULE_NAME,
10433 .id_table = bnx2x_pci_tbl,
10434 .probe = bnx2x_init_one,
10435 .remove = __devexit_p(bnx2x_remove_one),
10436 .suspend = bnx2x_suspend,
10437 .resume = bnx2x_resume,
10438 .err_handler = &bnx2x_err_handler,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010439};
10440
10441static int __init bnx2x_init(void)
10442{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010443 int ret;
10444
Joe Perches7995c642010-02-17 15:01:52 +000010445 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +000010446
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010447 bnx2x_wq = create_singlethread_workqueue("bnx2x");
10448 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +000010449 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010450 return -ENOMEM;
10451 }
10452
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010453 ret = pci_register_driver(&bnx2x_pci_driver);
10454 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +000010455 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000010456 destroy_workqueue(bnx2x_wq);
10457 }
10458 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010459}
10460
10461static void __exit bnx2x_cleanup(void)
10462{
10463 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080010464
10465 destroy_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010466}
10467
10468module_init(bnx2x_init);
10469module_exit(bnx2x_cleanup);
10470
Michael Chan993ac7b2009-10-10 13:46:56 +000010471#ifdef BCM_CNIC
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010472/**
10473 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
10474 *
10475 * @bp: driver handle
10476 * @set: set or clear the CAM entry
10477 *
10478 * This function will wait until the ramdord completion returns.
10479 * Return 0 if success, -ENODEV if ramrod doesn't return.
10480 */
10481static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
10482{
10483 unsigned long ramrod_flags = 0;
10484
10485 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
10486 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
10487 &bp->iscsi_l2_mac_obj, true,
10488 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
10489}
Michael Chan993ac7b2009-10-10 13:46:56 +000010490
10491/* count denotes the number of new completions we have seen */
10492static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
10493{
10494 struct eth_spe *spe;
10495
10496#ifdef BNX2X_STOP_ON_ERROR
10497 if (unlikely(bp->panic))
10498 return;
10499#endif
10500
10501 spin_lock_bh(&bp->spq_lock);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010502 BUG_ON(bp->cnic_spq_pending < count);
Michael Chan993ac7b2009-10-10 13:46:56 +000010503 bp->cnic_spq_pending -= count;
10504
Michael Chan993ac7b2009-10-10 13:46:56 +000010505
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010506 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
10507 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
10508 & SPE_HDR_CONN_TYPE) >>
10509 SPE_HDR_CONN_TYPE_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010510 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
10511 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010512
10513 /* Set validation for iSCSI L2 client before sending SETUP
10514 * ramrod
10515 */
10516 if (type == ETH_CONNECTION_TYPE) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010517 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010518 bnx2x_set_ctx_validation(bp, &bp->context.
10519 vcxt[BNX2X_ISCSI_ETH_CID].eth,
10520 BNX2X_ISCSI_ETH_CID);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010521 }
10522
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010523 /*
10524 * There may be not more than 8 L2, not more than 8 L5 SPEs
10525 * and in the air. We also check that number of outstanding
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010526 * COMMON ramrods is not more than the EQ and SPQ can
10527 * accommodate.
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010528 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010529 if (type == ETH_CONNECTION_TYPE) {
10530 if (!atomic_read(&bp->cq_spq_left))
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010531 break;
10532 else
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010533 atomic_dec(&bp->cq_spq_left);
10534 } else if (type == NONE_CONNECTION_TYPE) {
10535 if (!atomic_read(&bp->eq_spq_left))
10536 break;
10537 else
10538 atomic_dec(&bp->eq_spq_left);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010539 } else if ((type == ISCSI_CONNECTION_TYPE) ||
10540 (type == FCOE_CONNECTION_TYPE)) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010541 if (bp->cnic_spq_pending >=
10542 bp->cnic_eth_dev.max_kwqe_pending)
10543 break;
10544 else
10545 bp->cnic_spq_pending++;
10546 } else {
10547 BNX2X_ERR("Unknown SPE type: %d\n", type);
10548 bnx2x_panic();
Michael Chan993ac7b2009-10-10 13:46:56 +000010549 break;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010550 }
Michael Chan993ac7b2009-10-10 13:46:56 +000010551
10552 spe = bnx2x_sp_get_next(bp);
10553 *spe = *bp->cnic_kwq_cons;
10554
Michael Chan993ac7b2009-10-10 13:46:56 +000010555 DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
10556 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
10557
10558 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
10559 bp->cnic_kwq_cons = bp->cnic_kwq;
10560 else
10561 bp->cnic_kwq_cons++;
10562 }
10563 bnx2x_sp_prod_update(bp);
10564 spin_unlock_bh(&bp->spq_lock);
10565}
10566
10567static int bnx2x_cnic_sp_queue(struct net_device *dev,
10568 struct kwqe_16 *kwqes[], u32 count)
10569{
10570 struct bnx2x *bp = netdev_priv(dev);
10571 int i;
10572
10573#ifdef BNX2X_STOP_ON_ERROR
10574 if (unlikely(bp->panic))
10575 return -EIO;
10576#endif
10577
10578 spin_lock_bh(&bp->spq_lock);
10579
10580 for (i = 0; i < count; i++) {
10581 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
10582
10583 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
10584 break;
10585
10586 *bp->cnic_kwq_prod = *spe;
10587
10588 bp->cnic_kwq_pending++;
10589
10590 DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
10591 spe->hdr.conn_and_cmd_data, spe->hdr.type,
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010592 spe->data.update_data_addr.hi,
10593 spe->data.update_data_addr.lo,
Michael Chan993ac7b2009-10-10 13:46:56 +000010594 bp->cnic_kwq_pending);
10595
10596 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
10597 bp->cnic_kwq_prod = bp->cnic_kwq;
10598 else
10599 bp->cnic_kwq_prod++;
10600 }
10601
10602 spin_unlock_bh(&bp->spq_lock);
10603
10604 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
10605 bnx2x_cnic_sp_post(bp, 0);
10606
10607 return i;
10608}
10609
10610static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10611{
10612 struct cnic_ops *c_ops;
10613 int rc = 0;
10614
10615 mutex_lock(&bp->cnic_mutex);
Eric Dumazet13707f92011-01-26 19:28:23 +000010616 c_ops = rcu_dereference_protected(bp->cnic_ops,
10617 lockdep_is_held(&bp->cnic_mutex));
Michael Chan993ac7b2009-10-10 13:46:56 +000010618 if (c_ops)
10619 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10620 mutex_unlock(&bp->cnic_mutex);
10621
10622 return rc;
10623}
10624
10625static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
10626{
10627 struct cnic_ops *c_ops;
10628 int rc = 0;
10629
10630 rcu_read_lock();
10631 c_ops = rcu_dereference(bp->cnic_ops);
10632 if (c_ops)
10633 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
10634 rcu_read_unlock();
10635
10636 return rc;
10637}
10638
10639/*
10640 * for commands that have no data
10641 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000010642int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +000010643{
10644 struct cnic_ctl_info ctl = {0};
10645
10646 ctl.cmd = cmd;
10647
10648 return bnx2x_cnic_ctl_send(bp, &ctl);
10649}
10650
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010651static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
Michael Chan993ac7b2009-10-10 13:46:56 +000010652{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010653 struct cnic_ctl_info ctl = {0};
Michael Chan993ac7b2009-10-10 13:46:56 +000010654
10655 /* first we tell CNIC and only then we count this as a completion */
10656 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
10657 ctl.data.comp.cid = cid;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010658 ctl.data.comp.error = err;
Michael Chan993ac7b2009-10-10 13:46:56 +000010659
10660 bnx2x_cnic_ctl_send_bh(bp, &ctl);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010661 bnx2x_cnic_sp_post(bp, 0);
Michael Chan993ac7b2009-10-10 13:46:56 +000010662}
10663
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010664
10665/* Called with netif_addr_lock_bh() taken.
10666 * Sets an rx_mode config for an iSCSI ETH client.
10667 * Doesn't block.
10668 * Completion should be checked outside.
10669 */
10670static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
10671{
10672 unsigned long accept_flags = 0, ramrod_flags = 0;
10673 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
10674 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
10675
10676 if (start) {
10677 /* Start accepting on iSCSI L2 ring. Accept all multicasts
10678 * because it's the only way for UIO Queue to accept
10679 * multicasts (in non-promiscuous mode only one Queue per
10680 * function will receive multicast packets (leading in our
10681 * case).
10682 */
10683 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
10684 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
10685 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
10686 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
10687
10688 /* Clear STOP_PENDING bit if START is requested */
10689 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
10690
10691 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
10692 } else
10693 /* Clear START_PENDING bit if STOP is requested */
10694 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
10695
10696 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
10697 set_bit(sched_state, &bp->sp_state);
10698 else {
10699 __set_bit(RAMROD_RX, &ramrod_flags);
10700 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
10701 ramrod_flags);
10702 }
10703}
10704
10705
Michael Chan993ac7b2009-10-10 13:46:56 +000010706static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
10707{
10708 struct bnx2x *bp = netdev_priv(dev);
10709 int rc = 0;
10710
10711 switch (ctl->cmd) {
10712 case DRV_CTL_CTXTBL_WR_CMD: {
10713 u32 index = ctl->data.io.offset;
10714 dma_addr_t addr = ctl->data.io.dma_addr;
10715
10716 bnx2x_ilt_wr(bp, index, addr);
10717 break;
10718 }
10719
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010720 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
10721 int count = ctl->data.credit.credit_count;
Michael Chan993ac7b2009-10-10 13:46:56 +000010722
10723 bnx2x_cnic_sp_post(bp, count);
10724 break;
10725 }
10726
10727 /* rtnl_lock is held. */
10728 case DRV_CTL_START_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010729 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10730 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000010731
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010732 /* Configure the iSCSI classification object */
10733 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
10734 cp->iscsi_l2_client_id,
10735 cp->iscsi_l2_cid, BP_FUNC(bp),
10736 bnx2x_sp(bp, mac_rdata),
10737 bnx2x_sp_mapping(bp, mac_rdata),
10738 BNX2X_FILTER_MAC_PENDING,
10739 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
10740 &bp->macs_pool);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010741
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010742 /* Set iSCSI MAC address */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010743 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
10744 if (rc)
10745 break;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010746
10747 mmiowb();
10748 barrier();
10749
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010750 /* Start accepting on iSCSI L2 ring */
10751
10752 netif_addr_lock_bh(dev);
10753 bnx2x_set_iscsi_eth_rx_mode(bp, true);
10754 netif_addr_unlock_bh(dev);
10755
10756 /* bits to wait on */
10757 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10758 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
10759
10760 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10761 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010762
Michael Chan993ac7b2009-10-10 13:46:56 +000010763 break;
10764 }
10765
10766 /* rtnl_lock is held. */
10767 case DRV_CTL_STOP_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010768 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000010769
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010770 /* Stop accepting on iSCSI L2 ring */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010771 netif_addr_lock_bh(dev);
10772 bnx2x_set_iscsi_eth_rx_mode(bp, false);
10773 netif_addr_unlock_bh(dev);
10774
10775 /* bits to wait on */
10776 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
10777 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
10778
10779 if (!bnx2x_wait_sp_comp(bp, sp_bits))
10780 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010781
10782 mmiowb();
10783 barrier();
10784
10785 /* Unset iSCSI L2 MAC */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010786 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
10787 BNX2X_ISCSI_ETH_MAC, true);
Michael Chan993ac7b2009-10-10 13:46:56 +000010788 break;
10789 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010790 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
10791 int count = ctl->data.credit.credit_count;
10792
10793 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080010794 atomic_add(count, &bp->cq_spq_left);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010795 smp_mb__after_atomic_inc();
10796 break;
10797 }
Michael Chan993ac7b2009-10-10 13:46:56 +000010798
10799 default:
10800 BNX2X_ERR("unknown command %x\n", ctl->cmd);
10801 rc = -EINVAL;
10802 }
10803
10804 return rc;
10805}
10806
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000010807void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +000010808{
10809 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10810
10811 if (bp->flags & USING_MSIX_FLAG) {
10812 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
10813 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
10814 cp->irq_arr[0].vector = bp->msix_table[1].vector;
10815 } else {
10816 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
10817 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
10818 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010819 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010820 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
10821 else
10822 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
10823
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010824 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
10825 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000010826 cp->irq_arr[1].status_blk = bp->def_status_blk;
10827 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010828 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
Michael Chan993ac7b2009-10-10 13:46:56 +000010829
10830 cp->num_irq = 2;
10831}
10832
10833static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
10834 void *data)
10835{
10836 struct bnx2x *bp = netdev_priv(dev);
10837 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10838
10839 if (ops == NULL)
10840 return -EINVAL;
10841
Michael Chan993ac7b2009-10-10 13:46:56 +000010842 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
10843 if (!bp->cnic_kwq)
10844 return -ENOMEM;
10845
10846 bp->cnic_kwq_cons = bp->cnic_kwq;
10847 bp->cnic_kwq_prod = bp->cnic_kwq;
10848 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
10849
10850 bp->cnic_spq_pending = 0;
10851 bp->cnic_kwq_pending = 0;
10852
10853 bp->cnic_data = data;
10854
10855 cp->num_irq = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010856 cp->drv_state |= CNIC_DRV_STATE_REGD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010857 cp->iro_arr = bp->iro_arr;
Michael Chan993ac7b2009-10-10 13:46:56 +000010858
Michael Chan993ac7b2009-10-10 13:46:56 +000010859 bnx2x_setup_cnic_irq_info(bp);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010860
Michael Chan993ac7b2009-10-10 13:46:56 +000010861 rcu_assign_pointer(bp->cnic_ops, ops);
10862
10863 return 0;
10864}
10865
10866static int bnx2x_unregister_cnic(struct net_device *dev)
10867{
10868 struct bnx2x *bp = netdev_priv(dev);
10869 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10870
10871 mutex_lock(&bp->cnic_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +000010872 cp->drv_state = 0;
10873 rcu_assign_pointer(bp->cnic_ops, NULL);
10874 mutex_unlock(&bp->cnic_mutex);
10875 synchronize_rcu();
10876 kfree(bp->cnic_kwq);
10877 bp->cnic_kwq = NULL;
10878
10879 return 0;
10880}
10881
10882struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
10883{
10884 struct bnx2x *bp = netdev_priv(dev);
10885 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
10886
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010887 /* If both iSCSI and FCoE are disabled - return NULL in
10888 * order to indicate CNIC that it should not try to work
10889 * with this device.
10890 */
10891 if (NO_ISCSI(bp) && NO_FCOE(bp))
10892 return NULL;
10893
Michael Chan993ac7b2009-10-10 13:46:56 +000010894 cp->drv_owner = THIS_MODULE;
10895 cp->chip_id = CHIP_ID(bp);
10896 cp->pdev = bp->pdev;
10897 cp->io_base = bp->regview;
10898 cp->io_base2 = bp->doorbells;
10899 cp->max_kwqe_pending = 8;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010900 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010901 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
10902 bnx2x_cid_ilt_lines(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000010903 cp->ctx_tbl_len = CNIC_ILT_LINES;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010904 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
Michael Chan993ac7b2009-10-10 13:46:56 +000010905 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
10906 cp->drv_ctl = bnx2x_drv_ctl;
10907 cp->drv_register_cnic = bnx2x_register_cnic;
10908 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000010909 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010910 cp->iscsi_l2_client_id =
10911 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010912 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
Michael Chan993ac7b2009-10-10 13:46:56 +000010913
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010914 if (NO_ISCSI_OOO(bp))
10915 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
10916
10917 if (NO_ISCSI(bp))
10918 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
10919
10920 if (NO_FCOE(bp))
10921 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
10922
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000010923 DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
10924 "starting cid %d\n",
10925 cp->ctx_blk_size,
10926 cp->ctx_tbl_offset,
10927 cp->ctx_tbl_len,
10928 cp->starting_cid);
Michael Chan993ac7b2009-10-10 13:46:56 +000010929 return cp;
10930}
10931EXPORT_SYMBOL(bnx2x_cnic_probe);
10932
10933#endif /* BCM_CNIC */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070010934