blob: 7f4ec80f0cb3febb81d7eaafc604e1f0fbfbc330 [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 *
Yuval Mintz247fa822013-01-14 05:11:50 +00003 * Copyright (c) 2007-2013 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
Joe Perchesf1deab52011-08-14 12:16:21 +000018#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020020#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/kernel.h>
23#include <linux/device.h> /* for dev_info() */
24#include <linux/timer.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020028#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/skbuff.h>
34#include <linux/dma-mapping.h>
35#include <linux/bitops.h>
36#include <linux/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080042#include <linux/if_vlan.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020043#include <net/ip.h>
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030044#include <net/ipv6.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020045#include <net/tcp.h>
46#include <net/checksum.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070047#include <net/ip6_checksum.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020048#include <linux/workqueue.h>
49#include <linux/crc32.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070050#include <linux/crc32c.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020051#include <linux/prefetch.h>
52#include <linux/zlib.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020053#include <linux/io.h>
Yuval Mintz452427b2012-03-26 20:47:07 +000054#include <linux/semaphore.h>
Ben Hutchings45229b42009-11-07 11:53:39 +000055#include <linux/stringify.h>
David S. Miller7ab24bf2011-06-29 05:48:41 -070056#include <linux/vmalloc.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020057
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020058#include "bnx2x.h"
59#include "bnx2x_init.h"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070060#include "bnx2x_init_ops.h"
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000061#include "bnx2x_cmn.h"
Ariel Elior1ab44342013-01-01 05:22:23 +000062#include "bnx2x_vfpf.h"
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000063#include "bnx2x_dcb.h"
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000064#include "bnx2x_sp.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020065
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070066#include <linux/firmware.h>
67#include "bnx2x_fw_file_hdr.h"
68/* FW files */
Ben Hutchings45229b42009-11-07 11:53:39 +000069#define FW_FILE_VERSION \
70 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
71 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
72 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
73 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
Dmitry Kravkov560131f2010-10-06 03:18:47 +000074#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
75#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000076#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070077
Eilon Greenstein34f80b02008-06-23 20:33:01 -070078/* Time in jiffies before concluding the transmitter is hung */
79#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020080
Bill Pemberton0329aba2012-12-03 09:24:24 -050081static char version[] =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030082 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020083 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
84
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070085MODULE_AUTHOR("Eliezer Tamir");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000086MODULE_DESCRIPTION("Broadcom NetXtreme II "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030087 "BCM57710/57711/57711E/"
88 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
89 "57840/57840_MF Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020090MODULE_LICENSE("GPL");
91MODULE_VERSION(DRV_MODULE_VERSION);
Ben Hutchings45229b42009-11-07 11:53:39 +000092MODULE_FIRMWARE(FW_FILE_NAME_E1);
93MODULE_FIRMWARE(FW_FILE_NAME_E1H);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000094MODULE_FIRMWARE(FW_FILE_NAME_E2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020095
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000096int num_queues;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +000097module_param(num_queues, int, 0);
Dmitry Kravkov96305232012-04-03 18:41:30 +000098MODULE_PARM_DESC(num_queues,
99 " Set number of queues (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
Merav Sicron0e8d2ec2012-06-19 07:48:30 +0000105int int_mode;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000106module_param(int_mode, int, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300107MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000108 "(1 INT#x; 2 MSI)");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000109
Eilon Greensteina18f5122009-08-12 08:23:26 +0000110static int dropless_fc;
111module_param(dropless_fc, int, 0);
112MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
113
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000114static int mrrs = -1;
115module_param(mrrs, int, 0);
116MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
117
Eilon Greenstein9898f862009-02-12 08:38:27 +0000118static int debug;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200119module_param(debug, int, 0);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000120MODULE_PARM_DESC(debug, " Default debug msglevel");
121
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300122struct workqueue_struct *bnx2x_wq;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000123
Barak Witkowski1ef1d452013-01-10 04:53:40 +0000124struct bnx2x_mac_vals {
125 u32 xmac_addr;
126 u32 xmac_val;
127 u32 emac_addr;
128 u32 emac_val;
129 u32 umac_addr;
130 u32 umac_val;
131 u32 bmac_addr;
132 u32 bmac_val[2];
133};
134
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200135enum bnx2x_board_type {
136 BCM57710 = 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300137 BCM57711,
138 BCM57711E,
139 BCM57712,
140 BCM57712_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000141 BCM57712_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300142 BCM57800,
143 BCM57800_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000144 BCM57800_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300145 BCM57810,
146 BCM57810_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000147 BCM57810_VF,
Yuval Mintzc3def942012-07-23 10:25:43 +0300148 BCM57840_4_10,
149 BCM57840_2_20,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000150 BCM57840_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000151 BCM57840_VF,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000152 BCM57811,
Ariel Elior1ab44342013-01-01 05:22:23 +0000153 BCM57811_MF,
154 BCM57840_O,
155 BCM57840_MFO,
156 BCM57811_VF
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200157};
158
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700159/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800160static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200161 char *name;
Bill Pemberton0329aba2012-12-03 09:24:24 -0500162} board_info[] = {
Ariel Elior1ab44342013-01-01 05:22:23 +0000163 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
164 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
165 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
166 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
167 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
168 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
169 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
170 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
171 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
172 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
173 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
174 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
175 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
176 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
177 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
178 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
179 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
180 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
181 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
182 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
183 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200184};
185
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300186#ifndef PCI_DEVICE_ID_NX2_57710
187#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
188#endif
189#ifndef PCI_DEVICE_ID_NX2_57711
190#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
191#endif
192#ifndef PCI_DEVICE_ID_NX2_57711E
193#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
194#endif
195#ifndef PCI_DEVICE_ID_NX2_57712
196#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
197#endif
198#ifndef PCI_DEVICE_ID_NX2_57712_MF
199#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
200#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000201#ifndef PCI_DEVICE_ID_NX2_57712_VF
202#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
203#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300204#ifndef PCI_DEVICE_ID_NX2_57800
205#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
206#endif
207#ifndef PCI_DEVICE_ID_NX2_57800_MF
208#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
209#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000210#ifndef PCI_DEVICE_ID_NX2_57800_VF
211#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
212#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300213#ifndef PCI_DEVICE_ID_NX2_57810
214#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
215#endif
216#ifndef PCI_DEVICE_ID_NX2_57810_MF
217#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
218#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300219#ifndef PCI_DEVICE_ID_NX2_57840_O
220#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
221#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000222#ifndef PCI_DEVICE_ID_NX2_57810_VF
223#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
224#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300225#ifndef PCI_DEVICE_ID_NX2_57840_4_10
226#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
227#endif
228#ifndef PCI_DEVICE_ID_NX2_57840_2_20
229#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
230#endif
231#ifndef PCI_DEVICE_ID_NX2_57840_MFO
232#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300233#endif
234#ifndef PCI_DEVICE_ID_NX2_57840_MF
235#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
236#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000237#ifndef PCI_DEVICE_ID_NX2_57840_VF
238#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
239#endif
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000240#ifndef PCI_DEVICE_ID_NX2_57811
241#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
242#endif
243#ifndef PCI_DEVICE_ID_NX2_57811_MF
244#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
245#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000246#ifndef PCI_DEVICE_ID_NX2_57811_VF
247#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
248#endif
249
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000250static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000251 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
252 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
Ariel Elior8395be52013-01-01 05:22:44 +0000265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200272 { 0 }
273};
274
275MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
276
Yuval Mintz452427b2012-03-26 20:47:07 +0000277/* Global resources for unloading a previously loaded device */
278#define BNX2X_PREV_WAIT_NEEDED 1
279static DEFINE_SEMAPHORE(bnx2x_prev_sem);
280static LIST_HEAD(bnx2x_prev_list);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200281/****************************************************************************
282* General service functions
283****************************************************************************/
284
Eric Dumazet1191cb82012-04-27 21:39:21 +0000285static void __storm_memset_dma_mapping(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300286 u32 addr, dma_addr_t mapping)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000287{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300288 REG_WR(bp, addr, U64_LO(mapping));
289 REG_WR(bp, addr + 4, U64_HI(mapping));
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000290}
291
Eric Dumazet1191cb82012-04-27 21:39:21 +0000292static void storm_memset_spq_addr(struct bnx2x *bp,
293 dma_addr_t mapping, u16 abs_fid)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300294{
295 u32 addr = XSEM_REG_FAST_MEMORY +
296 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
297
298 __storm_memset_dma_mapping(bp, addr, mapping);
299}
300
Eric Dumazet1191cb82012-04-27 21:39:21 +0000301static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
302 u16 pf_id)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300303{
304 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
305 pf_id);
306 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
307 pf_id);
308 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
309 pf_id);
310 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
311 pf_id);
312}
313
Eric Dumazet1191cb82012-04-27 21:39:21 +0000314static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
315 u8 enable)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300316{
317 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
318 enable);
319 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
320 enable);
321 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
322 enable);
323 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
324 enable);
325}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000326
Eric Dumazet1191cb82012-04-27 21:39:21 +0000327static void storm_memset_eq_data(struct bnx2x *bp,
328 struct event_ring_data *eq_data,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000329 u16 pfid)
330{
331 size_t size = sizeof(struct event_ring_data);
332
333 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
334
335 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
336}
337
Eric Dumazet1191cb82012-04-27 21:39:21 +0000338static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
339 u16 pfid)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000340{
341 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
342 REG_WR16(bp, addr, eq_prod);
343}
344
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200345/* used only at init
346 * locking is done by mcp
347 */
stephen hemminger8d962862010-10-21 07:50:56 +0000348static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200349{
350 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
351 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
352 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
353 PCICFG_VENDOR_ID_OFFSET);
354}
355
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200356static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
357{
358 u32 val;
359
360 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
361 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
362 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
363 PCICFG_VENDOR_ID_OFFSET);
364
365 return val;
366}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200367
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000368#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
369#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
370#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
371#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
372#define DMAE_DP_DST_NONE "dst_addr [none]"
373
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000374static void bnx2x_dp_dmae(struct bnx2x *bp,
375 struct dmae_command *dmae, int msglvl)
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000376{
377 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000378 int i;
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000379
380 switch (dmae->opcode & DMAE_COMMAND_DST) {
381 case DMAE_CMD_DST_PCI:
382 if (src_type == DMAE_CMD_SRC_PCI)
383 DP(msglvl, "DMAE: opcode 0x%08x\n"
384 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
385 "comp_addr [%x:%08x], comp_val 0x%08x\n",
386 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
387 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
388 dmae->comp_addr_hi, dmae->comp_addr_lo,
389 dmae->comp_val);
390 else
391 DP(msglvl, "DMAE: opcode 0x%08x\n"
392 "src [%08x], len [%d*4], dst [%x:%08x]\n"
393 "comp_addr [%x:%08x], comp_val 0x%08x\n",
394 dmae->opcode, dmae->src_addr_lo >> 2,
395 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
396 dmae->comp_addr_hi, dmae->comp_addr_lo,
397 dmae->comp_val);
398 break;
399 case DMAE_CMD_DST_GRC:
400 if (src_type == DMAE_CMD_SRC_PCI)
401 DP(msglvl, "DMAE: opcode 0x%08x\n"
402 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
403 "comp_addr [%x:%08x], comp_val 0x%08x\n",
404 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
405 dmae->len, dmae->dst_addr_lo >> 2,
406 dmae->comp_addr_hi, dmae->comp_addr_lo,
407 dmae->comp_val);
408 else
409 DP(msglvl, "DMAE: opcode 0x%08x\n"
410 "src [%08x], len [%d*4], dst [%08x]\n"
411 "comp_addr [%x:%08x], comp_val 0x%08x\n",
412 dmae->opcode, dmae->src_addr_lo >> 2,
413 dmae->len, dmae->dst_addr_lo >> 2,
414 dmae->comp_addr_hi, dmae->comp_addr_lo,
415 dmae->comp_val);
416 break;
417 default:
418 if (src_type == DMAE_CMD_SRC_PCI)
419 DP(msglvl, "DMAE: opcode 0x%08x\n"
420 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
421 "comp_addr [%x:%08x] comp_val 0x%08x\n",
422 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
423 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
424 dmae->comp_val);
425 else
426 DP(msglvl, "DMAE: opcode 0x%08x\n"
427 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
428 "comp_addr [%x:%08x] comp_val 0x%08x\n",
429 dmae->opcode, dmae->src_addr_lo >> 2,
430 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
431 dmae->comp_val);
432 break;
433 }
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000434
435 for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
436 DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
437 i, *(((u32 *)dmae) + i));
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000438}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000439
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200440/* copy command into DMAE command memory and set DMAE command go */
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000441void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200442{
443 u32 cmd_offset;
444 int i;
445
446 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
447 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
448 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200449 }
450 REG_WR(bp, dmae_reg_go_c[idx], 1);
451}
452
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000453u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
454{
455 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
456 DMAE_CMD_C_ENABLE);
457}
458
459u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
460{
461 return opcode & ~DMAE_CMD_SRC_RESET;
462}
463
464u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
465 bool with_comp, u8 comp_type)
466{
467 u32 opcode = 0;
468
469 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
470 (dst_type << DMAE_COMMAND_DST_SHIFT));
471
472 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
473
474 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
David S. Miller8decf862011-09-22 03:23:13 -0400475 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
476 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000477 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
478
479#ifdef __BIG_ENDIAN
480 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
481#else
482 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
483#endif
484 if (with_comp)
485 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
486 return opcode;
487}
488
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000489void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
stephen hemminger8d962862010-10-21 07:50:56 +0000490 struct dmae_command *dmae,
491 u8 src_type, u8 dst_type)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000492{
493 memset(dmae, 0, sizeof(struct dmae_command));
494
495 /* set the opcode */
496 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
497 true, DMAE_COMP_PCI);
498
499 /* fill in the completion parameters */
500 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
501 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
502 dmae->comp_val = DMAE_COMP_VAL;
503}
504
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000505/* issue a dmae command over the init-channel and wait for completion */
506int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000507{
508 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
Dmitry Kravkov5e374b52011-05-22 10:09:19 +0000509 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000510 int rc = 0;
511
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000512 bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
513
514 /* Lock the dmae channel. Disable BHs to prevent a dead-lock
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300515 * as long as this code is called both from syscall context and
516 * from ndo_set_rx_mode() flow that may be called from BH.
517 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800518 spin_lock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000519
520 /* reset completion */
521 *wb_comp = 0;
522
523 /* post the command on the channel used for initializations */
524 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
525
526 /* wait for completion */
527 udelay(5);
528 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000529
Ariel Elior95c6c6162012-01-26 06:01:52 +0000530 if (!cnt ||
531 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
532 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000533 BNX2X_ERR("DMAE timeout!\n");
534 rc = DMAE_TIMEOUT;
535 goto unlock;
536 }
537 cnt--;
538 udelay(50);
539 }
540 if (*wb_comp & DMAE_PCI_ERR_FLAG) {
541 BNX2X_ERR("DMAE PCI error!\n");
542 rc = DMAE_PCI_ERROR;
543 }
544
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000545unlock:
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800546 spin_unlock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000547 return rc;
548}
549
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700550void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
551 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200552{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000553 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000554 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700555
556 if (!bp->dmae_ready) {
557 u32 *data = bnx2x_sp(bp, wb_data[0]);
558
Ariel Elior127a4252012-01-26 06:01:46 +0000559 if (CHIP_IS_E1(bp))
560 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
561 else
562 bnx2x_init_str_wr(bp, dst_addr, data, len32);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700563 return;
564 }
565
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000566 /* set opcode and fixed command fields */
567 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200568
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000569 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000570 dmae.src_addr_lo = U64_LO(dma_addr);
571 dmae.src_addr_hi = U64_HI(dma_addr);
572 dmae.dst_addr_lo = dst_addr >> 2;
573 dmae.dst_addr_hi = 0;
574 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200575
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000576 /* issue the command and wait for completion */
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000577 rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
578 if (rc) {
579 BNX2X_ERR("DMAE returned failure %d\n", rc);
580 bnx2x_panic();
581 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200582}
583
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700584void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200585{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000586 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000587 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700588
589 if (!bp->dmae_ready) {
590 u32 *data = bnx2x_sp(bp, wb_data[0]);
591 int i;
592
Merav Sicron51c1a582012-03-18 10:33:38 +0000593 if (CHIP_IS_E1(bp))
Ariel Elior127a4252012-01-26 06:01:46 +0000594 for (i = 0; i < len32; i++)
595 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
Merav Sicron51c1a582012-03-18 10:33:38 +0000596 else
Ariel Elior127a4252012-01-26 06:01:46 +0000597 for (i = 0; i < len32; i++)
598 data[i] = REG_RD(bp, src_addr + i*4);
599
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700600 return;
601 }
602
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000603 /* set opcode and fixed command fields */
604 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200605
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000606 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000607 dmae.src_addr_lo = src_addr >> 2;
608 dmae.src_addr_hi = 0;
609 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
610 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
611 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200612
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000613 /* issue the command and wait for completion */
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000614 rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
615 if (rc) {
616 BNX2X_ERR("DMAE returned failure %d\n", rc);
617 bnx2x_panic();
Yuval Mintzc957d092013-06-25 08:50:11 +0300618 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200619}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200620
stephen hemminger8d962862010-10-21 07:50:56 +0000621static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
622 u32 addr, u32 len)
Eilon Greenstein573f2032009-08-12 08:24:14 +0000623{
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000624 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
Eilon Greenstein573f2032009-08-12 08:24:14 +0000625 int offset = 0;
626
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000627 while (len > dmae_wr_max) {
Eilon Greenstein573f2032009-08-12 08:24:14 +0000628 bnx2x_write_dmae(bp, phys_addr + offset,
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000629 addr + offset, dmae_wr_max);
630 offset += dmae_wr_max * 4;
631 len -= dmae_wr_max;
Eilon Greenstein573f2032009-08-12 08:24:14 +0000632 }
633
634 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
635}
636
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200637static int bnx2x_mc_assert(struct bnx2x *bp)
638{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200639 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700640 int i, rc = 0;
641 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200642
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700643 /* XSTORM */
644 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
645 XSTORM_ASSERT_LIST_INDEX_OFFSET);
646 if (last_idx)
647 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200648
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700649 /* print the asserts */
650 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200651
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700652 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
653 XSTORM_ASSERT_LIST_OFFSET(i));
654 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
655 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
656 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
657 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
658 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
659 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200660
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700661 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000662 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700663 i, row3, row2, row1, row0);
664 rc++;
665 } else {
666 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200667 }
668 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700669
670 /* TSTORM */
671 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
672 TSTORM_ASSERT_LIST_INDEX_OFFSET);
673 if (last_idx)
674 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
675
676 /* print the asserts */
677 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
678
679 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
680 TSTORM_ASSERT_LIST_OFFSET(i));
681 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
682 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
683 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
684 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
685 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
686 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
687
688 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000689 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700690 i, row3, row2, row1, row0);
691 rc++;
692 } else {
693 break;
694 }
695 }
696
697 /* CSTORM */
698 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
699 CSTORM_ASSERT_LIST_INDEX_OFFSET);
700 if (last_idx)
701 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
702
703 /* print the asserts */
704 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
705
706 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
707 CSTORM_ASSERT_LIST_OFFSET(i));
708 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
709 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
710 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
711 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
712 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
713 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
714
715 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000716 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700717 i, row3, row2, row1, row0);
718 rc++;
719 } else {
720 break;
721 }
722 }
723
724 /* USTORM */
725 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
726 USTORM_ASSERT_LIST_INDEX_OFFSET);
727 if (last_idx)
728 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
729
730 /* print the asserts */
731 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
732
733 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
734 USTORM_ASSERT_LIST_OFFSET(i));
735 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
736 USTORM_ASSERT_LIST_OFFSET(i) + 4);
737 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
738 USTORM_ASSERT_LIST_OFFSET(i) + 8);
739 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
740 USTORM_ASSERT_LIST_OFFSET(i) + 12);
741
742 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000743 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700744 i, row3, row2, row1, row0);
745 rc++;
746 } else {
747 break;
748 }
749 }
750
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200751 return rc;
752}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800753
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000754void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200755{
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000756 u32 addr, val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200757 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000758 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200759 int word;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000760 u32 trace_shmem_base;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +0000761 if (BP_NOMCP(bp)) {
762 BNX2X_ERR("NO MCP - can not dump\n");
763 return;
764 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000765 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
766 (bp->common.bc_ver & 0xff0000) >> 16,
767 (bp->common.bc_ver & 0xff00) >> 8,
768 (bp->common.bc_ver & 0xff));
769
770 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
771 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
Merav Sicron51c1a582012-03-18 10:33:38 +0000772 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000773
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000774 if (BP_PATH(bp) == 0)
775 trace_shmem_base = bp->common.shmem_base;
776 else
777 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
Dmitry Kravkovde128802012-03-18 10:33:45 +0000778 addr = trace_shmem_base - 0x800;
779
780 /* validate TRCB signature */
781 mark = REG_RD(bp, addr);
782 if (mark != MFW_TRACE_SIGNATURE) {
783 BNX2X_ERR("Trace buffer signature is missing.");
784 return ;
785 }
786
787 /* read cyclic buffer pointer */
788 addr += 4;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000789 mark = REG_RD(bp, addr);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000790 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
791 + ((mark + 0x3) & ~0x3) - 0x08000000;
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000792 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200793
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000794 printk("%s", lvl);
Yuval Mintz2de67432013-01-23 03:21:43 +0000795
796 /* dump buffer after the mark */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000797 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200798 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000799 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200800 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000801 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200802 }
Yuval Mintz2de67432013-01-23 03:21:43 +0000803
804 /* dump buffer before the mark */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000805 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200806 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000807 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200808 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000809 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200810 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000811 printk("%s" "end of fw dump\n", lvl);
812}
813
Eric Dumazet1191cb82012-04-27 21:39:21 +0000814static void bnx2x_fw_dump(struct bnx2x *bp)
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000815{
816 bnx2x_fw_dump_lvl(bp, KERN_ERR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200817}
818
Yuval Mintz823e1d92013-01-14 05:11:47 +0000819static void bnx2x_hc_int_disable(struct bnx2x *bp)
820{
821 int port = BP_PORT(bp);
822 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
823 u32 val = REG_RD(bp, addr);
824
825 /* in E1 we must use only PCI configuration space to disable
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000826 * MSI/MSIX capability
827 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
Yuval Mintz823e1d92013-01-14 05:11:47 +0000828 */
829 if (CHIP_IS_E1(bp)) {
830 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
831 * Use mask register to prevent from HC sending interrupts
832 * after we exit the function
833 */
834 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
835
836 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
837 HC_CONFIG_0_REG_INT_LINE_EN_0 |
838 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
839 } else
840 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
841 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
842 HC_CONFIG_0_REG_INT_LINE_EN_0 |
843 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
844
845 DP(NETIF_MSG_IFDOWN,
846 "write %x to HC %d (addr 0x%x)\n",
847 val, port, addr);
848
849 /* flush all outstanding writes */
850 mmiowb();
851
852 REG_WR(bp, addr, val);
853 if (REG_RD(bp, addr) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000854 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000855}
856
857static void bnx2x_igu_int_disable(struct bnx2x *bp)
858{
859 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
860
861 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
862 IGU_PF_CONF_INT_LINE_EN |
863 IGU_PF_CONF_ATTN_BIT_EN);
864
865 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
866
867 /* flush all outstanding writes */
868 mmiowb();
869
870 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
871 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000872 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000873}
874
875static void bnx2x_int_disable(struct bnx2x *bp)
876{
877 if (bp->common.int_block == INT_BLOCK_HC)
878 bnx2x_hc_int_disable(bp);
879 else
880 bnx2x_igu_int_disable(bp);
881}
882
883void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200884{
885 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000886 u16 j;
887 struct hc_sp_status_block_data sp_sb_data;
888 int func = BP_FUNC(bp);
889#ifdef BNX2X_STOP_ON_ERROR
890 u16 start = 0, end = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000891 u8 cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000892#endif
Yuval Mintz823e1d92013-01-14 05:11:47 +0000893 if (disable_int)
894 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200895
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700896 bp->stats_state = STATS_STATE_DISABLED;
Ariel Elior7a752992012-01-26 06:01:53 +0000897 bp->eth_stats.unrecoverable_error++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700898 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
899
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200900 BNX2X_ERR("begin crash dump -----------------\n");
901
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000902 /* Indices */
903 /* Common */
Merav Sicron51c1a582012-03-18 10:33:38 +0000904 BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300905 bp->def_idx, bp->def_att_idx, bp->attn_state,
906 bp->spq_prod_idx, bp->stats_counter);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000907 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
908 bp->def_status_blk->atten_status_block.attn_bits,
909 bp->def_status_blk->atten_status_block.attn_bits_ack,
910 bp->def_status_blk->atten_status_block.status_block_id,
911 bp->def_status_blk->atten_status_block.attn_bits_index);
912 BNX2X_ERR(" def (");
913 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
914 pr_cont("0x%x%s",
Joe Perchesf1deab52011-08-14 12:16:21 +0000915 bp->def_status_blk->sp_sb.index_values[i],
916 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000917
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000918 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
919 *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
920 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
921 i*sizeof(u32));
922
Joe Perchesf1deab52011-08-14 12:16:21 +0000923 pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000924 sp_sb_data.igu_sb_id,
925 sp_sb_data.igu_seg_id,
926 sp_sb_data.p_func.pf_id,
927 sp_sb_data.p_func.vnic_id,
928 sp_sb_data.p_func.vf_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300929 sp_sb_data.p_func.vf_valid,
930 sp_sb_data.state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000931
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000932 for_each_eth_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000933 struct bnx2x_fastpath *fp = &bp->fp[i];
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000934 int loop;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000935 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000936 struct hc_status_block_data_e1x sb_data_e1x;
937 struct hc_status_block_sm *hc_sm_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300938 CHIP_IS_E1x(bp) ?
939 sb_data_e1x.common.state_machine :
940 sb_data_e2.common.state_machine;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000941 struct hc_index_data *hc_index_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300942 CHIP_IS_E1x(bp) ?
943 sb_data_e1x.index_data :
944 sb_data_e2.index_data;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000945 u8 data_size, cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000946 u32 *sb_data_p;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000947 struct bnx2x_fp_txdata txdata;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000948
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000949 /* Rx */
Merav Sicron51c1a582012-03-18 10:33:38 +0000950 BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000951 i, fp->rx_bd_prod, fp->rx_bd_cons,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000952 fp->rx_comp_prod,
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000953 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Merav Sicron51c1a582012-03-18 10:33:38 +0000954 BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000955 fp->rx_sge_prod, fp->last_max_sge,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000956 le16_to_cpu(fp->fp_hc_idx));
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000957
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000958 /* Tx */
Ariel Elior6383c0b2011-07-14 08:31:57 +0000959 for_each_cos_in_tx_queue(fp, cos)
960 {
Merav Sicron65565882012-06-19 07:48:26 +0000961 txdata = *fp->txdata_ptr[cos];
Merav Sicron51c1a582012-03-18 10:33:38 +0000962 BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +0000963 i, txdata.tx_pkt_prod,
964 txdata.tx_pkt_cons, txdata.tx_bd_prod,
965 txdata.tx_bd_cons,
966 le16_to_cpu(*txdata.tx_cons_sb));
967 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000968
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300969 loop = CHIP_IS_E1x(bp) ?
970 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000971
972 /* host sb data */
973
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000974 if (IS_FCOE_FP(fp))
975 continue;
Merav Sicron55c11942012-11-07 00:45:48 +0000976
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000977 BNX2X_ERR(" run indexes (");
978 for (j = 0; j < HC_SB_MAX_SM; j++)
979 pr_cont("0x%x%s",
980 fp->sb_running_index[j],
981 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
982
983 BNX2X_ERR(" indexes (");
984 for (j = 0; j < loop; j++)
985 pr_cont("0x%x%s",
986 fp->sb_index_values[j],
987 (j == loop - 1) ? ")" : " ");
988 /* fw sb data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300989 data_size = CHIP_IS_E1x(bp) ?
990 sizeof(struct hc_status_block_data_e1x) :
991 sizeof(struct hc_status_block_data_e2);
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000992 data_size /= sizeof(u32);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300993 sb_data_p = CHIP_IS_E1x(bp) ?
994 (u32 *)&sb_data_e1x :
995 (u32 *)&sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000996 /* copy sb data in here */
997 for (j = 0; j < data_size; j++)
998 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
999 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
1000 j * sizeof(u32));
1001
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001002 if (!CHIP_IS_E1x(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001003 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001004 sb_data_e2.common.p_func.pf_id,
1005 sb_data_e2.common.p_func.vf_id,
1006 sb_data_e2.common.p_func.vf_valid,
1007 sb_data_e2.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001008 sb_data_e2.common.same_igu_sb_1b,
1009 sb_data_e2.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001010 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00001011 pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001012 sb_data_e1x.common.p_func.pf_id,
1013 sb_data_e1x.common.p_func.vf_id,
1014 sb_data_e1x.common.p_func.vf_valid,
1015 sb_data_e1x.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001016 sb_data_e1x.common.same_igu_sb_1b,
1017 sb_data_e1x.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001018 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001019
1020 /* SB_SMs data */
1021 for (j = 0; j < HC_SB_MAX_SM; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001022 pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
1023 j, hc_sm_p[j].__flags,
1024 hc_sm_p[j].igu_sb_id,
1025 hc_sm_p[j].igu_seg_id,
1026 hc_sm_p[j].time_to_expire,
1027 hc_sm_p[j].timer_value);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001028 }
1029
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001030 /* Indices data */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001031 for (j = 0; j < loop; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001032 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001033 hc_index_p[j].flags,
1034 hc_index_p[j].timeout);
1035 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001036 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001037
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001038#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz04c46732013-01-23 03:21:46 +00001039
1040 /* event queue */
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001041 BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
Yuval Mintz04c46732013-01-23 03:21:46 +00001042 for (i = 0; i < NUM_EQ_DESC; i++) {
1043 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
1044
1045 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1046 i, bp->eq_ring[i].message.opcode,
1047 bp->eq_ring[i].message.error);
1048 BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
1049 }
1050
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001051 /* Rings */
1052 /* Rx */
Merav Sicron55c11942012-11-07 00:45:48 +00001053 for_each_valid_rx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001054 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001055
1056 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1057 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001058 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001059 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1060 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1061
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001062 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
Yuval Mintz44151ac2012-01-23 07:31:56 +00001063 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001064 }
1065
Eilon Greenstein3196a882008-08-13 15:58:49 -07001066 start = RX_SGE(fp->rx_sge_prod);
1067 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001068 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001069 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1070 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1071
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001072 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1073 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001074 }
1075
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001076 start = RCQ_BD(fp->rx_comp_cons - 10);
1077 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001078 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001079 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1080
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001081 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1082 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001083 }
1084 }
1085
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001086 /* Tx */
Merav Sicron55c11942012-11-07 00:45:48 +00001087 for_each_valid_tx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001088 struct bnx2x_fastpath *fp = &bp->fp[i];
Ariel Elior6383c0b2011-07-14 08:31:57 +00001089 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00001090 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001091
Ariel Elior6383c0b2011-07-14 08:31:57 +00001092 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1093 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1094 for (j = start; j != end; j = TX_BD(j + 1)) {
1095 struct sw_tx_bd *sw_bd =
1096 &txdata->tx_buf_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001097
Merav Sicron51c1a582012-03-18 10:33:38 +00001098 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001099 i, cos, j, sw_bd->skb,
1100 sw_bd->first_bd);
1101 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001102
Ariel Elior6383c0b2011-07-14 08:31:57 +00001103 start = TX_BD(txdata->tx_bd_cons - 10);
1104 end = TX_BD(txdata->tx_bd_cons + 254);
1105 for (j = start; j != end; j = TX_BD(j + 1)) {
1106 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001107
Merav Sicron51c1a582012-03-18 10:33:38 +00001108 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001109 i, cos, j, tx_bd[0], tx_bd[1],
1110 tx_bd[2], tx_bd[3]);
1111 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001112 }
1113 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001114#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001115 bnx2x_fw_dump(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001116 bnx2x_mc_assert(bp);
1117 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001118}
1119
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001120/*
1121 * FLR Support for E2
1122 *
1123 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1124 * initialization.
1125 */
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001126#define FLR_WAIT_USEC 10000 /* 10 milliseconds */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001127#define FLR_WAIT_INTERVAL 50 /* usec */
1128#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001129
1130struct pbf_pN_buf_regs {
1131 int pN;
1132 u32 init_crd;
1133 u32 crd;
1134 u32 crd_freed;
1135};
1136
1137struct pbf_pN_cmd_regs {
1138 int pN;
1139 u32 lines_occup;
1140 u32 lines_freed;
1141};
1142
1143static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1144 struct pbf_pN_buf_regs *regs,
1145 u32 poll_count)
1146{
1147 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1148 u32 cur_cnt = poll_count;
1149
1150 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1151 crd = crd_start = REG_RD(bp, regs->crd);
1152 init_crd = REG_RD(bp, regs->init_crd);
1153
1154 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1155 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1156 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1157
1158 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1159 (init_crd - crd_start))) {
1160 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001161 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001162 crd = REG_RD(bp, regs->crd);
1163 crd_freed = REG_RD(bp, regs->crd_freed);
1164 } else {
1165 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1166 regs->pN);
1167 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1168 regs->pN, crd);
1169 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1170 regs->pN, crd_freed);
1171 break;
1172 }
1173 }
1174 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001175 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001176}
1177
1178static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1179 struct pbf_pN_cmd_regs *regs,
1180 u32 poll_count)
1181{
1182 u32 occup, to_free, freed, freed_start;
1183 u32 cur_cnt = poll_count;
1184
1185 occup = to_free = REG_RD(bp, regs->lines_occup);
1186 freed = freed_start = REG_RD(bp, regs->lines_freed);
1187
1188 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1189 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1190
1191 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1192 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001193 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001194 occup = REG_RD(bp, regs->lines_occup);
1195 freed = REG_RD(bp, regs->lines_freed);
1196 } else {
1197 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1198 regs->pN);
1199 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1200 regs->pN, occup);
1201 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1202 regs->pN, freed);
1203 break;
1204 }
1205 }
1206 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001207 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001208}
1209
Eric Dumazet1191cb82012-04-27 21:39:21 +00001210static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1211 u32 expected, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001212{
1213 u32 cur_cnt = poll_count;
1214 u32 val;
1215
1216 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
Ariel Elior89db4ad2012-01-26 06:01:48 +00001217 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001218
1219 return val;
1220}
1221
Ariel Eliord16132c2013-01-01 05:22:42 +00001222int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1223 char *msg, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001224{
1225 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1226 if (val != 0) {
1227 BNX2X_ERR("%s usage count=%d\n", msg, val);
1228 return 1;
1229 }
1230 return 0;
1231}
1232
Ariel Eliord16132c2013-01-01 05:22:42 +00001233/* Common routines with VF FLR cleanup */
1234u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001235{
1236 /* adjust polling timeout */
1237 if (CHIP_REV_IS_EMUL(bp))
1238 return FLR_POLL_CNT * 2000;
1239
1240 if (CHIP_REV_IS_FPGA(bp))
1241 return FLR_POLL_CNT * 120;
1242
1243 return FLR_POLL_CNT;
1244}
1245
Ariel Eliord16132c2013-01-01 05:22:42 +00001246void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001247{
1248 struct pbf_pN_cmd_regs cmd_regs[] = {
1249 {0, (CHIP_IS_E3B0(bp)) ?
1250 PBF_REG_TQ_OCCUPANCY_Q0 :
1251 PBF_REG_P0_TQ_OCCUPANCY,
1252 (CHIP_IS_E3B0(bp)) ?
1253 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1254 PBF_REG_P0_TQ_LINES_FREED_CNT},
1255 {1, (CHIP_IS_E3B0(bp)) ?
1256 PBF_REG_TQ_OCCUPANCY_Q1 :
1257 PBF_REG_P1_TQ_OCCUPANCY,
1258 (CHIP_IS_E3B0(bp)) ?
1259 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1260 PBF_REG_P1_TQ_LINES_FREED_CNT},
1261 {4, (CHIP_IS_E3B0(bp)) ?
1262 PBF_REG_TQ_OCCUPANCY_LB_Q :
1263 PBF_REG_P4_TQ_OCCUPANCY,
1264 (CHIP_IS_E3B0(bp)) ?
1265 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1266 PBF_REG_P4_TQ_LINES_FREED_CNT}
1267 };
1268
1269 struct pbf_pN_buf_regs buf_regs[] = {
1270 {0, (CHIP_IS_E3B0(bp)) ?
1271 PBF_REG_INIT_CRD_Q0 :
1272 PBF_REG_P0_INIT_CRD ,
1273 (CHIP_IS_E3B0(bp)) ?
1274 PBF_REG_CREDIT_Q0 :
1275 PBF_REG_P0_CREDIT,
1276 (CHIP_IS_E3B0(bp)) ?
1277 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1278 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1279 {1, (CHIP_IS_E3B0(bp)) ?
1280 PBF_REG_INIT_CRD_Q1 :
1281 PBF_REG_P1_INIT_CRD,
1282 (CHIP_IS_E3B0(bp)) ?
1283 PBF_REG_CREDIT_Q1 :
1284 PBF_REG_P1_CREDIT,
1285 (CHIP_IS_E3B0(bp)) ?
1286 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1287 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1288 {4, (CHIP_IS_E3B0(bp)) ?
1289 PBF_REG_INIT_CRD_LB_Q :
1290 PBF_REG_P4_INIT_CRD,
1291 (CHIP_IS_E3B0(bp)) ?
1292 PBF_REG_CREDIT_LB_Q :
1293 PBF_REG_P4_CREDIT,
1294 (CHIP_IS_E3B0(bp)) ?
1295 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1296 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1297 };
1298
1299 int i;
1300
1301 /* Verify the command queues are flushed P0, P1, P4 */
1302 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1303 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1304
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001305 /* Verify the transmission buffers are flushed P0, P1, P4 */
1306 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1307 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1308}
1309
1310#define OP_GEN_PARAM(param) \
1311 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1312
1313#define OP_GEN_TYPE(type) \
1314 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1315
1316#define OP_GEN_AGG_VECT(index) \
1317 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1318
Ariel Eliord16132c2013-01-01 05:22:42 +00001319int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001320{
Yuval Mintz86564c32013-01-23 03:21:50 +00001321 u32 op_gen_command = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001322 u32 comp_addr = BAR_CSTRORM_INTMEM +
1323 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1324 int ret = 0;
1325
1326 if (REG_RD(bp, comp_addr)) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001327 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001328 return 1;
1329 }
1330
Yuval Mintz86564c32013-01-23 03:21:50 +00001331 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1332 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1333 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1334 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001335
Ariel Elior89db4ad2012-01-26 06:01:48 +00001336 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
Yuval Mintz86564c32013-01-23 03:21:50 +00001337 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001338
1339 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1340 BNX2X_ERR("FW final cleanup did not succeed\n");
Merav Sicron51c1a582012-03-18 10:33:38 +00001341 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1342 (REG_RD(bp, comp_addr)));
Ariel Eliord16132c2013-01-01 05:22:42 +00001343 bnx2x_panic();
1344 return 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001345 }
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001346 /* Zero completion for next FLR */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001347 REG_WR(bp, comp_addr, 0);
1348
1349 return ret;
1350}
1351
Ariel Eliorb56e9672013-01-01 05:22:32 +00001352u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001353{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001354 u16 status;
1355
Jiang Liu2a80eeb2012-08-20 13:26:51 -06001356 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001357 return status & PCI_EXP_DEVSTA_TRPND;
1358}
1359
1360/* PF FLR specific routines
1361*/
1362static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1363{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001364 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1365 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1366 CFC_REG_NUM_LCIDS_INSIDE_PF,
1367 "CFC PF usage counter timed out",
1368 poll_cnt))
1369 return 1;
1370
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001371 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1372 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1373 DORQ_REG_PF_USAGE_CNT,
1374 "DQ PF usage counter timed out",
1375 poll_cnt))
1376 return 1;
1377
1378 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1379 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1380 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1381 "QM PF usage counter timed out",
1382 poll_cnt))
1383 return 1;
1384
1385 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1386 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1387 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1388 "Timers VNIC usage counter timed out",
1389 poll_cnt))
1390 return 1;
1391 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1392 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1393 "Timers NUM_SCANS usage counter timed out",
1394 poll_cnt))
1395 return 1;
1396
1397 /* Wait DMAE PF usage counter to zero */
1398 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1399 dmae_reg_go_c[INIT_DMAE_C(bp)],
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001400 "DMAE command register timed out",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001401 poll_cnt))
1402 return 1;
1403
1404 return 0;
1405}
1406
1407static void bnx2x_hw_enable_status(struct bnx2x *bp)
1408{
1409 u32 val;
1410
1411 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1412 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1413
1414 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1415 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1416
1417 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1418 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1419
1420 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1421 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1422
1423 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1424 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1425
1426 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1427 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1428
1429 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1430 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1431
1432 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1433 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1434 val);
1435}
1436
1437static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1438{
1439 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1440
1441 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1442
1443 /* Re-enable PF target read access */
1444 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1445
1446 /* Poll HW usage counters */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001447 DP(BNX2X_MSG_SP, "Polling usage counters\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001448 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1449 return -EBUSY;
1450
1451 /* Zero the igu 'trailing edge' and 'leading edge' */
1452
1453 /* Send the FW cleanup command */
1454 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1455 return -EBUSY;
1456
1457 /* ATC cleanup */
1458
1459 /* Verify TX hw is flushed */
1460 bnx2x_tx_hw_flushed(bp, poll_cnt);
1461
1462 /* Wait 100ms (not adjusted according to platform) */
1463 msleep(100);
1464
1465 /* Verify no pending pci transactions */
1466 if (bnx2x_is_pcie_pending(bp->pdev))
1467 BNX2X_ERR("PCIE Transactions still pending\n");
1468
1469 /* Debug */
1470 bnx2x_hw_enable_status(bp);
1471
1472 /*
1473 * Master enable - Due to WB DMAE writes performed before this
1474 * register is re-initialized as part of the regular function init
1475 */
1476 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1477
1478 return 0;
1479}
1480
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001481static void bnx2x_hc_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001482{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001483 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001484 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1485 u32 val = REG_RD(bp, addr);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001486 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1487 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1488 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001489
1490 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001491 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1492 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001493 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1494 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001495 if (single_msix)
1496 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001497 } else if (msi) {
1498 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1499 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1500 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1501 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001502 } else {
1503 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001504 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001505 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1506 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001507
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001508 if (!CHIP_IS_E1(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001509 DP(NETIF_MSG_IFUP,
1510 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001511
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001512 REG_WR(bp, addr, val);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001513
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001514 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1515 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001516 }
1517
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001518 if (CHIP_IS_E1(bp))
1519 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1520
Merav Sicron51c1a582012-03-18 10:33:38 +00001521 DP(NETIF_MSG_IFUP,
1522 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1523 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001524
1525 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001526 /*
1527 * Ensure that HC_CONFIG is written before leading/trailing edge config
1528 */
1529 mmiowb();
1530 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001531
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001532 if (!CHIP_IS_E1(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001533 /* init leading/trailing edge */
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00001534 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001535 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001536 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001537 /* enable nig and gpio3 attention */
1538 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001539 } else
1540 val = 0xffff;
1541
1542 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1543 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1544 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001545
1546 /* Make sure that interrupts are indeed enabled from here on */
1547 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001548}
1549
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001550static void bnx2x_igu_int_enable(struct bnx2x *bp)
1551{
1552 u32 val;
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001553 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1554 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1555 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001556
1557 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1558
1559 if (msix) {
1560 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1561 IGU_PF_CONF_SINGLE_ISR_EN);
Yuval Mintzebe61d82013-01-14 05:11:48 +00001562 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001563 IGU_PF_CONF_ATTN_BIT_EN);
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001564
1565 if (single_msix)
1566 val |= IGU_PF_CONF_SINGLE_ISR_EN;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001567 } else if (msi) {
1568 val &= ~IGU_PF_CONF_INT_LINE_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001569 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001570 IGU_PF_CONF_ATTN_BIT_EN |
1571 IGU_PF_CONF_SINGLE_ISR_EN);
1572 } else {
1573 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001574 val |= (IGU_PF_CONF_INT_LINE_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001575 IGU_PF_CONF_ATTN_BIT_EN |
1576 IGU_PF_CONF_SINGLE_ISR_EN);
1577 }
1578
Yuval Mintzebe61d82013-01-14 05:11:48 +00001579 /* Clean previous status - need to configure igu prior to ack*/
1580 if ((!msix) || single_msix) {
1581 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1582 bnx2x_ack_int(bp);
1583 }
1584
1585 val |= IGU_PF_CONF_FUNC_EN;
1586
Merav Sicron51c1a582012-03-18 10:33:38 +00001587 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001588 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1589
1590 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1591
Yuval Mintz79a85572012-04-03 18:41:25 +00001592 if (val & IGU_PF_CONF_INT_LINE_EN)
1593 pci_intx(bp->pdev, true);
1594
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001595 barrier();
1596
1597 /* init leading/trailing edge */
1598 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001599 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001600 if (bp->port.pmf)
1601 /* enable nig and gpio3 attention */
1602 val |= 0x1100;
1603 } else
1604 val = 0xffff;
1605
1606 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1607 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1608
1609 /* Make sure that interrupts are indeed enabled from here on */
1610 mmiowb();
1611}
1612
1613void bnx2x_int_enable(struct bnx2x *bp)
1614{
1615 if (bp->common.int_block == INT_BLOCK_HC)
1616 bnx2x_hc_int_enable(bp);
1617 else
1618 bnx2x_igu_int_enable(bp);
1619}
1620
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001621void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001622{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001623 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001624 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001625
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07001626 if (disable_hw)
1627 /* prevent the HW from sending interrupts */
1628 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001629
1630 /* make sure all ISRs are done */
1631 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001632 synchronize_irq(bp->msix_table[0].vector);
1633 offset = 1;
Merav Sicron55c11942012-11-07 00:45:48 +00001634 if (CNIC_SUPPORT(bp))
1635 offset++;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001636 for_each_eth_queue(bp, i)
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001637 synchronize_irq(bp->msix_table[offset++].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001638 } else
1639 synchronize_irq(bp->pdev->irq);
1640
1641 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001642 cancel_delayed_work(&bp->sp_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00001643 cancel_delayed_work(&bp->period_task);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001644 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001645}
1646
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001647/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001648
1649/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001650 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001651 */
1652
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001653/* Return true if succeeded to acquire the lock */
1654static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1655{
1656 u32 lock_status;
1657 u32 resource_bit = (1 << resource);
1658 int func = BP_FUNC(bp);
1659 u32 hw_lock_control_reg;
1660
Merav Sicron51c1a582012-03-18 10:33:38 +00001661 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1662 "Trying to take a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001663
1664 /* Validating that the resource is within range */
1665 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001666 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001667 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1668 resource, HW_LOCK_MAX_RESOURCE_VALUE);
Eric Dumazet0fdf4d02010-08-26 22:03:53 -07001669 return false;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001670 }
1671
1672 if (func <= 5)
1673 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1674 else
1675 hw_lock_control_reg =
1676 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1677
1678 /* Try to acquire the lock */
1679 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1680 lock_status = REG_RD(bp, hw_lock_control_reg);
1681 if (lock_status & resource_bit)
1682 return true;
1683
Merav Sicron51c1a582012-03-18 10:33:38 +00001684 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1685 "Failed to get a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001686 return false;
1687}
1688
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001689/**
1690 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1691 *
1692 * @bp: driver handle
1693 *
1694 * Returns the recovery leader resource id according to the engine this function
1695 * belongs to. Currently only only 2 engines is supported.
1696 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001697static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001698{
1699 if (BP_PATH(bp))
1700 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1701 else
1702 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1703}
1704
1705/**
Yuval Mintz2de67432013-01-23 03:21:43 +00001706 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001707 *
1708 * @bp: driver handle
1709 *
Yuval Mintz2de67432013-01-23 03:21:43 +00001710 * Tries to acquire a leader lock for current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001711 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001712static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001713{
1714 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1715}
1716
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001717static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
Merav Sicron55c11942012-11-07 00:45:48 +00001718
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001719/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1720static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1721{
1722 /* Set the interrupt occurred bit for the sp-task to recognize it
1723 * must ack the interrupt and transition according to the IGU
1724 * state machine.
1725 */
1726 atomic_set(&bp->interrupt_occurred, 1);
1727
1728 /* The sp_task must execute only after this bit
1729 * is set, otherwise we will get out of sync and miss all
1730 * further interrupts. Hence, the barrier.
1731 */
1732 smp_wmb();
1733
1734 /* schedule sp_task to workqueue */
1735 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1736}
Eilon Greenstein3196a882008-08-13 15:58:49 -07001737
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001738void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001739{
1740 struct bnx2x *bp = fp->bp;
1741 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1742 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001743 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
Barak Witkowski15192a82012-06-19 07:48:28 +00001744 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001745
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001746 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001747 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001748 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001749 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001750
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001751 /* If cid is within VF range, replace the slowpath object with the
1752 * one corresponding to this VF
1753 */
1754 if (cid >= BNX2X_FIRST_VF_CID &&
1755 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1756 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1757
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001758 switch (command) {
1759 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001760 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001761 drv_cmd = BNX2X_Q_CMD_UPDATE;
1762 break;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001763
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001764 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001765 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001766 drv_cmd = BNX2X_Q_CMD_SETUP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001767 break;
1768
Ariel Elior6383c0b2011-07-14 08:31:57 +00001769 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
Merav Sicron51c1a582012-03-18 10:33:38 +00001770 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
Ariel Elior6383c0b2011-07-14 08:31:57 +00001771 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1772 break;
1773
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001774 case (RAMROD_CMD_ID_ETH_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001775 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001776 drv_cmd = BNX2X_Q_CMD_HALT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001777 break;
1778
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001779 case (RAMROD_CMD_ID_ETH_TERMINATE):
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001780 DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001781 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1782 break;
1783
1784 case (RAMROD_CMD_ID_ETH_EMPTY):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001785 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001786 drv_cmd = BNX2X_Q_CMD_EMPTY;
Eliezer Tamir49d66772008-02-28 11:53:13 -08001787 break;
1788
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001789 default:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001790 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1791 command, fp->index);
1792 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001793 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001794
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001795 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1796 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1797 /* q_obj->complete_cmd() failure means that this was
1798 * an unexpected completion.
1799 *
1800 * In this case we don't want to increase the bp->spq_left
1801 * because apparently we haven't sent this command the first
1802 * place.
1803 */
1804#ifdef BNX2X_STOP_ON_ERROR
1805 bnx2x_panic();
1806#else
1807 return;
1808#endif
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001809 /* SRIOV: reschedule any 'in_progress' operations */
1810 bnx2x_iov_sp_event(bp, cid, true);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001811
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00001812 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08001813 atomic_inc(&bp->cq_spq_left);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001814 /* push the change in bp->spq_left and towards the memory */
1815 smp_mb__after_atomic_inc();
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001816
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001817 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1818
Barak Witkowskia3348722012-04-23 03:04:46 +00001819 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1820 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1821 /* if Q update ramrod is completed for last Q in AFEX vif set
1822 * flow, then ACK MCP at the end
1823 *
1824 * mark pending ACK to MCP bit.
1825 * prevent case that both bits are cleared.
1826 * At the end of load/unload driver checks that
Yuval Mintz2de67432013-01-23 03:21:43 +00001827 * sp_state is cleared, and this order prevents
Barak Witkowskia3348722012-04-23 03:04:46 +00001828 * races
1829 */
1830 smp_mb__before_clear_bit();
1831 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1832 wmb();
1833 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1834 smp_mb__after_clear_bit();
1835
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001836 /* schedule the sp task as mcp ack is required */
1837 bnx2x_schedule_sp_task(bp);
Barak Witkowskia3348722012-04-23 03:04:46 +00001838 }
1839
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001840 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001841}
1842
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001843irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001844{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001845 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001846 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001847 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -07001848 int i;
Ariel Elior6383c0b2011-07-14 08:31:57 +00001849 u8 cos;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001850
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001851 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001852 if (unlikely(status == 0)) {
1853 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1854 return IRQ_NONE;
1855 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001856 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001857
Eilon Greenstein3196a882008-08-13 15:58:49 -07001858#ifdef BNX2X_STOP_ON_ERROR
1859 if (unlikely(bp->panic))
1860 return IRQ_HANDLED;
1861#endif
1862
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001863 for_each_eth_queue(bp, i) {
Eilon Greensteinca003922009-08-12 22:53:28 -07001864 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001865
Merav Sicron55c11942012-11-07 00:45:48 +00001866 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
Eilon Greensteinca003922009-08-12 22:53:28 -07001867 if (status & mask) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001868 /* Handle Rx or Tx according to SB id */
Ariel Elior6383c0b2011-07-14 08:31:57 +00001869 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00001870 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001871 prefetch(&fp->sb_running_index[SM_RX_ID]);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001872 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eilon Greensteinca003922009-08-12 22:53:28 -07001873 status &= ~mask;
1874 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001875 }
1876
Merav Sicron55c11942012-11-07 00:45:48 +00001877 if (CNIC_SUPPORT(bp)) {
1878 mask = 0x2;
1879 if (status & (mask | 0x1)) {
1880 struct cnic_ops *c_ops = NULL;
Michael Chan993ac7b2009-10-10 13:46:56 +00001881
Michael Chanad9b4352013-01-23 03:21:52 +00001882 rcu_read_lock();
1883 c_ops = rcu_dereference(bp->cnic_ops);
1884 if (c_ops && (bp->cnic_eth_dev.drv_state &
1885 CNIC_DRV_STATE_HANDLES_IRQ))
1886 c_ops->cnic_handler(bp->cnic_data, NULL);
1887 rcu_read_unlock();
Merav Sicron55c11942012-11-07 00:45:48 +00001888
1889 status &= ~mask;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001890 }
Michael Chan993ac7b2009-10-10 13:46:56 +00001891 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001892
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001893 if (unlikely(status & 0x1)) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001894
1895 /* schedule sp task to perform default status block work, ack
1896 * attentions and enable interrupts.
1897 */
1898 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001899
1900 status &= ~0x1;
1901 if (!status)
1902 return IRQ_HANDLED;
1903 }
1904
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001905 if (unlikely(status))
1906 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001907 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001908
1909 return IRQ_HANDLED;
1910}
1911
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001912/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001913
1914/*
1915 * General service functions
1916 */
1917
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001918int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001919{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001920 u32 lock_status;
1921 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001922 int func = BP_FUNC(bp);
1923 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001924 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001925
1926 /* Validating that the resource is within range */
1927 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001928 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001929 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1930 return -EINVAL;
1931 }
1932
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001933 if (func <= 5) {
1934 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1935 } else {
1936 hw_lock_control_reg =
1937 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1938 }
1939
Eliezer Tamirf1410642008-02-28 11:51:50 -08001940 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001941 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001942 if (lock_status & resource_bit) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001943 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001944 lock_status, resource_bit);
1945 return -EEXIST;
1946 }
1947
Eilon Greenstein46230476b2008-08-25 15:23:30 -07001948 /* Try for 5 second every 5ms */
1949 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001950 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001951 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1952 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001953 if (lock_status & resource_bit)
1954 return 0;
1955
Yuval Mintz639d65b2013-06-02 00:06:21 +00001956 usleep_range(5000, 10000);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001957 }
Merav Sicron51c1a582012-03-18 10:33:38 +00001958 BNX2X_ERR("Timeout\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -08001959 return -EAGAIN;
1960}
1961
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001962int bnx2x_release_leader_lock(struct bnx2x *bp)
1963{
1964 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1965}
1966
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001967int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001968{
1969 u32 lock_status;
1970 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001971 int func = BP_FUNC(bp);
1972 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001973
1974 /* Validating that the resource is within range */
1975 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001976 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001977 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1978 return -EINVAL;
1979 }
1980
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001981 if (func <= 5) {
1982 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1983 } else {
1984 hw_lock_control_reg =
1985 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1986 }
1987
Eliezer Tamirf1410642008-02-28 11:51:50 -08001988 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001989 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001990 if (!(lock_status & resource_bit)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001991 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
1992 lock_status, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001993 return -EFAULT;
1994 }
1995
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001996 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001997 return 0;
1998}
1999
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002000int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2001{
2002 /* The GPIO should be swapped if swap register is set and active */
2003 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2004 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2005 int gpio_shift = gpio_num +
2006 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2007 u32 gpio_mask = (1 << gpio_shift);
2008 u32 gpio_reg;
2009 int value;
2010
2011 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2012 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2013 return -EINVAL;
2014 }
2015
2016 /* read GPIO value */
2017 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2018
2019 /* get the requested pin value */
2020 if ((gpio_reg & gpio_mask) == gpio_mask)
2021 value = 1;
2022 else
2023 value = 0;
2024
2025 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2026
2027 return value;
2028}
2029
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002030int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002031{
2032 /* The GPIO should be swapped if swap register is set and active */
2033 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002034 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002035 int gpio_shift = gpio_num +
2036 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2037 u32 gpio_mask = (1 << gpio_shift);
2038 u32 gpio_reg;
2039
2040 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2041 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2042 return -EINVAL;
2043 }
2044
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002045 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002046 /* read GPIO and mask except the float bits */
2047 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
2048
2049 switch (mode) {
2050 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
Merav Sicron51c1a582012-03-18 10:33:38 +00002051 DP(NETIF_MSG_LINK,
2052 "Set GPIO %d (shift %d) -> output low\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002053 gpio_num, gpio_shift);
2054 /* clear FLOAT and set CLR */
2055 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2056 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2057 break;
2058
2059 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
Merav Sicron51c1a582012-03-18 10:33:38 +00002060 DP(NETIF_MSG_LINK,
2061 "Set GPIO %d (shift %d) -> output high\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002062 gpio_num, gpio_shift);
2063 /* clear FLOAT and set SET */
2064 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2065 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2066 break;
2067
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002068 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Merav Sicron51c1a582012-03-18 10:33:38 +00002069 DP(NETIF_MSG_LINK,
2070 "Set GPIO %d (shift %d) -> input\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002071 gpio_num, gpio_shift);
2072 /* set FLOAT */
2073 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2074 break;
2075
2076 default:
2077 break;
2078 }
2079
2080 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002081 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002082
2083 return 0;
2084}
2085
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00002086int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2087{
2088 u32 gpio_reg = 0;
2089 int rc = 0;
2090
2091 /* Any port swapping should be handled by caller. */
2092
2093 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2094 /* read GPIO and mask except the float bits */
2095 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2096 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2097 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2098 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2099
2100 switch (mode) {
2101 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2102 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2103 /* set CLR */
2104 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2105 break;
2106
2107 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2108 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2109 /* set SET */
2110 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2111 break;
2112
2113 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2114 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2115 /* set FLOAT */
2116 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2117 break;
2118
2119 default:
2120 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2121 rc = -EINVAL;
2122 break;
2123 }
2124
2125 if (rc == 0)
2126 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2127
2128 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2129
2130 return rc;
2131}
2132
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002133int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2134{
2135 /* The GPIO should be swapped if swap register is set and active */
2136 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2137 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2138 int gpio_shift = gpio_num +
2139 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2140 u32 gpio_mask = (1 << gpio_shift);
2141 u32 gpio_reg;
2142
2143 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2144 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2145 return -EINVAL;
2146 }
2147
2148 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2149 /* read GPIO int */
2150 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2151
2152 switch (mode) {
2153 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
Merav Sicron51c1a582012-03-18 10:33:38 +00002154 DP(NETIF_MSG_LINK,
2155 "Clear GPIO INT %d (shift %d) -> output low\n",
2156 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002157 /* clear SET and set CLR */
2158 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2159 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2160 break;
2161
2162 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
Merav Sicron51c1a582012-03-18 10:33:38 +00002163 DP(NETIF_MSG_LINK,
2164 "Set GPIO INT %d (shift %d) -> output high\n",
2165 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002166 /* clear CLR and set SET */
2167 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2168 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2169 break;
2170
2171 default:
2172 break;
2173 }
2174
2175 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2176 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2177
2178 return 0;
2179}
2180
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002181static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002182{
Eliezer Tamirf1410642008-02-28 11:51:50 -08002183 u32 spio_reg;
2184
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002185 /* Only 2 SPIOs are configurable */
2186 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2187 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002188 return -EINVAL;
2189 }
2190
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002191 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002192 /* read SPIO and mask except the float bits */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002193 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002194
2195 switch (mode) {
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002196 case MISC_SPIO_OUTPUT_LOW:
2197 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002198 /* clear FLOAT and set CLR */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002199 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2200 spio_reg |= (spio << MISC_SPIO_CLR_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002201 break;
2202
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002203 case MISC_SPIO_OUTPUT_HIGH:
2204 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002205 /* clear FLOAT and set SET */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002206 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2207 spio_reg |= (spio << MISC_SPIO_SET_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002208 break;
2209
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002210 case MISC_SPIO_INPUT_HI_Z:
2211 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002212 /* set FLOAT */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002213 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002214 break;
2215
2216 default:
2217 break;
2218 }
2219
2220 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002221 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002222
2223 return 0;
2224}
2225
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002226void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002227{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002228 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002229 switch (bp->link_vars.ieee_fc &
2230 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002231 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002232 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002233 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002234 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002235
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002236 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002237 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002238 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002239 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002240
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002241 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002242 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002243 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002244
Eliezer Tamirf1410642008-02-28 11:51:50 -08002245 default:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002246 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002247 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002248 break;
2249 }
2250}
2251
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002252static void bnx2x_set_requested_fc(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002253{
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002254 /* Initialize link parameters structure variables
2255 * It is recommended to turn off RX FC for jumbo frames
2256 * for better performance
2257 */
2258 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2259 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2260 else
2261 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2262}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002263
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002264int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2265{
2266 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2267 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2268
2269 if (!BP_NOMCP(bp)) {
2270 bnx2x_set_requested_fc(bp);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002271 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002272
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002273 if (load_mode == LOAD_DIAG) {
Yaniv Rosner1cb0c782011-07-24 03:53:21 +00002274 struct link_params *lp = &bp->link_params;
2275 lp->loopback_mode = LOOPBACK_XGXS;
2276 /* do PHY loopback at 10G speed, if possible */
2277 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2278 if (lp->speed_cap_mask[cfx_idx] &
2279 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2280 lp->req_line_speed[cfx_idx] =
2281 SPEED_10000;
2282 else
2283 lp->req_line_speed[cfx_idx] =
2284 SPEED_1000;
2285 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002286 }
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002287
Merav Sicron8970b2e2012-06-19 07:48:22 +00002288 if (load_mode == LOAD_LOOPBACK_EXT) {
2289 struct link_params *lp = &bp->link_params;
2290 lp->loopback_mode = LOOPBACK_EXT;
2291 }
2292
Eilon Greenstein19680c42008-08-13 15:47:33 -07002293 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002294
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002295 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002296
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002297 bnx2x_calc_fc_adv(bp);
2298
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002299 if (bp->link_vars.link_up) {
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002300 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002301 bnx2x_link_report(bp);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002302 }
2303 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002304 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
Eilon Greenstein19680c42008-08-13 15:47:33 -07002305 return rc;
2306 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002307 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002308 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002309}
2310
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002311void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002312{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002313 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002314 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002315 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002316 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002317
Eilon Greenstein19680c42008-08-13 15:47:33 -07002318 bnx2x_calc_fc_adv(bp);
2319 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002320 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002321}
2322
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002323static void bnx2x__link_reset(struct bnx2x *bp)
2324{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002325 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002326 bnx2x_acquire_phy_lock(bp);
Yuval Mintz5d07d862012-09-13 02:56:21 +00002327 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002328 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002329 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002330 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002331}
2332
Yuval Mintz5d07d862012-09-13 02:56:21 +00002333void bnx2x_force_link_reset(struct bnx2x *bp)
2334{
2335 bnx2x_acquire_phy_lock(bp);
2336 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2337 bnx2x_release_phy_lock(bp);
2338}
2339
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002340u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002341{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002342 u8 rc = 0;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002343
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002344 if (!BP_NOMCP(bp)) {
2345 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002346 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2347 is_serdes);
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002348 bnx2x_release_phy_lock(bp);
2349 } else
2350 BNX2X_ERR("Bootcode is missing - can not test link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002351
2352 return rc;
2353}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002354
Eilon Greenstein2691d512009-08-12 08:22:08 +00002355/* Calculates the sum of vn_min_rates.
2356 It's needed for further normalizing of the min_rates.
2357 Returns:
2358 sum of vn_min_rates.
2359 or
2360 0 - if all the min_rates are 0.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002361 In the later case fairness algorithm should be deactivated.
Eilon Greenstein2691d512009-08-12 08:22:08 +00002362 If not all min_rates are zero then those that are zeroes will be set to 1.
2363 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002364static void bnx2x_calc_vn_min(struct bnx2x *bp,
2365 struct cmng_init_input *input)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002366{
2367 int all_zero = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002368 int vn;
2369
David S. Miller8decf862011-09-22 03:23:13 -04002370 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002371 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein2691d512009-08-12 08:22:08 +00002372 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2373 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2374
2375 /* Skip hidden vns */
2376 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Yuval Mintzb475d782012-04-03 18:41:29 +00002377 vn_min_rate = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002378 /* If min rate is zero - set it to 1 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002379 else if (!vn_min_rate)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002380 vn_min_rate = DEF_MIN_RATE;
2381 else
2382 all_zero = 0;
2383
Yuval Mintzb475d782012-04-03 18:41:29 +00002384 input->vnic_min_rate[vn] = vn_min_rate;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002385 }
2386
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002387 /* if ETS or all min rates are zeros - disable fairness */
2388 if (BNX2X_IS_ETS_ENABLED(bp)) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002389 input->flags.cmng_enables &=
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002390 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2391 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2392 } else if (all_zero) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002393 input->flags.cmng_enables &=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002394 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002395 DP(NETIF_MSG_IFUP,
2396 "All MIN values are zeroes fairness will be disabled\n");
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002397 } else
Yuval Mintzb475d782012-04-03 18:41:29 +00002398 input->flags.cmng_enables |=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002399 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002400}
2401
Yuval Mintzb475d782012-04-03 18:41:29 +00002402static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2403 struct cmng_init_input *input)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002404{
Yuval Mintzb475d782012-04-03 18:41:29 +00002405 u16 vn_max_rate;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002406 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002407
Yuval Mintzb475d782012-04-03 18:41:29 +00002408 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002409 vn_max_rate = 0;
Yuval Mintzb475d782012-04-03 18:41:29 +00002410 else {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002411 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2412
Yuval Mintzb475d782012-04-03 18:41:29 +00002413 if (IS_MF_SI(bp)) {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002414 /* maxCfg in percents of linkspeed */
2415 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
Yuval Mintzb475d782012-04-03 18:41:29 +00002416 } else /* SD modes */
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002417 /* maxCfg is absolute in 100Mb units */
2418 vn_max_rate = maxCfg * 100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002419 }
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002420
Yuval Mintzb475d782012-04-03 18:41:29 +00002421 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002422
Yuval Mintzb475d782012-04-03 18:41:29 +00002423 input->vnic_max_rate[vn] = vn_max_rate;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002424}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002425
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002426static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2427{
2428 if (CHIP_REV_IS_SLOW(bp))
2429 return CMNG_FNS_NONE;
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00002430 if (IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002431 return CMNG_FNS_MINMAX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002432
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002433 return CMNG_FNS_NONE;
2434}
2435
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002436void bnx2x_read_mf_cfg(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002437{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002438 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002439
2440 if (BP_NOMCP(bp))
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002441 return; /* what should be the default value in this case */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002442
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002443 /* For 2 port configuration the absolute function number formula
2444 * is:
2445 * abs_func = 2 * vn + BP_PORT + BP_PATH
2446 *
2447 * and there are 4 functions per port
2448 *
2449 * For 4 port configuration it is
2450 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2451 *
2452 * and there are 2 functions per port
2453 */
David S. Miller8decf862011-09-22 03:23:13 -04002454 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002455 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2456
2457 if (func >= E1H_FUNC_MAX)
2458 break;
2459
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002460 bp->mf_config[vn] =
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002461 MF_CFG_RD(bp, func_mf_config[func].config);
2462 }
Barak Witkowskia3348722012-04-23 03:04:46 +00002463 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2464 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2465 bp->flags |= MF_FUNC_DIS;
2466 } else {
2467 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2468 bp->flags &= ~MF_FUNC_DIS;
2469 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002470}
2471
2472static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2473{
Yuval Mintzb475d782012-04-03 18:41:29 +00002474 struct cmng_init_input input;
2475 memset(&input, 0, sizeof(struct cmng_init_input));
2476
2477 input.port_rate = bp->link_vars.line_speed;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002478
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002479 if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002480 int vn;
2481
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002482 /* read mf conf from shmem */
2483 if (read_cfg)
2484 bnx2x_read_mf_cfg(bp);
2485
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002486 /* vn_weight_sum and enable fairness if not 0 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002487 bnx2x_calc_vn_min(bp, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002488
2489 /* calculate and set min-max rate for each vn */
Dmitry Kravkovc4154f22011-03-06 10:49:25 +00002490 if (bp->port.pmf)
David S. Miller8decf862011-09-22 03:23:13 -04002491 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
Yuval Mintzb475d782012-04-03 18:41:29 +00002492 bnx2x_calc_vn_max(bp, vn, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002493
2494 /* always enable rate shaping and fairness */
Yuval Mintzb475d782012-04-03 18:41:29 +00002495 input.flags.cmng_enables |=
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002496 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002497
2498 bnx2x_init_cmng(&input, &bp->cmng);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002499 return;
2500 }
2501
2502 /* rate shaping and fairness are disabled */
2503 DP(NETIF_MSG_IFUP,
2504 "rate shaping and fairness are disabled\n");
2505}
2506
Eric Dumazet1191cb82012-04-27 21:39:21 +00002507static void storm_memset_cmng(struct bnx2x *bp,
2508 struct cmng_init *cmng,
2509 u8 port)
2510{
2511 int vn;
2512 size_t size = sizeof(struct cmng_struct_per_port);
2513
2514 u32 addr = BAR_XSTRORM_INTMEM +
2515 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2516
2517 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2518
2519 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2520 int func = func_by_vn(bp, vn);
2521
2522 addr = BAR_XSTRORM_INTMEM +
2523 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2524 size = sizeof(struct rate_shaping_vars_per_vn);
2525 __storm_memset_struct(bp, addr, size,
2526 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2527
2528 addr = BAR_XSTRORM_INTMEM +
2529 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2530 size = sizeof(struct fairness_vars_per_vn);
2531 __storm_memset_struct(bp, addr, size,
2532 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2533 }
2534}
2535
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002536/* init cmng mode in HW according to local configuration */
2537void bnx2x_set_local_cmng(struct bnx2x *bp)
2538{
2539 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2540
2541 if (cmng_fns != CMNG_FNS_NONE) {
2542 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2543 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2544 } else {
2545 /* rate shaping and fairness are disabled */
2546 DP(NETIF_MSG_IFUP,
2547 "single function mode without fairness\n");
2548 }
2549}
2550
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002551/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002552static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002553{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002554 /* Make sure that we are synced with the current statistics */
2555 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2556
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002557 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002558
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002559 if (bp->link_vars.link_up) {
2560
Eilon Greenstein1c063282009-02-12 08:36:43 +00002561 /* dropless flow control */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002562 if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
Eilon Greenstein1c063282009-02-12 08:36:43 +00002563 int port = BP_PORT(bp);
2564 u32 pause_enabled = 0;
2565
2566 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2567 pause_enabled = 1;
2568
2569 REG_WR(bp, BAR_USTRORM_INTMEM +
Eilon Greensteinca003922009-08-12 22:53:28 -07002570 USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
Eilon Greenstein1c063282009-02-12 08:36:43 +00002571 pause_enabled);
2572 }
2573
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002574 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002575 struct host_port_stats *pstats;
2576
2577 pstats = bnx2x_sp(bp, port_stats);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002578 /* reset old mac stats */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002579 memset(&(pstats->mac_stx[0]), 0,
2580 sizeof(struct mac_stx));
2581 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002582 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002583 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2584 }
2585
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002586 if (bp->link_vars.link_up && bp->link_vars.line_speed)
2587 bnx2x_set_local_cmng(bp);
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002588
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002589 __bnx2x_link_report(bp);
2590
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002591 if (IS_MF(bp))
2592 bnx2x_link_sync_notify(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002593}
2594
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002595void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002596{
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002597 if (bp->state != BNX2X_STATE_OPEN)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002598 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002599
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002600 /* read updated dcb configuration */
Ariel Eliorad5afc82013-01-01 05:22:26 +00002601 if (IS_PF(bp)) {
2602 bnx2x_dcbx_pmf_update(bp);
2603 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2604 if (bp->link_vars.link_up)
2605 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2606 else
2607 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2608 /* indicate link status */
2609 bnx2x_link_report(bp);
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002610
Ariel Eliorad5afc82013-01-01 05:22:26 +00002611 } else { /* VF */
2612 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2613 SUPPORTED_10baseT_Full |
2614 SUPPORTED_100baseT_Half |
2615 SUPPORTED_100baseT_Full |
2616 SUPPORTED_1000baseT_Full |
2617 SUPPORTED_2500baseX_Full |
2618 SUPPORTED_10000baseT_Full |
2619 SUPPORTED_TP |
2620 SUPPORTED_FIBRE |
2621 SUPPORTED_Autoneg |
2622 SUPPORTED_Pause |
2623 SUPPORTED_Asym_Pause);
2624 bp->port.advertising[0] = bp->port.supported[0];
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002625
Ariel Eliorad5afc82013-01-01 05:22:26 +00002626 bp->link_params.bp = bp;
2627 bp->link_params.port = BP_PORT(bp);
2628 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2629 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2630 bp->link_params.req_line_speed[0] = SPEED_10000;
2631 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2632 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2633 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2634 bp->link_vars.line_speed = SPEED_10000;
2635 bp->link_vars.link_status =
2636 (LINK_STATUS_LINK_UP |
2637 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2638 bp->link_vars.link_up = 1;
2639 bp->link_vars.duplex = DUPLEX_FULL;
2640 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2641 __bnx2x_link_report(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002642 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Ariel Eliorad5afc82013-01-01 05:22:26 +00002643 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002644}
2645
Barak Witkowskia3348722012-04-23 03:04:46 +00002646static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2647 u16 vlan_val, u8 allowed_prio)
2648{
Yuval Mintz86564c32013-01-23 03:21:50 +00002649 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002650 struct bnx2x_func_afex_update_params *f_update_params =
2651 &func_params.params.afex_update;
2652
2653 func_params.f_obj = &bp->func_obj;
2654 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2655
2656 /* no need to wait for RAMROD completion, so don't
2657 * set RAMROD_COMP_WAIT flag
2658 */
2659
2660 f_update_params->vif_id = vifid;
2661 f_update_params->afex_default_vlan = vlan_val;
2662 f_update_params->allowed_priorities = allowed_prio;
2663
2664 /* if ramrod can not be sent, response to MCP immediately */
2665 if (bnx2x_func_state_change(bp, &func_params) < 0)
2666 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2667
2668 return 0;
2669}
2670
2671static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2672 u16 vif_index, u8 func_bit_map)
2673{
Yuval Mintz86564c32013-01-23 03:21:50 +00002674 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002675 struct bnx2x_func_afex_viflists_params *update_params =
2676 &func_params.params.afex_viflists;
2677 int rc;
2678 u32 drv_msg_code;
2679
2680 /* validate only LIST_SET and LIST_GET are received from switch */
2681 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2682 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2683 cmd_type);
2684
2685 func_params.f_obj = &bp->func_obj;
2686 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2687
2688 /* set parameters according to cmd_type */
2689 update_params->afex_vif_list_command = cmd_type;
Yuval Mintz86564c32013-01-23 03:21:50 +00002690 update_params->vif_list_index = vif_index;
Barak Witkowskia3348722012-04-23 03:04:46 +00002691 update_params->func_bit_map =
2692 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2693 update_params->func_to_clear = 0;
2694 drv_msg_code =
2695 (cmd_type == VIF_LIST_RULE_GET) ?
2696 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2697 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2698
2699 /* if ramrod can not be sent, respond to MCP immediately for
2700 * SET and GET requests (other are not triggered from MCP)
2701 */
2702 rc = bnx2x_func_state_change(bp, &func_params);
2703 if (rc < 0)
2704 bnx2x_fw_command(bp, drv_msg_code, 0);
2705
2706 return 0;
2707}
2708
2709static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2710{
2711 struct afex_stats afex_stats;
2712 u32 func = BP_ABS_FUNC(bp);
2713 u32 mf_config;
2714 u16 vlan_val;
2715 u32 vlan_prio;
2716 u16 vif_id;
2717 u8 allowed_prio;
2718 u8 vlan_mode;
2719 u32 addr_to_write, vifid, addrs, stats_type, i;
2720
2721 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2722 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2723 DP(BNX2X_MSG_MCP,
2724 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2725 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2726 }
2727
2728 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2729 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2730 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2731 DP(BNX2X_MSG_MCP,
2732 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2733 vifid, addrs);
2734 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2735 addrs);
2736 }
2737
2738 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2739 addr_to_write = SHMEM2_RD(bp,
2740 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2741 stats_type = SHMEM2_RD(bp,
2742 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2743
2744 DP(BNX2X_MSG_MCP,
2745 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2746 addr_to_write);
2747
2748 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2749
2750 /* write response to scratchpad, for MCP */
2751 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2752 REG_WR(bp, addr_to_write + i*sizeof(u32),
2753 *(((u32 *)(&afex_stats))+i));
2754
2755 /* send ack message to MCP */
2756 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2757 }
2758
2759 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2760 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2761 bp->mf_config[BP_VN(bp)] = mf_config;
2762 DP(BNX2X_MSG_MCP,
2763 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2764 mf_config);
2765
2766 /* if VIF_SET is "enabled" */
2767 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2768 /* set rate limit directly to internal RAM */
2769 struct cmng_init_input cmng_input;
2770 struct rate_shaping_vars_per_vn m_rs_vn;
2771 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2772 u32 addr = BAR_XSTRORM_INTMEM +
2773 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2774
2775 bp->mf_config[BP_VN(bp)] = mf_config;
2776
2777 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2778 m_rs_vn.vn_counter.rate =
2779 cmng_input.vnic_max_rate[BP_VN(bp)];
2780 m_rs_vn.vn_counter.quota =
2781 (m_rs_vn.vn_counter.rate *
2782 RS_PERIODIC_TIMEOUT_USEC) / 8;
2783
2784 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2785
2786 /* read relevant values from mf_cfg struct in shmem */
2787 vif_id =
2788 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2789 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2790 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2791 vlan_val =
2792 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2793 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2794 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2795 vlan_prio = (mf_config &
2796 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2797 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2798 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2799 vlan_mode =
2800 (MF_CFG_RD(bp,
2801 func_mf_config[func].afex_config) &
2802 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2803 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2804 allowed_prio =
2805 (MF_CFG_RD(bp,
2806 func_mf_config[func].afex_config) &
2807 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2808 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2809
2810 /* send ramrod to FW, return in case of failure */
2811 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2812 allowed_prio))
2813 return;
2814
2815 bp->afex_def_vlan_tag = vlan_val;
2816 bp->afex_vlan_mode = vlan_mode;
2817 } else {
2818 /* notify link down because BP->flags is disabled */
2819 bnx2x_link_report(bp);
2820
2821 /* send INVALID VIF ramrod to FW */
2822 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2823
2824 /* Reset the default afex VLAN */
2825 bp->afex_def_vlan_tag = -1;
2826 }
2827 }
2828}
2829
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002830static void bnx2x_pmf_update(struct bnx2x *bp)
2831{
2832 int port = BP_PORT(bp);
2833 u32 val;
2834
2835 bp->port.pmf = 1;
Merav Sicron51c1a582012-03-18 10:33:38 +00002836 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002837
Yaniv Rosner3deb8162011-06-14 01:34:33 +00002838 /*
2839 * We need the mb() to ensure the ordering between the writing to
2840 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2841 */
2842 smp_mb();
2843
2844 /* queue a periodic task */
2845 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2846
Dmitry Kravkovef018542011-06-14 01:33:57 +00002847 bnx2x_dcbx_pmf_update(bp);
2848
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002849 /* enable nig attention */
David S. Miller8decf862011-09-22 03:23:13 -04002850 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002851 if (bp->common.int_block == INT_BLOCK_HC) {
2852 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2853 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002854 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002855 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2856 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2857 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002858
2859 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002860}
2861
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002862/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002863
2864/* slow path */
2865
2866/*
2867 * General service functions
2868 */
2869
Eilon Greenstein2691d512009-08-12 08:22:08 +00002870/* send the MCP a request, block until there is a reply */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002871u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002872{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002873 int mb_idx = BP_FW_MB_IDX(bp);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002874 u32 seq;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002875 u32 rc = 0;
2876 u32 cnt = 1;
2877 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2878
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002879 mutex_lock(&bp->fw_mb_mutex);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002880 seq = ++bp->fw_seq;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002881 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2882 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2883
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00002884 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2885 (command | seq), param);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002886
2887 do {
2888 /* let the FW do it's magic ... */
2889 msleep(delay);
2890
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002891 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002892
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002893 /* Give the FW up to 5 second (500*10ms) */
2894 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002895
2896 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2897 cnt*delay, rc, seq);
2898
2899 /* is this a reply to our command? */
2900 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2901 rc &= FW_MSG_CODE_MASK;
2902 else {
2903 /* FW BUG! */
2904 BNX2X_ERR("FW failed to respond!\n");
2905 bnx2x_fw_dump(bp);
2906 rc = 0;
2907 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002908 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002909
2910 return rc;
2911}
2912
Eric Dumazet1191cb82012-04-27 21:39:21 +00002913static void storm_memset_func_cfg(struct bnx2x *bp,
2914 struct tstorm_eth_function_common_config *tcfg,
2915 u16 abs_fid)
2916{
2917 size_t size = sizeof(struct tstorm_eth_function_common_config);
2918
2919 u32 addr = BAR_TSTRORM_INTMEM +
2920 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2921
2922 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2923}
2924
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002925void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002926{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002927 if (CHIP_IS_E1x(bp)) {
2928 struct tstorm_eth_function_common_config tcfg = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002929
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002930 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2931 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002932
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002933 /* Enable the function in the FW */
2934 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2935 storm_memset_func_en(bp, p->func_id, 1);
2936
2937 /* spq */
2938 if (p->func_flgs & FUNC_FLG_SPQ) {
2939 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
2940 REG_WR(bp, XSEM_REG_FAST_MEMORY +
2941 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
2942 }
2943}
2944
Ariel Elior6383c0b2011-07-14 08:31:57 +00002945/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002946 * bnx2x_get_common_flags - Return common flags
Ariel Elior6383c0b2011-07-14 08:31:57 +00002947 *
2948 * @bp device handle
2949 * @fp queue handle
2950 * @zero_stats TRUE if statistics zeroing is needed
2951 *
2952 * Return the flags that are common for the Tx-only and not normal connections.
2953 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00002954static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
2955 struct bnx2x_fastpath *fp,
2956 bool zero_stats)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002957{
2958 unsigned long flags = 0;
2959
2960 /* PF driver will always initialize the Queue to an ACTIVE state */
2961 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
2962
Ariel Elior6383c0b2011-07-14 08:31:57 +00002963 /* tx only connections collect statistics (on the same index as the
Dmitry Kravkov91226792013-03-11 05:17:52 +00002964 * parent connection). The statistics are zeroed when the parent
2965 * connection is initialized.
Ariel Elior6383c0b2011-07-14 08:31:57 +00002966 */
Barak Witkowski50f0a562011-12-05 21:52:23 +00002967
2968 __set_bit(BNX2X_Q_FLG_STATS, &flags);
2969 if (zero_stats)
2970 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
2971
Dmitry Kravkov91226792013-03-11 05:17:52 +00002972 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
Dmitry Kravkove287a752013-03-21 15:38:24 +00002973 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
Ariel Elior6383c0b2011-07-14 08:31:57 +00002974
Yuval Mintz823e1d92013-01-14 05:11:47 +00002975#ifdef BNX2X_STOP_ON_ERROR
2976 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
2977#endif
2978
Ariel Elior6383c0b2011-07-14 08:31:57 +00002979 return flags;
2980}
2981
Eric Dumazet1191cb82012-04-27 21:39:21 +00002982static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
2983 struct bnx2x_fastpath *fp,
2984 bool leading)
Ariel Elior6383c0b2011-07-14 08:31:57 +00002985{
2986 unsigned long flags = 0;
2987
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002988 /* calculate other queue flags */
2989 if (IS_MF_SD(bp))
2990 __set_bit(BNX2X_Q_FLG_OV, &flags);
2991
Barak Witkowskia3348722012-04-23 03:04:46 +00002992 if (IS_FCOE_FP(fp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002993 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00002994 /* For FCoE - force usage of default priority (for afex) */
2995 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
2996 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002997
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00002998 if (!fp->disable_tpa) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002999 __set_bit(BNX2X_Q_FLG_TPA, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003000 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00003001 if (fp->mode == TPA_MODE_GRO)
3002 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003003 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003004
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003005 if (leading) {
3006 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3007 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3008 }
3009
3010 /* Always set HW VLAN stripping */
3011 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003012
Barak Witkowskia3348722012-04-23 03:04:46 +00003013 /* configure silent vlan removal */
3014 if (IS_MF_AFEX(bp))
3015 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3016
Ariel Elior6383c0b2011-07-14 08:31:57 +00003017 return flags | bnx2x_get_common_flags(bp, fp, true);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003018}
3019
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003020static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003021 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3022 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003023{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003024 gen_init->stat_id = bnx2x_stats_id(fp);
3025 gen_init->spcl_id = fp->cl_id;
3026
3027 /* Always use mini-jumbo MTU for FCoE L2 ring */
3028 if (IS_FCOE_FP(fp))
3029 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3030 else
3031 gen_init->mtu = bp->dev->mtu;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003032
3033 gen_init->cos = cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003034}
3035
3036static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
3037 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
3038 struct bnx2x_rxq_setup_params *rxq_init)
3039{
3040 u8 max_sge = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003041 u16 sge_sz = 0;
3042 u16 tpa_agg_size = 0;
3043
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003044 if (!fp->disable_tpa) {
David S. Miller8decf862011-09-22 03:23:13 -04003045 pause->sge_th_lo = SGE_TH_LO(bp);
3046 pause->sge_th_hi = SGE_TH_HI(bp);
3047
3048 /* validate SGE ring has enough to cross high threshold */
3049 WARN_ON(bp->dropless_fc &&
3050 pause->sge_th_hi + FW_PREFETCH_CNT >
3051 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3052
Yuval Mintz924d75a2013-01-23 03:21:44 +00003053 tpa_agg_size = TPA_AGG_SIZE;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003054 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3055 SGE_PAGE_SHIFT;
3056 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3057 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
Yuval Mintz924d75a2013-01-23 03:21:44 +00003058 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003059 }
3060
3061 /* pause - not for e1 */
3062 if (!CHIP_IS_E1(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04003063 pause->bd_th_lo = BD_TH_LO(bp);
3064 pause->bd_th_hi = BD_TH_HI(bp);
3065
3066 pause->rcq_th_lo = RCQ_TH_LO(bp);
3067 pause->rcq_th_hi = RCQ_TH_HI(bp);
3068 /*
3069 * validate that rings have enough entries to cross
3070 * high thresholds
3071 */
3072 WARN_ON(bp->dropless_fc &&
3073 pause->bd_th_hi + FW_PREFETCH_CNT >
3074 bp->rx_ring_size);
3075 WARN_ON(bp->dropless_fc &&
3076 pause->rcq_th_hi + FW_PREFETCH_CNT >
3077 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003078
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003079 pause->pri_map = 1;
3080 }
3081
3082 /* rxq setup */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003083 rxq_init->dscr_map = fp->rx_desc_mapping;
3084 rxq_init->sge_map = fp->rx_sge_mapping;
3085 rxq_init->rcq_map = fp->rx_comp_mapping;
3086 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003087
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003088 /* This should be a maximum number of data bytes that may be
3089 * placed on the BD (not including paddings).
3090 */
Eric Dumazete52fcb22011-11-14 06:05:34 +00003091 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003092 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003093
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003094 rxq_init->cl_qzone_id = fp->cl_qzone_id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003095 rxq_init->tpa_agg_sz = tpa_agg_size;
3096 rxq_init->sge_buf_sz = sge_sz;
3097 rxq_init->max_sges_pkt = max_sge;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003098 rxq_init->rss_engine_id = BP_FUNC(bp);
Yuval Mintz259afa12012-03-12 08:53:10 +00003099 rxq_init->mcast_engine_id = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003100
3101 /* Maximum number or simultaneous TPA aggregation for this Queue.
3102 *
Yuval Mintz2de67432013-01-23 03:21:43 +00003103 * For PF Clients it should be the maximum available number.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003104 * VF driver(s) may want to define it to a smaller value.
3105 */
David S. Miller8decf862011-09-22 03:23:13 -04003106 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003107
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003108 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3109 rxq_init->fw_sb_id = fp->fw_sb_id;
3110
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003111 if (IS_FCOE_FP(fp))
3112 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3113 else
Ariel Elior6383c0b2011-07-14 08:31:57 +00003114 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
Barak Witkowskia3348722012-04-23 03:04:46 +00003115 /* configure silent vlan removal
3116 * if multi function mode is afex, then mask default vlan
3117 */
3118 if (IS_MF_AFEX(bp)) {
3119 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3120 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3121 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003122}
3123
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003124static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003125 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3126 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003127{
Merav Sicron65565882012-06-19 07:48:26 +00003128 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003129 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003130 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3131 txq_init->fw_sb_id = fp->fw_sb_id;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003132
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003133 /*
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003134 * set the tss leading client id for TX classification ==
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003135 * leading RSS client id
3136 */
3137 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3138
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003139 if (IS_FCOE_FP(fp)) {
3140 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3141 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3142 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003143}
3144
stephen hemminger8d962862010-10-21 07:50:56 +00003145static void bnx2x_pf_init(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003146{
3147 struct bnx2x_func_init_params func_init = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003148 struct event_ring_data eq_data = { {0} };
3149 u16 flags;
3150
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003151 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003152 /* reset IGU PF statistics: MSIX + ATTN */
3153 /* PF */
3154 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3155 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3156 (CHIP_MODE_IS_4_PORT(bp) ?
3157 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3158 /* ATTN */
3159 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3160 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3161 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3162 (CHIP_MODE_IS_4_PORT(bp) ?
3163 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3164 }
3165
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003166 /* function setup flags */
3167 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3168
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003169 /* This flag is relevant for E1x only.
3170 * E2 doesn't have a TPA configuration in a function level.
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003171 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003172 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003173
3174 func_init.func_flgs = flags;
3175 func_init.pf_id = BP_FUNC(bp);
3176 func_init.func_id = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003177 func_init.spq_map = bp->spq_mapping;
3178 func_init.spq_prod = bp->spq_prod_idx;
3179
3180 bnx2x_func_init(bp, &func_init);
3181
3182 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3183
3184 /*
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003185 * Congestion management values depend on the link rate
3186 * There is no active link so initial link rate is set to 10 Gbps.
3187 * When the link comes up The congestion management values are
3188 * re-calculated according to the actual link rate.
3189 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003190 bp->link_vars.line_speed = SPEED_10000;
3191 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3192
3193 /* Only the PMF sets the HW */
3194 if (bp->port.pmf)
3195 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3196
Yuval Mintz86564c32013-01-23 03:21:50 +00003197 /* init Event Queue - PCI bus guarantees correct endianity*/
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003198 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3199 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3200 eq_data.producer = bp->eq_prod;
3201 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3202 eq_data.sb_id = DEF_SB_ID;
3203 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3204}
3205
Eilon Greenstein2691d512009-08-12 08:22:08 +00003206static void bnx2x_e1h_disable(struct bnx2x *bp)
3207{
3208 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003209
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003210 bnx2x_tx_disable(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003211
3212 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003213}
3214
3215static void bnx2x_e1h_enable(struct bnx2x *bp)
3216{
3217 int port = BP_PORT(bp);
3218
3219 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3220
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003221 /* Tx queue should be only re-enabled */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003222 netif_tx_wake_all_queues(bp->dev);
3223
Eilon Greenstein061bc702009-10-15 00:18:47 -07003224 /*
3225 * Should not call netif_carrier_on since it will be called if the link
3226 * is up when checking for link state
3227 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003228}
3229
Barak Witkowski1d187b32011-12-05 22:41:50 +00003230#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3231
3232static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3233{
3234 struct eth_stats_info *ether_stat =
3235 &bp->slowpath->drv_info_to_mcp.ether_stat;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003236 struct bnx2x_vlan_mac_obj *mac_obj =
3237 &bp->sp_objs->mac_obj;
3238 int i;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003239
Dan Carpenter786fdf02012-10-02 01:47:46 +00003240 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3241 ETH_STAT_INFO_VERSION_LEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003242
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003243 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3244 * mac_local field in ether_stat struct. The base address is offset by 2
3245 * bytes to account for the field being 8 bytes but a mac address is
3246 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3247 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3248 * allocated by the ether_stat struct, so the macs will land in their
3249 * proper positions.
3250 */
3251 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3252 memset(ether_stat->mac_local + i, 0,
3253 sizeof(ether_stat->mac_local[0]));
3254 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3255 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3256 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3257 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003258 ether_stat->mtu_size = bp->dev->mtu;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003259 if (bp->dev->features & NETIF_F_RXCSUM)
3260 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3261 if (bp->dev->features & NETIF_F_TSO)
3262 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3263 ether_stat->feature_flags |= bp->common.boot_mode;
3264
3265 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3266
3267 ether_stat->txq_size = bp->tx_ring_size;
3268 ether_stat->rxq_size = bp->rx_ring_size;
3269}
3270
3271static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3272{
3273 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3274 struct fcoe_stats_info *fcoe_stat =
3275 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3276
Merav Sicron55c11942012-11-07 00:45:48 +00003277 if (!CNIC_LOADED(bp))
3278 return;
3279
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003280 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003281
3282 fcoe_stat->qos_priority =
3283 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3284
3285 /* insert FCoE stats from ramrod response */
3286 if (!NO_FCOE(bp)) {
3287 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003288 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003289 tstorm_queue_statistics;
3290
3291 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003292 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003293 xstorm_queue_statistics;
3294
3295 struct fcoe_statistics_params *fw_fcoe_stat =
3296 &bp->fw_stats_data->fcoe;
3297
Yuval Mintz86564c32013-01-23 03:21:50 +00003298 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3299 fcoe_stat->rx_bytes_lo,
3300 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003301
Yuval Mintz86564c32013-01-23 03:21:50 +00003302 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3303 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3304 fcoe_stat->rx_bytes_lo,
3305 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003306
Yuval Mintz86564c32013-01-23 03:21:50 +00003307 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3308 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3309 fcoe_stat->rx_bytes_lo,
3310 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003311
Yuval Mintz86564c32013-01-23 03:21:50 +00003312 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3313 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3314 fcoe_stat->rx_bytes_lo,
3315 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003316
Yuval Mintz86564c32013-01-23 03:21:50 +00003317 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3318 fcoe_stat->rx_frames_lo,
3319 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003320
Yuval Mintz86564c32013-01-23 03:21:50 +00003321 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3322 fcoe_stat->rx_frames_lo,
3323 fcoe_q_tstorm_stats->rcv_ucast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003324
Yuval Mintz86564c32013-01-23 03:21:50 +00003325 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3326 fcoe_stat->rx_frames_lo,
3327 fcoe_q_tstorm_stats->rcv_bcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003328
Yuval Mintz86564c32013-01-23 03:21:50 +00003329 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3330 fcoe_stat->rx_frames_lo,
3331 fcoe_q_tstorm_stats->rcv_mcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003332
Yuval Mintz86564c32013-01-23 03:21:50 +00003333 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3334 fcoe_stat->tx_bytes_lo,
3335 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003336
Yuval Mintz86564c32013-01-23 03:21:50 +00003337 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3338 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3339 fcoe_stat->tx_bytes_lo,
3340 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003341
Yuval Mintz86564c32013-01-23 03:21:50 +00003342 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3343 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3344 fcoe_stat->tx_bytes_lo,
3345 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003346
Yuval Mintz86564c32013-01-23 03:21:50 +00003347 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3348 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3349 fcoe_stat->tx_bytes_lo,
3350 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003351
Yuval Mintz86564c32013-01-23 03:21:50 +00003352 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3353 fcoe_stat->tx_frames_lo,
3354 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003355
Yuval Mintz86564c32013-01-23 03:21:50 +00003356 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3357 fcoe_stat->tx_frames_lo,
3358 fcoe_q_xstorm_stats->ucast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003359
Yuval Mintz86564c32013-01-23 03:21:50 +00003360 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3361 fcoe_stat->tx_frames_lo,
3362 fcoe_q_xstorm_stats->bcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003363
Yuval Mintz86564c32013-01-23 03:21:50 +00003364 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3365 fcoe_stat->tx_frames_lo,
3366 fcoe_q_xstorm_stats->mcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003367 }
3368
Barak Witkowski1d187b32011-12-05 22:41:50 +00003369 /* ask L5 driver to add data to the struct */
3370 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003371}
3372
3373static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3374{
3375 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3376 struct iscsi_stats_info *iscsi_stat =
3377 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3378
Merav Sicron55c11942012-11-07 00:45:48 +00003379 if (!CNIC_LOADED(bp))
3380 return;
3381
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003382 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3383 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003384
3385 iscsi_stat->qos_priority =
3386 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3387
Barak Witkowski1d187b32011-12-05 22:41:50 +00003388 /* ask L5 driver to add data to the struct */
3389 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003390}
3391
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003392/* called due to MCP event (on pmf):
3393 * reread new bandwidth configuration
3394 * configure FW
3395 * notify others function about the change
3396 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003397static void bnx2x_config_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003398{
3399 if (bp->link_vars.link_up) {
3400 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3401 bnx2x_link_sync_notify(bp);
3402 }
3403 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3404}
3405
Eric Dumazet1191cb82012-04-27 21:39:21 +00003406static void bnx2x_set_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003407{
3408 bnx2x_config_mf_bw(bp);
3409 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3410}
3411
Yuval Mintzc8c60d82012-06-06 17:13:07 +00003412static void bnx2x_handle_eee_event(struct bnx2x *bp)
3413{
3414 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3415 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3416}
3417
Barak Witkowski1d187b32011-12-05 22:41:50 +00003418static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3419{
3420 enum drv_info_opcode op_code;
3421 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3422
3423 /* if drv_info version supported by MFW doesn't match - send NACK */
3424 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3425 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3426 return;
3427 }
3428
3429 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3430 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3431
3432 memset(&bp->slowpath->drv_info_to_mcp, 0,
3433 sizeof(union drv_info_to_mcp));
3434
3435 switch (op_code) {
3436 case ETH_STATS_OPCODE:
3437 bnx2x_drv_info_ether_stat(bp);
3438 break;
3439 case FCOE_STATS_OPCODE:
3440 bnx2x_drv_info_fcoe_stat(bp);
3441 break;
3442 case ISCSI_STATS_OPCODE:
3443 bnx2x_drv_info_iscsi_stat(bp);
3444 break;
3445 default:
3446 /* if op code isn't supported - send NACK */
3447 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3448 return;
3449 }
3450
3451 /* if we got drv_info attn from MFW then these fields are defined in
3452 * shmem2 for sure
3453 */
3454 SHMEM2_WR(bp, drv_info_host_addr_lo,
3455 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3456 SHMEM2_WR(bp, drv_info_host_addr_hi,
3457 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3458
3459 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3460}
3461
Eilon Greenstein2691d512009-08-12 08:22:08 +00003462static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3463{
Eilon Greenstein2691d512009-08-12 08:22:08 +00003464 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003465
3466 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3467
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003468 /*
3469 * This is the only place besides the function initialization
3470 * where the bp->flags can change so it is done without any
3471 * locks
3472 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003473 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003474 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003475 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003476
3477 bnx2x_e1h_disable(bp);
3478 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00003479 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003480 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003481
3482 bnx2x_e1h_enable(bp);
3483 }
3484 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3485 }
3486 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003487 bnx2x_config_mf_bw(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003488 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3489 }
3490
3491 /* Report results to MCP */
3492 if (dcc_event)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003493 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003494 else
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003495 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003496}
3497
Michael Chan289129022009-10-10 13:46:53 +00003498/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003499static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003500{
3501 struct eth_spe *next_spe = bp->spq_prod_bd;
3502
3503 if (bp->spq_prod_bd == bp->spq_last_bd) {
3504 bp->spq_prod_bd = bp->spq;
3505 bp->spq_prod_idx = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00003506 DP(BNX2X_MSG_SP, "end of spq\n");
Michael Chan289129022009-10-10 13:46:53 +00003507 } else {
3508 bp->spq_prod_bd++;
3509 bp->spq_prod_idx++;
3510 }
3511 return next_spe;
3512}
3513
3514/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003515static void bnx2x_sp_prod_update(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003516{
3517 int func = BP_FUNC(bp);
3518
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003519 /*
3520 * Make sure that BD data is updated before writing the producer:
3521 * BD data is written to the memory, the producer is read from the
3522 * memory, thus we need a full memory barrier to ensure the ordering.
3523 */
3524 mb();
Michael Chan289129022009-10-10 13:46:53 +00003525
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003526 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00003527 bp->spq_prod_idx);
Michael Chan289129022009-10-10 13:46:53 +00003528 mmiowb();
3529}
3530
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003531/**
3532 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3533 *
3534 * @cmd: command to check
3535 * @cmd_type: command type
3536 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003537static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003538{
3539 if ((cmd_type == NONE_CONNECTION_TYPE) ||
Ariel Elior6383c0b2011-07-14 08:31:57 +00003540 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003541 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3542 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3543 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3544 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3545 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3546 return true;
3547 else
3548 return false;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003549}
3550
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003551/**
3552 * bnx2x_sp_post - place a single command on an SP ring
3553 *
3554 * @bp: driver handle
3555 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3556 * @cid: SW CID the command is related to
3557 * @data_hi: command private data address (high 32 bits)
3558 * @data_lo: command private data address (low 32 bits)
3559 * @cmd_type: command type (e.g. NONE, ETH)
3560 *
3561 * SP data is handled as if it's always an address pair, thus data fields are
3562 * not swapped to little endian in upper functions. Instead this function swaps
3563 * data as if it's two u32 fields.
3564 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003565int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003566 u32 data_hi, u32 data_lo, int cmd_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003567{
Michael Chan289129022009-10-10 13:46:53 +00003568 struct eth_spe *spe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003569 u16 type;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003570 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003571
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003572#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00003573 if (unlikely(bp->panic)) {
3574 BNX2X_ERR("Can't post SP when there is panic\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003575 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +00003576 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003577#endif
3578
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003579 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003580
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003581 if (common) {
3582 if (!atomic_read(&bp->eq_spq_left)) {
3583 BNX2X_ERR("BUG! EQ ring full!\n");
3584 spin_unlock_bh(&bp->spq_lock);
3585 bnx2x_panic();
3586 return -EBUSY;
3587 }
3588 } else if (!atomic_read(&bp->cq_spq_left)) {
3589 BNX2X_ERR("BUG! SPQ ring full!\n");
3590 spin_unlock_bh(&bp->spq_lock);
3591 bnx2x_panic();
3592 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003593 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08003594
Michael Chan289129022009-10-10 13:46:53 +00003595 spe = bnx2x_sp_get_next(bp);
3596
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003597 /* CID needs port number to be encoded int it */
Michael Chan289129022009-10-10 13:46:53 +00003598 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003599 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3600 HW_CID(bp, cid));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003601
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003602 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003603
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003604 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3605 SPE_HDR_FUNCTION_ID);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003606
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003607 spe->hdr.type = cpu_to_le16(type);
3608
3609 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3610 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3611
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003612 /*
3613 * It's ok if the actual decrement is issued towards the memory
3614 * somewhere between the spin_lock and spin_unlock. Thus no
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003615 * more explicit memory barrier is needed.
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003616 */
3617 if (common)
3618 atomic_dec(&bp->eq_spq_left);
3619 else
3620 atomic_dec(&bp->cq_spq_left);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003621
Merav Sicron51c1a582012-03-18 10:33:38 +00003622 DP(BNX2X_MSG_SP,
3623 "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003624 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3625 (u32)(U64_LO(bp->spq_mapping) +
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003626 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003627 HW_CID(bp, cid), data_hi, data_lo, type,
3628 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003629
Michael Chan289129022009-10-10 13:46:53 +00003630 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003631 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003632 return 0;
3633}
3634
3635/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003636static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003637{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003638 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003639 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003640
3641 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003642 for (j = 0; j < 1000; j++) {
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003643 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
3644 val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
3645 if (val & MCPR_ACCESS_LOCK_LOCK)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003646 break;
3647
Yuval Mintz639d65b2013-06-02 00:06:21 +00003648 usleep_range(5000, 10000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003649 }
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003650 if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07003651 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003652 rc = -EBUSY;
3653 }
3654
3655 return rc;
3656}
3657
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003658/* release split MCP access lock register */
3659static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003660{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003661 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003662}
3663
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003664#define BNX2X_DEF_SB_ATT_IDX 0x0001
3665#define BNX2X_DEF_SB_IDX 0x0002
3666
Eric Dumazet1191cb82012-04-27 21:39:21 +00003667static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003668{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003669 struct host_sp_status_block *def_sb = bp->def_status_blk;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003670 u16 rc = 0;
3671
3672 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003673 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3674 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003675 rc |= BNX2X_DEF_SB_ATT_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003676 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003677
3678 if (bp->def_idx != def_sb->sp_sb.running_index) {
3679 bp->def_idx = def_sb->sp_sb.running_index;
3680 rc |= BNX2X_DEF_SB_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003681 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003682
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003683 /* Do not reorder: indices reading should complete before handling */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003684 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003685 return rc;
3686}
3687
3688/*
3689 * slow path service functions
3690 */
3691
3692static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3693{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003694 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003695 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3696 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003697 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3698 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003699 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00003700 u32 nig_mask = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003701 u32 reg_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003702
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003703 if (bp->attn_state & asserted)
3704 BNX2X_ERR("IGU ERROR\n");
3705
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003706 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3707 aeu_mask = REG_RD(bp, aeu_addr);
3708
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003709 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003710 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003711 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003712 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003713
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003714 REG_WR(bp, aeu_addr, aeu_mask);
3715 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003716
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003717 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003718 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003719 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003720
3721 if (asserted & ATTN_HARD_WIRED_MASK) {
3722 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003723
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003724 bnx2x_acquire_phy_lock(bp);
3725
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003726 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00003727 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003728
Yaniv Rosner361c3912011-06-14 01:33:19 +00003729 /* If nig_mask is not set, no need to call the update
3730 * function.
3731 */
3732 if (nig_mask) {
3733 REG_WR(bp, nig_int_mask_addr, 0);
3734
3735 bnx2x_link_attn(bp);
3736 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003737
3738 /* handle unicore attn? */
3739 }
3740 if (asserted & ATTN_SW_TIMER_4_FUNC)
3741 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3742
3743 if (asserted & GPIO_2_FUNC)
3744 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3745
3746 if (asserted & GPIO_3_FUNC)
3747 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3748
3749 if (asserted & GPIO_4_FUNC)
3750 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3751
3752 if (port == 0) {
3753 if (asserted & ATTN_GENERAL_ATTN_1) {
3754 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3755 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3756 }
3757 if (asserted & ATTN_GENERAL_ATTN_2) {
3758 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3759 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3760 }
3761 if (asserted & ATTN_GENERAL_ATTN_3) {
3762 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3763 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3764 }
3765 } else {
3766 if (asserted & ATTN_GENERAL_ATTN_4) {
3767 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3768 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3769 }
3770 if (asserted & ATTN_GENERAL_ATTN_5) {
3771 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3772 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3773 }
3774 if (asserted & ATTN_GENERAL_ATTN_6) {
3775 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3776 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3777 }
3778 }
3779
3780 } /* if hardwired */
3781
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003782 if (bp->common.int_block == INT_BLOCK_HC)
3783 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3784 COMMAND_REG_ATTN_BITS_SET);
3785 else
3786 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3787
3788 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3789 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3790 REG_WR(bp, reg_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003791
3792 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003793 if (asserted & ATTN_NIG_FOR_FUNC) {
Yaniv Rosner27c11512012-12-02 04:05:54 +00003794 /* Verify that IGU ack through BAR was written before restoring
3795 * NIG mask. This loop should exit after 2-3 iterations max.
3796 */
3797 if (bp->common.int_block != INT_BLOCK_HC) {
3798 u32 cnt = 0, igu_acked;
3799 do {
3800 igu_acked = REG_RD(bp,
3801 IGU_REG_ATTENTION_ACK_BITS);
3802 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3803 (++cnt < MAX_IGU_ATTN_ACK_TO));
3804 if (!igu_acked)
3805 DP(NETIF_MSG_HW,
3806 "Failed to verify IGU ack on time\n");
3807 barrier();
3808 }
Eilon Greenstein87942b42009-02-12 08:36:49 +00003809 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003810 bnx2x_release_phy_lock(bp);
3811 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003812}
3813
Eric Dumazet1191cb82012-04-27 21:39:21 +00003814static void bnx2x_fan_failure(struct bnx2x *bp)
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003815{
3816 int port = BP_PORT(bp);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003817 u32 ext_phy_config;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003818 /* mark the failure */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003819 ext_phy_config =
3820 SHMEM_RD(bp,
3821 dev_info.port_hw_config[port].external_phy_config);
3822
3823 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3824 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003825 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003826 ext_phy_config);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003827
3828 /* log the failure */
Merav Sicron51c1a582012-03-18 10:33:38 +00003829 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3830 "Please contact OEM Support for assistance\n");
Ariel Elior83048592011-11-13 04:34:29 +00003831
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003832 /* Schedule device reset (unload)
Ariel Elior83048592011-11-13 04:34:29 +00003833 * This is due to some boards consuming sufficient power when driver is
3834 * up to overheat if fan fails.
3835 */
3836 smp_mb__before_clear_bit();
3837 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3838 smp_mb__after_clear_bit();
3839 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003840}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003841
Eric Dumazet1191cb82012-04-27 21:39:21 +00003842static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003843{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003844 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003845 int reg_offset;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003846 u32 val;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003847
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003848 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3849 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003850
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003851 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003852
3853 val = REG_RD(bp, reg_offset);
3854 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3855 REG_WR(bp, reg_offset, val);
3856
3857 BNX2X_ERR("SPIO5 hw attention\n");
3858
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003859 /* Fan failure attention */
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003860 bnx2x_hw_reset_phy(&bp->link_params);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003861 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003862 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003863
Yaniv Rosner3deb8162011-06-14 01:34:33 +00003864 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00003865 bnx2x_acquire_phy_lock(bp);
3866 bnx2x_handle_module_detect_int(&bp->link_params);
3867 bnx2x_release_phy_lock(bp);
3868 }
3869
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003870 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3871
3872 val = REG_RD(bp, reg_offset);
3873 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3874 REG_WR(bp, reg_offset, val);
3875
3876 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003877 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003878 bnx2x_panic();
3879 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003880}
3881
Eric Dumazet1191cb82012-04-27 21:39:21 +00003882static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003883{
3884 u32 val;
3885
Eilon Greenstein0626b892009-02-12 08:38:14 +00003886 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003887
3888 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3889 BNX2X_ERR("DB hw attention 0x%x\n", val);
3890 /* DORQ discard attention */
3891 if (val & 0x2)
3892 BNX2X_ERR("FATAL error from DORQ\n");
3893 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003894
3895 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3896
3897 int port = BP_PORT(bp);
3898 int reg_offset;
3899
3900 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3901 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3902
3903 val = REG_RD(bp, reg_offset);
3904 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3905 REG_WR(bp, reg_offset, val);
3906
3907 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003908 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003909 bnx2x_panic();
3910 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003911}
3912
Eric Dumazet1191cb82012-04-27 21:39:21 +00003913static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003914{
3915 u32 val;
3916
3917 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3918
3919 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3920 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3921 /* CFC error attention */
3922 if (val & 0x2)
3923 BNX2X_ERR("FATAL error from CFC\n");
3924 }
3925
3926 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003927 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003928 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003929 /* RQ_USDMDP_FIFO_OVERFLOW */
3930 if (val & 0x18000)
3931 BNX2X_ERR("FATAL error from PXP\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003932
3933 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003934 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
3935 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
3936 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003937 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003938
3939 if (attn & HW_INTERRUT_ASSERT_SET_2) {
3940
3941 int port = BP_PORT(bp);
3942 int reg_offset;
3943
3944 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
3945 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
3946
3947 val = REG_RD(bp, reg_offset);
3948 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
3949 REG_WR(bp, reg_offset, val);
3950
3951 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003952 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003953 bnx2x_panic();
3954 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003955}
3956
Eric Dumazet1191cb82012-04-27 21:39:21 +00003957static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003958{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003959 u32 val;
3960
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003961 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
3962
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003963 if (attn & BNX2X_PMF_LINK_ASSERT) {
3964 int func = BP_FUNC(bp);
3965
3966 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Barak Witkowskia3348722012-04-23 03:04:46 +00003967 bnx2x_read_mf_cfg(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003968 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
3969 func_mf_config[BP_ABS_FUNC(bp)].config);
3970 val = SHMEM_RD(bp,
3971 func_mb[BP_FW_MB_IDX(bp)].drv_status);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003972 if (val & DRV_STATUS_DCC_EVENT_MASK)
3973 bnx2x_dcc_event(bp,
3974 (val & DRV_STATUS_DCC_EVENT_MASK));
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003975
3976 if (val & DRV_STATUS_SET_MF_BW)
3977 bnx2x_set_mf_bw(bp);
3978
Barak Witkowski1d187b32011-12-05 22:41:50 +00003979 if (val & DRV_STATUS_DRV_INFO_REQ)
3980 bnx2x_handle_drv_info_req(bp);
Ariel Eliord16132c2013-01-01 05:22:42 +00003981
3982 if (val & DRV_STATUS_VF_DISABLED)
3983 bnx2x_vf_handle_flr_event(bp);
3984
Eilon Greenstein2691d512009-08-12 08:22:08 +00003985 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003986 bnx2x_pmf_update(bp);
3987
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003988 if (bp->port.pmf &&
Shmulik Ravid785b9b12010-12-30 06:27:03 +00003989 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
3990 bp->dcbx_enabled > 0)
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00003991 /* start dcbx state machine */
3992 bnx2x_dcbx_set_params(bp,
3993 BNX2X_DCBX_STATE_NEG_RECEIVED);
Barak Witkowskia3348722012-04-23 03:04:46 +00003994 if (val & DRV_STATUS_AFEX_EVENT_MASK)
3995 bnx2x_handle_afex_cmd(bp,
3996 val & DRV_STATUS_AFEX_EVENT_MASK);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00003997 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
3998 bnx2x_handle_eee_event(bp);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00003999 if (bp->link_vars.periodic_flags &
4000 PERIODIC_FLAGS_LINK_EVENT) {
4001 /* sync with link */
4002 bnx2x_acquire_phy_lock(bp);
4003 bp->link_vars.periodic_flags &=
4004 ~PERIODIC_FLAGS_LINK_EVENT;
4005 bnx2x_release_phy_lock(bp);
4006 if (IS_MF(bp))
4007 bnx2x_link_sync_notify(bp);
4008 bnx2x_link_report(bp);
4009 }
4010 /* Always call it here: bnx2x_link_report() will
4011 * prevent the link indication duplication.
4012 */
4013 bnx2x__link_status_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004014 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004015
4016 BNX2X_ERR("MC assert!\n");
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00004017 bnx2x_mc_assert(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004018 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4019 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4020 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4021 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4022 bnx2x_panic();
4023
4024 } else if (attn & BNX2X_MCP_ASSERT) {
4025
4026 BNX2X_ERR("MCP assert!\n");
4027 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004028 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004029
4030 } else
4031 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4032 }
4033
4034 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004035 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4036 if (attn & BNX2X_GRC_TIMEOUT) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004037 val = CHIP_IS_E1(bp) ? 0 :
4038 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004039 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4040 }
4041 if (attn & BNX2X_GRC_RSV) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004042 val = CHIP_IS_E1(bp) ? 0 :
4043 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004044 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4045 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004046 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004047 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004048}
4049
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004050/*
4051 * Bits map:
4052 * 0-7 - Engine0 load counter.
4053 * 8-15 - Engine1 load counter.
4054 * 16 - Engine0 RESET_IN_PROGRESS bit.
4055 * 17 - Engine1 RESET_IN_PROGRESS bit.
4056 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4057 * on the engine
4058 * 19 - Engine1 ONE_IS_LOADED.
4059 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4060 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4061 * just the one belonging to its engine).
4062 *
4063 */
4064#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4065
4066#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4067#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4068#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4069#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4070#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4071#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4072#define BNX2X_GLOBAL_RESET_BIT 0x00040000
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00004073
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004074/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004075 * Set the GLOBAL_RESET bit.
4076 *
4077 * Should be run under rtnl lock
4078 */
4079void bnx2x_set_reset_global(struct bnx2x *bp)
4080{
Ariel Eliorf16da432012-01-26 06:01:50 +00004081 u32 val;
4082 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4083 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004084 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
Ariel Eliorf16da432012-01-26 06:01:50 +00004085 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004086}
4087
4088/*
4089 * Clear the GLOBAL_RESET bit.
4090 *
4091 * Should be run under rtnl lock
4092 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004093static void bnx2x_clear_reset_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004094{
Ariel Eliorf16da432012-01-26 06:01:50 +00004095 u32 val;
4096 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4097 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004098 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
Ariel Eliorf16da432012-01-26 06:01:50 +00004099 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004100}
4101
4102/*
4103 * Checks the GLOBAL_RESET bit.
4104 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004105 * should be run under rtnl lock
4106 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004107static bool bnx2x_reset_is_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004108{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004109 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004110
4111 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4112 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4113}
4114
4115/*
4116 * Clear RESET_IN_PROGRESS bit for the current engine.
4117 *
4118 * Should be run under rtnl lock
4119 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004120static void bnx2x_set_reset_done(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004121{
Ariel Eliorf16da432012-01-26 06:01:50 +00004122 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004123 u32 bit = BP_PATH(bp) ?
4124 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004125 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4126 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004127
4128 /* Clear the bit */
4129 val &= ~bit;
4130 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004131
4132 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004133}
4134
4135/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004136 * Set RESET_IN_PROGRESS for the current engine.
4137 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004138 * should be run under rtnl lock
4139 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004140void bnx2x_set_reset_in_progress(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004141{
Ariel Eliorf16da432012-01-26 06:01:50 +00004142 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004143 u32 bit = BP_PATH(bp) ?
4144 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004145 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4146 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004147
4148 /* Set the bit */
4149 val |= bit;
4150 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004151 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004152}
4153
4154/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004155 * Checks the RESET_IN_PROGRESS bit for the given engine.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004156 * should be run under rtnl lock
4157 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004158bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004159{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004160 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004161 u32 bit = engine ?
4162 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4163
4164 /* return false if bit is set */
4165 return (val & bit) ? false : true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004166}
4167
4168/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004169 * set pf load for the current pf.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004170 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004171 * should be run under rtnl lock
4172 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004173void bnx2x_set_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004174{
Ariel Eliorf16da432012-01-26 06:01:50 +00004175 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004176 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4177 BNX2X_PATH0_LOAD_CNT_MASK;
4178 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4179 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004180
Ariel Eliorf16da432012-01-26 06:01:50 +00004181 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4182 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4183
Merav Sicron51c1a582012-03-18 10:33:38 +00004184 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004185
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004186 /* get the current counter value */
4187 val1 = (val & mask) >> shift;
4188
Ariel Elior889b9af2012-01-26 06:01:51 +00004189 /* set bit of that PF */
4190 val1 |= (1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004191
4192 /* clear the old value */
4193 val &= ~mask;
4194
4195 /* set the new one */
4196 val |= ((val1 << shift) & mask);
4197
4198 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004199 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004200}
4201
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004202/**
Ariel Elior889b9af2012-01-26 06:01:51 +00004203 * bnx2x_clear_pf_load - clear pf load mark
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004204 *
4205 * @bp: driver handle
4206 *
4207 * Should be run under rtnl lock.
4208 * Decrements the load counter for the current engine. Returns
Ariel Elior889b9af2012-01-26 06:01:51 +00004209 * whether other functions are still loaded
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004210 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004211bool bnx2x_clear_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004212{
Ariel Eliorf16da432012-01-26 06:01:50 +00004213 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004214 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4215 BNX2X_PATH0_LOAD_CNT_MASK;
4216 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4217 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004218
Ariel Eliorf16da432012-01-26 06:01:50 +00004219 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4220 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Merav Sicron51c1a582012-03-18 10:33:38 +00004221 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004222
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004223 /* get the current counter value */
4224 val1 = (val & mask) >> shift;
4225
Ariel Elior889b9af2012-01-26 06:01:51 +00004226 /* clear bit of that PF */
4227 val1 &= ~(1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004228
4229 /* clear the old value */
4230 val &= ~mask;
4231
4232 /* set the new one */
4233 val |= ((val1 << shift) & mask);
4234
4235 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004236 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4237 return val1 != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004238}
4239
4240/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004241 * Read the load status for the current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004242 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004243 * should be run under rtnl lock
4244 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004245static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004246{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004247 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4248 BNX2X_PATH0_LOAD_CNT_MASK);
4249 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4250 BNX2X_PATH0_LOAD_CNT_SHIFT);
4251 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4252
Merav Sicron51c1a582012-03-18 10:33:38 +00004253 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004254
4255 val = (val & mask) >> shift;
4256
Merav Sicron51c1a582012-03-18 10:33:38 +00004257 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4258 engine, val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004259
Ariel Elior889b9af2012-01-26 06:01:51 +00004260 return val != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004261}
4262
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004263static void _print_parity(struct bnx2x *bp, u32 reg)
4264{
4265 pr_cont(" [0x%08x] ", REG_RD(bp, reg));
4266}
4267
Eric Dumazet1191cb82012-04-27 21:39:21 +00004268static void _print_next_block(int idx, const char *blk)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004269{
Joe Perchesf1deab52011-08-14 12:16:21 +00004270 pr_cont("%s%s", idx ? ", " : "", blk);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004271}
4272
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004273static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4274 int par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004275{
4276 int i = 0;
4277 u32 cur_bit = 0;
4278 for (i = 0; sig; i++) {
4279 cur_bit = ((u32)0x1 << i);
4280 if (sig & cur_bit) {
4281 switch (cur_bit) {
4282 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004283 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004284 _print_next_block(par_num++, "BRB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004285 _print_parity(bp,
4286 BRB1_REG_BRB1_PRTY_STS);
4287 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004288 break;
4289 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004290 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004291 _print_next_block(par_num++, "PARSER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004292 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
4293 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004294 break;
4295 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004296 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004297 _print_next_block(par_num++, "TSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004298 _print_parity(bp,
4299 TSDM_REG_TSDM_PRTY_STS);
4300 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004301 break;
4302 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004303 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004304 _print_next_block(par_num++,
4305 "SEARCHER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004306 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
4307 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004308 break;
4309 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004310 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004311 _print_next_block(par_num++, "TCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004312 _print_parity(bp,
4313 TCM_REG_TCM_PRTY_STS);
4314 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004315 break;
4316 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004317 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004318 _print_next_block(par_num++, "TSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004319 _print_parity(bp,
4320 TSEM_REG_TSEM_PRTY_STS_0);
4321 _print_parity(bp,
4322 TSEM_REG_TSEM_PRTY_STS_1);
4323 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004324 break;
4325 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004326 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004327 _print_next_block(par_num++, "XPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004328 _print_parity(bp, GRCBASE_XPB +
4329 PB_REG_PB_PRTY_STS);
4330 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004331 break;
4332 }
4333
4334 /* Clear the bit */
4335 sig &= ~cur_bit;
4336 }
4337 }
4338
4339 return par_num;
4340}
4341
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004342static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4343 int par_num, bool *global,
4344 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004345{
4346 int i = 0;
4347 u32 cur_bit = 0;
4348 for (i = 0; sig; i++) {
4349 cur_bit = ((u32)0x1 << i);
4350 if (sig & cur_bit) {
4351 switch (cur_bit) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004352 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004353 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004354 _print_next_block(par_num++, "PBF");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004355 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4356 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004357 break;
4358 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004359 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004360 _print_next_block(par_num++, "QM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004361 _print_parity(bp, QM_REG_QM_PRTY_STS);
4362 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004363 break;
4364 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004365 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004366 _print_next_block(par_num++, "TM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004367 _print_parity(bp, TM_REG_TM_PRTY_STS);
4368 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004369 break;
4370 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004371 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004372 _print_next_block(par_num++, "XSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004373 _print_parity(bp,
4374 XSDM_REG_XSDM_PRTY_STS);
4375 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004376 break;
4377 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004378 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004379 _print_next_block(par_num++, "XCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004380 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4381 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004382 break;
4383 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004384 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004385 _print_next_block(par_num++, "XSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004386 _print_parity(bp,
4387 XSEM_REG_XSEM_PRTY_STS_0);
4388 _print_parity(bp,
4389 XSEM_REG_XSEM_PRTY_STS_1);
4390 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004391 break;
4392 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004393 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004394 _print_next_block(par_num++,
4395 "DOORBELLQ");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004396 _print_parity(bp,
4397 DORQ_REG_DORQ_PRTY_STS);
4398 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004399 break;
4400 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004401 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004402 _print_next_block(par_num++, "NIG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004403 if (CHIP_IS_E1x(bp)) {
4404 _print_parity(bp,
4405 NIG_REG_NIG_PRTY_STS);
4406 } else {
4407 _print_parity(bp,
4408 NIG_REG_NIG_PRTY_STS_0);
4409 _print_parity(bp,
4410 NIG_REG_NIG_PRTY_STS_1);
4411 }
4412 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004413 break;
4414 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004415 if (print)
4416 _print_next_block(par_num++,
4417 "VAUX PCI CORE");
4418 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004419 break;
4420 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004421 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004422 _print_next_block(par_num++, "DEBUG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004423 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4424 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004425 break;
4426 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004427 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004428 _print_next_block(par_num++, "USDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004429 _print_parity(bp,
4430 USDM_REG_USDM_PRTY_STS);
4431 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004432 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004433 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004434 if (print) {
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004435 _print_next_block(par_num++, "UCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004436 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4437 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004438 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004439 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004440 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004441 _print_next_block(par_num++, "USEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004442 _print_parity(bp,
4443 USEM_REG_USEM_PRTY_STS_0);
4444 _print_parity(bp,
4445 USEM_REG_USEM_PRTY_STS_1);
4446 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004447 break;
4448 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004449 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004450 _print_next_block(par_num++, "UPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004451 _print_parity(bp, GRCBASE_UPB +
4452 PB_REG_PB_PRTY_STS);
4453 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004454 break;
4455 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004456 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004457 _print_next_block(par_num++, "CSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004458 _print_parity(bp,
4459 CSDM_REG_CSDM_PRTY_STS);
4460 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004461 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004462 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004463 if (print) {
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004464 _print_next_block(par_num++, "CCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004465 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4466 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004467 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004468 }
4469
4470 /* Clear the bit */
4471 sig &= ~cur_bit;
4472 }
4473 }
4474
4475 return par_num;
4476}
4477
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004478static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4479 int par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004480{
4481 int i = 0;
4482 u32 cur_bit = 0;
4483 for (i = 0; sig; i++) {
4484 cur_bit = ((u32)0x1 << i);
4485 if (sig & cur_bit) {
4486 switch (cur_bit) {
4487 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004488 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004489 _print_next_block(par_num++, "CSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004490 _print_parity(bp,
4491 CSEM_REG_CSEM_PRTY_STS_0);
4492 _print_parity(bp,
4493 CSEM_REG_CSEM_PRTY_STS_1);
4494 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004495 break;
4496 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004497 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004498 _print_next_block(par_num++, "PXP");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004499 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4500 _print_parity(bp,
4501 PXP2_REG_PXP2_PRTY_STS_0);
4502 _print_parity(bp,
4503 PXP2_REG_PXP2_PRTY_STS_1);
4504 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004505 break;
4506 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004507 if (print)
4508 _print_next_block(par_num++,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004509 "PXPPCICLOCKCLIENT");
4510 break;
4511 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004512 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004513 _print_next_block(par_num++, "CFC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004514 _print_parity(bp,
4515 CFC_REG_CFC_PRTY_STS);
4516 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004517 break;
4518 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004519 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004520 _print_next_block(par_num++, "CDU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004521 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
4522 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004523 break;
4524 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004525 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004526 _print_next_block(par_num++, "DMAE");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004527 _print_parity(bp,
4528 DMAE_REG_DMAE_PRTY_STS);
4529 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004530 break;
4531 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004532 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004533 _print_next_block(par_num++, "IGU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004534 if (CHIP_IS_E1x(bp))
4535 _print_parity(bp,
4536 HC_REG_HC_PRTY_STS);
4537 else
4538 _print_parity(bp,
4539 IGU_REG_IGU_PRTY_STS);
4540 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004541 break;
4542 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004543 if (print) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004544 _print_next_block(par_num++, "MISC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004545 _print_parity(bp,
4546 MISC_REG_MISC_PRTY_STS);
4547 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004548 break;
4549 }
4550
4551 /* Clear the bit */
4552 sig &= ~cur_bit;
4553 }
4554 }
4555
4556 return par_num;
4557}
4558
Eric Dumazet1191cb82012-04-27 21:39:21 +00004559static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4560 bool *global, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004561{
4562 int i = 0;
4563 u32 cur_bit = 0;
4564 for (i = 0; sig; i++) {
4565 cur_bit = ((u32)0x1 << i);
4566 if (sig & cur_bit) {
4567 switch (cur_bit) {
4568 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004569 if (print)
4570 _print_next_block(par_num++, "MCP ROM");
4571 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004572 break;
4573 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004574 if (print)
4575 _print_next_block(par_num++,
4576 "MCP UMP RX");
4577 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004578 break;
4579 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004580 if (print)
4581 _print_next_block(par_num++,
4582 "MCP UMP TX");
4583 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004584 break;
4585 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004586 if (print)
4587 _print_next_block(par_num++,
4588 "MCP SCPAD");
4589 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004590 break;
4591 }
4592
4593 /* Clear the bit */
4594 sig &= ~cur_bit;
4595 }
4596 }
4597
4598 return par_num;
4599}
4600
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004601static int bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4602 int par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004603{
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004604 int i = 0;
4605 u32 cur_bit = 0;
4606 for (i = 0; sig; i++) {
4607 cur_bit = ((u32)0x1 << i);
4608 if (sig & cur_bit) {
4609 switch (cur_bit) {
4610 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004611 if (print) {
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004612 _print_next_block(par_num++, "PGLUE_B");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004613 _print_parity(bp,
4614 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4615 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004616 break;
4617 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004618 if (print) {
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004619 _print_next_block(par_num++, "ATC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004620 _print_parity(bp,
4621 ATC_REG_ATC_PRTY_STS);
4622 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004623 break;
4624 }
4625
4626 /* Clear the bit */
4627 sig &= ~cur_bit;
4628 }
4629 }
4630
4631 return par_num;
4632}
4633
Eric Dumazet1191cb82012-04-27 21:39:21 +00004634static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4635 u32 *sig)
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004636{
4637 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4638 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4639 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4640 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4641 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004642 int par_num = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00004643 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4644 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004645 sig[0] & HW_PRTY_ASSERT_SET_0,
4646 sig[1] & HW_PRTY_ASSERT_SET_1,
4647 sig[2] & HW_PRTY_ASSERT_SET_2,
4648 sig[3] & HW_PRTY_ASSERT_SET_3,
4649 sig[4] & HW_PRTY_ASSERT_SET_4);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004650 if (print)
4651 netdev_err(bp->dev,
4652 "Parity errors detected in blocks: ");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004653 par_num = bnx2x_check_blocks_with_parity0(bp,
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004654 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004655 par_num = bnx2x_check_blocks_with_parity1(bp,
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004656 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004657 par_num = bnx2x_check_blocks_with_parity2(bp,
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004658 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004659 par_num = bnx2x_check_blocks_with_parity3(
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004660 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004661 par_num = bnx2x_check_blocks_with_parity4(bp,
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004662 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
4663
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004664 if (print)
4665 pr_cont("\n");
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004666
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004667 return true;
4668 } else
4669 return false;
4670}
4671
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004672/**
4673 * bnx2x_chk_parity_attn - checks for parity attentions.
4674 *
4675 * @bp: driver handle
4676 * @global: true if there was a global attention
4677 * @print: show parity attention in syslog
4678 */
4679bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004680{
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004681 struct attn_route attn = { {0} };
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004682 int port = BP_PORT(bp);
4683
4684 attn.sig[0] = REG_RD(bp,
4685 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4686 port*4);
4687 attn.sig[1] = REG_RD(bp,
4688 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4689 port*4);
4690 attn.sig[2] = REG_RD(bp,
4691 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4692 port*4);
4693 attn.sig[3] = REG_RD(bp,
4694 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4695 port*4);
4696
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004697 if (!CHIP_IS_E1x(bp))
4698 attn.sig[4] = REG_RD(bp,
4699 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4700 port*4);
4701
4702 return bnx2x_parity_attn(bp, global, print, attn.sig);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004703}
4704
Eric Dumazet1191cb82012-04-27 21:39:21 +00004705static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004706{
4707 u32 val;
4708 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4709
4710 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4711 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4712 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004713 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004714 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004715 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004716 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004717 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004718 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004719 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004720 if (val &
4721 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004722 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004723 if (val &
4724 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004725 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004726 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004727 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004728 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004729 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004730 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
Merav Sicron51c1a582012-03-18 10:33:38 +00004731 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004732 }
4733 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4734 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4735 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4736 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4737 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4738 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
Merav Sicron51c1a582012-03-18 10:33:38 +00004739 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004740 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
Merav Sicron51c1a582012-03-18 10:33:38 +00004741 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004742 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
Merav Sicron51c1a582012-03-18 10:33:38 +00004743 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004744 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4745 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4746 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
Merav Sicron51c1a582012-03-18 10:33:38 +00004747 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004748 }
4749
4750 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4751 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4752 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4753 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4754 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4755 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004756}
4757
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004758static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4759{
4760 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004761 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004762 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004763 u32 reg_addr;
4764 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004765 u32 aeu_mask;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004766 bool global = false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004767
4768 /* need to take HW lock because MCP or other port might also
4769 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004770 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004771
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004772 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4773#ifndef BNX2X_STOP_ON_ERROR
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004774 bp->recovery_state = BNX2X_RECOVERY_INIT;
Ariel Elior7be08a72011-07-14 08:31:19 +00004775 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004776 /* Disable HW interrupts */
4777 bnx2x_int_disable(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004778 /* In case of parity errors don't handle attentions so that
4779 * other function would "see" parity errors.
4780 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004781#else
4782 bnx2x_panic();
4783#endif
4784 bnx2x_release_alr(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004785 return;
4786 }
4787
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004788 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4789 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4790 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4791 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004792 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004793 attn.sig[4] =
4794 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4795 else
4796 attn.sig[4] = 0;
4797
4798 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4799 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004800
4801 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4802 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004803 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004804
Merav Sicron51c1a582012-03-18 10:33:38 +00004805 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004806 index,
4807 group_mask->sig[0], group_mask->sig[1],
4808 group_mask->sig[2], group_mask->sig[3],
4809 group_mask->sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004810
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004811 bnx2x_attn_int_deasserted4(bp,
4812 attn.sig[4] & group_mask->sig[4]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004813 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004814 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004815 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004816 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004817 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004818 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004819 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004820 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004821 }
4822 }
4823
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004824 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004825
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004826 if (bp->common.int_block == INT_BLOCK_HC)
4827 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4828 COMMAND_REG_ATTN_BITS_CLR);
4829 else
4830 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004831
4832 val = ~deasserted;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004833 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4834 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004835 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004836
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004837 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004838 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004839
4840 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4841 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4842
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004843 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4844 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004845
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004846 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4847 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004848 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004849 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4850
4851 REG_WR(bp, reg_addr, aeu_mask);
4852 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004853
4854 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4855 bp->attn_state &= ~deasserted;
4856 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4857}
4858
4859static void bnx2x_attn_int(struct bnx2x *bp)
4860{
4861 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08004862 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4863 attn_bits);
4864 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4865 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004866 u32 attn_state = bp->attn_state;
4867
4868 /* look for changed bits */
4869 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4870 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4871
4872 DP(NETIF_MSG_HW,
4873 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4874 attn_bits, attn_ack, asserted, deasserted);
4875
4876 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004877 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004878
4879 /* handle bits that were raised */
4880 if (asserted)
4881 bnx2x_attn_int_asserted(bp, asserted);
4882
4883 if (deasserted)
4884 bnx2x_attn_int_deasserted(bp, deasserted);
4885}
4886
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004887void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4888 u16 index, u8 op, u8 update)
4889{
Ariel Eliordc1ba592013-01-01 05:22:30 +00004890 u32 igu_addr = bp->igu_base_addr;
4891 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004892 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4893 igu_addr);
4894}
4895
Eric Dumazet1191cb82012-04-27 21:39:21 +00004896static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004897{
4898 /* No memory barriers */
4899 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4900 mmiowb(); /* keep prod updates ordered */
4901}
4902
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004903static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4904 union event_ring_elem *elem)
4905{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004906 u8 err = elem->message.error;
4907
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004908 if (!bp->cnic_eth_dev.starting_cid ||
Vladislav Zolotarovc3a8ce62011-05-22 10:08:09 +00004909 (cid < bp->cnic_eth_dev.starting_cid &&
4910 cid != bp->cnic_eth_dev.iscsi_l2_cid))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004911 return 1;
4912
4913 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
4914
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004915 if (unlikely(err)) {
4916
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004917 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
4918 cid);
Yuval Mintz823e1d92013-01-14 05:11:47 +00004919 bnx2x_panic_dump(bp, false);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004920 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004921 bnx2x_cnic_cfc_comp(bp, cid, err);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004922 return 0;
4923}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004924
Eric Dumazet1191cb82012-04-27 21:39:21 +00004925static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004926{
4927 struct bnx2x_mcast_ramrod_params rparam;
4928 int rc;
4929
4930 memset(&rparam, 0, sizeof(rparam));
4931
4932 rparam.mcast_obj = &bp->mcast_obj;
4933
4934 netif_addr_lock_bh(bp->dev);
4935
4936 /* Clear pending state for the last command */
4937 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
4938
4939 /* If there are pending mcast commands - send them */
4940 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
4941 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
4942 if (rc < 0)
4943 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
4944 rc);
4945 }
4946
4947 netif_addr_unlock_bh(bp->dev);
4948}
4949
Eric Dumazet1191cb82012-04-27 21:39:21 +00004950static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
4951 union event_ring_elem *elem)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004952{
4953 unsigned long ramrod_flags = 0;
4954 int rc = 0;
4955 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
4956 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
4957
4958 /* Always push next commands out, don't wait here */
4959 __set_bit(RAMROD_CONT, &ramrod_flags);
4960
Yuval Mintz86564c32013-01-23 03:21:50 +00004961 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
4962 >> BNX2X_SWCID_SHIFT) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004963 case BNX2X_FILTER_MAC_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00004964 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
Merav Sicron55c11942012-11-07 00:45:48 +00004965 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004966 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
4967 else
Barak Witkowski15192a82012-06-19 07:48:28 +00004968 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004969
4970 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004971 case BNX2X_FILTER_MCAST_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00004972 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004973 /* This is only relevant for 57710 where multicast MACs are
4974 * configured as unicast MACs using the same ramrod.
4975 */
4976 bnx2x_handle_mcast_eqe(bp);
4977 return;
4978 default:
4979 BNX2X_ERR("Unsupported classification command: %d\n",
4980 elem->message.data.eth_event.echo);
4981 return;
4982 }
4983
4984 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
4985
4986 if (rc < 0)
4987 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
4988 else if (rc > 0)
4989 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004990}
4991
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004992static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004993
Eric Dumazet1191cb82012-04-27 21:39:21 +00004994static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004995{
4996 netif_addr_lock_bh(bp->dev);
4997
4998 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
4999
5000 /* Send rx_mode command again if was requested */
5001 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
5002 bnx2x_set_storm_rx_mode(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005003 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
5004 &bp->sp_state))
5005 bnx2x_set_iscsi_eth_rx_mode(bp, true);
5006 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
5007 &bp->sp_state))
5008 bnx2x_set_iscsi_eth_rx_mode(bp, false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005009
5010 netif_addr_unlock_bh(bp->dev);
5011}
5012
Eric Dumazet1191cb82012-04-27 21:39:21 +00005013static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
Barak Witkowskia3348722012-04-23 03:04:46 +00005014 union event_ring_elem *elem)
5015{
5016 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
5017 DP(BNX2X_MSG_SP,
5018 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
5019 elem->message.data.vif_list_event.func_bit_map);
5020 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
5021 elem->message.data.vif_list_event.func_bit_map);
5022 } else if (elem->message.data.vif_list_event.echo ==
5023 VIF_LIST_RULE_SET) {
5024 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
5025 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
5026 }
5027}
5028
5029/* called with rtnl_lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005030static void bnx2x_after_function_update(struct bnx2x *bp)
Barak Witkowskia3348722012-04-23 03:04:46 +00005031{
5032 int q, rc;
5033 struct bnx2x_fastpath *fp;
5034 struct bnx2x_queue_state_params queue_params = {NULL};
5035 struct bnx2x_queue_update_params *q_update_params =
5036 &queue_params.params.update;
5037
Yuval Mintz2de67432013-01-23 03:21:43 +00005038 /* Send Q update command with afex vlan removal values for all Qs */
Barak Witkowskia3348722012-04-23 03:04:46 +00005039 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
5040
5041 /* set silent vlan removal values according to vlan mode */
5042 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
5043 &q_update_params->update_flags);
5044 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
5045 &q_update_params->update_flags);
5046 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5047
5048 /* in access mode mark mask and value are 0 to strip all vlans */
5049 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
5050 q_update_params->silent_removal_value = 0;
5051 q_update_params->silent_removal_mask = 0;
5052 } else {
5053 q_update_params->silent_removal_value =
5054 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
5055 q_update_params->silent_removal_mask = VLAN_VID_MASK;
5056 }
5057
5058 for_each_eth_queue(bp, q) {
5059 /* Set the appropriate Queue object */
5060 fp = &bp->fp[q];
Barak Witkowski15192a82012-06-19 07:48:28 +00005061 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005062
5063 /* send the ramrod */
5064 rc = bnx2x_queue_state_change(bp, &queue_params);
5065 if (rc < 0)
5066 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5067 q);
5068 }
5069
Yuval Mintzfea75642013-04-10 13:34:39 +03005070 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
Merav Sicron65565882012-06-19 07:48:26 +00005071 fp = &bp->fp[FCOE_IDX(bp)];
Barak Witkowski15192a82012-06-19 07:48:28 +00005072 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005073
5074 /* clear pending completion bit */
5075 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5076
5077 /* mark latest Q bit */
5078 smp_mb__before_clear_bit();
5079 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
5080 smp_mb__after_clear_bit();
5081
5082 /* send Q update ramrod for FCoE Q */
5083 rc = bnx2x_queue_state_change(bp, &queue_params);
5084 if (rc < 0)
5085 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5086 q);
5087 } else {
5088 /* If no FCoE ring - ACK MCP now */
5089 bnx2x_link_report(bp);
5090 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5091 }
Barak Witkowskia3348722012-04-23 03:04:46 +00005092}
5093
Eric Dumazet1191cb82012-04-27 21:39:21 +00005094static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005095 struct bnx2x *bp, u32 cid)
5096{
Joe Perches94f05b02011-08-14 12:16:20 +00005097 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005098
5099 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
Barak Witkowski15192a82012-06-19 07:48:28 +00005100 return &bnx2x_fcoe_sp_obj(bp, q_obj);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005101 else
Barak Witkowski15192a82012-06-19 07:48:28 +00005102 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005103}
5104
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005105static void bnx2x_eq_int(struct bnx2x *bp)
5106{
5107 u16 hw_cons, sw_cons, sw_prod;
5108 union event_ring_elem *elem;
Merav Sicron55c11942012-11-07 00:45:48 +00005109 u8 echo;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005110 u32 cid;
5111 u8 opcode;
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005112 int rc, spqe_cnt = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005113 struct bnx2x_queue_sp_obj *q_obj;
5114 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
5115 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005116
5117 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5118
5119 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005120 * when we get the next-page we need to adjust so the loop
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005121 * condition below will be met. The next element is the size of a
5122 * regular element and hence incrementing by 1
5123 */
5124 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5125 hw_cons++;
5126
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005127 /* This function may never run in parallel with itself for a
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005128 * specific bp, thus there is no need in "paired" read memory
5129 * barrier here.
5130 */
5131 sw_cons = bp->eq_cons;
5132 sw_prod = bp->eq_prod;
5133
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005134 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005135 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005136
5137 for (; sw_cons != hw_cons;
5138 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5139
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005140 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5141
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005142 rc = bnx2x_iov_eq_sp_event(bp, elem);
5143 if (!rc) {
5144 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5145 rc);
5146 goto next_spqe;
5147 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005148
Yuval Mintz86564c32013-01-23 03:21:50 +00005149 /* elem CID originates from FW; actually LE */
5150 cid = SW_CID((__force __le32)
5151 elem->message.data.cfc_del_event.cid);
5152 opcode = elem->message.opcode;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005153
5154 /* handle eq element */
5155 switch (opcode) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005156 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5157 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
5158 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
5159 continue;
5160
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005161 case EVENT_RING_OPCODE_STAT_QUERY:
Merav Sicron51c1a582012-03-18 10:33:38 +00005162 DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
5163 "got statistics comp event %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005164 bp->stats_comp++);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005165 /* nothing to do with stats comp */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005166 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005167
5168 case EVENT_RING_OPCODE_CFC_DEL:
5169 /* handle according to cid range */
5170 /*
5171 * we may want to verify here that the bp state is
5172 * HALTING
5173 */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005174 DP(BNX2X_MSG_SP,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005175 "got delete ramrod for MULTI[%d]\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005176
5177 if (CNIC_LOADED(bp) &&
5178 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005179 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005180
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005181 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5182
5183 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5184 break;
5185
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005186 goto next_spqe;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005187
5188 case EVENT_RING_OPCODE_STOP_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005189 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005190 if (f_obj->complete_cmd(bp, f_obj,
5191 BNX2X_F_CMD_TX_STOP))
5192 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005193 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
5194 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005195
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005196 case EVENT_RING_OPCODE_START_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005197 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005198 if (f_obj->complete_cmd(bp, f_obj,
5199 BNX2X_F_CMD_TX_START))
5200 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005201 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
5202 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005203
Barak Witkowskia3348722012-04-23 03:04:46 +00005204 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
Merav Sicron55c11942012-11-07 00:45:48 +00005205 echo = elem->message.data.function_update_event.echo;
5206 if (echo == SWITCH_UPDATE) {
5207 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5208 "got FUNC_SWITCH_UPDATE ramrod\n");
5209 if (f_obj->complete_cmd(
5210 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5211 break;
Barak Witkowskia3348722012-04-23 03:04:46 +00005212
Merav Sicron55c11942012-11-07 00:45:48 +00005213 } else {
5214 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5215 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5216 f_obj->complete_cmd(bp, f_obj,
5217 BNX2X_F_CMD_AFEX_UPDATE);
Barak Witkowskia3348722012-04-23 03:04:46 +00005218
Merav Sicron55c11942012-11-07 00:45:48 +00005219 /* We will perform the Queues update from
5220 * sp_rtnl task as all Queue SP operations
5221 * should run under rtnl_lock.
5222 */
5223 smp_mb__before_clear_bit();
5224 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5225 &bp->sp_rtnl_state);
5226 smp_mb__after_clear_bit();
5227
5228 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5229 }
5230
Barak Witkowskia3348722012-04-23 03:04:46 +00005231 goto next_spqe;
5232
5233 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5234 f_obj->complete_cmd(bp, f_obj,
5235 BNX2X_F_CMD_AFEX_VIFLISTS);
5236 bnx2x_after_afex_vif_lists(bp, elem);
5237 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005238 case EVENT_RING_OPCODE_FUNCTION_START:
Merav Sicron51c1a582012-03-18 10:33:38 +00005239 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5240 "got FUNC_START ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005241 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5242 break;
5243
5244 goto next_spqe;
5245
5246 case EVENT_RING_OPCODE_FUNCTION_STOP:
Merav Sicron51c1a582012-03-18 10:33:38 +00005247 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5248 "got FUNC_STOP ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005249 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5250 break;
5251
5252 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005253 }
5254
5255 switch (opcode | bp->state) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005256 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5257 BNX2X_STATE_OPEN):
5258 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005259 BNX2X_STATE_OPENING_WAIT4_PORT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005260 cid = elem->message.data.eth_event.echo &
5261 BNX2X_SWCID_MASK;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005262 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005263 cid);
5264 rss_raw->clear_pending(rss_raw);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005265 break;
5266
5267 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5268 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005269 case (EVENT_RING_OPCODE_SET_MAC |
5270 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005271 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5272 BNX2X_STATE_OPEN):
5273 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5274 BNX2X_STATE_DIAG):
5275 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5276 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005277 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005278 bnx2x_handle_classification_eqe(bp, elem);
5279 break;
5280
5281 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5282 BNX2X_STATE_OPEN):
5283 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5284 BNX2X_STATE_DIAG):
5285 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5286 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005287 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005288 bnx2x_handle_mcast_eqe(bp);
5289 break;
5290
5291 case (EVENT_RING_OPCODE_FILTERS_RULES |
5292 BNX2X_STATE_OPEN):
5293 case (EVENT_RING_OPCODE_FILTERS_RULES |
5294 BNX2X_STATE_DIAG):
5295 case (EVENT_RING_OPCODE_FILTERS_RULES |
5296 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005297 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005298 bnx2x_handle_rx_mode_eqe(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005299 break;
5300 default:
5301 /* unknown event log error and continue */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005302 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5303 elem->message.opcode, bp->state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005304 }
5305next_spqe:
5306 spqe_cnt++;
5307 } /* for */
5308
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00005309 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005310 atomic_add(spqe_cnt, &bp->eq_spq_left);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005311
5312 bp->eq_cons = sw_cons;
5313 bp->eq_prod = sw_prod;
5314 /* Make sure that above mem writes were issued towards the memory */
5315 smp_wmb();
5316
5317 /* update producer */
5318 bnx2x_update_eq_prod(bp, bp->eq_prod);
5319}
5320
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005321static void bnx2x_sp_task(struct work_struct *work)
5322{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08005323 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005324
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005325 DP(BNX2X_MSG_SP, "sp task invoked\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005326
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005327 /* make sure the atomic interrupt_occurred has been written */
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005328 smp_rmb();
5329 if (atomic_read(&bp->interrupt_occurred)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005330
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005331 /* what work needs to be performed? */
5332 u16 status = bnx2x_update_dsb_idx(bp);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005333
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005334 DP(BNX2X_MSG_SP, "status %x\n", status);
5335 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5336 atomic_set(&bp->interrupt_occurred, 0);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005337
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005338 /* HW attentions */
5339 if (status & BNX2X_DEF_SB_ATT_IDX) {
5340 bnx2x_attn_int(bp);
5341 status &= ~BNX2X_DEF_SB_ATT_IDX;
Vladislav Zolotarov019dbb42011-07-19 01:43:25 +00005342 }
Merav Sicron55c11942012-11-07 00:45:48 +00005343
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005344 /* SP events: STAT_QUERY and others */
5345 if (status & BNX2X_DEF_SB_IDX) {
5346 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005347
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005348 if (FCOE_INIT(bp) &&
5349 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5350 /* Prevent local bottom-halves from running as
5351 * we are going to change the local NAPI list.
5352 */
5353 local_bh_disable();
5354 napi_schedule(&bnx2x_fcoe(bp, napi));
5355 local_bh_enable();
5356 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005357
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005358 /* Handle EQ completions */
5359 bnx2x_eq_int(bp);
5360 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5361 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5362
5363 status &= ~BNX2X_DEF_SB_IDX;
5364 }
5365
5366 /* if status is non zero then perhaps something went wrong */
5367 if (unlikely(status))
5368 DP(BNX2X_MSG_SP,
5369 "got an unknown interrupt! (status 0x%x)\n", status);
5370
5371 /* ack status block only if something was actually handled */
5372 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5373 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005374 }
5375
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005376 /* must be called after the EQ processing (since eq leads to sriov
5377 * ramrod completion flows).
5378 * This flow may have been scheduled by the arrival of a ramrod
5379 * completion, or by the sriov code rescheduling itself.
5380 */
5381 bnx2x_iov_sp_task(bp);
Barak Witkowskia3348722012-04-23 03:04:46 +00005382
5383 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5384 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5385 &bp->sp_state)) {
5386 bnx2x_link_report(bp);
5387 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5388 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005389}
5390
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005391irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005392{
5393 struct net_device *dev = dev_instance;
5394 struct bnx2x *bp = netdev_priv(dev);
5395
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005396 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5397 IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005398
5399#ifdef BNX2X_STOP_ON_ERROR
5400 if (unlikely(bp->panic))
5401 return IRQ_HANDLED;
5402#endif
5403
Merav Sicron55c11942012-11-07 00:45:48 +00005404 if (CNIC_LOADED(bp)) {
Michael Chan993ac7b2009-10-10 13:46:56 +00005405 struct cnic_ops *c_ops;
5406
5407 rcu_read_lock();
5408 c_ops = rcu_dereference(bp->cnic_ops);
5409 if (c_ops)
5410 c_ops->cnic_handler(bp->cnic_data, NULL);
5411 rcu_read_unlock();
5412 }
Merav Sicron55c11942012-11-07 00:45:48 +00005413
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005414 /* schedule sp task to perform default status block work, ack
5415 * attentions and enable interrupts.
5416 */
5417 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005418
5419 return IRQ_HANDLED;
5420}
5421
5422/* end of slow path */
5423
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005424void bnx2x_drv_pulse(struct bnx2x *bp)
5425{
5426 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5427 bp->fw_drv_pulse_wr_seq);
5428}
5429
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005430static void bnx2x_timer(unsigned long data)
5431{
5432 struct bnx2x *bp = (struct bnx2x *) data;
5433
5434 if (!netif_running(bp->dev))
5435 return;
5436
Ariel Elior67c431a2013-01-01 05:22:36 +00005437 if (IS_PF(bp) &&
5438 !BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005439 int mb_idx = BP_FW_MB_IDX(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005440 u32 drv_pulse;
5441 u32 mcp_pulse;
5442
5443 ++bp->fw_drv_pulse_wr_seq;
5444 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
5445 /* TBD - add SYSTEM_TIME */
5446 drv_pulse = bp->fw_drv_pulse_wr_seq;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005447 bnx2x_drv_pulse(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005448
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005449 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005450 MCP_PULSE_SEQ_MASK);
5451 /* The delta between driver pulse and mcp response
5452 * should be 1 (before mcp response) or 0 (after mcp response)
5453 */
5454 if ((drv_pulse != mcp_pulse) &&
5455 (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
5456 /* someone lost a heartbeat... */
5457 BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
5458 drv_pulse, mcp_pulse);
5459 }
5460 }
5461
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07005462 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07005463 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005464
Ariel Eliorabc5a022013-01-01 05:22:43 +00005465 /* sample pf vf bulletin board for new posts from pf */
Yuval Mintz371734882013-06-24 11:04:10 +03005466 if (IS_VF(bp))
5467 bnx2x_timer_sriov(bp);
Ariel Elior78c3bcc2013-06-20 17:39:08 +03005468
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005469 mod_timer(&bp->timer, jiffies + bp->current_interval);
5470}
5471
5472/* end of Statistics */
5473
5474/* nic init */
5475
5476/*
5477 * nic init service functions
5478 */
5479
Eric Dumazet1191cb82012-04-27 21:39:21 +00005480static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005481{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005482 u32 i;
5483 if (!(len%4) && !(addr%4))
5484 for (i = 0; i < len; i += 4)
5485 REG_WR(bp, addr + i, fill);
5486 else
5487 for (i = 0; i < len; i++)
5488 REG_WR8(bp, addr + i, fill);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005489}
5490
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005491/* helper: writes FP SP data to FW - data_size in dwords */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005492static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5493 int fw_sb_id,
5494 u32 *sb_data_p,
5495 u32 data_size)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005496{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005497 int index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005498 for (index = 0; index < data_size; index++)
5499 REG_WR(bp, BAR_CSTRORM_INTMEM +
5500 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5501 sizeof(u32)*index,
5502 *(sb_data_p + index));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005503}
5504
Eric Dumazet1191cb82012-04-27 21:39:21 +00005505static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005506{
5507 u32 *sb_data_p;
5508 u32 data_size = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005509 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005510 struct hc_status_block_data_e1x sb_data_e1x;
5511
5512 /* disable the function first */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005513 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005514 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005515 sb_data_e2.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005516 sb_data_e2.common.p_func.vf_valid = false;
5517 sb_data_p = (u32 *)&sb_data_e2;
5518 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5519 } else {
5520 memset(&sb_data_e1x, 0,
5521 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005522 sb_data_e1x.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005523 sb_data_e1x.common.p_func.vf_valid = false;
5524 sb_data_p = (u32 *)&sb_data_e1x;
5525 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5526 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005527 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5528
5529 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5530 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5531 CSTORM_STATUS_BLOCK_SIZE);
5532 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5533 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5534 CSTORM_SYNC_BLOCK_SIZE);
5535}
5536
5537/* helper: writes SP SB data to FW */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005538static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005539 struct hc_sp_status_block_data *sp_sb_data)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005540{
5541 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005542 int i;
5543 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5544 REG_WR(bp, BAR_CSTRORM_INTMEM +
5545 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5546 i*sizeof(u32),
5547 *((u32 *)sp_sb_data + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005548}
5549
Eric Dumazet1191cb82012-04-27 21:39:21 +00005550static void bnx2x_zero_sp_sb(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005551{
5552 int func = BP_FUNC(bp);
5553 struct hc_sp_status_block_data sp_sb_data;
5554 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5555
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005556 sp_sb_data.state = SB_DISABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005557 sp_sb_data.p_func.vf_valid = false;
5558
5559 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5560
5561 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5562 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5563 CSTORM_SP_STATUS_BLOCK_SIZE);
5564 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5565 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5566 CSTORM_SP_SYNC_BLOCK_SIZE);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005567}
5568
Eric Dumazet1191cb82012-04-27 21:39:21 +00005569static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005570 int igu_sb_id, int igu_seg_id)
5571{
5572 hc_sm->igu_sb_id = igu_sb_id;
5573 hc_sm->igu_seg_id = igu_seg_id;
5574 hc_sm->timer_value = 0xFF;
5575 hc_sm->time_to_expire = 0xFFFFFFFF;
5576}
5577
David S. Miller8decf862011-09-22 03:23:13 -04005578/* allocates state machine ids. */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005579static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
David S. Miller8decf862011-09-22 03:23:13 -04005580{
5581 /* zero out state machine indices */
5582 /* rx indices */
5583 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5584
5585 /* tx indices */
5586 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5587 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5588 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5589 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5590
5591 /* map indices */
5592 /* rx indices */
5593 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5594 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5595
5596 /* tx indices */
5597 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5598 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5599 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5600 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5601 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5602 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5603 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5604 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5605}
5606
Ariel Eliorb93288d2013-01-01 05:22:35 +00005607void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005608 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5609{
5610 int igu_seg_id;
5611
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005612 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005613 struct hc_status_block_data_e1x sb_data_e1x;
5614 struct hc_status_block_sm *hc_sm_p;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005615 int data_size;
5616 u32 *sb_data_p;
5617
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005618 if (CHIP_INT_MODE_IS_BC(bp))
5619 igu_seg_id = HC_SEG_ACCESS_NORM;
5620 else
5621 igu_seg_id = IGU_SEG_ACCESS_NORM;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005622
5623 bnx2x_zero_fp_sb(bp, fw_sb_id);
5624
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005625 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005626 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005627 sb_data_e2.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005628 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5629 sb_data_e2.common.p_func.vf_id = vfid;
5630 sb_data_e2.common.p_func.vf_valid = vf_valid;
5631 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5632 sb_data_e2.common.same_igu_sb_1b = true;
5633 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5634 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5635 hc_sm_p = sb_data_e2.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005636 sb_data_p = (u32 *)&sb_data_e2;
5637 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005638 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005639 } else {
5640 memset(&sb_data_e1x, 0,
5641 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005642 sb_data_e1x.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005643 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5644 sb_data_e1x.common.p_func.vf_id = 0xff;
5645 sb_data_e1x.common.p_func.vf_valid = false;
5646 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5647 sb_data_e1x.common.same_igu_sb_1b = true;
5648 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5649 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5650 hc_sm_p = sb_data_e1x.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005651 sb_data_p = (u32 *)&sb_data_e1x;
5652 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005653 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005654 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005655
5656 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5657 igu_sb_id, igu_seg_id);
5658 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5659 igu_sb_id, igu_seg_id);
5660
Merav Sicron51c1a582012-03-18 10:33:38 +00005661 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005662
Yuval Mintz86564c32013-01-23 03:21:50 +00005663 /* write indices to HW - PCI guarantees endianity of regpairs */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005664 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5665}
5666
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005667static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005668 u16 tx_usec, u16 rx_usec)
5669{
Ariel Elior6383c0b2011-07-14 08:31:57 +00005670 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005671 false, rx_usec);
Ariel Elior6383c0b2011-07-14 08:31:57 +00005672 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5673 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5674 tx_usec);
5675 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5676 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5677 tx_usec);
5678 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5679 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5680 tx_usec);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005681}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005682
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005683static void bnx2x_init_def_sb(struct bnx2x *bp)
5684{
5685 struct host_sp_status_block *def_sb = bp->def_status_blk;
5686 dma_addr_t mapping = bp->def_status_blk_mapping;
5687 int igu_sp_sb_index;
5688 int igu_seg_id;
5689 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005690 int func = BP_FUNC(bp);
David S. Miller88c51002011-10-07 13:38:43 -04005691 int reg_offset, reg_offset_en5;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005692 u64 section;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005693 int index;
5694 struct hc_sp_status_block_data sp_sb_data;
5695 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5696
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005697 if (CHIP_INT_MODE_IS_BC(bp)) {
5698 igu_sp_sb_index = DEF_SB_IGU_ID;
5699 igu_seg_id = HC_SEG_ACCESS_DEF;
5700 } else {
5701 igu_sp_sb_index = bp->igu_dsb_id;
5702 igu_seg_id = IGU_SEG_ACCESS_DEF;
5703 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005704
5705 /* ATTN */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005706 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005707 atten_status_block);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005708 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005709
Eliezer Tamir49d66772008-02-28 11:53:13 -08005710 bp->attn_state = 0;
5711
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005712 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5713 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
David S. Miller88c51002011-10-07 13:38:43 -04005714 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5715 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005716 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005717 int sindex;
5718 /* take care of sig[0]..sig[4] */
5719 for (sindex = 0; sindex < 4; sindex++)
5720 bp->attn_group[index].sig[sindex] =
5721 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005722
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005723 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005724 /*
5725 * enable5 is separate from the rest of the registers,
5726 * and therefore the address skip is 4
5727 * and not 16 between the different groups
5728 */
5729 bp->attn_group[index].sig[4] = REG_RD(bp,
David S. Miller88c51002011-10-07 13:38:43 -04005730 reg_offset_en5 + 0x4*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005731 else
5732 bp->attn_group[index].sig[4] = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005733 }
5734
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005735 if (bp->common.int_block == INT_BLOCK_HC) {
5736 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5737 HC_REG_ATTN_MSG0_ADDR_L);
5738
5739 REG_WR(bp, reg_offset, U64_LO(section));
5740 REG_WR(bp, reg_offset + 4, U64_HI(section));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005741 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005742 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5743 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5744 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005745
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005746 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5747 sp_sb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005748
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005749 bnx2x_zero_sp_sb(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005750
Yuval Mintz86564c32013-01-23 03:21:50 +00005751 /* PCI guarantees endianity of regpairs */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005752 sp_sb_data.state = SB_ENABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005753 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5754 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5755 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5756 sp_sb_data.igu_seg_id = igu_seg_id;
5757 sp_sb_data.p_func.pf_id = func;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005758 sp_sb_data.p_func.vnic_id = BP_VN(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005759 sp_sb_data.p_func.vf_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005760
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005761 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005762
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005763 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005764}
5765
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005766void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005767{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005768 int i;
5769
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005770 for_each_eth_queue(bp, i)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005771 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
Ariel Elior423cfa7e2011-03-14 13:43:22 -07005772 bp->tx_ticks, bp->rx_ticks);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005773}
5774
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005775static void bnx2x_init_sp_ring(struct bnx2x *bp)
5776{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005777 spin_lock_init(&bp->spq_lock);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005778 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005779
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005780 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005781 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5782 bp->spq_prod_bd = bp->spq;
5783 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005784}
5785
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005786static void bnx2x_init_eq_ring(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005787{
5788 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005789 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5790 union event_ring_elem *elem =
5791 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005792
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005793 elem->next_page.addr.hi =
5794 cpu_to_le32(U64_HI(bp->eq_mapping +
5795 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5796 elem->next_page.addr.lo =
5797 cpu_to_le32(U64_LO(bp->eq_mapping +
5798 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005799 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005800 bp->eq_cons = 0;
5801 bp->eq_prod = NUM_EQ_DESC;
5802 bp->eq_cons_sb = BNX2X_EQ_INDEX;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005803 /* we want a warning message before it gets wrought... */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005804 atomic_set(&bp->eq_spq_left,
5805 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005806}
5807
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005808/* called with netif_addr_lock_bh() */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005809int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5810 unsigned long rx_mode_flags,
5811 unsigned long rx_accept_flags,
5812 unsigned long tx_accept_flags,
5813 unsigned long ramrod_flags)
Tom Herbertab532cf2011-02-16 10:27:02 +00005814{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005815 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5816 int rc;
Tom Herbertab532cf2011-02-16 10:27:02 +00005817
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005818 memset(&ramrod_param, 0, sizeof(ramrod_param));
Tom Herbertab532cf2011-02-16 10:27:02 +00005819
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005820 /* Prepare ramrod parameters */
5821 ramrod_param.cid = 0;
5822 ramrod_param.cl_id = cl_id;
5823 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5824 ramrod_param.func_id = BP_FUNC(bp);
5825
5826 ramrod_param.pstate = &bp->sp_state;
5827 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
5828
5829 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5830 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5831
5832 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5833
5834 ramrod_param.ramrod_flags = ramrod_flags;
5835 ramrod_param.rx_mode_flags = rx_mode_flags;
5836
5837 ramrod_param.rx_accept_flags = rx_accept_flags;
5838 ramrod_param.tx_accept_flags = tx_accept_flags;
5839
5840 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5841 if (rc < 0) {
5842 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
Yuval Mintz924d75a2013-01-23 03:21:44 +00005843 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005844 }
Yuval Mintz924d75a2013-01-23 03:21:44 +00005845
5846 return 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005847}
5848
Yuval Mintz86564c32013-01-23 03:21:50 +00005849static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
5850 unsigned long *rx_accept_flags,
5851 unsigned long *tx_accept_flags)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005852{
Yuval Mintz924d75a2013-01-23 03:21:44 +00005853 /* Clear the flags first */
5854 *rx_accept_flags = 0;
5855 *tx_accept_flags = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005856
Yuval Mintz924d75a2013-01-23 03:21:44 +00005857 switch (rx_mode) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005858 case BNX2X_RX_MODE_NONE:
5859 /*
5860 * 'drop all' supersedes any accept flags that may have been
5861 * passed to the function.
5862 */
5863 break;
5864 case BNX2X_RX_MODE_NORMAL:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005865 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5866 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
5867 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005868
5869 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005870 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5871 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
5872 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005873
5874 break;
5875 case BNX2X_RX_MODE_ALLMULTI:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005876 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5877 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5878 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005879
5880 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005881 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5882 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5883 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005884
5885 break;
5886 case BNX2X_RX_MODE_PROMISC:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005887 /* According to definition of SI mode, iface in promisc mode
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005888 * should receive matched and unmatched (in resolution of port)
5889 * unicast packets.
5890 */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005891 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
5892 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5893 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5894 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005895
5896 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005897 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5898 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005899
5900 if (IS_MF_SI(bp))
Yuval Mintz924d75a2013-01-23 03:21:44 +00005901 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005902 else
Yuval Mintz924d75a2013-01-23 03:21:44 +00005903 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005904
5905 break;
5906 default:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005907 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
5908 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005909 }
5910
Yuval Mintz924d75a2013-01-23 03:21:44 +00005911 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005912 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
Yuval Mintz924d75a2013-01-23 03:21:44 +00005913 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
5914 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005915 }
5916
Yuval Mintz924d75a2013-01-23 03:21:44 +00005917 return 0;
5918}
5919
5920/* called with netif_addr_lock_bh() */
5921int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
5922{
5923 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
5924 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
5925 int rc;
5926
5927 if (!NO_FCOE(bp))
5928 /* Configure rx_mode of FCoE Queue */
5929 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
5930
5931 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
5932 &tx_accept_flags);
5933 if (rc)
5934 return rc;
5935
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005936 __set_bit(RAMROD_RX, &ramrod_flags);
5937 __set_bit(RAMROD_TX, &ramrod_flags);
5938
Yuval Mintz924d75a2013-01-23 03:21:44 +00005939 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
5940 rx_accept_flags, tx_accept_flags,
5941 ramrod_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005942}
5943
Eilon Greenstein471de712008-08-13 15:49:35 -07005944static void bnx2x_init_internal_common(struct bnx2x *bp)
5945{
5946 int i;
5947
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08005948 if (IS_MF_SI(bp))
5949 /*
5950 * In switch independent mode, the TSTORM needs to accept
5951 * packets that failed classification, since approximate match
5952 * mac addresses aren't written to NIG LLH
5953 */
5954 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5955 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005956 else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
5957 REG_WR8(bp, BAR_TSTRORM_INTMEM +
5958 TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08005959
Eilon Greenstein471de712008-08-13 15:49:35 -07005960 /* Zero this manually as its initialization is
5961 currently missing in the initTool */
5962 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
5963 REG_WR(bp, BAR_USTRORM_INTMEM +
5964 USTORM_AGG_DATA_OFFSET + i * 4, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005965 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005966 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
5967 CHIP_INT_MODE_IS_BC(bp) ?
5968 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
5969 }
Eilon Greenstein471de712008-08-13 15:49:35 -07005970}
5971
Eilon Greenstein471de712008-08-13 15:49:35 -07005972static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
5973{
5974 switch (load_code) {
5975 case FW_MSG_CODE_DRV_LOAD_COMMON:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005976 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
Eilon Greenstein471de712008-08-13 15:49:35 -07005977 bnx2x_init_internal_common(bp);
5978 /* no break */
5979
5980 case FW_MSG_CODE_DRV_LOAD_PORT:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005981 /* nothing to do */
Eilon Greenstein471de712008-08-13 15:49:35 -07005982 /* no break */
5983
5984 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005985 /* internal memory per function is
5986 initialized inside bnx2x_pf_init */
Eilon Greenstein471de712008-08-13 15:49:35 -07005987 break;
5988
5989 default:
5990 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5991 break;
5992 }
5993}
5994
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005995static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
5996{
Merav Sicron55c11942012-11-07 00:45:48 +00005997 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005998}
5999
6000static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
6001{
Merav Sicron55c11942012-11-07 00:45:48 +00006002 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006003}
6004
Eric Dumazet1191cb82012-04-27 21:39:21 +00006005static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006006{
6007 if (CHIP_IS_E1x(fp->bp))
6008 return BP_L_ID(fp->bp) + fp->index;
6009 else /* We want Client ID to be the same as IGU SB ID for 57712 */
6010 return bnx2x_fp_igu_sb_id(fp);
6011}
6012
Ariel Elior6383c0b2011-07-14 08:31:57 +00006013static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006014{
6015 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
Ariel Elior6383c0b2011-07-14 08:31:57 +00006016 u8 cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006017 unsigned long q_type = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006018 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
Dmitry Kravkovf233caf2011-11-13 04:34:22 +00006019 fp->rx_queue = fp_idx;
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006020 fp->cid = fp_idx;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006021 fp->cl_id = bnx2x_fp_cl_id(fp);
6022 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
6023 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006024 /* qZone id equals to FW (per path) client id */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006025 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
6026
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006027 /* init shortcut */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006028 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
Ariel Elior7a752992012-01-26 06:01:53 +00006029
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006030 /* Setup SB indices */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006031 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006032
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006033 /* Configure Queue State object */
6034 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6035 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
Ariel Elior6383c0b2011-07-14 08:31:57 +00006036
6037 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
6038
6039 /* init tx data */
6040 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00006041 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
6042 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
6043 FP_COS_TO_TXQ(fp, cos, bp),
6044 BNX2X_TX_SB_INDEX_BASE + cos, fp);
6045 cids[cos] = fp->txdata_ptr[cos]->cid;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006046 }
6047
Ariel Eliorad5afc82013-01-01 05:22:26 +00006048 /* nothing more for vf to do here */
6049 if (IS_VF(bp))
6050 return;
6051
6052 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
6053 fp->fw_sb_id, fp->igu_sb_id);
6054 bnx2x_update_fpsb_idx(fp);
Barak Witkowski15192a82012-06-19 07:48:28 +00006055 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
6056 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
Ariel Elior6383c0b2011-07-14 08:31:57 +00006057 bnx2x_sp_mapping(bp, q_rdata), q_type);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006058
6059 /**
6060 * Configure classification DBs: Always enable Tx switching
6061 */
6062 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
6063
Ariel Eliorad5afc82013-01-01 05:22:26 +00006064 DP(NETIF_MSG_IFUP,
6065 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6066 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6067 fp->igu_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006068}
6069
Eric Dumazet1191cb82012-04-27 21:39:21 +00006070static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
6071{
6072 int i;
6073
6074 for (i = 1; i <= NUM_TX_RINGS; i++) {
6075 struct eth_tx_next_bd *tx_next_bd =
6076 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
6077
6078 tx_next_bd->addr_hi =
6079 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
6080 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6081 tx_next_bd->addr_lo =
6082 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
6083 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6084 }
6085
Yuval Mintz639d65b2013-06-02 00:06:21 +00006086 *txdata->tx_cons_sb = cpu_to_le16(0);
6087
Eric Dumazet1191cb82012-04-27 21:39:21 +00006088 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
6089 txdata->tx_db.data.zero_fill1 = 0;
6090 txdata->tx_db.data.prod = 0;
6091
6092 txdata->tx_pkt_prod = 0;
6093 txdata->tx_pkt_cons = 0;
6094 txdata->tx_bd_prod = 0;
6095 txdata->tx_bd_cons = 0;
6096 txdata->tx_pkt = 0;
6097}
6098
Merav Sicron55c11942012-11-07 00:45:48 +00006099static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
6100{
6101 int i;
6102
6103 for_each_tx_queue_cnic(bp, i)
6104 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
6105}
Yuval Mintzd76a6112013-06-02 00:06:17 +00006106
Eric Dumazet1191cb82012-04-27 21:39:21 +00006107static void bnx2x_init_tx_rings(struct bnx2x *bp)
6108{
6109 int i;
6110 u8 cos;
6111
Merav Sicron55c11942012-11-07 00:45:48 +00006112 for_each_eth_queue(bp, i)
Eric Dumazet1191cb82012-04-27 21:39:21 +00006113 for_each_cos_in_tx_queue(&bp->fp[i], cos)
Merav Sicron65565882012-06-19 07:48:26 +00006114 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
Eric Dumazet1191cb82012-04-27 21:39:21 +00006115}
6116
Merav Sicron55c11942012-11-07 00:45:48 +00006117void bnx2x_nic_init_cnic(struct bnx2x *bp)
6118{
6119 if (!NO_FCOE(bp))
6120 bnx2x_init_fcoe_fp(bp);
6121
6122 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6123 BNX2X_VF_ID_INVALID, false,
6124 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
6125
6126 /* ensure status block indices were read */
6127 rmb();
6128 bnx2x_init_rx_rings_cnic(bp);
6129 bnx2x_init_tx_rings_cnic(bp);
6130
6131 /* flush all */
6132 mb();
6133 mmiowb();
6134}
6135
Yuval Mintzecf01c22013-04-22 02:53:03 +00006136void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006137{
6138 int i;
6139
Yuval Mintzecf01c22013-04-22 02:53:03 +00006140 /* Setup NIC internals and enable interrupts */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006141 for_each_eth_queue(bp, i)
Ariel Elior6383c0b2011-07-14 08:31:57 +00006142 bnx2x_init_eth_fp(bp, i);
Ariel Eliorad5afc82013-01-01 05:22:26 +00006143
6144 /* ensure status block indices were read */
6145 rmb();
6146 bnx2x_init_rx_rings(bp);
6147 bnx2x_init_tx_rings(bp);
6148
Yuval Mintzecf01c22013-04-22 02:53:03 +00006149 if (IS_PF(bp)) {
6150 /* Initialize MOD_ABS interrupts */
6151 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6152 bp->common.shmem_base,
6153 bp->common.shmem2_base, BP_PORT(bp));
Eilon Greenstein16119782009-03-02 07:59:27 +00006154
Yuval Mintzecf01c22013-04-22 02:53:03 +00006155 /* initialize the default status block and sp ring */
6156 bnx2x_init_def_sb(bp);
6157 bnx2x_update_dsb_idx(bp);
6158 bnx2x_init_sp_ring(bp);
Yuval Mintz3cdeec22013-06-02 00:06:19 +00006159 } else {
6160 bnx2x_memset_stats(bp);
Yuval Mintzecf01c22013-04-22 02:53:03 +00006161 }
6162}
Eilon Greenstein16119782009-03-02 07:59:27 +00006163
Yuval Mintzecf01c22013-04-22 02:53:03 +00006164void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6165{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006166 bnx2x_init_eq_ring(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07006167 bnx2x_init_internal(bp, load_code);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006168 bnx2x_pf_init(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006169 bnx2x_stats_init(bp);
6170
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006171 /* flush all before enabling interrupts */
6172 mb();
6173 mmiowb();
6174
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08006175 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00006176
6177 /* Check for SPIO5 */
6178 bnx2x_attn_int_deasserted0(bp,
6179 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6180 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006181}
6182
Yuval Mintzecf01c22013-04-22 02:53:03 +00006183/* gzip service functions */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006184static int bnx2x_gunzip_init(struct bnx2x *bp)
6185{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006186 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6187 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006188 if (bp->gunzip_buf == NULL)
6189 goto gunzip_nomem1;
6190
6191 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6192 if (bp->strm == NULL)
6193 goto gunzip_nomem2;
6194
David S. Miller7ab24bf2011-06-29 05:48:41 -07006195 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006196 if (bp->strm->workspace == NULL)
6197 goto gunzip_nomem3;
6198
6199 return 0;
6200
6201gunzip_nomem3:
6202 kfree(bp->strm);
6203 bp->strm = NULL;
6204
6205gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006206 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6207 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006208 bp->gunzip_buf = NULL;
6209
6210gunzip_nomem1:
Merav Sicron51c1a582012-03-18 10:33:38 +00006211 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006212 return -ENOMEM;
6213}
6214
6215static void bnx2x_gunzip_end(struct bnx2x *bp)
6216{
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006217 if (bp->strm) {
David S. Miller7ab24bf2011-06-29 05:48:41 -07006218 vfree(bp->strm->workspace);
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006219 kfree(bp->strm);
6220 bp->strm = NULL;
6221 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006222
6223 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006224 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6225 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006226 bp->gunzip_buf = NULL;
6227 }
6228}
6229
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006230static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006231{
6232 int n, rc;
6233
6234 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006235 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6236 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006237 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006238 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006239
6240 n = 10;
6241
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006242#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006243
6244 if (zbuf[3] & FNAME)
6245 while ((zbuf[n++] != 0) && (n < len));
6246
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006247 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006248 bp->strm->avail_in = len - n;
6249 bp->strm->next_out = bp->gunzip_buf;
6250 bp->strm->avail_out = FW_BUF_SIZE;
6251
6252 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6253 if (rc != Z_OK)
6254 return rc;
6255
6256 rc = zlib_inflate(bp->strm, Z_FINISH);
6257 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00006258 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6259 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006260
6261 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6262 if (bp->gunzip_outlen & 0x3)
Merav Sicron51c1a582012-03-18 10:33:38 +00006263 netdev_err(bp->dev,
6264 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006265 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006266 bp->gunzip_outlen >>= 2;
6267
6268 zlib_inflateEnd(bp->strm);
6269
6270 if (rc == Z_STREAM_END)
6271 return 0;
6272
6273 return rc;
6274}
6275
6276/* nic load/unload */
6277
6278/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006279 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006280 */
6281
6282/* send a NIG loopback debug packet */
6283static void bnx2x_lb_pckt(struct bnx2x *bp)
6284{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006285 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006286
6287 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006288 wb_write[0] = 0x55555555;
6289 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006290 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006291 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006292
6293 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006294 wb_write[0] = 0x09000000;
6295 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006296 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006297 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006298}
6299
6300/* some of the internal memories
6301 * are not directly readable from the driver
6302 * to test them we send debug packets
6303 */
6304static int bnx2x_int_mem_test(struct bnx2x *bp)
6305{
6306 int factor;
6307 int count, i;
6308 u32 val = 0;
6309
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006310 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006311 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006312 else if (CHIP_REV_IS_EMUL(bp))
6313 factor = 200;
6314 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006315 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006316
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006317 /* Disable inputs of parser neighbor blocks */
6318 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6319 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6320 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006321 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006322
6323 /* Write 0 to parser credits for CFC search request */
6324 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6325
6326 /* send Ethernet packet */
6327 bnx2x_lb_pckt(bp);
6328
6329 /* TODO do i reset NIG statistic? */
6330 /* Wait until NIG register shows 1 packet of size 0x10 */
6331 count = 1000 * factor;
6332 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006333
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006334 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6335 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006336 if (val == 0x10)
6337 break;
6338
Yuval Mintz639d65b2013-06-02 00:06:21 +00006339 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006340 count--;
6341 }
6342 if (val != 0x10) {
6343 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6344 return -1;
6345 }
6346
6347 /* Wait until PRS register shows 1 packet */
6348 count = 1000 * factor;
6349 while (count) {
6350 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006351 if (val == 1)
6352 break;
6353
Yuval Mintz639d65b2013-06-02 00:06:21 +00006354 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006355 count--;
6356 }
6357 if (val != 0x1) {
6358 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6359 return -2;
6360 }
6361
6362 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006363 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006364 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006365 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006366 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006367 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6368 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006369
6370 DP(NETIF_MSG_HW, "part2\n");
6371
6372 /* Disable inputs of parser neighbor blocks */
6373 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6374 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6375 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006376 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006377
6378 /* Write 0 to parser credits for CFC search request */
6379 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6380
6381 /* send 10 Ethernet packets */
6382 for (i = 0; i < 10; i++)
6383 bnx2x_lb_pckt(bp);
6384
6385 /* Wait until NIG register shows 10 + 1
6386 packets of size 11*0x10 = 0xb0 */
6387 count = 1000 * factor;
6388 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006389
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006390 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6391 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006392 if (val == 0xb0)
6393 break;
6394
Yuval Mintz639d65b2013-06-02 00:06:21 +00006395 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006396 count--;
6397 }
6398 if (val != 0xb0) {
6399 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6400 return -3;
6401 }
6402
6403 /* Wait until PRS register shows 2 packets */
6404 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6405 if (val != 2)
6406 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6407
6408 /* Write 1 to parser credits for CFC search request */
6409 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6410
6411 /* Wait until PRS register shows 3 packets */
6412 msleep(10 * factor);
6413 /* Wait until NIG register shows 1 packet of size 0x10 */
6414 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6415 if (val != 3)
6416 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6417
6418 /* clear NIG EOP FIFO */
6419 for (i = 0; i < 11; i++)
6420 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6421 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6422 if (val != 1) {
6423 BNX2X_ERR("clear of NIG failed\n");
6424 return -4;
6425 }
6426
6427 /* Reset and init BRB, PRS, NIG */
6428 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6429 msleep(50);
6430 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6431 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006432 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6433 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Merav Sicron55c11942012-11-07 00:45:48 +00006434 if (!CNIC_SUPPORT(bp))
6435 /* set NIC mode */
6436 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006437
6438 /* Enable inputs of parser neighbor blocks */
6439 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6440 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6441 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006442 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006443
6444 DP(NETIF_MSG_HW, "done\n");
6445
6446 return 0; /* OK */
6447}
6448
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006449static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006450{
Yuval Mintzb343d002012-12-02 04:05:53 +00006451 u32 val;
6452
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006453 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006454 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006455 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6456 else
6457 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006458 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6459 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006460 /*
6461 * mask read length error interrupts in brb for parser
6462 * (parsing unit and 'checksum and crc' unit)
6463 * these errors are legal (PU reads fixed length and CAC can cause
6464 * read length error on truncated packets)
6465 */
6466 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006467 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6468 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6469 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6470 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6471 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006472/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6473/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006474 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6475 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6476 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006477/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6478/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006479 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6480 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6481 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6482 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006483/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6484/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006485
Yuval Mintzb343d002012-12-02 04:05:53 +00006486 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6487 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6488 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6489 if (!CHIP_IS_E1x(bp))
6490 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6491 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6492 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6493
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006494 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6495 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6496 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006497/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006498
6499 if (!CHIP_IS_E1x(bp))
6500 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6501 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6502
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006503 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6504 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006505/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006506 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006507}
6508
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006509static void bnx2x_reset_common(struct bnx2x *bp)
6510{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006511 u32 val = 0x1400;
6512
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006513 /* reset_common */
6514 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6515 0xd3ffff7f);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006516
6517 if (CHIP_IS_E3(bp)) {
6518 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6519 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6520 }
6521
6522 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6523}
6524
6525static void bnx2x_setup_dmae(struct bnx2x *bp)
6526{
6527 bp->dmae_ready = 0;
6528 spin_lock_init(&bp->dmae_lock);
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006529}
6530
Eilon Greenstein573f2032009-08-12 08:24:14 +00006531static void bnx2x_init_pxp(struct bnx2x *bp)
6532{
6533 u16 devctl;
6534 int r_order, w_order;
6535
Jiang Liu2a80eeb2012-08-20 13:26:51 -06006536 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
Eilon Greenstein573f2032009-08-12 08:24:14 +00006537 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6538 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6539 if (bp->mrrs == -1)
6540 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6541 else {
6542 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6543 r_order = bp->mrrs;
6544 }
6545
6546 bnx2x_init_pxp_arb(bp, r_order, w_order);
6547}
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006548
6549static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6550{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006551 int is_required;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006552 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006553 int port;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006554
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006555 if (BP_NOMCP(bp))
6556 return;
6557
6558 is_required = 0;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006559 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6560 SHARED_HW_CFG_FAN_FAILURE_MASK;
6561
6562 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6563 is_required = 1;
6564
6565 /*
6566 * The fan failure mechanism is usually related to the PHY type since
6567 * the power consumption of the board is affected by the PHY. Currently,
6568 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6569 */
6570 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6571 for (port = PORT_0; port < PORT_MAX; port++) {
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006572 is_required |=
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006573 bnx2x_fan_failure_det_req(
6574 bp,
6575 bp->common.shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006576 bp->common.shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006577 port);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006578 }
6579
6580 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6581
6582 if (is_required == 0)
6583 return;
6584
6585 /* Fan failure is indicated by SPIO 5 */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006586 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006587
6588 /* set to active low mode */
6589 val = REG_RD(bp, MISC_REG_SPIO_INT);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006590 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006591 REG_WR(bp, MISC_REG_SPIO_INT, val);
6592
6593 /* enable interrupt to signal the IGU */
6594 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006595 val |= MISC_SPIO_SPIO5;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006596 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6597}
6598
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00006599void bnx2x_pf_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006600{
6601 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6602 val &= ~IGU_PF_CONF_FUNC_EN;
6603
6604 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6605 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6606 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6607}
6608
Eric Dumazet1191cb82012-04-27 21:39:21 +00006609static void bnx2x__common_init_phy(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006610{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006611 u32 shmem_base[2], shmem2_base[2];
Yaniv Rosnerb884d952012-11-27 03:46:28 +00006612 /* Avoid common init in case MFW supports LFA */
6613 if (SHMEM2_RD(bp, size) >
6614 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6615 return;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006616 shmem_base[0] = bp->common.shmem_base;
6617 shmem2_base[0] = bp->common.shmem2_base;
6618 if (!CHIP_IS_E1x(bp)) {
6619 shmem_base[1] =
6620 SHMEM2_RD(bp, other_shmem_base_addr);
6621 shmem2_base[1] =
6622 SHMEM2_RD(bp, other_shmem2_base_addr);
6623 }
6624 bnx2x_acquire_phy_lock(bp);
6625 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6626 bp->common.chip_id);
6627 bnx2x_release_phy_lock(bp);
6628}
6629
6630/**
6631 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6632 *
6633 * @bp: driver handle
6634 */
6635static int bnx2x_init_hw_common(struct bnx2x *bp)
6636{
6637 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006638
Merav Sicron51c1a582012-03-18 10:33:38 +00006639 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006640
David S. Miller823dcd22011-08-20 10:39:12 -07006641 /*
Yuval Mintz2de67432013-01-23 03:21:43 +00006642 * take the RESET lock to protect undi_unload flow from accessing
David S. Miller823dcd22011-08-20 10:39:12 -07006643 * registers while we're resetting the chip
6644 */
David S. Miller8decf862011-09-22 03:23:13 -04006645 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006646
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006647 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006648 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006649
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006650 val = 0xfffc;
6651 if (CHIP_IS_E3(bp)) {
6652 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6653 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6654 }
6655 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006656
David S. Miller8decf862011-09-22 03:23:13 -04006657 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006658
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006659 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6660
6661 if (!CHIP_IS_E1x(bp)) {
6662 u8 abs_func_id;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006663
6664 /**
6665 * 4-port mode or 2-port mode we need to turn of master-enable
6666 * for everyone, after that, turn it back on for self.
6667 * so, we disregard multi-function or not, and always disable
6668 * for all functions on the given path, this means 0,2,4,6 for
6669 * path 0 and 1,3,5,7 for path 1
6670 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006671 for (abs_func_id = BP_PATH(bp);
6672 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6673 if (abs_func_id == BP_ABS_FUNC(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006674 REG_WR(bp,
6675 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6676 1);
6677 continue;
6678 }
6679
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006680 bnx2x_pretend_func(bp, abs_func_id);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006681 /* clear pf enable */
6682 bnx2x_pf_disable(bp);
6683 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6684 }
6685 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006686
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006687 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006688 if (CHIP_IS_E1(bp)) {
6689 /* enable HW interrupt from PXP on USDM overflow
6690 bit 16 on INT_MASK_0 */
6691 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006692 }
6693
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006694 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006695 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006696
6697#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006698 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6699 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6700 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6701 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6702 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006703 /* make sure this value is 0 */
6704 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006705
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006706/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6707 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6708 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6709 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6710 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006711#endif
6712
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006713 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6714
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006715 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6716 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006717
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006718 /* let the HW do it's magic ... */
6719 msleep(100);
6720 /* finish PXP init */
6721 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6722 if (val != 1) {
6723 BNX2X_ERR("PXP2 CFG failed\n");
6724 return -EBUSY;
6725 }
6726 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6727 if (val != 1) {
6728 BNX2X_ERR("PXP2 RD_INIT failed\n");
6729 return -EBUSY;
6730 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006731
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006732 /* Timers bug workaround E2 only. We need to set the entire ILT to
6733 * have entries with value "0" and valid bit on.
6734 * This needs to be done by the first PF that is loaded in a path
6735 * (i.e. common phase)
6736 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006737 if (!CHIP_IS_E1x(bp)) {
6738/* In E2 there is a bug in the timers block that can cause function 6 / 7
6739 * (i.e. vnic3) to start even if it is marked as "scan-off".
6740 * This occurs when a different function (func2,3) is being marked
6741 * as "scan-off". Real-life scenario for example: if a driver is being
6742 * load-unloaded while func6,7 are down. This will cause the timer to access
6743 * the ilt, translate to a logical address and send a request to read/write.
6744 * Since the ilt for the function that is down is not valid, this will cause
6745 * a translation error which is unrecoverable.
6746 * The Workaround is intended to make sure that when this happens nothing fatal
6747 * will occur. The workaround:
6748 * 1. First PF driver which loads on a path will:
6749 * a. After taking the chip out of reset, by using pretend,
6750 * it will write "0" to the following registers of
6751 * the other vnics.
6752 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6753 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6754 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6755 * And for itself it will write '1' to
6756 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6757 * dmae-operations (writing to pram for example.)
6758 * note: can be done for only function 6,7 but cleaner this
6759 * way.
6760 * b. Write zero+valid to the entire ILT.
6761 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6762 * VNIC3 (of that port). The range allocated will be the
6763 * entire ILT. This is needed to prevent ILT range error.
6764 * 2. Any PF driver load flow:
6765 * a. ILT update with the physical addresses of the allocated
6766 * logical pages.
6767 * b. Wait 20msec. - note that this timeout is needed to make
6768 * sure there are no requests in one of the PXP internal
6769 * queues with "old" ILT addresses.
6770 * c. PF enable in the PGLC.
6771 * d. Clear the was_error of the PF in the PGLC. (could have
Yuval Mintz2de67432013-01-23 03:21:43 +00006772 * occurred while driver was down)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006773 * e. PF enable in the CFC (WEAK + STRONG)
6774 * f. Timers scan enable
6775 * 3. PF driver unload flow:
6776 * a. Clear the Timers scan_en.
6777 * b. Polling for scan_on=0 for that PF.
6778 * c. Clear the PF enable bit in the PXP.
6779 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6780 * e. Write zero+valid to all ILT entries (The valid bit must
6781 * stay set)
6782 * f. If this is VNIC 3 of a port then also init
6783 * first_timers_ilt_entry to zero and last_timers_ilt_entry
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006784 * to the last entry in the ILT.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006785 *
6786 * Notes:
6787 * Currently the PF error in the PGLC is non recoverable.
6788 * In the future the there will be a recovery routine for this error.
6789 * Currently attention is masked.
6790 * Having an MCP lock on the load/unload process does not guarantee that
6791 * there is no Timer disable during Func6/7 enable. This is because the
6792 * Timers scan is currently being cleared by the MCP on FLR.
6793 * Step 2.d can be done only for PF6/7 and the driver can also check if
6794 * there is error before clearing it. But the flow above is simpler and
6795 * more general.
6796 * All ILT entries are written by zero+valid and not just PF6/7
6797 * ILT entries since in the future the ILT entries allocation for
6798 * PF-s might be dynamic.
6799 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006800 struct ilt_client_info ilt_cli;
6801 struct bnx2x_ilt ilt;
6802 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6803 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6804
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04006805 /* initialize dummy TM client */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006806 ilt_cli.start = 0;
6807 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6808 ilt_cli.client_num = ILT_CLIENT_TM;
6809
6810 /* Step 1: set zeroes to all ilt page entries with valid bit on
6811 * Step 2: set the timers first/last ilt entry to point
6812 * to the entire range to prevent ILT range error for 3rd/4th
Yuval Mintz2de67432013-01-23 03:21:43 +00006813 * vnic (this code assumes existence of the vnic)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006814 *
6815 * both steps performed by call to bnx2x_ilt_client_init_op()
6816 * with dummy TM client
6817 *
6818 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6819 * and his brother are split registers
6820 */
6821 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6822 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6823 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6824
6825 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6826 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6827 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6828 }
6829
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006830 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6831 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006832
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006833 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006834 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6835 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006836 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006837
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006838 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006839
6840 /* let the HW do it's magic ... */
6841 do {
6842 msleep(200);
6843 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6844 } while (factor-- && (val != 1));
6845
6846 if (val != 1) {
6847 BNX2X_ERR("ATC_INIT failed\n");
6848 return -EBUSY;
6849 }
6850 }
6851
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006852 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006853
Ariel Eliorb56e9672013-01-01 05:22:32 +00006854 bnx2x_iov_init_dmae(bp);
6855
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006856 /* clean the DMAE memory */
6857 bp->dmae_ready = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006858 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006859
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006860 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6861
6862 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6863
6864 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
6865
6866 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006867
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006868 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6869 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6870 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6871 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6872
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006873 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00006874
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006875 /* QM queues pointers table */
6876 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
Michael Chan37b091b2009-10-10 13:46:55 +00006877
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006878 /* soft reset pulse */
6879 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6880 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006881
Merav Sicron55c11942012-11-07 00:45:48 +00006882 if (CNIC_SUPPORT(bp))
6883 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006884
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006885 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006886 REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006887 if (!CHIP_REV_IS_SLOW(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006888 /* enable hw interrupt from doorbell Q */
6889 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006890
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006891 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006892
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006893 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08006894 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006895
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006896 if (!CHIP_IS_E1(bp))
6897 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
6898
Barak Witkowskia3348722012-04-23 03:04:46 +00006899 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
6900 if (IS_MF_AFEX(bp)) {
6901 /* configure that VNTag and VLAN headers must be
6902 * received in afex mode
6903 */
6904 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
6905 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
6906 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
6907 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
6908 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
6909 } else {
6910 /* Bit-map indicating which L2 hdrs may appear
6911 * after the basic Ethernet header
6912 */
6913 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
6914 bp->path_has_ovlan ? 7 : 6);
6915 }
6916 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006917
6918 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
6919 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
6920 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
6921 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
6922
6923 if (!CHIP_IS_E1x(bp)) {
6924 /* reset VFC memories */
6925 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6926 VFC_MEMORIES_RST_REG_CAM_RST |
6927 VFC_MEMORIES_RST_REG_RAM_RST);
6928 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
6929 VFC_MEMORIES_RST_REG_CAM_RST |
6930 VFC_MEMORIES_RST_REG_RAM_RST);
6931
6932 msleep(20);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006933 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006934
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006935 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
6936 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
6937 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
6938 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006939
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006940 /* sync semi rtc */
6941 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6942 0x80000000);
6943 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
6944 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006945
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006946 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
6947 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
6948 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006949
Barak Witkowskia3348722012-04-23 03:04:46 +00006950 if (!CHIP_IS_E1x(bp)) {
6951 if (IS_MF_AFEX(bp)) {
6952 /* configure that VNTag and VLAN headers must be
6953 * sent in afex mode
6954 */
6955 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
6956 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
6957 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
6958 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
6959 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
6960 } else {
6961 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
6962 bp->path_has_ovlan ? 7 : 6);
6963 }
6964 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006965
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006966 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006967
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006968 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
6969
Merav Sicron55c11942012-11-07 00:45:48 +00006970 if (CNIC_SUPPORT(bp)) {
6971 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
6972 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
6973 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
6974 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
6975 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
6976 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
6977 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
6978 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
6979 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
6980 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
6981 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006982 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006983
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006984 if (sizeof(union cdu_context) != 1024)
6985 /* we currently assume that a context is 1024 bytes */
Merav Sicron51c1a582012-03-18 10:33:38 +00006986 dev_alert(&bp->pdev->dev,
6987 "please adjust the size of cdu_context(%ld)\n",
6988 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006989
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006990 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006991 val = (4 << 24) + (0 << 12) + 1024;
6992 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006993
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006994 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006995 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08006996 /* enable context validation interrupt from CFC */
6997 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
6998
6999 /* set the thresholds to prevent CFC/CDU race */
7000 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007001
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007002 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007003
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007004 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007005 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
7006
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007007 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
7008 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007009
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007010 /* Reset PCIE errors for debug */
7011 REG_WR(bp, 0x2814, 0xffffffff);
7012 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007013
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007014 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007015 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
7016 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
7017 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
7018 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
7019 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
7020 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
7021 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
7022 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
7023 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
7024 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
7025 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
7026 }
7027
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007028 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007029 if (!CHIP_IS_E1(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007030 /* in E3 this done in per-port section */
7031 if (!CHIP_IS_E3(bp))
7032 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
7033 }
7034 if (CHIP_IS_E1H(bp))
7035 /* not applicable for E2 (and above ...) */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007036 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007037
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007038 if (CHIP_REV_IS_SLOW(bp))
7039 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007040
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007041 /* finish CFC init */
7042 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
7043 if (val != 1) {
7044 BNX2X_ERR("CFC LL_INIT failed\n");
7045 return -EBUSY;
7046 }
7047 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
7048 if (val != 1) {
7049 BNX2X_ERR("CFC AC_INIT failed\n");
7050 return -EBUSY;
7051 }
7052 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
7053 if (val != 1) {
7054 BNX2X_ERR("CFC CAM_INIT failed\n");
7055 return -EBUSY;
7056 }
7057 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007058
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007059 if (CHIP_IS_E1(bp)) {
7060 /* read NIG statistic
7061 to see if this is our first up since powerup */
7062 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
7063 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007064
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007065 /* do internal memory self test */
7066 if ((val == 0) && bnx2x_int_mem_test(bp)) {
7067 BNX2X_ERR("internal mem self test failed\n");
7068 return -EBUSY;
7069 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007070 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007071
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00007072 bnx2x_setup_fan_failure_detection(bp);
7073
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007074 /* clear PXP2 attentions */
7075 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007076
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00007077 bnx2x_enable_blocks_attention(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007078 bnx2x_enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007079
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007080 if (!BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007081 if (CHIP_IS_E1x(bp))
7082 bnx2x__common_init_phy(bp);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007083 } else
7084 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
7085
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007086 return 0;
7087}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007088
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007089/**
7090 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
7091 *
7092 * @bp: driver handle
7093 */
7094static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
7095{
7096 int rc = bnx2x_init_hw_common(bp);
7097
7098 if (rc)
7099 return rc;
7100
7101 /* In E2 2-PORT mode, same ext phy is used for the two paths */
7102 if (!BP_NOMCP(bp))
7103 bnx2x__common_init_phy(bp);
7104
7105 return 0;
7106}
7107
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007108static int bnx2x_init_hw_port(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007109{
7110 int port = BP_PORT(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007111 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
Eilon Greenstein1c063282009-02-12 08:36:43 +00007112 u32 low, high;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007113 u32 val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007114
Merav Sicron51c1a582012-03-18 10:33:38 +00007115 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007116
7117 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007118
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007119 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7120 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7121 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
Eilon Greensteinca003922009-08-12 22:53:28 -07007122
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007123 /* Timers bug workaround: disables the pf_master bit in pglue at
7124 * common phase, we need to enable it here before any dmae access are
7125 * attempted. Therefore we manually added the enable-master to the
7126 * port phase (it also happens in the function phase)
7127 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007128 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007129 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7130
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007131 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7132 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7133 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7134 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7135
7136 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7137 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7138 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7139 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007140
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007141 /* QM cid (connection) count */
7142 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007143
Merav Sicron55c11942012-11-07 00:45:48 +00007144 if (CNIC_SUPPORT(bp)) {
7145 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7146 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7147 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7148 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007149
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007150 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Eilon Greenstein1c063282009-02-12 08:36:43 +00007151
Dmitry Kravkov2b674042012-10-28 21:59:04 +00007152 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7153
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007154 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007155
7156 if (IS_MF(bp))
7157 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7158 else if (bp->dev->mtu > 4096) {
7159 if (bp->flags & ONE_PORT_FLAG)
7160 low = 160;
7161 else {
7162 val = bp->dev->mtu;
7163 /* (24*1024 + val*4)/256 */
7164 low = 96 + (val/64) +
7165 ((val % 64) ? 1 : 0);
7166 }
7167 } else
7168 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7169 high = low + 56; /* 14*1024/256 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007170 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7171 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
7172 }
7173
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007174 if (CHIP_MODE_IS_4_PORT(bp))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007175 REG_WR(bp, (BP_PORT(bp) ?
7176 BRB1_REG_MAC_GUARANTIED_1 :
7177 BRB1_REG_MAC_GUARANTIED_0), 40);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007178
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007179 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
Barak Witkowskia3348722012-04-23 03:04:46 +00007180 if (CHIP_IS_E3B0(bp)) {
7181 if (IS_MF_AFEX(bp)) {
7182 /* configure headers for AFEX mode */
7183 REG_WR(bp, BP_PORT(bp) ?
7184 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7185 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7186 REG_WR(bp, BP_PORT(bp) ?
7187 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7188 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7189 REG_WR(bp, BP_PORT(bp) ?
7190 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7191 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7192 } else {
7193 /* Ovlan exists only if we are in multi-function +
7194 * switch-dependent mode, in switch-independent there
7195 * is no ovlan headers
7196 */
7197 REG_WR(bp, BP_PORT(bp) ?
7198 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7199 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7200 (bp->path_has_ovlan ? 7 : 6));
7201 }
7202 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007203
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007204 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7205 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7206 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7207 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7208
7209 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7210 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7211 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7212 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7213
7214 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7215 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7216
7217 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7218
7219 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007220 /* configure PBF to work without PAUSE mtu 9000 */
7221 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007222
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007223 /* update threshold */
7224 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7225 /* update init credit */
7226 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007227
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007228 /* probe changes */
7229 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7230 udelay(50);
7231 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7232 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007233
Merav Sicron55c11942012-11-07 00:45:48 +00007234 if (CNIC_SUPPORT(bp))
7235 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7236
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007237 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7238 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007239
7240 if (CHIP_IS_E1(bp)) {
7241 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7242 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7243 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007244 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007245
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007246 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007247
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007248 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007249 /* init aeu_mask_attn_func_0/1:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007250 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7251 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007252 * bits 4-7 are used for "per vn group attention" */
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00007253 val = IS_MF(bp) ? 0xF7 : 0x7;
7254 /* Enable DCBX attention for all but E1 */
7255 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7256 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007257
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007258 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007259
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007260 if (!CHIP_IS_E1x(bp)) {
7261 /* Bit-map indicating which L2 hdrs may appear after the
7262 * basic Ethernet header
7263 */
Barak Witkowskia3348722012-04-23 03:04:46 +00007264 if (IS_MF_AFEX(bp))
7265 REG_WR(bp, BP_PORT(bp) ?
7266 NIG_REG_P1_HDRS_AFTER_BASIC :
7267 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7268 else
7269 REG_WR(bp, BP_PORT(bp) ?
7270 NIG_REG_P1_HDRS_AFTER_BASIC :
7271 NIG_REG_P0_HDRS_AFTER_BASIC,
7272 IS_MF_SD(bp) ? 7 : 6);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007273
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007274 if (CHIP_IS_E3(bp))
7275 REG_WR(bp, BP_PORT(bp) ?
7276 NIG_REG_LLH1_MF_MODE :
7277 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7278 }
7279 if (!CHIP_IS_E3(bp))
7280 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007281
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007282 if (!CHIP_IS_E1(bp)) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007283 /* 0x2 disable mf_ov, 0x1 enable */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007284 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007285 (IS_MF_SD(bp) ? 0x1 : 0x2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007286
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007287 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007288 val = 0;
7289 switch (bp->mf_mode) {
7290 case MULTI_FUNCTION_SD:
7291 val = 1;
7292 break;
7293 case MULTI_FUNCTION_SI:
Barak Witkowskia3348722012-04-23 03:04:46 +00007294 case MULTI_FUNCTION_AFEX:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007295 val = 2;
7296 break;
7297 }
7298
7299 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7300 NIG_REG_LLH0_CLS_TYPE), val);
7301 }
Eilon Greenstein1c063282009-02-12 08:36:43 +00007302 {
7303 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7304 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7305 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7306 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007307 }
7308
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007309 /* If SPIO5 is set to generate interrupts, enable it for this port */
7310 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00007311 if (val & MISC_SPIO_SPIO5) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007312 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7313 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7314 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007315 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007316 REG_WR(bp, reg_addr, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007317 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007318
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007319 return 0;
7320}
7321
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007322static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7323{
7324 int reg;
Yuval Mintz32d68de2012-04-03 18:41:24 +00007325 u32 wb_write[2];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007326
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007327 if (CHIP_IS_E1(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007328 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007329 else
7330 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007331
Yuval Mintz32d68de2012-04-03 18:41:24 +00007332 wb_write[0] = ONCHIP_ADDR1(addr);
7333 wb_write[1] = ONCHIP_ADDR2(addr);
7334 REG_WR_DMAE(bp, reg, wb_write, 2);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007335}
7336
Ariel Eliorb56e9672013-01-01 05:22:32 +00007337void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
Eric Dumazet1191cb82012-04-27 21:39:21 +00007338{
7339 u32 data, ctl, cnt = 100;
7340 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7341 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7342 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7343 u32 sb_bit = 1 << (idu_sb_id%32);
Ariel Eliorb56e9672013-01-01 05:22:32 +00007344 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
Eric Dumazet1191cb82012-04-27 21:39:21 +00007345 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7346
7347 /* Not supported in BC mode */
7348 if (CHIP_INT_MODE_IS_BC(bp))
7349 return;
7350
7351 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7352 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7353 IGU_REGULAR_CLEANUP_SET |
7354 IGU_REGULAR_BCLEANUP;
7355
7356 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7357 func_encode << IGU_CTRL_REG_FID_SHIFT |
7358 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7359
7360 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7361 data, igu_addr_data);
7362 REG_WR(bp, igu_addr_data, data);
7363 mmiowb();
7364 barrier();
7365 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7366 ctl, igu_addr_ctl);
7367 REG_WR(bp, igu_addr_ctl, ctl);
7368 mmiowb();
7369 barrier();
7370
7371 /* wait for clean up to finish */
7372 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7373 msleep(20);
7374
Eric Dumazet1191cb82012-04-27 21:39:21 +00007375 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7376 DP(NETIF_MSG_HW,
7377 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7378 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7379 }
7380}
7381
7382static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007383{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007384 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007385}
7386
Eric Dumazet1191cb82012-04-27 21:39:21 +00007387static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007388{
7389 u32 i, base = FUNC_ILT_BASE(func);
7390 for (i = base; i < base + ILT_PER_FUNC; i++)
7391 bnx2x_ilt_wr(bp, i, 0);
7392}
7393
Merav Sicron910cc722012-11-11 03:56:08 +00007394static void bnx2x_init_searcher(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007395{
7396 int port = BP_PORT(bp);
7397 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7398 /* T1 hash bits value determines the T1 number of entries */
7399 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7400}
7401
7402static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7403{
7404 int rc;
7405 struct bnx2x_func_state_params func_params = {NULL};
7406 struct bnx2x_func_switch_update_params *switch_update_params =
7407 &func_params.params.switch_update;
7408
7409 /* Prepare parameters for function state transitions */
7410 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7411 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7412
7413 func_params.f_obj = &bp->func_obj;
7414 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7415
7416 /* Function parameters */
7417 switch_update_params->suspend = suspend;
7418
7419 rc = bnx2x_func_state_change(bp, &func_params);
7420
7421 return rc;
7422}
7423
Merav Sicron910cc722012-11-11 03:56:08 +00007424static int bnx2x_reset_nic_mode(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007425{
7426 int rc, i, port = BP_PORT(bp);
7427 int vlan_en = 0, mac_en[NUM_MACS];
7428
Merav Sicron55c11942012-11-07 00:45:48 +00007429 /* Close input from network */
7430 if (bp->mf_mode == SINGLE_FUNCTION) {
7431 bnx2x_set_rx_filter(&bp->link_params, 0);
7432 } else {
7433 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7434 NIG_REG_LLH0_FUNC_EN);
7435 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7436 NIG_REG_LLH0_FUNC_EN, 0);
7437 for (i = 0; i < NUM_MACS; i++) {
7438 mac_en[i] = REG_RD(bp, port ?
7439 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7440 4 * i) :
7441 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7442 4 * i));
7443 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7444 4 * i) :
7445 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7446 }
7447 }
7448
7449 /* Close BMC to host */
7450 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7451 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7452
7453 /* Suspend Tx switching to the PF. Completion of this ramrod
7454 * further guarantees that all the packets of that PF / child
7455 * VFs in BRB were processed by the Parser, so it is safe to
7456 * change the NIC_MODE register.
7457 */
7458 rc = bnx2x_func_switch_update(bp, 1);
7459 if (rc) {
7460 BNX2X_ERR("Can't suspend tx-switching!\n");
7461 return rc;
7462 }
7463
7464 /* Change NIC_MODE register */
7465 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7466
7467 /* Open input from network */
7468 if (bp->mf_mode == SINGLE_FUNCTION) {
7469 bnx2x_set_rx_filter(&bp->link_params, 1);
7470 } else {
7471 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7472 NIG_REG_LLH0_FUNC_EN, vlan_en);
7473 for (i = 0; i < NUM_MACS; i++) {
7474 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7475 4 * i) :
7476 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7477 mac_en[i]);
7478 }
7479 }
7480
7481 /* Enable BMC to host */
7482 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7483 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7484
7485 /* Resume Tx switching to the PF */
7486 rc = bnx2x_func_switch_update(bp, 0);
7487 if (rc) {
7488 BNX2X_ERR("Can't resume tx-switching!\n");
7489 return rc;
7490 }
7491
7492 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7493 return 0;
7494}
7495
7496int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7497{
7498 int rc;
7499
7500 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7501
7502 if (CONFIGURE_NIC_MODE(bp)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007503 /* Configure searcher as part of function hw init */
Merav Sicron55c11942012-11-07 00:45:48 +00007504 bnx2x_init_searcher(bp);
7505
7506 /* Reset NIC mode */
7507 rc = bnx2x_reset_nic_mode(bp);
7508 if (rc)
7509 BNX2X_ERR("Can't change NIC mode!\n");
7510 return rc;
7511 }
7512
7513 return 0;
7514}
7515
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007516static int bnx2x_init_hw_func(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007517{
7518 int port = BP_PORT(bp);
7519 int func = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007520 int init_phase = PHASE_PF0 + func;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007521 struct bnx2x_ilt *ilt = BP_ILT(bp);
7522 u16 cdu_ilt_start;
Eilon Greenstein8badd272009-02-12 08:36:15 +00007523 u32 addr, val;
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007524 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
Ariel Elior89db4ad2012-01-26 06:01:48 +00007525 int i, main_mem_width, rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007526
Merav Sicron51c1a582012-03-18 10:33:38 +00007527 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007528
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007529 /* FLR cleanup - hmmm */
Ariel Elior89db4ad2012-01-26 06:01:48 +00007530 if (!CHIP_IS_E1x(bp)) {
7531 rc = bnx2x_pf_flr_clnup(bp);
Yuval Mintz04c46732013-01-23 03:21:46 +00007532 if (rc) {
7533 bnx2x_fw_dump(bp);
Ariel Elior89db4ad2012-01-26 06:01:48 +00007534 return rc;
Yuval Mintz04c46732013-01-23 03:21:46 +00007535 }
Ariel Elior89db4ad2012-01-26 06:01:48 +00007536 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007537
Eilon Greenstein8badd272009-02-12 08:36:15 +00007538 /* set MSI reconfigure capability */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007539 if (bp->common.int_block == INT_BLOCK_HC) {
7540 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7541 val = REG_RD(bp, addr);
7542 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7543 REG_WR(bp, addr, val);
7544 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007545
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007546 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7547 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7548
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007549 ilt = BP_ILT(bp);
7550 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007551
Ariel Elior290ca2b2013-01-01 05:22:31 +00007552 if (IS_SRIOV(bp))
7553 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7554 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7555
7556 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7557 * those of the VFs, so start line should be reset
7558 */
7559 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007560 for (i = 0; i < L2_ILT_LINES(bp); i++) {
Merav Sicrona0529972012-06-19 07:48:25 +00007561 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007562 ilt->lines[cdu_ilt_start + i].page_mapping =
Merav Sicrona0529972012-06-19 07:48:25 +00007563 bp->context[i].cxt_mapping;
7564 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007565 }
Ariel Elior290ca2b2013-01-01 05:22:31 +00007566
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007567 bnx2x_ilt_init_op(bp, INITOP_SET);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007568
Merav Sicron55c11942012-11-07 00:45:48 +00007569 if (!CONFIGURE_NIC_MODE(bp)) {
7570 bnx2x_init_searcher(bp);
7571 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7572 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7573 } else {
7574 /* Set NIC mode */
7575 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00007576 DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
Merav Sicron55c11942012-11-07 00:45:48 +00007577 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007578
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007579 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007580 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7581
7582 /* Turn on a single ISR mode in IGU if driver is going to use
7583 * INT#x or MSI
7584 */
7585 if (!(bp->flags & USING_MSIX_FLAG))
7586 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7587 /*
7588 * Timers workaround bug: function init part.
7589 * Need to wait 20msec after initializing ILT,
7590 * needed to make sure there are no requests in
7591 * one of the PXP internal queues with "old" ILT addresses
7592 */
7593 msleep(20);
7594 /*
7595 * Master enable - Due to WB DMAE writes performed before this
7596 * register is re-initialized as part of the regular function
7597 * init
7598 */
7599 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7600 /* Enable the function in IGU */
7601 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7602 }
7603
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007604 bp->dmae_ready = 1;
7605
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007606 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007607
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007608 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007609 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7610
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007611 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7612 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7613 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7614 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7615 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7616 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7617 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7618 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7619 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7620 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7621 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7622 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7623 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007624
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007625 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007626 REG_WR(bp, QM_REG_PF_EN, 1);
7627
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007628 if (!CHIP_IS_E1x(bp)) {
7629 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7630 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7631 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7632 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7633 }
7634 bnx2x_init_block(bp, BLOCK_QM, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007635
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007636 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7637 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Ariel Eliorb56e9672013-01-01 05:22:32 +00007638
7639 bnx2x_iov_init_dq(bp);
7640
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007641 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7642 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7643 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7644 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7645 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7646 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7647 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7648 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7649 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7650 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007651 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7652
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007653 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007654
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007655 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007656
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007657 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007658 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7659
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007660 if (IS_MF(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007661 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007662 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007663 }
7664
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007665 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007666
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007667 /* HC init per function */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007668 if (bp->common.int_block == INT_BLOCK_HC) {
7669 if (CHIP_IS_E1H(bp)) {
7670 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7671
7672 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7673 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7674 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007675 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007676
7677 } else {
7678 int num_segs, sb_idx, prod_offset;
7679
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007680 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7681
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007682 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007683 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7684 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7685 }
7686
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007687 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007688
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007689 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007690 int dsb_idx = 0;
7691 /**
7692 * Producer memory:
7693 * E2 mode: address 0-135 match to the mapping memory;
7694 * 136 - PF0 default prod; 137 - PF1 default prod;
7695 * 138 - PF2 default prod; 139 - PF3 default prod;
7696 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7697 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7698 * 144-147 reserved.
7699 *
7700 * E1.5 mode - In backward compatible mode;
7701 * for non default SB; each even line in the memory
7702 * holds the U producer and each odd line hold
7703 * the C producer. The first 128 producers are for
7704 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7705 * producers are for the DSB for each PF.
7706 * Each PF has five segments: (the order inside each
7707 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7708 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7709 * 144-147 attn prods;
7710 */
7711 /* non-default-status-blocks */
7712 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7713 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7714 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7715 prod_offset = (bp->igu_base_sb + sb_idx) *
7716 num_segs;
7717
7718 for (i = 0; i < num_segs; i++) {
7719 addr = IGU_REG_PROD_CONS_MEMORY +
7720 (prod_offset + i) * 4;
7721 REG_WR(bp, addr, 0);
7722 }
7723 /* send consumer update with value 0 */
7724 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7725 USTORM_ID, 0, IGU_INT_NOP, 1);
7726 bnx2x_igu_clear_sb(bp,
7727 bp->igu_base_sb + sb_idx);
7728 }
7729
7730 /* default-status-blocks */
7731 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7732 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7733
7734 if (CHIP_MODE_IS_4_PORT(bp))
7735 dsb_idx = BP_FUNC(bp);
7736 else
David S. Miller8decf862011-09-22 03:23:13 -04007737 dsb_idx = BP_VN(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007738
7739 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7740 IGU_BC_BASE_DSB_PROD + dsb_idx :
7741 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7742
David S. Miller8decf862011-09-22 03:23:13 -04007743 /*
7744 * igu prods come in chunks of E1HVN_MAX (4) -
7745 * does not matters what is the current chip mode
7746 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007747 for (i = 0; i < (num_segs * E1HVN_MAX);
7748 i += E1HVN_MAX) {
7749 addr = IGU_REG_PROD_CONS_MEMORY +
7750 (prod_offset + i)*4;
7751 REG_WR(bp, addr, 0);
7752 }
7753 /* send consumer update with 0 */
7754 if (CHIP_INT_MODE_IS_BC(bp)) {
7755 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7756 USTORM_ID, 0, IGU_INT_NOP, 1);
7757 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7758 CSTORM_ID, 0, IGU_INT_NOP, 1);
7759 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7760 XSTORM_ID, 0, IGU_INT_NOP, 1);
7761 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7762 TSTORM_ID, 0, IGU_INT_NOP, 1);
7763 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7764 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7765 } else {
7766 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7767 USTORM_ID, 0, IGU_INT_NOP, 1);
7768 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7769 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7770 }
7771 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7772
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007773 /* !!! These should become driver const once
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007774 rf-tool supports split-68 const */
7775 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7776 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7777 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7778 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7779 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7780 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7781 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007782 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007783
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007784 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007785 REG_WR(bp, 0x2114, 0xffffffff);
7786 REG_WR(bp, 0x2120, 0xffffffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007787
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007788 if (CHIP_IS_E1x(bp)) {
7789 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7790 main_mem_base = HC_REG_MAIN_MEMORY +
7791 BP_PORT(bp) * (main_mem_size * 4);
7792 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7793 main_mem_width = 8;
7794
7795 val = REG_RD(bp, main_mem_prty_clr);
7796 if (val)
Merav Sicron51c1a582012-03-18 10:33:38 +00007797 DP(NETIF_MSG_HW,
7798 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7799 val);
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007800
7801 /* Clear "false" parity errors in MSI-X table */
7802 for (i = main_mem_base;
7803 i < main_mem_base + main_mem_size * 4;
7804 i += main_mem_width) {
7805 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7806 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7807 i, main_mem_width / 4);
7808 }
7809 /* Clear HC parity attention */
7810 REG_RD(bp, main_mem_prty_clr);
7811 }
7812
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007813#ifdef BNX2X_STOP_ON_ERROR
7814 /* Enable STORMs SP logging */
7815 REG_WR8(bp, BAR_USTRORM_INTMEM +
7816 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7817 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7818 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7819 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7820 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7821 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7822 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7823#endif
7824
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007825 bnx2x_phy_probe(&bp->link_params);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007826
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007827 return 0;
7828}
7829
Merav Sicron55c11942012-11-07 00:45:48 +00007830void bnx2x_free_mem_cnic(struct bnx2x *bp)
7831{
7832 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7833
7834 if (!CHIP_IS_E1x(bp))
7835 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7836 sizeof(struct host_hc_status_block_e2));
7837 else
7838 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7839 sizeof(struct host_hc_status_block_e1x));
7840
7841 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7842}
7843
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00007844void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007845{
Merav Sicrona0529972012-06-19 07:48:25 +00007846 int i;
7847
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007848 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007849 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007850
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007851 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7852 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7853
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007854 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007855 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007856
Merav Sicrona0529972012-06-19 07:48:25 +00007857 for (i = 0; i < L2_ILT_LINES(bp); i++)
7858 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7859 bp->context[i].size);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007860 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7861
7862 BNX2X_FREE(bp->ilt->lines);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007863
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007864 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007865
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007866 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
7867 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Yuval Mintz580d9d02013-01-23 03:21:51 +00007868
Yuval Mintz05952242013-05-01 04:27:58 +00007869 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7870
Yuval Mintz580d9d02013-01-23 03:21:51 +00007871 bnx2x_iov_free_mem(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007872}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007873
Merav Sicron55c11942012-11-07 00:45:48 +00007874int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007875{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007876 if (!CHIP_IS_E1x(bp))
7877 /* size = the status block + ramrod buffers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007878 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
7879 sizeof(struct host_hc_status_block_e2));
7880 else
Merav Sicron55c11942012-11-07 00:45:48 +00007881 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
7882 &bp->cnic_sb_mapping,
7883 sizeof(struct
7884 host_hc_status_block_e1x));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007885
Yuval Mintz2f7a3122013-04-24 01:45:01 +00007886 if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007887 /* allocate searcher T2 table, as it wasn't allocated before */
Merav Sicron55c11942012-11-07 00:45:48 +00007888 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007889
Merav Sicron55c11942012-11-07 00:45:48 +00007890 /* write address to which L5 should insert its values */
7891 bp->cnic_eth_dev.addr_drv_info_to_mcp =
7892 &bp->slowpath->drv_info_to_mcp;
7893
7894 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
7895 goto alloc_mem_err;
7896
7897 return 0;
7898
7899alloc_mem_err:
7900 bnx2x_free_mem_cnic(bp);
7901 BNX2X_ERR("Can't allocate memory\n");
7902 return -ENOMEM;
7903}
7904
7905int bnx2x_alloc_mem(struct bnx2x *bp)
7906{
7907 int i, allocated, context_size;
7908
Yuval Mintz2f7a3122013-04-24 01:45:01 +00007909 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
Merav Sicron55c11942012-11-07 00:45:48 +00007910 /* allocate searcher T2 table */
7911 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007912
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007913 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007914 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007915
7916 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
7917 sizeof(struct bnx2x_slowpath));
7918
Merav Sicrona0529972012-06-19 07:48:25 +00007919 /* Allocate memory for CDU context:
7920 * This memory is allocated separately and not in the generic ILT
7921 * functions because CDU differs in few aspects:
7922 * 1. There are multiple entities allocating memory for context -
7923 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
7924 * its own ILT lines.
7925 * 2. Since CDU page-size is not a single 4KB page (which is the case
7926 * for the other ILT clients), to be efficient we want to support
7927 * allocation of sub-page-size in the last entry.
7928 * 3. Context pointers are used by the driver to pass to FW / update
7929 * the context (for the other ILT clients the pointers are used just to
7930 * free the memory during unload).
7931 */
7932 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007933
Merav Sicrona0529972012-06-19 07:48:25 +00007934 for (i = 0, allocated = 0; allocated < context_size; i++) {
7935 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
7936 (context_size - allocated));
7937 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
7938 &bp->context[i].cxt_mapping,
7939 bp->context[i].size);
7940 allocated += bp->context[i].size;
7941 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007942 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007943
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007944 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
7945 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007946
Ariel Elior67c431a2013-01-01 05:22:36 +00007947 if (bnx2x_iov_alloc_mem(bp))
7948 goto alloc_mem_err;
7949
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007950 /* Slow path ring */
7951 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
7952
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007953 /* EQ */
7954 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
7955 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Tom Herbertab532cf2011-02-16 10:27:02 +00007956
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007957 return 0;
7958
7959alloc_mem_err:
7960 bnx2x_free_mem(bp);
Merav Sicron51c1a582012-03-18 10:33:38 +00007961 BNX2X_ERR("Can't allocate memory\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007962 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007963}
7964
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007965/*
7966 * Init service functions
7967 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007968
7969int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
7970 struct bnx2x_vlan_mac_obj *obj, bool set,
7971 int mac_type, unsigned long *ramrod_flags)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007972{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007973 int rc;
7974 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007975
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007976 memset(&ramrod_param, 0, sizeof(ramrod_param));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007977
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007978 /* Fill general parameters */
7979 ramrod_param.vlan_mac_obj = obj;
7980 ramrod_param.ramrod_flags = *ramrod_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007981
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007982 /* Fill a user request section if needed */
7983 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
7984 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007985
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007986 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007987
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007988 /* Set the command: ADD or DEL */
7989 if (set)
7990 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
7991 else
7992 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007993 }
7994
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007995 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
Yuval Mintz7b5342d2012-09-11 04:34:14 +00007996
7997 if (rc == -EEXIST) {
7998 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
7999 /* do not treat adding same MAC as error */
8000 rc = 0;
8001 } else if (rc < 0)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008002 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
Yuval Mintz7b5342d2012-09-11 04:34:14 +00008003
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008004 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008005}
8006
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008007int bnx2x_del_all_macs(struct bnx2x *bp,
8008 struct bnx2x_vlan_mac_obj *mac_obj,
8009 int mac_type, bool wait_for_comp)
Michael Chane665bfd2009-10-10 13:46:54 +00008010{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008011 int rc;
8012 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
8013
8014 /* Wait for completion of requested */
8015 if (wait_for_comp)
8016 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8017
8018 /* Set the mac type of addresses we want to clear */
8019 __set_bit(mac_type, &vlan_mac_flags);
8020
8021 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
8022 if (rc < 0)
8023 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
8024
8025 return rc;
Michael Chane665bfd2009-10-10 13:46:54 +00008026}
8027
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008028int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008029{
Barak Witkowskia3348722012-04-23 03:04:46 +00008030 if (is_zero_ether_addr(bp->dev->dev_addr) &&
8031 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00008032 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
8033 "Ignoring Zero MAC for STORAGE SD mode\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008034 return 0;
8035 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008036
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008037 if (IS_PF(bp)) {
8038 unsigned long ramrod_flags = 0;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008039
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008040 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
8041 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8042 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
8043 &bp->sp_objs->mac_obj, set,
8044 BNX2X_ETH_MAC, &ramrod_flags);
8045 } else { /* vf */
8046 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
8047 bp->fp->index, true);
8048 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008049}
8050
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008051int bnx2x_setup_leading(struct bnx2x *bp)
Michael Chane665bfd2009-10-10 13:46:54 +00008052{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008053 return bnx2x_setup_queue(bp, &bp->fp[0], 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008054}
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08008055
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008056/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00008057 * bnx2x_set_int_mode - configure interrupt mode
8058 *
8059 * @bp: driver handle
8060 *
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008061 * In case of MSI-X it will also try to enable MSI-X.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008062 */
Ariel Elior1ab44342013-01-01 05:22:23 +00008063int bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008064{
Ariel Elior1ab44342013-01-01 05:22:23 +00008065 int rc = 0;
8066
8067 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
8068 return -EINVAL;
8069
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00008070 switch (int_mode) {
Ariel Elior1ab44342013-01-01 05:22:23 +00008071 case BNX2X_INT_MODE_MSIX:
8072 /* attempt to enable msix */
8073 rc = bnx2x_enable_msix(bp);
8074
8075 /* msix attained */
8076 if (!rc)
8077 return 0;
8078
8079 /* vfs use only msix */
8080 if (rc && IS_VF(bp))
8081 return rc;
8082
8083 /* failed to enable multiple MSI-X */
8084 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
8085 bp->num_queues,
8086 1 + bp->num_cnic_queues);
8087
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008088 /* falling through... */
Ariel Elior1ab44342013-01-01 05:22:23 +00008089 case BNX2X_INT_MODE_MSI:
8090 bnx2x_enable_msi(bp);
8091
8092 /* falling through... */
8093 case BNX2X_INT_MODE_INTX:
Merav Sicron55c11942012-11-07 00:45:48 +00008094 bp->num_ethernet_queues = 1;
8095 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
Merav Sicron51c1a582012-03-18 10:33:38 +00008096 BNX2X_DEV_INFO("set number of queues to 1\n");
Eilon Greensteinca003922009-08-12 22:53:28 -07008097 break;
Eilon Greensteinca003922009-08-12 22:53:28 -07008098 default:
Ariel Elior1ab44342013-01-01 05:22:23 +00008099 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
8100 return -EINVAL;
Eilon Greensteinca003922009-08-12 22:53:28 -07008101 }
Ariel Elior1ab44342013-01-01 05:22:23 +00008102 return 0;
Eilon Greensteinca003922009-08-12 22:53:28 -07008103}
8104
Ariel Elior1ab44342013-01-01 05:22:23 +00008105/* must be called prior to any HW initializations */
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008106static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
8107{
Ariel Elior290ca2b2013-01-01 05:22:31 +00008108 if (IS_SRIOV(bp))
8109 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008110 return L2_ILT_LINES(bp);
8111}
8112
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008113void bnx2x_ilt_set_info(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008114{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008115 struct ilt_client_info *ilt_client;
8116 struct bnx2x_ilt *ilt = BP_ILT(bp);
8117 u16 line = 0;
8118
8119 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8120 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8121
8122 /* CDU */
8123 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8124 ilt_client->client_num = ILT_CLIENT_CDU;
8125 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8126 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8127 ilt_client->start = line;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008128 line += bnx2x_cid_ilt_lines(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00008129
8130 if (CNIC_SUPPORT(bp))
8131 line += CNIC_ILT_LINES;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008132 ilt_client->end = line - 1;
8133
Merav Sicron51c1a582012-03-18 10:33:38 +00008134 DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008135 ilt_client->start,
8136 ilt_client->end,
8137 ilt_client->page_size,
8138 ilt_client->flags,
8139 ilog2(ilt_client->page_size >> 12));
8140
8141 /* QM */
8142 if (QM_INIT(bp->qm_cid_count)) {
8143 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8144 ilt_client->client_num = ILT_CLIENT_QM;
8145 ilt_client->page_size = QM_ILT_PAGE_SZ;
8146 ilt_client->flags = 0;
8147 ilt_client->start = line;
8148
8149 /* 4 bytes for each cid */
8150 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8151 QM_ILT_PAGE_SZ);
8152
8153 ilt_client->end = line - 1;
8154
Merav Sicron51c1a582012-03-18 10:33:38 +00008155 DP(NETIF_MSG_IFUP,
8156 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008157 ilt_client->start,
8158 ilt_client->end,
8159 ilt_client->page_size,
8160 ilt_client->flags,
8161 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008162 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008163
Merav Sicron55c11942012-11-07 00:45:48 +00008164 if (CNIC_SUPPORT(bp)) {
8165 /* SRC */
8166 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8167 ilt_client->client_num = ILT_CLIENT_SRC;
8168 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8169 ilt_client->flags = 0;
8170 ilt_client->start = line;
8171 line += SRC_ILT_LINES;
8172 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008173
Merav Sicron55c11942012-11-07 00:45:48 +00008174 DP(NETIF_MSG_IFUP,
8175 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8176 ilt_client->start,
8177 ilt_client->end,
8178 ilt_client->page_size,
8179 ilt_client->flags,
8180 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008181
Merav Sicron55c11942012-11-07 00:45:48 +00008182 /* TM */
8183 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8184 ilt_client->client_num = ILT_CLIENT_TM;
8185 ilt_client->page_size = TM_ILT_PAGE_SZ;
8186 ilt_client->flags = 0;
8187 ilt_client->start = line;
8188 line += TM_ILT_LINES;
8189 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008190
Merav Sicron55c11942012-11-07 00:45:48 +00008191 DP(NETIF_MSG_IFUP,
8192 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8193 ilt_client->start,
8194 ilt_client->end,
8195 ilt_client->page_size,
8196 ilt_client->flags,
8197 ilog2(ilt_client->page_size >> 12));
8198 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008199
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008200 BUG_ON(line > ILT_MAX_LINES);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008201}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008202
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008203/**
8204 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8205 *
8206 * @bp: driver handle
8207 * @fp: pointer to fastpath
8208 * @init_params: pointer to parameters structure
8209 *
8210 * parameters configured:
8211 * - HC configuration
8212 * - Queue's CDU context
8213 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00008214static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008215 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008216{
Ariel Elior6383c0b2011-07-14 08:31:57 +00008217 u8 cos;
Merav Sicrona0529972012-06-19 07:48:25 +00008218 int cxt_index, cxt_offset;
8219
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008220 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8221 if (!IS_FCOE_FP(fp)) {
8222 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8223 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8224
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008225 /* If HC is supported, enable host coalescing in the transition
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008226 * to INIT state.
8227 */
8228 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8229 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8230
8231 /* HC rate */
8232 init_params->rx.hc_rate = bp->rx_ticks ?
8233 (1000000 / bp->rx_ticks) : 0;
8234 init_params->tx.hc_rate = bp->tx_ticks ?
8235 (1000000 / bp->tx_ticks) : 0;
8236
8237 /* FW SB ID */
8238 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8239 fp->fw_sb_id;
8240
8241 /*
8242 * CQ index among the SB indices: FCoE clients uses the default
8243 * SB, therefore it's different.
8244 */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008245 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8246 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008247 }
8248
Ariel Elior6383c0b2011-07-14 08:31:57 +00008249 /* set maximum number of COSs supported by this queue */
8250 init_params->max_cos = fp->max_cos;
8251
Merav Sicron51c1a582012-03-18 10:33:38 +00008252 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008253 fp->index, init_params->max_cos);
8254
8255 /* set the context pointers queue object */
Merav Sicrona0529972012-06-19 07:48:25 +00008256 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
Merav Sicron65565882012-06-19 07:48:26 +00008257 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8258 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
Merav Sicrona0529972012-06-19 07:48:25 +00008259 ILT_PAGE_CIDS);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008260 init_params->cxts[cos] =
Merav Sicrona0529972012-06-19 07:48:25 +00008261 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8262 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008263}
8264
Merav Sicron910cc722012-11-11 03:56:08 +00008265static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00008266 struct bnx2x_queue_state_params *q_params,
8267 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8268 int tx_index, bool leading)
8269{
8270 memset(tx_only_params, 0, sizeof(*tx_only_params));
8271
8272 /* Set the command */
8273 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8274
8275 /* Set tx-only QUEUE flags: don't zero statistics */
8276 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8277
8278 /* choose the index of the cid to send the slow path on */
8279 tx_only_params->cid_index = tx_index;
8280
8281 /* Set general TX_ONLY_SETUP parameters */
8282 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8283
8284 /* Set Tx TX_ONLY_SETUP parameters */
8285 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8286
Merav Sicron51c1a582012-03-18 10:33:38 +00008287 DP(NETIF_MSG_IFUP,
8288 "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008289 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8290 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8291 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8292
8293 /* send the ramrod */
8294 return bnx2x_queue_state_change(bp, q_params);
8295}
8296
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008297/**
8298 * bnx2x_setup_queue - setup queue
8299 *
8300 * @bp: driver handle
8301 * @fp: pointer to fastpath
8302 * @leading: is leading
8303 *
8304 * This function performs 2 steps in a Queue state machine
8305 * actually: 1) RESET->INIT 2) INIT->SETUP
8306 */
8307
8308int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8309 bool leading)
8310{
Yuval Mintz3b603062012-03-18 10:33:39 +00008311 struct bnx2x_queue_state_params q_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008312 struct bnx2x_queue_setup_params *setup_params =
8313 &q_params.params.setup;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008314 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8315 &q_params.params.tx_only;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008316 int rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008317 u8 tx_index;
8318
Merav Sicron51c1a582012-03-18 10:33:38 +00008319 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008320
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008321 /* reset IGU state skip FCoE L2 queue */
8322 if (!IS_FCOE_FP(fp))
8323 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008324 IGU_INT_ENABLE, 0);
8325
Barak Witkowski15192a82012-06-19 07:48:28 +00008326 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008327 /* We want to wait for completion in this context */
8328 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008329
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008330 /* Prepare the INIT parameters */
8331 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008332
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008333 /* Set the command */
8334 q_params.cmd = BNX2X_Q_CMD_INIT;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008335
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008336 /* Change the state to INIT */
8337 rc = bnx2x_queue_state_change(bp, &q_params);
8338 if (rc) {
Ariel Elior6383c0b2011-07-14 08:31:57 +00008339 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008340 return rc;
8341 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008342
Merav Sicron51c1a582012-03-18 10:33:38 +00008343 DP(NETIF_MSG_IFUP, "init complete\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +00008344
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008345 /* Now move the Queue to the SETUP state... */
8346 memset(setup_params, 0, sizeof(*setup_params));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008347
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008348 /* Set QUEUE flags */
8349 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008350
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008351 /* Set general SETUP parameters */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008352 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8353 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008354
Ariel Elior6383c0b2011-07-14 08:31:57 +00008355 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008356 &setup_params->rxq_params);
8357
Ariel Elior6383c0b2011-07-14 08:31:57 +00008358 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8359 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008360
8361 /* Set the command */
8362 q_params.cmd = BNX2X_Q_CMD_SETUP;
8363
Merav Sicron55c11942012-11-07 00:45:48 +00008364 if (IS_FCOE_FP(fp))
8365 bp->fcoe_init = true;
8366
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008367 /* Change the state to SETUP */
8368 rc = bnx2x_queue_state_change(bp, &q_params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008369 if (rc) {
8370 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8371 return rc;
8372 }
8373
8374 /* loop through the relevant tx-only indices */
8375 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8376 tx_index < fp->max_cos;
8377 tx_index++) {
8378
8379 /* prepare and send tx-only ramrod*/
8380 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8381 tx_only_params, tx_index, leading);
8382 if (rc) {
8383 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8384 fp->index, tx_index);
8385 return rc;
8386 }
8387 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008388
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008389 return rc;
8390}
8391
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008392static int bnx2x_stop_queue(struct bnx2x *bp, int index)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008393{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008394 struct bnx2x_fastpath *fp = &bp->fp[index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008395 struct bnx2x_fp_txdata *txdata;
Yuval Mintz3b603062012-03-18 10:33:39 +00008396 struct bnx2x_queue_state_params q_params = {NULL};
Ariel Elior6383c0b2011-07-14 08:31:57 +00008397 int rc, tx_index;
8398
Merav Sicron51c1a582012-03-18 10:33:38 +00008399 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008400
Barak Witkowski15192a82012-06-19 07:48:28 +00008401 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008402 /* We want to wait for completion in this context */
8403 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008404
Ariel Elior6383c0b2011-07-14 08:31:57 +00008405 /* close tx-only connections */
8406 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8407 tx_index < fp->max_cos;
8408 tx_index++){
8409
8410 /* ascertain this is a normal queue*/
Merav Sicron65565882012-06-19 07:48:26 +00008411 txdata = fp->txdata_ptr[tx_index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008412
Merav Sicron51c1a582012-03-18 10:33:38 +00008413 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008414 txdata->txq_index);
8415
8416 /* send halt terminate on tx-only connection */
8417 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8418 memset(&q_params.params.terminate, 0,
8419 sizeof(q_params.params.terminate));
8420 q_params.params.terminate.cid_index = tx_index;
8421
8422 rc = bnx2x_queue_state_change(bp, &q_params);
8423 if (rc)
8424 return rc;
8425
8426 /* send halt terminate on tx-only connection */
8427 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8428 memset(&q_params.params.cfc_del, 0,
8429 sizeof(q_params.params.cfc_del));
8430 q_params.params.cfc_del.cid_index = tx_index;
8431 rc = bnx2x_queue_state_change(bp, &q_params);
8432 if (rc)
8433 return rc;
8434 }
8435 /* Stop the primary connection: */
8436 /* ...halt the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008437 q_params.cmd = BNX2X_Q_CMD_HALT;
8438 rc = bnx2x_queue_state_change(bp, &q_params);
8439 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008440 return rc;
8441
Ariel Elior6383c0b2011-07-14 08:31:57 +00008442 /* ...terminate the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008443 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008444 memset(&q_params.params.terminate, 0,
8445 sizeof(q_params.params.terminate));
8446 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008447 rc = bnx2x_queue_state_change(bp, &q_params);
8448 if (rc)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008449 return rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008450 /* ...delete cfc entry */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008451 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008452 memset(&q_params.params.cfc_del, 0,
8453 sizeof(q_params.params.cfc_del));
8454 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008455 return bnx2x_queue_state_change(bp, &q_params);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008456}
8457
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008458static void bnx2x_reset_func(struct bnx2x *bp)
8459{
8460 int port = BP_PORT(bp);
8461 int func = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008462 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008463
8464 /* Disable the function in the FW */
8465 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8466 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8467 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8468 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8469
8470 /* FP SBs */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008471 for_each_eth_queue(bp, i) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008472 struct bnx2x_fastpath *fp = &bp->fp[i];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008473 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Ariel Elior6383c0b2011-07-14 08:31:57 +00008474 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8475 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008476 }
8477
Merav Sicron55c11942012-11-07 00:45:48 +00008478 if (CNIC_LOADED(bp))
8479 /* CNIC SB */
8480 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8481 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8482 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8483
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008484 /* SP SB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008485 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Yuval Mintz2de67432013-01-23 03:21:43 +00008486 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8487 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008488
8489 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8490 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8491 0);
Eliezer Tamir49d66772008-02-28 11:53:13 -08008492
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008493 /* Configure IGU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008494 if (bp->common.int_block == INT_BLOCK_HC) {
8495 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8496 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8497 } else {
8498 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8499 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8500 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008501
Merav Sicron55c11942012-11-07 00:45:48 +00008502 if (CNIC_LOADED(bp)) {
8503 /* Disable Timer scan */
8504 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8505 /*
8506 * Wait for at least 10ms and up to 2 second for the timers
8507 * scan to complete
8508 */
8509 for (i = 0; i < 200; i++) {
Yuval Mintz639d65b2013-06-02 00:06:21 +00008510 usleep_range(10000, 20000);
Merav Sicron55c11942012-11-07 00:45:48 +00008511 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8512 break;
8513 }
Michael Chan37b091b2009-10-10 13:46:55 +00008514 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008515 /* Clear ILT */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008516 bnx2x_clear_func_ilt(bp, func);
8517
8518 /* Timers workaround bug for E2: if this is vnic-3,
8519 * we need to set the entire ilt range for this timers.
8520 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008521 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008522 struct ilt_client_info ilt_cli;
8523 /* use dummy TM client */
8524 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8525 ilt_cli.start = 0;
8526 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8527 ilt_cli.client_num = ILT_CLIENT_TM;
8528
8529 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8530 }
8531
8532 /* this assumes that reset_port() called before reset_func()*/
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008533 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008534 bnx2x_pf_disable(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008535
8536 bp->dmae_ready = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008537}
8538
8539static void bnx2x_reset_port(struct bnx2x *bp)
8540{
8541 int port = BP_PORT(bp);
8542 u32 val;
8543
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008544 /* Reset physical Link */
8545 bnx2x__link_reset(bp);
8546
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008547 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8548
8549 /* Do not rcv packets to BRB */
8550 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8551 /* Do not direct rcv packets that are not for MCP to the BRB */
8552 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8553 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8554
8555 /* Configure AEU */
8556 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8557
8558 msleep(100);
8559 /* Check for BRB port occupancy */
8560 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8561 if (val)
8562 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07008563 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008564
8565 /* TODO: Close Doorbell port? */
8566}
8567
Eric Dumazet1191cb82012-04-27 21:39:21 +00008568static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008569{
Yuval Mintz3b603062012-03-18 10:33:39 +00008570 struct bnx2x_func_state_params func_params = {NULL};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008571
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008572 /* Prepare parameters for function state transitions */
8573 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008574
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008575 func_params.f_obj = &bp->func_obj;
8576 func_params.cmd = BNX2X_F_CMD_HW_RESET;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008577
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008578 func_params.params.hw_init.load_phase = load_code;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008579
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008580 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008581}
8582
Eric Dumazet1191cb82012-04-27 21:39:21 +00008583static int bnx2x_func_stop(struct bnx2x *bp)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008584{
Yuval Mintz3b603062012-03-18 10:33:39 +00008585 struct bnx2x_func_state_params func_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008586 int rc;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008587
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008588 /* Prepare parameters for function state transitions */
8589 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8590 func_params.f_obj = &bp->func_obj;
8591 func_params.cmd = BNX2X_F_CMD_STOP;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008592
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008593 /*
8594 * Try to stop the function the 'good way'. If fails (in case
8595 * of a parity error during bnx2x_chip_cleanup()) and we are
8596 * not in a debug mode, perform a state transaction in order to
8597 * enable further HW_RESET transaction.
8598 */
8599 rc = bnx2x_func_state_change(bp, &func_params);
8600 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008601#ifdef BNX2X_STOP_ON_ERROR
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008602 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008603#else
Merav Sicron51c1a582012-03-18 10:33:38 +00008604 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008605 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8606 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008607#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07008608 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008609
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008610 return 0;
8611}
Yitchak Gertner65abd742008-08-25 15:26:24 -07008612
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008613/**
8614 * bnx2x_send_unload_req - request unload mode from the MCP.
8615 *
8616 * @bp: driver handle
8617 * @unload_mode: requested function's unload mode
8618 *
8619 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8620 */
8621u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8622{
8623 u32 reset_code = 0;
8624 int port = BP_PORT(bp);
8625
8626 /* Select the UNLOAD request mode */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008627 if (unload_mode == UNLOAD_NORMAL)
8628 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008629
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008630 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008631 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008632
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008633 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008634 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008635 u8 *mac_addr = bp->dev->dev_addr;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008636 u32 val;
David S. Miller88c51002011-10-07 13:38:43 -04008637 u16 pmc;
8638
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008639 /* The mac address is written to entries 1-4 to
David S. Miller88c51002011-10-07 13:38:43 -04008640 * preserve entry 0 which is used by the PMF
8641 */
David S. Miller8decf862011-09-22 03:23:13 -04008642 u8 entry = (BP_VN(bp) + 1)*8;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008643
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008644 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008645 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008646
8647 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8648 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008649 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008650
David S. Miller88c51002011-10-07 13:38:43 -04008651 /* Enable the PME and clear the status */
8652 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
8653 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
8654 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
8655
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008656 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008657
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008658 } else
8659 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8660
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008661 /* Send the request to the MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008662 if (!BP_NOMCP(bp))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008663 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008664 else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008665 int path = BP_PATH(bp);
8666
Merav Sicron51c1a582012-03-18 10:33:38 +00008667 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008668 path, load_count[path][0], load_count[path][1],
8669 load_count[path][2]);
8670 load_count[path][0]--;
8671 load_count[path][1 + port]--;
Merav Sicron51c1a582012-03-18 10:33:38 +00008672 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008673 path, load_count[path][0], load_count[path][1],
8674 load_count[path][2]);
8675 if (load_count[path][0] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008676 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008677 else if (load_count[path][1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008678 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8679 else
8680 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8681 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008682
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008683 return reset_code;
8684}
8685
8686/**
8687 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8688 *
8689 * @bp: driver handle
Yuval Mintz5d07d862012-09-13 02:56:21 +00008690 * @keep_link: true iff link should be kept up
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008691 */
Yuval Mintz5d07d862012-09-13 02:56:21 +00008692void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008693{
Yuval Mintz5d07d862012-09-13 02:56:21 +00008694 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8695
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008696 /* Report UNLOAD_DONE to MCP */
8697 if (!BP_NOMCP(bp))
Yuval Mintz5d07d862012-09-13 02:56:21 +00008698 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008699}
8700
Eric Dumazet1191cb82012-04-27 21:39:21 +00008701static int bnx2x_func_wait_started(struct bnx2x *bp)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008702{
8703 int tout = 50;
8704 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8705
8706 if (!bp->port.pmf)
8707 return 0;
8708
8709 /*
8710 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008711 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008712 * 1. Sync IRS for default SB
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008713 * 2. Sync SP queue - this guarantees us that attention handling started
8714 * 3. Wait, that TX disable/enable transaction completes
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008715 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008716 * 1+2 guarantee that if DCBx attention was scheduled it already changed
8717 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
8718 * received completion for the transaction the state is TX_STOPPED.
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008719 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8720 * transaction.
8721 */
8722
8723 /* make sure default SB ISR is done */
8724 if (msix)
8725 synchronize_irq(bp->msix_table[0].vector);
8726 else
8727 synchronize_irq(bp->pdev->irq);
8728
8729 flush_workqueue(bnx2x_wq);
8730
8731 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8732 BNX2X_F_STATE_STARTED && tout--)
8733 msleep(20);
8734
8735 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8736 BNX2X_F_STATE_STARTED) {
8737#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00008738 BNX2X_ERR("Wrong function state\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008739 return -EBUSY;
8740#else
8741 /*
8742 * Failed to complete the transaction in a "good way"
8743 * Force both transactions with CLR bit
8744 */
Yuval Mintz3b603062012-03-18 10:33:39 +00008745 struct bnx2x_func_state_params func_params = {NULL};
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008746
Merav Sicron51c1a582012-03-18 10:33:38 +00008747 DP(NETIF_MSG_IFDOWN,
Yuval Mintz6bf07b82013-06-02 00:06:20 +00008748 "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008749
8750 func_params.f_obj = &bp->func_obj;
8751 __set_bit(RAMROD_DRV_CLR_ONLY,
8752 &func_params.ramrod_flags);
8753
8754 /* STARTED-->TX_ST0PPED */
8755 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8756 bnx2x_func_state_change(bp, &func_params);
8757
8758 /* TX_ST0PPED-->STARTED */
8759 func_params.cmd = BNX2X_F_CMD_TX_START;
8760 return bnx2x_func_state_change(bp, &func_params);
8761#endif
8762 }
8763
8764 return 0;
8765}
8766
Yuval Mintz5d07d862012-09-13 02:56:21 +00008767void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008768{
8769 int port = BP_PORT(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008770 int i, rc = 0;
8771 u8 cos;
Yuval Mintz3b603062012-03-18 10:33:39 +00008772 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008773 u32 reset_code;
8774
8775 /* Wait until tx fastpath tasks complete */
8776 for_each_tx_queue(bp, i) {
8777 struct bnx2x_fastpath *fp = &bp->fp[i];
8778
Ariel Elior6383c0b2011-07-14 08:31:57 +00008779 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00008780 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008781#ifdef BNX2X_STOP_ON_ERROR
8782 if (rc)
8783 return;
8784#endif
8785 }
8786
8787 /* Give HW time to discard old tx messages */
Yuval Mintz0926d492013-01-23 03:21:45 +00008788 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008789
8790 /* Clean all ETH MACs */
Barak Witkowski15192a82012-06-19 07:48:28 +00008791 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8792 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008793 if (rc < 0)
8794 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8795
8796 /* Clean up UC list */
Barak Witkowski15192a82012-06-19 07:48:28 +00008797 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008798 true);
8799 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +00008800 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8801 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008802
8803 /* Disable LLH */
8804 if (!CHIP_IS_E1(bp))
8805 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8806
8807 /* Set "drop all" (stop Rx).
8808 * We need to take a netif_addr_lock() here in order to prevent
8809 * a race between the completion code and this code.
8810 */
8811 netif_addr_lock_bh(bp->dev);
8812 /* Schedule the rx_mode command */
8813 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8814 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8815 else
8816 bnx2x_set_storm_rx_mode(bp);
8817
8818 /* Cleanup multicast configuration */
8819 rparam.mcast_obj = &bp->mcast_obj;
8820 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8821 if (rc < 0)
8822 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8823
8824 netif_addr_unlock_bh(bp->dev);
8825
Ariel Eliorf1929b02013-01-01 05:22:41 +00008826 bnx2x_iov_chip_cleanup(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008827
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008828 /*
8829 * Send the UNLOAD_REQUEST to the MCP. This will return if
8830 * this function should perform FUNC, PORT or COMMON HW
8831 * reset.
8832 */
8833 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8834
8835 /*
8836 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008837 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008838 */
8839 rc = bnx2x_func_wait_started(bp);
8840 if (rc) {
8841 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8842#ifdef BNX2X_STOP_ON_ERROR
8843 return;
8844#endif
8845 }
8846
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008847 /* Close multi and leading connections
8848 * Completions for ramrods are collected in a synchronous way
8849 */
Merav Sicron55c11942012-11-07 00:45:48 +00008850 for_each_eth_queue(bp, i)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008851 if (bnx2x_stop_queue(bp, i))
8852#ifdef BNX2X_STOP_ON_ERROR
8853 return;
8854#else
8855 goto unload_error;
8856#endif
Merav Sicron55c11942012-11-07 00:45:48 +00008857
8858 if (CNIC_LOADED(bp)) {
8859 for_each_cnic_queue(bp, i)
8860 if (bnx2x_stop_queue(bp, i))
8861#ifdef BNX2X_STOP_ON_ERROR
8862 return;
8863#else
8864 goto unload_error;
8865#endif
8866 }
8867
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008868 /* If SP settings didn't get completed so far - something
8869 * very wrong has happen.
8870 */
8871 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
8872 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
8873
8874#ifndef BNX2X_STOP_ON_ERROR
8875unload_error:
8876#endif
8877 rc = bnx2x_func_stop(bp);
8878 if (rc) {
8879 BNX2X_ERR("Function stop failed!\n");
8880#ifdef BNX2X_STOP_ON_ERROR
8881 return;
8882#endif
8883 }
8884
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008885 /* Disable HW interrupts, NAPI */
8886 bnx2x_netif_stop(bp, 1);
Merav Sicron26614ba2012-08-27 03:26:19 +00008887 /* Delete all NAPI objects */
8888 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00008889 if (CNIC_LOADED(bp))
8890 bnx2x_del_all_napi_cnic(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008891
8892 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008893 bnx2x_free_irq(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008894
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008895 /* Reset the chip */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008896 rc = bnx2x_reset_hw(bp, reset_code);
8897 if (rc)
8898 BNX2X_ERR("HW_RESET failed\n");
8899
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008900 /* Report UNLOAD_DONE to MCP */
Yuval Mintz5d07d862012-09-13 02:56:21 +00008901 bnx2x_send_unload_done(bp, keep_link);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008902}
8903
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00008904void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008905{
8906 u32 val;
8907
Merav Sicron51c1a582012-03-18 10:33:38 +00008908 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008909
8910 if (CHIP_IS_E1(bp)) {
8911 int port = BP_PORT(bp);
8912 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
8913 MISC_REG_AEU_MASK_ATTN_FUNC_0;
8914
8915 val = REG_RD(bp, addr);
8916 val &= ~(0x300);
8917 REG_WR(bp, addr, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008918 } else {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008919 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
8920 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
8921 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
8922 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
8923 }
8924}
8925
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008926/* Close gates #2, #3 and #4: */
8927static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
8928{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00008929 u32 val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008930
8931 /* Gates #2 and #4a are closed/opened for "not E1" only */
8932 if (!CHIP_IS_E1(bp)) {
8933 /* #4 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00008934 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008935 /* #2 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00008936 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008937 }
8938
8939 /* #3 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00008940 if (CHIP_IS_E1x(bp)) {
8941 /* Prevent interrupts from HC on both ports */
8942 val = REG_RD(bp, HC_REG_CONFIG_1);
8943 REG_WR(bp, HC_REG_CONFIG_1,
8944 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
8945 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
8946
8947 val = REG_RD(bp, HC_REG_CONFIG_0);
8948 REG_WR(bp, HC_REG_CONFIG_0,
8949 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
8950 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
8951 } else {
Jorrit Schippersd82603c2012-12-27 17:33:02 +01008952 /* Prevent incoming interrupts in IGU */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00008953 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
8954
8955 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
8956 (!close) ?
8957 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
8958 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
8959 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008960
Merav Sicron51c1a582012-03-18 10:33:38 +00008961 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008962 close ? "closing" : "opening");
8963 mmiowb();
8964}
8965
8966#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
8967
8968static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
8969{
8970 /* Do some magic... */
8971 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8972 *magic_val = val & SHARED_MF_CLP_MAGIC;
8973 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
8974}
8975
Dmitry Kravkove8920672011-05-04 23:52:40 +00008976/**
8977 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008978 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00008979 * @bp: driver handle
8980 * @magic_val: old value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008981 */
8982static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
8983{
8984 /* Restore the `magic' bit value... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008985 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
8986 MF_CFG_WR(bp, shared_mf_config.clp_mb,
8987 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
8988}
8989
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008990/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00008991 * bnx2x_reset_mcp_prep - prepare for MCP reset.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008992 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00008993 * @bp: driver handle
8994 * @magic_val: old value of 'magic' bit.
8995 *
8996 * Takes care of CLP configurations.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00008997 */
8998static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
8999{
9000 u32 shmem;
9001 u32 validity_offset;
9002
Merav Sicron51c1a582012-03-18 10:33:38 +00009003 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009004
9005 /* Set `magic' bit in order to save MF config */
9006 if (!CHIP_IS_E1(bp))
9007 bnx2x_clp_reset_prep(bp, magic_val);
9008
9009 /* Get shmem offset */
9010 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009011 validity_offset =
9012 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009013
9014 /* Clear validity map flags */
9015 if (shmem > 0)
9016 REG_WR(bp, shmem + validity_offset, 0);
9017}
9018
9019#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
9020#define MCP_ONE_TIMEOUT 100 /* 100 ms */
9021
Dmitry Kravkove8920672011-05-04 23:52:40 +00009022/**
9023 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009024 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009025 * @bp: driver handle
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009026 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00009027static void bnx2x_mcp_wait_one(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009028{
9029 /* special handling for emulation and FPGA,
9030 wait 10 times longer */
9031 if (CHIP_REV_IS_SLOW(bp))
9032 msleep(MCP_ONE_TIMEOUT*10);
9033 else
9034 msleep(MCP_ONE_TIMEOUT);
9035}
9036
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009037/*
9038 * initializes bp->common.shmem_base and waits for validity signature to appear
9039 */
9040static int bnx2x_init_shmem(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009041{
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009042 int cnt = 0;
9043 u32 val = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009044
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009045 do {
9046 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9047 if (bp->common.shmem_base) {
9048 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
9049 if (val & SHR_MEM_VALIDITY_MB)
9050 return 0;
9051 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009052
9053 bnx2x_mcp_wait_one(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009054
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009055 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009056
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009057 BNX2X_ERR("BAD MCP validity signature\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009058
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009059 return -ENODEV;
9060}
9061
9062static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
9063{
9064 int rc = bnx2x_init_shmem(bp);
9065
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009066 /* Restore the `magic' bit value */
9067 if (!CHIP_IS_E1(bp))
9068 bnx2x_clp_reset_done(bp, magic_val);
9069
9070 return rc;
9071}
9072
9073static void bnx2x_pxp_prep(struct bnx2x *bp)
9074{
9075 if (!CHIP_IS_E1(bp)) {
9076 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
9077 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009078 mmiowb();
9079 }
9080}
9081
9082/*
9083 * Reset the whole chip except for:
9084 * - PCIE core
9085 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
9086 * one reset bit)
9087 * - IGU
9088 * - MISC (including AEU)
9089 * - GRC
9090 * - RBCN, RBCP
9091 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009092static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009093{
9094 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009095 u32 global_bits2, stay_reset2;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009096
9097 /*
9098 * Bits that have to be set in reset_mask2 if we want to reset 'global'
9099 * (per chip) blocks.
9100 */
9101 global_bits2 =
9102 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9103 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009104
Barak Witkowskic55e7712012-12-02 04:05:46 +00009105 /* Don't reset the following blocks.
9106 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9107 * reset, as in 4 port device they might still be owned
9108 * by the MCP (there is only one leader per path).
9109 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009110 not_reset_mask1 =
9111 MISC_REGISTERS_RESET_REG_1_RST_HC |
9112 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9113 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9114
9115 not_reset_mask2 =
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009116 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009117 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9118 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9119 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9120 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9121 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9122 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009123 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9124 MISC_REGISTERS_RESET_REG_2_RST_ATC |
Barak Witkowskic55e7712012-12-02 04:05:46 +00009125 MISC_REGISTERS_RESET_REG_2_PGLC |
9126 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9127 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9128 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9129 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9130 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9131 MISC_REGISTERS_RESET_REG_2_UMAC1;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009132
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009133 /*
9134 * Keep the following blocks in reset:
9135 * - all xxMACs are handled by the bnx2x_link code.
9136 */
9137 stay_reset2 =
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009138 MISC_REGISTERS_RESET_REG_2_XMAC |
9139 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9140
9141 /* Full reset masks according to the chip */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009142 reset_mask1 = 0xffffffff;
9143
9144 if (CHIP_IS_E1(bp))
9145 reset_mask2 = 0xffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009146 else if (CHIP_IS_E1H(bp))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009147 reset_mask2 = 0x1ffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009148 else if (CHIP_IS_E2(bp))
9149 reset_mask2 = 0xfffff;
9150 else /* CHIP_IS_E3 */
9151 reset_mask2 = 0x3ffffff;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009152
9153 /* Don't reset global blocks unless we need to */
9154 if (!global)
9155 reset_mask2 &= ~global_bits2;
9156
9157 /*
9158 * In case of attention in the QM, we need to reset PXP
9159 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9160 * because otherwise QM reset would release 'close the gates' shortly
9161 * before resetting the PXP, then the PSWRQ would send a write
9162 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9163 * read the payload data from PSWWR, but PSWWR would not
9164 * respond. The write queue in PGLUE would stuck, dmae commands
9165 * would not return. Therefore it's important to reset the second
9166 * reset register (containing the
9167 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9168 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9169 * bit).
9170 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009171 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9172 reset_mask2 & (~not_reset_mask2));
9173
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009174 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9175 reset_mask1 & (~not_reset_mask1));
9176
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009177 barrier();
9178 mmiowb();
9179
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009180 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9181 reset_mask2 & (~stay_reset2));
9182
9183 barrier();
9184 mmiowb();
9185
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009186 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009187 mmiowb();
9188}
9189
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009190/**
9191 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9192 * It should get cleared in no more than 1s.
9193 *
9194 * @bp: driver handle
9195 *
9196 * It should get cleared in no more than 1s. Returns 0 if
9197 * pending writes bit gets cleared.
9198 */
9199static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9200{
9201 u32 cnt = 1000;
9202 u32 pend_bits = 0;
9203
9204 do {
9205 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9206
9207 if (pend_bits == 0)
9208 break;
9209
Yuval Mintz0926d492013-01-23 03:21:45 +00009210 usleep_range(1000, 2000);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009211 } while (cnt-- > 0);
9212
9213 if (cnt <= 0) {
9214 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9215 pend_bits);
9216 return -EBUSY;
9217 }
9218
9219 return 0;
9220}
9221
9222static int bnx2x_process_kill(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009223{
9224 int cnt = 1000;
9225 u32 val = 0;
9226 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
Yuval Mintz2de67432013-01-23 03:21:43 +00009227 u32 tags_63_32 = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009228
9229 /* Empty the Tetris buffer, wait for 1s */
9230 do {
9231 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9232 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9233 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9234 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9235 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009236 if (CHIP_IS_E3(bp))
9237 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9238
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009239 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9240 ((port_is_idle_0 & 0x1) == 0x1) &&
9241 ((port_is_idle_1 & 0x1) == 0x1) &&
Barak Witkowskic55e7712012-12-02 04:05:46 +00009242 (pgl_exp_rom2 == 0xffffffff) &&
9243 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009244 break;
Yuval Mintz0926d492013-01-23 03:21:45 +00009245 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009246 } while (cnt-- > 0);
9247
9248 if (cnt <= 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009249 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9250 BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009251 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9252 pgl_exp_rom2);
9253 return -EAGAIN;
9254 }
9255
9256 barrier();
9257
9258 /* Close gates #2, #3 and #4 */
9259 bnx2x_set_234_gates(bp, true);
9260
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009261 /* Poll for IGU VQs for 57712 and newer chips */
9262 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9263 return -EAGAIN;
9264
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009265 /* TBD: Indicate that "process kill" is in progress to MCP */
9266
9267 /* Clear "unprepared" bit */
9268 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9269 barrier();
9270
9271 /* Make sure all is written to the chip before the reset */
9272 mmiowb();
9273
9274 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9275 * PSWHST, GRC and PSWRD Tetris buffer.
9276 */
Yuval Mintz0926d492013-01-23 03:21:45 +00009277 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009278
9279 /* Prepare to chip reset: */
9280 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009281 if (global)
9282 bnx2x_reset_mcp_prep(bp, &val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009283
9284 /* PXP */
9285 bnx2x_pxp_prep(bp);
9286 barrier();
9287
9288 /* reset the chip */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009289 bnx2x_process_kill_chip_reset(bp, global);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009290 barrier();
9291
9292 /* Recover after reset: */
9293 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009294 if (global && bnx2x_reset_mcp_comp(bp, val))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009295 return -EAGAIN;
9296
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009297 /* TBD: Add resetting the NO_MCP mode DB here */
9298
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009299 /* Open the gates #2, #3 and #4 */
9300 bnx2x_set_234_gates(bp, false);
9301
9302 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9303 * reset state, re-enable attentions. */
9304
9305 return 0;
9306}
9307
Merav Sicron910cc722012-11-11 03:56:08 +00009308static int bnx2x_leader_reset(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009309{
9310 int rc = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009311 bool global = bnx2x_reset_is_global(bp);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009312 u32 load_code;
9313
9314 /* if not going to reset MCP - load "fake" driver to reset HW while
9315 * driver is owner of the HW
9316 */
9317 if (!global && !BP_NOMCP(bp)) {
Yuval Mintz5d07d862012-09-13 02:56:21 +00009318 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9319 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009320 if (!load_code) {
9321 BNX2X_ERR("MCP response failure, aborting\n");
9322 rc = -EAGAIN;
9323 goto exit_leader_reset;
9324 }
9325 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9326 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9327 BNX2X_ERR("MCP unexpected resp, aborting\n");
9328 rc = -EAGAIN;
9329 goto exit_leader_reset2;
9330 }
9331 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9332 if (!load_code) {
9333 BNX2X_ERR("MCP response failure, aborting\n");
9334 rc = -EAGAIN;
9335 goto exit_leader_reset2;
9336 }
9337 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009338
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009339 /* Try to recover after the failure */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009340 if (bnx2x_process_kill(bp, global)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009341 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9342 BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009343 rc = -EAGAIN;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009344 goto exit_leader_reset2;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009345 }
9346
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009347 /*
9348 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9349 * state.
9350 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009351 bnx2x_set_reset_done(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009352 if (global)
9353 bnx2x_clear_reset_global(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009354
Ariel Elior95c6c6162012-01-26 06:01:52 +00009355exit_leader_reset2:
9356 /* unload "fake driver" if it was loaded */
9357 if (!global && !BP_NOMCP(bp)) {
9358 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9359 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9360 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009361exit_leader_reset:
9362 bp->is_leader = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009363 bnx2x_release_leader_lock(bp);
9364 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009365 return rc;
9366}
9367
Eric Dumazet1191cb82012-04-27 21:39:21 +00009368static void bnx2x_recovery_failed(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009369{
9370 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9371
9372 /* Disconnect this device */
9373 netif_device_detach(bp->dev);
9374
9375 /*
9376 * Block ifup for all function on this engine until "process kill"
9377 * or power cycle.
9378 */
9379 bnx2x_set_reset_in_progress(bp);
9380
9381 /* Shut down the power */
9382 bnx2x_set_power_state(bp, PCI_D3hot);
9383
9384 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9385
9386 smp_mb();
9387}
9388
9389/*
9390 * Assumption: runs under rtnl lock. This together with the fact
Ariel Elior6383c0b2011-07-14 08:31:57 +00009391 * that it's called only from bnx2x_sp_rtnl() ensure that it
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009392 * will never be called when netif_running(bp->dev) is false.
9393 */
9394static void bnx2x_parity_recover(struct bnx2x *bp)
9395{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009396 bool global = false;
Ariel Elior7a752992012-01-26 06:01:53 +00009397 u32 error_recovered, error_unrecovered;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009398 bool is_parity;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009399
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009400 DP(NETIF_MSG_HW, "Handling parity\n");
9401 while (1) {
9402 switch (bp->recovery_state) {
9403 case BNX2X_RECOVERY_INIT:
9404 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009405 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9406 WARN_ON(!is_parity);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009407
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009408 /* Try to get a LEADER_LOCK HW lock */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009409 if (bnx2x_trylock_leader_lock(bp)) {
9410 bnx2x_set_reset_in_progress(bp);
9411 /*
9412 * Check if there is a global attention and if
9413 * there was a global attention, set the global
9414 * reset bit.
9415 */
9416
9417 if (global)
9418 bnx2x_set_reset_global(bp);
9419
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009420 bp->is_leader = 1;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009421 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009422
9423 /* Stop the driver */
9424 /* If interface has been removed - break */
Yuval Mintz5d07d862012-09-13 02:56:21 +00009425 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009426 return;
9427
9428 bp->recovery_state = BNX2X_RECOVERY_WAIT;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009429
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009430 /* Ensure "is_leader", MCP command sequence and
9431 * "recovery_state" update values are seen on other
9432 * CPUs.
9433 */
9434 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009435 break;
9436
9437 case BNX2X_RECOVERY_WAIT:
9438 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9439 if (bp->is_leader) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009440 int other_engine = BP_PATH(bp) ? 0 : 1;
Ariel Elior889b9af2012-01-26 06:01:51 +00009441 bool other_load_status =
9442 bnx2x_get_load_status(bp, other_engine);
9443 bool load_status =
9444 bnx2x_get_load_status(bp, BP_PATH(bp));
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009445 global = bnx2x_reset_is_global(bp);
9446
9447 /*
9448 * In case of a parity in a global block, let
9449 * the first leader that performs a
9450 * leader_reset() reset the global blocks in
9451 * order to clear global attentions. Otherwise
Yuval Mintz16a5fd92013-06-02 00:06:18 +00009452 * the gates will remain closed for that
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009453 * engine.
9454 */
Ariel Elior889b9af2012-01-26 06:01:51 +00009455 if (load_status ||
9456 (global && other_load_status)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009457 /* Wait until all other functions get
9458 * down.
9459 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009460 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009461 HZ/10);
9462 return;
9463 } else {
9464 /* If all other functions got down -
9465 * try to bring the chip back to
9466 * normal. In any case it's an exit
9467 * point for a leader.
9468 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009469 if (bnx2x_leader_reset(bp)) {
9470 bnx2x_recovery_failed(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009471 return;
9472 }
9473
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009474 /* If we are here, means that the
9475 * leader has succeeded and doesn't
9476 * want to be a leader any more. Try
9477 * to continue as a none-leader.
9478 */
9479 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009480 }
9481 } else { /* non-leader */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009482 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009483 /* Try to get a LEADER_LOCK HW lock as
9484 * long as a former leader may have
9485 * been unloaded by the user or
9486 * released a leadership by another
9487 * reason.
9488 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009489 if (bnx2x_trylock_leader_lock(bp)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009490 /* I'm a leader now! Restart a
9491 * switch case.
9492 */
9493 bp->is_leader = 1;
9494 break;
9495 }
9496
Ariel Elior7be08a72011-07-14 08:31:19 +00009497 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009498 HZ/10);
9499 return;
9500
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009501 } else {
9502 /*
9503 * If there was a global attention, wait
9504 * for it to be cleared.
9505 */
9506 if (bnx2x_reset_is_global(bp)) {
9507 schedule_delayed_work(
Ariel Elior7be08a72011-07-14 08:31:19 +00009508 &bp->sp_rtnl_task,
9509 HZ/10);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009510 return;
9511 }
9512
Ariel Elior7a752992012-01-26 06:01:53 +00009513 error_recovered =
9514 bp->eth_stats.recoverable_error;
9515 error_unrecovered =
9516 bp->eth_stats.unrecoverable_error;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009517 bp->recovery_state =
9518 BNX2X_RECOVERY_NIC_LOADING;
9519 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
Ariel Elior7a752992012-01-26 06:01:53 +00009520 error_unrecovered++;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009521 netdev_err(bp->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +00009522 "Recovery failed. Power cycle needed\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009523 /* Disconnect this device */
9524 netif_device_detach(bp->dev);
9525 /* Shut down the power */
9526 bnx2x_set_power_state(
9527 bp, PCI_D3hot);
9528 smp_mb();
9529 } else {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009530 bp->recovery_state =
9531 BNX2X_RECOVERY_DONE;
Ariel Elior7a752992012-01-26 06:01:53 +00009532 error_recovered++;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009533 smp_mb();
9534 }
Ariel Elior7a752992012-01-26 06:01:53 +00009535 bp->eth_stats.recoverable_error =
9536 error_recovered;
9537 bp->eth_stats.unrecoverable_error =
9538 error_unrecovered;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009539
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009540 return;
9541 }
9542 }
9543 default:
9544 return;
9545 }
9546 }
9547}
9548
Michal Schmidt56ad3152012-02-16 02:38:48 +00009549static int bnx2x_close(struct net_device *dev);
9550
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009551/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9552 * scheduled on a general queue in order to prevent a dead lock.
9553 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009554static void bnx2x_sp_rtnl_task(struct work_struct *work)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009555{
Ariel Elior7be08a72011-07-14 08:31:19 +00009556 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009557
9558 rtnl_lock();
9559
Ariel Elior8395be52013-01-01 05:22:44 +00009560 if (!netif_running(bp->dev)) {
9561 rtnl_unlock();
9562 return;
9563 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009564
Ariel Elior7be08a72011-07-14 08:31:19 +00009565 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009566#ifdef BNX2X_STOP_ON_ERROR
9567 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9568 "you will need to reboot when done\n");
9569 goto sp_rtnl_not_reset;
9570#endif
Ariel Elior7be08a72011-07-14 08:31:19 +00009571 /*
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009572 * Clear all pending SP commands as we are going to reset the
9573 * function anyway.
Ariel Elior7be08a72011-07-14 08:31:19 +00009574 */
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009575 bp->sp_rtnl_state = 0;
9576 smp_mb();
9577
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009578 bnx2x_parity_recover(bp);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009579
Ariel Elior8395be52013-01-01 05:22:44 +00009580 rtnl_unlock();
9581 return;
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009582 }
9583
9584 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009585#ifdef BNX2X_STOP_ON_ERROR
9586 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9587 "you will need to reboot when done\n");
9588 goto sp_rtnl_not_reset;
9589#endif
9590
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009591 /*
9592 * Clear all pending SP commands as we are going to reset the
9593 * function anyway.
9594 */
9595 bp->sp_rtnl_state = 0;
9596 smp_mb();
9597
Yuval Mintz5d07d862012-09-13 02:56:21 +00009598 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009599 bnx2x_nic_load(bp, LOAD_NORMAL);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009600
Ariel Elior8395be52013-01-01 05:22:44 +00009601 rtnl_unlock();
9602 return;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009603 }
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009604#ifdef BNX2X_STOP_ON_ERROR
9605sp_rtnl_not_reset:
9606#endif
9607 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9608 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
Barak Witkowskia3348722012-04-23 03:04:46 +00009609 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9610 bnx2x_after_function_update(bp);
Ariel Elior83048592011-11-13 04:34:29 +00009611 /*
9612 * in case of fan failure we need to reset id if the "stop on error"
9613 * debug flag is set, since we trying to prevent permanent overheating
9614 * damage
9615 */
9616 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009617 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
Ariel Elior83048592011-11-13 04:34:29 +00009618 netif_device_detach(bp->dev);
9619 bnx2x_close(bp->dev);
Ariel Elior8395be52013-01-01 05:22:44 +00009620 rtnl_unlock();
9621 return;
Ariel Elior83048592011-11-13 04:34:29 +00009622 }
9623
Ariel Elior381ac162013-01-01 05:22:29 +00009624 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9625 DP(BNX2X_MSG_SP,
9626 "sending set mcast vf pf channel message from rtnl sp-task\n");
9627 bnx2x_vfpf_set_mcast(bp->dev);
9628 }
Ariel Elior78c3bcc2013-06-20 17:39:08 +03009629 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
9630 &bp->sp_rtnl_state)){
9631 if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
9632 bnx2x_tx_disable(bp);
9633 BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
9634 }
9635 }
Ariel Elior381ac162013-01-01 05:22:29 +00009636
Yuval Mintz8b09be52013-08-01 17:30:59 +03009637 if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
9638 DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
9639 bnx2x_set_rx_mode_inner(bp);
Ariel Elior381ac162013-01-01 05:22:29 +00009640 }
9641
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00009642 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9643 &bp->sp_rtnl_state))
9644 bnx2x_pf_set_vfs_vlan(bp);
9645
Ariel Elior8395be52013-01-01 05:22:44 +00009646 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9647 * can be called from other contexts as well)
9648 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009649 rtnl_unlock();
Ariel Elior8395be52013-01-01 05:22:44 +00009650
Ariel Elior64112802013-01-07 00:50:23 +00009651 /* enable SR-IOV if applicable */
Ariel Elior8395be52013-01-01 05:22:44 +00009652 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
Ariel Elior3c76fef2013-03-11 05:17:46 +00009653 &bp->sp_rtnl_state)) {
9654 bnx2x_disable_sriov(bp);
Ariel Elior64112802013-01-07 00:50:23 +00009655 bnx2x_enable_sriov(bp);
Ariel Elior3c76fef2013-03-11 05:17:46 +00009656 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009657}
9658
Yaniv Rosner3deb8162011-06-14 01:34:33 +00009659static void bnx2x_period_task(struct work_struct *work)
9660{
9661 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9662
9663 if (!netif_running(bp->dev))
9664 goto period_task_exit;
9665
9666 if (CHIP_REV_IS_SLOW(bp)) {
9667 BNX2X_ERR("period task called on emulation, ignoring\n");
9668 goto period_task_exit;
9669 }
9670
9671 bnx2x_acquire_phy_lock(bp);
9672 /*
9673 * The barrier is needed to ensure the ordering between the writing to
9674 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9675 * the reading here.
9676 */
9677 smp_mb();
9678 if (bp->port.pmf) {
9679 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9680
9681 /* Re-queue task in 1 sec */
9682 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9683 }
9684
9685 bnx2x_release_phy_lock(bp);
9686period_task_exit:
9687 return;
9688}
9689
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009690/*
9691 * Init service functions
9692 */
9693
Ariel Eliorb56e9672013-01-01 05:22:32 +00009694u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009695{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009696 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9697 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9698 return base + (BP_ABS_FUNC(bp)) * stride;
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009699}
9700
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009701static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9702 struct bnx2x_mac_vals *vals)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009703{
Yuval Mintz452427b2012-03-26 20:47:07 +00009704 u32 val, base_addr, offset, mask, reset_reg;
9705 bool mac_stopped = false;
9706 u8 port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009707
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009708 /* reset addresses as they also mark which values were changed */
9709 vals->bmac_addr = 0;
9710 vals->umac_addr = 0;
9711 vals->xmac_addr = 0;
9712 vals->emac_addr = 0;
9713
Yuval Mintz452427b2012-03-26 20:47:07 +00009714 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
David S. Miller8decf862011-09-22 03:23:13 -04009715
Yuval Mintz452427b2012-03-26 20:47:07 +00009716 if (!CHIP_IS_E3(bp)) {
9717 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9718 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9719 if ((mask & reset_reg) && val) {
9720 u32 wb_data[2];
9721 BNX2X_DEV_INFO("Disable bmac Rx\n");
9722 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9723 : NIG_REG_INGRESS_BMAC0_MEM;
9724 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9725 : BIGMAC_REGISTER_BMAC_CONTROL;
Ariel Eliorf16da432012-01-26 06:01:50 +00009726
Yuval Mintz452427b2012-03-26 20:47:07 +00009727 /*
9728 * use rd/wr since we cannot use dmae. This is safe
9729 * since MCP won't access the bus due to the request
9730 * to unload, and no function on the path can be
9731 * loaded at this time.
9732 */
9733 wb_data[0] = REG_RD(bp, base_addr + offset);
9734 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009735 vals->bmac_addr = base_addr + offset;
9736 vals->bmac_val[0] = wb_data[0];
9737 vals->bmac_val[1] = wb_data[1];
Yuval Mintz452427b2012-03-26 20:47:07 +00009738 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009739 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9740 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
Yuval Mintz452427b2012-03-26 20:47:07 +00009741 }
9742 BNX2X_DEV_INFO("Disable emac Rx\n");
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009743 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9744 vals->emac_val = REG_RD(bp, vals->emac_addr);
9745 REG_WR(bp, vals->emac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009746 mac_stopped = true;
9747 } else {
9748 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9749 BNX2X_DEV_INFO("Disable xmac Rx\n");
9750 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9751 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9752 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9753 val & ~(1 << 1));
9754 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9755 val | (1 << 1));
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009756 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9757 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9758 REG_WR(bp, vals->xmac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009759 mac_stopped = true;
9760 }
9761 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9762 if (mask & reset_reg) {
9763 BNX2X_DEV_INFO("Disable umac Rx\n");
9764 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009765 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9766 vals->umac_val = REG_RD(bp, vals->umac_addr);
9767 REG_WR(bp, vals->umac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009768 mac_stopped = true;
David S. Miller8decf862011-09-22 03:23:13 -04009769 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009770 }
Ariel Eliorf16da432012-01-26 06:01:50 +00009771
Yuval Mintz452427b2012-03-26 20:47:07 +00009772 if (mac_stopped)
9773 msleep(20);
Yuval Mintz452427b2012-03-26 20:47:07 +00009774}
9775
9776#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9777#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9778#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9779#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9780
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009781static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
Yuval Mintz452427b2012-03-26 20:47:07 +00009782{
9783 u16 rcq, bd;
9784 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9785
9786 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9787 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9788
9789 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9790 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9791
9792 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
9793 port, bd, rcq);
9794}
9795
Bill Pemberton0329aba2012-12-03 09:24:24 -05009796static int bnx2x_prev_mcp_done(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +00009797{
Yuval Mintz5d07d862012-09-13 02:56:21 +00009798 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
9799 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
Yuval Mintz452427b2012-03-26 20:47:07 +00009800 if (!rc) {
9801 BNX2X_ERR("MCP response failure, aborting\n");
9802 return -EBUSY;
9803 }
9804
9805 return 0;
9806}
9807
Barak Witkowskic63da992012-12-05 23:04:03 +00009808static struct bnx2x_prev_path_list *
9809 bnx2x_prev_path_get_entry(struct bnx2x *bp)
9810{
9811 struct bnx2x_prev_path_list *tmp_list;
9812
9813 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
9814 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
9815 bp->pdev->bus->number == tmp_list->bus &&
9816 BP_PATH(bp) == tmp_list->path)
9817 return tmp_list;
9818
9819 return NULL;
9820}
9821
Yuval Mintz7fa6f3402013-03-20 05:21:28 +00009822static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
9823{
9824 struct bnx2x_prev_path_list *tmp_list;
9825 int rc;
9826
9827 rc = down_interruptible(&bnx2x_prev_sem);
9828 if (rc) {
9829 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9830 return rc;
9831 }
9832
9833 tmp_list = bnx2x_prev_path_get_entry(bp);
9834 if (tmp_list) {
9835 tmp_list->aer = 1;
9836 rc = 0;
9837 } else {
9838 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
9839 BP_PATH(bp));
9840 }
9841
9842 up(&bnx2x_prev_sem);
9843
9844 return rc;
9845}
9846
Bill Pemberton0329aba2012-12-03 09:24:24 -05009847static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +00009848{
9849 struct bnx2x_prev_path_list *tmp_list;
9850 int rc = false;
9851
9852 if (down_trylock(&bnx2x_prev_sem))
9853 return false;
9854
Yuval Mintz7fa6f3402013-03-20 05:21:28 +00009855 tmp_list = bnx2x_prev_path_get_entry(bp);
9856 if (tmp_list) {
9857 if (tmp_list->aer) {
9858 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
9859 BP_PATH(bp));
9860 } else {
Yuval Mintz452427b2012-03-26 20:47:07 +00009861 rc = true;
9862 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
9863 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +00009864 }
9865 }
9866
9867 up(&bnx2x_prev_sem);
9868
9869 return rc;
9870}
9871
Dmitry Kravkov178135c2013-05-22 21:21:50 +00009872bool bnx2x_port_after_undi(struct bnx2x *bp)
9873{
9874 struct bnx2x_prev_path_list *entry;
9875 bool val;
9876
9877 down(&bnx2x_prev_sem);
9878
9879 entry = bnx2x_prev_path_get_entry(bp);
9880 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
9881
9882 up(&bnx2x_prev_sem);
9883
9884 return val;
9885}
9886
Barak Witkowskic63da992012-12-05 23:04:03 +00009887static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
Yuval Mintz452427b2012-03-26 20:47:07 +00009888{
9889 struct bnx2x_prev_path_list *tmp_list;
9890 int rc;
9891
Yuval Mintz7fa6f3402013-03-20 05:21:28 +00009892 rc = down_interruptible(&bnx2x_prev_sem);
9893 if (rc) {
9894 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9895 return rc;
9896 }
9897
9898 /* Check whether the entry for this path already exists */
9899 tmp_list = bnx2x_prev_path_get_entry(bp);
9900 if (tmp_list) {
9901 if (!tmp_list->aer) {
9902 BNX2X_ERR("Re-Marking the path.\n");
9903 } else {
9904 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
9905 BP_PATH(bp));
9906 tmp_list->aer = 0;
9907 }
9908 up(&bnx2x_prev_sem);
9909 return 0;
9910 }
9911 up(&bnx2x_prev_sem);
9912
9913 /* Create an entry for this path and add it */
Devendra Nagaea4b3852012-07-29 03:19:23 +00009914 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
Yuval Mintz452427b2012-03-26 20:47:07 +00009915 if (!tmp_list) {
9916 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
9917 return -ENOMEM;
9918 }
9919
9920 tmp_list->bus = bp->pdev->bus->number;
9921 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
9922 tmp_list->path = BP_PATH(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +00009923 tmp_list->aer = 0;
Barak Witkowskic63da992012-12-05 23:04:03 +00009924 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
Yuval Mintz452427b2012-03-26 20:47:07 +00009925
9926 rc = down_interruptible(&bnx2x_prev_sem);
9927 if (rc) {
9928 BNX2X_ERR("Received %d when tried to take lock\n", rc);
9929 kfree(tmp_list);
9930 } else {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +00009931 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
9932 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +00009933 list_add(&tmp_list->list, &bnx2x_prev_list);
9934 up(&bnx2x_prev_sem);
9935 }
9936
9937 return rc;
9938}
9939
Bill Pemberton0329aba2012-12-03 09:24:24 -05009940static int bnx2x_do_flr(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +00009941{
Jiang Liu2a80eeb2012-08-20 13:26:51 -06009942 int i;
Yuval Mintz452427b2012-03-26 20:47:07 +00009943 u16 status;
9944 struct pci_dev *dev = bp->pdev;
9945
Yuval Mintz8eee6942012-08-09 04:37:25 +00009946 if (CHIP_IS_E1x(bp)) {
9947 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
9948 return -EINVAL;
9949 }
9950
9951 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
9952 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
9953 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
9954 bp->common.bc_ver);
9955 return -EINVAL;
9956 }
Yuval Mintz452427b2012-03-26 20:47:07 +00009957
Yuval Mintz452427b2012-03-26 20:47:07 +00009958 /* Wait for Transaction Pending bit clean */
9959 for (i = 0; i < 4; i++) {
9960 if (i)
9961 msleep((1 << (i - 1)) * 100);
9962
Jiang Liu2a80eeb2012-08-20 13:26:51 -06009963 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
Yuval Mintz452427b2012-03-26 20:47:07 +00009964 if (!(status & PCI_EXP_DEVSTA_TRPND))
9965 goto clear;
9966 }
9967
9968 dev_err(&dev->dev,
9969 "transaction is not cleared; proceeding with reset anyway\n");
9970
9971clear:
Yuval Mintz452427b2012-03-26 20:47:07 +00009972
Yuval Mintz8eee6942012-08-09 04:37:25 +00009973 BNX2X_DEV_INFO("Initiating FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +00009974 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
9975
9976 return 0;
9977}
9978
Bill Pemberton0329aba2012-12-03 09:24:24 -05009979static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +00009980{
9981 int rc;
9982
9983 BNX2X_DEV_INFO("Uncommon unload Flow\n");
9984
9985 /* Test if previous unload process was already finished for this path */
9986 if (bnx2x_prev_is_path_marked(bp))
9987 return bnx2x_prev_mcp_done(bp);
9988
Yuval Mintz04c46732013-01-23 03:21:46 +00009989 BNX2X_DEV_INFO("Path is unmarked\n");
9990
Yuval Mintz452427b2012-03-26 20:47:07 +00009991 /* If function has FLR capabilities, and existing FW version matches
9992 * the one required, then FLR will be sufficient to clean any residue
9993 * left by previous driver
9994 */
Ariel Eliorad5afc82013-01-01 05:22:26 +00009995 rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
Yuval Mintz8eee6942012-08-09 04:37:25 +00009996
9997 if (!rc) {
9998 /* fw version is good */
9999 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
10000 rc = bnx2x_do_flr(bp);
10001 }
10002
10003 if (!rc) {
10004 /* FLR was performed */
10005 BNX2X_DEV_INFO("FLR successful\n");
10006 return 0;
10007 }
10008
10009 BNX2X_DEV_INFO("Could not FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010010
10011 /* Close the MCP request, return failure*/
10012 rc = bnx2x_prev_mcp_done(bp);
10013 if (!rc)
10014 rc = BNX2X_PREV_WAIT_NEEDED;
10015
10016 return rc;
10017}
10018
Bill Pemberton0329aba2012-12-03 09:24:24 -050010019static int bnx2x_prev_unload_common(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010020{
10021 u32 reset_reg, tmp_reg = 0, rc;
Barak Witkowskic63da992012-12-05 23:04:03 +000010022 bool prev_undi = false;
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010023 struct bnx2x_mac_vals mac_vals;
10024
Yuval Mintz452427b2012-03-26 20:47:07 +000010025 /* It is possible a previous function received 'common' answer,
10026 * but hasn't loaded yet, therefore creating a scenario of
10027 * multiple functions receiving 'common' on the same path.
10028 */
10029 BNX2X_DEV_INFO("Common unload Flow\n");
10030
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010031 memset(&mac_vals, 0, sizeof(mac_vals));
10032
Yuval Mintz452427b2012-03-26 20:47:07 +000010033 if (bnx2x_prev_is_path_marked(bp))
10034 return bnx2x_prev_mcp_done(bp);
10035
10036 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
10037
10038 /* Reset should be performed after BRB is emptied */
10039 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
10040 u32 timer_count = 1000;
Yuval Mintz452427b2012-03-26 20:47:07 +000010041
10042 /* Close the MAC Rx to prevent BRB from filling up */
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010043 bnx2x_prev_unload_close_mac(bp, &mac_vals);
10044
10045 /* close LLH filters towards the BRB */
10046 bnx2x_set_rx_filter(&bp->link_params, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010047
10048 /* Check if the UNDI driver was previously loaded
10049 * UNDI driver initializes CID offset for normal bell to 0x7
10050 */
Yuval Mintz452427b2012-03-26 20:47:07 +000010051 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
10052 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
10053 if (tmp_reg == 0x7) {
10054 BNX2X_DEV_INFO("UNDI previously loaded\n");
10055 prev_undi = true;
10056 /* clear the UNDI indication */
10057 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
Yuval Mintza74801c2013-01-14 05:11:41 +000010058 /* clear possible idle check errors */
10059 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010060 }
10061 }
Dmitry Kravkovd46f7c42013-04-17 22:49:05 +000010062 if (!CHIP_IS_E1x(bp))
10063 /* block FW from writing to host */
10064 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10065
Yuval Mintz452427b2012-03-26 20:47:07 +000010066 /* wait until BRB is empty */
10067 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10068 while (timer_count) {
10069 u32 prev_brb = tmp_reg;
10070
10071 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10072 if (!tmp_reg)
10073 break;
10074
10075 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
10076
10077 /* reset timer as long as BRB actually gets emptied */
10078 if (prev_brb > tmp_reg)
10079 timer_count = 1000;
10080 else
10081 timer_count--;
10082
10083 /* If UNDI resides in memory, manually increment it */
10084 if (prev_undi)
10085 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
10086
10087 udelay(10);
10088 }
10089
10090 if (!timer_count)
10091 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010092 }
10093
10094 /* No packets are in the pipeline, path is ready for reset */
10095 bnx2x_reset_common(bp);
10096
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010097 if (mac_vals.xmac_addr)
10098 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
10099 if (mac_vals.umac_addr)
10100 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
10101 if (mac_vals.emac_addr)
10102 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
10103 if (mac_vals.bmac_addr) {
10104 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
10105 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
10106 }
10107
Barak Witkowskic63da992012-12-05 23:04:03 +000010108 rc = bnx2x_prev_mark_path(bp, prev_undi);
Yuval Mintz452427b2012-03-26 20:47:07 +000010109 if (rc) {
10110 bnx2x_prev_mcp_done(bp);
10111 return rc;
10112 }
10113
10114 return bnx2x_prev_mcp_done(bp);
10115}
10116
Ariel Elior24f06712012-05-06 07:05:57 +000010117/* previous driver DMAE transaction may have occurred when pre-boot stage ended
10118 * and boot began, or when kdump kernel was loaded. Either case would invalidate
10119 * the addresses of the transaction, resulting in was-error bit set in the pci
10120 * causing all hw-to-host pcie transactions to timeout. If this happened we want
10121 * to clear the interrupt which detected this from the pglueb and the was done
10122 * bit
10123 */
Bill Pemberton0329aba2012-12-03 09:24:24 -050010124static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
Ariel Elior24f06712012-05-06 07:05:57 +000010125{
Ariel Elior4a254172012-11-22 07:16:17 +000010126 if (!CHIP_IS_E1x(bp)) {
10127 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
10128 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
Yuval Mintz04c46732013-01-23 03:21:46 +000010129 DP(BNX2X_MSG_SP,
10130 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
Ariel Elior4a254172012-11-22 07:16:17 +000010131 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
10132 1 << BP_FUNC(bp));
10133 }
Ariel Elior24f06712012-05-06 07:05:57 +000010134 }
10135}
10136
Bill Pemberton0329aba2012-12-03 09:24:24 -050010137static int bnx2x_prev_unload(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010138{
10139 int time_counter = 10;
10140 u32 rc, fw, hw_lock_reg, hw_lock_val;
10141 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10142
Ariel Elior24f06712012-05-06 07:05:57 +000010143 /* clear hw from errors which may have resulted from an interrupted
10144 * dmae transaction.
10145 */
10146 bnx2x_prev_interrupted_dmae(bp);
10147
10148 /* Release previously held locks */
Yuval Mintz452427b2012-03-26 20:47:07 +000010149 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10150 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10151 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10152
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010153 hw_lock_val = REG_RD(bp, hw_lock_reg);
Yuval Mintz452427b2012-03-26 20:47:07 +000010154 if (hw_lock_val) {
10155 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10156 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10157 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10158 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10159 }
10160
10161 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10162 REG_WR(bp, hw_lock_reg, 0xffffffff);
10163 } else
10164 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10165
10166 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10167 BNX2X_DEV_INFO("Release previously held alr\n");
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010168 bnx2x_release_alr(bp);
Yuval Mintz452427b2012-03-26 20:47:07 +000010169 }
10170
Yuval Mintz452427b2012-03-26 20:47:07 +000010171 do {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010172 int aer = 0;
Yuval Mintz452427b2012-03-26 20:47:07 +000010173 /* Lock MCP using an unload request */
10174 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10175 if (!fw) {
10176 BNX2X_ERR("MCP response failure, aborting\n");
10177 rc = -EBUSY;
10178 break;
10179 }
10180
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010181 rc = down_interruptible(&bnx2x_prev_sem);
10182 if (rc) {
10183 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10184 rc);
10185 } else {
10186 /* If Path is marked by EEH, ignore unload status */
10187 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10188 bnx2x_prev_path_get_entry(bp)->aer);
Yuval Mintz60cde812013-03-26 23:28:03 +000010189 up(&bnx2x_prev_sem);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010190 }
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010191
10192 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
Yuval Mintz452427b2012-03-26 20:47:07 +000010193 rc = bnx2x_prev_unload_common(bp);
10194 break;
10195 }
10196
Yuval Mintz16a5fd92013-06-02 00:06:18 +000010197 /* non-common reply from MCP might require looping */
Yuval Mintz452427b2012-03-26 20:47:07 +000010198 rc = bnx2x_prev_unload_uncommon(bp);
10199 if (rc != BNX2X_PREV_WAIT_NEEDED)
10200 break;
10201
10202 msleep(20);
10203 } while (--time_counter);
10204
10205 if (!time_counter || rc) {
10206 BNX2X_ERR("Failed unloading previous driver, aborting\n");
10207 rc = -EBUSY;
10208 }
10209
Barak Witkowskic63da992012-12-05 23:04:03 +000010210 /* Mark function if its port was used to boot from SAN */
Dmitry Kravkov178135c2013-05-22 21:21:50 +000010211 if (bnx2x_port_after_undi(bp))
Barak Witkowskic63da992012-12-05 23:04:03 +000010212 bp->link_params.feature_config_flags |=
10213 FEATURE_CONFIG_BOOT_FROM_SAN;
10214
Yuval Mintz452427b2012-03-26 20:47:07 +000010215 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10216
10217 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010218}
10219
Bill Pemberton0329aba2012-12-03 09:24:24 -050010220static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010221{
Barak Witkowski1d187b32011-12-05 22:41:50 +000010222 u32 val, val2, val3, val4, id, boot_mode;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010223 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010224
10225 /* Get the chip revision id and number. */
10226 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10227 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10228 id = ((val & 0xffff) << 16);
10229 val = REG_RD(bp, MISC_REG_CHIP_REV);
10230 id |= ((val & 0xf) << 12);
Yuval Mintzf22fdf22013-03-11 05:17:43 +000010231
10232 /* Metal is read from PCI regs, but we can't access >=0x400 from
10233 * the configuration space (so we need to reg_rd)
10234 */
10235 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10236 id |= (((val >> 24) & 0xf) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +000010237 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010238 id |= (val & 0xf);
10239 bp->common.chip_id = id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010240
Barak Witkowski7e8e02d2012-04-03 18:41:28 +000010241 /* force 57811 according to MISC register */
10242 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10243 if (CHIP_IS_57810(bp))
10244 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10245 (bp->common.chip_id & 0x0000FFFF);
10246 else if (CHIP_IS_57810_MF(bp))
10247 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10248 (bp->common.chip_id & 0x0000FFFF);
10249 bp->common.chip_id |= 0x1;
10250 }
10251
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010252 /* Set doorbell size */
10253 bp->db_size = (1 << BNX2X_DB_SHIFT);
10254
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010255 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010256 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10257 if ((val & 1) == 0)
10258 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10259 else
10260 val = (val >> 1) & 1;
10261 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10262 "2_PORT_MODE");
10263 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10264 CHIP_2_PORT_MODE;
10265
10266 if (CHIP_MODE_IS_4_PORT(bp))
10267 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10268 else
10269 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10270 } else {
10271 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10272 bp->pfid = bp->pf_num; /* 0..7 */
10273 }
10274
Merav Sicron51c1a582012-03-18 10:33:38 +000010275 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10276
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010277 bp->link_params.chip_id = bp->common.chip_id;
10278 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010279
Eilon Greenstein1c063282009-02-12 08:36:43 +000010280 val = (REG_RD(bp, 0x2874) & 0x55);
10281 if ((bp->common.chip_id & 0x1) ||
10282 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10283 bp->flags |= ONE_PORT_FLAG;
10284 BNX2X_DEV_INFO("single port device\n");
10285 }
10286
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010287 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010288 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010289 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10290 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10291 bp->common.flash_size, bp->common.flash_size);
10292
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010293 bnx2x_init_shmem(bp);
10294
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010295 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10296 MISC_REG_GENERIC_CR_1 :
10297 MISC_REG_GENERIC_CR_0));
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010298
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010299 bp->link_params.shmem_base = bp->common.shmem_base;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010300 bp->link_params.shmem2_base = bp->common.shmem2_base;
Yaniv Rosnerb884d952012-11-27 03:46:28 +000010301 if (SHMEM2_RD(bp, size) >
10302 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10303 bp->link_params.lfa_base =
10304 REG_RD(bp, bp->common.shmem2_base +
10305 (u32)offsetof(struct shmem2_region,
10306 lfa_host_addr[BP_PORT(bp)]));
10307 else
10308 bp->link_params.lfa_base = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +000010309 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10310 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010311
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010312 if (!bp->common.shmem_base) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010313 BNX2X_DEV_INFO("MCP not active\n");
10314 bp->flags |= NO_MCP_FLAG;
10315 return;
10316 }
10317
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010318 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +000010319 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010320
10321 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10322 SHARED_HW_CFG_LED_MODE_MASK) >>
10323 SHARED_HW_CFG_LED_MODE_SHIFT);
10324
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000010325 bp->link_params.feature_config_flags = 0;
10326 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10327 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10328 bp->link_params.feature_config_flags |=
10329 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10330 else
10331 bp->link_params.feature_config_flags &=
10332 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10333
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010334 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10335 bp->common.bc_ver = val;
10336 BNX2X_DEV_INFO("bc_ver %X\n", val);
10337 if (val < BNX2X_BC_VER) {
10338 /* for now only warn
10339 * later we might need to enforce this */
Merav Sicron51c1a582012-03-18 10:33:38 +000010340 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10341 BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010342 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010343 bp->link_params.feature_config_flags |=
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010344 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010345 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10346
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010347 bp->link_params.feature_config_flags |=
10348 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10349 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
Barak Witkowskia3348722012-04-23 03:04:46 +000010350 bp->link_params.feature_config_flags |=
10351 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10352 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010353 bp->link_params.feature_config_flags |=
10354 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10355 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
Yaniv Rosner55386fe82012-11-27 03:46:30 +000010356
10357 bp->link_params.feature_config_flags |=
10358 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10359 FEATURE_CONFIG_MT_SUPPORT : 0;
10360
Barak Witkowski0e898dd2011-12-05 21:52:22 +000010361 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10362 BC_SUPPORTS_PFC_STATS : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010363
Barak Witkowski2e499d32012-06-26 01:31:19 +000010364 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10365 BC_SUPPORTS_FCOE_FEATURES : 0;
10366
Barak Witkowski98768792012-06-19 07:48:31 +000010367 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10368 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030010369
10370 bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
10371 BC_SUPPORTS_RMMOD_CMD : 0;
10372
Barak Witkowski1d187b32011-12-05 22:41:50 +000010373 boot_mode = SHMEM_RD(bp,
10374 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10375 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10376 switch (boot_mode) {
10377 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10378 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10379 break;
10380 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10381 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10382 break;
10383 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10384 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10385 break;
10386 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10387 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10388 break;
10389 }
10390
Dmitry Kravkovf9a3ebb2011-05-04 23:49:11 +000010391 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
10392 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10393
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010394 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +000010395 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010396
10397 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10398 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10399 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10400 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10401
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010402 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10403 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010404}
10405
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010406#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10407#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10408
Bill Pemberton0329aba2012-12-03 09:24:24 -050010409static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010410{
10411 int pfid = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010412 int igu_sb_id;
10413 u32 val;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010414 u8 fid, igu_sb_cnt = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010415
10416 bp->igu_base_sb = 0xff;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010417 if (CHIP_INT_MODE_IS_BC(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -040010418 int vn = BP_VN(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010419 igu_sb_cnt = bp->igu_sb_cnt;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010420 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10421 FP_SB_MAX_E1x;
10422
10423 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10424 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10425
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010426 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010427 }
10428
10429 /* IGU in normal mode - read CAM */
10430 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10431 igu_sb_id++) {
10432 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10433 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10434 continue;
10435 fid = IGU_FID(val);
10436 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10437 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10438 continue;
10439 if (IGU_VEC(val) == 0)
10440 /* default status block */
10441 bp->igu_dsb_id = igu_sb_id;
10442 else {
10443 if (bp->igu_base_sb == 0xff)
10444 bp->igu_base_sb = igu_sb_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010445 igu_sb_cnt++;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010446 }
10447 }
10448 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010449
Ariel Elior6383c0b2011-07-14 08:31:57 +000010450#ifdef CONFIG_PCI_MSI
Ariel Elior185d4c82012-09-20 05:26:41 +000010451 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10452 * optional that number of CAM entries will not be equal to the value
10453 * advertised in PCI.
10454 * Driver should use the minimal value of both as the actual status
10455 * block count
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010456 */
Ariel Elior185d4c82012-09-20 05:26:41 +000010457 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010458#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010459
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010460 if (igu_sb_cnt == 0) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010461 BNX2X_ERR("CAM configuration error\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010462 return -EINVAL;
10463 }
10464
10465 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010466}
10467
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010468static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010469{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010470 int cfg_size = 0, idx, port = BP_PORT(bp);
10471
10472 /* Aggregation of supported attributes of all external phys */
10473 bp->port.supported[0] = 0;
10474 bp->port.supported[1] = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010475 switch (bp->link_params.num_phys) {
10476 case 1:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010477 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10478 cfg_size = 1;
10479 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010480 case 2:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010481 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10482 cfg_size = 1;
10483 break;
10484 case 3:
10485 if (bp->link_params.multi_phy_config &
10486 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10487 bp->port.supported[1] =
10488 bp->link_params.phy[EXT_PHY1].supported;
10489 bp->port.supported[0] =
10490 bp->link_params.phy[EXT_PHY2].supported;
10491 } else {
10492 bp->port.supported[0] =
10493 bp->link_params.phy[EXT_PHY1].supported;
10494 bp->port.supported[1] =
10495 bp->link_params.phy[EXT_PHY2].supported;
10496 }
10497 cfg_size = 2;
10498 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010499 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010500
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010501 if (!(bp->port.supported[0] || bp->port.supported[1])) {
Merav Sicron51c1a582012-03-18 10:33:38 +000010502 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010503 SHMEM_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010504 dev_info.port_hw_config[port].external_phy_config),
10505 SHMEM_RD(bp,
10506 dev_info.port_hw_config[port].external_phy_config2));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010507 return;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010508 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010509
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010510 if (CHIP_IS_E3(bp))
10511 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10512 else {
10513 switch (switch_cfg) {
10514 case SWITCH_CFG_1G:
10515 bp->port.phy_addr = REG_RD(
10516 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10517 break;
10518 case SWITCH_CFG_10G:
10519 bp->port.phy_addr = REG_RD(
10520 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10521 break;
10522 default:
10523 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10524 bp->port.link_config[0]);
10525 return;
10526 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010527 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010528 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010529 /* mask what we support according to speed_cap_mask per configuration */
10530 for (idx = 0; idx < cfg_size; idx++) {
10531 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010532 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010533 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010534
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010535 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010536 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010537 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010538
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010539 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010540 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010541 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010542
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010543 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010544 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010545 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010546
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010547 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010548 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010549 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010550 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010551
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010552 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010553 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010554 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010555
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010556 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010557 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010558 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
Yaniv Rosnerb8e0d882013-06-20 17:39:11 +030010559
10560 if (!(bp->link_params.speed_cap_mask[idx] &
10561 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
10562 bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010563 }
10564
10565 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10566 bp->port.supported[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010567}
10568
Bill Pemberton0329aba2012-12-03 09:24:24 -050010569static void bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010570{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010571 u32 link_config, idx, cfg_size = 0;
10572 bp->port.advertising[0] = 0;
10573 bp->port.advertising[1] = 0;
10574 switch (bp->link_params.num_phys) {
10575 case 1:
10576 case 2:
10577 cfg_size = 1;
10578 break;
10579 case 3:
10580 cfg_size = 2;
10581 break;
10582 }
10583 for (idx = 0; idx < cfg_size; idx++) {
10584 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10585 link_config = bp->port.link_config[idx];
10586 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010587 case PORT_FEATURE_LINK_SPEED_AUTO:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010588 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10589 bp->link_params.req_line_speed[idx] =
10590 SPEED_AUTO_NEG;
10591 bp->port.advertising[idx] |=
10592 bp->port.supported[idx];
Mintz Yuval10bd1f22012-02-15 02:10:30 +000010593 if (bp->link_params.phy[EXT_PHY1].type ==
10594 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10595 bp->port.advertising[idx] |=
10596 (SUPPORTED_100baseT_Half |
10597 SUPPORTED_100baseT_Full);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010598 } else {
10599 /* force 10G, no AN */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010600 bp->link_params.req_line_speed[idx] =
10601 SPEED_10000;
10602 bp->port.advertising[idx] |=
10603 (ADVERTISED_10000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010604 ADVERTISED_FIBRE);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010605 continue;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010606 }
10607 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010608
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010609 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010610 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10611 bp->link_params.req_line_speed[idx] =
10612 SPEED_10;
10613 bp->port.advertising[idx] |=
10614 (ADVERTISED_10baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010615 ADVERTISED_TP);
10616 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010617 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010618 link_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010619 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010620 return;
10621 }
10622 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010623
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010624 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010625 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10626 bp->link_params.req_line_speed[idx] =
10627 SPEED_10;
10628 bp->link_params.req_duplex[idx] =
10629 DUPLEX_HALF;
10630 bp->port.advertising[idx] |=
10631 (ADVERTISED_10baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010632 ADVERTISED_TP);
10633 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010634 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010635 link_config,
10636 bp->link_params.speed_cap_mask[idx]);
10637 return;
10638 }
10639 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010640
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010641 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10642 if (bp->port.supported[idx] &
10643 SUPPORTED_100baseT_Full) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010644 bp->link_params.req_line_speed[idx] =
10645 SPEED_100;
10646 bp->port.advertising[idx] |=
10647 (ADVERTISED_100baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010648 ADVERTISED_TP);
10649 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010650 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010651 link_config,
10652 bp->link_params.speed_cap_mask[idx]);
10653 return;
10654 }
10655 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010656
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010657 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10658 if (bp->port.supported[idx] &
10659 SUPPORTED_100baseT_Half) {
10660 bp->link_params.req_line_speed[idx] =
10661 SPEED_100;
10662 bp->link_params.req_duplex[idx] =
10663 DUPLEX_HALF;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010664 bp->port.advertising[idx] |=
10665 (ADVERTISED_100baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010666 ADVERTISED_TP);
10667 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010668 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010669 link_config,
10670 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010671 return;
10672 }
10673 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010674
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010675 case PORT_FEATURE_LINK_SPEED_1G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010676 if (bp->port.supported[idx] &
10677 SUPPORTED_1000baseT_Full) {
10678 bp->link_params.req_line_speed[idx] =
10679 SPEED_1000;
10680 bp->port.advertising[idx] |=
10681 (ADVERTISED_1000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010682 ADVERTISED_TP);
10683 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010684 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010685 link_config,
10686 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010687 return;
10688 }
10689 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010690
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010691 case PORT_FEATURE_LINK_SPEED_2_5G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010692 if (bp->port.supported[idx] &
10693 SUPPORTED_2500baseX_Full) {
10694 bp->link_params.req_line_speed[idx] =
10695 SPEED_2500;
10696 bp->port.advertising[idx] |=
10697 (ADVERTISED_2500baseX_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010698 ADVERTISED_TP);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010699 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010700 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010701 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010702 bp->link_params.speed_cap_mask[idx]);
10703 return;
10704 }
10705 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010706
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010707 case PORT_FEATURE_LINK_SPEED_10G_CX4:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010708 if (bp->port.supported[idx] &
10709 SUPPORTED_10000baseT_Full) {
10710 bp->link_params.req_line_speed[idx] =
10711 SPEED_10000;
10712 bp->port.advertising[idx] |=
10713 (ADVERTISED_10000baseT_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010714 ADVERTISED_FIBRE);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010715 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010716 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010717 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010718 bp->link_params.speed_cap_mask[idx]);
10719 return;
10720 }
10721 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010722 case PORT_FEATURE_LINK_SPEED_20G:
10723 bp->link_params.req_line_speed[idx] = SPEED_20000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010724
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010725 break;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010726 default:
Merav Sicron51c1a582012-03-18 10:33:38 +000010727 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010728 link_config);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010729 bp->link_params.req_line_speed[idx] =
10730 SPEED_AUTO_NEG;
10731 bp->port.advertising[idx] =
10732 bp->port.supported[idx];
10733 break;
10734 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010735
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010736 bp->link_params.req_flow_ctrl[idx] = (link_config &
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010737 PORT_FEATURE_FLOW_CONTROL_MASK);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +000010738 if (bp->link_params.req_flow_ctrl[idx] ==
10739 BNX2X_FLOW_CTRL_AUTO) {
10740 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10741 bp->link_params.req_flow_ctrl[idx] =
10742 BNX2X_FLOW_CTRL_NONE;
10743 else
10744 bnx2x_set_requested_fc(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010745 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010746
Merav Sicron51c1a582012-03-18 10:33:38 +000010747 BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010748 bp->link_params.req_line_speed[idx],
10749 bp->link_params.req_duplex[idx],
10750 bp->link_params.req_flow_ctrl[idx],
10751 bp->port.advertising[idx]);
10752 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010753}
10754
Bill Pemberton0329aba2012-12-03 09:24:24 -050010755static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
Michael Chane665bfd2009-10-10 13:46:54 +000010756{
Yuval Mintz86564c32013-01-23 03:21:50 +000010757 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10758 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10759 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10760 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
Michael Chane665bfd2009-10-10 13:46:54 +000010761}
10762
Bill Pemberton0329aba2012-12-03 09:24:24 -050010763static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010764{
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010765 int port = BP_PORT(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +000010766 u32 config;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010767 u32 ext_phy_type, ext_phy_config, eee_mode;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010768
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010769 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010770 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010771
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010772 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010773 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010774
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010775 bp->link_params.speed_cap_mask[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010776 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000010777 dev_info.port_hw_config[port].speed_capability_mask) &
10778 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010779 bp->link_params.speed_cap_mask[1] =
10780 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000010781 dev_info.port_hw_config[port].speed_capability_mask2) &
10782 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010783 bp->port.link_config[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010784 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10785
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010786 bp->port.link_config[1] =
10787 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000010788
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010789 bp->link_params.multi_phy_config =
10790 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000010791 /* If the device is capable of WoL, set the default state according
10792 * to the HW
10793 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010794 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000010795 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10796 (config & PORT_FEATURE_WOL_ENABLED));
10797
Yuval Mintz4ba76992013-01-14 05:11:45 +000010798 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10799 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
10800 bp->flags |= NO_ISCSI_FLAG;
10801 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10802 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
10803 bp->flags |= NO_FCOE_FLAG;
10804
Merav Sicron51c1a582012-03-18 10:33:38 +000010805 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010806 bp->link_params.lane_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010807 bp->link_params.speed_cap_mask[0],
10808 bp->port.link_config[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010809
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010810 bp->link_params.switch_cfg = (bp->port.link_config[0] &
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010811 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010812 bnx2x_phy_probe(&bp->link_params);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010813 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010814
10815 bnx2x_link_settings_requested(bp);
10816
Eilon Greenstein01cd4522009-08-12 08:23:08 +000010817 /*
10818 * If connected directly, work with the internal PHY, otherwise, work
10819 * with the external PHY
10820 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010821 ext_phy_config =
10822 SHMEM_RD(bp,
10823 dev_info.port_hw_config[port].external_phy_config);
10824 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000010825 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010826 bp->mdio.prtad = bp->port.phy_addr;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000010827
10828 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
10829 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
10830 bp->mdio.prtad =
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010831 XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner5866df62011-01-30 04:15:07 +000010832
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010833 /* Configure link feature according to nvram value */
10834 eee_mode = (((SHMEM_RD(bp, dev_info.
10835 port_feature_config[port].eee_power_mode)) &
10836 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
10837 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
10838 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
10839 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
10840 EEE_MODE_ENABLE_LPI |
10841 EEE_MODE_OUTPUT_TIME;
10842 } else {
10843 bp->link_params.eee_mode = 0;
10844 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080010845}
Eilon Greenstein01cd4522009-08-12 08:23:08 +000010846
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010847void bnx2x_get_iscsi_info(struct bnx2x *bp)
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010848{
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000010849 u32 no_flags = NO_ISCSI_FLAG;
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010850 int port = BP_PORT(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010851 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010852 drv_lic_key[port].max_iscsi_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010853
Merav Sicron55c11942012-11-07 00:45:48 +000010854 if (!CNIC_SUPPORT(bp)) {
10855 bp->flags |= no_flags;
10856 return;
10857 }
10858
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010859 /* Get the number of maximum allowed iSCSI connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010860 bp->cnic_eth_dev.max_iscsi_conn =
10861 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
10862 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
10863
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010864 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
10865 bp->cnic_eth_dev.max_iscsi_conn);
10866
10867 /*
10868 * If maximum allowed number of connections is zero -
10869 * disable the feature.
10870 */
10871 if (!bp->cnic_eth_dev.max_iscsi_conn)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000010872 bp->flags |= no_flags;
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010873}
10874
Bill Pemberton0329aba2012-12-03 09:24:24 -050010875static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000010876{
10877 /* Port info */
10878 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10879 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
10880 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10881 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
10882
10883 /* Node info */
10884 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10885 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
10886 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10887 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
10888}
Dmitry Kravkov86800192013-05-27 04:08:29 +000010889
10890static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
10891{
10892 u8 count = 0;
10893
10894 if (IS_MF(bp)) {
10895 u8 fid;
10896
10897 /* iterate over absolute function ids for this path: */
10898 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
10899 if (IS_MF_SD(bp)) {
10900 u32 cfg = MF_CFG_RD(bp,
10901 func_mf_config[fid].config);
10902
10903 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
10904 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
10905 FUNC_MF_CFG_PROTOCOL_FCOE))
10906 count++;
10907 } else {
10908 u32 cfg = MF_CFG_RD(bp,
10909 func_ext_config[fid].
10910 func_cfg);
10911
10912 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
10913 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
10914 count++;
10915 }
10916 }
10917 } else { /* SF */
10918 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
10919
10920 for (port = 0; port < port_cnt; port++) {
10921 u32 lic = SHMEM_RD(bp,
10922 drv_lic_key[port].max_fcoe_conn) ^
10923 FW_ENCODE_32BIT_PATTERN;
10924 if (lic)
10925 count++;
10926 }
10927 }
10928
10929 return count;
10930}
10931
Bill Pemberton0329aba2012-12-03 09:24:24 -050010932static void bnx2x_get_fcoe_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010933{
10934 int port = BP_PORT(bp);
10935 int func = BP_ABS_FUNC(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010936 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
10937 drv_lic_key[port].max_fcoe_conn);
Dmitry Kravkov86800192013-05-27 04:08:29 +000010938 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010939
Merav Sicron55c11942012-11-07 00:45:48 +000010940 if (!CNIC_SUPPORT(bp)) {
10941 bp->flags |= NO_FCOE_FLAG;
10942 return;
10943 }
10944
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010945 /* Get the number of maximum allowed FCoE connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010946 bp->cnic_eth_dev.max_fcoe_conn =
10947 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
10948 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
10949
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000010950 /* Calculate the number of maximum allowed FCoE tasks */
10951 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
Dmitry Kravkov86800192013-05-27 04:08:29 +000010952
10953 /* check if FCoE resources must be shared between different functions */
10954 if (num_fcoe_func)
10955 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000010956
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010957 /* Read the WWN: */
10958 if (!IS_MF(bp)) {
10959 /* Port info */
10960 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
10961 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000010962 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010963 fcoe_wwn_port_name_upper);
10964 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
10965 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000010966 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010967 fcoe_wwn_port_name_lower);
10968
10969 /* Node info */
10970 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
10971 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000010972 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010973 fcoe_wwn_node_name_upper);
10974 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
10975 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000010976 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010977 fcoe_wwn_node_name_lower);
10978 } else if (!IS_MF_SD(bp)) {
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010979 /*
10980 * Read the WWN info only if the FCoE feature is enabled for
10981 * this function.
10982 */
Yuval Mintz7b5342d2012-09-11 04:34:14 +000010983 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000010984 bnx2x_get_ext_wwn_info(bp, func);
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010985
Yuval Mintz382e5132012-12-02 04:05:51 +000010986 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000010987 bnx2x_get_ext_wwn_info(bp, func);
Yuval Mintz382e5132012-12-02 04:05:51 +000010988 }
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010989
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010990 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010991
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000010992 /*
10993 * If maximum allowed number of connections is zero -
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010994 * disable the feature.
10995 */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000010996 if (!bp->cnic_eth_dev.max_fcoe_conn)
10997 bp->flags |= NO_FCOE_FLAG;
10998}
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000010999
Bill Pemberton0329aba2012-12-03 09:24:24 -050011000static void bnx2x_get_cnic_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011001{
11002 /*
11003 * iSCSI may be dynamically disabled but reading
11004 * info here we will decrease memory usage by driver
11005 * if the feature is disabled for good
11006 */
11007 bnx2x_get_iscsi_info(bp);
11008 bnx2x_get_fcoe_info(bp);
11009}
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011010
Bill Pemberton0329aba2012-12-03 09:24:24 -050011011static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +000011012{
11013 u32 val, val2;
11014 int func = BP_ABS_FUNC(bp);
11015 int port = BP_PORT(bp);
11016 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
11017 u8 *fip_mac = bp->fip_mac;
11018
11019 if (IS_MF(bp)) {
11020 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
11021 * FCoE MAC then the appropriate feature should be disabled.
11022 * In non SD mode features configuration comes from struct
11023 * func_ext_config.
11024 */
11025 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
11026 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
11027 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
11028 val2 = MF_CFG_RD(bp, func_ext_config[func].
11029 iscsi_mac_addr_upper);
11030 val = MF_CFG_RD(bp, func_ext_config[func].
11031 iscsi_mac_addr_lower);
11032 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11033 BNX2X_DEV_INFO
11034 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11035 } else {
11036 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11037 }
11038
11039 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
11040 val2 = MF_CFG_RD(bp, func_ext_config[func].
11041 fcoe_mac_addr_upper);
11042 val = MF_CFG_RD(bp, func_ext_config[func].
11043 fcoe_mac_addr_lower);
11044 bnx2x_set_mac_buf(fip_mac, val, val2);
11045 BNX2X_DEV_INFO
11046 ("Read FCoE L2 MAC: %pM\n", fip_mac);
11047 } else {
11048 bp->flags |= NO_FCOE_FLAG;
11049 }
11050
11051 bp->mf_ext_config = cfg;
11052
11053 } else { /* SD MODE */
11054 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
11055 /* use primary mac as iscsi mac */
11056 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
11057
11058 BNX2X_DEV_INFO("SD ISCSI MODE\n");
11059 BNX2X_DEV_INFO
11060 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11061 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
11062 /* use primary mac as fip mac */
11063 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
11064 BNX2X_DEV_INFO("SD FCoE MODE\n");
11065 BNX2X_DEV_INFO
11066 ("Read FIP MAC: %pM\n", fip_mac);
11067 }
11068 }
11069
Yuval Mintz82594f82013-03-11 05:17:51 +000011070 /* If this is a storage-only interface, use SAN mac as
11071 * primary MAC. Notice that for SD this is already the case,
11072 * as the SAN mac was copied from the primary MAC.
11073 */
11074 if (IS_MF_FCOE_AFEX(bp))
Merav Sicron55c11942012-11-07 00:45:48 +000011075 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
Merav Sicron55c11942012-11-07 00:45:48 +000011076 } else {
11077 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11078 iscsi_mac_upper);
11079 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11080 iscsi_mac_lower);
11081 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11082
11083 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11084 fcoe_fip_mac_upper);
11085 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11086 fcoe_fip_mac_lower);
11087 bnx2x_set_mac_buf(fip_mac, val, val2);
11088 }
11089
11090 /* Disable iSCSI OOO if MAC configuration is invalid. */
11091 if (!is_valid_ether_addr(iscsi_mac)) {
11092 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11093 memset(iscsi_mac, 0, ETH_ALEN);
11094 }
11095
11096 /* Disable FCoE if MAC configuration is invalid. */
11097 if (!is_valid_ether_addr(fip_mac)) {
11098 bp->flags |= NO_FCOE_FLAG;
11099 memset(bp->fip_mac, 0, ETH_ALEN);
11100 }
11101}
11102
Bill Pemberton0329aba2012-12-03 09:24:24 -050011103static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011104{
11105 u32 val, val2;
11106 int func = BP_ABS_FUNC(bp);
11107 int port = BP_PORT(bp);
11108
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011109 /* Zero primary MAC configuration */
11110 memset(bp->dev->dev_addr, 0, ETH_ALEN);
11111
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011112 if (BP_NOMCP(bp)) {
11113 BNX2X_ERROR("warning: random MAC workaround active\n");
Danny Kukawka7ce5d222012-02-15 06:45:40 +000011114 eth_hw_addr_random(bp->dev);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011115 } else if (IS_MF(bp)) {
11116 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
11117 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
11118 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11119 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11120 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11121
Merav Sicron55c11942012-11-07 00:45:48 +000011122 if (CNIC_SUPPORT(bp))
11123 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011124 } else {
11125 /* in SF read MACs from port configuration */
11126 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11127 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11128 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11129
Merav Sicron55c11942012-11-07 00:45:48 +000011130 if (CNIC_SUPPORT(bp))
11131 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011132 }
11133
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011134 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +000011135
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011136 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011137 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011138 "bad Ethernet MAC address configuration: %pM\n"
11139 "change it manually before bringing up the appropriate network interface\n",
Joe Perches0f9dad12011-08-14 12:16:19 +000011140 bp->dev->dev_addr);
Yuval Mintz79642112012-12-02 04:05:50 +000011141}
Merav Sicron51c1a582012-03-18 10:33:38 +000011142
Bill Pemberton0329aba2012-12-03 09:24:24 -050011143static bool bnx2x_get_dropless_info(struct bnx2x *bp)
Yuval Mintz79642112012-12-02 04:05:50 +000011144{
11145 int tmp;
11146 u32 cfg;
Merav Sicron51c1a582012-03-18 10:33:38 +000011147
Yuval Mintz79642112012-12-02 04:05:50 +000011148 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11149 /* Take function: tmp = func */
11150 tmp = BP_ABS_FUNC(bp);
11151 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11152 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11153 } else {
11154 /* Take port: tmp = port */
11155 tmp = BP_PORT(bp);
11156 cfg = SHMEM_RD(bp,
11157 dev_info.port_hw_config[tmp].generic_features);
11158 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11159 }
11160 return cfg;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011161}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011162
Bill Pemberton0329aba2012-12-03 09:24:24 -050011163static int bnx2x_get_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011164{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011165 int /*abs*/func = BP_ABS_FUNC(bp);
David S. Millerb8ee8322011-04-17 16:56:12 -070011166 int vn;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011167 u32 val = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011168 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011169
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011170 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011171
Ariel Elior6383c0b2011-07-14 08:31:57 +000011172 /*
11173 * initialize IGU parameters
11174 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011175 if (CHIP_IS_E1x(bp)) {
11176 bp->common.int_block = INT_BLOCK_HC;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011177
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011178 bp->igu_dsb_id = DEF_SB_IGU_ID;
11179 bp->igu_base_sb = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011180 } else {
11181 bp->common.int_block = INT_BLOCK_IGU;
David S. Miller8decf862011-09-22 03:23:13 -040011182
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011183 /* do not allow device reset during IGU info processing */
David S. Miller8decf862011-09-22 03:23:13 -040011184 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11185
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011186 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011187
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011188 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011189 int tout = 5000;
11190
11191 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11192
11193 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11194 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11195 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11196
11197 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11198 tout--;
Yuval Mintz0926d492013-01-23 03:21:45 +000011199 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011200 }
11201
11202 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11203 dev_err(&bp->pdev->dev,
11204 "FORCING Normal Mode failed!!!\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011205 bnx2x_release_hw_lock(bp,
11206 HW_LOCK_RESOURCE_RESET);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011207 return -EPERM;
11208 }
11209 }
11210
11211 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11212 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011213 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11214 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011215 BNX2X_DEV_INFO("IGU Normal Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011216
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011217 rc = bnx2x_get_igu_cam_info(bp);
David S. Miller8decf862011-09-22 03:23:13 -040011218 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011219 if (rc)
11220 return rc;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011221 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011222
11223 /*
11224 * set base FW non-default (fast path) status block id, this value is
11225 * used to initialize the fw_sb_id saved on the fp/queue structure to
11226 * determine the id used by the FW.
11227 */
11228 if (CHIP_IS_E1x(bp))
11229 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11230 else /*
11231 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11232 * the same queue are indicated on the same IGU SB). So we prefer
11233 * FW and IGU SBs to be the same value.
11234 */
11235 bp->base_fw_ndsb = bp->igu_base_sb;
11236
11237 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11238 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11239 bp->igu_sb_cnt, bp->base_fw_ndsb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011240
11241 /*
11242 * Initialize MF configuration
11243 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011244
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011245 bp->mf_ov = 0;
11246 bp->mf_mode = 0;
David S. Miller8decf862011-09-22 03:23:13 -040011247 vn = BP_VN(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011248
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011249 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011250 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11251 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11252 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11253
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011254 if (SHMEM2_HAS(bp, mf_cfg_addr))
11255 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11256 else
11257 bp->common.mf_cfg_base = bp->common.shmem_base +
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011258 offsetof(struct shmem_region, func_mb) +
11259 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011260 /*
11261 * get mf configuration:
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011262 * 1. Existence of MF configuration
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011263 * 2. MAC address must be legal (check only upper bytes)
11264 * for Switch-Independent mode;
11265 * OVLAN must be legal for Switch-Dependent mode
11266 * 3. SF_MODE configures specific MF mode
11267 */
11268 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11269 /* get mf configuration */
11270 val = SHMEM_RD(bp,
11271 dev_info.shared_feature_config.config);
11272 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011273
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011274 switch (val) {
11275 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11276 val = MF_CFG_RD(bp, func_mf_config[func].
11277 mac_upper);
11278 /* check for legal mac (upper bytes)*/
11279 if (val != 0xffff) {
11280 bp->mf_mode = MULTI_FUNCTION_SI;
11281 bp->mf_config[vn] = MF_CFG_RD(bp,
11282 func_mf_config[func].config);
11283 } else
Merav Sicron51c1a582012-03-18 10:33:38 +000011284 BNX2X_DEV_INFO("illegal MAC address for SI\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011285 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011286 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11287 if ((!CHIP_IS_E1x(bp)) &&
11288 (MF_CFG_RD(bp, func_mf_config[func].
11289 mac_upper) != 0xffff) &&
11290 (SHMEM2_HAS(bp,
11291 afex_driver_support))) {
11292 bp->mf_mode = MULTI_FUNCTION_AFEX;
11293 bp->mf_config[vn] = MF_CFG_RD(bp,
11294 func_mf_config[func].config);
11295 } else {
11296 BNX2X_DEV_INFO("can not configure afex mode\n");
11297 }
11298 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011299 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11300 /* get OV configuration */
11301 val = MF_CFG_RD(bp,
11302 func_mf_config[FUNC_0].e1hov_tag);
11303 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11304
11305 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11306 bp->mf_mode = MULTI_FUNCTION_SD;
11307 bp->mf_config[vn] = MF_CFG_RD(bp,
11308 func_mf_config[func].config);
11309 } else
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000011310 BNX2X_DEV_INFO("illegal OV for SD\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011311 break;
Ariel Elior3786b942013-03-11 05:17:44 +000011312 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11313 bp->mf_config[vn] = 0;
11314 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011315 default:
11316 /* Unknown configuration: reset mf_config */
11317 bp->mf_config[vn] = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +000011318 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011319 }
11320 }
11321
Eilon Greenstein2691d512009-08-12 08:22:08 +000011322 BNX2X_DEV_INFO("%s function mode\n",
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011323 IS_MF(bp) ? "multi" : "single");
Eilon Greenstein2691d512009-08-12 08:22:08 +000011324
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011325 switch (bp->mf_mode) {
11326 case MULTI_FUNCTION_SD:
11327 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11328 FUNC_MF_CFG_E1HOV_TAG_MASK;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011329 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011330 bp->mf_ov = val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011331 bp->path_has_ovlan = true;
11332
Merav Sicron51c1a582012-03-18 10:33:38 +000011333 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11334 func, bp->mf_ov, bp->mf_ov);
Eilon Greenstein2691d512009-08-12 08:22:08 +000011335 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011336 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011337 "No valid MF OV for func %d, aborting\n",
11338 func);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011339 return -EPERM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011340 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011341 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011342 case MULTI_FUNCTION_AFEX:
11343 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11344 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011345 case MULTI_FUNCTION_SI:
Merav Sicron51c1a582012-03-18 10:33:38 +000011346 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11347 func);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011348 break;
11349 default:
11350 if (vn) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011351 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011352 "VN %d is in a single function mode, aborting\n",
11353 vn);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011354 return -EPERM;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011355 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011356 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011357 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011358
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011359 /* check if other port on the path needs ovlan:
11360 * Since MF configuration is shared between ports
11361 * Possible mixed modes are only
11362 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11363 */
11364 if (CHIP_MODE_IS_4_PORT(bp) &&
11365 !bp->path_has_ovlan &&
11366 !IS_MF(bp) &&
11367 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11368 u8 other_port = !BP_PORT(bp);
11369 u8 other_func = BP_PATH(bp) + 2*other_port;
11370 val = MF_CFG_RD(bp,
11371 func_mf_config[other_func].e1hov_tag);
11372 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11373 bp->path_has_ovlan = true;
11374 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011375 }
11376
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011377 /* adjust igu_sb_cnt to MF for E1x */
11378 if (CHIP_IS_E1x(bp) && IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011379 bp->igu_sb_cnt /= E1HVN_MAX;
11380
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011381 /* port info */
11382 bnx2x_get_port_hwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011383
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011384 /* Get MAC addresses */
11385 bnx2x_get_mac_hwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011386
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011387 bnx2x_get_cnic_info(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011388
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011389 return rc;
11390}
11391
Bill Pemberton0329aba2012-12-03 09:24:24 -050011392static void bnx2x_read_fwinfo(struct bnx2x *bp)
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011393{
11394 int cnt, i, block_end, rodi;
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011395 char vpd_start[BNX2X_VPD_LEN+1];
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011396 char str_id_reg[VENDOR_ID_LEN+1];
11397 char str_id_cap[VENDOR_ID_LEN+1];
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011398 char *vpd_data;
11399 char *vpd_extended_data = NULL;
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011400 u8 len;
11401
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011402 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011403 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11404
11405 if (cnt < BNX2X_VPD_LEN)
11406 goto out_not_found;
11407
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011408 /* VPD RO tag should be first tag after identifier string, hence
11409 * we should be able to find it in first BNX2X_VPD_LEN chars
11410 */
11411 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011412 PCI_VPD_LRDT_RO_DATA);
11413 if (i < 0)
11414 goto out_not_found;
11415
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011416 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011417 pci_vpd_lrdt_size(&vpd_start[i]);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011418
11419 i += PCI_VPD_LRDT_TAG_SIZE;
11420
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011421 if (block_end > BNX2X_VPD_LEN) {
11422 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11423 if (vpd_extended_data == NULL)
11424 goto out_not_found;
11425
11426 /* read rest of vpd image into vpd_extended_data */
11427 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11428 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11429 block_end - BNX2X_VPD_LEN,
11430 vpd_extended_data + BNX2X_VPD_LEN);
11431 if (cnt < (block_end - BNX2X_VPD_LEN))
11432 goto out_not_found;
11433 vpd_data = vpd_extended_data;
11434 } else
11435 vpd_data = vpd_start;
11436
11437 /* now vpd_data holds full vpd content in both cases */
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011438
11439 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11440 PCI_VPD_RO_KEYWORD_MFR_ID);
11441 if (rodi < 0)
11442 goto out_not_found;
11443
11444 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11445
11446 if (len != VENDOR_ID_LEN)
11447 goto out_not_found;
11448
11449 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11450
11451 /* vendor specific info */
11452 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11453 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11454 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11455 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11456
11457 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11458 PCI_VPD_RO_KEYWORD_VENDOR0);
11459 if (rodi >= 0) {
11460 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11461
11462 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11463
11464 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11465 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11466 bp->fw_ver[len] = ' ';
11467 }
11468 }
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011469 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011470 return;
11471 }
11472out_not_found:
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011473 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011474 return;
11475}
11476
Bill Pemberton0329aba2012-12-03 09:24:24 -050011477static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011478{
11479 u32 flags = 0;
11480
11481 if (CHIP_REV_IS_FPGA(bp))
11482 SET_FLAGS(flags, MODE_FPGA);
11483 else if (CHIP_REV_IS_EMUL(bp))
11484 SET_FLAGS(flags, MODE_EMUL);
11485 else
11486 SET_FLAGS(flags, MODE_ASIC);
11487
11488 if (CHIP_MODE_IS_4_PORT(bp))
11489 SET_FLAGS(flags, MODE_PORT4);
11490 else
11491 SET_FLAGS(flags, MODE_PORT2);
11492
11493 if (CHIP_IS_E2(bp))
11494 SET_FLAGS(flags, MODE_E2);
11495 else if (CHIP_IS_E3(bp)) {
11496 SET_FLAGS(flags, MODE_E3);
11497 if (CHIP_REV(bp) == CHIP_REV_Ax)
11498 SET_FLAGS(flags, MODE_E3_A0);
Ariel Elior6383c0b2011-07-14 08:31:57 +000011499 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11500 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011501 }
11502
11503 if (IS_MF(bp)) {
11504 SET_FLAGS(flags, MODE_MF);
11505 switch (bp->mf_mode) {
11506 case MULTI_FUNCTION_SD:
11507 SET_FLAGS(flags, MODE_MF_SD);
11508 break;
11509 case MULTI_FUNCTION_SI:
11510 SET_FLAGS(flags, MODE_MF_SI);
11511 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011512 case MULTI_FUNCTION_AFEX:
11513 SET_FLAGS(flags, MODE_MF_AFEX);
11514 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011515 }
11516 } else
11517 SET_FLAGS(flags, MODE_SF);
11518
11519#if defined(__LITTLE_ENDIAN)
11520 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11521#else /*(__BIG_ENDIAN)*/
11522 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11523#endif
11524 INIT_MODE_FLAGS(bp) = flags;
11525}
11526
Bill Pemberton0329aba2012-12-03 09:24:24 -050011527static int bnx2x_init_bp(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011528{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011529 int func;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011530 int rc;
11531
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011532 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -070011533 mutex_init(&bp->fw_mb_mutex);
David S. Millerbb7e95c2010-07-27 21:01:35 -070011534 spin_lock_init(&bp->stats_lock);
Dmitry Kravkov507393e2013-08-13 02:24:59 +030011535 sema_init(&bp->stats_sema, 1);
Merav Sicron55c11942012-11-07 00:45:48 +000011536
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011537 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Ariel Elior7be08a72011-07-14 08:31:19 +000011538 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000011539 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
Ariel Elior1ab44342013-01-01 05:22:23 +000011540 if (IS_PF(bp)) {
11541 rc = bnx2x_get_hwinfo(bp);
11542 if (rc)
11543 return rc;
11544 } else {
Ariel Eliore09b74d2013-05-27 04:08:26 +000011545 eth_zero_addr(bp->dev->dev_addr);
Ariel Elior1ab44342013-01-01 05:22:23 +000011546 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011547
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011548 bnx2x_set_modes_bitmap(bp);
11549
11550 rc = bnx2x_alloc_mem_bp(bp);
11551 if (rc)
11552 return rc;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011553
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011554 bnx2x_read_fwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011555
11556 func = BP_FUNC(bp);
11557
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011558 /* need to reset chip if undi was active */
Ariel Elior1ab44342013-01-01 05:22:23 +000011559 if (IS_PF(bp) && !BP_NOMCP(bp)) {
Yuval Mintz452427b2012-03-26 20:47:07 +000011560 /* init fw_seq */
11561 bp->fw_seq =
11562 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11563 DRV_MSG_SEQ_NUMBER_MASK;
11564 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11565
11566 bnx2x_prev_unload(bp);
11567 }
11568
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011569 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000011570 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011571
11572 if (BP_NOMCP(bp) && (func == 0))
Merav Sicron51c1a582012-03-18 10:33:38 +000011573 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011574
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011575 bp->disable_tpa = disable_tpa;
Barak Witkowskia3348722012-04-23 03:04:46 +000011576 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011577
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011578 /* Set TPA flags */
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011579 if (bp->disable_tpa) {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011580 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011581 bp->dev->features &= ~NETIF_F_LRO;
11582 } else {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011583 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011584 bp->dev->features |= NETIF_F_LRO;
11585 }
11586
Eilon Greensteina18f5122009-08-12 08:23:26 +000011587 if (CHIP_IS_E1(bp))
11588 bp->dropless_fc = 0;
11589 else
Yuval Mintz79642112012-12-02 04:05:50 +000011590 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
Eilon Greensteina18f5122009-08-12 08:23:26 +000011591
Eilon Greenstein8d5726c2009-02-12 08:37:19 +000011592 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011593
Barak Witkowskia3348722012-04-23 03:04:46 +000011594 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
Ariel Elior1ab44342013-01-01 05:22:23 +000011595 if (IS_VF(bp))
11596 bp->rx_ring_size = MAX_RX_AVAIL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011597
Eilon Greenstein7d323bf2009-11-09 06:09:35 +000011598 /* make sure that the numbers are in the right granularity */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011599 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11600 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011601
Michal Schmidtfc543632012-02-14 09:05:46 +000011602 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011603
11604 init_timer(&bp->timer);
11605 bp->timer.expires = jiffies + bp->current_interval;
11606 bp->timer.data = (unsigned long) bp;
11607 bp->timer.function = bnx2x_timer;
11608
Barak Witkowski0370cf92012-12-02 04:05:55 +000011609 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11610 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11611 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11612 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11613 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11614 bnx2x_dcbx_init_params(bp);
11615 } else {
11616 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11617 }
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000011618
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011619 if (CHIP_IS_E1x(bp))
11620 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11621 else
11622 bp->cnic_base_cl_id = FP_SB_MAX_E2;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011623
Ariel Elior6383c0b2011-07-14 08:31:57 +000011624 /* multiple tx priority */
Ariel Elior1ab44342013-01-01 05:22:23 +000011625 if (IS_VF(bp))
11626 bp->max_cos = 1;
11627 else if (CHIP_IS_E1x(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011628 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
Ariel Elior1ab44342013-01-01 05:22:23 +000011629 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011630 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
Ariel Elior1ab44342013-01-01 05:22:23 +000011631 else if (CHIP_IS_E3B0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011632 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
Ariel Elior1ab44342013-01-01 05:22:23 +000011633 else
11634 BNX2X_ERR("unknown chip %x revision %x\n",
11635 CHIP_NUM(bp), CHIP_REV(bp));
11636 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
Ariel Elior6383c0b2011-07-14 08:31:57 +000011637
Merav Sicron55c11942012-11-07 00:45:48 +000011638 /* We need at least one default status block for slow-path events,
11639 * second status block for the L2 queue, and a third status block for
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011640 * CNIC if supported.
Merav Sicron55c11942012-11-07 00:45:48 +000011641 */
11642 if (CNIC_SUPPORT(bp))
11643 bp->min_msix_vec_cnt = 3;
11644 else
11645 bp->min_msix_vec_cnt = 2;
11646 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11647
Michal Schmidt5bb680d2013-07-01 17:23:06 +020011648 bp->dump_preset_idx = 1;
11649
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011650 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011651}
11652
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000011653/****************************************************************************
11654* General service functions
11655****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011656
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011657/*
11658 * net_device service functions
11659 */
11660
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011661/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011662static int bnx2x_open(struct net_device *dev)
11663{
11664 struct bnx2x *bp = netdev_priv(dev);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011665 bool global = false;
11666 int other_engine = BP_PATH(bp) ? 0 : 1;
Ariel Elior889b9af2012-01-26 06:01:51 +000011667 bool other_load_status, load_status;
Ariel Elior8395be52013-01-01 05:22:44 +000011668 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011669
Mintz Yuval1355b702012-02-15 02:10:22 +000011670 bp->stats_init = true;
11671
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000011672 netif_carrier_off(dev);
11673
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011674 bnx2x_set_power_state(bp, PCI_D0);
11675
Ariel Eliorad5afc82013-01-01 05:22:26 +000011676 /* If parity had happen during the unload, then attentions
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011677 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11678 * want the first function loaded on the current engine to
11679 * complete the recovery.
Ariel Eliorad5afc82013-01-01 05:22:26 +000011680 * Parity recovery is only relevant for PF driver.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011681 */
Ariel Eliorad5afc82013-01-01 05:22:26 +000011682 if (IS_PF(bp)) {
11683 other_load_status = bnx2x_get_load_status(bp, other_engine);
11684 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11685 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11686 bnx2x_chk_parity_attn(bp, &global, true)) {
11687 do {
11688 /* If there are attentions and they are in a
11689 * global blocks, set the GLOBAL_RESET bit
11690 * regardless whether it will be this function
11691 * that will complete the recovery or not.
11692 */
11693 if (global)
11694 bnx2x_set_reset_global(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011695
Ariel Eliorad5afc82013-01-01 05:22:26 +000011696 /* Only the first function on the current
11697 * engine should try to recover in open. In case
11698 * of attentions in global blocks only the first
11699 * in the chip should try to recover.
11700 */
11701 if ((!load_status &&
11702 (!global || !other_load_status)) &&
11703 bnx2x_trylock_leader_lock(bp) &&
11704 !bnx2x_leader_reset(bp)) {
11705 netdev_info(bp->dev,
11706 "Recovered in open\n");
11707 break;
11708 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011709
Ariel Eliorad5afc82013-01-01 05:22:26 +000011710 /* recovery has failed... */
11711 bnx2x_set_power_state(bp, PCI_D3hot);
11712 bp->recovery_state = BNX2X_RECOVERY_FAILED;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011713
Ariel Eliorad5afc82013-01-01 05:22:26 +000011714 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11715 "If you still see this message after a few retries then power cycle is required.\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011716
Ariel Eliorad5afc82013-01-01 05:22:26 +000011717 return -EAGAIN;
11718 } while (0);
11719 }
11720 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011721
11722 bp->recovery_state = BNX2X_RECOVERY_DONE;
Ariel Elior8395be52013-01-01 05:22:44 +000011723 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11724 if (rc)
11725 return rc;
11726 return bnx2x_open_epilog(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011727}
11728
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011729/* called with rtnl_lock */
Michal Schmidt56ad3152012-02-16 02:38:48 +000011730static int bnx2x_close(struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011731{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011732 struct bnx2x *bp = netdev_priv(dev);
11733
11734 /* Unload the driver, release IRQs */
Yuval Mintz5d07d862012-09-13 02:56:21 +000011735 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011736
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011737 return 0;
11738}
11739
Eric Dumazet1191cb82012-04-27 21:39:21 +000011740static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11741 struct bnx2x_mcast_ramrod_params *p)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011742{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011743 int mc_count = netdev_mc_count(bp->dev);
11744 struct bnx2x_mcast_list_elem *mc_mac =
11745 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011746 struct netdev_hw_addr *ha;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011747
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011748 if (!mc_mac)
11749 return -ENOMEM;
11750
11751 INIT_LIST_HEAD(&p->mcast_list);
11752
11753 netdev_for_each_mc_addr(ha, bp->dev) {
11754 mc_mac->mac = bnx2x_mc_addr(ha);
11755 list_add_tail(&mc_mac->link, &p->mcast_list);
11756 mc_mac++;
11757 }
11758
11759 p->mcast_list_len = mc_count;
11760
11761 return 0;
11762}
11763
Eric Dumazet1191cb82012-04-27 21:39:21 +000011764static void bnx2x_free_mcast_macs_list(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011765 struct bnx2x_mcast_ramrod_params *p)
11766{
11767 struct bnx2x_mcast_list_elem *mc_mac =
11768 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11769 link);
11770
11771 WARN_ON(!mc_mac);
11772 kfree(mc_mac);
11773}
11774
11775/**
11776 * bnx2x_set_uc_list - configure a new unicast MACs list.
11777 *
11778 * @bp: driver handle
11779 *
11780 * We will use zero (0) as a MAC type for these MACs.
11781 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000011782static int bnx2x_set_uc_list(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011783{
11784 int rc;
11785 struct net_device *dev = bp->dev;
11786 struct netdev_hw_addr *ha;
Barak Witkowski15192a82012-06-19 07:48:28 +000011787 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011788 unsigned long ramrod_flags = 0;
11789
11790 /* First schedule a cleanup up of old configuration */
11791 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
11792 if (rc < 0) {
11793 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
11794 return rc;
11795 }
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011796
11797 netdev_for_each_uc_addr(ha, dev) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011798 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
11799 BNX2X_UC_LIST_MAC, &ramrod_flags);
Yuval Mintz7b5342d2012-09-11 04:34:14 +000011800 if (rc == -EEXIST) {
11801 DP(BNX2X_MSG_SP,
11802 "Failed to schedule ADD operations: %d\n", rc);
11803 /* do not treat adding same MAC as error */
11804 rc = 0;
11805
11806 } else if (rc < 0) {
11807
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011808 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
11809 rc);
11810 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011811 }
11812 }
11813
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011814 /* Execute the pending commands */
11815 __set_bit(RAMROD_CONT, &ramrod_flags);
11816 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
11817 BNX2X_UC_LIST_MAC, &ramrod_flags);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011818}
11819
Eric Dumazet1191cb82012-04-27 21:39:21 +000011820static int bnx2x_set_mc_list(struct bnx2x *bp)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011821{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011822 struct net_device *dev = bp->dev;
Yuval Mintz3b603062012-03-18 10:33:39 +000011823 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011824 int rc = 0;
11825
11826 rparam.mcast_obj = &bp->mcast_obj;
11827
11828 /* first, clear all configured multicast MACs */
11829 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
11830 if (rc < 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +000011831 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011832 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011833 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011834
11835 /* then, configure a new MACs list */
11836 if (netdev_mc_count(dev)) {
11837 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
11838 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +000011839 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
11840 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011841 return rc;
11842 }
11843
11844 /* Now add the new MACs */
11845 rc = bnx2x_config_mcast(bp, &rparam,
11846 BNX2X_MCAST_CMD_ADD);
11847 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +000011848 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
11849 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011850
11851 bnx2x_free_mcast_macs_list(&rparam);
11852 }
11853
11854 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011855}
11856
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011857/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000011858void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011859{
11860 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011861
11862 if (bp->state != BNX2X_STATE_OPEN) {
11863 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
11864 return;
Yuval Mintz8b09be52013-08-01 17:30:59 +030011865 } else {
11866 /* Schedule an SP task to handle rest of change */
11867 DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
11868 smp_mb__before_clear_bit();
11869 set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
11870 smp_mb__after_clear_bit();
11871 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011872 }
Yuval Mintz8b09be52013-08-01 17:30:59 +030011873}
11874
11875void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
11876{
11877 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011878
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011879 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011880
Yuval Mintz8b09be52013-08-01 17:30:59 +030011881 netif_addr_lock_bh(bp->dev);
11882
11883 if (bp->dev->flags & IFF_PROMISC) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011884 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030011885 } else if ((bp->dev->flags & IFF_ALLMULTI) ||
11886 ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
11887 CHIP_IS_E1(bp))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011888 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Yuval Mintz8b09be52013-08-01 17:30:59 +030011889 } else {
Ariel Elior381ac162013-01-01 05:22:29 +000011890 if (IS_PF(bp)) {
11891 /* some multicasts */
11892 if (bnx2x_set_mc_list(bp) < 0)
11893 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011894
Yuval Mintz8b09be52013-08-01 17:30:59 +030011895 /* release bh lock, as bnx2x_set_uc_list might sleep */
11896 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000011897 if (bnx2x_set_uc_list(bp) < 0)
11898 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030011899 netif_addr_lock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000011900 } else {
11901 /* configuring mcast to a vf involves sleeping (when we
Yuval Mintz8b09be52013-08-01 17:30:59 +030011902 * wait for the pf's response).
Ariel Elior381ac162013-01-01 05:22:29 +000011903 */
11904 smp_mb__before_clear_bit();
11905 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
11906 &bp->sp_rtnl_state);
11907 smp_mb__after_clear_bit();
11908 schedule_delayed_work(&bp->sp_rtnl_task, 0);
11909 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011910 }
11911
11912 bp->rx_mode = rx_mode;
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011913 /* handle ISCSI SD mode */
11914 if (IS_MF_ISCSI_SD(bp))
11915 bp->rx_mode = BNX2X_RX_MODE_NONE;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011916
11917 /* Schedule the rx_mode command */
11918 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
11919 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
Yuval Mintz8b09be52013-08-01 17:30:59 +030011920 netif_addr_unlock_bh(bp->dev);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011921 return;
11922 }
11923
Ariel Elior381ac162013-01-01 05:22:29 +000011924 if (IS_PF(bp)) {
11925 bnx2x_set_storm_rx_mode(bp);
Yuval Mintz8b09be52013-08-01 17:30:59 +030011926 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000011927 } else {
Yuval Mintz8b09be52013-08-01 17:30:59 +030011928 /* VF will need to request the PF to make this change, and so
11929 * the VF needs to release the bottom-half lock prior to the
11930 * request (as it will likely require sleep on the VF side)
Ariel Elior381ac162013-01-01 05:22:29 +000011931 */
Yuval Mintz8b09be52013-08-01 17:30:59 +030011932 netif_addr_unlock_bh(bp->dev);
11933 bnx2x_vfpf_storm_rx_mode(bp);
Ariel Elior381ac162013-01-01 05:22:29 +000011934 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011935}
11936
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011937/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011938static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
11939 int devad, u16 addr)
11940{
11941 struct bnx2x *bp = netdev_priv(netdev);
11942 u16 value;
11943 int rc;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011944
11945 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
11946 prtad, devad, addr);
11947
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011948 /* The HW expects different devad if CL22 is used */
11949 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11950
11951 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011952 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011953 bnx2x_release_phy_lock(bp);
11954 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
11955
11956 if (!rc)
11957 rc = value;
11958 return rc;
11959}
11960
11961/* called with rtnl_lock */
11962static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
11963 u16 addr, u16 value)
11964{
11965 struct bnx2x *bp = netdev_priv(netdev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011966 int rc;
11967
Merav Sicron51c1a582012-03-18 10:33:38 +000011968 DP(NETIF_MSG_LINK,
11969 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
11970 prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011971
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011972 /* The HW expects different devad if CL22 is used */
11973 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
11974
11975 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011976 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011977 bnx2x_release_phy_lock(bp);
11978 return rc;
11979}
11980
11981/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011982static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
11983{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011984 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011985 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011986
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011987 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
11988 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011989
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011990 if (!netif_running(dev))
11991 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011992
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011993 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011994}
11995
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000011996#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011997static void poll_bnx2x(struct net_device *dev)
11998{
11999 struct bnx2x *bp = netdev_priv(dev);
Merav Sicron14a15d62012-08-27 03:26:20 +000012000 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012001
Merav Sicron14a15d62012-08-27 03:26:20 +000012002 for_each_eth_queue(bp, i) {
12003 struct bnx2x_fastpath *fp = &bp->fp[i];
12004 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
12005 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012006}
12007#endif
12008
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012009static int bnx2x_validate_addr(struct net_device *dev)
12010{
12011 struct bnx2x *bp = netdev_priv(dev);
12012
Ariel Eliore09b74d2013-05-27 04:08:26 +000012013 /* query the bulletin board for mac address configured by the PF */
12014 if (IS_VF(bp))
12015 bnx2x_sample_bulletin(bp);
12016
Merav Sicron51c1a582012-03-18 10:33:38 +000012017 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
12018 BNX2X_ERR("Non-valid Ethernet address\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012019 return -EADDRNOTAVAIL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012020 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012021 return 0;
12022}
12023
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012024static const struct net_device_ops bnx2x_netdev_ops = {
12025 .ndo_open = bnx2x_open,
12026 .ndo_stop = bnx2x_close,
12027 .ndo_start_xmit = bnx2x_start_xmit,
Vladislav Zolotarov8307fa32010-12-13 05:44:09 +000012028 .ndo_select_queue = bnx2x_select_queue,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012029 .ndo_set_rx_mode = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012030 .ndo_set_mac_address = bnx2x_change_mac_addr,
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012031 .ndo_validate_addr = bnx2x_validate_addr,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012032 .ndo_do_ioctl = bnx2x_ioctl,
12033 .ndo_change_mtu = bnx2x_change_mtu,
Michał Mirosław66371c42011-04-12 09:38:23 +000012034 .ndo_fix_features = bnx2x_fix_features,
12035 .ndo_set_features = bnx2x_set_features,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012036 .ndo_tx_timeout = bnx2x_tx_timeout,
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000012037#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012038 .ndo_poll_controller = poll_bnx2x,
12039#endif
Ariel Elior6383c0b2011-07-14 08:31:57 +000012040 .ndo_setup_tc = bnx2x_setup_tc,
Ariel Elior64112802013-01-07 00:50:23 +000012041#ifdef CONFIG_BNX2X_SRIOV
Ariel Eliorabc5a022013-01-01 05:22:43 +000012042 .ndo_set_vf_mac = bnx2x_set_vf_mac,
Yuval Mintz3cdeec22013-06-02 00:06:19 +000012043 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
Ariel Elior3ec9f9c2013-03-11 05:17:45 +000012044 .ndo_get_vf_config = bnx2x_get_vf_config,
Ariel Elior64112802013-01-07 00:50:23 +000012045#endif
Merav Sicron55c11942012-11-07 00:45:48 +000012046#ifdef NETDEV_FCOE_WWNN
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000012047 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
12048#endif
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012049
Cong Wange0d10952013-08-01 11:10:25 +080012050#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +030012051 .ndo_busy_poll = bnx2x_low_latency_recv,
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012052#endif
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012053};
12054
Eric Dumazet1191cb82012-04-27 21:39:21 +000012055static int bnx2x_set_coherency_mask(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012056{
12057 struct device *dev = &bp->pdev->dev;
12058
12059 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
12060 bp->flags |= USING_DAC_FLAG;
12061 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012062 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012063 return -EIO;
12064 }
12065 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
12066 dev_err(dev, "System does not support DMA, aborting\n");
12067 return -EIO;
12068 }
12069
12070 return 0;
12071}
12072
Ariel Elior1ab44342013-01-01 05:22:23 +000012073static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12074 struct net_device *dev, unsigned long board_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012075{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012076 int rc;
Ariel Eliorc22610d02012-01-26 06:01:47 +000012077 u32 pci_cfg_dword;
Ariel Elior65087cf2012-01-23 07:31:55 +000012078 bool chip_is_e1x = (board_type == BCM57710 ||
12079 board_type == BCM57711 ||
12080 board_type == BCM57711E);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012081
12082 SET_NETDEV_DEV(dev, &pdev->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012083
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012084 bp->dev = dev;
12085 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012086
12087 rc = pci_enable_device(pdev);
12088 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012089 dev_err(&bp->pdev->dev,
12090 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012091 goto err_out;
12092 }
12093
12094 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012095 dev_err(&bp->pdev->dev,
12096 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012097 rc = -ENODEV;
12098 goto err_out_disable;
12099 }
12100
Ariel Elior1ab44342013-01-01 05:22:23 +000012101 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
12102 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012103 rc = -ENODEV;
12104 goto err_out_disable;
12105 }
12106
Yaniv Rosner092a5fc2012-12-02 23:56:49 +000012107 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
12108 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
12109 PCICFG_REVESION_ID_ERROR_VAL) {
12110 pr_err("PCI device error, probably due to fan failure, aborting\n");
12111 rc = -ENODEV;
12112 goto err_out_disable;
12113 }
12114
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012115 if (atomic_read(&pdev->enable_cnt) == 1) {
12116 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
12117 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012118 dev_err(&bp->pdev->dev,
12119 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012120 goto err_out_disable;
12121 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012122
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012123 pci_set_master(pdev);
12124 pci_save_state(pdev);
12125 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012126
Ariel Elior1ab44342013-01-01 05:22:23 +000012127 if (IS_PF(bp)) {
Yijing Wangb8a39dd2013-06-18 16:05:39 +080012128 bp->pm_cap = pdev->pm_cap;
Ariel Elior1ab44342013-01-01 05:22:23 +000012129 if (bp->pm_cap == 0) {
12130 dev_err(&bp->pdev->dev,
12131 "Cannot find power management capability, aborting\n");
12132 rc = -EIO;
12133 goto err_out_release;
12134 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012135 }
12136
Jon Mason77c98e62011-06-27 07:45:12 +000012137 if (!pci_is_pcie(pdev)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012138 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012139 rc = -EIO;
12140 goto err_out_release;
12141 }
12142
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012143 rc = bnx2x_set_coherency_mask(bp);
12144 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012145 goto err_out_release;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012146
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012147 dev->mem_start = pci_resource_start(pdev, 0);
12148 dev->base_addr = dev->mem_start;
12149 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012150
12151 dev->irq = pdev->irq;
12152
Arjan van de Ven275f1652008-10-20 21:42:39 -070012153 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012154 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012155 dev_err(&bp->pdev->dev,
12156 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012157 rc = -ENOMEM;
12158 goto err_out_release;
12159 }
12160
Ariel Eliorc22610d02012-01-26 06:01:47 +000012161 /* In E1/E1H use pci device function given by kernel.
12162 * In E2/E3 read physical function from ME register since these chips
12163 * support Physical Device Assignment where kernel BDF maybe arbitrary
12164 * (depending on hypervisor).
12165 */
Yuval Mintz2de67432013-01-23 03:21:43 +000012166 if (chip_is_e1x) {
Ariel Eliorc22610d02012-01-26 06:01:47 +000012167 bp->pf_num = PCI_FUNC(pdev->devfn);
Yuval Mintz2de67432013-01-23 03:21:43 +000012168 } else {
12169 /* chip is E2/3*/
Ariel Eliorc22610d02012-01-26 06:01:47 +000012170 pci_read_config_dword(bp->pdev,
12171 PCICFG_ME_REGISTER, &pci_cfg_dword);
12172 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
Yuval Mintz2de67432013-01-23 03:21:43 +000012173 ME_REG_ABS_PF_NUM_SHIFT);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012174 }
Merav Sicron51c1a582012-03-18 10:33:38 +000012175 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012176
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012177 /* clean indirect addresses */
12178 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12179 PCICFG_VENDOR_ID_OFFSET);
David S. Miller8decf862011-09-22 03:23:13 -040012180 /*
12181 * Clean the following indirect addresses for all functions since it
David S. Miller823dcd22011-08-20 10:39:12 -070012182 * is not used by the driver.
12183 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012184 if (IS_PF(bp)) {
12185 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12186 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12187 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12188 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
David S. Miller8decf862011-09-22 03:23:13 -040012189
Ariel Elior1ab44342013-01-01 05:22:23 +000012190 if (chip_is_e1x) {
12191 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12192 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12193 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12194 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12195 }
12196
12197 /* Enable internal target-read (in case we are probed after PF
12198 * FLR). Must be done prior to any BAR read access. Only for
12199 * 57712 and up
12200 */
12201 if (!chip_is_e1x)
12202 REG_WR(bp,
12203 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
David S. Miller8decf862011-09-22 03:23:13 -040012204 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012205
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012206 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012207
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012208 dev->netdev_ops = &bnx2x_netdev_ops;
Ariel Elior005a07ba2013-03-11 05:17:42 +000012209 bnx2x_set_ethtool_ops(bp, dev);
Michał Mirosław66371c42011-04-12 09:38:23 +000012210
Jiri Pirko01789342011-08-16 06:29:00 +000012211 dev->priv_flags |= IFF_UNICAST_FLT;
12212
Michał Mirosław66371c42011-04-12 09:38:23 +000012213 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000012214 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12215 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +000012216 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012217 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkov65bc0cf2013-04-28 08:16:02 +000012218 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012219 dev->hw_enc_features =
12220 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12221 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
Dmitry Kravkov65bc0cf2013-04-28 08:16:02 +000012222 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012223 }
Michał Mirosław66371c42011-04-12 09:38:23 +000012224
12225 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12226 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12227
Patrick McHardyf6469682013-04-19 02:04:27 +000012228 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012229 if (bp->flags & USING_DAC_FLAG)
12230 dev->features |= NETIF_F_HIGHDMA;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012231
Mahesh Bandewar538dd2e2011-05-13 15:08:49 +000012232 /* Add Loopback capability to the device */
12233 dev->hw_features |= NETIF_F_LOOPBACK;
12234
Shmulik Ravid98507672011-02-28 12:19:55 -080012235#ifdef BCM_DCBNL
Shmulik Ravid785b9b12010-12-30 06:27:03 +000012236 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12237#endif
12238
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012239 /* get_port_hwinfo() will set prtad and mmds properly */
12240 bp->mdio.prtad = MDIO_PRTAD_NONE;
12241 bp->mdio.mmds = 0;
12242 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12243 bp->mdio.dev = dev;
12244 bp->mdio.mdio_read = bnx2x_mdio_read;
12245 bp->mdio.mdio_write = bnx2x_mdio_write;
12246
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012247 return 0;
12248
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012249err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012250 if (atomic_read(&pdev->enable_cnt) == 1)
12251 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012252
12253err_out_disable:
12254 pci_disable_device(pdev);
12255 pci_set_drvdata(pdev, NULL);
12256
12257err_out:
12258 return rc;
12259}
12260
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000012261static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
12262 enum bnx2x_pci_bus_speed *speed)
Eliezer Tamir25047952008-02-28 11:50:16 -080012263{
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000012264 u32 link_speed, val = 0;
Eliezer Tamir25047952008-02-28 11:50:16 -080012265
Ariel Elior1ab44342013-01-01 05:22:23 +000012266 pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012267 *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
12268
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000012269 link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
12270
12271 switch (link_speed) {
12272 case 3:
12273 *speed = BNX2X_PCI_LINK_SPEED_8000;
12274 break;
12275 case 2:
12276 *speed = BNX2X_PCI_LINK_SPEED_5000;
12277 break;
12278 default:
12279 *speed = BNX2X_PCI_LINK_SPEED_2500;
12280 }
Eliezer Tamir25047952008-02-28 11:50:16 -080012281}
12282
Dmitry Kravkov6891dd22010-08-03 21:49:40 +000012283static int bnx2x_check_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012284{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012285 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012286 struct bnx2x_fw_file_hdr *fw_hdr;
12287 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012288 u32 offset, len, num_ops;
Yuval Mintz86564c32013-01-23 03:21:50 +000012289 __be16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012290 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012291 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012292
Merav Sicron51c1a582012-03-18 10:33:38 +000012293 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12294 BNX2X_ERR("Wrong FW size\n");
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012295 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012296 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012297
12298 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12299 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12300
12301 /* Make sure none of the offsets and sizes make us read beyond
12302 * the end of the firmware data */
12303 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12304 offset = be32_to_cpu(sections[i].offset);
12305 len = be32_to_cpu(sections[i].len);
12306 if (offset + len > firmware->size) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012307 BNX2X_ERR("Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012308 return -EINVAL;
12309 }
12310 }
12311
12312 /* Likewise for the init_ops offsets */
12313 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
Yuval Mintz86564c32013-01-23 03:21:50 +000012314 ops_offsets = (__force __be16 *)(firmware->data + offset);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012315 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12316
12317 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12318 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012319 BNX2X_ERR("Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012320 return -EINVAL;
12321 }
12322 }
12323
12324 /* Check FW version */
12325 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12326 fw_ver = firmware->data + offset;
12327 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12328 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12329 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12330 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012331 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12332 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12333 BCM_5710_FW_MAJOR_VERSION,
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012334 BCM_5710_FW_MINOR_VERSION,
12335 BCM_5710_FW_REVISION_VERSION,
12336 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012337 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012338 }
12339
12340 return 0;
12341}
12342
Eric Dumazet1191cb82012-04-27 21:39:21 +000012343static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012344{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012345 const __be32 *source = (const __be32 *)_source;
12346 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012347 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012348
12349 for (i = 0; i < n/4; i++)
12350 target[i] = be32_to_cpu(source[i]);
12351}
12352
12353/*
12354 Ops array is stored in the following format:
12355 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12356 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012357static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012358{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012359 const __be32 *source = (const __be32 *)_source;
12360 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012361 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012362
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012363 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012364 tmp = be32_to_cpu(source[j]);
12365 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012366 target[i].offset = tmp & 0xffffff;
12367 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012368 }
12369}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012370
Ben Hutchings1aa8b472012-07-10 10:56:59 +000012371/* IRO array is stored in the following format:
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012372 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12373 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012374static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012375{
12376 const __be32 *source = (const __be32 *)_source;
12377 struct iro *target = (struct iro *)_target;
12378 u32 i, j, tmp;
12379
12380 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12381 target[i].base = be32_to_cpu(source[j]);
12382 j++;
12383 tmp = be32_to_cpu(source[j]);
12384 target[i].m1 = (tmp >> 16) & 0xffff;
12385 target[i].m2 = tmp & 0xffff;
12386 j++;
12387 tmp = be32_to_cpu(source[j]);
12388 target[i].m3 = (tmp >> 16) & 0xffff;
12389 target[i].size = tmp & 0xffff;
12390 j++;
12391 }
12392}
12393
Eric Dumazet1191cb82012-04-27 21:39:21 +000012394static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012395{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012396 const __be16 *source = (const __be16 *)_source;
12397 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012398 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012399
12400 for (i = 0; i < n/2; i++)
12401 target[i] = be16_to_cpu(source[i]);
12402}
12403
Joe Perches7995c642010-02-17 15:01:52 +000012404#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12405do { \
12406 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12407 bp->arr = kmalloc(len, GFP_KERNEL); \
Joe Perchese404dec2012-01-29 12:56:23 +000012408 if (!bp->arr) \
Joe Perches7995c642010-02-17 15:01:52 +000012409 goto lbl; \
Joe Perches7995c642010-02-17 15:01:52 +000012410 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12411 (u8 *)bp->arr, len); \
12412} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012413
Yuval Mintz3b603062012-03-18 10:33:39 +000012414static int bnx2x_init_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012415{
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012416 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012417 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +000012418 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012419
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012420 if (bp->firmware)
12421 return 0;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012422
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012423 if (CHIP_IS_E1(bp))
12424 fw_file_name = FW_FILE_NAME_E1;
12425 else if (CHIP_IS_E1H(bp))
12426 fw_file_name = FW_FILE_NAME_E1H;
12427 else if (!CHIP_IS_E1x(bp))
12428 fw_file_name = FW_FILE_NAME_E2;
12429 else {
12430 BNX2X_ERR("Unsupported chip revision\n");
12431 return -EINVAL;
12432 }
12433 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012434
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012435 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12436 if (rc) {
12437 BNX2X_ERR("Can't load firmware file %s\n",
12438 fw_file_name);
12439 goto request_firmware_exit;
12440 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012441
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012442 rc = bnx2x_check_firmware(bp);
12443 if (rc) {
12444 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12445 goto request_firmware_exit;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012446 }
12447
12448 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12449
12450 /* Initialize the pointers to the init arrays */
12451 /* Blob */
12452 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12453
12454 /* Opcodes */
12455 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12456
12457 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012458 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12459 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012460
12461 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +000012462 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12463 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12464 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12465 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12466 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12467 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12468 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12469 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12470 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12471 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12472 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12473 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12474 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12475 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12476 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12477 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012478 /* IRO */
12479 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012480
12481 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012482
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012483iro_alloc_err:
12484 kfree(bp->init_ops_offsets);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012485init_offsets_alloc_err:
12486 kfree(bp->init_ops);
12487init_ops_alloc_err:
12488 kfree(bp->init_data);
12489request_firmware_exit:
12490 release_firmware(bp->firmware);
Michal Schmidt127d0a12012-03-15 14:08:28 +000012491 bp->firmware = NULL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012492
12493 return rc;
12494}
12495
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012496static void bnx2x_release_firmware(struct bnx2x *bp)
12497{
12498 kfree(bp->init_ops_offsets);
12499 kfree(bp->init_ops);
12500 kfree(bp->init_data);
12501 release_firmware(bp->firmware);
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +000012502 bp->firmware = NULL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012503}
12504
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012505static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12506 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12507 .init_hw_cmn = bnx2x_init_hw_common,
12508 .init_hw_port = bnx2x_init_hw_port,
12509 .init_hw_func = bnx2x_init_hw_func,
12510
12511 .reset_hw_cmn = bnx2x_reset_common,
12512 .reset_hw_port = bnx2x_reset_port,
12513 .reset_hw_func = bnx2x_reset_func,
12514
12515 .gunzip_init = bnx2x_gunzip_init,
12516 .gunzip_end = bnx2x_gunzip_end,
12517
12518 .init_fw = bnx2x_init_firmware,
12519 .release_fw = bnx2x_release_firmware,
12520};
12521
12522void bnx2x__init_func_obj(struct bnx2x *bp)
12523{
12524 /* Prepare DMAE related driver resources */
12525 bnx2x_setup_dmae(bp);
12526
12527 bnx2x_init_func_obj(bp, &bp->func_obj,
12528 bnx2x_sp(bp, func_rdata),
12529 bnx2x_sp_mapping(bp, func_rdata),
Barak Witkowskia3348722012-04-23 03:04:46 +000012530 bnx2x_sp(bp, func_afex_rdata),
12531 bnx2x_sp_mapping(bp, func_afex_rdata),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012532 &bnx2x_func_sp_drv);
12533}
12534
12535/* must be called after sriov-enable */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012536static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012537{
Merav Sicron37ae41a2012-06-19 07:48:27 +000012538 int cid_count = BNX2X_L2_MAX_CID(bp);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012539
Ariel Elior290ca2b2013-01-01 05:22:31 +000012540 if (IS_SRIOV(bp))
12541 cid_count += BNX2X_VF_CIDS;
12542
Merav Sicron55c11942012-11-07 00:45:48 +000012543 if (CNIC_SUPPORT(bp))
12544 cid_count += CNIC_CID_MAX;
Ariel Elior290ca2b2013-01-01 05:22:31 +000012545
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012546 return roundup(cid_count, QM_CID_ROUND);
12547}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012548
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012549/**
Ariel Elior6383c0b2011-07-14 08:31:57 +000012550 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012551 *
12552 * @dev: pci device
12553 *
12554 */
Merav Sicron55c11942012-11-07 00:45:48 +000012555static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
Ariel Elior1ab44342013-01-01 05:22:23 +000012556 int cnic_cnt, bool is_vf)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012557{
Yijing Wangae2104b2013-08-08 21:02:36 +080012558 int index;
Ariel Elior1ab44342013-01-01 05:22:23 +000012559 u16 control = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012560
Ariel Elior6383c0b2011-07-14 08:31:57 +000012561 /*
12562 * If MSI-X is not supported - return number of SBs needed to support
12563 * one fast path queue: one FP queue + SB for CNIC
12564 */
Yijing Wangae2104b2013-08-08 21:02:36 +080012565 if (!pdev->msix_cap) {
Ariel Elior1ab44342013-01-01 05:22:23 +000012566 dev_info(&pdev->dev, "no msix capability found\n");
Merav Sicron55c11942012-11-07 00:45:48 +000012567 return 1 + cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012568 }
12569 dev_info(&pdev->dev, "msix capability found\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +000012570
12571 /*
12572 * The value in the PCI configuration space is the index of the last
12573 * entry, namely one less than the actual size of the table, which is
12574 * exactly what we want to return from this function: number of all SBs
12575 * without the default SB.
Ariel Elior1ab44342013-01-01 05:22:23 +000012576 * For VFs there is no default SB, then we return (index+1).
Ariel Elior6383c0b2011-07-14 08:31:57 +000012577 */
Yijing Wangae2104b2013-08-08 21:02:36 +080012578 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
Ariel Elior1ab44342013-01-01 05:22:23 +000012579
12580 index = control & PCI_MSIX_FLAGS_QSIZE;
12581
12582 return is_vf ? index + 1 : index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012583}
12584
Ariel Elior1ab44342013-01-01 05:22:23 +000012585static int set_max_cos_est(int chip_id)
12586{
12587 switch (chip_id) {
12588 case BCM57710:
12589 case BCM57711:
12590 case BCM57711E:
12591 return BNX2X_MULTI_TX_COS_E1X;
12592 case BCM57712:
12593 case BCM57712_MF:
12594 case BCM57712_VF:
12595 return BNX2X_MULTI_TX_COS_E2_E3A0;
12596 case BCM57800:
12597 case BCM57800_MF:
12598 case BCM57800_VF:
12599 case BCM57810:
12600 case BCM57810_MF:
12601 case BCM57840_4_10:
12602 case BCM57840_2_20:
12603 case BCM57840_O:
12604 case BCM57840_MFO:
12605 case BCM57810_VF:
12606 case BCM57840_MF:
12607 case BCM57840_VF:
12608 case BCM57811:
12609 case BCM57811_MF:
12610 case BCM57811_VF:
12611 return BNX2X_MULTI_TX_COS_E3B0;
12612 return 1;
12613 default:
12614 pr_err("Unknown board_type (%d), aborting\n", chip_id);
12615 return -ENODEV;
12616 }
12617}
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000012618
Ariel Elior1ab44342013-01-01 05:22:23 +000012619static int set_is_vf(int chip_id)
12620{
12621 switch (chip_id) {
12622 case BCM57712_VF:
12623 case BCM57800_VF:
12624 case BCM57810_VF:
12625 case BCM57840_VF:
12626 case BCM57811_VF:
12627 return true;
12628 default:
12629 return false;
12630 }
12631}
12632
12633struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
12634
12635static int bnx2x_init_one(struct pci_dev *pdev,
12636 const struct pci_device_id *ent)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012637{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012638 struct net_device *dev = NULL;
12639 struct bnx2x *bp;
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000012640 int pcie_width;
12641 enum bnx2x_pci_bus_speed pcie_speed;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012642 int rc, max_non_def_sbs;
Merav Sicron65565882012-06-19 07:48:26 +000012643 int rx_count, tx_count, rss_count, doorbell_size;
Ariel Elior1ab44342013-01-01 05:22:23 +000012644 int max_cos_est;
12645 bool is_vf;
Merav Sicron55c11942012-11-07 00:45:48 +000012646 int cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012647
12648 /* An estimated maximum supported CoS number according to the chip
Ariel Elior6383c0b2011-07-14 08:31:57 +000012649 * version.
12650 * We will try to roughly estimate the maximum number of CoSes this chip
12651 * may support in order to minimize the memory allocated for Tx
12652 * netdev_queue's. This number will be accurately calculated during the
12653 * initialization of bp->max_cos based on the chip versions AND chip
12654 * revision in the bnx2x_init_bp().
12655 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012656 max_cos_est = set_max_cos_est(ent->driver_data);
12657 if (max_cos_est < 0)
12658 return max_cos_est;
12659 is_vf = set_is_vf(ent->driver_data);
12660 cnic_cnt = is_vf ? 0 : 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012661
Ariel Elior1ab44342013-01-01 05:22:23 +000012662 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
Ariel Elior6383c0b2011-07-14 08:31:57 +000012663
12664 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
Ariel Elior1ab44342013-01-01 05:22:23 +000012665 rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
12666
12667 if (rss_count < 1)
12668 return -EINVAL;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012669
12670 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
Merav Sicron55c11942012-11-07 00:45:48 +000012671 rx_count = rss_count + cnic_cnt;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012672
Ariel Elior1ab44342013-01-01 05:22:23 +000012673 /* Maximum number of netdev Tx queues:
Merav Sicron37ae41a2012-06-19 07:48:27 +000012674 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
Ariel Elior6383c0b2011-07-14 08:31:57 +000012675 */
Merav Sicron55c11942012-11-07 00:45:48 +000012676 tx_count = rss_count * max_cos_est + cnic_cnt;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012677
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012678 /* dev zeroed in init_etherdev */
Ariel Elior6383c0b2011-07-14 08:31:57 +000012679 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
Joe Perches41de8d42012-01-29 13:47:52 +000012680 if (!dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012681 return -ENOMEM;
12682
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012683 bp = netdev_priv(dev);
Ariel Elior6383c0b2011-07-14 08:31:57 +000012684
Ariel Elior1ab44342013-01-01 05:22:23 +000012685 bp->flags = 0;
12686 if (is_vf)
12687 bp->flags |= IS_VF_FLAG;
12688
Ariel Elior6383c0b2011-07-14 08:31:57 +000012689 bp->igu_sb_cnt = max_non_def_sbs;
Ariel Elior1ab44342013-01-01 05:22:23 +000012690 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
Joe Perches7995c642010-02-17 15:01:52 +000012691 bp->msg_enable = debug;
Merav Sicron55c11942012-11-07 00:45:48 +000012692 bp->cnic_support = cnic_cnt;
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000012693 bp->cnic_probe = bnx2x_cnic_probe;
Merav Sicron55c11942012-11-07 00:45:48 +000012694
Eilon Greensteindf4770de2009-08-12 08:23:28 +000012695 pci_set_drvdata(pdev, dev);
12696
Ariel Elior1ab44342013-01-01 05:22:23 +000012697 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012698 if (rc < 0) {
12699 free_netdev(dev);
12700 return rc;
12701 }
12702
Ariel Elior1ab44342013-01-01 05:22:23 +000012703 BNX2X_DEV_INFO("This is a %s function\n",
12704 IS_PF(bp) ? "physical" : "virtual");
Merav Sicron55c11942012-11-07 00:45:48 +000012705 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
Ariel Elior1ab44342013-01-01 05:22:23 +000012706 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
Merav Sicron60aa0502012-06-19 07:48:29 +000012707 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
Yuval Mintz2de67432013-01-23 03:21:43 +000012708 tx_count, rx_count);
Merav Sicron60aa0502012-06-19 07:48:29 +000012709
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012710 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000012711 if (rc)
12712 goto init_one_exit;
12713
Ariel Elior1ab44342013-01-01 05:22:23 +000012714 /* Map doorbells here as we need the real value of bp->max_cos which
12715 * is initialized in bnx2x_init_bp() to determine the number of
12716 * l2 connections.
Ariel Elior6383c0b2011-07-14 08:31:57 +000012717 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012718 if (IS_VF(bp)) {
Dmitry Kravkov1d6f3cd2013-03-27 01:05:17 +000012719 bp->doorbells = bnx2x_vf_doorbells(bp);
Ariel Elior64112802013-01-07 00:50:23 +000012720 rc = bnx2x_vf_pci_alloc(bp);
12721 if (rc)
12722 goto init_one_exit;
Ariel Elior1ab44342013-01-01 05:22:23 +000012723 } else {
12724 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12725 if (doorbell_size > pci_resource_len(pdev, 2)) {
12726 dev_err(&bp->pdev->dev,
12727 "Cannot map doorbells, bar size too small, aborting\n");
12728 rc = -ENOMEM;
12729 goto init_one_exit;
12730 }
12731 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12732 doorbell_size);
Merav Sicron37ae41a2012-06-19 07:48:27 +000012733 }
Ariel Elior6383c0b2011-07-14 08:31:57 +000012734 if (!bp->doorbells) {
12735 dev_err(&bp->pdev->dev,
12736 "Cannot map doorbell space, aborting\n");
12737 rc = -ENOMEM;
12738 goto init_one_exit;
12739 }
12740
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000012741 if (IS_VF(bp)) {
12742 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12743 if (rc)
12744 goto init_one_exit;
12745 }
12746
Ariel Elior3c76fef2013-03-11 05:17:46 +000012747 /* Enable SRIOV if capability found in configuration space */
12748 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
Ariel Elior290ca2b2013-01-01 05:22:31 +000012749 if (rc)
12750 goto init_one_exit;
12751
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012752 /* calc qm_cid_count */
Ariel Elior6383c0b2011-07-14 08:31:57 +000012753 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
Ariel Elior1ab44342013-01-01 05:22:23 +000012754 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012755
Merav Sicron55c11942012-11-07 00:45:48 +000012756 /* disable FCOE L2 queue for E1x*/
Dmitry Kravkov62ac0dc2011-11-13 04:34:21 +000012757 if (CHIP_IS_E1x(bp))
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012758 bp->flags |= NO_FCOE_FLAG;
12759
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000012760 /* Set bp->num_queues for MSI-X mode*/
12761 bnx2x_set_num_queues(bp);
12762
Lucas De Marchi25985ed2011-03-30 22:57:33 -030012763 /* Configure interrupt mode: try to enable MSI-X/MSI if
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000012764 * needed.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012765 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012766 rc = bnx2x_set_int_mode(bp);
12767 if (rc) {
12768 dev_err(&pdev->dev, "Cannot set interrupts\n");
12769 goto init_one_exit;
12770 }
Yuval Mintz04c46732013-01-23 03:21:46 +000012771 BNX2X_DEV_INFO("set interrupts successfully\n");
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012772
Ariel Elior1ab44342013-01-01 05:22:23 +000012773 /* register the net device */
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080012774 rc = register_netdev(dev);
12775 if (rc) {
12776 dev_err(&pdev->dev, "Cannot register net device\n");
12777 goto init_one_exit;
12778 }
Ariel Elior1ab44342013-01-01 05:22:23 +000012779 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080012780
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012781 if (!NO_FCOE(bp)) {
12782 /* Add storage MAC address */
12783 rtnl_lock();
12784 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12785 rtnl_unlock();
12786 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012787
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012788 bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
Ariel Elior1ab44342013-01-01 05:22:23 +000012789 BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
12790 pcie_width, pcie_speed);
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012791
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000012792 BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
12793 board_info[ent->driver_data].name,
12794 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
12795 pcie_width,
12796 pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
12797 pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
12798 pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
12799 "Unknown",
12800 dev->base_addr, bp->pdev->irq, dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000012801
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012802 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012803
12804init_one_exit:
12805 if (bp->regview)
12806 iounmap(bp->regview);
12807
Ariel Elior1ab44342013-01-01 05:22:23 +000012808 if (IS_PF(bp) && bp->doorbells)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012809 iounmap(bp->doorbells);
12810
12811 free_netdev(dev);
12812
12813 if (atomic_read(&pdev->enable_cnt) == 1)
12814 pci_release_regions(pdev);
12815
12816 pci_disable_device(pdev);
12817 pci_set_drvdata(pdev, NULL);
12818
12819 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012820}
12821
Yuval Mintzb030ed22013-05-27 04:08:30 +000012822static void __bnx2x_remove(struct pci_dev *pdev,
12823 struct net_device *dev,
12824 struct bnx2x *bp,
12825 bool remove_netdev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012826{
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012827 /* Delete storage MAC address */
12828 if (!NO_FCOE(bp)) {
12829 rtnl_lock();
12830 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
12831 rtnl_unlock();
12832 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012833
Shmulik Ravid98507672011-02-28 12:19:55 -080012834#ifdef BCM_DCBNL
12835 /* Delete app tlvs from dcbnl */
12836 bnx2x_dcbnl_update_applist(bp, true);
12837#endif
12838
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030012839 if (IS_PF(bp) &&
12840 !BP_NOMCP(bp) &&
12841 (bp->flags & BC_SUPPORTS_RMMOD_CMD))
12842 bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
12843
Yuval Mintzb030ed22013-05-27 04:08:30 +000012844 /* Close the interface - either directly or implicitly */
12845 if (remove_netdev) {
12846 unregister_netdev(dev);
12847 } else {
12848 rtnl_lock();
Yuval Mintz6ef5a922013-08-13 02:25:03 +030012849 dev_close(dev);
Yuval Mintzb030ed22013-05-27 04:08:30 +000012850 rtnl_unlock();
12851 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012852
Ariel Elior78c3bcc2013-06-20 17:39:08 +030012853 bnx2x_iov_remove_one(bp);
12854
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000012855 /* Power on: we can't let PCI layer write to us while we are in D3 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012856 if (IS_PF(bp))
12857 bnx2x_set_power_state(bp, PCI_D0);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000012858
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012859 /* Disable MSI/MSI-X */
12860 bnx2x_disable_msi(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012861
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000012862 /* Power off */
Ariel Elior1ab44342013-01-01 05:22:23 +000012863 if (IS_PF(bp))
12864 bnx2x_set_power_state(bp, PCI_D3hot);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000012865
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012866 /* Make sure RESET task is not scheduled before continuing */
Ariel Elior7be08a72011-07-14 08:31:19 +000012867 cancel_delayed_work_sync(&bp->sp_rtnl_task);
Ariel Elior290ca2b2013-01-01 05:22:31 +000012868
Ariel Elior4513f922013-01-01 05:22:25 +000012869 /* send message via vfpf channel to release the resources of this vf */
12870 if (IS_VF(bp))
12871 bnx2x_vfpf_release(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012872
Yuval Mintzb030ed22013-05-27 04:08:30 +000012873 /* Assumes no further PCIe PM changes will occur */
12874 if (system_state == SYSTEM_POWER_OFF) {
12875 pci_wake_from_d3(pdev, bp->wol);
12876 pci_set_power_state(pdev, PCI_D3hot);
12877 }
12878
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012879 if (bp->regview)
12880 iounmap(bp->regview);
12881
Ariel Elior1ab44342013-01-01 05:22:23 +000012882 /* for vf doorbells are part of the regview and were unmapped along with
12883 * it. FW is only loaded by PF.
12884 */
12885 if (IS_PF(bp)) {
12886 if (bp->doorbells)
12887 iounmap(bp->doorbells);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012888
Ariel Elior1ab44342013-01-01 05:22:23 +000012889 bnx2x_release_firmware(bp);
12890 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012891 bnx2x_free_mem_bp(bp);
12892
Yuval Mintzb030ed22013-05-27 04:08:30 +000012893 if (remove_netdev)
12894 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012895
12896 if (atomic_read(&pdev->enable_cnt) == 1)
12897 pci_release_regions(pdev);
12898
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012899 pci_disable_device(pdev);
12900 pci_set_drvdata(pdev, NULL);
12901}
12902
Yuval Mintzb030ed22013-05-27 04:08:30 +000012903static void bnx2x_remove_one(struct pci_dev *pdev)
12904{
12905 struct net_device *dev = pci_get_drvdata(pdev);
12906 struct bnx2x *bp;
12907
12908 if (!dev) {
12909 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
12910 return;
12911 }
12912 bp = netdev_priv(dev);
12913
12914 __bnx2x_remove(pdev, dev, bp, true);
12915}
12916
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012917static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
12918{
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012919 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012920
12921 bp->rx_mode = BNX2X_RX_MODE_NONE;
12922
Merav Sicron55c11942012-11-07 00:45:48 +000012923 if (CNIC_LOADED(bp))
12924 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
12925
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012926 /* Stop Tx */
12927 bnx2x_tx_disable(bp);
Merav Sicron26614ba2012-08-27 03:26:19 +000012928 /* Delete all NAPI objects */
12929 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +000012930 if (CNIC_LOADED(bp))
12931 bnx2x_del_all_napi_cnic(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012932 netdev_reset_tc(bp->dev);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012933
12934 del_timer_sync(&bp->timer);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012935 cancel_delayed_work(&bp->sp_task);
12936 cancel_delayed_work(&bp->period_task);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012937
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012938 spin_lock_bh(&bp->stats_lock);
12939 bp->stats_state = STATS_STATE_DISABLED;
12940 spin_unlock_bh(&bp->stats_lock);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012941
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012942 bnx2x_save_statistics(bp);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012943
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012944 netif_carrier_off(bp->dev);
12945
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012946 return 0;
12947}
12948
Wendy Xiong493adb12008-06-23 20:36:22 -070012949/**
12950 * bnx2x_io_error_detected - called when PCI error is detected
12951 * @pdev: Pointer to PCI device
12952 * @state: The current pci connection state
12953 *
12954 * This function is called after a PCI bus error affecting
12955 * this device has been detected.
12956 */
12957static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
12958 pci_channel_state_t state)
12959{
12960 struct net_device *dev = pci_get_drvdata(pdev);
12961 struct bnx2x *bp = netdev_priv(dev);
12962
12963 rtnl_lock();
12964
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012965 BNX2X_ERR("IO error detected\n");
12966
Wendy Xiong493adb12008-06-23 20:36:22 -070012967 netif_device_detach(dev);
12968
Dean Nelson07ce50e42009-07-31 09:13:25 +000012969 if (state == pci_channel_io_perm_failure) {
12970 rtnl_unlock();
12971 return PCI_ERS_RESULT_DISCONNECT;
12972 }
12973
Wendy Xiong493adb12008-06-23 20:36:22 -070012974 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070012975 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070012976
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012977 bnx2x_prev_path_mark_eeh(bp);
12978
Wendy Xiong493adb12008-06-23 20:36:22 -070012979 pci_disable_device(pdev);
12980
12981 rtnl_unlock();
12982
12983 /* Request a slot reset */
12984 return PCI_ERS_RESULT_NEED_RESET;
12985}
12986
12987/**
12988 * bnx2x_io_slot_reset - called after the PCI bus has been reset
12989 * @pdev: Pointer to PCI device
12990 *
12991 * Restart the card from scratch, as if from a cold-boot.
12992 */
12993static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
12994{
12995 struct net_device *dev = pci_get_drvdata(pdev);
12996 struct bnx2x *bp = netdev_priv(dev);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000012997 int i;
Wendy Xiong493adb12008-06-23 20:36:22 -070012998
12999 rtnl_lock();
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013000 BNX2X_ERR("IO slot reset initializing...\n");
Wendy Xiong493adb12008-06-23 20:36:22 -070013001 if (pci_enable_device(pdev)) {
13002 dev_err(&pdev->dev,
13003 "Cannot re-enable PCI device after reset\n");
13004 rtnl_unlock();
13005 return PCI_ERS_RESULT_DISCONNECT;
13006 }
13007
13008 pci_set_master(pdev);
13009 pci_restore_state(pdev);
Yuval Mintz70632d02013-04-24 01:45:02 +000013010 pci_save_state(pdev);
Wendy Xiong493adb12008-06-23 20:36:22 -070013011
13012 if (netif_running(dev))
13013 bnx2x_set_power_state(bp, PCI_D0);
13014
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013015 if (netif_running(dev)) {
13016 BNX2X_ERR("IO slot reset --> driver unload\n");
Yuval Mintze68072e2013-05-22 21:21:51 +000013017
13018 /* MCP should have been reset; Need to wait for validity */
13019 bnx2x_init_shmem(bp);
13020
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013021 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
13022 u32 v;
13023
13024 v = SHMEM2_RD(bp,
13025 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
13026 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
13027 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
13028 }
13029 bnx2x_drain_tx_queues(bp);
13030 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
13031 bnx2x_netif_stop(bp, 1);
13032 bnx2x_free_irq(bp);
13033
13034 /* Report UNLOAD_DONE to MCP */
13035 bnx2x_send_unload_done(bp, true);
13036
13037 bp->sp_state = 0;
13038 bp->port.pmf = 0;
13039
13040 bnx2x_prev_unload(bp);
13041
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013042 /* We should have reseted the engine, so It's fair to
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013043 * assume the FW will no longer write to the bnx2x driver.
13044 */
13045 bnx2x_squeeze_objects(bp);
13046 bnx2x_free_skbs(bp);
13047 for_each_rx_queue(bp, i)
13048 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
13049 bnx2x_free_fp_mem(bp);
13050 bnx2x_free_mem(bp);
13051
13052 bp->state = BNX2X_STATE_CLOSED;
13053 }
13054
Wendy Xiong493adb12008-06-23 20:36:22 -070013055 rtnl_unlock();
13056
13057 return PCI_ERS_RESULT_RECOVERED;
13058}
13059
13060/**
13061 * bnx2x_io_resume - called when traffic can start flowing again
13062 * @pdev: Pointer to PCI device
13063 *
13064 * This callback is called when the error recovery driver tells us that
13065 * its OK to resume normal operation.
13066 */
13067static void bnx2x_io_resume(struct pci_dev *pdev)
13068{
13069 struct net_device *dev = pci_get_drvdata(pdev);
13070 struct bnx2x *bp = netdev_priv(dev);
13071
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013072 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013073 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013074 return;
13075 }
13076
Wendy Xiong493adb12008-06-23 20:36:22 -070013077 rtnl_lock();
13078
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013079 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
13080 DRV_MSG_SEQ_NUMBER_MASK;
13081
Wendy Xiong493adb12008-06-23 20:36:22 -070013082 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013083 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070013084
13085 netif_device_attach(dev);
13086
13087 rtnl_unlock();
13088}
13089
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070013090static const struct pci_error_handlers bnx2x_err_handler = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013091 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000013092 .slot_reset = bnx2x_io_slot_reset,
13093 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070013094};
13095
Yuval Mintzb030ed22013-05-27 04:08:30 +000013096static void bnx2x_shutdown(struct pci_dev *pdev)
13097{
13098 struct net_device *dev = pci_get_drvdata(pdev);
13099 struct bnx2x *bp;
13100
13101 if (!dev)
13102 return;
13103
13104 bp = netdev_priv(dev);
13105 if (!bp)
13106 return;
13107
13108 rtnl_lock();
13109 netif_device_detach(dev);
13110 rtnl_unlock();
13111
13112 /* Don't remove the netdevice, as there are scenarios which will cause
13113 * the kernel to hang, e.g., when trying to remove bnx2i while the
13114 * rootfs is mounted from SAN.
13115 */
13116 __bnx2x_remove(pdev, dev, bp, false);
13117}
13118
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013119static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013120 .name = DRV_MODULE_NAME,
13121 .id_table = bnx2x_pci_tbl,
13122 .probe = bnx2x_init_one,
Bill Pemberton0329aba2012-12-03 09:24:24 -050013123 .remove = bnx2x_remove_one,
Wendy Xiong493adb12008-06-23 20:36:22 -070013124 .suspend = bnx2x_suspend,
13125 .resume = bnx2x_resume,
13126 .err_handler = &bnx2x_err_handler,
Ariel Elior3c76fef2013-03-11 05:17:46 +000013127#ifdef CONFIG_BNX2X_SRIOV
13128 .sriov_configure = bnx2x_sriov_configure,
13129#endif
Yuval Mintzb030ed22013-05-27 04:08:30 +000013130 .shutdown = bnx2x_shutdown,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013131};
13132
13133static int __init bnx2x_init(void)
13134{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013135 int ret;
13136
Joe Perches7995c642010-02-17 15:01:52 +000013137 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +000013138
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013139 bnx2x_wq = create_singlethread_workqueue("bnx2x");
13140 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +000013141 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013142 return -ENOMEM;
13143 }
13144
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013145 ret = pci_register_driver(&bnx2x_pci_driver);
13146 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +000013147 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013148 destroy_workqueue(bnx2x_wq);
13149 }
13150 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013151}
13152
13153static void __exit bnx2x_cleanup(void)
13154{
Yuval Mintz452427b2012-03-26 20:47:07 +000013155 struct list_head *pos, *q;
Yuval Mintzd76a6112013-06-02 00:06:17 +000013156
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013157 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013158
13159 destroy_workqueue(bnx2x_wq);
Yuval Mintz452427b2012-03-26 20:47:07 +000013160
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013161 /* Free globally allocated resources */
Yuval Mintz452427b2012-03-26 20:47:07 +000013162 list_for_each_safe(pos, q, &bnx2x_prev_list) {
13163 struct bnx2x_prev_path_list *tmp =
13164 list_entry(pos, struct bnx2x_prev_path_list, list);
13165 list_del(pos);
13166 kfree(tmp);
13167 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013168}
13169
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013170void bnx2x_notify_link_changed(struct bnx2x *bp)
13171{
13172 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13173}
13174
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013175module_init(bnx2x_init);
13176module_exit(bnx2x_cleanup);
13177
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013178/**
13179 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13180 *
13181 * @bp: driver handle
13182 * @set: set or clear the CAM entry
13183 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013184 * This function will wait until the ramrod completion returns.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013185 * Return 0 if success, -ENODEV if ramrod doesn't return.
13186 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000013187static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013188{
13189 unsigned long ramrod_flags = 0;
13190
13191 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13192 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13193 &bp->iscsi_l2_mac_obj, true,
13194 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13195}
Michael Chan993ac7b2009-10-10 13:46:56 +000013196
13197/* count denotes the number of new completions we have seen */
13198static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13199{
13200 struct eth_spe *spe;
Merav Sicrona0529972012-06-19 07:48:25 +000013201 int cxt_index, cxt_offset;
Michael Chan993ac7b2009-10-10 13:46:56 +000013202
13203#ifdef BNX2X_STOP_ON_ERROR
13204 if (unlikely(bp->panic))
13205 return;
13206#endif
13207
13208 spin_lock_bh(&bp->spq_lock);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013209 BUG_ON(bp->cnic_spq_pending < count);
Michael Chan993ac7b2009-10-10 13:46:56 +000013210 bp->cnic_spq_pending -= count;
13211
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013212 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13213 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13214 & SPE_HDR_CONN_TYPE) >>
13215 SPE_HDR_CONN_TYPE_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013216 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13217 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013218
13219 /* Set validation for iSCSI L2 client before sending SETUP
13220 * ramrod
13221 */
13222 if (type == ETH_CONNECTION_TYPE) {
Merav Sicrona0529972012-06-19 07:48:25 +000013223 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
Merav Sicron37ae41a2012-06-19 07:48:27 +000013224 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
Merav Sicrona0529972012-06-19 07:48:25 +000013225 ILT_PAGE_CIDS;
Merav Sicron37ae41a2012-06-19 07:48:27 +000013226 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
Merav Sicrona0529972012-06-19 07:48:25 +000013227 (cxt_index * ILT_PAGE_CIDS);
13228 bnx2x_set_ctx_validation(bp,
13229 &bp->context[cxt_index].
13230 vcxt[cxt_offset].eth,
Merav Sicron37ae41a2012-06-19 07:48:27 +000013231 BNX2X_ISCSI_ETH_CID(bp));
Merav Sicrona0529972012-06-19 07:48:25 +000013232 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013233 }
13234
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013235 /*
13236 * There may be not more than 8 L2, not more than 8 L5 SPEs
13237 * and in the air. We also check that number of outstanding
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013238 * COMMON ramrods is not more than the EQ and SPQ can
13239 * accommodate.
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013240 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013241 if (type == ETH_CONNECTION_TYPE) {
13242 if (!atomic_read(&bp->cq_spq_left))
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013243 break;
13244 else
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013245 atomic_dec(&bp->cq_spq_left);
13246 } else if (type == NONE_CONNECTION_TYPE) {
13247 if (!atomic_read(&bp->eq_spq_left))
13248 break;
13249 else
13250 atomic_dec(&bp->eq_spq_left);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013251 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13252 (type == FCOE_CONNECTION_TYPE)) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013253 if (bp->cnic_spq_pending >=
13254 bp->cnic_eth_dev.max_kwqe_pending)
13255 break;
13256 else
13257 bp->cnic_spq_pending++;
13258 } else {
13259 BNX2X_ERR("Unknown SPE type: %d\n", type);
13260 bnx2x_panic();
Michael Chan993ac7b2009-10-10 13:46:56 +000013261 break;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013262 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013263
13264 spe = bnx2x_sp_get_next(bp);
13265 *spe = *bp->cnic_kwq_cons;
13266
Merav Sicron51c1a582012-03-18 10:33:38 +000013267 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013268 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13269
13270 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13271 bp->cnic_kwq_cons = bp->cnic_kwq;
13272 else
13273 bp->cnic_kwq_cons++;
13274 }
13275 bnx2x_sp_prod_update(bp);
13276 spin_unlock_bh(&bp->spq_lock);
13277}
13278
13279static int bnx2x_cnic_sp_queue(struct net_device *dev,
13280 struct kwqe_16 *kwqes[], u32 count)
13281{
13282 struct bnx2x *bp = netdev_priv(dev);
13283 int i;
13284
13285#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +000013286 if (unlikely(bp->panic)) {
13287 BNX2X_ERR("Can't post to SP queue while panic\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013288 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +000013289 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013290#endif
13291
Ariel Elior95c6c6162012-01-26 06:01:52 +000013292 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13293 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013294 BNX2X_ERR("Handling parity error recovery. Try again later\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +000013295 return -EAGAIN;
13296 }
13297
Michael Chan993ac7b2009-10-10 13:46:56 +000013298 spin_lock_bh(&bp->spq_lock);
13299
13300 for (i = 0; i < count; i++) {
13301 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13302
13303 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13304 break;
13305
13306 *bp->cnic_kwq_prod = *spe;
13307
13308 bp->cnic_kwq_pending++;
13309
Merav Sicron51c1a582012-03-18 10:33:38 +000013310 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013311 spe->hdr.conn_and_cmd_data, spe->hdr.type,
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013312 spe->data.update_data_addr.hi,
13313 spe->data.update_data_addr.lo,
Michael Chan993ac7b2009-10-10 13:46:56 +000013314 bp->cnic_kwq_pending);
13315
13316 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13317 bp->cnic_kwq_prod = bp->cnic_kwq;
13318 else
13319 bp->cnic_kwq_prod++;
13320 }
13321
13322 spin_unlock_bh(&bp->spq_lock);
13323
13324 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13325 bnx2x_cnic_sp_post(bp, 0);
13326
13327 return i;
13328}
13329
13330static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13331{
13332 struct cnic_ops *c_ops;
13333 int rc = 0;
13334
13335 mutex_lock(&bp->cnic_mutex);
Eric Dumazet13707f92011-01-26 19:28:23 +000013336 c_ops = rcu_dereference_protected(bp->cnic_ops,
13337 lockdep_is_held(&bp->cnic_mutex));
Michael Chan993ac7b2009-10-10 13:46:56 +000013338 if (c_ops)
13339 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13340 mutex_unlock(&bp->cnic_mutex);
13341
13342 return rc;
13343}
13344
13345static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13346{
13347 struct cnic_ops *c_ops;
13348 int rc = 0;
13349
13350 rcu_read_lock();
13351 c_ops = rcu_dereference(bp->cnic_ops);
13352 if (c_ops)
13353 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13354 rcu_read_unlock();
13355
13356 return rc;
13357}
13358
13359/*
13360 * for commands that have no data
13361 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013362int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +000013363{
13364 struct cnic_ctl_info ctl = {0};
13365
13366 ctl.cmd = cmd;
13367
13368 return bnx2x_cnic_ctl_send(bp, &ctl);
13369}
13370
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013371static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
Michael Chan993ac7b2009-10-10 13:46:56 +000013372{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013373 struct cnic_ctl_info ctl = {0};
Michael Chan993ac7b2009-10-10 13:46:56 +000013374
13375 /* first we tell CNIC and only then we count this as a completion */
13376 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13377 ctl.data.comp.cid = cid;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013378 ctl.data.comp.error = err;
Michael Chan993ac7b2009-10-10 13:46:56 +000013379
13380 bnx2x_cnic_ctl_send_bh(bp, &ctl);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013381 bnx2x_cnic_sp_post(bp, 0);
Michael Chan993ac7b2009-10-10 13:46:56 +000013382}
13383
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013384/* Called with netif_addr_lock_bh() taken.
13385 * Sets an rx_mode config for an iSCSI ETH client.
13386 * Doesn't block.
13387 * Completion should be checked outside.
13388 */
13389static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13390{
13391 unsigned long accept_flags = 0, ramrod_flags = 0;
13392 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13393 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13394
13395 if (start) {
13396 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13397 * because it's the only way for UIO Queue to accept
13398 * multicasts (in non-promiscuous mode only one Queue per
13399 * function will receive multicast packets (leading in our
13400 * case).
13401 */
13402 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13403 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13404 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13405 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13406
13407 /* Clear STOP_PENDING bit if START is requested */
13408 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13409
13410 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13411 } else
13412 /* Clear START_PENDING bit if STOP is requested */
13413 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13414
13415 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13416 set_bit(sched_state, &bp->sp_state);
13417 else {
13418 __set_bit(RAMROD_RX, &ramrod_flags);
13419 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13420 ramrod_flags);
13421 }
13422}
13423
Michael Chan993ac7b2009-10-10 13:46:56 +000013424static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13425{
13426 struct bnx2x *bp = netdev_priv(dev);
13427 int rc = 0;
13428
13429 switch (ctl->cmd) {
13430 case DRV_CTL_CTXTBL_WR_CMD: {
13431 u32 index = ctl->data.io.offset;
13432 dma_addr_t addr = ctl->data.io.dma_addr;
13433
13434 bnx2x_ilt_wr(bp, index, addr);
13435 break;
13436 }
13437
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013438 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13439 int count = ctl->data.credit.credit_count;
Michael Chan993ac7b2009-10-10 13:46:56 +000013440
13441 bnx2x_cnic_sp_post(bp, count);
13442 break;
13443 }
13444
13445 /* rtnl_lock is held. */
13446 case DRV_CTL_START_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013447 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13448 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013449
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013450 /* Configure the iSCSI classification object */
13451 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13452 cp->iscsi_l2_client_id,
13453 cp->iscsi_l2_cid, BP_FUNC(bp),
13454 bnx2x_sp(bp, mac_rdata),
13455 bnx2x_sp_mapping(bp, mac_rdata),
13456 BNX2X_FILTER_MAC_PENDING,
13457 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13458 &bp->macs_pool);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013459
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013460 /* Set iSCSI MAC address */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013461 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13462 if (rc)
13463 break;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013464
13465 mmiowb();
13466 barrier();
13467
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013468 /* Start accepting on iSCSI L2 ring */
13469
13470 netif_addr_lock_bh(dev);
13471 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13472 netif_addr_unlock_bh(dev);
13473
13474 /* bits to wait on */
13475 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13476 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13477
13478 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13479 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013480
Michael Chan993ac7b2009-10-10 13:46:56 +000013481 break;
13482 }
13483
13484 /* rtnl_lock is held. */
13485 case DRV_CTL_STOP_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013486 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013487
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013488 /* Stop accepting on iSCSI L2 ring */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013489 netif_addr_lock_bh(dev);
13490 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13491 netif_addr_unlock_bh(dev);
13492
13493 /* bits to wait on */
13494 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13495 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13496
13497 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13498 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013499
13500 mmiowb();
13501 barrier();
13502
13503 /* Unset iSCSI L2 MAC */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013504 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13505 BNX2X_ISCSI_ETH_MAC, true);
Michael Chan993ac7b2009-10-10 13:46:56 +000013506 break;
13507 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013508 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13509 int count = ctl->data.credit.credit_count;
13510
13511 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013512 atomic_add(count, &bp->cq_spq_left);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013513 smp_mb__after_atomic_inc();
13514 break;
13515 }
Barak Witkowski1d187b32011-12-05 22:41:50 +000013516 case DRV_CTL_ULP_REGISTER_CMD: {
Barak Witkowski2e499d32012-06-26 01:31:19 +000013517 int ulp_type = ctl->data.register_data.ulp_type;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013518
13519 if (CHIP_IS_E3(bp)) {
13520 int idx = BP_FW_MB_IDX(bp);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013521 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13522 int path = BP_PATH(bp);
13523 int port = BP_PORT(bp);
13524 int i;
13525 u32 scratch_offset;
13526 u32 *host_addr;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013527
Barak Witkowski2e499d32012-06-26 01:31:19 +000013528 /* first write capability to shmem2 */
Barak Witkowski1d187b32011-12-05 22:41:50 +000013529 if (ulp_type == CNIC_ULP_ISCSI)
13530 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13531 else if (ulp_type == CNIC_ULP_FCOE)
13532 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13533 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013534
13535 if ((ulp_type != CNIC_ULP_FCOE) ||
13536 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13537 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13538 break;
13539
13540 /* if reached here - should write fcoe capabilities */
13541 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13542 if (!scratch_offset)
13543 break;
13544 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13545 fcoe_features[path][port]);
13546 host_addr = (u32 *) &(ctl->data.register_data.
13547 fcoe_features);
13548 for (i = 0; i < sizeof(struct fcoe_capabilities);
13549 i += 4)
13550 REG_WR(bp, scratch_offset + i,
13551 *(host_addr + i/4));
Barak Witkowski1d187b32011-12-05 22:41:50 +000013552 }
13553 break;
13554 }
Barak Witkowski2e499d32012-06-26 01:31:19 +000013555
Barak Witkowski1d187b32011-12-05 22:41:50 +000013556 case DRV_CTL_ULP_UNREGISTER_CMD: {
13557 int ulp_type = ctl->data.ulp_type;
13558
13559 if (CHIP_IS_E3(bp)) {
13560 int idx = BP_FW_MB_IDX(bp);
13561 u32 cap;
13562
13563 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13564 if (ulp_type == CNIC_ULP_ISCSI)
13565 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13566 else if (ulp_type == CNIC_ULP_FCOE)
13567 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13568 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13569 }
13570 break;
13571 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013572
13573 default:
13574 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13575 rc = -EINVAL;
13576 }
13577
13578 return rc;
13579}
13580
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013581void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +000013582{
13583 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13584
13585 if (bp->flags & USING_MSIX_FLAG) {
13586 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13587 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13588 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13589 } else {
13590 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13591 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13592 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013593 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013594 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13595 else
13596 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13597
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013598 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13599 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013600 cp->irq_arr[1].status_blk = bp->def_status_blk;
13601 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013602 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
Michael Chan993ac7b2009-10-10 13:46:56 +000013603
13604 cp->num_irq = 2;
13605}
13606
Merav Sicron37ae41a2012-06-19 07:48:27 +000013607void bnx2x_setup_cnic_info(struct bnx2x *bp)
13608{
13609 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13610
Merav Sicron37ae41a2012-06-19 07:48:27 +000013611 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13612 bnx2x_cid_ilt_lines(bp);
13613 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13614 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13615 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13616
13617 if (NO_ISCSI_OOO(bp))
13618 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13619}
13620
Michael Chan993ac7b2009-10-10 13:46:56 +000013621static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13622 void *data)
13623{
13624 struct bnx2x *bp = netdev_priv(dev);
13625 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
Merav Sicron55c11942012-11-07 00:45:48 +000013626 int rc;
13627
13628 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013629
Merav Sicron51c1a582012-03-18 10:33:38 +000013630 if (ops == NULL) {
13631 BNX2X_ERR("NULL ops received\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013632 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000013633 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013634
Merav Sicron55c11942012-11-07 00:45:48 +000013635 if (!CNIC_SUPPORT(bp)) {
13636 BNX2X_ERR("Can't register CNIC when not supported\n");
13637 return -EOPNOTSUPP;
13638 }
13639
13640 if (!CNIC_LOADED(bp)) {
13641 rc = bnx2x_load_cnic(bp);
13642 if (rc) {
13643 BNX2X_ERR("CNIC-related load failed\n");
13644 return rc;
13645 }
Merav Sicron55c11942012-11-07 00:45:48 +000013646 }
13647
13648 bp->cnic_enabled = true;
13649
Michael Chan993ac7b2009-10-10 13:46:56 +000013650 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13651 if (!bp->cnic_kwq)
13652 return -ENOMEM;
13653
13654 bp->cnic_kwq_cons = bp->cnic_kwq;
13655 bp->cnic_kwq_prod = bp->cnic_kwq;
13656 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13657
13658 bp->cnic_spq_pending = 0;
13659 bp->cnic_kwq_pending = 0;
13660
13661 bp->cnic_data = data;
13662
13663 cp->num_irq = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013664 cp->drv_state |= CNIC_DRV_STATE_REGD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013665 cp->iro_arr = bp->iro_arr;
Michael Chan993ac7b2009-10-10 13:46:56 +000013666
Michael Chan993ac7b2009-10-10 13:46:56 +000013667 bnx2x_setup_cnic_irq_info(bp);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013668
Michael Chan993ac7b2009-10-10 13:46:56 +000013669 rcu_assign_pointer(bp->cnic_ops, ops);
13670
13671 return 0;
13672}
13673
13674static int bnx2x_unregister_cnic(struct net_device *dev)
13675{
13676 struct bnx2x *bp = netdev_priv(dev);
13677 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13678
13679 mutex_lock(&bp->cnic_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +000013680 cp->drv_state = 0;
Eric Dumazet2cfa5a02011-11-23 07:09:32 +000013681 RCU_INIT_POINTER(bp->cnic_ops, NULL);
Michael Chan993ac7b2009-10-10 13:46:56 +000013682 mutex_unlock(&bp->cnic_mutex);
13683 synchronize_rcu();
Yuval Mintzfea75642013-04-10 13:34:39 +030013684 bp->cnic_enabled = false;
Michael Chan993ac7b2009-10-10 13:46:56 +000013685 kfree(bp->cnic_kwq);
13686 bp->cnic_kwq = NULL;
13687
13688 return 0;
13689}
13690
13691struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
13692{
13693 struct bnx2x *bp = netdev_priv(dev);
13694 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13695
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000013696 /* If both iSCSI and FCoE are disabled - return NULL in
13697 * order to indicate CNIC that it should not try to work
13698 * with this device.
13699 */
13700 if (NO_ISCSI(bp) && NO_FCOE(bp))
13701 return NULL;
13702
Michael Chan993ac7b2009-10-10 13:46:56 +000013703 cp->drv_owner = THIS_MODULE;
13704 cp->chip_id = CHIP_ID(bp);
13705 cp->pdev = bp->pdev;
13706 cp->io_base = bp->regview;
13707 cp->io_base2 = bp->doorbells;
13708 cp->max_kwqe_pending = 8;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013709 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013710 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13711 bnx2x_cid_ilt_lines(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013712 cp->ctx_tbl_len = CNIC_ILT_LINES;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013713 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
Michael Chan993ac7b2009-10-10 13:46:56 +000013714 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13715 cp->drv_ctl = bnx2x_drv_ctl;
13716 cp->drv_register_cnic = bnx2x_register_cnic;
13717 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
Merav Sicron37ae41a2012-06-19 07:48:27 +000013718 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013719 cp->iscsi_l2_client_id =
13720 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
Merav Sicron37ae41a2012-06-19 07:48:27 +000013721 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013722
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000013723 if (NO_ISCSI_OOO(bp))
13724 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13725
13726 if (NO_ISCSI(bp))
13727 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13728
13729 if (NO_FCOE(bp))
13730 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13731
Merav Sicron51c1a582012-03-18 10:33:38 +000013732 BNX2X_DEV_INFO(
13733 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013734 cp->ctx_blk_size,
13735 cp->ctx_tbl_offset,
13736 cp->ctx_tbl_len,
13737 cp->starting_cid);
Michael Chan993ac7b2009-10-10 13:46:56 +000013738 return cp;
13739}
Michael Chan993ac7b2009-10-10 13:46:56 +000013740
Ariel Elior64112802013-01-07 00:50:23 +000013741u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013742{
Ariel Elior64112802013-01-07 00:50:23 +000013743 struct bnx2x *bp = fp->bp;
13744 u32 offset = BAR_USTRORM_INTMEM;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070013745
Ariel Elior64112802013-01-07 00:50:23 +000013746 if (IS_VF(bp))
13747 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13748 else if (!CHIP_IS_E1x(bp))
13749 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13750 else
13751 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013752
Ariel Elior64112802013-01-07 00:50:23 +000013753 return offset;
13754}
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013755
Ariel Elior64112802013-01-07 00:50:23 +000013756/* called only on E1H or E2.
13757 * When pretending to be PF, the pretend value is the function number 0...7
13758 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13759 * combination
13760 */
13761int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
13762{
13763 u32 pretend_reg;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013764
Ariel Elior23826852013-01-09 07:04:35 +000013765 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
Ariel Elior64112802013-01-07 00:50:23 +000013766 return -1;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013767
Ariel Elior64112802013-01-07 00:50:23 +000013768 /* get my own pretend register */
13769 pretend_reg = bnx2x_get_pretend_reg(bp);
13770 REG_WR(bp, pretend_reg, pretend_func_val);
13771 REG_RD(bp, pretend_reg);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013772 return 0;
13773}