blob: da4f75e5cf07993138fb17d5df486d2af31c87d9 [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>
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020030#include <linux/aer.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020031#include <linux/init.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/skbuff.h>
35#include <linux/dma-mapping.h>
36#include <linux/bitops.h>
37#include <linux/irq.h>
38#include <linux/delay.h>
39#include <asm/byteorder.h>
40#include <linux/time.h>
41#include <linux/ethtool.h>
42#include <linux/mii.h>
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080043#include <linux/if_vlan.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020044#include <net/ip.h>
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030045#include <net/ipv6.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020046#include <net/tcp.h>
47#include <net/checksum.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070048#include <net/ip6_checksum.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020049#include <linux/workqueue.h>
50#include <linux/crc32.h>
Eilon Greenstein34f80b02008-06-23 20:33:01 -070051#include <linux/crc32c.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020052#include <linux/prefetch.h>
53#include <linux/zlib.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020054#include <linux/io.h>
Yuval Mintz452427b2012-03-26 20:47:07 +000055#include <linux/semaphore.h>
Ben Hutchings45229b42009-11-07 11:53:39 +000056#include <linux/stringify.h>
David S. Miller7ab24bf2011-06-29 05:48:41 -070057#include <linux/vmalloc.h>
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020058
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020059#include "bnx2x.h"
60#include "bnx2x_init.h"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070061#include "bnx2x_init_ops.h"
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000062#include "bnx2x_cmn.h"
Ariel Elior1ab44342013-01-01 05:22:23 +000063#include "bnx2x_vfpf.h"
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000064#include "bnx2x_dcb.h"
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000065#include "bnx2x_sp.h"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020066
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070067#include <linux/firmware.h>
68#include "bnx2x_fw_file_hdr.h"
69/* FW files */
Ben Hutchings45229b42009-11-07 11:53:39 +000070#define FW_FILE_VERSION \
71 __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
72 __stringify(BCM_5710_FW_MINOR_VERSION) "." \
73 __stringify(BCM_5710_FW_REVISION_VERSION) "." \
74 __stringify(BCM_5710_FW_ENGINEERING_VERSION)
Dmitry Kravkov560131f2010-10-06 03:18:47 +000075#define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
76#define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000077#define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070078
Eilon Greenstein34f80b02008-06-23 20:33:01 -070079/* Time in jiffies before concluding the transmitter is hung */
80#define TX_TIMEOUT (5*HZ)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020081
Bill Pemberton0329aba2012-12-03 09:24:24 -050082static char version[] =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030083 "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020084 DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
85
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070086MODULE_AUTHOR("Eliezer Tamir");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000087MODULE_DESCRIPTION("Broadcom NetXtreme II "
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030088 "BCM57710/57711/57711E/"
89 "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
90 "57840/57840_MF Driver");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020091MODULE_LICENSE("GPL");
92MODULE_VERSION(DRV_MODULE_VERSION);
Ben Hutchings45229b42009-11-07 11:53:39 +000093MODULE_FIRMWARE(FW_FILE_NAME_E1);
94MODULE_FIRMWARE(FW_FILE_NAME_E1H);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000095MODULE_FIRMWARE(FW_FILE_NAME_E2);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020096
stephen hemmingera8f47eb2014-01-09 22:20:11 -080097int bnx2x_num_queues;
James M Leddy1c8bb762014-02-04 15:10:59 -050098module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
Dmitry Kravkov96305232012-04-03 18:41:30 +000099MODULE_PARM_DESC(num_queues,
100 " Set number of queues (default is as a number of CPUs)");
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000101
Eilon Greenstein19680c42008-08-13 15:47:33 -0700102static int disable_tpa;
James M Leddy1c8bb762014-02-04 15:10:59 -0500103module_param(disable_tpa, int, S_IRUGO);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000104MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000105
stephen hemmingera8f47eb2014-01-09 22:20:11 -0800106static int int_mode;
James M Leddy1c8bb762014-02-04 15:10:59 -0500107module_param(int_mode, int, S_IRUGO);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300108MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000109 "(1 INT#x; 2 MSI)");
Eilon Greenstein8badd272009-02-12 08:36:15 +0000110
Eilon Greensteina18f5122009-08-12 08:23:26 +0000111static int dropless_fc;
James M Leddy1c8bb762014-02-04 15:10:59 -0500112module_param(dropless_fc, int, S_IRUGO);
Eilon Greensteina18f5122009-08-12 08:23:26 +0000113MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
114
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000115static int mrrs = -1;
James M Leddy1c8bb762014-02-04 15:10:59 -0500116module_param(mrrs, int, S_IRUGO);
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000117MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
118
Eilon Greenstein9898f862009-02-12 08:38:27 +0000119static int debug;
James M Leddy1c8bb762014-02-04 15:10:59 -0500120module_param(debug, int, S_IRUGO);
Eilon Greenstein9898f862009-02-12 08:38:27 +0000121MODULE_PARM_DESC(debug, " Default debug msglevel");
122
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300123struct workqueue_struct *bnx2x_wq;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000124
Barak Witkowski1ef1d452013-01-10 04:53:40 +0000125struct bnx2x_mac_vals {
126 u32 xmac_addr;
127 u32 xmac_val;
128 u32 emac_addr;
129 u32 emac_val;
130 u32 umac_addr;
131 u32 umac_val;
132 u32 bmac_addr;
133 u32 bmac_val[2];
134};
135
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200136enum bnx2x_board_type {
137 BCM57710 = 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300138 BCM57711,
139 BCM57711E,
140 BCM57712,
141 BCM57712_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000142 BCM57712_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300143 BCM57800,
144 BCM57800_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000145 BCM57800_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300146 BCM57810,
147 BCM57810_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000148 BCM57810_VF,
Yuval Mintzc3def942012-07-23 10:25:43 +0300149 BCM57840_4_10,
150 BCM57840_2_20,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000151 BCM57840_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000152 BCM57840_VF,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000153 BCM57811,
Ariel Elior1ab44342013-01-01 05:22:23 +0000154 BCM57811_MF,
155 BCM57840_O,
156 BCM57840_MFO,
157 BCM57811_VF
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200158};
159
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700160/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800161static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200162 char *name;
Bill Pemberton0329aba2012-12-03 09:24:24 -0500163} board_info[] = {
Ariel Elior1ab44342013-01-01 05:22:23 +0000164 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
165 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
166 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
167 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
168 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
169 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
170 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
171 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
172 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
173 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
174 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
175 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
176 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
177 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
178 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
179 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
180 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
181 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
182 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
183 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
184 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200185};
186
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300187#ifndef PCI_DEVICE_ID_NX2_57710
188#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
189#endif
190#ifndef PCI_DEVICE_ID_NX2_57711
191#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
192#endif
193#ifndef PCI_DEVICE_ID_NX2_57711E
194#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
195#endif
196#ifndef PCI_DEVICE_ID_NX2_57712
197#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
198#endif
199#ifndef PCI_DEVICE_ID_NX2_57712_MF
200#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
201#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000202#ifndef PCI_DEVICE_ID_NX2_57712_VF
203#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
204#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300205#ifndef PCI_DEVICE_ID_NX2_57800
206#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
207#endif
208#ifndef PCI_DEVICE_ID_NX2_57800_MF
209#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
210#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000211#ifndef PCI_DEVICE_ID_NX2_57800_VF
212#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
213#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300214#ifndef PCI_DEVICE_ID_NX2_57810
215#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
216#endif
217#ifndef PCI_DEVICE_ID_NX2_57810_MF
218#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
219#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300220#ifndef PCI_DEVICE_ID_NX2_57840_O
221#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
222#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000223#ifndef PCI_DEVICE_ID_NX2_57810_VF
224#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
225#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300226#ifndef PCI_DEVICE_ID_NX2_57840_4_10
227#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
228#endif
229#ifndef PCI_DEVICE_ID_NX2_57840_2_20
230#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
231#endif
232#ifndef PCI_DEVICE_ID_NX2_57840_MFO
233#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300234#endif
235#ifndef PCI_DEVICE_ID_NX2_57840_MF
236#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
237#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000238#ifndef PCI_DEVICE_ID_NX2_57840_VF
239#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
240#endif
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000241#ifndef PCI_DEVICE_ID_NX2_57811
242#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
243#endif
244#ifndef PCI_DEVICE_ID_NX2_57811_MF
245#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
246#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000247#ifndef PCI_DEVICE_ID_NX2_57811_VF
248#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
249#endif
250
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000251static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000252 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
Ariel Elior8395be52013-01-01 05:22:44 +0000266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200273 { 0 }
274};
275
276MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
277
Yuval Mintz452427b2012-03-26 20:47:07 +0000278/* Global resources for unloading a previously loaded device */
279#define BNX2X_PREV_WAIT_NEEDED 1
280static DEFINE_SEMAPHORE(bnx2x_prev_sem);
281static LIST_HEAD(bnx2x_prev_list);
stephen hemmingera8f47eb2014-01-09 22:20:11 -0800282
283/* Forward declaration */
284static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
285static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
286static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
287
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200288/****************************************************************************
289* General service functions
290****************************************************************************/
291
Eric Dumazet1191cb82012-04-27 21:39:21 +0000292static void __storm_memset_dma_mapping(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300293 u32 addr, dma_addr_t mapping)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000294{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300295 REG_WR(bp, addr, U64_LO(mapping));
296 REG_WR(bp, addr + 4, U64_HI(mapping));
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000297}
298
Eric Dumazet1191cb82012-04-27 21:39:21 +0000299static void storm_memset_spq_addr(struct bnx2x *bp,
300 dma_addr_t mapping, u16 abs_fid)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300301{
302 u32 addr = XSEM_REG_FAST_MEMORY +
303 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
304
305 __storm_memset_dma_mapping(bp, addr, mapping);
306}
307
Eric Dumazet1191cb82012-04-27 21:39:21 +0000308static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
309 u16 pf_id)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300310{
311 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
312 pf_id);
313 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
314 pf_id);
315 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
316 pf_id);
317 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
318 pf_id);
319}
320
Eric Dumazet1191cb82012-04-27 21:39:21 +0000321static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
322 u8 enable)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300323{
324 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
325 enable);
326 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
327 enable);
328 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
329 enable);
330 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
331 enable);
332}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000333
Eric Dumazet1191cb82012-04-27 21:39:21 +0000334static void storm_memset_eq_data(struct bnx2x *bp,
335 struct event_ring_data *eq_data,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000336 u16 pfid)
337{
338 size_t size = sizeof(struct event_ring_data);
339
340 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
341
342 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
343}
344
Eric Dumazet1191cb82012-04-27 21:39:21 +0000345static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
346 u16 pfid)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000347{
348 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
349 REG_WR16(bp, addr, eq_prod);
350}
351
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200352/* used only at init
353 * locking is done by mcp
354 */
stephen hemminger8d962862010-10-21 07:50:56 +0000355static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200356{
357 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
358 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
359 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
360 PCICFG_VENDOR_ID_OFFSET);
361}
362
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200363static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
364{
365 u32 val;
366
367 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
368 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
369 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
370 PCICFG_VENDOR_ID_OFFSET);
371
372 return val;
373}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200374
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000375#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
376#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
377#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
378#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
379#define DMAE_DP_DST_NONE "dst_addr [none]"
380
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000381static void bnx2x_dp_dmae(struct bnx2x *bp,
382 struct dmae_command *dmae, int msglvl)
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000383{
384 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000385 int i;
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000386
387 switch (dmae->opcode & DMAE_COMMAND_DST) {
388 case DMAE_CMD_DST_PCI:
389 if (src_type == DMAE_CMD_SRC_PCI)
390 DP(msglvl, "DMAE: opcode 0x%08x\n"
391 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
392 "comp_addr [%x:%08x], comp_val 0x%08x\n",
393 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
394 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
395 dmae->comp_addr_hi, dmae->comp_addr_lo,
396 dmae->comp_val);
397 else
398 DP(msglvl, "DMAE: opcode 0x%08x\n"
399 "src [%08x], len [%d*4], dst [%x:%08x]\n"
400 "comp_addr [%x:%08x], comp_val 0x%08x\n",
401 dmae->opcode, dmae->src_addr_lo >> 2,
402 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
403 dmae->comp_addr_hi, dmae->comp_addr_lo,
404 dmae->comp_val);
405 break;
406 case DMAE_CMD_DST_GRC:
407 if (src_type == DMAE_CMD_SRC_PCI)
408 DP(msglvl, "DMAE: opcode 0x%08x\n"
409 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
410 "comp_addr [%x:%08x], comp_val 0x%08x\n",
411 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
412 dmae->len, dmae->dst_addr_lo >> 2,
413 dmae->comp_addr_hi, dmae->comp_addr_lo,
414 dmae->comp_val);
415 else
416 DP(msglvl, "DMAE: opcode 0x%08x\n"
417 "src [%08x], len [%d*4], dst [%08x]\n"
418 "comp_addr [%x:%08x], comp_val 0x%08x\n",
419 dmae->opcode, dmae->src_addr_lo >> 2,
420 dmae->len, dmae->dst_addr_lo >> 2,
421 dmae->comp_addr_hi, dmae->comp_addr_lo,
422 dmae->comp_val);
423 break;
424 default:
425 if (src_type == DMAE_CMD_SRC_PCI)
426 DP(msglvl, "DMAE: opcode 0x%08x\n"
427 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
428 "comp_addr [%x:%08x] comp_val 0x%08x\n",
429 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
430 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
431 dmae->comp_val);
432 else
433 DP(msglvl, "DMAE: opcode 0x%08x\n"
434 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
435 "comp_addr [%x:%08x] comp_val 0x%08x\n",
436 dmae->opcode, dmae->src_addr_lo >> 2,
437 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
438 dmae->comp_val);
439 break;
440 }
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000441
442 for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
443 DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
444 i, *(((u32 *)dmae) + i));
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000445}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000446
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200447/* copy command into DMAE command memory and set DMAE command go */
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000448void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200449{
450 u32 cmd_offset;
451 int i;
452
453 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
454 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
455 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200456 }
457 REG_WR(bp, dmae_reg_go_c[idx], 1);
458}
459
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000460u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
461{
462 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
463 DMAE_CMD_C_ENABLE);
464}
465
466u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
467{
468 return opcode & ~DMAE_CMD_SRC_RESET;
469}
470
471u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
472 bool with_comp, u8 comp_type)
473{
474 u32 opcode = 0;
475
476 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
477 (dst_type << DMAE_COMMAND_DST_SHIFT));
478
479 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
480
481 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
David S. Miller8decf862011-09-22 03:23:13 -0400482 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
483 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000484 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
485
486#ifdef __BIG_ENDIAN
487 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
488#else
489 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
490#endif
491 if (with_comp)
492 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
493 return opcode;
494}
495
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000496void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
stephen hemminger8d962862010-10-21 07:50:56 +0000497 struct dmae_command *dmae,
498 u8 src_type, u8 dst_type)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000499{
500 memset(dmae, 0, sizeof(struct dmae_command));
501
502 /* set the opcode */
503 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
504 true, DMAE_COMP_PCI);
505
506 /* fill in the completion parameters */
507 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
508 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
509 dmae->comp_val = DMAE_COMP_VAL;
510}
511
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000512/* issue a dmae command over the init-channel and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200513int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
514 u32 *comp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000515{
Dmitry Kravkov5e374b52011-05-22 10:09:19 +0000516 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000517 int rc = 0;
518
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000519 bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
520
521 /* Lock the dmae channel. Disable BHs to prevent a dead-lock
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300522 * as long as this code is called both from syscall context and
523 * from ndo_set_rx_mode() flow that may be called from BH.
524 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800525 spin_lock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000526
527 /* reset completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200528 *comp = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000529
530 /* post the command on the channel used for initializations */
531 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
532
533 /* wait for completion */
534 udelay(5);
Ariel Elior32316a42013-10-20 16:51:32 +0200535 while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000536
Ariel Elior95c6c6162012-01-26 06:01:52 +0000537 if (!cnt ||
538 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
539 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000540 BNX2X_ERR("DMAE timeout!\n");
541 rc = DMAE_TIMEOUT;
542 goto unlock;
543 }
544 cnt--;
545 udelay(50);
546 }
Ariel Elior32316a42013-10-20 16:51:32 +0200547 if (*comp & DMAE_PCI_ERR_FLAG) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000548 BNX2X_ERR("DMAE PCI error!\n");
549 rc = DMAE_PCI_ERROR;
550 }
551
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000552unlock:
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800553 spin_unlock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000554 return rc;
555}
556
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700557void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
558 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200559{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000560 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000561 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700562
563 if (!bp->dmae_ready) {
564 u32 *data = bnx2x_sp(bp, wb_data[0]);
565
Ariel Elior127a4252012-01-26 06:01:46 +0000566 if (CHIP_IS_E1(bp))
567 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
568 else
569 bnx2x_init_str_wr(bp, dst_addr, data, len32);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700570 return;
571 }
572
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000573 /* set opcode and fixed command fields */
574 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200575
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000576 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000577 dmae.src_addr_lo = U64_LO(dma_addr);
578 dmae.src_addr_hi = U64_HI(dma_addr);
579 dmae.dst_addr_lo = dst_addr >> 2;
580 dmae.dst_addr_hi = 0;
581 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200582
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000583 /* issue the command and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200584 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000585 if (rc) {
586 BNX2X_ERR("DMAE returned failure %d\n", rc);
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200587#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000588 bnx2x_panic();
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200589#endif
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000590 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200591}
592
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700593void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200594{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000595 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000596 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700597
598 if (!bp->dmae_ready) {
599 u32 *data = bnx2x_sp(bp, wb_data[0]);
600 int i;
601
Merav Sicron51c1a582012-03-18 10:33:38 +0000602 if (CHIP_IS_E1(bp))
Ariel Elior127a4252012-01-26 06:01:46 +0000603 for (i = 0; i < len32; i++)
604 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
Merav Sicron51c1a582012-03-18 10:33:38 +0000605 else
Ariel Elior127a4252012-01-26 06:01:46 +0000606 for (i = 0; i < len32; i++)
607 data[i] = REG_RD(bp, src_addr + i*4);
608
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700609 return;
610 }
611
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000612 /* set opcode and fixed command fields */
613 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200614
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000615 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000616 dmae.src_addr_lo = src_addr >> 2;
617 dmae.src_addr_hi = 0;
618 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
619 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
620 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200621
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000622 /* issue the command and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200623 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000624 if (rc) {
625 BNX2X_ERR("DMAE returned failure %d\n", rc);
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200626#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000627 bnx2x_panic();
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200628#endif
Yuval Mintzc957d092013-06-25 08:50:11 +0300629 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200630}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200631
stephen hemminger8d962862010-10-21 07:50:56 +0000632static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
633 u32 addr, u32 len)
Eilon Greenstein573f2032009-08-12 08:24:14 +0000634{
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000635 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
Eilon Greenstein573f2032009-08-12 08:24:14 +0000636 int offset = 0;
637
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000638 while (len > dmae_wr_max) {
Eilon Greenstein573f2032009-08-12 08:24:14 +0000639 bnx2x_write_dmae(bp, phys_addr + offset,
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000640 addr + offset, dmae_wr_max);
641 offset += dmae_wr_max * 4;
642 len -= dmae_wr_max;
Eilon Greenstein573f2032009-08-12 08:24:14 +0000643 }
644
645 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
646}
647
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200648static int bnx2x_mc_assert(struct bnx2x *bp)
649{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200650 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700651 int i, rc = 0;
652 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200653
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700654 /* XSTORM */
655 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
656 XSTORM_ASSERT_LIST_INDEX_OFFSET);
657 if (last_idx)
658 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200659
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700660 /* print the asserts */
661 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200662
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700663 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
664 XSTORM_ASSERT_LIST_OFFSET(i));
665 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
666 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
667 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
668 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
669 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
670 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200671
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700672 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000673 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700674 i, row3, row2, row1, row0);
675 rc++;
676 } else {
677 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200678 }
679 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700680
681 /* TSTORM */
682 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
683 TSTORM_ASSERT_LIST_INDEX_OFFSET);
684 if (last_idx)
685 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
686
687 /* print the asserts */
688 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
689
690 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
691 TSTORM_ASSERT_LIST_OFFSET(i));
692 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
693 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
694 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
695 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
696 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
697 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
698
699 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000700 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700701 i, row3, row2, row1, row0);
702 rc++;
703 } else {
704 break;
705 }
706 }
707
708 /* CSTORM */
709 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
710 CSTORM_ASSERT_LIST_INDEX_OFFSET);
711 if (last_idx)
712 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
713
714 /* print the asserts */
715 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
716
717 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
718 CSTORM_ASSERT_LIST_OFFSET(i));
719 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
720 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
721 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
722 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
723 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
724 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
725
726 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000727 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700728 i, row3, row2, row1, row0);
729 rc++;
730 } else {
731 break;
732 }
733 }
734
735 /* USTORM */
736 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
737 USTORM_ASSERT_LIST_INDEX_OFFSET);
738 if (last_idx)
739 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
740
741 /* print the asserts */
742 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
743
744 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
745 USTORM_ASSERT_LIST_OFFSET(i));
746 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
747 USTORM_ASSERT_LIST_OFFSET(i) + 4);
748 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
749 USTORM_ASSERT_LIST_OFFSET(i) + 8);
750 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
751 USTORM_ASSERT_LIST_OFFSET(i) + 12);
752
753 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000754 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700755 i, row3, row2, row1, row0);
756 rc++;
757 } else {
758 break;
759 }
760 }
761
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200762 return rc;
763}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800764
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200765#define MCPR_TRACE_BUFFER_SIZE (0x800)
766#define SCRATCH_BUFFER_SIZE(bp) \
767 (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
768
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000769void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200770{
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000771 u32 addr, val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200772 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000773 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200774 int word;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000775 u32 trace_shmem_base;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +0000776 if (BP_NOMCP(bp)) {
777 BNX2X_ERR("NO MCP - can not dump\n");
778 return;
779 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000780 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
781 (bp->common.bc_ver & 0xff0000) >> 16,
782 (bp->common.bc_ver & 0xff00) >> 8,
783 (bp->common.bc_ver & 0xff));
784
785 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
786 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
Merav Sicron51c1a582012-03-18 10:33:38 +0000787 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000788
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000789 if (BP_PATH(bp) == 0)
790 trace_shmem_base = bp->common.shmem_base;
791 else
792 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200793
794 /* sanity */
795 if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
796 trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
797 SCRATCH_BUFFER_SIZE(bp)) {
798 BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
799 trace_shmem_base);
800 return;
801 }
802
803 addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
Dmitry Kravkovde128802012-03-18 10:33:45 +0000804
805 /* validate TRCB signature */
806 mark = REG_RD(bp, addr);
807 if (mark != MFW_TRACE_SIGNATURE) {
808 BNX2X_ERR("Trace buffer signature is missing.");
809 return ;
810 }
811
812 /* read cyclic buffer pointer */
813 addr += 4;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000814 mark = REG_RD(bp, addr);
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200815 mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
816 if (mark >= trace_shmem_base || mark < addr + 4) {
817 BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
818 return;
819 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000820 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200821
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000822 printk("%s", lvl);
Yuval Mintz2de67432013-01-23 03:21:43 +0000823
824 /* dump buffer after the mark */
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200825 for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200826 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000827 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200828 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000829 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200830 }
Yuval Mintz2de67432013-01-23 03:21:43 +0000831
832 /* dump buffer before the mark */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000833 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200834 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000835 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200836 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000837 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200838 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000839 printk("%s" "end of fw dump\n", lvl);
840}
841
Eric Dumazet1191cb82012-04-27 21:39:21 +0000842static void bnx2x_fw_dump(struct bnx2x *bp)
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000843{
844 bnx2x_fw_dump_lvl(bp, KERN_ERR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200845}
846
Yuval Mintz823e1d92013-01-14 05:11:47 +0000847static void bnx2x_hc_int_disable(struct bnx2x *bp)
848{
849 int port = BP_PORT(bp);
850 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
851 u32 val = REG_RD(bp, addr);
852
853 /* in E1 we must use only PCI configuration space to disable
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000854 * MSI/MSIX capability
855 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
Yuval Mintz823e1d92013-01-14 05:11:47 +0000856 */
857 if (CHIP_IS_E1(bp)) {
858 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
859 * Use mask register to prevent from HC sending interrupts
860 * after we exit the function
861 */
862 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
863
864 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
865 HC_CONFIG_0_REG_INT_LINE_EN_0 |
866 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
867 } else
868 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
869 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
870 HC_CONFIG_0_REG_INT_LINE_EN_0 |
871 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
872
873 DP(NETIF_MSG_IFDOWN,
874 "write %x to HC %d (addr 0x%x)\n",
875 val, port, addr);
876
877 /* flush all outstanding writes */
878 mmiowb();
879
880 REG_WR(bp, addr, val);
881 if (REG_RD(bp, addr) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000882 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000883}
884
885static void bnx2x_igu_int_disable(struct bnx2x *bp)
886{
887 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
888
889 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
890 IGU_PF_CONF_INT_LINE_EN |
891 IGU_PF_CONF_ATTN_BIT_EN);
892
893 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
894
895 /* flush all outstanding writes */
896 mmiowb();
897
898 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
899 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000900 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000901}
902
903static void bnx2x_int_disable(struct bnx2x *bp)
904{
905 if (bp->common.int_block == INT_BLOCK_HC)
906 bnx2x_hc_int_disable(bp);
907 else
908 bnx2x_igu_int_disable(bp);
909}
910
911void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200912{
913 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000914 u16 j;
915 struct hc_sp_status_block_data sp_sb_data;
916 int func = BP_FUNC(bp);
917#ifdef BNX2X_STOP_ON_ERROR
918 u16 start = 0, end = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000919 u8 cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000920#endif
Yuval Mintz0155a272014-02-12 18:19:55 +0200921 if (IS_PF(bp) && disable_int)
Yuval Mintz823e1d92013-01-14 05:11:47 +0000922 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200923
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700924 bp->stats_state = STATS_STATE_DISABLED;
Ariel Elior7a752992012-01-26 06:01:53 +0000925 bp->eth_stats.unrecoverable_error++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700926 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
927
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200928 BNX2X_ERR("begin crash dump -----------------\n");
929
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000930 /* Indices */
931 /* Common */
Yuval Mintz0155a272014-02-12 18:19:55 +0200932 if (IS_PF(bp)) {
933 struct host_sp_status_block *def_sb = bp->def_status_blk;
934 int data_size, cstorm_offset;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000935
Yuval Mintz0155a272014-02-12 18:19:55 +0200936 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",
937 bp->def_idx, bp->def_att_idx, bp->attn_state,
938 bp->spq_prod_idx, bp->stats_counter);
939 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
940 def_sb->atten_status_block.attn_bits,
941 def_sb->atten_status_block.attn_bits_ack,
942 def_sb->atten_status_block.status_block_id,
943 def_sb->atten_status_block.attn_bits_index);
944 BNX2X_ERR(" def (");
945 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
946 pr_cont("0x%x%s",
947 def_sb->sp_sb.index_values[i],
948 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000949
Yuval Mintz0155a272014-02-12 18:19:55 +0200950 data_size = sizeof(struct hc_sp_status_block_data) /
951 sizeof(u32);
952 cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
953 for (i = 0; i < data_size; i++)
954 *((u32 *)&sp_sb_data + i) =
955 REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
956 i * sizeof(u32));
957
958 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",
959 sp_sb_data.igu_sb_id,
960 sp_sb_data.igu_seg_id,
961 sp_sb_data.p_func.pf_id,
962 sp_sb_data.p_func.vnic_id,
963 sp_sb_data.p_func.vf_id,
964 sp_sb_data.p_func.vf_valid,
965 sp_sb_data.state);
966 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000967
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000968 for_each_eth_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000969 struct bnx2x_fastpath *fp = &bp->fp[i];
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000970 int loop;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000971 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000972 struct hc_status_block_data_e1x sb_data_e1x;
973 struct hc_status_block_sm *hc_sm_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300974 CHIP_IS_E1x(bp) ?
975 sb_data_e1x.common.state_machine :
976 sb_data_e2.common.state_machine;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000977 struct hc_index_data *hc_index_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300978 CHIP_IS_E1x(bp) ?
979 sb_data_e1x.index_data :
980 sb_data_e2.index_data;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000981 u8 data_size, cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000982 u32 *sb_data_p;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000983 struct bnx2x_fp_txdata txdata;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000984
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000985 /* Rx */
Merav Sicron51c1a582012-03-18 10:33:38 +0000986 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 +0000987 i, fp->rx_bd_prod, fp->rx_bd_cons,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000988 fp->rx_comp_prod,
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000989 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Merav Sicron51c1a582012-03-18 10:33:38 +0000990 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 +0000991 fp->rx_sge_prod, fp->last_max_sge,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000992 le16_to_cpu(fp->fp_hc_idx));
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000993
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000994 /* Tx */
Ariel Elior6383c0b2011-07-14 08:31:57 +0000995 for_each_cos_in_tx_queue(fp, cos)
996 {
Merav Sicron65565882012-06-19 07:48:26 +0000997 txdata = *fp->txdata_ptr[cos];
Merav Sicron51c1a582012-03-18 10:33:38 +0000998 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 +0000999 i, txdata.tx_pkt_prod,
1000 txdata.tx_pkt_cons, txdata.tx_bd_prod,
1001 txdata.tx_bd_cons,
1002 le16_to_cpu(*txdata.tx_cons_sb));
1003 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001004
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001005 loop = CHIP_IS_E1x(bp) ?
1006 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001007
1008 /* host sb data */
1009
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001010 if (IS_FCOE_FP(fp))
1011 continue;
Merav Sicron55c11942012-11-07 00:45:48 +00001012
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001013 BNX2X_ERR(" run indexes (");
1014 for (j = 0; j < HC_SB_MAX_SM; j++)
1015 pr_cont("0x%x%s",
1016 fp->sb_running_index[j],
1017 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
1018
1019 BNX2X_ERR(" indexes (");
1020 for (j = 0; j < loop; j++)
1021 pr_cont("0x%x%s",
1022 fp->sb_index_values[j],
1023 (j == loop - 1) ? ")" : " ");
Yuval Mintz0155a272014-02-12 18:19:55 +02001024
1025 /* VF cannot access FW refelection for status block */
1026 if (IS_VF(bp))
1027 continue;
1028
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001029 /* fw sb data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001030 data_size = CHIP_IS_E1x(bp) ?
1031 sizeof(struct hc_status_block_data_e1x) :
1032 sizeof(struct hc_status_block_data_e2);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001033 data_size /= sizeof(u32);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001034 sb_data_p = CHIP_IS_E1x(bp) ?
1035 (u32 *)&sb_data_e1x :
1036 (u32 *)&sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001037 /* copy sb data in here */
1038 for (j = 0; j < data_size; j++)
1039 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
1040 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
1041 j * sizeof(u32));
1042
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001043 if (!CHIP_IS_E1x(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001044 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 +00001045 sb_data_e2.common.p_func.pf_id,
1046 sb_data_e2.common.p_func.vf_id,
1047 sb_data_e2.common.p_func.vf_valid,
1048 sb_data_e2.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001049 sb_data_e2.common.same_igu_sb_1b,
1050 sb_data_e2.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001051 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00001052 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 +00001053 sb_data_e1x.common.p_func.pf_id,
1054 sb_data_e1x.common.p_func.vf_id,
1055 sb_data_e1x.common.p_func.vf_valid,
1056 sb_data_e1x.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001057 sb_data_e1x.common.same_igu_sb_1b,
1058 sb_data_e1x.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001059 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001060
1061 /* SB_SMs data */
1062 for (j = 0; j < HC_SB_MAX_SM; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001063 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",
1064 j, hc_sm_p[j].__flags,
1065 hc_sm_p[j].igu_sb_id,
1066 hc_sm_p[j].igu_seg_id,
1067 hc_sm_p[j].time_to_expire,
1068 hc_sm_p[j].timer_value);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001069 }
1070
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001071 /* Indices data */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001072 for (j = 0; j < loop; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001073 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001074 hc_index_p[j].flags,
1075 hc_index_p[j].timeout);
1076 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001077 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001078
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001079#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz0155a272014-02-12 18:19:55 +02001080 if (IS_PF(bp)) {
1081 /* event queue */
1082 BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
1083 for (i = 0; i < NUM_EQ_DESC; i++) {
1084 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
Yuval Mintz04c46732013-01-23 03:21:46 +00001085
Yuval Mintz0155a272014-02-12 18:19:55 +02001086 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1087 i, bp->eq_ring[i].message.opcode,
1088 bp->eq_ring[i].message.error);
1089 BNX2X_ERR("data: %x %x %x\n",
1090 data[0], data[1], data[2]);
1091 }
Yuval Mintz04c46732013-01-23 03:21:46 +00001092 }
1093
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001094 /* Rings */
1095 /* Rx */
Merav Sicron55c11942012-11-07 00:45:48 +00001096 for_each_valid_rx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001097 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001098
1099 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1100 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001101 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001102 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1103 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1104
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001105 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
Yuval Mintz44151ac2012-01-23 07:31:56 +00001106 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001107 }
1108
Eilon Greenstein3196a882008-08-13 15:58:49 -07001109 start = RX_SGE(fp->rx_sge_prod);
1110 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001111 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001112 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1113 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1114
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001115 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1116 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001117 }
1118
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001119 start = RCQ_BD(fp->rx_comp_cons - 10);
1120 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001121 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001122 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1123
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001124 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1125 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001126 }
1127 }
1128
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001129 /* Tx */
Merav Sicron55c11942012-11-07 00:45:48 +00001130 for_each_valid_tx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001131 struct bnx2x_fastpath *fp = &bp->fp[i];
Ariel Elior6383c0b2011-07-14 08:31:57 +00001132 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00001133 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001134
Ariel Elior6383c0b2011-07-14 08:31:57 +00001135 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1136 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1137 for (j = start; j != end; j = TX_BD(j + 1)) {
1138 struct sw_tx_bd *sw_bd =
1139 &txdata->tx_buf_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001140
Merav Sicron51c1a582012-03-18 10:33:38 +00001141 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001142 i, cos, j, sw_bd->skb,
1143 sw_bd->first_bd);
1144 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001145
Ariel Elior6383c0b2011-07-14 08:31:57 +00001146 start = TX_BD(txdata->tx_bd_cons - 10);
1147 end = TX_BD(txdata->tx_bd_cons + 254);
1148 for (j = start; j != end; j = TX_BD(j + 1)) {
1149 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001150
Merav Sicron51c1a582012-03-18 10:33:38 +00001151 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001152 i, cos, j, tx_bd[0], tx_bd[1],
1153 tx_bd[2], tx_bd[3]);
1154 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001155 }
1156 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001157#endif
Yuval Mintz0155a272014-02-12 18:19:55 +02001158 if (IS_PF(bp)) {
1159 bnx2x_fw_dump(bp);
1160 bnx2x_mc_assert(bp);
1161 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001162 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001163}
1164
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001165/*
1166 * FLR Support for E2
1167 *
1168 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1169 * initialization.
1170 */
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001171#define FLR_WAIT_USEC 10000 /* 10 milliseconds */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001172#define FLR_WAIT_INTERVAL 50 /* usec */
1173#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001174
1175struct pbf_pN_buf_regs {
1176 int pN;
1177 u32 init_crd;
1178 u32 crd;
1179 u32 crd_freed;
1180};
1181
1182struct pbf_pN_cmd_regs {
1183 int pN;
1184 u32 lines_occup;
1185 u32 lines_freed;
1186};
1187
1188static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1189 struct pbf_pN_buf_regs *regs,
1190 u32 poll_count)
1191{
1192 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1193 u32 cur_cnt = poll_count;
1194
1195 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1196 crd = crd_start = REG_RD(bp, regs->crd);
1197 init_crd = REG_RD(bp, regs->init_crd);
1198
1199 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1200 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1201 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1202
1203 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1204 (init_crd - crd_start))) {
1205 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001206 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001207 crd = REG_RD(bp, regs->crd);
1208 crd_freed = REG_RD(bp, regs->crd_freed);
1209 } else {
1210 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1211 regs->pN);
1212 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1213 regs->pN, crd);
1214 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1215 regs->pN, crd_freed);
1216 break;
1217 }
1218 }
1219 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001220 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001221}
1222
1223static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1224 struct pbf_pN_cmd_regs *regs,
1225 u32 poll_count)
1226{
1227 u32 occup, to_free, freed, freed_start;
1228 u32 cur_cnt = poll_count;
1229
1230 occup = to_free = REG_RD(bp, regs->lines_occup);
1231 freed = freed_start = REG_RD(bp, regs->lines_freed);
1232
1233 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1234 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1235
1236 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1237 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001238 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001239 occup = REG_RD(bp, regs->lines_occup);
1240 freed = REG_RD(bp, regs->lines_freed);
1241 } else {
1242 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1243 regs->pN);
1244 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1245 regs->pN, occup);
1246 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1247 regs->pN, freed);
1248 break;
1249 }
1250 }
1251 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001252 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001253}
1254
Eric Dumazet1191cb82012-04-27 21:39:21 +00001255static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1256 u32 expected, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001257{
1258 u32 cur_cnt = poll_count;
1259 u32 val;
1260
1261 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
Ariel Elior89db4ad2012-01-26 06:01:48 +00001262 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001263
1264 return val;
1265}
1266
Ariel Eliord16132c2013-01-01 05:22:42 +00001267int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1268 char *msg, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001269{
1270 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1271 if (val != 0) {
1272 BNX2X_ERR("%s usage count=%d\n", msg, val);
1273 return 1;
1274 }
1275 return 0;
1276}
1277
Ariel Eliord16132c2013-01-01 05:22:42 +00001278/* Common routines with VF FLR cleanup */
1279u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001280{
1281 /* adjust polling timeout */
1282 if (CHIP_REV_IS_EMUL(bp))
1283 return FLR_POLL_CNT * 2000;
1284
1285 if (CHIP_REV_IS_FPGA(bp))
1286 return FLR_POLL_CNT * 120;
1287
1288 return FLR_POLL_CNT;
1289}
1290
Ariel Eliord16132c2013-01-01 05:22:42 +00001291void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001292{
1293 struct pbf_pN_cmd_regs cmd_regs[] = {
1294 {0, (CHIP_IS_E3B0(bp)) ?
1295 PBF_REG_TQ_OCCUPANCY_Q0 :
1296 PBF_REG_P0_TQ_OCCUPANCY,
1297 (CHIP_IS_E3B0(bp)) ?
1298 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1299 PBF_REG_P0_TQ_LINES_FREED_CNT},
1300 {1, (CHIP_IS_E3B0(bp)) ?
1301 PBF_REG_TQ_OCCUPANCY_Q1 :
1302 PBF_REG_P1_TQ_OCCUPANCY,
1303 (CHIP_IS_E3B0(bp)) ?
1304 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1305 PBF_REG_P1_TQ_LINES_FREED_CNT},
1306 {4, (CHIP_IS_E3B0(bp)) ?
1307 PBF_REG_TQ_OCCUPANCY_LB_Q :
1308 PBF_REG_P4_TQ_OCCUPANCY,
1309 (CHIP_IS_E3B0(bp)) ?
1310 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1311 PBF_REG_P4_TQ_LINES_FREED_CNT}
1312 };
1313
1314 struct pbf_pN_buf_regs buf_regs[] = {
1315 {0, (CHIP_IS_E3B0(bp)) ?
1316 PBF_REG_INIT_CRD_Q0 :
1317 PBF_REG_P0_INIT_CRD ,
1318 (CHIP_IS_E3B0(bp)) ?
1319 PBF_REG_CREDIT_Q0 :
1320 PBF_REG_P0_CREDIT,
1321 (CHIP_IS_E3B0(bp)) ?
1322 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1323 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1324 {1, (CHIP_IS_E3B0(bp)) ?
1325 PBF_REG_INIT_CRD_Q1 :
1326 PBF_REG_P1_INIT_CRD,
1327 (CHIP_IS_E3B0(bp)) ?
1328 PBF_REG_CREDIT_Q1 :
1329 PBF_REG_P1_CREDIT,
1330 (CHIP_IS_E3B0(bp)) ?
1331 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1332 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1333 {4, (CHIP_IS_E3B0(bp)) ?
1334 PBF_REG_INIT_CRD_LB_Q :
1335 PBF_REG_P4_INIT_CRD,
1336 (CHIP_IS_E3B0(bp)) ?
1337 PBF_REG_CREDIT_LB_Q :
1338 PBF_REG_P4_CREDIT,
1339 (CHIP_IS_E3B0(bp)) ?
1340 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1341 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1342 };
1343
1344 int i;
1345
1346 /* Verify the command queues are flushed P0, P1, P4 */
1347 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1348 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1349
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001350 /* Verify the transmission buffers are flushed P0, P1, P4 */
1351 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1352 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1353}
1354
1355#define OP_GEN_PARAM(param) \
1356 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1357
1358#define OP_GEN_TYPE(type) \
1359 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1360
1361#define OP_GEN_AGG_VECT(index) \
1362 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1363
Ariel Eliord16132c2013-01-01 05:22:42 +00001364int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001365{
Yuval Mintz86564c32013-01-23 03:21:50 +00001366 u32 op_gen_command = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001367 u32 comp_addr = BAR_CSTRORM_INTMEM +
1368 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1369 int ret = 0;
1370
1371 if (REG_RD(bp, comp_addr)) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001372 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001373 return 1;
1374 }
1375
Yuval Mintz86564c32013-01-23 03:21:50 +00001376 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1377 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1378 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1379 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001380
Ariel Elior89db4ad2012-01-26 06:01:48 +00001381 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
Yuval Mintz86564c32013-01-23 03:21:50 +00001382 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001383
1384 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1385 BNX2X_ERR("FW final cleanup did not succeed\n");
Merav Sicron51c1a582012-03-18 10:33:38 +00001386 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1387 (REG_RD(bp, comp_addr)));
Ariel Eliord16132c2013-01-01 05:22:42 +00001388 bnx2x_panic();
1389 return 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001390 }
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001391 /* Zero completion for next FLR */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001392 REG_WR(bp, comp_addr, 0);
1393
1394 return ret;
1395}
1396
Ariel Eliorb56e9672013-01-01 05:22:32 +00001397u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001398{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001399 u16 status;
1400
Jiang Liu2a80eeb2012-08-20 13:26:51 -06001401 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001402 return status & PCI_EXP_DEVSTA_TRPND;
1403}
1404
1405/* PF FLR specific routines
1406*/
1407static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1408{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001409 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1410 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1411 CFC_REG_NUM_LCIDS_INSIDE_PF,
1412 "CFC PF usage counter timed out",
1413 poll_cnt))
1414 return 1;
1415
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001416 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1417 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1418 DORQ_REG_PF_USAGE_CNT,
1419 "DQ PF usage counter timed out",
1420 poll_cnt))
1421 return 1;
1422
1423 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1424 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1425 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1426 "QM PF usage counter timed out",
1427 poll_cnt))
1428 return 1;
1429
1430 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1431 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1432 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1433 "Timers VNIC usage counter timed out",
1434 poll_cnt))
1435 return 1;
1436 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1437 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1438 "Timers NUM_SCANS usage counter timed out",
1439 poll_cnt))
1440 return 1;
1441
1442 /* Wait DMAE PF usage counter to zero */
1443 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1444 dmae_reg_go_c[INIT_DMAE_C(bp)],
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001445 "DMAE command register timed out",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001446 poll_cnt))
1447 return 1;
1448
1449 return 0;
1450}
1451
1452static void bnx2x_hw_enable_status(struct bnx2x *bp)
1453{
1454 u32 val;
1455
1456 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1457 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1458
1459 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1460 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1461
1462 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1463 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1464
1465 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1466 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1467
1468 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1469 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1470
1471 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1472 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1473
1474 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1475 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1476
1477 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1478 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1479 val);
1480}
1481
1482static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1483{
1484 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1485
1486 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1487
1488 /* Re-enable PF target read access */
1489 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1490
1491 /* Poll HW usage counters */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001492 DP(BNX2X_MSG_SP, "Polling usage counters\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001493 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1494 return -EBUSY;
1495
1496 /* Zero the igu 'trailing edge' and 'leading edge' */
1497
1498 /* Send the FW cleanup command */
1499 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1500 return -EBUSY;
1501
1502 /* ATC cleanup */
1503
1504 /* Verify TX hw is flushed */
1505 bnx2x_tx_hw_flushed(bp, poll_cnt);
1506
1507 /* Wait 100ms (not adjusted according to platform) */
1508 msleep(100);
1509
1510 /* Verify no pending pci transactions */
1511 if (bnx2x_is_pcie_pending(bp->pdev))
1512 BNX2X_ERR("PCIE Transactions still pending\n");
1513
1514 /* Debug */
1515 bnx2x_hw_enable_status(bp);
1516
1517 /*
1518 * Master enable - Due to WB DMAE writes performed before this
1519 * register is re-initialized as part of the regular function init
1520 */
1521 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1522
1523 return 0;
1524}
1525
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001526static void bnx2x_hc_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001527{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001528 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001529 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1530 u32 val = REG_RD(bp, addr);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001531 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1532 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1533 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001534
1535 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001536 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1537 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001538 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1539 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001540 if (single_msix)
1541 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001542 } else if (msi) {
1543 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1544 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1545 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1546 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001547 } else {
1548 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001549 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001550 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1551 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001552
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001553 if (!CHIP_IS_E1(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001554 DP(NETIF_MSG_IFUP,
1555 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001556
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001557 REG_WR(bp, addr, val);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001558
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001559 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1560 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001561 }
1562
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001563 if (CHIP_IS_E1(bp))
1564 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1565
Merav Sicron51c1a582012-03-18 10:33:38 +00001566 DP(NETIF_MSG_IFUP,
1567 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1568 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001569
1570 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001571 /*
1572 * Ensure that HC_CONFIG is written before leading/trailing edge config
1573 */
1574 mmiowb();
1575 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001576
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001577 if (!CHIP_IS_E1(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001578 /* init leading/trailing edge */
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00001579 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001580 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001581 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001582 /* enable nig and gpio3 attention */
1583 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001584 } else
1585 val = 0xffff;
1586
1587 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1588 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1589 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001590
1591 /* Make sure that interrupts are indeed enabled from here on */
1592 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001593}
1594
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001595static void bnx2x_igu_int_enable(struct bnx2x *bp)
1596{
1597 u32 val;
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001598 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1599 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1600 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001601
1602 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1603
1604 if (msix) {
1605 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1606 IGU_PF_CONF_SINGLE_ISR_EN);
Yuval Mintzebe61d82013-01-14 05:11:48 +00001607 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001608 IGU_PF_CONF_ATTN_BIT_EN);
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001609
1610 if (single_msix)
1611 val |= IGU_PF_CONF_SINGLE_ISR_EN;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001612 } else if (msi) {
1613 val &= ~IGU_PF_CONF_INT_LINE_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001614 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001615 IGU_PF_CONF_ATTN_BIT_EN |
1616 IGU_PF_CONF_SINGLE_ISR_EN);
1617 } else {
1618 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001619 val |= (IGU_PF_CONF_INT_LINE_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001620 IGU_PF_CONF_ATTN_BIT_EN |
1621 IGU_PF_CONF_SINGLE_ISR_EN);
1622 }
1623
Yuval Mintzebe61d82013-01-14 05:11:48 +00001624 /* Clean previous status - need to configure igu prior to ack*/
1625 if ((!msix) || single_msix) {
1626 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1627 bnx2x_ack_int(bp);
1628 }
1629
1630 val |= IGU_PF_CONF_FUNC_EN;
1631
Merav Sicron51c1a582012-03-18 10:33:38 +00001632 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001633 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1634
1635 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1636
Yuval Mintz79a85572012-04-03 18:41:25 +00001637 if (val & IGU_PF_CONF_INT_LINE_EN)
1638 pci_intx(bp->pdev, true);
1639
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001640 barrier();
1641
1642 /* init leading/trailing edge */
1643 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001644 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001645 if (bp->port.pmf)
1646 /* enable nig and gpio3 attention */
1647 val |= 0x1100;
1648 } else
1649 val = 0xffff;
1650
1651 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1652 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1653
1654 /* Make sure that interrupts are indeed enabled from here on */
1655 mmiowb();
1656}
1657
1658void bnx2x_int_enable(struct bnx2x *bp)
1659{
1660 if (bp->common.int_block == INT_BLOCK_HC)
1661 bnx2x_hc_int_enable(bp);
1662 else
1663 bnx2x_igu_int_enable(bp);
1664}
1665
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001666void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001667{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001668 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001669 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001670
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07001671 if (disable_hw)
1672 /* prevent the HW from sending interrupts */
1673 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001674
1675 /* make sure all ISRs are done */
1676 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001677 synchronize_irq(bp->msix_table[0].vector);
1678 offset = 1;
Merav Sicron55c11942012-11-07 00:45:48 +00001679 if (CNIC_SUPPORT(bp))
1680 offset++;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001681 for_each_eth_queue(bp, i)
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001682 synchronize_irq(bp->msix_table[offset++].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001683 } else
1684 synchronize_irq(bp->pdev->irq);
1685
1686 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001687 cancel_delayed_work(&bp->sp_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00001688 cancel_delayed_work(&bp->period_task);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001689 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001690}
1691
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001692/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001693
1694/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001695 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001696 */
1697
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001698/* Return true if succeeded to acquire the lock */
1699static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1700{
1701 u32 lock_status;
1702 u32 resource_bit = (1 << resource);
1703 int func = BP_FUNC(bp);
1704 u32 hw_lock_control_reg;
1705
Merav Sicron51c1a582012-03-18 10:33:38 +00001706 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1707 "Trying to take a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001708
1709 /* Validating that the resource is within range */
1710 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001711 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001712 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1713 resource, HW_LOCK_MAX_RESOURCE_VALUE);
Eric Dumazet0fdf4d02010-08-26 22:03:53 -07001714 return false;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001715 }
1716
1717 if (func <= 5)
1718 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1719 else
1720 hw_lock_control_reg =
1721 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1722
1723 /* Try to acquire the lock */
1724 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1725 lock_status = REG_RD(bp, hw_lock_control_reg);
1726 if (lock_status & resource_bit)
1727 return true;
1728
Merav Sicron51c1a582012-03-18 10:33:38 +00001729 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1730 "Failed to get a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001731 return false;
1732}
1733
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001734/**
1735 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1736 *
1737 * @bp: driver handle
1738 *
1739 * Returns the recovery leader resource id according to the engine this function
1740 * belongs to. Currently only only 2 engines is supported.
1741 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001742static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001743{
1744 if (BP_PATH(bp))
1745 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1746 else
1747 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1748}
1749
1750/**
Yuval Mintz2de67432013-01-23 03:21:43 +00001751 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001752 *
1753 * @bp: driver handle
1754 *
Yuval Mintz2de67432013-01-23 03:21:43 +00001755 * Tries to acquire a leader lock for current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001756 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001757static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001758{
1759 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1760}
1761
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001762static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
Merav Sicron55c11942012-11-07 00:45:48 +00001763
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001764/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1765static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1766{
1767 /* Set the interrupt occurred bit for the sp-task to recognize it
1768 * must ack the interrupt and transition according to the IGU
1769 * state machine.
1770 */
1771 atomic_set(&bp->interrupt_occurred, 1);
1772
1773 /* The sp_task must execute only after this bit
1774 * is set, otherwise we will get out of sync and miss all
1775 * further interrupts. Hence, the barrier.
1776 */
1777 smp_wmb();
1778
1779 /* schedule sp_task to workqueue */
1780 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1781}
Eilon Greenstein3196a882008-08-13 15:58:49 -07001782
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001783void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001784{
1785 struct bnx2x *bp = fp->bp;
1786 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1787 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001788 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
Barak Witkowski15192a82012-06-19 07:48:28 +00001789 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001790
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001791 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001792 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001793 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001794 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001795
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001796 /* If cid is within VF range, replace the slowpath object with the
1797 * one corresponding to this VF
1798 */
1799 if (cid >= BNX2X_FIRST_VF_CID &&
1800 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1801 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1802
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001803 switch (command) {
1804 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001805 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001806 drv_cmd = BNX2X_Q_CMD_UPDATE;
1807 break;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001808
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001809 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001810 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001811 drv_cmd = BNX2X_Q_CMD_SETUP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001812 break;
1813
Ariel Elior6383c0b2011-07-14 08:31:57 +00001814 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
Merav Sicron51c1a582012-03-18 10:33:38 +00001815 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
Ariel Elior6383c0b2011-07-14 08:31:57 +00001816 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1817 break;
1818
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001819 case (RAMROD_CMD_ID_ETH_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001820 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001821 drv_cmd = BNX2X_Q_CMD_HALT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001822 break;
1823
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001824 case (RAMROD_CMD_ID_ETH_TERMINATE):
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001825 DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001826 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1827 break;
1828
1829 case (RAMROD_CMD_ID_ETH_EMPTY):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001830 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001831 drv_cmd = BNX2X_Q_CMD_EMPTY;
Eliezer Tamir49d66772008-02-28 11:53:13 -08001832 break;
1833
Michal Kalderon14a94eb2014-02-12 18:19:53 +02001834 case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
1835 DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
1836 drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
1837 break;
1838
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001839 default:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001840 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1841 command, fp->index);
1842 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001843 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001844
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001845 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1846 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1847 /* q_obj->complete_cmd() failure means that this was
1848 * an unexpected completion.
1849 *
1850 * In this case we don't want to increase the bp->spq_left
1851 * because apparently we haven't sent this command the first
1852 * place.
1853 */
1854#ifdef BNX2X_STOP_ON_ERROR
1855 bnx2x_panic();
1856#else
1857 return;
1858#endif
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001859 /* SRIOV: reschedule any 'in_progress' operations */
1860 bnx2x_iov_sp_event(bp, cid, true);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001861
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00001862 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08001863 atomic_inc(&bp->cq_spq_left);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001864 /* push the change in bp->spq_left and towards the memory */
1865 smp_mb__after_atomic_inc();
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001866
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001867 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1868
Barak Witkowskia3348722012-04-23 03:04:46 +00001869 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1870 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1871 /* if Q update ramrod is completed for last Q in AFEX vif set
1872 * flow, then ACK MCP at the end
1873 *
1874 * mark pending ACK to MCP bit.
1875 * prevent case that both bits are cleared.
1876 * At the end of load/unload driver checks that
Yuval Mintz2de67432013-01-23 03:21:43 +00001877 * sp_state is cleared, and this order prevents
Barak Witkowskia3348722012-04-23 03:04:46 +00001878 * races
1879 */
1880 smp_mb__before_clear_bit();
1881 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1882 wmb();
1883 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
1884 smp_mb__after_clear_bit();
1885
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001886 /* schedule the sp task as mcp ack is required */
1887 bnx2x_schedule_sp_task(bp);
Barak Witkowskia3348722012-04-23 03:04:46 +00001888 }
1889
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001890 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001891}
1892
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001893irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001894{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001895 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001896 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001897 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -07001898 int i;
Ariel Elior6383c0b2011-07-14 08:31:57 +00001899 u8 cos;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001900
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001901 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001902 if (unlikely(status == 0)) {
1903 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1904 return IRQ_NONE;
1905 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001906 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001907
Eilon Greenstein3196a882008-08-13 15:58:49 -07001908#ifdef BNX2X_STOP_ON_ERROR
1909 if (unlikely(bp->panic))
1910 return IRQ_HANDLED;
1911#endif
1912
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001913 for_each_eth_queue(bp, i) {
Eilon Greensteinca003922009-08-12 22:53:28 -07001914 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001915
Merav Sicron55c11942012-11-07 00:45:48 +00001916 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
Eilon Greensteinca003922009-08-12 22:53:28 -07001917 if (status & mask) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001918 /* Handle Rx or Tx according to SB id */
Ariel Elior6383c0b2011-07-14 08:31:57 +00001919 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00001920 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001921 prefetch(&fp->sb_running_index[SM_RX_ID]);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001922 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eilon Greensteinca003922009-08-12 22:53:28 -07001923 status &= ~mask;
1924 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001925 }
1926
Merav Sicron55c11942012-11-07 00:45:48 +00001927 if (CNIC_SUPPORT(bp)) {
1928 mask = 0x2;
1929 if (status & (mask | 0x1)) {
1930 struct cnic_ops *c_ops = NULL;
Michael Chan993ac7b2009-10-10 13:46:56 +00001931
Michael Chanad9b4352013-01-23 03:21:52 +00001932 rcu_read_lock();
1933 c_ops = rcu_dereference(bp->cnic_ops);
1934 if (c_ops && (bp->cnic_eth_dev.drv_state &
1935 CNIC_DRV_STATE_HANDLES_IRQ))
1936 c_ops->cnic_handler(bp->cnic_data, NULL);
1937 rcu_read_unlock();
Merav Sicron55c11942012-11-07 00:45:48 +00001938
1939 status &= ~mask;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001940 }
Michael Chan993ac7b2009-10-10 13:46:56 +00001941 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001942
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001943 if (unlikely(status & 0x1)) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001944
1945 /* schedule sp task to perform default status block work, ack
1946 * attentions and enable interrupts.
1947 */
1948 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001949
1950 status &= ~0x1;
1951 if (!status)
1952 return IRQ_HANDLED;
1953 }
1954
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001955 if (unlikely(status))
1956 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001957 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001958
1959 return IRQ_HANDLED;
1960}
1961
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001962/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001963
1964/*
1965 * General service functions
1966 */
1967
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001968int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001969{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001970 u32 lock_status;
1971 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001972 int func = BP_FUNC(bp);
1973 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001974 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001975
1976 /* Validating that the resource is within range */
1977 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001978 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001979 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1980 return -EINVAL;
1981 }
1982
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001983 if (func <= 5) {
1984 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1985 } else {
1986 hw_lock_control_reg =
1987 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1988 }
1989
Eliezer Tamirf1410642008-02-28 11:51:50 -08001990 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001991 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001992 if (lock_status & resource_bit) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001993 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001994 lock_status, resource_bit);
1995 return -EEXIST;
1996 }
1997
Eilon Greenstein46230476b2008-08-25 15:23:30 -07001998 /* Try for 5 second every 5ms */
1999 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08002000 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002001 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
2002 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002003 if (lock_status & resource_bit)
2004 return 0;
2005
Yuval Mintz639d65b2013-06-02 00:06:21 +00002006 usleep_range(5000, 10000);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002007 }
Merav Sicron51c1a582012-03-18 10:33:38 +00002008 BNX2X_ERR("Timeout\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -08002009 return -EAGAIN;
2010}
2011
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00002012int bnx2x_release_leader_lock(struct bnx2x *bp)
2013{
2014 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
2015}
2016
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002017int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002018{
2019 u32 lock_status;
2020 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002021 int func = BP_FUNC(bp);
2022 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002023
2024 /* Validating that the resource is within range */
2025 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002026 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002027 resource, HW_LOCK_MAX_RESOURCE_VALUE);
2028 return -EINVAL;
2029 }
2030
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002031 if (func <= 5) {
2032 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
2033 } else {
2034 hw_lock_control_reg =
2035 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
2036 }
2037
Eliezer Tamirf1410642008-02-28 11:51:50 -08002038 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002039 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002040 if (!(lock_status & resource_bit)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00002041 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
2042 lock_status, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002043 return -EFAULT;
2044 }
2045
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002046 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002047 return 0;
2048}
2049
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002050int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2051{
2052 /* The GPIO should be swapped if swap register is set and active */
2053 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2054 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2055 int gpio_shift = gpio_num +
2056 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2057 u32 gpio_mask = (1 << gpio_shift);
2058 u32 gpio_reg;
2059 int value;
2060
2061 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2062 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2063 return -EINVAL;
2064 }
2065
2066 /* read GPIO value */
2067 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2068
2069 /* get the requested pin value */
2070 if ((gpio_reg & gpio_mask) == gpio_mask)
2071 value = 1;
2072 else
2073 value = 0;
2074
2075 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2076
2077 return value;
2078}
2079
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002080int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002081{
2082 /* The GPIO should be swapped if swap register is set and active */
2083 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002084 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002085 int gpio_shift = gpio_num +
2086 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2087 u32 gpio_mask = (1 << gpio_shift);
2088 u32 gpio_reg;
2089
2090 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2091 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2092 return -EINVAL;
2093 }
2094
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002095 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002096 /* read GPIO and mask except the float bits */
2097 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
2098
2099 switch (mode) {
2100 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
Merav Sicron51c1a582012-03-18 10:33:38 +00002101 DP(NETIF_MSG_LINK,
2102 "Set GPIO %d (shift %d) -> output low\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002103 gpio_num, gpio_shift);
2104 /* clear FLOAT and set CLR */
2105 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2106 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2107 break;
2108
2109 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
Merav Sicron51c1a582012-03-18 10:33:38 +00002110 DP(NETIF_MSG_LINK,
2111 "Set GPIO %d (shift %d) -> output high\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002112 gpio_num, gpio_shift);
2113 /* clear FLOAT and set SET */
2114 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2115 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2116 break;
2117
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002118 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Merav Sicron51c1a582012-03-18 10:33:38 +00002119 DP(NETIF_MSG_LINK,
2120 "Set GPIO %d (shift %d) -> input\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002121 gpio_num, gpio_shift);
2122 /* set FLOAT */
2123 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2124 break;
2125
2126 default:
2127 break;
2128 }
2129
2130 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002131 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002132
2133 return 0;
2134}
2135
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00002136int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2137{
2138 u32 gpio_reg = 0;
2139 int rc = 0;
2140
2141 /* Any port swapping should be handled by caller. */
2142
2143 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2144 /* read GPIO and mask except the float bits */
2145 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2146 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2147 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2148 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2149
2150 switch (mode) {
2151 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2152 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2153 /* set CLR */
2154 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2155 break;
2156
2157 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2158 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2159 /* set SET */
2160 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2161 break;
2162
2163 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2164 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2165 /* set FLOAT */
2166 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2167 break;
2168
2169 default:
2170 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2171 rc = -EINVAL;
2172 break;
2173 }
2174
2175 if (rc == 0)
2176 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2177
2178 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2179
2180 return rc;
2181}
2182
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002183int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2184{
2185 /* The GPIO should be swapped if swap register is set and active */
2186 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2187 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2188 int gpio_shift = gpio_num +
2189 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2190 u32 gpio_mask = (1 << gpio_shift);
2191 u32 gpio_reg;
2192
2193 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2194 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2195 return -EINVAL;
2196 }
2197
2198 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2199 /* read GPIO int */
2200 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2201
2202 switch (mode) {
2203 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
Merav Sicron51c1a582012-03-18 10:33:38 +00002204 DP(NETIF_MSG_LINK,
2205 "Clear GPIO INT %d (shift %d) -> output low\n",
2206 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002207 /* clear SET and set CLR */
2208 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2209 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2210 break;
2211
2212 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
Merav Sicron51c1a582012-03-18 10:33:38 +00002213 DP(NETIF_MSG_LINK,
2214 "Set GPIO INT %d (shift %d) -> output high\n",
2215 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002216 /* clear CLR and set SET */
2217 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2218 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2219 break;
2220
2221 default:
2222 break;
2223 }
2224
2225 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2226 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2227
2228 return 0;
2229}
2230
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002231static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002232{
Eliezer Tamirf1410642008-02-28 11:51:50 -08002233 u32 spio_reg;
2234
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002235 /* Only 2 SPIOs are configurable */
2236 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2237 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002238 return -EINVAL;
2239 }
2240
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002241 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002242 /* read SPIO and mask except the float bits */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002243 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002244
2245 switch (mode) {
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002246 case MISC_SPIO_OUTPUT_LOW:
2247 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002248 /* clear FLOAT and set CLR */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002249 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2250 spio_reg |= (spio << MISC_SPIO_CLR_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002251 break;
2252
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002253 case MISC_SPIO_OUTPUT_HIGH:
2254 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002255 /* clear FLOAT and set SET */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002256 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2257 spio_reg |= (spio << MISC_SPIO_SET_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002258 break;
2259
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002260 case MISC_SPIO_INPUT_HI_Z:
2261 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002262 /* set FLOAT */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002263 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002264 break;
2265
2266 default:
2267 break;
2268 }
2269
2270 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002271 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002272
2273 return 0;
2274}
2275
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002276void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002277{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002278 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002279 switch (bp->link_vars.ieee_fc &
2280 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002281 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002282 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002283 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002284 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002285
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002286 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002287 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002288 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002289 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002290
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002291 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002292 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002293 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002294
Eliezer Tamirf1410642008-02-28 11:51:50 -08002295 default:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002296 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002297 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002298 break;
2299 }
2300}
2301
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002302static void bnx2x_set_requested_fc(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002303{
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002304 /* Initialize link parameters structure variables
2305 * It is recommended to turn off RX FC for jumbo frames
2306 * for better performance
2307 */
2308 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2309 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2310 else
2311 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2312}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002313
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002314static void bnx2x_init_dropless_fc(struct bnx2x *bp)
2315{
2316 u32 pause_enabled = 0;
2317
2318 if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
2319 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2320 pause_enabled = 1;
2321
2322 REG_WR(bp, BAR_USTRORM_INTMEM +
2323 USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
2324 pause_enabled);
2325 }
2326
2327 DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
2328 pause_enabled ? "enabled" : "disabled");
2329}
2330
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002331int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2332{
2333 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2334 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2335
2336 if (!BP_NOMCP(bp)) {
2337 bnx2x_set_requested_fc(bp);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002338 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002339
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002340 if (load_mode == LOAD_DIAG) {
Yaniv Rosner1cb0c782011-07-24 03:53:21 +00002341 struct link_params *lp = &bp->link_params;
2342 lp->loopback_mode = LOOPBACK_XGXS;
2343 /* do PHY loopback at 10G speed, if possible */
2344 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2345 if (lp->speed_cap_mask[cfx_idx] &
2346 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2347 lp->req_line_speed[cfx_idx] =
2348 SPEED_10000;
2349 else
2350 lp->req_line_speed[cfx_idx] =
2351 SPEED_1000;
2352 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002353 }
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002354
Merav Sicron8970b2e2012-06-19 07:48:22 +00002355 if (load_mode == LOAD_LOOPBACK_EXT) {
2356 struct link_params *lp = &bp->link_params;
2357 lp->loopback_mode = LOOPBACK_EXT;
2358 }
2359
Eilon Greenstein19680c42008-08-13 15:47:33 -07002360 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002361
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002362 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002363
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002364 bnx2x_init_dropless_fc(bp);
2365
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002366 bnx2x_calc_fc_adv(bp);
2367
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002368 if (bp->link_vars.link_up) {
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002369 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002370 bnx2x_link_report(bp);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002371 }
2372 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002373 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
Eilon Greenstein19680c42008-08-13 15:47:33 -07002374 return rc;
2375 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002376 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002377 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002378}
2379
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002380void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002381{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002382 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002383 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002384 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002385 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002386
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002387 bnx2x_init_dropless_fc(bp);
2388
Eilon Greenstein19680c42008-08-13 15:47:33 -07002389 bnx2x_calc_fc_adv(bp);
2390 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002391 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002392}
2393
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002394static void bnx2x__link_reset(struct bnx2x *bp)
2395{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002396 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002397 bnx2x_acquire_phy_lock(bp);
Yuval Mintz5d07d862012-09-13 02:56:21 +00002398 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002399 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002400 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002401 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002402}
2403
Yuval Mintz5d07d862012-09-13 02:56:21 +00002404void bnx2x_force_link_reset(struct bnx2x *bp)
2405{
2406 bnx2x_acquire_phy_lock(bp);
2407 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2408 bnx2x_release_phy_lock(bp);
2409}
2410
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002411u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002412{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002413 u8 rc = 0;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002414
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002415 if (!BP_NOMCP(bp)) {
2416 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002417 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2418 is_serdes);
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002419 bnx2x_release_phy_lock(bp);
2420 } else
2421 BNX2X_ERR("Bootcode is missing - can not test link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002422
2423 return rc;
2424}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002425
Eilon Greenstein2691d512009-08-12 08:22:08 +00002426/* Calculates the sum of vn_min_rates.
2427 It's needed for further normalizing of the min_rates.
2428 Returns:
2429 sum of vn_min_rates.
2430 or
2431 0 - if all the min_rates are 0.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002432 In the later case fairness algorithm should be deactivated.
Eilon Greenstein2691d512009-08-12 08:22:08 +00002433 If not all min_rates are zero then those that are zeroes will be set to 1.
2434 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002435static void bnx2x_calc_vn_min(struct bnx2x *bp,
2436 struct cmng_init_input *input)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002437{
2438 int all_zero = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002439 int vn;
2440
David S. Miller8decf862011-09-22 03:23:13 -04002441 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002442 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein2691d512009-08-12 08:22:08 +00002443 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2444 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2445
2446 /* Skip hidden vns */
2447 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Yuval Mintzb475d782012-04-03 18:41:29 +00002448 vn_min_rate = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002449 /* If min rate is zero - set it to 1 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002450 else if (!vn_min_rate)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002451 vn_min_rate = DEF_MIN_RATE;
2452 else
2453 all_zero = 0;
2454
Yuval Mintzb475d782012-04-03 18:41:29 +00002455 input->vnic_min_rate[vn] = vn_min_rate;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002456 }
2457
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002458 /* if ETS or all min rates are zeros - disable fairness */
2459 if (BNX2X_IS_ETS_ENABLED(bp)) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002460 input->flags.cmng_enables &=
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002461 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2462 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2463 } else if (all_zero) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002464 input->flags.cmng_enables &=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002465 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002466 DP(NETIF_MSG_IFUP,
2467 "All MIN values are zeroes fairness will be disabled\n");
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002468 } else
Yuval Mintzb475d782012-04-03 18:41:29 +00002469 input->flags.cmng_enables |=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002470 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002471}
2472
Yuval Mintzb475d782012-04-03 18:41:29 +00002473static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2474 struct cmng_init_input *input)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002475{
Yuval Mintzb475d782012-04-03 18:41:29 +00002476 u16 vn_max_rate;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002477 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002478
Yuval Mintzb475d782012-04-03 18:41:29 +00002479 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002480 vn_max_rate = 0;
Yuval Mintzb475d782012-04-03 18:41:29 +00002481 else {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002482 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2483
Yuval Mintzb475d782012-04-03 18:41:29 +00002484 if (IS_MF_SI(bp)) {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002485 /* maxCfg in percents of linkspeed */
2486 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
Yuval Mintzb475d782012-04-03 18:41:29 +00002487 } else /* SD modes */
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002488 /* maxCfg is absolute in 100Mb units */
2489 vn_max_rate = maxCfg * 100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002490 }
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002491
Yuval Mintzb475d782012-04-03 18:41:29 +00002492 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002493
Yuval Mintzb475d782012-04-03 18:41:29 +00002494 input->vnic_max_rate[vn] = vn_max_rate;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002495}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002496
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002497static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2498{
2499 if (CHIP_REV_IS_SLOW(bp))
2500 return CMNG_FNS_NONE;
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00002501 if (IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002502 return CMNG_FNS_MINMAX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002503
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002504 return CMNG_FNS_NONE;
2505}
2506
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002507void bnx2x_read_mf_cfg(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002508{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002509 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002510
2511 if (BP_NOMCP(bp))
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002512 return; /* what should be the default value in this case */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002513
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002514 /* For 2 port configuration the absolute function number formula
2515 * is:
2516 * abs_func = 2 * vn + BP_PORT + BP_PATH
2517 *
2518 * and there are 4 functions per port
2519 *
2520 * For 4 port configuration it is
2521 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2522 *
2523 * and there are 2 functions per port
2524 */
David S. Miller8decf862011-09-22 03:23:13 -04002525 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002526 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2527
2528 if (func >= E1H_FUNC_MAX)
2529 break;
2530
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002531 bp->mf_config[vn] =
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002532 MF_CFG_RD(bp, func_mf_config[func].config);
2533 }
Barak Witkowskia3348722012-04-23 03:04:46 +00002534 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2535 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2536 bp->flags |= MF_FUNC_DIS;
2537 } else {
2538 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2539 bp->flags &= ~MF_FUNC_DIS;
2540 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002541}
2542
2543static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2544{
Yuval Mintzb475d782012-04-03 18:41:29 +00002545 struct cmng_init_input input;
2546 memset(&input, 0, sizeof(struct cmng_init_input));
2547
2548 input.port_rate = bp->link_vars.line_speed;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002549
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002550 if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002551 int vn;
2552
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002553 /* read mf conf from shmem */
2554 if (read_cfg)
2555 bnx2x_read_mf_cfg(bp);
2556
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002557 /* vn_weight_sum and enable fairness if not 0 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002558 bnx2x_calc_vn_min(bp, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002559
2560 /* calculate and set min-max rate for each vn */
Dmitry Kravkovc4154f22011-03-06 10:49:25 +00002561 if (bp->port.pmf)
David S. Miller8decf862011-09-22 03:23:13 -04002562 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
Yuval Mintzb475d782012-04-03 18:41:29 +00002563 bnx2x_calc_vn_max(bp, vn, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002564
2565 /* always enable rate shaping and fairness */
Yuval Mintzb475d782012-04-03 18:41:29 +00002566 input.flags.cmng_enables |=
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002567 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002568
2569 bnx2x_init_cmng(&input, &bp->cmng);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002570 return;
2571 }
2572
2573 /* rate shaping and fairness are disabled */
2574 DP(NETIF_MSG_IFUP,
2575 "rate shaping and fairness are disabled\n");
2576}
2577
Eric Dumazet1191cb82012-04-27 21:39:21 +00002578static void storm_memset_cmng(struct bnx2x *bp,
2579 struct cmng_init *cmng,
2580 u8 port)
2581{
2582 int vn;
2583 size_t size = sizeof(struct cmng_struct_per_port);
2584
2585 u32 addr = BAR_XSTRORM_INTMEM +
2586 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2587
2588 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2589
2590 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2591 int func = func_by_vn(bp, vn);
2592
2593 addr = BAR_XSTRORM_INTMEM +
2594 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2595 size = sizeof(struct rate_shaping_vars_per_vn);
2596 __storm_memset_struct(bp, addr, size,
2597 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2598
2599 addr = BAR_XSTRORM_INTMEM +
2600 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2601 size = sizeof(struct fairness_vars_per_vn);
2602 __storm_memset_struct(bp, addr, size,
2603 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2604 }
2605}
2606
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002607/* init cmng mode in HW according to local configuration */
2608void bnx2x_set_local_cmng(struct bnx2x *bp)
2609{
2610 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2611
2612 if (cmng_fns != CMNG_FNS_NONE) {
2613 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2614 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2615 } else {
2616 /* rate shaping and fairness are disabled */
2617 DP(NETIF_MSG_IFUP,
2618 "single function mode without fairness\n");
2619 }
2620}
2621
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002622/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002623static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002624{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002625 /* Make sure that we are synced with the current statistics */
2626 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2627
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002628 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002629
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002630 bnx2x_init_dropless_fc(bp);
2631
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002632 if (bp->link_vars.link_up) {
2633
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002634 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002635 struct host_port_stats *pstats;
2636
2637 pstats = bnx2x_sp(bp, port_stats);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002638 /* reset old mac stats */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002639 memset(&(pstats->mac_stx[0]), 0,
2640 sizeof(struct mac_stx));
2641 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002642 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002643 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2644 }
2645
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002646 if (bp->link_vars.link_up && bp->link_vars.line_speed)
2647 bnx2x_set_local_cmng(bp);
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002648
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002649 __bnx2x_link_report(bp);
2650
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002651 if (IS_MF(bp))
2652 bnx2x_link_sync_notify(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002653}
2654
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002655void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002656{
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002657 if (bp->state != BNX2X_STATE_OPEN)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002658 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002659
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002660 /* read updated dcb configuration */
Ariel Eliorad5afc82013-01-01 05:22:26 +00002661 if (IS_PF(bp)) {
2662 bnx2x_dcbx_pmf_update(bp);
2663 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2664 if (bp->link_vars.link_up)
2665 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2666 else
2667 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2668 /* indicate link status */
2669 bnx2x_link_report(bp);
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002670
Ariel Eliorad5afc82013-01-01 05:22:26 +00002671 } else { /* VF */
2672 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2673 SUPPORTED_10baseT_Full |
2674 SUPPORTED_100baseT_Half |
2675 SUPPORTED_100baseT_Full |
2676 SUPPORTED_1000baseT_Full |
2677 SUPPORTED_2500baseX_Full |
2678 SUPPORTED_10000baseT_Full |
2679 SUPPORTED_TP |
2680 SUPPORTED_FIBRE |
2681 SUPPORTED_Autoneg |
2682 SUPPORTED_Pause |
2683 SUPPORTED_Asym_Pause);
2684 bp->port.advertising[0] = bp->port.supported[0];
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002685
Ariel Eliorad5afc82013-01-01 05:22:26 +00002686 bp->link_params.bp = bp;
2687 bp->link_params.port = BP_PORT(bp);
2688 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2689 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2690 bp->link_params.req_line_speed[0] = SPEED_10000;
2691 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2692 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2693 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2694 bp->link_vars.line_speed = SPEED_10000;
2695 bp->link_vars.link_status =
2696 (LINK_STATUS_LINK_UP |
2697 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2698 bp->link_vars.link_up = 1;
2699 bp->link_vars.duplex = DUPLEX_FULL;
2700 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2701 __bnx2x_link_report(bp);
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002702 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Ariel Eliorad5afc82013-01-01 05:22:26 +00002703 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002704}
2705
Barak Witkowskia3348722012-04-23 03:04:46 +00002706static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2707 u16 vlan_val, u8 allowed_prio)
2708{
Yuval Mintz86564c32013-01-23 03:21:50 +00002709 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002710 struct bnx2x_func_afex_update_params *f_update_params =
2711 &func_params.params.afex_update;
2712
2713 func_params.f_obj = &bp->func_obj;
2714 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2715
2716 /* no need to wait for RAMROD completion, so don't
2717 * set RAMROD_COMP_WAIT flag
2718 */
2719
2720 f_update_params->vif_id = vifid;
2721 f_update_params->afex_default_vlan = vlan_val;
2722 f_update_params->allowed_priorities = allowed_prio;
2723
2724 /* if ramrod can not be sent, response to MCP immediately */
2725 if (bnx2x_func_state_change(bp, &func_params) < 0)
2726 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2727
2728 return 0;
2729}
2730
2731static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2732 u16 vif_index, u8 func_bit_map)
2733{
Yuval Mintz86564c32013-01-23 03:21:50 +00002734 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002735 struct bnx2x_func_afex_viflists_params *update_params =
2736 &func_params.params.afex_viflists;
2737 int rc;
2738 u32 drv_msg_code;
2739
2740 /* validate only LIST_SET and LIST_GET are received from switch */
2741 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2742 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2743 cmd_type);
2744
2745 func_params.f_obj = &bp->func_obj;
2746 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2747
2748 /* set parameters according to cmd_type */
2749 update_params->afex_vif_list_command = cmd_type;
Yuval Mintz86564c32013-01-23 03:21:50 +00002750 update_params->vif_list_index = vif_index;
Barak Witkowskia3348722012-04-23 03:04:46 +00002751 update_params->func_bit_map =
2752 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2753 update_params->func_to_clear = 0;
2754 drv_msg_code =
2755 (cmd_type == VIF_LIST_RULE_GET) ?
2756 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2757 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2758
2759 /* if ramrod can not be sent, respond to MCP immediately for
2760 * SET and GET requests (other are not triggered from MCP)
2761 */
2762 rc = bnx2x_func_state_change(bp, &func_params);
2763 if (rc < 0)
2764 bnx2x_fw_command(bp, drv_msg_code, 0);
2765
2766 return 0;
2767}
2768
2769static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2770{
2771 struct afex_stats afex_stats;
2772 u32 func = BP_ABS_FUNC(bp);
2773 u32 mf_config;
2774 u16 vlan_val;
2775 u32 vlan_prio;
2776 u16 vif_id;
2777 u8 allowed_prio;
2778 u8 vlan_mode;
2779 u32 addr_to_write, vifid, addrs, stats_type, i;
2780
2781 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2782 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2783 DP(BNX2X_MSG_MCP,
2784 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2785 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2786 }
2787
2788 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2789 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2790 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2791 DP(BNX2X_MSG_MCP,
2792 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2793 vifid, addrs);
2794 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2795 addrs);
2796 }
2797
2798 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2799 addr_to_write = SHMEM2_RD(bp,
2800 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2801 stats_type = SHMEM2_RD(bp,
2802 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2803
2804 DP(BNX2X_MSG_MCP,
2805 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2806 addr_to_write);
2807
2808 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2809
2810 /* write response to scratchpad, for MCP */
2811 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2812 REG_WR(bp, addr_to_write + i*sizeof(u32),
2813 *(((u32 *)(&afex_stats))+i));
2814
2815 /* send ack message to MCP */
2816 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2817 }
2818
2819 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2820 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2821 bp->mf_config[BP_VN(bp)] = mf_config;
2822 DP(BNX2X_MSG_MCP,
2823 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2824 mf_config);
2825
2826 /* if VIF_SET is "enabled" */
2827 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2828 /* set rate limit directly to internal RAM */
2829 struct cmng_init_input cmng_input;
2830 struct rate_shaping_vars_per_vn m_rs_vn;
2831 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2832 u32 addr = BAR_XSTRORM_INTMEM +
2833 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2834
2835 bp->mf_config[BP_VN(bp)] = mf_config;
2836
2837 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2838 m_rs_vn.vn_counter.rate =
2839 cmng_input.vnic_max_rate[BP_VN(bp)];
2840 m_rs_vn.vn_counter.quota =
2841 (m_rs_vn.vn_counter.rate *
2842 RS_PERIODIC_TIMEOUT_USEC) / 8;
2843
2844 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2845
2846 /* read relevant values from mf_cfg struct in shmem */
2847 vif_id =
2848 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2849 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2850 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2851 vlan_val =
2852 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2853 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2854 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2855 vlan_prio = (mf_config &
2856 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2857 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2858 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2859 vlan_mode =
2860 (MF_CFG_RD(bp,
2861 func_mf_config[func].afex_config) &
2862 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2863 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2864 allowed_prio =
2865 (MF_CFG_RD(bp,
2866 func_mf_config[func].afex_config) &
2867 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2868 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2869
2870 /* send ramrod to FW, return in case of failure */
2871 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2872 allowed_prio))
2873 return;
2874
2875 bp->afex_def_vlan_tag = vlan_val;
2876 bp->afex_vlan_mode = vlan_mode;
2877 } else {
2878 /* notify link down because BP->flags is disabled */
2879 bnx2x_link_report(bp);
2880
2881 /* send INVALID VIF ramrod to FW */
2882 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2883
2884 /* Reset the default afex VLAN */
2885 bp->afex_def_vlan_tag = -1;
2886 }
2887 }
2888}
2889
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002890static void bnx2x_pmf_update(struct bnx2x *bp)
2891{
2892 int port = BP_PORT(bp);
2893 u32 val;
2894
2895 bp->port.pmf = 1;
Merav Sicron51c1a582012-03-18 10:33:38 +00002896 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002897
Yaniv Rosner3deb8162011-06-14 01:34:33 +00002898 /*
2899 * We need the mb() to ensure the ordering between the writing to
2900 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2901 */
2902 smp_mb();
2903
2904 /* queue a periodic task */
2905 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2906
Dmitry Kravkovef018542011-06-14 01:33:57 +00002907 bnx2x_dcbx_pmf_update(bp);
2908
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002909 /* enable nig attention */
David S. Miller8decf862011-09-22 03:23:13 -04002910 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002911 if (bp->common.int_block == INT_BLOCK_HC) {
2912 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2913 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002914 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002915 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2916 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2917 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002918
2919 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002920}
2921
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002922/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002923
2924/* slow path */
2925
2926/*
2927 * General service functions
2928 */
2929
Eilon Greenstein2691d512009-08-12 08:22:08 +00002930/* send the MCP a request, block until there is a reply */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002931u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002932{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002933 int mb_idx = BP_FW_MB_IDX(bp);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002934 u32 seq;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002935 u32 rc = 0;
2936 u32 cnt = 1;
2937 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2938
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002939 mutex_lock(&bp->fw_mb_mutex);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002940 seq = ++bp->fw_seq;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002941 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2942 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2943
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00002944 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2945 (command | seq), param);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002946
2947 do {
2948 /* let the FW do it's magic ... */
2949 msleep(delay);
2950
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002951 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002952
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002953 /* Give the FW up to 5 second (500*10ms) */
2954 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002955
2956 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2957 cnt*delay, rc, seq);
2958
2959 /* is this a reply to our command? */
2960 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2961 rc &= FW_MSG_CODE_MASK;
2962 else {
2963 /* FW BUG! */
2964 BNX2X_ERR("FW failed to respond!\n");
2965 bnx2x_fw_dump(bp);
2966 rc = 0;
2967 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002968 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002969
2970 return rc;
2971}
2972
Eric Dumazet1191cb82012-04-27 21:39:21 +00002973static void storm_memset_func_cfg(struct bnx2x *bp,
2974 struct tstorm_eth_function_common_config *tcfg,
2975 u16 abs_fid)
2976{
2977 size_t size = sizeof(struct tstorm_eth_function_common_config);
2978
2979 u32 addr = BAR_TSTRORM_INTMEM +
2980 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2981
2982 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2983}
2984
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002985void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002986{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002987 if (CHIP_IS_E1x(bp)) {
2988 struct tstorm_eth_function_common_config tcfg = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002989
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002990 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2991 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002992
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002993 /* Enable the function in the FW */
2994 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
2995 storm_memset_func_en(bp, p->func_id, 1);
2996
2997 /* spq */
2998 if (p->func_flgs & FUNC_FLG_SPQ) {
2999 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
3000 REG_WR(bp, XSEM_REG_FAST_MEMORY +
3001 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
3002 }
3003}
3004
Ariel Elior6383c0b2011-07-14 08:31:57 +00003005/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003006 * bnx2x_get_common_flags - Return common flags
Ariel Elior6383c0b2011-07-14 08:31:57 +00003007 *
3008 * @bp device handle
3009 * @fp queue handle
3010 * @zero_stats TRUE if statistics zeroing is needed
3011 *
3012 * Return the flags that are common for the Tx-only and not normal connections.
3013 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003014static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
3015 struct bnx2x_fastpath *fp,
3016 bool zero_stats)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003017{
3018 unsigned long flags = 0;
3019
3020 /* PF driver will always initialize the Queue to an ACTIVE state */
3021 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
3022
Ariel Elior6383c0b2011-07-14 08:31:57 +00003023 /* tx only connections collect statistics (on the same index as the
Dmitry Kravkov91226792013-03-11 05:17:52 +00003024 * parent connection). The statistics are zeroed when the parent
3025 * connection is initialized.
Ariel Elior6383c0b2011-07-14 08:31:57 +00003026 */
Barak Witkowski50f0a562011-12-05 21:52:23 +00003027
3028 __set_bit(BNX2X_Q_FLG_STATS, &flags);
3029 if (zero_stats)
3030 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
3031
Yuval Mintzc14db202014-01-12 14:37:59 +02003032 if (bp->flags & TX_SWITCHING)
3033 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
3034
Dmitry Kravkov91226792013-03-11 05:17:52 +00003035 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
Dmitry Kravkove287a752013-03-21 15:38:24 +00003036 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
Ariel Elior6383c0b2011-07-14 08:31:57 +00003037
Yuval Mintz823e1d92013-01-14 05:11:47 +00003038#ifdef BNX2X_STOP_ON_ERROR
3039 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
3040#endif
3041
Ariel Elior6383c0b2011-07-14 08:31:57 +00003042 return flags;
3043}
3044
Eric Dumazet1191cb82012-04-27 21:39:21 +00003045static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
3046 struct bnx2x_fastpath *fp,
3047 bool leading)
Ariel Elior6383c0b2011-07-14 08:31:57 +00003048{
3049 unsigned long flags = 0;
3050
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003051 /* calculate other queue flags */
3052 if (IS_MF_SD(bp))
3053 __set_bit(BNX2X_Q_FLG_OV, &flags);
3054
Barak Witkowskia3348722012-04-23 03:04:46 +00003055 if (IS_FCOE_FP(fp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003056 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00003057 /* For FCoE - force usage of default priority (for afex) */
3058 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
3059 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003060
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003061 if (!fp->disable_tpa) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003062 __set_bit(BNX2X_Q_FLG_TPA, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003063 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00003064 if (fp->mode == TPA_MODE_GRO)
3065 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003066 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003067
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003068 if (leading) {
3069 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3070 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3071 }
3072
3073 /* Always set HW VLAN stripping */
3074 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003075
Barak Witkowskia3348722012-04-23 03:04:46 +00003076 /* configure silent vlan removal */
3077 if (IS_MF_AFEX(bp))
3078 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3079
Ariel Elior6383c0b2011-07-14 08:31:57 +00003080 return flags | bnx2x_get_common_flags(bp, fp, true);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003081}
3082
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003083static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003084 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3085 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003086{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003087 gen_init->stat_id = bnx2x_stats_id(fp);
3088 gen_init->spcl_id = fp->cl_id;
3089
3090 /* Always use mini-jumbo MTU for FCoE L2 ring */
3091 if (IS_FCOE_FP(fp))
3092 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3093 else
3094 gen_init->mtu = bp->dev->mtu;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003095
3096 gen_init->cos = cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003097}
3098
3099static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
3100 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
3101 struct bnx2x_rxq_setup_params *rxq_init)
3102{
3103 u8 max_sge = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003104 u16 sge_sz = 0;
3105 u16 tpa_agg_size = 0;
3106
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003107 if (!fp->disable_tpa) {
David S. Miller8decf862011-09-22 03:23:13 -04003108 pause->sge_th_lo = SGE_TH_LO(bp);
3109 pause->sge_th_hi = SGE_TH_HI(bp);
3110
3111 /* validate SGE ring has enough to cross high threshold */
3112 WARN_ON(bp->dropless_fc &&
3113 pause->sge_th_hi + FW_PREFETCH_CNT >
3114 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3115
Yuval Mintz924d75a2013-01-23 03:21:44 +00003116 tpa_agg_size = TPA_AGG_SIZE;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003117 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3118 SGE_PAGE_SHIFT;
3119 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3120 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
Yuval Mintz924d75a2013-01-23 03:21:44 +00003121 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003122 }
3123
3124 /* pause - not for e1 */
3125 if (!CHIP_IS_E1(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04003126 pause->bd_th_lo = BD_TH_LO(bp);
3127 pause->bd_th_hi = BD_TH_HI(bp);
3128
3129 pause->rcq_th_lo = RCQ_TH_LO(bp);
3130 pause->rcq_th_hi = RCQ_TH_HI(bp);
3131 /*
3132 * validate that rings have enough entries to cross
3133 * high thresholds
3134 */
3135 WARN_ON(bp->dropless_fc &&
3136 pause->bd_th_hi + FW_PREFETCH_CNT >
3137 bp->rx_ring_size);
3138 WARN_ON(bp->dropless_fc &&
3139 pause->rcq_th_hi + FW_PREFETCH_CNT >
3140 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003141
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003142 pause->pri_map = 1;
3143 }
3144
3145 /* rxq setup */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003146 rxq_init->dscr_map = fp->rx_desc_mapping;
3147 rxq_init->sge_map = fp->rx_sge_mapping;
3148 rxq_init->rcq_map = fp->rx_comp_mapping;
3149 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003150
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003151 /* This should be a maximum number of data bytes that may be
3152 * placed on the BD (not including paddings).
3153 */
Eric Dumazete52fcb22011-11-14 06:05:34 +00003154 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003155 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003156
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003157 rxq_init->cl_qzone_id = fp->cl_qzone_id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003158 rxq_init->tpa_agg_sz = tpa_agg_size;
3159 rxq_init->sge_buf_sz = sge_sz;
3160 rxq_init->max_sges_pkt = max_sge;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003161 rxq_init->rss_engine_id = BP_FUNC(bp);
Yuval Mintz259afa12012-03-12 08:53:10 +00003162 rxq_init->mcast_engine_id = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003163
3164 /* Maximum number or simultaneous TPA aggregation for this Queue.
3165 *
Yuval Mintz2de67432013-01-23 03:21:43 +00003166 * For PF Clients it should be the maximum available number.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003167 * VF driver(s) may want to define it to a smaller value.
3168 */
David S. Miller8decf862011-09-22 03:23:13 -04003169 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003170
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003171 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3172 rxq_init->fw_sb_id = fp->fw_sb_id;
3173
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003174 if (IS_FCOE_FP(fp))
3175 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3176 else
Ariel Elior6383c0b2011-07-14 08:31:57 +00003177 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
Barak Witkowskia3348722012-04-23 03:04:46 +00003178 /* configure silent vlan removal
3179 * if multi function mode is afex, then mask default vlan
3180 */
3181 if (IS_MF_AFEX(bp)) {
3182 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3183 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3184 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003185}
3186
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003187static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003188 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3189 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003190{
Merav Sicron65565882012-06-19 07:48:26 +00003191 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003192 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003193 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3194 txq_init->fw_sb_id = fp->fw_sb_id;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003195
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003196 /*
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003197 * set the tss leading client id for TX classification ==
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003198 * leading RSS client id
3199 */
3200 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3201
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003202 if (IS_FCOE_FP(fp)) {
3203 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3204 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3205 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003206}
3207
stephen hemminger8d962862010-10-21 07:50:56 +00003208static void bnx2x_pf_init(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003209{
3210 struct bnx2x_func_init_params func_init = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003211 struct event_ring_data eq_data = { {0} };
3212 u16 flags;
3213
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003214 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003215 /* reset IGU PF statistics: MSIX + ATTN */
3216 /* PF */
3217 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3218 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3219 (CHIP_MODE_IS_4_PORT(bp) ?
3220 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3221 /* ATTN */
3222 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3223 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3224 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3225 (CHIP_MODE_IS_4_PORT(bp) ?
3226 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3227 }
3228
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003229 /* function setup flags */
3230 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3231
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003232 /* This flag is relevant for E1x only.
3233 * E2 doesn't have a TPA configuration in a function level.
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003234 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003235 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003236
3237 func_init.func_flgs = flags;
3238 func_init.pf_id = BP_FUNC(bp);
3239 func_init.func_id = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003240 func_init.spq_map = bp->spq_mapping;
3241 func_init.spq_prod = bp->spq_prod_idx;
3242
3243 bnx2x_func_init(bp, &func_init);
3244
3245 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3246
3247 /*
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003248 * Congestion management values depend on the link rate
3249 * There is no active link so initial link rate is set to 10 Gbps.
3250 * When the link comes up The congestion management values are
3251 * re-calculated according to the actual link rate.
3252 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003253 bp->link_vars.line_speed = SPEED_10000;
3254 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3255
3256 /* Only the PMF sets the HW */
3257 if (bp->port.pmf)
3258 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3259
Yuval Mintz86564c32013-01-23 03:21:50 +00003260 /* init Event Queue - PCI bus guarantees correct endianity*/
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003261 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3262 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3263 eq_data.producer = bp->eq_prod;
3264 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3265 eq_data.sb_id = DEF_SB_ID;
3266 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3267}
3268
Eilon Greenstein2691d512009-08-12 08:22:08 +00003269static void bnx2x_e1h_disable(struct bnx2x *bp)
3270{
3271 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003272
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003273 bnx2x_tx_disable(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003274
3275 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003276}
3277
3278static void bnx2x_e1h_enable(struct bnx2x *bp)
3279{
3280 int port = BP_PORT(bp);
3281
3282 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3283
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003284 /* Tx queue should be only re-enabled */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003285 netif_tx_wake_all_queues(bp->dev);
3286
Eilon Greenstein061bc702009-10-15 00:18:47 -07003287 /*
3288 * Should not call netif_carrier_on since it will be called if the link
3289 * is up when checking for link state
3290 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003291}
3292
Barak Witkowski1d187b32011-12-05 22:41:50 +00003293#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3294
3295static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3296{
3297 struct eth_stats_info *ether_stat =
3298 &bp->slowpath->drv_info_to_mcp.ether_stat;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003299 struct bnx2x_vlan_mac_obj *mac_obj =
3300 &bp->sp_objs->mac_obj;
3301 int i;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003302
Dan Carpenter786fdf02012-10-02 01:47:46 +00003303 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3304 ETH_STAT_INFO_VERSION_LEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003305
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003306 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3307 * mac_local field in ether_stat struct. The base address is offset by 2
3308 * bytes to account for the field being 8 bytes but a mac address is
3309 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3310 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3311 * allocated by the ether_stat struct, so the macs will land in their
3312 * proper positions.
3313 */
3314 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3315 memset(ether_stat->mac_local + i, 0,
3316 sizeof(ether_stat->mac_local[0]));
3317 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3318 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3319 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3320 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003321 ether_stat->mtu_size = bp->dev->mtu;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003322 if (bp->dev->features & NETIF_F_RXCSUM)
3323 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3324 if (bp->dev->features & NETIF_F_TSO)
3325 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3326 ether_stat->feature_flags |= bp->common.boot_mode;
3327
3328 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3329
3330 ether_stat->txq_size = bp->tx_ring_size;
3331 ether_stat->rxq_size = bp->rx_ring_size;
Yuval Mintz0c757de2013-12-26 09:57:11 +02003332
David S. Millerfcf93a02013-12-26 18:33:10 -05003333#ifdef CONFIG_BNX2X_SRIOV
Yuval Mintz0c757de2013-12-26 09:57:11 +02003334 ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
David S. Millerfcf93a02013-12-26 18:33:10 -05003335#endif
Barak Witkowski1d187b32011-12-05 22:41:50 +00003336}
3337
3338static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3339{
3340 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3341 struct fcoe_stats_info *fcoe_stat =
3342 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3343
Merav Sicron55c11942012-11-07 00:45:48 +00003344 if (!CNIC_LOADED(bp))
3345 return;
3346
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003347 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003348
3349 fcoe_stat->qos_priority =
3350 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3351
3352 /* insert FCoE stats from ramrod response */
3353 if (!NO_FCOE(bp)) {
3354 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003355 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003356 tstorm_queue_statistics;
3357
3358 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003359 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003360 xstorm_queue_statistics;
3361
3362 struct fcoe_statistics_params *fw_fcoe_stat =
3363 &bp->fw_stats_data->fcoe;
3364
Yuval Mintz86564c32013-01-23 03:21:50 +00003365 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3366 fcoe_stat->rx_bytes_lo,
3367 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003368
Yuval Mintz86564c32013-01-23 03:21:50 +00003369 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3370 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3371 fcoe_stat->rx_bytes_lo,
3372 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003373
Yuval Mintz86564c32013-01-23 03:21:50 +00003374 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3375 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3376 fcoe_stat->rx_bytes_lo,
3377 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003378
Yuval Mintz86564c32013-01-23 03:21:50 +00003379 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3380 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3381 fcoe_stat->rx_bytes_lo,
3382 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003383
Yuval Mintz86564c32013-01-23 03:21:50 +00003384 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3385 fcoe_stat->rx_frames_lo,
3386 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003387
Yuval Mintz86564c32013-01-23 03:21:50 +00003388 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3389 fcoe_stat->rx_frames_lo,
3390 fcoe_q_tstorm_stats->rcv_ucast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003391
Yuval Mintz86564c32013-01-23 03:21:50 +00003392 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3393 fcoe_stat->rx_frames_lo,
3394 fcoe_q_tstorm_stats->rcv_bcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003395
Yuval Mintz86564c32013-01-23 03:21:50 +00003396 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3397 fcoe_stat->rx_frames_lo,
3398 fcoe_q_tstorm_stats->rcv_mcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003399
Yuval Mintz86564c32013-01-23 03:21:50 +00003400 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3401 fcoe_stat->tx_bytes_lo,
3402 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003403
Yuval Mintz86564c32013-01-23 03:21:50 +00003404 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3405 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3406 fcoe_stat->tx_bytes_lo,
3407 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003408
Yuval Mintz86564c32013-01-23 03:21:50 +00003409 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3410 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3411 fcoe_stat->tx_bytes_lo,
3412 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003413
Yuval Mintz86564c32013-01-23 03:21:50 +00003414 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3415 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3416 fcoe_stat->tx_bytes_lo,
3417 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003418
Yuval Mintz86564c32013-01-23 03:21:50 +00003419 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3420 fcoe_stat->tx_frames_lo,
3421 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003422
Yuval Mintz86564c32013-01-23 03:21:50 +00003423 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3424 fcoe_stat->tx_frames_lo,
3425 fcoe_q_xstorm_stats->ucast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003426
Yuval Mintz86564c32013-01-23 03:21:50 +00003427 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3428 fcoe_stat->tx_frames_lo,
3429 fcoe_q_xstorm_stats->bcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003430
Yuval Mintz86564c32013-01-23 03:21:50 +00003431 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3432 fcoe_stat->tx_frames_lo,
3433 fcoe_q_xstorm_stats->mcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003434 }
3435
Barak Witkowski1d187b32011-12-05 22:41:50 +00003436 /* ask L5 driver to add data to the struct */
3437 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003438}
3439
3440static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3441{
3442 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3443 struct iscsi_stats_info *iscsi_stat =
3444 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3445
Merav Sicron55c11942012-11-07 00:45:48 +00003446 if (!CNIC_LOADED(bp))
3447 return;
3448
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003449 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3450 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003451
3452 iscsi_stat->qos_priority =
3453 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3454
Barak Witkowski1d187b32011-12-05 22:41:50 +00003455 /* ask L5 driver to add data to the struct */
3456 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003457}
3458
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003459/* called due to MCP event (on pmf):
3460 * reread new bandwidth configuration
3461 * configure FW
3462 * notify others function about the change
3463 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003464static void bnx2x_config_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003465{
3466 if (bp->link_vars.link_up) {
3467 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3468 bnx2x_link_sync_notify(bp);
3469 }
3470 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3471}
3472
Eric Dumazet1191cb82012-04-27 21:39:21 +00003473static void bnx2x_set_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003474{
3475 bnx2x_config_mf_bw(bp);
3476 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3477}
3478
Yuval Mintzc8c60d82012-06-06 17:13:07 +00003479static void bnx2x_handle_eee_event(struct bnx2x *bp)
3480{
3481 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3482 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3483}
3484
Barak Witkowski1d187b32011-12-05 22:41:50 +00003485static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3486{
3487 enum drv_info_opcode op_code;
3488 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
3489
3490 /* if drv_info version supported by MFW doesn't match - send NACK */
3491 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3492 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3493 return;
3494 }
3495
3496 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3497 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3498
3499 memset(&bp->slowpath->drv_info_to_mcp, 0,
3500 sizeof(union drv_info_to_mcp));
3501
3502 switch (op_code) {
3503 case ETH_STATS_OPCODE:
3504 bnx2x_drv_info_ether_stat(bp);
3505 break;
3506 case FCOE_STATS_OPCODE:
3507 bnx2x_drv_info_fcoe_stat(bp);
3508 break;
3509 case ISCSI_STATS_OPCODE:
3510 bnx2x_drv_info_iscsi_stat(bp);
3511 break;
3512 default:
3513 /* if op code isn't supported - send NACK */
3514 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3515 return;
3516 }
3517
3518 /* if we got drv_info attn from MFW then these fields are defined in
3519 * shmem2 for sure
3520 */
3521 SHMEM2_WR(bp, drv_info_host_addr_lo,
3522 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3523 SHMEM2_WR(bp, drv_info_host_addr_hi,
3524 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3525
3526 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
3527}
3528
Eilon Greenstein2691d512009-08-12 08:22:08 +00003529static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3530{
Eilon Greenstein2691d512009-08-12 08:22:08 +00003531 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003532
3533 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3534
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003535 /*
3536 * This is the only place besides the function initialization
3537 * where the bp->flags can change so it is done without any
3538 * locks
3539 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003540 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003541 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003542 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003543
3544 bnx2x_e1h_disable(bp);
3545 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00003546 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003547 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003548
3549 bnx2x_e1h_enable(bp);
3550 }
3551 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3552 }
3553 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003554 bnx2x_config_mf_bw(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003555 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3556 }
3557
3558 /* Report results to MCP */
3559 if (dcc_event)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003560 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003561 else
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003562 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003563}
3564
Michael Chan289129022009-10-10 13:46:53 +00003565/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003566static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003567{
3568 struct eth_spe *next_spe = bp->spq_prod_bd;
3569
3570 if (bp->spq_prod_bd == bp->spq_last_bd) {
3571 bp->spq_prod_bd = bp->spq;
3572 bp->spq_prod_idx = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00003573 DP(BNX2X_MSG_SP, "end of spq\n");
Michael Chan289129022009-10-10 13:46:53 +00003574 } else {
3575 bp->spq_prod_bd++;
3576 bp->spq_prod_idx++;
3577 }
3578 return next_spe;
3579}
3580
3581/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003582static void bnx2x_sp_prod_update(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003583{
3584 int func = BP_FUNC(bp);
3585
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003586 /*
3587 * Make sure that BD data is updated before writing the producer:
3588 * BD data is written to the memory, the producer is read from the
3589 * memory, thus we need a full memory barrier to ensure the ordering.
3590 */
3591 mb();
Michael Chan289129022009-10-10 13:46:53 +00003592
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003593 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00003594 bp->spq_prod_idx);
Michael Chan289129022009-10-10 13:46:53 +00003595 mmiowb();
3596}
3597
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003598/**
3599 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3600 *
3601 * @cmd: command to check
3602 * @cmd_type: command type
3603 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003604static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003605{
3606 if ((cmd_type == NONE_CONNECTION_TYPE) ||
Ariel Elior6383c0b2011-07-14 08:31:57 +00003607 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003608 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3609 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3610 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3611 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3612 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3613 return true;
3614 else
3615 return false;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003616}
3617
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003618/**
3619 * bnx2x_sp_post - place a single command on an SP ring
3620 *
3621 * @bp: driver handle
3622 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3623 * @cid: SW CID the command is related to
3624 * @data_hi: command private data address (high 32 bits)
3625 * @data_lo: command private data address (low 32 bits)
3626 * @cmd_type: command type (e.g. NONE, ETH)
3627 *
3628 * SP data is handled as if it's always an address pair, thus data fields are
3629 * not swapped to little endian in upper functions. Instead this function swaps
3630 * data as if it's two u32 fields.
3631 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003632int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003633 u32 data_hi, u32 data_lo, int cmd_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003634{
Michael Chan289129022009-10-10 13:46:53 +00003635 struct eth_spe *spe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003636 u16 type;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003637 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003638
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003639#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00003640 if (unlikely(bp->panic)) {
3641 BNX2X_ERR("Can't post SP when there is panic\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003642 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +00003643 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003644#endif
3645
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003646 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003647
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003648 if (common) {
3649 if (!atomic_read(&bp->eq_spq_left)) {
3650 BNX2X_ERR("BUG! EQ ring full!\n");
3651 spin_unlock_bh(&bp->spq_lock);
3652 bnx2x_panic();
3653 return -EBUSY;
3654 }
3655 } else if (!atomic_read(&bp->cq_spq_left)) {
3656 BNX2X_ERR("BUG! SPQ ring full!\n");
3657 spin_unlock_bh(&bp->spq_lock);
3658 bnx2x_panic();
3659 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003660 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08003661
Michael Chan289129022009-10-10 13:46:53 +00003662 spe = bnx2x_sp_get_next(bp);
3663
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003664 /* CID needs port number to be encoded int it */
Michael Chan289129022009-10-10 13:46:53 +00003665 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003666 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3667 HW_CID(bp, cid));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003668
Michal Kalderon14a94eb2014-02-12 18:19:53 +02003669 /* In some cases, type may already contain the func-id
3670 * mainly in SRIOV related use cases, so we add it here only
3671 * if it's not already set.
3672 */
3673 if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
3674 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
3675 SPE_HDR_CONN_TYPE;
3676 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3677 SPE_HDR_FUNCTION_ID);
3678 } else {
3679 type = cmd_type;
3680 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003681
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003682 spe->hdr.type = cpu_to_le16(type);
3683
3684 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3685 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3686
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003687 /*
3688 * It's ok if the actual decrement is issued towards the memory
3689 * somewhere between the spin_lock and spin_unlock. Thus no
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003690 * more explicit memory barrier is needed.
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003691 */
3692 if (common)
3693 atomic_dec(&bp->eq_spq_left);
3694 else
3695 atomic_dec(&bp->cq_spq_left);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003696
Merav Sicron51c1a582012-03-18 10:33:38 +00003697 DP(BNX2X_MSG_SP,
3698 "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 +00003699 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3700 (u32)(U64_LO(bp->spq_mapping) +
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003701 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003702 HW_CID(bp, cid), data_hi, data_lo, type,
3703 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003704
Michael Chan289129022009-10-10 13:46:53 +00003705 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003706 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003707 return 0;
3708}
3709
3710/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003711static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003712{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003713 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003714 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003715
3716 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003717 for (j = 0; j < 1000; j++) {
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003718 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
3719 val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
3720 if (val & MCPR_ACCESS_LOCK_LOCK)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003721 break;
3722
Yuval Mintz639d65b2013-06-02 00:06:21 +00003723 usleep_range(5000, 10000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003724 }
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003725 if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07003726 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003727 rc = -EBUSY;
3728 }
3729
3730 return rc;
3731}
3732
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003733/* release split MCP access lock register */
3734static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003735{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003736 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003737}
3738
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003739#define BNX2X_DEF_SB_ATT_IDX 0x0001
3740#define BNX2X_DEF_SB_IDX 0x0002
3741
Eric Dumazet1191cb82012-04-27 21:39:21 +00003742static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003743{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003744 struct host_sp_status_block *def_sb = bp->def_status_blk;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003745 u16 rc = 0;
3746
3747 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003748 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3749 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003750 rc |= BNX2X_DEF_SB_ATT_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003751 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003752
3753 if (bp->def_idx != def_sb->sp_sb.running_index) {
3754 bp->def_idx = def_sb->sp_sb.running_index;
3755 rc |= BNX2X_DEF_SB_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003756 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003757
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003758 /* Do not reorder: indices reading should complete before handling */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003759 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003760 return rc;
3761}
3762
3763/*
3764 * slow path service functions
3765 */
3766
3767static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3768{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003769 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003770 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3771 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003772 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3773 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003774 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00003775 u32 nig_mask = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003776 u32 reg_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003777
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003778 if (bp->attn_state & asserted)
3779 BNX2X_ERR("IGU ERROR\n");
3780
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003781 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3782 aeu_mask = REG_RD(bp, aeu_addr);
3783
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003784 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003785 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003786 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003787 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003788
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003789 REG_WR(bp, aeu_addr, aeu_mask);
3790 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003791
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003792 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003793 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003794 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003795
3796 if (asserted & ATTN_HARD_WIRED_MASK) {
3797 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003798
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003799 bnx2x_acquire_phy_lock(bp);
3800
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003801 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00003802 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003803
Yaniv Rosner361c3912011-06-14 01:33:19 +00003804 /* If nig_mask is not set, no need to call the update
3805 * function.
3806 */
3807 if (nig_mask) {
3808 REG_WR(bp, nig_int_mask_addr, 0);
3809
3810 bnx2x_link_attn(bp);
3811 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003812
3813 /* handle unicore attn? */
3814 }
3815 if (asserted & ATTN_SW_TIMER_4_FUNC)
3816 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3817
3818 if (asserted & GPIO_2_FUNC)
3819 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3820
3821 if (asserted & GPIO_3_FUNC)
3822 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3823
3824 if (asserted & GPIO_4_FUNC)
3825 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3826
3827 if (port == 0) {
3828 if (asserted & ATTN_GENERAL_ATTN_1) {
3829 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3830 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3831 }
3832 if (asserted & ATTN_GENERAL_ATTN_2) {
3833 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3834 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3835 }
3836 if (asserted & ATTN_GENERAL_ATTN_3) {
3837 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3838 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3839 }
3840 } else {
3841 if (asserted & ATTN_GENERAL_ATTN_4) {
3842 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3843 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3844 }
3845 if (asserted & ATTN_GENERAL_ATTN_5) {
3846 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3847 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3848 }
3849 if (asserted & ATTN_GENERAL_ATTN_6) {
3850 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3851 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3852 }
3853 }
3854
3855 } /* if hardwired */
3856
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003857 if (bp->common.int_block == INT_BLOCK_HC)
3858 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3859 COMMAND_REG_ATTN_BITS_SET);
3860 else
3861 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3862
3863 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3864 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3865 REG_WR(bp, reg_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003866
3867 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003868 if (asserted & ATTN_NIG_FOR_FUNC) {
Yaniv Rosner27c11512012-12-02 04:05:54 +00003869 /* Verify that IGU ack through BAR was written before restoring
3870 * NIG mask. This loop should exit after 2-3 iterations max.
3871 */
3872 if (bp->common.int_block != INT_BLOCK_HC) {
3873 u32 cnt = 0, igu_acked;
3874 do {
3875 igu_acked = REG_RD(bp,
3876 IGU_REG_ATTENTION_ACK_BITS);
3877 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3878 (++cnt < MAX_IGU_ATTN_ACK_TO));
3879 if (!igu_acked)
3880 DP(NETIF_MSG_HW,
3881 "Failed to verify IGU ack on time\n");
3882 barrier();
3883 }
Eilon Greenstein87942b42009-02-12 08:36:49 +00003884 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003885 bnx2x_release_phy_lock(bp);
3886 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003887}
3888
Eric Dumazet1191cb82012-04-27 21:39:21 +00003889static void bnx2x_fan_failure(struct bnx2x *bp)
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003890{
3891 int port = BP_PORT(bp);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003892 u32 ext_phy_config;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003893 /* mark the failure */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003894 ext_phy_config =
3895 SHMEM_RD(bp,
3896 dev_info.port_hw_config[port].external_phy_config);
3897
3898 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
3899 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003900 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003901 ext_phy_config);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003902
3903 /* log the failure */
Merav Sicron51c1a582012-03-18 10:33:38 +00003904 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
3905 "Please contact OEM Support for assistance\n");
Ariel Elior83048592011-11-13 04:34:29 +00003906
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003907 /* Schedule device reset (unload)
Ariel Elior83048592011-11-13 04:34:29 +00003908 * This is due to some boards consuming sufficient power when driver is
3909 * up to overheat if fan fails.
3910 */
3911 smp_mb__before_clear_bit();
3912 set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
3913 smp_mb__after_clear_bit();
3914 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003915}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003916
Eric Dumazet1191cb82012-04-27 21:39:21 +00003917static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003918{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003919 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003920 int reg_offset;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003921 u32 val;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003922
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003923 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
3924 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003925
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003926 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003927
3928 val = REG_RD(bp, reg_offset);
3929 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
3930 REG_WR(bp, reg_offset, val);
3931
3932 BNX2X_ERR("SPIO5 hw attention\n");
3933
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003934 /* Fan failure attention */
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003935 bnx2x_hw_reset_phy(&bp->link_params);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00003936 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003937 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003938
Yaniv Rosner3deb8162011-06-14 01:34:33 +00003939 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00003940 bnx2x_acquire_phy_lock(bp);
3941 bnx2x_handle_module_detect_int(&bp->link_params);
3942 bnx2x_release_phy_lock(bp);
3943 }
3944
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003945 if (attn & HW_INTERRUT_ASSERT_SET_0) {
3946
3947 val = REG_RD(bp, reg_offset);
3948 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
3949 REG_WR(bp, reg_offset, val);
3950
3951 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003952 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
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_deasserted1(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003958{
3959 u32 val;
3960
Eilon Greenstein0626b892009-02-12 08:38:14 +00003961 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003962
3963 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
3964 BNX2X_ERR("DB hw attention 0x%x\n", val);
3965 /* DORQ discard attention */
3966 if (val & 0x2)
3967 BNX2X_ERR("FATAL error from DORQ\n");
3968 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003969
3970 if (attn & HW_INTERRUT_ASSERT_SET_1) {
3971
3972 int port = BP_PORT(bp);
3973 int reg_offset;
3974
3975 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
3976 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
3977
3978 val = REG_RD(bp, reg_offset);
3979 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
3980 REG_WR(bp, reg_offset, val);
3981
3982 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00003983 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003984 bnx2x_panic();
3985 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003986}
3987
Eric Dumazet1191cb82012-04-27 21:39:21 +00003988static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003989{
3990 u32 val;
3991
3992 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
3993
3994 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
3995 BNX2X_ERR("CFC hw attention 0x%x\n", val);
3996 /* CFC error attention */
3997 if (val & 0x2)
3998 BNX2X_ERR("FATAL error from CFC\n");
3999 }
4000
4001 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004002 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004003 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004004 /* RQ_USDMDP_FIFO_OVERFLOW */
4005 if (val & 0x18000)
4006 BNX2X_ERR("FATAL error from PXP\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004007
4008 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004009 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
4010 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
4011 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004012 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004013
4014 if (attn & HW_INTERRUT_ASSERT_SET_2) {
4015
4016 int port = BP_PORT(bp);
4017 int reg_offset;
4018
4019 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
4020 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
4021
4022 val = REG_RD(bp, reg_offset);
4023 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
4024 REG_WR(bp, reg_offset, val);
4025
4026 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00004027 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004028 bnx2x_panic();
4029 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004030}
4031
Eric Dumazet1191cb82012-04-27 21:39:21 +00004032static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004033{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004034 u32 val;
4035
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004036 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
4037
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004038 if (attn & BNX2X_PMF_LINK_ASSERT) {
4039 int func = BP_FUNC(bp);
4040
4041 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Barak Witkowskia3348722012-04-23 03:04:46 +00004042 bnx2x_read_mf_cfg(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004043 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
4044 func_mf_config[BP_ABS_FUNC(bp)].config);
4045 val = SHMEM_RD(bp,
4046 func_mb[BP_FW_MB_IDX(bp)].drv_status);
Eilon Greenstein2691d512009-08-12 08:22:08 +00004047 if (val & DRV_STATUS_DCC_EVENT_MASK)
4048 bnx2x_dcc_event(bp,
4049 (val & DRV_STATUS_DCC_EVENT_MASK));
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004050
4051 if (val & DRV_STATUS_SET_MF_BW)
4052 bnx2x_set_mf_bw(bp);
4053
Barak Witkowski1d187b32011-12-05 22:41:50 +00004054 if (val & DRV_STATUS_DRV_INFO_REQ)
4055 bnx2x_handle_drv_info_req(bp);
Ariel Eliord16132c2013-01-01 05:22:42 +00004056
4057 if (val & DRV_STATUS_VF_DISABLED)
4058 bnx2x_vf_handle_flr_event(bp);
4059
Eilon Greenstein2691d512009-08-12 08:22:08 +00004060 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004061 bnx2x_pmf_update(bp);
4062
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004063 if (bp->port.pmf &&
Shmulik Ravid785b9b12010-12-30 06:27:03 +00004064 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
4065 bp->dcbx_enabled > 0)
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004066 /* start dcbx state machine */
4067 bnx2x_dcbx_set_params(bp,
4068 BNX2X_DCBX_STATE_NEG_RECEIVED);
Barak Witkowskia3348722012-04-23 03:04:46 +00004069 if (val & DRV_STATUS_AFEX_EVENT_MASK)
4070 bnx2x_handle_afex_cmd(bp,
4071 val & DRV_STATUS_AFEX_EVENT_MASK);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00004072 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
4073 bnx2x_handle_eee_event(bp);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00004074 if (bp->link_vars.periodic_flags &
4075 PERIODIC_FLAGS_LINK_EVENT) {
4076 /* sync with link */
4077 bnx2x_acquire_phy_lock(bp);
4078 bp->link_vars.periodic_flags &=
4079 ~PERIODIC_FLAGS_LINK_EVENT;
4080 bnx2x_release_phy_lock(bp);
4081 if (IS_MF(bp))
4082 bnx2x_link_sync_notify(bp);
4083 bnx2x_link_report(bp);
4084 }
4085 /* Always call it here: bnx2x_link_report() will
4086 * prevent the link indication duplication.
4087 */
4088 bnx2x__link_status_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004089 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004090
4091 BNX2X_ERR("MC assert!\n");
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00004092 bnx2x_mc_assert(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004093 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4094 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4095 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4096 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4097 bnx2x_panic();
4098
4099 } else if (attn & BNX2X_MCP_ASSERT) {
4100
4101 BNX2X_ERR("MCP assert!\n");
4102 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004103 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004104
4105 } else
4106 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4107 }
4108
4109 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004110 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4111 if (attn & BNX2X_GRC_TIMEOUT) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004112 val = CHIP_IS_E1(bp) ? 0 :
4113 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004114 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4115 }
4116 if (attn & BNX2X_GRC_RSV) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004117 val = CHIP_IS_E1(bp) ? 0 :
4118 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004119 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4120 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004121 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004122 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004123}
4124
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004125/*
4126 * Bits map:
4127 * 0-7 - Engine0 load counter.
4128 * 8-15 - Engine1 load counter.
4129 * 16 - Engine0 RESET_IN_PROGRESS bit.
4130 * 17 - Engine1 RESET_IN_PROGRESS bit.
4131 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4132 * on the engine
4133 * 19 - Engine1 ONE_IS_LOADED.
4134 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4135 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4136 * just the one belonging to its engine).
4137 *
4138 */
4139#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4140
4141#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4142#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4143#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4144#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4145#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4146#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4147#define BNX2X_GLOBAL_RESET_BIT 0x00040000
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00004148
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004149/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004150 * Set the GLOBAL_RESET bit.
4151 *
4152 * Should be run under rtnl lock
4153 */
4154void bnx2x_set_reset_global(struct bnx2x *bp)
4155{
Ariel Eliorf16da432012-01-26 06:01:50 +00004156 u32 val;
4157 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4158 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004159 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
Ariel Eliorf16da432012-01-26 06:01:50 +00004160 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004161}
4162
4163/*
4164 * Clear the GLOBAL_RESET bit.
4165 *
4166 * Should be run under rtnl lock
4167 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004168static void bnx2x_clear_reset_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004169{
Ariel Eliorf16da432012-01-26 06:01:50 +00004170 u32 val;
4171 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4172 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004173 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
Ariel Eliorf16da432012-01-26 06:01:50 +00004174 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004175}
4176
4177/*
4178 * Checks the GLOBAL_RESET bit.
4179 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004180 * should be run under rtnl lock
4181 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004182static bool bnx2x_reset_is_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004183{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004184 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004185
4186 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4187 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4188}
4189
4190/*
4191 * Clear RESET_IN_PROGRESS bit for the current engine.
4192 *
4193 * Should be run under rtnl lock
4194 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004195static void bnx2x_set_reset_done(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004196{
Ariel Eliorf16da432012-01-26 06:01:50 +00004197 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004198 u32 bit = BP_PATH(bp) ?
4199 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004200 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4201 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004202
4203 /* Clear the bit */
4204 val &= ~bit;
4205 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004206
4207 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004208}
4209
4210/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004211 * Set RESET_IN_PROGRESS for the current engine.
4212 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004213 * should be run under rtnl lock
4214 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004215void bnx2x_set_reset_in_progress(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004216{
Ariel Eliorf16da432012-01-26 06:01:50 +00004217 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004218 u32 bit = BP_PATH(bp) ?
4219 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004220 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4221 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004222
4223 /* Set the bit */
4224 val |= bit;
4225 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004226 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004227}
4228
4229/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004230 * Checks the RESET_IN_PROGRESS bit for the given engine.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004231 * should be run under rtnl lock
4232 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004233bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004234{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004235 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004236 u32 bit = engine ?
4237 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4238
4239 /* return false if bit is set */
4240 return (val & bit) ? false : true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004241}
4242
4243/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004244 * set pf load for the current pf.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004245 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004246 * should be run under rtnl lock
4247 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004248void bnx2x_set_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004249{
Ariel Eliorf16da432012-01-26 06:01:50 +00004250 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004251 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4252 BNX2X_PATH0_LOAD_CNT_MASK;
4253 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4254 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004255
Ariel Eliorf16da432012-01-26 06:01:50 +00004256 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4257 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4258
Merav Sicron51c1a582012-03-18 10:33:38 +00004259 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004260
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004261 /* get the current counter value */
4262 val1 = (val & mask) >> shift;
4263
Ariel Elior889b9af2012-01-26 06:01:51 +00004264 /* set bit of that PF */
4265 val1 |= (1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004266
4267 /* clear the old value */
4268 val &= ~mask;
4269
4270 /* set the new one */
4271 val |= ((val1 << shift) & mask);
4272
4273 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004274 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004275}
4276
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004277/**
Ariel Elior889b9af2012-01-26 06:01:51 +00004278 * bnx2x_clear_pf_load - clear pf load mark
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004279 *
4280 * @bp: driver handle
4281 *
4282 * Should be run under rtnl lock.
4283 * Decrements the load counter for the current engine. Returns
Ariel Elior889b9af2012-01-26 06:01:51 +00004284 * whether other functions are still loaded
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004285 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004286bool bnx2x_clear_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004287{
Ariel Eliorf16da432012-01-26 06:01:50 +00004288 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004289 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4290 BNX2X_PATH0_LOAD_CNT_MASK;
4291 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4292 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004293
Ariel Eliorf16da432012-01-26 06:01:50 +00004294 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4295 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Merav Sicron51c1a582012-03-18 10:33:38 +00004296 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004297
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004298 /* get the current counter value */
4299 val1 = (val & mask) >> shift;
4300
Ariel Elior889b9af2012-01-26 06:01:51 +00004301 /* clear bit of that PF */
4302 val1 &= ~(1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004303
4304 /* clear the old value */
4305 val &= ~mask;
4306
4307 /* set the new one */
4308 val |= ((val1 << shift) & mask);
4309
4310 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004311 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4312 return val1 != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004313}
4314
4315/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004316 * Read the load status for the current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004317 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004318 * should be run under rtnl lock
4319 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004320static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004321{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004322 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4323 BNX2X_PATH0_LOAD_CNT_MASK);
4324 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4325 BNX2X_PATH0_LOAD_CNT_SHIFT);
4326 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4327
Merav Sicron51c1a582012-03-18 10:33:38 +00004328 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004329
4330 val = (val & mask) >> shift;
4331
Merav Sicron51c1a582012-03-18 10:33:38 +00004332 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4333 engine, val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004334
Ariel Elior889b9af2012-01-26 06:01:51 +00004335 return val != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004336}
4337
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004338static void _print_parity(struct bnx2x *bp, u32 reg)
4339{
4340 pr_cont(" [0x%08x] ", REG_RD(bp, reg));
4341}
4342
Eric Dumazet1191cb82012-04-27 21:39:21 +00004343static void _print_next_block(int idx, const char *blk)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004344{
Joe Perchesf1deab52011-08-14 12:16:21 +00004345 pr_cont("%s%s", idx ? ", " : "", blk);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004346}
4347
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004348static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4349 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004350{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004351 u32 cur_bit;
4352 bool res;
4353 int i;
4354
4355 res = false;
4356
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004357 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004358 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004359 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004360 res |= true; /* Each bit is real error! */
4361
4362 if (print) {
4363 switch (cur_bit) {
4364 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4365 _print_next_block((*par_num)++, "BRB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004366 _print_parity(bp,
4367 BRB1_REG_BRB1_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004368 break;
4369 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4370 _print_next_block((*par_num)++,
4371 "PARSER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004372 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004373 break;
4374 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4375 _print_next_block((*par_num)++, "TSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004376 _print_parity(bp,
4377 TSDM_REG_TSDM_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004378 break;
4379 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4380 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004381 "SEARCHER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004382 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004383 break;
4384 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4385 _print_next_block((*par_num)++, "TCM");
4386 _print_parity(bp, TCM_REG_TCM_PRTY_STS);
4387 break;
4388 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4389 _print_next_block((*par_num)++,
4390 "TSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004391 _print_parity(bp,
4392 TSEM_REG_TSEM_PRTY_STS_0);
4393 _print_parity(bp,
4394 TSEM_REG_TSEM_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004395 break;
4396 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4397 _print_next_block((*par_num)++, "XPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004398 _print_parity(bp, GRCBASE_XPB +
4399 PB_REG_PB_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004400 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004401 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004402 }
4403
4404 /* Clear the bit */
4405 sig &= ~cur_bit;
4406 }
4407 }
4408
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004409 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004410}
4411
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004412static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4413 int *par_num, bool *global,
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004414 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004415{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004416 u32 cur_bit;
4417 bool res;
4418 int i;
4419
4420 res = false;
4421
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004422 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004423 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004424 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004425 res |= true; /* Each bit is real error! */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004426 switch (cur_bit) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004427 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004428 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004429 _print_next_block((*par_num)++, "PBF");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004430 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4431 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004432 break;
4433 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004434 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004435 _print_next_block((*par_num)++, "QM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004436 _print_parity(bp, QM_REG_QM_PRTY_STS);
4437 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004438 break;
4439 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004440 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004441 _print_next_block((*par_num)++, "TM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004442 _print_parity(bp, TM_REG_TM_PRTY_STS);
4443 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004444 break;
4445 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004446 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004447 _print_next_block((*par_num)++, "XSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004448 _print_parity(bp,
4449 XSDM_REG_XSDM_PRTY_STS);
4450 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004451 break;
4452 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004453 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004454 _print_next_block((*par_num)++, "XCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004455 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4456 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004457 break;
4458 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004459 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004460 _print_next_block((*par_num)++,
4461 "XSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004462 _print_parity(bp,
4463 XSEM_REG_XSEM_PRTY_STS_0);
4464 _print_parity(bp,
4465 XSEM_REG_XSEM_PRTY_STS_1);
4466 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004467 break;
4468 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004469 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004470 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004471 "DOORBELLQ");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004472 _print_parity(bp,
4473 DORQ_REG_DORQ_PRTY_STS);
4474 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004475 break;
4476 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004477 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004478 _print_next_block((*par_num)++, "NIG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004479 if (CHIP_IS_E1x(bp)) {
4480 _print_parity(bp,
4481 NIG_REG_NIG_PRTY_STS);
4482 } else {
4483 _print_parity(bp,
4484 NIG_REG_NIG_PRTY_STS_0);
4485 _print_parity(bp,
4486 NIG_REG_NIG_PRTY_STS_1);
4487 }
4488 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004489 break;
4490 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004491 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004492 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004493 "VAUX PCI CORE");
4494 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004495 break;
4496 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004497 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004498 _print_next_block((*par_num)++,
4499 "DEBUG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004500 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4501 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004502 break;
4503 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004504 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004505 _print_next_block((*par_num)++, "USDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004506 _print_parity(bp,
4507 USDM_REG_USDM_PRTY_STS);
4508 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004509 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004510 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004511 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004512 _print_next_block((*par_num)++, "UCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004513 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4514 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004515 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004516 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004517 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004518 _print_next_block((*par_num)++,
4519 "USEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004520 _print_parity(bp,
4521 USEM_REG_USEM_PRTY_STS_0);
4522 _print_parity(bp,
4523 USEM_REG_USEM_PRTY_STS_1);
4524 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004525 break;
4526 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004527 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004528 _print_next_block((*par_num)++, "UPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004529 _print_parity(bp, GRCBASE_UPB +
4530 PB_REG_PB_PRTY_STS);
4531 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004532 break;
4533 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004534 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004535 _print_next_block((*par_num)++, "CSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004536 _print_parity(bp,
4537 CSDM_REG_CSDM_PRTY_STS);
4538 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004539 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004540 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004541 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004542 _print_next_block((*par_num)++, "CCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004543 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4544 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004545 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004546 }
4547
4548 /* Clear the bit */
4549 sig &= ~cur_bit;
4550 }
4551 }
4552
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004553 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004554}
4555
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004556static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4557 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004558{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004559 u32 cur_bit;
4560 bool res;
4561 int i;
4562
4563 res = false;
4564
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004565 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004566 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004567 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004568 res |= true; /* Each bit is real error! */
4569 if (print) {
4570 switch (cur_bit) {
4571 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4572 _print_next_block((*par_num)++,
4573 "CSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004574 _print_parity(bp,
4575 CSEM_REG_CSEM_PRTY_STS_0);
4576 _print_parity(bp,
4577 CSEM_REG_CSEM_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004578 break;
4579 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4580 _print_next_block((*par_num)++, "PXP");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004581 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4582 _print_parity(bp,
4583 PXP2_REG_PXP2_PRTY_STS_0);
4584 _print_parity(bp,
4585 PXP2_REG_PXP2_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004586 break;
4587 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4588 _print_next_block((*par_num)++,
4589 "PXPPCICLOCKCLIENT");
4590 break;
4591 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4592 _print_next_block((*par_num)++, "CFC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004593 _print_parity(bp,
4594 CFC_REG_CFC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004595 break;
4596 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4597 _print_next_block((*par_num)++, "CDU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004598 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004599 break;
4600 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4601 _print_next_block((*par_num)++, "DMAE");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004602 _print_parity(bp,
4603 DMAE_REG_DMAE_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004604 break;
4605 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4606 _print_next_block((*par_num)++, "IGU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004607 if (CHIP_IS_E1x(bp))
4608 _print_parity(bp,
4609 HC_REG_HC_PRTY_STS);
4610 else
4611 _print_parity(bp,
4612 IGU_REG_IGU_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004613 break;
4614 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4615 _print_next_block((*par_num)++, "MISC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004616 _print_parity(bp,
4617 MISC_REG_MISC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004618 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004619 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004620 }
4621
4622 /* Clear the bit */
4623 sig &= ~cur_bit;
4624 }
4625 }
4626
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004627 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004628}
4629
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004630static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
4631 int *par_num, bool *global,
4632 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004633{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004634 bool res = false;
4635 u32 cur_bit;
4636 int i;
4637
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004638 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004639 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004640 if (sig & cur_bit) {
4641 switch (cur_bit) {
4642 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004643 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004644 _print_next_block((*par_num)++,
4645 "MCP ROM");
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004646 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004647 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004648 break;
4649 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004650 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004651 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004652 "MCP UMP RX");
4653 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004654 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004655 break;
4656 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004657 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004658 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004659 "MCP UMP TX");
4660 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004661 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004662 break;
4663 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004664 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004665 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004666 "MCP SCPAD");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004667 /* clear latched SCPAD PATIRY from MCP */
4668 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
4669 1UL << 10);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004670 break;
4671 }
4672
4673 /* Clear the bit */
4674 sig &= ~cur_bit;
4675 }
4676 }
4677
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004678 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004679}
4680
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004681static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4682 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004683{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004684 u32 cur_bit;
4685 bool res;
4686 int i;
4687
4688 res = false;
4689
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004690 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004691 cur_bit = (0x1UL << i);
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004692 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004693 res |= true; /* Each bit is real error! */
4694 if (print) {
4695 switch (cur_bit) {
4696 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4697 _print_next_block((*par_num)++,
4698 "PGLUE_B");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004699 _print_parity(bp,
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004700 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4701 break;
4702 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4703 _print_next_block((*par_num)++, "ATC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004704 _print_parity(bp,
4705 ATC_REG_ATC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004706 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004707 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004708 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004709 /* Clear the bit */
4710 sig &= ~cur_bit;
4711 }
4712 }
4713
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004714 return res;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004715}
4716
Eric Dumazet1191cb82012-04-27 21:39:21 +00004717static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4718 u32 *sig)
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004719{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004720 bool res = false;
4721
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004722 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4723 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4724 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4725 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4726 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004727 int par_num = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00004728 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4729 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004730 sig[0] & HW_PRTY_ASSERT_SET_0,
4731 sig[1] & HW_PRTY_ASSERT_SET_1,
4732 sig[2] & HW_PRTY_ASSERT_SET_2,
4733 sig[3] & HW_PRTY_ASSERT_SET_3,
4734 sig[4] & HW_PRTY_ASSERT_SET_4);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004735 if (print)
4736 netdev_err(bp->dev,
4737 "Parity errors detected in blocks: ");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004738 res |= bnx2x_check_blocks_with_parity0(bp,
4739 sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
4740 res |= bnx2x_check_blocks_with_parity1(bp,
4741 sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
4742 res |= bnx2x_check_blocks_with_parity2(bp,
4743 sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
4744 res |= bnx2x_check_blocks_with_parity3(bp,
4745 sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
4746 res |= bnx2x_check_blocks_with_parity4(bp,
4747 sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004748
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004749 if (print)
4750 pr_cont("\n");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004751 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004752
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004753 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004754}
4755
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004756/**
4757 * bnx2x_chk_parity_attn - checks for parity attentions.
4758 *
4759 * @bp: driver handle
4760 * @global: true if there was a global attention
4761 * @print: show parity attention in syslog
4762 */
4763bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004764{
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004765 struct attn_route attn = { {0} };
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004766 int port = BP_PORT(bp);
4767
4768 attn.sig[0] = REG_RD(bp,
4769 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4770 port*4);
4771 attn.sig[1] = REG_RD(bp,
4772 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4773 port*4);
4774 attn.sig[2] = REG_RD(bp,
4775 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4776 port*4);
4777 attn.sig[3] = REG_RD(bp,
4778 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4779 port*4);
Yuval Mintz0a5ccb72013-09-23 10:12:54 +03004780 /* Since MCP attentions can't be disabled inside the block, we need to
4781 * read AEU registers to see whether they're currently disabled
4782 */
4783 attn.sig[3] &= ((REG_RD(bp,
4784 !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
4785 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
4786 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
4787 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004788
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004789 if (!CHIP_IS_E1x(bp))
4790 attn.sig[4] = REG_RD(bp,
4791 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4792 port*4);
4793
4794 return bnx2x_parity_attn(bp, global, print, attn.sig);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004795}
4796
Eric Dumazet1191cb82012-04-27 21:39:21 +00004797static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004798{
4799 u32 val;
4800 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4801
4802 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4803 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4804 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004805 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004806 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004807 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004808 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004809 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004810 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004811 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004812 if (val &
4813 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004814 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004815 if (val &
4816 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004817 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004818 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004819 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004820 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004821 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004822 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
Merav Sicron51c1a582012-03-18 10:33:38 +00004823 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004824 }
4825 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4826 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4827 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4828 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4829 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4830 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
Merav Sicron51c1a582012-03-18 10:33:38 +00004831 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004832 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
Merav Sicron51c1a582012-03-18 10:33:38 +00004833 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004834 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
Merav Sicron51c1a582012-03-18 10:33:38 +00004835 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004836 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4837 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4838 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
Merav Sicron51c1a582012-03-18 10:33:38 +00004839 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004840 }
4841
4842 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4843 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4844 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4845 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4846 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4847 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004848}
4849
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004850static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4851{
4852 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004853 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004854 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004855 u32 reg_addr;
4856 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004857 u32 aeu_mask;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004858 bool global = false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004859
4860 /* need to take HW lock because MCP or other port might also
4861 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004862 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004863
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004864 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4865#ifndef BNX2X_STOP_ON_ERROR
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004866 bp->recovery_state = BNX2X_RECOVERY_INIT;
Ariel Elior7be08a72011-07-14 08:31:19 +00004867 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004868 /* Disable HW interrupts */
4869 bnx2x_int_disable(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004870 /* In case of parity errors don't handle attentions so that
4871 * other function would "see" parity errors.
4872 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004873#else
4874 bnx2x_panic();
4875#endif
4876 bnx2x_release_alr(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004877 return;
4878 }
4879
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004880 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4881 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4882 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4883 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004884 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004885 attn.sig[4] =
4886 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
4887 else
4888 attn.sig[4] = 0;
4889
4890 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
4891 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004892
4893 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
4894 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004895 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004896
Merav Sicron51c1a582012-03-18 10:33:38 +00004897 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004898 index,
4899 group_mask->sig[0], group_mask->sig[1],
4900 group_mask->sig[2], group_mask->sig[3],
4901 group_mask->sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004902
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004903 bnx2x_attn_int_deasserted4(bp,
4904 attn.sig[4] & group_mask->sig[4]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004905 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004906 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004907 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004908 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004909 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004910 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004911 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004912 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004913 }
4914 }
4915
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004916 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004917
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004918 if (bp->common.int_block == INT_BLOCK_HC)
4919 reg_addr = (HC_REG_COMMAND_REG + port*32 +
4920 COMMAND_REG_ATTN_BITS_CLR);
4921 else
4922 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004923
4924 val = ~deasserted;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004925 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
4926 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07004927 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004928
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004929 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004930 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004931
4932 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
4933 MISC_REG_AEU_MASK_ATTN_FUNC_0;
4934
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004935 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
4936 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004937
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004938 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
4939 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004940 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004941 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
4942
4943 REG_WR(bp, reg_addr, aeu_mask);
4944 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004945
4946 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
4947 bp->attn_state &= ~deasserted;
4948 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
4949}
4950
4951static void bnx2x_attn_int(struct bnx2x *bp)
4952{
4953 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08004954 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
4955 attn_bits);
4956 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
4957 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004958 u32 attn_state = bp->attn_state;
4959
4960 /* look for changed bits */
4961 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
4962 u32 deasserted = ~attn_bits & attn_ack & attn_state;
4963
4964 DP(NETIF_MSG_HW,
4965 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
4966 attn_bits, attn_ack, asserted, deasserted);
4967
4968 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004969 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004970
4971 /* handle bits that were raised */
4972 if (asserted)
4973 bnx2x_attn_int_asserted(bp, asserted);
4974
4975 if (deasserted)
4976 bnx2x_attn_int_deasserted(bp, deasserted);
4977}
4978
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004979void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
4980 u16 index, u8 op, u8 update)
4981{
Ariel Eliordc1ba592013-01-01 05:22:30 +00004982 u32 igu_addr = bp->igu_base_addr;
4983 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004984 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
4985 igu_addr);
4986}
4987
Eric Dumazet1191cb82012-04-27 21:39:21 +00004988static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004989{
4990 /* No memory barriers */
4991 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
4992 mmiowb(); /* keep prod updates ordered */
4993}
4994
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004995static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
4996 union event_ring_elem *elem)
4997{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004998 u8 err = elem->message.error;
4999
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005000 if (!bp->cnic_eth_dev.starting_cid ||
Vladislav Zolotarovc3a8ce62011-05-22 10:08:09 +00005001 (cid < bp->cnic_eth_dev.starting_cid &&
5002 cid != bp->cnic_eth_dev.iscsi_l2_cid))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005003 return 1;
5004
5005 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
5006
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005007 if (unlikely(err)) {
5008
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005009 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
5010 cid);
Yuval Mintz823e1d92013-01-14 05:11:47 +00005011 bnx2x_panic_dump(bp, false);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005012 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005013 bnx2x_cnic_cfc_comp(bp, cid, err);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005014 return 0;
5015}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005016
Eric Dumazet1191cb82012-04-27 21:39:21 +00005017static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005018{
5019 struct bnx2x_mcast_ramrod_params rparam;
5020 int rc;
5021
5022 memset(&rparam, 0, sizeof(rparam));
5023
5024 rparam.mcast_obj = &bp->mcast_obj;
5025
5026 netif_addr_lock_bh(bp->dev);
5027
5028 /* Clear pending state for the last command */
5029 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
5030
5031 /* If there are pending mcast commands - send them */
5032 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
5033 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
5034 if (rc < 0)
5035 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
5036 rc);
5037 }
5038
5039 netif_addr_unlock_bh(bp->dev);
5040}
5041
Eric Dumazet1191cb82012-04-27 21:39:21 +00005042static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
5043 union event_ring_elem *elem)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005044{
5045 unsigned long ramrod_flags = 0;
5046 int rc = 0;
5047 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
5048 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
5049
5050 /* Always push next commands out, don't wait here */
5051 __set_bit(RAMROD_CONT, &ramrod_flags);
5052
Yuval Mintz86564c32013-01-23 03:21:50 +00005053 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
5054 >> BNX2X_SWCID_SHIFT) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005055 case BNX2X_FILTER_MAC_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00005056 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
Merav Sicron55c11942012-11-07 00:45:48 +00005057 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005058 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
5059 else
Barak Witkowski15192a82012-06-19 07:48:28 +00005060 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005061
5062 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005063 case BNX2X_FILTER_MCAST_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00005064 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005065 /* This is only relevant for 57710 where multicast MACs are
5066 * configured as unicast MACs using the same ramrod.
5067 */
5068 bnx2x_handle_mcast_eqe(bp);
5069 return;
5070 default:
5071 BNX2X_ERR("Unsupported classification command: %d\n",
5072 elem->message.data.eth_event.echo);
5073 return;
5074 }
5075
5076 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
5077
5078 if (rc < 0)
5079 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
5080 else if (rc > 0)
5081 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005082}
5083
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005084static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005085
Eric Dumazet1191cb82012-04-27 21:39:21 +00005086static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005087{
5088 netif_addr_lock_bh(bp->dev);
5089
5090 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5091
5092 /* Send rx_mode command again if was requested */
5093 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
5094 bnx2x_set_storm_rx_mode(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005095 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
5096 &bp->sp_state))
5097 bnx2x_set_iscsi_eth_rx_mode(bp, true);
5098 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
5099 &bp->sp_state))
5100 bnx2x_set_iscsi_eth_rx_mode(bp, false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005101
5102 netif_addr_unlock_bh(bp->dev);
5103}
5104
Eric Dumazet1191cb82012-04-27 21:39:21 +00005105static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
Barak Witkowskia3348722012-04-23 03:04:46 +00005106 union event_ring_elem *elem)
5107{
5108 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
5109 DP(BNX2X_MSG_SP,
5110 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
5111 elem->message.data.vif_list_event.func_bit_map);
5112 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
5113 elem->message.data.vif_list_event.func_bit_map);
5114 } else if (elem->message.data.vif_list_event.echo ==
5115 VIF_LIST_RULE_SET) {
5116 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
5117 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
5118 }
5119}
5120
5121/* called with rtnl_lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005122static void bnx2x_after_function_update(struct bnx2x *bp)
Barak Witkowskia3348722012-04-23 03:04:46 +00005123{
5124 int q, rc;
5125 struct bnx2x_fastpath *fp;
5126 struct bnx2x_queue_state_params queue_params = {NULL};
5127 struct bnx2x_queue_update_params *q_update_params =
5128 &queue_params.params.update;
5129
Yuval Mintz2de67432013-01-23 03:21:43 +00005130 /* Send Q update command with afex vlan removal values for all Qs */
Barak Witkowskia3348722012-04-23 03:04:46 +00005131 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
5132
5133 /* set silent vlan removal values according to vlan mode */
5134 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
5135 &q_update_params->update_flags);
5136 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
5137 &q_update_params->update_flags);
5138 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5139
5140 /* in access mode mark mask and value are 0 to strip all vlans */
5141 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
5142 q_update_params->silent_removal_value = 0;
5143 q_update_params->silent_removal_mask = 0;
5144 } else {
5145 q_update_params->silent_removal_value =
5146 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
5147 q_update_params->silent_removal_mask = VLAN_VID_MASK;
5148 }
5149
5150 for_each_eth_queue(bp, q) {
5151 /* Set the appropriate Queue object */
5152 fp = &bp->fp[q];
Barak Witkowski15192a82012-06-19 07:48:28 +00005153 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005154
5155 /* send the ramrod */
5156 rc = bnx2x_queue_state_change(bp, &queue_params);
5157 if (rc < 0)
5158 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5159 q);
5160 }
5161
Yuval Mintzfea75642013-04-10 13:34:39 +03005162 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
Merav Sicron65565882012-06-19 07:48:26 +00005163 fp = &bp->fp[FCOE_IDX(bp)];
Barak Witkowski15192a82012-06-19 07:48:28 +00005164 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005165
5166 /* clear pending completion bit */
5167 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5168
5169 /* mark latest Q bit */
5170 smp_mb__before_clear_bit();
5171 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
5172 smp_mb__after_clear_bit();
5173
5174 /* send Q update ramrod for FCoE Q */
5175 rc = bnx2x_queue_state_change(bp, &queue_params);
5176 if (rc < 0)
5177 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5178 q);
5179 } else {
5180 /* If no FCoE ring - ACK MCP now */
5181 bnx2x_link_report(bp);
5182 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5183 }
Barak Witkowskia3348722012-04-23 03:04:46 +00005184}
5185
Eric Dumazet1191cb82012-04-27 21:39:21 +00005186static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005187 struct bnx2x *bp, u32 cid)
5188{
Joe Perches94f05b02011-08-14 12:16:20 +00005189 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005190
5191 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
Barak Witkowski15192a82012-06-19 07:48:28 +00005192 return &bnx2x_fcoe_sp_obj(bp, q_obj);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005193 else
Barak Witkowski15192a82012-06-19 07:48:28 +00005194 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005195}
5196
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005197static void bnx2x_eq_int(struct bnx2x *bp)
5198{
5199 u16 hw_cons, sw_cons, sw_prod;
5200 union event_ring_elem *elem;
Merav Sicron55c11942012-11-07 00:45:48 +00005201 u8 echo;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005202 u32 cid;
5203 u8 opcode;
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005204 int rc, spqe_cnt = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005205 struct bnx2x_queue_sp_obj *q_obj;
5206 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
5207 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005208
5209 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5210
5211 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005212 * when we get the next-page we need to adjust so the loop
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005213 * condition below will be met. The next element is the size of a
5214 * regular element and hence incrementing by 1
5215 */
5216 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5217 hw_cons++;
5218
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005219 /* This function may never run in parallel with itself for a
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005220 * specific bp, thus there is no need in "paired" read memory
5221 * barrier here.
5222 */
5223 sw_cons = bp->eq_cons;
5224 sw_prod = bp->eq_prod;
5225
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005226 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005227 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005228
5229 for (; sw_cons != hw_cons;
5230 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5231
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005232 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5233
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005234 rc = bnx2x_iov_eq_sp_event(bp, elem);
5235 if (!rc) {
5236 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5237 rc);
5238 goto next_spqe;
5239 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005240
Yuval Mintz86564c32013-01-23 03:21:50 +00005241 /* elem CID originates from FW; actually LE */
5242 cid = SW_CID((__force __le32)
5243 elem->message.data.cfc_del_event.cid);
5244 opcode = elem->message.opcode;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005245
5246 /* handle eq element */
5247 switch (opcode) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005248 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
5249 DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
5250 bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
5251 continue;
5252
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005253 case EVENT_RING_OPCODE_STAT_QUERY:
Yuval Mintz76ca70f2014-02-12 18:19:49 +02005254 DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
5255 "got statistics comp event %d\n",
5256 bp->stats_comp++);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005257 /* nothing to do with stats comp */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005258 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005259
5260 case EVENT_RING_OPCODE_CFC_DEL:
5261 /* handle according to cid range */
5262 /*
5263 * we may want to verify here that the bp state is
5264 * HALTING
5265 */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005266 DP(BNX2X_MSG_SP,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005267 "got delete ramrod for MULTI[%d]\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005268
5269 if (CNIC_LOADED(bp) &&
5270 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005271 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005272
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005273 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5274
5275 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5276 break;
5277
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005278 goto next_spqe;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005279
5280 case EVENT_RING_OPCODE_STOP_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005281 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02005282 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005283 if (f_obj->complete_cmd(bp, f_obj,
5284 BNX2X_F_CMD_TX_STOP))
5285 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005286 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005287
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005288 case EVENT_RING_OPCODE_START_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005289 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02005290 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005291 if (f_obj->complete_cmd(bp, f_obj,
5292 BNX2X_F_CMD_TX_START))
5293 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005294 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005295
Barak Witkowskia3348722012-04-23 03:04:46 +00005296 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
Merav Sicron55c11942012-11-07 00:45:48 +00005297 echo = elem->message.data.function_update_event.echo;
5298 if (echo == SWITCH_UPDATE) {
5299 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5300 "got FUNC_SWITCH_UPDATE ramrod\n");
5301 if (f_obj->complete_cmd(
5302 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5303 break;
Barak Witkowskia3348722012-04-23 03:04:46 +00005304
Merav Sicron55c11942012-11-07 00:45:48 +00005305 } else {
5306 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5307 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5308 f_obj->complete_cmd(bp, f_obj,
5309 BNX2X_F_CMD_AFEX_UPDATE);
Barak Witkowskia3348722012-04-23 03:04:46 +00005310
Merav Sicron55c11942012-11-07 00:45:48 +00005311 /* We will perform the Queues update from
5312 * sp_rtnl task as all Queue SP operations
5313 * should run under rtnl_lock.
5314 */
5315 smp_mb__before_clear_bit();
5316 set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
5317 &bp->sp_rtnl_state);
5318 smp_mb__after_clear_bit();
5319
5320 schedule_delayed_work(&bp->sp_rtnl_task, 0);
5321 }
5322
Barak Witkowskia3348722012-04-23 03:04:46 +00005323 goto next_spqe;
5324
5325 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5326 f_obj->complete_cmd(bp, f_obj,
5327 BNX2X_F_CMD_AFEX_VIFLISTS);
5328 bnx2x_after_afex_vif_lists(bp, elem);
5329 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005330 case EVENT_RING_OPCODE_FUNCTION_START:
Merav Sicron51c1a582012-03-18 10:33:38 +00005331 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5332 "got FUNC_START ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005333 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5334 break;
5335
5336 goto next_spqe;
5337
5338 case EVENT_RING_OPCODE_FUNCTION_STOP:
Merav Sicron51c1a582012-03-18 10:33:38 +00005339 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5340 "got FUNC_STOP ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005341 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5342 break;
5343
5344 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005345 }
5346
5347 switch (opcode | bp->state) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005348 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5349 BNX2X_STATE_OPEN):
5350 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005351 BNX2X_STATE_OPENING_WAIT4_PORT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005352 cid = elem->message.data.eth_event.echo &
5353 BNX2X_SWCID_MASK;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005354 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005355 cid);
5356 rss_raw->clear_pending(rss_raw);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005357 break;
5358
5359 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5360 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005361 case (EVENT_RING_OPCODE_SET_MAC |
5362 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005363 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5364 BNX2X_STATE_OPEN):
5365 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5366 BNX2X_STATE_DIAG):
5367 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5368 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005369 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005370 bnx2x_handle_classification_eqe(bp, elem);
5371 break;
5372
5373 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5374 BNX2X_STATE_OPEN):
5375 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5376 BNX2X_STATE_DIAG):
5377 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5378 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005379 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005380 bnx2x_handle_mcast_eqe(bp);
5381 break;
5382
5383 case (EVENT_RING_OPCODE_FILTERS_RULES |
5384 BNX2X_STATE_OPEN):
5385 case (EVENT_RING_OPCODE_FILTERS_RULES |
5386 BNX2X_STATE_DIAG):
5387 case (EVENT_RING_OPCODE_FILTERS_RULES |
5388 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005389 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005390 bnx2x_handle_rx_mode_eqe(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005391 break;
5392 default:
5393 /* unknown event log error and continue */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005394 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5395 elem->message.opcode, bp->state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005396 }
5397next_spqe:
5398 spqe_cnt++;
5399 } /* for */
5400
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +00005401 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005402 atomic_add(spqe_cnt, &bp->eq_spq_left);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005403
5404 bp->eq_cons = sw_cons;
5405 bp->eq_prod = sw_prod;
5406 /* Make sure that above mem writes were issued towards the memory */
5407 smp_wmb();
5408
5409 /* update producer */
5410 bnx2x_update_eq_prod(bp, bp->eq_prod);
5411}
5412
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005413static void bnx2x_sp_task(struct work_struct *work)
5414{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08005415 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005416
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005417 DP(BNX2X_MSG_SP, "sp task invoked\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005418
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005419 /* make sure the atomic interrupt_occurred has been written */
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005420 smp_rmb();
5421 if (atomic_read(&bp->interrupt_occurred)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005422
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005423 /* what work needs to be performed? */
5424 u16 status = bnx2x_update_dsb_idx(bp);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005425
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005426 DP(BNX2X_MSG_SP, "status %x\n", status);
5427 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5428 atomic_set(&bp->interrupt_occurred, 0);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005429
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005430 /* HW attentions */
5431 if (status & BNX2X_DEF_SB_ATT_IDX) {
5432 bnx2x_attn_int(bp);
5433 status &= ~BNX2X_DEF_SB_ATT_IDX;
Vladislav Zolotarov019dbb42011-07-19 01:43:25 +00005434 }
Merav Sicron55c11942012-11-07 00:45:48 +00005435
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005436 /* SP events: STAT_QUERY and others */
5437 if (status & BNX2X_DEF_SB_IDX) {
5438 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005439
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005440 if (FCOE_INIT(bp) &&
5441 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5442 /* Prevent local bottom-halves from running as
5443 * we are going to change the local NAPI list.
5444 */
5445 local_bh_disable();
5446 napi_schedule(&bnx2x_fcoe(bp, napi));
5447 local_bh_enable();
5448 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005449
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005450 /* Handle EQ completions */
5451 bnx2x_eq_int(bp);
5452 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5453 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5454
5455 status &= ~BNX2X_DEF_SB_IDX;
5456 }
5457
5458 /* if status is non zero then perhaps something went wrong */
5459 if (unlikely(status))
5460 DP(BNX2X_MSG_SP,
5461 "got an unknown interrupt! (status 0x%x)\n", status);
5462
5463 /* ack status block only if something was actually handled */
5464 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5465 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005466 }
5467
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005468 /* must be called after the EQ processing (since eq leads to sriov
5469 * ramrod completion flows).
5470 * This flow may have been scheduled by the arrival of a ramrod
5471 * completion, or by the sriov code rescheduling itself.
5472 */
5473 bnx2x_iov_sp_task(bp);
Barak Witkowskia3348722012-04-23 03:04:46 +00005474
5475 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5476 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5477 &bp->sp_state)) {
5478 bnx2x_link_report(bp);
5479 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5480 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005481}
5482
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005483irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005484{
5485 struct net_device *dev = dev_instance;
5486 struct bnx2x *bp = netdev_priv(dev);
5487
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005488 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5489 IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005490
5491#ifdef BNX2X_STOP_ON_ERROR
5492 if (unlikely(bp->panic))
5493 return IRQ_HANDLED;
5494#endif
5495
Merav Sicron55c11942012-11-07 00:45:48 +00005496 if (CNIC_LOADED(bp)) {
Michael Chan993ac7b2009-10-10 13:46:56 +00005497 struct cnic_ops *c_ops;
5498
5499 rcu_read_lock();
5500 c_ops = rcu_dereference(bp->cnic_ops);
5501 if (c_ops)
5502 c_ops->cnic_handler(bp->cnic_data, NULL);
5503 rcu_read_unlock();
5504 }
Merav Sicron55c11942012-11-07 00:45:48 +00005505
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005506 /* schedule sp task to perform default status block work, ack
5507 * attentions and enable interrupts.
5508 */
5509 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005510
5511 return IRQ_HANDLED;
5512}
5513
5514/* end of slow path */
5515
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005516void bnx2x_drv_pulse(struct bnx2x *bp)
5517{
5518 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5519 bp->fw_drv_pulse_wr_seq);
5520}
5521
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005522static void bnx2x_timer(unsigned long data)
5523{
5524 struct bnx2x *bp = (struct bnx2x *) data;
5525
5526 if (!netif_running(bp->dev))
5527 return;
5528
Ariel Elior67c431a2013-01-01 05:22:36 +00005529 if (IS_PF(bp) &&
5530 !BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005531 int mb_idx = BP_FW_MB_IDX(bp);
Eilon Greenstein4c868662013-09-23 10:12:50 +03005532 u16 drv_pulse;
5533 u16 mcp_pulse;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005534
5535 ++bp->fw_drv_pulse_wr_seq;
5536 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005537 drv_pulse = bp->fw_drv_pulse_wr_seq;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005538 bnx2x_drv_pulse(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005539
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005540 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005541 MCP_PULSE_SEQ_MASK);
5542 /* The delta between driver pulse and mcp response
Eilon Greenstein4c868662013-09-23 10:12:50 +03005543 * should not get too big. If the MFW is more than 5 pulses
5544 * behind, we should worry about it enough to generate an error
5545 * log.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005546 */
Eilon Greenstein4c868662013-09-23 10:12:50 +03005547 if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
5548 BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005549 drv_pulse, mcp_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005550 }
5551
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07005552 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07005553 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005554
Ariel Eliorabc5a022013-01-01 05:22:43 +00005555 /* sample pf vf bulletin board for new posts from pf */
Yuval Mintz371734882013-06-24 11:04:10 +03005556 if (IS_VF(bp))
5557 bnx2x_timer_sriov(bp);
Ariel Elior78c3bcc2013-06-20 17:39:08 +03005558
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005559 mod_timer(&bp->timer, jiffies + bp->current_interval);
5560}
5561
5562/* end of Statistics */
5563
5564/* nic init */
5565
5566/*
5567 * nic init service functions
5568 */
5569
Eric Dumazet1191cb82012-04-27 21:39:21 +00005570static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005571{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005572 u32 i;
5573 if (!(len%4) && !(addr%4))
5574 for (i = 0; i < len; i += 4)
5575 REG_WR(bp, addr + i, fill);
5576 else
5577 for (i = 0; i < len; i++)
5578 REG_WR8(bp, addr + i, fill);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005579}
5580
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005581/* helper: writes FP SP data to FW - data_size in dwords */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005582static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5583 int fw_sb_id,
5584 u32 *sb_data_p,
5585 u32 data_size)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005586{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005587 int index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005588 for (index = 0; index < data_size; index++)
5589 REG_WR(bp, BAR_CSTRORM_INTMEM +
5590 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5591 sizeof(u32)*index,
5592 *(sb_data_p + index));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005593}
5594
Eric Dumazet1191cb82012-04-27 21:39:21 +00005595static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005596{
5597 u32 *sb_data_p;
5598 u32 data_size = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005599 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005600 struct hc_status_block_data_e1x sb_data_e1x;
5601
5602 /* disable the function first */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005603 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005604 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005605 sb_data_e2.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005606 sb_data_e2.common.p_func.vf_valid = false;
5607 sb_data_p = (u32 *)&sb_data_e2;
5608 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5609 } else {
5610 memset(&sb_data_e1x, 0,
5611 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005612 sb_data_e1x.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005613 sb_data_e1x.common.p_func.vf_valid = false;
5614 sb_data_p = (u32 *)&sb_data_e1x;
5615 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5616 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005617 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5618
5619 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5620 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5621 CSTORM_STATUS_BLOCK_SIZE);
5622 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5623 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5624 CSTORM_SYNC_BLOCK_SIZE);
5625}
5626
5627/* helper: writes SP SB data to FW */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005628static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005629 struct hc_sp_status_block_data *sp_sb_data)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005630{
5631 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005632 int i;
5633 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5634 REG_WR(bp, BAR_CSTRORM_INTMEM +
5635 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5636 i*sizeof(u32),
5637 *((u32 *)sp_sb_data + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005638}
5639
Eric Dumazet1191cb82012-04-27 21:39:21 +00005640static void bnx2x_zero_sp_sb(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005641{
5642 int func = BP_FUNC(bp);
5643 struct hc_sp_status_block_data sp_sb_data;
5644 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5645
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005646 sp_sb_data.state = SB_DISABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005647 sp_sb_data.p_func.vf_valid = false;
5648
5649 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5650
5651 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5652 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5653 CSTORM_SP_STATUS_BLOCK_SIZE);
5654 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5655 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5656 CSTORM_SP_SYNC_BLOCK_SIZE);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005657}
5658
Eric Dumazet1191cb82012-04-27 21:39:21 +00005659static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005660 int igu_sb_id, int igu_seg_id)
5661{
5662 hc_sm->igu_sb_id = igu_sb_id;
5663 hc_sm->igu_seg_id = igu_seg_id;
5664 hc_sm->timer_value = 0xFF;
5665 hc_sm->time_to_expire = 0xFFFFFFFF;
5666}
5667
David S. Miller8decf862011-09-22 03:23:13 -04005668/* allocates state machine ids. */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005669static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
David S. Miller8decf862011-09-22 03:23:13 -04005670{
5671 /* zero out state machine indices */
5672 /* rx indices */
5673 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5674
5675 /* tx indices */
5676 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5677 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5678 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5679 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5680
5681 /* map indices */
5682 /* rx indices */
5683 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5684 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5685
5686 /* tx indices */
5687 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5688 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5689 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5690 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5691 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5692 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5693 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5694 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5695}
5696
Ariel Eliorb93288d2013-01-01 05:22:35 +00005697void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005698 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5699{
5700 int igu_seg_id;
5701
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005702 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005703 struct hc_status_block_data_e1x sb_data_e1x;
5704 struct hc_status_block_sm *hc_sm_p;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005705 int data_size;
5706 u32 *sb_data_p;
5707
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005708 if (CHIP_INT_MODE_IS_BC(bp))
5709 igu_seg_id = HC_SEG_ACCESS_NORM;
5710 else
5711 igu_seg_id = IGU_SEG_ACCESS_NORM;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005712
5713 bnx2x_zero_fp_sb(bp, fw_sb_id);
5714
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005715 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005716 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005717 sb_data_e2.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005718 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5719 sb_data_e2.common.p_func.vf_id = vfid;
5720 sb_data_e2.common.p_func.vf_valid = vf_valid;
5721 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5722 sb_data_e2.common.same_igu_sb_1b = true;
5723 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5724 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5725 hc_sm_p = sb_data_e2.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005726 sb_data_p = (u32 *)&sb_data_e2;
5727 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005728 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005729 } else {
5730 memset(&sb_data_e1x, 0,
5731 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005732 sb_data_e1x.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005733 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5734 sb_data_e1x.common.p_func.vf_id = 0xff;
5735 sb_data_e1x.common.p_func.vf_valid = false;
5736 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5737 sb_data_e1x.common.same_igu_sb_1b = true;
5738 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5739 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5740 hc_sm_p = sb_data_e1x.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005741 sb_data_p = (u32 *)&sb_data_e1x;
5742 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005743 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005744 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005745
5746 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5747 igu_sb_id, igu_seg_id);
5748 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5749 igu_sb_id, igu_seg_id);
5750
Merav Sicron51c1a582012-03-18 10:33:38 +00005751 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005752
Yuval Mintz86564c32013-01-23 03:21:50 +00005753 /* write indices to HW - PCI guarantees endianity of regpairs */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005754 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5755}
5756
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005757static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005758 u16 tx_usec, u16 rx_usec)
5759{
Ariel Elior6383c0b2011-07-14 08:31:57 +00005760 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005761 false, rx_usec);
Ariel Elior6383c0b2011-07-14 08:31:57 +00005762 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5763 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5764 tx_usec);
5765 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5766 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5767 tx_usec);
5768 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5769 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5770 tx_usec);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005771}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005772
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005773static void bnx2x_init_def_sb(struct bnx2x *bp)
5774{
5775 struct host_sp_status_block *def_sb = bp->def_status_blk;
5776 dma_addr_t mapping = bp->def_status_blk_mapping;
5777 int igu_sp_sb_index;
5778 int igu_seg_id;
5779 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005780 int func = BP_FUNC(bp);
David S. Miller88c51002011-10-07 13:38:43 -04005781 int reg_offset, reg_offset_en5;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005782 u64 section;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005783 int index;
5784 struct hc_sp_status_block_data sp_sb_data;
5785 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5786
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005787 if (CHIP_INT_MODE_IS_BC(bp)) {
5788 igu_sp_sb_index = DEF_SB_IGU_ID;
5789 igu_seg_id = HC_SEG_ACCESS_DEF;
5790 } else {
5791 igu_sp_sb_index = bp->igu_dsb_id;
5792 igu_seg_id = IGU_SEG_ACCESS_DEF;
5793 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005794
5795 /* ATTN */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005796 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005797 atten_status_block);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005798 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005799
Eliezer Tamir49d66772008-02-28 11:53:13 -08005800 bp->attn_state = 0;
5801
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005802 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5803 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
David S. Miller88c51002011-10-07 13:38:43 -04005804 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5805 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005806 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005807 int sindex;
5808 /* take care of sig[0]..sig[4] */
5809 for (sindex = 0; sindex < 4; sindex++)
5810 bp->attn_group[index].sig[sindex] =
5811 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005812
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005813 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005814 /*
5815 * enable5 is separate from the rest of the registers,
5816 * and therefore the address skip is 4
5817 * and not 16 between the different groups
5818 */
5819 bp->attn_group[index].sig[4] = REG_RD(bp,
David S. Miller88c51002011-10-07 13:38:43 -04005820 reg_offset_en5 + 0x4*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005821 else
5822 bp->attn_group[index].sig[4] = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005823 }
5824
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005825 if (bp->common.int_block == INT_BLOCK_HC) {
5826 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5827 HC_REG_ATTN_MSG0_ADDR_L);
5828
5829 REG_WR(bp, reg_offset, U64_LO(section));
5830 REG_WR(bp, reg_offset + 4, U64_HI(section));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005831 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005832 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5833 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5834 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005835
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005836 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5837 sp_sb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005838
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005839 bnx2x_zero_sp_sb(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005840
Yuval Mintz86564c32013-01-23 03:21:50 +00005841 /* PCI guarantees endianity of regpairs */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005842 sp_sb_data.state = SB_ENABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005843 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5844 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5845 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5846 sp_sb_data.igu_seg_id = igu_seg_id;
5847 sp_sb_data.p_func.pf_id = func;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005848 sp_sb_data.p_func.vnic_id = BP_VN(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005849 sp_sb_data.p_func.vf_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005850
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005851 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005852
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005853 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005854}
5855
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005856void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005857{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005858 int i;
5859
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005860 for_each_eth_queue(bp, i)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005861 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
Ariel Elior423cfa7e2011-03-14 13:43:22 -07005862 bp->tx_ticks, bp->rx_ticks);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005863}
5864
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005865static void bnx2x_init_sp_ring(struct bnx2x *bp)
5866{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005867 spin_lock_init(&bp->spq_lock);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005868 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005869
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005870 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005871 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5872 bp->spq_prod_bd = bp->spq;
5873 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005874}
5875
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005876static void bnx2x_init_eq_ring(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005877{
5878 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005879 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5880 union event_ring_elem *elem =
5881 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005882
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005883 elem->next_page.addr.hi =
5884 cpu_to_le32(U64_HI(bp->eq_mapping +
5885 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5886 elem->next_page.addr.lo =
5887 cpu_to_le32(U64_LO(bp->eq_mapping +
5888 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005889 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005890 bp->eq_cons = 0;
5891 bp->eq_prod = NUM_EQ_DESC;
5892 bp->eq_cons_sb = BNX2X_EQ_INDEX;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005893 /* we want a warning message before it gets wrought... */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005894 atomic_set(&bp->eq_spq_left,
5895 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005896}
5897
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005898/* called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -08005899static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
5900 unsigned long rx_mode_flags,
5901 unsigned long rx_accept_flags,
5902 unsigned long tx_accept_flags,
5903 unsigned long ramrod_flags)
Tom Herbertab532cf2011-02-16 10:27:02 +00005904{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005905 struct bnx2x_rx_mode_ramrod_params ramrod_param;
5906 int rc;
Tom Herbertab532cf2011-02-16 10:27:02 +00005907
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005908 memset(&ramrod_param, 0, sizeof(ramrod_param));
Tom Herbertab532cf2011-02-16 10:27:02 +00005909
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005910 /* Prepare ramrod parameters */
5911 ramrod_param.cid = 0;
5912 ramrod_param.cl_id = cl_id;
5913 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
5914 ramrod_param.func_id = BP_FUNC(bp);
5915
5916 ramrod_param.pstate = &bp->sp_state;
5917 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
5918
5919 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
5920 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
5921
5922 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5923
5924 ramrod_param.ramrod_flags = ramrod_flags;
5925 ramrod_param.rx_mode_flags = rx_mode_flags;
5926
5927 ramrod_param.rx_accept_flags = rx_accept_flags;
5928 ramrod_param.tx_accept_flags = tx_accept_flags;
5929
5930 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
5931 if (rc < 0) {
5932 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
Yuval Mintz924d75a2013-01-23 03:21:44 +00005933 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005934 }
Yuval Mintz924d75a2013-01-23 03:21:44 +00005935
5936 return 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005937}
5938
Yuval Mintz86564c32013-01-23 03:21:50 +00005939static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
5940 unsigned long *rx_accept_flags,
5941 unsigned long *tx_accept_flags)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005942{
Yuval Mintz924d75a2013-01-23 03:21:44 +00005943 /* Clear the flags first */
5944 *rx_accept_flags = 0;
5945 *tx_accept_flags = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005946
Yuval Mintz924d75a2013-01-23 03:21:44 +00005947 switch (rx_mode) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005948 case BNX2X_RX_MODE_NONE:
5949 /*
5950 * 'drop all' supersedes any accept flags that may have been
5951 * passed to the function.
5952 */
5953 break;
5954 case BNX2X_RX_MODE_NORMAL:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005955 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5956 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
5957 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005958
5959 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005960 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5961 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
5962 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005963
5964 break;
5965 case BNX2X_RX_MODE_ALLMULTI:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005966 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5967 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5968 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005969
5970 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005971 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
5972 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5973 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005974
5975 break;
5976 case BNX2X_RX_MODE_PROMISC:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005977 /* According to definition of SI mode, iface in promisc mode
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005978 * should receive matched and unmatched (in resolution of port)
5979 * unicast packets.
5980 */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005981 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
5982 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
5983 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
5984 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005985
5986 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00005987 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
5988 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005989
5990 if (IS_MF_SI(bp))
Yuval Mintz924d75a2013-01-23 03:21:44 +00005991 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005992 else
Yuval Mintz924d75a2013-01-23 03:21:44 +00005993 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005994
5995 break;
5996 default:
Yuval Mintz924d75a2013-01-23 03:21:44 +00005997 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
5998 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005999 }
6000
Yuval Mintz924d75a2013-01-23 03:21:44 +00006001 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006002 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
Yuval Mintz924d75a2013-01-23 03:21:44 +00006003 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
6004 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006005 }
6006
Yuval Mintz924d75a2013-01-23 03:21:44 +00006007 return 0;
6008}
6009
6010/* called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -08006011static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
Yuval Mintz924d75a2013-01-23 03:21:44 +00006012{
6013 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
6014 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
6015 int rc;
6016
6017 if (!NO_FCOE(bp))
6018 /* Configure rx_mode of FCoE Queue */
6019 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
6020
6021 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
6022 &tx_accept_flags);
6023 if (rc)
6024 return rc;
6025
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006026 __set_bit(RAMROD_RX, &ramrod_flags);
6027 __set_bit(RAMROD_TX, &ramrod_flags);
6028
Yuval Mintz924d75a2013-01-23 03:21:44 +00006029 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
6030 rx_accept_flags, tx_accept_flags,
6031 ramrod_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006032}
6033
Eilon Greenstein471de712008-08-13 15:49:35 -07006034static void bnx2x_init_internal_common(struct bnx2x *bp)
6035{
6036 int i;
6037
6038 /* Zero this manually as its initialization is
6039 currently missing in the initTool */
6040 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
6041 REG_WR(bp, BAR_USTRORM_INTMEM +
6042 USTORM_AGG_DATA_OFFSET + i * 4, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006043 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006044 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
6045 CHIP_INT_MODE_IS_BC(bp) ?
6046 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
6047 }
Eilon Greenstein471de712008-08-13 15:49:35 -07006048}
6049
Eilon Greenstein471de712008-08-13 15:49:35 -07006050static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
6051{
6052 switch (load_code) {
6053 case FW_MSG_CODE_DRV_LOAD_COMMON:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006054 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
Eilon Greenstein471de712008-08-13 15:49:35 -07006055 bnx2x_init_internal_common(bp);
6056 /* no break */
6057
6058 case FW_MSG_CODE_DRV_LOAD_PORT:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006059 /* nothing to do */
Eilon Greenstein471de712008-08-13 15:49:35 -07006060 /* no break */
6061
6062 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006063 /* internal memory per function is
6064 initialized inside bnx2x_pf_init */
Eilon Greenstein471de712008-08-13 15:49:35 -07006065 break;
6066
6067 default:
6068 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6069 break;
6070 }
6071}
6072
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006073static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
6074{
Merav Sicron55c11942012-11-07 00:45:48 +00006075 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006076}
6077
6078static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
6079{
Merav Sicron55c11942012-11-07 00:45:48 +00006080 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006081}
6082
Eric Dumazet1191cb82012-04-27 21:39:21 +00006083static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006084{
6085 if (CHIP_IS_E1x(fp->bp))
6086 return BP_L_ID(fp->bp) + fp->index;
6087 else /* We want Client ID to be the same as IGU SB ID for 57712 */
6088 return bnx2x_fp_igu_sb_id(fp);
6089}
6090
Ariel Elior6383c0b2011-07-14 08:31:57 +00006091static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006092{
6093 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
Ariel Elior6383c0b2011-07-14 08:31:57 +00006094 u8 cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006095 unsigned long q_type = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006096 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
Dmitry Kravkovf233caf2011-11-13 04:34:22 +00006097 fp->rx_queue = fp_idx;
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006098 fp->cid = fp_idx;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006099 fp->cl_id = bnx2x_fp_cl_id(fp);
6100 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
6101 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006102 /* qZone id equals to FW (per path) client id */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006103 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
6104
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006105 /* init shortcut */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006106 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
Ariel Elior7a752992012-01-26 06:01:53 +00006107
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006108 /* Setup SB indices */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006109 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006110
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006111 /* Configure Queue State object */
6112 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6113 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
Ariel Elior6383c0b2011-07-14 08:31:57 +00006114
6115 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
6116
6117 /* init tx data */
6118 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00006119 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
6120 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
6121 FP_COS_TO_TXQ(fp, cos, bp),
6122 BNX2X_TX_SB_INDEX_BASE + cos, fp);
6123 cids[cos] = fp->txdata_ptr[cos]->cid;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006124 }
6125
Ariel Eliorad5afc82013-01-01 05:22:26 +00006126 /* nothing more for vf to do here */
6127 if (IS_VF(bp))
6128 return;
6129
6130 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
6131 fp->fw_sb_id, fp->igu_sb_id);
6132 bnx2x_update_fpsb_idx(fp);
Barak Witkowski15192a82012-06-19 07:48:28 +00006133 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
6134 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
Ariel Elior6383c0b2011-07-14 08:31:57 +00006135 bnx2x_sp_mapping(bp, q_rdata), q_type);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006136
6137 /**
6138 * Configure classification DBs: Always enable Tx switching
6139 */
6140 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
6141
Ariel Eliorad5afc82013-01-01 05:22:26 +00006142 DP(NETIF_MSG_IFUP,
6143 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6144 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6145 fp->igu_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006146}
6147
Eric Dumazet1191cb82012-04-27 21:39:21 +00006148static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
6149{
6150 int i;
6151
6152 for (i = 1; i <= NUM_TX_RINGS; i++) {
6153 struct eth_tx_next_bd *tx_next_bd =
6154 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
6155
6156 tx_next_bd->addr_hi =
6157 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
6158 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6159 tx_next_bd->addr_lo =
6160 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
6161 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6162 }
6163
Yuval Mintz639d65b2013-06-02 00:06:21 +00006164 *txdata->tx_cons_sb = cpu_to_le16(0);
6165
Eric Dumazet1191cb82012-04-27 21:39:21 +00006166 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
6167 txdata->tx_db.data.zero_fill1 = 0;
6168 txdata->tx_db.data.prod = 0;
6169
6170 txdata->tx_pkt_prod = 0;
6171 txdata->tx_pkt_cons = 0;
6172 txdata->tx_bd_prod = 0;
6173 txdata->tx_bd_cons = 0;
6174 txdata->tx_pkt = 0;
6175}
6176
Merav Sicron55c11942012-11-07 00:45:48 +00006177static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
6178{
6179 int i;
6180
6181 for_each_tx_queue_cnic(bp, i)
6182 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
6183}
Yuval Mintzd76a6112013-06-02 00:06:17 +00006184
Eric Dumazet1191cb82012-04-27 21:39:21 +00006185static void bnx2x_init_tx_rings(struct bnx2x *bp)
6186{
6187 int i;
6188 u8 cos;
6189
Merav Sicron55c11942012-11-07 00:45:48 +00006190 for_each_eth_queue(bp, i)
Eric Dumazet1191cb82012-04-27 21:39:21 +00006191 for_each_cos_in_tx_queue(&bp->fp[i], cos)
Merav Sicron65565882012-06-19 07:48:26 +00006192 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
Eric Dumazet1191cb82012-04-27 21:39:21 +00006193}
6194
stephen hemmingera8f47eb2014-01-09 22:20:11 -08006195static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
6196{
6197 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
6198 unsigned long q_type = 0;
6199
6200 bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
6201 bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
6202 BNX2X_FCOE_ETH_CL_ID_IDX);
6203 bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
6204 bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
6205 bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
6206 bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
6207 bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
6208 fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
6209 fp);
6210
6211 DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
6212
6213 /* qZone id equals to FW (per path) client id */
6214 bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
6215 /* init shortcut */
6216 bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
6217 bnx2x_rx_ustorm_prods_offset(fp);
6218
6219 /* Configure Queue State object */
6220 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6221 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6222
6223 /* No multi-CoS for FCoE L2 client */
6224 BUG_ON(fp->max_cos != 1);
6225
6226 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
6227 &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6228 bnx2x_sp_mapping(bp, q_rdata), q_type);
6229
6230 DP(NETIF_MSG_IFUP,
6231 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6232 fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6233 fp->igu_sb_id);
6234}
6235
Merav Sicron55c11942012-11-07 00:45:48 +00006236void bnx2x_nic_init_cnic(struct bnx2x *bp)
6237{
6238 if (!NO_FCOE(bp))
6239 bnx2x_init_fcoe_fp(bp);
6240
6241 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6242 BNX2X_VF_ID_INVALID, false,
6243 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
6244
6245 /* ensure status block indices were read */
6246 rmb();
6247 bnx2x_init_rx_rings_cnic(bp);
6248 bnx2x_init_tx_rings_cnic(bp);
6249
6250 /* flush all */
6251 mb();
6252 mmiowb();
6253}
6254
Yuval Mintzecf01c22013-04-22 02:53:03 +00006255void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006256{
6257 int i;
6258
Yuval Mintzecf01c22013-04-22 02:53:03 +00006259 /* Setup NIC internals and enable interrupts */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006260 for_each_eth_queue(bp, i)
Ariel Elior6383c0b2011-07-14 08:31:57 +00006261 bnx2x_init_eth_fp(bp, i);
Ariel Eliorad5afc82013-01-01 05:22:26 +00006262
6263 /* ensure status block indices were read */
6264 rmb();
6265 bnx2x_init_rx_rings(bp);
6266 bnx2x_init_tx_rings(bp);
6267
Yuval Mintzecf01c22013-04-22 02:53:03 +00006268 if (IS_PF(bp)) {
6269 /* Initialize MOD_ABS interrupts */
6270 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6271 bp->common.shmem_base,
6272 bp->common.shmem2_base, BP_PORT(bp));
Eilon Greenstein16119782009-03-02 07:59:27 +00006273
Yuval Mintzecf01c22013-04-22 02:53:03 +00006274 /* initialize the default status block and sp ring */
6275 bnx2x_init_def_sb(bp);
6276 bnx2x_update_dsb_idx(bp);
6277 bnx2x_init_sp_ring(bp);
Yuval Mintz3cdeec22013-06-02 00:06:19 +00006278 } else {
6279 bnx2x_memset_stats(bp);
Yuval Mintzecf01c22013-04-22 02:53:03 +00006280 }
6281}
Eilon Greenstein16119782009-03-02 07:59:27 +00006282
Yuval Mintzecf01c22013-04-22 02:53:03 +00006283void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6284{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006285 bnx2x_init_eq_ring(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07006286 bnx2x_init_internal(bp, load_code);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006287 bnx2x_pf_init(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006288 bnx2x_stats_init(bp);
6289
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006290 /* flush all before enabling interrupts */
6291 mb();
6292 mmiowb();
6293
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08006294 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00006295
6296 /* Check for SPIO5 */
6297 bnx2x_attn_int_deasserted0(bp,
6298 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6299 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006300}
6301
Yuval Mintzecf01c22013-04-22 02:53:03 +00006302/* gzip service functions */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006303static int bnx2x_gunzip_init(struct bnx2x *bp)
6304{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006305 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6306 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006307 if (bp->gunzip_buf == NULL)
6308 goto gunzip_nomem1;
6309
6310 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6311 if (bp->strm == NULL)
6312 goto gunzip_nomem2;
6313
David S. Miller7ab24bf2011-06-29 05:48:41 -07006314 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006315 if (bp->strm->workspace == NULL)
6316 goto gunzip_nomem3;
6317
6318 return 0;
6319
6320gunzip_nomem3:
6321 kfree(bp->strm);
6322 bp->strm = NULL;
6323
6324gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006325 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6326 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006327 bp->gunzip_buf = NULL;
6328
6329gunzip_nomem1:
Merav Sicron51c1a582012-03-18 10:33:38 +00006330 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006331 return -ENOMEM;
6332}
6333
6334static void bnx2x_gunzip_end(struct bnx2x *bp)
6335{
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006336 if (bp->strm) {
David S. Miller7ab24bf2011-06-29 05:48:41 -07006337 vfree(bp->strm->workspace);
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006338 kfree(bp->strm);
6339 bp->strm = NULL;
6340 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006341
6342 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006343 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6344 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006345 bp->gunzip_buf = NULL;
6346 }
6347}
6348
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006349static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006350{
6351 int n, rc;
6352
6353 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006354 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6355 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006356 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006357 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006358
6359 n = 10;
6360
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006361#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006362
6363 if (zbuf[3] & FNAME)
6364 while ((zbuf[n++] != 0) && (n < len));
6365
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006366 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006367 bp->strm->avail_in = len - n;
6368 bp->strm->next_out = bp->gunzip_buf;
6369 bp->strm->avail_out = FW_BUF_SIZE;
6370
6371 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6372 if (rc != Z_OK)
6373 return rc;
6374
6375 rc = zlib_inflate(bp->strm, Z_FINISH);
6376 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00006377 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6378 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006379
6380 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6381 if (bp->gunzip_outlen & 0x3)
Merav Sicron51c1a582012-03-18 10:33:38 +00006382 netdev_err(bp->dev,
6383 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006384 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006385 bp->gunzip_outlen >>= 2;
6386
6387 zlib_inflateEnd(bp->strm);
6388
6389 if (rc == Z_STREAM_END)
6390 return 0;
6391
6392 return rc;
6393}
6394
6395/* nic load/unload */
6396
6397/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006398 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006399 */
6400
6401/* send a NIG loopback debug packet */
6402static void bnx2x_lb_pckt(struct bnx2x *bp)
6403{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006404 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006405
6406 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006407 wb_write[0] = 0x55555555;
6408 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006409 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006410 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006411
6412 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006413 wb_write[0] = 0x09000000;
6414 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006415 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006416 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006417}
6418
6419/* some of the internal memories
6420 * are not directly readable from the driver
6421 * to test them we send debug packets
6422 */
6423static int bnx2x_int_mem_test(struct bnx2x *bp)
6424{
6425 int factor;
6426 int count, i;
6427 u32 val = 0;
6428
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006429 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006430 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006431 else if (CHIP_REV_IS_EMUL(bp))
6432 factor = 200;
6433 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006434 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006435
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006436 /* Disable inputs of parser neighbor blocks */
6437 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6438 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6439 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006440 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006441
6442 /* Write 0 to parser credits for CFC search request */
6443 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6444
6445 /* send Ethernet packet */
6446 bnx2x_lb_pckt(bp);
6447
6448 /* TODO do i reset NIG statistic? */
6449 /* Wait until NIG register shows 1 packet of size 0x10 */
6450 count = 1000 * factor;
6451 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006452
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006453 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6454 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006455 if (val == 0x10)
6456 break;
6457
Yuval Mintz639d65b2013-06-02 00:06:21 +00006458 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006459 count--;
6460 }
6461 if (val != 0x10) {
6462 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6463 return -1;
6464 }
6465
6466 /* Wait until PRS register shows 1 packet */
6467 count = 1000 * factor;
6468 while (count) {
6469 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006470 if (val == 1)
6471 break;
6472
Yuval Mintz639d65b2013-06-02 00:06:21 +00006473 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006474 count--;
6475 }
6476 if (val != 0x1) {
6477 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6478 return -2;
6479 }
6480
6481 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006482 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006483 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006484 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006485 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006486 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6487 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006488
6489 DP(NETIF_MSG_HW, "part2\n");
6490
6491 /* Disable inputs of parser neighbor blocks */
6492 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6493 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6494 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006495 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006496
6497 /* Write 0 to parser credits for CFC search request */
6498 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6499
6500 /* send 10 Ethernet packets */
6501 for (i = 0; i < 10; i++)
6502 bnx2x_lb_pckt(bp);
6503
6504 /* Wait until NIG register shows 10 + 1
6505 packets of size 11*0x10 = 0xb0 */
6506 count = 1000 * factor;
6507 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006508
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006509 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6510 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006511 if (val == 0xb0)
6512 break;
6513
Yuval Mintz639d65b2013-06-02 00:06:21 +00006514 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006515 count--;
6516 }
6517 if (val != 0xb0) {
6518 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6519 return -3;
6520 }
6521
6522 /* Wait until PRS register shows 2 packets */
6523 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6524 if (val != 2)
6525 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6526
6527 /* Write 1 to parser credits for CFC search request */
6528 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6529
6530 /* Wait until PRS register shows 3 packets */
6531 msleep(10 * factor);
6532 /* Wait until NIG register shows 1 packet of size 0x10 */
6533 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6534 if (val != 3)
6535 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6536
6537 /* clear NIG EOP FIFO */
6538 for (i = 0; i < 11; i++)
6539 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6540 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6541 if (val != 1) {
6542 BNX2X_ERR("clear of NIG failed\n");
6543 return -4;
6544 }
6545
6546 /* Reset and init BRB, PRS, NIG */
6547 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6548 msleep(50);
6549 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6550 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006551 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6552 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Merav Sicron55c11942012-11-07 00:45:48 +00006553 if (!CNIC_SUPPORT(bp))
6554 /* set NIC mode */
6555 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006556
6557 /* Enable inputs of parser neighbor blocks */
6558 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6559 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6560 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006561 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006562
6563 DP(NETIF_MSG_HW, "done\n");
6564
6565 return 0; /* OK */
6566}
6567
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006568static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006569{
Yuval Mintzb343d002012-12-02 04:05:53 +00006570 u32 val;
6571
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006572 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006573 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006574 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6575 else
6576 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006577 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6578 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006579 /*
6580 * mask read length error interrupts in brb for parser
6581 * (parsing unit and 'checksum and crc' unit)
6582 * these errors are legal (PU reads fixed length and CAC can cause
6583 * read length error on truncated packets)
6584 */
6585 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006586 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6587 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6588 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6589 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6590 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006591/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6592/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006593 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6594 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6595 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006596/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6597/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006598 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6599 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6600 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6601 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006602/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6603/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006604
Yuval Mintzb343d002012-12-02 04:05:53 +00006605 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6606 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6607 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6608 if (!CHIP_IS_E1x(bp))
6609 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6610 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6611 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6612
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006613 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6614 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6615 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006616/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006617
6618 if (!CHIP_IS_E1x(bp))
6619 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6620 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6621
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006622 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6623 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006624/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006625 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006626}
6627
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006628static void bnx2x_reset_common(struct bnx2x *bp)
6629{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006630 u32 val = 0x1400;
6631
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006632 /* reset_common */
6633 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6634 0xd3ffff7f);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006635
6636 if (CHIP_IS_E3(bp)) {
6637 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6638 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6639 }
6640
6641 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6642}
6643
6644static void bnx2x_setup_dmae(struct bnx2x *bp)
6645{
6646 bp->dmae_ready = 0;
6647 spin_lock_init(&bp->dmae_lock);
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006648}
6649
Eilon Greenstein573f2032009-08-12 08:24:14 +00006650static void bnx2x_init_pxp(struct bnx2x *bp)
6651{
6652 u16 devctl;
6653 int r_order, w_order;
6654
Jiang Liu2a80eeb2012-08-20 13:26:51 -06006655 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
Eilon Greenstein573f2032009-08-12 08:24:14 +00006656 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6657 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6658 if (bp->mrrs == -1)
6659 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6660 else {
6661 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6662 r_order = bp->mrrs;
6663 }
6664
6665 bnx2x_init_pxp_arb(bp, r_order, w_order);
6666}
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006667
6668static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6669{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006670 int is_required;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006671 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006672 int port;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006673
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006674 if (BP_NOMCP(bp))
6675 return;
6676
6677 is_required = 0;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006678 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6679 SHARED_HW_CFG_FAN_FAILURE_MASK;
6680
6681 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6682 is_required = 1;
6683
6684 /*
6685 * The fan failure mechanism is usually related to the PHY type since
6686 * the power consumption of the board is affected by the PHY. Currently,
6687 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6688 */
6689 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6690 for (port = PORT_0; port < PORT_MAX; port++) {
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006691 is_required |=
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006692 bnx2x_fan_failure_det_req(
6693 bp,
6694 bp->common.shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006695 bp->common.shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006696 port);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006697 }
6698
6699 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6700
6701 if (is_required == 0)
6702 return;
6703
6704 /* Fan failure is indicated by SPIO 5 */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006705 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006706
6707 /* set to active low mode */
6708 val = REG_RD(bp, MISC_REG_SPIO_INT);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006709 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006710 REG_WR(bp, MISC_REG_SPIO_INT, val);
6711
6712 /* enable interrupt to signal the IGU */
6713 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006714 val |= MISC_SPIO_SPIO5;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006715 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6716}
6717
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00006718void bnx2x_pf_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006719{
6720 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6721 val &= ~IGU_PF_CONF_FUNC_EN;
6722
6723 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6724 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6725 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6726}
6727
Eric Dumazet1191cb82012-04-27 21:39:21 +00006728static void bnx2x__common_init_phy(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006729{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006730 u32 shmem_base[2], shmem2_base[2];
Yaniv Rosnerb884d952012-11-27 03:46:28 +00006731 /* Avoid common init in case MFW supports LFA */
6732 if (SHMEM2_RD(bp, size) >
6733 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6734 return;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006735 shmem_base[0] = bp->common.shmem_base;
6736 shmem2_base[0] = bp->common.shmem2_base;
6737 if (!CHIP_IS_E1x(bp)) {
6738 shmem_base[1] =
6739 SHMEM2_RD(bp, other_shmem_base_addr);
6740 shmem2_base[1] =
6741 SHMEM2_RD(bp, other_shmem2_base_addr);
6742 }
6743 bnx2x_acquire_phy_lock(bp);
6744 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6745 bp->common.chip_id);
6746 bnx2x_release_phy_lock(bp);
6747}
6748
6749/**
6750 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6751 *
6752 * @bp: driver handle
6753 */
6754static int bnx2x_init_hw_common(struct bnx2x *bp)
6755{
6756 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006757
Merav Sicron51c1a582012-03-18 10:33:38 +00006758 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006759
David S. Miller823dcd22011-08-20 10:39:12 -07006760 /*
Yuval Mintz2de67432013-01-23 03:21:43 +00006761 * take the RESET lock to protect undi_unload flow from accessing
David S. Miller823dcd22011-08-20 10:39:12 -07006762 * registers while we're resetting the chip
6763 */
David S. Miller8decf862011-09-22 03:23:13 -04006764 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006765
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006766 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006767 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006768
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006769 val = 0xfffc;
6770 if (CHIP_IS_E3(bp)) {
6771 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6772 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6773 }
6774 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006775
David S. Miller8decf862011-09-22 03:23:13 -04006776 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006777
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006778 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6779
6780 if (!CHIP_IS_E1x(bp)) {
6781 u8 abs_func_id;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006782
6783 /**
6784 * 4-port mode or 2-port mode we need to turn of master-enable
6785 * for everyone, after that, turn it back on for self.
6786 * so, we disregard multi-function or not, and always disable
6787 * for all functions on the given path, this means 0,2,4,6 for
6788 * path 0 and 1,3,5,7 for path 1
6789 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006790 for (abs_func_id = BP_PATH(bp);
6791 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6792 if (abs_func_id == BP_ABS_FUNC(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006793 REG_WR(bp,
6794 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6795 1);
6796 continue;
6797 }
6798
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006799 bnx2x_pretend_func(bp, abs_func_id);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006800 /* clear pf enable */
6801 bnx2x_pf_disable(bp);
6802 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6803 }
6804 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006805
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006806 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006807 if (CHIP_IS_E1(bp)) {
6808 /* enable HW interrupt from PXP on USDM overflow
6809 bit 16 on INT_MASK_0 */
6810 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006811 }
6812
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006813 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006814 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006815
6816#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006817 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6818 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6819 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6820 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6821 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006822 /* make sure this value is 0 */
6823 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006824
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006825/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6826 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6827 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6828 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6829 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006830#endif
6831
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006832 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6833
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006834 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6835 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006836
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006837 /* let the HW do it's magic ... */
6838 msleep(100);
6839 /* finish PXP init */
6840 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6841 if (val != 1) {
6842 BNX2X_ERR("PXP2 CFG failed\n");
6843 return -EBUSY;
6844 }
6845 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6846 if (val != 1) {
6847 BNX2X_ERR("PXP2 RD_INIT failed\n");
6848 return -EBUSY;
6849 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006850
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006851 /* Timers bug workaround E2 only. We need to set the entire ILT to
6852 * have entries with value "0" and valid bit on.
6853 * This needs to be done by the first PF that is loaded in a path
6854 * (i.e. common phase)
6855 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006856 if (!CHIP_IS_E1x(bp)) {
6857/* In E2 there is a bug in the timers block that can cause function 6 / 7
6858 * (i.e. vnic3) to start even if it is marked as "scan-off".
6859 * This occurs when a different function (func2,3) is being marked
6860 * as "scan-off". Real-life scenario for example: if a driver is being
6861 * load-unloaded while func6,7 are down. This will cause the timer to access
6862 * the ilt, translate to a logical address and send a request to read/write.
6863 * Since the ilt for the function that is down is not valid, this will cause
6864 * a translation error which is unrecoverable.
6865 * The Workaround is intended to make sure that when this happens nothing fatal
6866 * will occur. The workaround:
6867 * 1. First PF driver which loads on a path will:
6868 * a. After taking the chip out of reset, by using pretend,
6869 * it will write "0" to the following registers of
6870 * the other vnics.
6871 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6872 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6873 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6874 * And for itself it will write '1' to
6875 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6876 * dmae-operations (writing to pram for example.)
6877 * note: can be done for only function 6,7 but cleaner this
6878 * way.
6879 * b. Write zero+valid to the entire ILT.
6880 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6881 * VNIC3 (of that port). The range allocated will be the
6882 * entire ILT. This is needed to prevent ILT range error.
6883 * 2. Any PF driver load flow:
6884 * a. ILT update with the physical addresses of the allocated
6885 * logical pages.
6886 * b. Wait 20msec. - note that this timeout is needed to make
6887 * sure there are no requests in one of the PXP internal
6888 * queues with "old" ILT addresses.
6889 * c. PF enable in the PGLC.
6890 * d. Clear the was_error of the PF in the PGLC. (could have
Yuval Mintz2de67432013-01-23 03:21:43 +00006891 * occurred while driver was down)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006892 * e. PF enable in the CFC (WEAK + STRONG)
6893 * f. Timers scan enable
6894 * 3. PF driver unload flow:
6895 * a. Clear the Timers scan_en.
6896 * b. Polling for scan_on=0 for that PF.
6897 * c. Clear the PF enable bit in the PXP.
6898 * d. Clear the PF enable in the CFC (WEAK + STRONG)
6899 * e. Write zero+valid to all ILT entries (The valid bit must
6900 * stay set)
6901 * f. If this is VNIC 3 of a port then also init
6902 * first_timers_ilt_entry to zero and last_timers_ilt_entry
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006903 * to the last entry in the ILT.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006904 *
6905 * Notes:
6906 * Currently the PF error in the PGLC is non recoverable.
6907 * In the future the there will be a recovery routine for this error.
6908 * Currently attention is masked.
6909 * Having an MCP lock on the load/unload process does not guarantee that
6910 * there is no Timer disable during Func6/7 enable. This is because the
6911 * Timers scan is currently being cleared by the MCP on FLR.
6912 * Step 2.d can be done only for PF6/7 and the driver can also check if
6913 * there is error before clearing it. But the flow above is simpler and
6914 * more general.
6915 * All ILT entries are written by zero+valid and not just PF6/7
6916 * ILT entries since in the future the ILT entries allocation for
6917 * PF-s might be dynamic.
6918 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006919 struct ilt_client_info ilt_cli;
6920 struct bnx2x_ilt ilt;
6921 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
6922 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
6923
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04006924 /* initialize dummy TM client */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006925 ilt_cli.start = 0;
6926 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
6927 ilt_cli.client_num = ILT_CLIENT_TM;
6928
6929 /* Step 1: set zeroes to all ilt page entries with valid bit on
6930 * Step 2: set the timers first/last ilt entry to point
6931 * to the entire range to prevent ILT range error for 3rd/4th
Yuval Mintz2de67432013-01-23 03:21:43 +00006932 * vnic (this code assumes existence of the vnic)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006933 *
6934 * both steps performed by call to bnx2x_ilt_client_init_op()
6935 * with dummy TM client
6936 *
6937 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
6938 * and his brother are split registers
6939 */
6940 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
6941 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
6942 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6943
6944 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
6945 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
6946 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
6947 }
6948
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006949 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
6950 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006951
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006952 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006953 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
6954 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006955 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006956
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006957 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006958
6959 /* let the HW do it's magic ... */
6960 do {
6961 msleep(200);
6962 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
6963 } while (factor-- && (val != 1));
6964
6965 if (val != 1) {
6966 BNX2X_ERR("ATC_INIT failed\n");
6967 return -EBUSY;
6968 }
6969 }
6970
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006971 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006972
Ariel Eliorb56e9672013-01-01 05:22:32 +00006973 bnx2x_iov_init_dmae(bp);
6974
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006975 /* clean the DMAE memory */
6976 bp->dmae_ready = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006977 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006978
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006979 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
6980
6981 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
6982
6983 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
6984
6985 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006986
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006987 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
6988 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
6989 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
6990 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
6991
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006992 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00006993
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006994 /* QM queues pointers table */
6995 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
Michael Chan37b091b2009-10-10 13:46:55 +00006996
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006997 /* soft reset pulse */
6998 REG_WR(bp, QM_REG_SOFT_RESET, 1);
6999 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007000
Merav Sicron55c11942012-11-07 00:45:48 +00007001 if (CNIC_SUPPORT(bp))
7002 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007003
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007004 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
Ariel Eliorb9871bc2013-09-04 14:09:21 +03007005
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007006 if (!CHIP_REV_IS_SLOW(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007007 /* enable hw interrupt from doorbell Q */
7008 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007009
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007010 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007011
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007012 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08007013 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007014
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007015 if (!CHIP_IS_E1(bp))
7016 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
7017
Barak Witkowskia3348722012-04-23 03:04:46 +00007018 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
7019 if (IS_MF_AFEX(bp)) {
7020 /* configure that VNTag and VLAN headers must be
7021 * received in afex mode
7022 */
7023 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
7024 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
7025 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
7026 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
7027 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
7028 } else {
7029 /* Bit-map indicating which L2 hdrs may appear
7030 * after the basic Ethernet header
7031 */
7032 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
7033 bp->path_has_ovlan ? 7 : 6);
7034 }
7035 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007036
7037 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
7038 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
7039 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
7040 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
7041
7042 if (!CHIP_IS_E1x(bp)) {
7043 /* reset VFC memories */
7044 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7045 VFC_MEMORIES_RST_REG_CAM_RST |
7046 VFC_MEMORIES_RST_REG_RAM_RST);
7047 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7048 VFC_MEMORIES_RST_REG_CAM_RST |
7049 VFC_MEMORIES_RST_REG_RAM_RST);
7050
7051 msleep(20);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007052 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007053
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007054 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
7055 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
7056 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
7057 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007058
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007059 /* sync semi rtc */
7060 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7061 0x80000000);
7062 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7063 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007064
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007065 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
7066 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
7067 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007068
Barak Witkowskia3348722012-04-23 03:04:46 +00007069 if (!CHIP_IS_E1x(bp)) {
7070 if (IS_MF_AFEX(bp)) {
7071 /* configure that VNTag and VLAN headers must be
7072 * sent in afex mode
7073 */
7074 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
7075 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
7076 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
7077 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
7078 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
7079 } else {
7080 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
7081 bp->path_has_ovlan ? 7 : 6);
7082 }
7083 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007084
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007085 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007086
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007087 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
7088
Merav Sicron55c11942012-11-07 00:45:48 +00007089 if (CNIC_SUPPORT(bp)) {
7090 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
7091 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
7092 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
7093 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
7094 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
7095 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
7096 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
7097 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
7098 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
7099 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
7100 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007101 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007102
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007103 if (sizeof(union cdu_context) != 1024)
7104 /* we currently assume that a context is 1024 bytes */
Merav Sicron51c1a582012-03-18 10:33:38 +00007105 dev_alert(&bp->pdev->dev,
7106 "please adjust the size of cdu_context(%ld)\n",
7107 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007108
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007109 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007110 val = (4 << 24) + (0 << 12) + 1024;
7111 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007112
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007113 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007114 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007115 /* enable context validation interrupt from CFC */
7116 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
7117
7118 /* set the thresholds to prevent CFC/CDU race */
7119 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007120
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007121 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007122
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007123 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007124 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
7125
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007126 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
7127 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007128
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007129 /* Reset PCIE errors for debug */
7130 REG_WR(bp, 0x2814, 0xffffffff);
7131 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007132
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007133 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007134 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
7135 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
7136 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
7137 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
7138 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
7139 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
7140 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
7141 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
7142 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
7143 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
7144 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
7145 }
7146
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007147 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007148 if (!CHIP_IS_E1(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007149 /* in E3 this done in per-port section */
7150 if (!CHIP_IS_E3(bp))
7151 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
7152 }
7153 if (CHIP_IS_E1H(bp))
7154 /* not applicable for E2 (and above ...) */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007155 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007156
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007157 if (CHIP_REV_IS_SLOW(bp))
7158 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007159
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007160 /* finish CFC init */
7161 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
7162 if (val != 1) {
7163 BNX2X_ERR("CFC LL_INIT failed\n");
7164 return -EBUSY;
7165 }
7166 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
7167 if (val != 1) {
7168 BNX2X_ERR("CFC AC_INIT failed\n");
7169 return -EBUSY;
7170 }
7171 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
7172 if (val != 1) {
7173 BNX2X_ERR("CFC CAM_INIT failed\n");
7174 return -EBUSY;
7175 }
7176 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007177
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007178 if (CHIP_IS_E1(bp)) {
7179 /* read NIG statistic
7180 to see if this is our first up since powerup */
7181 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
7182 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007183
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007184 /* do internal memory self test */
7185 if ((val == 0) && bnx2x_int_mem_test(bp)) {
7186 BNX2X_ERR("internal mem self test failed\n");
7187 return -EBUSY;
7188 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007189 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007190
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00007191 bnx2x_setup_fan_failure_detection(bp);
7192
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007193 /* clear PXP2 attentions */
7194 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007195
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00007196 bnx2x_enable_blocks_attention(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007197 bnx2x_enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007198
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007199 if (!BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007200 if (CHIP_IS_E1x(bp))
7201 bnx2x__common_init_phy(bp);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007202 } else
7203 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
7204
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007205 return 0;
7206}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007207
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007208/**
7209 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
7210 *
7211 * @bp: driver handle
7212 */
7213static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
7214{
7215 int rc = bnx2x_init_hw_common(bp);
7216
7217 if (rc)
7218 return rc;
7219
7220 /* In E2 2-PORT mode, same ext phy is used for the two paths */
7221 if (!BP_NOMCP(bp))
7222 bnx2x__common_init_phy(bp);
7223
7224 return 0;
7225}
7226
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007227static int bnx2x_init_hw_port(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007228{
7229 int port = BP_PORT(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007230 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
Eilon Greenstein1c063282009-02-12 08:36:43 +00007231 u32 low, high;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02007232 u32 val, reg;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007233
Merav Sicron51c1a582012-03-18 10:33:38 +00007234 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007235
7236 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007237
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007238 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7239 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7240 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
Eilon Greensteinca003922009-08-12 22:53:28 -07007241
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007242 /* Timers bug workaround: disables the pf_master bit in pglue at
7243 * common phase, we need to enable it here before any dmae access are
7244 * attempted. Therefore we manually added the enable-master to the
7245 * port phase (it also happens in the function phase)
7246 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007247 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007248 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7249
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007250 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7251 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7252 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7253 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7254
7255 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7256 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7257 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7258 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007259
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007260 /* QM cid (connection) count */
7261 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007262
Merav Sicron55c11942012-11-07 00:45:48 +00007263 if (CNIC_SUPPORT(bp)) {
7264 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7265 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7266 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7267 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007268
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007269 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Eilon Greenstein1c063282009-02-12 08:36:43 +00007270
Dmitry Kravkov2b674042012-10-28 21:59:04 +00007271 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7272
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007273 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007274
7275 if (IS_MF(bp))
7276 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7277 else if (bp->dev->mtu > 4096) {
7278 if (bp->flags & ONE_PORT_FLAG)
7279 low = 160;
7280 else {
7281 val = bp->dev->mtu;
7282 /* (24*1024 + val*4)/256 */
7283 low = 96 + (val/64) +
7284 ((val % 64) ? 1 : 0);
7285 }
7286 } else
7287 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7288 high = low + 56; /* 14*1024/256 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007289 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7290 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
7291 }
7292
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007293 if (CHIP_MODE_IS_4_PORT(bp))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007294 REG_WR(bp, (BP_PORT(bp) ?
7295 BRB1_REG_MAC_GUARANTIED_1 :
7296 BRB1_REG_MAC_GUARANTIED_0), 40);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007297
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007298 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
Barak Witkowskia3348722012-04-23 03:04:46 +00007299 if (CHIP_IS_E3B0(bp)) {
7300 if (IS_MF_AFEX(bp)) {
7301 /* configure headers for AFEX mode */
7302 REG_WR(bp, BP_PORT(bp) ?
7303 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7304 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7305 REG_WR(bp, BP_PORT(bp) ?
7306 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7307 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7308 REG_WR(bp, BP_PORT(bp) ?
7309 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7310 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7311 } else {
7312 /* Ovlan exists only if we are in multi-function +
7313 * switch-dependent mode, in switch-independent there
7314 * is no ovlan headers
7315 */
7316 REG_WR(bp, BP_PORT(bp) ?
7317 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7318 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7319 (bp->path_has_ovlan ? 7 : 6));
7320 }
7321 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007322
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007323 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7324 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7325 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7326 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7327
7328 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7329 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7330 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7331 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7332
7333 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7334 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7335
7336 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7337
7338 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007339 /* configure PBF to work without PAUSE mtu 9000 */
7340 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007341
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007342 /* update threshold */
7343 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7344 /* update init credit */
7345 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007346
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007347 /* probe changes */
7348 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7349 udelay(50);
7350 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7351 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007352
Merav Sicron55c11942012-11-07 00:45:48 +00007353 if (CNIC_SUPPORT(bp))
7354 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7355
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007356 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7357 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007358
7359 if (CHIP_IS_E1(bp)) {
7360 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7361 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7362 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007363 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007364
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007365 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007366
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007367 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007368 /* init aeu_mask_attn_func_0/1:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007369 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7370 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007371 * bits 4-7 are used for "per vn group attention" */
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00007372 val = IS_MF(bp) ? 0xF7 : 0x7;
7373 /* Enable DCBX attention for all but E1 */
7374 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7375 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007376
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02007377 /* SCPAD_PARITY should NOT trigger close the gates */
7378 reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
7379 REG_WR(bp, reg,
7380 REG_RD(bp, reg) &
7381 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7382
7383 reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
7384 REG_WR(bp, reg,
7385 REG_RD(bp, reg) &
7386 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7387
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007388 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007389
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007390 if (!CHIP_IS_E1x(bp)) {
7391 /* Bit-map indicating which L2 hdrs may appear after the
7392 * basic Ethernet header
7393 */
Barak Witkowskia3348722012-04-23 03:04:46 +00007394 if (IS_MF_AFEX(bp))
7395 REG_WR(bp, BP_PORT(bp) ?
7396 NIG_REG_P1_HDRS_AFTER_BASIC :
7397 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7398 else
7399 REG_WR(bp, BP_PORT(bp) ?
7400 NIG_REG_P1_HDRS_AFTER_BASIC :
7401 NIG_REG_P0_HDRS_AFTER_BASIC,
7402 IS_MF_SD(bp) ? 7 : 6);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007403
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007404 if (CHIP_IS_E3(bp))
7405 REG_WR(bp, BP_PORT(bp) ?
7406 NIG_REG_LLH1_MF_MODE :
7407 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7408 }
7409 if (!CHIP_IS_E3(bp))
7410 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007411
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007412 if (!CHIP_IS_E1(bp)) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007413 /* 0x2 disable mf_ov, 0x1 enable */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007414 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007415 (IS_MF_SD(bp) ? 0x1 : 0x2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007416
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007417 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007418 val = 0;
7419 switch (bp->mf_mode) {
7420 case MULTI_FUNCTION_SD:
7421 val = 1;
7422 break;
7423 case MULTI_FUNCTION_SI:
Barak Witkowskia3348722012-04-23 03:04:46 +00007424 case MULTI_FUNCTION_AFEX:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007425 val = 2;
7426 break;
7427 }
7428
7429 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7430 NIG_REG_LLH0_CLS_TYPE), val);
7431 }
Eilon Greenstein1c063282009-02-12 08:36:43 +00007432 {
7433 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7434 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7435 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7436 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007437 }
7438
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007439 /* If SPIO5 is set to generate interrupts, enable it for this port */
7440 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00007441 if (val & MISC_SPIO_SPIO5) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007442 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7443 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7444 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007445 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007446 REG_WR(bp, reg_addr, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007447 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007448
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007449 return 0;
7450}
7451
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007452static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7453{
7454 int reg;
Yuval Mintz32d68de2012-04-03 18:41:24 +00007455 u32 wb_write[2];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007456
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007457 if (CHIP_IS_E1(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007458 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007459 else
7460 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007461
Yuval Mintz32d68de2012-04-03 18:41:24 +00007462 wb_write[0] = ONCHIP_ADDR1(addr);
7463 wb_write[1] = ONCHIP_ADDR2(addr);
7464 REG_WR_DMAE(bp, reg, wb_write, 2);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007465}
7466
Ariel Eliorb56e9672013-01-01 05:22:32 +00007467void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
Eric Dumazet1191cb82012-04-27 21:39:21 +00007468{
7469 u32 data, ctl, cnt = 100;
7470 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7471 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7472 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7473 u32 sb_bit = 1 << (idu_sb_id%32);
Ariel Eliorb56e9672013-01-01 05:22:32 +00007474 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
Eric Dumazet1191cb82012-04-27 21:39:21 +00007475 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7476
7477 /* Not supported in BC mode */
7478 if (CHIP_INT_MODE_IS_BC(bp))
7479 return;
7480
7481 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7482 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7483 IGU_REGULAR_CLEANUP_SET |
7484 IGU_REGULAR_BCLEANUP;
7485
7486 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7487 func_encode << IGU_CTRL_REG_FID_SHIFT |
7488 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7489
7490 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7491 data, igu_addr_data);
7492 REG_WR(bp, igu_addr_data, data);
7493 mmiowb();
7494 barrier();
7495 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7496 ctl, igu_addr_ctl);
7497 REG_WR(bp, igu_addr_ctl, ctl);
7498 mmiowb();
7499 barrier();
7500
7501 /* wait for clean up to finish */
7502 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7503 msleep(20);
7504
Eric Dumazet1191cb82012-04-27 21:39:21 +00007505 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7506 DP(NETIF_MSG_HW,
7507 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7508 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7509 }
7510}
7511
7512static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007513{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007514 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007515}
7516
Eric Dumazet1191cb82012-04-27 21:39:21 +00007517static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007518{
7519 u32 i, base = FUNC_ILT_BASE(func);
7520 for (i = base; i < base + ILT_PER_FUNC; i++)
7521 bnx2x_ilt_wr(bp, i, 0);
7522}
7523
Merav Sicron910cc722012-11-11 03:56:08 +00007524static void bnx2x_init_searcher(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007525{
7526 int port = BP_PORT(bp);
7527 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7528 /* T1 hash bits value determines the T1 number of entries */
7529 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7530}
7531
7532static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7533{
7534 int rc;
7535 struct bnx2x_func_state_params func_params = {NULL};
7536 struct bnx2x_func_switch_update_params *switch_update_params =
7537 &func_params.params.switch_update;
7538
7539 /* Prepare parameters for function state transitions */
7540 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7541 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7542
7543 func_params.f_obj = &bp->func_obj;
7544 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7545
7546 /* Function parameters */
7547 switch_update_params->suspend = suspend;
7548
7549 rc = bnx2x_func_state_change(bp, &func_params);
7550
7551 return rc;
7552}
7553
Merav Sicron910cc722012-11-11 03:56:08 +00007554static int bnx2x_reset_nic_mode(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007555{
7556 int rc, i, port = BP_PORT(bp);
7557 int vlan_en = 0, mac_en[NUM_MACS];
7558
Merav Sicron55c11942012-11-07 00:45:48 +00007559 /* Close input from network */
7560 if (bp->mf_mode == SINGLE_FUNCTION) {
7561 bnx2x_set_rx_filter(&bp->link_params, 0);
7562 } else {
7563 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7564 NIG_REG_LLH0_FUNC_EN);
7565 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7566 NIG_REG_LLH0_FUNC_EN, 0);
7567 for (i = 0; i < NUM_MACS; i++) {
7568 mac_en[i] = REG_RD(bp, port ?
7569 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7570 4 * i) :
7571 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7572 4 * i));
7573 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7574 4 * i) :
7575 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7576 }
7577 }
7578
7579 /* Close BMC to host */
7580 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7581 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7582
7583 /* Suspend Tx switching to the PF. Completion of this ramrod
7584 * further guarantees that all the packets of that PF / child
7585 * VFs in BRB were processed by the Parser, so it is safe to
7586 * change the NIC_MODE register.
7587 */
7588 rc = bnx2x_func_switch_update(bp, 1);
7589 if (rc) {
7590 BNX2X_ERR("Can't suspend tx-switching!\n");
7591 return rc;
7592 }
7593
7594 /* Change NIC_MODE register */
7595 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7596
7597 /* Open input from network */
7598 if (bp->mf_mode == SINGLE_FUNCTION) {
7599 bnx2x_set_rx_filter(&bp->link_params, 1);
7600 } else {
7601 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7602 NIG_REG_LLH0_FUNC_EN, vlan_en);
7603 for (i = 0; i < NUM_MACS; i++) {
7604 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7605 4 * i) :
7606 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7607 mac_en[i]);
7608 }
7609 }
7610
7611 /* Enable BMC to host */
7612 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7613 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7614
7615 /* Resume Tx switching to the PF */
7616 rc = bnx2x_func_switch_update(bp, 0);
7617 if (rc) {
7618 BNX2X_ERR("Can't resume tx-switching!\n");
7619 return rc;
7620 }
7621
7622 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7623 return 0;
7624}
7625
7626int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7627{
7628 int rc;
7629
7630 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7631
7632 if (CONFIGURE_NIC_MODE(bp)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007633 /* Configure searcher as part of function hw init */
Merav Sicron55c11942012-11-07 00:45:48 +00007634 bnx2x_init_searcher(bp);
7635
7636 /* Reset NIC mode */
7637 rc = bnx2x_reset_nic_mode(bp);
7638 if (rc)
7639 BNX2X_ERR("Can't change NIC mode!\n");
7640 return rc;
7641 }
7642
7643 return 0;
7644}
7645
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007646static int bnx2x_init_hw_func(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007647{
7648 int port = BP_PORT(bp);
7649 int func = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007650 int init_phase = PHASE_PF0 + func;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007651 struct bnx2x_ilt *ilt = BP_ILT(bp);
7652 u16 cdu_ilt_start;
Eilon Greenstein8badd272009-02-12 08:36:15 +00007653 u32 addr, val;
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007654 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
Ariel Elior89db4ad2012-01-26 06:01:48 +00007655 int i, main_mem_width, rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007656
Merav Sicron51c1a582012-03-18 10:33:38 +00007657 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007658
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007659 /* FLR cleanup - hmmm */
Ariel Elior89db4ad2012-01-26 06:01:48 +00007660 if (!CHIP_IS_E1x(bp)) {
7661 rc = bnx2x_pf_flr_clnup(bp);
Yuval Mintz04c46732013-01-23 03:21:46 +00007662 if (rc) {
7663 bnx2x_fw_dump(bp);
Ariel Elior89db4ad2012-01-26 06:01:48 +00007664 return rc;
Yuval Mintz04c46732013-01-23 03:21:46 +00007665 }
Ariel Elior89db4ad2012-01-26 06:01:48 +00007666 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007667
Eilon Greenstein8badd272009-02-12 08:36:15 +00007668 /* set MSI reconfigure capability */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007669 if (bp->common.int_block == INT_BLOCK_HC) {
7670 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7671 val = REG_RD(bp, addr);
7672 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7673 REG_WR(bp, addr, val);
7674 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007675
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007676 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7677 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7678
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007679 ilt = BP_ILT(bp);
7680 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007681
Ariel Elior290ca2b2013-01-01 05:22:31 +00007682 if (IS_SRIOV(bp))
7683 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7684 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7685
7686 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7687 * those of the VFs, so start line should be reset
7688 */
7689 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007690 for (i = 0; i < L2_ILT_LINES(bp); i++) {
Merav Sicrona0529972012-06-19 07:48:25 +00007691 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007692 ilt->lines[cdu_ilt_start + i].page_mapping =
Merav Sicrona0529972012-06-19 07:48:25 +00007693 bp->context[i].cxt_mapping;
7694 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007695 }
Ariel Elior290ca2b2013-01-01 05:22:31 +00007696
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007697 bnx2x_ilt_init_op(bp, INITOP_SET);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007698
Merav Sicron55c11942012-11-07 00:45:48 +00007699 if (!CONFIGURE_NIC_MODE(bp)) {
7700 bnx2x_init_searcher(bp);
7701 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7702 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7703 } else {
7704 /* Set NIC mode */
7705 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00007706 DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
Merav Sicron55c11942012-11-07 00:45:48 +00007707 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007708
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007709 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007710 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7711
7712 /* Turn on a single ISR mode in IGU if driver is going to use
7713 * INT#x or MSI
7714 */
7715 if (!(bp->flags & USING_MSIX_FLAG))
7716 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7717 /*
7718 * Timers workaround bug: function init part.
7719 * Need to wait 20msec after initializing ILT,
7720 * needed to make sure there are no requests in
7721 * one of the PXP internal queues with "old" ILT addresses
7722 */
7723 msleep(20);
7724 /*
7725 * Master enable - Due to WB DMAE writes performed before this
7726 * register is re-initialized as part of the regular function
7727 * init
7728 */
7729 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7730 /* Enable the function in IGU */
7731 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7732 }
7733
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007734 bp->dmae_ready = 1;
7735
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007736 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007737
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007738 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007739 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7740
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007741 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7742 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7743 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7744 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7745 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7746 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7747 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7748 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7749 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7750 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7751 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7752 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7753 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007754
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007755 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007756 REG_WR(bp, QM_REG_PF_EN, 1);
7757
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007758 if (!CHIP_IS_E1x(bp)) {
7759 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7760 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7761 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7762 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7763 }
7764 bnx2x_init_block(bp, BLOCK_QM, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007765
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007766 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7767 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Ariel Eliorc19d65c2013-09-09 14:51:27 +03007768 REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
Ariel Eliorb56e9672013-01-01 05:22:32 +00007769
7770 bnx2x_iov_init_dq(bp);
7771
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007772 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7773 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7774 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7775 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7776 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7777 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7778 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7779 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7780 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7781 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007782 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7783
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007784 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007785
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007786 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007787
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007788 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007789 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7790
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007791 if (IS_MF(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007792 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007793 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007794 }
7795
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007796 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007797
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007798 /* HC init per function */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007799 if (bp->common.int_block == INT_BLOCK_HC) {
7800 if (CHIP_IS_E1H(bp)) {
7801 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7802
7803 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7804 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7805 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007806 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007807
7808 } else {
7809 int num_segs, sb_idx, prod_offset;
7810
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007811 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7812
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007813 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007814 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7815 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7816 }
7817
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007818 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007819
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007820 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007821 int dsb_idx = 0;
7822 /**
7823 * Producer memory:
7824 * E2 mode: address 0-135 match to the mapping memory;
7825 * 136 - PF0 default prod; 137 - PF1 default prod;
7826 * 138 - PF2 default prod; 139 - PF3 default prod;
7827 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7828 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7829 * 144-147 reserved.
7830 *
7831 * E1.5 mode - In backward compatible mode;
7832 * for non default SB; each even line in the memory
7833 * holds the U producer and each odd line hold
7834 * the C producer. The first 128 producers are for
7835 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7836 * producers are for the DSB for each PF.
7837 * Each PF has five segments: (the order inside each
7838 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7839 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7840 * 144-147 attn prods;
7841 */
7842 /* non-default-status-blocks */
7843 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7844 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7845 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7846 prod_offset = (bp->igu_base_sb + sb_idx) *
7847 num_segs;
7848
7849 for (i = 0; i < num_segs; i++) {
7850 addr = IGU_REG_PROD_CONS_MEMORY +
7851 (prod_offset + i) * 4;
7852 REG_WR(bp, addr, 0);
7853 }
7854 /* send consumer update with value 0 */
7855 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7856 USTORM_ID, 0, IGU_INT_NOP, 1);
7857 bnx2x_igu_clear_sb(bp,
7858 bp->igu_base_sb + sb_idx);
7859 }
7860
7861 /* default-status-blocks */
7862 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7863 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7864
7865 if (CHIP_MODE_IS_4_PORT(bp))
7866 dsb_idx = BP_FUNC(bp);
7867 else
David S. Miller8decf862011-09-22 03:23:13 -04007868 dsb_idx = BP_VN(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007869
7870 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7871 IGU_BC_BASE_DSB_PROD + dsb_idx :
7872 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7873
David S. Miller8decf862011-09-22 03:23:13 -04007874 /*
7875 * igu prods come in chunks of E1HVN_MAX (4) -
7876 * does not matters what is the current chip mode
7877 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007878 for (i = 0; i < (num_segs * E1HVN_MAX);
7879 i += E1HVN_MAX) {
7880 addr = IGU_REG_PROD_CONS_MEMORY +
7881 (prod_offset + i)*4;
7882 REG_WR(bp, addr, 0);
7883 }
7884 /* send consumer update with 0 */
7885 if (CHIP_INT_MODE_IS_BC(bp)) {
7886 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7887 USTORM_ID, 0, IGU_INT_NOP, 1);
7888 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7889 CSTORM_ID, 0, IGU_INT_NOP, 1);
7890 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7891 XSTORM_ID, 0, IGU_INT_NOP, 1);
7892 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7893 TSTORM_ID, 0, IGU_INT_NOP, 1);
7894 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7895 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7896 } else {
7897 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7898 USTORM_ID, 0, IGU_INT_NOP, 1);
7899 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7900 ATTENTION_ID, 0, IGU_INT_NOP, 1);
7901 }
7902 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
7903
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007904 /* !!! These should become driver const once
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007905 rf-tool supports split-68 const */
7906 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
7907 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
7908 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
7909 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
7910 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
7911 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
7912 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007913 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007914
Eliezer Tamirc14423f2008-02-28 11:49:42 -08007915 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007916 REG_WR(bp, 0x2114, 0xffffffff);
7917 REG_WR(bp, 0x2120, 0xffffffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007918
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007919 if (CHIP_IS_E1x(bp)) {
7920 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
7921 main_mem_base = HC_REG_MAIN_MEMORY +
7922 BP_PORT(bp) * (main_mem_size * 4);
7923 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
7924 main_mem_width = 8;
7925
7926 val = REG_RD(bp, main_mem_prty_clr);
7927 if (val)
Merav Sicron51c1a582012-03-18 10:33:38 +00007928 DP(NETIF_MSG_HW,
7929 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
7930 val);
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007931
7932 /* Clear "false" parity errors in MSI-X table */
7933 for (i = main_mem_base;
7934 i < main_mem_base + main_mem_size * 4;
7935 i += main_mem_width) {
7936 bnx2x_read_dmae(bp, i, main_mem_width / 4);
7937 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
7938 i, main_mem_width / 4);
7939 }
7940 /* Clear HC parity attention */
7941 REG_RD(bp, main_mem_prty_clr);
7942 }
7943
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007944#ifdef BNX2X_STOP_ON_ERROR
7945 /* Enable STORMs SP logging */
7946 REG_WR8(bp, BAR_USTRORM_INTMEM +
7947 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7948 REG_WR8(bp, BAR_TSTRORM_INTMEM +
7949 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7950 REG_WR8(bp, BAR_CSTRORM_INTMEM +
7951 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7952 REG_WR8(bp, BAR_XSTRORM_INTMEM +
7953 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
7954#endif
7955
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007956 bnx2x_phy_probe(&bp->link_params);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007957
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007958 return 0;
7959}
7960
Merav Sicron55c11942012-11-07 00:45:48 +00007961void bnx2x_free_mem_cnic(struct bnx2x *bp)
7962{
7963 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
7964
7965 if (!CHIP_IS_E1x(bp))
7966 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
7967 sizeof(struct host_hc_status_block_e2));
7968 else
7969 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
7970 sizeof(struct host_hc_status_block_e1x));
7971
7972 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
7973}
7974
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00007975void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007976{
Merav Sicrona0529972012-06-19 07:48:25 +00007977 int i;
7978
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007979 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
7980 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
7981
Ariel Eliorb4cddbd2013-08-28 01:13:03 +03007982 if (IS_VF(bp))
7983 return;
7984
7985 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
7986 sizeof(struct host_sp_status_block));
7987
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007988 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007989 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007990
Merav Sicrona0529972012-06-19 07:48:25 +00007991 for (i = 0; i < L2_ILT_LINES(bp); i++)
7992 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
7993 bp->context[i].size);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007994 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
7995
7996 BNX2X_FREE(bp->ilt->lines);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007997
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07007998 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007999
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008000 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
8001 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Yuval Mintz580d9d02013-01-23 03:21:51 +00008002
Yuval Mintz05952242013-05-01 04:27:58 +00008003 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
8004
Yuval Mintz580d9d02013-01-23 03:21:51 +00008005 bnx2x_iov_free_mem(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008006}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008007
Merav Sicron55c11942012-11-07 00:45:48 +00008008int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008009{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008010 if (!CHIP_IS_E1x(bp))
8011 /* size = the status block + ramrod buffers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008012 BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
8013 sizeof(struct host_hc_status_block_e2));
8014 else
Merav Sicron55c11942012-11-07 00:45:48 +00008015 BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
8016 &bp->cnic_sb_mapping,
8017 sizeof(struct
8018 host_hc_status_block_e1x));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008019
Yuval Mintz2f7a3122013-04-24 01:45:01 +00008020 if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008021 /* allocate searcher T2 table, as it wasn't allocated before */
Merav Sicron55c11942012-11-07 00:45:48 +00008022 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008023
Merav Sicron55c11942012-11-07 00:45:48 +00008024 /* write address to which L5 should insert its values */
8025 bp->cnic_eth_dev.addr_drv_info_to_mcp =
8026 &bp->slowpath->drv_info_to_mcp;
8027
8028 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
8029 goto alloc_mem_err;
8030
8031 return 0;
8032
8033alloc_mem_err:
8034 bnx2x_free_mem_cnic(bp);
8035 BNX2X_ERR("Can't allocate memory\n");
8036 return -ENOMEM;
8037}
8038
8039int bnx2x_alloc_mem(struct bnx2x *bp)
8040{
8041 int i, allocated, context_size;
8042
Yuval Mintz2f7a3122013-04-24 01:45:01 +00008043 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
Merav Sicron55c11942012-11-07 00:45:48 +00008044 /* allocate searcher T2 table */
8045 BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008046
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008047 BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008048 sizeof(struct host_sp_status_block));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008049
8050 BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
8051 sizeof(struct bnx2x_slowpath));
8052
Merav Sicrona0529972012-06-19 07:48:25 +00008053 /* Allocate memory for CDU context:
8054 * This memory is allocated separately and not in the generic ILT
8055 * functions because CDU differs in few aspects:
8056 * 1. There are multiple entities allocating memory for context -
8057 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
8058 * its own ILT lines.
8059 * 2. Since CDU page-size is not a single 4KB page (which is the case
8060 * for the other ILT clients), to be efficient we want to support
8061 * allocation of sub-page-size in the last entry.
8062 * 3. Context pointers are used by the driver to pass to FW / update
8063 * the context (for the other ILT clients the pointers are used just to
8064 * free the memory during unload).
8065 */
8066 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008067
Merav Sicrona0529972012-06-19 07:48:25 +00008068 for (i = 0, allocated = 0; allocated < context_size; i++) {
8069 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
8070 (context_size - allocated));
8071 BNX2X_PCI_ALLOC(bp->context[i].vcxt,
8072 &bp->context[i].cxt_mapping,
8073 bp->context[i].size);
8074 allocated += bp->context[i].size;
8075 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008076 BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008077
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008078 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
8079 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008080
Ariel Elior67c431a2013-01-01 05:22:36 +00008081 if (bnx2x_iov_alloc_mem(bp))
8082 goto alloc_mem_err;
8083
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008084 /* Slow path ring */
8085 BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
8086
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008087 /* EQ */
8088 BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
8089 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Tom Herbertab532cf2011-02-16 10:27:02 +00008090
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008091 return 0;
8092
8093alloc_mem_err:
8094 bnx2x_free_mem(bp);
Merav Sicron51c1a582012-03-18 10:33:38 +00008095 BNX2X_ERR("Can't allocate memory\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008096 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008097}
8098
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008099/*
8100 * Init service functions
8101 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008102
8103int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
8104 struct bnx2x_vlan_mac_obj *obj, bool set,
8105 int mac_type, unsigned long *ramrod_flags)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008106{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008107 int rc;
8108 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008109
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008110 memset(&ramrod_param, 0, sizeof(ramrod_param));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008111
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008112 /* Fill general parameters */
8113 ramrod_param.vlan_mac_obj = obj;
8114 ramrod_param.ramrod_flags = *ramrod_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008115
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008116 /* Fill a user request section if needed */
8117 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
8118 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008119
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008120 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008121
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008122 /* Set the command: ADD or DEL */
8123 if (set)
8124 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
8125 else
8126 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008127 }
8128
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008129 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
Yuval Mintz7b5342d2012-09-11 04:34:14 +00008130
8131 if (rc == -EEXIST) {
8132 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
8133 /* do not treat adding same MAC as error */
8134 rc = 0;
8135 } else if (rc < 0)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008136 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
Yuval Mintz7b5342d2012-09-11 04:34:14 +00008137
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008138 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008139}
8140
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008141int bnx2x_del_all_macs(struct bnx2x *bp,
8142 struct bnx2x_vlan_mac_obj *mac_obj,
8143 int mac_type, bool wait_for_comp)
Michael Chane665bfd2009-10-10 13:46:54 +00008144{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008145 int rc;
8146 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
8147
8148 /* Wait for completion of requested */
8149 if (wait_for_comp)
8150 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8151
8152 /* Set the mac type of addresses we want to clear */
8153 __set_bit(mac_type, &vlan_mac_flags);
8154
8155 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
8156 if (rc < 0)
8157 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
8158
8159 return rc;
Michael Chane665bfd2009-10-10 13:46:54 +00008160}
8161
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008162int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008163{
Barak Witkowskia3348722012-04-23 03:04:46 +00008164 if (is_zero_ether_addr(bp->dev->dev_addr) &&
8165 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00008166 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
8167 "Ignoring Zero MAC for STORAGE SD mode\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008168 return 0;
8169 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008170
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008171 if (IS_PF(bp)) {
8172 unsigned long ramrod_flags = 0;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008173
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008174 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
8175 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8176 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
8177 &bp->sp_objs->mac_obj, set,
8178 BNX2X_ETH_MAC, &ramrod_flags);
8179 } else { /* vf */
8180 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
8181 bp->fp->index, true);
8182 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008183}
8184
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008185int bnx2x_setup_leading(struct bnx2x *bp)
Michael Chane665bfd2009-10-10 13:46:54 +00008186{
Ariel Elior60cad4e2013-09-04 14:09:22 +03008187 if (IS_PF(bp))
8188 return bnx2x_setup_queue(bp, &bp->fp[0], true);
8189 else /* VF */
8190 return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008191}
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08008192
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008193/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00008194 * bnx2x_set_int_mode - configure interrupt mode
8195 *
8196 * @bp: driver handle
8197 *
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008198 * In case of MSI-X it will also try to enable MSI-X.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008199 */
Ariel Elior1ab44342013-01-01 05:22:23 +00008200int bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008201{
Ariel Elior1ab44342013-01-01 05:22:23 +00008202 int rc = 0;
8203
Ariel Elior60cad4e2013-09-04 14:09:22 +03008204 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
8205 BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
Ariel Elior1ab44342013-01-01 05:22:23 +00008206 return -EINVAL;
Ariel Elior60cad4e2013-09-04 14:09:22 +03008207 }
Ariel Elior1ab44342013-01-01 05:22:23 +00008208
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00008209 switch (int_mode) {
Ariel Elior1ab44342013-01-01 05:22:23 +00008210 case BNX2X_INT_MODE_MSIX:
8211 /* attempt to enable msix */
8212 rc = bnx2x_enable_msix(bp);
8213
8214 /* msix attained */
8215 if (!rc)
8216 return 0;
8217
8218 /* vfs use only msix */
8219 if (rc && IS_VF(bp))
8220 return rc;
8221
8222 /* failed to enable multiple MSI-X */
8223 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
8224 bp->num_queues,
8225 1 + bp->num_cnic_queues);
8226
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008227 /* falling through... */
Ariel Elior1ab44342013-01-01 05:22:23 +00008228 case BNX2X_INT_MODE_MSI:
8229 bnx2x_enable_msi(bp);
8230
8231 /* falling through... */
8232 case BNX2X_INT_MODE_INTX:
Merav Sicron55c11942012-11-07 00:45:48 +00008233 bp->num_ethernet_queues = 1;
8234 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
Merav Sicron51c1a582012-03-18 10:33:38 +00008235 BNX2X_DEV_INFO("set number of queues to 1\n");
Eilon Greensteinca003922009-08-12 22:53:28 -07008236 break;
Eilon Greensteinca003922009-08-12 22:53:28 -07008237 default:
Ariel Elior1ab44342013-01-01 05:22:23 +00008238 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
8239 return -EINVAL;
Eilon Greensteinca003922009-08-12 22:53:28 -07008240 }
Ariel Elior1ab44342013-01-01 05:22:23 +00008241 return 0;
Eilon Greensteinca003922009-08-12 22:53:28 -07008242}
8243
Ariel Elior1ab44342013-01-01 05:22:23 +00008244/* must be called prior to any HW initializations */
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008245static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
8246{
Ariel Elior290ca2b2013-01-01 05:22:31 +00008247 if (IS_SRIOV(bp))
8248 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008249 return L2_ILT_LINES(bp);
8250}
8251
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008252void bnx2x_ilt_set_info(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008253{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008254 struct ilt_client_info *ilt_client;
8255 struct bnx2x_ilt *ilt = BP_ILT(bp);
8256 u16 line = 0;
8257
8258 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8259 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8260
8261 /* CDU */
8262 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8263 ilt_client->client_num = ILT_CLIENT_CDU;
8264 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8265 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8266 ilt_client->start = line;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008267 line += bnx2x_cid_ilt_lines(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00008268
8269 if (CNIC_SUPPORT(bp))
8270 line += CNIC_ILT_LINES;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008271 ilt_client->end = line - 1;
8272
Merav Sicron51c1a582012-03-18 10:33:38 +00008273 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 +00008274 ilt_client->start,
8275 ilt_client->end,
8276 ilt_client->page_size,
8277 ilt_client->flags,
8278 ilog2(ilt_client->page_size >> 12));
8279
8280 /* QM */
8281 if (QM_INIT(bp->qm_cid_count)) {
8282 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8283 ilt_client->client_num = ILT_CLIENT_QM;
8284 ilt_client->page_size = QM_ILT_PAGE_SZ;
8285 ilt_client->flags = 0;
8286 ilt_client->start = line;
8287
8288 /* 4 bytes for each cid */
8289 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8290 QM_ILT_PAGE_SZ);
8291
8292 ilt_client->end = line - 1;
8293
Merav Sicron51c1a582012-03-18 10:33:38 +00008294 DP(NETIF_MSG_IFUP,
8295 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008296 ilt_client->start,
8297 ilt_client->end,
8298 ilt_client->page_size,
8299 ilt_client->flags,
8300 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008301 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008302
Merav Sicron55c11942012-11-07 00:45:48 +00008303 if (CNIC_SUPPORT(bp)) {
8304 /* SRC */
8305 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8306 ilt_client->client_num = ILT_CLIENT_SRC;
8307 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8308 ilt_client->flags = 0;
8309 ilt_client->start = line;
8310 line += SRC_ILT_LINES;
8311 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008312
Merav Sicron55c11942012-11-07 00:45:48 +00008313 DP(NETIF_MSG_IFUP,
8314 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8315 ilt_client->start,
8316 ilt_client->end,
8317 ilt_client->page_size,
8318 ilt_client->flags,
8319 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008320
Merav Sicron55c11942012-11-07 00:45:48 +00008321 /* TM */
8322 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8323 ilt_client->client_num = ILT_CLIENT_TM;
8324 ilt_client->page_size = TM_ILT_PAGE_SZ;
8325 ilt_client->flags = 0;
8326 ilt_client->start = line;
8327 line += TM_ILT_LINES;
8328 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008329
Merav Sicron55c11942012-11-07 00:45:48 +00008330 DP(NETIF_MSG_IFUP,
8331 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8332 ilt_client->start,
8333 ilt_client->end,
8334 ilt_client->page_size,
8335 ilt_client->flags,
8336 ilog2(ilt_client->page_size >> 12));
8337 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008338
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008339 BUG_ON(line > ILT_MAX_LINES);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008340}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008341
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008342/**
8343 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8344 *
8345 * @bp: driver handle
8346 * @fp: pointer to fastpath
8347 * @init_params: pointer to parameters structure
8348 *
8349 * parameters configured:
8350 * - HC configuration
8351 * - Queue's CDU context
8352 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00008353static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008354 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008355{
Ariel Elior6383c0b2011-07-14 08:31:57 +00008356 u8 cos;
Merav Sicrona0529972012-06-19 07:48:25 +00008357 int cxt_index, cxt_offset;
8358
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008359 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8360 if (!IS_FCOE_FP(fp)) {
8361 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8362 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8363
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008364 /* If HC is supported, enable host coalescing in the transition
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008365 * to INIT state.
8366 */
8367 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8368 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8369
8370 /* HC rate */
8371 init_params->rx.hc_rate = bp->rx_ticks ?
8372 (1000000 / bp->rx_ticks) : 0;
8373 init_params->tx.hc_rate = bp->tx_ticks ?
8374 (1000000 / bp->tx_ticks) : 0;
8375
8376 /* FW SB ID */
8377 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8378 fp->fw_sb_id;
8379
8380 /*
8381 * CQ index among the SB indices: FCoE clients uses the default
8382 * SB, therefore it's different.
8383 */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008384 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8385 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008386 }
8387
Ariel Elior6383c0b2011-07-14 08:31:57 +00008388 /* set maximum number of COSs supported by this queue */
8389 init_params->max_cos = fp->max_cos;
8390
Merav Sicron51c1a582012-03-18 10:33:38 +00008391 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008392 fp->index, init_params->max_cos);
8393
8394 /* set the context pointers queue object */
Merav Sicrona0529972012-06-19 07:48:25 +00008395 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
Merav Sicron65565882012-06-19 07:48:26 +00008396 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8397 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
Merav Sicrona0529972012-06-19 07:48:25 +00008398 ILT_PAGE_CIDS);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008399 init_params->cxts[cos] =
Merav Sicrona0529972012-06-19 07:48:25 +00008400 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8401 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008402}
8403
Merav Sicron910cc722012-11-11 03:56:08 +00008404static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00008405 struct bnx2x_queue_state_params *q_params,
8406 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8407 int tx_index, bool leading)
8408{
8409 memset(tx_only_params, 0, sizeof(*tx_only_params));
8410
8411 /* Set the command */
8412 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8413
8414 /* Set tx-only QUEUE flags: don't zero statistics */
8415 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8416
8417 /* choose the index of the cid to send the slow path on */
8418 tx_only_params->cid_index = tx_index;
8419
8420 /* Set general TX_ONLY_SETUP parameters */
8421 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8422
8423 /* Set Tx TX_ONLY_SETUP parameters */
8424 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8425
Merav Sicron51c1a582012-03-18 10:33:38 +00008426 DP(NETIF_MSG_IFUP,
8427 "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 +00008428 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8429 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8430 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8431
8432 /* send the ramrod */
8433 return bnx2x_queue_state_change(bp, q_params);
8434}
8435
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008436/**
8437 * bnx2x_setup_queue - setup queue
8438 *
8439 * @bp: driver handle
8440 * @fp: pointer to fastpath
8441 * @leading: is leading
8442 *
8443 * This function performs 2 steps in a Queue state machine
8444 * actually: 1) RESET->INIT 2) INIT->SETUP
8445 */
8446
8447int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8448 bool leading)
8449{
Yuval Mintz3b603062012-03-18 10:33:39 +00008450 struct bnx2x_queue_state_params q_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008451 struct bnx2x_queue_setup_params *setup_params =
8452 &q_params.params.setup;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008453 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8454 &q_params.params.tx_only;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008455 int rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008456 u8 tx_index;
8457
Merav Sicron51c1a582012-03-18 10:33:38 +00008458 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008459
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008460 /* reset IGU state skip FCoE L2 queue */
8461 if (!IS_FCOE_FP(fp))
8462 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008463 IGU_INT_ENABLE, 0);
8464
Barak Witkowski15192a82012-06-19 07:48:28 +00008465 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008466 /* We want to wait for completion in this context */
8467 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008468
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008469 /* Prepare the INIT parameters */
8470 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008471
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008472 /* Set the command */
8473 q_params.cmd = BNX2X_Q_CMD_INIT;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008474
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008475 /* Change the state to INIT */
8476 rc = bnx2x_queue_state_change(bp, &q_params);
8477 if (rc) {
Ariel Elior6383c0b2011-07-14 08:31:57 +00008478 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008479 return rc;
8480 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008481
Merav Sicron51c1a582012-03-18 10:33:38 +00008482 DP(NETIF_MSG_IFUP, "init complete\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +00008483
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008484 /* Now move the Queue to the SETUP state... */
8485 memset(setup_params, 0, sizeof(*setup_params));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008486
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008487 /* Set QUEUE flags */
8488 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008489
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008490 /* Set general SETUP parameters */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008491 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8492 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008493
Ariel Elior6383c0b2011-07-14 08:31:57 +00008494 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008495 &setup_params->rxq_params);
8496
Ariel Elior6383c0b2011-07-14 08:31:57 +00008497 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8498 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008499
8500 /* Set the command */
8501 q_params.cmd = BNX2X_Q_CMD_SETUP;
8502
Merav Sicron55c11942012-11-07 00:45:48 +00008503 if (IS_FCOE_FP(fp))
8504 bp->fcoe_init = true;
8505
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008506 /* Change the state to SETUP */
8507 rc = bnx2x_queue_state_change(bp, &q_params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008508 if (rc) {
8509 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8510 return rc;
8511 }
8512
8513 /* loop through the relevant tx-only indices */
8514 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8515 tx_index < fp->max_cos;
8516 tx_index++) {
8517
8518 /* prepare and send tx-only ramrod*/
8519 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8520 tx_only_params, tx_index, leading);
8521 if (rc) {
8522 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8523 fp->index, tx_index);
8524 return rc;
8525 }
8526 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008527
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008528 return rc;
8529}
8530
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008531static int bnx2x_stop_queue(struct bnx2x *bp, int index)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008532{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008533 struct bnx2x_fastpath *fp = &bp->fp[index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008534 struct bnx2x_fp_txdata *txdata;
Yuval Mintz3b603062012-03-18 10:33:39 +00008535 struct bnx2x_queue_state_params q_params = {NULL};
Ariel Elior6383c0b2011-07-14 08:31:57 +00008536 int rc, tx_index;
8537
Merav Sicron51c1a582012-03-18 10:33:38 +00008538 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008539
Barak Witkowski15192a82012-06-19 07:48:28 +00008540 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008541 /* We want to wait for completion in this context */
8542 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008543
Ariel Elior6383c0b2011-07-14 08:31:57 +00008544 /* close tx-only connections */
8545 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8546 tx_index < fp->max_cos;
8547 tx_index++){
8548
8549 /* ascertain this is a normal queue*/
Merav Sicron65565882012-06-19 07:48:26 +00008550 txdata = fp->txdata_ptr[tx_index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008551
Merav Sicron51c1a582012-03-18 10:33:38 +00008552 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008553 txdata->txq_index);
8554
8555 /* send halt terminate on tx-only connection */
8556 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8557 memset(&q_params.params.terminate, 0,
8558 sizeof(q_params.params.terminate));
8559 q_params.params.terminate.cid_index = tx_index;
8560
8561 rc = bnx2x_queue_state_change(bp, &q_params);
8562 if (rc)
8563 return rc;
8564
8565 /* send halt terminate on tx-only connection */
8566 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8567 memset(&q_params.params.cfc_del, 0,
8568 sizeof(q_params.params.cfc_del));
8569 q_params.params.cfc_del.cid_index = tx_index;
8570 rc = bnx2x_queue_state_change(bp, &q_params);
8571 if (rc)
8572 return rc;
8573 }
8574 /* Stop the primary connection: */
8575 /* ...halt the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008576 q_params.cmd = BNX2X_Q_CMD_HALT;
8577 rc = bnx2x_queue_state_change(bp, &q_params);
8578 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008579 return rc;
8580
Ariel Elior6383c0b2011-07-14 08:31:57 +00008581 /* ...terminate the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008582 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008583 memset(&q_params.params.terminate, 0,
8584 sizeof(q_params.params.terminate));
8585 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008586 rc = bnx2x_queue_state_change(bp, &q_params);
8587 if (rc)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008588 return rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008589 /* ...delete cfc entry */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008590 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008591 memset(&q_params.params.cfc_del, 0,
8592 sizeof(q_params.params.cfc_del));
8593 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008594 return bnx2x_queue_state_change(bp, &q_params);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008595}
8596
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008597static void bnx2x_reset_func(struct bnx2x *bp)
8598{
8599 int port = BP_PORT(bp);
8600 int func = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008601 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008602
8603 /* Disable the function in the FW */
8604 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8605 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8606 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8607 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8608
8609 /* FP SBs */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008610 for_each_eth_queue(bp, i) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008611 struct bnx2x_fastpath *fp = &bp->fp[i];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008612 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Ariel Elior6383c0b2011-07-14 08:31:57 +00008613 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8614 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008615 }
8616
Merav Sicron55c11942012-11-07 00:45:48 +00008617 if (CNIC_LOADED(bp))
8618 /* CNIC SB */
8619 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8620 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8621 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8622
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008623 /* SP SB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008624 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Yuval Mintz2de67432013-01-23 03:21:43 +00008625 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8626 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008627
8628 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8629 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8630 0);
Eliezer Tamir49d66772008-02-28 11:53:13 -08008631
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008632 /* Configure IGU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008633 if (bp->common.int_block == INT_BLOCK_HC) {
8634 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8635 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8636 } else {
8637 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8638 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8639 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008640
Merav Sicron55c11942012-11-07 00:45:48 +00008641 if (CNIC_LOADED(bp)) {
8642 /* Disable Timer scan */
8643 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8644 /*
8645 * Wait for at least 10ms and up to 2 second for the timers
8646 * scan to complete
8647 */
8648 for (i = 0; i < 200; i++) {
Yuval Mintz639d65b2013-06-02 00:06:21 +00008649 usleep_range(10000, 20000);
Merav Sicron55c11942012-11-07 00:45:48 +00008650 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8651 break;
8652 }
Michael Chan37b091b2009-10-10 13:46:55 +00008653 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008654 /* Clear ILT */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008655 bnx2x_clear_func_ilt(bp, func);
8656
8657 /* Timers workaround bug for E2: if this is vnic-3,
8658 * we need to set the entire ilt range for this timers.
8659 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008660 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008661 struct ilt_client_info ilt_cli;
8662 /* use dummy TM client */
8663 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8664 ilt_cli.start = 0;
8665 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8666 ilt_cli.client_num = ILT_CLIENT_TM;
8667
8668 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8669 }
8670
8671 /* this assumes that reset_port() called before reset_func()*/
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008672 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008673 bnx2x_pf_disable(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008674
8675 bp->dmae_ready = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008676}
8677
8678static void bnx2x_reset_port(struct bnx2x *bp)
8679{
8680 int port = BP_PORT(bp);
8681 u32 val;
8682
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008683 /* Reset physical Link */
8684 bnx2x__link_reset(bp);
8685
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008686 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8687
8688 /* Do not rcv packets to BRB */
8689 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8690 /* Do not direct rcv packets that are not for MCP to the BRB */
8691 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8692 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8693
8694 /* Configure AEU */
8695 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8696
8697 msleep(100);
8698 /* Check for BRB port occupancy */
8699 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8700 if (val)
8701 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07008702 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008703
8704 /* TODO: Close Doorbell port? */
8705}
8706
Eric Dumazet1191cb82012-04-27 21:39:21 +00008707static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008708{
Yuval Mintz3b603062012-03-18 10:33:39 +00008709 struct bnx2x_func_state_params func_params = {NULL};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008710
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008711 /* Prepare parameters for function state transitions */
8712 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008713
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008714 func_params.f_obj = &bp->func_obj;
8715 func_params.cmd = BNX2X_F_CMD_HW_RESET;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008716
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008717 func_params.params.hw_init.load_phase = load_code;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008718
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008719 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008720}
8721
Eric Dumazet1191cb82012-04-27 21:39:21 +00008722static int bnx2x_func_stop(struct bnx2x *bp)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008723{
Yuval Mintz3b603062012-03-18 10:33:39 +00008724 struct bnx2x_func_state_params func_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008725 int rc;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008726
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008727 /* Prepare parameters for function state transitions */
8728 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8729 func_params.f_obj = &bp->func_obj;
8730 func_params.cmd = BNX2X_F_CMD_STOP;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008731
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008732 /*
8733 * Try to stop the function the 'good way'. If fails (in case
8734 * of a parity error during bnx2x_chip_cleanup()) and we are
8735 * not in a debug mode, perform a state transaction in order to
8736 * enable further HW_RESET transaction.
8737 */
8738 rc = bnx2x_func_state_change(bp, &func_params);
8739 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008740#ifdef BNX2X_STOP_ON_ERROR
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008741 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008742#else
Merav Sicron51c1a582012-03-18 10:33:38 +00008743 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008744 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8745 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008746#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07008747 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008748
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008749 return 0;
8750}
Yitchak Gertner65abd742008-08-25 15:26:24 -07008751
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008752/**
8753 * bnx2x_send_unload_req - request unload mode from the MCP.
8754 *
8755 * @bp: driver handle
8756 * @unload_mode: requested function's unload mode
8757 *
8758 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8759 */
8760u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8761{
8762 u32 reset_code = 0;
8763 int port = BP_PORT(bp);
8764
8765 /* Select the UNLOAD request mode */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008766 if (unload_mode == UNLOAD_NORMAL)
8767 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008768
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008769 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008770 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008771
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008772 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008773 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008774 u8 *mac_addr = bp->dev->dev_addr;
Jon Mason29ed74c2013-09-11 11:22:39 -07008775 struct pci_dev *pdev = bp->pdev;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008776 u32 val;
David S. Miller88c51002011-10-07 13:38:43 -04008777 u16 pmc;
8778
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008779 /* The mac address is written to entries 1-4 to
David S. Miller88c51002011-10-07 13:38:43 -04008780 * preserve entry 0 which is used by the PMF
8781 */
David S. Miller8decf862011-09-22 03:23:13 -04008782 u8 entry = (BP_VN(bp) + 1)*8;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008783
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008784 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008785 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008786
8787 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8788 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008789 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008790
David S. Miller88c51002011-10-07 13:38:43 -04008791 /* Enable the PME and clear the status */
Jon Mason29ed74c2013-09-11 11:22:39 -07008792 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
David S. Miller88c51002011-10-07 13:38:43 -04008793 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
Jon Mason29ed74c2013-09-11 11:22:39 -07008794 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
David S. Miller88c51002011-10-07 13:38:43 -04008795
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008796 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008797
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008798 } else
8799 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8800
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008801 /* Send the request to the MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008802 if (!BP_NOMCP(bp))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008803 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008804 else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008805 int path = BP_PATH(bp);
8806
Merav Sicron51c1a582012-03-18 10:33:38 +00008807 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008808 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8809 bnx2x_load_count[path][2]);
8810 bnx2x_load_count[path][0]--;
8811 bnx2x_load_count[path][1 + port]--;
Merav Sicron51c1a582012-03-18 10:33:38 +00008812 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008813 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8814 bnx2x_load_count[path][2]);
8815 if (bnx2x_load_count[path][0] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008816 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008817 else if (bnx2x_load_count[path][1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008818 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8819 else
8820 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8821 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008822
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008823 return reset_code;
8824}
8825
8826/**
8827 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8828 *
8829 * @bp: driver handle
Yuval Mintz5d07d862012-09-13 02:56:21 +00008830 * @keep_link: true iff link should be kept up
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008831 */
Yuval Mintz5d07d862012-09-13 02:56:21 +00008832void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008833{
Yuval Mintz5d07d862012-09-13 02:56:21 +00008834 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8835
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008836 /* Report UNLOAD_DONE to MCP */
8837 if (!BP_NOMCP(bp))
Yuval Mintz5d07d862012-09-13 02:56:21 +00008838 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008839}
8840
Eric Dumazet1191cb82012-04-27 21:39:21 +00008841static int bnx2x_func_wait_started(struct bnx2x *bp)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008842{
8843 int tout = 50;
8844 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8845
8846 if (!bp->port.pmf)
8847 return 0;
8848
8849 /*
8850 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008851 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008852 * 1. Sync IRS for default SB
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008853 * 2. Sync SP queue - this guarantees us that attention handling started
8854 * 3. Wait, that TX disable/enable transaction completes
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008855 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008856 * 1+2 guarantee that if DCBx attention was scheduled it already changed
8857 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
8858 * received completion for the transaction the state is TX_STOPPED.
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008859 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8860 * transaction.
8861 */
8862
8863 /* make sure default SB ISR is done */
8864 if (msix)
8865 synchronize_irq(bp->msix_table[0].vector);
8866 else
8867 synchronize_irq(bp->pdev->irq);
8868
8869 flush_workqueue(bnx2x_wq);
8870
8871 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
8872 BNX2X_F_STATE_STARTED && tout--)
8873 msleep(20);
8874
8875 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
8876 BNX2X_F_STATE_STARTED) {
8877#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00008878 BNX2X_ERR("Wrong function state\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008879 return -EBUSY;
8880#else
8881 /*
8882 * Failed to complete the transaction in a "good way"
8883 * Force both transactions with CLR bit
8884 */
Yuval Mintz3b603062012-03-18 10:33:39 +00008885 struct bnx2x_func_state_params func_params = {NULL};
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008886
Merav Sicron51c1a582012-03-18 10:33:38 +00008887 DP(NETIF_MSG_IFDOWN,
Yuval Mintz6bf07b82013-06-02 00:06:20 +00008888 "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008889
8890 func_params.f_obj = &bp->func_obj;
8891 __set_bit(RAMROD_DRV_CLR_ONLY,
8892 &func_params.ramrod_flags);
8893
8894 /* STARTED-->TX_ST0PPED */
8895 func_params.cmd = BNX2X_F_CMD_TX_STOP;
8896 bnx2x_func_state_change(bp, &func_params);
8897
8898 /* TX_ST0PPED-->STARTED */
8899 func_params.cmd = BNX2X_F_CMD_TX_START;
8900 return bnx2x_func_state_change(bp, &func_params);
8901#endif
8902 }
8903
8904 return 0;
8905}
8906
Yuval Mintz5d07d862012-09-13 02:56:21 +00008907void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008908{
8909 int port = BP_PORT(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008910 int i, rc = 0;
8911 u8 cos;
Yuval Mintz3b603062012-03-18 10:33:39 +00008912 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008913 u32 reset_code;
8914
8915 /* Wait until tx fastpath tasks complete */
8916 for_each_tx_queue(bp, i) {
8917 struct bnx2x_fastpath *fp = &bp->fp[i];
8918
Ariel Elior6383c0b2011-07-14 08:31:57 +00008919 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00008920 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008921#ifdef BNX2X_STOP_ON_ERROR
8922 if (rc)
8923 return;
8924#endif
8925 }
8926
8927 /* Give HW time to discard old tx messages */
Yuval Mintz0926d492013-01-23 03:21:45 +00008928 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008929
8930 /* Clean all ETH MACs */
Barak Witkowski15192a82012-06-19 07:48:28 +00008931 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
8932 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008933 if (rc < 0)
8934 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
8935
8936 /* Clean up UC list */
Barak Witkowski15192a82012-06-19 07:48:28 +00008937 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008938 true);
8939 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +00008940 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
8941 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008942
8943 /* Disable LLH */
8944 if (!CHIP_IS_E1(bp))
8945 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
8946
8947 /* Set "drop all" (stop Rx).
8948 * We need to take a netif_addr_lock() here in order to prevent
8949 * a race between the completion code and this code.
8950 */
8951 netif_addr_lock_bh(bp->dev);
8952 /* Schedule the rx_mode command */
8953 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
8954 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
8955 else
8956 bnx2x_set_storm_rx_mode(bp);
8957
8958 /* Cleanup multicast configuration */
8959 rparam.mcast_obj = &bp->mcast_obj;
8960 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
8961 if (rc < 0)
8962 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
8963
8964 netif_addr_unlock_bh(bp->dev);
8965
Ariel Eliorf1929b02013-01-01 05:22:41 +00008966 bnx2x_iov_chip_cleanup(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008967
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008968 /*
8969 * Send the UNLOAD_REQUEST to the MCP. This will return if
8970 * this function should perform FUNC, PORT or COMMON HW
8971 * reset.
8972 */
8973 reset_code = bnx2x_send_unload_req(bp, unload_mode);
8974
8975 /*
8976 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008977 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008978 */
8979 rc = bnx2x_func_wait_started(bp);
8980 if (rc) {
8981 BNX2X_ERR("bnx2x_func_wait_started failed\n");
8982#ifdef BNX2X_STOP_ON_ERROR
8983 return;
8984#endif
8985 }
8986
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008987 /* Close multi and leading connections
8988 * Completions for ramrods are collected in a synchronous way
8989 */
Merav Sicron55c11942012-11-07 00:45:48 +00008990 for_each_eth_queue(bp, i)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008991 if (bnx2x_stop_queue(bp, i))
8992#ifdef BNX2X_STOP_ON_ERROR
8993 return;
8994#else
8995 goto unload_error;
8996#endif
Merav Sicron55c11942012-11-07 00:45:48 +00008997
8998 if (CNIC_LOADED(bp)) {
8999 for_each_cnic_queue(bp, i)
9000 if (bnx2x_stop_queue(bp, i))
9001#ifdef BNX2X_STOP_ON_ERROR
9002 return;
9003#else
9004 goto unload_error;
9005#endif
9006 }
9007
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009008 /* If SP settings didn't get completed so far - something
9009 * very wrong has happen.
9010 */
9011 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
9012 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
9013
9014#ifndef BNX2X_STOP_ON_ERROR
9015unload_error:
9016#endif
9017 rc = bnx2x_func_stop(bp);
9018 if (rc) {
9019 BNX2X_ERR("Function stop failed!\n");
9020#ifdef BNX2X_STOP_ON_ERROR
9021 return;
9022#endif
9023 }
9024
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009025 /* Disable HW interrupts, NAPI */
9026 bnx2x_netif_stop(bp, 1);
Merav Sicron26614ba2012-08-27 03:26:19 +00009027 /* Delete all NAPI objects */
9028 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00009029 if (CNIC_LOADED(bp))
9030 bnx2x_del_all_napi_cnic(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009031
9032 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00009033 bnx2x_free_irq(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009034
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009035 /* Reset the chip */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009036 rc = bnx2x_reset_hw(bp, reset_code);
9037 if (rc)
9038 BNX2X_ERR("HW_RESET failed\n");
9039
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009040 /* Report UNLOAD_DONE to MCP */
Yuval Mintz5d07d862012-09-13 02:56:21 +00009041 bnx2x_send_unload_done(bp, keep_link);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009042}
9043
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009044void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009045{
9046 u32 val;
9047
Merav Sicron51c1a582012-03-18 10:33:38 +00009048 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009049
9050 if (CHIP_IS_E1(bp)) {
9051 int port = BP_PORT(bp);
9052 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
9053 MISC_REG_AEU_MASK_ATTN_FUNC_0;
9054
9055 val = REG_RD(bp, addr);
9056 val &= ~(0x300);
9057 REG_WR(bp, addr, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009058 } else {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009059 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
9060 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
9061 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
9062 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
9063 }
9064}
9065
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009066/* Close gates #2, #3 and #4: */
9067static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
9068{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009069 u32 val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009070
9071 /* Gates #2 and #4a are closed/opened for "not E1" only */
9072 if (!CHIP_IS_E1(bp)) {
9073 /* #4 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009074 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009075 /* #2 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009076 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009077 }
9078
9079 /* #3 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009080 if (CHIP_IS_E1x(bp)) {
9081 /* Prevent interrupts from HC on both ports */
9082 val = REG_RD(bp, HC_REG_CONFIG_1);
9083 REG_WR(bp, HC_REG_CONFIG_1,
9084 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
9085 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
9086
9087 val = REG_RD(bp, HC_REG_CONFIG_0);
9088 REG_WR(bp, HC_REG_CONFIG_0,
9089 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
9090 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
9091 } else {
Jorrit Schippersd82603c2012-12-27 17:33:02 +01009092 /* Prevent incoming interrupts in IGU */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009093 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9094
9095 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
9096 (!close) ?
9097 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
9098 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
9099 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009100
Merav Sicron51c1a582012-03-18 10:33:38 +00009101 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009102 close ? "closing" : "opening");
9103 mmiowb();
9104}
9105
9106#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
9107
9108static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
9109{
9110 /* Do some magic... */
9111 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9112 *magic_val = val & SHARED_MF_CLP_MAGIC;
9113 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
9114}
9115
Dmitry Kravkove8920672011-05-04 23:52:40 +00009116/**
9117 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009118 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009119 * @bp: driver handle
9120 * @magic_val: old value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009121 */
9122static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
9123{
9124 /* Restore the `magic' bit value... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009125 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9126 MF_CFG_WR(bp, shared_mf_config.clp_mb,
9127 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
9128}
9129
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00009130/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00009131 * bnx2x_reset_mcp_prep - prepare for MCP reset.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009132 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009133 * @bp: driver handle
9134 * @magic_val: old value of 'magic' bit.
9135 *
9136 * Takes care of CLP configurations.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009137 */
9138static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
9139{
9140 u32 shmem;
9141 u32 validity_offset;
9142
Merav Sicron51c1a582012-03-18 10:33:38 +00009143 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009144
9145 /* Set `magic' bit in order to save MF config */
9146 if (!CHIP_IS_E1(bp))
9147 bnx2x_clp_reset_prep(bp, magic_val);
9148
9149 /* Get shmem offset */
9150 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009151 validity_offset =
9152 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009153
9154 /* Clear validity map flags */
9155 if (shmem > 0)
9156 REG_WR(bp, shmem + validity_offset, 0);
9157}
9158
9159#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
9160#define MCP_ONE_TIMEOUT 100 /* 100 ms */
9161
Dmitry Kravkove8920672011-05-04 23:52:40 +00009162/**
9163 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009164 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009165 * @bp: driver handle
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009166 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00009167static void bnx2x_mcp_wait_one(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009168{
9169 /* special handling for emulation and FPGA,
9170 wait 10 times longer */
9171 if (CHIP_REV_IS_SLOW(bp))
9172 msleep(MCP_ONE_TIMEOUT*10);
9173 else
9174 msleep(MCP_ONE_TIMEOUT);
9175}
9176
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009177/*
9178 * initializes bp->common.shmem_base and waits for validity signature to appear
9179 */
9180static int bnx2x_init_shmem(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009181{
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009182 int cnt = 0;
9183 u32 val = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009184
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009185 do {
9186 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9187 if (bp->common.shmem_base) {
9188 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
9189 if (val & SHR_MEM_VALIDITY_MB)
9190 return 0;
9191 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009192
9193 bnx2x_mcp_wait_one(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009194
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009195 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009196
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009197 BNX2X_ERR("BAD MCP validity signature\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009198
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009199 return -ENODEV;
9200}
9201
9202static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
9203{
9204 int rc = bnx2x_init_shmem(bp);
9205
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009206 /* Restore the `magic' bit value */
9207 if (!CHIP_IS_E1(bp))
9208 bnx2x_clp_reset_done(bp, magic_val);
9209
9210 return rc;
9211}
9212
9213static void bnx2x_pxp_prep(struct bnx2x *bp)
9214{
9215 if (!CHIP_IS_E1(bp)) {
9216 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
9217 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009218 mmiowb();
9219 }
9220}
9221
9222/*
9223 * Reset the whole chip except for:
9224 * - PCIE core
9225 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
9226 * one reset bit)
9227 * - IGU
9228 * - MISC (including AEU)
9229 * - GRC
9230 * - RBCN, RBCP
9231 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009232static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009233{
9234 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009235 u32 global_bits2, stay_reset2;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009236
9237 /*
9238 * Bits that have to be set in reset_mask2 if we want to reset 'global'
9239 * (per chip) blocks.
9240 */
9241 global_bits2 =
9242 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9243 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009244
Barak Witkowskic55e7712012-12-02 04:05:46 +00009245 /* Don't reset the following blocks.
9246 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9247 * reset, as in 4 port device they might still be owned
9248 * by the MCP (there is only one leader per path).
9249 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009250 not_reset_mask1 =
9251 MISC_REGISTERS_RESET_REG_1_RST_HC |
9252 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9253 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9254
9255 not_reset_mask2 =
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009256 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009257 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9258 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9259 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9260 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9261 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9262 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009263 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9264 MISC_REGISTERS_RESET_REG_2_RST_ATC |
Barak Witkowskic55e7712012-12-02 04:05:46 +00009265 MISC_REGISTERS_RESET_REG_2_PGLC |
9266 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9267 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9268 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9269 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9270 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9271 MISC_REGISTERS_RESET_REG_2_UMAC1;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009272
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009273 /*
9274 * Keep the following blocks in reset:
9275 * - all xxMACs are handled by the bnx2x_link code.
9276 */
9277 stay_reset2 =
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009278 MISC_REGISTERS_RESET_REG_2_XMAC |
9279 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9280
9281 /* Full reset masks according to the chip */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009282 reset_mask1 = 0xffffffff;
9283
9284 if (CHIP_IS_E1(bp))
9285 reset_mask2 = 0xffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009286 else if (CHIP_IS_E1H(bp))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009287 reset_mask2 = 0x1ffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009288 else if (CHIP_IS_E2(bp))
9289 reset_mask2 = 0xfffff;
9290 else /* CHIP_IS_E3 */
9291 reset_mask2 = 0x3ffffff;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009292
9293 /* Don't reset global blocks unless we need to */
9294 if (!global)
9295 reset_mask2 &= ~global_bits2;
9296
9297 /*
9298 * In case of attention in the QM, we need to reset PXP
9299 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9300 * because otherwise QM reset would release 'close the gates' shortly
9301 * before resetting the PXP, then the PSWRQ would send a write
9302 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9303 * read the payload data from PSWWR, but PSWWR would not
9304 * respond. The write queue in PGLUE would stuck, dmae commands
9305 * would not return. Therefore it's important to reset the second
9306 * reset register (containing the
9307 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9308 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9309 * bit).
9310 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009311 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9312 reset_mask2 & (~not_reset_mask2));
9313
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009314 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9315 reset_mask1 & (~not_reset_mask1));
9316
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009317 barrier();
9318 mmiowb();
9319
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009320 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9321 reset_mask2 & (~stay_reset2));
9322
9323 barrier();
9324 mmiowb();
9325
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009326 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009327 mmiowb();
9328}
9329
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009330/**
9331 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9332 * It should get cleared in no more than 1s.
9333 *
9334 * @bp: driver handle
9335 *
9336 * It should get cleared in no more than 1s. Returns 0 if
9337 * pending writes bit gets cleared.
9338 */
9339static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9340{
9341 u32 cnt = 1000;
9342 u32 pend_bits = 0;
9343
9344 do {
9345 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9346
9347 if (pend_bits == 0)
9348 break;
9349
Yuval Mintz0926d492013-01-23 03:21:45 +00009350 usleep_range(1000, 2000);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009351 } while (cnt-- > 0);
9352
9353 if (cnt <= 0) {
9354 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9355 pend_bits);
9356 return -EBUSY;
9357 }
9358
9359 return 0;
9360}
9361
9362static int bnx2x_process_kill(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009363{
9364 int cnt = 1000;
9365 u32 val = 0;
9366 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
Yuval Mintz2de67432013-01-23 03:21:43 +00009367 u32 tags_63_32 = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009368
9369 /* Empty the Tetris buffer, wait for 1s */
9370 do {
9371 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9372 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9373 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9374 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9375 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009376 if (CHIP_IS_E3(bp))
9377 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9378
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009379 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9380 ((port_is_idle_0 & 0x1) == 0x1) &&
9381 ((port_is_idle_1 & 0x1) == 0x1) &&
Barak Witkowskic55e7712012-12-02 04:05:46 +00009382 (pgl_exp_rom2 == 0xffffffff) &&
9383 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009384 break;
Yuval Mintz0926d492013-01-23 03:21:45 +00009385 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009386 } while (cnt-- > 0);
9387
9388 if (cnt <= 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009389 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9390 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 +00009391 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9392 pgl_exp_rom2);
9393 return -EAGAIN;
9394 }
9395
9396 barrier();
9397
9398 /* Close gates #2, #3 and #4 */
9399 bnx2x_set_234_gates(bp, true);
9400
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009401 /* Poll for IGU VQs for 57712 and newer chips */
9402 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9403 return -EAGAIN;
9404
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009405 /* TBD: Indicate that "process kill" is in progress to MCP */
9406
9407 /* Clear "unprepared" bit */
9408 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9409 barrier();
9410
9411 /* Make sure all is written to the chip before the reset */
9412 mmiowb();
9413
9414 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9415 * PSWHST, GRC and PSWRD Tetris buffer.
9416 */
Yuval Mintz0926d492013-01-23 03:21:45 +00009417 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009418
9419 /* Prepare to chip reset: */
9420 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009421 if (global)
9422 bnx2x_reset_mcp_prep(bp, &val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009423
9424 /* PXP */
9425 bnx2x_pxp_prep(bp);
9426 barrier();
9427
9428 /* reset the chip */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009429 bnx2x_process_kill_chip_reset(bp, global);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009430 barrier();
9431
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +02009432 /* clear errors in PGB */
9433 if (!CHIP_IS_E1x(bp))
9434 REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
9435
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009436 /* Recover after reset: */
9437 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009438 if (global && bnx2x_reset_mcp_comp(bp, val))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009439 return -EAGAIN;
9440
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009441 /* TBD: Add resetting the NO_MCP mode DB here */
9442
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009443 /* Open the gates #2, #3 and #4 */
9444 bnx2x_set_234_gates(bp, false);
9445
9446 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9447 * reset state, re-enable attentions. */
9448
9449 return 0;
9450}
9451
Merav Sicron910cc722012-11-11 03:56:08 +00009452static int bnx2x_leader_reset(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009453{
9454 int rc = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009455 bool global = bnx2x_reset_is_global(bp);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009456 u32 load_code;
9457
9458 /* if not going to reset MCP - load "fake" driver to reset HW while
9459 * driver is owner of the HW
9460 */
9461 if (!global && !BP_NOMCP(bp)) {
Yuval Mintz5d07d862012-09-13 02:56:21 +00009462 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9463 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009464 if (!load_code) {
9465 BNX2X_ERR("MCP response failure, aborting\n");
9466 rc = -EAGAIN;
9467 goto exit_leader_reset;
9468 }
9469 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9470 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9471 BNX2X_ERR("MCP unexpected resp, aborting\n");
9472 rc = -EAGAIN;
9473 goto exit_leader_reset2;
9474 }
9475 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9476 if (!load_code) {
9477 BNX2X_ERR("MCP response failure, aborting\n");
9478 rc = -EAGAIN;
9479 goto exit_leader_reset2;
9480 }
9481 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009482
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009483 /* Try to recover after the failure */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009484 if (bnx2x_process_kill(bp, global)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009485 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9486 BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009487 rc = -EAGAIN;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009488 goto exit_leader_reset2;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009489 }
9490
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009491 /*
9492 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9493 * state.
9494 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009495 bnx2x_set_reset_done(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009496 if (global)
9497 bnx2x_clear_reset_global(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009498
Ariel Elior95c6c6162012-01-26 06:01:52 +00009499exit_leader_reset2:
9500 /* unload "fake driver" if it was loaded */
9501 if (!global && !BP_NOMCP(bp)) {
9502 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9503 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9504 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009505exit_leader_reset:
9506 bp->is_leader = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009507 bnx2x_release_leader_lock(bp);
9508 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009509 return rc;
9510}
9511
Eric Dumazet1191cb82012-04-27 21:39:21 +00009512static void bnx2x_recovery_failed(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009513{
9514 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9515
9516 /* Disconnect this device */
9517 netif_device_detach(bp->dev);
9518
9519 /*
9520 * Block ifup for all function on this engine until "process kill"
9521 * or power cycle.
9522 */
9523 bnx2x_set_reset_in_progress(bp);
9524
9525 /* Shut down the power */
9526 bnx2x_set_power_state(bp, PCI_D3hot);
9527
9528 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9529
9530 smp_mb();
9531}
9532
9533/*
9534 * Assumption: runs under rtnl lock. This together with the fact
Ariel Elior6383c0b2011-07-14 08:31:57 +00009535 * that it's called only from bnx2x_sp_rtnl() ensure that it
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009536 * will never be called when netif_running(bp->dev) is false.
9537 */
9538static void bnx2x_parity_recover(struct bnx2x *bp)
9539{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009540 bool global = false;
Ariel Elior7a752992012-01-26 06:01:53 +00009541 u32 error_recovered, error_unrecovered;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009542 bool is_parity;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009543
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009544 DP(NETIF_MSG_HW, "Handling parity\n");
9545 while (1) {
9546 switch (bp->recovery_state) {
9547 case BNX2X_RECOVERY_INIT:
9548 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009549 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9550 WARN_ON(!is_parity);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009551
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009552 /* Try to get a LEADER_LOCK HW lock */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009553 if (bnx2x_trylock_leader_lock(bp)) {
9554 bnx2x_set_reset_in_progress(bp);
9555 /*
9556 * Check if there is a global attention and if
9557 * there was a global attention, set the global
9558 * reset bit.
9559 */
9560
9561 if (global)
9562 bnx2x_set_reset_global(bp);
9563
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009564 bp->is_leader = 1;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009565 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009566
9567 /* Stop the driver */
9568 /* If interface has been removed - break */
Yuval Mintz5d07d862012-09-13 02:56:21 +00009569 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009570 return;
9571
9572 bp->recovery_state = BNX2X_RECOVERY_WAIT;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009573
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009574 /* Ensure "is_leader", MCP command sequence and
9575 * "recovery_state" update values are seen on other
9576 * CPUs.
9577 */
9578 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009579 break;
9580
9581 case BNX2X_RECOVERY_WAIT:
9582 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9583 if (bp->is_leader) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009584 int other_engine = BP_PATH(bp) ? 0 : 1;
Ariel Elior889b9af2012-01-26 06:01:51 +00009585 bool other_load_status =
9586 bnx2x_get_load_status(bp, other_engine);
9587 bool load_status =
9588 bnx2x_get_load_status(bp, BP_PATH(bp));
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009589 global = bnx2x_reset_is_global(bp);
9590
9591 /*
9592 * In case of a parity in a global block, let
9593 * the first leader that performs a
9594 * leader_reset() reset the global blocks in
9595 * order to clear global attentions. Otherwise
Yuval Mintz16a5fd92013-06-02 00:06:18 +00009596 * the gates will remain closed for that
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009597 * engine.
9598 */
Ariel Elior889b9af2012-01-26 06:01:51 +00009599 if (load_status ||
9600 (global && other_load_status)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009601 /* Wait until all other functions get
9602 * down.
9603 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009604 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009605 HZ/10);
9606 return;
9607 } else {
9608 /* If all other functions got down -
9609 * try to bring the chip back to
9610 * normal. In any case it's an exit
9611 * point for a leader.
9612 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009613 if (bnx2x_leader_reset(bp)) {
9614 bnx2x_recovery_failed(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009615 return;
9616 }
9617
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009618 /* If we are here, means that the
9619 * leader has succeeded and doesn't
9620 * want to be a leader any more. Try
9621 * to continue as a none-leader.
9622 */
9623 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009624 }
9625 } else { /* non-leader */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009626 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009627 /* Try to get a LEADER_LOCK HW lock as
9628 * long as a former leader may have
9629 * been unloaded by the user or
9630 * released a leadership by another
9631 * reason.
9632 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009633 if (bnx2x_trylock_leader_lock(bp)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009634 /* I'm a leader now! Restart a
9635 * switch case.
9636 */
9637 bp->is_leader = 1;
9638 break;
9639 }
9640
Ariel Elior7be08a72011-07-14 08:31:19 +00009641 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009642 HZ/10);
9643 return;
9644
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009645 } else {
9646 /*
9647 * If there was a global attention, wait
9648 * for it to be cleared.
9649 */
9650 if (bnx2x_reset_is_global(bp)) {
9651 schedule_delayed_work(
Ariel Elior7be08a72011-07-14 08:31:19 +00009652 &bp->sp_rtnl_task,
9653 HZ/10);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009654 return;
9655 }
9656
Ariel Elior7a752992012-01-26 06:01:53 +00009657 error_recovered =
9658 bp->eth_stats.recoverable_error;
9659 error_unrecovered =
9660 bp->eth_stats.unrecoverable_error;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009661 bp->recovery_state =
9662 BNX2X_RECOVERY_NIC_LOADING;
9663 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
Ariel Elior7a752992012-01-26 06:01:53 +00009664 error_unrecovered++;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009665 netdev_err(bp->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +00009666 "Recovery failed. Power cycle needed\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009667 /* Disconnect this device */
9668 netif_device_detach(bp->dev);
9669 /* Shut down the power */
9670 bnx2x_set_power_state(
9671 bp, PCI_D3hot);
9672 smp_mb();
9673 } else {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009674 bp->recovery_state =
9675 BNX2X_RECOVERY_DONE;
Ariel Elior7a752992012-01-26 06:01:53 +00009676 error_recovered++;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009677 smp_mb();
9678 }
Ariel Elior7a752992012-01-26 06:01:53 +00009679 bp->eth_stats.recoverable_error =
9680 error_recovered;
9681 bp->eth_stats.unrecoverable_error =
9682 error_unrecovered;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009683
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009684 return;
9685 }
9686 }
9687 default:
9688 return;
9689 }
9690 }
9691}
9692
Michal Schmidt56ad3152012-02-16 02:38:48 +00009693static int bnx2x_close(struct net_device *dev);
9694
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009695/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9696 * scheduled on a general queue in order to prevent a dead lock.
9697 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009698static void bnx2x_sp_rtnl_task(struct work_struct *work)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009699{
Ariel Elior7be08a72011-07-14 08:31:19 +00009700 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009701
9702 rtnl_lock();
9703
Ariel Elior8395be52013-01-01 05:22:44 +00009704 if (!netif_running(bp->dev)) {
9705 rtnl_unlock();
9706 return;
9707 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009708
Ariel Elior7be08a72011-07-14 08:31:19 +00009709 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009710#ifdef BNX2X_STOP_ON_ERROR
9711 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9712 "you will need to reboot when done\n");
9713 goto sp_rtnl_not_reset;
9714#endif
Ariel Elior7be08a72011-07-14 08:31:19 +00009715 /*
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009716 * Clear all pending SP commands as we are going to reset the
9717 * function anyway.
Ariel Elior7be08a72011-07-14 08:31:19 +00009718 */
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009719 bp->sp_rtnl_state = 0;
9720 smp_mb();
9721
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009722 bnx2x_parity_recover(bp);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009723
Ariel Elior8395be52013-01-01 05:22:44 +00009724 rtnl_unlock();
9725 return;
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009726 }
9727
9728 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009729#ifdef BNX2X_STOP_ON_ERROR
9730 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9731 "you will need to reboot when done\n");
9732 goto sp_rtnl_not_reset;
9733#endif
9734
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009735 /*
9736 * Clear all pending SP commands as we are going to reset the
9737 * function anyway.
9738 */
9739 bp->sp_rtnl_state = 0;
9740 smp_mb();
9741
Yuval Mintz5d07d862012-09-13 02:56:21 +00009742 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009743 bnx2x_nic_load(bp, LOAD_NORMAL);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009744
Ariel Elior8395be52013-01-01 05:22:44 +00009745 rtnl_unlock();
9746 return;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009747 }
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009748#ifdef BNX2X_STOP_ON_ERROR
9749sp_rtnl_not_reset:
9750#endif
9751 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9752 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
Barak Witkowskia3348722012-04-23 03:04:46 +00009753 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9754 bnx2x_after_function_update(bp);
Ariel Elior83048592011-11-13 04:34:29 +00009755 /*
9756 * in case of fan failure we need to reset id if the "stop on error"
9757 * debug flag is set, since we trying to prevent permanent overheating
9758 * damage
9759 */
9760 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009761 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
Ariel Elior83048592011-11-13 04:34:29 +00009762 netif_device_detach(bp->dev);
9763 bnx2x_close(bp->dev);
Ariel Elior8395be52013-01-01 05:22:44 +00009764 rtnl_unlock();
9765 return;
Ariel Elior83048592011-11-13 04:34:29 +00009766 }
9767
Ariel Elior381ac162013-01-01 05:22:29 +00009768 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9769 DP(BNX2X_MSG_SP,
9770 "sending set mcast vf pf channel message from rtnl sp-task\n");
9771 bnx2x_vfpf_set_mcast(bp->dev);
9772 }
Ariel Elior78c3bcc2013-06-20 17:39:08 +03009773 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
9774 &bp->sp_rtnl_state)){
9775 if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
9776 bnx2x_tx_disable(bp);
9777 BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
9778 }
9779 }
Ariel Elior381ac162013-01-01 05:22:29 +00009780
Yuval Mintz8b09be52013-08-01 17:30:59 +03009781 if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
9782 DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
9783 bnx2x_set_rx_mode_inner(bp);
Ariel Elior381ac162013-01-01 05:22:29 +00009784 }
9785
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00009786 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9787 &bp->sp_rtnl_state))
9788 bnx2x_pf_set_vfs_vlan(bp);
9789
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02009790 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009791 bnx2x_dcbx_stop_hw_tx(bp);
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009792 bnx2x_dcbx_resume_hw_tx(bp);
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02009793 }
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009794
Ariel Elior8395be52013-01-01 05:22:44 +00009795 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9796 * can be called from other contexts as well)
9797 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009798 rtnl_unlock();
Ariel Elior8395be52013-01-01 05:22:44 +00009799
Ariel Elior64112802013-01-07 00:50:23 +00009800 /* enable SR-IOV if applicable */
Ariel Elior8395be52013-01-01 05:22:44 +00009801 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
Ariel Elior3c76fef2013-03-11 05:17:46 +00009802 &bp->sp_rtnl_state)) {
9803 bnx2x_disable_sriov(bp);
Ariel Elior64112802013-01-07 00:50:23 +00009804 bnx2x_enable_sriov(bp);
Ariel Elior3c76fef2013-03-11 05:17:46 +00009805 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009806}
9807
Yaniv Rosner3deb8162011-06-14 01:34:33 +00009808static void bnx2x_period_task(struct work_struct *work)
9809{
9810 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9811
9812 if (!netif_running(bp->dev))
9813 goto period_task_exit;
9814
9815 if (CHIP_REV_IS_SLOW(bp)) {
9816 BNX2X_ERR("period task called on emulation, ignoring\n");
9817 goto period_task_exit;
9818 }
9819
9820 bnx2x_acquire_phy_lock(bp);
9821 /*
9822 * The barrier is needed to ensure the ordering between the writing to
9823 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9824 * the reading here.
9825 */
9826 smp_mb();
9827 if (bp->port.pmf) {
9828 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9829
9830 /* Re-queue task in 1 sec */
9831 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9832 }
9833
9834 bnx2x_release_phy_lock(bp);
9835period_task_exit:
9836 return;
9837}
9838
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009839/*
9840 * Init service functions
9841 */
9842
stephen hemmingera8f47eb2014-01-09 22:20:11 -08009843static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009844{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009845 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9846 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9847 return base + (BP_ABS_FUNC(bp)) * stride;
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009848}
9849
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009850static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9851 struct bnx2x_mac_vals *vals)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009852{
Yuval Mintz452427b2012-03-26 20:47:07 +00009853 u32 val, base_addr, offset, mask, reset_reg;
9854 bool mac_stopped = false;
9855 u8 port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009856
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009857 /* reset addresses as they also mark which values were changed */
9858 vals->bmac_addr = 0;
9859 vals->umac_addr = 0;
9860 vals->xmac_addr = 0;
9861 vals->emac_addr = 0;
9862
Yuval Mintz452427b2012-03-26 20:47:07 +00009863 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
David S. Miller8decf862011-09-22 03:23:13 -04009864
Yuval Mintz452427b2012-03-26 20:47:07 +00009865 if (!CHIP_IS_E3(bp)) {
9866 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
9867 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
9868 if ((mask & reset_reg) && val) {
9869 u32 wb_data[2];
9870 BNX2X_DEV_INFO("Disable bmac Rx\n");
9871 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
9872 : NIG_REG_INGRESS_BMAC0_MEM;
9873 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
9874 : BIGMAC_REGISTER_BMAC_CONTROL;
Ariel Eliorf16da432012-01-26 06:01:50 +00009875
Yuval Mintz452427b2012-03-26 20:47:07 +00009876 /*
9877 * use rd/wr since we cannot use dmae. This is safe
9878 * since MCP won't access the bus due to the request
9879 * to unload, and no function on the path can be
9880 * loaded at this time.
9881 */
9882 wb_data[0] = REG_RD(bp, base_addr + offset);
9883 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009884 vals->bmac_addr = base_addr + offset;
9885 vals->bmac_val[0] = wb_data[0];
9886 vals->bmac_val[1] = wb_data[1];
Yuval Mintz452427b2012-03-26 20:47:07 +00009887 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009888 REG_WR(bp, vals->bmac_addr, wb_data[0]);
9889 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
Yuval Mintz452427b2012-03-26 20:47:07 +00009890 }
9891 BNX2X_DEV_INFO("Disable emac Rx\n");
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009892 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
9893 vals->emac_val = REG_RD(bp, vals->emac_addr);
9894 REG_WR(bp, vals->emac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009895 mac_stopped = true;
9896 } else {
9897 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
9898 BNX2X_DEV_INFO("Disable xmac Rx\n");
9899 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
9900 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
9901 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9902 val & ~(1 << 1));
9903 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
9904 val | (1 << 1));
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009905 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
9906 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
9907 REG_WR(bp, vals->xmac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009908 mac_stopped = true;
9909 }
9910 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
9911 if (mask & reset_reg) {
9912 BNX2X_DEV_INFO("Disable umac Rx\n");
9913 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009914 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
9915 vals->umac_val = REG_RD(bp, vals->umac_addr);
9916 REG_WR(bp, vals->umac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +00009917 mac_stopped = true;
David S. Miller8decf862011-09-22 03:23:13 -04009918 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009919 }
Ariel Eliorf16da432012-01-26 06:01:50 +00009920
Yuval Mintz452427b2012-03-26 20:47:07 +00009921 if (mac_stopped)
9922 msleep(20);
Yuval Mintz452427b2012-03-26 20:47:07 +00009923}
9924
9925#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
9926#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
9927#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
9928#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
9929
Yuval Mintz91ebb922013-12-26 09:57:07 +02009930#define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
9931#define BCM_5710_UNDI_FW_MF_MINOR (0x08)
9932#define BCM_5710_UNDI_FW_MF_VERS (0x05)
9933#define BNX2X_PREV_UNDI_MF_PORT(p) (0x1a150c + ((p) << 4))
9934#define BNX2X_PREV_UNDI_MF_FUNC(f) (0x1a184c + ((f) << 4))
9935static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
9936{
9937 u8 major, minor, version;
9938 u32 fw;
9939
9940 /* Must check that FW is loaded */
9941 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
9942 MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
9943 BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
9944 return false;
9945 }
9946
9947 /* Read Currently loaded FW version */
9948 fw = REG_RD(bp, XSEM_REG_PRAM);
9949 major = fw & 0xff;
9950 minor = (fw >> 0x8) & 0xff;
9951 version = (fw >> 0x10) & 0xff;
9952 BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
9953 fw, major, minor, version);
9954
9955 if (major > BCM_5710_UNDI_FW_MF_MAJOR)
9956 return true;
9957
9958 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
9959 (minor > BCM_5710_UNDI_FW_MF_MINOR))
9960 return true;
9961
9962 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
9963 (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
9964 (version >= BCM_5710_UNDI_FW_MF_VERS))
9965 return true;
9966
9967 return false;
9968}
9969
9970static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
9971{
9972 int i;
9973
9974 /* Due to legacy (FW) code, the first function on each engine has a
9975 * different offset macro from the rest of the functions.
9976 * Setting this for all 8 functions is harmless regardless of whether
9977 * this is actually a multi-function device.
9978 */
9979 for (i = 0; i < 2; i++)
9980 REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
9981
9982 for (i = 2; i < 8; i++)
9983 REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
9984
9985 BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
9986}
9987
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009988static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
Yuval Mintz452427b2012-03-26 20:47:07 +00009989{
9990 u16 rcq, bd;
9991 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
9992
9993 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
9994 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
9995
9996 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
9997 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
9998
9999 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
10000 port, bd, rcq);
10001}
10002
Bill Pemberton0329aba2012-12-03 09:24:24 -050010003static int bnx2x_prev_mcp_done(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010004{
Yuval Mintz5d07d862012-09-13 02:56:21 +000010005 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
10006 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
Yuval Mintz452427b2012-03-26 20:47:07 +000010007 if (!rc) {
10008 BNX2X_ERR("MCP response failure, aborting\n");
10009 return -EBUSY;
10010 }
10011
10012 return 0;
10013}
10014
Barak Witkowskic63da992012-12-05 23:04:03 +000010015static struct bnx2x_prev_path_list *
10016 bnx2x_prev_path_get_entry(struct bnx2x *bp)
10017{
10018 struct bnx2x_prev_path_list *tmp_list;
10019
10020 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
10021 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
10022 bp->pdev->bus->number == tmp_list->bus &&
10023 BP_PATH(bp) == tmp_list->path)
10024 return tmp_list;
10025
10026 return NULL;
10027}
10028
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010029static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
10030{
10031 struct bnx2x_prev_path_list *tmp_list;
10032 int rc;
10033
10034 rc = down_interruptible(&bnx2x_prev_sem);
10035 if (rc) {
10036 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10037 return rc;
10038 }
10039
10040 tmp_list = bnx2x_prev_path_get_entry(bp);
10041 if (tmp_list) {
10042 tmp_list->aer = 1;
10043 rc = 0;
10044 } else {
10045 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
10046 BP_PATH(bp));
10047 }
10048
10049 up(&bnx2x_prev_sem);
10050
10051 return rc;
10052}
10053
Bill Pemberton0329aba2012-12-03 09:24:24 -050010054static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010055{
10056 struct bnx2x_prev_path_list *tmp_list;
Peter Senna Tschudinb85d7172013-10-02 14:19:49 +020010057 bool rc = false;
Yuval Mintz452427b2012-03-26 20:47:07 +000010058
10059 if (down_trylock(&bnx2x_prev_sem))
10060 return false;
10061
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010062 tmp_list = bnx2x_prev_path_get_entry(bp);
10063 if (tmp_list) {
10064 if (tmp_list->aer) {
10065 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
10066 BP_PATH(bp));
10067 } else {
Yuval Mintz452427b2012-03-26 20:47:07 +000010068 rc = true;
10069 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
10070 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +000010071 }
10072 }
10073
10074 up(&bnx2x_prev_sem);
10075
10076 return rc;
10077}
10078
Dmitry Kravkov178135c2013-05-22 21:21:50 +000010079bool bnx2x_port_after_undi(struct bnx2x *bp)
10080{
10081 struct bnx2x_prev_path_list *entry;
10082 bool val;
10083
10084 down(&bnx2x_prev_sem);
10085
10086 entry = bnx2x_prev_path_get_entry(bp);
10087 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
10088
10089 up(&bnx2x_prev_sem);
10090
10091 return val;
10092}
10093
Barak Witkowskic63da992012-12-05 23:04:03 +000010094static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
Yuval Mintz452427b2012-03-26 20:47:07 +000010095{
10096 struct bnx2x_prev_path_list *tmp_list;
10097 int rc;
10098
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010099 rc = down_interruptible(&bnx2x_prev_sem);
10100 if (rc) {
10101 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10102 return rc;
10103 }
10104
10105 /* Check whether the entry for this path already exists */
10106 tmp_list = bnx2x_prev_path_get_entry(bp);
10107 if (tmp_list) {
10108 if (!tmp_list->aer) {
10109 BNX2X_ERR("Re-Marking the path.\n");
10110 } else {
10111 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
10112 BP_PATH(bp));
10113 tmp_list->aer = 0;
10114 }
10115 up(&bnx2x_prev_sem);
10116 return 0;
10117 }
10118 up(&bnx2x_prev_sem);
10119
10120 /* Create an entry for this path and add it */
Devendra Nagaea4b3852012-07-29 03:19:23 +000010121 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
Yuval Mintz452427b2012-03-26 20:47:07 +000010122 if (!tmp_list) {
10123 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
10124 return -ENOMEM;
10125 }
10126
10127 tmp_list->bus = bp->pdev->bus->number;
10128 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
10129 tmp_list->path = BP_PATH(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010130 tmp_list->aer = 0;
Barak Witkowskic63da992012-12-05 23:04:03 +000010131 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
Yuval Mintz452427b2012-03-26 20:47:07 +000010132
10133 rc = down_interruptible(&bnx2x_prev_sem);
10134 if (rc) {
10135 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10136 kfree(tmp_list);
10137 } else {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010138 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
10139 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +000010140 list_add(&tmp_list->list, &bnx2x_prev_list);
10141 up(&bnx2x_prev_sem);
10142 }
10143
10144 return rc;
10145}
10146
Bill Pemberton0329aba2012-12-03 09:24:24 -050010147static int bnx2x_do_flr(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010148{
Yuval Mintz452427b2012-03-26 20:47:07 +000010149 struct pci_dev *dev = bp->pdev;
10150
Yuval Mintz8eee6942012-08-09 04:37:25 +000010151 if (CHIP_IS_E1x(bp)) {
10152 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
10153 return -EINVAL;
10154 }
10155
10156 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
10157 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
10158 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
10159 bp->common.bc_ver);
10160 return -EINVAL;
10161 }
Yuval Mintz452427b2012-03-26 20:47:07 +000010162
Casey Leedom8903b9e2013-08-06 15:48:38 +053010163 if (!pci_wait_for_pending_transaction(dev))
10164 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010165
Yuval Mintz8eee6942012-08-09 04:37:25 +000010166 BNX2X_DEV_INFO("Initiating FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010167 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
10168
10169 return 0;
10170}
10171
Bill Pemberton0329aba2012-12-03 09:24:24 -050010172static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010173{
10174 int rc;
10175
10176 BNX2X_DEV_INFO("Uncommon unload Flow\n");
10177
10178 /* Test if previous unload process was already finished for this path */
10179 if (bnx2x_prev_is_path_marked(bp))
10180 return bnx2x_prev_mcp_done(bp);
10181
Yuval Mintz04c46732013-01-23 03:21:46 +000010182 BNX2X_DEV_INFO("Path is unmarked\n");
10183
Yuval Mintz452427b2012-03-26 20:47:07 +000010184 /* If function has FLR capabilities, and existing FW version matches
10185 * the one required, then FLR will be sufficient to clean any residue
10186 * left by previous driver
10187 */
Yuval Mintz91ebb922013-12-26 09:57:07 +020010188 rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
Yuval Mintz8eee6942012-08-09 04:37:25 +000010189
10190 if (!rc) {
10191 /* fw version is good */
10192 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
10193 rc = bnx2x_do_flr(bp);
10194 }
10195
10196 if (!rc) {
10197 /* FLR was performed */
10198 BNX2X_DEV_INFO("FLR successful\n");
10199 return 0;
10200 }
10201
10202 BNX2X_DEV_INFO("Could not FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010203
10204 /* Close the MCP request, return failure*/
10205 rc = bnx2x_prev_mcp_done(bp);
10206 if (!rc)
10207 rc = BNX2X_PREV_WAIT_NEEDED;
10208
10209 return rc;
10210}
10211
Bill Pemberton0329aba2012-12-03 09:24:24 -050010212static int bnx2x_prev_unload_common(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010213{
10214 u32 reset_reg, tmp_reg = 0, rc;
Barak Witkowskic63da992012-12-05 23:04:03 +000010215 bool prev_undi = false;
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010216 struct bnx2x_mac_vals mac_vals;
10217
Yuval Mintz452427b2012-03-26 20:47:07 +000010218 /* It is possible a previous function received 'common' answer,
10219 * but hasn't loaded yet, therefore creating a scenario of
10220 * multiple functions receiving 'common' on the same path.
10221 */
10222 BNX2X_DEV_INFO("Common unload Flow\n");
10223
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010224 memset(&mac_vals, 0, sizeof(mac_vals));
10225
Yuval Mintz452427b2012-03-26 20:47:07 +000010226 if (bnx2x_prev_is_path_marked(bp))
10227 return bnx2x_prev_mcp_done(bp);
10228
10229 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
10230
10231 /* Reset should be performed after BRB is emptied */
10232 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
10233 u32 timer_count = 1000;
Yuval Mintz452427b2012-03-26 20:47:07 +000010234
10235 /* Close the MAC Rx to prevent BRB from filling up */
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010236 bnx2x_prev_unload_close_mac(bp, &mac_vals);
10237
10238 /* close LLH filters towards the BRB */
10239 bnx2x_set_rx_filter(&bp->link_params, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010240
10241 /* Check if the UNDI driver was previously loaded
10242 * UNDI driver initializes CID offset for normal bell to 0x7
10243 */
Yuval Mintz452427b2012-03-26 20:47:07 +000010244 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
10245 tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
10246 if (tmp_reg == 0x7) {
10247 BNX2X_DEV_INFO("UNDI previously loaded\n");
10248 prev_undi = true;
10249 /* clear the UNDI indication */
10250 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
Yuval Mintza74801c2013-01-14 05:11:41 +000010251 /* clear possible idle check errors */
10252 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010253 }
10254 }
Dmitry Kravkovd46f7c42013-04-17 22:49:05 +000010255 if (!CHIP_IS_E1x(bp))
10256 /* block FW from writing to host */
10257 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10258
Yuval Mintz452427b2012-03-26 20:47:07 +000010259 /* wait until BRB is empty */
10260 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10261 while (timer_count) {
10262 u32 prev_brb = tmp_reg;
10263
10264 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10265 if (!tmp_reg)
10266 break;
10267
10268 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
10269
10270 /* reset timer as long as BRB actually gets emptied */
10271 if (prev_brb > tmp_reg)
10272 timer_count = 1000;
10273 else
10274 timer_count--;
10275
Yuval Mintz91ebb922013-12-26 09:57:07 +020010276 /* New UNDI FW supports MF and contains better
10277 * cleaning methods - might be redundant but harmless.
10278 */
10279 if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
10280 bnx2x_prev_unload_undi_mf(bp);
10281 } else if (prev_undi) {
10282 /* If UNDI resides in memory,
10283 * manually increment it
10284 */
Yuval Mintz452427b2012-03-26 20:47:07 +000010285 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
Yuval Mintz91ebb922013-12-26 09:57:07 +020010286 }
Yuval Mintz452427b2012-03-26 20:47:07 +000010287 udelay(10);
10288 }
10289
10290 if (!timer_count)
10291 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010292 }
10293
10294 /* No packets are in the pipeline, path is ready for reset */
10295 bnx2x_reset_common(bp);
10296
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010297 if (mac_vals.xmac_addr)
10298 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
10299 if (mac_vals.umac_addr)
10300 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
10301 if (mac_vals.emac_addr)
10302 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
10303 if (mac_vals.bmac_addr) {
10304 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
10305 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
10306 }
10307
Barak Witkowskic63da992012-12-05 23:04:03 +000010308 rc = bnx2x_prev_mark_path(bp, prev_undi);
Yuval Mintz452427b2012-03-26 20:47:07 +000010309 if (rc) {
10310 bnx2x_prev_mcp_done(bp);
10311 return rc;
10312 }
10313
10314 return bnx2x_prev_mcp_done(bp);
10315}
10316
Ariel Elior24f06712012-05-06 07:05:57 +000010317/* previous driver DMAE transaction may have occurred when pre-boot stage ended
10318 * and boot began, or when kdump kernel was loaded. Either case would invalidate
10319 * the addresses of the transaction, resulting in was-error bit set in the pci
10320 * causing all hw-to-host pcie transactions to timeout. If this happened we want
10321 * to clear the interrupt which detected this from the pglueb and the was done
10322 * bit
10323 */
Bill Pemberton0329aba2012-12-03 09:24:24 -050010324static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
Ariel Elior24f06712012-05-06 07:05:57 +000010325{
Ariel Elior4a254172012-11-22 07:16:17 +000010326 if (!CHIP_IS_E1x(bp)) {
10327 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
10328 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
Yuval Mintz04c46732013-01-23 03:21:46 +000010329 DP(BNX2X_MSG_SP,
10330 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
Ariel Elior4a254172012-11-22 07:16:17 +000010331 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
10332 1 << BP_FUNC(bp));
10333 }
Ariel Elior24f06712012-05-06 07:05:57 +000010334 }
10335}
10336
Bill Pemberton0329aba2012-12-03 09:24:24 -050010337static int bnx2x_prev_unload(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010338{
10339 int time_counter = 10;
10340 u32 rc, fw, hw_lock_reg, hw_lock_val;
10341 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10342
Ariel Elior24f06712012-05-06 07:05:57 +000010343 /* clear hw from errors which may have resulted from an interrupted
10344 * dmae transaction.
10345 */
10346 bnx2x_prev_interrupted_dmae(bp);
10347
10348 /* Release previously held locks */
Yuval Mintz452427b2012-03-26 20:47:07 +000010349 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10350 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10351 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10352
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010353 hw_lock_val = REG_RD(bp, hw_lock_reg);
Yuval Mintz452427b2012-03-26 20:47:07 +000010354 if (hw_lock_val) {
10355 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10356 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10357 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10358 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10359 }
10360
10361 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10362 REG_WR(bp, hw_lock_reg, 0xffffffff);
10363 } else
10364 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10365
10366 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10367 BNX2X_DEV_INFO("Release previously held alr\n");
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010368 bnx2x_release_alr(bp);
Yuval Mintz452427b2012-03-26 20:47:07 +000010369 }
10370
Yuval Mintz452427b2012-03-26 20:47:07 +000010371 do {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010372 int aer = 0;
Yuval Mintz452427b2012-03-26 20:47:07 +000010373 /* Lock MCP using an unload request */
10374 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10375 if (!fw) {
10376 BNX2X_ERR("MCP response failure, aborting\n");
10377 rc = -EBUSY;
10378 break;
10379 }
10380
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010381 rc = down_interruptible(&bnx2x_prev_sem);
10382 if (rc) {
10383 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10384 rc);
10385 } else {
10386 /* If Path is marked by EEH, ignore unload status */
10387 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10388 bnx2x_prev_path_get_entry(bp)->aer);
Yuval Mintz60cde812013-03-26 23:28:03 +000010389 up(&bnx2x_prev_sem);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010390 }
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010391
10392 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
Yuval Mintz452427b2012-03-26 20:47:07 +000010393 rc = bnx2x_prev_unload_common(bp);
10394 break;
10395 }
10396
Yuval Mintz16a5fd92013-06-02 00:06:18 +000010397 /* non-common reply from MCP might require looping */
Yuval Mintz452427b2012-03-26 20:47:07 +000010398 rc = bnx2x_prev_unload_uncommon(bp);
10399 if (rc != BNX2X_PREV_WAIT_NEEDED)
10400 break;
10401
10402 msleep(20);
10403 } while (--time_counter);
10404
10405 if (!time_counter || rc) {
Yuval Mintz91ebb922013-12-26 09:57:07 +020010406 BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
10407 rc = -EPROBE_DEFER;
Yuval Mintz452427b2012-03-26 20:47:07 +000010408 }
10409
Barak Witkowskic63da992012-12-05 23:04:03 +000010410 /* Mark function if its port was used to boot from SAN */
Dmitry Kravkov178135c2013-05-22 21:21:50 +000010411 if (bnx2x_port_after_undi(bp))
Barak Witkowskic63da992012-12-05 23:04:03 +000010412 bp->link_params.feature_config_flags |=
10413 FEATURE_CONFIG_BOOT_FROM_SAN;
10414
Yuval Mintz452427b2012-03-26 20:47:07 +000010415 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10416
10417 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010418}
10419
Bill Pemberton0329aba2012-12-03 09:24:24 -050010420static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010421{
Barak Witkowski1d187b32011-12-05 22:41:50 +000010422 u32 val, val2, val3, val4, id, boot_mode;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010423 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010424
10425 /* Get the chip revision id and number. */
10426 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10427 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10428 id = ((val & 0xffff) << 16);
10429 val = REG_RD(bp, MISC_REG_CHIP_REV);
10430 id |= ((val & 0xf) << 12);
Yuval Mintzf22fdf22013-03-11 05:17:43 +000010431
10432 /* Metal is read from PCI regs, but we can't access >=0x400 from
10433 * the configuration space (so we need to reg_rd)
10434 */
10435 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10436 id |= (((val >> 24) & 0xf) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +000010437 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010438 id |= (val & 0xf);
10439 bp->common.chip_id = id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010440
Barak Witkowski7e8e02d2012-04-03 18:41:28 +000010441 /* force 57811 according to MISC register */
10442 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10443 if (CHIP_IS_57810(bp))
10444 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10445 (bp->common.chip_id & 0x0000FFFF);
10446 else if (CHIP_IS_57810_MF(bp))
10447 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10448 (bp->common.chip_id & 0x0000FFFF);
10449 bp->common.chip_id |= 0x1;
10450 }
10451
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010452 /* Set doorbell size */
10453 bp->db_size = (1 << BNX2X_DB_SHIFT);
10454
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010455 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010456 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10457 if ((val & 1) == 0)
10458 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10459 else
10460 val = (val >> 1) & 1;
10461 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10462 "2_PORT_MODE");
10463 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10464 CHIP_2_PORT_MODE;
10465
10466 if (CHIP_MODE_IS_4_PORT(bp))
10467 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10468 else
10469 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10470 } else {
10471 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10472 bp->pfid = bp->pf_num; /* 0..7 */
10473 }
10474
Merav Sicron51c1a582012-03-18 10:33:38 +000010475 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10476
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010477 bp->link_params.chip_id = bp->common.chip_id;
10478 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010479
Eilon Greenstein1c063282009-02-12 08:36:43 +000010480 val = (REG_RD(bp, 0x2874) & 0x55);
10481 if ((bp->common.chip_id & 0x1) ||
10482 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10483 bp->flags |= ONE_PORT_FLAG;
10484 BNX2X_DEV_INFO("single port device\n");
10485 }
10486
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010487 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010488 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010489 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10490 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10491 bp->common.flash_size, bp->common.flash_size);
10492
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010493 bnx2x_init_shmem(bp);
10494
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010495 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10496 MISC_REG_GENERIC_CR_1 :
10497 MISC_REG_GENERIC_CR_0));
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010498
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010499 bp->link_params.shmem_base = bp->common.shmem_base;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010500 bp->link_params.shmem2_base = bp->common.shmem2_base;
Yaniv Rosnerb884d952012-11-27 03:46:28 +000010501 if (SHMEM2_RD(bp, size) >
10502 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10503 bp->link_params.lfa_base =
10504 REG_RD(bp, bp->common.shmem2_base +
10505 (u32)offsetof(struct shmem2_region,
10506 lfa_host_addr[BP_PORT(bp)]));
10507 else
10508 bp->link_params.lfa_base = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +000010509 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10510 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010511
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010512 if (!bp->common.shmem_base) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010513 BNX2X_DEV_INFO("MCP not active\n");
10514 bp->flags |= NO_MCP_FLAG;
10515 return;
10516 }
10517
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010518 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +000010519 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010520
10521 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10522 SHARED_HW_CFG_LED_MODE_MASK) >>
10523 SHARED_HW_CFG_LED_MODE_SHIFT);
10524
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000010525 bp->link_params.feature_config_flags = 0;
10526 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10527 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10528 bp->link_params.feature_config_flags |=
10529 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10530 else
10531 bp->link_params.feature_config_flags &=
10532 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10533
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010534 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10535 bp->common.bc_ver = val;
10536 BNX2X_DEV_INFO("bc_ver %X\n", val);
10537 if (val < BNX2X_BC_VER) {
10538 /* for now only warn
10539 * later we might need to enforce this */
Merav Sicron51c1a582012-03-18 10:33:38 +000010540 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10541 BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010542 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010543 bp->link_params.feature_config_flags |=
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010544 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010545 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10546
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010547 bp->link_params.feature_config_flags |=
10548 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10549 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
Barak Witkowskia3348722012-04-23 03:04:46 +000010550 bp->link_params.feature_config_flags |=
10551 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10552 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010553 bp->link_params.feature_config_flags |=
10554 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10555 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
Yaniv Rosner55386fe82012-11-27 03:46:30 +000010556
10557 bp->link_params.feature_config_flags |=
10558 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10559 FEATURE_CONFIG_MT_SUPPORT : 0;
10560
Barak Witkowski0e898dd2011-12-05 21:52:22 +000010561 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10562 BC_SUPPORTS_PFC_STATS : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010563
Barak Witkowski2e499d32012-06-26 01:31:19 +000010564 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10565 BC_SUPPORTS_FCOE_FEATURES : 0;
10566
Barak Witkowski98768792012-06-19 07:48:31 +000010567 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10568 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030010569
10570 bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
10571 BC_SUPPORTS_RMMOD_CMD : 0;
10572
Barak Witkowski1d187b32011-12-05 22:41:50 +000010573 boot_mode = SHMEM_RD(bp,
10574 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10575 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10576 switch (boot_mode) {
10577 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10578 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10579 break;
10580 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10581 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10582 break;
10583 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10584 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10585 break;
10586 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10587 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10588 break;
10589 }
10590
Jon Mason29ed74c2013-09-11 11:22:39 -070010591 pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
Dmitry Kravkovf9a3ebb2011-05-04 23:49:11 +000010592 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10593
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010594 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +000010595 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010596
10597 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10598 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10599 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10600 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10601
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010602 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10603 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010604}
10605
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010606#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10607#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10608
Bill Pemberton0329aba2012-12-03 09:24:24 -050010609static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010610{
10611 int pfid = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010612 int igu_sb_id;
10613 u32 val;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010614 u8 fid, igu_sb_cnt = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010615
10616 bp->igu_base_sb = 0xff;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010617 if (CHIP_INT_MODE_IS_BC(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -040010618 int vn = BP_VN(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010619 igu_sb_cnt = bp->igu_sb_cnt;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010620 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10621 FP_SB_MAX_E1x;
10622
10623 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10624 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10625
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010626 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010627 }
10628
10629 /* IGU in normal mode - read CAM */
10630 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10631 igu_sb_id++) {
10632 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10633 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10634 continue;
10635 fid = IGU_FID(val);
10636 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10637 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10638 continue;
10639 if (IGU_VEC(val) == 0)
10640 /* default status block */
10641 bp->igu_dsb_id = igu_sb_id;
10642 else {
10643 if (bp->igu_base_sb == 0xff)
10644 bp->igu_base_sb = igu_sb_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010645 igu_sb_cnt++;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010646 }
10647 }
10648 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010649
Ariel Elior6383c0b2011-07-14 08:31:57 +000010650#ifdef CONFIG_PCI_MSI
Ariel Elior185d4c82012-09-20 05:26:41 +000010651 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10652 * optional that number of CAM entries will not be equal to the value
10653 * advertised in PCI.
10654 * Driver should use the minimal value of both as the actual status
10655 * block count
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010656 */
Ariel Elior185d4c82012-09-20 05:26:41 +000010657 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010658#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010659
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010660 if (igu_sb_cnt == 0) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010661 BNX2X_ERR("CAM configuration error\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010662 return -EINVAL;
10663 }
10664
10665 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010666}
10667
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010668static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010669{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010670 int cfg_size = 0, idx, port = BP_PORT(bp);
10671
10672 /* Aggregation of supported attributes of all external phys */
10673 bp->port.supported[0] = 0;
10674 bp->port.supported[1] = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010675 switch (bp->link_params.num_phys) {
10676 case 1:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010677 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10678 cfg_size = 1;
10679 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010680 case 2:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010681 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10682 cfg_size = 1;
10683 break;
10684 case 3:
10685 if (bp->link_params.multi_phy_config &
10686 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10687 bp->port.supported[1] =
10688 bp->link_params.phy[EXT_PHY1].supported;
10689 bp->port.supported[0] =
10690 bp->link_params.phy[EXT_PHY2].supported;
10691 } else {
10692 bp->port.supported[0] =
10693 bp->link_params.phy[EXT_PHY1].supported;
10694 bp->port.supported[1] =
10695 bp->link_params.phy[EXT_PHY2].supported;
10696 }
10697 cfg_size = 2;
10698 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010699 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010700
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010701 if (!(bp->port.supported[0] || bp->port.supported[1])) {
Merav Sicron51c1a582012-03-18 10:33:38 +000010702 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010703 SHMEM_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010704 dev_info.port_hw_config[port].external_phy_config),
10705 SHMEM_RD(bp,
10706 dev_info.port_hw_config[port].external_phy_config2));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010707 return;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010708 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010709
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010710 if (CHIP_IS_E3(bp))
10711 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10712 else {
10713 switch (switch_cfg) {
10714 case SWITCH_CFG_1G:
10715 bp->port.phy_addr = REG_RD(
10716 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10717 break;
10718 case SWITCH_CFG_10G:
10719 bp->port.phy_addr = REG_RD(
10720 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10721 break;
10722 default:
10723 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10724 bp->port.link_config[0]);
10725 return;
10726 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010727 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010728 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010729 /* mask what we support according to speed_cap_mask per configuration */
10730 for (idx = 0; idx < cfg_size; idx++) {
10731 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010732 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010733 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010734
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010735 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010736 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010737 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010738
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010739 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010740 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010741 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010742
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010743 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010744 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010745 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010746
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010747 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010748 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010749 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010750 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010751
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010752 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010753 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010754 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010755
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010756 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010757 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010758 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
Yaniv Rosnerb8e0d882013-06-20 17:39:11 +030010759
10760 if (!(bp->link_params.speed_cap_mask[idx] &
10761 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
10762 bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010763 }
10764
10765 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10766 bp->port.supported[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010767}
10768
Bill Pemberton0329aba2012-12-03 09:24:24 -050010769static void bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010770{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010771 u32 link_config, idx, cfg_size = 0;
10772 bp->port.advertising[0] = 0;
10773 bp->port.advertising[1] = 0;
10774 switch (bp->link_params.num_phys) {
10775 case 1:
10776 case 2:
10777 cfg_size = 1;
10778 break;
10779 case 3:
10780 cfg_size = 2;
10781 break;
10782 }
10783 for (idx = 0; idx < cfg_size; idx++) {
10784 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10785 link_config = bp->port.link_config[idx];
10786 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010787 case PORT_FEATURE_LINK_SPEED_AUTO:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010788 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10789 bp->link_params.req_line_speed[idx] =
10790 SPEED_AUTO_NEG;
10791 bp->port.advertising[idx] |=
10792 bp->port.supported[idx];
Mintz Yuval10bd1f22012-02-15 02:10:30 +000010793 if (bp->link_params.phy[EXT_PHY1].type ==
10794 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10795 bp->port.advertising[idx] |=
10796 (SUPPORTED_100baseT_Half |
10797 SUPPORTED_100baseT_Full);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010798 } else {
10799 /* force 10G, no AN */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010800 bp->link_params.req_line_speed[idx] =
10801 SPEED_10000;
10802 bp->port.advertising[idx] |=
10803 (ADVERTISED_10000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010804 ADVERTISED_FIBRE);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010805 continue;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010806 }
10807 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010808
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010809 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010810 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10811 bp->link_params.req_line_speed[idx] =
10812 SPEED_10;
10813 bp->port.advertising[idx] |=
10814 (ADVERTISED_10baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010815 ADVERTISED_TP);
10816 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010817 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010818 link_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010819 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010820 return;
10821 }
10822 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010823
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010824 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010825 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10826 bp->link_params.req_line_speed[idx] =
10827 SPEED_10;
10828 bp->link_params.req_duplex[idx] =
10829 DUPLEX_HALF;
10830 bp->port.advertising[idx] |=
10831 (ADVERTISED_10baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010832 ADVERTISED_TP);
10833 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010834 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010835 link_config,
10836 bp->link_params.speed_cap_mask[idx]);
10837 return;
10838 }
10839 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010840
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010841 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10842 if (bp->port.supported[idx] &
10843 SUPPORTED_100baseT_Full) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010844 bp->link_params.req_line_speed[idx] =
10845 SPEED_100;
10846 bp->port.advertising[idx] |=
10847 (ADVERTISED_100baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010848 ADVERTISED_TP);
10849 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010850 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010851 link_config,
10852 bp->link_params.speed_cap_mask[idx]);
10853 return;
10854 }
10855 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010856
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010857 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10858 if (bp->port.supported[idx] &
10859 SUPPORTED_100baseT_Half) {
10860 bp->link_params.req_line_speed[idx] =
10861 SPEED_100;
10862 bp->link_params.req_duplex[idx] =
10863 DUPLEX_HALF;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010864 bp->port.advertising[idx] |=
10865 (ADVERTISED_100baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010866 ADVERTISED_TP);
10867 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010868 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010869 link_config,
10870 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010871 return;
10872 }
10873 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010874
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010875 case PORT_FEATURE_LINK_SPEED_1G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010876 if (bp->port.supported[idx] &
10877 SUPPORTED_1000baseT_Full) {
10878 bp->link_params.req_line_speed[idx] =
10879 SPEED_1000;
10880 bp->port.advertising[idx] |=
10881 (ADVERTISED_1000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010882 ADVERTISED_TP);
10883 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010884 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010885 link_config,
10886 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010887 return;
10888 }
10889 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010890
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010891 case PORT_FEATURE_LINK_SPEED_2_5G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010892 if (bp->port.supported[idx] &
10893 SUPPORTED_2500baseX_Full) {
10894 bp->link_params.req_line_speed[idx] =
10895 SPEED_2500;
10896 bp->port.advertising[idx] |=
10897 (ADVERTISED_2500baseX_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010898 ADVERTISED_TP);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010899 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010900 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010901 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010902 bp->link_params.speed_cap_mask[idx]);
10903 return;
10904 }
10905 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010906
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010907 case PORT_FEATURE_LINK_SPEED_10G_CX4:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010908 if (bp->port.supported[idx] &
10909 SUPPORTED_10000baseT_Full) {
10910 bp->link_params.req_line_speed[idx] =
10911 SPEED_10000;
10912 bp->port.advertising[idx] |=
10913 (ADVERTISED_10000baseT_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010914 ADVERTISED_FIBRE);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010915 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010916 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010917 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010918 bp->link_params.speed_cap_mask[idx]);
10919 return;
10920 }
10921 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010922 case PORT_FEATURE_LINK_SPEED_20G:
10923 bp->link_params.req_line_speed[idx] = SPEED_20000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010924
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010925 break;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010926 default:
Merav Sicron51c1a582012-03-18 10:33:38 +000010927 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010928 link_config);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010929 bp->link_params.req_line_speed[idx] =
10930 SPEED_AUTO_NEG;
10931 bp->port.advertising[idx] =
10932 bp->port.supported[idx];
10933 break;
10934 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010935
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010936 bp->link_params.req_flow_ctrl[idx] = (link_config &
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010937 PORT_FEATURE_FLOW_CONTROL_MASK);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +000010938 if (bp->link_params.req_flow_ctrl[idx] ==
10939 BNX2X_FLOW_CTRL_AUTO) {
10940 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
10941 bp->link_params.req_flow_ctrl[idx] =
10942 BNX2X_FLOW_CTRL_NONE;
10943 else
10944 bnx2x_set_requested_fc(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010945 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010946
Merav Sicron51c1a582012-03-18 10:33:38 +000010947 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 +000010948 bp->link_params.req_line_speed[idx],
10949 bp->link_params.req_duplex[idx],
10950 bp->link_params.req_flow_ctrl[idx],
10951 bp->port.advertising[idx]);
10952 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010953}
10954
Bill Pemberton0329aba2012-12-03 09:24:24 -050010955static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
Michael Chane665bfd2009-10-10 13:46:54 +000010956{
Yuval Mintz86564c32013-01-23 03:21:50 +000010957 __be16 mac_hi_be = cpu_to_be16(mac_hi);
10958 __be32 mac_lo_be = cpu_to_be32(mac_lo);
10959 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
10960 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
Michael Chane665bfd2009-10-10 13:46:54 +000010961}
10962
Bill Pemberton0329aba2012-12-03 09:24:24 -050010963static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010964{
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010965 int port = BP_PORT(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +000010966 u32 config;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010967 u32 ext_phy_type, ext_phy_config, eee_mode;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010968
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010969 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010970 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010971
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010972 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010973 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010974
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010975 bp->link_params.speed_cap_mask[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010976 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000010977 dev_info.port_hw_config[port].speed_capability_mask) &
10978 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010979 bp->link_params.speed_cap_mask[1] =
10980 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000010981 dev_info.port_hw_config[port].speed_capability_mask2) &
10982 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010983 bp->port.link_config[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010984 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
10985
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010986 bp->port.link_config[1] =
10987 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000010988
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010989 bp->link_params.multi_phy_config =
10990 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000010991 /* If the device is capable of WoL, set the default state according
10992 * to the HW
10993 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010994 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000010995 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
10996 (config & PORT_FEATURE_WOL_ENABLED));
10997
Yuval Mintz4ba76992013-01-14 05:11:45 +000010998 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
10999 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
11000 bp->flags |= NO_ISCSI_FLAG;
11001 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
11002 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
11003 bp->flags |= NO_FCOE_FLAG;
11004
Merav Sicron51c1a582012-03-18 10:33:38 +000011005 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011006 bp->link_params.lane_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011007 bp->link_params.speed_cap_mask[0],
11008 bp->port.link_config[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011009
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011010 bp->link_params.switch_cfg = (bp->port.link_config[0] &
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011011 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011012 bnx2x_phy_probe(&bp->link_params);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011013 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011014
11015 bnx2x_link_settings_requested(bp);
11016
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011017 /*
11018 * If connected directly, work with the internal PHY, otherwise, work
11019 * with the external PHY
11020 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011021 ext_phy_config =
11022 SHMEM_RD(bp,
11023 dev_info.port_hw_config[port].external_phy_config);
11024 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011025 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011026 bp->mdio.prtad = bp->port.phy_addr;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011027
11028 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
11029 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11030 bp->mdio.prtad =
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011031 XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner5866df62011-01-30 04:15:07 +000011032
Yuval Mintzc8c60d82012-06-06 17:13:07 +000011033 /* Configure link feature according to nvram value */
11034 eee_mode = (((SHMEM_RD(bp, dev_info.
11035 port_feature_config[port].eee_power_mode)) &
11036 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
11037 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
11038 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
11039 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
11040 EEE_MODE_ENABLE_LPI |
11041 EEE_MODE_OUTPUT_TIME;
11042 } else {
11043 bp->link_params.eee_mode = 0;
11044 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011045}
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011046
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011047void bnx2x_get_iscsi_info(struct bnx2x *bp)
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011048{
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011049 u32 no_flags = NO_ISCSI_FLAG;
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011050 int port = BP_PORT(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011051 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011052 drv_lic_key[port].max_iscsi_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011053
Merav Sicron55c11942012-11-07 00:45:48 +000011054 if (!CNIC_SUPPORT(bp)) {
11055 bp->flags |= no_flags;
11056 return;
11057 }
11058
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011059 /* Get the number of maximum allowed iSCSI connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011060 bp->cnic_eth_dev.max_iscsi_conn =
11061 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
11062 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
11063
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011064 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
11065 bp->cnic_eth_dev.max_iscsi_conn);
11066
11067 /*
11068 * If maximum allowed number of connections is zero -
11069 * disable the feature.
11070 */
11071 if (!bp->cnic_eth_dev.max_iscsi_conn)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011072 bp->flags |= no_flags;
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011073}
11074
Bill Pemberton0329aba2012-12-03 09:24:24 -050011075static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011076{
11077 /* Port info */
11078 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11079 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
11080 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11081 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
11082
11083 /* Node info */
11084 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11085 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
11086 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11087 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
11088}
Dmitry Kravkov86800192013-05-27 04:08:29 +000011089
11090static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
11091{
11092 u8 count = 0;
11093
11094 if (IS_MF(bp)) {
11095 u8 fid;
11096
11097 /* iterate over absolute function ids for this path: */
11098 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
11099 if (IS_MF_SD(bp)) {
11100 u32 cfg = MF_CFG_RD(bp,
11101 func_mf_config[fid].config);
11102
11103 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
11104 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
11105 FUNC_MF_CFG_PROTOCOL_FCOE))
11106 count++;
11107 } else {
11108 u32 cfg = MF_CFG_RD(bp,
11109 func_ext_config[fid].
11110 func_cfg);
11111
11112 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
11113 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
11114 count++;
11115 }
11116 }
11117 } else { /* SF */
11118 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
11119
11120 for (port = 0; port < port_cnt; port++) {
11121 u32 lic = SHMEM_RD(bp,
11122 drv_lic_key[port].max_fcoe_conn) ^
11123 FW_ENCODE_32BIT_PATTERN;
11124 if (lic)
11125 count++;
11126 }
11127 }
11128
11129 return count;
11130}
11131
Bill Pemberton0329aba2012-12-03 09:24:24 -050011132static void bnx2x_get_fcoe_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011133{
11134 int port = BP_PORT(bp);
11135 int func = BP_ABS_FUNC(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011136 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
11137 drv_lic_key[port].max_fcoe_conn);
Dmitry Kravkov86800192013-05-27 04:08:29 +000011138 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011139
Merav Sicron55c11942012-11-07 00:45:48 +000011140 if (!CNIC_SUPPORT(bp)) {
11141 bp->flags |= NO_FCOE_FLAG;
11142 return;
11143 }
11144
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011145 /* Get the number of maximum allowed FCoE connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011146 bp->cnic_eth_dev.max_fcoe_conn =
11147 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
11148 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
11149
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000011150 /* Calculate the number of maximum allowed FCoE tasks */
11151 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
Dmitry Kravkov86800192013-05-27 04:08:29 +000011152
11153 /* check if FCoE resources must be shared between different functions */
11154 if (num_fcoe_func)
11155 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000011156
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011157 /* Read the WWN: */
11158 if (!IS_MF(bp)) {
11159 /* Port info */
11160 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11161 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011162 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011163 fcoe_wwn_port_name_upper);
11164 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11165 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011166 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011167 fcoe_wwn_port_name_lower);
11168
11169 /* Node info */
11170 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11171 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011172 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011173 fcoe_wwn_node_name_upper);
11174 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11175 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011176 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011177 fcoe_wwn_node_name_lower);
11178 } else if (!IS_MF_SD(bp)) {
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011179 /*
11180 * Read the WWN info only if the FCoE feature is enabled for
11181 * this function.
11182 */
Yuval Mintz7b5342d2012-09-11 04:34:14 +000011183 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011184 bnx2x_get_ext_wwn_info(bp, func);
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011185
Yuval Mintz382e5132012-12-02 04:05:51 +000011186 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011187 bnx2x_get_ext_wwn_info(bp, func);
Yuval Mintz382e5132012-12-02 04:05:51 +000011188 }
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011189
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011190 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011191
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011192 /*
11193 * If maximum allowed number of connections is zero -
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011194 * disable the feature.
11195 */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011196 if (!bp->cnic_eth_dev.max_fcoe_conn)
11197 bp->flags |= NO_FCOE_FLAG;
11198}
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011199
Bill Pemberton0329aba2012-12-03 09:24:24 -050011200static void bnx2x_get_cnic_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011201{
11202 /*
11203 * iSCSI may be dynamically disabled but reading
11204 * info here we will decrease memory usage by driver
11205 * if the feature is disabled for good
11206 */
11207 bnx2x_get_iscsi_info(bp);
11208 bnx2x_get_fcoe_info(bp);
11209}
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011210
Bill Pemberton0329aba2012-12-03 09:24:24 -050011211static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +000011212{
11213 u32 val, val2;
11214 int func = BP_ABS_FUNC(bp);
11215 int port = BP_PORT(bp);
11216 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
11217 u8 *fip_mac = bp->fip_mac;
11218
11219 if (IS_MF(bp)) {
11220 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
11221 * FCoE MAC then the appropriate feature should be disabled.
11222 * In non SD mode features configuration comes from struct
11223 * func_ext_config.
11224 */
11225 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
11226 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
11227 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
11228 val2 = MF_CFG_RD(bp, func_ext_config[func].
11229 iscsi_mac_addr_upper);
11230 val = MF_CFG_RD(bp, func_ext_config[func].
11231 iscsi_mac_addr_lower);
11232 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11233 BNX2X_DEV_INFO
11234 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11235 } else {
11236 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11237 }
11238
11239 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
11240 val2 = MF_CFG_RD(bp, func_ext_config[func].
11241 fcoe_mac_addr_upper);
11242 val = MF_CFG_RD(bp, func_ext_config[func].
11243 fcoe_mac_addr_lower);
11244 bnx2x_set_mac_buf(fip_mac, val, val2);
11245 BNX2X_DEV_INFO
11246 ("Read FCoE L2 MAC: %pM\n", fip_mac);
11247 } else {
11248 bp->flags |= NO_FCOE_FLAG;
11249 }
11250
11251 bp->mf_ext_config = cfg;
11252
11253 } else { /* SD MODE */
11254 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
11255 /* use primary mac as iscsi mac */
11256 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
11257
11258 BNX2X_DEV_INFO("SD ISCSI MODE\n");
11259 BNX2X_DEV_INFO
11260 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11261 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
11262 /* use primary mac as fip mac */
11263 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
11264 BNX2X_DEV_INFO("SD FCoE MODE\n");
11265 BNX2X_DEV_INFO
11266 ("Read FIP MAC: %pM\n", fip_mac);
11267 }
11268 }
11269
Yuval Mintz82594f82013-03-11 05:17:51 +000011270 /* If this is a storage-only interface, use SAN mac as
11271 * primary MAC. Notice that for SD this is already the case,
11272 * as the SAN mac was copied from the primary MAC.
11273 */
11274 if (IS_MF_FCOE_AFEX(bp))
Merav Sicron55c11942012-11-07 00:45:48 +000011275 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
Merav Sicron55c11942012-11-07 00:45:48 +000011276 } else {
11277 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11278 iscsi_mac_upper);
11279 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11280 iscsi_mac_lower);
11281 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11282
11283 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11284 fcoe_fip_mac_upper);
11285 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11286 fcoe_fip_mac_lower);
11287 bnx2x_set_mac_buf(fip_mac, val, val2);
11288 }
11289
11290 /* Disable iSCSI OOO if MAC configuration is invalid. */
11291 if (!is_valid_ether_addr(iscsi_mac)) {
11292 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11293 memset(iscsi_mac, 0, ETH_ALEN);
11294 }
11295
11296 /* Disable FCoE if MAC configuration is invalid. */
11297 if (!is_valid_ether_addr(fip_mac)) {
11298 bp->flags |= NO_FCOE_FLAG;
11299 memset(bp->fip_mac, 0, ETH_ALEN);
11300 }
11301}
11302
Bill Pemberton0329aba2012-12-03 09:24:24 -050011303static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011304{
11305 u32 val, val2;
11306 int func = BP_ABS_FUNC(bp);
11307 int port = BP_PORT(bp);
11308
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011309 /* Zero primary MAC configuration */
11310 memset(bp->dev->dev_addr, 0, ETH_ALEN);
11311
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011312 if (BP_NOMCP(bp)) {
11313 BNX2X_ERROR("warning: random MAC workaround active\n");
Danny Kukawka7ce5d222012-02-15 06:45:40 +000011314 eth_hw_addr_random(bp->dev);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011315 } else if (IS_MF(bp)) {
11316 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
11317 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
11318 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11319 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11320 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11321
Merav Sicron55c11942012-11-07 00:45:48 +000011322 if (CNIC_SUPPORT(bp))
11323 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011324 } else {
11325 /* in SF read MACs from port configuration */
11326 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11327 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11328 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11329
Merav Sicron55c11942012-11-07 00:45:48 +000011330 if (CNIC_SUPPORT(bp))
11331 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011332 }
11333
Yuval Mintz3d7d5622013-10-09 16:06:28 +020011334 if (!BP_NOMCP(bp)) {
11335 /* Read physical port identifier from shmem */
11336 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11337 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11338 bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
11339 bp->flags |= HAS_PHYS_PORT_ID;
11340 }
11341
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011342 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +000011343
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011344 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011345 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011346 "bad Ethernet MAC address configuration: %pM\n"
11347 "change it manually before bringing up the appropriate network interface\n",
Joe Perches0f9dad12011-08-14 12:16:19 +000011348 bp->dev->dev_addr);
Yuval Mintz79642112012-12-02 04:05:50 +000011349}
Merav Sicron51c1a582012-03-18 10:33:38 +000011350
Bill Pemberton0329aba2012-12-03 09:24:24 -050011351static bool bnx2x_get_dropless_info(struct bnx2x *bp)
Yuval Mintz79642112012-12-02 04:05:50 +000011352{
11353 int tmp;
11354 u32 cfg;
Merav Sicron51c1a582012-03-18 10:33:38 +000011355
Yuval Mintzaeeddb82013-08-19 09:11:59 +030011356 if (IS_VF(bp))
11357 return 0;
11358
Yuval Mintz79642112012-12-02 04:05:50 +000011359 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11360 /* Take function: tmp = func */
11361 tmp = BP_ABS_FUNC(bp);
11362 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11363 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11364 } else {
11365 /* Take port: tmp = port */
11366 tmp = BP_PORT(bp);
11367 cfg = SHMEM_RD(bp,
11368 dev_info.port_hw_config[tmp].generic_features);
11369 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11370 }
11371 return cfg;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011372}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011373
Bill Pemberton0329aba2012-12-03 09:24:24 -050011374static int bnx2x_get_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011375{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011376 int /*abs*/func = BP_ABS_FUNC(bp);
David S. Millerb8ee8322011-04-17 16:56:12 -070011377 int vn;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011378 u32 val = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011379 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011380
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011381 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011382
Ariel Elior6383c0b2011-07-14 08:31:57 +000011383 /*
11384 * initialize IGU parameters
11385 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011386 if (CHIP_IS_E1x(bp)) {
11387 bp->common.int_block = INT_BLOCK_HC;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011388
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011389 bp->igu_dsb_id = DEF_SB_IGU_ID;
11390 bp->igu_base_sb = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011391 } else {
11392 bp->common.int_block = INT_BLOCK_IGU;
David S. Miller8decf862011-09-22 03:23:13 -040011393
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011394 /* do not allow device reset during IGU info processing */
David S. Miller8decf862011-09-22 03:23:13 -040011395 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11396
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011397 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011398
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011399 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011400 int tout = 5000;
11401
11402 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11403
11404 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11405 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11406 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11407
11408 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11409 tout--;
Yuval Mintz0926d492013-01-23 03:21:45 +000011410 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011411 }
11412
11413 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11414 dev_err(&bp->pdev->dev,
11415 "FORCING Normal Mode failed!!!\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011416 bnx2x_release_hw_lock(bp,
11417 HW_LOCK_RESOURCE_RESET);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011418 return -EPERM;
11419 }
11420 }
11421
11422 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11423 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011424 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11425 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011426 BNX2X_DEV_INFO("IGU Normal Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011427
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011428 rc = bnx2x_get_igu_cam_info(bp);
David S. Miller8decf862011-09-22 03:23:13 -040011429 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011430 if (rc)
11431 return rc;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011432 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011433
11434 /*
11435 * set base FW non-default (fast path) status block id, this value is
11436 * used to initialize the fw_sb_id saved on the fp/queue structure to
11437 * determine the id used by the FW.
11438 */
11439 if (CHIP_IS_E1x(bp))
11440 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11441 else /*
11442 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11443 * the same queue are indicated on the same IGU SB). So we prefer
11444 * FW and IGU SBs to be the same value.
11445 */
11446 bp->base_fw_ndsb = bp->igu_base_sb;
11447
11448 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11449 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11450 bp->igu_sb_cnt, bp->base_fw_ndsb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011451
11452 /*
11453 * Initialize MF configuration
11454 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011455
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011456 bp->mf_ov = 0;
11457 bp->mf_mode = 0;
David S. Miller8decf862011-09-22 03:23:13 -040011458 vn = BP_VN(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011459
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011460 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011461 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11462 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11463 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11464
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011465 if (SHMEM2_HAS(bp, mf_cfg_addr))
11466 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11467 else
11468 bp->common.mf_cfg_base = bp->common.shmem_base +
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011469 offsetof(struct shmem_region, func_mb) +
11470 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011471 /*
11472 * get mf configuration:
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011473 * 1. Existence of MF configuration
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011474 * 2. MAC address must be legal (check only upper bytes)
11475 * for Switch-Independent mode;
11476 * OVLAN must be legal for Switch-Dependent mode
11477 * 3. SF_MODE configures specific MF mode
11478 */
11479 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11480 /* get mf configuration */
11481 val = SHMEM_RD(bp,
11482 dev_info.shared_feature_config.config);
11483 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011484
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011485 switch (val) {
11486 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11487 val = MF_CFG_RD(bp, func_mf_config[func].
11488 mac_upper);
11489 /* check for legal mac (upper bytes)*/
11490 if (val != 0xffff) {
11491 bp->mf_mode = MULTI_FUNCTION_SI;
11492 bp->mf_config[vn] = MF_CFG_RD(bp,
11493 func_mf_config[func].config);
11494 } else
Merav Sicron51c1a582012-03-18 10:33:38 +000011495 BNX2X_DEV_INFO("illegal MAC address for SI\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011496 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011497 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11498 if ((!CHIP_IS_E1x(bp)) &&
11499 (MF_CFG_RD(bp, func_mf_config[func].
11500 mac_upper) != 0xffff) &&
11501 (SHMEM2_HAS(bp,
11502 afex_driver_support))) {
11503 bp->mf_mode = MULTI_FUNCTION_AFEX;
11504 bp->mf_config[vn] = MF_CFG_RD(bp,
11505 func_mf_config[func].config);
11506 } else {
11507 BNX2X_DEV_INFO("can not configure afex mode\n");
11508 }
11509 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011510 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11511 /* get OV configuration */
11512 val = MF_CFG_RD(bp,
11513 func_mf_config[FUNC_0].e1hov_tag);
11514 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11515
11516 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11517 bp->mf_mode = MULTI_FUNCTION_SD;
11518 bp->mf_config[vn] = MF_CFG_RD(bp,
11519 func_mf_config[func].config);
11520 } else
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000011521 BNX2X_DEV_INFO("illegal OV for SD\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011522 break;
Ariel Elior3786b942013-03-11 05:17:44 +000011523 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11524 bp->mf_config[vn] = 0;
11525 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011526 default:
11527 /* Unknown configuration: reset mf_config */
11528 bp->mf_config[vn] = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +000011529 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011530 }
11531 }
11532
Eilon Greenstein2691d512009-08-12 08:22:08 +000011533 BNX2X_DEV_INFO("%s function mode\n",
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011534 IS_MF(bp) ? "multi" : "single");
Eilon Greenstein2691d512009-08-12 08:22:08 +000011535
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011536 switch (bp->mf_mode) {
11537 case MULTI_FUNCTION_SD:
11538 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11539 FUNC_MF_CFG_E1HOV_TAG_MASK;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011540 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011541 bp->mf_ov = val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011542 bp->path_has_ovlan = true;
11543
Merav Sicron51c1a582012-03-18 10:33:38 +000011544 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11545 func, bp->mf_ov, bp->mf_ov);
Eilon Greenstein2691d512009-08-12 08:22:08 +000011546 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011547 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011548 "No valid MF OV for func %d, aborting\n",
11549 func);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011550 return -EPERM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011551 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011552 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011553 case MULTI_FUNCTION_AFEX:
11554 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11555 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011556 case MULTI_FUNCTION_SI:
Merav Sicron51c1a582012-03-18 10:33:38 +000011557 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11558 func);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011559 break;
11560 default:
11561 if (vn) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011562 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011563 "VN %d is in a single function mode, aborting\n",
11564 vn);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011565 return -EPERM;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011566 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011567 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011568 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011569
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011570 /* check if other port on the path needs ovlan:
11571 * Since MF configuration is shared between ports
11572 * Possible mixed modes are only
11573 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11574 */
11575 if (CHIP_MODE_IS_4_PORT(bp) &&
11576 !bp->path_has_ovlan &&
11577 !IS_MF(bp) &&
11578 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11579 u8 other_port = !BP_PORT(bp);
11580 u8 other_func = BP_PATH(bp) + 2*other_port;
11581 val = MF_CFG_RD(bp,
11582 func_mf_config[other_func].e1hov_tag);
11583 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11584 bp->path_has_ovlan = true;
11585 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011586 }
11587
Dmitry Kravkove8485822014-01-05 18:33:50 +020011588 /* adjust igu_sb_cnt to MF for E1H */
11589 if (CHIP_IS_E1H(bp) && IS_MF(bp))
11590 bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011591
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011592 /* port info */
11593 bnx2x_get_port_hwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011594
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011595 /* Get MAC addresses */
11596 bnx2x_get_mac_hwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011597
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011598 bnx2x_get_cnic_info(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011599
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011600 return rc;
11601}
11602
Bill Pemberton0329aba2012-12-03 09:24:24 -050011603static void bnx2x_read_fwinfo(struct bnx2x *bp)
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011604{
11605 int cnt, i, block_end, rodi;
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011606 char vpd_start[BNX2X_VPD_LEN+1];
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011607 char str_id_reg[VENDOR_ID_LEN+1];
11608 char str_id_cap[VENDOR_ID_LEN+1];
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011609 char *vpd_data;
11610 char *vpd_extended_data = NULL;
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011611 u8 len;
11612
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011613 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011614 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11615
11616 if (cnt < BNX2X_VPD_LEN)
11617 goto out_not_found;
11618
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011619 /* VPD RO tag should be first tag after identifier string, hence
11620 * we should be able to find it in first BNX2X_VPD_LEN chars
11621 */
11622 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011623 PCI_VPD_LRDT_RO_DATA);
11624 if (i < 0)
11625 goto out_not_found;
11626
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011627 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011628 pci_vpd_lrdt_size(&vpd_start[i]);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011629
11630 i += PCI_VPD_LRDT_TAG_SIZE;
11631
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011632 if (block_end > BNX2X_VPD_LEN) {
11633 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11634 if (vpd_extended_data == NULL)
11635 goto out_not_found;
11636
11637 /* read rest of vpd image into vpd_extended_data */
11638 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11639 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11640 block_end - BNX2X_VPD_LEN,
11641 vpd_extended_data + BNX2X_VPD_LEN);
11642 if (cnt < (block_end - BNX2X_VPD_LEN))
11643 goto out_not_found;
11644 vpd_data = vpd_extended_data;
11645 } else
11646 vpd_data = vpd_start;
11647
11648 /* now vpd_data holds full vpd content in both cases */
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011649
11650 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11651 PCI_VPD_RO_KEYWORD_MFR_ID);
11652 if (rodi < 0)
11653 goto out_not_found;
11654
11655 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11656
11657 if (len != VENDOR_ID_LEN)
11658 goto out_not_found;
11659
11660 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11661
11662 /* vendor specific info */
11663 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11664 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11665 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11666 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11667
11668 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11669 PCI_VPD_RO_KEYWORD_VENDOR0);
11670 if (rodi >= 0) {
11671 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11672
11673 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11674
11675 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11676 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11677 bp->fw_ver[len] = ' ';
11678 }
11679 }
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011680 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011681 return;
11682 }
11683out_not_found:
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011684 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011685 return;
11686}
11687
Bill Pemberton0329aba2012-12-03 09:24:24 -050011688static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011689{
11690 u32 flags = 0;
11691
11692 if (CHIP_REV_IS_FPGA(bp))
11693 SET_FLAGS(flags, MODE_FPGA);
11694 else if (CHIP_REV_IS_EMUL(bp))
11695 SET_FLAGS(flags, MODE_EMUL);
11696 else
11697 SET_FLAGS(flags, MODE_ASIC);
11698
11699 if (CHIP_MODE_IS_4_PORT(bp))
11700 SET_FLAGS(flags, MODE_PORT4);
11701 else
11702 SET_FLAGS(flags, MODE_PORT2);
11703
11704 if (CHIP_IS_E2(bp))
11705 SET_FLAGS(flags, MODE_E2);
11706 else if (CHIP_IS_E3(bp)) {
11707 SET_FLAGS(flags, MODE_E3);
11708 if (CHIP_REV(bp) == CHIP_REV_Ax)
11709 SET_FLAGS(flags, MODE_E3_A0);
Ariel Elior6383c0b2011-07-14 08:31:57 +000011710 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11711 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011712 }
11713
11714 if (IS_MF(bp)) {
11715 SET_FLAGS(flags, MODE_MF);
11716 switch (bp->mf_mode) {
11717 case MULTI_FUNCTION_SD:
11718 SET_FLAGS(flags, MODE_MF_SD);
11719 break;
11720 case MULTI_FUNCTION_SI:
11721 SET_FLAGS(flags, MODE_MF_SI);
11722 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011723 case MULTI_FUNCTION_AFEX:
11724 SET_FLAGS(flags, MODE_MF_AFEX);
11725 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011726 }
11727 } else
11728 SET_FLAGS(flags, MODE_SF);
11729
11730#if defined(__LITTLE_ENDIAN)
11731 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11732#else /*(__BIG_ENDIAN)*/
11733 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11734#endif
11735 INIT_MODE_FLAGS(bp) = flags;
11736}
11737
Bill Pemberton0329aba2012-12-03 09:24:24 -050011738static int bnx2x_init_bp(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011739{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011740 int func;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011741 int rc;
11742
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011743 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -070011744 mutex_init(&bp->fw_mb_mutex);
David S. Millerbb7e95c2010-07-27 21:01:35 -070011745 spin_lock_init(&bp->stats_lock);
Dmitry Kravkov507393e2013-08-13 02:24:59 +030011746 sema_init(&bp->stats_sema, 1);
Merav Sicron55c11942012-11-07 00:45:48 +000011747
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011748 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Ariel Elior7be08a72011-07-14 08:31:19 +000011749 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000011750 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
Ariel Elior1ab44342013-01-01 05:22:23 +000011751 if (IS_PF(bp)) {
11752 rc = bnx2x_get_hwinfo(bp);
11753 if (rc)
11754 return rc;
11755 } else {
Ariel Eliore09b74d2013-05-27 04:08:26 +000011756 eth_zero_addr(bp->dev->dev_addr);
Ariel Elior1ab44342013-01-01 05:22:23 +000011757 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011758
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011759 bnx2x_set_modes_bitmap(bp);
11760
11761 rc = bnx2x_alloc_mem_bp(bp);
11762 if (rc)
11763 return rc;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011764
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011765 bnx2x_read_fwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011766
11767 func = BP_FUNC(bp);
11768
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011769 /* need to reset chip if undi was active */
Ariel Elior1ab44342013-01-01 05:22:23 +000011770 if (IS_PF(bp) && !BP_NOMCP(bp)) {
Yuval Mintz452427b2012-03-26 20:47:07 +000011771 /* init fw_seq */
11772 bp->fw_seq =
11773 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11774 DRV_MSG_SEQ_NUMBER_MASK;
11775 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11776
Yuval Mintz91ebb922013-12-26 09:57:07 +020011777 rc = bnx2x_prev_unload(bp);
11778 if (rc) {
11779 bnx2x_free_mem_bp(bp);
11780 return rc;
11781 }
Yuval Mintz452427b2012-03-26 20:47:07 +000011782 }
11783
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011784 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000011785 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011786
11787 if (BP_NOMCP(bp) && (func == 0))
Merav Sicron51c1a582012-03-18 10:33:38 +000011788 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011789
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011790 bp->disable_tpa = disable_tpa;
Barak Witkowskia3348722012-04-23 03:04:46 +000011791 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011792
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011793 /* Set TPA flags */
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011794 if (bp->disable_tpa) {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011795 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011796 bp->dev->features &= ~NETIF_F_LRO;
11797 } else {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011798 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011799 bp->dev->features |= NETIF_F_LRO;
11800 }
11801
Eilon Greensteina18f5122009-08-12 08:23:26 +000011802 if (CHIP_IS_E1(bp))
11803 bp->dropless_fc = 0;
11804 else
Yuval Mintz79642112012-12-02 04:05:50 +000011805 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
Eilon Greensteina18f5122009-08-12 08:23:26 +000011806
Eilon Greenstein8d5726c2009-02-12 08:37:19 +000011807 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011808
Barak Witkowskia3348722012-04-23 03:04:46 +000011809 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
Ariel Elior1ab44342013-01-01 05:22:23 +000011810 if (IS_VF(bp))
11811 bp->rx_ring_size = MAX_RX_AVAIL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011812
Eilon Greenstein7d323bf2009-11-09 06:09:35 +000011813 /* make sure that the numbers are in the right granularity */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011814 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11815 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011816
Michal Schmidtfc543632012-02-14 09:05:46 +000011817 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011818
11819 init_timer(&bp->timer);
11820 bp->timer.expires = jiffies + bp->current_interval;
11821 bp->timer.data = (unsigned long) bp;
11822 bp->timer.function = bnx2x_timer;
11823
Barak Witkowski0370cf92012-12-02 04:05:55 +000011824 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11825 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11826 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11827 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11828 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11829 bnx2x_dcbx_init_params(bp);
11830 } else {
11831 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11832 }
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000011833
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011834 if (CHIP_IS_E1x(bp))
11835 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11836 else
11837 bp->cnic_base_cl_id = FP_SB_MAX_E2;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011838
Ariel Elior6383c0b2011-07-14 08:31:57 +000011839 /* multiple tx priority */
Ariel Elior1ab44342013-01-01 05:22:23 +000011840 if (IS_VF(bp))
11841 bp->max_cos = 1;
11842 else if (CHIP_IS_E1x(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011843 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
Ariel Elior1ab44342013-01-01 05:22:23 +000011844 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011845 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
Ariel Elior1ab44342013-01-01 05:22:23 +000011846 else if (CHIP_IS_E3B0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000011847 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
Ariel Elior1ab44342013-01-01 05:22:23 +000011848 else
11849 BNX2X_ERR("unknown chip %x revision %x\n",
11850 CHIP_NUM(bp), CHIP_REV(bp));
11851 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
Ariel Elior6383c0b2011-07-14 08:31:57 +000011852
Merav Sicron55c11942012-11-07 00:45:48 +000011853 /* We need at least one default status block for slow-path events,
11854 * second status block for the L2 queue, and a third status block for
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011855 * CNIC if supported.
Merav Sicron55c11942012-11-07 00:45:48 +000011856 */
Ariel Elior60cad4e2013-09-04 14:09:22 +030011857 if (IS_VF(bp))
11858 bp->min_msix_vec_cnt = 1;
11859 else if (CNIC_SUPPORT(bp))
Merav Sicron55c11942012-11-07 00:45:48 +000011860 bp->min_msix_vec_cnt = 3;
Ariel Elior60cad4e2013-09-04 14:09:22 +030011861 else /* PF w/o cnic */
Merav Sicron55c11942012-11-07 00:45:48 +000011862 bp->min_msix_vec_cnt = 2;
11863 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
11864
Michal Schmidt5bb680d2013-07-01 17:23:06 +020011865 bp->dump_preset_idx = 1;
11866
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011867 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011868}
11869
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000011870/****************************************************************************
11871* General service functions
11872****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011873
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011874/*
11875 * net_device service functions
11876 */
11877
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011878/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011879static int bnx2x_open(struct net_device *dev)
11880{
11881 struct bnx2x *bp = netdev_priv(dev);
Ariel Elior8395be52013-01-01 05:22:44 +000011882 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011883
Mintz Yuval1355b702012-02-15 02:10:22 +000011884 bp->stats_init = true;
11885
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000011886 netif_carrier_off(dev);
11887
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011888 bnx2x_set_power_state(bp, PCI_D0);
11889
Ariel Eliorad5afc82013-01-01 05:22:26 +000011890 /* If parity had happen during the unload, then attentions
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011891 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
11892 * want the first function loaded on the current engine to
11893 * complete the recovery.
Ariel Eliorad5afc82013-01-01 05:22:26 +000011894 * Parity recovery is only relevant for PF driver.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011895 */
Ariel Eliorad5afc82013-01-01 05:22:26 +000011896 if (IS_PF(bp)) {
Yuval Mintz1a6974b2013-10-20 16:51:27 +020011897 int other_engine = BP_PATH(bp) ? 0 : 1;
11898 bool other_load_status, load_status;
11899 bool global = false;
11900
Ariel Eliorad5afc82013-01-01 05:22:26 +000011901 other_load_status = bnx2x_get_load_status(bp, other_engine);
11902 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11903 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
11904 bnx2x_chk_parity_attn(bp, &global, true)) {
11905 do {
11906 /* If there are attentions and they are in a
11907 * global blocks, set the GLOBAL_RESET bit
11908 * regardless whether it will be this function
11909 * that will complete the recovery or not.
11910 */
11911 if (global)
11912 bnx2x_set_reset_global(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011913
Ariel Eliorad5afc82013-01-01 05:22:26 +000011914 /* Only the first function on the current
11915 * engine should try to recover in open. In case
11916 * of attentions in global blocks only the first
11917 * in the chip should try to recover.
11918 */
11919 if ((!load_status &&
11920 (!global || !other_load_status)) &&
11921 bnx2x_trylock_leader_lock(bp) &&
11922 !bnx2x_leader_reset(bp)) {
11923 netdev_info(bp->dev,
11924 "Recovered in open\n");
11925 break;
11926 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011927
Ariel Eliorad5afc82013-01-01 05:22:26 +000011928 /* recovery has failed... */
11929 bnx2x_set_power_state(bp, PCI_D3hot);
11930 bp->recovery_state = BNX2X_RECOVERY_FAILED;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011931
Ariel Eliorad5afc82013-01-01 05:22:26 +000011932 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
11933 "If you still see this message after a few retries then power cycle is required.\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011934
Ariel Eliorad5afc82013-01-01 05:22:26 +000011935 return -EAGAIN;
11936 } while (0);
11937 }
11938 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000011939
11940 bp->recovery_state = BNX2X_RECOVERY_DONE;
Ariel Elior8395be52013-01-01 05:22:44 +000011941 rc = bnx2x_nic_load(bp, LOAD_OPEN);
11942 if (rc)
11943 return rc;
Ariel Elior9a8130b2013-09-28 08:46:09 +030011944 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011945}
11946
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070011947/* called with rtnl_lock */
Michal Schmidt56ad3152012-02-16 02:38:48 +000011948static int bnx2x_close(struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011949{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011950 struct bnx2x *bp = netdev_priv(dev);
11951
11952 /* Unload the driver, release IRQs */
Yuval Mintz5d07d862012-09-13 02:56:21 +000011953 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000011954
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011955 return 0;
11956}
11957
Eric Dumazet1191cb82012-04-27 21:39:21 +000011958static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
11959 struct bnx2x_mcast_ramrod_params *p)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011960{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011961 int mc_count = netdev_mc_count(bp->dev);
11962 struct bnx2x_mcast_list_elem *mc_mac =
11963 kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011964 struct netdev_hw_addr *ha;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080011965
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011966 if (!mc_mac)
11967 return -ENOMEM;
11968
11969 INIT_LIST_HEAD(&p->mcast_list);
11970
11971 netdev_for_each_mc_addr(ha, bp->dev) {
11972 mc_mac->mac = bnx2x_mc_addr(ha);
11973 list_add_tail(&mc_mac->link, &p->mcast_list);
11974 mc_mac++;
11975 }
11976
11977 p->mcast_list_len = mc_count;
11978
11979 return 0;
11980}
11981
Eric Dumazet1191cb82012-04-27 21:39:21 +000011982static void bnx2x_free_mcast_macs_list(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011983 struct bnx2x_mcast_ramrod_params *p)
11984{
11985 struct bnx2x_mcast_list_elem *mc_mac =
11986 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
11987 link);
11988
11989 WARN_ON(!mc_mac);
11990 kfree(mc_mac);
11991}
11992
11993/**
11994 * bnx2x_set_uc_list - configure a new unicast MACs list.
11995 *
11996 * @bp: driver handle
11997 *
11998 * We will use zero (0) as a MAC type for these MACs.
11999 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012000static int bnx2x_set_uc_list(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012001{
12002 int rc;
12003 struct net_device *dev = bp->dev;
12004 struct netdev_hw_addr *ha;
Barak Witkowski15192a82012-06-19 07:48:28 +000012005 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012006 unsigned long ramrod_flags = 0;
12007
12008 /* First schedule a cleanup up of old configuration */
12009 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
12010 if (rc < 0) {
12011 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
12012 return rc;
12013 }
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012014
12015 netdev_for_each_uc_addr(ha, dev) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012016 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
12017 BNX2X_UC_LIST_MAC, &ramrod_flags);
Yuval Mintz7b5342d2012-09-11 04:34:14 +000012018 if (rc == -EEXIST) {
12019 DP(BNX2X_MSG_SP,
12020 "Failed to schedule ADD operations: %d\n", rc);
12021 /* do not treat adding same MAC as error */
12022 rc = 0;
12023
12024 } else if (rc < 0) {
12025
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012026 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
12027 rc);
12028 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012029 }
12030 }
12031
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012032 /* Execute the pending commands */
12033 __set_bit(RAMROD_CONT, &ramrod_flags);
12034 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
12035 BNX2X_UC_LIST_MAC, &ramrod_flags);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012036}
12037
Eric Dumazet1191cb82012-04-27 21:39:21 +000012038static int bnx2x_set_mc_list(struct bnx2x *bp)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012039{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012040 struct net_device *dev = bp->dev;
Yuval Mintz3b603062012-03-18 10:33:39 +000012041 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012042 int rc = 0;
12043
12044 rparam.mcast_obj = &bp->mcast_obj;
12045
12046 /* first, clear all configured multicast MACs */
12047 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
12048 if (rc < 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012049 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012050 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012051 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012052
12053 /* then, configure a new MACs list */
12054 if (netdev_mc_count(dev)) {
12055 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
12056 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012057 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
12058 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012059 return rc;
12060 }
12061
12062 /* Now add the new MACs */
12063 rc = bnx2x_config_mcast(bp, &rparam,
12064 BNX2X_MCAST_CMD_ADD);
12065 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +000012066 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
12067 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012068
12069 bnx2x_free_mcast_macs_list(&rparam);
12070 }
12071
12072 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012073}
12074
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012075/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -080012076static void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012077{
12078 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012079
12080 if (bp->state != BNX2X_STATE_OPEN) {
12081 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
12082 return;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012083 } else {
12084 /* Schedule an SP task to handle rest of change */
12085 DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
12086 smp_mb__before_clear_bit();
12087 set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
12088 smp_mb__after_clear_bit();
12089 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012090 }
Yuval Mintz8b09be52013-08-01 17:30:59 +030012091}
12092
12093void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
12094{
12095 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012096
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012097 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012098
Yuval Mintz8b09be52013-08-01 17:30:59 +030012099 netif_addr_lock_bh(bp->dev);
12100
12101 if (bp->dev->flags & IFF_PROMISC) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012102 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012103 } else if ((bp->dev->flags & IFF_ALLMULTI) ||
12104 ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
12105 CHIP_IS_E1(bp))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012106 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012107 } else {
Ariel Elior381ac162013-01-01 05:22:29 +000012108 if (IS_PF(bp)) {
12109 /* some multicasts */
12110 if (bnx2x_set_mc_list(bp) < 0)
12111 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012112
Yuval Mintz8b09be52013-08-01 17:30:59 +030012113 /* release bh lock, as bnx2x_set_uc_list might sleep */
12114 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012115 if (bnx2x_set_uc_list(bp) < 0)
12116 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012117 netif_addr_lock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012118 } else {
12119 /* configuring mcast to a vf involves sleeping (when we
Yuval Mintz8b09be52013-08-01 17:30:59 +030012120 * wait for the pf's response).
Ariel Elior381ac162013-01-01 05:22:29 +000012121 */
12122 smp_mb__before_clear_bit();
12123 set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
12124 &bp->sp_rtnl_state);
12125 smp_mb__after_clear_bit();
12126 schedule_delayed_work(&bp->sp_rtnl_task, 0);
12127 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012128 }
12129
12130 bp->rx_mode = rx_mode;
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012131 /* handle ISCSI SD mode */
12132 if (IS_MF_ISCSI_SD(bp))
12133 bp->rx_mode = BNX2X_RX_MODE_NONE;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012134
12135 /* Schedule the rx_mode command */
12136 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
12137 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
Yuval Mintz8b09be52013-08-01 17:30:59 +030012138 netif_addr_unlock_bh(bp->dev);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012139 return;
12140 }
12141
Ariel Elior381ac162013-01-01 05:22:29 +000012142 if (IS_PF(bp)) {
12143 bnx2x_set_storm_rx_mode(bp);
Yuval Mintz8b09be52013-08-01 17:30:59 +030012144 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012145 } else {
Yuval Mintz8b09be52013-08-01 17:30:59 +030012146 /* VF will need to request the PF to make this change, and so
12147 * the VF needs to release the bottom-half lock prior to the
12148 * request (as it will likely require sleep on the VF side)
Ariel Elior381ac162013-01-01 05:22:29 +000012149 */
Yuval Mintz8b09be52013-08-01 17:30:59 +030012150 netif_addr_unlock_bh(bp->dev);
12151 bnx2x_vfpf_storm_rx_mode(bp);
Ariel Elior381ac162013-01-01 05:22:29 +000012152 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012153}
12154
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070012155/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012156static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
12157 int devad, u16 addr)
12158{
12159 struct bnx2x *bp = netdev_priv(netdev);
12160 u16 value;
12161 int rc;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012162
12163 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
12164 prtad, devad, addr);
12165
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012166 /* The HW expects different devad if CL22 is used */
12167 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12168
12169 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012170 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012171 bnx2x_release_phy_lock(bp);
12172 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
12173
12174 if (!rc)
12175 rc = value;
12176 return rc;
12177}
12178
12179/* called with rtnl_lock */
12180static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
12181 u16 addr, u16 value)
12182{
12183 struct bnx2x *bp = netdev_priv(netdev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012184 int rc;
12185
Merav Sicron51c1a582012-03-18 10:33:38 +000012186 DP(NETIF_MSG_LINK,
12187 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
12188 prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012189
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012190 /* The HW expects different devad if CL22 is used */
12191 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12192
12193 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012194 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012195 bnx2x_release_phy_lock(bp);
12196 return rc;
12197}
12198
12199/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012200static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
12201{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012202 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012203 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012204
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012205 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
12206 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012207
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012208 if (!netif_running(dev))
12209 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070012210
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012211 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012212}
12213
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000012214#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012215static void poll_bnx2x(struct net_device *dev)
12216{
12217 struct bnx2x *bp = netdev_priv(dev);
Merav Sicron14a15d62012-08-27 03:26:20 +000012218 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012219
Merav Sicron14a15d62012-08-27 03:26:20 +000012220 for_each_eth_queue(bp, i) {
12221 struct bnx2x_fastpath *fp = &bp->fp[i];
12222 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
12223 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012224}
12225#endif
12226
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012227static int bnx2x_validate_addr(struct net_device *dev)
12228{
12229 struct bnx2x *bp = netdev_priv(dev);
12230
Ariel Eliore09b74d2013-05-27 04:08:26 +000012231 /* query the bulletin board for mac address configured by the PF */
12232 if (IS_VF(bp))
12233 bnx2x_sample_bulletin(bp);
12234
Merav Sicron51c1a582012-03-18 10:33:38 +000012235 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
12236 BNX2X_ERR("Non-valid Ethernet address\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012237 return -EADDRNOTAVAIL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012238 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012239 return 0;
12240}
12241
Yuval Mintz3d7d5622013-10-09 16:06:28 +020012242static int bnx2x_get_phys_port_id(struct net_device *netdev,
12243 struct netdev_phys_port_id *ppid)
12244{
12245 struct bnx2x *bp = netdev_priv(netdev);
12246
12247 if (!(bp->flags & HAS_PHYS_PORT_ID))
12248 return -EOPNOTSUPP;
12249
12250 ppid->id_len = sizeof(bp->phys_port_id);
12251 memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
12252
12253 return 0;
12254}
12255
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012256static const struct net_device_ops bnx2x_netdev_ops = {
12257 .ndo_open = bnx2x_open,
12258 .ndo_stop = bnx2x_close,
12259 .ndo_start_xmit = bnx2x_start_xmit,
Vladislav Zolotarov8307fa32010-12-13 05:44:09 +000012260 .ndo_select_queue = bnx2x_select_queue,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012261 .ndo_set_rx_mode = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012262 .ndo_set_mac_address = bnx2x_change_mac_addr,
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012263 .ndo_validate_addr = bnx2x_validate_addr,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012264 .ndo_do_ioctl = bnx2x_ioctl,
12265 .ndo_change_mtu = bnx2x_change_mtu,
Michał Mirosław66371c42011-04-12 09:38:23 +000012266 .ndo_fix_features = bnx2x_fix_features,
12267 .ndo_set_features = bnx2x_set_features,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012268 .ndo_tx_timeout = bnx2x_tx_timeout,
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000012269#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012270 .ndo_poll_controller = poll_bnx2x,
12271#endif
Ariel Elior6383c0b2011-07-14 08:31:57 +000012272 .ndo_setup_tc = bnx2x_setup_tc,
Ariel Elior64112802013-01-07 00:50:23 +000012273#ifdef CONFIG_BNX2X_SRIOV
Ariel Eliorabc5a022013-01-01 05:22:43 +000012274 .ndo_set_vf_mac = bnx2x_set_vf_mac,
Yuval Mintz3cdeec22013-06-02 00:06:19 +000012275 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
Ariel Elior3ec9f9c2013-03-11 05:17:45 +000012276 .ndo_get_vf_config = bnx2x_get_vf_config,
Ariel Elior64112802013-01-07 00:50:23 +000012277#endif
Merav Sicron55c11942012-11-07 00:45:48 +000012278#ifdef NETDEV_FCOE_WWNN
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000012279 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
12280#endif
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012281
Cong Wange0d10952013-08-01 11:10:25 +080012282#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +030012283 .ndo_busy_poll = bnx2x_low_latency_recv,
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012284#endif
Yuval Mintz3d7d5622013-10-09 16:06:28 +020012285 .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012286};
12287
Eric Dumazet1191cb82012-04-27 21:39:21 +000012288static int bnx2x_set_coherency_mask(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012289{
12290 struct device *dev = &bp->pdev->dev;
12291
Linus Torvalds8ceafbf2013-11-14 07:55:21 +090012292 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
12293 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012294 dev_err(dev, "System does not support DMA, aborting\n");
12295 return -EIO;
12296 }
12297
12298 return 0;
12299}
12300
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020012301static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
12302{
12303 if (bp->flags & AER_ENABLED) {
12304 pci_disable_pcie_error_reporting(bp->pdev);
12305 bp->flags &= ~AER_ENABLED;
12306 }
12307}
12308
Ariel Elior1ab44342013-01-01 05:22:23 +000012309static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12310 struct net_device *dev, unsigned long board_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012311{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012312 int rc;
Ariel Eliorc22610d02012-01-26 06:01:47 +000012313 u32 pci_cfg_dword;
Ariel Elior65087cf2012-01-23 07:31:55 +000012314 bool chip_is_e1x = (board_type == BCM57710 ||
12315 board_type == BCM57711 ||
12316 board_type == BCM57711E);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012317
12318 SET_NETDEV_DEV(dev, &pdev->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012319
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012320 bp->dev = dev;
12321 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012322
12323 rc = pci_enable_device(pdev);
12324 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012325 dev_err(&bp->pdev->dev,
12326 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012327 goto err_out;
12328 }
12329
12330 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012331 dev_err(&bp->pdev->dev,
12332 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012333 rc = -ENODEV;
12334 goto err_out_disable;
12335 }
12336
Ariel Elior1ab44342013-01-01 05:22:23 +000012337 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
12338 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012339 rc = -ENODEV;
12340 goto err_out_disable;
12341 }
12342
Yaniv Rosner092a5fc2012-12-02 23:56:49 +000012343 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
12344 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
12345 PCICFG_REVESION_ID_ERROR_VAL) {
12346 pr_err("PCI device error, probably due to fan failure, aborting\n");
12347 rc = -ENODEV;
12348 goto err_out_disable;
12349 }
12350
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012351 if (atomic_read(&pdev->enable_cnt) == 1) {
12352 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
12353 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012354 dev_err(&bp->pdev->dev,
12355 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012356 goto err_out_disable;
12357 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012358
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012359 pci_set_master(pdev);
12360 pci_save_state(pdev);
12361 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012362
Ariel Elior1ab44342013-01-01 05:22:23 +000012363 if (IS_PF(bp)) {
Jon Mason29ed74c2013-09-11 11:22:39 -070012364 if (!pdev->pm_cap) {
Ariel Elior1ab44342013-01-01 05:22:23 +000012365 dev_err(&bp->pdev->dev,
12366 "Cannot find power management capability, aborting\n");
12367 rc = -EIO;
12368 goto err_out_release;
12369 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012370 }
12371
Jon Mason77c98e62011-06-27 07:45:12 +000012372 if (!pci_is_pcie(pdev)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012373 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012374 rc = -EIO;
12375 goto err_out_release;
12376 }
12377
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012378 rc = bnx2x_set_coherency_mask(bp);
12379 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012380 goto err_out_release;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012381
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012382 dev->mem_start = pci_resource_start(pdev, 0);
12383 dev->base_addr = dev->mem_start;
12384 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012385
12386 dev->irq = pdev->irq;
12387
Arjan van de Ven275f1652008-10-20 21:42:39 -070012388 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012389 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012390 dev_err(&bp->pdev->dev,
12391 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012392 rc = -ENOMEM;
12393 goto err_out_release;
12394 }
12395
Ariel Eliorc22610d02012-01-26 06:01:47 +000012396 /* In E1/E1H use pci device function given by kernel.
12397 * In E2/E3 read physical function from ME register since these chips
12398 * support Physical Device Assignment where kernel BDF maybe arbitrary
12399 * (depending on hypervisor).
12400 */
Yuval Mintz2de67432013-01-23 03:21:43 +000012401 if (chip_is_e1x) {
Ariel Eliorc22610d02012-01-26 06:01:47 +000012402 bp->pf_num = PCI_FUNC(pdev->devfn);
Yuval Mintz2de67432013-01-23 03:21:43 +000012403 } else {
12404 /* chip is E2/3*/
Ariel Eliorc22610d02012-01-26 06:01:47 +000012405 pci_read_config_dword(bp->pdev,
12406 PCICFG_ME_REGISTER, &pci_cfg_dword);
12407 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
Yuval Mintz2de67432013-01-23 03:21:43 +000012408 ME_REG_ABS_PF_NUM_SHIFT);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012409 }
Merav Sicron51c1a582012-03-18 10:33:38 +000012410 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012411
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012412 /* clean indirect addresses */
12413 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12414 PCICFG_VENDOR_ID_OFFSET);
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020012415
12416 /* AER (Advanced Error reporting) configuration */
12417 rc = pci_enable_pcie_error_reporting(pdev);
12418 if (!rc)
12419 bp->flags |= AER_ENABLED;
12420 else
12421 BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
12422
David S. Miller8decf862011-09-22 03:23:13 -040012423 /*
12424 * Clean the following indirect addresses for all functions since it
David S. Miller823dcd22011-08-20 10:39:12 -070012425 * is not used by the driver.
12426 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012427 if (IS_PF(bp)) {
12428 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12429 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12430 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12431 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
David S. Miller8decf862011-09-22 03:23:13 -040012432
Ariel Elior1ab44342013-01-01 05:22:23 +000012433 if (chip_is_e1x) {
12434 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12435 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12436 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12437 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12438 }
12439
12440 /* Enable internal target-read (in case we are probed after PF
12441 * FLR). Must be done prior to any BAR read access. Only for
12442 * 57712 and up
12443 */
12444 if (!chip_is_e1x)
12445 REG_WR(bp,
12446 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
David S. Miller8decf862011-09-22 03:23:13 -040012447 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012448
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012449 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012450
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012451 dev->netdev_ops = &bnx2x_netdev_ops;
Ariel Elior005a07ba2013-03-11 05:17:42 +000012452 bnx2x_set_ethtool_ops(bp, dev);
Michał Mirosław66371c42011-04-12 09:38:23 +000012453
Jiri Pirko01789342011-08-16 06:29:00 +000012454 dev->priv_flags |= IFF_UNICAST_FLT;
12455
Michał Mirosław66371c42011-04-12 09:38:23 +000012456 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000012457 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12458 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +000012459 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012460 if (!CHIP_IS_E1x(bp)) {
Eric Dumazet117401e2013-10-19 11:42:58 -070012461 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Eric Dumazet2e3bd6a2013-10-20 20:47:31 -070012462 NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012463 dev->hw_enc_features =
12464 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12465 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
Eric Dumazet117401e2013-10-19 11:42:58 -070012466 NETIF_F_GSO_IPIP |
Eric Dumazet2e3bd6a2013-10-20 20:47:31 -070012467 NETIF_F_GSO_SIT |
Dmitry Kravkov65bc0cf2013-04-28 08:16:02 +000012468 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012469 }
Michał Mirosław66371c42011-04-12 09:38:23 +000012470
12471 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12472 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12473
Patrick McHardyf6469682013-04-19 02:04:27 +000012474 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
Merav Sicronedd31472013-10-20 16:51:34 +020012475 dev->features |= NETIF_F_HIGHDMA;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012476
Mahesh Bandewar538dd2e2011-05-13 15:08:49 +000012477 /* Add Loopback capability to the device */
12478 dev->hw_features |= NETIF_F_LOOPBACK;
12479
Shmulik Ravid98507672011-02-28 12:19:55 -080012480#ifdef BCM_DCBNL
Shmulik Ravid785b9b12010-12-30 06:27:03 +000012481 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12482#endif
12483
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012484 /* get_port_hwinfo() will set prtad and mmds properly */
12485 bp->mdio.prtad = MDIO_PRTAD_NONE;
12486 bp->mdio.mmds = 0;
12487 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12488 bp->mdio.dev = dev;
12489 bp->mdio.mdio_read = bnx2x_mdio_read;
12490 bp->mdio.mdio_write = bnx2x_mdio_write;
12491
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012492 return 0;
12493
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012494err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012495 if (atomic_read(&pdev->enable_cnt) == 1)
12496 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012497
12498err_out_disable:
12499 pci_disable_device(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012500
12501err_out:
12502 return rc;
12503}
12504
Dmitry Kravkov6891dd22010-08-03 21:49:40 +000012505static int bnx2x_check_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012506{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012507 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012508 struct bnx2x_fw_file_hdr *fw_hdr;
12509 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012510 u32 offset, len, num_ops;
Yuval Mintz86564c32013-01-23 03:21:50 +000012511 __be16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012512 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012513 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012514
Merav Sicron51c1a582012-03-18 10:33:38 +000012515 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12516 BNX2X_ERR("Wrong FW size\n");
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012517 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012518 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012519
12520 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12521 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12522
12523 /* Make sure none of the offsets and sizes make us read beyond
12524 * the end of the firmware data */
12525 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12526 offset = be32_to_cpu(sections[i].offset);
12527 len = be32_to_cpu(sections[i].len);
12528 if (offset + len > firmware->size) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012529 BNX2X_ERR("Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012530 return -EINVAL;
12531 }
12532 }
12533
12534 /* Likewise for the init_ops offsets */
12535 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
Yuval Mintz86564c32013-01-23 03:21:50 +000012536 ops_offsets = (__force __be16 *)(firmware->data + offset);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012537 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12538
12539 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12540 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012541 BNX2X_ERR("Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012542 return -EINVAL;
12543 }
12544 }
12545
12546 /* Check FW version */
12547 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12548 fw_ver = firmware->data + offset;
12549 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12550 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12551 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12552 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012553 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12554 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12555 BCM_5710_FW_MAJOR_VERSION,
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012556 BCM_5710_FW_MINOR_VERSION,
12557 BCM_5710_FW_REVISION_VERSION,
12558 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012559 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012560 }
12561
12562 return 0;
12563}
12564
Eric Dumazet1191cb82012-04-27 21:39:21 +000012565static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012566{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012567 const __be32 *source = (const __be32 *)_source;
12568 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012569 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012570
12571 for (i = 0; i < n/4; i++)
12572 target[i] = be32_to_cpu(source[i]);
12573}
12574
12575/*
12576 Ops array is stored in the following format:
12577 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12578 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012579static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012580{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012581 const __be32 *source = (const __be32 *)_source;
12582 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012583 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012584
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012585 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012586 tmp = be32_to_cpu(source[j]);
12587 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012588 target[i].offset = tmp & 0xffffff;
12589 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012590 }
12591}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012592
Ben Hutchings1aa8b472012-07-10 10:56:59 +000012593/* IRO array is stored in the following format:
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012594 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12595 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012596static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012597{
12598 const __be32 *source = (const __be32 *)_source;
12599 struct iro *target = (struct iro *)_target;
12600 u32 i, j, tmp;
12601
12602 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12603 target[i].base = be32_to_cpu(source[j]);
12604 j++;
12605 tmp = be32_to_cpu(source[j]);
12606 target[i].m1 = (tmp >> 16) & 0xffff;
12607 target[i].m2 = tmp & 0xffff;
12608 j++;
12609 tmp = be32_to_cpu(source[j]);
12610 target[i].m3 = (tmp >> 16) & 0xffff;
12611 target[i].size = tmp & 0xffff;
12612 j++;
12613 }
12614}
12615
Eric Dumazet1191cb82012-04-27 21:39:21 +000012616static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012617{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012618 const __be16 *source = (const __be16 *)_source;
12619 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012620 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012621
12622 for (i = 0; i < n/2; i++)
12623 target[i] = be16_to_cpu(source[i]);
12624}
12625
Joe Perches7995c642010-02-17 15:01:52 +000012626#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12627do { \
12628 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12629 bp->arr = kmalloc(len, GFP_KERNEL); \
Joe Perchese404dec2012-01-29 12:56:23 +000012630 if (!bp->arr) \
Joe Perches7995c642010-02-17 15:01:52 +000012631 goto lbl; \
Joe Perches7995c642010-02-17 15:01:52 +000012632 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12633 (u8 *)bp->arr, len); \
12634} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012635
Yuval Mintz3b603062012-03-18 10:33:39 +000012636static int bnx2x_init_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012637{
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012638 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012639 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +000012640 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012641
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012642 if (bp->firmware)
12643 return 0;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012644
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012645 if (CHIP_IS_E1(bp))
12646 fw_file_name = FW_FILE_NAME_E1;
12647 else if (CHIP_IS_E1H(bp))
12648 fw_file_name = FW_FILE_NAME_E1H;
12649 else if (!CHIP_IS_E1x(bp))
12650 fw_file_name = FW_FILE_NAME_E2;
12651 else {
12652 BNX2X_ERR("Unsupported chip revision\n");
12653 return -EINVAL;
12654 }
12655 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012656
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012657 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12658 if (rc) {
12659 BNX2X_ERR("Can't load firmware file %s\n",
12660 fw_file_name);
12661 goto request_firmware_exit;
12662 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012663
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012664 rc = bnx2x_check_firmware(bp);
12665 if (rc) {
12666 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12667 goto request_firmware_exit;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012668 }
12669
12670 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12671
12672 /* Initialize the pointers to the init arrays */
12673 /* Blob */
12674 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12675
12676 /* Opcodes */
12677 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12678
12679 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012680 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12681 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012682
12683 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +000012684 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12685 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12686 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12687 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12688 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12689 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12690 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12691 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12692 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12693 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12694 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12695 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12696 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12697 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12698 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12699 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012700 /* IRO */
12701 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012702
12703 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012704
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012705iro_alloc_err:
12706 kfree(bp->init_ops_offsets);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012707init_offsets_alloc_err:
12708 kfree(bp->init_ops);
12709init_ops_alloc_err:
12710 kfree(bp->init_data);
12711request_firmware_exit:
12712 release_firmware(bp->firmware);
Michal Schmidt127d0a12012-03-15 14:08:28 +000012713 bp->firmware = NULL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012714
12715 return rc;
12716}
12717
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012718static void bnx2x_release_firmware(struct bnx2x *bp)
12719{
12720 kfree(bp->init_ops_offsets);
12721 kfree(bp->init_ops);
12722 kfree(bp->init_data);
12723 release_firmware(bp->firmware);
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +000012724 bp->firmware = NULL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012725}
12726
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012727static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12728 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12729 .init_hw_cmn = bnx2x_init_hw_common,
12730 .init_hw_port = bnx2x_init_hw_port,
12731 .init_hw_func = bnx2x_init_hw_func,
12732
12733 .reset_hw_cmn = bnx2x_reset_common,
12734 .reset_hw_port = bnx2x_reset_port,
12735 .reset_hw_func = bnx2x_reset_func,
12736
12737 .gunzip_init = bnx2x_gunzip_init,
12738 .gunzip_end = bnx2x_gunzip_end,
12739
12740 .init_fw = bnx2x_init_firmware,
12741 .release_fw = bnx2x_release_firmware,
12742};
12743
12744void bnx2x__init_func_obj(struct bnx2x *bp)
12745{
12746 /* Prepare DMAE related driver resources */
12747 bnx2x_setup_dmae(bp);
12748
12749 bnx2x_init_func_obj(bp, &bp->func_obj,
12750 bnx2x_sp(bp, func_rdata),
12751 bnx2x_sp_mapping(bp, func_rdata),
Barak Witkowskia3348722012-04-23 03:04:46 +000012752 bnx2x_sp(bp, func_afex_rdata),
12753 bnx2x_sp_mapping(bp, func_afex_rdata),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012754 &bnx2x_func_sp_drv);
12755}
12756
12757/* must be called after sriov-enable */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012758static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012759{
Merav Sicron37ae41a2012-06-19 07:48:27 +000012760 int cid_count = BNX2X_L2_MAX_CID(bp);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012761
Ariel Elior290ca2b2013-01-01 05:22:31 +000012762 if (IS_SRIOV(bp))
12763 cid_count += BNX2X_VF_CIDS;
12764
Merav Sicron55c11942012-11-07 00:45:48 +000012765 if (CNIC_SUPPORT(bp))
12766 cid_count += CNIC_CID_MAX;
Ariel Elior290ca2b2013-01-01 05:22:31 +000012767
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012768 return roundup(cid_count, QM_CID_ROUND);
12769}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012770
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012771/**
Ariel Elior6383c0b2011-07-14 08:31:57 +000012772 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012773 *
12774 * @dev: pci device
12775 *
12776 */
Ariel Elior60cad4e2013-09-04 14:09:22 +030012777static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012778{
Yijing Wangae2104b2013-08-08 21:02:36 +080012779 int index;
Ariel Elior1ab44342013-01-01 05:22:23 +000012780 u16 control = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012781
Ariel Elior6383c0b2011-07-14 08:31:57 +000012782 /*
12783 * If MSI-X is not supported - return number of SBs needed to support
12784 * one fast path queue: one FP queue + SB for CNIC
12785 */
Yijing Wangae2104b2013-08-08 21:02:36 +080012786 if (!pdev->msix_cap) {
Ariel Elior1ab44342013-01-01 05:22:23 +000012787 dev_info(&pdev->dev, "no msix capability found\n");
Merav Sicron55c11942012-11-07 00:45:48 +000012788 return 1 + cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012789 }
12790 dev_info(&pdev->dev, "msix capability found\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +000012791
12792 /*
12793 * The value in the PCI configuration space is the index of the last
12794 * entry, namely one less than the actual size of the table, which is
12795 * exactly what we want to return from this function: number of all SBs
12796 * without the default SB.
Ariel Elior1ab44342013-01-01 05:22:23 +000012797 * For VFs there is no default SB, then we return (index+1).
Ariel Elior6383c0b2011-07-14 08:31:57 +000012798 */
Yijing Wangae2104b2013-08-08 21:02:36 +080012799 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
Ariel Elior1ab44342013-01-01 05:22:23 +000012800
12801 index = control & PCI_MSIX_FLAGS_QSIZE;
12802
Ariel Elior60cad4e2013-09-04 14:09:22 +030012803 return index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012804}
12805
Ariel Elior1ab44342013-01-01 05:22:23 +000012806static int set_max_cos_est(int chip_id)
12807{
12808 switch (chip_id) {
12809 case BCM57710:
12810 case BCM57711:
12811 case BCM57711E:
12812 return BNX2X_MULTI_TX_COS_E1X;
12813 case BCM57712:
12814 case BCM57712_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012815 return BNX2X_MULTI_TX_COS_E2_E3A0;
12816 case BCM57800:
12817 case BCM57800_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012818 case BCM57810:
12819 case BCM57810_MF:
12820 case BCM57840_4_10:
12821 case BCM57840_2_20:
12822 case BCM57840_O:
12823 case BCM57840_MFO:
Ariel Elior1ab44342013-01-01 05:22:23 +000012824 case BCM57840_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012825 case BCM57811:
12826 case BCM57811_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012827 return BNX2X_MULTI_TX_COS_E3B0;
Yuval Mintzb1239722013-10-20 16:51:26 +020012828 case BCM57712_VF:
12829 case BCM57800_VF:
12830 case BCM57810_VF:
12831 case BCM57840_VF:
12832 case BCM57811_VF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012833 return 1;
12834 default:
12835 pr_err("Unknown board_type (%d), aborting\n", chip_id);
12836 return -ENODEV;
12837 }
12838}
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000012839
Ariel Elior1ab44342013-01-01 05:22:23 +000012840static int set_is_vf(int chip_id)
12841{
12842 switch (chip_id) {
12843 case BCM57712_VF:
12844 case BCM57800_VF:
12845 case BCM57810_VF:
12846 case BCM57840_VF:
12847 case BCM57811_VF:
12848 return true;
12849 default:
12850 return false;
12851 }
12852}
12853
Ariel Elior1ab44342013-01-01 05:22:23 +000012854static int bnx2x_init_one(struct pci_dev *pdev,
12855 const struct pci_device_id *ent)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012856{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012857 struct net_device *dev = NULL;
12858 struct bnx2x *bp;
Yuval Mintzb91e1a12013-09-28 08:46:12 +030012859 enum pcie_link_width pcie_width;
12860 enum pci_bus_speed pcie_speed;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012861 int rc, max_non_def_sbs;
Merav Sicron65565882012-06-19 07:48:26 +000012862 int rx_count, tx_count, rss_count, doorbell_size;
Ariel Elior1ab44342013-01-01 05:22:23 +000012863 int max_cos_est;
12864 bool is_vf;
Merav Sicron55c11942012-11-07 00:45:48 +000012865 int cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012866
12867 /* An estimated maximum supported CoS number according to the chip
Ariel Elior6383c0b2011-07-14 08:31:57 +000012868 * version.
12869 * We will try to roughly estimate the maximum number of CoSes this chip
12870 * may support in order to minimize the memory allocated for Tx
12871 * netdev_queue's. This number will be accurately calculated during the
12872 * initialization of bp->max_cos based on the chip versions AND chip
12873 * revision in the bnx2x_init_bp().
12874 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012875 max_cos_est = set_max_cos_est(ent->driver_data);
12876 if (max_cos_est < 0)
12877 return max_cos_est;
12878 is_vf = set_is_vf(ent->driver_data);
12879 cnic_cnt = is_vf ? 0 : 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012880
Ariel Elior60cad4e2013-09-04 14:09:22 +030012881 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
12882
12883 /* add another SB for VF as it has no default SB */
12884 max_non_def_sbs += is_vf ? 1 : 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012885
12886 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
Ariel Elior60cad4e2013-09-04 14:09:22 +030012887 rss_count = max_non_def_sbs - cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012888
12889 if (rss_count < 1)
12890 return -EINVAL;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012891
12892 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
Merav Sicron55c11942012-11-07 00:45:48 +000012893 rx_count = rss_count + cnic_cnt;
Ariel Elior6383c0b2011-07-14 08:31:57 +000012894
Ariel Elior1ab44342013-01-01 05:22:23 +000012895 /* Maximum number of netdev Tx queues:
Merav Sicron37ae41a2012-06-19 07:48:27 +000012896 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
Ariel Elior6383c0b2011-07-14 08:31:57 +000012897 */
Merav Sicron55c11942012-11-07 00:45:48 +000012898 tx_count = rss_count * max_cos_est + cnic_cnt;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012899
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012900 /* dev zeroed in init_etherdev */
Ariel Elior6383c0b2011-07-14 08:31:57 +000012901 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
Joe Perches41de8d42012-01-29 13:47:52 +000012902 if (!dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012903 return -ENOMEM;
12904
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012905 bp = netdev_priv(dev);
Ariel Elior6383c0b2011-07-14 08:31:57 +000012906
Ariel Elior1ab44342013-01-01 05:22:23 +000012907 bp->flags = 0;
12908 if (is_vf)
12909 bp->flags |= IS_VF_FLAG;
12910
Ariel Elior6383c0b2011-07-14 08:31:57 +000012911 bp->igu_sb_cnt = max_non_def_sbs;
Ariel Elior1ab44342013-01-01 05:22:23 +000012912 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
Joe Perches7995c642010-02-17 15:01:52 +000012913 bp->msg_enable = debug;
Merav Sicron55c11942012-11-07 00:45:48 +000012914 bp->cnic_support = cnic_cnt;
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000012915 bp->cnic_probe = bnx2x_cnic_probe;
Merav Sicron55c11942012-11-07 00:45:48 +000012916
Eilon Greensteindf4770de2009-08-12 08:23:28 +000012917 pci_set_drvdata(pdev, dev);
12918
Ariel Elior1ab44342013-01-01 05:22:23 +000012919 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012920 if (rc < 0) {
12921 free_netdev(dev);
12922 return rc;
12923 }
12924
Ariel Elior1ab44342013-01-01 05:22:23 +000012925 BNX2X_DEV_INFO("This is a %s function\n",
12926 IS_PF(bp) ? "physical" : "virtual");
Merav Sicron55c11942012-11-07 00:45:48 +000012927 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
Ariel Elior1ab44342013-01-01 05:22:23 +000012928 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
Merav Sicron60aa0502012-06-19 07:48:29 +000012929 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
Yuval Mintz2de67432013-01-23 03:21:43 +000012930 tx_count, rx_count);
Merav Sicron60aa0502012-06-19 07:48:29 +000012931
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012932 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000012933 if (rc)
12934 goto init_one_exit;
12935
Ariel Elior1ab44342013-01-01 05:22:23 +000012936 /* Map doorbells here as we need the real value of bp->max_cos which
12937 * is initialized in bnx2x_init_bp() to determine the number of
12938 * l2 connections.
Ariel Elior6383c0b2011-07-14 08:31:57 +000012939 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012940 if (IS_VF(bp)) {
Dmitry Kravkov1d6f3cd2013-03-27 01:05:17 +000012941 bp->doorbells = bnx2x_vf_doorbells(bp);
Ariel Elior64112802013-01-07 00:50:23 +000012942 rc = bnx2x_vf_pci_alloc(bp);
12943 if (rc)
12944 goto init_one_exit;
Ariel Elior1ab44342013-01-01 05:22:23 +000012945 } else {
12946 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
12947 if (doorbell_size > pci_resource_len(pdev, 2)) {
12948 dev_err(&bp->pdev->dev,
12949 "Cannot map doorbells, bar size too small, aborting\n");
12950 rc = -ENOMEM;
12951 goto init_one_exit;
12952 }
12953 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
12954 doorbell_size);
Merav Sicron37ae41a2012-06-19 07:48:27 +000012955 }
Ariel Elior6383c0b2011-07-14 08:31:57 +000012956 if (!bp->doorbells) {
12957 dev_err(&bp->pdev->dev,
12958 "Cannot map doorbell space, aborting\n");
12959 rc = -ENOMEM;
12960 goto init_one_exit;
12961 }
12962
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000012963 if (IS_VF(bp)) {
12964 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
12965 if (rc)
12966 goto init_one_exit;
12967 }
12968
Ariel Elior3c76fef2013-03-11 05:17:46 +000012969 /* Enable SRIOV if capability found in configuration space */
12970 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
Ariel Elior290ca2b2013-01-01 05:22:31 +000012971 if (rc)
12972 goto init_one_exit;
12973
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012974 /* calc qm_cid_count */
Ariel Elior6383c0b2011-07-14 08:31:57 +000012975 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
Ariel Elior1ab44342013-01-01 05:22:23 +000012976 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012977
Merav Sicron55c11942012-11-07 00:45:48 +000012978 /* disable FCOE L2 queue for E1x*/
Dmitry Kravkov62ac0dc2011-11-13 04:34:21 +000012979 if (CHIP_IS_E1x(bp))
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000012980 bp->flags |= NO_FCOE_FLAG;
12981
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000012982 /* Set bp->num_queues for MSI-X mode*/
12983 bnx2x_set_num_queues(bp);
12984
Lucas De Marchi25985ed2011-03-30 22:57:33 -030012985 /* Configure interrupt mode: try to enable MSI-X/MSI if
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000012986 * needed.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012987 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012988 rc = bnx2x_set_int_mode(bp);
12989 if (rc) {
12990 dev_err(&pdev->dev, "Cannot set interrupts\n");
12991 goto init_one_exit;
12992 }
Yuval Mintz04c46732013-01-23 03:21:46 +000012993 BNX2X_DEV_INFO("set interrupts successfully\n");
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000012994
Ariel Elior1ab44342013-01-01 05:22:23 +000012995 /* register the net device */
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080012996 rc = register_netdev(dev);
12997 if (rc) {
12998 dev_err(&pdev->dev, "Cannot register net device\n");
12999 goto init_one_exit;
13000 }
Ariel Elior1ab44342013-01-01 05:22:23 +000013001 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080013002
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013003 if (!NO_FCOE(bp)) {
13004 /* Add storage MAC address */
13005 rtnl_lock();
13006 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13007 rtnl_unlock();
13008 }
Yuval Mintzb91e1a12013-09-28 08:46:12 +030013009 if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
13010 pcie_speed == PCI_SPEED_UNKNOWN ||
13011 pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
13012 BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
13013 else
13014 BNX2X_DEV_INFO(
13015 "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000013016 board_info[ent->driver_data].name,
13017 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
13018 pcie_width,
Yuval Mintzb91e1a12013-09-28 08:46:12 +030013019 pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
13020 pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
13021 pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000013022 "Unknown",
13023 dev->base_addr, bp->pdev->irq, dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000013024
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013025 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013026
13027init_one_exit:
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013028 bnx2x_disable_pcie_error_reporting(bp);
13029
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013030 if (bp->regview)
13031 iounmap(bp->regview);
13032
Ariel Elior1ab44342013-01-01 05:22:23 +000013033 if (IS_PF(bp) && bp->doorbells)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013034 iounmap(bp->doorbells);
13035
13036 free_netdev(dev);
13037
13038 if (atomic_read(&pdev->enable_cnt) == 1)
13039 pci_release_regions(pdev);
13040
13041 pci_disable_device(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013042
13043 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013044}
13045
Yuval Mintzb030ed22013-05-27 04:08:30 +000013046static void __bnx2x_remove(struct pci_dev *pdev,
13047 struct net_device *dev,
13048 struct bnx2x *bp,
13049 bool remove_netdev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013050{
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013051 /* Delete storage MAC address */
13052 if (!NO_FCOE(bp)) {
13053 rtnl_lock();
13054 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13055 rtnl_unlock();
13056 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013057
Shmulik Ravid98507672011-02-28 12:19:55 -080013058#ifdef BCM_DCBNL
13059 /* Delete app tlvs from dcbnl */
13060 bnx2x_dcbnl_update_applist(bp, true);
13061#endif
13062
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030013063 if (IS_PF(bp) &&
13064 !BP_NOMCP(bp) &&
13065 (bp->flags & BC_SUPPORTS_RMMOD_CMD))
13066 bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
13067
Yuval Mintzb030ed22013-05-27 04:08:30 +000013068 /* Close the interface - either directly or implicitly */
13069 if (remove_netdev) {
13070 unregister_netdev(dev);
13071 } else {
13072 rtnl_lock();
Yuval Mintz6ef5a922013-08-13 02:25:03 +030013073 dev_close(dev);
Yuval Mintzb030ed22013-05-27 04:08:30 +000013074 rtnl_unlock();
13075 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013076
Ariel Elior78c3bcc2013-06-20 17:39:08 +030013077 bnx2x_iov_remove_one(bp);
13078
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013079 /* Power on: we can't let PCI layer write to us while we are in D3 */
Ariel Elior1ab44342013-01-01 05:22:23 +000013080 if (IS_PF(bp))
13081 bnx2x_set_power_state(bp, PCI_D0);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013082
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000013083 /* Disable MSI/MSI-X */
13084 bnx2x_disable_msi(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000013085
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013086 /* Power off */
Ariel Elior1ab44342013-01-01 05:22:23 +000013087 if (IS_PF(bp))
13088 bnx2x_set_power_state(bp, PCI_D3hot);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013089
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013090 /* Make sure RESET task is not scheduled before continuing */
Ariel Elior7be08a72011-07-14 08:31:19 +000013091 cancel_delayed_work_sync(&bp->sp_rtnl_task);
Ariel Elior290ca2b2013-01-01 05:22:31 +000013092
Ariel Elior4513f922013-01-01 05:22:25 +000013093 /* send message via vfpf channel to release the resources of this vf */
13094 if (IS_VF(bp))
13095 bnx2x_vfpf_release(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013096
Yuval Mintzb030ed22013-05-27 04:08:30 +000013097 /* Assumes no further PCIe PM changes will occur */
13098 if (system_state == SYSTEM_POWER_OFF) {
13099 pci_wake_from_d3(pdev, bp->wol);
13100 pci_set_power_state(pdev, PCI_D3hot);
13101 }
13102
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013103 bnx2x_disable_pcie_error_reporting(bp);
Yuval Mintzd9aee592014-01-15 12:05:30 +020013104 if (remove_netdev) {
13105 if (bp->regview)
13106 iounmap(bp->regview);
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013107
Yuval Mintzd9aee592014-01-15 12:05:30 +020013108 /* For vfs, doorbells are part of the regview and were unmapped
13109 * along with it. FW is only loaded by PF.
13110 */
13111 if (IS_PF(bp)) {
13112 if (bp->doorbells)
13113 iounmap(bp->doorbells);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013114
Yuval Mintzd9aee592014-01-15 12:05:30 +020013115 bnx2x_release_firmware(bp);
13116 }
13117 bnx2x_free_mem_bp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013118
Yuval Mintzb030ed22013-05-27 04:08:30 +000013119 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013120
Yuval Mintzd9aee592014-01-15 12:05:30 +020013121 if (atomic_read(&pdev->enable_cnt) == 1)
13122 pci_release_regions(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013123
Yuval Mintz5f6db132014-01-27 17:11:58 +020013124 pci_disable_device(pdev);
13125 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013126}
13127
Yuval Mintzb030ed22013-05-27 04:08:30 +000013128static void bnx2x_remove_one(struct pci_dev *pdev)
13129{
13130 struct net_device *dev = pci_get_drvdata(pdev);
13131 struct bnx2x *bp;
13132
13133 if (!dev) {
13134 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
13135 return;
13136 }
13137 bp = netdev_priv(dev);
13138
13139 __bnx2x_remove(pdev, dev, bp, true);
13140}
13141
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013142static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
13143{
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013144 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013145
13146 bp->rx_mode = BNX2X_RX_MODE_NONE;
13147
Merav Sicron55c11942012-11-07 00:45:48 +000013148 if (CNIC_LOADED(bp))
13149 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
13150
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013151 /* Stop Tx */
13152 bnx2x_tx_disable(bp);
Merav Sicron26614ba2012-08-27 03:26:19 +000013153 /* Delete all NAPI objects */
13154 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +000013155 if (CNIC_LOADED(bp))
13156 bnx2x_del_all_napi_cnic(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013157 netdev_reset_tc(bp->dev);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013158
13159 del_timer_sync(&bp->timer);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013160 cancel_delayed_work(&bp->sp_task);
13161 cancel_delayed_work(&bp->period_task);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013162
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013163 spin_lock_bh(&bp->stats_lock);
13164 bp->stats_state = STATS_STATE_DISABLED;
13165 spin_unlock_bh(&bp->stats_lock);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013166
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013167 bnx2x_save_statistics(bp);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013168
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013169 netif_carrier_off(bp->dev);
13170
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013171 return 0;
13172}
13173
Wendy Xiong493adb12008-06-23 20:36:22 -070013174/**
13175 * bnx2x_io_error_detected - called when PCI error is detected
13176 * @pdev: Pointer to PCI device
13177 * @state: The current pci connection state
13178 *
13179 * This function is called after a PCI bus error affecting
13180 * this device has been detected.
13181 */
13182static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
13183 pci_channel_state_t state)
13184{
13185 struct net_device *dev = pci_get_drvdata(pdev);
13186 struct bnx2x *bp = netdev_priv(dev);
13187
13188 rtnl_lock();
13189
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013190 BNX2X_ERR("IO error detected\n");
13191
Wendy Xiong493adb12008-06-23 20:36:22 -070013192 netif_device_detach(dev);
13193
Dean Nelson07ce50e42009-07-31 09:13:25 +000013194 if (state == pci_channel_io_perm_failure) {
13195 rtnl_unlock();
13196 return PCI_ERS_RESULT_DISCONNECT;
13197 }
13198
Wendy Xiong493adb12008-06-23 20:36:22 -070013199 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013200 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070013201
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013202 bnx2x_prev_path_mark_eeh(bp);
13203
Wendy Xiong493adb12008-06-23 20:36:22 -070013204 pci_disable_device(pdev);
13205
13206 rtnl_unlock();
13207
13208 /* Request a slot reset */
13209 return PCI_ERS_RESULT_NEED_RESET;
13210}
13211
13212/**
13213 * bnx2x_io_slot_reset - called after the PCI bus has been reset
13214 * @pdev: Pointer to PCI device
13215 *
13216 * Restart the card from scratch, as if from a cold-boot.
13217 */
13218static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
13219{
13220 struct net_device *dev = pci_get_drvdata(pdev);
13221 struct bnx2x *bp = netdev_priv(dev);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013222 int i;
Wendy Xiong493adb12008-06-23 20:36:22 -070013223
13224 rtnl_lock();
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013225 BNX2X_ERR("IO slot reset initializing...\n");
Wendy Xiong493adb12008-06-23 20:36:22 -070013226 if (pci_enable_device(pdev)) {
13227 dev_err(&pdev->dev,
13228 "Cannot re-enable PCI device after reset\n");
13229 rtnl_unlock();
13230 return PCI_ERS_RESULT_DISCONNECT;
13231 }
13232
13233 pci_set_master(pdev);
13234 pci_restore_state(pdev);
Yuval Mintz70632d02013-04-24 01:45:02 +000013235 pci_save_state(pdev);
Wendy Xiong493adb12008-06-23 20:36:22 -070013236
13237 if (netif_running(dev))
13238 bnx2x_set_power_state(bp, PCI_D0);
13239
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013240 if (netif_running(dev)) {
13241 BNX2X_ERR("IO slot reset --> driver unload\n");
Yuval Mintze68072e2013-05-22 21:21:51 +000013242
13243 /* MCP should have been reset; Need to wait for validity */
13244 bnx2x_init_shmem(bp);
13245
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013246 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
13247 u32 v;
13248
13249 v = SHMEM2_RD(bp,
13250 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
13251 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
13252 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
13253 }
13254 bnx2x_drain_tx_queues(bp);
13255 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
13256 bnx2x_netif_stop(bp, 1);
13257 bnx2x_free_irq(bp);
13258
13259 /* Report UNLOAD_DONE to MCP */
13260 bnx2x_send_unload_done(bp, true);
13261
13262 bp->sp_state = 0;
13263 bp->port.pmf = 0;
13264
13265 bnx2x_prev_unload(bp);
13266
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013267 /* We should have reseted the engine, so It's fair to
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013268 * assume the FW will no longer write to the bnx2x driver.
13269 */
13270 bnx2x_squeeze_objects(bp);
13271 bnx2x_free_skbs(bp);
13272 for_each_rx_queue(bp, i)
13273 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
13274 bnx2x_free_fp_mem(bp);
13275 bnx2x_free_mem(bp);
13276
13277 bp->state = BNX2X_STATE_CLOSED;
13278 }
13279
Wendy Xiong493adb12008-06-23 20:36:22 -070013280 rtnl_unlock();
13281
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013282 /* If AER, perform cleanup of the PCIe registers */
13283 if (bp->flags & AER_ENABLED) {
13284 if (pci_cleanup_aer_uncorrect_error_status(pdev))
13285 BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
13286 else
13287 DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
13288 }
13289
Wendy Xiong493adb12008-06-23 20:36:22 -070013290 return PCI_ERS_RESULT_RECOVERED;
13291}
13292
13293/**
13294 * bnx2x_io_resume - called when traffic can start flowing again
13295 * @pdev: Pointer to PCI device
13296 *
13297 * This callback is called when the error recovery driver tells us that
13298 * its OK to resume normal operation.
13299 */
13300static void bnx2x_io_resume(struct pci_dev *pdev)
13301{
13302 struct net_device *dev = pci_get_drvdata(pdev);
13303 struct bnx2x *bp = netdev_priv(dev);
13304
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013305 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013306 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013307 return;
13308 }
13309
Wendy Xiong493adb12008-06-23 20:36:22 -070013310 rtnl_lock();
13311
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013312 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
13313 DRV_MSG_SEQ_NUMBER_MASK;
13314
Wendy Xiong493adb12008-06-23 20:36:22 -070013315 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013316 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070013317
13318 netif_device_attach(dev);
13319
13320 rtnl_unlock();
13321}
13322
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070013323static const struct pci_error_handlers bnx2x_err_handler = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013324 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000013325 .slot_reset = bnx2x_io_slot_reset,
13326 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070013327};
13328
Yuval Mintzb030ed22013-05-27 04:08:30 +000013329static void bnx2x_shutdown(struct pci_dev *pdev)
13330{
13331 struct net_device *dev = pci_get_drvdata(pdev);
13332 struct bnx2x *bp;
13333
13334 if (!dev)
13335 return;
13336
13337 bp = netdev_priv(dev);
13338 if (!bp)
13339 return;
13340
13341 rtnl_lock();
13342 netif_device_detach(dev);
13343 rtnl_unlock();
13344
13345 /* Don't remove the netdevice, as there are scenarios which will cause
13346 * the kernel to hang, e.g., when trying to remove bnx2i while the
13347 * rootfs is mounted from SAN.
13348 */
13349 __bnx2x_remove(pdev, dev, bp, false);
13350}
13351
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013352static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013353 .name = DRV_MODULE_NAME,
13354 .id_table = bnx2x_pci_tbl,
13355 .probe = bnx2x_init_one,
Bill Pemberton0329aba2012-12-03 09:24:24 -050013356 .remove = bnx2x_remove_one,
Wendy Xiong493adb12008-06-23 20:36:22 -070013357 .suspend = bnx2x_suspend,
13358 .resume = bnx2x_resume,
13359 .err_handler = &bnx2x_err_handler,
Ariel Elior3c76fef2013-03-11 05:17:46 +000013360#ifdef CONFIG_BNX2X_SRIOV
13361 .sriov_configure = bnx2x_sriov_configure,
13362#endif
Yuval Mintzb030ed22013-05-27 04:08:30 +000013363 .shutdown = bnx2x_shutdown,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013364};
13365
13366static int __init bnx2x_init(void)
13367{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013368 int ret;
13369
Joe Perches7995c642010-02-17 15:01:52 +000013370 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +000013371
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013372 bnx2x_wq = create_singlethread_workqueue("bnx2x");
13373 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +000013374 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013375 return -ENOMEM;
13376 }
13377
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013378 ret = pci_register_driver(&bnx2x_pci_driver);
13379 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +000013380 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013381 destroy_workqueue(bnx2x_wq);
13382 }
13383 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013384}
13385
13386static void __exit bnx2x_cleanup(void)
13387{
Yuval Mintz452427b2012-03-26 20:47:07 +000013388 struct list_head *pos, *q;
Yuval Mintzd76a6112013-06-02 00:06:17 +000013389
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013390 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013391
13392 destroy_workqueue(bnx2x_wq);
Yuval Mintz452427b2012-03-26 20:47:07 +000013393
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013394 /* Free globally allocated resources */
Yuval Mintz452427b2012-03-26 20:47:07 +000013395 list_for_each_safe(pos, q, &bnx2x_prev_list) {
13396 struct bnx2x_prev_path_list *tmp =
13397 list_entry(pos, struct bnx2x_prev_path_list, list);
13398 list_del(pos);
13399 kfree(tmp);
13400 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013401}
13402
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013403void bnx2x_notify_link_changed(struct bnx2x *bp)
13404{
13405 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13406}
13407
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013408module_init(bnx2x_init);
13409module_exit(bnx2x_cleanup);
13410
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013411/**
13412 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13413 *
13414 * @bp: driver handle
13415 * @set: set or clear the CAM entry
13416 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013417 * This function will wait until the ramrod completion returns.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013418 * Return 0 if success, -ENODEV if ramrod doesn't return.
13419 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000013420static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013421{
13422 unsigned long ramrod_flags = 0;
13423
13424 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13425 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13426 &bp->iscsi_l2_mac_obj, true,
13427 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13428}
Michael Chan993ac7b2009-10-10 13:46:56 +000013429
13430/* count denotes the number of new completions we have seen */
13431static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13432{
13433 struct eth_spe *spe;
Merav Sicrona0529972012-06-19 07:48:25 +000013434 int cxt_index, cxt_offset;
Michael Chan993ac7b2009-10-10 13:46:56 +000013435
13436#ifdef BNX2X_STOP_ON_ERROR
13437 if (unlikely(bp->panic))
13438 return;
13439#endif
13440
13441 spin_lock_bh(&bp->spq_lock);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013442 BUG_ON(bp->cnic_spq_pending < count);
Michael Chan993ac7b2009-10-10 13:46:56 +000013443 bp->cnic_spq_pending -= count;
13444
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013445 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13446 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13447 & SPE_HDR_CONN_TYPE) >>
13448 SPE_HDR_CONN_TYPE_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013449 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13450 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013451
13452 /* Set validation for iSCSI L2 client before sending SETUP
13453 * ramrod
13454 */
13455 if (type == ETH_CONNECTION_TYPE) {
Merav Sicrona0529972012-06-19 07:48:25 +000013456 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
Merav Sicron37ae41a2012-06-19 07:48:27 +000013457 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
Merav Sicrona0529972012-06-19 07:48:25 +000013458 ILT_PAGE_CIDS;
Merav Sicron37ae41a2012-06-19 07:48:27 +000013459 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
Merav Sicrona0529972012-06-19 07:48:25 +000013460 (cxt_index * ILT_PAGE_CIDS);
13461 bnx2x_set_ctx_validation(bp,
13462 &bp->context[cxt_index].
13463 vcxt[cxt_offset].eth,
Merav Sicron37ae41a2012-06-19 07:48:27 +000013464 BNX2X_ISCSI_ETH_CID(bp));
Merav Sicrona0529972012-06-19 07:48:25 +000013465 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013466 }
13467
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013468 /*
13469 * There may be not more than 8 L2, not more than 8 L5 SPEs
13470 * and in the air. We also check that number of outstanding
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013471 * COMMON ramrods is not more than the EQ and SPQ can
13472 * accommodate.
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013473 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013474 if (type == ETH_CONNECTION_TYPE) {
13475 if (!atomic_read(&bp->cq_spq_left))
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013476 break;
13477 else
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013478 atomic_dec(&bp->cq_spq_left);
13479 } else if (type == NONE_CONNECTION_TYPE) {
13480 if (!atomic_read(&bp->eq_spq_left))
13481 break;
13482 else
13483 atomic_dec(&bp->eq_spq_left);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013484 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13485 (type == FCOE_CONNECTION_TYPE)) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013486 if (bp->cnic_spq_pending >=
13487 bp->cnic_eth_dev.max_kwqe_pending)
13488 break;
13489 else
13490 bp->cnic_spq_pending++;
13491 } else {
13492 BNX2X_ERR("Unknown SPE type: %d\n", type);
13493 bnx2x_panic();
Michael Chan993ac7b2009-10-10 13:46:56 +000013494 break;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013495 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013496
13497 spe = bnx2x_sp_get_next(bp);
13498 *spe = *bp->cnic_kwq_cons;
13499
Merav Sicron51c1a582012-03-18 10:33:38 +000013500 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013501 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13502
13503 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13504 bp->cnic_kwq_cons = bp->cnic_kwq;
13505 else
13506 bp->cnic_kwq_cons++;
13507 }
13508 bnx2x_sp_prod_update(bp);
13509 spin_unlock_bh(&bp->spq_lock);
13510}
13511
13512static int bnx2x_cnic_sp_queue(struct net_device *dev,
13513 struct kwqe_16 *kwqes[], u32 count)
13514{
13515 struct bnx2x *bp = netdev_priv(dev);
13516 int i;
13517
13518#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +000013519 if (unlikely(bp->panic)) {
13520 BNX2X_ERR("Can't post to SP queue while panic\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013521 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +000013522 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013523#endif
13524
Ariel Elior95c6c6162012-01-26 06:01:52 +000013525 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13526 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013527 BNX2X_ERR("Handling parity error recovery. Try again later\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +000013528 return -EAGAIN;
13529 }
13530
Michael Chan993ac7b2009-10-10 13:46:56 +000013531 spin_lock_bh(&bp->spq_lock);
13532
13533 for (i = 0; i < count; i++) {
13534 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13535
13536 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13537 break;
13538
13539 *bp->cnic_kwq_prod = *spe;
13540
13541 bp->cnic_kwq_pending++;
13542
Merav Sicron51c1a582012-03-18 10:33:38 +000013543 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013544 spe->hdr.conn_and_cmd_data, spe->hdr.type,
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013545 spe->data.update_data_addr.hi,
13546 spe->data.update_data_addr.lo,
Michael Chan993ac7b2009-10-10 13:46:56 +000013547 bp->cnic_kwq_pending);
13548
13549 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13550 bp->cnic_kwq_prod = bp->cnic_kwq;
13551 else
13552 bp->cnic_kwq_prod++;
13553 }
13554
13555 spin_unlock_bh(&bp->spq_lock);
13556
13557 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13558 bnx2x_cnic_sp_post(bp, 0);
13559
13560 return i;
13561}
13562
13563static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13564{
13565 struct cnic_ops *c_ops;
13566 int rc = 0;
13567
13568 mutex_lock(&bp->cnic_mutex);
Eric Dumazet13707f92011-01-26 19:28:23 +000013569 c_ops = rcu_dereference_protected(bp->cnic_ops,
13570 lockdep_is_held(&bp->cnic_mutex));
Michael Chan993ac7b2009-10-10 13:46:56 +000013571 if (c_ops)
13572 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13573 mutex_unlock(&bp->cnic_mutex);
13574
13575 return rc;
13576}
13577
13578static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13579{
13580 struct cnic_ops *c_ops;
13581 int rc = 0;
13582
13583 rcu_read_lock();
13584 c_ops = rcu_dereference(bp->cnic_ops);
13585 if (c_ops)
13586 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13587 rcu_read_unlock();
13588
13589 return rc;
13590}
13591
13592/*
13593 * for commands that have no data
13594 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013595int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +000013596{
13597 struct cnic_ctl_info ctl = {0};
13598
13599 ctl.cmd = cmd;
13600
13601 return bnx2x_cnic_ctl_send(bp, &ctl);
13602}
13603
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013604static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
Michael Chan993ac7b2009-10-10 13:46:56 +000013605{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013606 struct cnic_ctl_info ctl = {0};
Michael Chan993ac7b2009-10-10 13:46:56 +000013607
13608 /* first we tell CNIC and only then we count this as a completion */
13609 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13610 ctl.data.comp.cid = cid;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013611 ctl.data.comp.error = err;
Michael Chan993ac7b2009-10-10 13:46:56 +000013612
13613 bnx2x_cnic_ctl_send_bh(bp, &ctl);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013614 bnx2x_cnic_sp_post(bp, 0);
Michael Chan993ac7b2009-10-10 13:46:56 +000013615}
13616
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013617/* Called with netif_addr_lock_bh() taken.
13618 * Sets an rx_mode config for an iSCSI ETH client.
13619 * Doesn't block.
13620 * Completion should be checked outside.
13621 */
13622static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13623{
13624 unsigned long accept_flags = 0, ramrod_flags = 0;
13625 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13626 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13627
13628 if (start) {
13629 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13630 * because it's the only way for UIO Queue to accept
13631 * multicasts (in non-promiscuous mode only one Queue per
13632 * function will receive multicast packets (leading in our
13633 * case).
13634 */
13635 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13636 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13637 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13638 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13639
13640 /* Clear STOP_PENDING bit if START is requested */
13641 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13642
13643 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13644 } else
13645 /* Clear START_PENDING bit if STOP is requested */
13646 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13647
13648 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13649 set_bit(sched_state, &bp->sp_state);
13650 else {
13651 __set_bit(RAMROD_RX, &ramrod_flags);
13652 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13653 ramrod_flags);
13654 }
13655}
13656
Michael Chan993ac7b2009-10-10 13:46:56 +000013657static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13658{
13659 struct bnx2x *bp = netdev_priv(dev);
13660 int rc = 0;
13661
13662 switch (ctl->cmd) {
13663 case DRV_CTL_CTXTBL_WR_CMD: {
13664 u32 index = ctl->data.io.offset;
13665 dma_addr_t addr = ctl->data.io.dma_addr;
13666
13667 bnx2x_ilt_wr(bp, index, addr);
13668 break;
13669 }
13670
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013671 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13672 int count = ctl->data.credit.credit_count;
Michael Chan993ac7b2009-10-10 13:46:56 +000013673
13674 bnx2x_cnic_sp_post(bp, count);
13675 break;
13676 }
13677
13678 /* rtnl_lock is held. */
13679 case DRV_CTL_START_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013680 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13681 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013682
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013683 /* Configure the iSCSI classification object */
13684 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13685 cp->iscsi_l2_client_id,
13686 cp->iscsi_l2_cid, BP_FUNC(bp),
13687 bnx2x_sp(bp, mac_rdata),
13688 bnx2x_sp_mapping(bp, mac_rdata),
13689 BNX2X_FILTER_MAC_PENDING,
13690 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13691 &bp->macs_pool);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013692
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013693 /* Set iSCSI MAC address */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013694 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13695 if (rc)
13696 break;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013697
13698 mmiowb();
13699 barrier();
13700
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013701 /* Start accepting on iSCSI L2 ring */
13702
13703 netif_addr_lock_bh(dev);
13704 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13705 netif_addr_unlock_bh(dev);
13706
13707 /* bits to wait on */
13708 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13709 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13710
13711 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13712 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013713
Michael Chan993ac7b2009-10-10 13:46:56 +000013714 break;
13715 }
13716
13717 /* rtnl_lock is held. */
13718 case DRV_CTL_STOP_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013719 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013720
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013721 /* Stop accepting on iSCSI L2 ring */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013722 netif_addr_lock_bh(dev);
13723 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13724 netif_addr_unlock_bh(dev);
13725
13726 /* bits to wait on */
13727 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13728 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13729
13730 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13731 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013732
13733 mmiowb();
13734 barrier();
13735
13736 /* Unset iSCSI L2 MAC */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013737 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13738 BNX2X_ISCSI_ETH_MAC, true);
Michael Chan993ac7b2009-10-10 13:46:56 +000013739 break;
13740 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013741 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13742 int count = ctl->data.credit.credit_count;
13743
13744 smp_mb__before_atomic_inc();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013745 atomic_add(count, &bp->cq_spq_left);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013746 smp_mb__after_atomic_inc();
13747 break;
13748 }
Barak Witkowski1d187b32011-12-05 22:41:50 +000013749 case DRV_CTL_ULP_REGISTER_CMD: {
Barak Witkowski2e499d32012-06-26 01:31:19 +000013750 int ulp_type = ctl->data.register_data.ulp_type;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013751
13752 if (CHIP_IS_E3(bp)) {
13753 int idx = BP_FW_MB_IDX(bp);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013754 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13755 int path = BP_PATH(bp);
13756 int port = BP_PORT(bp);
13757 int i;
13758 u32 scratch_offset;
13759 u32 *host_addr;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013760
Barak Witkowski2e499d32012-06-26 01:31:19 +000013761 /* first write capability to shmem2 */
Barak Witkowski1d187b32011-12-05 22:41:50 +000013762 if (ulp_type == CNIC_ULP_ISCSI)
13763 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13764 else if (ulp_type == CNIC_ULP_FCOE)
13765 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13766 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013767
13768 if ((ulp_type != CNIC_ULP_FCOE) ||
13769 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13770 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13771 break;
13772
13773 /* if reached here - should write fcoe capabilities */
13774 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13775 if (!scratch_offset)
13776 break;
13777 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13778 fcoe_features[path][port]);
13779 host_addr = (u32 *) &(ctl->data.register_data.
13780 fcoe_features);
13781 for (i = 0; i < sizeof(struct fcoe_capabilities);
13782 i += 4)
13783 REG_WR(bp, scratch_offset + i,
13784 *(host_addr + i/4));
Barak Witkowski1d187b32011-12-05 22:41:50 +000013785 }
13786 break;
13787 }
Barak Witkowski2e499d32012-06-26 01:31:19 +000013788
Barak Witkowski1d187b32011-12-05 22:41:50 +000013789 case DRV_CTL_ULP_UNREGISTER_CMD: {
13790 int ulp_type = ctl->data.ulp_type;
13791
13792 if (CHIP_IS_E3(bp)) {
13793 int idx = BP_FW_MB_IDX(bp);
13794 u32 cap;
13795
13796 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13797 if (ulp_type == CNIC_ULP_ISCSI)
13798 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13799 else if (ulp_type == CNIC_ULP_FCOE)
13800 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13801 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13802 }
13803 break;
13804 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013805
13806 default:
13807 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13808 rc = -EINVAL;
13809 }
13810
13811 return rc;
13812}
13813
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013814void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +000013815{
13816 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13817
13818 if (bp->flags & USING_MSIX_FLAG) {
13819 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13820 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13821 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13822 } else {
13823 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13824 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13825 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013826 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013827 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13828 else
13829 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13830
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013831 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13832 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013833 cp->irq_arr[1].status_blk = bp->def_status_blk;
13834 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013835 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
Michael Chan993ac7b2009-10-10 13:46:56 +000013836
13837 cp->num_irq = 2;
13838}
13839
Merav Sicron37ae41a2012-06-19 07:48:27 +000013840void bnx2x_setup_cnic_info(struct bnx2x *bp)
13841{
13842 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13843
Merav Sicron37ae41a2012-06-19 07:48:27 +000013844 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13845 bnx2x_cid_ilt_lines(bp);
13846 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
13847 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
13848 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
13849
Michael Chanf78afb32013-09-18 01:50:38 -070013850 DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
13851 BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
13852 cp->iscsi_l2_cid);
13853
Merav Sicron37ae41a2012-06-19 07:48:27 +000013854 if (NO_ISCSI_OOO(bp))
13855 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13856}
13857
Michael Chan993ac7b2009-10-10 13:46:56 +000013858static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
13859 void *data)
13860{
13861 struct bnx2x *bp = netdev_priv(dev);
13862 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
Merav Sicron55c11942012-11-07 00:45:48 +000013863 int rc;
13864
13865 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013866
Merav Sicron51c1a582012-03-18 10:33:38 +000013867 if (ops == NULL) {
13868 BNX2X_ERR("NULL ops received\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013869 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000013870 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013871
Merav Sicron55c11942012-11-07 00:45:48 +000013872 if (!CNIC_SUPPORT(bp)) {
13873 BNX2X_ERR("Can't register CNIC when not supported\n");
13874 return -EOPNOTSUPP;
13875 }
13876
13877 if (!CNIC_LOADED(bp)) {
13878 rc = bnx2x_load_cnic(bp);
13879 if (rc) {
13880 BNX2X_ERR("CNIC-related load failed\n");
13881 return rc;
13882 }
Merav Sicron55c11942012-11-07 00:45:48 +000013883 }
13884
13885 bp->cnic_enabled = true;
13886
Michael Chan993ac7b2009-10-10 13:46:56 +000013887 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
13888 if (!bp->cnic_kwq)
13889 return -ENOMEM;
13890
13891 bp->cnic_kwq_cons = bp->cnic_kwq;
13892 bp->cnic_kwq_prod = bp->cnic_kwq;
13893 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
13894
13895 bp->cnic_spq_pending = 0;
13896 bp->cnic_kwq_pending = 0;
13897
13898 bp->cnic_data = data;
13899
13900 cp->num_irq = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013901 cp->drv_state |= CNIC_DRV_STATE_REGD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013902 cp->iro_arr = bp->iro_arr;
Michael Chan993ac7b2009-10-10 13:46:56 +000013903
Michael Chan993ac7b2009-10-10 13:46:56 +000013904 bnx2x_setup_cnic_irq_info(bp);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013905
Michael Chan993ac7b2009-10-10 13:46:56 +000013906 rcu_assign_pointer(bp->cnic_ops, ops);
13907
13908 return 0;
13909}
13910
13911static int bnx2x_unregister_cnic(struct net_device *dev)
13912{
13913 struct bnx2x *bp = netdev_priv(dev);
13914 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13915
13916 mutex_lock(&bp->cnic_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +000013917 cp->drv_state = 0;
Eric Dumazet2cfa5a02011-11-23 07:09:32 +000013918 RCU_INIT_POINTER(bp->cnic_ops, NULL);
Michael Chan993ac7b2009-10-10 13:46:56 +000013919 mutex_unlock(&bp->cnic_mutex);
13920 synchronize_rcu();
Yuval Mintzfea75642013-04-10 13:34:39 +030013921 bp->cnic_enabled = false;
Michael Chan993ac7b2009-10-10 13:46:56 +000013922 kfree(bp->cnic_kwq);
13923 bp->cnic_kwq = NULL;
13924
13925 return 0;
13926}
13927
stephen hemmingera8f47eb2014-01-09 22:20:11 -080013928static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
Michael Chan993ac7b2009-10-10 13:46:56 +000013929{
13930 struct bnx2x *bp = netdev_priv(dev);
13931 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13932
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000013933 /* If both iSCSI and FCoE are disabled - return NULL in
13934 * order to indicate CNIC that it should not try to work
13935 * with this device.
13936 */
13937 if (NO_ISCSI(bp) && NO_FCOE(bp))
13938 return NULL;
13939
Michael Chan993ac7b2009-10-10 13:46:56 +000013940 cp->drv_owner = THIS_MODULE;
13941 cp->chip_id = CHIP_ID(bp);
13942 cp->pdev = bp->pdev;
13943 cp->io_base = bp->regview;
13944 cp->io_base2 = bp->doorbells;
13945 cp->max_kwqe_pending = 8;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013946 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013947 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
13948 bnx2x_cid_ilt_lines(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013949 cp->ctx_tbl_len = CNIC_ILT_LINES;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013950 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
Michael Chan993ac7b2009-10-10 13:46:56 +000013951 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
13952 cp->drv_ctl = bnx2x_drv_ctl;
13953 cp->drv_register_cnic = bnx2x_register_cnic;
13954 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
Merav Sicron37ae41a2012-06-19 07:48:27 +000013955 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013956 cp->iscsi_l2_client_id =
13957 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
Merav Sicron37ae41a2012-06-19 07:48:27 +000013958 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013959
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000013960 if (NO_ISCSI_OOO(bp))
13961 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
13962
13963 if (NO_ISCSI(bp))
13964 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
13965
13966 if (NO_FCOE(bp))
13967 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
13968
Merav Sicron51c1a582012-03-18 10:33:38 +000013969 BNX2X_DEV_INFO(
13970 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013971 cp->ctx_blk_size,
13972 cp->ctx_tbl_offset,
13973 cp->ctx_tbl_len,
13974 cp->starting_cid);
Michael Chan993ac7b2009-10-10 13:46:56 +000013975 return cp;
13976}
Michael Chan993ac7b2009-10-10 13:46:56 +000013977
stephen hemmingera8f47eb2014-01-09 22:20:11 -080013978static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013979{
Ariel Elior64112802013-01-07 00:50:23 +000013980 struct bnx2x *bp = fp->bp;
13981 u32 offset = BAR_USTRORM_INTMEM;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070013982
Ariel Elior64112802013-01-07 00:50:23 +000013983 if (IS_VF(bp))
13984 return bnx2x_vf_ustorm_prods_offset(bp, fp);
13985 else if (!CHIP_IS_E1x(bp))
13986 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
13987 else
13988 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013989
Ariel Elior64112802013-01-07 00:50:23 +000013990 return offset;
13991}
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013992
Ariel Elior64112802013-01-07 00:50:23 +000013993/* called only on E1H or E2.
13994 * When pretending to be PF, the pretend value is the function number 0...7
13995 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
13996 * combination
13997 */
13998int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
13999{
14000 u32 pretend_reg;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014001
Ariel Elior23826852013-01-09 07:04:35 +000014002 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
Ariel Elior64112802013-01-07 00:50:23 +000014003 return -1;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014004
Ariel Elior64112802013-01-07 00:50:23 +000014005 /* get my own pretend register */
14006 pretend_reg = bnx2x_get_pretend_reg(bp);
14007 REG_WR(bp, pretend_reg, pretend_func_val);
14008 REG_RD(bp, pretend_reg);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014009 return 0;
14010}