blob: a154c7e1550c812ba9cc37cc3e99c9550390aeae [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 *
Ariel Elior08f6dd82014-05-27 13:11:36 +03009 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
Eilon Greenstein24e3fce2008-06-12 14:30:28 -070010 * 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
Yuval Mintz370d4a22014-03-23 18:12:24 +0200123static struct workqueue_struct *bnx2x_wq;
124struct workqueue_struct *bnx2x_iov_wq;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000125
Barak Witkowski1ef1d452013-01-10 04:53:40 +0000126struct bnx2x_mac_vals {
127 u32 xmac_addr;
128 u32 xmac_val;
129 u32 emac_addr;
130 u32 emac_val;
131 u32 umac_addr;
132 u32 umac_val;
133 u32 bmac_addr;
134 u32 bmac_val[2];
135};
136
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200137enum bnx2x_board_type {
138 BCM57710 = 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300139 BCM57711,
140 BCM57711E,
141 BCM57712,
142 BCM57712_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000143 BCM57712_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300144 BCM57800,
145 BCM57800_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000146 BCM57800_VF,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300147 BCM57810,
148 BCM57810_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000149 BCM57810_VF,
Yuval Mintzc3def942012-07-23 10:25:43 +0300150 BCM57840_4_10,
151 BCM57840_2_20,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000152 BCM57840_MF,
Ariel Elior1ab44342013-01-01 05:22:23 +0000153 BCM57840_VF,
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000154 BCM57811,
Ariel Elior1ab44342013-01-01 05:22:23 +0000155 BCM57811_MF,
156 BCM57840_O,
157 BCM57840_MFO,
158 BCM57811_VF
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200159};
160
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700161/* indexed by board_type, above */
Andrew Morton53a10562008-02-09 23:16:41 -0800162static struct {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200163 char *name;
Bill Pemberton0329aba2012-12-03 09:24:24 -0500164} board_info[] = {
Ariel Elior1ab44342013-01-01 05:22:23 +0000165 [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
166 [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
167 [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
168 [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
169 [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
170 [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
171 [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
172 [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
173 [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
174 [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
175 [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
176 [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
177 [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
178 [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
179 [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
180 [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
181 [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
182 [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
183 [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
184 [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
185 [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200186};
187
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300188#ifndef PCI_DEVICE_ID_NX2_57710
189#define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
190#endif
191#ifndef PCI_DEVICE_ID_NX2_57711
192#define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
193#endif
194#ifndef PCI_DEVICE_ID_NX2_57711E
195#define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
196#endif
197#ifndef PCI_DEVICE_ID_NX2_57712
198#define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
199#endif
200#ifndef PCI_DEVICE_ID_NX2_57712_MF
201#define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
202#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000203#ifndef PCI_DEVICE_ID_NX2_57712_VF
204#define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
205#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300206#ifndef PCI_DEVICE_ID_NX2_57800
207#define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
208#endif
209#ifndef PCI_DEVICE_ID_NX2_57800_MF
210#define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
211#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000212#ifndef PCI_DEVICE_ID_NX2_57800_VF
213#define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
214#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300215#ifndef PCI_DEVICE_ID_NX2_57810
216#define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
217#endif
218#ifndef PCI_DEVICE_ID_NX2_57810_MF
219#define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
220#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300221#ifndef PCI_DEVICE_ID_NX2_57840_O
222#define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
223#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000224#ifndef PCI_DEVICE_ID_NX2_57810_VF
225#define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
226#endif
Yuval Mintzc3def942012-07-23 10:25:43 +0300227#ifndef PCI_DEVICE_ID_NX2_57840_4_10
228#define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
229#endif
230#ifndef PCI_DEVICE_ID_NX2_57840_2_20
231#define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
232#endif
233#ifndef PCI_DEVICE_ID_NX2_57840_MFO
234#define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300235#endif
236#ifndef PCI_DEVICE_ID_NX2_57840_MF
237#define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
238#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000239#ifndef PCI_DEVICE_ID_NX2_57840_VF
240#define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
241#endif
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000242#ifndef PCI_DEVICE_ID_NX2_57811
243#define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
244#endif
245#ifndef PCI_DEVICE_ID_NX2_57811_MF
246#define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
247#endif
Ariel Elior8395be52013-01-01 05:22:44 +0000248#ifndef PCI_DEVICE_ID_NX2_57811_VF
249#define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
250#endif
251
Benoit Taine9baa3c32014-08-08 15:56:03 +0200252static const struct pci_device_id bnx2x_pci_tbl[] = {
Eilon Greensteine4ed7112009-08-12 08:24:10 +0000253 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
254 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
255 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000256 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300257 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000258 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300259 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
260 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000261 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300262 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
263 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300264 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
265 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
266 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
Ariel Elior8395be52013-01-01 05:22:44 +0000267 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
Yuval Mintzc3def942012-07-23 10:25:43 +0300268 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300269 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000270 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
Barak Witkowski7e8e02d2012-04-03 18:41:28 +0000271 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
272 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
Ariel Elior8395be52013-01-01 05:22:44 +0000273 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200274 { 0 }
275};
276
277MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
278
Yuval Mintz452427b2012-03-26 20:47:07 +0000279/* Global resources for unloading a previously loaded device */
280#define BNX2X_PREV_WAIT_NEEDED 1
281static DEFINE_SEMAPHORE(bnx2x_prev_sem);
282static LIST_HEAD(bnx2x_prev_list);
stephen hemmingera8f47eb2014-01-09 22:20:11 -0800283
284/* Forward declaration */
285static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
286static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
287static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
288
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200289/****************************************************************************
290* General service functions
291****************************************************************************/
292
Eric Dumazet1191cb82012-04-27 21:39:21 +0000293static void __storm_memset_dma_mapping(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300294 u32 addr, dma_addr_t mapping)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000295{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300296 REG_WR(bp, addr, U64_LO(mapping));
297 REG_WR(bp, addr + 4, U64_HI(mapping));
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000298}
299
Eric Dumazet1191cb82012-04-27 21:39:21 +0000300static void storm_memset_spq_addr(struct bnx2x *bp,
301 dma_addr_t mapping, u16 abs_fid)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300302{
303 u32 addr = XSEM_REG_FAST_MEMORY +
304 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
305
306 __storm_memset_dma_mapping(bp, addr, mapping);
307}
308
Eric Dumazet1191cb82012-04-27 21:39:21 +0000309static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
310 u16 pf_id)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300311{
312 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
313 pf_id);
314 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
315 pf_id);
316 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
317 pf_id);
318 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
319 pf_id);
320}
321
Eric Dumazet1191cb82012-04-27 21:39:21 +0000322static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
323 u8 enable)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300324{
325 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
326 enable);
327 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
328 enable);
329 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
330 enable);
331 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
332 enable);
333}
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000334
Eric Dumazet1191cb82012-04-27 21:39:21 +0000335static void storm_memset_eq_data(struct bnx2x *bp,
336 struct event_ring_data *eq_data,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000337 u16 pfid)
338{
339 size_t size = sizeof(struct event_ring_data);
340
341 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
342
343 __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
344}
345
Eric Dumazet1191cb82012-04-27 21:39:21 +0000346static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
347 u16 pfid)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000348{
349 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
350 REG_WR16(bp, addr, eq_prod);
351}
352
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200353/* used only at init
354 * locking is done by mcp
355 */
stephen hemminger8d962862010-10-21 07:50:56 +0000356static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200357{
358 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
359 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
360 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
361 PCICFG_VENDOR_ID_OFFSET);
362}
363
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200364static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
365{
366 u32 val;
367
368 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
369 pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
370 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
371 PCICFG_VENDOR_ID_OFFSET);
372
373 return val;
374}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200375
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000376#define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
377#define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
378#define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
379#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
380#define DMAE_DP_DST_NONE "dst_addr [none]"
381
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000382static void bnx2x_dp_dmae(struct bnx2x *bp,
383 struct dmae_command *dmae, int msglvl)
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000384{
385 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000386 int i;
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000387
388 switch (dmae->opcode & DMAE_COMMAND_DST) {
389 case DMAE_CMD_DST_PCI:
390 if (src_type == DMAE_CMD_SRC_PCI)
391 DP(msglvl, "DMAE: opcode 0x%08x\n"
392 "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
393 "comp_addr [%x:%08x], comp_val 0x%08x\n",
394 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
395 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
396 dmae->comp_addr_hi, dmae->comp_addr_lo,
397 dmae->comp_val);
398 else
399 DP(msglvl, "DMAE: opcode 0x%08x\n"
400 "src [%08x], len [%d*4], dst [%x:%08x]\n"
401 "comp_addr [%x:%08x], comp_val 0x%08x\n",
402 dmae->opcode, dmae->src_addr_lo >> 2,
403 dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
404 dmae->comp_addr_hi, dmae->comp_addr_lo,
405 dmae->comp_val);
406 break;
407 case DMAE_CMD_DST_GRC:
408 if (src_type == DMAE_CMD_SRC_PCI)
409 DP(msglvl, "DMAE: opcode 0x%08x\n"
410 "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
411 "comp_addr [%x:%08x], comp_val 0x%08x\n",
412 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
413 dmae->len, dmae->dst_addr_lo >> 2,
414 dmae->comp_addr_hi, dmae->comp_addr_lo,
415 dmae->comp_val);
416 else
417 DP(msglvl, "DMAE: opcode 0x%08x\n"
418 "src [%08x], len [%d*4], dst [%08x]\n"
419 "comp_addr [%x:%08x], comp_val 0x%08x\n",
420 dmae->opcode, dmae->src_addr_lo >> 2,
421 dmae->len, dmae->dst_addr_lo >> 2,
422 dmae->comp_addr_hi, dmae->comp_addr_lo,
423 dmae->comp_val);
424 break;
425 default:
426 if (src_type == DMAE_CMD_SRC_PCI)
427 DP(msglvl, "DMAE: opcode 0x%08x\n"
428 "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
429 "comp_addr [%x:%08x] comp_val 0x%08x\n",
430 dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
431 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
432 dmae->comp_val);
433 else
434 DP(msglvl, "DMAE: opcode 0x%08x\n"
435 "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
436 "comp_addr [%x:%08x] comp_val 0x%08x\n",
437 dmae->opcode, dmae->src_addr_lo >> 2,
438 dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
439 dmae->comp_val);
440 break;
441 }
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000442
443 for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
444 DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
445 i, *(((u32 *)dmae) + i));
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000446}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000447
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200448/* copy command into DMAE command memory and set DMAE command go */
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000449void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200450{
451 u32 cmd_offset;
452 int i;
453
454 cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
455 for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
456 REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200457 }
458 REG_WR(bp, dmae_reg_go_c[idx], 1);
459}
460
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000461u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
462{
463 return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
464 DMAE_CMD_C_ENABLE);
465}
466
467u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
468{
469 return opcode & ~DMAE_CMD_SRC_RESET;
470}
471
472u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
473 bool with_comp, u8 comp_type)
474{
475 u32 opcode = 0;
476
477 opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
478 (dst_type << DMAE_COMMAND_DST_SHIFT));
479
480 opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
481
482 opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
David S. Miller8decf862011-09-22 03:23:13 -0400483 opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
484 (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000485 opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
486
487#ifdef __BIG_ENDIAN
488 opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
489#else
490 opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
491#endif
492 if (with_comp)
493 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
494 return opcode;
495}
496
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000497void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
stephen hemminger8d962862010-10-21 07:50:56 +0000498 struct dmae_command *dmae,
499 u8 src_type, u8 dst_type)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000500{
501 memset(dmae, 0, sizeof(struct dmae_command));
502
503 /* set the opcode */
504 dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
505 true, DMAE_COMP_PCI);
506
507 /* fill in the completion parameters */
508 dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
509 dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
510 dmae->comp_val = DMAE_COMP_VAL;
511}
512
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000513/* issue a dmae command over the init-channel and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200514int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
515 u32 *comp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000516{
Dmitry Kravkov5e374b52011-05-22 10:09:19 +0000517 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000518 int rc = 0;
519
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000520 bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
521
522 /* Lock the dmae channel. Disable BHs to prevent a dead-lock
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300523 * as long as this code is called both from syscall context and
524 * from ndo_set_rx_mode() flow that may be called from BH.
525 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800526 spin_lock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000527
528 /* reset completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200529 *comp = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000530
531 /* post the command on the channel used for initializations */
532 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
533
534 /* wait for completion */
535 udelay(5);
Ariel Elior32316a42013-10-20 16:51:32 +0200536 while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000537
Ariel Elior95c6c6162012-01-26 06:01:52 +0000538 if (!cnt ||
539 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
540 bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000541 BNX2X_ERR("DMAE timeout!\n");
542 rc = DMAE_TIMEOUT;
543 goto unlock;
544 }
545 cnt--;
546 udelay(50);
547 }
Ariel Elior32316a42013-10-20 16:51:32 +0200548 if (*comp & DMAE_PCI_ERR_FLAG) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000549 BNX2X_ERR("DMAE PCI error!\n");
550 rc = DMAE_PCI_ERROR;
551 }
552
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000553unlock:
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -0800554 spin_unlock_bh(&bp->dmae_lock);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000555 return rc;
556}
557
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700558void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
559 u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200560{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000561 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000562 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700563
564 if (!bp->dmae_ready) {
565 u32 *data = bnx2x_sp(bp, wb_data[0]);
566
Ariel Elior127a4252012-01-26 06:01:46 +0000567 if (CHIP_IS_E1(bp))
568 bnx2x_init_ind_wr(bp, dst_addr, data, len32);
569 else
570 bnx2x_init_str_wr(bp, dst_addr, data, len32);
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700571 return;
572 }
573
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000574 /* set opcode and fixed command fields */
575 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200576
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000577 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000578 dmae.src_addr_lo = U64_LO(dma_addr);
579 dmae.src_addr_hi = U64_HI(dma_addr);
580 dmae.dst_addr_lo = dst_addr >> 2;
581 dmae.dst_addr_hi = 0;
582 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200583
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000584 /* issue the command and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200585 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000586 if (rc) {
587 BNX2X_ERR("DMAE returned failure %d\n", rc);
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200588#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000589 bnx2x_panic();
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200590#endif
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000591 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200592}
593
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700594void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200595{
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000596 int rc;
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000597 struct dmae_command dmae;
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700598
599 if (!bp->dmae_ready) {
600 u32 *data = bnx2x_sp(bp, wb_data[0]);
601 int i;
602
Merav Sicron51c1a582012-03-18 10:33:38 +0000603 if (CHIP_IS_E1(bp))
Ariel Elior127a4252012-01-26 06:01:46 +0000604 for (i = 0; i < len32; i++)
605 data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
Merav Sicron51c1a582012-03-18 10:33:38 +0000606 else
Ariel Elior127a4252012-01-26 06:01:46 +0000607 for (i = 0; i < len32; i++)
608 data[i] = REG_RD(bp, src_addr + i*4);
609
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700610 return;
611 }
612
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000613 /* set opcode and fixed command fields */
614 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200615
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000616 /* fill in addresses and len */
Eilon Greenstein5ff7b6d2009-08-12 08:23:44 +0000617 dmae.src_addr_lo = src_addr >> 2;
618 dmae.src_addr_hi = 0;
619 dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
620 dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
621 dmae.len = len32;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200622
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000623 /* issue the command and wait for completion */
Ariel Elior32316a42013-10-20 16:51:32 +0200624 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000625 if (rc) {
626 BNX2X_ERR("DMAE returned failure %d\n", rc);
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200627#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000628 bnx2x_panic();
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +0200629#endif
Yuval Mintzc957d092013-06-25 08:50:11 +0300630 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200631}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200632
stephen hemminger8d962862010-10-21 07:50:56 +0000633static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
634 u32 addr, u32 len)
Eilon Greenstein573f2032009-08-12 08:24:14 +0000635{
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000636 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
Eilon Greenstein573f2032009-08-12 08:24:14 +0000637 int offset = 0;
638
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000639 while (len > dmae_wr_max) {
Eilon Greenstein573f2032009-08-12 08:24:14 +0000640 bnx2x_write_dmae(bp, phys_addr + offset,
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +0000641 addr + offset, dmae_wr_max);
642 offset += dmae_wr_max * 4;
643 len -= dmae_wr_max;
Eilon Greenstein573f2032009-08-12 08:24:14 +0000644 }
645
646 bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
647}
648
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200649static int bnx2x_mc_assert(struct bnx2x *bp)
650{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200651 char last_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700652 int i, rc = 0;
653 u32 row0, row1, row2, row3;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200654
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700655 /* XSTORM */
656 last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
657 XSTORM_ASSERT_LIST_INDEX_OFFSET);
658 if (last_idx)
659 BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200660
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700661 /* print the asserts */
662 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200663
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700664 row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
665 XSTORM_ASSERT_LIST_OFFSET(i));
666 row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
667 XSTORM_ASSERT_LIST_OFFSET(i) + 4);
668 row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
669 XSTORM_ASSERT_LIST_OFFSET(i) + 8);
670 row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
671 XSTORM_ASSERT_LIST_OFFSET(i) + 12);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200672
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700673 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000674 BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700675 i, row3, row2, row1, row0);
676 rc++;
677 } else {
678 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200679 }
680 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700681
682 /* TSTORM */
683 last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
684 TSTORM_ASSERT_LIST_INDEX_OFFSET);
685 if (last_idx)
686 BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
687
688 /* print the asserts */
689 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
690
691 row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
692 TSTORM_ASSERT_LIST_OFFSET(i));
693 row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
694 TSTORM_ASSERT_LIST_OFFSET(i) + 4);
695 row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
696 TSTORM_ASSERT_LIST_OFFSET(i) + 8);
697 row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
698 TSTORM_ASSERT_LIST_OFFSET(i) + 12);
699
700 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000701 BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700702 i, row3, row2, row1, row0);
703 rc++;
704 } else {
705 break;
706 }
707 }
708
709 /* CSTORM */
710 last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
711 CSTORM_ASSERT_LIST_INDEX_OFFSET);
712 if (last_idx)
713 BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
714
715 /* print the asserts */
716 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
717
718 row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
719 CSTORM_ASSERT_LIST_OFFSET(i));
720 row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
721 CSTORM_ASSERT_LIST_OFFSET(i) + 4);
722 row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
723 CSTORM_ASSERT_LIST_OFFSET(i) + 8);
724 row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
725 CSTORM_ASSERT_LIST_OFFSET(i) + 12);
726
727 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000728 BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700729 i, row3, row2, row1, row0);
730 rc++;
731 } else {
732 break;
733 }
734 }
735
736 /* USTORM */
737 last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
738 USTORM_ASSERT_LIST_INDEX_OFFSET);
739 if (last_idx)
740 BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
741
742 /* print the asserts */
743 for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
744
745 row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
746 USTORM_ASSERT_LIST_OFFSET(i));
747 row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
748 USTORM_ASSERT_LIST_OFFSET(i) + 4);
749 row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
750 USTORM_ASSERT_LIST_OFFSET(i) + 8);
751 row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
752 USTORM_ASSERT_LIST_OFFSET(i) + 12);
753
754 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000755 BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700756 i, row3, row2, row1, row0);
757 rc++;
758 } else {
759 break;
760 }
761 }
762
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200763 return rc;
764}
Eliezer Tamirc14423f2008-02-28 11:49:42 -0800765
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200766#define MCPR_TRACE_BUFFER_SIZE (0x800)
767#define SCRATCH_BUFFER_SIZE(bp) \
768 (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
769
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000770void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200771{
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000772 u32 addr, val;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200773 u32 mark, offset;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000774 __be32 data[9];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200775 int word;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000776 u32 trace_shmem_base;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +0000777 if (BP_NOMCP(bp)) {
778 BNX2X_ERR("NO MCP - can not dump\n");
779 return;
780 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000781 netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
782 (bp->common.bc_ver & 0xff0000) >> 16,
783 (bp->common.bc_ver & 0xff00) >> 8,
784 (bp->common.bc_ver & 0xff));
785
786 val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
787 if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
Merav Sicron51c1a582012-03-18 10:33:38 +0000788 BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000789
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000790 if (BP_PATH(bp) == 0)
791 trace_shmem_base = bp->common.shmem_base;
792 else
793 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200794
795 /* sanity */
796 if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
797 trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
798 SCRATCH_BUFFER_SIZE(bp)) {
799 BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
800 trace_shmem_base);
801 return;
802 }
803
804 addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
Dmitry Kravkovde128802012-03-18 10:33:45 +0000805
806 /* validate TRCB signature */
807 mark = REG_RD(bp, addr);
808 if (mark != MFW_TRACE_SIGNATURE) {
809 BNX2X_ERR("Trace buffer signature is missing.");
810 return ;
811 }
812
813 /* read cyclic buffer pointer */
814 addr += 4;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000815 mark = REG_RD(bp, addr);
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200816 mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
817 if (mark >= trace_shmem_base || mark < addr + 4) {
818 BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
819 return;
820 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000821 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200822
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000823 printk("%s", lvl);
Yuval Mintz2de67432013-01-23 03:21:43 +0000824
825 /* dump buffer after the mark */
Yuval Mintz1a6974b2013-10-20 16:51:27 +0200826 for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200827 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000828 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200829 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000830 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200831 }
Yuval Mintz2de67432013-01-23 03:21:43 +0000832
833 /* dump buffer before the mark */
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000834 for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200835 for (word = 0; word < 8; word++)
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000836 data[word] = htonl(REG_RD(bp, offset + 4*word));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200837 data[8] = 0x0;
Joe Perches7995c642010-02-17 15:01:52 +0000838 pr_cont("%s", (char *)data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200839 }
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000840 printk("%s" "end of fw dump\n", lvl);
841}
842
Eric Dumazet1191cb82012-04-27 21:39:21 +0000843static void bnx2x_fw_dump(struct bnx2x *bp)
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000844{
845 bnx2x_fw_dump_lvl(bp, KERN_ERR);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200846}
847
Yuval Mintz823e1d92013-01-14 05:11:47 +0000848static void bnx2x_hc_int_disable(struct bnx2x *bp)
849{
850 int port = BP_PORT(bp);
851 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
852 u32 val = REG_RD(bp, addr);
853
854 /* in E1 we must use only PCI configuration space to disable
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000855 * MSI/MSIX capability
856 * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
Yuval Mintz823e1d92013-01-14 05:11:47 +0000857 */
858 if (CHIP_IS_E1(bp)) {
859 /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
860 * Use mask register to prevent from HC sending interrupts
861 * after we exit the function
862 */
863 REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
864
865 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
866 HC_CONFIG_0_REG_INT_LINE_EN_0 |
867 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
868 } else
869 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
870 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
871 HC_CONFIG_0_REG_INT_LINE_EN_0 |
872 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
873
874 DP(NETIF_MSG_IFDOWN,
875 "write %x to HC %d (addr 0x%x)\n",
876 val, port, addr);
877
878 /* flush all outstanding writes */
879 mmiowb();
880
881 REG_WR(bp, addr, val);
882 if (REG_RD(bp, addr) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000883 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000884}
885
886static void bnx2x_igu_int_disable(struct bnx2x *bp)
887{
888 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
889
890 val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
891 IGU_PF_CONF_INT_LINE_EN |
892 IGU_PF_CONF_ATTN_BIT_EN);
893
894 DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
895
896 /* flush all outstanding writes */
897 mmiowb();
898
899 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
900 if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
Yuval Mintz6bf07b82013-06-02 00:06:20 +0000901 BNX2X_ERR("BUG! Proper val not read from IGU!\n");
Yuval Mintz823e1d92013-01-14 05:11:47 +0000902}
903
904static void bnx2x_int_disable(struct bnx2x *bp)
905{
906 if (bp->common.int_block == INT_BLOCK_HC)
907 bnx2x_hc_int_disable(bp);
908 else
909 bnx2x_igu_int_disable(bp);
910}
911
912void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200913{
914 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000915 u16 j;
916 struct hc_sp_status_block_data sp_sb_data;
917 int func = BP_FUNC(bp);
918#ifdef BNX2X_STOP_ON_ERROR
919 u16 start = 0, end = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000920 u8 cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000921#endif
Yuval Mintz0155a272014-02-12 18:19:55 +0200922 if (IS_PF(bp) && disable_int)
Yuval Mintz823e1d92013-01-14 05:11:47 +0000923 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200924
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700925 bp->stats_state = STATS_STATE_DISABLED;
Ariel Elior7a752992012-01-26 06:01:53 +0000926 bp->eth_stats.unrecoverable_error++;
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700927 DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
928
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200929 BNX2X_ERR("begin crash dump -----------------\n");
930
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000931 /* Indices */
932 /* Common */
Yuval Mintz0155a272014-02-12 18:19:55 +0200933 if (IS_PF(bp)) {
934 struct host_sp_status_block *def_sb = bp->def_status_blk;
935 int data_size, cstorm_offset;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000936
Yuval Mintz0155a272014-02-12 18:19:55 +0200937 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",
938 bp->def_idx, bp->def_att_idx, bp->attn_state,
939 bp->spq_prod_idx, bp->stats_counter);
940 BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
941 def_sb->atten_status_block.attn_bits,
942 def_sb->atten_status_block.attn_bits_ack,
943 def_sb->atten_status_block.status_block_id,
944 def_sb->atten_status_block.attn_bits_index);
945 BNX2X_ERR(" def (");
946 for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
947 pr_cont("0x%x%s",
948 def_sb->sp_sb.index_values[i],
949 (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000950
Yuval Mintz0155a272014-02-12 18:19:55 +0200951 data_size = sizeof(struct hc_sp_status_block_data) /
952 sizeof(u32);
953 cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
954 for (i = 0; i < data_size; i++)
955 *((u32 *)&sp_sb_data + i) =
956 REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
957 i * sizeof(u32));
958
959 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",
960 sp_sb_data.igu_sb_id,
961 sp_sb_data.igu_seg_id,
962 sp_sb_data.p_func.pf_id,
963 sp_sb_data.p_func.vnic_id,
964 sp_sb_data.p_func.vf_id,
965 sp_sb_data.p_func.vf_valid,
966 sp_sb_data.state);
967 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000968
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000969 for_each_eth_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000970 struct bnx2x_fastpath *fp = &bp->fp[i];
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000971 int loop;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000972 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000973 struct hc_status_block_data_e1x sb_data_e1x;
974 struct hc_status_block_sm *hc_sm_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300975 CHIP_IS_E1x(bp) ?
976 sb_data_e1x.common.state_machine :
977 sb_data_e2.common.state_machine;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000978 struct hc_index_data *hc_index_p =
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300979 CHIP_IS_E1x(bp) ?
980 sb_data_e1x.index_data :
981 sb_data_e2.index_data;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000982 u8 data_size, cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000983 u32 *sb_data_p;
Ariel Elior6383c0b2011-07-14 08:31:57 +0000984 struct bnx2x_fp_txdata txdata;
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000985
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000986 /* Rx */
Merav Sicron51c1a582012-03-18 10:33:38 +0000987 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 +0000988 i, fp->rx_bd_prod, fp->rx_bd_cons,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000989 fp->rx_comp_prod,
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000990 fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
Merav Sicron51c1a582012-03-18 10:33:38 +0000991 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 +0000992 fp->rx_sge_prod, fp->last_max_sge,
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000993 le16_to_cpu(fp->fp_hc_idx));
Eilon Greenstein8440d2b2009-02-12 08:38:22 +0000994
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000995 /* Tx */
Ariel Elior6383c0b2011-07-14 08:31:57 +0000996 for_each_cos_in_tx_queue(fp, cos)
997 {
Merav Sicron65565882012-06-19 07:48:26 +0000998 txdata = *fp->txdata_ptr[cos];
Merav Sicron51c1a582012-03-18 10:33:38 +0000999 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 +00001000 i, txdata.tx_pkt_prod,
1001 txdata.tx_pkt_cons, txdata.tx_bd_prod,
1002 txdata.tx_bd_cons,
1003 le16_to_cpu(*txdata.tx_cons_sb));
1004 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001005
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001006 loop = CHIP_IS_E1x(bp) ?
1007 HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001008
1009 /* host sb data */
1010
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001011 if (IS_FCOE_FP(fp))
1012 continue;
Merav Sicron55c11942012-11-07 00:45:48 +00001013
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001014 BNX2X_ERR(" run indexes (");
1015 for (j = 0; j < HC_SB_MAX_SM; j++)
1016 pr_cont("0x%x%s",
1017 fp->sb_running_index[j],
1018 (j == HC_SB_MAX_SM - 1) ? ")" : " ");
1019
1020 BNX2X_ERR(" indexes (");
1021 for (j = 0; j < loop; j++)
1022 pr_cont("0x%x%s",
1023 fp->sb_index_values[j],
1024 (j == loop - 1) ? ")" : " ");
Yuval Mintz0155a272014-02-12 18:19:55 +02001025
1026 /* VF cannot access FW refelection for status block */
1027 if (IS_VF(bp))
1028 continue;
1029
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001030 /* fw sb data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001031 data_size = CHIP_IS_E1x(bp) ?
1032 sizeof(struct hc_status_block_data_e1x) :
1033 sizeof(struct hc_status_block_data_e2);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001034 data_size /= sizeof(u32);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001035 sb_data_p = CHIP_IS_E1x(bp) ?
1036 (u32 *)&sb_data_e1x :
1037 (u32 *)&sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001038 /* copy sb data in here */
1039 for (j = 0; j < data_size; j++)
1040 *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
1041 CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
1042 j * sizeof(u32));
1043
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001044 if (!CHIP_IS_E1x(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001045 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 +00001046 sb_data_e2.common.p_func.pf_id,
1047 sb_data_e2.common.p_func.vf_id,
1048 sb_data_e2.common.p_func.vf_valid,
1049 sb_data_e2.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001050 sb_data_e2.common.same_igu_sb_1b,
1051 sb_data_e2.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001052 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00001053 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 +00001054 sb_data_e1x.common.p_func.pf_id,
1055 sb_data_e1x.common.p_func.vf_id,
1056 sb_data_e1x.common.p_func.vf_valid,
1057 sb_data_e1x.common.p_func.vnic_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001058 sb_data_e1x.common.same_igu_sb_1b,
1059 sb_data_e1x.common.state);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001060 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001061
1062 /* SB_SMs data */
1063 for (j = 0; j < HC_SB_MAX_SM; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001064 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",
1065 j, hc_sm_p[j].__flags,
1066 hc_sm_p[j].igu_sb_id,
1067 hc_sm_p[j].igu_seg_id,
1068 hc_sm_p[j].time_to_expire,
1069 hc_sm_p[j].timer_value);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001070 }
1071
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001072 /* Indices data */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001073 for (j = 0; j < loop; j++) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001074 pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001075 hc_index_p[j].flags,
1076 hc_index_p[j].timeout);
1077 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001078 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001079
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001080#ifdef BNX2X_STOP_ON_ERROR
Yuval Mintz0155a272014-02-12 18:19:55 +02001081 if (IS_PF(bp)) {
1082 /* event queue */
1083 BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
1084 for (i = 0; i < NUM_EQ_DESC; i++) {
1085 u32 *data = (u32 *)&bp->eq_ring[i].message.data;
Yuval Mintz04c46732013-01-23 03:21:46 +00001086
Yuval Mintz0155a272014-02-12 18:19:55 +02001087 BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
1088 i, bp->eq_ring[i].message.opcode,
1089 bp->eq_ring[i].message.error);
1090 BNX2X_ERR("data: %x %x %x\n",
1091 data[0], data[1], data[2]);
1092 }
Yuval Mintz04c46732013-01-23 03:21:46 +00001093 }
1094
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001095 /* Rings */
1096 /* Rx */
Merav Sicron55c11942012-11-07 00:45:48 +00001097 for_each_valid_rx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001098 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001099
1100 start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
1101 end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001102 for (j = start; j != end; j = RX_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001103 u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
1104 struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
1105
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001106 BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
Yuval Mintz44151ac2012-01-23 07:31:56 +00001107 i, j, rx_bd[1], rx_bd[0], sw_bd->data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001108 }
1109
Eilon Greenstein3196a882008-08-13 15:58:49 -07001110 start = RX_SGE(fp->rx_sge_prod);
1111 end = RX_SGE(fp->last_max_sge);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001112 for (j = start; j != end; j = RX_SGE(j + 1)) {
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001113 u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
1114 struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
1115
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001116 BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
1117 i, j, rx_sge[1], rx_sge[0], sw_page->page);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001118 }
1119
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001120 start = RCQ_BD(fp->rx_comp_cons - 10);
1121 end = RCQ_BD(fp->rx_comp_cons + 503);
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001122 for (j = start; j != end; j = RCQ_BD(j + 1)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001123 u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
1124
Eilon Greensteinc3eefaf2009-03-02 08:01:09 +00001125 BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
1126 i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001127 }
1128 }
1129
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001130 /* Tx */
Merav Sicron55c11942012-11-07 00:45:48 +00001131 for_each_valid_tx_queue(bp, i) {
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001132 struct bnx2x_fastpath *fp = &bp->fp[i];
Ariel Elior6383c0b2011-07-14 08:31:57 +00001133 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00001134 struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001135
Ariel Elior6383c0b2011-07-14 08:31:57 +00001136 start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
1137 end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
1138 for (j = start; j != end; j = TX_BD(j + 1)) {
1139 struct sw_tx_bd *sw_bd =
1140 &txdata->tx_buf_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001141
Merav Sicron51c1a582012-03-18 10:33:38 +00001142 BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001143 i, cos, j, sw_bd->skb,
1144 sw_bd->first_bd);
1145 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001146
Ariel Elior6383c0b2011-07-14 08:31:57 +00001147 start = TX_BD(txdata->tx_bd_cons - 10);
1148 end = TX_BD(txdata->tx_bd_cons + 254);
1149 for (j = start; j != end; j = TX_BD(j + 1)) {
1150 u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001151
Merav Sicron51c1a582012-03-18 10:33:38 +00001152 BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00001153 i, cos, j, tx_bd[0], tx_bd[1],
1154 tx_bd[2], tx_bd[3]);
1155 }
Eilon Greenstein8440d2b2009-02-12 08:38:22 +00001156 }
1157 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001158#endif
Yuval Mintz0155a272014-02-12 18:19:55 +02001159 if (IS_PF(bp)) {
1160 bnx2x_fw_dump(bp);
1161 bnx2x_mc_assert(bp);
1162 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001163 BNX2X_ERR("end crash dump -----------------\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001164}
1165
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001166/*
1167 * FLR Support for E2
1168 *
1169 * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
1170 * initialization.
1171 */
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001172#define FLR_WAIT_USEC 10000 /* 10 milliseconds */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001173#define FLR_WAIT_INTERVAL 50 /* usec */
1174#define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001175
1176struct pbf_pN_buf_regs {
1177 int pN;
1178 u32 init_crd;
1179 u32 crd;
1180 u32 crd_freed;
1181};
1182
1183struct pbf_pN_cmd_regs {
1184 int pN;
1185 u32 lines_occup;
1186 u32 lines_freed;
1187};
1188
1189static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
1190 struct pbf_pN_buf_regs *regs,
1191 u32 poll_count)
1192{
1193 u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
1194 u32 cur_cnt = poll_count;
1195
1196 crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
1197 crd = crd_start = REG_RD(bp, regs->crd);
1198 init_crd = REG_RD(bp, regs->init_crd);
1199
1200 DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
1201 DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
1202 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
1203
1204 while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
1205 (init_crd - crd_start))) {
1206 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001207 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001208 crd = REG_RD(bp, regs->crd);
1209 crd_freed = REG_RD(bp, regs->crd_freed);
1210 } else {
1211 DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
1212 regs->pN);
1213 DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
1214 regs->pN, crd);
1215 DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
1216 regs->pN, crd_freed);
1217 break;
1218 }
1219 }
1220 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001221 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001222}
1223
1224static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
1225 struct pbf_pN_cmd_regs *regs,
1226 u32 poll_count)
1227{
1228 u32 occup, to_free, freed, freed_start;
1229 u32 cur_cnt = poll_count;
1230
1231 occup = to_free = REG_RD(bp, regs->lines_occup);
1232 freed = freed_start = REG_RD(bp, regs->lines_freed);
1233
1234 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
1235 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
1236
1237 while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
1238 if (cur_cnt--) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001239 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001240 occup = REG_RD(bp, regs->lines_occup);
1241 freed = REG_RD(bp, regs->lines_freed);
1242 } else {
1243 DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
1244 regs->pN);
1245 DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
1246 regs->pN, occup);
1247 DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
1248 regs->pN, freed);
1249 break;
1250 }
1251 }
1252 DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
Ariel Elior89db4ad2012-01-26 06:01:48 +00001253 poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001254}
1255
Eric Dumazet1191cb82012-04-27 21:39:21 +00001256static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
1257 u32 expected, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001258{
1259 u32 cur_cnt = poll_count;
1260 u32 val;
1261
1262 while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
Ariel Elior89db4ad2012-01-26 06:01:48 +00001263 udelay(FLR_WAIT_INTERVAL);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001264
1265 return val;
1266}
1267
Ariel Eliord16132c2013-01-01 05:22:42 +00001268int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
1269 char *msg, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001270{
1271 u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
1272 if (val != 0) {
1273 BNX2X_ERR("%s usage count=%d\n", msg, val);
1274 return 1;
1275 }
1276 return 0;
1277}
1278
Ariel Eliord16132c2013-01-01 05:22:42 +00001279/* Common routines with VF FLR cleanup */
1280u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001281{
1282 /* adjust polling timeout */
1283 if (CHIP_REV_IS_EMUL(bp))
1284 return FLR_POLL_CNT * 2000;
1285
1286 if (CHIP_REV_IS_FPGA(bp))
1287 return FLR_POLL_CNT * 120;
1288
1289 return FLR_POLL_CNT;
1290}
1291
Ariel Eliord16132c2013-01-01 05:22:42 +00001292void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001293{
1294 struct pbf_pN_cmd_regs cmd_regs[] = {
1295 {0, (CHIP_IS_E3B0(bp)) ?
1296 PBF_REG_TQ_OCCUPANCY_Q0 :
1297 PBF_REG_P0_TQ_OCCUPANCY,
1298 (CHIP_IS_E3B0(bp)) ?
1299 PBF_REG_TQ_LINES_FREED_CNT_Q0 :
1300 PBF_REG_P0_TQ_LINES_FREED_CNT},
1301 {1, (CHIP_IS_E3B0(bp)) ?
1302 PBF_REG_TQ_OCCUPANCY_Q1 :
1303 PBF_REG_P1_TQ_OCCUPANCY,
1304 (CHIP_IS_E3B0(bp)) ?
1305 PBF_REG_TQ_LINES_FREED_CNT_Q1 :
1306 PBF_REG_P1_TQ_LINES_FREED_CNT},
1307 {4, (CHIP_IS_E3B0(bp)) ?
1308 PBF_REG_TQ_OCCUPANCY_LB_Q :
1309 PBF_REG_P4_TQ_OCCUPANCY,
1310 (CHIP_IS_E3B0(bp)) ?
1311 PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
1312 PBF_REG_P4_TQ_LINES_FREED_CNT}
1313 };
1314
1315 struct pbf_pN_buf_regs buf_regs[] = {
1316 {0, (CHIP_IS_E3B0(bp)) ?
1317 PBF_REG_INIT_CRD_Q0 :
1318 PBF_REG_P0_INIT_CRD ,
1319 (CHIP_IS_E3B0(bp)) ?
1320 PBF_REG_CREDIT_Q0 :
1321 PBF_REG_P0_CREDIT,
1322 (CHIP_IS_E3B0(bp)) ?
1323 PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
1324 PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
1325 {1, (CHIP_IS_E3B0(bp)) ?
1326 PBF_REG_INIT_CRD_Q1 :
1327 PBF_REG_P1_INIT_CRD,
1328 (CHIP_IS_E3B0(bp)) ?
1329 PBF_REG_CREDIT_Q1 :
1330 PBF_REG_P1_CREDIT,
1331 (CHIP_IS_E3B0(bp)) ?
1332 PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
1333 PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
1334 {4, (CHIP_IS_E3B0(bp)) ?
1335 PBF_REG_INIT_CRD_LB_Q :
1336 PBF_REG_P4_INIT_CRD,
1337 (CHIP_IS_E3B0(bp)) ?
1338 PBF_REG_CREDIT_LB_Q :
1339 PBF_REG_P4_CREDIT,
1340 (CHIP_IS_E3B0(bp)) ?
1341 PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
1342 PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
1343 };
1344
1345 int i;
1346
1347 /* Verify the command queues are flushed P0, P1, P4 */
1348 for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
1349 bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
1350
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001351 /* Verify the transmission buffers are flushed P0, P1, P4 */
1352 for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
1353 bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
1354}
1355
1356#define OP_GEN_PARAM(param) \
1357 (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
1358
1359#define OP_GEN_TYPE(type) \
1360 (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
1361
1362#define OP_GEN_AGG_VECT(index) \
1363 (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
1364
Ariel Eliord16132c2013-01-01 05:22:42 +00001365int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001366{
Yuval Mintz86564c32013-01-23 03:21:50 +00001367 u32 op_gen_command = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001368 u32 comp_addr = BAR_CSTRORM_INTMEM +
1369 CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
1370 int ret = 0;
1371
1372 if (REG_RD(bp, comp_addr)) {
Ariel Elior89db4ad2012-01-26 06:01:48 +00001373 BNX2X_ERR("Cleanup complete was not 0 before sending\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001374 return 1;
1375 }
1376
Yuval Mintz86564c32013-01-23 03:21:50 +00001377 op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
1378 op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
1379 op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
1380 op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001381
Ariel Elior89db4ad2012-01-26 06:01:48 +00001382 DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
Yuval Mintz86564c32013-01-23 03:21:50 +00001383 REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001384
1385 if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
1386 BNX2X_ERR("FW final cleanup did not succeed\n");
Merav Sicron51c1a582012-03-18 10:33:38 +00001387 DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
1388 (REG_RD(bp, comp_addr)));
Ariel Eliord16132c2013-01-01 05:22:42 +00001389 bnx2x_panic();
1390 return 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001391 }
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001392 /* Zero completion for next FLR */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001393 REG_WR(bp, comp_addr, 0);
1394
1395 return ret;
1396}
1397
Ariel Eliorb56e9672013-01-01 05:22:32 +00001398u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001399{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001400 u16 status;
1401
Jiang Liu2a80eeb2012-08-20 13:26:51 -06001402 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001403 return status & PCI_EXP_DEVSTA_TRPND;
1404}
1405
1406/* PF FLR specific routines
1407*/
1408static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
1409{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001410 /* wait for CFC PF usage-counter to zero (includes all the VFs) */
1411 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1412 CFC_REG_NUM_LCIDS_INSIDE_PF,
1413 "CFC PF usage counter timed out",
1414 poll_cnt))
1415 return 1;
1416
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001417 /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
1418 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1419 DORQ_REG_PF_USAGE_CNT,
1420 "DQ PF usage counter timed out",
1421 poll_cnt))
1422 return 1;
1423
1424 /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
1425 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1426 QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
1427 "QM PF usage counter timed out",
1428 poll_cnt))
1429 return 1;
1430
1431 /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
1432 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1433 TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
1434 "Timers VNIC usage counter timed out",
1435 poll_cnt))
1436 return 1;
1437 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1438 TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
1439 "Timers NUM_SCANS usage counter timed out",
1440 poll_cnt))
1441 return 1;
1442
1443 /* Wait DMAE PF usage counter to zero */
1444 if (bnx2x_flr_clnup_poll_hw_counter(bp,
1445 dmae_reg_go_c[INIT_DMAE_C(bp)],
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001446 "DMAE command register timed out",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001447 poll_cnt))
1448 return 1;
1449
1450 return 0;
1451}
1452
1453static void bnx2x_hw_enable_status(struct bnx2x *bp)
1454{
1455 u32 val;
1456
1457 val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
1458 DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
1459
1460 val = REG_RD(bp, PBF_REG_DISABLE_PF);
1461 DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
1462
1463 val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
1464 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
1465
1466 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
1467 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
1468
1469 val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
1470 DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
1471
1472 val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
1473 DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
1474
1475 val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
1476 DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
1477
1478 val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1479 DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
1480 val);
1481}
1482
1483static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
1484{
1485 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1486
1487 DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
1488
1489 /* Re-enable PF target read access */
1490 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1491
1492 /* Poll HW usage counters */
Ariel Elior89db4ad2012-01-26 06:01:48 +00001493 DP(BNX2X_MSG_SP, "Polling usage counters\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001494 if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
1495 return -EBUSY;
1496
1497 /* Zero the igu 'trailing edge' and 'leading edge' */
1498
1499 /* Send the FW cleanup command */
1500 if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
1501 return -EBUSY;
1502
1503 /* ATC cleanup */
1504
1505 /* Verify TX hw is flushed */
1506 bnx2x_tx_hw_flushed(bp, poll_cnt);
1507
1508 /* Wait 100ms (not adjusted according to platform) */
1509 msleep(100);
1510
1511 /* Verify no pending pci transactions */
1512 if (bnx2x_is_pcie_pending(bp->pdev))
1513 BNX2X_ERR("PCIE Transactions still pending\n");
1514
1515 /* Debug */
1516 bnx2x_hw_enable_status(bp);
1517
1518 /*
1519 * Master enable - Due to WB DMAE writes performed before this
1520 * register is re-initialized as part of the regular function init
1521 */
1522 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
1523
1524 return 0;
1525}
1526
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001527static void bnx2x_hc_int_enable(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001528{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001529 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001530 u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
1531 u32 val = REG_RD(bp, addr);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001532 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1533 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1534 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001535
1536 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001537 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1538 HC_CONFIG_0_REG_INT_LINE_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001539 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1540 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Dmitry Kravkov69c326b2012-05-02 01:16:33 +00001541 if (single_msix)
1542 val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001543 } else if (msi) {
1544 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
1545 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
1546 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
1547 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001548 } else {
1549 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001550 HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001551 HC_CONFIG_0_REG_INT_LINE_EN_0 |
1552 HC_CONFIG_0_REG_ATTN_BIT_EN_0);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001553
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001554 if (!CHIP_IS_E1(bp)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001555 DP(NETIF_MSG_IFUP,
1556 "write %x to HC %d (addr 0x%x)\n", val, port, addr);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001557
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001558 REG_WR(bp, addr, val);
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08001559
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001560 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
1561 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001562 }
1563
Dmitry Kravkova0fd0652010-10-19 05:13:05 +00001564 if (CHIP_IS_E1(bp))
1565 REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
1566
Merav Sicron51c1a582012-03-18 10:33:38 +00001567 DP(NETIF_MSG_IFUP,
1568 "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
1569 (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001570
1571 REG_WR(bp, addr, val);
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001572 /*
1573 * Ensure that HC_CONFIG is written before leading/trailing edge config
1574 */
1575 mmiowb();
1576 barrier();
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001577
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001578 if (!CHIP_IS_E1(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001579 /* init leading/trailing edge */
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00001580 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001581 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001582 if (bp->port.pmf)
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001583 /* enable nig and gpio3 attention */
1584 val |= 0x1100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001585 } else
1586 val = 0xffff;
1587
1588 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
1589 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
1590 }
Eilon Greenstein37dbbf32009-07-21 05:47:33 +00001591
1592 /* Make sure that interrupts are indeed enabled from here on */
1593 mmiowb();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001594}
1595
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001596static void bnx2x_igu_int_enable(struct bnx2x *bp)
1597{
1598 u32 val;
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001599 bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
1600 bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
1601 bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001602
1603 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
1604
1605 if (msix) {
1606 val &= ~(IGU_PF_CONF_INT_LINE_EN |
1607 IGU_PF_CONF_SINGLE_ISR_EN);
Yuval Mintzebe61d82013-01-14 05:11:48 +00001608 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001609 IGU_PF_CONF_ATTN_BIT_EN);
Dmitry Kravkov30a5de72012-04-03 18:41:26 +00001610
1611 if (single_msix)
1612 val |= IGU_PF_CONF_SINGLE_ISR_EN;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001613 } else if (msi) {
1614 val &= ~IGU_PF_CONF_INT_LINE_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001615 val |= (IGU_PF_CONF_MSI_MSIX_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001616 IGU_PF_CONF_ATTN_BIT_EN |
1617 IGU_PF_CONF_SINGLE_ISR_EN);
1618 } else {
1619 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
Yuval Mintzebe61d82013-01-14 05:11:48 +00001620 val |= (IGU_PF_CONF_INT_LINE_EN |
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001621 IGU_PF_CONF_ATTN_BIT_EN |
1622 IGU_PF_CONF_SINGLE_ISR_EN);
1623 }
1624
Yuval Mintzebe61d82013-01-14 05:11:48 +00001625 /* Clean previous status - need to configure igu prior to ack*/
1626 if ((!msix) || single_msix) {
1627 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1628 bnx2x_ack_int(bp);
1629 }
1630
1631 val |= IGU_PF_CONF_FUNC_EN;
1632
Merav Sicron51c1a582012-03-18 10:33:38 +00001633 DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001634 val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
1635
1636 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
1637
Yuval Mintz79a85572012-04-03 18:41:25 +00001638 if (val & IGU_PF_CONF_INT_LINE_EN)
1639 pci_intx(bp->pdev, true);
1640
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001641 barrier();
1642
1643 /* init leading/trailing edge */
1644 if (IS_MF(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04001645 val = (0xee0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001646 if (bp->port.pmf)
1647 /* enable nig and gpio3 attention */
1648 val |= 0x1100;
1649 } else
1650 val = 0xffff;
1651
1652 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
1653 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
1654
1655 /* Make sure that interrupts are indeed enabled from here on */
1656 mmiowb();
1657}
1658
1659void bnx2x_int_enable(struct bnx2x *bp)
1660{
1661 if (bp->common.int_block == INT_BLOCK_HC)
1662 bnx2x_hc_int_enable(bp);
1663 else
1664 bnx2x_igu_int_enable(bp);
1665}
1666
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001667void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001668{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001669 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
Eilon Greenstein8badd272009-02-12 08:36:15 +00001670 int i, offset;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001671
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -07001672 if (disable_hw)
1673 /* prevent the HW from sending interrupts */
1674 bnx2x_int_disable(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001675
1676 /* make sure all ISRs are done */
1677 if (msix) {
Eilon Greenstein8badd272009-02-12 08:36:15 +00001678 synchronize_irq(bp->msix_table[0].vector);
1679 offset = 1;
Merav Sicron55c11942012-11-07 00:45:48 +00001680 if (CNIC_SUPPORT(bp))
1681 offset++;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001682 for_each_eth_queue(bp, i)
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001683 synchronize_irq(bp->msix_table[offset++].vector);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001684 } else
1685 synchronize_irq(bp->pdev->irq);
1686
1687 /* make sure sp_task is not running */
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001688 cancel_delayed_work(&bp->sp_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00001689 cancel_delayed_work(&bp->period_task);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08001690 flush_workqueue(bnx2x_wq);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001691}
1692
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001693/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001694
1695/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001696 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001697 */
1698
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001699/* Return true if succeeded to acquire the lock */
1700static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
1701{
1702 u32 lock_status;
1703 u32 resource_bit = (1 << resource);
1704 int func = BP_FUNC(bp);
1705 u32 hw_lock_control_reg;
1706
Merav Sicron51c1a582012-03-18 10:33:38 +00001707 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1708 "Trying to take a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001709
1710 /* Validating that the resource is within range */
1711 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001712 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001713 "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
1714 resource, HW_LOCK_MAX_RESOURCE_VALUE);
Eric Dumazet0fdf4d02010-08-26 22:03:53 -07001715 return false;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001716 }
1717
1718 if (func <= 5)
1719 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1720 else
1721 hw_lock_control_reg =
1722 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1723
1724 /* Try to acquire the lock */
1725 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
1726 lock_status = REG_RD(bp, hw_lock_control_reg);
1727 if (lock_status & resource_bit)
1728 return true;
1729
Merav Sicron51c1a582012-03-18 10:33:38 +00001730 DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
1731 "Failed to get a lock on resource %d\n", resource);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001732 return false;
1733}
1734
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001735/**
1736 * bnx2x_get_leader_lock_resource - get the recovery leader resource id
1737 *
1738 * @bp: driver handle
1739 *
1740 * Returns the recovery leader resource id according to the engine this function
1741 * belongs to. Currently only only 2 engines is supported.
1742 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001743static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001744{
1745 if (BP_PATH(bp))
1746 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
1747 else
1748 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
1749}
1750
1751/**
Yuval Mintz2de67432013-01-23 03:21:43 +00001752 * bnx2x_trylock_leader_lock- try to acquire a leader lock.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001753 *
1754 * @bp: driver handle
1755 *
Yuval Mintz2de67432013-01-23 03:21:43 +00001756 * Tries to acquire a leader lock for current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001757 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00001758static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00001759{
1760 return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
1761}
1762
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001763static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
Merav Sicron55c11942012-11-07 00:45:48 +00001764
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001765/* schedule the sp task and mark that interrupt occurred (runs from ISR) */
1766static int bnx2x_schedule_sp_task(struct bnx2x *bp)
1767{
1768 /* Set the interrupt occurred bit for the sp-task to recognize it
1769 * must ack the interrupt and transition according to the IGU
1770 * state machine.
1771 */
1772 atomic_set(&bp->interrupt_occurred, 1);
1773
1774 /* The sp_task must execute only after this bit
1775 * is set, otherwise we will get out of sync and miss all
1776 * further interrupts. Hence, the barrier.
1777 */
1778 smp_wmb();
1779
1780 /* schedule sp_task to workqueue */
1781 return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1782}
Eilon Greenstein3196a882008-08-13 15:58:49 -07001783
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001784void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001785{
1786 struct bnx2x *bp = fp->bp;
1787 int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
1788 int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001789 enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
Barak Witkowski15192a82012-06-19 07:48:28 +00001790 struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001791
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001792 DP(BNX2X_MSG_SP,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001793 "fp %d cid %d got ramrod #%d state is %x type is %d\n",
Eilon Greenstein0626b892009-02-12 08:38:14 +00001794 fp->index, cid, command, bp->state,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001795 rr_cqe->ramrod_cqe.ramrod_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001796
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001797 /* If cid is within VF range, replace the slowpath object with the
1798 * one corresponding to this VF
1799 */
1800 if (cid >= BNX2X_FIRST_VF_CID &&
1801 cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
1802 bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
1803
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001804 switch (command) {
1805 case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001806 DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001807 drv_cmd = BNX2X_Q_CMD_UPDATE;
1808 break;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001809
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001810 case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001811 DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001812 drv_cmd = BNX2X_Q_CMD_SETUP;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001813 break;
1814
Ariel Elior6383c0b2011-07-14 08:31:57 +00001815 case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
Merav Sicron51c1a582012-03-18 10:33:38 +00001816 DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
Ariel Elior6383c0b2011-07-14 08:31:57 +00001817 drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
1818 break;
1819
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001820 case (RAMROD_CMD_ID_ETH_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001821 DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001822 drv_cmd = BNX2X_Q_CMD_HALT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001823 break;
1824
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001825 case (RAMROD_CMD_ID_ETH_TERMINATE):
Yuval Mintz6bf07b82013-06-02 00:06:20 +00001826 DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001827 drv_cmd = BNX2X_Q_CMD_TERMINATE;
1828 break;
1829
1830 case (RAMROD_CMD_ID_ETH_EMPTY):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001831 DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001832 drv_cmd = BNX2X_Q_CMD_EMPTY;
Eliezer Tamir49d66772008-02-28 11:53:13 -08001833 break;
1834
Michal Kalderon14a94eb2014-02-12 18:19:53 +02001835 case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
1836 DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
1837 drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
1838 break;
1839
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001840 default:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001841 BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
1842 command, fp->index);
1843 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001844 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001845
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001846 if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
1847 q_obj->complete_cmd(bp, q_obj, drv_cmd))
1848 /* q_obj->complete_cmd() failure means that this was
1849 * an unexpected completion.
1850 *
1851 * In this case we don't want to increase the bp->spq_left
1852 * because apparently we haven't sent this command the first
1853 * place.
1854 */
1855#ifdef BNX2X_STOP_ON_ERROR
1856 bnx2x_panic();
1857#else
1858 return;
1859#endif
1860
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001861 smp_mb__before_atomic();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08001862 atomic_inc(&bp->cq_spq_left);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001863 /* push the change in bp->spq_left and towards the memory */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001864 smp_mb__after_atomic();
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001865
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00001866 DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
1867
Barak Witkowskia3348722012-04-23 03:04:46 +00001868 if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
1869 (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
1870 /* if Q update ramrod is completed for last Q in AFEX vif set
1871 * flow, then ACK MCP at the end
1872 *
1873 * mark pending ACK to MCP bit.
1874 * prevent case that both bits are cleared.
1875 * At the end of load/unload driver checks that
Yuval Mintz2de67432013-01-23 03:21:43 +00001876 * sp_state is cleared, and this order prevents
Barak Witkowskia3348722012-04-23 03:04:46 +00001877 * races
1878 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001879 smp_mb__before_atomic();
Barak Witkowskia3348722012-04-23 03:04:46 +00001880 set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
1881 wmb();
1882 clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001883 smp_mb__after_atomic();
Barak Witkowskia3348722012-04-23 03:04:46 +00001884
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001885 /* schedule the sp task as mcp ack is required */
1886 bnx2x_schedule_sp_task(bp);
Barak Witkowskia3348722012-04-23 03:04:46 +00001887 }
1888
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001889 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001890}
1891
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001892irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001893{
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001894 struct bnx2x *bp = netdev_priv(dev_instance);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001895 u16 status = bnx2x_ack_int(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001896 u16 mask;
Eilon Greensteinca003922009-08-12 22:53:28 -07001897 int i;
Ariel Elior6383c0b2011-07-14 08:31:57 +00001898 u8 cos;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001899
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001900 /* Return here if interrupt is shared and it's not for us */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001901 if (unlikely(status == 0)) {
1902 DP(NETIF_MSG_INTR, "not our interrupt!\n");
1903 return IRQ_NONE;
1904 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00001905 DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001906
Eilon Greenstein3196a882008-08-13 15:58:49 -07001907#ifdef BNX2X_STOP_ON_ERROR
1908 if (unlikely(bp->panic))
1909 return IRQ_HANDLED;
1910#endif
1911
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001912 for_each_eth_queue(bp, i) {
Eilon Greensteinca003922009-08-12 22:53:28 -07001913 struct bnx2x_fastpath *fp = &bp->fp[i];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001914
Merav Sicron55c11942012-11-07 00:45:48 +00001915 mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
Eilon Greensteinca003922009-08-12 22:53:28 -07001916 if (status & mask) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001917 /* Handle Rx or Tx according to SB id */
Ariel Elior6383c0b2011-07-14 08:31:57 +00001918 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00001919 prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001920 prefetch(&fp->sb_running_index[SM_RX_ID]);
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001921 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
Eilon Greensteinca003922009-08-12 22:53:28 -07001922 status &= ~mask;
1923 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001924 }
1925
Merav Sicron55c11942012-11-07 00:45:48 +00001926 if (CNIC_SUPPORT(bp)) {
1927 mask = 0x2;
1928 if (status & (mask | 0x1)) {
1929 struct cnic_ops *c_ops = NULL;
Michael Chan993ac7b2009-10-10 13:46:56 +00001930
Michael Chanad9b4352013-01-23 03:21:52 +00001931 rcu_read_lock();
1932 c_ops = rcu_dereference(bp->cnic_ops);
1933 if (c_ops && (bp->cnic_eth_dev.drv_state &
1934 CNIC_DRV_STATE_HANDLES_IRQ))
1935 c_ops->cnic_handler(bp->cnic_data, NULL);
1936 rcu_read_unlock();
Merav Sicron55c11942012-11-07 00:45:48 +00001937
1938 status &= ~mask;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001939 }
Michael Chan993ac7b2009-10-10 13:46:56 +00001940 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001941
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001942 if (unlikely(status & 0x1)) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00001943
1944 /* schedule sp task to perform default status block work, ack
1945 * attentions and enable interrupts.
1946 */
1947 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001948
1949 status &= ~0x1;
1950 if (!status)
1951 return IRQ_HANDLED;
1952 }
1953
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00001954 if (unlikely(status))
1955 DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001956 status);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001957
1958 return IRQ_HANDLED;
1959}
1960
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001961/* Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001962
1963/*
1964 * General service functions
1965 */
1966
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00001967int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08001968{
Eliezer Tamirf1410642008-02-28 11:51:50 -08001969 u32 lock_status;
1970 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001971 int func = BP_FUNC(bp);
1972 u32 hw_lock_control_reg;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001973 int cnt;
Eliezer Tamirf1410642008-02-28 11:51:50 -08001974
1975 /* Validating that the resource is within range */
1976 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001977 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001978 resource, HW_LOCK_MAX_RESOURCE_VALUE);
1979 return -EINVAL;
1980 }
1981
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001982 if (func <= 5) {
1983 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
1984 } else {
1985 hw_lock_control_reg =
1986 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
1987 }
1988
Eliezer Tamirf1410642008-02-28 11:51:50 -08001989 /* Validating that the resource is not already taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07001990 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08001991 if (lock_status & resource_bit) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001992 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08001993 lock_status, resource_bit);
1994 return -EEXIST;
1995 }
1996
Eilon Greenstein46230476b2008-08-25 15:23:30 -07001997 /* Try for 5 second every 5ms */
1998 for (cnt = 0; cnt < 1000; cnt++) {
Eliezer Tamirf1410642008-02-28 11:51:50 -08001999 /* Try to acquire the lock */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002000 REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
2001 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002002 if (lock_status & resource_bit)
2003 return 0;
2004
Yuval Mintz639d65b2013-06-02 00:06:21 +00002005 usleep_range(5000, 10000);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002006 }
Merav Sicron51c1a582012-03-18 10:33:38 +00002007 BNX2X_ERR("Timeout\n");
Eliezer Tamirf1410642008-02-28 11:51:50 -08002008 return -EAGAIN;
2009}
2010
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00002011int bnx2x_release_leader_lock(struct bnx2x *bp)
2012{
2013 return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
2014}
2015
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002016int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002017{
2018 u32 lock_status;
2019 u32 resource_bit = (1 << resource);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002020 int func = BP_FUNC(bp);
2021 u32 hw_lock_control_reg;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002022
2023 /* Validating that the resource is within range */
2024 if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002025 BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002026 resource, HW_LOCK_MAX_RESOURCE_VALUE);
2027 return -EINVAL;
2028 }
2029
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002030 if (func <= 5) {
2031 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
2032 } else {
2033 hw_lock_control_reg =
2034 (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
2035 }
2036
Eliezer Tamirf1410642008-02-28 11:51:50 -08002037 /* Validating that the resource is currently taken */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002038 lock_status = REG_RD(bp, hw_lock_control_reg);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002039 if (!(lock_status & resource_bit)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00002040 BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
2041 lock_status, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002042 return -EFAULT;
2043 }
2044
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002045 REG_WR(bp, hw_lock_control_reg, resource_bit);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002046 return 0;
2047}
2048
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002049int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
2050{
2051 /* The GPIO should be swapped if swap register is set and active */
2052 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2053 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2054 int gpio_shift = gpio_num +
2055 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2056 u32 gpio_mask = (1 << gpio_shift);
2057 u32 gpio_reg;
2058 int value;
2059
2060 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2061 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2062 return -EINVAL;
2063 }
2064
2065 /* read GPIO value */
2066 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2067
2068 /* get the requested pin value */
2069 if ((gpio_reg & gpio_mask) == gpio_mask)
2070 value = 1;
2071 else
2072 value = 0;
2073
2074 DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
2075
2076 return value;
2077}
2078
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002079int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002080{
2081 /* The GPIO should be swapped if swap register is set and active */
2082 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002083 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002084 int gpio_shift = gpio_num +
2085 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2086 u32 gpio_mask = (1 << gpio_shift);
2087 u32 gpio_reg;
2088
2089 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2090 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2091 return -EINVAL;
2092 }
2093
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002094 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002095 /* read GPIO and mask except the float bits */
2096 gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
2097
2098 switch (mode) {
2099 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
Merav Sicron51c1a582012-03-18 10:33:38 +00002100 DP(NETIF_MSG_LINK,
2101 "Set GPIO %d (shift %d) -> output low\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002102 gpio_num, gpio_shift);
2103 /* clear FLOAT and set CLR */
2104 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2105 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
2106 break;
2107
2108 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
Merav Sicron51c1a582012-03-18 10:33:38 +00002109 DP(NETIF_MSG_LINK,
2110 "Set GPIO %d (shift %d) -> output high\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002111 gpio_num, gpio_shift);
2112 /* clear FLOAT and set SET */
2113 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2114 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
2115 break;
2116
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002117 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
Merav Sicron51c1a582012-03-18 10:33:38 +00002118 DP(NETIF_MSG_LINK,
2119 "Set GPIO %d (shift %d) -> input\n",
Eliezer Tamirf1410642008-02-28 11:51:50 -08002120 gpio_num, gpio_shift);
2121 /* set FLOAT */
2122 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
2123 break;
2124
2125 default:
2126 break;
2127 }
2128
2129 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002130 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002131
2132 return 0;
2133}
2134
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00002135int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
2136{
2137 u32 gpio_reg = 0;
2138 int rc = 0;
2139
2140 /* Any port swapping should be handled by caller. */
2141
2142 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2143 /* read GPIO and mask except the float bits */
2144 gpio_reg = REG_RD(bp, MISC_REG_GPIO);
2145 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2146 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
2147 gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
2148
2149 switch (mode) {
2150 case MISC_REGISTERS_GPIO_OUTPUT_LOW:
2151 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
2152 /* set CLR */
2153 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
2154 break;
2155
2156 case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
2157 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
2158 /* set SET */
2159 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
2160 break;
2161
2162 case MISC_REGISTERS_GPIO_INPUT_HI_Z:
2163 DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
2164 /* set FLOAT */
2165 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
2166 break;
2167
2168 default:
2169 BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
2170 rc = -EINVAL;
2171 break;
2172 }
2173
2174 if (rc == 0)
2175 REG_WR(bp, MISC_REG_GPIO, gpio_reg);
2176
2177 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2178
2179 return rc;
2180}
2181
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002182int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
2183{
2184 /* The GPIO should be swapped if swap register is set and active */
2185 int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
2186 REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
2187 int gpio_shift = gpio_num +
2188 (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
2189 u32 gpio_mask = (1 << gpio_shift);
2190 u32 gpio_reg;
2191
2192 if (gpio_num > MISC_REGISTERS_GPIO_3) {
2193 BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
2194 return -EINVAL;
2195 }
2196
2197 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2198 /* read GPIO int */
2199 gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
2200
2201 switch (mode) {
2202 case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
Merav Sicron51c1a582012-03-18 10:33:38 +00002203 DP(NETIF_MSG_LINK,
2204 "Clear GPIO INT %d (shift %d) -> output low\n",
2205 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002206 /* clear SET and set CLR */
2207 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2208 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2209 break;
2210
2211 case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
Merav Sicron51c1a582012-03-18 10:33:38 +00002212 DP(NETIF_MSG_LINK,
2213 "Set GPIO INT %d (shift %d) -> output high\n",
2214 gpio_num, gpio_shift);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00002215 /* clear CLR and set SET */
2216 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
2217 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
2218 break;
2219
2220 default:
2221 break;
2222 }
2223
2224 REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
2225 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
2226
2227 return 0;
2228}
2229
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002230static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
Eliezer Tamirf1410642008-02-28 11:51:50 -08002231{
Eliezer Tamirf1410642008-02-28 11:51:50 -08002232 u32 spio_reg;
2233
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002234 /* Only 2 SPIOs are configurable */
2235 if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
2236 BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002237 return -EINVAL;
2238 }
2239
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002240 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002241 /* read SPIO and mask except the float bits */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002242 spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002243
2244 switch (mode) {
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002245 case MISC_SPIO_OUTPUT_LOW:
2246 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002247 /* clear FLOAT and set CLR */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002248 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2249 spio_reg |= (spio << MISC_SPIO_CLR_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002250 break;
2251
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002252 case MISC_SPIO_OUTPUT_HIGH:
2253 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002254 /* clear FLOAT and set SET */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002255 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
2256 spio_reg |= (spio << MISC_SPIO_SET_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002257 break;
2258
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002259 case MISC_SPIO_INPUT_HI_Z:
2260 DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002261 /* set FLOAT */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00002262 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002263 break;
2264
2265 default:
2266 break;
2267 }
2268
2269 REG_WR(bp, MISC_REG_SPIO, spio_reg);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002270 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002271
2272 return 0;
2273}
2274
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002275void bnx2x_calc_fc_adv(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002276{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002277 u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
Eilon Greensteinad33ea32009-01-14 21:24:57 -08002278 switch (bp->link_vars.ieee_fc &
2279 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002280 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002281 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002282 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002283 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002284
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002285 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002286 bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002287 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002288 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002289
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002290 case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002291 bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
Eliezer Tamirf1410642008-02-28 11:51:50 -08002292 break;
Eilon Greenstein356e2382009-02-12 08:38:32 +00002293
Eliezer Tamirf1410642008-02-28 11:51:50 -08002294 default:
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002295 bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002296 ADVERTISED_Pause);
Eliezer Tamirf1410642008-02-28 11:51:50 -08002297 break;
2298 }
2299}
2300
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002301static void bnx2x_set_requested_fc(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002302{
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002303 /* Initialize link parameters structure variables
2304 * It is recommended to turn off RX FC for jumbo frames
2305 * for better performance
2306 */
2307 if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
2308 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
2309 else
2310 bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
2311}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002312
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002313static void bnx2x_init_dropless_fc(struct bnx2x *bp)
2314{
2315 u32 pause_enabled = 0;
2316
2317 if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
2318 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
2319 pause_enabled = 1;
2320
2321 REG_WR(bp, BAR_USTRORM_INTMEM +
2322 USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
2323 pause_enabled);
2324 }
2325
2326 DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
2327 pause_enabled ? "enabled" : "disabled");
2328}
2329
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002330int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
2331{
2332 int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
2333 u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
2334
2335 if (!BP_NOMCP(bp)) {
2336 bnx2x_set_requested_fc(bp);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002337 bnx2x_acquire_phy_lock(bp);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002338
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002339 if (load_mode == LOAD_DIAG) {
Yaniv Rosner1cb0c782011-07-24 03:53:21 +00002340 struct link_params *lp = &bp->link_params;
2341 lp->loopback_mode = LOOPBACK_XGXS;
2342 /* do PHY loopback at 10G speed, if possible */
2343 if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
2344 if (lp->speed_cap_mask[cfx_idx] &
2345 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2346 lp->req_line_speed[cfx_idx] =
2347 SPEED_10000;
2348 else
2349 lp->req_line_speed[cfx_idx] =
2350 SPEED_1000;
2351 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002352 }
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002353
Merav Sicron8970b2e2012-06-19 07:48:22 +00002354 if (load_mode == LOAD_LOOPBACK_EXT) {
2355 struct link_params *lp = &bp->link_params;
2356 lp->loopback_mode = LOOPBACK_EXT;
2357 }
2358
Eilon Greenstein19680c42008-08-13 15:47:33 -07002359 rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002360
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002361 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002362
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002363 bnx2x_init_dropless_fc(bp);
2364
Eilon Greenstein3c96c682009-01-14 21:25:31 -08002365 bnx2x_calc_fc_adv(bp);
2366
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002367 if (bp->link_vars.link_up) {
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00002368 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002369 bnx2x_link_report(bp);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +00002370 }
2371 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002372 bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
Eilon Greenstein19680c42008-08-13 15:47:33 -07002373 return rc;
2374 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00002375 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
Eilon Greenstein19680c42008-08-13 15:47:33 -07002376 return -EINVAL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002377}
2378
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002379void bnx2x_link_set(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002380{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002381 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002382 bnx2x_acquire_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002383 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002384 bnx2x_release_phy_lock(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002385
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002386 bnx2x_init_dropless_fc(bp);
2387
Eilon Greenstein19680c42008-08-13 15:47:33 -07002388 bnx2x_calc_fc_adv(bp);
2389 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002390 BNX2X_ERR("Bootcode is missing - can not set link\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002391}
2392
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002393static void bnx2x__link_reset(struct bnx2x *bp)
2394{
Eilon Greenstein19680c42008-08-13 15:47:33 -07002395 if (!BP_NOMCP(bp)) {
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002396 bnx2x_acquire_phy_lock(bp);
Yuval Mintz5d07d862012-09-13 02:56:21 +00002397 bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07002398 bnx2x_release_phy_lock(bp);
Eilon Greenstein19680c42008-08-13 15:47:33 -07002399 } else
Eilon Greensteinf5372252009-02-12 08:38:30 +00002400 BNX2X_ERR("Bootcode is missing - can not reset link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002401}
2402
Yuval Mintz5d07d862012-09-13 02:56:21 +00002403void bnx2x_force_link_reset(struct bnx2x *bp)
2404{
2405 bnx2x_acquire_phy_lock(bp);
2406 bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
2407 bnx2x_release_phy_lock(bp);
2408}
2409
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002410u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002411{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002412 u8 rc = 0;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002413
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002414 if (!BP_NOMCP(bp)) {
2415 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002416 rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
2417 is_serdes);
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00002418 bnx2x_release_phy_lock(bp);
2419 } else
2420 BNX2X_ERR("Bootcode is missing - can not test link\n");
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002421
2422 return rc;
2423}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002424
Eilon Greenstein2691d512009-08-12 08:22:08 +00002425/* Calculates the sum of vn_min_rates.
2426 It's needed for further normalizing of the min_rates.
2427 Returns:
2428 sum of vn_min_rates.
2429 or
2430 0 - if all the min_rates are 0.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002431 In the later case fairness algorithm should be deactivated.
Eilon Greenstein2691d512009-08-12 08:22:08 +00002432 If not all min_rates are zero then those that are zeroes will be set to 1.
2433 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002434static void bnx2x_calc_vn_min(struct bnx2x *bp,
2435 struct cmng_init_input *input)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002436{
2437 int all_zero = 1;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002438 int vn;
2439
David S. Miller8decf862011-09-22 03:23:13 -04002440 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002441 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein2691d512009-08-12 08:22:08 +00002442 u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
2443 FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
2444
2445 /* Skip hidden vns */
2446 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Yuval Mintzb475d782012-04-03 18:41:29 +00002447 vn_min_rate = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002448 /* If min rate is zero - set it to 1 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002449 else if (!vn_min_rate)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002450 vn_min_rate = DEF_MIN_RATE;
2451 else
2452 all_zero = 0;
2453
Yuval Mintzb475d782012-04-03 18:41:29 +00002454 input->vnic_min_rate[vn] = vn_min_rate;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002455 }
2456
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002457 /* if ETS or all min rates are zeros - disable fairness */
2458 if (BNX2X_IS_ETS_ENABLED(bp)) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002459 input->flags.cmng_enables &=
Dmitry Kravkov30ae438b2011-06-14 01:33:13 +00002460 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
2461 DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
2462 } else if (all_zero) {
Yuval Mintzb475d782012-04-03 18:41:29 +00002463 input->flags.cmng_enables &=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002464 ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002465 DP(NETIF_MSG_IFUP,
2466 "All MIN values are zeroes fairness will be disabled\n");
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002467 } else
Yuval Mintzb475d782012-04-03 18:41:29 +00002468 input->flags.cmng_enables |=
Eilon Greensteinb015e3d2009-10-15 00:17:20 -07002469 CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002470}
2471
Yuval Mintzb475d782012-04-03 18:41:29 +00002472static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
2473 struct cmng_init_input *input)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002474{
Yuval Mintzb475d782012-04-03 18:41:29 +00002475 u16 vn_max_rate;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002476 u32 vn_cfg = bp->mf_config[vn];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002477
Yuval Mintzb475d782012-04-03 18:41:29 +00002478 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002479 vn_max_rate = 0;
Yuval Mintzb475d782012-04-03 18:41:29 +00002480 else {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002481 u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
2482
Yuval Mintzb475d782012-04-03 18:41:29 +00002483 if (IS_MF_SI(bp)) {
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002484 /* maxCfg in percents of linkspeed */
2485 vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
Yuval Mintzb475d782012-04-03 18:41:29 +00002486 } else /* SD modes */
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +00002487 /* maxCfg is absolute in 100Mb units */
2488 vn_max_rate = maxCfg * 100;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002489 }
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002490
Yuval Mintzb475d782012-04-03 18:41:29 +00002491 DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002492
Yuval Mintzb475d782012-04-03 18:41:29 +00002493 input->vnic_max_rate[vn] = vn_max_rate;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002494}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002495
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002496static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
2497{
2498 if (CHIP_REV_IS_SLOW(bp))
2499 return CMNG_FNS_NONE;
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00002500 if (IS_MF(bp))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002501 return CMNG_FNS_MINMAX;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002502
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002503 return CMNG_FNS_NONE;
2504}
2505
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002506void bnx2x_read_mf_cfg(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002507{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002508 int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002509
2510 if (BP_NOMCP(bp))
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002511 return; /* what should be the default value in this case */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002512
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002513 /* For 2 port configuration the absolute function number formula
2514 * is:
2515 * abs_func = 2 * vn + BP_PORT + BP_PATH
2516 *
2517 * and there are 4 functions per port
2518 *
2519 * For 4 port configuration it is
2520 * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
2521 *
2522 * and there are 2 functions per port
2523 */
David S. Miller8decf862011-09-22 03:23:13 -04002524 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08002525 int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
2526
2527 if (func >= E1H_FUNC_MAX)
2528 break;
2529
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002530 bp->mf_config[vn] =
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002531 MF_CFG_RD(bp, func_mf_config[func].config);
2532 }
Barak Witkowskia3348722012-04-23 03:04:46 +00002533 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
2534 DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
2535 bp->flags |= MF_FUNC_DIS;
2536 } else {
2537 DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
2538 bp->flags &= ~MF_FUNC_DIS;
2539 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002540}
2541
2542static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
2543{
Yuval Mintzb475d782012-04-03 18:41:29 +00002544 struct cmng_init_input input;
2545 memset(&input, 0, sizeof(struct cmng_init_input));
2546
2547 input.port_rate = bp->link_vars.line_speed;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002548
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002549 if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002550 int vn;
2551
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002552 /* read mf conf from shmem */
2553 if (read_cfg)
2554 bnx2x_read_mf_cfg(bp);
2555
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002556 /* vn_weight_sum and enable fairness if not 0 */
Yuval Mintzb475d782012-04-03 18:41:29 +00002557 bnx2x_calc_vn_min(bp, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002558
2559 /* calculate and set min-max rate for each vn */
Dmitry Kravkovc4154f22011-03-06 10:49:25 +00002560 if (bp->port.pmf)
David S. Miller8decf862011-09-22 03:23:13 -04002561 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
Yuval Mintzb475d782012-04-03 18:41:29 +00002562 bnx2x_calc_vn_max(bp, vn, &input);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002563
2564 /* always enable rate shaping and fairness */
Yuval Mintzb475d782012-04-03 18:41:29 +00002565 input.flags.cmng_enables |=
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002566 CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
Yuval Mintzb475d782012-04-03 18:41:29 +00002567
2568 bnx2x_init_cmng(&input, &bp->cmng);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002569 return;
2570 }
2571
2572 /* rate shaping and fairness are disabled */
2573 DP(NETIF_MSG_IFUP,
2574 "rate shaping and fairness are disabled\n");
2575}
2576
Eric Dumazet1191cb82012-04-27 21:39:21 +00002577static void storm_memset_cmng(struct bnx2x *bp,
2578 struct cmng_init *cmng,
2579 u8 port)
2580{
2581 int vn;
2582 size_t size = sizeof(struct cmng_struct_per_port);
2583
2584 u32 addr = BAR_XSTRORM_INTMEM +
2585 XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
2586
2587 __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
2588
2589 for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
2590 int func = func_by_vn(bp, vn);
2591
2592 addr = BAR_XSTRORM_INTMEM +
2593 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
2594 size = sizeof(struct rate_shaping_vars_per_vn);
2595 __storm_memset_struct(bp, addr, size,
2596 (u32 *)&cmng->vnic.vnic_max_rate[vn]);
2597
2598 addr = BAR_XSTRORM_INTMEM +
2599 XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
2600 size = sizeof(struct fairness_vars_per_vn);
2601 __storm_memset_struct(bp, addr, size,
2602 (u32 *)&cmng->vnic.vnic_min_rate[vn]);
2603 }
2604}
2605
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002606/* init cmng mode in HW according to local configuration */
2607void bnx2x_set_local_cmng(struct bnx2x *bp)
2608{
2609 int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
2610
2611 if (cmng_fns != CMNG_FNS_NONE) {
2612 bnx2x_cmng_fns_init(bp, false, cmng_fns);
2613 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
2614 } else {
2615 /* rate shaping and fairness are disabled */
2616 DP(NETIF_MSG_IFUP,
2617 "single function mode without fairness\n");
2618 }
2619}
2620
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002621/* This function is called upon link interrupt */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002622static void bnx2x_link_attn(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002623{
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002624 /* Make sure that we are synced with the current statistics */
2625 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2626
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002627 bnx2x_link_update(&bp->link_params, &bp->link_vars);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002628
Dmitry Kravkov9156b302013-08-19 09:11:56 +03002629 bnx2x_init_dropless_fc(bp);
2630
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002631 if (bp->link_vars.link_up) {
2632
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002633 if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002634 struct host_port_stats *pstats;
2635
2636 pstats = bnx2x_sp(bp, port_stats);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002637 /* reset old mac stats */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002638 memset(&(pstats->mac_stx[0]), 0,
2639 sizeof(struct mac_stx));
2640 }
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07002641 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002642 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2643 }
2644
Dmitry Kravkov568e2422013-08-13 02:25:00 +03002645 if (bp->link_vars.link_up && bp->link_vars.line_speed)
2646 bnx2x_set_local_cmng(bp);
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002647
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002648 __bnx2x_link_report(bp);
2649
Dmitry Kravkov9fdc3e92011-03-06 10:49:15 +00002650 if (IS_MF(bp))
2651 bnx2x_link_sync_notify(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002652}
2653
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00002654void bnx2x__link_status_update(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002655{
Vladislav Zolotarov2ae17f62011-05-04 23:48:23 +00002656 if (bp->state != BNX2X_STATE_OPEN)
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002657 return;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002658
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002659 /* read updated dcb configuration */
Ariel Eliorad5afc82013-01-01 05:22:26 +00002660 if (IS_PF(bp)) {
2661 bnx2x_dcbx_pmf_update(bp);
2662 bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
2663 if (bp->link_vars.link_up)
2664 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
2665 else
2666 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2667 /* indicate link status */
2668 bnx2x_link_report(bp);
Dmitry Kravkov00253a82011-11-13 04:34:25 +00002669
Ariel Eliorad5afc82013-01-01 05:22:26 +00002670 } else { /* VF */
2671 bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
2672 SUPPORTED_10baseT_Full |
2673 SUPPORTED_100baseT_Half |
2674 SUPPORTED_100baseT_Full |
2675 SUPPORTED_1000baseT_Full |
2676 SUPPORTED_2500baseX_Full |
2677 SUPPORTED_10000baseT_Full |
2678 SUPPORTED_TP |
2679 SUPPORTED_FIBRE |
2680 SUPPORTED_Autoneg |
2681 SUPPORTED_Pause |
2682 SUPPORTED_Asym_Pause);
2683 bp->port.advertising[0] = bp->port.supported[0];
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002684
Ariel Eliorad5afc82013-01-01 05:22:26 +00002685 bp->link_params.bp = bp;
2686 bp->link_params.port = BP_PORT(bp);
2687 bp->link_params.req_duplex[0] = DUPLEX_FULL;
2688 bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
2689 bp->link_params.req_line_speed[0] = SPEED_10000;
2690 bp->link_params.speed_cap_mask[0] = 0x7f0000;
2691 bp->link_params.switch_cfg = SWITCH_CFG_10G;
2692 bp->link_vars.mac_type = MAC_TYPE_BMAC;
2693 bp->link_vars.line_speed = SPEED_10000;
2694 bp->link_vars.link_status =
2695 (LINK_STATUS_LINK_UP |
2696 LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
2697 bp->link_vars.link_up = 1;
2698 bp->link_vars.duplex = DUPLEX_FULL;
2699 bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2700 __bnx2x_link_report(bp);
Dmitry Kravkov6495d152014-06-26 14:31:04 +03002701
2702 bnx2x_sample_bulletin(bp);
2703
2704 /* if bulletin board did not have an update for link status
2705 * __bnx2x_link_report will report current status
2706 * but it will NOT duplicate report in case of already reported
2707 * during sampling bulletin board.
2708 */
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002709 bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
Ariel Eliorad5afc82013-01-01 05:22:26 +00002710 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002711}
2712
Barak Witkowskia3348722012-04-23 03:04:46 +00002713static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
2714 u16 vlan_val, u8 allowed_prio)
2715{
Yuval Mintz86564c32013-01-23 03:21:50 +00002716 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002717 struct bnx2x_func_afex_update_params *f_update_params =
2718 &func_params.params.afex_update;
2719
2720 func_params.f_obj = &bp->func_obj;
2721 func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
2722
2723 /* no need to wait for RAMROD completion, so don't
2724 * set RAMROD_COMP_WAIT flag
2725 */
2726
2727 f_update_params->vif_id = vifid;
2728 f_update_params->afex_default_vlan = vlan_val;
2729 f_update_params->allowed_priorities = allowed_prio;
2730
2731 /* if ramrod can not be sent, response to MCP immediately */
2732 if (bnx2x_func_state_change(bp, &func_params) < 0)
2733 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
2734
2735 return 0;
2736}
2737
2738static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
2739 u16 vif_index, u8 func_bit_map)
2740{
Yuval Mintz86564c32013-01-23 03:21:50 +00002741 struct bnx2x_func_state_params func_params = {NULL};
Barak Witkowskia3348722012-04-23 03:04:46 +00002742 struct bnx2x_func_afex_viflists_params *update_params =
2743 &func_params.params.afex_viflists;
2744 int rc;
2745 u32 drv_msg_code;
2746
2747 /* validate only LIST_SET and LIST_GET are received from switch */
2748 if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
2749 BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
2750 cmd_type);
2751
2752 func_params.f_obj = &bp->func_obj;
2753 func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
2754
2755 /* set parameters according to cmd_type */
2756 update_params->afex_vif_list_command = cmd_type;
Yuval Mintz86564c32013-01-23 03:21:50 +00002757 update_params->vif_list_index = vif_index;
Barak Witkowskia3348722012-04-23 03:04:46 +00002758 update_params->func_bit_map =
2759 (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
2760 update_params->func_to_clear = 0;
2761 drv_msg_code =
2762 (cmd_type == VIF_LIST_RULE_GET) ?
2763 DRV_MSG_CODE_AFEX_LISTGET_ACK :
2764 DRV_MSG_CODE_AFEX_LISTSET_ACK;
2765
2766 /* if ramrod can not be sent, respond to MCP immediately for
2767 * SET and GET requests (other are not triggered from MCP)
2768 */
2769 rc = bnx2x_func_state_change(bp, &func_params);
2770 if (rc < 0)
2771 bnx2x_fw_command(bp, drv_msg_code, 0);
2772
2773 return 0;
2774}
2775
2776static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
2777{
2778 struct afex_stats afex_stats;
2779 u32 func = BP_ABS_FUNC(bp);
2780 u32 mf_config;
2781 u16 vlan_val;
2782 u32 vlan_prio;
2783 u16 vif_id;
2784 u8 allowed_prio;
2785 u8 vlan_mode;
2786 u32 addr_to_write, vifid, addrs, stats_type, i;
2787
2788 if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
2789 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2790 DP(BNX2X_MSG_MCP,
2791 "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
2792 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
2793 }
2794
2795 if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
2796 vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2797 addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
2798 DP(BNX2X_MSG_MCP,
2799 "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
2800 vifid, addrs);
2801 bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
2802 addrs);
2803 }
2804
2805 if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
2806 addr_to_write = SHMEM2_RD(bp,
2807 afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
2808 stats_type = SHMEM2_RD(bp,
2809 afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
2810
2811 DP(BNX2X_MSG_MCP,
2812 "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
2813 addr_to_write);
2814
2815 bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
2816
2817 /* write response to scratchpad, for MCP */
2818 for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
2819 REG_WR(bp, addr_to_write + i*sizeof(u32),
2820 *(((u32 *)(&afex_stats))+i));
2821
2822 /* send ack message to MCP */
2823 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
2824 }
2825
2826 if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
2827 mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
2828 bp->mf_config[BP_VN(bp)] = mf_config;
2829 DP(BNX2X_MSG_MCP,
2830 "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
2831 mf_config);
2832
2833 /* if VIF_SET is "enabled" */
2834 if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
2835 /* set rate limit directly to internal RAM */
2836 struct cmng_init_input cmng_input;
2837 struct rate_shaping_vars_per_vn m_rs_vn;
2838 size_t size = sizeof(struct rate_shaping_vars_per_vn);
2839 u32 addr = BAR_XSTRORM_INTMEM +
2840 XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
2841
2842 bp->mf_config[BP_VN(bp)] = mf_config;
2843
2844 bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
2845 m_rs_vn.vn_counter.rate =
2846 cmng_input.vnic_max_rate[BP_VN(bp)];
2847 m_rs_vn.vn_counter.quota =
2848 (m_rs_vn.vn_counter.rate *
2849 RS_PERIODIC_TIMEOUT_USEC) / 8;
2850
2851 __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
2852
2853 /* read relevant values from mf_cfg struct in shmem */
2854 vif_id =
2855 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2856 FUNC_MF_CFG_E1HOV_TAG_MASK) >>
2857 FUNC_MF_CFG_E1HOV_TAG_SHIFT;
2858 vlan_val =
2859 (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
2860 FUNC_MF_CFG_AFEX_VLAN_MASK) >>
2861 FUNC_MF_CFG_AFEX_VLAN_SHIFT;
2862 vlan_prio = (mf_config &
2863 FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
2864 FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
2865 vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
2866 vlan_mode =
2867 (MF_CFG_RD(bp,
2868 func_mf_config[func].afex_config) &
2869 FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
2870 FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
2871 allowed_prio =
2872 (MF_CFG_RD(bp,
2873 func_mf_config[func].afex_config) &
2874 FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
2875 FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
2876
2877 /* send ramrod to FW, return in case of failure */
2878 if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
2879 allowed_prio))
2880 return;
2881
2882 bp->afex_def_vlan_tag = vlan_val;
2883 bp->afex_vlan_mode = vlan_mode;
2884 } else {
2885 /* notify link down because BP->flags is disabled */
2886 bnx2x_link_report(bp);
2887
2888 /* send INVALID VIF ramrod to FW */
2889 bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
2890
2891 /* Reset the default afex VLAN */
2892 bp->afex_def_vlan_tag = -1;
2893 }
2894 }
2895}
2896
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002897static void bnx2x_pmf_update(struct bnx2x *bp)
2898{
2899 int port = BP_PORT(bp);
2900 u32 val;
2901
2902 bp->port.pmf = 1;
Merav Sicron51c1a582012-03-18 10:33:38 +00002903 DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002904
Yaniv Rosner3deb8162011-06-14 01:34:33 +00002905 /*
2906 * We need the mb() to ensure the ordering between the writing to
2907 * bp->port.pmf here and reading it from the bnx2x_periodic_task().
2908 */
2909 smp_mb();
2910
2911 /* queue a periodic task */
2912 queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
2913
Dmitry Kravkovef018542011-06-14 01:33:57 +00002914 bnx2x_dcbx_pmf_update(bp);
2915
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002916 /* enable nig attention */
David S. Miller8decf862011-09-22 03:23:13 -04002917 val = (0xff0f | (1 << (BP_VN(bp) + 4)));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002918 if (bp->common.int_block == INT_BLOCK_HC) {
2919 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
2920 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002921 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002922 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
2923 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
2924 }
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07002925
2926 bnx2x_stats_handle(bp, STATS_EVENT_PMF);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07002927}
2928
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07002929/* end of Link */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02002930
2931/* slow path */
2932
2933/*
2934 * General service functions
2935 */
2936
Eilon Greenstein2691d512009-08-12 08:22:08 +00002937/* send the MCP a request, block until there is a reply */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002938u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
Eilon Greenstein2691d512009-08-12 08:22:08 +00002939{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002940 int mb_idx = BP_FW_MB_IDX(bp);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002941 u32 seq;
Eilon Greenstein2691d512009-08-12 08:22:08 +00002942 u32 rc = 0;
2943 u32 cnt = 1;
2944 u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
2945
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002946 mutex_lock(&bp->fw_mb_mutex);
Dmitry Kravkova5971d42011-05-25 04:55:51 +00002947 seq = ++bp->fw_seq;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002948 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
2949 SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
2950
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00002951 DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
2952 (command | seq), param);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002953
2954 do {
2955 /* let the FW do it's magic ... */
2956 msleep(delay);
2957
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002958 rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002959
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002960 /* Give the FW up to 5 second (500*10ms) */
2961 } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
Eilon Greenstein2691d512009-08-12 08:22:08 +00002962
2963 DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
2964 cnt*delay, rc, seq);
2965
2966 /* is this a reply to our command? */
2967 if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
2968 rc &= FW_MSG_CODE_MASK;
2969 else {
2970 /* FW BUG! */
2971 BNX2X_ERR("FW failed to respond!\n");
2972 bnx2x_fw_dump(bp);
2973 rc = 0;
2974 }
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07002975 mutex_unlock(&bp->fw_mb_mutex);
Eilon Greenstein2691d512009-08-12 08:22:08 +00002976
2977 return rc;
2978}
2979
Eric Dumazet1191cb82012-04-27 21:39:21 +00002980static void storm_memset_func_cfg(struct bnx2x *bp,
2981 struct tstorm_eth_function_common_config *tcfg,
2982 u16 abs_fid)
2983{
2984 size_t size = sizeof(struct tstorm_eth_function_common_config);
2985
2986 u32 addr = BAR_TSTRORM_INTMEM +
2987 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
2988
2989 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
2990}
2991
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002992void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002993{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002994 if (CHIP_IS_E1x(bp)) {
2995 struct tstorm_eth_function_common_config tcfg = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002996
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002997 storm_memset_func_cfg(bp, &tcfg, p->func_id);
2998 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002999
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003000 /* Enable the function in the FW */
3001 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
3002 storm_memset_func_en(bp, p->func_id, 1);
3003
3004 /* spq */
3005 if (p->func_flgs & FUNC_FLG_SPQ) {
3006 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
3007 REG_WR(bp, XSEM_REG_FAST_MEMORY +
3008 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
3009 }
3010}
3011
Ariel Elior6383c0b2011-07-14 08:31:57 +00003012/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003013 * bnx2x_get_common_flags - Return common flags
Ariel Elior6383c0b2011-07-14 08:31:57 +00003014 *
3015 * @bp device handle
3016 * @fp queue handle
3017 * @zero_stats TRUE if statistics zeroing is needed
3018 *
3019 * Return the flags that are common for the Tx-only and not normal connections.
3020 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003021static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
3022 struct bnx2x_fastpath *fp,
3023 bool zero_stats)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003024{
3025 unsigned long flags = 0;
3026
3027 /* PF driver will always initialize the Queue to an ACTIVE state */
3028 __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
3029
Ariel Elior6383c0b2011-07-14 08:31:57 +00003030 /* tx only connections collect statistics (on the same index as the
Dmitry Kravkov91226792013-03-11 05:17:52 +00003031 * parent connection). The statistics are zeroed when the parent
3032 * connection is initialized.
Ariel Elior6383c0b2011-07-14 08:31:57 +00003033 */
Barak Witkowski50f0a562011-12-05 21:52:23 +00003034
3035 __set_bit(BNX2X_Q_FLG_STATS, &flags);
3036 if (zero_stats)
3037 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
3038
Yuval Mintzc14db202014-01-12 14:37:59 +02003039 if (bp->flags & TX_SWITCHING)
3040 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
3041
Dmitry Kravkov91226792013-03-11 05:17:52 +00003042 __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
Dmitry Kravkove287a752013-03-21 15:38:24 +00003043 __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
Ariel Elior6383c0b2011-07-14 08:31:57 +00003044
Yuval Mintz823e1d92013-01-14 05:11:47 +00003045#ifdef BNX2X_STOP_ON_ERROR
3046 __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
3047#endif
3048
Ariel Elior6383c0b2011-07-14 08:31:57 +00003049 return flags;
3050}
3051
Eric Dumazet1191cb82012-04-27 21:39:21 +00003052static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
3053 struct bnx2x_fastpath *fp,
3054 bool leading)
Ariel Elior6383c0b2011-07-14 08:31:57 +00003055{
3056 unsigned long flags = 0;
3057
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003058 /* calculate other queue flags */
3059 if (IS_MF_SD(bp))
3060 __set_bit(BNX2X_Q_FLG_OV, &flags);
3061
Barak Witkowskia3348722012-04-23 03:04:46 +00003062 if (IS_FCOE_FP(fp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003063 __set_bit(BNX2X_Q_FLG_FCOE, &flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00003064 /* For FCoE - force usage of default priority (for afex) */
3065 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
3066 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003067
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003068 if (!fp->disable_tpa) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003069 __set_bit(BNX2X_Q_FLG_TPA, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003070 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00003071 if (fp->mode == TPA_MODE_GRO)
3072 __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00003073 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003074
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003075 if (leading) {
3076 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
3077 __set_bit(BNX2X_Q_FLG_MCAST, &flags);
3078 }
3079
3080 /* Always set HW VLAN stripping */
3081 __set_bit(BNX2X_Q_FLG_VLAN, &flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003082
Barak Witkowskia3348722012-04-23 03:04:46 +00003083 /* configure silent vlan removal */
3084 if (IS_MF_AFEX(bp))
3085 __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
3086
Ariel Elior6383c0b2011-07-14 08:31:57 +00003087 return flags | bnx2x_get_common_flags(bp, fp, true);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003088}
3089
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003090static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003091 struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
3092 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003093{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003094 gen_init->stat_id = bnx2x_stats_id(fp);
3095 gen_init->spcl_id = fp->cl_id;
3096
3097 /* Always use mini-jumbo MTU for FCoE L2 ring */
3098 if (IS_FCOE_FP(fp))
3099 gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
3100 else
3101 gen_init->mtu = bp->dev->mtu;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003102
3103 gen_init->cos = cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003104}
3105
3106static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
3107 struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
3108 struct bnx2x_rxq_setup_params *rxq_init)
3109{
3110 u8 max_sge = 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003111 u16 sge_sz = 0;
3112 u16 tpa_agg_size = 0;
3113
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003114 if (!fp->disable_tpa) {
David S. Miller8decf862011-09-22 03:23:13 -04003115 pause->sge_th_lo = SGE_TH_LO(bp);
3116 pause->sge_th_hi = SGE_TH_HI(bp);
3117
3118 /* validate SGE ring has enough to cross high threshold */
3119 WARN_ON(bp->dropless_fc &&
3120 pause->sge_th_hi + FW_PREFETCH_CNT >
3121 MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
3122
Yuval Mintz924d75a2013-01-23 03:21:44 +00003123 tpa_agg_size = TPA_AGG_SIZE;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003124 max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
3125 SGE_PAGE_SHIFT;
3126 max_sge = ((max_sge + PAGES_PER_SGE - 1) &
3127 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
Yuval Mintz924d75a2013-01-23 03:21:44 +00003128 sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003129 }
3130
3131 /* pause - not for e1 */
3132 if (!CHIP_IS_E1(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -04003133 pause->bd_th_lo = BD_TH_LO(bp);
3134 pause->bd_th_hi = BD_TH_HI(bp);
3135
3136 pause->rcq_th_lo = RCQ_TH_LO(bp);
3137 pause->rcq_th_hi = RCQ_TH_HI(bp);
3138 /*
3139 * validate that rings have enough entries to cross
3140 * high thresholds
3141 */
3142 WARN_ON(bp->dropless_fc &&
3143 pause->bd_th_hi + FW_PREFETCH_CNT >
3144 bp->rx_ring_size);
3145 WARN_ON(bp->dropless_fc &&
3146 pause->rcq_th_hi + FW_PREFETCH_CNT >
3147 NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003148
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003149 pause->pri_map = 1;
3150 }
3151
3152 /* rxq setup */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003153 rxq_init->dscr_map = fp->rx_desc_mapping;
3154 rxq_init->sge_map = fp->rx_sge_mapping;
3155 rxq_init->rcq_map = fp->rx_comp_mapping;
3156 rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003157
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003158 /* This should be a maximum number of data bytes that may be
3159 * placed on the BD (not including paddings).
3160 */
Eric Dumazete52fcb22011-11-14 06:05:34 +00003161 rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003162 BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08003163
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003164 rxq_init->cl_qzone_id = fp->cl_qzone_id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003165 rxq_init->tpa_agg_sz = tpa_agg_size;
3166 rxq_init->sge_buf_sz = sge_sz;
3167 rxq_init->max_sges_pkt = max_sge;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003168 rxq_init->rss_engine_id = BP_FUNC(bp);
Yuval Mintz259afa12012-03-12 08:53:10 +00003169 rxq_init->mcast_engine_id = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003170
3171 /* Maximum number or simultaneous TPA aggregation for this Queue.
3172 *
Yuval Mintz2de67432013-01-23 03:21:43 +00003173 * For PF Clients it should be the maximum available number.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003174 * VF driver(s) may want to define it to a smaller value.
3175 */
David S. Miller8decf862011-09-22 03:23:13 -04003176 rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003177
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003178 rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
3179 rxq_init->fw_sb_id = fp->fw_sb_id;
3180
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003181 if (IS_FCOE_FP(fp))
3182 rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
3183 else
Ariel Elior6383c0b2011-07-14 08:31:57 +00003184 rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
Barak Witkowskia3348722012-04-23 03:04:46 +00003185 /* configure silent vlan removal
3186 * if multi function mode is afex, then mask default vlan
3187 */
3188 if (IS_MF_AFEX(bp)) {
3189 rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
3190 rxq_init->silent_removal_mask = VLAN_VID_MASK;
3191 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003192}
3193
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003194static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00003195 struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
3196 u8 cos)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003197{
Merav Sicron65565882012-06-19 07:48:26 +00003198 txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00003199 txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003200 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
3201 txq_init->fw_sb_id = fp->fw_sb_id;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003202
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003203 /*
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003204 * set the tss leading client id for TX classification ==
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003205 * leading RSS client id
3206 */
3207 txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
3208
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00003209 if (IS_FCOE_FP(fp)) {
3210 txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
3211 txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
3212 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003213}
3214
stephen hemminger8d962862010-10-21 07:50:56 +00003215static void bnx2x_pf_init(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003216{
3217 struct bnx2x_func_init_params func_init = {0};
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003218 struct event_ring_data eq_data = { {0} };
3219 u16 flags;
3220
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003221 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003222 /* reset IGU PF statistics: MSIX + ATTN */
3223 /* PF */
3224 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3225 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3226 (CHIP_MODE_IS_4_PORT(bp) ?
3227 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3228 /* ATTN */
3229 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
3230 BNX2X_IGU_STAS_MSG_VF_CNT*4 +
3231 BNX2X_IGU_STAS_MSG_PF_CNT*4 +
3232 (CHIP_MODE_IS_4_PORT(bp) ?
3233 BP_FUNC(bp) : BP_VN(bp))*4, 0);
3234 }
3235
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003236 /* function setup flags */
3237 flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
3238
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003239 /* This flag is relevant for E1x only.
3240 * E2 doesn't have a TPA configuration in a function level.
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003241 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003242 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003243
3244 func_init.func_flgs = flags;
3245 func_init.pf_id = BP_FUNC(bp);
3246 func_init.func_id = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003247 func_init.spq_map = bp->spq_mapping;
3248 func_init.spq_prod = bp->spq_prod_idx;
3249
3250 bnx2x_func_init(bp, &func_init);
3251
3252 memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
3253
3254 /*
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003255 * Congestion management values depend on the link rate
3256 * There is no active link so initial link rate is set to 10 Gbps.
3257 * When the link comes up The congestion management values are
3258 * re-calculated according to the actual link rate.
3259 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003260 bp->link_vars.line_speed = SPEED_10000;
3261 bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
3262
3263 /* Only the PMF sets the HW */
3264 if (bp->port.pmf)
3265 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3266
Yuval Mintz86564c32013-01-23 03:21:50 +00003267 /* init Event Queue - PCI bus guarantees correct endianity*/
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003268 eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
3269 eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
3270 eq_data.producer = bp->eq_prod;
3271 eq_data.index_id = HC_SP_INDEX_EQ_CONS;
3272 eq_data.sb_id = DEF_SB_ID;
3273 storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
3274}
3275
Eilon Greenstein2691d512009-08-12 08:22:08 +00003276static void bnx2x_e1h_disable(struct bnx2x *bp)
3277{
3278 int port = BP_PORT(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003279
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003280 bnx2x_tx_disable(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003281
3282 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003283}
3284
3285static void bnx2x_e1h_enable(struct bnx2x *bp)
3286{
3287 int port = BP_PORT(bp);
3288
3289 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
3290
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003291 /* Tx queue should be only re-enabled */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003292 netif_tx_wake_all_queues(bp->dev);
3293
Eilon Greenstein061bc702009-10-15 00:18:47 -07003294 /*
3295 * Should not call netif_carrier_on since it will be called if the link
3296 * is up when checking for link state
3297 */
Eilon Greenstein2691d512009-08-12 08:22:08 +00003298}
3299
Barak Witkowski1d187b32011-12-05 22:41:50 +00003300#define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
3301
3302static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
3303{
3304 struct eth_stats_info *ether_stat =
3305 &bp->slowpath->drv_info_to_mcp.ether_stat;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003306 struct bnx2x_vlan_mac_obj *mac_obj =
3307 &bp->sp_objs->mac_obj;
3308 int i;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003309
Dan Carpenter786fdf02012-10-02 01:47:46 +00003310 strlcpy(ether_stat->version, DRV_MODULE_VERSION,
3311 ETH_STAT_INFO_VERSION_LEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003312
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003313 /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
3314 * mac_local field in ether_stat struct. The base address is offset by 2
3315 * bytes to account for the field being 8 bytes but a mac address is
3316 * only 6 bytes. Likewise, the stride for the get_n_elements function is
3317 * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
3318 * allocated by the ether_stat struct, so the macs will land in their
3319 * proper positions.
3320 */
3321 for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
3322 memset(ether_stat->mac_local + i, 0,
3323 sizeof(ether_stat->mac_local[0]));
3324 mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
3325 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
3326 ether_stat->mac_local + MAC_PAD, MAC_PAD,
3327 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003328 ether_stat->mtu_size = bp->dev->mtu;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003329 if (bp->dev->features & NETIF_F_RXCSUM)
3330 ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
3331 if (bp->dev->features & NETIF_F_TSO)
3332 ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
3333 ether_stat->feature_flags |= bp->common.boot_mode;
3334
3335 ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
3336
3337 ether_stat->txq_size = bp->tx_ring_size;
3338 ether_stat->rxq_size = bp->rx_ring_size;
Yuval Mintz0c757de2013-12-26 09:57:11 +02003339
David S. Millerfcf93a02013-12-26 18:33:10 -05003340#ifdef CONFIG_BNX2X_SRIOV
Yuval Mintz0c757de2013-12-26 09:57:11 +02003341 ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
David S. Millerfcf93a02013-12-26 18:33:10 -05003342#endif
Barak Witkowski1d187b32011-12-05 22:41:50 +00003343}
3344
3345static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
3346{
3347 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3348 struct fcoe_stats_info *fcoe_stat =
3349 &bp->slowpath->drv_info_to_mcp.fcoe_stat;
3350
Merav Sicron55c11942012-11-07 00:45:48 +00003351 if (!CNIC_LOADED(bp))
3352 return;
3353
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003354 memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003355
3356 fcoe_stat->qos_priority =
3357 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
3358
3359 /* insert FCoE stats from ramrod response */
3360 if (!NO_FCOE(bp)) {
3361 struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003362 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003363 tstorm_queue_statistics;
3364
3365 struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
Merav Sicron65565882012-06-19 07:48:26 +00003366 &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
Barak Witkowski1d187b32011-12-05 22:41:50 +00003367 xstorm_queue_statistics;
3368
3369 struct fcoe_statistics_params *fw_fcoe_stat =
3370 &bp->fw_stats_data->fcoe;
3371
Yuval Mintz86564c32013-01-23 03:21:50 +00003372 ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
3373 fcoe_stat->rx_bytes_lo,
3374 fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003375
Yuval Mintz86564c32013-01-23 03:21:50 +00003376 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3377 fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
3378 fcoe_stat->rx_bytes_lo,
3379 fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003380
Yuval Mintz86564c32013-01-23 03:21:50 +00003381 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3382 fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
3383 fcoe_stat->rx_bytes_lo,
3384 fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003385
Yuval Mintz86564c32013-01-23 03:21:50 +00003386 ADD_64_LE(fcoe_stat->rx_bytes_hi,
3387 fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
3388 fcoe_stat->rx_bytes_lo,
3389 fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003390
Yuval Mintz86564c32013-01-23 03:21:50 +00003391 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3392 fcoe_stat->rx_frames_lo,
3393 fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003394
Yuval Mintz86564c32013-01-23 03:21:50 +00003395 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3396 fcoe_stat->rx_frames_lo,
3397 fcoe_q_tstorm_stats->rcv_ucast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003398
Yuval Mintz86564c32013-01-23 03:21:50 +00003399 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3400 fcoe_stat->rx_frames_lo,
3401 fcoe_q_tstorm_stats->rcv_bcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003402
Yuval Mintz86564c32013-01-23 03:21:50 +00003403 ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
3404 fcoe_stat->rx_frames_lo,
3405 fcoe_q_tstorm_stats->rcv_mcast_pkts);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003406
Yuval Mintz86564c32013-01-23 03:21:50 +00003407 ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
3408 fcoe_stat->tx_bytes_lo,
3409 fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003410
Yuval Mintz86564c32013-01-23 03:21:50 +00003411 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3412 fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
3413 fcoe_stat->tx_bytes_lo,
3414 fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003415
Yuval Mintz86564c32013-01-23 03:21:50 +00003416 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3417 fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
3418 fcoe_stat->tx_bytes_lo,
3419 fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003420
Yuval Mintz86564c32013-01-23 03:21:50 +00003421 ADD_64_LE(fcoe_stat->tx_bytes_hi,
3422 fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
3423 fcoe_stat->tx_bytes_lo,
3424 fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003425
Yuval Mintz86564c32013-01-23 03:21:50 +00003426 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3427 fcoe_stat->tx_frames_lo,
3428 fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003429
Yuval Mintz86564c32013-01-23 03:21:50 +00003430 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3431 fcoe_stat->tx_frames_lo,
3432 fcoe_q_xstorm_stats->ucast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003433
Yuval Mintz86564c32013-01-23 03:21:50 +00003434 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3435 fcoe_stat->tx_frames_lo,
3436 fcoe_q_xstorm_stats->bcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003437
Yuval Mintz86564c32013-01-23 03:21:50 +00003438 ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
3439 fcoe_stat->tx_frames_lo,
3440 fcoe_q_xstorm_stats->mcast_pkts_sent);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003441 }
3442
Barak Witkowski1d187b32011-12-05 22:41:50 +00003443 /* ask L5 driver to add data to the struct */
3444 bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003445}
3446
3447static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
3448{
3449 struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
3450 struct iscsi_stats_info *iscsi_stat =
3451 &bp->slowpath->drv_info_to_mcp.iscsi_stat;
3452
Merav Sicron55c11942012-11-07 00:45:48 +00003453 if (!CNIC_LOADED(bp))
3454 return;
3455
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00003456 memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
3457 ETH_ALEN);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003458
3459 iscsi_stat->qos_priority =
3460 app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
3461
Barak Witkowski1d187b32011-12-05 22:41:50 +00003462 /* ask L5 driver to add data to the struct */
3463 bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003464}
3465
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003466/* called due to MCP event (on pmf):
3467 * reread new bandwidth configuration
3468 * configure FW
3469 * notify others function about the change
3470 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003471static void bnx2x_config_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003472{
3473 if (bp->link_vars.link_up) {
3474 bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
3475 bnx2x_link_sync_notify(bp);
3476 }
3477 storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
3478}
3479
Eric Dumazet1191cb82012-04-27 21:39:21 +00003480static void bnx2x_set_mf_bw(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003481{
3482 bnx2x_config_mf_bw(bp);
3483 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
3484}
3485
Yuval Mintzc8c60d82012-06-06 17:13:07 +00003486static void bnx2x_handle_eee_event(struct bnx2x *bp)
3487{
3488 DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
3489 bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
3490}
3491
Yuval Mintz42f82772014-03-23 18:12:23 +02003492#define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
3493#define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
3494
Barak Witkowski1d187b32011-12-05 22:41:50 +00003495static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
3496{
3497 enum drv_info_opcode op_code;
3498 u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
Yuval Mintz42f82772014-03-23 18:12:23 +02003499 bool release = false;
3500 int wait;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003501
3502 /* if drv_info version supported by MFW doesn't match - send NACK */
3503 if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
3504 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
3505 return;
3506 }
3507
3508 op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
3509 DRV_INFO_CONTROL_OP_CODE_SHIFT;
3510
Yuval Mintz42f82772014-03-23 18:12:23 +02003511 /* Must prevent other flows from accessing drv_info_to_mcp */
3512 mutex_lock(&bp->drv_info_mutex);
3513
Barak Witkowski1d187b32011-12-05 22:41:50 +00003514 memset(&bp->slowpath->drv_info_to_mcp, 0,
3515 sizeof(union drv_info_to_mcp));
3516
3517 switch (op_code) {
3518 case ETH_STATS_OPCODE:
3519 bnx2x_drv_info_ether_stat(bp);
3520 break;
3521 case FCOE_STATS_OPCODE:
3522 bnx2x_drv_info_fcoe_stat(bp);
3523 break;
3524 case ISCSI_STATS_OPCODE:
3525 bnx2x_drv_info_iscsi_stat(bp);
3526 break;
3527 default:
3528 /* if op code isn't supported - send NACK */
3529 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
Yuval Mintz42f82772014-03-23 18:12:23 +02003530 goto out;
Barak Witkowski1d187b32011-12-05 22:41:50 +00003531 }
3532
3533 /* if we got drv_info attn from MFW then these fields are defined in
3534 * shmem2 for sure
3535 */
3536 SHMEM2_WR(bp, drv_info_host_addr_lo,
3537 U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3538 SHMEM2_WR(bp, drv_info_host_addr_hi,
3539 U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
3540
3541 bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
Yuval Mintz42f82772014-03-23 18:12:23 +02003542
3543 /* Since possible management wants both this and get_driver_version
3544 * need to wait until management notifies us it finished utilizing
3545 * the buffer.
3546 */
3547 if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
3548 DP(BNX2X_MSG_MCP, "Management does not support indication\n");
3549 } else if (!bp->drv_info_mng_owner) {
3550 u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
3551
3552 for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
3553 u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
3554
3555 /* Management is done; need to clear indication */
3556 if (indication & bit) {
3557 SHMEM2_WR(bp, mfw_drv_indication,
3558 indication & ~bit);
3559 release = true;
3560 break;
3561 }
3562
3563 msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
3564 }
3565 }
3566 if (!release) {
3567 DP(BNX2X_MSG_MCP, "Management did not release indication\n");
3568 bp->drv_info_mng_owner = true;
3569 }
3570
3571out:
3572 mutex_unlock(&bp->drv_info_mutex);
3573}
3574
3575static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
3576{
3577 u8 vals[4];
3578 int i = 0;
3579
3580 if (bnx2x_format) {
3581 i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
3582 &vals[0], &vals[1], &vals[2], &vals[3]);
3583 if (i > 0)
3584 vals[0] -= '0';
3585 } else {
3586 i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
3587 &vals[0], &vals[1], &vals[2], &vals[3]);
3588 }
3589
3590 while (i < 4)
3591 vals[i++] = 0;
3592
3593 return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
3594}
3595
3596void bnx2x_update_mng_version(struct bnx2x *bp)
3597{
3598 u32 iscsiver = DRV_VER_NOT_LOADED;
3599 u32 fcoever = DRV_VER_NOT_LOADED;
3600 u32 ethver = DRV_VER_NOT_LOADED;
3601 int idx = BP_FW_MB_IDX(bp);
3602 u8 *version;
3603
3604 if (!SHMEM2_HAS(bp, func_os_drv_ver))
3605 return;
3606
3607 mutex_lock(&bp->drv_info_mutex);
3608 /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
3609 if (bp->drv_info_mng_owner)
3610 goto out;
3611
3612 if (bp->state != BNX2X_STATE_OPEN)
3613 goto out;
3614
3615 /* Parse ethernet driver version */
3616 ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
3617 if (!CNIC_LOADED(bp))
3618 goto out;
3619
3620 /* Try getting storage driver version via cnic */
3621 memset(&bp->slowpath->drv_info_to_mcp, 0,
3622 sizeof(union drv_info_to_mcp));
3623 bnx2x_drv_info_iscsi_stat(bp);
3624 version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
3625 iscsiver = bnx2x_update_mng_version_utility(version, false);
3626
3627 memset(&bp->slowpath->drv_info_to_mcp, 0,
3628 sizeof(union drv_info_to_mcp));
3629 bnx2x_drv_info_fcoe_stat(bp);
3630 version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
3631 fcoever = bnx2x_update_mng_version_utility(version, false);
3632
3633out:
3634 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
3635 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
3636 SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
3637
3638 mutex_unlock(&bp->drv_info_mutex);
3639
3640 DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
3641 ethver, iscsiver, fcoever);
Barak Witkowski1d187b32011-12-05 22:41:50 +00003642}
3643
Eilon Greenstein2691d512009-08-12 08:22:08 +00003644static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
3645{
Eilon Greenstein2691d512009-08-12 08:22:08 +00003646 DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003647
3648 if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
3649
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003650 /*
3651 * This is the only place besides the function initialization
3652 * where the bp->flags can change so it is done without any
3653 * locks
3654 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003655 if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003656 DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003657 bp->flags |= MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003658
3659 bnx2x_e1h_disable(bp);
3660 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +00003661 DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07003662 bp->flags &= ~MF_FUNC_DIS;
Eilon Greenstein2691d512009-08-12 08:22:08 +00003663
3664 bnx2x_e1h_enable(bp);
3665 }
3666 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
3667 }
3668 if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08003669 bnx2x_config_mf_bw(bp);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003670 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
3671 }
3672
3673 /* Report results to MCP */
3674 if (dcc_event)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003675 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003676 else
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003677 bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
Eilon Greenstein2691d512009-08-12 08:22:08 +00003678}
3679
Michael Chan289129022009-10-10 13:46:53 +00003680/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003681static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003682{
3683 struct eth_spe *next_spe = bp->spq_prod_bd;
3684
3685 if (bp->spq_prod_bd == bp->spq_last_bd) {
3686 bp->spq_prod_bd = bp->spq;
3687 bp->spq_prod_idx = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00003688 DP(BNX2X_MSG_SP, "end of spq\n");
Michael Chan289129022009-10-10 13:46:53 +00003689 } else {
3690 bp->spq_prod_bd++;
3691 bp->spq_prod_idx++;
3692 }
3693 return next_spe;
3694}
3695
3696/* must be called under the spq lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003697static void bnx2x_sp_prod_update(struct bnx2x *bp)
Michael Chan289129022009-10-10 13:46:53 +00003698{
3699 int func = BP_FUNC(bp);
3700
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003701 /*
3702 * Make sure that BD data is updated before writing the producer:
3703 * BD data is written to the memory, the producer is read from the
3704 * memory, thus we need a full memory barrier to ensure the ordering.
3705 */
3706 mb();
Michael Chan289129022009-10-10 13:46:53 +00003707
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003708 REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00003709 bp->spq_prod_idx);
Michael Chan289129022009-10-10 13:46:53 +00003710 mmiowb();
3711}
3712
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003713/**
3714 * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
3715 *
3716 * @cmd: command to check
3717 * @cmd_type: command type
3718 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00003719static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003720{
3721 if ((cmd_type == NONE_CONNECTION_TYPE) ||
Ariel Elior6383c0b2011-07-14 08:31:57 +00003722 (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003723 (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
3724 (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
3725 (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
3726 (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
3727 (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
3728 return true;
3729 else
3730 return false;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003731}
3732
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003733/**
3734 * bnx2x_sp_post - place a single command on an SP ring
3735 *
3736 * @bp: driver handle
3737 * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
3738 * @cid: SW CID the command is related to
3739 * @data_hi: command private data address (high 32 bits)
3740 * @data_lo: command private data address (low 32 bits)
3741 * @cmd_type: command type (e.g. NONE, ETH)
3742 *
3743 * SP data is handled as if it's always an address pair, thus data fields are
3744 * not swapped to little endian in upper functions. Instead this function swaps
3745 * data as if it's two u32 fields.
3746 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00003747int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003748 u32 data_hi, u32 data_lo, int cmd_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003749{
Michael Chan289129022009-10-10 13:46:53 +00003750 struct eth_spe *spe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003751 u16 type;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003752 bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003753
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003754#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00003755 if (unlikely(bp->panic)) {
3756 BNX2X_ERR("Can't post SP when there is panic\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003757 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +00003758 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003759#endif
3760
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003761 spin_lock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003762
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003763 if (common) {
3764 if (!atomic_read(&bp->eq_spq_left)) {
3765 BNX2X_ERR("BUG! EQ ring full!\n");
3766 spin_unlock_bh(&bp->spq_lock);
3767 bnx2x_panic();
3768 return -EBUSY;
3769 }
3770 } else if (!atomic_read(&bp->cq_spq_left)) {
3771 BNX2X_ERR("BUG! SPQ ring full!\n");
3772 spin_unlock_bh(&bp->spq_lock);
3773 bnx2x_panic();
3774 return -EBUSY;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003775 }
Eliezer Tamirf1410642008-02-28 11:51:50 -08003776
Michael Chan289129022009-10-10 13:46:53 +00003777 spe = bnx2x_sp_get_next(bp);
3778
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003779 /* CID needs port number to be encoded int it */
Michael Chan289129022009-10-10 13:46:53 +00003780 spe->hdr.conn_and_cmd_data =
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003781 cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
3782 HW_CID(bp, cid));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003783
Michal Kalderon14a94eb2014-02-12 18:19:53 +02003784 /* In some cases, type may already contain the func-id
3785 * mainly in SRIOV related use cases, so we add it here only
3786 * if it's not already set.
3787 */
3788 if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
3789 type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
3790 SPE_HDR_CONN_TYPE;
3791 type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
3792 SPE_HDR_FUNCTION_ID);
3793 } else {
3794 type = cmd_type;
3795 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003796
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003797 spe->hdr.type = cpu_to_le16(type);
3798
3799 spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
3800 spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
3801
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003802 /*
3803 * It's ok if the actual decrement is issued towards the memory
3804 * somewhere between the spin_lock and spin_unlock. Thus no
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003805 * more explicit memory barrier is needed.
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003806 */
3807 if (common)
3808 atomic_dec(&bp->eq_spq_left);
3809 else
3810 atomic_dec(&bp->cq_spq_left);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003811
Merav Sicron51c1a582012-03-18 10:33:38 +00003812 DP(BNX2X_MSG_SP,
3813 "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 +00003814 bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
3815 (u32)(U64_LO(bp->spq_mapping) +
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00003816 (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08003817 HW_CID(bp, cid), data_hi, data_lo, type,
3818 atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00003819
Michael Chan289129022009-10-10 13:46:53 +00003820 bnx2x_sp_prod_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003821 spin_unlock_bh(&bp->spq_lock);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003822 return 0;
3823}
3824
3825/* acquire split MCP access lock register */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003826static int bnx2x_acquire_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003827{
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003828 u32 j, val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003829 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003830
3831 might_sleep();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003832 for (j = 0; j < 1000; j++) {
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003833 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
3834 val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
3835 if (val & MCPR_ACCESS_LOCK_LOCK)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003836 break;
3837
Yuval Mintz639d65b2013-06-02 00:06:21 +00003838 usleep_range(5000, 10000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003839 }
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003840 if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
Eilon Greenstein19680c42008-08-13 15:47:33 -07003841 BNX2X_ERR("Cannot acquire MCP access lock register\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003842 rc = -EBUSY;
3843 }
3844
3845 return rc;
3846}
3847
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07003848/* release split MCP access lock register */
3849static void bnx2x_release_alr(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003850{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00003851 REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003852}
3853
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003854#define BNX2X_DEF_SB_ATT_IDX 0x0001
3855#define BNX2X_DEF_SB_IDX 0x0002
3856
Eric Dumazet1191cb82012-04-27 21:39:21 +00003857static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003858{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003859 struct host_sp_status_block *def_sb = bp->def_status_blk;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003860 u16 rc = 0;
3861
3862 barrier(); /* status block is written to by the chip */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003863 if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
3864 bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003865 rc |= BNX2X_DEF_SB_ATT_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003866 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003867
3868 if (bp->def_idx != def_sb->sp_sb.running_index) {
3869 bp->def_idx = def_sb->sp_sb.running_index;
3870 rc |= BNX2X_DEF_SB_IDX;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003871 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003872
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003873 /* Do not reorder: indices reading should complete before handling */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00003874 barrier();
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003875 return rc;
3876}
3877
3878/*
3879 * slow path service functions
3880 */
3881
3882static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
3883{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003884 int port = BP_PORT(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003885 u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
3886 MISC_REG_AEU_MASK_ATTN_FUNC_0;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003887 u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
3888 NIG_REG_MASK_INTERRUPT_PORT0;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003889 u32 aeu_mask;
Eilon Greenstein87942b42009-02-12 08:36:49 +00003890 u32 nig_mask = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003891 u32 reg_addr;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003892
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003893 if (bp->attn_state & asserted)
3894 BNX2X_ERR("IGU ERROR\n");
3895
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003896 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
3897 aeu_mask = REG_RD(bp, aeu_addr);
3898
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003899 DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003900 aeu_mask, asserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00003901 aeu_mask &= ~(asserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003902 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003903
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003904 REG_WR(bp, aeu_addr, aeu_mask);
3905 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003906
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003907 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003908 bp->attn_state |= asserted;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07003909 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003910
3911 if (asserted & ATTN_HARD_WIRED_MASK) {
3912 if (asserted & ATTN_NIG_FOR_FUNC) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003913
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003914 bnx2x_acquire_phy_lock(bp);
3915
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08003916 /* save nig interrupt mask */
Eilon Greenstein87942b42009-02-12 08:36:49 +00003917 nig_mask = REG_RD(bp, nig_int_mask_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003918
Yaniv Rosner361c3912011-06-14 01:33:19 +00003919 /* If nig_mask is not set, no need to call the update
3920 * function.
3921 */
3922 if (nig_mask) {
3923 REG_WR(bp, nig_int_mask_addr, 0);
3924
3925 bnx2x_link_attn(bp);
3926 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003927
3928 /* handle unicore attn? */
3929 }
3930 if (asserted & ATTN_SW_TIMER_4_FUNC)
3931 DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
3932
3933 if (asserted & GPIO_2_FUNC)
3934 DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
3935
3936 if (asserted & GPIO_3_FUNC)
3937 DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
3938
3939 if (asserted & GPIO_4_FUNC)
3940 DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
3941
3942 if (port == 0) {
3943 if (asserted & ATTN_GENERAL_ATTN_1) {
3944 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
3945 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
3946 }
3947 if (asserted & ATTN_GENERAL_ATTN_2) {
3948 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
3949 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
3950 }
3951 if (asserted & ATTN_GENERAL_ATTN_3) {
3952 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
3953 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
3954 }
3955 } else {
3956 if (asserted & ATTN_GENERAL_ATTN_4) {
3957 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
3958 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
3959 }
3960 if (asserted & ATTN_GENERAL_ATTN_5) {
3961 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
3962 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
3963 }
3964 if (asserted & ATTN_GENERAL_ATTN_6) {
3965 DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
3966 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
3967 }
3968 }
3969
3970 } /* if hardwired */
3971
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003972 if (bp->common.int_block == INT_BLOCK_HC)
3973 reg_addr = (HC_REG_COMMAND_REG + port*32 +
3974 COMMAND_REG_ATTN_BITS_SET);
3975 else
3976 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
3977
3978 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
3979 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
3980 REG_WR(bp, reg_addr, asserted);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02003981
3982 /* now set back the mask */
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08003983 if (asserted & ATTN_NIG_FOR_FUNC) {
Yaniv Rosner27c11512012-12-02 04:05:54 +00003984 /* Verify that IGU ack through BAR was written before restoring
3985 * NIG mask. This loop should exit after 2-3 iterations max.
3986 */
3987 if (bp->common.int_block != INT_BLOCK_HC) {
3988 u32 cnt = 0, igu_acked;
3989 do {
3990 igu_acked = REG_RD(bp,
3991 IGU_REG_ATTENTION_ACK_BITS);
3992 } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
3993 (++cnt < MAX_IGU_ATTN_ACK_TO));
3994 if (!igu_acked)
3995 DP(NETIF_MSG_HW,
3996 "Failed to verify IGU ack on time\n");
3997 barrier();
3998 }
Eilon Greenstein87942b42009-02-12 08:36:49 +00003999 REG_WR(bp, nig_int_mask_addr, nig_mask);
Eilon Greensteina5e9a7c2009-01-14 21:26:01 -08004000 bnx2x_release_phy_lock(bp);
4001 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004002}
4003
Eric Dumazet1191cb82012-04-27 21:39:21 +00004004static void bnx2x_fan_failure(struct bnx2x *bp)
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004005{
4006 int port = BP_PORT(bp);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004007 u32 ext_phy_config;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004008 /* mark the failure */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004009 ext_phy_config =
4010 SHMEM_RD(bp,
4011 dev_info.port_hw_config[port].external_phy_config);
4012
4013 ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
4014 ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004015 SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004016 ext_phy_config);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004017
4018 /* log the failure */
Merav Sicron51c1a582012-03-18 10:33:38 +00004019 netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
4020 "Please contact OEM Support for assistance\n");
Ariel Elior83048592011-11-13 04:34:29 +00004021
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004022 /* Schedule device reset (unload)
Ariel Elior83048592011-11-13 04:34:29 +00004023 * This is due to some boards consuming sufficient power when driver is
4024 * up to overheat if fan fails.
4025 */
Yuval Mintz230bb0f2014-02-12 18:19:56 +02004026 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004027}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004028
Eric Dumazet1191cb82012-04-27 21:39:21 +00004029static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004030{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004031 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004032 int reg_offset;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00004033 u32 val;
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004034
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004035 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
4036 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004037
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004038 if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004039
4040 val = REG_RD(bp, reg_offset);
4041 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
4042 REG_WR(bp, reg_offset, val);
4043
4044 BNX2X_ERR("SPIO5 hw attention\n");
4045
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004046 /* Fan failure attention */
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00004047 bnx2x_hw_reset_phy(&bp->link_params);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00004048 bnx2x_fan_failure(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004049 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004050
Yaniv Rosner3deb8162011-06-14 01:34:33 +00004051 if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00004052 bnx2x_acquire_phy_lock(bp);
4053 bnx2x_handle_module_detect_int(&bp->link_params);
4054 bnx2x_release_phy_lock(bp);
4055 }
4056
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004057 if (attn & HW_INTERRUT_ASSERT_SET_0) {
4058
4059 val = REG_RD(bp, reg_offset);
4060 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
4061 REG_WR(bp, reg_offset, val);
4062
4063 BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00004064 (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004065 bnx2x_panic();
4066 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004067}
4068
Eric Dumazet1191cb82012-04-27 21:39:21 +00004069static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004070{
4071 u32 val;
4072
Eilon Greenstein0626b892009-02-12 08:38:14 +00004073 if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004074
4075 val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
4076 BNX2X_ERR("DB hw attention 0x%x\n", val);
4077 /* DORQ discard attention */
4078 if (val & 0x2)
4079 BNX2X_ERR("FATAL error from DORQ\n");
4080 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004081
4082 if (attn & HW_INTERRUT_ASSERT_SET_1) {
4083
4084 int port = BP_PORT(bp);
4085 int reg_offset;
4086
4087 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
4088 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
4089
4090 val = REG_RD(bp, reg_offset);
4091 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
4092 REG_WR(bp, reg_offset, val);
4093
4094 BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00004095 (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004096 bnx2x_panic();
4097 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004098}
4099
Eric Dumazet1191cb82012-04-27 21:39:21 +00004100static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004101{
4102 u32 val;
4103
4104 if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
4105
4106 val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
4107 BNX2X_ERR("CFC hw attention 0x%x\n", val);
4108 /* CFC error attention */
4109 if (val & 0x2)
4110 BNX2X_ERR("FATAL error from CFC\n");
4111 }
4112
4113 if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004114 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004115 BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004116 /* RQ_USDMDP_FIFO_OVERFLOW */
4117 if (val & 0x18000)
4118 BNX2X_ERR("FATAL error from PXP\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004119
4120 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004121 val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
4122 BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
4123 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004124 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004125
4126 if (attn & HW_INTERRUT_ASSERT_SET_2) {
4127
4128 int port = BP_PORT(bp);
4129 int reg_offset;
4130
4131 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
4132 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
4133
4134 val = REG_RD(bp, reg_offset);
4135 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
4136 REG_WR(bp, reg_offset, val);
4137
4138 BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
Eilon Greenstein0fc5d002009-08-12 08:24:05 +00004139 (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004140 bnx2x_panic();
4141 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004142}
4143
Eric Dumazet1191cb82012-04-27 21:39:21 +00004144static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004145{
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004146 u32 val;
4147
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004148 if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
4149
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004150 if (attn & BNX2X_PMF_LINK_ASSERT) {
4151 int func = BP_FUNC(bp);
4152
4153 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
Barak Witkowskia3348722012-04-23 03:04:46 +00004154 bnx2x_read_mf_cfg(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004155 bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
4156 func_mf_config[BP_ABS_FUNC(bp)].config);
4157 val = SHMEM_RD(bp,
4158 func_mb[BP_FW_MB_IDX(bp)].drv_status);
Eilon Greenstein2691d512009-08-12 08:22:08 +00004159 if (val & DRV_STATUS_DCC_EVENT_MASK)
4160 bnx2x_dcc_event(bp,
4161 (val & DRV_STATUS_DCC_EVENT_MASK));
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08004162
4163 if (val & DRV_STATUS_SET_MF_BW)
4164 bnx2x_set_mf_bw(bp);
4165
Barak Witkowski1d187b32011-12-05 22:41:50 +00004166 if (val & DRV_STATUS_DRV_INFO_REQ)
4167 bnx2x_handle_drv_info_req(bp);
Ariel Eliord16132c2013-01-01 05:22:42 +00004168
4169 if (val & DRV_STATUS_VF_DISABLED)
Yuval Mintz370d4a22014-03-23 18:12:24 +02004170 bnx2x_schedule_iov_task(bp,
4171 BNX2X_IOV_HANDLE_FLR);
Ariel Eliord16132c2013-01-01 05:22:42 +00004172
Eilon Greenstein2691d512009-08-12 08:22:08 +00004173 if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004174 bnx2x_pmf_update(bp);
4175
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004176 if (bp->port.pmf &&
Shmulik Ravid785b9b12010-12-30 06:27:03 +00004177 (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
4178 bp->dcbx_enabled > 0)
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00004179 /* start dcbx state machine */
4180 bnx2x_dcbx_set_params(bp,
4181 BNX2X_DCBX_STATE_NEG_RECEIVED);
Barak Witkowskia3348722012-04-23 03:04:46 +00004182 if (val & DRV_STATUS_AFEX_EVENT_MASK)
4183 bnx2x_handle_afex_cmd(bp,
4184 val & DRV_STATUS_AFEX_EVENT_MASK);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00004185 if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
4186 bnx2x_handle_eee_event(bp);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00004187 if (bp->link_vars.periodic_flags &
4188 PERIODIC_FLAGS_LINK_EVENT) {
4189 /* sync with link */
4190 bnx2x_acquire_phy_lock(bp);
4191 bp->link_vars.periodic_flags &=
4192 ~PERIODIC_FLAGS_LINK_EVENT;
4193 bnx2x_release_phy_lock(bp);
4194 if (IS_MF(bp))
4195 bnx2x_link_sync_notify(bp);
4196 bnx2x_link_report(bp);
4197 }
4198 /* Always call it here: bnx2x_link_report() will
4199 * prevent the link indication duplication.
4200 */
4201 bnx2x__link_status_update(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004202 } else if (attn & BNX2X_MC_ASSERT_BITS) {
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004203
4204 BNX2X_ERR("MC assert!\n");
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00004205 bnx2x_mc_assert(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004206 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
4207 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
4208 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
4209 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
4210 bnx2x_panic();
4211
4212 } else if (attn & BNX2X_MCP_ASSERT) {
4213
4214 BNX2X_ERR("MCP assert!\n");
4215 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004216 bnx2x_fw_dump(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004217
4218 } else
4219 BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
4220 }
4221
4222 if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004223 BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
4224 if (attn & BNX2X_GRC_TIMEOUT) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004225 val = CHIP_IS_E1(bp) ? 0 :
4226 REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004227 BNX2X_ERR("GRC time-out 0x%08x\n", val);
4228 }
4229 if (attn & BNX2X_GRC_RSV) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004230 val = CHIP_IS_E1(bp) ? 0 :
4231 REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004232 BNX2X_ERR("GRC reserved 0x%08x\n", val);
4233 }
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004234 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004235 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004236}
4237
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004238/*
4239 * Bits map:
4240 * 0-7 - Engine0 load counter.
4241 * 8-15 - Engine1 load counter.
4242 * 16 - Engine0 RESET_IN_PROGRESS bit.
4243 * 17 - Engine1 RESET_IN_PROGRESS bit.
4244 * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
4245 * on the engine
4246 * 19 - Engine1 ONE_IS_LOADED.
4247 * 20 - Chip reset flow bit. When set none-leader must wait for both engines
4248 * leader to complete (check for both RESET_IN_PROGRESS bits and not for
4249 * just the one belonging to its engine).
4250 *
4251 */
4252#define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
4253
4254#define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
4255#define BNX2X_PATH0_LOAD_CNT_SHIFT 0
4256#define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
4257#define BNX2X_PATH1_LOAD_CNT_SHIFT 8
4258#define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
4259#define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
4260#define BNX2X_GLOBAL_RESET_BIT 0x00040000
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00004261
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004262/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004263 * Set the GLOBAL_RESET bit.
4264 *
4265 * Should be run under rtnl lock
4266 */
4267void bnx2x_set_reset_global(struct bnx2x *bp)
4268{
Ariel Eliorf16da432012-01-26 06:01:50 +00004269 u32 val;
4270 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4271 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004272 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
Ariel Eliorf16da432012-01-26 06:01:50 +00004273 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004274}
4275
4276/*
4277 * Clear the GLOBAL_RESET bit.
4278 *
4279 * Should be run under rtnl lock
4280 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004281static void bnx2x_clear_reset_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004282{
Ariel Eliorf16da432012-01-26 06:01:50 +00004283 u32 val;
4284 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4285 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004286 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
Ariel Eliorf16da432012-01-26 06:01:50 +00004287 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004288}
4289
4290/*
4291 * Checks the GLOBAL_RESET bit.
4292 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004293 * should be run under rtnl lock
4294 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004295static bool bnx2x_reset_is_global(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004296{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004297 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004298
4299 DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
4300 return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
4301}
4302
4303/*
4304 * Clear RESET_IN_PROGRESS bit for the current engine.
4305 *
4306 * Should be run under rtnl lock
4307 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004308static void bnx2x_set_reset_done(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004309{
Ariel Eliorf16da432012-01-26 06:01:50 +00004310 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004311 u32 bit = BP_PATH(bp) ?
4312 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004313 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4314 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004315
4316 /* Clear the bit */
4317 val &= ~bit;
4318 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004319
4320 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004321}
4322
4323/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004324 * Set RESET_IN_PROGRESS for the current engine.
4325 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004326 * should be run under rtnl lock
4327 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004328void bnx2x_set_reset_in_progress(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004329{
Ariel Eliorf16da432012-01-26 06:01:50 +00004330 u32 val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004331 u32 bit = BP_PATH(bp) ?
4332 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
Ariel Eliorf16da432012-01-26 06:01:50 +00004333 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4334 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004335
4336 /* Set the bit */
4337 val |= bit;
4338 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004339 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004340}
4341
4342/*
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004343 * Checks the RESET_IN_PROGRESS bit for the given engine.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004344 * should be run under rtnl lock
4345 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004346bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004347{
Yuval Mintz3cdeec22013-06-02 00:06:19 +00004348 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004349 u32 bit = engine ?
4350 BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
4351
4352 /* return false if bit is set */
4353 return (val & bit) ? false : true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004354}
4355
4356/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004357 * set pf load for the current pf.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004358 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004359 * should be run under rtnl lock
4360 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004361void bnx2x_set_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004362{
Ariel Eliorf16da432012-01-26 06:01:50 +00004363 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004364 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4365 BNX2X_PATH0_LOAD_CNT_MASK;
4366 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4367 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004368
Ariel Eliorf16da432012-01-26 06:01:50 +00004369 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4370 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4371
Merav Sicron51c1a582012-03-18 10:33:38 +00004372 DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004373
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004374 /* get the current counter value */
4375 val1 = (val & mask) >> shift;
4376
Ariel Elior889b9af2012-01-26 06:01:51 +00004377 /* set bit of that PF */
4378 val1 |= (1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004379
4380 /* clear the old value */
4381 val &= ~mask;
4382
4383 /* set the new one */
4384 val |= ((val1 << shift) & mask);
4385
4386 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004387 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004388}
4389
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004390/**
Ariel Elior889b9af2012-01-26 06:01:51 +00004391 * bnx2x_clear_pf_load - clear pf load mark
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004392 *
4393 * @bp: driver handle
4394 *
4395 * Should be run under rtnl lock.
4396 * Decrements the load counter for the current engine. Returns
Ariel Elior889b9af2012-01-26 06:01:51 +00004397 * whether other functions are still loaded
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004398 */
Ariel Elior889b9af2012-01-26 06:01:51 +00004399bool bnx2x_clear_pf_load(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004400{
Ariel Eliorf16da432012-01-26 06:01:50 +00004401 u32 val1, val;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004402 u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
4403 BNX2X_PATH0_LOAD_CNT_MASK;
4404 u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4405 BNX2X_PATH0_LOAD_CNT_SHIFT;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004406
Ariel Eliorf16da432012-01-26 06:01:50 +00004407 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4408 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
Merav Sicron51c1a582012-03-18 10:33:38 +00004409 DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004410
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004411 /* get the current counter value */
4412 val1 = (val & mask) >> shift;
4413
Ariel Elior889b9af2012-01-26 06:01:51 +00004414 /* clear bit of that PF */
4415 val1 &= ~(1 << bp->pf_num);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004416
4417 /* clear the old value */
4418 val &= ~mask;
4419
4420 /* set the new one */
4421 val |= ((val1 << shift) & mask);
4422
4423 REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
Ariel Eliorf16da432012-01-26 06:01:50 +00004424 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
4425 return val1 != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004426}
4427
4428/*
Ariel Elior889b9af2012-01-26 06:01:51 +00004429 * Read the load status for the current engine.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004430 *
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004431 * should be run under rtnl lock
4432 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00004433static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004434{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004435 u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
4436 BNX2X_PATH0_LOAD_CNT_MASK);
4437 u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
4438 BNX2X_PATH0_LOAD_CNT_SHIFT);
4439 u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
4440
Merav Sicron51c1a582012-03-18 10:33:38 +00004441 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004442
4443 val = (val & mask) >> shift;
4444
Merav Sicron51c1a582012-03-18 10:33:38 +00004445 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
4446 engine, val);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004447
Ariel Elior889b9af2012-01-26 06:01:51 +00004448 return val != 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004449}
4450
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004451static void _print_parity(struct bnx2x *bp, u32 reg)
4452{
4453 pr_cont(" [0x%08x] ", REG_RD(bp, reg));
4454}
4455
Eric Dumazet1191cb82012-04-27 21:39:21 +00004456static void _print_next_block(int idx, const char *blk)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004457{
Joe Perchesf1deab52011-08-14 12:16:21 +00004458 pr_cont("%s%s", idx ? ", " : "", blk);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004459}
4460
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004461static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4462 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004463{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004464 u32 cur_bit;
4465 bool res;
4466 int i;
4467
4468 res = false;
4469
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004470 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004471 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004472 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004473 res |= true; /* Each bit is real error! */
4474
4475 if (print) {
4476 switch (cur_bit) {
4477 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4478 _print_next_block((*par_num)++, "BRB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004479 _print_parity(bp,
4480 BRB1_REG_BRB1_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004481 break;
4482 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4483 _print_next_block((*par_num)++,
4484 "PARSER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004485 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004486 break;
4487 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4488 _print_next_block((*par_num)++, "TSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004489 _print_parity(bp,
4490 TSDM_REG_TSDM_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004491 break;
4492 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4493 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004494 "SEARCHER");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004495 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004496 break;
4497 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4498 _print_next_block((*par_num)++, "TCM");
4499 _print_parity(bp, TCM_REG_TCM_PRTY_STS);
4500 break;
4501 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4502 _print_next_block((*par_num)++,
4503 "TSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004504 _print_parity(bp,
4505 TSEM_REG_TSEM_PRTY_STS_0);
4506 _print_parity(bp,
4507 TSEM_REG_TSEM_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004508 break;
4509 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4510 _print_next_block((*par_num)++, "XPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004511 _print_parity(bp, GRCBASE_XPB +
4512 PB_REG_PB_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004513 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004514 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004515 }
4516
4517 /* Clear the bit */
4518 sig &= ~cur_bit;
4519 }
4520 }
4521
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004522 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004523}
4524
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004525static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4526 int *par_num, bool *global,
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004527 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004528{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004529 u32 cur_bit;
4530 bool res;
4531 int i;
4532
4533 res = false;
4534
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004535 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004536 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004537 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004538 res |= true; /* Each bit is real error! */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004539 switch (cur_bit) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004540 case AEU_INPUTS_ATTN_BITS_PBF_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)++, "PBF");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004543 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4544 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004545 break;
4546 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004547 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004548 _print_next_block((*par_num)++, "QM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004549 _print_parity(bp, QM_REG_QM_PRTY_STS);
4550 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004551 break;
4552 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004553 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004554 _print_next_block((*par_num)++, "TM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004555 _print_parity(bp, TM_REG_TM_PRTY_STS);
4556 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004557 break;
4558 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004559 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004560 _print_next_block((*par_num)++, "XSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004561 _print_parity(bp,
4562 XSDM_REG_XSDM_PRTY_STS);
4563 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004564 break;
4565 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004566 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004567 _print_next_block((*par_num)++, "XCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004568 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4569 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004570 break;
4571 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004572 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004573 _print_next_block((*par_num)++,
4574 "XSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004575 _print_parity(bp,
4576 XSEM_REG_XSEM_PRTY_STS_0);
4577 _print_parity(bp,
4578 XSEM_REG_XSEM_PRTY_STS_1);
4579 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004580 break;
4581 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004582 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004583 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004584 "DOORBELLQ");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004585 _print_parity(bp,
4586 DORQ_REG_DORQ_PRTY_STS);
4587 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004588 break;
4589 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004590 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004591 _print_next_block((*par_num)++, "NIG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004592 if (CHIP_IS_E1x(bp)) {
4593 _print_parity(bp,
4594 NIG_REG_NIG_PRTY_STS);
4595 } else {
4596 _print_parity(bp,
4597 NIG_REG_NIG_PRTY_STS_0);
4598 _print_parity(bp,
4599 NIG_REG_NIG_PRTY_STS_1);
4600 }
4601 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004602 break;
4603 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004604 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004605 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004606 "VAUX PCI CORE");
4607 *global = true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004608 break;
4609 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004610 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004611 _print_next_block((*par_num)++,
4612 "DEBUG");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004613 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4614 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004615 break;
4616 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004617 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004618 _print_next_block((*par_num)++, "USDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004619 _print_parity(bp,
4620 USDM_REG_USDM_PRTY_STS);
4621 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004622 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004623 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004624 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004625 _print_next_block((*par_num)++, "UCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004626 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4627 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004628 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004629 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004630 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004631 _print_next_block((*par_num)++,
4632 "USEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004633 _print_parity(bp,
4634 USEM_REG_USEM_PRTY_STS_0);
4635 _print_parity(bp,
4636 USEM_REG_USEM_PRTY_STS_1);
4637 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004638 break;
4639 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004640 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004641 _print_next_block((*par_num)++, "UPB");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004642 _print_parity(bp, GRCBASE_UPB +
4643 PB_REG_PB_PRTY_STS);
4644 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004645 break;
4646 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004647 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004648 _print_next_block((*par_num)++, "CSDM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004649 _print_parity(bp,
4650 CSDM_REG_CSDM_PRTY_STS);
4651 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004652 break;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004653 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004654 if (print) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004655 _print_next_block((*par_num)++, "CCM");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004656 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4657 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004658 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004659 }
4660
4661 /* Clear the bit */
4662 sig &= ~cur_bit;
4663 }
4664 }
4665
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004666 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004667}
4668
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004669static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4670 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004671{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004672 u32 cur_bit;
4673 bool res;
4674 int i;
4675
4676 res = false;
4677
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004678 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004679 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004680 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004681 res |= true; /* Each bit is real error! */
4682 if (print) {
4683 switch (cur_bit) {
4684 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4685 _print_next_block((*par_num)++,
4686 "CSEMI");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004687 _print_parity(bp,
4688 CSEM_REG_CSEM_PRTY_STS_0);
4689 _print_parity(bp,
4690 CSEM_REG_CSEM_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004691 break;
4692 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4693 _print_next_block((*par_num)++, "PXP");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004694 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4695 _print_parity(bp,
4696 PXP2_REG_PXP2_PRTY_STS_0);
4697 _print_parity(bp,
4698 PXP2_REG_PXP2_PRTY_STS_1);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004699 break;
4700 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4701 _print_next_block((*par_num)++,
4702 "PXPPCICLOCKCLIENT");
4703 break;
4704 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4705 _print_next_block((*par_num)++, "CFC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004706 _print_parity(bp,
4707 CFC_REG_CFC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004708 break;
4709 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4710 _print_next_block((*par_num)++, "CDU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004711 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004712 break;
4713 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4714 _print_next_block((*par_num)++, "DMAE");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004715 _print_parity(bp,
4716 DMAE_REG_DMAE_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004717 break;
4718 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4719 _print_next_block((*par_num)++, "IGU");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004720 if (CHIP_IS_E1x(bp))
4721 _print_parity(bp,
4722 HC_REG_HC_PRTY_STS);
4723 else
4724 _print_parity(bp,
4725 IGU_REG_IGU_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004726 break;
4727 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4728 _print_next_block((*par_num)++, "MISC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004729 _print_parity(bp,
4730 MISC_REG_MISC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004731 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004732 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004733 }
4734
4735 /* Clear the bit */
4736 sig &= ~cur_bit;
4737 }
4738 }
4739
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004740 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004741}
4742
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004743static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
4744 int *par_num, bool *global,
4745 bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004746{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004747 bool res = false;
4748 u32 cur_bit;
4749 int i;
4750
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004751 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004752 cur_bit = (0x1UL << i);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004753 if (sig & cur_bit) {
4754 switch (cur_bit) {
4755 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004756 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004757 _print_next_block((*par_num)++,
4758 "MCP ROM");
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004759 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004760 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004761 break;
4762 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004763 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004764 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004765 "MCP UMP RX");
4766 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004767 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004768 break;
4769 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004770 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004771 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004772 "MCP UMP TX");
4773 *global = true;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004774 res |= true;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004775 break;
4776 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004777 if (print)
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004778 _print_next_block((*par_num)++,
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004779 "MCP SCPAD");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004780 /* clear latched SCPAD PATIRY from MCP */
4781 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
4782 1UL << 10);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004783 break;
4784 }
4785
4786 /* Clear the bit */
4787 sig &= ~cur_bit;
4788 }
4789 }
4790
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004791 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004792}
4793
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004794static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4795 int *par_num, bool print)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004796{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004797 u32 cur_bit;
4798 bool res;
4799 int i;
4800
4801 res = false;
4802
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004803 for (i = 0; sig; i++) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004804 cur_bit = (0x1UL << i);
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004805 if (sig & cur_bit) {
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004806 res |= true; /* Each bit is real error! */
4807 if (print) {
4808 switch (cur_bit) {
4809 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4810 _print_next_block((*par_num)++,
4811 "PGLUE_B");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004812 _print_parity(bp,
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004813 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4814 break;
4815 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4816 _print_next_block((*par_num)++, "ATC");
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004817 _print_parity(bp,
4818 ATC_REG_ATC_PRTY_STS);
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004819 break;
Yuval Mintz6bf07b82013-06-02 00:06:20 +00004820 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004821 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004822 /* Clear the bit */
4823 sig &= ~cur_bit;
4824 }
4825 }
4826
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004827 return res;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004828}
4829
Eric Dumazet1191cb82012-04-27 21:39:21 +00004830static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4831 u32 *sig)
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004832{
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004833 bool res = false;
4834
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004835 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4836 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4837 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
4838 (sig[3] & HW_PRTY_ASSERT_SET_3) ||
4839 (sig[4] & HW_PRTY_ASSERT_SET_4)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004840 int par_num = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +00004841 DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
4842 "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004843 sig[0] & HW_PRTY_ASSERT_SET_0,
4844 sig[1] & HW_PRTY_ASSERT_SET_1,
4845 sig[2] & HW_PRTY_ASSERT_SET_2,
4846 sig[3] & HW_PRTY_ASSERT_SET_3,
4847 sig[4] & HW_PRTY_ASSERT_SET_4);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004848 if (print)
4849 netdev_err(bp->dev,
4850 "Parity errors detected in blocks: ");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004851 res |= bnx2x_check_blocks_with_parity0(bp,
4852 sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
4853 res |= bnx2x_check_blocks_with_parity1(bp,
4854 sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
4855 res |= bnx2x_check_blocks_with_parity2(bp,
4856 sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
4857 res |= bnx2x_check_blocks_with_parity3(bp,
4858 sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
4859 res |= bnx2x_check_blocks_with_parity4(bp,
4860 sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004861
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004862 if (print)
4863 pr_cont("\n");
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004864 }
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004865
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02004866 return res;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004867}
4868
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004869/**
4870 * bnx2x_chk_parity_attn - checks for parity attentions.
4871 *
4872 * @bp: driver handle
4873 * @global: true if there was a global attention
4874 * @print: show parity attention in syslog
4875 */
4876bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004877{
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004878 struct attn_route attn = { {0} };
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004879 int port = BP_PORT(bp);
4880
4881 attn.sig[0] = REG_RD(bp,
4882 MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
4883 port*4);
4884 attn.sig[1] = REG_RD(bp,
4885 MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
4886 port*4);
4887 attn.sig[2] = REG_RD(bp,
4888 MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
4889 port*4);
4890 attn.sig[3] = REG_RD(bp,
4891 MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
4892 port*4);
Yuval Mintz0a5ccb72013-09-23 10:12:54 +03004893 /* Since MCP attentions can't be disabled inside the block, we need to
4894 * read AEU registers to see whether they're currently disabled
4895 */
4896 attn.sig[3] &= ((REG_RD(bp,
4897 !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
4898 : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
4899 MISC_AEU_ENABLE_MCP_PRTY_BITS) |
4900 ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004901
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00004902 if (!CHIP_IS_E1x(bp))
4903 attn.sig[4] = REG_RD(bp,
4904 MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
4905 port*4);
4906
4907 return bnx2x_parity_attn(bp, global, print, attn.sig);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004908}
4909
Eric Dumazet1191cb82012-04-27 21:39:21 +00004910static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004911{
4912 u32 val;
4913 if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
4914
4915 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
4916 BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
4917 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004918 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004919 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
Merav Sicron51c1a582012-03-18 10:33:38 +00004920 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004921 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004922 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004923 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004924 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004925 if (val &
4926 PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004927 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004928 if (val &
4929 PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004930 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004931 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004932 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004933 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
Merav Sicron51c1a582012-03-18 10:33:38 +00004934 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004935 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
Merav Sicron51c1a582012-03-18 10:33:38 +00004936 BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004937 }
4938 if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
4939 val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
4940 BNX2X_ERR("ATC hw attention 0x%x\n", val);
4941 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
4942 BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
4943 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
Merav Sicron51c1a582012-03-18 10:33:38 +00004944 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004945 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
Merav Sicron51c1a582012-03-18 10:33:38 +00004946 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004947 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
Merav Sicron51c1a582012-03-18 10:33:38 +00004948 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004949 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
4950 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
4951 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
Merav Sicron51c1a582012-03-18 10:33:38 +00004952 BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004953 }
4954
4955 if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4956 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
4957 BNX2X_ERR("FATAL parity attention set4 0x%x\n",
4958 (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
4959 AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
4960 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004961}
4962
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004963static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
4964{
4965 struct attn_route attn, *group_mask;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07004966 int port = BP_PORT(bp);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08004967 int index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004968 u32 reg_addr;
4969 u32 val;
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07004970 u32 aeu_mask;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004971 bool global = false;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004972
4973 /* need to take HW lock because MCP or other port might also
4974 try to handle this event */
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07004975 bnx2x_acquire_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004976
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004977 if (bnx2x_chk_parity_attn(bp, &global, true)) {
4978#ifndef BNX2X_STOP_ON_ERROR
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004979 bp->recovery_state = BNX2X_RECOVERY_INIT;
Ariel Elior7be08a72011-07-14 08:31:19 +00004980 schedule_delayed_work(&bp->sp_rtnl_task, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004981 /* Disable HW interrupts */
4982 bnx2x_int_disable(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004983 /* In case of parity errors don't handle attentions so that
4984 * other function would "see" parity errors.
4985 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00004986#else
4987 bnx2x_panic();
4988#endif
4989 bnx2x_release_alr(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00004990 return;
4991 }
4992
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004993 attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
4994 attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
4995 attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
4996 attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004997 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004998 attn.sig[4] =
4999 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
5000 else
5001 attn.sig[4] = 0;
5002
5003 DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
5004 attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005005
5006 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
5007 if (deasserted & (1 << index)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005008 group_mask = &bp->attn_group[index];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005009
Merav Sicron51c1a582012-03-18 10:33:38 +00005010 DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005011 index,
5012 group_mask->sig[0], group_mask->sig[1],
5013 group_mask->sig[2], group_mask->sig[3],
5014 group_mask->sig[4]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005015
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005016 bnx2x_attn_int_deasserted4(bp,
5017 attn.sig[4] & group_mask->sig[4]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08005018 bnx2x_attn_int_deasserted3(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005019 attn.sig[3] & group_mask->sig[3]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08005020 bnx2x_attn_int_deasserted1(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005021 attn.sig[1] & group_mask->sig[1]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08005022 bnx2x_attn_int_deasserted2(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005023 attn.sig[2] & group_mask->sig[2]);
Eliezer Tamir877e9aa2008-02-28 11:55:53 -08005024 bnx2x_attn_int_deasserted0(bp,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005025 attn.sig[0] & group_mask->sig[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005026 }
5027 }
5028
Yitchak Gertner4a37fb62008-08-13 15:50:23 -07005029 bnx2x_release_alr(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005030
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005031 if (bp->common.int_block == INT_BLOCK_HC)
5032 reg_addr = (HC_REG_COMMAND_REG + port*32 +
5033 COMMAND_REG_ATTN_BITS_CLR);
5034 else
5035 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005036
5037 val = ~deasserted;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005038 DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
5039 (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
Eilon Greenstein5c862842008-08-13 15:51:48 -07005040 REG_WR(bp, reg_addr, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005041
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005042 if (~bp->attn_state & deasserted)
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07005043 BNX2X_ERR("IGU ERROR\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005044
5045 reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
5046 MISC_REG_AEU_MASK_ATTN_FUNC_0;
5047
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07005048 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
5049 aeu_mask = REG_RD(bp, reg_addr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005050
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07005051 DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
5052 aeu_mask, deasserted);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00005053 aeu_mask |= (deasserted & 0x3ff);
Eilon Greenstein3fcaf2e2008-08-13 15:50:45 -07005054 DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
5055
5056 REG_WR(bp, reg_addr, aeu_mask);
5057 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005058
5059 DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
5060 bp->attn_state &= ~deasserted;
5061 DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
5062}
5063
5064static void bnx2x_attn_int(struct bnx2x *bp)
5065{
5066 /* read local copy of bits */
Eilon Greenstein68d59482009-01-14 21:27:36 -08005067 u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
5068 attn_bits);
5069 u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
5070 attn_bits_ack);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005071 u32 attn_state = bp->attn_state;
5072
5073 /* look for changed bits */
5074 u32 asserted = attn_bits & ~attn_ack & ~attn_state;
5075 u32 deasserted = ~attn_bits & attn_ack & attn_state;
5076
5077 DP(NETIF_MSG_HW,
5078 "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
5079 attn_bits, attn_ack, asserted, deasserted);
5080
5081 if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005082 BNX2X_ERR("BAD attention state\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005083
5084 /* handle bits that were raised */
5085 if (asserted)
5086 bnx2x_attn_int_asserted(bp, asserted);
5087
5088 if (deasserted)
5089 bnx2x_attn_int_deasserted(bp, deasserted);
5090}
5091
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005092void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
5093 u16 index, u8 op, u8 update)
5094{
Ariel Eliordc1ba592013-01-01 05:22:30 +00005095 u32 igu_addr = bp->igu_base_addr;
5096 igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005097 bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
5098 igu_addr);
5099}
5100
Eric Dumazet1191cb82012-04-27 21:39:21 +00005101static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005102{
5103 /* No memory barriers */
5104 storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
5105 mmiowb(); /* keep prod updates ordered */
5106}
5107
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005108static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
5109 union event_ring_elem *elem)
5110{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005111 u8 err = elem->message.error;
5112
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005113 if (!bp->cnic_eth_dev.starting_cid ||
Vladislav Zolotarovc3a8ce62011-05-22 10:08:09 +00005114 (cid < bp->cnic_eth_dev.starting_cid &&
5115 cid != bp->cnic_eth_dev.iscsi_l2_cid))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005116 return 1;
5117
5118 DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
5119
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005120 if (unlikely(err)) {
5121
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005122 BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
5123 cid);
Yuval Mintz823e1d92013-01-14 05:11:47 +00005124 bnx2x_panic_dump(bp, false);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005125 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005126 bnx2x_cnic_cfc_comp(bp, cid, err);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005127 return 0;
5128}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005129
Eric Dumazet1191cb82012-04-27 21:39:21 +00005130static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005131{
5132 struct bnx2x_mcast_ramrod_params rparam;
5133 int rc;
5134
5135 memset(&rparam, 0, sizeof(rparam));
5136
5137 rparam.mcast_obj = &bp->mcast_obj;
5138
5139 netif_addr_lock_bh(bp->dev);
5140
5141 /* Clear pending state for the last command */
5142 bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
5143
5144 /* If there are pending mcast commands - send them */
5145 if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
5146 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
5147 if (rc < 0)
5148 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
5149 rc);
5150 }
5151
5152 netif_addr_unlock_bh(bp->dev);
5153}
5154
Eric Dumazet1191cb82012-04-27 21:39:21 +00005155static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
5156 union event_ring_elem *elem)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005157{
5158 unsigned long ramrod_flags = 0;
5159 int rc = 0;
5160 u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
5161 struct bnx2x_vlan_mac_obj *vlan_mac_obj;
5162
5163 /* Always push next commands out, don't wait here */
5164 __set_bit(RAMROD_CONT, &ramrod_flags);
5165
Yuval Mintz86564c32013-01-23 03:21:50 +00005166 switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
5167 >> BNX2X_SWCID_SHIFT) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005168 case BNX2X_FILTER_MAC_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00005169 DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
Merav Sicron55c11942012-11-07 00:45:48 +00005170 if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005171 vlan_mac_obj = &bp->iscsi_l2_mac_obj;
5172 else
Barak Witkowski15192a82012-06-19 07:48:28 +00005173 vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005174
5175 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005176 case BNX2X_FILTER_MCAST_PENDING:
Merav Sicron51c1a582012-03-18 10:33:38 +00005177 DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005178 /* This is only relevant for 57710 where multicast MACs are
5179 * configured as unicast MACs using the same ramrod.
5180 */
5181 bnx2x_handle_mcast_eqe(bp);
5182 return;
5183 default:
5184 BNX2X_ERR("Unsupported classification command: %d\n",
5185 elem->message.data.eth_event.echo);
5186 return;
5187 }
5188
5189 rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
5190
5191 if (rc < 0)
5192 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
5193 else if (rc > 0)
5194 DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005195}
5196
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005197static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005198
Eric Dumazet1191cb82012-04-27 21:39:21 +00005199static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005200{
5201 netif_addr_lock_bh(bp->dev);
5202
5203 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
5204
5205 /* Send rx_mode command again if was requested */
5206 if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
5207 bnx2x_set_storm_rx_mode(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005208 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
5209 &bp->sp_state))
5210 bnx2x_set_iscsi_eth_rx_mode(bp, true);
5211 else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
5212 &bp->sp_state))
5213 bnx2x_set_iscsi_eth_rx_mode(bp, false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005214
5215 netif_addr_unlock_bh(bp->dev);
5216}
5217
Eric Dumazet1191cb82012-04-27 21:39:21 +00005218static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
Barak Witkowskia3348722012-04-23 03:04:46 +00005219 union event_ring_elem *elem)
5220{
5221 if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
5222 DP(BNX2X_MSG_SP,
5223 "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
5224 elem->message.data.vif_list_event.func_bit_map);
5225 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
5226 elem->message.data.vif_list_event.func_bit_map);
5227 } else if (elem->message.data.vif_list_event.echo ==
5228 VIF_LIST_RULE_SET) {
5229 DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
5230 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
5231 }
5232}
5233
5234/* called with rtnl_lock */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005235static void bnx2x_after_function_update(struct bnx2x *bp)
Barak Witkowskia3348722012-04-23 03:04:46 +00005236{
5237 int q, rc;
5238 struct bnx2x_fastpath *fp;
5239 struct bnx2x_queue_state_params queue_params = {NULL};
5240 struct bnx2x_queue_update_params *q_update_params =
5241 &queue_params.params.update;
5242
Yuval Mintz2de67432013-01-23 03:21:43 +00005243 /* Send Q update command with afex vlan removal values for all Qs */
Barak Witkowskia3348722012-04-23 03:04:46 +00005244 queue_params.cmd = BNX2X_Q_CMD_UPDATE;
5245
5246 /* set silent vlan removal values according to vlan mode */
5247 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
5248 &q_update_params->update_flags);
5249 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
5250 &q_update_params->update_flags);
5251 __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5252
5253 /* in access mode mark mask and value are 0 to strip all vlans */
5254 if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
5255 q_update_params->silent_removal_value = 0;
5256 q_update_params->silent_removal_mask = 0;
5257 } else {
5258 q_update_params->silent_removal_value =
5259 (bp->afex_def_vlan_tag & VLAN_VID_MASK);
5260 q_update_params->silent_removal_mask = VLAN_VID_MASK;
5261 }
5262
5263 for_each_eth_queue(bp, q) {
5264 /* Set the appropriate Queue object */
5265 fp = &bp->fp[q];
Barak Witkowski15192a82012-06-19 07:48:28 +00005266 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005267
5268 /* send the ramrod */
5269 rc = bnx2x_queue_state_change(bp, &queue_params);
5270 if (rc < 0)
5271 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5272 q);
5273 }
5274
Yuval Mintzfea75642013-04-10 13:34:39 +03005275 if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
Merav Sicron65565882012-06-19 07:48:26 +00005276 fp = &bp->fp[FCOE_IDX(bp)];
Barak Witkowski15192a82012-06-19 07:48:28 +00005277 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Barak Witkowskia3348722012-04-23 03:04:46 +00005278
5279 /* clear pending completion bit */
5280 __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
5281
5282 /* mark latest Q bit */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005283 smp_mb__before_atomic();
Barak Witkowskia3348722012-04-23 03:04:46 +00005284 set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005285 smp_mb__after_atomic();
Barak Witkowskia3348722012-04-23 03:04:46 +00005286
5287 /* send Q update ramrod for FCoE Q */
5288 rc = bnx2x_queue_state_change(bp, &queue_params);
5289 if (rc < 0)
5290 BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
5291 q);
5292 } else {
5293 /* If no FCoE ring - ACK MCP now */
5294 bnx2x_link_report(bp);
5295 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5296 }
Barak Witkowskia3348722012-04-23 03:04:46 +00005297}
5298
Eric Dumazet1191cb82012-04-27 21:39:21 +00005299static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005300 struct bnx2x *bp, u32 cid)
5301{
Joe Perches94f05b02011-08-14 12:16:20 +00005302 DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005303
5304 if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
Barak Witkowski15192a82012-06-19 07:48:28 +00005305 return &bnx2x_fcoe_sp_obj(bp, q_obj);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005306 else
Barak Witkowski15192a82012-06-19 07:48:28 +00005307 return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005308}
5309
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005310static void bnx2x_eq_int(struct bnx2x *bp)
5311{
5312 u16 hw_cons, sw_cons, sw_prod;
5313 union event_ring_elem *elem;
Merav Sicron55c11942012-11-07 00:45:48 +00005314 u8 echo;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005315 u32 cid;
5316 u8 opcode;
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005317 int rc, spqe_cnt = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005318 struct bnx2x_queue_sp_obj *q_obj;
5319 struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
5320 struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005321
5322 hw_cons = le16_to_cpu(*bp->eq_cons_sb);
5323
5324 /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005325 * when we get the next-page we need to adjust so the loop
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005326 * condition below will be met. The next element is the size of a
5327 * regular element and hence incrementing by 1
5328 */
5329 if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
5330 hw_cons++;
5331
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005332 /* This function may never run in parallel with itself for a
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005333 * specific bp, thus there is no need in "paired" read memory
5334 * barrier here.
5335 */
5336 sw_cons = bp->eq_cons;
5337 sw_prod = bp->eq_prod;
5338
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005339 DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005340 hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005341
5342 for (; sw_cons != hw_cons;
5343 sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
5344
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005345 elem = &bp->eq_ring[EQ_DESC(sw_cons)];
5346
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005347 rc = bnx2x_iov_eq_sp_event(bp, elem);
5348 if (!rc) {
5349 DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
5350 rc);
5351 goto next_spqe;
5352 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005353
Yuval Mintz86564c32013-01-23 03:21:50 +00005354 /* elem CID originates from FW; actually LE */
5355 cid = SW_CID((__force __le32)
5356 elem->message.data.cfc_del_event.cid);
5357 opcode = elem->message.opcode;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005358
5359 /* handle eq element */
5360 switch (opcode) {
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005361 case EVENT_RING_OPCODE_VF_PF_CHANNEL:
Yuval Mintz370d4a22014-03-23 18:12:24 +02005362 bnx2x_vf_mbx_schedule(bp,
5363 &elem->message.data.vf_pf_event);
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005364 continue;
5365
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005366 case EVENT_RING_OPCODE_STAT_QUERY:
Yuval Mintz76ca70f2014-02-12 18:19:49 +02005367 DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
5368 "got statistics comp event %d\n",
5369 bp->stats_comp++);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005370 /* nothing to do with stats comp */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005371 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005372
5373 case EVENT_RING_OPCODE_CFC_DEL:
5374 /* handle according to cid range */
5375 /*
5376 * we may want to verify here that the bp state is
5377 * HALTING
5378 */
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005379 DP(BNX2X_MSG_SP,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005380 "got delete ramrod for MULTI[%d]\n", cid);
Merav Sicron55c11942012-11-07 00:45:48 +00005381
5382 if (CNIC_LOADED(bp) &&
5383 !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005384 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005385
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005386 q_obj = bnx2x_cid_to_q_obj(bp, cid);
5387
5388 if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
5389 break;
5390
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005391 goto next_spqe;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005392
5393 case EVENT_RING_OPCODE_STOP_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005394 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02005395 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005396 if (f_obj->complete_cmd(bp, f_obj,
5397 BNX2X_F_CMD_TX_STOP))
5398 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005399 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005400
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005401 case EVENT_RING_OPCODE_START_TRAFFIC:
Merav Sicron51c1a582012-03-18 10:33:38 +00005402 DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02005403 bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005404 if (f_obj->complete_cmd(bp, f_obj,
5405 BNX2X_F_CMD_TX_START))
5406 break;
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00005407 goto next_spqe;
Merav Sicron55c11942012-11-07 00:45:48 +00005408
Barak Witkowskia3348722012-04-23 03:04:46 +00005409 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
Merav Sicron55c11942012-11-07 00:45:48 +00005410 echo = elem->message.data.function_update_event.echo;
5411 if (echo == SWITCH_UPDATE) {
5412 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5413 "got FUNC_SWITCH_UPDATE ramrod\n");
5414 if (f_obj->complete_cmd(
5415 bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
5416 break;
Barak Witkowskia3348722012-04-23 03:04:46 +00005417
Merav Sicron55c11942012-11-07 00:45:48 +00005418 } else {
Yuval Mintz230bb0f2014-02-12 18:19:56 +02005419 int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
5420
Merav Sicron55c11942012-11-07 00:45:48 +00005421 DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
5422 "AFEX: ramrod completed FUNCTION_UPDATE\n");
5423 f_obj->complete_cmd(bp, f_obj,
5424 BNX2X_F_CMD_AFEX_UPDATE);
Barak Witkowskia3348722012-04-23 03:04:46 +00005425
Merav Sicron55c11942012-11-07 00:45:48 +00005426 /* We will perform the Queues update from
5427 * sp_rtnl task as all Queue SP operations
5428 * should run under rtnl_lock.
5429 */
Yuval Mintz230bb0f2014-02-12 18:19:56 +02005430 bnx2x_schedule_sp_rtnl(bp, cmd, 0);
Merav Sicron55c11942012-11-07 00:45:48 +00005431 }
5432
Barak Witkowskia3348722012-04-23 03:04:46 +00005433 goto next_spqe;
5434
5435 case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
5436 f_obj->complete_cmd(bp, f_obj,
5437 BNX2X_F_CMD_AFEX_VIFLISTS);
5438 bnx2x_after_afex_vif_lists(bp, elem);
5439 goto next_spqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005440 case EVENT_RING_OPCODE_FUNCTION_START:
Merav Sicron51c1a582012-03-18 10:33:38 +00005441 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5442 "got FUNC_START ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005443 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
5444 break;
5445
5446 goto next_spqe;
5447
5448 case EVENT_RING_OPCODE_FUNCTION_STOP:
Merav Sicron51c1a582012-03-18 10:33:38 +00005449 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
5450 "got FUNC_STOP ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005451 if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
5452 break;
5453
5454 goto next_spqe;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005455 }
5456
5457 switch (opcode | bp->state) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005458 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
5459 BNX2X_STATE_OPEN):
5460 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005461 BNX2X_STATE_OPENING_WAIT4_PORT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005462 cid = elem->message.data.eth_event.echo &
5463 BNX2X_SWCID_MASK;
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005464 DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005465 cid);
5466 rss_raw->clear_pending(rss_raw);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005467 break;
5468
5469 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
5470 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005471 case (EVENT_RING_OPCODE_SET_MAC |
5472 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005473 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5474 BNX2X_STATE_OPEN):
5475 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5476 BNX2X_STATE_DIAG):
5477 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
5478 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005479 DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005480 bnx2x_handle_classification_eqe(bp, elem);
5481 break;
5482
5483 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5484 BNX2X_STATE_OPEN):
5485 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5486 BNX2X_STATE_DIAG):
5487 case (EVENT_RING_OPCODE_MULTICAST_RULES |
5488 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005489 DP(BNX2X_MSG_SP, "got mcast ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005490 bnx2x_handle_mcast_eqe(bp);
5491 break;
5492
5493 case (EVENT_RING_OPCODE_FILTERS_RULES |
5494 BNX2X_STATE_OPEN):
5495 case (EVENT_RING_OPCODE_FILTERS_RULES |
5496 BNX2X_STATE_DIAG):
5497 case (EVENT_RING_OPCODE_FILTERS_RULES |
5498 BNX2X_STATE_CLOSING_WAIT4_HALT):
Vladislav Zolotarovd6cae232011-07-24 03:54:17 +00005499 DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005500 bnx2x_handle_rx_mode_eqe(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005501 break;
5502 default:
5503 /* unknown event log error and continue */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005504 BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
5505 elem->message.opcode, bp->state);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005506 }
5507next_spqe:
5508 spqe_cnt++;
5509 } /* for */
5510
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005511 smp_mb__before_atomic();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005512 atomic_add(spqe_cnt, &bp->eq_spq_left);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005513
5514 bp->eq_cons = sw_cons;
5515 bp->eq_prod = sw_prod;
5516 /* Make sure that above mem writes were issued towards the memory */
5517 smp_wmb();
5518
5519 /* update producer */
5520 bnx2x_update_eq_prod(bp, bp->eq_prod);
5521}
5522
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005523static void bnx2x_sp_task(struct work_struct *work)
5524{
Eilon Greenstein1cf167f2009-01-14 21:22:18 -08005525 struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005526
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005527 DP(BNX2X_MSG_SP, "sp task invoked\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005528
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005529 /* make sure the atomic interrupt_occurred has been written */
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005530 smp_rmb();
5531 if (atomic_read(&bp->interrupt_occurred)) {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005532
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005533 /* what work needs to be performed? */
5534 u16 status = bnx2x_update_dsb_idx(bp);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005535
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005536 DP(BNX2X_MSG_SP, "status %x\n", status);
5537 DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
5538 atomic_set(&bp->interrupt_occurred, 0);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005539
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005540 /* HW attentions */
5541 if (status & BNX2X_DEF_SB_ATT_IDX) {
5542 bnx2x_attn_int(bp);
5543 status &= ~BNX2X_DEF_SB_ATT_IDX;
Vladislav Zolotarov019dbb42011-07-19 01:43:25 +00005544 }
Merav Sicron55c11942012-11-07 00:45:48 +00005545
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005546 /* SP events: STAT_QUERY and others */
5547 if (status & BNX2X_DEF_SB_IDX) {
5548 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005549
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005550 if (FCOE_INIT(bp) &&
5551 (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
5552 /* Prevent local bottom-halves from running as
5553 * we are going to change the local NAPI list.
5554 */
5555 local_bh_disable();
5556 napi_schedule(&bnx2x_fcoe(bp, napi));
5557 local_bh_enable();
5558 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005559
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005560 /* Handle EQ completions */
5561 bnx2x_eq_int(bp);
5562 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
5563 le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
5564
5565 status &= ~BNX2X_DEF_SB_IDX;
5566 }
5567
5568 /* if status is non zero then perhaps something went wrong */
5569 if (unlikely(status))
5570 DP(BNX2X_MSG_SP,
5571 "got an unknown interrupt! (status 0x%x)\n", status);
5572
5573 /* ack status block only if something was actually handled */
5574 bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
5575 le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00005576 }
5577
Barak Witkowskia3348722012-04-23 03:04:46 +00005578 /* afex - poll to check if VIFSET_ACK should be sent to MFW */
5579 if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
5580 &bp->sp_state)) {
5581 bnx2x_link_report(bp);
5582 bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
5583 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005584}
5585
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005586irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005587{
5588 struct net_device *dev = dev_instance;
5589 struct bnx2x *bp = netdev_priv(dev);
5590
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005591 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
5592 IGU_INT_DISABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005593
5594#ifdef BNX2X_STOP_ON_ERROR
5595 if (unlikely(bp->panic))
5596 return IRQ_HANDLED;
5597#endif
5598
Merav Sicron55c11942012-11-07 00:45:48 +00005599 if (CNIC_LOADED(bp)) {
Michael Chan993ac7b2009-10-10 13:46:56 +00005600 struct cnic_ops *c_ops;
5601
5602 rcu_read_lock();
5603 c_ops = rcu_dereference(bp->cnic_ops);
5604 if (c_ops)
5605 c_ops->cnic_handler(bp->cnic_data, NULL);
5606 rcu_read_unlock();
5607 }
Merav Sicron55c11942012-11-07 00:45:48 +00005608
Ariel Eliorfd1fc792013-01-01 05:22:33 +00005609 /* schedule sp task to perform default status block work, ack
5610 * attentions and enable interrupts.
5611 */
5612 bnx2x_schedule_sp_task(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005613
5614 return IRQ_HANDLED;
5615}
5616
5617/* end of slow path */
5618
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005619void bnx2x_drv_pulse(struct bnx2x *bp)
5620{
5621 SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
5622 bp->fw_drv_pulse_wr_seq);
5623}
5624
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005625static void bnx2x_timer(unsigned long data)
5626{
5627 struct bnx2x *bp = (struct bnx2x *) data;
5628
5629 if (!netif_running(bp->dev))
5630 return;
5631
Ariel Elior67c431a2013-01-01 05:22:36 +00005632 if (IS_PF(bp) &&
5633 !BP_NOMCP(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005634 int mb_idx = BP_FW_MB_IDX(bp);
Eilon Greenstein4c868662013-09-23 10:12:50 +03005635 u16 drv_pulse;
5636 u16 mcp_pulse;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005637
5638 ++bp->fw_drv_pulse_wr_seq;
5639 bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005640 drv_pulse = bp->fw_drv_pulse_wr_seq;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005641 bnx2x_drv_pulse(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005642
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005643 mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005644 MCP_PULSE_SEQ_MASK);
5645 /* The delta between driver pulse and mcp response
Eilon Greenstein4c868662013-09-23 10:12:50 +03005646 * should not get too big. If the MFW is more than 5 pulses
5647 * behind, we should worry about it enough to generate an error
5648 * log.
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005649 */
Eilon Greenstein4c868662013-09-23 10:12:50 +03005650 if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
5651 BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005652 drv_pulse, mcp_pulse);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005653 }
5654
Eilon Greensteinf34d28e2009-10-15 00:18:08 -07005655 if (bp->state == BNX2X_STATE_OPEN)
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07005656 bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005657
Ariel Eliorabc5a022013-01-01 05:22:43 +00005658 /* sample pf vf bulletin board for new posts from pf */
Yuval Mintz371734882013-06-24 11:04:10 +03005659 if (IS_VF(bp))
5660 bnx2x_timer_sriov(bp);
Ariel Elior78c3bcc2013-06-20 17:39:08 +03005661
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005662 mod_timer(&bp->timer, jiffies + bp->current_interval);
5663}
5664
5665/* end of Statistics */
5666
5667/* nic init */
5668
5669/*
5670 * nic init service functions
5671 */
5672
Eric Dumazet1191cb82012-04-27 21:39:21 +00005673static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005674{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005675 u32 i;
5676 if (!(len%4) && !(addr%4))
5677 for (i = 0; i < len; i += 4)
5678 REG_WR(bp, addr + i, fill);
5679 else
5680 for (i = 0; i < len; i++)
5681 REG_WR8(bp, addr + i, fill);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005682}
5683
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005684/* helper: writes FP SP data to FW - data_size in dwords */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005685static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
5686 int fw_sb_id,
5687 u32 *sb_data_p,
5688 u32 data_size)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005689{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005690 int index;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005691 for (index = 0; index < data_size; index++)
5692 REG_WR(bp, BAR_CSTRORM_INTMEM +
5693 CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
5694 sizeof(u32)*index,
5695 *(sb_data_p + index));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005696}
5697
Eric Dumazet1191cb82012-04-27 21:39:21 +00005698static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005699{
5700 u32 *sb_data_p;
5701 u32 data_size = 0;
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
5705 /* disable the function first */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005706 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005707 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005708 sb_data_e2.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005709 sb_data_e2.common.p_func.vf_valid = false;
5710 sb_data_p = (u32 *)&sb_data_e2;
5711 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
5712 } else {
5713 memset(&sb_data_e1x, 0,
5714 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005715 sb_data_e1x.common.state = SB_DISABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005716 sb_data_e1x.common.p_func.vf_valid = false;
5717 sb_data_p = (u32 *)&sb_data_e1x;
5718 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
5719 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005720 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5721
5722 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5723 CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
5724 CSTORM_STATUS_BLOCK_SIZE);
5725 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5726 CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
5727 CSTORM_SYNC_BLOCK_SIZE);
5728}
5729
5730/* helper: writes SP SB data to FW */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005731static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005732 struct hc_sp_status_block_data *sp_sb_data)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005733{
5734 int func = BP_FUNC(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005735 int i;
5736 for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
5737 REG_WR(bp, BAR_CSTRORM_INTMEM +
5738 CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
5739 i*sizeof(u32),
5740 *((u32 *)sp_sb_data + i));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005741}
5742
Eric Dumazet1191cb82012-04-27 21:39:21 +00005743static void bnx2x_zero_sp_sb(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005744{
5745 int func = BP_FUNC(bp);
5746 struct hc_sp_status_block_data sp_sb_data;
5747 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5748
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005749 sp_sb_data.state = SB_DISABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005750 sp_sb_data.p_func.vf_valid = false;
5751
5752 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
5753
5754 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5755 CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
5756 CSTORM_SP_STATUS_BLOCK_SIZE);
5757 bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
5758 CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
5759 CSTORM_SP_SYNC_BLOCK_SIZE);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005760}
5761
Eric Dumazet1191cb82012-04-27 21:39:21 +00005762static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005763 int igu_sb_id, int igu_seg_id)
5764{
5765 hc_sm->igu_sb_id = igu_sb_id;
5766 hc_sm->igu_seg_id = igu_seg_id;
5767 hc_sm->timer_value = 0xFF;
5768 hc_sm->time_to_expire = 0xFFFFFFFF;
5769}
5770
David S. Miller8decf862011-09-22 03:23:13 -04005771/* allocates state machine ids. */
Eric Dumazet1191cb82012-04-27 21:39:21 +00005772static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
David S. Miller8decf862011-09-22 03:23:13 -04005773{
5774 /* zero out state machine indices */
5775 /* rx indices */
5776 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5777
5778 /* tx indices */
5779 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
5780 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
5781 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
5782 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
5783
5784 /* map indices */
5785 /* rx indices */
5786 index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
5787 SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5788
5789 /* tx indices */
5790 index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
5791 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5792 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
5793 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5794 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
5795 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5796 index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
5797 SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
5798}
5799
Ariel Eliorb93288d2013-01-01 05:22:35 +00005800void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005801 u8 vf_valid, int fw_sb_id, int igu_sb_id)
5802{
5803 int igu_seg_id;
5804
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005805 struct hc_status_block_data_e2 sb_data_e2;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005806 struct hc_status_block_data_e1x sb_data_e1x;
5807 struct hc_status_block_sm *hc_sm_p;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005808 int data_size;
5809 u32 *sb_data_p;
5810
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005811 if (CHIP_INT_MODE_IS_BC(bp))
5812 igu_seg_id = HC_SEG_ACCESS_NORM;
5813 else
5814 igu_seg_id = IGU_SEG_ACCESS_NORM;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005815
5816 bnx2x_zero_fp_sb(bp, fw_sb_id);
5817
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005818 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005819 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005820 sb_data_e2.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005821 sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
5822 sb_data_e2.common.p_func.vf_id = vfid;
5823 sb_data_e2.common.p_func.vf_valid = vf_valid;
5824 sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
5825 sb_data_e2.common.same_igu_sb_1b = true;
5826 sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
5827 sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
5828 hc_sm_p = sb_data_e2.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005829 sb_data_p = (u32 *)&sb_data_e2;
5830 data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005831 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005832 } else {
5833 memset(&sb_data_e1x, 0,
5834 sizeof(struct hc_status_block_data_e1x));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005835 sb_data_e1x.common.state = SB_ENABLED;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005836 sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
5837 sb_data_e1x.common.p_func.vf_id = 0xff;
5838 sb_data_e1x.common.p_func.vf_valid = false;
5839 sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
5840 sb_data_e1x.common.same_igu_sb_1b = true;
5841 sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
5842 sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
5843 hc_sm_p = sb_data_e1x.common.state_machine;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005844 sb_data_p = (u32 *)&sb_data_e1x;
5845 data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
David S. Miller8decf862011-09-22 03:23:13 -04005846 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005847 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005848
5849 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
5850 igu_sb_id, igu_seg_id);
5851 bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
5852 igu_sb_id, igu_seg_id);
5853
Merav Sicron51c1a582012-03-18 10:33:38 +00005854 DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005855
Yuval Mintz86564c32013-01-23 03:21:50 +00005856 /* write indices to HW - PCI guarantees endianity of regpairs */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005857 bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
5858}
5859
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005860static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005861 u16 tx_usec, u16 rx_usec)
5862{
Ariel Elior6383c0b2011-07-14 08:31:57 +00005863 bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005864 false, rx_usec);
Ariel Elior6383c0b2011-07-14 08:31:57 +00005865 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5866 HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
5867 tx_usec);
5868 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5869 HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
5870 tx_usec);
5871 bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
5872 HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
5873 tx_usec);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005874}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005875
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005876static void bnx2x_init_def_sb(struct bnx2x *bp)
5877{
5878 struct host_sp_status_block *def_sb = bp->def_status_blk;
5879 dma_addr_t mapping = bp->def_status_blk_mapping;
5880 int igu_sp_sb_index;
5881 int igu_seg_id;
5882 int port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005883 int func = BP_FUNC(bp);
David S. Miller88c51002011-10-07 13:38:43 -04005884 int reg_offset, reg_offset_en5;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005885 u64 section;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005886 int index;
5887 struct hc_sp_status_block_data sp_sb_data;
5888 memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
5889
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005890 if (CHIP_INT_MODE_IS_BC(bp)) {
5891 igu_sp_sb_index = DEF_SB_IGU_ID;
5892 igu_seg_id = HC_SEG_ACCESS_DEF;
5893 } else {
5894 igu_sp_sb_index = bp->igu_dsb_id;
5895 igu_seg_id = IGU_SEG_ACCESS_DEF;
5896 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005897
5898 /* ATTN */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005899 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005900 atten_status_block);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005901 def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005902
Eliezer Tamir49d66772008-02-28 11:53:13 -08005903 bp->attn_state = 0;
5904
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005905 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
5906 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
David S. Miller88c51002011-10-07 13:38:43 -04005907 reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
5908 MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005909 for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005910 int sindex;
5911 /* take care of sig[0]..sig[4] */
5912 for (sindex = 0; sindex < 4; sindex++)
5913 bp->attn_group[index].sig[sindex] =
5914 REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005915
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005916 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005917 /*
5918 * enable5 is separate from the rest of the registers,
5919 * and therefore the address skip is 4
5920 * and not 16 between the different groups
5921 */
5922 bp->attn_group[index].sig[4] = REG_RD(bp,
David S. Miller88c51002011-10-07 13:38:43 -04005923 reg_offset_en5 + 0x4*index);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005924 else
5925 bp->attn_group[index].sig[4] = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005926 }
5927
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005928 if (bp->common.int_block == INT_BLOCK_HC) {
5929 reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
5930 HC_REG_ATTN_MSG0_ADDR_L);
5931
5932 REG_WR(bp, reg_offset, U64_LO(section));
5933 REG_WR(bp, reg_offset + 4, U64_HI(section));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005934 } else if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005935 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
5936 REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
5937 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005938
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005939 section = ((u64)mapping) + offsetof(struct host_sp_status_block,
5940 sp_sb);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005941
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005942 bnx2x_zero_sp_sb(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005943
Yuval Mintz86564c32013-01-23 03:21:50 +00005944 /* PCI guarantees endianity of regpairs */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005945 sp_sb_data.state = SB_ENABLED;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005946 sp_sb_data.host_sb_addr.lo = U64_LO(section);
5947 sp_sb_data.host_sb_addr.hi = U64_HI(section);
5948 sp_sb_data.igu_sb_id = igu_sp_sb_index;
5949 sp_sb_data.igu_seg_id = igu_seg_id;
5950 sp_sb_data.p_func.pf_id = func;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005951 sp_sb_data.p_func.vnic_id = BP_VN(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005952 sp_sb_data.p_func.vf_id = 0xff;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005953
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005954 bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005955
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005956 bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005957}
5958
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00005959void bnx2x_update_coalesce(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005960{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005961 int i;
5962
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00005963 for_each_eth_queue(bp, i)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005964 bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
Ariel Elior423cfa7e2011-03-14 13:43:22 -07005965 bp->tx_ticks, bp->rx_ticks);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005966}
5967
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005968static void bnx2x_init_sp_ring(struct bnx2x *bp)
5969{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005970 spin_lock_init(&bp->spq_lock);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005971 atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005972
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005973 bp->spq_prod_idx = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005974 bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
5975 bp->spq_prod_bd = bp->spq;
5976 bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005977}
5978
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005979static void bnx2x_init_eq_ring(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005980{
5981 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005982 for (i = 1; i <= NUM_EQ_PAGES; i++) {
5983 union event_ring_elem *elem =
5984 &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005985
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005986 elem->next_page.addr.hi =
5987 cpu_to_le32(U64_HI(bp->eq_mapping +
5988 BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
5989 elem->next_page.addr.lo =
5990 cpu_to_le32(U64_LO(bp->eq_mapping +
5991 BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005992 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00005993 bp->eq_cons = 0;
5994 bp->eq_prod = NUM_EQ_DESC;
5995 bp->eq_cons_sb = BNX2X_EQ_INDEX;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005996 /* we want a warning message before it gets wrought... */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08005997 atomic_set(&bp->eq_spq_left,
5998 min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02005999}
6000
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006001/* called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -08006002static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
6003 unsigned long rx_mode_flags,
6004 unsigned long rx_accept_flags,
6005 unsigned long tx_accept_flags,
6006 unsigned long ramrod_flags)
Tom Herbertab532cf2011-02-16 10:27:02 +00006007{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006008 struct bnx2x_rx_mode_ramrod_params ramrod_param;
6009 int rc;
Tom Herbertab532cf2011-02-16 10:27:02 +00006010
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006011 memset(&ramrod_param, 0, sizeof(ramrod_param));
Tom Herbertab532cf2011-02-16 10:27:02 +00006012
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006013 /* Prepare ramrod parameters */
6014 ramrod_param.cid = 0;
6015 ramrod_param.cl_id = cl_id;
6016 ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
6017 ramrod_param.func_id = BP_FUNC(bp);
6018
6019 ramrod_param.pstate = &bp->sp_state;
6020 ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
6021
6022 ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
6023 ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
6024
6025 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
6026
6027 ramrod_param.ramrod_flags = ramrod_flags;
6028 ramrod_param.rx_mode_flags = rx_mode_flags;
6029
6030 ramrod_param.rx_accept_flags = rx_accept_flags;
6031 ramrod_param.tx_accept_flags = tx_accept_flags;
6032
6033 rc = bnx2x_config_rx_mode(bp, &ramrod_param);
6034 if (rc < 0) {
6035 BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
Yuval Mintz924d75a2013-01-23 03:21:44 +00006036 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006037 }
Yuval Mintz924d75a2013-01-23 03:21:44 +00006038
6039 return 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006040}
6041
Yuval Mintz86564c32013-01-23 03:21:50 +00006042static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
6043 unsigned long *rx_accept_flags,
6044 unsigned long *tx_accept_flags)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006045{
Yuval Mintz924d75a2013-01-23 03:21:44 +00006046 /* Clear the flags first */
6047 *rx_accept_flags = 0;
6048 *tx_accept_flags = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006049
Yuval Mintz924d75a2013-01-23 03:21:44 +00006050 switch (rx_mode) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006051 case BNX2X_RX_MODE_NONE:
6052 /*
6053 * 'drop all' supersedes any accept flags that may have been
6054 * passed to the function.
6055 */
6056 break;
6057 case BNX2X_RX_MODE_NORMAL:
Yuval Mintz924d75a2013-01-23 03:21:44 +00006058 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6059 __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
6060 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006061
6062 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00006063 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
6064 __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
6065 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006066
6067 break;
6068 case BNX2X_RX_MODE_ALLMULTI:
Yuval Mintz924d75a2013-01-23 03:21:44 +00006069 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6070 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
6071 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006072
6073 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00006074 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
6075 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
6076 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006077
6078 break;
6079 case BNX2X_RX_MODE_PROMISC:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006080 /* According to definition of SI mode, iface in promisc mode
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006081 * should receive matched and unmatched (in resolution of port)
6082 * unicast packets.
6083 */
Yuval Mintz924d75a2013-01-23 03:21:44 +00006084 __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
6085 __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
6086 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
6087 __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006088
6089 /* internal switching mode */
Yuval Mintz924d75a2013-01-23 03:21:44 +00006090 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
6091 __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006092
6093 if (IS_MF_SI(bp))
Yuval Mintz924d75a2013-01-23 03:21:44 +00006094 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006095 else
Yuval Mintz924d75a2013-01-23 03:21:44 +00006096 __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006097
6098 break;
6099 default:
Yuval Mintz924d75a2013-01-23 03:21:44 +00006100 BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
6101 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006102 }
6103
Yuval Mintz924d75a2013-01-23 03:21:44 +00006104 /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006105 if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
Yuval Mintz924d75a2013-01-23 03:21:44 +00006106 __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
6107 __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006108 }
6109
Yuval Mintz924d75a2013-01-23 03:21:44 +00006110 return 0;
6111}
6112
6113/* called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -08006114static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
Yuval Mintz924d75a2013-01-23 03:21:44 +00006115{
6116 unsigned long rx_mode_flags = 0, ramrod_flags = 0;
6117 unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
6118 int rc;
6119
6120 if (!NO_FCOE(bp))
6121 /* Configure rx_mode of FCoE Queue */
6122 __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
6123
6124 rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
6125 &tx_accept_flags);
6126 if (rc)
6127 return rc;
6128
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006129 __set_bit(RAMROD_RX, &ramrod_flags);
6130 __set_bit(RAMROD_TX, &ramrod_flags);
6131
Yuval Mintz924d75a2013-01-23 03:21:44 +00006132 return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
6133 rx_accept_flags, tx_accept_flags,
6134 ramrod_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006135}
6136
Eilon Greenstein471de712008-08-13 15:49:35 -07006137static void bnx2x_init_internal_common(struct bnx2x *bp)
6138{
6139 int i;
6140
6141 /* Zero this manually as its initialization is
6142 currently missing in the initTool */
6143 for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
6144 REG_WR(bp, BAR_USTRORM_INTMEM +
6145 USTORM_AGG_DATA_OFFSET + i * 4, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006146 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006147 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
6148 CHIP_INT_MODE_IS_BC(bp) ?
6149 HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
6150 }
Eilon Greenstein471de712008-08-13 15:49:35 -07006151}
6152
Eilon Greenstein471de712008-08-13 15:49:35 -07006153static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
6154{
6155 switch (load_code) {
6156 case FW_MSG_CODE_DRV_LOAD_COMMON:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006157 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
Eilon Greenstein471de712008-08-13 15:49:35 -07006158 bnx2x_init_internal_common(bp);
6159 /* no break */
6160
6161 case FW_MSG_CODE_DRV_LOAD_PORT:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006162 /* nothing to do */
Eilon Greenstein471de712008-08-13 15:49:35 -07006163 /* no break */
6164
6165 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006166 /* internal memory per function is
6167 initialized inside bnx2x_pf_init */
Eilon Greenstein471de712008-08-13 15:49:35 -07006168 break;
6169
6170 default:
6171 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
6172 break;
6173 }
6174}
6175
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006176static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
6177{
Merav Sicron55c11942012-11-07 00:45:48 +00006178 return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006179}
6180
6181static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
6182{
Merav Sicron55c11942012-11-07 00:45:48 +00006183 return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006184}
6185
Eric Dumazet1191cb82012-04-27 21:39:21 +00006186static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006187{
6188 if (CHIP_IS_E1x(fp->bp))
6189 return BP_L_ID(fp->bp) + fp->index;
6190 else /* We want Client ID to be the same as IGU SB ID for 57712 */
6191 return bnx2x_fp_igu_sb_id(fp);
6192}
6193
Ariel Elior6383c0b2011-07-14 08:31:57 +00006194static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006195{
6196 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
Ariel Elior6383c0b2011-07-14 08:31:57 +00006197 u8 cos;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006198 unsigned long q_type = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006199 u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
Dmitry Kravkovf233caf2011-11-13 04:34:22 +00006200 fp->rx_queue = fp_idx;
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006201 fp->cid = fp_idx;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006202 fp->cl_id = bnx2x_fp_cl_id(fp);
6203 fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
6204 fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006205 /* qZone id equals to FW (per path) client id */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006206 fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
6207
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006208 /* init shortcut */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006209 fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
Ariel Elior7a752992012-01-26 06:01:53 +00006210
Yuval Mintz16a5fd92013-06-02 00:06:18 +00006211 /* Setup SB indices */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006212 fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006213
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006214 /* Configure Queue State object */
6215 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6216 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
Ariel Elior6383c0b2011-07-14 08:31:57 +00006217
6218 BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
6219
6220 /* init tx data */
6221 for_each_cos_in_tx_queue(fp, cos) {
Merav Sicron65565882012-06-19 07:48:26 +00006222 bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
6223 CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
6224 FP_COS_TO_TXQ(fp, cos, bp),
6225 BNX2X_TX_SB_INDEX_BASE + cos, fp);
6226 cids[cos] = fp->txdata_ptr[cos]->cid;
Ariel Elior6383c0b2011-07-14 08:31:57 +00006227 }
6228
Ariel Eliorad5afc82013-01-01 05:22:26 +00006229 /* nothing more for vf to do here */
6230 if (IS_VF(bp))
6231 return;
6232
6233 bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
6234 fp->fw_sb_id, fp->igu_sb_id);
6235 bnx2x_update_fpsb_idx(fp);
Barak Witkowski15192a82012-06-19 07:48:28 +00006236 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
6237 fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
Ariel Elior6383c0b2011-07-14 08:31:57 +00006238 bnx2x_sp_mapping(bp, q_rdata), q_type);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006239
6240 /**
6241 * Configure classification DBs: Always enable Tx switching
6242 */
6243 bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
6244
Ariel Eliorad5afc82013-01-01 05:22:26 +00006245 DP(NETIF_MSG_IFUP,
6246 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6247 fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6248 fp->igu_sb_id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006249}
6250
Eric Dumazet1191cb82012-04-27 21:39:21 +00006251static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
6252{
6253 int i;
6254
6255 for (i = 1; i <= NUM_TX_RINGS; i++) {
6256 struct eth_tx_next_bd *tx_next_bd =
6257 &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
6258
6259 tx_next_bd->addr_hi =
6260 cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
6261 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6262 tx_next_bd->addr_lo =
6263 cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
6264 BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
6265 }
6266
Yuval Mintz639d65b2013-06-02 00:06:21 +00006267 *txdata->tx_cons_sb = cpu_to_le16(0);
6268
Eric Dumazet1191cb82012-04-27 21:39:21 +00006269 SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
6270 txdata->tx_db.data.zero_fill1 = 0;
6271 txdata->tx_db.data.prod = 0;
6272
6273 txdata->tx_pkt_prod = 0;
6274 txdata->tx_pkt_cons = 0;
6275 txdata->tx_bd_prod = 0;
6276 txdata->tx_bd_cons = 0;
6277 txdata->tx_pkt = 0;
6278}
6279
Merav Sicron55c11942012-11-07 00:45:48 +00006280static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
6281{
6282 int i;
6283
6284 for_each_tx_queue_cnic(bp, i)
6285 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
6286}
Yuval Mintzd76a6112013-06-02 00:06:17 +00006287
Eric Dumazet1191cb82012-04-27 21:39:21 +00006288static void bnx2x_init_tx_rings(struct bnx2x *bp)
6289{
6290 int i;
6291 u8 cos;
6292
Merav Sicron55c11942012-11-07 00:45:48 +00006293 for_each_eth_queue(bp, i)
Eric Dumazet1191cb82012-04-27 21:39:21 +00006294 for_each_cos_in_tx_queue(&bp->fp[i], cos)
Merav Sicron65565882012-06-19 07:48:26 +00006295 bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
Eric Dumazet1191cb82012-04-27 21:39:21 +00006296}
6297
stephen hemmingera8f47eb2014-01-09 22:20:11 -08006298static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
6299{
6300 struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
6301 unsigned long q_type = 0;
6302
6303 bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
6304 bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
6305 BNX2X_FCOE_ETH_CL_ID_IDX);
6306 bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
6307 bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
6308 bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
6309 bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
6310 bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
6311 fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
6312 fp);
6313
6314 DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
6315
6316 /* qZone id equals to FW (per path) client id */
6317 bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
6318 /* init shortcut */
6319 bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
6320 bnx2x_rx_ustorm_prods_offset(fp);
6321
6322 /* Configure Queue State object */
6323 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
6324 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
6325
6326 /* No multi-CoS for FCoE L2 client */
6327 BUG_ON(fp->max_cos != 1);
6328
6329 bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
6330 &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
6331 bnx2x_sp_mapping(bp, q_rdata), q_type);
6332
6333 DP(NETIF_MSG_IFUP,
6334 "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
6335 fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
6336 fp->igu_sb_id);
6337}
6338
Merav Sicron55c11942012-11-07 00:45:48 +00006339void bnx2x_nic_init_cnic(struct bnx2x *bp)
6340{
6341 if (!NO_FCOE(bp))
6342 bnx2x_init_fcoe_fp(bp);
6343
6344 bnx2x_init_sb(bp, bp->cnic_sb_mapping,
6345 BNX2X_VF_ID_INVALID, false,
6346 bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
6347
6348 /* ensure status block indices were read */
6349 rmb();
6350 bnx2x_init_rx_rings_cnic(bp);
6351 bnx2x_init_tx_rings_cnic(bp);
6352
6353 /* flush all */
6354 mb();
6355 mmiowb();
6356}
6357
Yuval Mintzecf01c22013-04-22 02:53:03 +00006358void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006359{
6360 int i;
6361
Yuval Mintzecf01c22013-04-22 02:53:03 +00006362 /* Setup NIC internals and enable interrupts */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00006363 for_each_eth_queue(bp, i)
Ariel Elior6383c0b2011-07-14 08:31:57 +00006364 bnx2x_init_eth_fp(bp, i);
Ariel Eliorad5afc82013-01-01 05:22:26 +00006365
6366 /* ensure status block indices were read */
6367 rmb();
6368 bnx2x_init_rx_rings(bp);
6369 bnx2x_init_tx_rings(bp);
6370
Yuval Mintzecf01c22013-04-22 02:53:03 +00006371 if (IS_PF(bp)) {
6372 /* Initialize MOD_ABS interrupts */
6373 bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
6374 bp->common.shmem_base,
6375 bp->common.shmem2_base, BP_PORT(bp));
Eilon Greenstein16119782009-03-02 07:59:27 +00006376
Yuval Mintzecf01c22013-04-22 02:53:03 +00006377 /* initialize the default status block and sp ring */
6378 bnx2x_init_def_sb(bp);
6379 bnx2x_update_dsb_idx(bp);
6380 bnx2x_init_sp_ring(bp);
Yuval Mintz3cdeec22013-06-02 00:06:19 +00006381 } else {
6382 bnx2x_memset_stats(bp);
Yuval Mintzecf01c22013-04-22 02:53:03 +00006383 }
6384}
Eilon Greenstein16119782009-03-02 07:59:27 +00006385
Yuval Mintzecf01c22013-04-22 02:53:03 +00006386void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
6387{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006388 bnx2x_init_eq_ring(bp);
Eilon Greenstein471de712008-08-13 15:49:35 -07006389 bnx2x_init_internal(bp, load_code);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006390 bnx2x_pf_init(bp);
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006391 bnx2x_stats_init(bp);
6392
Eilon Greenstein0ef00452009-01-14 21:31:08 -08006393 /* flush all before enabling interrupts */
6394 mb();
6395 mmiowb();
6396
Eliezer Tamir615f8fd2008-02-28 11:54:54 -08006397 bnx2x_int_enable(bp);
Eilon Greensteineb8da202009-07-21 05:47:30 +00006398
6399 /* Check for SPIO5 */
6400 bnx2x_attn_int_deasserted0(bp,
6401 REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
6402 AEU_INPUTS_ATTN_BITS_SPIO5);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006403}
6404
Yuval Mintzecf01c22013-04-22 02:53:03 +00006405/* gzip service functions */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006406static int bnx2x_gunzip_init(struct bnx2x *bp)
6407{
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006408 bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
6409 &bp->gunzip_mapping, GFP_KERNEL);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006410 if (bp->gunzip_buf == NULL)
6411 goto gunzip_nomem1;
6412
6413 bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
6414 if (bp->strm == NULL)
6415 goto gunzip_nomem2;
6416
David S. Miller7ab24bf2011-06-29 05:48:41 -07006417 bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006418 if (bp->strm->workspace == NULL)
6419 goto gunzip_nomem3;
6420
6421 return 0;
6422
6423gunzip_nomem3:
6424 kfree(bp->strm);
6425 bp->strm = NULL;
6426
6427gunzip_nomem2:
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006428 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6429 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006430 bp->gunzip_buf = NULL;
6431
6432gunzip_nomem1:
Merav Sicron51c1a582012-03-18 10:33:38 +00006433 BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006434 return -ENOMEM;
6435}
6436
6437static void bnx2x_gunzip_end(struct bnx2x *bp)
6438{
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006439 if (bp->strm) {
David S. Miller7ab24bf2011-06-29 05:48:41 -07006440 vfree(bp->strm->workspace);
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00006441 kfree(bp->strm);
6442 bp->strm = NULL;
6443 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006444
6445 if (bp->gunzip_buf) {
FUJITA Tomonori1a983142010-04-04 01:51:03 +00006446 dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
6447 bp->gunzip_mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006448 bp->gunzip_buf = NULL;
6449 }
6450}
6451
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006452static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006453{
6454 int n, rc;
6455
6456 /* check gzip header */
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006457 if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
6458 BNX2X_ERR("Bad gzip header\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006459 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006460 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006461
6462 n = 10;
6463
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006464#define FNAME 0x8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006465
6466 if (zbuf[3] & FNAME)
6467 while ((zbuf[n++] != 0) && (n < len));
6468
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07006469 bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006470 bp->strm->avail_in = len - n;
6471 bp->strm->next_out = bp->gunzip_buf;
6472 bp->strm->avail_out = FW_BUF_SIZE;
6473
6474 rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
6475 if (rc != Z_OK)
6476 return rc;
6477
6478 rc = zlib_inflate(bp->strm, Z_FINISH);
6479 if ((rc != Z_OK) && (rc != Z_STREAM_END))
Joe Perches7995c642010-02-17 15:01:52 +00006480 netdev_err(bp->dev, "Firmware decompression error: %s\n",
6481 bp->strm->msg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006482
6483 bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
6484 if (bp->gunzip_outlen & 0x3)
Merav Sicron51c1a582012-03-18 10:33:38 +00006485 netdev_err(bp->dev,
6486 "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00006487 bp->gunzip_outlen);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006488 bp->gunzip_outlen >>= 2;
6489
6490 zlib_inflateEnd(bp->strm);
6491
6492 if (rc == Z_STREAM_END)
6493 return 0;
6494
6495 return rc;
6496}
6497
6498/* nic load/unload */
6499
6500/*
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006501 * General service functions
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006502 */
6503
6504/* send a NIG loopback debug packet */
6505static void bnx2x_lb_pckt(struct bnx2x *bp)
6506{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006507 u32 wb_write[3];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006508
6509 /* Ethernet source and destination addresses */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006510 wb_write[0] = 0x55555555;
6511 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006512 wb_write[2] = 0x20; /* SOP */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006513 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006514
6515 /* NON-IP protocol */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006516 wb_write[0] = 0x09000000;
6517 wb_write[1] = 0x55555555;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006518 wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006519 REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006520}
6521
6522/* some of the internal memories
6523 * are not directly readable from the driver
6524 * to test them we send debug packets
6525 */
6526static int bnx2x_int_mem_test(struct bnx2x *bp)
6527{
6528 int factor;
6529 int count, i;
6530 u32 val = 0;
6531
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006532 if (CHIP_REV_IS_FPGA(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006533 factor = 120;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07006534 else if (CHIP_REV_IS_EMUL(bp))
6535 factor = 200;
6536 else
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006537 factor = 1;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006538
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006539 /* Disable inputs of parser neighbor blocks */
6540 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6541 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6542 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006543 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006544
6545 /* Write 0 to parser credits for CFC search request */
6546 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6547
6548 /* send Ethernet packet */
6549 bnx2x_lb_pckt(bp);
6550
6551 /* TODO do i reset NIG statistic? */
6552 /* Wait until NIG register shows 1 packet of size 0x10 */
6553 count = 1000 * factor;
6554 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006555
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006556 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6557 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006558 if (val == 0x10)
6559 break;
6560
Yuval Mintz639d65b2013-06-02 00:06:21 +00006561 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006562 count--;
6563 }
6564 if (val != 0x10) {
6565 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6566 return -1;
6567 }
6568
6569 /* Wait until PRS register shows 1 packet */
6570 count = 1000 * factor;
6571 while (count) {
6572 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006573 if (val == 1)
6574 break;
6575
Yuval Mintz639d65b2013-06-02 00:06:21 +00006576 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006577 count--;
6578 }
6579 if (val != 0x1) {
6580 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6581 return -2;
6582 }
6583
6584 /* Reset and init BRB, PRS */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006585 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006586 msleep(50);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006587 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006588 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006589 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6590 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006591
6592 DP(NETIF_MSG_HW, "part2\n");
6593
6594 /* Disable inputs of parser neighbor blocks */
6595 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
6596 REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
6597 REG_WR(bp, CFC_REG_DEBUG0, 0x1);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006598 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006599
6600 /* Write 0 to parser credits for CFC search request */
6601 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
6602
6603 /* send 10 Ethernet packets */
6604 for (i = 0; i < 10; i++)
6605 bnx2x_lb_pckt(bp);
6606
6607 /* Wait until NIG register shows 10 + 1
6608 packets of size 11*0x10 = 0xb0 */
6609 count = 1000 * factor;
6610 while (count) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006611
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006612 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
6613 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006614 if (val == 0xb0)
6615 break;
6616
Yuval Mintz639d65b2013-06-02 00:06:21 +00006617 usleep_range(10000, 20000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006618 count--;
6619 }
6620 if (val != 0xb0) {
6621 BNX2X_ERR("NIG timeout val = 0x%x\n", val);
6622 return -3;
6623 }
6624
6625 /* Wait until PRS register shows 2 packets */
6626 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6627 if (val != 2)
6628 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6629
6630 /* Write 1 to parser credits for CFC search request */
6631 REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
6632
6633 /* Wait until PRS register shows 3 packets */
6634 msleep(10 * factor);
6635 /* Wait until NIG register shows 1 packet of size 0x10 */
6636 val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
6637 if (val != 3)
6638 BNX2X_ERR("PRS timeout val = 0x%x\n", val);
6639
6640 /* clear NIG EOP FIFO */
6641 for (i = 0; i < 11; i++)
6642 REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
6643 val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
6644 if (val != 1) {
6645 BNX2X_ERR("clear of NIG failed\n");
6646 return -4;
6647 }
6648
6649 /* Reset and init BRB, PRS, NIG */
6650 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
6651 msleep(50);
6652 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
6653 msleep(50);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006654 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
6655 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Merav Sicron55c11942012-11-07 00:45:48 +00006656 if (!CNIC_SUPPORT(bp))
6657 /* set NIC mode */
6658 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006659
6660 /* Enable inputs of parser neighbor blocks */
6661 REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
6662 REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
6663 REG_WR(bp, CFC_REG_DEBUG0, 0x0);
Eilon Greenstein3196a882008-08-13 15:58:49 -07006664 REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006665
6666 DP(NETIF_MSG_HW, "done\n");
6667
6668 return 0; /* OK */
6669}
6670
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006671static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006672{
Yuval Mintzb343d002012-12-02 04:05:53 +00006673 u32 val;
6674
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006675 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006676 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006677 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
6678 else
6679 REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006680 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
6681 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006682 /*
6683 * mask read length error interrupts in brb for parser
6684 * (parsing unit and 'checksum and crc' unit)
6685 * these errors are legal (PU reads fixed length and CAC can cause
6686 * read length error on truncated packets)
6687 */
6688 REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006689 REG_WR(bp, QM_REG_QM_INT_MASK, 0);
6690 REG_WR(bp, TM_REG_TM_INT_MASK, 0);
6691 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
6692 REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
6693 REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006694/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
6695/* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006696 REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
6697 REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
6698 REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006699/* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
6700/* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006701 REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
6702 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
6703 REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
6704 REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006705/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
6706/* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00006707
Yuval Mintzb343d002012-12-02 04:05:53 +00006708 val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
6709 PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
6710 PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
6711 if (!CHIP_IS_E1x(bp))
6712 val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
6713 PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
6714 REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
6715
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006716 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
6717 REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
6718 REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006719/* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006720
6721 if (!CHIP_IS_E1x(bp))
6722 /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
6723 REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
6724
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006725 REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
6726 REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006727/* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00006728 REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006729}
6730
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006731static void bnx2x_reset_common(struct bnx2x *bp)
6732{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006733 u32 val = 0x1400;
6734
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006735 /* reset_common */
6736 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
6737 0xd3ffff7f);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006738
6739 if (CHIP_IS_E3(bp)) {
6740 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6741 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6742 }
6743
6744 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
6745}
6746
6747static void bnx2x_setup_dmae(struct bnx2x *bp)
6748{
6749 bp->dmae_ready = 0;
6750 spin_lock_init(&bp->dmae_lock);
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006751}
6752
Eilon Greenstein573f2032009-08-12 08:24:14 +00006753static void bnx2x_init_pxp(struct bnx2x *bp)
6754{
6755 u16 devctl;
6756 int r_order, w_order;
6757
Jiang Liu2a80eeb2012-08-20 13:26:51 -06006758 pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
Eilon Greenstein573f2032009-08-12 08:24:14 +00006759 DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
6760 w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
6761 if (bp->mrrs == -1)
6762 r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
6763 else {
6764 DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
6765 r_order = bp->mrrs;
6766 }
6767
6768 bnx2x_init_pxp_arb(bp, r_order, w_order);
6769}
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006770
6771static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
6772{
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006773 int is_required;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006774 u32 val;
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006775 int port;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006776
Vladislav Zolotarov2145a922010-04-19 01:13:49 +00006777 if (BP_NOMCP(bp))
6778 return;
6779
6780 is_required = 0;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006781 val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
6782 SHARED_HW_CFG_FAN_FAILURE_MASK;
6783
6784 if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
6785 is_required = 1;
6786
6787 /*
6788 * The fan failure mechanism is usually related to the PHY type since
6789 * the power consumption of the board is affected by the PHY. Currently,
6790 * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
6791 */
6792 else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
6793 for (port = PORT_0; port < PORT_MAX; port++) {
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006794 is_required |=
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006795 bnx2x_fan_failure_det_req(
6796 bp,
6797 bp->common.shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006798 bp->common.shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006799 port);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006800 }
6801
6802 DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
6803
6804 if (is_required == 0)
6805 return;
6806
6807 /* Fan failure is indicated by SPIO 5 */
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006808 bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006809
6810 /* set to active low mode */
6811 val = REG_RD(bp, MISC_REG_SPIO_INT);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006812 val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006813 REG_WR(bp, MISC_REG_SPIO_INT, val);
6814
6815 /* enable interrupt to signal the IGU */
6816 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00006817 val |= MISC_SPIO_SPIO5;
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00006818 REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
6819}
6820
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00006821void bnx2x_pf_disable(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006822{
6823 u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
6824 val &= ~IGU_PF_CONF_FUNC_EN;
6825
6826 REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
6827 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6828 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
6829}
6830
Eric Dumazet1191cb82012-04-27 21:39:21 +00006831static void bnx2x__common_init_phy(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006832{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006833 u32 shmem_base[2], shmem2_base[2];
Yaniv Rosnerb884d952012-11-27 03:46:28 +00006834 /* Avoid common init in case MFW supports LFA */
6835 if (SHMEM2_RD(bp, size) >
6836 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
6837 return;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006838 shmem_base[0] = bp->common.shmem_base;
6839 shmem2_base[0] = bp->common.shmem2_base;
6840 if (!CHIP_IS_E1x(bp)) {
6841 shmem_base[1] =
6842 SHMEM2_RD(bp, other_shmem_base_addr);
6843 shmem2_base[1] =
6844 SHMEM2_RD(bp, other_shmem2_base_addr);
6845 }
6846 bnx2x_acquire_phy_lock(bp);
6847 bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
6848 bp->common.chip_id);
6849 bnx2x_release_phy_lock(bp);
6850}
6851
6852/**
6853 * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
6854 *
6855 * @bp: driver handle
6856 */
6857static int bnx2x_init_hw_common(struct bnx2x *bp)
6858{
6859 u32 val;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006860
Merav Sicron51c1a582012-03-18 10:33:38 +00006861 DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006862
David S. Miller823dcd22011-08-20 10:39:12 -07006863 /*
Yuval Mintz2de67432013-01-23 03:21:43 +00006864 * take the RESET lock to protect undi_unload flow from accessing
David S. Miller823dcd22011-08-20 10:39:12 -07006865 * registers while we're resetting the chip
6866 */
David S. Miller8decf862011-09-22 03:23:13 -04006867 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006868
Eilon Greenstein81f75bb2009-01-22 03:37:31 +00006869 bnx2x_reset_common(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006870 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006871
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006872 val = 0xfffc;
6873 if (CHIP_IS_E3(bp)) {
6874 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
6875 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
6876 }
6877 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006878
David S. Miller8decf862011-09-22 03:23:13 -04006879 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
David S. Miller823dcd22011-08-20 10:39:12 -07006880
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006881 bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
6882
6883 if (!CHIP_IS_E1x(bp)) {
6884 u8 abs_func_id;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006885
6886 /**
6887 * 4-port mode or 2-port mode we need to turn of master-enable
6888 * for everyone, after that, turn it back on for self.
6889 * so, we disregard multi-function or not, and always disable
6890 * for all functions on the given path, this means 0,2,4,6 for
6891 * path 0 and 1,3,5,7 for path 1
6892 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006893 for (abs_func_id = BP_PATH(bp);
6894 abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
6895 if (abs_func_id == BP_ABS_FUNC(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006896 REG_WR(bp,
6897 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
6898 1);
6899 continue;
6900 }
6901
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006902 bnx2x_pretend_func(bp, abs_func_id);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006903 /* clear pf enable */
6904 bnx2x_pf_disable(bp);
6905 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
6906 }
6907 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006908
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006909 bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006910 if (CHIP_IS_E1(bp)) {
6911 /* enable HW interrupt from PXP on USDM overflow
6912 bit 16 on INT_MASK_0 */
6913 REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006914 }
6915
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006916 bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006917 bnx2x_init_pxp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006918
6919#ifdef __BIG_ENDIAN
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006920 REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
6921 REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
6922 REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
6923 REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
6924 REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
Eilon Greenstein8badd272009-02-12 08:36:15 +00006925 /* make sure this value is 0 */
6926 REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006927
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006928/* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
6929 REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
6930 REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
6931 REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
6932 REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006933#endif
6934
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006935 bnx2x_ilt_init_page_size(bp, INITOP_SET);
6936
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006937 if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
6938 REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006939
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006940 /* let the HW do it's magic ... */
6941 msleep(100);
6942 /* finish PXP init */
6943 val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
6944 if (val != 1) {
6945 BNX2X_ERR("PXP2 CFG failed\n");
6946 return -EBUSY;
6947 }
6948 val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
6949 if (val != 1) {
6950 BNX2X_ERR("PXP2 RD_INIT failed\n");
6951 return -EBUSY;
6952 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02006953
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006954 /* Timers bug workaround E2 only. We need to set the entire ILT to
6955 * have entries with value "0" and valid bit on.
6956 * This needs to be done by the first PF that is loaded in a path
6957 * (i.e. common phase)
6958 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006959 if (!CHIP_IS_E1x(bp)) {
6960/* In E2 there is a bug in the timers block that can cause function 6 / 7
6961 * (i.e. vnic3) to start even if it is marked as "scan-off".
6962 * This occurs when a different function (func2,3) is being marked
6963 * as "scan-off". Real-life scenario for example: if a driver is being
6964 * load-unloaded while func6,7 are down. This will cause the timer to access
6965 * the ilt, translate to a logical address and send a request to read/write.
6966 * Since the ilt for the function that is down is not valid, this will cause
6967 * a translation error which is unrecoverable.
6968 * The Workaround is intended to make sure that when this happens nothing fatal
6969 * will occur. The workaround:
6970 * 1. First PF driver which loads on a path will:
6971 * a. After taking the chip out of reset, by using pretend,
6972 * it will write "0" to the following registers of
6973 * the other vnics.
6974 * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
6975 * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
6976 * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
6977 * And for itself it will write '1' to
6978 * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
6979 * dmae-operations (writing to pram for example.)
6980 * note: can be done for only function 6,7 but cleaner this
6981 * way.
6982 * b. Write zero+valid to the entire ILT.
6983 * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
6984 * VNIC3 (of that port). The range allocated will be the
6985 * entire ILT. This is needed to prevent ILT range error.
6986 * 2. Any PF driver load flow:
6987 * a. ILT update with the physical addresses of the allocated
6988 * logical pages.
6989 * b. Wait 20msec. - note that this timeout is needed to make
6990 * sure there are no requests in one of the PXP internal
6991 * queues with "old" ILT addresses.
6992 * c. PF enable in the PGLC.
6993 * d. Clear the was_error of the PF in the PGLC. (could have
Yuval Mintz2de67432013-01-23 03:21:43 +00006994 * occurred while driver was down)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006995 * e. PF enable in the CFC (WEAK + STRONG)
6996 * f. Timers scan enable
6997 * 3. PF driver unload flow:
6998 * a. Clear the Timers scan_en.
6999 * b. Polling for scan_on=0 for that PF.
7000 * c. Clear the PF enable bit in the PXP.
7001 * d. Clear the PF enable in the CFC (WEAK + STRONG)
7002 * e. Write zero+valid to all ILT entries (The valid bit must
7003 * stay set)
7004 * f. If this is VNIC 3 of a port then also init
7005 * first_timers_ilt_entry to zero and last_timers_ilt_entry
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007006 * to the last entry in the ILT.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007007 *
7008 * Notes:
7009 * Currently the PF error in the PGLC is non recoverable.
7010 * In the future the there will be a recovery routine for this error.
7011 * Currently attention is masked.
7012 * Having an MCP lock on the load/unload process does not guarantee that
7013 * there is no Timer disable during Func6/7 enable. This is because the
7014 * Timers scan is currently being cleared by the MCP on FLR.
7015 * Step 2.d can be done only for PF6/7 and the driver can also check if
7016 * there is error before clearing it. But the flow above is simpler and
7017 * more general.
7018 * All ILT entries are written by zero+valid and not just PF6/7
7019 * ILT entries since in the future the ILT entries allocation for
7020 * PF-s might be dynamic.
7021 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007022 struct ilt_client_info ilt_cli;
7023 struct bnx2x_ilt ilt;
7024 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
7025 memset(&ilt, 0, sizeof(struct bnx2x_ilt));
7026
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04007027 /* initialize dummy TM client */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007028 ilt_cli.start = 0;
7029 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
7030 ilt_cli.client_num = ILT_CLIENT_TM;
7031
7032 /* Step 1: set zeroes to all ilt page entries with valid bit on
7033 * Step 2: set the timers first/last ilt entry to point
7034 * to the entire range to prevent ILT range error for 3rd/4th
Yuval Mintz2de67432013-01-23 03:21:43 +00007035 * vnic (this code assumes existence of the vnic)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007036 *
7037 * both steps performed by call to bnx2x_ilt_client_init_op()
7038 * with dummy TM client
7039 *
7040 * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
7041 * and his brother are split registers
7042 */
7043 bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
7044 bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
7045 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
7046
7047 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
7048 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
7049 REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
7050 }
7051
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007052 REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
7053 REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007054
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007055 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007056 int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
7057 (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007058 bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007059
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007060 bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007061
7062 /* let the HW do it's magic ... */
7063 do {
7064 msleep(200);
7065 val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
7066 } while (factor-- && (val != 1));
7067
7068 if (val != 1) {
7069 BNX2X_ERR("ATC_INIT failed\n");
7070 return -EBUSY;
7071 }
7072 }
7073
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007074 bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007075
Ariel Eliorb56e9672013-01-01 05:22:32 +00007076 bnx2x_iov_init_dmae(bp);
7077
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007078 /* clean the DMAE memory */
7079 bp->dmae_ready = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007080 bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007081
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007082 bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
7083
7084 bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
7085
7086 bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
7087
7088 bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007089
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007090 bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
7091 bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
7092 bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
7093 bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
7094
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007095 bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
Michael Chan37b091b2009-10-10 13:46:55 +00007096
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007097 /* QM queues pointers table */
7098 bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
Michael Chan37b091b2009-10-10 13:46:55 +00007099
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007100 /* soft reset pulse */
7101 REG_WR(bp, QM_REG_SOFT_RESET, 1);
7102 REG_WR(bp, QM_REG_SOFT_RESET, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007103
Merav Sicron55c11942012-11-07 00:45:48 +00007104 if (CNIC_SUPPORT(bp))
7105 bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007106
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007107 bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
Ariel Eliorb9871bc2013-09-04 14:09:21 +03007108
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007109 if (!CHIP_REV_IS_SLOW(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007110 /* enable hw interrupt from doorbell Q */
7111 REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007112
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007113 bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007114
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007115 bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
Eilon Greenstein26c8fa42009-01-14 21:29:55 -08007116 REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007117
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007118 if (!CHIP_IS_E1(bp))
7119 REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
7120
Barak Witkowskia3348722012-04-23 03:04:46 +00007121 if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
7122 if (IS_MF_AFEX(bp)) {
7123 /* configure that VNTag and VLAN headers must be
7124 * received in afex mode
7125 */
7126 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
7127 REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
7128 REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
7129 REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
7130 REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
7131 } else {
7132 /* Bit-map indicating which L2 hdrs may appear
7133 * after the basic Ethernet header
7134 */
7135 REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
7136 bp->path_has_ovlan ? 7 : 6);
7137 }
7138 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007139
7140 bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
7141 bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
7142 bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
7143 bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
7144
7145 if (!CHIP_IS_E1x(bp)) {
7146 /* reset VFC memories */
7147 REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7148 VFC_MEMORIES_RST_REG_CAM_RST |
7149 VFC_MEMORIES_RST_REG_RAM_RST);
7150 REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
7151 VFC_MEMORIES_RST_REG_CAM_RST |
7152 VFC_MEMORIES_RST_REG_RAM_RST);
7153
7154 msleep(20);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007155 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007156
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007157 bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
7158 bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
7159 bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
7160 bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007161
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007162 /* sync semi rtc */
7163 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
7164 0x80000000);
7165 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
7166 0x80000000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007167
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007168 bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
7169 bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
7170 bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007171
Barak Witkowskia3348722012-04-23 03:04:46 +00007172 if (!CHIP_IS_E1x(bp)) {
7173 if (IS_MF_AFEX(bp)) {
7174 /* configure that VNTag and VLAN headers must be
7175 * sent in afex mode
7176 */
7177 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
7178 REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
7179 REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
7180 REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
7181 REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
7182 } else {
7183 REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
7184 bp->path_has_ovlan ? 7 : 6);
7185 }
7186 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007187
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007188 REG_WR(bp, SRC_REG_SOFT_RST, 1);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007189
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007190 bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
7191
Merav Sicron55c11942012-11-07 00:45:48 +00007192 if (CNIC_SUPPORT(bp)) {
7193 REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
7194 REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
7195 REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
7196 REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
7197 REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
7198 REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
7199 REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
7200 REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
7201 REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
7202 REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
7203 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007204 REG_WR(bp, SRC_REG_SOFT_RST, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007205
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007206 if (sizeof(union cdu_context) != 1024)
7207 /* we currently assume that a context is 1024 bytes */
Merav Sicron51c1a582012-03-18 10:33:38 +00007208 dev_alert(&bp->pdev->dev,
7209 "please adjust the size of cdu_context(%ld)\n",
7210 (long)sizeof(union cdu_context));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007211
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007212 bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007213 val = (4 << 24) + (0 << 12) + 1024;
7214 REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007215
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007216 bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007217 REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
Eilon Greenstein8d9c5f32009-02-15 23:24:08 -08007218 /* enable context validation interrupt from CFC */
7219 REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
7220
7221 /* set the thresholds to prevent CFC/CDU race */
7222 REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007223
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007224 bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007225
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007226 if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007227 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
7228
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007229 bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
7230 bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007231
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007232 /* Reset PCIE errors for debug */
7233 REG_WR(bp, 0x2814, 0xffffffff);
7234 REG_WR(bp, 0x3820, 0xffffffff);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007235
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007236 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007237 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
7238 (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
7239 PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
7240 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
7241 (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
7242 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
7243 PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
7244 REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
7245 (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
7246 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
7247 PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
7248 }
7249
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007250 bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007251 if (!CHIP_IS_E1(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007252 /* in E3 this done in per-port section */
7253 if (!CHIP_IS_E3(bp))
7254 REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
7255 }
7256 if (CHIP_IS_E1H(bp))
7257 /* not applicable for E2 (and above ...) */
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007258 REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007259
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007260 if (CHIP_REV_IS_SLOW(bp))
7261 msleep(200);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007262
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007263 /* finish CFC init */
7264 val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
7265 if (val != 1) {
7266 BNX2X_ERR("CFC LL_INIT failed\n");
7267 return -EBUSY;
7268 }
7269 val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
7270 if (val != 1) {
7271 BNX2X_ERR("CFC AC_INIT failed\n");
7272 return -EBUSY;
7273 }
7274 val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
7275 if (val != 1) {
7276 BNX2X_ERR("CFC CAM_INIT failed\n");
7277 return -EBUSY;
7278 }
7279 REG_WR(bp, CFC_REG_DEBUG0, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007280
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007281 if (CHIP_IS_E1(bp)) {
7282 /* read NIG statistic
7283 to see if this is our first up since powerup */
7284 bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
7285 val = *bnx2x_sp(bp, wb_data[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007286
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007287 /* do internal memory self test */
7288 if ((val == 0) && bnx2x_int_mem_test(bp)) {
7289 BNX2X_ERR("internal mem self test failed\n");
7290 return -EBUSY;
7291 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007292 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007293
Eilon Greensteinfd4ef402009-07-21 05:47:27 +00007294 bnx2x_setup_fan_failure_detection(bp);
7295
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007296 /* clear PXP2 attentions */
7297 REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007298
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +00007299 bnx2x_enable_blocks_attention(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00007300 bnx2x_enable_blocks_parity(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007301
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007302 if (!BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007303 if (CHIP_IS_E1x(bp))
7304 bnx2x__common_init_phy(bp);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007305 } else
7306 BNX2X_ERR("Bootcode is missing - can not initialize link\n");
7307
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007308 return 0;
7309}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007310
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007311/**
7312 * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
7313 *
7314 * @bp: driver handle
7315 */
7316static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
7317{
7318 int rc = bnx2x_init_hw_common(bp);
7319
7320 if (rc)
7321 return rc;
7322
7323 /* In E2 2-PORT mode, same ext phy is used for the two paths */
7324 if (!BP_NOMCP(bp))
7325 bnx2x__common_init_phy(bp);
7326
7327 return 0;
7328}
7329
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007330static int bnx2x_init_hw_port(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007331{
7332 int port = BP_PORT(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007333 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
Eilon Greenstein1c063282009-02-12 08:36:43 +00007334 u32 low, high;
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02007335 u32 val, reg;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007336
Merav Sicron51c1a582012-03-18 10:33:38 +00007337 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007338
7339 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007340
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007341 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7342 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7343 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
Eilon Greensteinca003922009-08-12 22:53:28 -07007344
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007345 /* Timers bug workaround: disables the pf_master bit in pglue at
7346 * common phase, we need to enable it here before any dmae access are
7347 * attempted. Therefore we manually added the enable-master to the
7348 * port phase (it also happens in the function phase)
7349 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007350 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007351 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7352
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007353 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7354 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7355 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
7356 bnx2x_init_block(bp, BLOCK_QM, init_phase);
7357
7358 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7359 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7360 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7361 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007362
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007363 /* QM cid (connection) count */
7364 bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007365
Merav Sicron55c11942012-11-07 00:45:48 +00007366 if (CNIC_SUPPORT(bp)) {
7367 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7368 REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
7369 REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
7370 }
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +00007371
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007372 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Eilon Greenstein1c063282009-02-12 08:36:43 +00007373
Dmitry Kravkov2b674042012-10-28 21:59:04 +00007374 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7375
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007376 if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007377
7378 if (IS_MF(bp))
7379 low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
7380 else if (bp->dev->mtu > 4096) {
7381 if (bp->flags & ONE_PORT_FLAG)
7382 low = 160;
7383 else {
7384 val = bp->dev->mtu;
7385 /* (24*1024 + val*4)/256 */
7386 low = 96 + (val/64) +
7387 ((val % 64) ? 1 : 0);
7388 }
7389 } else
7390 low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
7391 high = low + 56; /* 14*1024/256 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007392 REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
7393 REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
7394 }
7395
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007396 if (CHIP_MODE_IS_4_PORT(bp))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007397 REG_WR(bp, (BP_PORT(bp) ?
7398 BRB1_REG_MAC_GUARANTIED_1 :
7399 BRB1_REG_MAC_GUARANTIED_0), 40);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007400
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007401 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
Barak Witkowskia3348722012-04-23 03:04:46 +00007402 if (CHIP_IS_E3B0(bp)) {
7403 if (IS_MF_AFEX(bp)) {
7404 /* configure headers for AFEX mode */
7405 REG_WR(bp, BP_PORT(bp) ?
7406 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7407 PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
7408 REG_WR(bp, BP_PORT(bp) ?
7409 PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
7410 PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
7411 REG_WR(bp, BP_PORT(bp) ?
7412 PRS_REG_MUST_HAVE_HDRS_PORT_1 :
7413 PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
7414 } else {
7415 /* Ovlan exists only if we are in multi-function +
7416 * switch-dependent mode, in switch-independent there
7417 * is no ovlan headers
7418 */
7419 REG_WR(bp, BP_PORT(bp) ?
7420 PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
7421 PRS_REG_HDRS_AFTER_BASIC_PORT_0,
7422 (bp->path_has_ovlan ? 7 : 6));
7423 }
7424 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007425
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007426 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7427 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7428 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7429 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7430
7431 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7432 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7433 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7434 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
7435
7436 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7437 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7438
7439 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7440
7441 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007442 /* configure PBF to work without PAUSE mtu 9000 */
7443 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007444
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007445 /* update threshold */
7446 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
7447 /* update init credit */
7448 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007449
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007450 /* probe changes */
7451 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
7452 udelay(50);
7453 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
7454 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007455
Merav Sicron55c11942012-11-07 00:45:48 +00007456 if (CNIC_SUPPORT(bp))
7457 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7458
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007459 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
7460 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007461
7462 if (CHIP_IS_E1(bp)) {
7463 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7464 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7465 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007466 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007467
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007468 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007469
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007470 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007471 /* init aeu_mask_attn_func_0/1:
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007472 * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
7473 * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007474 * bits 4-7 are used for "per vn group attention" */
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +00007475 val = IS_MF(bp) ? 0xF7 : 0x7;
7476 /* Enable DCBX attention for all but E1 */
7477 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7478 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007479
Dmitry Kravkov4293b9f2013-10-20 16:51:33 +02007480 /* SCPAD_PARITY should NOT trigger close the gates */
7481 reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
7482 REG_WR(bp, reg,
7483 REG_RD(bp, reg) &
7484 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7485
7486 reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
7487 REG_WR(bp, reg,
7488 REG_RD(bp, reg) &
7489 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7490
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007491 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
Eilon Greenstein356e2382009-02-12 08:38:32 +00007492
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007493 if (!CHIP_IS_E1x(bp)) {
7494 /* Bit-map indicating which L2 hdrs may appear after the
7495 * basic Ethernet header
7496 */
Barak Witkowskia3348722012-04-23 03:04:46 +00007497 if (IS_MF_AFEX(bp))
7498 REG_WR(bp, BP_PORT(bp) ?
7499 NIG_REG_P1_HDRS_AFTER_BASIC :
7500 NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
7501 else
7502 REG_WR(bp, BP_PORT(bp) ?
7503 NIG_REG_P1_HDRS_AFTER_BASIC :
7504 NIG_REG_P0_HDRS_AFTER_BASIC,
7505 IS_MF_SD(bp) ? 7 : 6);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007506
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007507 if (CHIP_IS_E3(bp))
7508 REG_WR(bp, BP_PORT(bp) ?
7509 NIG_REG_LLH1_MF_MODE :
7510 NIG_REG_LLH_MF_MODE, IS_MF(bp));
7511 }
7512 if (!CHIP_IS_E3(bp))
7513 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007514
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007515 if (!CHIP_IS_E1(bp)) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007516 /* 0x2 disable mf_ov, 0x1 enable */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007517 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08007518 (IS_MF_SD(bp) ? 0x1 : 0x2));
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007519
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007520 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007521 val = 0;
7522 switch (bp->mf_mode) {
7523 case MULTI_FUNCTION_SD:
7524 val = 1;
7525 break;
7526 case MULTI_FUNCTION_SI:
Barak Witkowskia3348722012-04-23 03:04:46 +00007527 case MULTI_FUNCTION_AFEX:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007528 val = 2;
7529 break;
7530 }
7531
7532 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
7533 NIG_REG_LLH0_CLS_TYPE), val);
7534 }
Eilon Greenstein1c063282009-02-12 08:36:43 +00007535 {
7536 REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
7537 REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
7538 REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
7539 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007540 }
7541
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007542 /* If SPIO5 is set to generate interrupts, enable it for this port */
7543 val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
Yuval Mintzd6d99a32012-12-02 04:05:45 +00007544 if (val & MISC_SPIO_SPIO5) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007545 u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
7546 MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
7547 val = REG_RD(bp, reg_addr);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007548 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00007549 REG_WR(bp, reg_addr, val);
Eliezer Tamirf1410642008-02-28 11:51:50 -08007550 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02007551
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007552 return 0;
7553}
7554
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007555static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
7556{
7557 int reg;
Yuval Mintz32d68de2012-04-03 18:41:24 +00007558 u32 wb_write[2];
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007559
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007560 if (CHIP_IS_E1(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007561 reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007562 else
7563 reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007564
Yuval Mintz32d68de2012-04-03 18:41:24 +00007565 wb_write[0] = ONCHIP_ADDR1(addr);
7566 wb_write[1] = ONCHIP_ADDR2(addr);
7567 REG_WR_DMAE(bp, reg, wb_write, 2);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007568}
7569
Ariel Eliorb56e9672013-01-01 05:22:32 +00007570void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
Eric Dumazet1191cb82012-04-27 21:39:21 +00007571{
7572 u32 data, ctl, cnt = 100;
7573 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
7574 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
7575 u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
7576 u32 sb_bit = 1 << (idu_sb_id%32);
Ariel Eliorb56e9672013-01-01 05:22:32 +00007577 u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
Eric Dumazet1191cb82012-04-27 21:39:21 +00007578 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
7579
7580 /* Not supported in BC mode */
7581 if (CHIP_INT_MODE_IS_BC(bp))
7582 return;
7583
7584 data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
7585 << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
7586 IGU_REGULAR_CLEANUP_SET |
7587 IGU_REGULAR_BCLEANUP;
7588
7589 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
7590 func_encode << IGU_CTRL_REG_FID_SHIFT |
7591 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
7592
7593 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7594 data, igu_addr_data);
7595 REG_WR(bp, igu_addr_data, data);
7596 mmiowb();
7597 barrier();
7598 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
7599 ctl, igu_addr_ctl);
7600 REG_WR(bp, igu_addr_ctl, ctl);
7601 mmiowb();
7602 barrier();
7603
7604 /* wait for clean up to finish */
7605 while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
7606 msleep(20);
7607
Eric Dumazet1191cb82012-04-27 21:39:21 +00007608 if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
7609 DP(NETIF_MSG_HW,
7610 "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
7611 idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
7612 }
7613}
7614
7615static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007616{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007617 bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007618}
7619
Eric Dumazet1191cb82012-04-27 21:39:21 +00007620static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007621{
7622 u32 i, base = FUNC_ILT_BASE(func);
7623 for (i = base; i < base + ILT_PER_FUNC; i++)
7624 bnx2x_ilt_wr(bp, i, 0);
7625}
7626
Merav Sicron910cc722012-11-11 03:56:08 +00007627static void bnx2x_init_searcher(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007628{
7629 int port = BP_PORT(bp);
7630 bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
7631 /* T1 hash bits value determines the T1 number of entries */
7632 REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
7633}
7634
7635static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
7636{
7637 int rc;
7638 struct bnx2x_func_state_params func_params = {NULL};
7639 struct bnx2x_func_switch_update_params *switch_update_params =
7640 &func_params.params.switch_update;
7641
7642 /* Prepare parameters for function state transitions */
7643 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
7644 __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
7645
7646 func_params.f_obj = &bp->func_obj;
7647 func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
7648
7649 /* Function parameters */
Dmitry Kravkove42780b2014-08-17 16:47:43 +03007650 __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
7651 &switch_update_params->changes);
7652 if (suspend)
7653 __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
7654 &switch_update_params->changes);
Merav Sicron55c11942012-11-07 00:45:48 +00007655
7656 rc = bnx2x_func_state_change(bp, &func_params);
7657
7658 return rc;
7659}
7660
Merav Sicron910cc722012-11-11 03:56:08 +00007661static int bnx2x_reset_nic_mode(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +00007662{
7663 int rc, i, port = BP_PORT(bp);
7664 int vlan_en = 0, mac_en[NUM_MACS];
7665
Merav Sicron55c11942012-11-07 00:45:48 +00007666 /* Close input from network */
7667 if (bp->mf_mode == SINGLE_FUNCTION) {
7668 bnx2x_set_rx_filter(&bp->link_params, 0);
7669 } else {
7670 vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
7671 NIG_REG_LLH0_FUNC_EN);
7672 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7673 NIG_REG_LLH0_FUNC_EN, 0);
7674 for (i = 0; i < NUM_MACS; i++) {
7675 mac_en[i] = REG_RD(bp, port ?
7676 (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7677 4 * i) :
7678 (NIG_REG_LLH0_FUNC_MEM_ENABLE +
7679 4 * i));
7680 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7681 4 * i) :
7682 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
7683 }
7684 }
7685
7686 /* Close BMC to host */
7687 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7688 NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
7689
7690 /* Suspend Tx switching to the PF. Completion of this ramrod
7691 * further guarantees that all the packets of that PF / child
7692 * VFs in BRB were processed by the Parser, so it is safe to
7693 * change the NIC_MODE register.
7694 */
7695 rc = bnx2x_func_switch_update(bp, 1);
7696 if (rc) {
7697 BNX2X_ERR("Can't suspend tx-switching!\n");
7698 return rc;
7699 }
7700
7701 /* Change NIC_MODE register */
7702 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7703
7704 /* Open input from network */
7705 if (bp->mf_mode == SINGLE_FUNCTION) {
7706 bnx2x_set_rx_filter(&bp->link_params, 1);
7707 } else {
7708 REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
7709 NIG_REG_LLH0_FUNC_EN, vlan_en);
7710 for (i = 0; i < NUM_MACS; i++) {
7711 REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
7712 4 * i) :
7713 (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
7714 mac_en[i]);
7715 }
7716 }
7717
7718 /* Enable BMC to host */
7719 REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
7720 NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
7721
7722 /* Resume Tx switching to the PF */
7723 rc = bnx2x_func_switch_update(bp, 0);
7724 if (rc) {
7725 BNX2X_ERR("Can't resume tx-switching!\n");
7726 return rc;
7727 }
7728
7729 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7730 return 0;
7731}
7732
7733int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
7734{
7735 int rc;
7736
7737 bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
7738
7739 if (CONFIGURE_NIC_MODE(bp)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00007740 /* Configure searcher as part of function hw init */
Merav Sicron55c11942012-11-07 00:45:48 +00007741 bnx2x_init_searcher(bp);
7742
7743 /* Reset NIC mode */
7744 rc = bnx2x_reset_nic_mode(bp);
7745 if (rc)
7746 BNX2X_ERR("Can't change NIC mode!\n");
7747 return rc;
7748 }
7749
7750 return 0;
7751}
7752
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007753static int bnx2x_init_hw_func(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007754{
7755 int port = BP_PORT(bp);
7756 int func = BP_FUNC(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007757 int init_phase = PHASE_PF0 + func;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007758 struct bnx2x_ilt *ilt = BP_ILT(bp);
7759 u16 cdu_ilt_start;
Eilon Greenstein8badd272009-02-12 08:36:15 +00007760 u32 addr, val;
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00007761 u32 main_mem_base, main_mem_size, main_mem_prty_clr;
Ariel Elior89db4ad2012-01-26 06:01:48 +00007762 int i, main_mem_width, rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007763
Merav Sicron51c1a582012-03-18 10:33:38 +00007764 DP(NETIF_MSG_HW, "starting func init func %d\n", func);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007765
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007766 /* FLR cleanup - hmmm */
Ariel Elior89db4ad2012-01-26 06:01:48 +00007767 if (!CHIP_IS_E1x(bp)) {
7768 rc = bnx2x_pf_flr_clnup(bp);
Yuval Mintz04c46732013-01-23 03:21:46 +00007769 if (rc) {
7770 bnx2x_fw_dump(bp);
Ariel Elior89db4ad2012-01-26 06:01:48 +00007771 return rc;
Yuval Mintz04c46732013-01-23 03:21:46 +00007772 }
Ariel Elior89db4ad2012-01-26 06:01:48 +00007773 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007774
Eilon Greenstein8badd272009-02-12 08:36:15 +00007775 /* set MSI reconfigure capability */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007776 if (bp->common.int_block == INT_BLOCK_HC) {
7777 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
7778 val = REG_RD(bp, addr);
7779 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
7780 REG_WR(bp, addr, val);
7781 }
Eilon Greenstein8badd272009-02-12 08:36:15 +00007782
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007783 bnx2x_init_block(bp, BLOCK_PXP, init_phase);
7784 bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
7785
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007786 ilt = BP_ILT(bp);
7787 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007788
Ariel Elior290ca2b2013-01-01 05:22:31 +00007789 if (IS_SRIOV(bp))
7790 cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
7791 cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
7792
7793 /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
7794 * those of the VFs, so start line should be reset
7795 */
7796 cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007797 for (i = 0; i < L2_ILT_LINES(bp); i++) {
Merav Sicrona0529972012-06-19 07:48:25 +00007798 ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007799 ilt->lines[cdu_ilt_start + i].page_mapping =
Merav Sicrona0529972012-06-19 07:48:25 +00007800 bp->context[i].cxt_mapping;
7801 ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007802 }
Ariel Elior290ca2b2013-01-01 05:22:31 +00007803
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007804 bnx2x_ilt_init_op(bp, INITOP_SET);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00007805
Merav Sicron55c11942012-11-07 00:45:48 +00007806 if (!CONFIGURE_NIC_MODE(bp)) {
7807 bnx2x_init_searcher(bp);
7808 REG_WR(bp, PRS_REG_NIC_MODE, 0);
7809 DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
7810 } else {
7811 /* Set NIC mode */
7812 REG_WR(bp, PRS_REG_NIC_MODE, 1);
Yuval Mintz6bf07b82013-06-02 00:06:20 +00007813 DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
Merav Sicron55c11942012-11-07 00:45:48 +00007814 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007815
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007816 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007817 u32 pf_conf = IGU_PF_CONF_FUNC_EN;
7818
7819 /* Turn on a single ISR mode in IGU if driver is going to use
7820 * INT#x or MSI
7821 */
7822 if (!(bp->flags & USING_MSIX_FLAG))
7823 pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
7824 /*
7825 * Timers workaround bug: function init part.
7826 * Need to wait 20msec after initializing ILT,
7827 * needed to make sure there are no requests in
7828 * one of the PXP internal queues with "old" ILT addresses
7829 */
7830 msleep(20);
7831 /*
7832 * Master enable - Due to WB DMAE writes performed before this
7833 * register is re-initialized as part of the regular function
7834 * init
7835 */
7836 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
7837 /* Enable the function in IGU */
7838 REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
7839 }
7840
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007841 bp->dmae_ready = 1;
7842
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007843 bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007844
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007845 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007846 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
7847
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007848 bnx2x_init_block(bp, BLOCK_ATC, init_phase);
7849 bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
7850 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7851 bnx2x_init_block(bp, BLOCK_SRC, init_phase);
7852 bnx2x_init_block(bp, BLOCK_MISC, init_phase);
7853 bnx2x_init_block(bp, BLOCK_TCM, init_phase);
7854 bnx2x_init_block(bp, BLOCK_UCM, init_phase);
7855 bnx2x_init_block(bp, BLOCK_CCM, init_phase);
7856 bnx2x_init_block(bp, BLOCK_XCM, init_phase);
7857 bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
7858 bnx2x_init_block(bp, BLOCK_USEM, init_phase);
7859 bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
7860 bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007861
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007862 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007863 REG_WR(bp, QM_REG_PF_EN, 1);
7864
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007865 if (!CHIP_IS_E1x(bp)) {
7866 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7867 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7868 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7869 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
7870 }
7871 bnx2x_init_block(bp, BLOCK_QM, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007872
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007873 bnx2x_init_block(bp, BLOCK_TM, init_phase);
7874 bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
Ariel Eliorc19d65c2013-09-09 14:51:27 +03007875 REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
Ariel Eliorb56e9672013-01-01 05:22:32 +00007876
7877 bnx2x_iov_init_dq(bp);
7878
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007879 bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
7880 bnx2x_init_block(bp, BLOCK_PRS, init_phase);
7881 bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
7882 bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
7883 bnx2x_init_block(bp, BLOCK_USDM, init_phase);
7884 bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
7885 bnx2x_init_block(bp, BLOCK_UPB, init_phase);
7886 bnx2x_init_block(bp, BLOCK_XPB, init_phase);
7887 bnx2x_init_block(bp, BLOCK_PBF, init_phase);
7888 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007889 REG_WR(bp, PBF_REG_DISABLE_PF, 0);
7890
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007891 bnx2x_init_block(bp, BLOCK_CDU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007892
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007893 bnx2x_init_block(bp, BLOCK_CFC, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007894
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007895 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007896 REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
7897
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007898 if (IS_MF(bp)) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007899 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00007900 REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007901 }
7902
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007903 bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007904
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007905 /* HC init per function */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007906 if (bp->common.int_block == INT_BLOCK_HC) {
7907 if (CHIP_IS_E1H(bp)) {
7908 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7909
7910 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
7911 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
7912 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007913 bnx2x_init_block(bp, BLOCK_HC, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007914
7915 } else {
7916 int num_segs, sb_idx, prod_offset;
7917
Eilon Greenstein34f80b02008-06-23 20:33:01 -07007918 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
7919
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007920 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007921 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
7922 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
7923 }
7924
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007925 bnx2x_init_block(bp, BLOCK_IGU, init_phase);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007926
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03007927 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007928 int dsb_idx = 0;
7929 /**
7930 * Producer memory:
7931 * E2 mode: address 0-135 match to the mapping memory;
7932 * 136 - PF0 default prod; 137 - PF1 default prod;
7933 * 138 - PF2 default prod; 139 - PF3 default prod;
7934 * 140 - PF0 attn prod; 141 - PF1 attn prod;
7935 * 142 - PF2 attn prod; 143 - PF3 attn prod;
7936 * 144-147 reserved.
7937 *
7938 * E1.5 mode - In backward compatible mode;
7939 * for non default SB; each even line in the memory
7940 * holds the U producer and each odd line hold
7941 * the C producer. The first 128 producers are for
7942 * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
7943 * producers are for the DSB for each PF.
7944 * Each PF has five segments: (the order inside each
7945 * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
7946 * 132-135 C prods; 136-139 X prods; 140-143 T prods;
7947 * 144-147 attn prods;
7948 */
7949 /* non-default-status-blocks */
7950 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7951 IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
7952 for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
7953 prod_offset = (bp->igu_base_sb + sb_idx) *
7954 num_segs;
7955
7956 for (i = 0; i < num_segs; i++) {
7957 addr = IGU_REG_PROD_CONS_MEMORY +
7958 (prod_offset + i) * 4;
7959 REG_WR(bp, addr, 0);
7960 }
7961 /* send consumer update with value 0 */
7962 bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
7963 USTORM_ID, 0, IGU_INT_NOP, 1);
7964 bnx2x_igu_clear_sb(bp,
7965 bp->igu_base_sb + sb_idx);
7966 }
7967
7968 /* default-status-blocks */
7969 num_segs = CHIP_INT_MODE_IS_BC(bp) ?
7970 IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
7971
7972 if (CHIP_MODE_IS_4_PORT(bp))
7973 dsb_idx = BP_FUNC(bp);
7974 else
David S. Miller8decf862011-09-22 03:23:13 -04007975 dsb_idx = BP_VN(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007976
7977 prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
7978 IGU_BC_BASE_DSB_PROD + dsb_idx :
7979 IGU_NORM_BASE_DSB_PROD + dsb_idx);
7980
David S. Miller8decf862011-09-22 03:23:13 -04007981 /*
7982 * igu prods come in chunks of E1HVN_MAX (4) -
7983 * does not matters what is the current chip mode
7984 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007985 for (i = 0; i < (num_segs * E1HVN_MAX);
7986 i += E1HVN_MAX) {
7987 addr = IGU_REG_PROD_CONS_MEMORY +
7988 (prod_offset + i)*4;
7989 REG_WR(bp, addr, 0);
7990 }
7991 /* send consumer update with 0 */
7992 if (CHIP_INT_MODE_IS_BC(bp)) {
7993 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7994 USTORM_ID, 0, IGU_INT_NOP, 1);
7995 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7996 CSTORM_ID, 0, IGU_INT_NOP, 1);
7997 bnx2x_ack_sb(bp, bp->igu_dsb_id,
7998 XSTORM_ID, 0, IGU_INT_NOP, 1);
7999 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8000 TSTORM_ID, 0, IGU_INT_NOP, 1);
8001 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8002 ATTENTION_ID, 0, IGU_INT_NOP, 1);
8003 } else {
8004 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8005 USTORM_ID, 0, IGU_INT_NOP, 1);
8006 bnx2x_ack_sb(bp, bp->igu_dsb_id,
8007 ATTENTION_ID, 0, IGU_INT_NOP, 1);
8008 }
8009 bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
8010
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008011 /* !!! These should become driver const once
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008012 rf-tool supports split-68 const */
8013 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
8014 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
8015 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
8016 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
8017 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
8018 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
8019 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008020 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008021
Eliezer Tamirc14423f2008-02-28 11:49:42 -08008022 /* Reset PCIE errors for debug */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008023 REG_WR(bp, 0x2114, 0xffffffff);
8024 REG_WR(bp, 0x2120, 0xffffffff);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008025
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00008026 if (CHIP_IS_E1x(bp)) {
8027 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
8028 main_mem_base = HC_REG_MAIN_MEMORY +
8029 BP_PORT(bp) * (main_mem_size * 4);
8030 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
8031 main_mem_width = 8;
8032
8033 val = REG_RD(bp, main_mem_prty_clr);
8034 if (val)
Merav Sicron51c1a582012-03-18 10:33:38 +00008035 DP(NETIF_MSG_HW,
8036 "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
8037 val);
Vladislav Zolotarovf4a66892010-10-19 05:13:09 +00008038
8039 /* Clear "false" parity errors in MSI-X table */
8040 for (i = main_mem_base;
8041 i < main_mem_base + main_mem_size * 4;
8042 i += main_mem_width) {
8043 bnx2x_read_dmae(bp, i, main_mem_width / 4);
8044 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
8045 i, main_mem_width / 4);
8046 }
8047 /* Clear HC parity attention */
8048 REG_RD(bp, main_mem_prty_clr);
8049 }
8050
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008051#ifdef BNX2X_STOP_ON_ERROR
8052 /* Enable STORMs SP logging */
8053 REG_WR8(bp, BAR_USTRORM_INTMEM +
8054 USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8055 REG_WR8(bp, BAR_TSTRORM_INTMEM +
8056 TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8057 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8058 CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8059 REG_WR8(bp, BAR_XSTRORM_INTMEM +
8060 XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
8061#endif
8062
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008063 bnx2x_phy_probe(&bp->link_params);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008064
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008065 return 0;
8066}
8067
Merav Sicron55c11942012-11-07 00:45:48 +00008068void bnx2x_free_mem_cnic(struct bnx2x *bp)
8069{
8070 bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
8071
8072 if (!CHIP_IS_E1x(bp))
8073 BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
8074 sizeof(struct host_hc_status_block_e2));
8075 else
8076 BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
8077 sizeof(struct host_hc_status_block_e1x));
8078
8079 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
8080}
8081
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00008082void bnx2x_free_mem(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008083{
Merav Sicrona0529972012-06-19 07:48:25 +00008084 int i;
8085
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008086 BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
8087 bp->fw_stats_data_sz + bp->fw_stats_req_sz);
8088
Ariel Eliorb4cddbd2013-08-28 01:13:03 +03008089 if (IS_VF(bp))
8090 return;
8091
8092 BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
8093 sizeof(struct host_sp_status_block));
8094
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008095 BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008096 sizeof(struct bnx2x_slowpath));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008097
Merav Sicrona0529972012-06-19 07:48:25 +00008098 for (i = 0; i < L2_ILT_LINES(bp); i++)
8099 BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
8100 bp->context[i].size);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008101 bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
8102
8103 BNX2X_FREE(bp->ilt->lines);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008104
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07008105 BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008106
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008107 BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
8108 BCM_PAGE_SIZE * NUM_EQ_PAGES);
Yuval Mintz580d9d02013-01-23 03:21:51 +00008109
Yuval Mintz05952242013-05-01 04:27:58 +00008110 BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
8111
Yuval Mintz580d9d02013-01-23 03:21:51 +00008112 bnx2x_iov_free_mem(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008113}
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008114
Merav Sicron55c11942012-11-07 00:45:48 +00008115int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008116{
Joe Perchescd2b0382014-02-20 13:25:51 -08008117 if (!CHIP_IS_E1x(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008118 /* size = the status block + ramrod buffers */
Joe Perchescd2b0382014-02-20 13:25:51 -08008119 bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
8120 sizeof(struct host_hc_status_block_e2));
8121 if (!bp->cnic_sb.e2_sb)
8122 goto alloc_mem_err;
8123 } else {
8124 bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
8125 sizeof(struct host_hc_status_block_e1x));
8126 if (!bp->cnic_sb.e1x_sb)
8127 goto alloc_mem_err;
8128 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008129
Joe Perchescd2b0382014-02-20 13:25:51 -08008130 if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008131 /* allocate searcher T2 table, as it wasn't allocated before */
Joe Perchescd2b0382014-02-20 13:25:51 -08008132 bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
8133 if (!bp->t2)
8134 goto alloc_mem_err;
8135 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008136
Merav Sicron55c11942012-11-07 00:45:48 +00008137 /* write address to which L5 should insert its values */
8138 bp->cnic_eth_dev.addr_drv_info_to_mcp =
8139 &bp->slowpath->drv_info_to_mcp;
8140
8141 if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
8142 goto alloc_mem_err;
8143
8144 return 0;
8145
8146alloc_mem_err:
8147 bnx2x_free_mem_cnic(bp);
8148 BNX2X_ERR("Can't allocate memory\n");
8149 return -ENOMEM;
8150}
8151
8152int bnx2x_alloc_mem(struct bnx2x *bp)
8153{
8154 int i, allocated, context_size;
8155
Joe Perchescd2b0382014-02-20 13:25:51 -08008156 if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
Merav Sicron55c11942012-11-07 00:45:48 +00008157 /* allocate searcher T2 table */
Joe Perchescd2b0382014-02-20 13:25:51 -08008158 bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
8159 if (!bp->t2)
8160 goto alloc_mem_err;
8161 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008162
Joe Perchescd2b0382014-02-20 13:25:51 -08008163 bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
8164 sizeof(struct host_sp_status_block));
8165 if (!bp->def_status_blk)
8166 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008167
Joe Perchescd2b0382014-02-20 13:25:51 -08008168 bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
8169 sizeof(struct bnx2x_slowpath));
8170 if (!bp->slowpath)
8171 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008172
Merav Sicrona0529972012-06-19 07:48:25 +00008173 /* Allocate memory for CDU context:
8174 * This memory is allocated separately and not in the generic ILT
8175 * functions because CDU differs in few aspects:
8176 * 1. There are multiple entities allocating memory for context -
8177 * 'regular' driver, CNIC and SRIOV driver. Each separately controls
8178 * its own ILT lines.
8179 * 2. Since CDU page-size is not a single 4KB page (which is the case
8180 * for the other ILT clients), to be efficient we want to support
8181 * allocation of sub-page-size in the last entry.
8182 * 3. Context pointers are used by the driver to pass to FW / update
8183 * the context (for the other ILT clients the pointers are used just to
8184 * free the memory during unload).
8185 */
8186 context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008187
Merav Sicrona0529972012-06-19 07:48:25 +00008188 for (i = 0, allocated = 0; allocated < context_size; i++) {
8189 bp->context[i].size = min(CDU_ILT_PAGE_SZ,
8190 (context_size - allocated));
Joe Perchescd2b0382014-02-20 13:25:51 -08008191 bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
8192 bp->context[i].size);
8193 if (!bp->context[i].vcxt)
8194 goto alloc_mem_err;
Merav Sicrona0529972012-06-19 07:48:25 +00008195 allocated += bp->context[i].size;
8196 }
Joe Perchescd2b0382014-02-20 13:25:51 -08008197 bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
8198 GFP_KERNEL);
8199 if (!bp->ilt->lines)
8200 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008201
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008202 if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
8203 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008204
Ariel Elior67c431a2013-01-01 05:22:36 +00008205 if (bnx2x_iov_alloc_mem(bp))
8206 goto alloc_mem_err;
8207
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008208 /* Slow path ring */
Joe Perchescd2b0382014-02-20 13:25:51 -08008209 bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
8210 if (!bp->spq)
8211 goto alloc_mem_err;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008212
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008213 /* EQ */
Joe Perchescd2b0382014-02-20 13:25:51 -08008214 bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
8215 BCM_PAGE_SIZE * NUM_EQ_PAGES);
8216 if (!bp->eq_ring)
8217 goto alloc_mem_err;
Tom Herbertab532cf2011-02-16 10:27:02 +00008218
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008219 return 0;
8220
8221alloc_mem_err:
8222 bnx2x_free_mem(bp);
Merav Sicron51c1a582012-03-18 10:33:38 +00008223 BNX2X_ERR("Can't allocate memory\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008224 return -ENOMEM;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008225}
8226
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008227/*
8228 * Init service functions
8229 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008230
8231int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
8232 struct bnx2x_vlan_mac_obj *obj, bool set,
8233 int mac_type, unsigned long *ramrod_flags)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008234{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008235 int rc;
8236 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008237
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008238 memset(&ramrod_param, 0, sizeof(ramrod_param));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008239
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008240 /* Fill general parameters */
8241 ramrod_param.vlan_mac_obj = obj;
8242 ramrod_param.ramrod_flags = *ramrod_flags;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008243
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008244 /* Fill a user request section if needed */
8245 if (!test_bit(RAMROD_CONT, ramrod_flags)) {
8246 memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008247
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008248 __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008249
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008250 /* Set the command: ADD or DEL */
8251 if (set)
8252 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
8253 else
8254 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008255 }
8256
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008257 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
Yuval Mintz7b5342d2012-09-11 04:34:14 +00008258
8259 if (rc == -EEXIST) {
8260 DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
8261 /* do not treat adding same MAC as error */
8262 rc = 0;
8263 } else if (rc < 0)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008264 BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
Yuval Mintz7b5342d2012-09-11 04:34:14 +00008265
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008266 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008267}
8268
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008269int bnx2x_del_all_macs(struct bnx2x *bp,
8270 struct bnx2x_vlan_mac_obj *mac_obj,
8271 int mac_type, bool wait_for_comp)
Michael Chane665bfd2009-10-10 13:46:54 +00008272{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008273 int rc;
8274 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
8275
8276 /* Wait for completion of requested */
8277 if (wait_for_comp)
8278 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8279
8280 /* Set the mac type of addresses we want to clear */
8281 __set_bit(mac_type, &vlan_mac_flags);
8282
8283 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
8284 if (rc < 0)
8285 BNX2X_ERR("Failed to delete MACs: %d\n", rc);
8286
8287 return rc;
Michael Chane665bfd2009-10-10 13:46:54 +00008288}
8289
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008290int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008291{
Barak Witkowskia3348722012-04-23 03:04:46 +00008292 if (is_zero_ether_addr(bp->dev->dev_addr) &&
8293 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00008294 DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
8295 "Ignoring Zero MAC for STORAGE SD mode\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008296 return 0;
8297 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +00008298
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008299 if (IS_PF(bp)) {
8300 unsigned long ramrod_flags = 0;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008301
Dmitry Kravkovf8f4f612013-04-24 01:45:00 +00008302 DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
8303 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
8304 return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
8305 &bp->sp_objs->mac_obj, set,
8306 BNX2X_ETH_MAC, &ramrod_flags);
8307 } else { /* vf */
8308 return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
8309 bp->fp->index, true);
8310 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08008311}
8312
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008313int bnx2x_setup_leading(struct bnx2x *bp)
Michael Chane665bfd2009-10-10 13:46:54 +00008314{
Ariel Elior60cad4e2013-09-04 14:09:22 +03008315 if (IS_PF(bp))
8316 return bnx2x_setup_queue(bp, &bp->fp[0], true);
8317 else /* VF */
8318 return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008319}
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -08008320
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008321/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00008322 * bnx2x_set_int_mode - configure interrupt mode
8323 *
8324 * @bp: driver handle
8325 *
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008326 * In case of MSI-X it will also try to enable MSI-X.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008327 */
Ariel Elior1ab44342013-01-01 05:22:23 +00008328int bnx2x_set_int_mode(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008329{
Ariel Elior1ab44342013-01-01 05:22:23 +00008330 int rc = 0;
8331
Ariel Elior60cad4e2013-09-04 14:09:22 +03008332 if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
8333 BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
Ariel Elior1ab44342013-01-01 05:22:23 +00008334 return -EINVAL;
Ariel Elior60cad4e2013-09-04 14:09:22 +03008335 }
Ariel Elior1ab44342013-01-01 05:22:23 +00008336
Dmitry Kravkov9ee3d372011-06-14 01:33:34 +00008337 switch (int_mode) {
Ariel Elior1ab44342013-01-01 05:22:23 +00008338 case BNX2X_INT_MODE_MSIX:
8339 /* attempt to enable msix */
8340 rc = bnx2x_enable_msix(bp);
8341
8342 /* msix attained */
8343 if (!rc)
8344 return 0;
8345
8346 /* vfs use only msix */
8347 if (rc && IS_VF(bp))
8348 return rc;
8349
8350 /* failed to enable multiple MSI-X */
8351 BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
8352 bp->num_queues,
8353 1 + bp->num_cnic_queues);
8354
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00008355 /* falling through... */
Ariel Elior1ab44342013-01-01 05:22:23 +00008356 case BNX2X_INT_MODE_MSI:
8357 bnx2x_enable_msi(bp);
8358
8359 /* falling through... */
8360 case BNX2X_INT_MODE_INTX:
Merav Sicron55c11942012-11-07 00:45:48 +00008361 bp->num_ethernet_queues = 1;
8362 bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
Merav Sicron51c1a582012-03-18 10:33:38 +00008363 BNX2X_DEV_INFO("set number of queues to 1\n");
Eilon Greensteinca003922009-08-12 22:53:28 -07008364 break;
Eilon Greensteinca003922009-08-12 22:53:28 -07008365 default:
Ariel Elior1ab44342013-01-01 05:22:23 +00008366 BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
8367 return -EINVAL;
Eilon Greensteinca003922009-08-12 22:53:28 -07008368 }
Ariel Elior1ab44342013-01-01 05:22:23 +00008369 return 0;
Eilon Greensteinca003922009-08-12 22:53:28 -07008370}
8371
Ariel Elior1ab44342013-01-01 05:22:23 +00008372/* must be called prior to any HW initializations */
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008373static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
8374{
Ariel Elior290ca2b2013-01-01 05:22:31 +00008375 if (IS_SRIOV(bp))
8376 return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +00008377 return L2_ILT_LINES(bp);
8378}
8379
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008380void bnx2x_ilt_set_info(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008381{
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008382 struct ilt_client_info *ilt_client;
8383 struct bnx2x_ilt *ilt = BP_ILT(bp);
8384 u16 line = 0;
8385
8386 ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
8387 DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
8388
8389 /* CDU */
8390 ilt_client = &ilt->clients[ILT_CLIENT_CDU];
8391 ilt_client->client_num = ILT_CLIENT_CDU;
8392 ilt_client->page_size = CDU_ILT_PAGE_SZ;
8393 ilt_client->flags = ILT_CLIENT_SKIP_MEM;
8394 ilt_client->start = line;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008395 line += bnx2x_cid_ilt_lines(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00008396
8397 if (CNIC_SUPPORT(bp))
8398 line += CNIC_ILT_LINES;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008399 ilt_client->end = line - 1;
8400
Merav Sicron51c1a582012-03-18 10:33:38 +00008401 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 +00008402 ilt_client->start,
8403 ilt_client->end,
8404 ilt_client->page_size,
8405 ilt_client->flags,
8406 ilog2(ilt_client->page_size >> 12));
8407
8408 /* QM */
8409 if (QM_INIT(bp->qm_cid_count)) {
8410 ilt_client = &ilt->clients[ILT_CLIENT_QM];
8411 ilt_client->client_num = ILT_CLIENT_QM;
8412 ilt_client->page_size = QM_ILT_PAGE_SZ;
8413 ilt_client->flags = 0;
8414 ilt_client->start = line;
8415
8416 /* 4 bytes for each cid */
8417 line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
8418 QM_ILT_PAGE_SZ);
8419
8420 ilt_client->end = line - 1;
8421
Merav Sicron51c1a582012-03-18 10:33:38 +00008422 DP(NETIF_MSG_IFUP,
8423 "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008424 ilt_client->start,
8425 ilt_client->end,
8426 ilt_client->page_size,
8427 ilt_client->flags,
8428 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008429 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008430
Merav Sicron55c11942012-11-07 00:45:48 +00008431 if (CNIC_SUPPORT(bp)) {
8432 /* SRC */
8433 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
8434 ilt_client->client_num = ILT_CLIENT_SRC;
8435 ilt_client->page_size = SRC_ILT_PAGE_SZ;
8436 ilt_client->flags = 0;
8437 ilt_client->start = line;
8438 line += SRC_ILT_LINES;
8439 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008440
Merav Sicron55c11942012-11-07 00:45:48 +00008441 DP(NETIF_MSG_IFUP,
8442 "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8443 ilt_client->start,
8444 ilt_client->end,
8445 ilt_client->page_size,
8446 ilt_client->flags,
8447 ilog2(ilt_client->page_size >> 12));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008448
Merav Sicron55c11942012-11-07 00:45:48 +00008449 /* TM */
8450 ilt_client = &ilt->clients[ILT_CLIENT_TM];
8451 ilt_client->client_num = ILT_CLIENT_TM;
8452 ilt_client->page_size = TM_ILT_PAGE_SZ;
8453 ilt_client->flags = 0;
8454 ilt_client->start = line;
8455 line += TM_ILT_LINES;
8456 ilt_client->end = line - 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008457
Merav Sicron55c11942012-11-07 00:45:48 +00008458 DP(NETIF_MSG_IFUP,
8459 "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
8460 ilt_client->start,
8461 ilt_client->end,
8462 ilt_client->page_size,
8463 ilt_client->flags,
8464 ilog2(ilt_client->page_size >> 12));
8465 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008466
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008467 BUG_ON(line > ILT_MAX_LINES);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008468}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00008469
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008470/**
8471 * bnx2x_pf_q_prep_init - prepare INIT transition parameters
8472 *
8473 * @bp: driver handle
8474 * @fp: pointer to fastpath
8475 * @init_params: pointer to parameters structure
8476 *
8477 * parameters configured:
8478 * - HC configuration
8479 * - Queue's CDU context
8480 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00008481static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008482 struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008483{
Ariel Elior6383c0b2011-07-14 08:31:57 +00008484 u8 cos;
Merav Sicrona0529972012-06-19 07:48:25 +00008485 int cxt_index, cxt_offset;
8486
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008487 /* FCoE Queue uses Default SB, thus has no HC capabilities */
8488 if (!IS_FCOE_FP(fp)) {
8489 __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
8490 __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
8491
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008492 /* If HC is supported, enable host coalescing in the transition
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008493 * to INIT state.
8494 */
8495 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
8496 __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
8497
8498 /* HC rate */
8499 init_params->rx.hc_rate = bp->rx_ticks ?
8500 (1000000 / bp->rx_ticks) : 0;
8501 init_params->tx.hc_rate = bp->tx_ticks ?
8502 (1000000 / bp->tx_ticks) : 0;
8503
8504 /* FW SB ID */
8505 init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
8506 fp->fw_sb_id;
8507
8508 /*
8509 * CQ index among the SB indices: FCoE clients uses the default
8510 * SB, therefore it's different.
8511 */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008512 init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
8513 init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008514 }
8515
Ariel Elior6383c0b2011-07-14 08:31:57 +00008516 /* set maximum number of COSs supported by this queue */
8517 init_params->max_cos = fp->max_cos;
8518
Merav Sicron51c1a582012-03-18 10:33:38 +00008519 DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008520 fp->index, init_params->max_cos);
8521
8522 /* set the context pointers queue object */
Merav Sicrona0529972012-06-19 07:48:25 +00008523 for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
Merav Sicron65565882012-06-19 07:48:26 +00008524 cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
8525 cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
Merav Sicrona0529972012-06-19 07:48:25 +00008526 ILT_PAGE_CIDS);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008527 init_params->cxts[cos] =
Merav Sicrona0529972012-06-19 07:48:25 +00008528 &bp->context[cxt_index].vcxt[cxt_offset].eth;
8529 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008530}
8531
Merav Sicron910cc722012-11-11 03:56:08 +00008532static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
Ariel Elior6383c0b2011-07-14 08:31:57 +00008533 struct bnx2x_queue_state_params *q_params,
8534 struct bnx2x_queue_setup_tx_only_params *tx_only_params,
8535 int tx_index, bool leading)
8536{
8537 memset(tx_only_params, 0, sizeof(*tx_only_params));
8538
8539 /* Set the command */
8540 q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
8541
8542 /* Set tx-only QUEUE flags: don't zero statistics */
8543 tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
8544
8545 /* choose the index of the cid to send the slow path on */
8546 tx_only_params->cid_index = tx_index;
8547
8548 /* Set general TX_ONLY_SETUP parameters */
8549 bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
8550
8551 /* Set Tx TX_ONLY_SETUP parameters */
8552 bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
8553
Merav Sicron51c1a582012-03-18 10:33:38 +00008554 DP(NETIF_MSG_IFUP,
8555 "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 +00008556 tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
8557 q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
8558 tx_only_params->gen_params.spcl_id, tx_only_params->flags);
8559
8560 /* send the ramrod */
8561 return bnx2x_queue_state_change(bp, q_params);
8562}
8563
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008564/**
8565 * bnx2x_setup_queue - setup queue
8566 *
8567 * @bp: driver handle
8568 * @fp: pointer to fastpath
8569 * @leading: is leading
8570 *
8571 * This function performs 2 steps in a Queue state machine
8572 * actually: 1) RESET->INIT 2) INIT->SETUP
8573 */
8574
8575int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
8576 bool leading)
8577{
Yuval Mintz3b603062012-03-18 10:33:39 +00008578 struct bnx2x_queue_state_params q_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008579 struct bnx2x_queue_setup_params *setup_params =
8580 &q_params.params.setup;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008581 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
8582 &q_params.params.tx_only;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008583 int rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008584 u8 tx_index;
8585
Merav Sicron51c1a582012-03-18 10:33:38 +00008586 DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008587
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008588 /* reset IGU state skip FCoE L2 queue */
8589 if (!IS_FCOE_FP(fp))
8590 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008591 IGU_INT_ENABLE, 0);
8592
Barak Witkowski15192a82012-06-19 07:48:28 +00008593 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008594 /* We want to wait for completion in this context */
8595 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008596
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008597 /* Prepare the INIT parameters */
8598 bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008599
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008600 /* Set the command */
8601 q_params.cmd = BNX2X_Q_CMD_INIT;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008602
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008603 /* Change the state to INIT */
8604 rc = bnx2x_queue_state_change(bp, &q_params);
8605 if (rc) {
Ariel Elior6383c0b2011-07-14 08:31:57 +00008606 BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008607 return rc;
8608 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008609
Merav Sicron51c1a582012-03-18 10:33:38 +00008610 DP(NETIF_MSG_IFUP, "init complete\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +00008611
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008612 /* Now move the Queue to the SETUP state... */
8613 memset(setup_params, 0, sizeof(*setup_params));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008614
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008615 /* Set QUEUE flags */
8616 setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008617
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008618 /* Set general SETUP parameters */
Ariel Elior6383c0b2011-07-14 08:31:57 +00008619 bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
8620 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008621
Ariel Elior6383c0b2011-07-14 08:31:57 +00008622 bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008623 &setup_params->rxq_params);
8624
Ariel Elior6383c0b2011-07-14 08:31:57 +00008625 bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
8626 FIRST_TX_COS_INDEX);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008627
8628 /* Set the command */
8629 q_params.cmd = BNX2X_Q_CMD_SETUP;
8630
Merav Sicron55c11942012-11-07 00:45:48 +00008631 if (IS_FCOE_FP(fp))
8632 bp->fcoe_init = true;
8633
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008634 /* Change the state to SETUP */
8635 rc = bnx2x_queue_state_change(bp, &q_params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00008636 if (rc) {
8637 BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
8638 return rc;
8639 }
8640
8641 /* loop through the relevant tx-only indices */
8642 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8643 tx_index < fp->max_cos;
8644 tx_index++) {
8645
8646 /* prepare and send tx-only ramrod*/
8647 rc = bnx2x_setup_tx_only(bp, fp, &q_params,
8648 tx_only_params, tx_index, leading);
8649 if (rc) {
8650 BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
8651 fp->index, tx_index);
8652 return rc;
8653 }
8654 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008655
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008656 return rc;
8657}
8658
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008659static int bnx2x_stop_queue(struct bnx2x *bp, int index)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008660{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008661 struct bnx2x_fastpath *fp = &bp->fp[index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008662 struct bnx2x_fp_txdata *txdata;
Yuval Mintz3b603062012-03-18 10:33:39 +00008663 struct bnx2x_queue_state_params q_params = {NULL};
Ariel Elior6383c0b2011-07-14 08:31:57 +00008664 int rc, tx_index;
8665
Merav Sicron51c1a582012-03-18 10:33:38 +00008666 DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008667
Barak Witkowski15192a82012-06-19 07:48:28 +00008668 q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008669 /* We want to wait for completion in this context */
8670 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008671
Ariel Elior6383c0b2011-07-14 08:31:57 +00008672 /* close tx-only connections */
8673 for (tx_index = FIRST_TX_ONLY_COS_INDEX;
8674 tx_index < fp->max_cos;
8675 tx_index++){
8676
8677 /* ascertain this is a normal queue*/
Merav Sicron65565882012-06-19 07:48:26 +00008678 txdata = fp->txdata_ptr[tx_index];
Ariel Elior6383c0b2011-07-14 08:31:57 +00008679
Merav Sicron51c1a582012-03-18 10:33:38 +00008680 DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00008681 txdata->txq_index);
8682
8683 /* send halt terminate on tx-only connection */
8684 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
8685 memset(&q_params.params.terminate, 0,
8686 sizeof(q_params.params.terminate));
8687 q_params.params.terminate.cid_index = tx_index;
8688
8689 rc = bnx2x_queue_state_change(bp, &q_params);
8690 if (rc)
8691 return rc;
8692
8693 /* send halt terminate on tx-only connection */
8694 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
8695 memset(&q_params.params.cfc_del, 0,
8696 sizeof(q_params.params.cfc_del));
8697 q_params.params.cfc_del.cid_index = tx_index;
8698 rc = bnx2x_queue_state_change(bp, &q_params);
8699 if (rc)
8700 return rc;
8701 }
8702 /* Stop the primary connection: */
8703 /* ...halt the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008704 q_params.cmd = BNX2X_Q_CMD_HALT;
8705 rc = bnx2x_queue_state_change(bp, &q_params);
8706 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008707 return rc;
8708
Ariel Elior6383c0b2011-07-14 08:31:57 +00008709 /* ...terminate the connection */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008710 q_params.cmd = BNX2X_Q_CMD_TERMINATE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008711 memset(&q_params.params.terminate, 0,
8712 sizeof(q_params.params.terminate));
8713 q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008714 rc = bnx2x_queue_state_change(bp, &q_params);
8715 if (rc)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008716 return rc;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008717 /* ...delete cfc entry */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008718 q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
Ariel Elior6383c0b2011-07-14 08:31:57 +00008719 memset(&q_params.params.cfc_del, 0,
8720 sizeof(q_params.params.cfc_del));
8721 q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008722 return bnx2x_queue_state_change(bp, &q_params);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008723}
8724
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008725static void bnx2x_reset_func(struct bnx2x *bp)
8726{
8727 int port = BP_PORT(bp);
8728 int func = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008729 int i;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008730
8731 /* Disable the function in the FW */
8732 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
8733 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
8734 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
8735 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
8736
8737 /* FP SBs */
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008738 for_each_eth_queue(bp, i) {
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008739 struct bnx2x_fastpath *fp = &bp->fp[i];
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008740 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Ariel Elior6383c0b2011-07-14 08:31:57 +00008741 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
8742 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008743 }
8744
Merav Sicron55c11942012-11-07 00:45:48 +00008745 if (CNIC_LOADED(bp))
8746 /* CNIC SB */
8747 REG_WR8(bp, BAR_CSTRORM_INTMEM +
8748 CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
8749 (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
8750
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008751 /* SP SB */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008752 REG_WR8(bp, BAR_CSTRORM_INTMEM +
Yuval Mintz2de67432013-01-23 03:21:43 +00008753 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
8754 SB_DISABLED);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008755
8756 for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
8757 REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
8758 0);
Eliezer Tamir49d66772008-02-28 11:53:13 -08008759
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008760 /* Configure IGU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008761 if (bp->common.int_block == INT_BLOCK_HC) {
8762 REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
8763 REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
8764 } else {
8765 REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
8766 REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
8767 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008768
Merav Sicron55c11942012-11-07 00:45:48 +00008769 if (CNIC_LOADED(bp)) {
8770 /* Disable Timer scan */
8771 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
8772 /*
8773 * Wait for at least 10ms and up to 2 second for the timers
8774 * scan to complete
8775 */
8776 for (i = 0; i < 200; i++) {
Yuval Mintz639d65b2013-06-02 00:06:21 +00008777 usleep_range(10000, 20000);
Merav Sicron55c11942012-11-07 00:45:48 +00008778 if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
8779 break;
8780 }
Michael Chan37b091b2009-10-10 13:46:55 +00008781 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008782 /* Clear ILT */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008783 bnx2x_clear_func_ilt(bp, func);
8784
8785 /* Timers workaround bug for E2: if this is vnic-3,
8786 * we need to set the entire ilt range for this timers.
8787 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008788 if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008789 struct ilt_client_info ilt_cli;
8790 /* use dummy TM client */
8791 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
8792 ilt_cli.start = 0;
8793 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
8794 ilt_cli.client_num = ILT_CLIENT_TM;
8795
8796 bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
8797 }
8798
8799 /* this assumes that reset_port() called before reset_func()*/
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008800 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008801 bnx2x_pf_disable(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008802
8803 bp->dmae_ready = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008804}
8805
8806static void bnx2x_reset_port(struct bnx2x *bp)
8807{
8808 int port = BP_PORT(bp);
8809 u32 val;
8810
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008811 /* Reset physical Link */
8812 bnx2x__link_reset(bp);
8813
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008814 REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
8815
8816 /* Do not rcv packets to BRB */
8817 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
8818 /* Do not direct rcv packets that are not for MCP to the BRB */
8819 REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
8820 NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
8821
8822 /* Configure AEU */
8823 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
8824
8825 msleep(100);
8826 /* Check for BRB port occupancy */
8827 val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
8828 if (val)
8829 DP(NETIF_MSG_IFDOWN,
Eilon Greenstein33471622008-08-13 15:59:08 -07008830 "BRB1 is not empty %d blocks are occupied\n", val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008831
8832 /* TODO: Close Doorbell port? */
8833}
8834
Eric Dumazet1191cb82012-04-27 21:39:21 +00008835static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008836{
Yuval Mintz3b603062012-03-18 10:33:39 +00008837 struct bnx2x_func_state_params func_params = {NULL};
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008838
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008839 /* Prepare parameters for function state transitions */
8840 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008841
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008842 func_params.f_obj = &bp->func_obj;
8843 func_params.cmd = BNX2X_F_CMD_HW_RESET;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008844
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008845 func_params.params.hw_init.load_phase = load_code;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008846
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008847 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008848}
8849
Eric Dumazet1191cb82012-04-27 21:39:21 +00008850static int bnx2x_func_stop(struct bnx2x *bp)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008851{
Yuval Mintz3b603062012-03-18 10:33:39 +00008852 struct bnx2x_func_state_params func_params = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008853 int rc;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008854
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008855 /* Prepare parameters for function state transitions */
8856 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
8857 func_params.f_obj = &bp->func_obj;
8858 func_params.cmd = BNX2X_F_CMD_STOP;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00008859
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008860 /*
8861 * Try to stop the function the 'good way'. If fails (in case
8862 * of a parity error during bnx2x_chip_cleanup()) and we are
8863 * not in a debug mode, perform a state transaction in order to
8864 * enable further HW_RESET transaction.
8865 */
8866 rc = bnx2x_func_state_change(bp, &func_params);
8867 if (rc) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008868#ifdef BNX2X_STOP_ON_ERROR
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008869 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008870#else
Merav Sicron51c1a582012-03-18 10:33:38 +00008871 BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008872 __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
8873 return bnx2x_func_state_change(bp, &func_params);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008874#endif
Yitchak Gertner65abd742008-08-25 15:26:24 -07008875 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008876
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008877 return 0;
8878}
Yitchak Gertner65abd742008-08-25 15:26:24 -07008879
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008880/**
8881 * bnx2x_send_unload_req - request unload mode from the MCP.
8882 *
8883 * @bp: driver handle
8884 * @unload_mode: requested function's unload mode
8885 *
8886 * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
8887 */
8888u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
8889{
8890 u32 reset_code = 0;
8891 int port = BP_PORT(bp);
8892
8893 /* Select the UNLOAD request mode */
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008894 if (unload_mode == UNLOAD_NORMAL)
8895 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008896
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008897 else if (bp->flags & NO_WOL_FLAG)
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008898 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008899
Eilon Greenstein7d0446c2009-07-29 00:20:10 +00008900 else if (bp->wol) {
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008901 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008902 u8 *mac_addr = bp->dev->dev_addr;
Jon Mason29ed74c2013-09-11 11:22:39 -07008903 struct pci_dev *pdev = bp->pdev;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008904 u32 val;
David S. Miller88c51002011-10-07 13:38:43 -04008905 u16 pmc;
8906
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008907 /* The mac address is written to entries 1-4 to
David S. Miller88c51002011-10-07 13:38:43 -04008908 * preserve entry 0 which is used by the PMF
8909 */
David S. Miller8decf862011-09-22 03:23:13 -04008910 u8 entry = (BP_VN(bp) + 1)*8;
Vladislav Zolotarovda5a6622008-08-13 15:50:00 -07008911
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008912 val = (mac_addr[0] << 8) | mac_addr[1];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008913 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008914
8915 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
8916 (mac_addr[4] << 8) | mac_addr[5];
Eilon Greenstein3196a882008-08-13 15:58:49 -07008917 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008918
David S. Miller88c51002011-10-07 13:38:43 -04008919 /* Enable the PME and clear the status */
Jon Mason29ed74c2013-09-11 11:22:39 -07008920 pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
David S. Miller88c51002011-10-07 13:38:43 -04008921 pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
Jon Mason29ed74c2013-09-11 11:22:39 -07008922 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
David S. Miller88c51002011-10-07 13:38:43 -04008923
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008924 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
Eliezer Tamir228241e2008-02-28 11:56:57 -08008925
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008926 } else
8927 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
8928
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008929 /* Send the request to the MCP */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008930 if (!BP_NOMCP(bp))
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008931 reset_code = bnx2x_fw_command(bp, reset_code, 0);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008932 else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008933 int path = BP_PATH(bp);
8934
Merav Sicron51c1a582012-03-18 10:33:38 +00008935 DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008936 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8937 bnx2x_load_count[path][2]);
8938 bnx2x_load_count[path][0]--;
8939 bnx2x_load_count[path][1 + port]--;
Merav Sicron51c1a582012-03-18 10:33:38 +00008940 DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008941 path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
8942 bnx2x_load_count[path][2]);
8943 if (bnx2x_load_count[path][0] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008944 reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
stephen hemmingera8f47eb2014-01-09 22:20:11 -08008945 else if (bnx2x_load_count[path][1 + port] == 0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07008946 reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
8947 else
8948 reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
8949 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02008950
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008951 return reset_code;
8952}
8953
8954/**
8955 * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
8956 *
8957 * @bp: driver handle
Yuval Mintz5d07d862012-09-13 02:56:21 +00008958 * @keep_link: true iff link should be kept up
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008959 */
Yuval Mintz5d07d862012-09-13 02:56:21 +00008960void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008961{
Yuval Mintz5d07d862012-09-13 02:56:21 +00008962 u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
8963
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008964 /* Report UNLOAD_DONE to MCP */
8965 if (!BP_NOMCP(bp))
Yuval Mintz5d07d862012-09-13 02:56:21 +00008966 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03008967}
8968
Eric Dumazet1191cb82012-04-27 21:39:21 +00008969static int bnx2x_func_wait_started(struct bnx2x *bp)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008970{
8971 int tout = 50;
8972 int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
8973
8974 if (!bp->port.pmf)
8975 return 0;
8976
8977 /*
8978 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008979 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008980 * 1. Sync IRS for default SB
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008981 * 2. Sync SP queue - this guarantees us that attention handling started
8982 * 3. Wait, that TX disable/enable transaction completes
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008983 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00008984 * 1+2 guarantee that if DCBx attention was scheduled it already changed
8985 * pending bit of transaction from STARTED-->TX_STOPPED, if we already
8986 * received completion for the transaction the state is TX_STOPPED.
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008987 * State will return to STARTED after completion of TX_STOPPED-->STARTED
8988 * transaction.
8989 */
8990
8991 /* make sure default SB ISR is done */
8992 if (msix)
8993 synchronize_irq(bp->msix_table[0].vector);
8994 else
8995 synchronize_irq(bp->pdev->irq);
8996
8997 flush_workqueue(bnx2x_wq);
Yuval Mintz370d4a22014-03-23 18:12:24 +02008998 flush_workqueue(bnx2x_iov_wq);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00008999
9000 while (bnx2x_func_get_state(bp, &bp->func_obj) !=
9001 BNX2X_F_STATE_STARTED && tout--)
9002 msleep(20);
9003
9004 if (bnx2x_func_get_state(bp, &bp->func_obj) !=
9005 BNX2X_F_STATE_STARTED) {
9006#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +00009007 BNX2X_ERR("Wrong function state\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00009008 return -EBUSY;
9009#else
9010 /*
9011 * Failed to complete the transaction in a "good way"
9012 * Force both transactions with CLR bit
9013 */
Yuval Mintz3b603062012-03-18 10:33:39 +00009014 struct bnx2x_func_state_params func_params = {NULL};
Dmitry Kravkov6debea82011-07-19 01:42:04 +00009015
Merav Sicron51c1a582012-03-18 10:33:38 +00009016 DP(NETIF_MSG_IFDOWN,
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009017 "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
Dmitry Kravkov6debea82011-07-19 01:42:04 +00009018
9019 func_params.f_obj = &bp->func_obj;
9020 __set_bit(RAMROD_DRV_CLR_ONLY,
9021 &func_params.ramrod_flags);
9022
9023 /* STARTED-->TX_ST0PPED */
9024 func_params.cmd = BNX2X_F_CMD_TX_STOP;
9025 bnx2x_func_state_change(bp, &func_params);
9026
9027 /* TX_ST0PPED-->STARTED */
9028 func_params.cmd = BNX2X_F_CMD_TX_START;
9029 return bnx2x_func_state_change(bp, &func_params);
9030#endif
9031 }
9032
9033 return 0;
9034}
9035
Yuval Mintz5d07d862012-09-13 02:56:21 +00009036void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009037{
9038 int port = BP_PORT(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +00009039 int i, rc = 0;
9040 u8 cos;
Yuval Mintz3b603062012-03-18 10:33:39 +00009041 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009042 u32 reset_code;
9043
9044 /* Wait until tx fastpath tasks complete */
9045 for_each_tx_queue(bp, i) {
9046 struct bnx2x_fastpath *fp = &bp->fp[i];
9047
Ariel Elior6383c0b2011-07-14 08:31:57 +00009048 for_each_cos_in_tx_queue(fp, cos)
Merav Sicron65565882012-06-19 07:48:26 +00009049 rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009050#ifdef BNX2X_STOP_ON_ERROR
9051 if (rc)
9052 return;
9053#endif
9054 }
9055
9056 /* Give HW time to discard old tx messages */
Yuval Mintz0926d492013-01-23 03:21:45 +00009057 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009058
9059 /* Clean all ETH MACs */
Barak Witkowski15192a82012-06-19 07:48:28 +00009060 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
9061 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009062 if (rc < 0)
9063 BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
9064
9065 /* Clean up UC list */
Barak Witkowski15192a82012-06-19 07:48:28 +00009066 rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009067 true);
9068 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +00009069 BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
9070 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009071
9072 /* Disable LLH */
9073 if (!CHIP_IS_E1(bp))
9074 REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
9075
9076 /* Set "drop all" (stop Rx).
9077 * We need to take a netif_addr_lock() here in order to prevent
9078 * a race between the completion code and this code.
9079 */
9080 netif_addr_lock_bh(bp->dev);
9081 /* Schedule the rx_mode command */
9082 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
9083 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
9084 else
9085 bnx2x_set_storm_rx_mode(bp);
9086
9087 /* Cleanup multicast configuration */
9088 rparam.mcast_obj = &bp->mcast_obj;
9089 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
9090 if (rc < 0)
9091 BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
9092
9093 netif_addr_unlock_bh(bp->dev);
9094
Ariel Eliorf1929b02013-01-01 05:22:41 +00009095 bnx2x_iov_chip_cleanup(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009096
Dmitry Kravkov6debea82011-07-19 01:42:04 +00009097 /*
9098 * Send the UNLOAD_REQUEST to the MCP. This will return if
9099 * this function should perform FUNC, PORT or COMMON HW
9100 * reset.
9101 */
9102 reset_code = bnx2x_send_unload_req(bp, unload_mode);
9103
9104 /*
9105 * (assumption: No Attention from MCP at this stage)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00009106 * PMF probably in the middle of TX disable/enable transaction
Dmitry Kravkov6debea82011-07-19 01:42:04 +00009107 */
9108 rc = bnx2x_func_wait_started(bp);
9109 if (rc) {
9110 BNX2X_ERR("bnx2x_func_wait_started failed\n");
9111#ifdef BNX2X_STOP_ON_ERROR
9112 return;
9113#endif
9114 }
9115
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009116 /* Close multi and leading connections
9117 * Completions for ramrods are collected in a synchronous way
9118 */
Merav Sicron55c11942012-11-07 00:45:48 +00009119 for_each_eth_queue(bp, i)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009120 if (bnx2x_stop_queue(bp, i))
9121#ifdef BNX2X_STOP_ON_ERROR
9122 return;
9123#else
9124 goto unload_error;
9125#endif
Merav Sicron55c11942012-11-07 00:45:48 +00009126
9127 if (CNIC_LOADED(bp)) {
9128 for_each_cnic_queue(bp, i)
9129 if (bnx2x_stop_queue(bp, i))
9130#ifdef BNX2X_STOP_ON_ERROR
9131 return;
9132#else
9133 goto unload_error;
9134#endif
9135 }
9136
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009137 /* If SP settings didn't get completed so far - something
9138 * very wrong has happen.
9139 */
9140 if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
9141 BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
9142
9143#ifndef BNX2X_STOP_ON_ERROR
9144unload_error:
9145#endif
9146 rc = bnx2x_func_stop(bp);
9147 if (rc) {
9148 BNX2X_ERR("Function stop failed!\n");
9149#ifdef BNX2X_STOP_ON_ERROR
9150 return;
9151#endif
9152 }
9153
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009154 /* Disable HW interrupts, NAPI */
9155 bnx2x_netif_stop(bp, 1);
Merav Sicron26614ba2012-08-27 03:26:19 +00009156 /* Delete all NAPI objects */
9157 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +00009158 if (CNIC_LOADED(bp))
9159 bnx2x_del_all_napi_cnic(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009160
9161 /* Release IRQs */
Dmitry Kravkovd6214d72010-10-06 03:32:10 +00009162 bnx2x_free_irq(bp);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00009163
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009164 /* Reset the chip */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009165 rc = bnx2x_reset_hw(bp, reset_code);
9166 if (rc)
9167 BNX2X_ERR("HW_RESET failed\n");
9168
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009169 /* Report UNLOAD_DONE to MCP */
Yuval Mintz5d07d862012-09-13 02:56:21 +00009170 bnx2x_send_unload_done(bp, keep_link);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009171}
9172
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +00009173void bnx2x_disable_close_the_gate(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009174{
9175 u32 val;
9176
Merav Sicron51c1a582012-03-18 10:33:38 +00009177 DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009178
9179 if (CHIP_IS_E1(bp)) {
9180 int port = BP_PORT(bp);
9181 u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
9182 MISC_REG_AEU_MASK_ATTN_FUNC_0;
9183
9184 val = REG_RD(bp, addr);
9185 val &= ~(0x300);
9186 REG_WR(bp, addr, val);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03009187 } else {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009188 val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
9189 val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
9190 MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
9191 REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
9192 }
9193}
9194
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009195/* Close gates #2, #3 and #4: */
9196static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
9197{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009198 u32 val;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009199
9200 /* Gates #2 and #4a are closed/opened for "not E1" only */
9201 if (!CHIP_IS_E1(bp)) {
9202 /* #4 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009203 REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009204 /* #2 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009205 REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009206 }
9207
9208 /* #3 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009209 if (CHIP_IS_E1x(bp)) {
9210 /* Prevent interrupts from HC on both ports */
9211 val = REG_RD(bp, HC_REG_CONFIG_1);
9212 REG_WR(bp, HC_REG_CONFIG_1,
9213 (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
9214 (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
9215
9216 val = REG_RD(bp, HC_REG_CONFIG_0);
9217 REG_WR(bp, HC_REG_CONFIG_0,
9218 (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
9219 (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
9220 } else {
Jorrit Schippersd82603c2012-12-27 17:33:02 +01009221 /* Prevent incoming interrupts in IGU */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009222 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
9223
9224 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
9225 (!close) ?
9226 (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
9227 (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
9228 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009229
Merav Sicron51c1a582012-03-18 10:33:38 +00009230 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009231 close ? "closing" : "opening");
9232 mmiowb();
9233}
9234
9235#define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
9236
9237static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
9238{
9239 /* Do some magic... */
9240 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9241 *magic_val = val & SHARED_MF_CLP_MAGIC;
9242 MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
9243}
9244
Dmitry Kravkove8920672011-05-04 23:52:40 +00009245/**
9246 * bnx2x_clp_reset_done - restore the value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009247 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009248 * @bp: driver handle
9249 * @magic_val: old value of the `magic' bit.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009250 */
9251static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
9252{
9253 /* Restore the `magic' bit value... */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009254 u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
9255 MF_CFG_WR(bp, shared_mf_config.clp_mb,
9256 (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
9257}
9258
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00009259/**
Dmitry Kravkove8920672011-05-04 23:52:40 +00009260 * bnx2x_reset_mcp_prep - prepare for MCP reset.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009261 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009262 * @bp: driver handle
9263 * @magic_val: old value of 'magic' bit.
9264 *
9265 * Takes care of CLP configurations.
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009266 */
9267static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
9268{
9269 u32 shmem;
9270 u32 validity_offset;
9271
Merav Sicron51c1a582012-03-18 10:33:38 +00009272 DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009273
9274 /* Set `magic' bit in order to save MF config */
9275 if (!CHIP_IS_E1(bp))
9276 bnx2x_clp_reset_prep(bp, magic_val);
9277
9278 /* Get shmem offset */
9279 shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009280 validity_offset =
9281 offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009282
9283 /* Clear validity map flags */
9284 if (shmem > 0)
9285 REG_WR(bp, shmem + validity_offset, 0);
9286}
9287
9288#define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
9289#define MCP_ONE_TIMEOUT 100 /* 100 ms */
9290
Dmitry Kravkove8920672011-05-04 23:52:40 +00009291/**
9292 * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009293 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00009294 * @bp: driver handle
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009295 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00009296static void bnx2x_mcp_wait_one(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009297{
9298 /* special handling for emulation and FPGA,
9299 wait 10 times longer */
9300 if (CHIP_REV_IS_SLOW(bp))
9301 msleep(MCP_ONE_TIMEOUT*10);
9302 else
9303 msleep(MCP_ONE_TIMEOUT);
9304}
9305
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009306/*
9307 * initializes bp->common.shmem_base and waits for validity signature to appear
9308 */
9309static int bnx2x_init_shmem(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009310{
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009311 int cnt = 0;
9312 u32 val = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009313
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009314 do {
9315 bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
9316 if (bp->common.shmem_base) {
9317 val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
9318 if (val & SHR_MEM_VALIDITY_MB)
9319 return 0;
9320 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009321
9322 bnx2x_mcp_wait_one(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009323
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009324 } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009325
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009326 BNX2X_ERR("BAD MCP validity signature\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009327
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +00009328 return -ENODEV;
9329}
9330
9331static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
9332{
9333 int rc = bnx2x_init_shmem(bp);
9334
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009335 /* Restore the `magic' bit value */
9336 if (!CHIP_IS_E1(bp))
9337 bnx2x_clp_reset_done(bp, magic_val);
9338
9339 return rc;
9340}
9341
9342static void bnx2x_pxp_prep(struct bnx2x *bp)
9343{
9344 if (!CHIP_IS_E1(bp)) {
9345 REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
9346 REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009347 mmiowb();
9348 }
9349}
9350
9351/*
9352 * Reset the whole chip except for:
9353 * - PCIE core
9354 * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
9355 * one reset bit)
9356 * - IGU
9357 * - MISC (including AEU)
9358 * - GRC
9359 * - RBCN, RBCP
9360 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009361static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009362{
9363 u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009364 u32 global_bits2, stay_reset2;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009365
9366 /*
9367 * Bits that have to be set in reset_mask2 if we want to reset 'global'
9368 * (per chip) blocks.
9369 */
9370 global_bits2 =
9371 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
9372 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009373
Barak Witkowskic55e7712012-12-02 04:05:46 +00009374 /* Don't reset the following blocks.
9375 * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
9376 * reset, as in 4 port device they might still be owned
9377 * by the MCP (there is only one leader per path).
9378 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009379 not_reset_mask1 =
9380 MISC_REGISTERS_RESET_REG_1_RST_HC |
9381 MISC_REGISTERS_RESET_REG_1_RST_PXPV |
9382 MISC_REGISTERS_RESET_REG_1_RST_PXP;
9383
9384 not_reset_mask2 =
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009385 MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009386 MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
9387 MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
9388 MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
9389 MISC_REGISTERS_RESET_REG_2_RST_RBCN |
9390 MISC_REGISTERS_RESET_REG_2_RST_GRC |
9391 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009392 MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
9393 MISC_REGISTERS_RESET_REG_2_RST_ATC |
Barak Witkowskic55e7712012-12-02 04:05:46 +00009394 MISC_REGISTERS_RESET_REG_2_PGLC |
9395 MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
9396 MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
9397 MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
9398 MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
9399 MISC_REGISTERS_RESET_REG_2_UMAC0 |
9400 MISC_REGISTERS_RESET_REG_2_UMAC1;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009401
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009402 /*
9403 * Keep the following blocks in reset:
9404 * - all xxMACs are handled by the bnx2x_link code.
9405 */
9406 stay_reset2 =
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009407 MISC_REGISTERS_RESET_REG_2_XMAC |
9408 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
9409
9410 /* Full reset masks according to the chip */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009411 reset_mask1 = 0xffffffff;
9412
9413 if (CHIP_IS_E1(bp))
9414 reset_mask2 = 0xffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009415 else if (CHIP_IS_E1H(bp))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009416 reset_mask2 = 0x1ffff;
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009417 else if (CHIP_IS_E2(bp))
9418 reset_mask2 = 0xfffff;
9419 else /* CHIP_IS_E3 */
9420 reset_mask2 = 0x3ffffff;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009421
9422 /* Don't reset global blocks unless we need to */
9423 if (!global)
9424 reset_mask2 &= ~global_bits2;
9425
9426 /*
9427 * In case of attention in the QM, we need to reset PXP
9428 * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
9429 * because otherwise QM reset would release 'close the gates' shortly
9430 * before resetting the PXP, then the PSWRQ would send a write
9431 * request to PGLUE. Then when PXP is reset, PGLUE would try to
9432 * read the payload data from PSWWR, but PSWWR would not
9433 * respond. The write queue in PGLUE would stuck, dmae commands
9434 * would not return. Therefore it's important to reset the second
9435 * reset register (containing the
9436 * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
9437 * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
9438 * bit).
9439 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009440 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
9441 reset_mask2 & (~not_reset_mask2));
9442
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009443 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
9444 reset_mask1 & (~not_reset_mask1));
9445
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009446 barrier();
9447 mmiowb();
9448
Vladislav Zolotarov8736c822011-07-21 07:58:36 +00009449 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
9450 reset_mask2 & (~stay_reset2));
9451
9452 barrier();
9453 mmiowb();
9454
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009455 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009456 mmiowb();
9457}
9458
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009459/**
9460 * bnx2x_er_poll_igu_vq - poll for pending writes bit.
9461 * It should get cleared in no more than 1s.
9462 *
9463 * @bp: driver handle
9464 *
9465 * It should get cleared in no more than 1s. Returns 0 if
9466 * pending writes bit gets cleared.
9467 */
9468static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
9469{
9470 u32 cnt = 1000;
9471 u32 pend_bits = 0;
9472
9473 do {
9474 pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
9475
9476 if (pend_bits == 0)
9477 break;
9478
Yuval Mintz0926d492013-01-23 03:21:45 +00009479 usleep_range(1000, 2000);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009480 } while (cnt-- > 0);
9481
9482 if (cnt <= 0) {
9483 BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
9484 pend_bits);
9485 return -EBUSY;
9486 }
9487
9488 return 0;
9489}
9490
9491static int bnx2x_process_kill(struct bnx2x *bp, bool global)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009492{
9493 int cnt = 1000;
9494 u32 val = 0;
9495 u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
Yuval Mintz2de67432013-01-23 03:21:43 +00009496 u32 tags_63_32 = 0;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009497
9498 /* Empty the Tetris buffer, wait for 1s */
9499 do {
9500 sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
9501 blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
9502 port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
9503 port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
9504 pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
Barak Witkowskic55e7712012-12-02 04:05:46 +00009505 if (CHIP_IS_E3(bp))
9506 tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
9507
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009508 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
9509 ((port_is_idle_0 & 0x1) == 0x1) &&
9510 ((port_is_idle_1 & 0x1) == 0x1) &&
Barak Witkowskic55e7712012-12-02 04:05:46 +00009511 (pgl_exp_rom2 == 0xffffffff) &&
9512 (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009513 break;
Yuval Mintz0926d492013-01-23 03:21:45 +00009514 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009515 } while (cnt-- > 0);
9516
9517 if (cnt <= 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009518 BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
9519 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 +00009520 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
9521 pgl_exp_rom2);
9522 return -EAGAIN;
9523 }
9524
9525 barrier();
9526
9527 /* Close gates #2, #3 and #4 */
9528 bnx2x_set_234_gates(bp, true);
9529
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009530 /* Poll for IGU VQs for 57712 and newer chips */
9531 if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
9532 return -EAGAIN;
9533
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009534 /* TBD: Indicate that "process kill" is in progress to MCP */
9535
9536 /* Clear "unprepared" bit */
9537 REG_WR(bp, MISC_REG_UNPREPARED, 0);
9538 barrier();
9539
9540 /* Make sure all is written to the chip before the reset */
9541 mmiowb();
9542
9543 /* Wait for 1ms to empty GLUE and PCI-E core queues,
9544 * PSWHST, GRC and PSWRD Tetris buffer.
9545 */
Yuval Mintz0926d492013-01-23 03:21:45 +00009546 usleep_range(1000, 2000);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009547
9548 /* Prepare to chip reset: */
9549 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009550 if (global)
9551 bnx2x_reset_mcp_prep(bp, &val);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009552
9553 /* PXP */
9554 bnx2x_pxp_prep(bp);
9555 barrier();
9556
9557 /* reset the chip */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009558 bnx2x_process_kill_chip_reset(bp, global);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009559 barrier();
9560
Dmitry Kravkov9dcd9ac2013-11-17 08:59:27 +02009561 /* clear errors in PGB */
9562 if (!CHIP_IS_E1x(bp))
9563 REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
9564
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009565 /* Recover after reset: */
9566 /* MCP */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009567 if (global && bnx2x_reset_mcp_comp(bp, val))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009568 return -EAGAIN;
9569
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009570 /* TBD: Add resetting the NO_MCP mode DB here */
9571
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009572 /* Open the gates #2, #3 and #4 */
9573 bnx2x_set_234_gates(bp, false);
9574
9575 /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
9576 * reset state, re-enable attentions. */
9577
9578 return 0;
9579}
9580
Merav Sicron910cc722012-11-11 03:56:08 +00009581static int bnx2x_leader_reset(struct bnx2x *bp)
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009582{
9583 int rc = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009584 bool global = bnx2x_reset_is_global(bp);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009585 u32 load_code;
9586
9587 /* if not going to reset MCP - load "fake" driver to reset HW while
9588 * driver is owner of the HW
9589 */
9590 if (!global && !BP_NOMCP(bp)) {
Yuval Mintz5d07d862012-09-13 02:56:21 +00009591 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
9592 DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
Ariel Elior95c6c6162012-01-26 06:01:52 +00009593 if (!load_code) {
9594 BNX2X_ERR("MCP response failure, aborting\n");
9595 rc = -EAGAIN;
9596 goto exit_leader_reset;
9597 }
9598 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
9599 (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
9600 BNX2X_ERR("MCP unexpected resp, aborting\n");
9601 rc = -EAGAIN;
9602 goto exit_leader_reset2;
9603 }
9604 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
9605 if (!load_code) {
9606 BNX2X_ERR("MCP response failure, aborting\n");
9607 rc = -EAGAIN;
9608 goto exit_leader_reset2;
9609 }
9610 }
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009611
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009612 /* Try to recover after the failure */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009613 if (bnx2x_process_kill(bp, global)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009614 BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
9615 BP_PATH(bp));
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009616 rc = -EAGAIN;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009617 goto exit_leader_reset2;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009618 }
9619
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009620 /*
9621 * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
9622 * state.
9623 */
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009624 bnx2x_set_reset_done(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009625 if (global)
9626 bnx2x_clear_reset_global(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009627
Ariel Elior95c6c6162012-01-26 06:01:52 +00009628exit_leader_reset2:
9629 /* unload "fake driver" if it was loaded */
9630 if (!global && !BP_NOMCP(bp)) {
9631 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
9632 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
9633 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009634exit_leader_reset:
9635 bp->is_leader = 0;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009636 bnx2x_release_leader_lock(bp);
9637 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009638 return rc;
9639}
9640
Eric Dumazet1191cb82012-04-27 21:39:21 +00009641static void bnx2x_recovery_failed(struct bnx2x *bp)
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009642{
9643 netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
9644
9645 /* Disconnect this device */
9646 netif_device_detach(bp->dev);
9647
9648 /*
9649 * Block ifup for all function on this engine until "process kill"
9650 * or power cycle.
9651 */
9652 bnx2x_set_reset_in_progress(bp);
9653
9654 /* Shut down the power */
9655 bnx2x_set_power_state(bp, PCI_D3hot);
9656
9657 bp->recovery_state = BNX2X_RECOVERY_FAILED;
9658
9659 smp_mb();
9660}
9661
9662/*
9663 * Assumption: runs under rtnl lock. This together with the fact
Ariel Elior6383c0b2011-07-14 08:31:57 +00009664 * that it's called only from bnx2x_sp_rtnl() ensure that it
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009665 * will never be called when netif_running(bp->dev) is false.
9666 */
9667static void bnx2x_parity_recover(struct bnx2x *bp)
9668{
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009669 bool global = false;
Ariel Elior7a752992012-01-26 06:01:53 +00009670 u32 error_recovered, error_unrecovered;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009671 bool is_parity;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009672
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009673 DP(NETIF_MSG_HW, "Handling parity\n");
9674 while (1) {
9675 switch (bp->recovery_state) {
9676 case BNX2X_RECOVERY_INIT:
9677 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009678 is_parity = bnx2x_chk_parity_attn(bp, &global, false);
9679 WARN_ON(!is_parity);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009680
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009681 /* Try to get a LEADER_LOCK HW lock */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009682 if (bnx2x_trylock_leader_lock(bp)) {
9683 bnx2x_set_reset_in_progress(bp);
9684 /*
9685 * Check if there is a global attention and if
9686 * there was a global attention, set the global
9687 * reset bit.
9688 */
9689
9690 if (global)
9691 bnx2x_set_reset_global(bp);
9692
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009693 bp->is_leader = 1;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009694 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009695
9696 /* Stop the driver */
9697 /* If interface has been removed - break */
Yuval Mintz5d07d862012-09-13 02:56:21 +00009698 if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009699 return;
9700
9701 bp->recovery_state = BNX2X_RECOVERY_WAIT;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009702
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009703 /* Ensure "is_leader", MCP command sequence and
9704 * "recovery_state" update values are seen on other
9705 * CPUs.
9706 */
9707 smp_mb();
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009708 break;
9709
9710 case BNX2X_RECOVERY_WAIT:
9711 DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
9712 if (bp->is_leader) {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009713 int other_engine = BP_PATH(bp) ? 0 : 1;
Ariel Elior889b9af2012-01-26 06:01:51 +00009714 bool other_load_status =
9715 bnx2x_get_load_status(bp, other_engine);
9716 bool load_status =
9717 bnx2x_get_load_status(bp, BP_PATH(bp));
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009718 global = bnx2x_reset_is_global(bp);
9719
9720 /*
9721 * In case of a parity in a global block, let
9722 * the first leader that performs a
9723 * leader_reset() reset the global blocks in
9724 * order to clear global attentions. Otherwise
Yuval Mintz16a5fd92013-06-02 00:06:18 +00009725 * the gates will remain closed for that
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009726 * engine.
9727 */
Ariel Elior889b9af2012-01-26 06:01:51 +00009728 if (load_status ||
9729 (global && other_load_status)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009730 /* Wait until all other functions get
9731 * down.
9732 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009733 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009734 HZ/10);
9735 return;
9736 } else {
9737 /* If all other functions got down -
9738 * try to bring the chip back to
9739 * normal. In any case it's an exit
9740 * point for a leader.
9741 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009742 if (bnx2x_leader_reset(bp)) {
9743 bnx2x_recovery_failed(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009744 return;
9745 }
9746
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009747 /* If we are here, means that the
9748 * leader has succeeded and doesn't
9749 * want to be a leader any more. Try
9750 * to continue as a none-leader.
9751 */
9752 break;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009753 }
9754 } else { /* non-leader */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009755 if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009756 /* Try to get a LEADER_LOCK HW lock as
9757 * long as a former leader may have
9758 * been unloaded by the user or
9759 * released a leadership by another
9760 * reason.
9761 */
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009762 if (bnx2x_trylock_leader_lock(bp)) {
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009763 /* I'm a leader now! Restart a
9764 * switch case.
9765 */
9766 bp->is_leader = 1;
9767 break;
9768 }
9769
Ariel Elior7be08a72011-07-14 08:31:19 +00009770 schedule_delayed_work(&bp->sp_rtnl_task,
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009771 HZ/10);
9772 return;
9773
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009774 } else {
9775 /*
9776 * If there was a global attention, wait
9777 * for it to be cleared.
9778 */
9779 if (bnx2x_reset_is_global(bp)) {
9780 schedule_delayed_work(
Ariel Elior7be08a72011-07-14 08:31:19 +00009781 &bp->sp_rtnl_task,
9782 HZ/10);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009783 return;
9784 }
9785
Ariel Elior7a752992012-01-26 06:01:53 +00009786 error_recovered =
9787 bp->eth_stats.recoverable_error;
9788 error_unrecovered =
9789 bp->eth_stats.unrecoverable_error;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009790 bp->recovery_state =
9791 BNX2X_RECOVERY_NIC_LOADING;
9792 if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
Ariel Elior7a752992012-01-26 06:01:53 +00009793 error_unrecovered++;
Ariel Elior95c6c6162012-01-26 06:01:52 +00009794 netdev_err(bp->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +00009795 "Recovery failed. Power cycle needed\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +00009796 /* Disconnect this device */
9797 netif_device_detach(bp->dev);
9798 /* Shut down the power */
9799 bnx2x_set_power_state(
9800 bp, PCI_D3hot);
9801 smp_mb();
9802 } else {
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009803 bp->recovery_state =
9804 BNX2X_RECOVERY_DONE;
Ariel Elior7a752992012-01-26 06:01:53 +00009805 error_recovered++;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009806 smp_mb();
9807 }
Ariel Elior7a752992012-01-26 06:01:53 +00009808 bp->eth_stats.recoverable_error =
9809 error_recovered;
9810 bp->eth_stats.unrecoverable_error =
9811 error_unrecovered;
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +00009812
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009813 return;
9814 }
9815 }
9816 default:
9817 return;
9818 }
9819 }
9820}
9821
Michal Schmidt56ad3152012-02-16 02:38:48 +00009822static int bnx2x_close(struct net_device *dev);
9823
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009824/* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
9825 * scheduled on a general queue in order to prevent a dead lock.
9826 */
Ariel Elior7be08a72011-07-14 08:31:19 +00009827static void bnx2x_sp_rtnl_task(struct work_struct *work)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009828{
Ariel Elior7be08a72011-07-14 08:31:19 +00009829 struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009830
9831 rtnl_lock();
9832
Ariel Elior8395be52013-01-01 05:22:44 +00009833 if (!netif_running(bp->dev)) {
9834 rtnl_unlock();
9835 return;
9836 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009837
Ariel Elior7be08a72011-07-14 08:31:19 +00009838 if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009839#ifdef BNX2X_STOP_ON_ERROR
9840 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9841 "you will need to reboot when done\n");
9842 goto sp_rtnl_not_reset;
9843#endif
Ariel Elior7be08a72011-07-14 08:31:19 +00009844 /*
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009845 * Clear all pending SP commands as we are going to reset the
9846 * function anyway.
Ariel Elior7be08a72011-07-14 08:31:19 +00009847 */
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009848 bp->sp_rtnl_state = 0;
9849 smp_mb();
9850
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009851 bnx2x_parity_recover(bp);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009852
Ariel Elior8395be52013-01-01 05:22:44 +00009853 rtnl_unlock();
9854 return;
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009855 }
9856
9857 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
Yuval Mintz6bf07b82013-06-02 00:06:20 +00009858#ifdef BNX2X_STOP_ON_ERROR
9859 BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
9860 "you will need to reboot when done\n");
9861 goto sp_rtnl_not_reset;
9862#endif
9863
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009864 /*
9865 * Clear all pending SP commands as we are going to reset the
9866 * function anyway.
9867 */
9868 bp->sp_rtnl_state = 0;
9869 smp_mb();
9870
Yuval Mintz5d07d862012-09-13 02:56:21 +00009871 bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009872 bnx2x_nic_load(bp, LOAD_NORMAL);
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009873
Ariel Elior8395be52013-01-01 05:22:44 +00009874 rtnl_unlock();
9875 return;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00009876 }
Vladislav Zolotarovb1fb8742011-07-24 03:57:46 +00009877#ifdef BNX2X_STOP_ON_ERROR
9878sp_rtnl_not_reset:
9879#endif
9880 if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
9881 bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
Barak Witkowskia3348722012-04-23 03:04:46 +00009882 if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
9883 bnx2x_after_function_update(bp);
Ariel Elior83048592011-11-13 04:34:29 +00009884 /*
9885 * in case of fan failure we need to reset id if the "stop on error"
9886 * debug flag is set, since we trying to prevent permanent overheating
9887 * damage
9888 */
9889 if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00009890 DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
Ariel Elior83048592011-11-13 04:34:29 +00009891 netif_device_detach(bp->dev);
9892 bnx2x_close(bp->dev);
Ariel Elior8395be52013-01-01 05:22:44 +00009893 rtnl_unlock();
9894 return;
Ariel Elior83048592011-11-13 04:34:29 +00009895 }
9896
Ariel Elior381ac162013-01-01 05:22:29 +00009897 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
9898 DP(BNX2X_MSG_SP,
9899 "sending set mcast vf pf channel message from rtnl sp-task\n");
9900 bnx2x_vfpf_set_mcast(bp->dev);
9901 }
Ariel Elior78c3bcc2013-06-20 17:39:08 +03009902 if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
9903 &bp->sp_rtnl_state)){
9904 if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
9905 bnx2x_tx_disable(bp);
9906 BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
9907 }
9908 }
Ariel Elior381ac162013-01-01 05:22:29 +00009909
Yuval Mintz8b09be52013-08-01 17:30:59 +03009910 if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
9911 DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
9912 bnx2x_set_rx_mode_inner(bp);
Ariel Elior381ac162013-01-01 05:22:29 +00009913 }
9914
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00009915 if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
9916 &bp->sp_rtnl_state))
9917 bnx2x_pf_set_vfs_vlan(bp);
9918
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02009919 if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009920 bnx2x_dcbx_stop_hw_tx(bp);
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009921 bnx2x_dcbx_resume_hw_tx(bp);
Dmitry Kravkov6ffa39f2013-11-17 08:59:29 +02009922 }
Dmitry Kravkov07b4eb32013-08-19 09:11:57 +03009923
Yuval Mintz42f82772014-03-23 18:12:23 +02009924 if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
9925 &bp->sp_rtnl_state))
9926 bnx2x_update_mng_version(bp);
9927
Ariel Elior8395be52013-01-01 05:22:44 +00009928 /* work which needs rtnl lock not-taken (as it takes the lock itself and
9929 * can be called from other contexts as well)
9930 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009931 rtnl_unlock();
Ariel Elior8395be52013-01-01 05:22:44 +00009932
Ariel Elior64112802013-01-07 00:50:23 +00009933 /* enable SR-IOV if applicable */
Ariel Elior8395be52013-01-01 05:22:44 +00009934 if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
Ariel Elior3c76fef2013-03-11 05:17:46 +00009935 &bp->sp_rtnl_state)) {
9936 bnx2x_disable_sriov(bp);
Ariel Elior64112802013-01-07 00:50:23 +00009937 bnx2x_enable_sriov(bp);
Ariel Elior3c76fef2013-03-11 05:17:46 +00009938 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009939}
9940
Yaniv Rosner3deb8162011-06-14 01:34:33 +00009941static void bnx2x_period_task(struct work_struct *work)
9942{
9943 struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
9944
9945 if (!netif_running(bp->dev))
9946 goto period_task_exit;
9947
9948 if (CHIP_REV_IS_SLOW(bp)) {
9949 BNX2X_ERR("period task called on emulation, ignoring\n");
9950 goto period_task_exit;
9951 }
9952
9953 bnx2x_acquire_phy_lock(bp);
9954 /*
9955 * The barrier is needed to ensure the ordering between the writing to
9956 * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
9957 * the reading here.
9958 */
9959 smp_mb();
9960 if (bp->port.pmf) {
9961 bnx2x_period_func(&bp->link_params, &bp->link_vars);
9962
9963 /* Re-queue task in 1 sec */
9964 queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
9965 }
9966
9967 bnx2x_release_phy_lock(bp);
9968period_task_exit:
9969 return;
9970}
9971
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009972/*
9973 * Init service functions
9974 */
9975
stephen hemmingera8f47eb2014-01-09 22:20:11 -08009976static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009977{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00009978 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
9979 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
9980 return base + (BP_ABS_FUNC(bp)) * stride;
Eilon Greensteinf1ef27e2009-02-12 08:36:23 +00009981}
9982
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009983static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
9984 struct bnx2x_mac_vals *vals)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02009985{
Yuval Mintz452427b2012-03-26 20:47:07 +00009986 u32 val, base_addr, offset, mask, reset_reg;
9987 bool mac_stopped = false;
9988 u8 port = BP_PORT(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07009989
Barak Witkowski1ef1d452013-01-10 04:53:40 +00009990 /* reset addresses as they also mark which values were changed */
9991 vals->bmac_addr = 0;
9992 vals->umac_addr = 0;
9993 vals->xmac_addr = 0;
9994 vals->emac_addr = 0;
9995
Yuval Mintz452427b2012-03-26 20:47:07 +00009996 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
David S. Miller8decf862011-09-22 03:23:13 -04009997
Yuval Mintz452427b2012-03-26 20:47:07 +00009998 if (!CHIP_IS_E3(bp)) {
9999 val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
10000 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
10001 if ((mask & reset_reg) && val) {
10002 u32 wb_data[2];
10003 BNX2X_DEV_INFO("Disable bmac Rx\n");
10004 base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
10005 : NIG_REG_INGRESS_BMAC0_MEM;
10006 offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
10007 : BIGMAC_REGISTER_BMAC_CONTROL;
Ariel Eliorf16da432012-01-26 06:01:50 +000010008
Yuval Mintz452427b2012-03-26 20:47:07 +000010009 /*
10010 * use rd/wr since we cannot use dmae. This is safe
10011 * since MCP won't access the bus due to the request
10012 * to unload, and no function on the path can be
10013 * loaded at this time.
10014 */
10015 wb_data[0] = REG_RD(bp, base_addr + offset);
10016 wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010017 vals->bmac_addr = base_addr + offset;
10018 vals->bmac_val[0] = wb_data[0];
10019 vals->bmac_val[1] = wb_data[1];
Yuval Mintz452427b2012-03-26 20:47:07 +000010020 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010021 REG_WR(bp, vals->bmac_addr, wb_data[0]);
10022 REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
Yuval Mintz452427b2012-03-26 20:47:07 +000010023 }
10024 BNX2X_DEV_INFO("Disable emac Rx\n");
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010025 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
10026 vals->emac_val = REG_RD(bp, vals->emac_addr);
10027 REG_WR(bp, vals->emac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010028 mac_stopped = true;
10029 } else {
10030 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
10031 BNX2X_DEV_INFO("Disable xmac Rx\n");
10032 base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
10033 val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
10034 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
10035 val & ~(1 << 1));
10036 REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
10037 val | (1 << 1));
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010038 vals->xmac_addr = base_addr + XMAC_REG_CTRL;
10039 vals->xmac_val = REG_RD(bp, vals->xmac_addr);
10040 REG_WR(bp, vals->xmac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010041 mac_stopped = true;
10042 }
10043 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
10044 if (mask & reset_reg) {
10045 BNX2X_DEV_INFO("Disable umac Rx\n");
10046 base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010047 vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
10048 vals->umac_val = REG_RD(bp, vals->umac_addr);
10049 REG_WR(bp, vals->umac_addr, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010050 mac_stopped = true;
David S. Miller8decf862011-09-22 03:23:13 -040010051 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010052 }
Ariel Eliorf16da432012-01-26 06:01:50 +000010053
Yuval Mintz452427b2012-03-26 20:47:07 +000010054 if (mac_stopped)
10055 msleep(20);
Yuval Mintz452427b2012-03-26 20:47:07 +000010056}
10057
10058#define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
10059#define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
10060#define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
10061#define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
10062
Yuval Mintz91ebb922013-12-26 09:57:07 +020010063#define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
10064#define BCM_5710_UNDI_FW_MF_MINOR (0x08)
10065#define BCM_5710_UNDI_FW_MF_VERS (0x05)
Yuval Mintzde682942014-05-08 12:34:31 +030010066#define BNX2X_PREV_UNDI_MF_PORT(p) (BAR_TSTRORM_INTMEM + 0x150c + ((p) << 4))
10067#define BNX2X_PREV_UNDI_MF_FUNC(f) (BAR_TSTRORM_INTMEM + 0x184c + ((f) << 4))
Yuval Mintzb17b0ca2014-06-12 07:55:31 +030010068
10069static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
10070{
10071 /* UNDI marks its presence in DORQ -
10072 * it initializes CID offset for normal bell to 0x7
10073 */
10074 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
10075 MISC_REGISTERS_RESET_REG_1_RST_DORQ))
10076 return false;
10077
10078 if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
10079 BNX2X_DEV_INFO("UNDI previously loaded\n");
10080 return true;
10081 }
10082
10083 return false;
10084}
10085
Yuval Mintz91ebb922013-12-26 09:57:07 +020010086static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
10087{
10088 u8 major, minor, version;
10089 u32 fw;
10090
10091 /* Must check that FW is loaded */
10092 if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
10093 MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
10094 BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
10095 return false;
10096 }
10097
10098 /* Read Currently loaded FW version */
10099 fw = REG_RD(bp, XSEM_REG_PRAM);
10100 major = fw & 0xff;
10101 minor = (fw >> 0x8) & 0xff;
10102 version = (fw >> 0x10) & 0xff;
10103 BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
10104 fw, major, minor, version);
10105
10106 if (major > BCM_5710_UNDI_FW_MF_MAJOR)
10107 return true;
10108
10109 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
10110 (minor > BCM_5710_UNDI_FW_MF_MINOR))
10111 return true;
10112
10113 if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
10114 (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
10115 (version >= BCM_5710_UNDI_FW_MF_VERS))
10116 return true;
10117
10118 return false;
10119}
10120
10121static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
10122{
10123 int i;
10124
10125 /* Due to legacy (FW) code, the first function on each engine has a
10126 * different offset macro from the rest of the functions.
10127 * Setting this for all 8 functions is harmless regardless of whether
10128 * this is actually a multi-function device.
10129 */
10130 for (i = 0; i < 2; i++)
10131 REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
10132
10133 for (i = 2; i < 8; i++)
10134 REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
10135
10136 BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
10137}
10138
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010139static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
Yuval Mintz452427b2012-03-26 20:47:07 +000010140{
10141 u16 rcq, bd;
10142 u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
10143
10144 rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
10145 bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
10146
10147 tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
10148 REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
10149
10150 BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
10151 port, bd, rcq);
10152}
10153
Bill Pemberton0329aba2012-12-03 09:24:24 -050010154static int bnx2x_prev_mcp_done(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010155{
Yuval Mintz5d07d862012-09-13 02:56:21 +000010156 u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
10157 DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
Yuval Mintz452427b2012-03-26 20:47:07 +000010158 if (!rc) {
10159 BNX2X_ERR("MCP response failure, aborting\n");
10160 return -EBUSY;
10161 }
10162
10163 return 0;
10164}
10165
Barak Witkowskic63da992012-12-05 23:04:03 +000010166static struct bnx2x_prev_path_list *
10167 bnx2x_prev_path_get_entry(struct bnx2x *bp)
10168{
10169 struct bnx2x_prev_path_list *tmp_list;
10170
10171 list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
10172 if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
10173 bp->pdev->bus->number == tmp_list->bus &&
10174 BP_PATH(bp) == tmp_list->path)
10175 return tmp_list;
10176
10177 return NULL;
10178}
10179
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010180static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
10181{
10182 struct bnx2x_prev_path_list *tmp_list;
10183 int rc;
10184
10185 rc = down_interruptible(&bnx2x_prev_sem);
10186 if (rc) {
10187 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10188 return rc;
10189 }
10190
10191 tmp_list = bnx2x_prev_path_get_entry(bp);
10192 if (tmp_list) {
10193 tmp_list->aer = 1;
10194 rc = 0;
10195 } else {
10196 BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
10197 BP_PATH(bp));
10198 }
10199
10200 up(&bnx2x_prev_sem);
10201
10202 return rc;
10203}
10204
Bill Pemberton0329aba2012-12-03 09:24:24 -050010205static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010206{
10207 struct bnx2x_prev_path_list *tmp_list;
Peter Senna Tschudinb85d7172013-10-02 14:19:49 +020010208 bool rc = false;
Yuval Mintz452427b2012-03-26 20:47:07 +000010209
10210 if (down_trylock(&bnx2x_prev_sem))
10211 return false;
10212
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010213 tmp_list = bnx2x_prev_path_get_entry(bp);
10214 if (tmp_list) {
10215 if (tmp_list->aer) {
10216 DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
10217 BP_PATH(bp));
10218 } else {
Yuval Mintz452427b2012-03-26 20:47:07 +000010219 rc = true;
10220 BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
10221 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +000010222 }
10223 }
10224
10225 up(&bnx2x_prev_sem);
10226
10227 return rc;
10228}
10229
Dmitry Kravkov178135c2013-05-22 21:21:50 +000010230bool bnx2x_port_after_undi(struct bnx2x *bp)
10231{
10232 struct bnx2x_prev_path_list *entry;
10233 bool val;
10234
10235 down(&bnx2x_prev_sem);
10236
10237 entry = bnx2x_prev_path_get_entry(bp);
10238 val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
10239
10240 up(&bnx2x_prev_sem);
10241
10242 return val;
10243}
10244
Barak Witkowskic63da992012-12-05 23:04:03 +000010245static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
Yuval Mintz452427b2012-03-26 20:47:07 +000010246{
10247 struct bnx2x_prev_path_list *tmp_list;
10248 int rc;
10249
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010250 rc = down_interruptible(&bnx2x_prev_sem);
10251 if (rc) {
10252 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10253 return rc;
10254 }
10255
10256 /* Check whether the entry for this path already exists */
10257 tmp_list = bnx2x_prev_path_get_entry(bp);
10258 if (tmp_list) {
10259 if (!tmp_list->aer) {
10260 BNX2X_ERR("Re-Marking the path.\n");
10261 } else {
10262 DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
10263 BP_PATH(bp));
10264 tmp_list->aer = 0;
10265 }
10266 up(&bnx2x_prev_sem);
10267 return 0;
10268 }
10269 up(&bnx2x_prev_sem);
10270
10271 /* Create an entry for this path and add it */
Devendra Nagaea4b3852012-07-29 03:19:23 +000010272 tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
Yuval Mintz452427b2012-03-26 20:47:07 +000010273 if (!tmp_list) {
10274 BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
10275 return -ENOMEM;
10276 }
10277
10278 tmp_list->bus = bp->pdev->bus->number;
10279 tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
10280 tmp_list->path = BP_PATH(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010281 tmp_list->aer = 0;
Barak Witkowskic63da992012-12-05 23:04:03 +000010282 tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
Yuval Mintz452427b2012-03-26 20:47:07 +000010283
10284 rc = down_interruptible(&bnx2x_prev_sem);
10285 if (rc) {
10286 BNX2X_ERR("Received %d when tried to take lock\n", rc);
10287 kfree(tmp_list);
10288 } else {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010289 DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
10290 BP_PATH(bp));
Yuval Mintz452427b2012-03-26 20:47:07 +000010291 list_add(&tmp_list->list, &bnx2x_prev_list);
10292 up(&bnx2x_prev_sem);
10293 }
10294
10295 return rc;
10296}
10297
Bill Pemberton0329aba2012-12-03 09:24:24 -050010298static int bnx2x_do_flr(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010299{
Yuval Mintz452427b2012-03-26 20:47:07 +000010300 struct pci_dev *dev = bp->pdev;
10301
Yuval Mintz8eee6942012-08-09 04:37:25 +000010302 if (CHIP_IS_E1x(bp)) {
10303 BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
10304 return -EINVAL;
10305 }
10306
10307 /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
10308 if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
10309 BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
10310 bp->common.bc_ver);
10311 return -EINVAL;
10312 }
Yuval Mintz452427b2012-03-26 20:47:07 +000010313
Casey Leedom8903b9e2013-08-06 15:48:38 +053010314 if (!pci_wait_for_pending_transaction(dev))
10315 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010316
Yuval Mintz8eee6942012-08-09 04:37:25 +000010317 BNX2X_DEV_INFO("Initiating FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010318 bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
10319
10320 return 0;
10321}
10322
Bill Pemberton0329aba2012-12-03 09:24:24 -050010323static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010324{
10325 int rc;
10326
10327 BNX2X_DEV_INFO("Uncommon unload Flow\n");
10328
10329 /* Test if previous unload process was already finished for this path */
10330 if (bnx2x_prev_is_path_marked(bp))
10331 return bnx2x_prev_mcp_done(bp);
10332
Yuval Mintz04c46732013-01-23 03:21:46 +000010333 BNX2X_DEV_INFO("Path is unmarked\n");
10334
Yuval Mintzb17b0ca2014-06-12 07:55:31 +030010335 /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
10336 if (bnx2x_prev_is_after_undi(bp))
10337 goto out;
10338
Yuval Mintz452427b2012-03-26 20:47:07 +000010339 /* If function has FLR capabilities, and existing FW version matches
10340 * the one required, then FLR will be sufficient to clean any residue
10341 * left by previous driver
10342 */
Yuval Mintz91ebb922013-12-26 09:57:07 +020010343 rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
Yuval Mintz8eee6942012-08-09 04:37:25 +000010344
10345 if (!rc) {
10346 /* fw version is good */
10347 BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
10348 rc = bnx2x_do_flr(bp);
10349 }
10350
10351 if (!rc) {
10352 /* FLR was performed */
10353 BNX2X_DEV_INFO("FLR successful\n");
10354 return 0;
10355 }
10356
10357 BNX2X_DEV_INFO("Could not FLR\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010358
Yuval Mintzb17b0ca2014-06-12 07:55:31 +030010359out:
Yuval Mintz452427b2012-03-26 20:47:07 +000010360 /* Close the MCP request, return failure*/
10361 rc = bnx2x_prev_mcp_done(bp);
10362 if (!rc)
10363 rc = BNX2X_PREV_WAIT_NEEDED;
10364
10365 return rc;
10366}
10367
Bill Pemberton0329aba2012-12-03 09:24:24 -050010368static int bnx2x_prev_unload_common(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010369{
10370 u32 reset_reg, tmp_reg = 0, rc;
Barak Witkowskic63da992012-12-05 23:04:03 +000010371 bool prev_undi = false;
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010372 struct bnx2x_mac_vals mac_vals;
10373
Yuval Mintz452427b2012-03-26 20:47:07 +000010374 /* It is possible a previous function received 'common' answer,
10375 * but hasn't loaded yet, therefore creating a scenario of
10376 * multiple functions receiving 'common' on the same path.
10377 */
10378 BNX2X_DEV_INFO("Common unload Flow\n");
10379
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010380 memset(&mac_vals, 0, sizeof(mac_vals));
10381
Yuval Mintz452427b2012-03-26 20:47:07 +000010382 if (bnx2x_prev_is_path_marked(bp))
10383 return bnx2x_prev_mcp_done(bp);
10384
10385 reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
10386
10387 /* Reset should be performed after BRB is emptied */
10388 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
10389 u32 timer_count = 1000;
Yuval Mintzde682942014-05-08 12:34:31 +030010390 bool need_write = true;
Yuval Mintz452427b2012-03-26 20:47:07 +000010391
10392 /* Close the MAC Rx to prevent BRB from filling up */
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010393 bnx2x_prev_unload_close_mac(bp, &mac_vals);
10394
10395 /* close LLH filters towards the BRB */
10396 bnx2x_set_rx_filter(&bp->link_params, 0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010397
Yuval Mintzb17b0ca2014-06-12 07:55:31 +030010398 /* Check if the UNDI driver was previously loaded */
10399 if (bnx2x_prev_is_after_undi(bp)) {
10400 prev_undi = true;
10401 /* clear the UNDI indication */
10402 REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
10403 /* clear possible idle check errors */
10404 REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
Yuval Mintz452427b2012-03-26 20:47:07 +000010405 }
Dmitry Kravkovd46f7c42013-04-17 22:49:05 +000010406 if (!CHIP_IS_E1x(bp))
10407 /* block FW from writing to host */
10408 REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
10409
Yuval Mintz452427b2012-03-26 20:47:07 +000010410 /* wait until BRB is empty */
10411 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10412 while (timer_count) {
10413 u32 prev_brb = tmp_reg;
10414
10415 tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
10416 if (!tmp_reg)
10417 break;
10418
10419 BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
10420
10421 /* reset timer as long as BRB actually gets emptied */
10422 if (prev_brb > tmp_reg)
10423 timer_count = 1000;
10424 else
10425 timer_count--;
10426
Yuval Mintz91ebb922013-12-26 09:57:07 +020010427 /* New UNDI FW supports MF and contains better
10428 * cleaning methods - might be redundant but harmless.
10429 */
10430 if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
Yuval Mintzde682942014-05-08 12:34:31 +030010431 if (need_write) {
10432 bnx2x_prev_unload_undi_mf(bp);
10433 need_write = false;
10434 }
Yuval Mintz91ebb922013-12-26 09:57:07 +020010435 } else if (prev_undi) {
10436 /* If UNDI resides in memory,
10437 * manually increment it
10438 */
Yuval Mintz452427b2012-03-26 20:47:07 +000010439 bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
Yuval Mintz91ebb922013-12-26 09:57:07 +020010440 }
Yuval Mintz452427b2012-03-26 20:47:07 +000010441 udelay(10);
10442 }
10443
10444 if (!timer_count)
10445 BNX2X_ERR("Failed to empty BRB, hope for the best\n");
Yuval Mintz452427b2012-03-26 20:47:07 +000010446 }
10447
10448 /* No packets are in the pipeline, path is ready for reset */
10449 bnx2x_reset_common(bp);
10450
Barak Witkowski1ef1d452013-01-10 04:53:40 +000010451 if (mac_vals.xmac_addr)
10452 REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
10453 if (mac_vals.umac_addr)
10454 REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
10455 if (mac_vals.emac_addr)
10456 REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
10457 if (mac_vals.bmac_addr) {
10458 REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
10459 REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
10460 }
10461
Barak Witkowskic63da992012-12-05 23:04:03 +000010462 rc = bnx2x_prev_mark_path(bp, prev_undi);
Yuval Mintz452427b2012-03-26 20:47:07 +000010463 if (rc) {
10464 bnx2x_prev_mcp_done(bp);
10465 return rc;
10466 }
10467
10468 return bnx2x_prev_mcp_done(bp);
10469}
10470
Ariel Elior24f06712012-05-06 07:05:57 +000010471/* previous driver DMAE transaction may have occurred when pre-boot stage ended
10472 * and boot began, or when kdump kernel was loaded. Either case would invalidate
10473 * the addresses of the transaction, resulting in was-error bit set in the pci
10474 * causing all hw-to-host pcie transactions to timeout. If this happened we want
10475 * to clear the interrupt which detected this from the pglueb and the was done
10476 * bit
10477 */
Bill Pemberton0329aba2012-12-03 09:24:24 -050010478static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
Ariel Elior24f06712012-05-06 07:05:57 +000010479{
Ariel Elior4a254172012-11-22 07:16:17 +000010480 if (!CHIP_IS_E1x(bp)) {
10481 u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
10482 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
Yuval Mintz04c46732013-01-23 03:21:46 +000010483 DP(BNX2X_MSG_SP,
10484 "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
Ariel Elior4a254172012-11-22 07:16:17 +000010485 REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
10486 1 << BP_FUNC(bp));
10487 }
Ariel Elior24f06712012-05-06 07:05:57 +000010488 }
10489}
10490
Bill Pemberton0329aba2012-12-03 09:24:24 -050010491static int bnx2x_prev_unload(struct bnx2x *bp)
Yuval Mintz452427b2012-03-26 20:47:07 +000010492{
10493 int time_counter = 10;
10494 u32 rc, fw, hw_lock_reg, hw_lock_val;
10495 BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
10496
Ariel Elior24f06712012-05-06 07:05:57 +000010497 /* clear hw from errors which may have resulted from an interrupted
10498 * dmae transaction.
10499 */
10500 bnx2x_prev_interrupted_dmae(bp);
10501
10502 /* Release previously held locks */
Yuval Mintz452427b2012-03-26 20:47:07 +000010503 hw_lock_reg = (BP_FUNC(bp) <= 5) ?
10504 (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
10505 (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
10506
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010507 hw_lock_val = REG_RD(bp, hw_lock_reg);
Yuval Mintz452427b2012-03-26 20:47:07 +000010508 if (hw_lock_val) {
10509 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
10510 BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
10511 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
10512 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
10513 }
10514
10515 BNX2X_DEV_INFO("Release Previously held hw lock\n");
10516 REG_WR(bp, hw_lock_reg, 0xffffffff);
10517 } else
10518 BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
10519
10520 if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
10521 BNX2X_DEV_INFO("Release previously held alr\n");
Yuval Mintz3cdeec22013-06-02 00:06:19 +000010522 bnx2x_release_alr(bp);
Yuval Mintz452427b2012-03-26 20:47:07 +000010523 }
10524
Yuval Mintz452427b2012-03-26 20:47:07 +000010525 do {
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010526 int aer = 0;
Yuval Mintz452427b2012-03-26 20:47:07 +000010527 /* Lock MCP using an unload request */
10528 fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
10529 if (!fw) {
10530 BNX2X_ERR("MCP response failure, aborting\n");
10531 rc = -EBUSY;
10532 break;
10533 }
10534
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010535 rc = down_interruptible(&bnx2x_prev_sem);
10536 if (rc) {
10537 BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
10538 rc);
10539 } else {
10540 /* If Path is marked by EEH, ignore unload status */
10541 aer = !!(bnx2x_prev_path_get_entry(bp) &&
10542 bnx2x_prev_path_get_entry(bp)->aer);
Yuval Mintz60cde812013-03-26 23:28:03 +000010543 up(&bnx2x_prev_sem);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010544 }
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000010545
10546 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
Yuval Mintz452427b2012-03-26 20:47:07 +000010547 rc = bnx2x_prev_unload_common(bp);
10548 break;
10549 }
10550
Yuval Mintz16a5fd92013-06-02 00:06:18 +000010551 /* non-common reply from MCP might require looping */
Yuval Mintz452427b2012-03-26 20:47:07 +000010552 rc = bnx2x_prev_unload_uncommon(bp);
10553 if (rc != BNX2X_PREV_WAIT_NEEDED)
10554 break;
10555
10556 msleep(20);
10557 } while (--time_counter);
10558
10559 if (!time_counter || rc) {
Yuval Mintz91ebb922013-12-26 09:57:07 +020010560 BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
10561 rc = -EPROBE_DEFER;
Yuval Mintz452427b2012-03-26 20:47:07 +000010562 }
10563
Barak Witkowskic63da992012-12-05 23:04:03 +000010564 /* Mark function if its port was used to boot from SAN */
Dmitry Kravkov178135c2013-05-22 21:21:50 +000010565 if (bnx2x_port_after_undi(bp))
Barak Witkowskic63da992012-12-05 23:04:03 +000010566 bp->link_params.feature_config_flags |=
10567 FEATURE_CONFIG_BOOT_FROM_SAN;
10568
Yuval Mintz452427b2012-03-26 20:47:07 +000010569 BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
10570
10571 return rc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010572}
10573
Bill Pemberton0329aba2012-12-03 09:24:24 -050010574static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010575{
Barak Witkowski1d187b32011-12-05 22:41:50 +000010576 u32 val, val2, val3, val4, id, boot_mode;
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010577 u16 pmc;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010578
10579 /* Get the chip revision id and number. */
10580 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
10581 val = REG_RD(bp, MISC_REG_CHIP_NUM);
10582 id = ((val & 0xffff) << 16);
10583 val = REG_RD(bp, MISC_REG_CHIP_REV);
10584 id |= ((val & 0xf) << 12);
Yuval Mintzf22fdf22013-03-11 05:17:43 +000010585
10586 /* Metal is read from PCI regs, but we can't access >=0x400 from
10587 * the configuration space (so we need to reg_rd)
10588 */
10589 val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
10590 id |= (((val >> 24) & 0xf) << 4);
Eilon Greenstein5a40e082009-01-14 06:44:04 +000010591 val = REG_RD(bp, MISC_REG_BOND_ID);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010592 id |= (val & 0xf);
10593 bp->common.chip_id = id;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010594
Barak Witkowski7e8e02d2012-04-03 18:41:28 +000010595 /* force 57811 according to MISC register */
10596 if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
10597 if (CHIP_IS_57810(bp))
10598 bp->common.chip_id = (CHIP_NUM_57811 << 16) |
10599 (bp->common.chip_id & 0x0000FFFF);
10600 else if (CHIP_IS_57810_MF(bp))
10601 bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
10602 (bp->common.chip_id & 0x0000FFFF);
10603 bp->common.chip_id |= 0x1;
10604 }
10605
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010606 /* Set doorbell size */
10607 bp->db_size = (1 << BNX2X_DB_SHIFT);
10608
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010609 if (!CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010610 val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
10611 if ((val & 1) == 0)
10612 val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
10613 else
10614 val = (val >> 1) & 1;
10615 BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
10616 "2_PORT_MODE");
10617 bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
10618 CHIP_2_PORT_MODE;
10619
10620 if (CHIP_MODE_IS_4_PORT(bp))
10621 bp->pfid = (bp->pf_num >> 1); /* 0..3 */
10622 else
10623 bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
10624 } else {
10625 bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
10626 bp->pfid = bp->pf_num; /* 0..7 */
10627 }
10628
Merav Sicron51c1a582012-03-18 10:33:38 +000010629 BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
10630
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010631 bp->link_params.chip_id = bp->common.chip_id;
10632 BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000010633
Eilon Greenstein1c063282009-02-12 08:36:43 +000010634 val = (REG_RD(bp, 0x2874) & 0x55);
10635 if ((bp->common.chip_id & 0x1) ||
10636 (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
10637 bp->flags |= ONE_PORT_FLAG;
10638 BNX2X_DEV_INFO("single port device\n");
10639 }
10640
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010641 val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000010642 bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010643 (val & MCPR_NVM_CFG4_FLASH_SIZE));
10644 BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
10645 bp->common.flash_size, bp->common.flash_size);
10646
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010647 bnx2x_init_shmem(bp);
10648
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010649 bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
10650 MISC_REG_GENERIC_CR_1 :
10651 MISC_REG_GENERIC_CR_0));
Dmitry Kravkov1b6e2ce2011-05-22 10:11:26 +000010652
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010653 bp->link_params.shmem_base = bp->common.shmem_base;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010654 bp->link_params.shmem2_base = bp->common.shmem2_base;
Yaniv Rosnerb884d952012-11-27 03:46:28 +000010655 if (SHMEM2_RD(bp, size) >
10656 (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
10657 bp->link_params.lfa_base =
10658 REG_RD(bp, bp->common.shmem2_base +
10659 (u32)offsetof(struct shmem2_region,
10660 lfa_host_addr[BP_PORT(bp)]));
10661 else
10662 bp->link_params.lfa_base = 0;
Eilon Greenstein2691d512009-08-12 08:22:08 +000010663 BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
10664 bp->common.shmem_base, bp->common.shmem2_base);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010665
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010666 if (!bp->common.shmem_base) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010667 BNX2X_DEV_INFO("MCP not active\n");
10668 bp->flags |= NO_MCP_FLAG;
10669 return;
10670 }
10671
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010672 bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
Eilon Greenstein35b19ba2009-02-12 08:36:47 +000010673 BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010674
10675 bp->link_params.hw_led_mode = ((bp->common.hw_config &
10676 SHARED_HW_CFG_LED_MODE_MASK) >>
10677 SHARED_HW_CFG_LED_MODE_SHIFT);
10678
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000010679 bp->link_params.feature_config_flags = 0;
10680 val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
10681 if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
10682 bp->link_params.feature_config_flags |=
10683 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10684 else
10685 bp->link_params.feature_config_flags &=
10686 ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
10687
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010688 val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
10689 bp->common.bc_ver = val;
10690 BNX2X_DEV_INFO("bc_ver %X\n", val);
10691 if (val < BNX2X_BC_VER) {
10692 /* for now only warn
10693 * later we might need to enforce this */
Merav Sicron51c1a582012-03-18 10:33:38 +000010694 BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
10695 BNX2X_BC_VER, val);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010696 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010697 bp->link_params.feature_config_flags |=
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010698 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010699 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
10700
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010701 bp->link_params.feature_config_flags |=
10702 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
10703 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
Barak Witkowskia3348722012-04-23 03:04:46 +000010704 bp->link_params.feature_config_flags |=
10705 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
10706 FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010707 bp->link_params.feature_config_flags |=
10708 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
10709 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
Yaniv Rosner55386fe82012-11-27 03:46:30 +000010710
10711 bp->link_params.feature_config_flags |=
10712 (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
10713 FEATURE_CONFIG_MT_SUPPORT : 0;
10714
Barak Witkowski0e898dd2011-12-05 21:52:22 +000010715 bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
10716 BC_SUPPORTS_PFC_STATS : 0;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000010717
Barak Witkowski2e499d32012-06-26 01:31:19 +000010718 bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
10719 BC_SUPPORTS_FCOE_FEATURES : 0;
10720
Barak Witkowski98768792012-06-19 07:48:31 +000010721 bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
10722 BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030010723
10724 bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
10725 BC_SUPPORTS_RMMOD_CMD : 0;
10726
Barak Witkowski1d187b32011-12-05 22:41:50 +000010727 boot_mode = SHMEM_RD(bp,
10728 dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
10729 PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
10730 switch (boot_mode) {
10731 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
10732 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
10733 break;
10734 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
10735 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
10736 break;
10737 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
10738 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
10739 break;
10740 case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
10741 bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
10742 break;
10743 }
10744
Jon Mason29ed74c2013-09-11 11:22:39 -070010745 pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
Dmitry Kravkovf9a3ebb2011-05-04 23:49:11 +000010746 bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
10747
Eilon Greenstein72ce58c2008-08-13 15:52:46 -070010748 BNX2X_DEV_INFO("%sWoL capable\n",
Eilon Greensteinf5372252009-02-12 08:38:30 +000010749 (bp->flags & NO_WOL_FLAG) ? "not " : "");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010750
10751 val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
10752 val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
10753 val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
10754 val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
10755
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000010756 dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
10757 val, val2, val3, val4);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010758}
10759
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010760#define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
10761#define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
10762
Bill Pemberton0329aba2012-12-03 09:24:24 -050010763static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010764{
10765 int pfid = BP_FUNC(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010766 int igu_sb_id;
10767 u32 val;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010768 u8 fid, igu_sb_cnt = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010769
10770 bp->igu_base_sb = 0xff;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010771 if (CHIP_INT_MODE_IS_BC(bp)) {
David S. Miller8decf862011-09-22 03:23:13 -040010772 int vn = BP_VN(bp);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010773 igu_sb_cnt = bp->igu_sb_cnt;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010774 bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
10775 FP_SB_MAX_E1x;
10776
10777 bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
10778 (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
10779
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010780 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010781 }
10782
10783 /* IGU in normal mode - read CAM */
10784 for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
10785 igu_sb_id++) {
10786 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
10787 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
10788 continue;
10789 fid = IGU_FID(val);
10790 if ((fid & IGU_FID_ENCODE_IS_PF)) {
10791 if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
10792 continue;
10793 if (IGU_VEC(val) == 0)
10794 /* default status block */
10795 bp->igu_dsb_id = igu_sb_id;
10796 else {
10797 if (bp->igu_base_sb == 0xff)
10798 bp->igu_base_sb = igu_sb_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +000010799 igu_sb_cnt++;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010800 }
10801 }
10802 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010803
Ariel Elior6383c0b2011-07-14 08:31:57 +000010804#ifdef CONFIG_PCI_MSI
Ariel Elior185d4c82012-09-20 05:26:41 +000010805 /* Due to new PF resource allocation by MFW T7.4 and above, it's
10806 * optional that number of CAM entries will not be equal to the value
10807 * advertised in PCI.
10808 * Driver should use the minimal value of both as the actual status
10809 * block count
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010810 */
Ariel Elior185d4c82012-09-20 05:26:41 +000010811 bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
Ariel Elior6383c0b2011-07-14 08:31:57 +000010812#endif
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010813
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010814 if (igu_sb_cnt == 0) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010815 BNX2X_ERR("CAM configuration error\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000010816 return -EINVAL;
10817 }
10818
10819 return 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010820}
10821
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010822static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070010823{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010824 int cfg_size = 0, idx, port = BP_PORT(bp);
10825
10826 /* Aggregation of supported attributes of all external phys */
10827 bp->port.supported[0] = 0;
10828 bp->port.supported[1] = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010829 switch (bp->link_params.num_phys) {
10830 case 1:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010831 bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
10832 cfg_size = 1;
10833 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010834 case 2:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010835 bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
10836 cfg_size = 1;
10837 break;
10838 case 3:
10839 if (bp->link_params.multi_phy_config &
10840 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
10841 bp->port.supported[1] =
10842 bp->link_params.phy[EXT_PHY1].supported;
10843 bp->port.supported[0] =
10844 bp->link_params.phy[EXT_PHY2].supported;
10845 } else {
10846 bp->port.supported[0] =
10847 bp->link_params.phy[EXT_PHY1].supported;
10848 bp->port.supported[1] =
10849 bp->link_params.phy[EXT_PHY2].supported;
10850 }
10851 cfg_size = 2;
10852 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010853 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010854
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010855 if (!(bp->port.supported[0] || bp->port.supported[1])) {
Merav Sicron51c1a582012-03-18 10:33:38 +000010856 BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010857 SHMEM_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010858 dev_info.port_hw_config[port].external_phy_config),
10859 SHMEM_RD(bp,
10860 dev_info.port_hw_config[port].external_phy_config2));
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010861 return;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010862 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010863
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010864 if (CHIP_IS_E3(bp))
10865 bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
10866 else {
10867 switch (switch_cfg) {
10868 case SWITCH_CFG_1G:
10869 bp->port.phy_addr = REG_RD(
10870 bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
10871 break;
10872 case SWITCH_CFG_10G:
10873 bp->port.phy_addr = REG_RD(
10874 bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
10875 break;
10876 default:
10877 BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
10878 bp->port.link_config[0]);
10879 return;
10880 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010881 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030010882 BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010883 /* mask what we support according to speed_cap_mask per configuration */
10884 for (idx = 0; idx < cfg_size; idx++) {
10885 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010886 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010887 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010888
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010889 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010890 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010891 bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010892
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010893 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010894 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010895 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010896
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010897 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010898 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010899 bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010900
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010901 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010902 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010903 bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010904 SUPPORTED_1000baseT_Full);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010905
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010906 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010907 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010908 bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010909
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010910 if (!(bp->link_params.speed_cap_mask[idx] &
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070010911 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010912 bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
Yaniv Rosnerb8e0d882013-06-20 17:39:11 +030010913
10914 if (!(bp->link_params.speed_cap_mask[idx] &
10915 PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
10916 bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010917 }
10918
10919 BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
10920 bp->port.supported[1]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010921}
10922
Bill Pemberton0329aba2012-12-03 09:24:24 -050010923static void bnx2x_link_settings_requested(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010924{
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010925 u32 link_config, idx, cfg_size = 0;
10926 bp->port.advertising[0] = 0;
10927 bp->port.advertising[1] = 0;
10928 switch (bp->link_params.num_phys) {
10929 case 1:
10930 case 2:
10931 cfg_size = 1;
10932 break;
10933 case 3:
10934 cfg_size = 2;
10935 break;
10936 }
10937 for (idx = 0; idx < cfg_size; idx++) {
10938 bp->link_params.req_duplex[idx] = DUPLEX_FULL;
10939 link_config = bp->port.link_config[idx];
10940 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010941 case PORT_FEATURE_LINK_SPEED_AUTO:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010942 if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
10943 bp->link_params.req_line_speed[idx] =
10944 SPEED_AUTO_NEG;
10945 bp->port.advertising[idx] |=
10946 bp->port.supported[idx];
Mintz Yuval10bd1f22012-02-15 02:10:30 +000010947 if (bp->link_params.phy[EXT_PHY1].type ==
10948 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10949 bp->port.advertising[idx] |=
10950 (SUPPORTED_100baseT_Half |
10951 SUPPORTED_100baseT_Full);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010952 } else {
10953 /* force 10G, no AN */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010954 bp->link_params.req_line_speed[idx] =
10955 SPEED_10000;
10956 bp->port.advertising[idx] |=
10957 (ADVERTISED_10000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010958 ADVERTISED_FIBRE);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010959 continue;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010960 }
10961 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010962
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010963 case PORT_FEATURE_LINK_SPEED_10M_FULL:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010964 if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
10965 bp->link_params.req_line_speed[idx] =
10966 SPEED_10;
10967 bp->port.advertising[idx] |=
10968 (ADVERTISED_10baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010969 ADVERTISED_TP);
10970 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010971 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010972 link_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010973 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010974 return;
10975 }
10976 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010977
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010978 case PORT_FEATURE_LINK_SPEED_10M_HALF:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010979 if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
10980 bp->link_params.req_line_speed[idx] =
10981 SPEED_10;
10982 bp->link_params.req_duplex[idx] =
10983 DUPLEX_HALF;
10984 bp->port.advertising[idx] |=
10985 (ADVERTISED_10baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010986 ADVERTISED_TP);
10987 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000010988 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010989 link_config,
10990 bp->link_params.speed_cap_mask[idx]);
10991 return;
10992 }
10993 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020010994
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000010995 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10996 if (bp->port.supported[idx] &
10997 SUPPORTED_100baseT_Full) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010998 bp->link_params.req_line_speed[idx] =
10999 SPEED_100;
11000 bp->port.advertising[idx] |=
11001 (ADVERTISED_100baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011002 ADVERTISED_TP);
11003 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000011004 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011005 link_config,
11006 bp->link_params.speed_cap_mask[idx]);
11007 return;
11008 }
11009 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011010
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011011 case PORT_FEATURE_LINK_SPEED_100M_HALF:
11012 if (bp->port.supported[idx] &
11013 SUPPORTED_100baseT_Half) {
11014 bp->link_params.req_line_speed[idx] =
11015 SPEED_100;
11016 bp->link_params.req_duplex[idx] =
11017 DUPLEX_HALF;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011018 bp->port.advertising[idx] |=
11019 (ADVERTISED_100baseT_Half |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011020 ADVERTISED_TP);
11021 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000011022 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011023 link_config,
11024 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011025 return;
11026 }
11027 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011028
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011029 case PORT_FEATURE_LINK_SPEED_1G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011030 if (bp->port.supported[idx] &
11031 SUPPORTED_1000baseT_Full) {
11032 bp->link_params.req_line_speed[idx] =
11033 SPEED_1000;
11034 bp->port.advertising[idx] |=
11035 (ADVERTISED_1000baseT_Full |
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011036 ADVERTISED_TP);
11037 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000011038 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011039 link_config,
11040 bp->link_params.speed_cap_mask[idx]);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011041 return;
11042 }
11043 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011044
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011045 case PORT_FEATURE_LINK_SPEED_2_5G:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011046 if (bp->port.supported[idx] &
11047 SUPPORTED_2500baseX_Full) {
11048 bp->link_params.req_line_speed[idx] =
11049 SPEED_2500;
11050 bp->port.advertising[idx] |=
11051 (ADVERTISED_2500baseX_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011052 ADVERTISED_TP);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011053 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000011054 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011055 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011056 bp->link_params.speed_cap_mask[idx]);
11057 return;
11058 }
11059 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011060
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011061 case PORT_FEATURE_LINK_SPEED_10G_CX4:
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011062 if (bp->port.supported[idx] &
11063 SUPPORTED_10000baseT_Full) {
11064 bp->link_params.req_line_speed[idx] =
11065 SPEED_10000;
11066 bp->port.advertising[idx] |=
11067 (ADVERTISED_10000baseT_Full |
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011068 ADVERTISED_FIBRE);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011069 } else {
Merav Sicron51c1a582012-03-18 10:33:38 +000011070 BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011071 link_config,
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011072 bp->link_params.speed_cap_mask[idx]);
11073 return;
11074 }
11075 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011076 case PORT_FEATURE_LINK_SPEED_20G:
11077 bp->link_params.req_line_speed[idx] = SPEED_20000;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011078
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011079 break;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011080 default:
Merav Sicron51c1a582012-03-18 10:33:38 +000011081 BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000011082 link_config);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011083 bp->link_params.req_line_speed[idx] =
11084 SPEED_AUTO_NEG;
11085 bp->port.advertising[idx] =
11086 bp->port.supported[idx];
11087 break;
11088 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011089
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011090 bp->link_params.req_flow_ctrl[idx] = (link_config &
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011091 PORT_FEATURE_FLOW_CONTROL_MASK);
Yuval Mintzcd1dfce2012-12-02 04:05:56 +000011092 if (bp->link_params.req_flow_ctrl[idx] ==
11093 BNX2X_FLOW_CTRL_AUTO) {
11094 if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
11095 bp->link_params.req_flow_ctrl[idx] =
11096 BNX2X_FLOW_CTRL_NONE;
11097 else
11098 bnx2x_set_requested_fc(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011099 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011100
Merav Sicron51c1a582012-03-18 10:33:38 +000011101 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 +000011102 bp->link_params.req_line_speed[idx],
11103 bp->link_params.req_duplex[idx],
11104 bp->link_params.req_flow_ctrl[idx],
11105 bp->port.advertising[idx]);
11106 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011107}
11108
Bill Pemberton0329aba2012-12-03 09:24:24 -050011109static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
Michael Chane665bfd2009-10-10 13:46:54 +000011110{
Yuval Mintz86564c32013-01-23 03:21:50 +000011111 __be16 mac_hi_be = cpu_to_be16(mac_hi);
11112 __be32 mac_lo_be = cpu_to_be32(mac_lo);
11113 memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
11114 memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
Michael Chane665bfd2009-10-10 13:46:54 +000011115}
11116
Bill Pemberton0329aba2012-12-03 09:24:24 -050011117static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011118{
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011119 int port = BP_PORT(bp);
Eilon Greenstein589abe32009-02-12 08:36:55 +000011120 u32 config;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000011121 u32 ext_phy_type, ext_phy_config, eee_mode;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011122
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011123 bp->link_params.bp = bp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011124 bp->link_params.port = port;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011125
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011126 bp->link_params.lane_config =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011127 SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000011128
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011129 bp->link_params.speed_cap_mask[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011130 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000011131 dev_info.port_hw_config[port].speed_capability_mask) &
11132 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011133 bp->link_params.speed_cap_mask[1] =
11134 SHMEM_RD(bp,
Yaniv Rosnerb0261922013-05-01 04:27:57 +000011135 dev_info.port_hw_config[port].speed_capability_mask2) &
11136 PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011137 bp->port.link_config[0] =
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011138 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
11139
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011140 bp->port.link_config[1] =
11141 SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +000011142
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011143 bp->link_params.multi_phy_config =
11144 SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000011145 /* If the device is capable of WoL, set the default state according
11146 * to the HW
11147 */
Eilon Greenstein4d295db2009-07-21 05:47:47 +000011148 config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
Eilon Greenstein3ce2c3f2009-02-12 08:37:52 +000011149 bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
11150 (config & PORT_FEATURE_WOL_ENABLED));
11151
Yuval Mintz4ba76992013-01-14 05:11:45 +000011152 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
11153 PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
11154 bp->flags |= NO_ISCSI_FLAG;
11155 if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
11156 PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
11157 bp->flags |= NO_FCOE_FLAG;
11158
Merav Sicron51c1a582012-03-18 10:33:38 +000011159 BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011160 bp->link_params.lane_config,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011161 bp->link_params.speed_cap_mask[0],
11162 bp->port.link_config[0]);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011163
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011164 bp->link_params.switch_cfg = (bp->port.link_config[0] &
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000011165 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011166 bnx2x_phy_probe(&bp->link_params);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011167 bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011168
11169 bnx2x_link_settings_requested(bp);
11170
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011171 /*
11172 * If connected directly, work with the internal PHY, otherwise, work
11173 * with the external PHY
11174 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011175 ext_phy_config =
11176 SHMEM_RD(bp,
11177 dev_info.port_hw_config[port].external_phy_config);
11178 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011179 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011180 bp->mdio.prtad = bp->port.phy_addr;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011181
11182 else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
11183 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11184 bp->mdio.prtad =
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011185 XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner5866df62011-01-30 04:15:07 +000011186
Yuval Mintzc8c60d82012-06-06 17:13:07 +000011187 /* Configure link feature according to nvram value */
11188 eee_mode = (((SHMEM_RD(bp, dev_info.
11189 port_feature_config[port].eee_power_mode)) &
11190 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
11191 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
11192 if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
11193 bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
11194 EEE_MODE_ENABLE_LPI |
11195 EEE_MODE_OUTPUT_TIME;
11196 } else {
11197 bp->link_params.eee_mode = 0;
11198 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011199}
Eilon Greenstein01cd4522009-08-12 08:23:08 +000011200
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011201void bnx2x_get_iscsi_info(struct bnx2x *bp)
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011202{
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011203 u32 no_flags = NO_ISCSI_FLAG;
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011204 int port = BP_PORT(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011205 u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011206 drv_lic_key[port].max_iscsi_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011207
Merav Sicron55c11942012-11-07 00:45:48 +000011208 if (!CNIC_SUPPORT(bp)) {
11209 bp->flags |= no_flags;
11210 return;
11211 }
11212
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011213 /* Get the number of maximum allowed iSCSI connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011214 bp->cnic_eth_dev.max_iscsi_conn =
11215 (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
11216 BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
11217
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011218 BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
11219 bp->cnic_eth_dev.max_iscsi_conn);
11220
11221 /*
11222 * If maximum allowed number of connections is zero -
11223 * disable the feature.
11224 */
11225 if (!bp->cnic_eth_dev.max_iscsi_conn)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011226 bp->flags |= no_flags;
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011227}
11228
Bill Pemberton0329aba2012-12-03 09:24:24 -050011229static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011230{
11231 /* Port info */
11232 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11233 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
11234 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11235 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
11236
11237 /* Node info */
11238 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11239 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
11240 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11241 MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
11242}
Dmitry Kravkov86800192013-05-27 04:08:29 +000011243
11244static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
11245{
11246 u8 count = 0;
11247
11248 if (IS_MF(bp)) {
11249 u8 fid;
11250
11251 /* iterate over absolute function ids for this path: */
11252 for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
11253 if (IS_MF_SD(bp)) {
11254 u32 cfg = MF_CFG_RD(bp,
11255 func_mf_config[fid].config);
11256
11257 if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
11258 ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
11259 FUNC_MF_CFG_PROTOCOL_FCOE))
11260 count++;
11261 } else {
11262 u32 cfg = MF_CFG_RD(bp,
11263 func_ext_config[fid].
11264 func_cfg);
11265
11266 if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
11267 (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
11268 count++;
11269 }
11270 }
11271 } else { /* SF */
11272 int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
11273
11274 for (port = 0; port < port_cnt; port++) {
11275 u32 lic = SHMEM_RD(bp,
11276 drv_lic_key[port].max_fcoe_conn) ^
11277 FW_ENCODE_32BIT_PATTERN;
11278 if (lic)
11279 count++;
11280 }
11281 }
11282
11283 return count;
11284}
11285
Bill Pemberton0329aba2012-12-03 09:24:24 -050011286static void bnx2x_get_fcoe_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011287{
11288 int port = BP_PORT(bp);
11289 int func = BP_ABS_FUNC(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011290 u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
11291 drv_lic_key[port].max_fcoe_conn);
Dmitry Kravkov86800192013-05-27 04:08:29 +000011292 u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011293
Merav Sicron55c11942012-11-07 00:45:48 +000011294 if (!CNIC_SUPPORT(bp)) {
11295 bp->flags |= NO_FCOE_FLAG;
11296 return;
11297 }
11298
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011299 /* Get the number of maximum allowed FCoE connections */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011300 bp->cnic_eth_dev.max_fcoe_conn =
11301 (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
11302 BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
11303
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000011304 /* Calculate the number of maximum allowed FCoE tasks */
11305 bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
Dmitry Kravkov86800192013-05-27 04:08:29 +000011306
11307 /* check if FCoE resources must be shared between different functions */
11308 if (num_fcoe_func)
11309 bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000011310
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011311 /* Read the WWN: */
11312 if (!IS_MF(bp)) {
11313 /* Port info */
11314 bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
11315 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011316 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011317 fcoe_wwn_port_name_upper);
11318 bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
11319 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011320 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011321 fcoe_wwn_port_name_lower);
11322
11323 /* Node info */
11324 bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
11325 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011326 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011327 fcoe_wwn_node_name_upper);
11328 bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
11329 SHMEM_RD(bp,
Yuval Mintz2de67432013-01-23 03:21:43 +000011330 dev_info.port_hw_config[port].
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011331 fcoe_wwn_node_name_lower);
11332 } else if (!IS_MF_SD(bp)) {
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011333 /*
11334 * Read the WWN info only if the FCoE feature is enabled for
11335 * this function.
11336 */
Yuval Mintz7b5342d2012-09-11 04:34:14 +000011337 if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011338 bnx2x_get_ext_wwn_info(bp, func);
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011339
Yuval Mintz382e5132012-12-02 04:05:51 +000011340 } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
Dmitry Kravkov9e62e912012-03-18 10:33:43 +000011341 bnx2x_get_ext_wwn_info(bp, func);
Yuval Mintz382e5132012-12-02 04:05:51 +000011342 }
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011343
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011344 BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011345
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000011346 /*
11347 * If maximum allowed number of connections is zero -
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011348 * disable the feature.
11349 */
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011350 if (!bp->cnic_eth_dev.max_fcoe_conn)
11351 bp->flags |= NO_FCOE_FLAG;
11352}
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011353
Bill Pemberton0329aba2012-12-03 09:24:24 -050011354static void bnx2x_get_cnic_info(struct bnx2x *bp)
Dmitry Kravkovb306f5e2011-11-13 04:34:24 +000011355{
11356 /*
11357 * iSCSI may be dynamically disabled but reading
11358 * info here we will decrease memory usage by driver
11359 * if the feature is disabled for good
11360 */
11361 bnx2x_get_iscsi_info(bp);
11362 bnx2x_get_fcoe_info(bp);
11363}
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011364
Bill Pemberton0329aba2012-12-03 09:24:24 -050011365static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
Merav Sicron55c11942012-11-07 00:45:48 +000011366{
11367 u32 val, val2;
11368 int func = BP_ABS_FUNC(bp);
11369 int port = BP_PORT(bp);
11370 u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
11371 u8 *fip_mac = bp->fip_mac;
11372
11373 if (IS_MF(bp)) {
11374 /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
11375 * FCoE MAC then the appropriate feature should be disabled.
11376 * In non SD mode features configuration comes from struct
11377 * func_ext_config.
11378 */
11379 if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
11380 u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
11381 if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
11382 val2 = MF_CFG_RD(bp, func_ext_config[func].
11383 iscsi_mac_addr_upper);
11384 val = MF_CFG_RD(bp, func_ext_config[func].
11385 iscsi_mac_addr_lower);
11386 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11387 BNX2X_DEV_INFO
11388 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11389 } else {
11390 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11391 }
11392
11393 if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
11394 val2 = MF_CFG_RD(bp, func_ext_config[func].
11395 fcoe_mac_addr_upper);
11396 val = MF_CFG_RD(bp, func_ext_config[func].
11397 fcoe_mac_addr_lower);
11398 bnx2x_set_mac_buf(fip_mac, val, val2);
11399 BNX2X_DEV_INFO
11400 ("Read FCoE L2 MAC: %pM\n", fip_mac);
11401 } else {
11402 bp->flags |= NO_FCOE_FLAG;
11403 }
11404
11405 bp->mf_ext_config = cfg;
11406
11407 } else { /* SD MODE */
11408 if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
11409 /* use primary mac as iscsi mac */
11410 memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
11411
11412 BNX2X_DEV_INFO("SD ISCSI MODE\n");
11413 BNX2X_DEV_INFO
11414 ("Read iSCSI MAC: %pM\n", iscsi_mac);
11415 } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
11416 /* use primary mac as fip mac */
11417 memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
11418 BNX2X_DEV_INFO("SD FCoE MODE\n");
11419 BNX2X_DEV_INFO
11420 ("Read FIP MAC: %pM\n", fip_mac);
11421 }
11422 }
11423
Yuval Mintz82594f82013-03-11 05:17:51 +000011424 /* If this is a storage-only interface, use SAN mac as
11425 * primary MAC. Notice that for SD this is already the case,
11426 * as the SAN mac was copied from the primary MAC.
11427 */
11428 if (IS_MF_FCOE_AFEX(bp))
Merav Sicron55c11942012-11-07 00:45:48 +000011429 memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
Merav Sicron55c11942012-11-07 00:45:48 +000011430 } else {
11431 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11432 iscsi_mac_upper);
11433 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11434 iscsi_mac_lower);
11435 bnx2x_set_mac_buf(iscsi_mac, val, val2);
11436
11437 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
11438 fcoe_fip_mac_upper);
11439 val = SHMEM_RD(bp, dev_info.port_hw_config[port].
11440 fcoe_fip_mac_lower);
11441 bnx2x_set_mac_buf(fip_mac, val, val2);
11442 }
11443
11444 /* Disable iSCSI OOO if MAC configuration is invalid. */
11445 if (!is_valid_ether_addr(iscsi_mac)) {
11446 bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
11447 memset(iscsi_mac, 0, ETH_ALEN);
11448 }
11449
11450 /* Disable FCoE if MAC configuration is invalid. */
11451 if (!is_valid_ether_addr(fip_mac)) {
11452 bp->flags |= NO_FCOE_FLAG;
11453 memset(bp->fip_mac, 0, ETH_ALEN);
11454 }
11455}
11456
Bill Pemberton0329aba2012-12-03 09:24:24 -050011457static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011458{
11459 u32 val, val2;
11460 int func = BP_ABS_FUNC(bp);
11461 int port = BP_PORT(bp);
11462
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011463 /* Zero primary MAC configuration */
11464 memset(bp->dev->dev_addr, 0, ETH_ALEN);
11465
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011466 if (BP_NOMCP(bp)) {
11467 BNX2X_ERROR("warning: random MAC workaround active\n");
Danny Kukawka7ce5d222012-02-15 06:45:40 +000011468 eth_hw_addr_random(bp->dev);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011469 } else if (IS_MF(bp)) {
11470 val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
11471 val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
11472 if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11473 (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11474 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11475
Merav Sicron55c11942012-11-07 00:45:48 +000011476 if (CNIC_SUPPORT(bp))
11477 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011478 } else {
11479 /* in SF read MACs from port configuration */
11480 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11481 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11482 bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11483
Merav Sicron55c11942012-11-07 00:45:48 +000011484 if (CNIC_SUPPORT(bp))
11485 bnx2x_get_cnic_mac_hwinfo(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011486 }
11487
Yuval Mintz3d7d5622013-10-09 16:06:28 +020011488 if (!BP_NOMCP(bp)) {
11489 /* Read physical port identifier from shmem */
11490 val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
11491 val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11492 bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
11493 bp->flags |= HAS_PHYS_PORT_ID;
11494 }
11495
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070011496 memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
Michael Chan37b091b2009-10-10 13:46:55 +000011497
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011498 if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011499 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011500 "bad Ethernet MAC address configuration: %pM\n"
11501 "change it manually before bringing up the appropriate network interface\n",
Joe Perches0f9dad12011-08-14 12:16:19 +000011502 bp->dev->dev_addr);
Yuval Mintz79642112012-12-02 04:05:50 +000011503}
Merav Sicron51c1a582012-03-18 10:33:38 +000011504
Bill Pemberton0329aba2012-12-03 09:24:24 -050011505static bool bnx2x_get_dropless_info(struct bnx2x *bp)
Yuval Mintz79642112012-12-02 04:05:50 +000011506{
11507 int tmp;
11508 u32 cfg;
Merav Sicron51c1a582012-03-18 10:33:38 +000011509
Yuval Mintzaeeddb82013-08-19 09:11:59 +030011510 if (IS_VF(bp))
11511 return 0;
11512
Yuval Mintz79642112012-12-02 04:05:50 +000011513 if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
11514 /* Take function: tmp = func */
11515 tmp = BP_ABS_FUNC(bp);
11516 cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
11517 cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
11518 } else {
11519 /* Take port: tmp = port */
11520 tmp = BP_PORT(bp);
11521 cfg = SHMEM_RD(bp,
11522 dev_info.port_hw_config[tmp].generic_features);
11523 cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
11524 }
11525 return cfg;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011526}
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011527
Bill Pemberton0329aba2012-12-03 09:24:24 -050011528static int bnx2x_get_hwinfo(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011529{
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011530 int /*abs*/func = BP_ABS_FUNC(bp);
David S. Millerb8ee8322011-04-17 16:56:12 -070011531 int vn;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011532 u32 val = 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011533 int rc = 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011534
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011535 bnx2x_get_common_hwinfo(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011536
Ariel Elior6383c0b2011-07-14 08:31:57 +000011537 /*
11538 * initialize IGU parameters
11539 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011540 if (CHIP_IS_E1x(bp)) {
11541 bp->common.int_block = INT_BLOCK_HC;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011542
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011543 bp->igu_dsb_id = DEF_SB_IGU_ID;
11544 bp->igu_base_sb = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011545 } else {
11546 bp->common.int_block = INT_BLOCK_IGU;
David S. Miller8decf862011-09-22 03:23:13 -040011547
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011548 /* do not allow device reset during IGU info processing */
David S. Miller8decf862011-09-22 03:23:13 -040011549 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
11550
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011551 val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011552
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011553 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011554 int tout = 5000;
11555
11556 BNX2X_DEV_INFO("FORCING Normal Mode\n");
11557
11558 val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
11559 REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
11560 REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
11561
11562 while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11563 tout--;
Yuval Mintz0926d492013-01-23 03:21:45 +000011564 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011565 }
11566
11567 if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
11568 dev_err(&bp->pdev->dev,
11569 "FORCING Normal Mode failed!!!\n");
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011570 bnx2x_release_hw_lock(bp,
11571 HW_LOCK_RESOURCE_RESET);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011572 return -EPERM;
11573 }
11574 }
11575
11576 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
11577 BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011578 bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
11579 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011580 BNX2X_DEV_INFO("IGU Normal Mode\n");
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011581
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011582 rc = bnx2x_get_igu_cam_info(bp);
David S. Miller8decf862011-09-22 03:23:13 -040011583 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
Barak Witkowski9b341bb2012-12-02 04:05:52 +000011584 if (rc)
11585 return rc;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011586 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011587
11588 /*
11589 * set base FW non-default (fast path) status block id, this value is
11590 * used to initialize the fw_sb_id saved on the fp/queue structure to
11591 * determine the id used by the FW.
11592 */
11593 if (CHIP_IS_E1x(bp))
11594 bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
11595 else /*
11596 * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
11597 * the same queue are indicated on the same IGU SB). So we prefer
11598 * FW and IGU SBs to be the same value.
11599 */
11600 bp->base_fw_ndsb = bp->igu_base_sb;
11601
11602 BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
11603 "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
11604 bp->igu_sb_cnt, bp->base_fw_ndsb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011605
11606 /*
11607 * Initialize MF configuration
11608 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011609
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011610 bp->mf_ov = 0;
11611 bp->mf_mode = 0;
David S. Miller8decf862011-09-22 03:23:13 -040011612 vn = BP_VN(bp);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011613
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011614 if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011615 BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
11616 bp->common.shmem2_base, SHMEM2_RD(bp, size),
11617 (u32)offsetof(struct shmem2_region, mf_cfg_addr));
11618
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011619 if (SHMEM2_HAS(bp, mf_cfg_addr))
11620 bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
11621 else
11622 bp->common.mf_cfg_base = bp->common.shmem_base +
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011623 offsetof(struct shmem_region, func_mb) +
11624 E1H_FUNC_MAX * sizeof(struct drv_func_mb);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011625 /*
11626 * get mf configuration:
Yuval Mintz16a5fd92013-06-02 00:06:18 +000011627 * 1. Existence of MF configuration
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011628 * 2. MAC address must be legal (check only upper bytes)
11629 * for Switch-Independent mode;
11630 * OVLAN must be legal for Switch-Dependent mode
11631 * 3. SF_MODE configures specific MF mode
11632 */
11633 if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11634 /* get mf configuration */
11635 val = SHMEM_RD(bp,
11636 dev_info.shared_feature_config.config);
11637 val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011638
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011639 switch (val) {
11640 case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
11641 val = MF_CFG_RD(bp, func_mf_config[func].
11642 mac_upper);
11643 /* check for legal mac (upper bytes)*/
11644 if (val != 0xffff) {
11645 bp->mf_mode = MULTI_FUNCTION_SI;
11646 bp->mf_config[vn] = MF_CFG_RD(bp,
11647 func_mf_config[func].config);
11648 } else
Merav Sicron51c1a582012-03-18 10:33:38 +000011649 BNX2X_DEV_INFO("illegal MAC address for SI\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011650 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011651 case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
11652 if ((!CHIP_IS_E1x(bp)) &&
11653 (MF_CFG_RD(bp, func_mf_config[func].
11654 mac_upper) != 0xffff) &&
11655 (SHMEM2_HAS(bp,
11656 afex_driver_support))) {
11657 bp->mf_mode = MULTI_FUNCTION_AFEX;
11658 bp->mf_config[vn] = MF_CFG_RD(bp,
11659 func_mf_config[func].config);
11660 } else {
11661 BNX2X_DEV_INFO("can not configure afex mode\n");
11662 }
11663 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011664 case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
11665 /* get OV configuration */
11666 val = MF_CFG_RD(bp,
11667 func_mf_config[FUNC_0].e1hov_tag);
11668 val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
11669
11670 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
11671 bp->mf_mode = MULTI_FUNCTION_SD;
11672 bp->mf_config[vn] = MF_CFG_RD(bp,
11673 func_mf_config[func].config);
11674 } else
Dmitry Kravkov754a2f52011-06-14 01:34:02 +000011675 BNX2X_DEV_INFO("illegal OV for SD\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011676 break;
Ariel Elior3786b942013-03-11 05:17:44 +000011677 case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
11678 bp->mf_config[vn] = 0;
11679 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011680 default:
11681 /* Unknown configuration: reset mf_config */
11682 bp->mf_config[vn] = 0;
Merav Sicron51c1a582012-03-18 10:33:38 +000011683 BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011684 }
11685 }
11686
Eilon Greenstein2691d512009-08-12 08:22:08 +000011687 BNX2X_DEV_INFO("%s function mode\n",
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011688 IS_MF(bp) ? "multi" : "single");
Eilon Greenstein2691d512009-08-12 08:22:08 +000011689
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011690 switch (bp->mf_mode) {
11691 case MULTI_FUNCTION_SD:
11692 val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
11693 FUNC_MF_CFG_E1HOV_TAG_MASK;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011694 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +000011695 bp->mf_ov = val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011696 bp->path_has_ovlan = true;
11697
Merav Sicron51c1a582012-03-18 10:33:38 +000011698 BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
11699 func, bp->mf_ov, bp->mf_ov);
Eilon Greenstein2691d512009-08-12 08:22:08 +000011700 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011701 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011702 "No valid MF OV for func %d, aborting\n",
11703 func);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011704 return -EPERM;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011705 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011706 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011707 case MULTI_FUNCTION_AFEX:
11708 BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
11709 break;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011710 case MULTI_FUNCTION_SI:
Merav Sicron51c1a582012-03-18 10:33:38 +000011711 BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
11712 func);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011713 break;
11714 default:
11715 if (vn) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011716 dev_err(&bp->pdev->dev,
Merav Sicron51c1a582012-03-18 10:33:38 +000011717 "VN %d is in a single function mode, aborting\n",
11718 vn);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011719 return -EPERM;
Eilon Greenstein2691d512009-08-12 08:22:08 +000011720 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011721 break;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011722 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011723
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011724 /* check if other port on the path needs ovlan:
11725 * Since MF configuration is shared between ports
11726 * Possible mixed modes are only
11727 * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
11728 */
11729 if (CHIP_MODE_IS_4_PORT(bp) &&
11730 !bp->path_has_ovlan &&
11731 !IS_MF(bp) &&
11732 bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
11733 u8 other_port = !BP_PORT(bp);
11734 u8 other_func = BP_PATH(bp) + 2*other_port;
11735 val = MF_CFG_RD(bp,
11736 func_mf_config[other_func].e1hov_tag);
11737 if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
11738 bp->path_has_ovlan = true;
11739 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011740 }
11741
Dmitry Kravkove8485822014-01-05 18:33:50 +020011742 /* adjust igu_sb_cnt to MF for E1H */
11743 if (CHIP_IS_E1H(bp) && IS_MF(bp))
11744 bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011745
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011746 /* port info */
11747 bnx2x_get_port_hwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011748
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080011749 /* Get MAC addresses */
11750 bnx2x_get_mac_hwinfo(bp);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011751
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011752 bnx2x_get_cnic_info(bp);
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000011753
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011754 return rc;
11755}
11756
Bill Pemberton0329aba2012-12-03 09:24:24 -050011757static void bnx2x_read_fwinfo(struct bnx2x *bp)
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011758{
11759 int cnt, i, block_end, rodi;
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011760 char vpd_start[BNX2X_VPD_LEN+1];
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011761 char str_id_reg[VENDOR_ID_LEN+1];
11762 char str_id_cap[VENDOR_ID_LEN+1];
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011763 char *vpd_data;
11764 char *vpd_extended_data = NULL;
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011765 u8 len;
11766
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011767 cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011768 memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
11769
11770 if (cnt < BNX2X_VPD_LEN)
11771 goto out_not_found;
11772
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011773 /* VPD RO tag should be first tag after identifier string, hence
11774 * we should be able to find it in first BNX2X_VPD_LEN chars
11775 */
11776 i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011777 PCI_VPD_LRDT_RO_DATA);
11778 if (i < 0)
11779 goto out_not_found;
11780
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011781 block_end = i + PCI_VPD_LRDT_TAG_SIZE +
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011782 pci_vpd_lrdt_size(&vpd_start[i]);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011783
11784 i += PCI_VPD_LRDT_TAG_SIZE;
11785
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011786 if (block_end > BNX2X_VPD_LEN) {
11787 vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
11788 if (vpd_extended_data == NULL)
11789 goto out_not_found;
11790
11791 /* read rest of vpd image into vpd_extended_data */
11792 memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
11793 cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
11794 block_end - BNX2X_VPD_LEN,
11795 vpd_extended_data + BNX2X_VPD_LEN);
11796 if (cnt < (block_end - BNX2X_VPD_LEN))
11797 goto out_not_found;
11798 vpd_data = vpd_extended_data;
11799 } else
11800 vpd_data = vpd_start;
11801
11802 /* now vpd_data holds full vpd content in both cases */
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011803
11804 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11805 PCI_VPD_RO_KEYWORD_MFR_ID);
11806 if (rodi < 0)
11807 goto out_not_found;
11808
11809 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11810
11811 if (len != VENDOR_ID_LEN)
11812 goto out_not_found;
11813
11814 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11815
11816 /* vendor specific info */
11817 snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
11818 snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
11819 if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
11820 !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
11821
11822 rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
11823 PCI_VPD_RO_KEYWORD_VENDOR0);
11824 if (rodi >= 0) {
11825 len = pci_vpd_info_field_size(&vpd_data[rodi]);
11826
11827 rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
11828
11829 if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
11830 memcpy(bp->fw_ver, &vpd_data[rodi], len);
11831 bp->fw_ver[len] = ' ';
11832 }
11833 }
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011834 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011835 return;
11836 }
11837out_not_found:
Barak Witkowskifcdf95c2011-12-14 00:14:53 +000011838 kfree(vpd_extended_data);
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011839 return;
11840}
11841
Bill Pemberton0329aba2012-12-03 09:24:24 -050011842static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011843{
11844 u32 flags = 0;
11845
11846 if (CHIP_REV_IS_FPGA(bp))
11847 SET_FLAGS(flags, MODE_FPGA);
11848 else if (CHIP_REV_IS_EMUL(bp))
11849 SET_FLAGS(flags, MODE_EMUL);
11850 else
11851 SET_FLAGS(flags, MODE_ASIC);
11852
11853 if (CHIP_MODE_IS_4_PORT(bp))
11854 SET_FLAGS(flags, MODE_PORT4);
11855 else
11856 SET_FLAGS(flags, MODE_PORT2);
11857
11858 if (CHIP_IS_E2(bp))
11859 SET_FLAGS(flags, MODE_E2);
11860 else if (CHIP_IS_E3(bp)) {
11861 SET_FLAGS(flags, MODE_E3);
11862 if (CHIP_REV(bp) == CHIP_REV_Ax)
11863 SET_FLAGS(flags, MODE_E3_A0);
Ariel Elior6383c0b2011-07-14 08:31:57 +000011864 else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
11865 SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011866 }
11867
11868 if (IS_MF(bp)) {
11869 SET_FLAGS(flags, MODE_MF);
11870 switch (bp->mf_mode) {
11871 case MULTI_FUNCTION_SD:
11872 SET_FLAGS(flags, MODE_MF_SD);
11873 break;
11874 case MULTI_FUNCTION_SI:
11875 SET_FLAGS(flags, MODE_MF_SI);
11876 break;
Barak Witkowskia3348722012-04-23 03:04:46 +000011877 case MULTI_FUNCTION_AFEX:
11878 SET_FLAGS(flags, MODE_MF_AFEX);
11879 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011880 }
11881 } else
11882 SET_FLAGS(flags, MODE_SF);
11883
11884#if defined(__LITTLE_ENDIAN)
11885 SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
11886#else /*(__BIG_ENDIAN)*/
11887 SET_FLAGS(flags, MODE_BIG_ENDIAN);
11888#endif
11889 INIT_MODE_FLAGS(bp) = flags;
11890}
11891
Bill Pemberton0329aba2012-12-03 09:24:24 -050011892static int bnx2x_init_bp(struct bnx2x *bp)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011893{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011894 int func;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011895 int rc;
11896
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011897 mutex_init(&bp->port.phy_mutex);
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -070011898 mutex_init(&bp->fw_mb_mutex);
Yuval Mintz42f82772014-03-23 18:12:23 +020011899 mutex_init(&bp->drv_info_mutex);
11900 bp->drv_info_mng_owner = false;
David S. Millerbb7e95c2010-07-27 21:01:35 -070011901 spin_lock_init(&bp->stats_lock);
Dmitry Kravkov507393e2013-08-13 02:24:59 +030011902 sema_init(&bp->stats_sema, 1);
Merav Sicron55c11942012-11-07 00:45:48 +000011903
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080011904 INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
Ariel Elior7be08a72011-07-14 08:31:19 +000011905 INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000011906 INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
Yuval Mintz370d4a22014-03-23 18:12:24 +020011907 INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
Ariel Elior1ab44342013-01-01 05:22:23 +000011908 if (IS_PF(bp)) {
11909 rc = bnx2x_get_hwinfo(bp);
11910 if (rc)
11911 return rc;
11912 } else {
Ariel Eliore09b74d2013-05-27 04:08:26 +000011913 eth_zero_addr(bp->dev->dev_addr);
Ariel Elior1ab44342013-01-01 05:22:23 +000011914 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011915
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011916 bnx2x_set_modes_bitmap(bp);
11917
11918 rc = bnx2x_alloc_mem_bp(bp);
11919 if (rc)
11920 return rc;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011921
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +000011922 bnx2x_read_fwinfo(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011923
11924 func = BP_FUNC(bp);
11925
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011926 /* need to reset chip if undi was active */
Ariel Elior1ab44342013-01-01 05:22:23 +000011927 if (IS_PF(bp) && !BP_NOMCP(bp)) {
Yuval Mintz452427b2012-03-26 20:47:07 +000011928 /* init fw_seq */
11929 bp->fw_seq =
11930 SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
11931 DRV_MSG_SEQ_NUMBER_MASK;
11932 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
11933
Yuval Mintz91ebb922013-12-26 09:57:07 +020011934 rc = bnx2x_prev_unload(bp);
11935 if (rc) {
11936 bnx2x_free_mem_bp(bp);
11937 return rc;
11938 }
Yuval Mintz452427b2012-03-26 20:47:07 +000011939 }
11940
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011941 if (CHIP_REV_IS_FPGA(bp))
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000011942 dev_err(&bp->pdev->dev, "FPGA detected\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011943
11944 if (BP_NOMCP(bp) && (func == 0))
Merav Sicron51c1a582012-03-18 10:33:38 +000011945 dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011946
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011947 bp->disable_tpa = disable_tpa;
Barak Witkowskia3348722012-04-23 03:04:46 +000011948 bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
Michal Schmidt94d9de32014-02-25 16:04:26 +010011949 /* Reduce memory usage in kdump environment by disabling TPA */
11950 bp->disable_tpa |= reset_devices;
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011951
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011952 /* Set TPA flags */
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000011953 if (bp->disable_tpa) {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011954 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011955 bp->dev->features &= ~NETIF_F_LRO;
11956 } else {
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000011957 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011958 bp->dev->features |= NETIF_F_LRO;
11959 }
11960
Eilon Greensteina18f5122009-08-12 08:23:26 +000011961 if (CHIP_IS_E1(bp))
11962 bp->dropless_fc = 0;
11963 else
Yuval Mintz79642112012-12-02 04:05:50 +000011964 bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
Eilon Greensteina18f5122009-08-12 08:23:26 +000011965
Eilon Greenstein8d5726c2009-02-12 08:37:19 +000011966 bp->mrrs = mrrs;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -070011967
Barak Witkowskia3348722012-04-23 03:04:46 +000011968 bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
Ariel Elior1ab44342013-01-01 05:22:23 +000011969 if (IS_VF(bp))
11970 bp->rx_ring_size = MAX_RX_AVAIL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011971
Eilon Greenstein7d323bf2009-11-09 06:09:35 +000011972 /* make sure that the numbers are in the right granularity */
Dmitry Kravkov523224a2010-10-06 03:23:26 +000011973 bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
11974 bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011975
Michal Schmidtfc543632012-02-14 09:05:46 +000011976 bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070011977
11978 init_timer(&bp->timer);
11979 bp->timer.expires = jiffies + bp->current_interval;
11980 bp->timer.data = (unsigned long) bp;
11981 bp->timer.function = bnx2x_timer;
11982
Barak Witkowski0370cf92012-12-02 04:05:55 +000011983 if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
11984 SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
11985 SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
11986 SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
11987 bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
11988 bnx2x_dcbx_init_params(bp);
11989 } else {
11990 bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
11991 }
Vladislav Zolotarove4901dd2010-12-13 05:44:18 +000011992
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011993 if (CHIP_IS_E1x(bp))
11994 bp->cnic_base_cl_id = FP_SB_MAX_E1x;
11995 else
11996 bp->cnic_base_cl_id = FP_SB_MAX_E2;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030011997
Ariel Elior6383c0b2011-07-14 08:31:57 +000011998 /* multiple tx priority */
Ariel Elior1ab44342013-01-01 05:22:23 +000011999 if (IS_VF(bp))
12000 bp->max_cos = 1;
12001 else if (CHIP_IS_E1x(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000012002 bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
Ariel Elior1ab44342013-01-01 05:22:23 +000012003 else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000012004 bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
Ariel Elior1ab44342013-01-01 05:22:23 +000012005 else if (CHIP_IS_E3B0(bp))
Ariel Elior6383c0b2011-07-14 08:31:57 +000012006 bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
Ariel Elior1ab44342013-01-01 05:22:23 +000012007 else
12008 BNX2X_ERR("unknown chip %x revision %x\n",
12009 CHIP_NUM(bp), CHIP_REV(bp));
12010 BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
Ariel Elior6383c0b2011-07-14 08:31:57 +000012011
Merav Sicron55c11942012-11-07 00:45:48 +000012012 /* We need at least one default status block for slow-path events,
12013 * second status block for the L2 queue, and a third status block for
Yuval Mintz16a5fd92013-06-02 00:06:18 +000012014 * CNIC if supported.
Merav Sicron55c11942012-11-07 00:45:48 +000012015 */
Ariel Elior60cad4e2013-09-04 14:09:22 +030012016 if (IS_VF(bp))
12017 bp->min_msix_vec_cnt = 1;
12018 else if (CNIC_SUPPORT(bp))
Merav Sicron55c11942012-11-07 00:45:48 +000012019 bp->min_msix_vec_cnt = 3;
Ariel Elior60cad4e2013-09-04 14:09:22 +030012020 else /* PF w/o cnic */
Merav Sicron55c11942012-11-07 00:45:48 +000012021 bp->min_msix_vec_cnt = 2;
12022 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
12023
Michal Schmidt5bb680d2013-07-01 17:23:06 +020012024 bp->dump_preset_idx = 1;
12025
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012026 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012027}
12028
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000012029/****************************************************************************
12030* General service functions
12031****************************************************************************/
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012032
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012033/*
12034 * net_device service functions
12035 */
12036
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070012037/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012038static int bnx2x_open(struct net_device *dev)
12039{
12040 struct bnx2x *bp = netdev_priv(dev);
Ariel Elior8395be52013-01-01 05:22:44 +000012041 int rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012042
Mintz Yuval1355b702012-02-15 02:10:22 +000012043 bp->stats_init = true;
12044
Eilon Greenstein6eccabb2009-01-22 03:37:48 +000012045 netif_carrier_off(dev);
12046
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012047 bnx2x_set_power_state(bp, PCI_D0);
12048
Ariel Eliorad5afc82013-01-01 05:22:26 +000012049 /* If parity had happen during the unload, then attentions
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000012050 * and/or RECOVERY_IN_PROGRES may still be set. In this case we
12051 * want the first function loaded on the current engine to
12052 * complete the recovery.
Ariel Eliorad5afc82013-01-01 05:22:26 +000012053 * Parity recovery is only relevant for PF driver.
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000012054 */
Ariel Eliorad5afc82013-01-01 05:22:26 +000012055 if (IS_PF(bp)) {
Yuval Mintz1a6974b2013-10-20 16:51:27 +020012056 int other_engine = BP_PATH(bp) ? 0 : 1;
12057 bool other_load_status, load_status;
12058 bool global = false;
12059
Ariel Eliorad5afc82013-01-01 05:22:26 +000012060 other_load_status = bnx2x_get_load_status(bp, other_engine);
12061 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
12062 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
12063 bnx2x_chk_parity_attn(bp, &global, true)) {
12064 do {
12065 /* If there are attentions and they are in a
12066 * global blocks, set the GLOBAL_RESET bit
12067 * regardless whether it will be this function
12068 * that will complete the recovery or not.
12069 */
12070 if (global)
12071 bnx2x_set_reset_global(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000012072
Ariel Eliorad5afc82013-01-01 05:22:26 +000012073 /* Only the first function on the current
12074 * engine should try to recover in open. In case
12075 * of attentions in global blocks only the first
12076 * in the chip should try to recover.
12077 */
12078 if ((!load_status &&
12079 (!global || !other_load_status)) &&
12080 bnx2x_trylock_leader_lock(bp) &&
12081 !bnx2x_leader_reset(bp)) {
12082 netdev_info(bp->dev,
12083 "Recovered in open\n");
12084 break;
12085 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012086
Ariel Eliorad5afc82013-01-01 05:22:26 +000012087 /* recovery has failed... */
12088 bnx2x_set_power_state(bp, PCI_D3hot);
12089 bp->recovery_state = BNX2X_RECOVERY_FAILED;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012090
Ariel Eliorad5afc82013-01-01 05:22:26 +000012091 BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
12092 "If you still see this message after a few retries then power cycle is required.\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012093
Ariel Eliorad5afc82013-01-01 05:22:26 +000012094 return -EAGAIN;
12095 } while (0);
12096 }
12097 }
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000012098
12099 bp->recovery_state = BNX2X_RECOVERY_DONE;
Ariel Elior8395be52013-01-01 05:22:44 +000012100 rc = bnx2x_nic_load(bp, LOAD_OPEN);
12101 if (rc)
12102 return rc;
Ariel Elior9a8130b2013-09-28 08:46:09 +030012103 return 0;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012104}
12105
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -070012106/* called with rtnl_lock */
Michal Schmidt56ad3152012-02-16 02:38:48 +000012107static int bnx2x_close(struct net_device *dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012108{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012109 struct bnx2x *bp = netdev_priv(dev);
12110
12111 /* Unload the driver, release IRQs */
Yuval Mintz5d07d862012-09-13 02:56:21 +000012112 bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +000012113
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012114 return 0;
12115}
12116
Eric Dumazet1191cb82012-04-27 21:39:21 +000012117static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
12118 struct bnx2x_mcast_ramrod_params *p)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012119{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012120 int mc_count = netdev_mc_count(bp->dev);
12121 struct bnx2x_mcast_list_elem *mc_mac =
Joe Perchescd2b0382014-02-20 13:25:51 -080012122 kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012123 struct netdev_hw_addr *ha;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012124
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012125 if (!mc_mac)
12126 return -ENOMEM;
12127
12128 INIT_LIST_HEAD(&p->mcast_list);
12129
12130 netdev_for_each_mc_addr(ha, bp->dev) {
12131 mc_mac->mac = bnx2x_mc_addr(ha);
12132 list_add_tail(&mc_mac->link, &p->mcast_list);
12133 mc_mac++;
12134 }
12135
12136 p->mcast_list_len = mc_count;
12137
12138 return 0;
12139}
12140
Eric Dumazet1191cb82012-04-27 21:39:21 +000012141static void bnx2x_free_mcast_macs_list(
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012142 struct bnx2x_mcast_ramrod_params *p)
12143{
12144 struct bnx2x_mcast_list_elem *mc_mac =
12145 list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
12146 link);
12147
12148 WARN_ON(!mc_mac);
12149 kfree(mc_mac);
12150}
12151
12152/**
12153 * bnx2x_set_uc_list - configure a new unicast MACs list.
12154 *
12155 * @bp: driver handle
12156 *
12157 * We will use zero (0) as a MAC type for these MACs.
12158 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012159static int bnx2x_set_uc_list(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012160{
12161 int rc;
12162 struct net_device *dev = bp->dev;
12163 struct netdev_hw_addr *ha;
Barak Witkowski15192a82012-06-19 07:48:28 +000012164 struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012165 unsigned long ramrod_flags = 0;
12166
12167 /* First schedule a cleanup up of old configuration */
12168 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
12169 if (rc < 0) {
12170 BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
12171 return rc;
12172 }
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012173
12174 netdev_for_each_uc_addr(ha, dev) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012175 rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
12176 BNX2X_UC_LIST_MAC, &ramrod_flags);
Yuval Mintz7b5342d2012-09-11 04:34:14 +000012177 if (rc == -EEXIST) {
12178 DP(BNX2X_MSG_SP,
12179 "Failed to schedule ADD operations: %d\n", rc);
12180 /* do not treat adding same MAC as error */
12181 rc = 0;
12182
12183 } else if (rc < 0) {
12184
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012185 BNX2X_ERR("Failed to schedule ADD operations: %d\n",
12186 rc);
12187 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012188 }
12189 }
12190
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012191 /* Execute the pending commands */
12192 __set_bit(RAMROD_CONT, &ramrod_flags);
12193 return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
12194 BNX2X_UC_LIST_MAC, &ramrod_flags);
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012195}
12196
Eric Dumazet1191cb82012-04-27 21:39:21 +000012197static int bnx2x_set_mc_list(struct bnx2x *bp)
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012198{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012199 struct net_device *dev = bp->dev;
Yuval Mintz3b603062012-03-18 10:33:39 +000012200 struct bnx2x_mcast_ramrod_params rparam = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012201 int rc = 0;
12202
12203 rparam.mcast_obj = &bp->mcast_obj;
12204
12205 /* first, clear all configured multicast MACs */
12206 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
12207 if (rc < 0) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012208 BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012209 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012210 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012211
12212 /* then, configure a new MACs list */
12213 if (netdev_mc_count(dev)) {
12214 rc = bnx2x_init_mcast_macs_list(bp, &rparam);
12215 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012216 BNX2X_ERR("Failed to create multicast MACs list: %d\n",
12217 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012218 return rc;
12219 }
12220
12221 /* Now add the new MACs */
12222 rc = bnx2x_config_mcast(bp, &rparam,
12223 BNX2X_MCAST_CMD_ADD);
12224 if (rc < 0)
Merav Sicron51c1a582012-03-18 10:33:38 +000012225 BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
12226 rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012227
12228 bnx2x_free_mcast_macs_list(&rparam);
12229 }
12230
12231 return rc;
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012232}
12233
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012234/* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
stephen hemmingera8f47eb2014-01-09 22:20:11 -080012235static void bnx2x_set_rx_mode(struct net_device *dev)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012236{
12237 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012238
12239 if (bp->state != BNX2X_STATE_OPEN) {
12240 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
12241 return;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012242 } else {
12243 /* Schedule an SP task to handle rest of change */
Yuval Mintz230bb0f2014-02-12 18:19:56 +020012244 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
12245 NETIF_MSG_IFUP);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012246 }
Yuval Mintz8b09be52013-08-01 17:30:59 +030012247}
12248
12249void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
12250{
12251 u32 rx_mode = BNX2X_RX_MODE_NORMAL;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012252
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012253 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012254
Yuval Mintz8b09be52013-08-01 17:30:59 +030012255 netif_addr_lock_bh(bp->dev);
12256
12257 if (bp->dev->flags & IFF_PROMISC) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012258 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012259 } else if ((bp->dev->flags & IFF_ALLMULTI) ||
12260 ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
12261 CHIP_IS_E1(bp))) {
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012262 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012263 } else {
Ariel Elior381ac162013-01-01 05:22:29 +000012264 if (IS_PF(bp)) {
12265 /* some multicasts */
12266 if (bnx2x_set_mc_list(bp) < 0)
12267 rx_mode = BNX2X_RX_MODE_ALLMULTI;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012268
Yuval Mintz8b09be52013-08-01 17:30:59 +030012269 /* release bh lock, as bnx2x_set_uc_list might sleep */
12270 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012271 if (bnx2x_set_uc_list(bp) < 0)
12272 rx_mode = BNX2X_RX_MODE_PROMISC;
Yuval Mintz8b09be52013-08-01 17:30:59 +030012273 netif_addr_lock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012274 } else {
12275 /* configuring mcast to a vf involves sleeping (when we
Yuval Mintz8b09be52013-08-01 17:30:59 +030012276 * wait for the pf's response).
Ariel Elior381ac162013-01-01 05:22:29 +000012277 */
Yuval Mintz230bb0f2014-02-12 18:19:56 +020012278 bnx2x_schedule_sp_rtnl(bp,
12279 BNX2X_SP_RTNL_VFPF_MCAST, 0);
Ariel Elior381ac162013-01-01 05:22:29 +000012280 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012281 }
12282
12283 bp->rx_mode = rx_mode;
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012284 /* handle ISCSI SD mode */
12285 if (IS_MF_ISCSI_SD(bp))
12286 bp->rx_mode = BNX2X_RX_MODE_NONE;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012287
12288 /* Schedule the rx_mode command */
12289 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
12290 set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
Yuval Mintz8b09be52013-08-01 17:30:59 +030012291 netif_addr_unlock_bh(bp->dev);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012292 return;
12293 }
12294
Ariel Elior381ac162013-01-01 05:22:29 +000012295 if (IS_PF(bp)) {
12296 bnx2x_set_storm_rx_mode(bp);
Yuval Mintz8b09be52013-08-01 17:30:59 +030012297 netif_addr_unlock_bh(bp->dev);
Ariel Elior381ac162013-01-01 05:22:29 +000012298 } else {
Yuval Mintz8b09be52013-08-01 17:30:59 +030012299 /* VF will need to request the PF to make this change, and so
12300 * the VF needs to release the bottom-half lock prior to the
12301 * request (as it will likely require sleep on the VF side)
Ariel Elior381ac162013-01-01 05:22:29 +000012302 */
Yuval Mintz8b09be52013-08-01 17:30:59 +030012303 netif_addr_unlock_bh(bp->dev);
12304 bnx2x_vfpf_storm_rx_mode(bp);
Ariel Elior381ac162013-01-01 05:22:29 +000012305 }
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012306}
12307
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070012308/* called with rtnl_lock */
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012309static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
12310 int devad, u16 addr)
12311{
12312 struct bnx2x *bp = netdev_priv(netdev);
12313 u16 value;
12314 int rc;
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012315
12316 DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
12317 prtad, devad, addr);
12318
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012319 /* The HW expects different devad if CL22 is used */
12320 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12321
12322 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012323 rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012324 bnx2x_release_phy_lock(bp);
12325 DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
12326
12327 if (!rc)
12328 rc = value;
12329 return rc;
12330}
12331
12332/* called with rtnl_lock */
12333static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
12334 u16 addr, u16 value)
12335{
12336 struct bnx2x *bp = netdev_priv(netdev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012337 int rc;
12338
Merav Sicron51c1a582012-03-18 10:33:38 +000012339 DP(NETIF_MSG_LINK,
12340 "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
12341 prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012342
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012343 /* The HW expects different devad if CL22 is used */
12344 devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
12345
12346 bnx2x_acquire_phy_lock(bp);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012347 rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012348 bnx2x_release_phy_lock(bp);
12349 return rc;
12350}
12351
12352/* called with rtnl_lock */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012353static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
12354{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012355 struct bnx2x *bp = netdev_priv(dev);
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012356 struct mii_ioctl_data *mdio = if_mii(ifr);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012357
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012358 DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
12359 mdio->phy_id, mdio->reg_num, mdio->val_in);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012360
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012361 if (!netif_running(dev))
12362 return -EAGAIN;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -070012363
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012364 return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012365}
12366
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000012367#ifdef CONFIG_NET_POLL_CONTROLLER
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012368static void poll_bnx2x(struct net_device *dev)
12369{
12370 struct bnx2x *bp = netdev_priv(dev);
Merav Sicron14a15d62012-08-27 03:26:20 +000012371 int i;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012372
Merav Sicron14a15d62012-08-27 03:26:20 +000012373 for_each_eth_queue(bp, i) {
12374 struct bnx2x_fastpath *fp = &bp->fp[i];
12375 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
12376 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012377}
12378#endif
12379
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012380static int bnx2x_validate_addr(struct net_device *dev)
12381{
12382 struct bnx2x *bp = netdev_priv(dev);
12383
Ariel Eliore09b74d2013-05-27 04:08:26 +000012384 /* query the bulletin board for mac address configured by the PF */
12385 if (IS_VF(bp))
12386 bnx2x_sample_bulletin(bp);
12387
Merav Sicron51c1a582012-03-18 10:33:38 +000012388 if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
12389 BNX2X_ERR("Non-valid Ethernet address\n");
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012390 return -EADDRNOTAVAIL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012391 }
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012392 return 0;
12393}
12394
Yuval Mintz3d7d5622013-10-09 16:06:28 +020012395static int bnx2x_get_phys_port_id(struct net_device *netdev,
12396 struct netdev_phys_port_id *ppid)
12397{
12398 struct bnx2x *bp = netdev_priv(netdev);
12399
12400 if (!(bp->flags & HAS_PHYS_PORT_ID))
12401 return -EOPNOTSUPP;
12402
12403 ppid->id_len = sizeof(bp->phys_port_id);
12404 memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
12405
12406 return 0;
12407}
12408
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012409static const struct net_device_ops bnx2x_netdev_ops = {
12410 .ndo_open = bnx2x_open,
12411 .ndo_stop = bnx2x_close,
12412 .ndo_start_xmit = bnx2x_start_xmit,
Vladislav Zolotarov8307fa32010-12-13 05:44:09 +000012413 .ndo_select_queue = bnx2x_select_queue,
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080012414 .ndo_set_rx_mode = bnx2x_set_rx_mode,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012415 .ndo_set_mac_address = bnx2x_change_mac_addr,
Dmitry Kravkov614c76d2011-11-28 12:31:49 +000012416 .ndo_validate_addr = bnx2x_validate_addr,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012417 .ndo_do_ioctl = bnx2x_ioctl,
12418 .ndo_change_mtu = bnx2x_change_mtu,
Michał Mirosław66371c42011-04-12 09:38:23 +000012419 .ndo_fix_features = bnx2x_fix_features,
12420 .ndo_set_features = bnx2x_set_features,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012421 .ndo_tx_timeout = bnx2x_tx_timeout,
Alexey Dobriyan257ddbd2010-01-27 10:17:41 +000012422#ifdef CONFIG_NET_POLL_CONTROLLER
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012423 .ndo_poll_controller = poll_bnx2x,
12424#endif
Ariel Elior6383c0b2011-07-14 08:31:57 +000012425 .ndo_setup_tc = bnx2x_setup_tc,
Ariel Elior64112802013-01-07 00:50:23 +000012426#ifdef CONFIG_BNX2X_SRIOV
Ariel Eliorabc5a022013-01-01 05:22:43 +000012427 .ndo_set_vf_mac = bnx2x_set_vf_mac,
Yuval Mintz3cdeec22013-06-02 00:06:19 +000012428 .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
Ariel Elior3ec9f9c2013-03-11 05:17:45 +000012429 .ndo_get_vf_config = bnx2x_get_vf_config,
Ariel Elior64112802013-01-07 00:50:23 +000012430#endif
Merav Sicron55c11942012-11-07 00:45:48 +000012431#ifdef NETDEV_FCOE_WWNN
Vladislav Zolotarovbf61ee12011-07-21 07:56:51 +000012432 .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
12433#endif
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012434
Cong Wange0d10952013-08-01 11:10:25 +080012435#ifdef CONFIG_NET_RX_BUSY_POLL
Eliezer Tamir8b80cda2013-07-10 17:13:26 +030012436 .ndo_busy_poll = bnx2x_low_latency_recv,
Dmitry Kravkov8f20aa52013-06-19 01:36:04 +030012437#endif
Yuval Mintz3d7d5622013-10-09 16:06:28 +020012438 .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
Dmitry Kravkov6495d152014-06-26 14:31:04 +030012439 .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012440};
12441
Eric Dumazet1191cb82012-04-27 21:39:21 +000012442static int bnx2x_set_coherency_mask(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012443{
12444 struct device *dev = &bp->pdev->dev;
12445
Linus Torvalds8ceafbf2013-11-14 07:55:21 +090012446 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
12447 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012448 dev_err(dev, "System does not support DMA, aborting\n");
12449 return -EIO;
12450 }
12451
12452 return 0;
12453}
12454
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020012455static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
12456{
12457 if (bp->flags & AER_ENABLED) {
12458 pci_disable_pcie_error_reporting(bp->pdev);
12459 bp->flags &= ~AER_ENABLED;
12460 }
12461}
12462
Ariel Elior1ab44342013-01-01 05:22:23 +000012463static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12464 struct net_device *dev, unsigned long board_type)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012465{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012466 int rc;
Ariel Eliorc22610d02012-01-26 06:01:47 +000012467 u32 pci_cfg_dword;
Ariel Elior65087cf2012-01-23 07:31:55 +000012468 bool chip_is_e1x = (board_type == BCM57710 ||
12469 board_type == BCM57711 ||
12470 board_type == BCM57711E);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012471
12472 SET_NETDEV_DEV(dev, &pdev->dev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012473
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012474 bp->dev = dev;
12475 bp->pdev = pdev;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012476
12477 rc = pci_enable_device(pdev);
12478 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012479 dev_err(&bp->pdev->dev,
12480 "Cannot enable PCI device, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012481 goto err_out;
12482 }
12483
12484 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012485 dev_err(&bp->pdev->dev,
12486 "Cannot find PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012487 rc = -ENODEV;
12488 goto err_out_disable;
12489 }
12490
Ariel Elior1ab44342013-01-01 05:22:23 +000012491 if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
12492 dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012493 rc = -ENODEV;
12494 goto err_out_disable;
12495 }
12496
Yaniv Rosner092a5fc2012-12-02 23:56:49 +000012497 pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
12498 if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
12499 PCICFG_REVESION_ID_ERROR_VAL) {
12500 pr_err("PCI device error, probably due to fan failure, aborting\n");
12501 rc = -ENODEV;
12502 goto err_out_disable;
12503 }
12504
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012505 if (atomic_read(&pdev->enable_cnt) == 1) {
12506 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
12507 if (rc) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012508 dev_err(&bp->pdev->dev,
12509 "Cannot obtain PCI resources, aborting\n");
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012510 goto err_out_disable;
12511 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012512
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012513 pci_set_master(pdev);
12514 pci_save_state(pdev);
12515 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012516
Ariel Elior1ab44342013-01-01 05:22:23 +000012517 if (IS_PF(bp)) {
Jon Mason29ed74c2013-09-11 11:22:39 -070012518 if (!pdev->pm_cap) {
Ariel Elior1ab44342013-01-01 05:22:23 +000012519 dev_err(&bp->pdev->dev,
12520 "Cannot find power management capability, aborting\n");
12521 rc = -EIO;
12522 goto err_out_release;
12523 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012524 }
12525
Jon Mason77c98e62011-06-27 07:45:12 +000012526 if (!pci_is_pcie(pdev)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012527 dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012528 rc = -EIO;
12529 goto err_out_release;
12530 }
12531
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012532 rc = bnx2x_set_coherency_mask(bp);
12533 if (rc)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012534 goto err_out_release;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012535
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012536 dev->mem_start = pci_resource_start(pdev, 0);
12537 dev->base_addr = dev->mem_start;
12538 dev->mem_end = pci_resource_end(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012539
12540 dev->irq = pdev->irq;
12541
Arjan van de Ven275f1652008-10-20 21:42:39 -070012542 bp->regview = pci_ioremap_bar(pdev, 0);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012543 if (!bp->regview) {
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012544 dev_err(&bp->pdev->dev,
12545 "Cannot map register space, aborting\n");
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012546 rc = -ENOMEM;
12547 goto err_out_release;
12548 }
12549
Ariel Eliorc22610d02012-01-26 06:01:47 +000012550 /* In E1/E1H use pci device function given by kernel.
12551 * In E2/E3 read physical function from ME register since these chips
12552 * support Physical Device Assignment where kernel BDF maybe arbitrary
12553 * (depending on hypervisor).
12554 */
Yuval Mintz2de67432013-01-23 03:21:43 +000012555 if (chip_is_e1x) {
Ariel Eliorc22610d02012-01-26 06:01:47 +000012556 bp->pf_num = PCI_FUNC(pdev->devfn);
Yuval Mintz2de67432013-01-23 03:21:43 +000012557 } else {
12558 /* chip is E2/3*/
Ariel Eliorc22610d02012-01-26 06:01:47 +000012559 pci_read_config_dword(bp->pdev,
12560 PCICFG_ME_REGISTER, &pci_cfg_dword);
12561 bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
Yuval Mintz2de67432013-01-23 03:21:43 +000012562 ME_REG_ABS_PF_NUM_SHIFT);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012563 }
Merav Sicron51c1a582012-03-18 10:33:38 +000012564 BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
Ariel Eliorc22610d02012-01-26 06:01:47 +000012565
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012566 /* clean indirect addresses */
12567 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
12568 PCICFG_VENDOR_ID_OFFSET);
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020012569
12570 /* AER (Advanced Error reporting) configuration */
12571 rc = pci_enable_pcie_error_reporting(pdev);
12572 if (!rc)
12573 bp->flags |= AER_ENABLED;
12574 else
12575 BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
12576
David S. Miller8decf862011-09-22 03:23:13 -040012577 /*
12578 * Clean the following indirect addresses for all functions since it
David S. Miller823dcd22011-08-20 10:39:12 -070012579 * is not used by the driver.
12580 */
Ariel Elior1ab44342013-01-01 05:22:23 +000012581 if (IS_PF(bp)) {
12582 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
12583 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
12584 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
12585 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
David S. Miller8decf862011-09-22 03:23:13 -040012586
Ariel Elior1ab44342013-01-01 05:22:23 +000012587 if (chip_is_e1x) {
12588 REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
12589 REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
12590 REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
12591 REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
12592 }
12593
12594 /* Enable internal target-read (in case we are probed after PF
12595 * FLR). Must be done prior to any BAR read access. Only for
12596 * 57712 and up
12597 */
12598 if (!chip_is_e1x)
12599 REG_WR(bp,
12600 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
David S. Miller8decf862011-09-22 03:23:13 -040012601 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012602
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012603 dev->watchdog_timeo = TX_TIMEOUT;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012604
Stephen Hemmingerc64213c2008-11-21 17:36:04 -080012605 dev->netdev_ops = &bnx2x_netdev_ops;
Ariel Elior005a07ba2013-03-11 05:17:42 +000012606 bnx2x_set_ethtool_ops(bp, dev);
Michał Mirosław66371c42011-04-12 09:38:23 +000012607
Jiri Pirko01789342011-08-16 06:29:00 +000012608 dev->priv_flags |= IFF_UNICAST_FLT;
12609
Michał Mirosław66371c42011-04-12 09:38:23 +000012610 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
Dmitry Kravkov621b4d62012-02-20 09:59:08 +000012611 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
12612 NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +000012613 NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012614 if (!CHIP_IS_E1x(bp)) {
Eric Dumazet117401e2013-10-19 11:42:58 -070012615 dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Eric Dumazet2e3bd6a2013-10-20 20:47:31 -070012616 NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012617 dev->hw_enc_features =
12618 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
12619 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
Eric Dumazet117401e2013-10-19 11:42:58 -070012620 NETIF_F_GSO_IPIP |
Eric Dumazet2e3bd6a2013-10-20 20:47:31 -070012621 NETIF_F_GSO_SIT |
Dmitry Kravkov65bc0cf2013-04-28 08:16:02 +000012622 NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
Dmitry Kravkova848ade2013-03-18 06:51:03 +000012623 }
Michał Mirosław66371c42011-04-12 09:38:23 +000012624
12625 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
12626 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12627
Patrick McHardyf6469682013-04-19 02:04:27 +000012628 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
Merav Sicronedd31472013-10-20 16:51:34 +020012629 dev->features |= NETIF_F_HIGHDMA;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012630
Mahesh Bandewar538dd2e2011-05-13 15:08:49 +000012631 /* Add Loopback capability to the device */
12632 dev->hw_features |= NETIF_F_LOOPBACK;
12633
Shmulik Ravid98507672011-02-28 12:19:55 -080012634#ifdef BCM_DCBNL
Shmulik Ravid785b9b12010-12-30 06:27:03 +000012635 dev->dcbnl_ops = &bnx2x_dcbnl_ops;
12636#endif
12637
Eilon Greenstein01cd4522009-08-12 08:23:08 +000012638 /* get_port_hwinfo() will set prtad and mmds properly */
12639 bp->mdio.prtad = MDIO_PRTAD_NONE;
12640 bp->mdio.mmds = 0;
12641 bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
12642 bp->mdio.dev = dev;
12643 bp->mdio.mdio_read = bnx2x_mdio_read;
12644 bp->mdio.mdio_write = bnx2x_mdio_write;
12645
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012646 return 0;
12647
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012648err_out_release:
Eilon Greenstein34f80b02008-06-23 20:33:01 -070012649 if (atomic_read(&pdev->enable_cnt) == 1)
12650 pci_release_regions(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012651
12652err_out_disable:
12653 pci_disable_device(pdev);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020012654
12655err_out:
12656 return rc;
12657}
12658
Dmitry Kravkov6891dd22010-08-03 21:49:40 +000012659static int bnx2x_check_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012660{
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012661 const struct firmware *firmware = bp->firmware;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012662 struct bnx2x_fw_file_hdr *fw_hdr;
12663 struct bnx2x_fw_file_section *sections;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012664 u32 offset, len, num_ops;
Yuval Mintz86564c32013-01-23 03:21:50 +000012665 __be16 *ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012666 int i;
Eilon Greenstein37f9ce62009-08-12 08:23:34 +000012667 const u8 *fw_ver;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012668
Merav Sicron51c1a582012-03-18 10:33:38 +000012669 if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
12670 BNX2X_ERR("Wrong FW size\n");
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012671 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000012672 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012673
12674 fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
12675 sections = (struct bnx2x_fw_file_section *)fw_hdr;
12676
12677 /* Make sure none of the offsets and sizes make us read beyond
12678 * the end of the firmware data */
12679 for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
12680 offset = be32_to_cpu(sections[i].offset);
12681 len = be32_to_cpu(sections[i].len);
12682 if (offset + len > firmware->size) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012683 BNX2X_ERR("Section %d length is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012684 return -EINVAL;
12685 }
12686 }
12687
12688 /* Likewise for the init_ops offsets */
12689 offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
Yuval Mintz86564c32013-01-23 03:21:50 +000012690 ops_offsets = (__force __be16 *)(firmware->data + offset);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012691 num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
12692
12693 for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
12694 if (be16_to_cpu(ops_offsets[i]) > num_ops) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012695 BNX2X_ERR("Section offset %d is out of bounds\n", i);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012696 return -EINVAL;
12697 }
12698 }
12699
12700 /* Check FW version */
12701 offset = be32_to_cpu(fw_hdr->fw_version.offset);
12702 fw_ver = firmware->data + offset;
12703 if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
12704 (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
12705 (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
12706 (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000012707 BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
12708 fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
12709 BCM_5710_FW_MAJOR_VERSION,
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012710 BCM_5710_FW_MINOR_VERSION,
12711 BCM_5710_FW_REVISION_VERSION,
12712 BCM_5710_FW_ENGINEERING_VERSION);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012713 return -EINVAL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012714 }
12715
12716 return 0;
12717}
12718
Eric Dumazet1191cb82012-04-27 21:39:21 +000012719static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012720{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012721 const __be32 *source = (const __be32 *)_source;
12722 u32 *target = (u32 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012723 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012724
12725 for (i = 0; i < n/4; i++)
12726 target[i] = be32_to_cpu(source[i]);
12727}
12728
12729/*
12730 Ops array is stored in the following format:
12731 {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
12732 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012733static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012734{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012735 const __be32 *source = (const __be32 *)_source;
12736 struct raw_op *target = (struct raw_op *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012737 u32 i, j, tmp;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012738
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012739 for (i = 0, j = 0; i < n/8; i++, j += 2) {
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012740 tmp = be32_to_cpu(source[j]);
12741 target[i].op = (tmp >> 24) & 0xff;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000012742 target[i].offset = tmp & 0xffffff;
12743 target[i].raw_data = be32_to_cpu(source[j + 1]);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012744 }
12745}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012746
Ben Hutchings1aa8b472012-07-10 10:56:59 +000012747/* IRO array is stored in the following format:
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012748 * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
12749 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012750static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012751{
12752 const __be32 *source = (const __be32 *)_source;
12753 struct iro *target = (struct iro *)_target;
12754 u32 i, j, tmp;
12755
12756 for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
12757 target[i].base = be32_to_cpu(source[j]);
12758 j++;
12759 tmp = be32_to_cpu(source[j]);
12760 target[i].m1 = (tmp >> 16) & 0xffff;
12761 target[i].m2 = tmp & 0xffff;
12762 j++;
12763 tmp = be32_to_cpu(source[j]);
12764 target[i].m3 = (tmp >> 16) & 0xffff;
12765 target[i].size = tmp & 0xffff;
12766 j++;
12767 }
12768}
12769
Eric Dumazet1191cb82012-04-27 21:39:21 +000012770static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012771{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012772 const __be16 *source = (const __be16 *)_source;
12773 u16 *target = (u16 *)_target;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012774 u32 i;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012775
12776 for (i = 0; i < n/2; i++)
12777 target[i] = be16_to_cpu(source[i]);
12778}
12779
Joe Perches7995c642010-02-17 15:01:52 +000012780#define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
12781do { \
12782 u32 len = be32_to_cpu(fw_hdr->arr.len); \
12783 bp->arr = kmalloc(len, GFP_KERNEL); \
Joe Perchese404dec2012-01-29 12:56:23 +000012784 if (!bp->arr) \
Joe Perches7995c642010-02-17 15:01:52 +000012785 goto lbl; \
Joe Perches7995c642010-02-17 15:01:52 +000012786 func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
12787 (u8 *)bp->arr, len); \
12788} while (0)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012789
Yuval Mintz3b603062012-03-18 10:33:39 +000012790static int bnx2x_init_firmware(struct bnx2x *bp)
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012791{
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012792 const char *fw_file_name;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012793 struct bnx2x_fw_file_hdr *fw_hdr;
Ben Hutchings45229b42009-11-07 11:53:39 +000012794 int rc;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012795
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012796 if (bp->firmware)
12797 return 0;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012798
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012799 if (CHIP_IS_E1(bp))
12800 fw_file_name = FW_FILE_NAME_E1;
12801 else if (CHIP_IS_E1H(bp))
12802 fw_file_name = FW_FILE_NAME_E1H;
12803 else if (!CHIP_IS_E1x(bp))
12804 fw_file_name = FW_FILE_NAME_E2;
12805 else {
12806 BNX2X_ERR("Unsupported chip revision\n");
12807 return -EINVAL;
12808 }
12809 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012810
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012811 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
12812 if (rc) {
12813 BNX2X_ERR("Can't load firmware file %s\n",
12814 fw_file_name);
12815 goto request_firmware_exit;
12816 }
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012817
Michal Schmidtc0ea4522012-03-15 14:08:29 +000012818 rc = bnx2x_check_firmware(bp);
12819 if (rc) {
12820 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
12821 goto request_firmware_exit;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012822 }
12823
12824 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
12825
12826 /* Initialize the pointers to the init arrays */
12827 /* Blob */
12828 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
12829
12830 /* Opcodes */
12831 BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
12832
12833 /* Offsets */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012834 BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
12835 be16_to_cpu_n);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012836
12837 /* STORMs firmware */
Eilon Greenstein573f2032009-08-12 08:24:14 +000012838 INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12839 be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
12840 INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
12841 be32_to_cpu(fw_hdr->tsem_pram_data.offset);
12842 INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12843 be32_to_cpu(fw_hdr->usem_int_table_data.offset);
12844 INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
12845 be32_to_cpu(fw_hdr->usem_pram_data.offset);
12846 INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12847 be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
12848 INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
12849 be32_to_cpu(fw_hdr->xsem_pram_data.offset);
12850 INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
12851 be32_to_cpu(fw_hdr->csem_int_table_data.offset);
12852 INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
12853 be32_to_cpu(fw_hdr->csem_pram_data.offset);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012854 /* IRO */
12855 BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012856
12857 return 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +000012858
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012859iro_alloc_err:
12860 kfree(bp->init_ops_offsets);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012861init_offsets_alloc_err:
12862 kfree(bp->init_ops);
12863init_ops_alloc_err:
12864 kfree(bp->init_data);
12865request_firmware_exit:
12866 release_firmware(bp->firmware);
Michal Schmidt127d0a12012-03-15 14:08:28 +000012867 bp->firmware = NULL;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012868
12869 return rc;
12870}
12871
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012872static void bnx2x_release_firmware(struct bnx2x *bp)
12873{
12874 kfree(bp->init_ops_offsets);
12875 kfree(bp->init_ops);
12876 kfree(bp->init_data);
12877 release_firmware(bp->firmware);
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +000012878 bp->firmware = NULL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012879}
12880
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012881static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
12882 .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
12883 .init_hw_cmn = bnx2x_init_hw_common,
12884 .init_hw_port = bnx2x_init_hw_port,
12885 .init_hw_func = bnx2x_init_hw_func,
12886
12887 .reset_hw_cmn = bnx2x_reset_common,
12888 .reset_hw_port = bnx2x_reset_port,
12889 .reset_hw_func = bnx2x_reset_func,
12890
12891 .gunzip_init = bnx2x_gunzip_init,
12892 .gunzip_end = bnx2x_gunzip_end,
12893
12894 .init_fw = bnx2x_init_firmware,
12895 .release_fw = bnx2x_release_firmware,
12896};
12897
12898void bnx2x__init_func_obj(struct bnx2x *bp)
12899{
12900 /* Prepare DMAE related driver resources */
12901 bnx2x_setup_dmae(bp);
12902
12903 bnx2x_init_func_obj(bp, &bp->func_obj,
12904 bnx2x_sp(bp, func_rdata),
12905 bnx2x_sp_mapping(bp, func_rdata),
Barak Witkowskia3348722012-04-23 03:04:46 +000012906 bnx2x_sp(bp, func_afex_rdata),
12907 bnx2x_sp_mapping(bp, func_afex_rdata),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012908 &bnx2x_func_sp_drv);
12909}
12910
12911/* must be called after sriov-enable */
Eric Dumazet1191cb82012-04-27 21:39:21 +000012912static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012913{
Merav Sicron37ae41a2012-06-19 07:48:27 +000012914 int cid_count = BNX2X_L2_MAX_CID(bp);
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070012915
Ariel Elior290ca2b2013-01-01 05:22:31 +000012916 if (IS_SRIOV(bp))
12917 cid_count += BNX2X_VF_CIDS;
12918
Merav Sicron55c11942012-11-07 00:45:48 +000012919 if (CNIC_SUPPORT(bp))
12920 cid_count += CNIC_CID_MAX;
Ariel Elior290ca2b2013-01-01 05:22:31 +000012921
Dmitry Kravkov523224a2010-10-06 03:23:26 +000012922 return roundup(cid_count, QM_CID_ROUND);
12923}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000012924
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012925/**
Ariel Elior6383c0b2011-07-14 08:31:57 +000012926 * bnx2x_get_num_none_def_sbs - return the number of none default SBs
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012927 *
12928 * @dev: pci device
12929 *
12930 */
Ariel Elior60cad4e2013-09-04 14:09:22 +030012931static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012932{
Yijing Wangae2104b2013-08-08 21:02:36 +080012933 int index;
Ariel Elior1ab44342013-01-01 05:22:23 +000012934 u16 control = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012935
Ariel Elior6383c0b2011-07-14 08:31:57 +000012936 /*
12937 * If MSI-X is not supported - return number of SBs needed to support
12938 * one fast path queue: one FP queue + SB for CNIC
12939 */
Yijing Wangae2104b2013-08-08 21:02:36 +080012940 if (!pdev->msix_cap) {
Ariel Elior1ab44342013-01-01 05:22:23 +000012941 dev_info(&pdev->dev, "no msix capability found\n");
Merav Sicron55c11942012-11-07 00:45:48 +000012942 return 1 + cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000012943 }
12944 dev_info(&pdev->dev, "msix capability found\n");
Ariel Elior6383c0b2011-07-14 08:31:57 +000012945
12946 /*
12947 * The value in the PCI configuration space is the index of the last
12948 * entry, namely one less than the actual size of the table, which is
12949 * exactly what we want to return from this function: number of all SBs
12950 * without the default SB.
Ariel Elior1ab44342013-01-01 05:22:23 +000012951 * For VFs there is no default SB, then we return (index+1).
Ariel Elior6383c0b2011-07-14 08:31:57 +000012952 */
Yijing Wang73413ff2014-06-25 12:22:56 +080012953 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
Ariel Elior1ab44342013-01-01 05:22:23 +000012954
12955 index = control & PCI_MSIX_FLAGS_QSIZE;
12956
Ariel Elior60cad4e2013-09-04 14:09:22 +030012957 return index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030012958}
12959
Ariel Elior1ab44342013-01-01 05:22:23 +000012960static int set_max_cos_est(int chip_id)
12961{
12962 switch (chip_id) {
12963 case BCM57710:
12964 case BCM57711:
12965 case BCM57711E:
12966 return BNX2X_MULTI_TX_COS_E1X;
12967 case BCM57712:
12968 case BCM57712_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012969 return BNX2X_MULTI_TX_COS_E2_E3A0;
12970 case BCM57800:
12971 case BCM57800_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012972 case BCM57810:
12973 case BCM57810_MF:
12974 case BCM57840_4_10:
12975 case BCM57840_2_20:
12976 case BCM57840_O:
12977 case BCM57840_MFO:
Ariel Elior1ab44342013-01-01 05:22:23 +000012978 case BCM57840_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012979 case BCM57811:
12980 case BCM57811_MF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012981 return BNX2X_MULTI_TX_COS_E3B0;
Yuval Mintzb1239722013-10-20 16:51:26 +020012982 case BCM57712_VF:
12983 case BCM57800_VF:
12984 case BCM57810_VF:
12985 case BCM57840_VF:
12986 case BCM57811_VF:
Ariel Elior1ab44342013-01-01 05:22:23 +000012987 return 1;
12988 default:
12989 pr_err("Unknown board_type (%d), aborting\n", chip_id);
12990 return -ENODEV;
12991 }
12992}
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000012993
Ariel Elior1ab44342013-01-01 05:22:23 +000012994static int set_is_vf(int chip_id)
12995{
12996 switch (chip_id) {
12997 case BCM57712_VF:
12998 case BCM57800_VF:
12999 case BCM57810_VF:
13000 case BCM57840_VF:
13001 case BCM57811_VF:
13002 return true;
13003 default:
13004 return false;
13005 }
13006}
13007
Ariel Elior1ab44342013-01-01 05:22:23 +000013008static int bnx2x_init_one(struct pci_dev *pdev,
13009 const struct pci_device_id *ent)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013010{
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013011 struct net_device *dev = NULL;
13012 struct bnx2x *bp;
Yuval Mintzb91e1a12013-09-28 08:46:12 +030013013 enum pcie_link_width pcie_width;
13014 enum pci_bus_speed pcie_speed;
Ariel Elior6383c0b2011-07-14 08:31:57 +000013015 int rc, max_non_def_sbs;
Merav Sicron65565882012-06-19 07:48:26 +000013016 int rx_count, tx_count, rss_count, doorbell_size;
Ariel Elior1ab44342013-01-01 05:22:23 +000013017 int max_cos_est;
13018 bool is_vf;
Merav Sicron55c11942012-11-07 00:45:48 +000013019 int cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000013020
13021 /* An estimated maximum supported CoS number according to the chip
Ariel Elior6383c0b2011-07-14 08:31:57 +000013022 * version.
13023 * We will try to roughly estimate the maximum number of CoSes this chip
13024 * may support in order to minimize the memory allocated for Tx
13025 * netdev_queue's. This number will be accurately calculated during the
13026 * initialization of bp->max_cos based on the chip versions AND chip
13027 * revision in the bnx2x_init_bp().
13028 */
Ariel Elior1ab44342013-01-01 05:22:23 +000013029 max_cos_est = set_max_cos_est(ent->driver_data);
13030 if (max_cos_est < 0)
13031 return max_cos_est;
13032 is_vf = set_is_vf(ent->driver_data);
13033 cnic_cnt = is_vf ? 0 : 1;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013034
Ariel Elior60cad4e2013-09-04 14:09:22 +030013035 max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
13036
13037 /* add another SB for VF as it has no default SB */
13038 max_non_def_sbs += is_vf ? 1 : 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +000013039
13040 /* Maximum number of RSS queues: one IGU SB goes to CNIC */
Ariel Elior60cad4e2013-09-04 14:09:22 +030013041 rss_count = max_non_def_sbs - cnic_cnt;
Ariel Elior1ab44342013-01-01 05:22:23 +000013042
13043 if (rss_count < 1)
13044 return -EINVAL;
Ariel Elior6383c0b2011-07-14 08:31:57 +000013045
13046 /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
Merav Sicron55c11942012-11-07 00:45:48 +000013047 rx_count = rss_count + cnic_cnt;
Ariel Elior6383c0b2011-07-14 08:31:57 +000013048
Ariel Elior1ab44342013-01-01 05:22:23 +000013049 /* Maximum number of netdev Tx queues:
Merav Sicron37ae41a2012-06-19 07:48:27 +000013050 * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
Ariel Elior6383c0b2011-07-14 08:31:57 +000013051 */
Merav Sicron55c11942012-11-07 00:45:48 +000013052 tx_count = rss_count * max_cos_est + cnic_cnt;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000013053
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013054 /* dev zeroed in init_etherdev */
Ariel Elior6383c0b2011-07-14 08:31:57 +000013055 dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
Joe Perches41de8d42012-01-29 13:47:52 +000013056 if (!dev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013057 return -ENOMEM;
13058
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013059 bp = netdev_priv(dev);
Ariel Elior6383c0b2011-07-14 08:31:57 +000013060
Ariel Elior1ab44342013-01-01 05:22:23 +000013061 bp->flags = 0;
13062 if (is_vf)
13063 bp->flags |= IS_VF_FLAG;
13064
Ariel Elior6383c0b2011-07-14 08:31:57 +000013065 bp->igu_sb_cnt = max_non_def_sbs;
Ariel Elior1ab44342013-01-01 05:22:23 +000013066 bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
Joe Perches7995c642010-02-17 15:01:52 +000013067 bp->msg_enable = debug;
Merav Sicron55c11942012-11-07 00:45:48 +000013068 bp->cnic_support = cnic_cnt;
Michael Chan4bd9b0ff2012-12-06 10:33:12 +000013069 bp->cnic_probe = bnx2x_cnic_probe;
Merav Sicron55c11942012-11-07 00:45:48 +000013070
Eilon Greensteindf4770de2009-08-12 08:23:28 +000013071 pci_set_drvdata(pdev, dev);
13072
Ariel Elior1ab44342013-01-01 05:22:23 +000013073 rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013074 if (rc < 0) {
13075 free_netdev(dev);
13076 return rc;
13077 }
13078
Ariel Elior1ab44342013-01-01 05:22:23 +000013079 BNX2X_DEV_INFO("This is a %s function\n",
13080 IS_PF(bp) ? "physical" : "virtual");
Merav Sicron55c11942012-11-07 00:45:48 +000013081 BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
Ariel Elior1ab44342013-01-01 05:22:23 +000013082 BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
Merav Sicron60aa0502012-06-19 07:48:29 +000013083 BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
Yuval Mintz2de67432013-01-23 03:21:43 +000013084 tx_count, rx_count);
Merav Sicron60aa0502012-06-19 07:48:29 +000013085
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013086 rc = bnx2x_init_bp(bp);
Eilon Greenstein693fc0d2009-01-14 06:43:52 +000013087 if (rc)
13088 goto init_one_exit;
13089
Ariel Elior1ab44342013-01-01 05:22:23 +000013090 /* Map doorbells here as we need the real value of bp->max_cos which
13091 * is initialized in bnx2x_init_bp() to determine the number of
13092 * l2 connections.
Ariel Elior6383c0b2011-07-14 08:31:57 +000013093 */
Ariel Elior1ab44342013-01-01 05:22:23 +000013094 if (IS_VF(bp)) {
Dmitry Kravkov1d6f3cd2013-03-27 01:05:17 +000013095 bp->doorbells = bnx2x_vf_doorbells(bp);
Ariel Elior64112802013-01-07 00:50:23 +000013096 rc = bnx2x_vf_pci_alloc(bp);
13097 if (rc)
13098 goto init_one_exit;
Ariel Elior1ab44342013-01-01 05:22:23 +000013099 } else {
13100 doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
13101 if (doorbell_size > pci_resource_len(pdev, 2)) {
13102 dev_err(&bp->pdev->dev,
13103 "Cannot map doorbells, bar size too small, aborting\n");
13104 rc = -ENOMEM;
13105 goto init_one_exit;
13106 }
13107 bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
13108 doorbell_size);
Merav Sicron37ae41a2012-06-19 07:48:27 +000013109 }
Ariel Elior6383c0b2011-07-14 08:31:57 +000013110 if (!bp->doorbells) {
13111 dev_err(&bp->pdev->dev,
13112 "Cannot map doorbell space, aborting\n");
13113 rc = -ENOMEM;
13114 goto init_one_exit;
13115 }
13116
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000013117 if (IS_VF(bp)) {
13118 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
13119 if (rc)
13120 goto init_one_exit;
13121 }
13122
Ariel Elior3c76fef2013-03-11 05:17:46 +000013123 /* Enable SRIOV if capability found in configuration space */
13124 rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
Ariel Elior290ca2b2013-01-01 05:22:31 +000013125 if (rc)
13126 goto init_one_exit;
13127
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013128 /* calc qm_cid_count */
Ariel Elior6383c0b2011-07-14 08:31:57 +000013129 bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
Ariel Elior1ab44342013-01-01 05:22:23 +000013130 BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013131
Merav Sicron55c11942012-11-07 00:45:48 +000013132 /* disable FCOE L2 queue for E1x*/
Dmitry Kravkov62ac0dc2011-11-13 04:34:21 +000013133 if (CHIP_IS_E1x(bp))
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013134 bp->flags |= NO_FCOE_FLAG;
13135
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000013136 /* Set bp->num_queues for MSI-X mode*/
13137 bnx2x_set_num_queues(bp);
13138
Lucas De Marchi25985ed2011-03-30 22:57:33 -030013139 /* Configure interrupt mode: try to enable MSI-X/MSI if
Merav Sicron0e8d2ec2012-06-19 07:48:30 +000013140 * needed.
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000013141 */
Ariel Elior1ab44342013-01-01 05:22:23 +000013142 rc = bnx2x_set_int_mode(bp);
13143 if (rc) {
13144 dev_err(&pdev->dev, "Cannot set interrupts\n");
13145 goto init_one_exit;
13146 }
Yuval Mintz04c46732013-01-23 03:21:46 +000013147 BNX2X_DEV_INFO("set interrupts successfully\n");
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000013148
Ariel Elior1ab44342013-01-01 05:22:23 +000013149 /* register the net device */
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080013150 rc = register_netdev(dev);
13151 if (rc) {
13152 dev_err(&pdev->dev, "Cannot register net device\n");
13153 goto init_one_exit;
13154 }
Ariel Elior1ab44342013-01-01 05:22:23 +000013155 BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
Vladislav Zolotarovb3400072010-11-24 11:09:50 -080013156
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013157 if (!NO_FCOE(bp)) {
13158 /* Add storage MAC address */
13159 rtnl_lock();
13160 dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13161 rtnl_unlock();
13162 }
Yuval Mintzb91e1a12013-09-28 08:46:12 +030013163 if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
13164 pcie_speed == PCI_SPEED_UNKNOWN ||
13165 pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
13166 BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
13167 else
13168 BNX2X_DEV_INFO(
13169 "%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 +000013170 board_info[ent->driver_data].name,
13171 (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
13172 pcie_width,
Yuval Mintzb91e1a12013-09-28 08:46:12 +030013173 pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
13174 pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
13175 pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
Dmitry Kravkovca1ee4b2013-05-27 04:08:27 +000013176 "Unknown",
13177 dev->base_addr, bp->pdev->irq, dev->dev_addr);
Eilon Greensteinc0162012009-03-02 08:01:05 +000013178
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013179 return 0;
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013180
13181init_one_exit:
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013182 bnx2x_disable_pcie_error_reporting(bp);
13183
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013184 if (bp->regview)
13185 iounmap(bp->regview);
13186
Ariel Elior1ab44342013-01-01 05:22:23 +000013187 if (IS_PF(bp) && bp->doorbells)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013188 iounmap(bp->doorbells);
13189
13190 free_netdev(dev);
13191
13192 if (atomic_read(&pdev->enable_cnt) == 1)
13193 pci_release_regions(pdev);
13194
13195 pci_disable_device(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013196
13197 return rc;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013198}
13199
Yuval Mintzb030ed22013-05-27 04:08:30 +000013200static void __bnx2x_remove(struct pci_dev *pdev,
13201 struct net_device *dev,
13202 struct bnx2x *bp,
13203 bool remove_netdev)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013204{
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013205 /* Delete storage MAC address */
13206 if (!NO_FCOE(bp)) {
13207 rtnl_lock();
13208 dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
13209 rtnl_unlock();
13210 }
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013211
Shmulik Ravid98507672011-02-28 12:19:55 -080013212#ifdef BCM_DCBNL
13213 /* Delete app tlvs from dcbnl */
13214 bnx2x_dcbnl_update_applist(bp, true);
13215#endif
13216
Barak Witkowskya6d3a5b2013-08-13 02:25:02 +030013217 if (IS_PF(bp) &&
13218 !BP_NOMCP(bp) &&
13219 (bp->flags & BC_SUPPORTS_RMMOD_CMD))
13220 bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
13221
Yuval Mintzb030ed22013-05-27 04:08:30 +000013222 /* Close the interface - either directly or implicitly */
13223 if (remove_netdev) {
13224 unregister_netdev(dev);
13225 } else {
13226 rtnl_lock();
Yuval Mintz6ef5a922013-08-13 02:25:03 +030013227 dev_close(dev);
Yuval Mintzb030ed22013-05-27 04:08:30 +000013228 rtnl_unlock();
13229 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013230
Ariel Elior78c3bcc2013-06-20 17:39:08 +030013231 bnx2x_iov_remove_one(bp);
13232
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013233 /* Power on: we can't let PCI layer write to us while we are in D3 */
Ariel Elior1ab44342013-01-01 05:22:23 +000013234 if (IS_PF(bp))
13235 bnx2x_set_power_state(bp, PCI_D0);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013236
Dmitry Kravkovd6214d72010-10-06 03:32:10 +000013237 /* Disable MSI/MSI-X */
13238 bnx2x_disable_msi(bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +000013239
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013240 /* Power off */
Ariel Elior1ab44342013-01-01 05:22:23 +000013241 if (IS_PF(bp))
13242 bnx2x_set_power_state(bp, PCI_D3hot);
Vladislav Zolotarov084d6cb2011-01-09 02:20:19 +000013243
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013244 /* Make sure RESET task is not scheduled before continuing */
Ariel Elior7be08a72011-07-14 08:31:19 +000013245 cancel_delayed_work_sync(&bp->sp_rtnl_task);
Ariel Elior290ca2b2013-01-01 05:22:31 +000013246
Ariel Elior4513f922013-01-01 05:22:25 +000013247 /* send message via vfpf channel to release the resources of this vf */
13248 if (IS_VF(bp))
13249 bnx2x_vfpf_release(bp);
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013250
Yuval Mintzb030ed22013-05-27 04:08:30 +000013251 /* Assumes no further PCIe PM changes will occur */
13252 if (system_state == SYSTEM_POWER_OFF) {
13253 pci_wake_from_d3(pdev, bp->wol);
13254 pci_set_power_state(pdev, PCI_D3hot);
13255 }
13256
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013257 bnx2x_disable_pcie_error_reporting(bp);
Yuval Mintzd9aee592014-01-15 12:05:30 +020013258 if (remove_netdev) {
13259 if (bp->regview)
13260 iounmap(bp->regview);
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013261
Yuval Mintzd9aee592014-01-15 12:05:30 +020013262 /* For vfs, doorbells are part of the regview and were unmapped
13263 * along with it. FW is only loaded by PF.
13264 */
13265 if (IS_PF(bp)) {
13266 if (bp->doorbells)
13267 iounmap(bp->doorbells);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013268
Yuval Mintzd9aee592014-01-15 12:05:30 +020013269 bnx2x_release_firmware(bp);
Yuval Mintze2a367f2014-04-24 19:29:52 +030013270 } else {
13271 bnx2x_vf_pci_dealloc(bp);
Yuval Mintzd9aee592014-01-15 12:05:30 +020013272 }
13273 bnx2x_free_mem_bp(bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013274
Yuval Mintzb030ed22013-05-27 04:08:30 +000013275 free_netdev(dev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013276
Yuval Mintzd9aee592014-01-15 12:05:30 +020013277 if (atomic_read(&pdev->enable_cnt) == 1)
13278 pci_release_regions(pdev);
Eilon Greenstein34f80b02008-06-23 20:33:01 -070013279
Yuval Mintz5f6db132014-01-27 17:11:58 +020013280 pci_disable_device(pdev);
13281 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013282}
13283
Yuval Mintzb030ed22013-05-27 04:08:30 +000013284static void bnx2x_remove_one(struct pci_dev *pdev)
13285{
13286 struct net_device *dev = pci_get_drvdata(pdev);
13287 struct bnx2x *bp;
13288
13289 if (!dev) {
13290 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
13291 return;
13292 }
13293 bp = netdev_priv(dev);
13294
13295 __bnx2x_remove(pdev, dev, bp, true);
13296}
13297
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013298static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
13299{
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013300 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013301
13302 bp->rx_mode = BNX2X_RX_MODE_NONE;
13303
Merav Sicron55c11942012-11-07 00:45:48 +000013304 if (CNIC_LOADED(bp))
13305 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
13306
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013307 /* Stop Tx */
13308 bnx2x_tx_disable(bp);
Merav Sicron26614ba2012-08-27 03:26:19 +000013309 /* Delete all NAPI objects */
13310 bnx2x_del_all_napi(bp);
Merav Sicron55c11942012-11-07 00:45:48 +000013311 if (CNIC_LOADED(bp))
13312 bnx2x_del_all_napi_cnic(bp);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013313 netdev_reset_tc(bp->dev);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013314
13315 del_timer_sync(&bp->timer);
wenxiong@linux.vnet.ibm.com0c0e6342014-06-03 14:14:45 -050013316 cancel_delayed_work_sync(&bp->sp_task);
13317 cancel_delayed_work_sync(&bp->period_task);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013318
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013319 spin_lock_bh(&bp->stats_lock);
13320 bp->stats_state = STATS_STATE_DISABLED;
13321 spin_unlock_bh(&bp->stats_lock);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013322
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013323 bnx2x_save_statistics(bp);
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013324
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013325 netif_carrier_off(bp->dev);
13326
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013327 return 0;
13328}
13329
Wendy Xiong493adb12008-06-23 20:36:22 -070013330/**
13331 * bnx2x_io_error_detected - called when PCI error is detected
13332 * @pdev: Pointer to PCI device
13333 * @state: The current pci connection state
13334 *
13335 * This function is called after a PCI bus error affecting
13336 * this device has been detected.
13337 */
13338static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
13339 pci_channel_state_t state)
13340{
13341 struct net_device *dev = pci_get_drvdata(pdev);
13342 struct bnx2x *bp = netdev_priv(dev);
13343
13344 rtnl_lock();
13345
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013346 BNX2X_ERR("IO error detected\n");
13347
Wendy Xiong493adb12008-06-23 20:36:22 -070013348 netif_device_detach(dev);
13349
Dean Nelson07ce50e42009-07-31 09:13:25 +000013350 if (state == pci_channel_io_perm_failure) {
13351 rtnl_unlock();
13352 return PCI_ERS_RESULT_DISCONNECT;
13353 }
13354
Wendy Xiong493adb12008-06-23 20:36:22 -070013355 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013356 bnx2x_eeh_nic_unload(bp);
Wendy Xiong493adb12008-06-23 20:36:22 -070013357
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013358 bnx2x_prev_path_mark_eeh(bp);
13359
Wendy Xiong493adb12008-06-23 20:36:22 -070013360 pci_disable_device(pdev);
13361
13362 rtnl_unlock();
13363
13364 /* Request a slot reset */
13365 return PCI_ERS_RESULT_NEED_RESET;
13366}
13367
13368/**
13369 * bnx2x_io_slot_reset - called after the PCI bus has been reset
13370 * @pdev: Pointer to PCI device
13371 *
13372 * Restart the card from scratch, as if from a cold-boot.
13373 */
13374static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
13375{
13376 struct net_device *dev = pci_get_drvdata(pdev);
13377 struct bnx2x *bp = netdev_priv(dev);
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013378 int i;
Wendy Xiong493adb12008-06-23 20:36:22 -070013379
13380 rtnl_lock();
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013381 BNX2X_ERR("IO slot reset initializing...\n");
Wendy Xiong493adb12008-06-23 20:36:22 -070013382 if (pci_enable_device(pdev)) {
13383 dev_err(&pdev->dev,
13384 "Cannot re-enable PCI device after reset\n");
13385 rtnl_unlock();
13386 return PCI_ERS_RESULT_DISCONNECT;
13387 }
13388
13389 pci_set_master(pdev);
13390 pci_restore_state(pdev);
Yuval Mintz70632d02013-04-24 01:45:02 +000013391 pci_save_state(pdev);
Wendy Xiong493adb12008-06-23 20:36:22 -070013392
13393 if (netif_running(dev))
13394 bnx2x_set_power_state(bp, PCI_D0);
13395
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013396 if (netif_running(dev)) {
13397 BNX2X_ERR("IO slot reset --> driver unload\n");
Yuval Mintze68072e2013-05-22 21:21:51 +000013398
13399 /* MCP should have been reset; Need to wait for validity */
13400 bnx2x_init_shmem(bp);
13401
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013402 if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
13403 u32 v;
13404
13405 v = SHMEM2_RD(bp,
13406 drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
13407 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
13408 v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
13409 }
13410 bnx2x_drain_tx_queues(bp);
13411 bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
13412 bnx2x_netif_stop(bp, 1);
13413 bnx2x_free_irq(bp);
13414
13415 /* Report UNLOAD_DONE to MCP */
13416 bnx2x_send_unload_done(bp, true);
13417
13418 bp->sp_state = 0;
13419 bp->port.pmf = 0;
13420
13421 bnx2x_prev_unload(bp);
13422
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013423 /* We should have reseted the engine, so It's fair to
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013424 * assume the FW will no longer write to the bnx2x driver.
13425 */
13426 bnx2x_squeeze_objects(bp);
13427 bnx2x_free_skbs(bp);
13428 for_each_rx_queue(bp, i)
13429 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
13430 bnx2x_free_fp_mem(bp);
13431 bnx2x_free_mem(bp);
13432
13433 bp->state = BNX2X_STATE_CLOSED;
13434 }
13435
Wendy Xiong493adb12008-06-23 20:36:22 -070013436 rtnl_unlock();
13437
Yuval Mintz33d8e6a2013-12-26 09:57:08 +020013438 /* If AER, perform cleanup of the PCIe registers */
13439 if (bp->flags & AER_ENABLED) {
13440 if (pci_cleanup_aer_uncorrect_error_status(pdev))
13441 BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
13442 else
13443 DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
13444 }
13445
Wendy Xiong493adb12008-06-23 20:36:22 -070013446 return PCI_ERS_RESULT_RECOVERED;
13447}
13448
13449/**
13450 * bnx2x_io_resume - called when traffic can start flowing again
13451 * @pdev: Pointer to PCI device
13452 *
13453 * This callback is called when the error recovery driver tells us that
13454 * its OK to resume normal operation.
13455 */
13456static void bnx2x_io_resume(struct pci_dev *pdev)
13457{
13458 struct net_device *dev = pci_get_drvdata(pdev);
13459 struct bnx2x *bp = netdev_priv(dev);
13460
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013461 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013462 netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +000013463 return;
13464 }
13465
Wendy Xiong493adb12008-06-23 20:36:22 -070013466 rtnl_lock();
13467
Yuval Mintz7fa6f3402013-03-20 05:21:28 +000013468 bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
13469 DRV_MSG_SEQ_NUMBER_MASK;
13470
Wendy Xiong493adb12008-06-23 20:36:22 -070013471 if (netif_running(dev))
Yitchak Gertnerf8ef6e42008-09-09 05:07:25 -070013472 bnx2x_nic_load(bp, LOAD_NORMAL);
Wendy Xiong493adb12008-06-23 20:36:22 -070013473
13474 netif_device_attach(dev);
13475
13476 rtnl_unlock();
13477}
13478
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070013479static const struct pci_error_handlers bnx2x_err_handler = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013480 .error_detected = bnx2x_io_error_detected,
Eilon Greenstein356e2382009-02-12 08:38:32 +000013481 .slot_reset = bnx2x_io_slot_reset,
13482 .resume = bnx2x_io_resume,
Wendy Xiong493adb12008-06-23 20:36:22 -070013483};
13484
Yuval Mintzb030ed22013-05-27 04:08:30 +000013485static void bnx2x_shutdown(struct pci_dev *pdev)
13486{
13487 struct net_device *dev = pci_get_drvdata(pdev);
13488 struct bnx2x *bp;
13489
13490 if (!dev)
13491 return;
13492
13493 bp = netdev_priv(dev);
13494 if (!bp)
13495 return;
13496
13497 rtnl_lock();
13498 netif_device_detach(dev);
13499 rtnl_unlock();
13500
13501 /* Don't remove the netdevice, as there are scenarios which will cause
13502 * the kernel to hang, e.g., when trying to remove bnx2i while the
13503 * rootfs is mounted from SAN.
13504 */
13505 __bnx2x_remove(pdev, dev, bp, false);
13506}
13507
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013508static struct pci_driver bnx2x_pci_driver = {
Wendy Xiong493adb12008-06-23 20:36:22 -070013509 .name = DRV_MODULE_NAME,
13510 .id_table = bnx2x_pci_tbl,
13511 .probe = bnx2x_init_one,
Bill Pemberton0329aba2012-12-03 09:24:24 -050013512 .remove = bnx2x_remove_one,
Wendy Xiong493adb12008-06-23 20:36:22 -070013513 .suspend = bnx2x_suspend,
13514 .resume = bnx2x_resume,
13515 .err_handler = &bnx2x_err_handler,
Ariel Elior3c76fef2013-03-11 05:17:46 +000013516#ifdef CONFIG_BNX2X_SRIOV
13517 .sriov_configure = bnx2x_sriov_configure,
13518#endif
Yuval Mintzb030ed22013-05-27 04:08:30 +000013519 .shutdown = bnx2x_shutdown,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013520};
13521
13522static int __init bnx2x_init(void)
13523{
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013524 int ret;
13525
Joe Perches7995c642010-02-17 15:01:52 +000013526 pr_info("%s", version);
Eilon Greenstein938cf542009-08-12 08:23:37 +000013527
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013528 bnx2x_wq = create_singlethread_workqueue("bnx2x");
13529 if (bnx2x_wq == NULL) {
Joe Perches7995c642010-02-17 15:01:52 +000013530 pr_err("Cannot create workqueue\n");
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013531 return -ENOMEM;
13532 }
Yuval Mintz370d4a22014-03-23 18:12:24 +020013533 bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
13534 if (!bnx2x_iov_wq) {
13535 pr_err("Cannot create iov workqueue\n");
13536 destroy_workqueue(bnx2x_wq);
13537 return -ENOMEM;
13538 }
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013539
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013540 ret = pci_register_driver(&bnx2x_pci_driver);
13541 if (ret) {
Joe Perches7995c642010-02-17 15:01:52 +000013542 pr_err("Cannot register driver\n");
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013543 destroy_workqueue(bnx2x_wq);
Yuval Mintz370d4a22014-03-23 18:12:24 +020013544 destroy_workqueue(bnx2x_iov_wq);
Stanislaw Gruszkadd21ca62009-05-05 23:22:01 +000013545 }
13546 return ret;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013547}
13548
13549static void __exit bnx2x_cleanup(void)
13550{
Yuval Mintz452427b2012-03-26 20:47:07 +000013551 struct list_head *pos, *q;
Yuval Mintzd76a6112013-06-02 00:06:17 +000013552
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013553 pci_unregister_driver(&bnx2x_pci_driver);
Eilon Greenstein1cf167f2009-01-14 21:22:18 -080013554
13555 destroy_workqueue(bnx2x_wq);
Yuval Mintz370d4a22014-03-23 18:12:24 +020013556 destroy_workqueue(bnx2x_iov_wq);
Yuval Mintz452427b2012-03-26 20:47:07 +000013557
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013558 /* Free globally allocated resources */
Yuval Mintz452427b2012-03-26 20:47:07 +000013559 list_for_each_safe(pos, q, &bnx2x_prev_list) {
13560 struct bnx2x_prev_path_list *tmp =
13561 list_entry(pos, struct bnx2x_prev_path_list, list);
13562 list_del(pos);
13563 kfree(tmp);
13564 }
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013565}
13566
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013567void bnx2x_notify_link_changed(struct bnx2x *bp)
13568{
13569 REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
13570}
13571
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020013572module_init(bnx2x_init);
13573module_exit(bnx2x_cleanup);
13574
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013575/**
13576 * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
13577 *
13578 * @bp: driver handle
13579 * @set: set or clear the CAM entry
13580 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +000013581 * This function will wait until the ramrod completion returns.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013582 * Return 0 if success, -ENODEV if ramrod doesn't return.
13583 */
Eric Dumazet1191cb82012-04-27 21:39:21 +000013584static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013585{
13586 unsigned long ramrod_flags = 0;
13587
13588 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
13589 return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
13590 &bp->iscsi_l2_mac_obj, true,
13591 BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
13592}
Michael Chan993ac7b2009-10-10 13:46:56 +000013593
13594/* count denotes the number of new completions we have seen */
13595static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
13596{
13597 struct eth_spe *spe;
Merav Sicrona0529972012-06-19 07:48:25 +000013598 int cxt_index, cxt_offset;
Michael Chan993ac7b2009-10-10 13:46:56 +000013599
13600#ifdef BNX2X_STOP_ON_ERROR
13601 if (unlikely(bp->panic))
13602 return;
13603#endif
13604
13605 spin_lock_bh(&bp->spq_lock);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013606 BUG_ON(bp->cnic_spq_pending < count);
Michael Chan993ac7b2009-10-10 13:46:56 +000013607 bp->cnic_spq_pending -= count;
13608
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013609 for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
13610 u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
13611 & SPE_HDR_CONN_TYPE) >>
13612 SPE_HDR_CONN_TYPE_SHIFT;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013613 u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
13614 >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013615
13616 /* Set validation for iSCSI L2 client before sending SETUP
13617 * ramrod
13618 */
13619 if (type == ETH_CONNECTION_TYPE) {
Merav Sicrona0529972012-06-19 07:48:25 +000013620 if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
Merav Sicron37ae41a2012-06-19 07:48:27 +000013621 cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
Merav Sicrona0529972012-06-19 07:48:25 +000013622 ILT_PAGE_CIDS;
Merav Sicron37ae41a2012-06-19 07:48:27 +000013623 cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
Merav Sicrona0529972012-06-19 07:48:25 +000013624 (cxt_index * ILT_PAGE_CIDS);
13625 bnx2x_set_ctx_validation(bp,
13626 &bp->context[cxt_index].
13627 vcxt[cxt_offset].eth,
Merav Sicron37ae41a2012-06-19 07:48:27 +000013628 BNX2X_ISCSI_ETH_CID(bp));
Merav Sicrona0529972012-06-19 07:48:25 +000013629 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013630 }
13631
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013632 /*
13633 * There may be not more than 8 L2, not more than 8 L5 SPEs
13634 * and in the air. We also check that number of outstanding
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013635 * COMMON ramrods is not more than the EQ and SPQ can
13636 * accommodate.
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013637 */
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013638 if (type == ETH_CONNECTION_TYPE) {
13639 if (!atomic_read(&bp->cq_spq_left))
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013640 break;
13641 else
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013642 atomic_dec(&bp->cq_spq_left);
13643 } else if (type == NONE_CONNECTION_TYPE) {
13644 if (!atomic_read(&bp->eq_spq_left))
13645 break;
13646 else
13647 atomic_dec(&bp->eq_spq_left);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013648 } else if ((type == ISCSI_CONNECTION_TYPE) ||
13649 (type == FCOE_CONNECTION_TYPE)) {
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013650 if (bp->cnic_spq_pending >=
13651 bp->cnic_eth_dev.max_kwqe_pending)
13652 break;
13653 else
13654 bp->cnic_spq_pending++;
13655 } else {
13656 BNX2X_ERR("Unknown SPE type: %d\n", type);
13657 bnx2x_panic();
Michael Chan993ac7b2009-10-10 13:46:56 +000013658 break;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013659 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013660
13661 spe = bnx2x_sp_get_next(bp);
13662 *spe = *bp->cnic_kwq_cons;
13663
Merav Sicron51c1a582012-03-18 10:33:38 +000013664 DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013665 bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
13666
13667 if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
13668 bp->cnic_kwq_cons = bp->cnic_kwq;
13669 else
13670 bp->cnic_kwq_cons++;
13671 }
13672 bnx2x_sp_prod_update(bp);
13673 spin_unlock_bh(&bp->spq_lock);
13674}
13675
13676static int bnx2x_cnic_sp_queue(struct net_device *dev,
13677 struct kwqe_16 *kwqes[], u32 count)
13678{
13679 struct bnx2x *bp = netdev_priv(dev);
13680 int i;
13681
13682#ifdef BNX2X_STOP_ON_ERROR
Merav Sicron51c1a582012-03-18 10:33:38 +000013683 if (unlikely(bp->panic)) {
13684 BNX2X_ERR("Can't post to SP queue while panic\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000013685 return -EIO;
Merav Sicron51c1a582012-03-18 10:33:38 +000013686 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013687#endif
13688
Ariel Elior95c6c6162012-01-26 06:01:52 +000013689 if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
13690 (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
Merav Sicron51c1a582012-03-18 10:33:38 +000013691 BNX2X_ERR("Handling parity error recovery. Try again later\n");
Ariel Elior95c6c6162012-01-26 06:01:52 +000013692 return -EAGAIN;
13693 }
13694
Michael Chan993ac7b2009-10-10 13:46:56 +000013695 spin_lock_bh(&bp->spq_lock);
13696
13697 for (i = 0; i < count; i++) {
13698 struct eth_spe *spe = (struct eth_spe *)kwqes[i];
13699
13700 if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
13701 break;
13702
13703 *bp->cnic_kwq_prod = *spe;
13704
13705 bp->cnic_kwq_pending++;
13706
Merav Sicron51c1a582012-03-18 10:33:38 +000013707 DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
Michael Chan993ac7b2009-10-10 13:46:56 +000013708 spe->hdr.conn_and_cmd_data, spe->hdr.type,
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013709 spe->data.update_data_addr.hi,
13710 spe->data.update_data_addr.lo,
Michael Chan993ac7b2009-10-10 13:46:56 +000013711 bp->cnic_kwq_pending);
13712
13713 if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
13714 bp->cnic_kwq_prod = bp->cnic_kwq;
13715 else
13716 bp->cnic_kwq_prod++;
13717 }
13718
13719 spin_unlock_bh(&bp->spq_lock);
13720
13721 if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
13722 bnx2x_cnic_sp_post(bp, 0);
13723
13724 return i;
13725}
13726
13727static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13728{
13729 struct cnic_ops *c_ops;
13730 int rc = 0;
13731
13732 mutex_lock(&bp->cnic_mutex);
Eric Dumazet13707f92011-01-26 19:28:23 +000013733 c_ops = rcu_dereference_protected(bp->cnic_ops,
13734 lockdep_is_held(&bp->cnic_mutex));
Michael Chan993ac7b2009-10-10 13:46:56 +000013735 if (c_ops)
13736 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13737 mutex_unlock(&bp->cnic_mutex);
13738
13739 return rc;
13740}
13741
13742static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
13743{
13744 struct cnic_ops *c_ops;
13745 int rc = 0;
13746
13747 rcu_read_lock();
13748 c_ops = rcu_dereference(bp->cnic_ops);
13749 if (c_ops)
13750 rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
13751 rcu_read_unlock();
13752
13753 return rc;
13754}
13755
13756/*
13757 * for commands that have no data
13758 */
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013759int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
Michael Chan993ac7b2009-10-10 13:46:56 +000013760{
13761 struct cnic_ctl_info ctl = {0};
13762
13763 ctl.cmd = cmd;
13764
13765 return bnx2x_cnic_ctl_send(bp, &ctl);
13766}
13767
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013768static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
Michael Chan993ac7b2009-10-10 13:46:56 +000013769{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013770 struct cnic_ctl_info ctl = {0};
Michael Chan993ac7b2009-10-10 13:46:56 +000013771
13772 /* first we tell CNIC and only then we count this as a completion */
13773 ctl.cmd = CNIC_CTL_COMPLETION_CMD;
13774 ctl.data.comp.cid = cid;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013775 ctl.data.comp.error = err;
Michael Chan993ac7b2009-10-10 13:46:56 +000013776
13777 bnx2x_cnic_ctl_send_bh(bp, &ctl);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013778 bnx2x_cnic_sp_post(bp, 0);
Michael Chan993ac7b2009-10-10 13:46:56 +000013779}
13780
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013781/* Called with netif_addr_lock_bh() taken.
13782 * Sets an rx_mode config for an iSCSI ETH client.
13783 * Doesn't block.
13784 * Completion should be checked outside.
13785 */
13786static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
13787{
13788 unsigned long accept_flags = 0, ramrod_flags = 0;
13789 u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
13790 int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
13791
13792 if (start) {
13793 /* Start accepting on iSCSI L2 ring. Accept all multicasts
13794 * because it's the only way for UIO Queue to accept
13795 * multicasts (in non-promiscuous mode only one Queue per
13796 * function will receive multicast packets (leading in our
13797 * case).
13798 */
13799 __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
13800 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
13801 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
13802 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
13803
13804 /* Clear STOP_PENDING bit if START is requested */
13805 clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
13806
13807 sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
13808 } else
13809 /* Clear START_PENDING bit if STOP is requested */
13810 clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
13811
13812 if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
13813 set_bit(sched_state, &bp->sp_state);
13814 else {
13815 __set_bit(RAMROD_RX, &ramrod_flags);
13816 bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
13817 ramrod_flags);
13818 }
13819}
13820
Michael Chan993ac7b2009-10-10 13:46:56 +000013821static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
13822{
13823 struct bnx2x *bp = netdev_priv(dev);
13824 int rc = 0;
13825
13826 switch (ctl->cmd) {
13827 case DRV_CTL_CTXTBL_WR_CMD: {
13828 u32 index = ctl->data.io.offset;
13829 dma_addr_t addr = ctl->data.io.dma_addr;
13830
13831 bnx2x_ilt_wr(bp, index, addr);
13832 break;
13833 }
13834
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013835 case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
13836 int count = ctl->data.credit.credit_count;
Michael Chan993ac7b2009-10-10 13:46:56 +000013837
13838 bnx2x_cnic_sp_post(bp, count);
13839 break;
13840 }
13841
13842 /* rtnl_lock is held. */
13843 case DRV_CTL_START_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013844 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13845 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013846
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013847 /* Configure the iSCSI classification object */
13848 bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
13849 cp->iscsi_l2_client_id,
13850 cp->iscsi_l2_cid, BP_FUNC(bp),
13851 bnx2x_sp(bp, mac_rdata),
13852 bnx2x_sp_mapping(bp, mac_rdata),
13853 BNX2X_FILTER_MAC_PENDING,
13854 &bp->sp_state, BNX2X_OBJ_TYPE_RX,
13855 &bp->macs_pool);
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000013856
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013857 /* Set iSCSI MAC address */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013858 rc = bnx2x_set_iscsi_eth_mac_addr(bp);
13859 if (rc)
13860 break;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013861
13862 mmiowb();
13863 barrier();
13864
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013865 /* Start accepting on iSCSI L2 ring */
13866
13867 netif_addr_lock_bh(dev);
13868 bnx2x_set_iscsi_eth_rx_mode(bp, true);
13869 netif_addr_unlock_bh(dev);
13870
13871 /* bits to wait on */
13872 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13873 __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
13874
13875 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13876 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013877
Michael Chan993ac7b2009-10-10 13:46:56 +000013878 break;
13879 }
13880
13881 /* rtnl_lock is held. */
13882 case DRV_CTL_STOP_L2_CMD: {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013883 unsigned long sp_bits = 0;
Michael Chan993ac7b2009-10-10 13:46:56 +000013884
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013885 /* Stop accepting on iSCSI L2 ring */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013886 netif_addr_lock_bh(dev);
13887 bnx2x_set_iscsi_eth_rx_mode(bp, false);
13888 netif_addr_unlock_bh(dev);
13889
13890 /* bits to wait on */
13891 __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
13892 __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
13893
13894 if (!bnx2x_wait_sp_comp(bp, sp_bits))
13895 BNX2X_ERR("rx_mode completion timed out!\n");
Dmitry Kravkov523224a2010-10-06 03:23:26 +000013896
13897 mmiowb();
13898 barrier();
13899
13900 /* Unset iSCSI L2 MAC */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013901 rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
13902 BNX2X_ISCSI_ETH_MAC, true);
Michael Chan993ac7b2009-10-10 13:46:56 +000013903 break;
13904 }
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013905 case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
13906 int count = ctl->data.credit.credit_count;
13907
Peter Zijlstra4e857c52014-03-17 18:06:10 +010013908 smp_mb__before_atomic();
Vladislav Zolotarov6e30dd42011-02-06 11:25:41 -080013909 atomic_add(count, &bp->cq_spq_left);
Peter Zijlstra4e857c52014-03-17 18:06:10 +010013910 smp_mb__after_atomic();
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000013911 break;
13912 }
Barak Witkowski1d187b32011-12-05 22:41:50 +000013913 case DRV_CTL_ULP_REGISTER_CMD: {
Barak Witkowski2e499d32012-06-26 01:31:19 +000013914 int ulp_type = ctl->data.register_data.ulp_type;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013915
13916 if (CHIP_IS_E3(bp)) {
13917 int idx = BP_FW_MB_IDX(bp);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013918 u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13919 int path = BP_PATH(bp);
13920 int port = BP_PORT(bp);
13921 int i;
13922 u32 scratch_offset;
13923 u32 *host_addr;
Barak Witkowski1d187b32011-12-05 22:41:50 +000013924
Barak Witkowski2e499d32012-06-26 01:31:19 +000013925 /* first write capability to shmem2 */
Barak Witkowski1d187b32011-12-05 22:41:50 +000013926 if (ulp_type == CNIC_ULP_ISCSI)
13927 cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13928 else if (ulp_type == CNIC_ULP_FCOE)
13929 cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13930 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
Barak Witkowski2e499d32012-06-26 01:31:19 +000013931
13932 if ((ulp_type != CNIC_ULP_FCOE) ||
13933 (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
13934 (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
13935 break;
13936
13937 /* if reached here - should write fcoe capabilities */
13938 scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
13939 if (!scratch_offset)
13940 break;
13941 scratch_offset += offsetof(struct glob_ncsi_oem_data,
13942 fcoe_features[path][port]);
13943 host_addr = (u32 *) &(ctl->data.register_data.
13944 fcoe_features);
13945 for (i = 0; i < sizeof(struct fcoe_capabilities);
13946 i += 4)
13947 REG_WR(bp, scratch_offset + i,
13948 *(host_addr + i/4));
Barak Witkowski1d187b32011-12-05 22:41:50 +000013949 }
Yuval Mintz42f82772014-03-23 18:12:23 +020013950 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
Barak Witkowski1d187b32011-12-05 22:41:50 +000013951 break;
13952 }
Barak Witkowski2e499d32012-06-26 01:31:19 +000013953
Barak Witkowski1d187b32011-12-05 22:41:50 +000013954 case DRV_CTL_ULP_UNREGISTER_CMD: {
13955 int ulp_type = ctl->data.ulp_type;
13956
13957 if (CHIP_IS_E3(bp)) {
13958 int idx = BP_FW_MB_IDX(bp);
13959 u32 cap;
13960
13961 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
13962 if (ulp_type == CNIC_ULP_ISCSI)
13963 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
13964 else if (ulp_type == CNIC_ULP_FCOE)
13965 cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
13966 SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
13967 }
Yuval Mintz42f82772014-03-23 18:12:23 +020013968 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
Barak Witkowski1d187b32011-12-05 22:41:50 +000013969 break;
13970 }
Michael Chan993ac7b2009-10-10 13:46:56 +000013971
13972 default:
13973 BNX2X_ERR("unknown command %x\n", ctl->cmd);
13974 rc = -EINVAL;
13975 }
13976
13977 return rc;
13978}
13979
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000013980void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
Michael Chan993ac7b2009-10-10 13:46:56 +000013981{
13982 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
13983
13984 if (bp->flags & USING_MSIX_FLAG) {
13985 cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
13986 cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
13987 cp->irq_arr[0].vector = bp->msix_table[1].vector;
13988 } else {
13989 cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
13990 cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
13991 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013992 if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013993 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
13994 else
13995 cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
13996
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030013997 cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
13998 cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000013999 cp->irq_arr[1].status_blk = bp->def_status_blk;
14000 cp->irq_arr[1].status_blk_num = DEF_SB_ID;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000014001 cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
Michael Chan993ac7b2009-10-10 13:46:56 +000014002
14003 cp->num_irq = 2;
14004}
14005
Merav Sicron37ae41a2012-06-19 07:48:27 +000014006void bnx2x_setup_cnic_info(struct bnx2x *bp)
14007{
14008 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14009
Merav Sicron37ae41a2012-06-19 07:48:27 +000014010 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
14011 bnx2x_cid_ilt_lines(bp);
14012 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
14013 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
14014 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
14015
Michael Chanf78afb32013-09-18 01:50:38 -070014016 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",
14017 BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
14018 cp->iscsi_l2_cid);
14019
Merav Sicron37ae41a2012-06-19 07:48:27 +000014020 if (NO_ISCSI_OOO(bp))
14021 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
14022}
14023
Michael Chan993ac7b2009-10-10 13:46:56 +000014024static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
14025 void *data)
14026{
14027 struct bnx2x *bp = netdev_priv(dev);
14028 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
Merav Sicron55c11942012-11-07 00:45:48 +000014029 int rc;
14030
14031 DP(NETIF_MSG_IFUP, "Register_cnic called\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000014032
Merav Sicron51c1a582012-03-18 10:33:38 +000014033 if (ops == NULL) {
14034 BNX2X_ERR("NULL ops received\n");
Michael Chan993ac7b2009-10-10 13:46:56 +000014035 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +000014036 }
Michael Chan993ac7b2009-10-10 13:46:56 +000014037
Merav Sicron55c11942012-11-07 00:45:48 +000014038 if (!CNIC_SUPPORT(bp)) {
14039 BNX2X_ERR("Can't register CNIC when not supported\n");
14040 return -EOPNOTSUPP;
14041 }
14042
14043 if (!CNIC_LOADED(bp)) {
14044 rc = bnx2x_load_cnic(bp);
14045 if (rc) {
14046 BNX2X_ERR("CNIC-related load failed\n");
14047 return rc;
14048 }
Merav Sicron55c11942012-11-07 00:45:48 +000014049 }
14050
14051 bp->cnic_enabled = true;
14052
Michael Chan993ac7b2009-10-10 13:46:56 +000014053 bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
14054 if (!bp->cnic_kwq)
14055 return -ENOMEM;
14056
14057 bp->cnic_kwq_cons = bp->cnic_kwq;
14058 bp->cnic_kwq_prod = bp->cnic_kwq;
14059 bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
14060
14061 bp->cnic_spq_pending = 0;
14062 bp->cnic_kwq_pending = 0;
14063
14064 bp->cnic_data = data;
14065
14066 cp->num_irq = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030014067 cp->drv_state |= CNIC_DRV_STATE_REGD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000014068 cp->iro_arr = bp->iro_arr;
Michael Chan993ac7b2009-10-10 13:46:56 +000014069
Michael Chan993ac7b2009-10-10 13:46:56 +000014070 bnx2x_setup_cnic_irq_info(bp);
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000014071
Michael Chan993ac7b2009-10-10 13:46:56 +000014072 rcu_assign_pointer(bp->cnic_ops, ops);
14073
Yuval Mintz42f82772014-03-23 18:12:23 +020014074 /* Schedule driver to read CNIC driver versions */
14075 bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
14076
Michael Chan993ac7b2009-10-10 13:46:56 +000014077 return 0;
14078}
14079
14080static int bnx2x_unregister_cnic(struct net_device *dev)
14081{
14082 struct bnx2x *bp = netdev_priv(dev);
14083 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14084
14085 mutex_lock(&bp->cnic_mutex);
Michael Chan993ac7b2009-10-10 13:46:56 +000014086 cp->drv_state = 0;
Eric Dumazet2cfa5a02011-11-23 07:09:32 +000014087 RCU_INIT_POINTER(bp->cnic_ops, NULL);
Michael Chan993ac7b2009-10-10 13:46:56 +000014088 mutex_unlock(&bp->cnic_mutex);
14089 synchronize_rcu();
Yuval Mintzfea75642013-04-10 13:34:39 +030014090 bp->cnic_enabled = false;
Michael Chan993ac7b2009-10-10 13:46:56 +000014091 kfree(bp->cnic_kwq);
14092 bp->cnic_kwq = NULL;
14093
14094 return 0;
14095}
14096
stephen hemmingera8f47eb2014-01-09 22:20:11 -080014097static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
Michael Chan993ac7b2009-10-10 13:46:56 +000014098{
14099 struct bnx2x *bp = netdev_priv(dev);
14100 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
14101
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000014102 /* If both iSCSI and FCoE are disabled - return NULL in
14103 * order to indicate CNIC that it should not try to work
14104 * with this device.
14105 */
14106 if (NO_ISCSI(bp) && NO_FCOE(bp))
14107 return NULL;
14108
Michael Chan993ac7b2009-10-10 13:46:56 +000014109 cp->drv_owner = THIS_MODULE;
14110 cp->chip_id = CHIP_ID(bp);
14111 cp->pdev = bp->pdev;
14112 cp->io_base = bp->regview;
14113 cp->io_base2 = bp->doorbells;
14114 cp->max_kwqe_pending = 8;
Dmitry Kravkov523224a2010-10-06 03:23:26 +000014115 cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000014116 cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
14117 bnx2x_cid_ilt_lines(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000014118 cp->ctx_tbl_len = CNIC_ILT_LINES;
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000014119 cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
Michael Chan993ac7b2009-10-10 13:46:56 +000014120 cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
14121 cp->drv_ctl = bnx2x_drv_ctl;
14122 cp->drv_register_cnic = bnx2x_register_cnic;
14123 cp->drv_unregister_cnic = bnx2x_unregister_cnic;
Merav Sicron37ae41a2012-06-19 07:48:27 +000014124 cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030014125 cp->iscsi_l2_client_id =
14126 bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
Merav Sicron37ae41a2012-06-19 07:48:27 +000014127 cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
Michael Chan993ac7b2009-10-10 13:46:56 +000014128
Vladislav Zolotarov2ba45142011-01-31 14:39:17 +000014129 if (NO_ISCSI_OOO(bp))
14130 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
14131
14132 if (NO_ISCSI(bp))
14133 cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
14134
14135 if (NO_FCOE(bp))
14136 cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
14137
Merav Sicron51c1a582012-03-18 10:33:38 +000014138 BNX2X_DEV_INFO(
14139 "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
Dmitry Kravkovc2bff632010-10-06 03:33:18 +000014140 cp->ctx_blk_size,
14141 cp->ctx_tbl_offset,
14142 cp->ctx_tbl_len,
14143 cp->starting_cid);
Michael Chan993ac7b2009-10-10 13:46:56 +000014144 return cp;
14145}
Michael Chan993ac7b2009-10-10 13:46:56 +000014146
stephen hemmingera8f47eb2014-01-09 22:20:11 -080014147static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014148{
Ariel Elior64112802013-01-07 00:50:23 +000014149 struct bnx2x *bp = fp->bp;
14150 u32 offset = BAR_USTRORM_INTMEM;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -070014151
Ariel Elior64112802013-01-07 00:50:23 +000014152 if (IS_VF(bp))
14153 return bnx2x_vf_ustorm_prods_offset(bp, fp);
14154 else if (!CHIP_IS_E1x(bp))
14155 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
14156 else
14157 offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014158
Ariel Elior64112802013-01-07 00:50:23 +000014159 return offset;
14160}
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014161
Ariel Elior64112802013-01-07 00:50:23 +000014162/* called only on E1H or E2.
14163 * When pretending to be PF, the pretend value is the function number 0...7
14164 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
14165 * combination
14166 */
14167int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
14168{
14169 u32 pretend_reg;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014170
Ariel Elior23826852013-01-09 07:04:35 +000014171 if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
Ariel Elior64112802013-01-07 00:50:23 +000014172 return -1;
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014173
Ariel Elior64112802013-01-07 00:50:23 +000014174 /* get my own pretend register */
14175 pretend_reg = bnx2x_get_pretend_reg(bp);
14176 REG_WR(bp, pretend_reg, pretend_func_val);
14177 REG_RD(bp, pretend_reg);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000014178 return 0;
14179}