Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1 | /* bnx2x_main.c: Broadcom Everest network driver. |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2 | * |
Dmitry Kravkov | 5de9240 | 2011-05-04 23:51:13 +0000 | [diff] [blame] | 3 | * Copyright (c) 2007-2011 Broadcom Corporation |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 9 | * Maintained by: Eilon Greenstein <eilong@broadcom.com> |
| 10 | * Written by: Eliezer Tamir |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11 | * Based on code from Michael Chan's bnx2 driver |
| 12 | * UDP CSUM errata workaround by Arik Gendelman |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 13 | * Slowpath and fastpath rework by Vladislav Zolotarov |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 14 | * Statistics and Link management by Yitchak Gertner |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/device.h> /* for dev_info() */ |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <linux/slab.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/pci.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/netdevice.h> |
| 30 | #include <linux/etherdevice.h> |
| 31 | #include <linux/skbuff.h> |
| 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/bitops.h> |
| 34 | #include <linux/irq.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <asm/byteorder.h> |
| 37 | #include <linux/time.h> |
| 38 | #include <linux/ethtool.h> |
| 39 | #include <linux/mii.h> |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 40 | #include <linux/if_vlan.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 41 | #include <net/ip.h> |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 42 | #include <net/ipv6.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 43 | #include <net/tcp.h> |
| 44 | #include <net/checksum.h> |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 45 | #include <net/ip6_checksum.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 46 | #include <linux/workqueue.h> |
| 47 | #include <linux/crc32.h> |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 48 | #include <linux/crc32c.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 49 | #include <linux/prefetch.h> |
| 50 | #include <linux/zlib.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 51 | #include <linux/io.h> |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 52 | #include <linux/stringify.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 53 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 54 | #include "bnx2x.h" |
| 55 | #include "bnx2x_init.h" |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 56 | #include "bnx2x_init_ops.h" |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 57 | #include "bnx2x_cmn.h" |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 58 | #include "bnx2x_dcb.h" |
Vladislav Zolotarov | 042181f | 2011-06-14 01:33:39 +0000 | [diff] [blame] | 59 | #include "bnx2x_sp.h" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 60 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 61 | #include <linux/firmware.h> |
| 62 | #include "bnx2x_fw_file_hdr.h" |
| 63 | /* FW files */ |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 64 | #define FW_FILE_VERSION \ |
| 65 | __stringify(BCM_5710_FW_MAJOR_VERSION) "." \ |
| 66 | __stringify(BCM_5710_FW_MINOR_VERSION) "." \ |
| 67 | __stringify(BCM_5710_FW_REVISION_VERSION) "." \ |
| 68 | __stringify(BCM_5710_FW_ENGINEERING_VERSION) |
Dmitry Kravkov | 560131f | 2010-10-06 03:18:47 +0000 | [diff] [blame] | 69 | #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw" |
| 70 | #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw" |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 71 | #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw" |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 72 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 73 | /* Time in jiffies before concluding the transmitter is hung */ |
| 74 | #define TX_TIMEOUT (5*HZ) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 75 | |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 76 | static char version[] __devinitdata = |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 77 | "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 78 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 79 | |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 80 | MODULE_AUTHOR("Eliezer Tamir"); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 81 | MODULE_DESCRIPTION("Broadcom NetXtreme II " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 82 | "BCM57710/57711/57711E/" |
| 83 | "57712/57712_MF/57800/57800_MF/57810/57810_MF/" |
| 84 | "57840/57840_MF Driver"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 85 | MODULE_LICENSE("GPL"); |
| 86 | MODULE_VERSION(DRV_MODULE_VERSION); |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 87 | MODULE_FIRMWARE(FW_FILE_NAME_E1); |
| 88 | MODULE_FIRMWARE(FW_FILE_NAME_E1H); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 89 | MODULE_FIRMWARE(FW_FILE_NAME_E2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 90 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 91 | static int multi_mode = 1; |
| 92 | module_param(multi_mode, int, 0); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 93 | MODULE_PARM_DESC(multi_mode, " Multi queue mode " |
| 94 | "(0 Disable; 1 Enable (default))"); |
| 95 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 96 | int num_queues; |
Vladislav Zolotarov | 54b9dda | 2009-11-16 06:05:58 +0000 | [diff] [blame] | 97 | module_param(num_queues, int, 0); |
| 98 | MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1" |
| 99 | " (default is as a number of CPUs)"); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 100 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 101 | static int disable_tpa; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 102 | module_param(disable_tpa, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 103 | MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 104 | |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 105 | #define INT_MODE_INTx 1 |
| 106 | #define INT_MODE_MSI 2 |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 107 | static int int_mode; |
| 108 | module_param(int_mode, int, 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 109 | MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 110 | "(1 INT#x; 2 MSI)"); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 111 | |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 112 | static int dropless_fc; |
| 113 | module_param(dropless_fc, int, 0); |
| 114 | MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); |
| 115 | |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 116 | static int poll; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 117 | module_param(poll, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 118 | MODULE_PARM_DESC(poll, " Use polling (for debug)"); |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 119 | |
| 120 | static int mrrs = -1; |
| 121 | module_param(mrrs, int, 0); |
| 122 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); |
| 123 | |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 124 | static int debug; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 125 | module_param(debug, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 126 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
| 127 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 128 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 129 | |
| 130 | struct workqueue_struct *bnx2x_wq; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 131 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 132 | enum bnx2x_board_type { |
| 133 | BCM57710 = 0, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 134 | BCM57711, |
| 135 | BCM57711E, |
| 136 | BCM57712, |
| 137 | BCM57712_MF, |
| 138 | BCM57800, |
| 139 | BCM57800_MF, |
| 140 | BCM57810, |
| 141 | BCM57810_MF, |
| 142 | BCM57840, |
| 143 | BCM57840_MF |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 144 | }; |
| 145 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 146 | /* indexed by board_type, above */ |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 147 | static struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 148 | char *name; |
| 149 | } board_info[] __devinitdata = { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 150 | { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" }, |
| 151 | { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" }, |
| 152 | { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" }, |
| 153 | { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" }, |
| 154 | { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" }, |
| 155 | { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" }, |
| 156 | { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" }, |
| 157 | { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" }, |
| 158 | { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" }, |
| 159 | { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" }, |
| 160 | { "Broadcom NetXtreme II BCM57840 10/20 Gigabit " |
| 161 | "Ethernet Multi Function"} |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 164 | #ifndef PCI_DEVICE_ID_NX2_57710 |
| 165 | #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710 |
| 166 | #endif |
| 167 | #ifndef PCI_DEVICE_ID_NX2_57711 |
| 168 | #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711 |
| 169 | #endif |
| 170 | #ifndef PCI_DEVICE_ID_NX2_57711E |
| 171 | #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E |
| 172 | #endif |
| 173 | #ifndef PCI_DEVICE_ID_NX2_57712 |
| 174 | #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712 |
| 175 | #endif |
| 176 | #ifndef PCI_DEVICE_ID_NX2_57712_MF |
| 177 | #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF |
| 178 | #endif |
| 179 | #ifndef PCI_DEVICE_ID_NX2_57800 |
| 180 | #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800 |
| 181 | #endif |
| 182 | #ifndef PCI_DEVICE_ID_NX2_57800_MF |
| 183 | #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF |
| 184 | #endif |
| 185 | #ifndef PCI_DEVICE_ID_NX2_57810 |
| 186 | #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810 |
| 187 | #endif |
| 188 | #ifndef PCI_DEVICE_ID_NX2_57810_MF |
| 189 | #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF |
| 190 | #endif |
| 191 | #ifndef PCI_DEVICE_ID_NX2_57840 |
| 192 | #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840 |
| 193 | #endif |
| 194 | #ifndef PCI_DEVICE_ID_NX2_57840_MF |
| 195 | #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF |
| 196 | #endif |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 197 | static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = { |
Eilon Greenstein | e4ed711 | 2009-08-12 08:24:10 +0000 | [diff] [blame] | 198 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, |
| 199 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, |
| 200 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E }, |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 201 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 }, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 202 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF }, |
| 203 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 }, |
| 204 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF }, |
| 205 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 }, |
| 206 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF }, |
| 207 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 }, |
| 208 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF }, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 209 | { 0 } |
| 210 | }; |
| 211 | |
| 212 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); |
| 213 | |
| 214 | /**************************************************************************** |
| 215 | * General service functions |
| 216 | ****************************************************************************/ |
| 217 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 218 | static inline void __storm_memset_dma_mapping(struct bnx2x *bp, |
| 219 | u32 addr, dma_addr_t mapping) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 220 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 221 | REG_WR(bp, addr, U64_LO(mapping)); |
| 222 | REG_WR(bp, addr + 4, U64_HI(mapping)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 225 | static inline void storm_memset_spq_addr(struct bnx2x *bp, |
| 226 | dma_addr_t mapping, u16 abs_fid) |
| 227 | { |
| 228 | u32 addr = XSEM_REG_FAST_MEMORY + |
| 229 | XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid); |
| 230 | |
| 231 | __storm_memset_dma_mapping(bp, addr, mapping); |
| 232 | } |
| 233 | |
| 234 | static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid, |
| 235 | u16 pf_id) |
| 236 | { |
| 237 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid), |
| 238 | pf_id); |
| 239 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid), |
| 240 | pf_id); |
| 241 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid), |
| 242 | pf_id); |
| 243 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid), |
| 244 | pf_id); |
| 245 | } |
| 246 | |
| 247 | static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid, |
| 248 | u8 enable) |
| 249 | { |
| 250 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid), |
| 251 | enable); |
| 252 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid), |
| 253 | enable); |
| 254 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid), |
| 255 | enable); |
| 256 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid), |
| 257 | enable); |
| 258 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 259 | |
| 260 | static inline void storm_memset_eq_data(struct bnx2x *bp, |
| 261 | struct event_ring_data *eq_data, |
| 262 | u16 pfid) |
| 263 | { |
| 264 | size_t size = sizeof(struct event_ring_data); |
| 265 | |
| 266 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid); |
| 267 | |
| 268 | __storm_memset_struct(bp, addr, size, (u32 *)eq_data); |
| 269 | } |
| 270 | |
| 271 | static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod, |
| 272 | u16 pfid) |
| 273 | { |
| 274 | u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid); |
| 275 | REG_WR16(bp, addr, eq_prod); |
| 276 | } |
| 277 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 278 | /* used only at init |
| 279 | * locking is done by mcp |
| 280 | */ |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 281 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 282 | { |
| 283 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 284 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); |
| 285 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 286 | PCICFG_VENDOR_ID_OFFSET); |
| 287 | } |
| 288 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 289 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
| 290 | { |
| 291 | u32 val; |
| 292 | |
| 293 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 294 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); |
| 295 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 296 | PCICFG_VENDOR_ID_OFFSET); |
| 297 | |
| 298 | return val; |
| 299 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 300 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 301 | #define DMAE_DP_SRC_GRC "grc src_addr [%08x]" |
| 302 | #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]" |
| 303 | #define DMAE_DP_DST_GRC "grc dst_addr [%08x]" |
| 304 | #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]" |
| 305 | #define DMAE_DP_DST_NONE "dst_addr [none]" |
| 306 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 307 | static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, |
| 308 | int msglvl) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 309 | { |
| 310 | u32 src_type = dmae->opcode & DMAE_COMMAND_SRC; |
| 311 | |
| 312 | switch (dmae->opcode & DMAE_COMMAND_DST) { |
| 313 | case DMAE_CMD_DST_PCI: |
| 314 | if (src_type == DMAE_CMD_SRC_PCI) |
| 315 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 316 | "src [%x:%08x], len [%d*4], dst [%x:%08x]\n" |
| 317 | "comp_addr [%x:%08x], comp_val 0x%08x\n", |
| 318 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 319 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, |
| 320 | dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 321 | dmae->comp_val); |
| 322 | else |
| 323 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 324 | "src [%08x], len [%d*4], dst [%x:%08x]\n" |
| 325 | "comp_addr [%x:%08x], comp_val 0x%08x\n", |
| 326 | dmae->opcode, dmae->src_addr_lo >> 2, |
| 327 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, |
| 328 | dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 329 | dmae->comp_val); |
| 330 | break; |
| 331 | case DMAE_CMD_DST_GRC: |
| 332 | if (src_type == DMAE_CMD_SRC_PCI) |
| 333 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 334 | "src [%x:%08x], len [%d*4], dst_addr [%08x]\n" |
| 335 | "comp_addr [%x:%08x], comp_val 0x%08x\n", |
| 336 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 337 | dmae->len, dmae->dst_addr_lo >> 2, |
| 338 | dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 339 | dmae->comp_val); |
| 340 | else |
| 341 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 342 | "src [%08x], len [%d*4], dst [%08x]\n" |
| 343 | "comp_addr [%x:%08x], comp_val 0x%08x\n", |
| 344 | dmae->opcode, dmae->src_addr_lo >> 2, |
| 345 | dmae->len, dmae->dst_addr_lo >> 2, |
| 346 | dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 347 | dmae->comp_val); |
| 348 | break; |
| 349 | default: |
| 350 | if (src_type == DMAE_CMD_SRC_PCI) |
| 351 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 352 | DP_LEVEL "src_addr [%x:%08x] len [%d * 4] " |
| 353 | "dst_addr [none]\n" |
| 354 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 355 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 356 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 357 | dmae->comp_val); |
| 358 | else |
| 359 | DP(msglvl, "DMAE: opcode 0x%08x\n" |
| 360 | DP_LEVEL "src_addr [%08x] len [%d * 4] " |
| 361 | "dst_addr [none]\n" |
| 362 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 363 | dmae->opcode, dmae->src_addr_lo >> 2, |
| 364 | dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo, |
| 365 | dmae->comp_val); |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | } |
| 370 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 371 | /* copy command into DMAE command memory and set DMAE command go */ |
Dmitry Kravkov | 6c719d0 | 2010-07-27 12:36:15 +0000 | [diff] [blame] | 372 | void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 373 | { |
| 374 | u32 cmd_offset; |
| 375 | int i; |
| 376 | |
| 377 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); |
| 378 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { |
| 379 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
| 380 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 381 | DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n", |
| 382 | idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 383 | } |
| 384 | REG_WR(bp, dmae_reg_go_c[idx], 1); |
| 385 | } |
| 386 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 387 | u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type) |
| 388 | { |
| 389 | return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) | |
| 390 | DMAE_CMD_C_ENABLE); |
| 391 | } |
| 392 | |
| 393 | u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode) |
| 394 | { |
| 395 | return opcode & ~DMAE_CMD_SRC_RESET; |
| 396 | } |
| 397 | |
| 398 | u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type, |
| 399 | bool with_comp, u8 comp_type) |
| 400 | { |
| 401 | u32 opcode = 0; |
| 402 | |
| 403 | opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) | |
| 404 | (dst_type << DMAE_COMMAND_DST_SHIFT)); |
| 405 | |
| 406 | opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET); |
| 407 | |
| 408 | opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0); |
| 409 | opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) | |
| 410 | (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT)); |
| 411 | opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT); |
| 412 | |
| 413 | #ifdef __BIG_ENDIAN |
| 414 | opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP; |
| 415 | #else |
| 416 | opcode |= DMAE_CMD_ENDIANITY_DW_SWAP; |
| 417 | #endif |
| 418 | if (with_comp) |
| 419 | opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type); |
| 420 | return opcode; |
| 421 | } |
| 422 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 423 | static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, |
| 424 | struct dmae_command *dmae, |
| 425 | u8 src_type, u8 dst_type) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 426 | { |
| 427 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 428 | |
| 429 | /* set the opcode */ |
| 430 | dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type, |
| 431 | true, DMAE_COMP_PCI); |
| 432 | |
| 433 | /* fill in the completion parameters */ |
| 434 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 435 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
| 436 | dmae->comp_val = DMAE_COMP_VAL; |
| 437 | } |
| 438 | |
| 439 | /* issue a dmae command over the init-channel and wailt for completion */ |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 440 | static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, |
| 441 | struct dmae_command *dmae) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 442 | { |
| 443 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Dmitry Kravkov | 5e374b5 | 2011-05-22 10:09:19 +0000 | [diff] [blame] | 444 | int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 445 | int rc = 0; |
| 446 | |
| 447 | DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
| 448 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 449 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
| 450 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 451 | /* |
| 452 | * Lock the dmae channel. Disable BHs to prevent a dead-lock |
| 453 | * as long as this code is called both from syscall context and |
| 454 | * from ndo_set_rx_mode() flow that may be called from BH. |
| 455 | */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 456 | spin_lock_bh(&bp->dmae_lock); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 457 | |
| 458 | /* reset completion */ |
| 459 | *wb_comp = 0; |
| 460 | |
| 461 | /* post the command on the channel used for initializations */ |
| 462 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
| 463 | |
| 464 | /* wait for completion */ |
| 465 | udelay(5); |
| 466 | while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) { |
| 467 | DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp); |
| 468 | |
| 469 | if (!cnt) { |
| 470 | BNX2X_ERR("DMAE timeout!\n"); |
| 471 | rc = DMAE_TIMEOUT; |
| 472 | goto unlock; |
| 473 | } |
| 474 | cnt--; |
| 475 | udelay(50); |
| 476 | } |
| 477 | if (*wb_comp & DMAE_PCI_ERR_FLAG) { |
| 478 | BNX2X_ERR("DMAE PCI error!\n"); |
| 479 | rc = DMAE_PCI_ERROR; |
| 480 | } |
| 481 | |
| 482 | DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
| 483 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 484 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
| 485 | |
| 486 | unlock: |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 487 | spin_unlock_bh(&bp->dmae_lock); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 488 | return rc; |
| 489 | } |
| 490 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 491 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, |
| 492 | u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 493 | { |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 494 | struct dmae_command dmae; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 495 | |
| 496 | if (!bp->dmae_ready) { |
| 497 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 498 | |
| 499 | DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)" |
| 500 | " using indirect\n", dst_addr, len32); |
| 501 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); |
| 502 | return; |
| 503 | } |
| 504 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 505 | /* set opcode and fixed command fields */ |
| 506 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 507 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 508 | /* fill in addresses and len */ |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 509 | dmae.src_addr_lo = U64_LO(dma_addr); |
| 510 | dmae.src_addr_hi = U64_HI(dma_addr); |
| 511 | dmae.dst_addr_lo = dst_addr >> 2; |
| 512 | dmae.dst_addr_hi = 0; |
| 513 | dmae.len = len32; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 514 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 515 | bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 516 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 517 | /* issue the command and wait for completion */ |
| 518 | bnx2x_issue_dmae_with_comp(bp, &dmae); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 521 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 522 | { |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 523 | struct dmae_command dmae; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 524 | |
| 525 | if (!bp->dmae_ready) { |
| 526 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 527 | int i; |
| 528 | |
| 529 | DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)" |
| 530 | " using indirect\n", src_addr, len32); |
| 531 | for (i = 0; i < len32; i++) |
| 532 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); |
| 533 | return; |
| 534 | } |
| 535 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 536 | /* set opcode and fixed command fields */ |
| 537 | bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 538 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 539 | /* fill in addresses and len */ |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 540 | dmae.src_addr_lo = src_addr >> 2; |
| 541 | dmae.src_addr_hi = 0; |
| 542 | dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); |
| 543 | dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); |
| 544 | dmae.len = len32; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 545 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 546 | bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 547 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 548 | /* issue the command and wait for completion */ |
| 549 | bnx2x_issue_dmae_with_comp(bp, &dmae); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 550 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 551 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 552 | static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, |
| 553 | u32 addr, u32 len) |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 554 | { |
Vladislav Zolotarov | 02e3c6c | 2010-04-19 01:13:33 +0000 | [diff] [blame] | 555 | int dmae_wr_max = DMAE_LEN32_WR_MAX(bp); |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 556 | int offset = 0; |
| 557 | |
Vladislav Zolotarov | 02e3c6c | 2010-04-19 01:13:33 +0000 | [diff] [blame] | 558 | while (len > dmae_wr_max) { |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 559 | bnx2x_write_dmae(bp, phys_addr + offset, |
Vladislav Zolotarov | 02e3c6c | 2010-04-19 01:13:33 +0000 | [diff] [blame] | 560 | addr + offset, dmae_wr_max); |
| 561 | offset += dmae_wr_max * 4; |
| 562 | len -= dmae_wr_max; |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len); |
| 566 | } |
| 567 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 568 | /* used only for slowpath so not inlined */ |
| 569 | static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo) |
| 570 | { |
| 571 | u32 wb_write[2]; |
| 572 | |
| 573 | wb_write[0] = val_hi; |
| 574 | wb_write[1] = val_lo; |
| 575 | REG_WR_DMAE(bp, reg, wb_write, 2); |
| 576 | } |
| 577 | |
| 578 | #ifdef USE_WB_RD |
| 579 | static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg) |
| 580 | { |
| 581 | u32 wb_data[2]; |
| 582 | |
| 583 | REG_RD_DMAE(bp, reg, wb_data, 2); |
| 584 | |
| 585 | return HILO_U64(wb_data[0], wb_data[1]); |
| 586 | } |
| 587 | #endif |
| 588 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 589 | static int bnx2x_mc_assert(struct bnx2x *bp) |
| 590 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 591 | char last_idx; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 592 | int i, rc = 0; |
| 593 | u32 row0, row1, row2, row3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 594 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 595 | /* XSTORM */ |
| 596 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + |
| 597 | XSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 598 | if (last_idx) |
| 599 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 600 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 601 | /* print the asserts */ |
| 602 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 603 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 604 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 605 | XSTORM_ASSERT_LIST_OFFSET(i)); |
| 606 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 607 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 608 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 609 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 610 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 611 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 612 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 613 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 614 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 615 | " 0x%08x 0x%08x 0x%08x\n", |
| 616 | i, row3, row2, row1, row0); |
| 617 | rc++; |
| 618 | } else { |
| 619 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 620 | } |
| 621 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 622 | |
| 623 | /* TSTORM */ |
| 624 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + |
| 625 | TSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 626 | if (last_idx) |
| 627 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 628 | |
| 629 | /* print the asserts */ |
| 630 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 631 | |
| 632 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 633 | TSTORM_ASSERT_LIST_OFFSET(i)); |
| 634 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 635 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 636 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 637 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 638 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 639 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 640 | |
| 641 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 642 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 643 | " 0x%08x 0x%08x 0x%08x\n", |
| 644 | i, row3, row2, row1, row0); |
| 645 | rc++; |
| 646 | } else { |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | /* CSTORM */ |
| 652 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + |
| 653 | CSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 654 | if (last_idx) |
| 655 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 656 | |
| 657 | /* print the asserts */ |
| 658 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 659 | |
| 660 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 661 | CSTORM_ASSERT_LIST_OFFSET(i)); |
| 662 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 663 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 664 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 665 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 666 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 667 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 668 | |
| 669 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 670 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 671 | " 0x%08x 0x%08x 0x%08x\n", |
| 672 | i, row3, row2, row1, row0); |
| 673 | rc++; |
| 674 | } else { |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /* USTORM */ |
| 680 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + |
| 681 | USTORM_ASSERT_LIST_INDEX_OFFSET); |
| 682 | if (last_idx) |
| 683 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 684 | |
| 685 | /* print the asserts */ |
| 686 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 687 | |
| 688 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 689 | USTORM_ASSERT_LIST_OFFSET(i)); |
| 690 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 691 | USTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 692 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 693 | USTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 694 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 695 | USTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 696 | |
| 697 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 698 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 699 | " 0x%08x 0x%08x 0x%08x\n", |
| 700 | i, row3, row2, row1, row0); |
| 701 | rc++; |
| 702 | } else { |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 707 | return rc; |
| 708 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 709 | |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 710 | void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 711 | { |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 712 | u32 addr, val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 713 | u32 mark, offset; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 714 | __be32 data[9]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 715 | int word; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 716 | u32 trace_shmem_base; |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 717 | if (BP_NOMCP(bp)) { |
| 718 | BNX2X_ERR("NO MCP - can not dump\n"); |
| 719 | return; |
| 720 | } |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 721 | netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n", |
| 722 | (bp->common.bc_ver & 0xff0000) >> 16, |
| 723 | (bp->common.bc_ver & 0xff00) >> 8, |
| 724 | (bp->common.bc_ver & 0xff)); |
| 725 | |
| 726 | val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER); |
| 727 | if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER)) |
| 728 | printk("%s" "MCP PC at 0x%x\n", lvl, val); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 729 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 730 | if (BP_PATH(bp) == 0) |
| 731 | trace_shmem_base = bp->common.shmem_base; |
| 732 | else |
| 733 | trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr); |
| 734 | addr = trace_shmem_base - 0x0800 + 4; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 735 | mark = REG_RD(bp, addr); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 736 | mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH) |
| 737 | + ((mark + 0x3) & ~0x3) - 0x08000000; |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 738 | printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 739 | |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 740 | printk("%s", lvl); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 741 | for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 742 | for (word = 0; word < 8; word++) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 743 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 744 | data[8] = 0x0; |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 745 | pr_cont("%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 746 | } |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 747 | for (offset = addr + 4; offset <= mark; offset += 0x8*4) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 748 | for (word = 0; word < 8; word++) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 749 | data[word] = htonl(REG_RD(bp, offset + 4*word)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 750 | data[8] = 0x0; |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 751 | pr_cont("%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 752 | } |
Dmitry Kravkov | 7a25cc7 | 2011-06-14 01:33:25 +0000 | [diff] [blame] | 753 | printk("%s" "end of fw dump\n", lvl); |
| 754 | } |
| 755 | |
| 756 | static inline void bnx2x_fw_dump(struct bnx2x *bp) |
| 757 | { |
| 758 | bnx2x_fw_dump_lvl(bp, KERN_ERR); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 759 | } |
| 760 | |
Dmitry Kravkov | 6c719d0 | 2010-07-27 12:36:15 +0000 | [diff] [blame] | 761 | void bnx2x_panic_dump(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 762 | { |
| 763 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 764 | u16 j; |
| 765 | struct hc_sp_status_block_data sp_sb_data; |
| 766 | int func = BP_FUNC(bp); |
| 767 | #ifdef BNX2X_STOP_ON_ERROR |
| 768 | u16 start = 0, end = 0; |
| 769 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 770 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 771 | bp->stats_state = STATS_STATE_DISABLED; |
| 772 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 773 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 774 | BNX2X_ERR("begin crash dump -----------------\n"); |
| 775 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 776 | /* Indices */ |
| 777 | /* Common */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 778 | BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)" |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 779 | " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n", |
| 780 | bp->def_idx, bp->def_att_idx, bp->attn_state, |
| 781 | bp->spq_prod_idx, bp->stats_counter); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 782 | BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n", |
| 783 | bp->def_status_blk->atten_status_block.attn_bits, |
| 784 | bp->def_status_blk->atten_status_block.attn_bits_ack, |
| 785 | bp->def_status_blk->atten_status_block.status_block_id, |
| 786 | bp->def_status_blk->atten_status_block.attn_bits_index); |
| 787 | BNX2X_ERR(" def ("); |
| 788 | for (i = 0; i < HC_SP_SB_MAX_INDICES; i++) |
| 789 | pr_cont("0x%x%s", |
| 790 | bp->def_status_blk->sp_sb.index_values[i], |
| 791 | (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " "); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 792 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 793 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) |
| 794 | *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 795 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + |
| 796 | i*sizeof(u32)); |
| 797 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 798 | pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) " |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 799 | "pf_id(0x%x) vnic_id(0x%x) " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 800 | "vf_id(0x%x) vf_valid (0x%x) " |
| 801 | "state(0x%x)\n", |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 802 | sp_sb_data.igu_sb_id, |
| 803 | sp_sb_data.igu_seg_id, |
| 804 | sp_sb_data.p_func.pf_id, |
| 805 | sp_sb_data.p_func.vnic_id, |
| 806 | sp_sb_data.p_func.vf_id, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 807 | sp_sb_data.p_func.vf_valid, |
| 808 | sp_sb_data.state); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 809 | |
| 810 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 811 | for_each_eth_queue(bp, i) { |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 812 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 813 | int loop; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 814 | struct hc_status_block_data_e2 sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 815 | struct hc_status_block_data_e1x sb_data_e1x; |
| 816 | struct hc_status_block_sm *hc_sm_p = |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 817 | CHIP_IS_E1x(bp) ? |
| 818 | sb_data_e1x.common.state_machine : |
| 819 | sb_data_e2.common.state_machine; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 820 | struct hc_index_data *hc_index_p = |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 821 | CHIP_IS_E1x(bp) ? |
| 822 | sb_data_e1x.index_data : |
| 823 | sb_data_e2.index_data; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 824 | int data_size; |
| 825 | u32 *sb_data_p; |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 826 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 827 | /* Rx */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 828 | BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)" |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 829 | " rx_comp_prod(0x%x)" |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 830 | " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n", |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 831 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 832 | fp->rx_comp_prod, |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 833 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 834 | BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)" |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 835 | " fp_hc_idx(0x%x)\n", |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 836 | fp->rx_sge_prod, fp->last_max_sge, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 837 | le16_to_cpu(fp->fp_hc_idx)); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 838 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 839 | /* Tx */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 840 | BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)" |
| 841 | " tx_bd_prod(0x%x) tx_bd_cons(0x%x)" |
| 842 | " *tx_cons_sb(0x%x)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 843 | i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 844 | fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 845 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 846 | loop = CHIP_IS_E1x(bp) ? |
| 847 | HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 848 | |
| 849 | /* host sb data */ |
| 850 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 851 | #ifdef BCM_CNIC |
| 852 | if (IS_FCOE_FP(fp)) |
| 853 | continue; |
| 854 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 855 | BNX2X_ERR(" run indexes ("); |
| 856 | for (j = 0; j < HC_SB_MAX_SM; j++) |
| 857 | pr_cont("0x%x%s", |
| 858 | fp->sb_running_index[j], |
| 859 | (j == HC_SB_MAX_SM - 1) ? ")" : " "); |
| 860 | |
| 861 | BNX2X_ERR(" indexes ("); |
| 862 | for (j = 0; j < loop; j++) |
| 863 | pr_cont("0x%x%s", |
| 864 | fp->sb_index_values[j], |
| 865 | (j == loop - 1) ? ")" : " "); |
| 866 | /* fw sb data */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 867 | data_size = CHIP_IS_E1x(bp) ? |
| 868 | sizeof(struct hc_status_block_data_e1x) : |
| 869 | sizeof(struct hc_status_block_data_e2); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 870 | data_size /= sizeof(u32); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 871 | sb_data_p = CHIP_IS_E1x(bp) ? |
| 872 | (u32 *)&sb_data_e1x : |
| 873 | (u32 *)&sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 874 | /* copy sb data in here */ |
| 875 | for (j = 0; j < data_size; j++) |
| 876 | *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 877 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) + |
| 878 | j * sizeof(u32)); |
| 879 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 880 | if (!CHIP_IS_E1x(bp)) { |
| 881 | pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) " |
| 882 | "vnic_id(0x%x) same_igu_sb_1b(0x%x) " |
| 883 | "state(0x%x)\n", |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 884 | sb_data_e2.common.p_func.pf_id, |
| 885 | sb_data_e2.common.p_func.vf_id, |
| 886 | sb_data_e2.common.p_func.vf_valid, |
| 887 | sb_data_e2.common.p_func.vnic_id, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 888 | sb_data_e2.common.same_igu_sb_1b, |
| 889 | sb_data_e2.common.state); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 890 | } else { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 891 | pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) " |
| 892 | "vnic_id(0x%x) same_igu_sb_1b(0x%x) " |
| 893 | "state(0x%x)\n", |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 894 | sb_data_e1x.common.p_func.pf_id, |
| 895 | sb_data_e1x.common.p_func.vf_id, |
| 896 | sb_data_e1x.common.p_func.vf_valid, |
| 897 | sb_data_e1x.common.p_func.vnic_id, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 898 | sb_data_e1x.common.same_igu_sb_1b, |
| 899 | sb_data_e1x.common.state); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 900 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 901 | |
| 902 | /* SB_SMs data */ |
| 903 | for (j = 0; j < HC_SB_MAX_SM; j++) { |
| 904 | pr_cont("SM[%d] __flags (0x%x) " |
| 905 | "igu_sb_id (0x%x) igu_seg_id(0x%x) " |
| 906 | "time_to_expire (0x%x) " |
| 907 | "timer_value(0x%x)\n", j, |
| 908 | hc_sm_p[j].__flags, |
| 909 | hc_sm_p[j].igu_sb_id, |
| 910 | hc_sm_p[j].igu_seg_id, |
| 911 | hc_sm_p[j].time_to_expire, |
| 912 | hc_sm_p[j].timer_value); |
| 913 | } |
| 914 | |
| 915 | /* Indecies data */ |
| 916 | for (j = 0; j < loop; j++) { |
| 917 | pr_cont("INDEX[%d] flags (0x%x) " |
| 918 | "timeout (0x%x)\n", j, |
| 919 | hc_index_p[j].flags, |
| 920 | hc_index_p[j].timeout); |
| 921 | } |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 922 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 923 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 924 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 925 | /* Rings */ |
| 926 | /* Rx */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 927 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 928 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 929 | |
| 930 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); |
| 931 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 932 | for (j = start; j != end; j = RX_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 933 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
| 934 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; |
| 935 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 936 | BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
| 937 | i, j, rx_bd[1], rx_bd[0], sw_bd->skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 938 | } |
| 939 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 940 | start = RX_SGE(fp->rx_sge_prod); |
| 941 | end = RX_SGE(fp->last_max_sge); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 942 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 943 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
| 944 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; |
| 945 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 946 | BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
| 947 | i, j, rx_sge[1], rx_sge[0], sw_page->page); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 950 | start = RCQ_BD(fp->rx_comp_cons - 10); |
| 951 | end = RCQ_BD(fp->rx_comp_cons + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 952 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 953 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
| 954 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 955 | BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n", |
| 956 | i, j, cqe[0], cqe[1], cqe[2], cqe[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 960 | /* Tx */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 961 | for_each_tx_queue(bp, i) { |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 962 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 963 | |
| 964 | start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10); |
| 965 | end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245); |
| 966 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 967 | struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j]; |
| 968 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 969 | BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n", |
| 970 | i, j, sw_bd->skb, sw_bd->first_bd); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | start = TX_BD(fp->tx_bd_cons - 10); |
| 974 | end = TX_BD(fp->tx_bd_cons + 254); |
| 975 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 976 | u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j]; |
| 977 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 978 | BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n", |
| 979 | i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 982 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 983 | bnx2x_fw_dump(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 984 | bnx2x_mc_assert(bp); |
| 985 | BNX2X_ERR("end crash dump -----------------\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 986 | } |
| 987 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 988 | /* |
| 989 | * FLR Support for E2 |
| 990 | * |
| 991 | * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW |
| 992 | * initialization. |
| 993 | */ |
| 994 | #define FLR_WAIT_USEC 10000 /* 10 miliseconds */ |
| 995 | #define FLR_WAIT_INTERAVAL 50 /* usec */ |
| 996 | #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */ |
| 997 | |
| 998 | struct pbf_pN_buf_regs { |
| 999 | int pN; |
| 1000 | u32 init_crd; |
| 1001 | u32 crd; |
| 1002 | u32 crd_freed; |
| 1003 | }; |
| 1004 | |
| 1005 | struct pbf_pN_cmd_regs { |
| 1006 | int pN; |
| 1007 | u32 lines_occup; |
| 1008 | u32 lines_freed; |
| 1009 | }; |
| 1010 | |
| 1011 | static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp, |
| 1012 | struct pbf_pN_buf_regs *regs, |
| 1013 | u32 poll_count) |
| 1014 | { |
| 1015 | u32 init_crd, crd, crd_start, crd_freed, crd_freed_start; |
| 1016 | u32 cur_cnt = poll_count; |
| 1017 | |
| 1018 | crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed); |
| 1019 | crd = crd_start = REG_RD(bp, regs->crd); |
| 1020 | init_crd = REG_RD(bp, regs->init_crd); |
| 1021 | |
| 1022 | DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd); |
| 1023 | DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd); |
| 1024 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed); |
| 1025 | |
| 1026 | while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) < |
| 1027 | (init_crd - crd_start))) { |
| 1028 | if (cur_cnt--) { |
| 1029 | udelay(FLR_WAIT_INTERAVAL); |
| 1030 | crd = REG_RD(bp, regs->crd); |
| 1031 | crd_freed = REG_RD(bp, regs->crd_freed); |
| 1032 | } else { |
| 1033 | DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n", |
| 1034 | regs->pN); |
| 1035 | DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n", |
| 1036 | regs->pN, crd); |
| 1037 | DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n", |
| 1038 | regs->pN, crd_freed); |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n", |
| 1043 | poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN); |
| 1044 | } |
| 1045 | |
| 1046 | static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp, |
| 1047 | struct pbf_pN_cmd_regs *regs, |
| 1048 | u32 poll_count) |
| 1049 | { |
| 1050 | u32 occup, to_free, freed, freed_start; |
| 1051 | u32 cur_cnt = poll_count; |
| 1052 | |
| 1053 | occup = to_free = REG_RD(bp, regs->lines_occup); |
| 1054 | freed = freed_start = REG_RD(bp, regs->lines_freed); |
| 1055 | |
| 1056 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup); |
| 1057 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed); |
| 1058 | |
| 1059 | while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) { |
| 1060 | if (cur_cnt--) { |
| 1061 | udelay(FLR_WAIT_INTERAVAL); |
| 1062 | occup = REG_RD(bp, regs->lines_occup); |
| 1063 | freed = REG_RD(bp, regs->lines_freed); |
| 1064 | } else { |
| 1065 | DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n", |
| 1066 | regs->pN); |
| 1067 | DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", |
| 1068 | regs->pN, occup); |
| 1069 | DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", |
| 1070 | regs->pN, freed); |
| 1071 | break; |
| 1072 | } |
| 1073 | } |
| 1074 | DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n", |
| 1075 | poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN); |
| 1076 | } |
| 1077 | |
| 1078 | static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg, |
| 1079 | u32 expected, u32 poll_count) |
| 1080 | { |
| 1081 | u32 cur_cnt = poll_count; |
| 1082 | u32 val; |
| 1083 | |
| 1084 | while ((val = REG_RD(bp, reg)) != expected && cur_cnt--) |
| 1085 | udelay(FLR_WAIT_INTERAVAL); |
| 1086 | |
| 1087 | return val; |
| 1088 | } |
| 1089 | |
| 1090 | static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg, |
| 1091 | char *msg, u32 poll_cnt) |
| 1092 | { |
| 1093 | u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt); |
| 1094 | if (val != 0) { |
| 1095 | BNX2X_ERR("%s usage count=%d\n", msg, val); |
| 1096 | return 1; |
| 1097 | } |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp) |
| 1102 | { |
| 1103 | /* adjust polling timeout */ |
| 1104 | if (CHIP_REV_IS_EMUL(bp)) |
| 1105 | return FLR_POLL_CNT * 2000; |
| 1106 | |
| 1107 | if (CHIP_REV_IS_FPGA(bp)) |
| 1108 | return FLR_POLL_CNT * 120; |
| 1109 | |
| 1110 | return FLR_POLL_CNT; |
| 1111 | } |
| 1112 | |
| 1113 | static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count) |
| 1114 | { |
| 1115 | struct pbf_pN_cmd_regs cmd_regs[] = { |
| 1116 | {0, (CHIP_IS_E3B0(bp)) ? |
| 1117 | PBF_REG_TQ_OCCUPANCY_Q0 : |
| 1118 | PBF_REG_P0_TQ_OCCUPANCY, |
| 1119 | (CHIP_IS_E3B0(bp)) ? |
| 1120 | PBF_REG_TQ_LINES_FREED_CNT_Q0 : |
| 1121 | PBF_REG_P0_TQ_LINES_FREED_CNT}, |
| 1122 | {1, (CHIP_IS_E3B0(bp)) ? |
| 1123 | PBF_REG_TQ_OCCUPANCY_Q1 : |
| 1124 | PBF_REG_P1_TQ_OCCUPANCY, |
| 1125 | (CHIP_IS_E3B0(bp)) ? |
| 1126 | PBF_REG_TQ_LINES_FREED_CNT_Q1 : |
| 1127 | PBF_REG_P1_TQ_LINES_FREED_CNT}, |
| 1128 | {4, (CHIP_IS_E3B0(bp)) ? |
| 1129 | PBF_REG_TQ_OCCUPANCY_LB_Q : |
| 1130 | PBF_REG_P4_TQ_OCCUPANCY, |
| 1131 | (CHIP_IS_E3B0(bp)) ? |
| 1132 | PBF_REG_TQ_LINES_FREED_CNT_LB_Q : |
| 1133 | PBF_REG_P4_TQ_LINES_FREED_CNT} |
| 1134 | }; |
| 1135 | |
| 1136 | struct pbf_pN_buf_regs buf_regs[] = { |
| 1137 | {0, (CHIP_IS_E3B0(bp)) ? |
| 1138 | PBF_REG_INIT_CRD_Q0 : |
| 1139 | PBF_REG_P0_INIT_CRD , |
| 1140 | (CHIP_IS_E3B0(bp)) ? |
| 1141 | PBF_REG_CREDIT_Q0 : |
| 1142 | PBF_REG_P0_CREDIT, |
| 1143 | (CHIP_IS_E3B0(bp)) ? |
| 1144 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 : |
| 1145 | PBF_REG_P0_INTERNAL_CRD_FREED_CNT}, |
| 1146 | {1, (CHIP_IS_E3B0(bp)) ? |
| 1147 | PBF_REG_INIT_CRD_Q1 : |
| 1148 | PBF_REG_P1_INIT_CRD, |
| 1149 | (CHIP_IS_E3B0(bp)) ? |
| 1150 | PBF_REG_CREDIT_Q1 : |
| 1151 | PBF_REG_P1_CREDIT, |
| 1152 | (CHIP_IS_E3B0(bp)) ? |
| 1153 | PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 : |
| 1154 | PBF_REG_P1_INTERNAL_CRD_FREED_CNT}, |
| 1155 | {4, (CHIP_IS_E3B0(bp)) ? |
| 1156 | PBF_REG_INIT_CRD_LB_Q : |
| 1157 | PBF_REG_P4_INIT_CRD, |
| 1158 | (CHIP_IS_E3B0(bp)) ? |
| 1159 | PBF_REG_CREDIT_LB_Q : |
| 1160 | PBF_REG_P4_CREDIT, |
| 1161 | (CHIP_IS_E3B0(bp)) ? |
| 1162 | PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q : |
| 1163 | PBF_REG_P4_INTERNAL_CRD_FREED_CNT}, |
| 1164 | }; |
| 1165 | |
| 1166 | int i; |
| 1167 | |
| 1168 | /* Verify the command queues are flushed P0, P1, P4 */ |
| 1169 | for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) |
| 1170 | bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count); |
| 1171 | |
| 1172 | |
| 1173 | /* Verify the transmission buffers are flushed P0, P1, P4 */ |
| 1174 | for (i = 0; i < ARRAY_SIZE(buf_regs); i++) |
| 1175 | bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count); |
| 1176 | } |
| 1177 | |
| 1178 | #define OP_GEN_PARAM(param) \ |
| 1179 | (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM) |
| 1180 | |
| 1181 | #define OP_GEN_TYPE(type) \ |
| 1182 | (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE) |
| 1183 | |
| 1184 | #define OP_GEN_AGG_VECT(index) \ |
| 1185 | (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX) |
| 1186 | |
| 1187 | |
| 1188 | static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, |
| 1189 | u32 poll_cnt) |
| 1190 | { |
| 1191 | struct sdm_op_gen op_gen = {0}; |
| 1192 | |
| 1193 | u32 comp_addr = BAR_CSTRORM_INTMEM + |
| 1194 | CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func); |
| 1195 | int ret = 0; |
| 1196 | |
| 1197 | if (REG_RD(bp, comp_addr)) { |
| 1198 | BNX2X_ERR("Cleanup complete is not 0\n"); |
| 1199 | return 1; |
| 1200 | } |
| 1201 | |
| 1202 | op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX); |
| 1203 | op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE); |
| 1204 | op_gen.command |= OP_GEN_AGG_VECT(clnup_func); |
| 1205 | op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT; |
| 1206 | |
| 1207 | DP(BNX2X_MSG_SP, "FW Final cleanup\n"); |
| 1208 | REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command); |
| 1209 | |
| 1210 | if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) { |
| 1211 | BNX2X_ERR("FW final cleanup did not succeed\n"); |
| 1212 | ret = 1; |
| 1213 | } |
| 1214 | /* Zero completion for nxt FLR */ |
| 1215 | REG_WR(bp, comp_addr, 0); |
| 1216 | |
| 1217 | return ret; |
| 1218 | } |
| 1219 | |
| 1220 | static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev) |
| 1221 | { |
| 1222 | int pos; |
| 1223 | u16 status; |
| 1224 | |
| 1225 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
| 1226 | if (!pos) |
| 1227 | return false; |
| 1228 | |
| 1229 | pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); |
| 1230 | return status & PCI_EXP_DEVSTA_TRPND; |
| 1231 | } |
| 1232 | |
| 1233 | /* PF FLR specific routines |
| 1234 | */ |
| 1235 | static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt) |
| 1236 | { |
| 1237 | |
| 1238 | /* wait for CFC PF usage-counter to zero (includes all the VFs) */ |
| 1239 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1240 | CFC_REG_NUM_LCIDS_INSIDE_PF, |
| 1241 | "CFC PF usage counter timed out", |
| 1242 | poll_cnt)) |
| 1243 | return 1; |
| 1244 | |
| 1245 | |
| 1246 | /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */ |
| 1247 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1248 | DORQ_REG_PF_USAGE_CNT, |
| 1249 | "DQ PF usage counter timed out", |
| 1250 | poll_cnt)) |
| 1251 | return 1; |
| 1252 | |
| 1253 | /* Wait for QM PF usage-counter to zero (until DQ cleanup) */ |
| 1254 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1255 | QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp), |
| 1256 | "QM PF usage counter timed out", |
| 1257 | poll_cnt)) |
| 1258 | return 1; |
| 1259 | |
| 1260 | /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */ |
| 1261 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1262 | TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp), |
| 1263 | "Timers VNIC usage counter timed out", |
| 1264 | poll_cnt)) |
| 1265 | return 1; |
| 1266 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1267 | TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp), |
| 1268 | "Timers NUM_SCANS usage counter timed out", |
| 1269 | poll_cnt)) |
| 1270 | return 1; |
| 1271 | |
| 1272 | /* Wait DMAE PF usage counter to zero */ |
| 1273 | if (bnx2x_flr_clnup_poll_hw_counter(bp, |
| 1274 | dmae_reg_go_c[INIT_DMAE_C(bp)], |
| 1275 | "DMAE dommand register timed out", |
| 1276 | poll_cnt)) |
| 1277 | return 1; |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | static void bnx2x_hw_enable_status(struct bnx2x *bp) |
| 1283 | { |
| 1284 | u32 val; |
| 1285 | |
| 1286 | val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF); |
| 1287 | DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val); |
| 1288 | |
| 1289 | val = REG_RD(bp, PBF_REG_DISABLE_PF); |
| 1290 | DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val); |
| 1291 | |
| 1292 | val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN); |
| 1293 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val); |
| 1294 | |
| 1295 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN); |
| 1296 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val); |
| 1297 | |
| 1298 | val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK); |
| 1299 | DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val); |
| 1300 | |
| 1301 | val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR); |
| 1302 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val); |
| 1303 | |
| 1304 | val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR); |
| 1305 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val); |
| 1306 | |
| 1307 | val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); |
| 1308 | DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n", |
| 1309 | val); |
| 1310 | } |
| 1311 | |
| 1312 | static int bnx2x_pf_flr_clnup(struct bnx2x *bp) |
| 1313 | { |
| 1314 | u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp); |
| 1315 | |
| 1316 | DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp)); |
| 1317 | |
| 1318 | /* Re-enable PF target read access */ |
| 1319 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); |
| 1320 | |
| 1321 | /* Poll HW usage counters */ |
| 1322 | if (bnx2x_poll_hw_usage_counters(bp, poll_cnt)) |
| 1323 | return -EBUSY; |
| 1324 | |
| 1325 | /* Zero the igu 'trailing edge' and 'leading edge' */ |
| 1326 | |
| 1327 | /* Send the FW cleanup command */ |
| 1328 | if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt)) |
| 1329 | return -EBUSY; |
| 1330 | |
| 1331 | /* ATC cleanup */ |
| 1332 | |
| 1333 | /* Verify TX hw is flushed */ |
| 1334 | bnx2x_tx_hw_flushed(bp, poll_cnt); |
| 1335 | |
| 1336 | /* Wait 100ms (not adjusted according to platform) */ |
| 1337 | msleep(100); |
| 1338 | |
| 1339 | /* Verify no pending pci transactions */ |
| 1340 | if (bnx2x_is_pcie_pending(bp->pdev)) |
| 1341 | BNX2X_ERR("PCIE Transactions still pending\n"); |
| 1342 | |
| 1343 | /* Debug */ |
| 1344 | bnx2x_hw_enable_status(bp); |
| 1345 | |
| 1346 | /* |
| 1347 | * Master enable - Due to WB DMAE writes performed before this |
| 1348 | * register is re-initialized as part of the regular function init |
| 1349 | */ |
| 1350 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
| 1351 | |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 1355 | static void bnx2x_hc_int_enable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1356 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1357 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1358 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 1359 | u32 val = REG_RD(bp, addr); |
| 1360 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1361 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1362 | |
| 1363 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1364 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 1365 | HC_CONFIG_0_REG_INT_LINE_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1366 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 1367 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1368 | } else if (msi) { |
| 1369 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; |
| 1370 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 1371 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 1372 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1373 | } else { |
| 1374 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 1375 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1376 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 1377 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 1378 | |
Dmitry Kravkov | a0fd065 | 2010-10-19 05:13:05 +0000 | [diff] [blame] | 1379 | if (!CHIP_IS_E1(bp)) { |
| 1380 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 1381 | val, port, addr); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 1382 | |
Dmitry Kravkov | a0fd065 | 2010-10-19 05:13:05 +0000 | [diff] [blame] | 1383 | REG_WR(bp, addr, val); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 1384 | |
Dmitry Kravkov | a0fd065 | 2010-10-19 05:13:05 +0000 | [diff] [blame] | 1385 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
| 1386 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Dmitry Kravkov | a0fd065 | 2010-10-19 05:13:05 +0000 | [diff] [blame] | 1389 | if (CHIP_IS_E1(bp)) |
| 1390 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF); |
| 1391 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1392 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n", |
| 1393 | val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1394 | |
| 1395 | REG_WR(bp, addr, val); |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 1396 | /* |
| 1397 | * Ensure that HC_CONFIG is written before leading/trailing edge config |
| 1398 | */ |
| 1399 | mmiowb(); |
| 1400 | barrier(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1401 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 1402 | if (!CHIP_IS_E1(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1403 | /* init leading/trailing edge */ |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 1404 | if (IS_MF(bp)) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1405 | val = (0xee0f | (1 << (BP_E1HVN(bp) + 4))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1406 | if (bp->port.pmf) |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1407 | /* enable nig and gpio3 attention */ |
| 1408 | val |= 0x1100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1409 | } else |
| 1410 | val = 0xffff; |
| 1411 | |
| 1412 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 1413 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
| 1414 | } |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 1415 | |
| 1416 | /* Make sure that interrupts are indeed enabled from here on */ |
| 1417 | mmiowb(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 1420 | static void bnx2x_igu_int_enable(struct bnx2x *bp) |
| 1421 | { |
| 1422 | u32 val; |
| 1423 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
| 1424 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
| 1425 | |
| 1426 | val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); |
| 1427 | |
| 1428 | if (msix) { |
| 1429 | val &= ~(IGU_PF_CONF_INT_LINE_EN | |
| 1430 | IGU_PF_CONF_SINGLE_ISR_EN); |
| 1431 | val |= (IGU_PF_CONF_FUNC_EN | |
| 1432 | IGU_PF_CONF_MSI_MSIX_EN | |
| 1433 | IGU_PF_CONF_ATTN_BIT_EN); |
| 1434 | } else if (msi) { |
| 1435 | val &= ~IGU_PF_CONF_INT_LINE_EN; |
| 1436 | val |= (IGU_PF_CONF_FUNC_EN | |
| 1437 | IGU_PF_CONF_MSI_MSIX_EN | |
| 1438 | IGU_PF_CONF_ATTN_BIT_EN | |
| 1439 | IGU_PF_CONF_SINGLE_ISR_EN); |
| 1440 | } else { |
| 1441 | val &= ~IGU_PF_CONF_MSI_MSIX_EN; |
| 1442 | val |= (IGU_PF_CONF_FUNC_EN | |
| 1443 | IGU_PF_CONF_INT_LINE_EN | |
| 1444 | IGU_PF_CONF_ATTN_BIT_EN | |
| 1445 | IGU_PF_CONF_SINGLE_ISR_EN); |
| 1446 | } |
| 1447 | |
| 1448 | DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n", |
| 1449 | val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
| 1450 | |
| 1451 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); |
| 1452 | |
| 1453 | barrier(); |
| 1454 | |
| 1455 | /* init leading/trailing edge */ |
| 1456 | if (IS_MF(bp)) { |
| 1457 | val = (0xee0f | (1 << (BP_E1HVN(bp) + 4))); |
| 1458 | if (bp->port.pmf) |
| 1459 | /* enable nig and gpio3 attention */ |
| 1460 | val |= 0x1100; |
| 1461 | } else |
| 1462 | val = 0xffff; |
| 1463 | |
| 1464 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); |
| 1465 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); |
| 1466 | |
| 1467 | /* Make sure that interrupts are indeed enabled from here on */ |
| 1468 | mmiowb(); |
| 1469 | } |
| 1470 | |
| 1471 | void bnx2x_int_enable(struct bnx2x *bp) |
| 1472 | { |
| 1473 | if (bp->common.int_block == INT_BLOCK_HC) |
| 1474 | bnx2x_hc_int_enable(bp); |
| 1475 | else |
| 1476 | bnx2x_igu_int_enable(bp); |
| 1477 | } |
| 1478 | |
| 1479 | static void bnx2x_hc_int_disable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1480 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1481 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1482 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 1483 | u32 val = REG_RD(bp, addr); |
| 1484 | |
Dmitry Kravkov | a0fd065 | 2010-10-19 05:13:05 +0000 | [diff] [blame] | 1485 | /* |
| 1486 | * in E1 we must use only PCI configuration space to disable |
| 1487 | * MSI/MSIX capablility |
| 1488 | * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block |
| 1489 | */ |
| 1490 | if (CHIP_IS_E1(bp)) { |
| 1491 | /* Since IGU_PF_CONF_MSI_MSIX_EN still always on |
| 1492 | * Use mask register to prevent from HC sending interrupts |
| 1493 | * after we exit the function |
| 1494 | */ |
| 1495 | REG_WR(bp, HC_REG_INT_MASK + port*4, 0); |
| 1496 | |
| 1497 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 1498 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 1499 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
| 1500 | } else |
| 1501 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 1502 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 1503 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 1504 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1505 | |
| 1506 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 1507 | val, port, addr); |
| 1508 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1509 | /* flush all outstanding writes */ |
| 1510 | mmiowb(); |
| 1511 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1512 | REG_WR(bp, addr, val); |
| 1513 | if (REG_RD(bp, addr) != val) |
| 1514 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); |
| 1515 | } |
| 1516 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 1517 | static void bnx2x_igu_int_disable(struct bnx2x *bp) |
| 1518 | { |
| 1519 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); |
| 1520 | |
| 1521 | val &= ~(IGU_PF_CONF_MSI_MSIX_EN | |
| 1522 | IGU_PF_CONF_INT_LINE_EN | |
| 1523 | IGU_PF_CONF_ATTN_BIT_EN); |
| 1524 | |
| 1525 | DP(NETIF_MSG_INTR, "write %x to IGU\n", val); |
| 1526 | |
| 1527 | /* flush all outstanding writes */ |
| 1528 | mmiowb(); |
| 1529 | |
| 1530 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); |
| 1531 | if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val) |
| 1532 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); |
| 1533 | } |
| 1534 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 1535 | static void bnx2x_int_disable(struct bnx2x *bp) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 1536 | { |
| 1537 | if (bp->common.int_block == INT_BLOCK_HC) |
| 1538 | bnx2x_hc_int_disable(bp); |
| 1539 | else |
| 1540 | bnx2x_igu_int_disable(bp); |
| 1541 | } |
| 1542 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1543 | void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1544 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1545 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1546 | int i, offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1547 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 1548 | if (disable_hw) |
| 1549 | /* prevent the HW from sending interrupts */ |
| 1550 | bnx2x_int_disable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1551 | |
| 1552 | /* make sure all ISRs are done */ |
| 1553 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1554 | synchronize_irq(bp->msix_table[0].vector); |
| 1555 | offset = 1; |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 1556 | #ifdef BCM_CNIC |
| 1557 | offset++; |
| 1558 | #endif |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 1559 | for_each_eth_queue(bp, i) |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 1560 | synchronize_irq(bp->msix_table[i + offset].vector); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1561 | } else |
| 1562 | synchronize_irq(bp->pdev->irq); |
| 1563 | |
| 1564 | /* make sure sp_task is not running */ |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 1565 | cancel_delayed_work(&bp->sp_task); |
| 1566 | flush_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1567 | } |
| 1568 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1569 | /* fast path */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1570 | |
| 1571 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1572 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1573 | */ |
| 1574 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 1575 | /* Return true if succeeded to acquire the lock */ |
| 1576 | static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource) |
| 1577 | { |
| 1578 | u32 lock_status; |
| 1579 | u32 resource_bit = (1 << resource); |
| 1580 | int func = BP_FUNC(bp); |
| 1581 | u32 hw_lock_control_reg; |
| 1582 | |
| 1583 | DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource); |
| 1584 | |
| 1585 | /* Validating that the resource is within range */ |
| 1586 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1587 | DP(NETIF_MSG_HW, |
| 1588 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1589 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
Eric Dumazet | 0fdf4d0 | 2010-08-26 22:03:53 -0700 | [diff] [blame] | 1590 | return false; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | if (func <= 5) |
| 1594 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1595 | else |
| 1596 | hw_lock_control_reg = |
| 1597 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1598 | |
| 1599 | /* Try to acquire the lock */ |
| 1600 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
| 1601 | lock_status = REG_RD(bp, hw_lock_control_reg); |
| 1602 | if (lock_status & resource_bit) |
| 1603 | return true; |
| 1604 | |
| 1605 | DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource); |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 1609 | /** |
| 1610 | * bnx2x_get_leader_lock_resource - get the recovery leader resource id |
| 1611 | * |
| 1612 | * @bp: driver handle |
| 1613 | * |
| 1614 | * Returns the recovery leader resource id according to the engine this function |
| 1615 | * belongs to. Currently only only 2 engines is supported. |
| 1616 | */ |
| 1617 | static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp) |
| 1618 | { |
| 1619 | if (BP_PATH(bp)) |
| 1620 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_1; |
| 1621 | else |
| 1622 | return HW_LOCK_RESOURCE_RECOVERY_LEADER_0; |
| 1623 | } |
| 1624 | |
| 1625 | /** |
| 1626 | * bnx2x_trylock_leader_lock- try to aquire a leader lock. |
| 1627 | * |
| 1628 | * @bp: driver handle |
| 1629 | * |
| 1630 | * Tries to aquire a leader lock for cuurent engine. |
| 1631 | */ |
| 1632 | static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp) |
| 1633 | { |
| 1634 | return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); |
| 1635 | } |
| 1636 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 1637 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1638 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 1639 | #endif |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1640 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1641 | void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1642 | { |
| 1643 | struct bnx2x *bp = fp->bp; |
| 1644 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 1645 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1646 | enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX; |
| 1647 | struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1648 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1649 | DP(BNX2X_MSG_SP, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1650 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1651 | fp->index, cid, command, bp->state, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1652 | rr_cqe->ramrod_cqe.ramrod_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1653 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1654 | switch (command) { |
| 1655 | case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE): |
| 1656 | DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid); |
| 1657 | drv_cmd = BNX2X_Q_CMD_UPDATE; |
| 1658 | break; |
| 1659 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP): |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1660 | DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1661 | drv_cmd = BNX2X_Q_CMD_SETUP; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1662 | break; |
| 1663 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1664 | case (RAMROD_CMD_ID_ETH_HALT): |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1665 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1666 | drv_cmd = BNX2X_Q_CMD_HALT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1667 | break; |
| 1668 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1669 | case (RAMROD_CMD_ID_ETH_TERMINATE): |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1670 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1671 | drv_cmd = BNX2X_Q_CMD_TERMINATE; |
| 1672 | break; |
| 1673 | |
| 1674 | case (RAMROD_CMD_ID_ETH_EMPTY): |
| 1675 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid); |
| 1676 | drv_cmd = BNX2X_Q_CMD_EMPTY; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1677 | break; |
| 1678 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1679 | default: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1680 | BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n", |
| 1681 | command, fp->index); |
| 1682 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1683 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1684 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1685 | if ((drv_cmd != BNX2X_Q_CMD_MAX) && |
| 1686 | q_obj->complete_cmd(bp, q_obj, drv_cmd)) |
| 1687 | /* q_obj->complete_cmd() failure means that this was |
| 1688 | * an unexpected completion. |
| 1689 | * |
| 1690 | * In this case we don't want to increase the bp->spq_left |
| 1691 | * because apparently we haven't sent this command the first |
| 1692 | * place. |
| 1693 | */ |
| 1694 | #ifdef BNX2X_STOP_ON_ERROR |
| 1695 | bnx2x_panic(); |
| 1696 | #else |
| 1697 | return; |
| 1698 | #endif |
| 1699 | |
Dmitry Kravkov | 8fe23fb | 2010-10-06 03:27:41 +0000 | [diff] [blame] | 1700 | smp_mb__before_atomic_inc(); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 1701 | atomic_inc(&bp->cq_spq_left); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1702 | /* push the change in bp->spq_left and towards the memory */ |
| 1703 | smp_mb__after_atomic_inc(); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1704 | |
| 1705 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1706 | } |
| 1707 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1708 | void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1709 | u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod) |
| 1710 | { |
| 1711 | u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset; |
| 1712 | |
| 1713 | bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod, |
| 1714 | start); |
| 1715 | } |
| 1716 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1717 | irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1718 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1719 | struct bnx2x *bp = netdev_priv(dev_instance); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1720 | u16 status = bnx2x_ack_int(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1721 | u16 mask; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1722 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1723 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1724 | /* Return here if interrupt is shared and it's not for us */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1725 | if (unlikely(status == 0)) { |
| 1726 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); |
| 1727 | return IRQ_NONE; |
| 1728 | } |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 1729 | DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1730 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1731 | #ifdef BNX2X_STOP_ON_ERROR |
| 1732 | if (unlikely(bp->panic)) |
| 1733 | return IRQ_HANDLED; |
| 1734 | #endif |
| 1735 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 1736 | for_each_eth_queue(bp, i) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1737 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1738 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1739 | mask = 0x2 << (fp->index + CNIC_CONTEXT_USE); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1740 | if (status & mask) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1741 | /* Handle Rx or Tx according to SB id */ |
Vladislav Zolotarov | 54b9dda | 2009-11-16 06:05:58 +0000 | [diff] [blame] | 1742 | prefetch(fp->rx_cons_sb); |
Vladislav Zolotarov | 54b9dda | 2009-11-16 06:05:58 +0000 | [diff] [blame] | 1743 | prefetch(fp->tx_cons_sb); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1744 | prefetch(&fp->sb_running_index[SM_RX_ID]); |
Vladislav Zolotarov | 54b9dda | 2009-11-16 06:05:58 +0000 | [diff] [blame] | 1745 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1746 | status &= ~mask; |
| 1747 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1748 | } |
| 1749 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 1750 | #ifdef BCM_CNIC |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1751 | mask = 0x2; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 1752 | if (status & (mask | 0x1)) { |
| 1753 | struct cnic_ops *c_ops = NULL; |
| 1754 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 1755 | if (likely(bp->state == BNX2X_STATE_OPEN)) { |
| 1756 | rcu_read_lock(); |
| 1757 | c_ops = rcu_dereference(bp->cnic_ops); |
| 1758 | if (c_ops) |
| 1759 | c_ops->cnic_handler(bp->cnic_data, NULL); |
| 1760 | rcu_read_unlock(); |
| 1761 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 1762 | |
| 1763 | status &= ~mask; |
| 1764 | } |
| 1765 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1766 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1767 | if (unlikely(status & 0x1)) { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 1768 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1769 | |
| 1770 | status &= ~0x1; |
| 1771 | if (!status) |
| 1772 | return IRQ_HANDLED; |
| 1773 | } |
| 1774 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 1775 | if (unlikely(status)) |
| 1776 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1777 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1778 | |
| 1779 | return IRQ_HANDLED; |
| 1780 | } |
| 1781 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1782 | /* Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1783 | |
| 1784 | /* |
| 1785 | * General service functions |
| 1786 | */ |
| 1787 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1788 | int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1789 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1790 | u32 lock_status; |
| 1791 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1792 | int func = BP_FUNC(bp); |
| 1793 | u32 hw_lock_control_reg; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1794 | int cnt; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1795 | |
| 1796 | /* Validating that the resource is within range */ |
| 1797 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1798 | DP(NETIF_MSG_HW, |
| 1799 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1800 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1801 | return -EINVAL; |
| 1802 | } |
| 1803 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1804 | if (func <= 5) { |
| 1805 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1806 | } else { |
| 1807 | hw_lock_control_reg = |
| 1808 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1809 | } |
| 1810 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1811 | /* Validating that the resource is not already taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1812 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1813 | if (lock_status & resource_bit) { |
| 1814 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1815 | lock_status, resource_bit); |
| 1816 | return -EEXIST; |
| 1817 | } |
| 1818 | |
Eilon Greenstein | 4623047 | 2008-08-25 15:23:30 -0700 | [diff] [blame] | 1819 | /* Try for 5 second every 5ms */ |
| 1820 | for (cnt = 0; cnt < 1000; cnt++) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1821 | /* Try to acquire the lock */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1822 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
| 1823 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1824 | if (lock_status & resource_bit) |
| 1825 | return 0; |
| 1826 | |
| 1827 | msleep(5); |
| 1828 | } |
| 1829 | DP(NETIF_MSG_HW, "Timeout\n"); |
| 1830 | return -EAGAIN; |
| 1831 | } |
| 1832 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 1833 | int bnx2x_release_leader_lock(struct bnx2x *bp) |
| 1834 | { |
| 1835 | return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp)); |
| 1836 | } |
| 1837 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 1838 | int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1839 | { |
| 1840 | u32 lock_status; |
| 1841 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1842 | int func = BP_FUNC(bp); |
| 1843 | u32 hw_lock_control_reg; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1844 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 1845 | DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource); |
| 1846 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1847 | /* Validating that the resource is within range */ |
| 1848 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1849 | DP(NETIF_MSG_HW, |
| 1850 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1851 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1852 | return -EINVAL; |
| 1853 | } |
| 1854 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1855 | if (func <= 5) { |
| 1856 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1857 | } else { |
| 1858 | hw_lock_control_reg = |
| 1859 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1860 | } |
| 1861 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1862 | /* Validating that the resource is currently taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1863 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1864 | if (!(lock_status & resource_bit)) { |
| 1865 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1866 | lock_status, resource_bit); |
| 1867 | return -EFAULT; |
| 1868 | } |
| 1869 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1870 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1871 | return 0; |
| 1872 | } |
| 1873 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1874 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1875 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
| 1876 | { |
| 1877 | /* The GPIO should be swapped if swap register is set and active */ |
| 1878 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 1879 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 1880 | int gpio_shift = gpio_num + |
| 1881 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1882 | u32 gpio_mask = (1 << gpio_shift); |
| 1883 | u32 gpio_reg; |
| 1884 | int value; |
| 1885 | |
| 1886 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1887 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1888 | return -EINVAL; |
| 1889 | } |
| 1890 | |
| 1891 | /* read GPIO value */ |
| 1892 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); |
| 1893 | |
| 1894 | /* get the requested pin value */ |
| 1895 | if ((gpio_reg & gpio_mask) == gpio_mask) |
| 1896 | value = 1; |
| 1897 | else |
| 1898 | value = 0; |
| 1899 | |
| 1900 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); |
| 1901 | |
| 1902 | return value; |
| 1903 | } |
| 1904 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1905 | int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1906 | { |
| 1907 | /* The GPIO should be swapped if swap register is set and active */ |
| 1908 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1909 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1910 | int gpio_shift = gpio_num + |
| 1911 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1912 | u32 gpio_mask = (1 << gpio_shift); |
| 1913 | u32 gpio_reg; |
| 1914 | |
| 1915 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1916 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1917 | return -EINVAL; |
| 1918 | } |
| 1919 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1920 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1921 | /* read GPIO and mask except the float bits */ |
| 1922 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); |
| 1923 | |
| 1924 | switch (mode) { |
| 1925 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: |
| 1926 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n", |
| 1927 | gpio_num, gpio_shift); |
| 1928 | /* clear FLOAT and set CLR */ |
| 1929 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1930 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); |
| 1931 | break; |
| 1932 | |
| 1933 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
| 1934 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n", |
| 1935 | gpio_num, gpio_shift); |
| 1936 | /* clear FLOAT and set SET */ |
| 1937 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1938 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); |
| 1939 | break; |
| 1940 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1941 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1942 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n", |
| 1943 | gpio_num, gpio_shift); |
| 1944 | /* set FLOAT */ |
| 1945 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1946 | break; |
| 1947 | |
| 1948 | default: |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1953 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1958 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
| 1959 | { |
| 1960 | /* The GPIO should be swapped if swap register is set and active */ |
| 1961 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 1962 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 1963 | int gpio_shift = gpio_num + |
| 1964 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1965 | u32 gpio_mask = (1 << gpio_shift); |
| 1966 | u32 gpio_reg; |
| 1967 | |
| 1968 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1969 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1970 | return -EINVAL; |
| 1971 | } |
| 1972 | |
| 1973 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 1974 | /* read GPIO int */ |
| 1975 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); |
| 1976 | |
| 1977 | switch (mode) { |
| 1978 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: |
| 1979 | DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> " |
| 1980 | "output low\n", gpio_num, gpio_shift); |
| 1981 | /* clear SET and set CLR */ |
| 1982 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 1983 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 1984 | break; |
| 1985 | |
| 1986 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: |
| 1987 | DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> " |
| 1988 | "output high\n", gpio_num, gpio_shift); |
| 1989 | /* clear CLR and set SET */ |
| 1990 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 1991 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 1992 | break; |
| 1993 | |
| 1994 | default: |
| 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); |
| 1999 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 2000 | |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2004 | static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode) |
| 2005 | { |
| 2006 | u32 spio_mask = (1 << spio_num); |
| 2007 | u32 spio_reg; |
| 2008 | |
| 2009 | if ((spio_num < MISC_REGISTERS_SPIO_4) || |
| 2010 | (spio_num > MISC_REGISTERS_SPIO_7)) { |
| 2011 | BNX2X_ERR("Invalid SPIO %d\n", spio_num); |
| 2012 | return -EINVAL; |
| 2013 | } |
| 2014 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2015 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2016 | /* read SPIO and mask except the float bits */ |
| 2017 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT); |
| 2018 | |
| 2019 | switch (mode) { |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2020 | case MISC_REGISTERS_SPIO_OUTPUT_LOW: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2021 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num); |
| 2022 | /* clear FLOAT and set CLR */ |
| 2023 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2024 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS); |
| 2025 | break; |
| 2026 | |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2027 | case MISC_REGISTERS_SPIO_OUTPUT_HIGH: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2028 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num); |
| 2029 | /* clear FLOAT and set SET */ |
| 2030 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2031 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS); |
| 2032 | break; |
| 2033 | |
| 2034 | case MISC_REGISTERS_SPIO_INPUT_HI_Z: |
| 2035 | DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num); |
| 2036 | /* set FLOAT */ |
| 2037 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | break; |
| 2042 | } |
| 2043 | |
| 2044 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2045 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2046 | |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2050 | void bnx2x_calc_fc_adv(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2051 | { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2052 | u8 cfg_idx = bnx2x_get_link_cfg_idx(bp); |
Eilon Greenstein | ad33ea3 | 2009-01-14 21:24:57 -0800 | [diff] [blame] | 2053 | switch (bp->link_vars.ieee_fc & |
| 2054 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2055 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2056 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2057 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2058 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2059 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2060 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2061 | bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2062 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2063 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2064 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2065 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2066 | bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2067 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2068 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2069 | default: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2070 | bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2071 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2072 | break; |
| 2073 | } |
| 2074 | } |
| 2075 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2076 | u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2077 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2078 | if (!BP_NOMCP(bp)) { |
| 2079 | u8 rc; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2080 | int cfx_idx = bnx2x_get_link_cfg_idx(bp); |
| 2081 | u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx]; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2082 | /* Initialize link parameters structure variables */ |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2083 | /* It is recommended to turn off RX FC for jumbo frames |
| 2084 | for better performance */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2085 | if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2086 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2087 | else |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2088 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2089 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2090 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2091 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2092 | if (load_mode == LOAD_DIAG) { |
Yaniv Rosner | de6eae1 | 2010-09-07 11:41:13 +0000 | [diff] [blame] | 2093 | bp->link_params.loopback_mode = LOOPBACK_XGXS; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2094 | bp->link_params.req_line_speed[cfx_idx] = SPEED_10000; |
| 2095 | } |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2096 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2097 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2098 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2099 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2100 | |
Eilon Greenstein | 3c96c68 | 2009-01-14 21:25:31 -0800 | [diff] [blame] | 2101 | bnx2x_calc_fc_adv(bp); |
| 2102 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2103 | if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) { |
| 2104 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2105 | bnx2x_link_report(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2106 | } |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2107 | bp->link_params.req_line_speed[cfx_idx] = req_line_speed; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2108 | return rc; |
| 2109 | } |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2110 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2111 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2112 | } |
| 2113 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2114 | void bnx2x_link_set(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2115 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2116 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2117 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | 54c2fb7 | 2010-09-01 09:51:23 +0000 | [diff] [blame] | 2118 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2119 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2120 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2121 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2122 | bnx2x_calc_fc_adv(bp); |
| 2123 | } else |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2124 | BNX2X_ERR("Bootcode is missing - can not set link\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2125 | } |
| 2126 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2127 | static void bnx2x__link_reset(struct bnx2x *bp) |
| 2128 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2129 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2130 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 2131 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2132 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2133 | } else |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2134 | BNX2X_ERR("Bootcode is missing - can not reset link\n"); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2137 | u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2138 | { |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 2139 | u8 rc = 0; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2140 | |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 2141 | if (!BP_NOMCP(bp)) { |
| 2142 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2143 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars, |
| 2144 | is_serdes); |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 2145 | bnx2x_release_phy_lock(bp); |
| 2146 | } else |
| 2147 | BNX2X_ERR("Bootcode is missing - can not test link\n"); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2148 | |
| 2149 | return rc; |
| 2150 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2151 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2152 | static void bnx2x_init_port_minmax(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2153 | { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2154 | u32 r_param = bp->link_vars.line_speed / 8; |
| 2155 | u32 fair_periodic_timeout_usec; |
| 2156 | u32 t_fair; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2157 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2158 | memset(&(bp->cmng.rs_vars), 0, |
| 2159 | sizeof(struct rate_shaping_vars_per_port)); |
| 2160 | memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2161 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2162 | /* 100 usec in SDM ticks = 25 since each tick is 4 usec */ |
| 2163 | bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2164 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2165 | /* this is the threshold below which no timer arming will occur |
| 2166 | 1.25 coefficient is for the threshold to be a little bigger |
| 2167 | than the real time, to compensate for timer in-accuracy */ |
| 2168 | bp->cmng.rs_vars.rs_threshold = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2169 | (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4; |
| 2170 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2171 | /* resolution of fairness timer */ |
| 2172 | fair_periodic_timeout_usec = QM_ARB_BYTES / r_param; |
| 2173 | /* for 10G it is 1000usec. for 1G it is 10000usec. */ |
| 2174 | t_fair = T_FAIR_COEF / bp->link_vars.line_speed; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2175 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2176 | /* this is the threshold below which we won't arm the timer anymore */ |
| 2177 | bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2178 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2179 | /* we multiply by 1e3/8 to get bytes/msec. |
| 2180 | We don't want the credits to pass a credit |
| 2181 | of the t_fair*FAIR_MEM (algorithm resolution) */ |
| 2182 | bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM; |
| 2183 | /* since each tick is 4 usec */ |
| 2184 | bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2187 | /* Calculates the sum of vn_min_rates. |
| 2188 | It's needed for further normalizing of the min_rates. |
| 2189 | Returns: |
| 2190 | sum of vn_min_rates. |
| 2191 | or |
| 2192 | 0 - if all the min_rates are 0. |
| 2193 | In the later case fainess algorithm should be deactivated. |
| 2194 | If not all min_rates are zero then those that are zeroes will be set to 1. |
| 2195 | */ |
| 2196 | static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp) |
| 2197 | { |
| 2198 | int all_zero = 1; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2199 | int vn; |
| 2200 | |
| 2201 | bp->vn_weight_sum = 0; |
| 2202 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2203 | u32 vn_cfg = bp->mf_config[vn]; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2204 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2205 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
| 2206 | |
| 2207 | /* Skip hidden vns */ |
| 2208 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
| 2209 | continue; |
| 2210 | |
| 2211 | /* If min rate is zero - set it to 1 */ |
| 2212 | if (!vn_min_rate) |
| 2213 | vn_min_rate = DEF_MIN_RATE; |
| 2214 | else |
| 2215 | all_zero = 0; |
| 2216 | |
| 2217 | bp->vn_weight_sum += vn_min_rate; |
| 2218 | } |
| 2219 | |
Dmitry Kravkov | 30ae438b | 2011-06-14 01:33:13 +0000 | [diff] [blame] | 2220 | /* if ETS or all min rates are zeros - disable fairness */ |
| 2221 | if (BNX2X_IS_ETS_ENABLED(bp)) { |
| 2222 | bp->cmng.flags.cmng_enables &= |
| 2223 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
| 2224 | DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n"); |
| 2225 | } else if (all_zero) { |
Eilon Greenstein | b015e3d | 2009-10-15 00:17:20 -0700 | [diff] [blame] | 2226 | bp->cmng.flags.cmng_enables &= |
| 2227 | ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
| 2228 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" |
| 2229 | " fairness will be disabled\n"); |
| 2230 | } else |
| 2231 | bp->cmng.flags.cmng_enables |= |
| 2232 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2235 | static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2236 | { |
| 2237 | struct rate_shaping_vars_per_vn m_rs_vn; |
| 2238 | struct fairness_vars_per_vn m_fair_vn; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2239 | u32 vn_cfg = bp->mf_config[vn]; |
| 2240 | int func = 2*vn + BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2241 | u16 vn_min_rate, vn_max_rate; |
| 2242 | int i; |
| 2243 | |
| 2244 | /* If function is hidden - set min and max to zeroes */ |
| 2245 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { |
| 2246 | vn_min_rate = 0; |
| 2247 | vn_max_rate = 0; |
| 2248 | |
| 2249 | } else { |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 2250 | u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg); |
| 2251 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2252 | vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2253 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 2254 | /* If fairness is enabled (not all min rates are zeroes) and |
| 2255 | if current min rate is zero - set it to 1. |
| 2256 | This is a requirement of the algorithm. */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2257 | if (bp->vn_weight_sum && (vn_min_rate == 0)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2258 | vn_min_rate = DEF_MIN_RATE; |
Dmitry Kravkov | faa6fcb | 2011-02-28 03:37:20 +0000 | [diff] [blame] | 2259 | |
| 2260 | if (IS_MF_SI(bp)) |
| 2261 | /* maxCfg in percents of linkspeed */ |
| 2262 | vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100; |
| 2263 | else |
| 2264 | /* maxCfg is absolute in 100Mb units */ |
| 2265 | vn_max_rate = maxCfg * 100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2266 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2267 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2268 | DP(NETIF_MSG_IFUP, |
Eilon Greenstein | b015e3d | 2009-10-15 00:17:20 -0700 | [diff] [blame] | 2269 | "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n", |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2270 | func, vn_min_rate, vn_max_rate, bp->vn_weight_sum); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2271 | |
| 2272 | memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn)); |
| 2273 | memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn)); |
| 2274 | |
| 2275 | /* global vn counter - maximal Mbps for this vn */ |
| 2276 | m_rs_vn.vn_counter.rate = vn_max_rate; |
| 2277 | |
| 2278 | /* quota - number of bytes transmitted in this period */ |
| 2279 | m_rs_vn.vn_counter.quota = |
| 2280 | (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8; |
| 2281 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2282 | if (bp->vn_weight_sum) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2283 | /* credit for each period of the fairness algorithm: |
| 2284 | number of bytes in T_FAIR (the vn share the port rate). |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2285 | vn_weight_sum should not be larger than 10000, thus |
| 2286 | T_FAIR_COEF / (8 * vn_weight_sum) will always be greater |
| 2287 | than zero */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2288 | m_fair_vn.vn_credit_delta = |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2289 | max_t(u32, (vn_min_rate * (T_FAIR_COEF / |
| 2290 | (8 * bp->vn_weight_sum))), |
Dmitry Kravkov | ff80ee0 | 2011-02-28 03:37:11 +0000 | [diff] [blame] | 2291 | (bp->cmng.fair_vars.fair_threshold + |
| 2292 | MIN_ABOVE_THRESH)); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2293 | DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2294 | m_fair_vn.vn_credit_delta); |
| 2295 | } |
| 2296 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2297 | /* Store it to internal memory */ |
| 2298 | for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++) |
| 2299 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2300 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2301 | ((u32 *)(&m_rs_vn))[i]); |
| 2302 | |
| 2303 | for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++) |
| 2304 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2305 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2306 | ((u32 *)(&m_fair_vn))[i]); |
| 2307 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2308 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2309 | static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp) |
| 2310 | { |
| 2311 | if (CHIP_REV_IS_SLOW(bp)) |
| 2312 | return CMNG_FNS_NONE; |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 2313 | if (IS_MF(bp)) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2314 | return CMNG_FNS_MINMAX; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2315 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2316 | return CMNG_FNS_NONE; |
| 2317 | } |
| 2318 | |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 2319 | void bnx2x_read_mf_cfg(struct bnx2x *bp) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2320 | { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2321 | int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2322 | |
| 2323 | if (BP_NOMCP(bp)) |
| 2324 | return; /* what should be the default bvalue in this case */ |
| 2325 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2326 | /* For 2 port configuration the absolute function number formula |
| 2327 | * is: |
| 2328 | * abs_func = 2 * vn + BP_PORT + BP_PATH |
| 2329 | * |
| 2330 | * and there are 4 functions per port |
| 2331 | * |
| 2332 | * For 4 port configuration it is |
| 2333 | * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH |
| 2334 | * |
| 2335 | * and there are 2 functions per port |
| 2336 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2337 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2338 | int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp); |
| 2339 | |
| 2340 | if (func >= E1H_FUNC_MAX) |
| 2341 | break; |
| 2342 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2343 | bp->mf_config[vn] = |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2344 | MF_CFG_RD(bp, func_mf_config[func].config); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type) |
| 2349 | { |
| 2350 | |
| 2351 | if (cmng_type == CMNG_FNS_MINMAX) { |
| 2352 | int vn; |
| 2353 | |
| 2354 | /* clear cmng_enables */ |
| 2355 | bp->cmng.flags.cmng_enables = 0; |
| 2356 | |
| 2357 | /* read mf conf from shmem */ |
| 2358 | if (read_cfg) |
| 2359 | bnx2x_read_mf_cfg(bp); |
| 2360 | |
| 2361 | /* Init rate shaping and fairness contexts */ |
| 2362 | bnx2x_init_port_minmax(bp); |
| 2363 | |
| 2364 | /* vn_weight_sum and enable fairness if not 0 */ |
| 2365 | bnx2x_calc_vn_weight_sum(bp); |
| 2366 | |
| 2367 | /* calculate and set min-max rate for each vn */ |
Dmitry Kravkov | c4154f2 | 2011-03-06 10:49:25 +0000 | [diff] [blame] | 2368 | if (bp->port.pmf) |
| 2369 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
| 2370 | bnx2x_init_vn_minmax(bp, vn); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2371 | |
| 2372 | /* always enable rate shaping and fairness */ |
| 2373 | bp->cmng.flags.cmng_enables |= |
| 2374 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
| 2375 | if (!bp->vn_weight_sum) |
| 2376 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" |
| 2377 | " fairness will be disabled\n"); |
| 2378 | return; |
| 2379 | } |
| 2380 | |
| 2381 | /* rate shaping and fairness are disabled */ |
| 2382 | DP(NETIF_MSG_IFUP, |
| 2383 | "rate shaping and fairness are disabled\n"); |
| 2384 | } |
| 2385 | |
| 2386 | static inline void bnx2x_link_sync_notify(struct bnx2x *bp) |
| 2387 | { |
| 2388 | int port = BP_PORT(bp); |
| 2389 | int func; |
| 2390 | int vn; |
| 2391 | |
| 2392 | /* Set the attention towards other drivers on the same port */ |
| 2393 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2394 | if (vn == BP_E1HVN(bp)) |
| 2395 | continue; |
| 2396 | |
| 2397 | func = ((vn << 1) | port); |
| 2398 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 + |
| 2399 | (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1); |
| 2400 | } |
| 2401 | } |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2402 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2403 | /* This function is called upon link interrupt */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2404 | static void bnx2x_link_attn(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2405 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2406 | /* Make sure that we are synced with the current statistics */ |
| 2407 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2408 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2409 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2410 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2411 | if (bp->link_vars.link_up) { |
| 2412 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2413 | /* dropless flow control */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2414 | if (!CHIP_IS_E1(bp) && bp->dropless_fc) { |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2415 | int port = BP_PORT(bp); |
| 2416 | u32 pause_enabled = 0; |
| 2417 | |
| 2418 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
| 2419 | pause_enabled = 1; |
| 2420 | |
| 2421 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 2422 | USTORM_ETH_PAUSE_ENABLED_OFFSET(port), |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2423 | pause_enabled); |
| 2424 | } |
| 2425 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2426 | if (bp->link_vars.mac_type != MAC_TYPE_EMAC) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2427 | struct host_port_stats *pstats; |
| 2428 | |
| 2429 | pstats = bnx2x_sp(bp, port_stats); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2430 | /* reset old mac stats */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2431 | memset(&(pstats->mac_stx[0]), 0, |
| 2432 | sizeof(struct mac_stx)); |
| 2433 | } |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2434 | if (bp->state == BNX2X_STATE_OPEN) |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2435 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2436 | } |
| 2437 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2438 | if (bp->link_vars.link_up && bp->link_vars.line_speed) { |
| 2439 | int cmng_fns = bnx2x_get_cmng_fns_mode(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2440 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2441 | if (cmng_fns != CMNG_FNS_NONE) { |
| 2442 | bnx2x_cmng_fns_init(bp, false, cmng_fns); |
| 2443 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); |
| 2444 | } else |
| 2445 | /* rate shaping and fairness are disabled */ |
| 2446 | DP(NETIF_MSG_IFUP, |
| 2447 | "single function mode without fairness\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2448 | } |
Dmitry Kravkov | 9fdc3e9 | 2011-03-06 10:49:15 +0000 | [diff] [blame] | 2449 | |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 2450 | __bnx2x_link_report(bp); |
| 2451 | |
Dmitry Kravkov | 9fdc3e9 | 2011-03-06 10:49:15 +0000 | [diff] [blame] | 2452 | if (IS_MF(bp)) |
| 2453 | bnx2x_link_sync_notify(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2454 | } |
| 2455 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2456 | void bnx2x__link_status_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2457 | { |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 2458 | if (bp->state != BNX2X_STATE_OPEN) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2459 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2460 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2461 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); |
| 2462 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2463 | if (bp->link_vars.link_up) |
| 2464 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2465 | else |
| 2466 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2467 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2468 | /* indicate link status */ |
| 2469 | bnx2x_link_report(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2472 | static void bnx2x_pmf_update(struct bnx2x *bp) |
| 2473 | { |
| 2474 | int port = BP_PORT(bp); |
| 2475 | u32 val; |
| 2476 | |
| 2477 | bp->port.pmf = 1; |
| 2478 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 2479 | |
Dmitry Kravkov | ef01854 | 2011-06-14 01:33:57 +0000 | [diff] [blame^] | 2480 | bnx2x_dcbx_pmf_update(bp); |
| 2481 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2482 | /* enable nig attention */ |
| 2483 | val = (0xff0f | (1 << (BP_E1HVN(bp) + 4))); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2484 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 2485 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 2486 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2487 | } else if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2488 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val); |
| 2489 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val); |
| 2490 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2491 | |
| 2492 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2495 | /* end of Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2496 | |
| 2497 | /* slow path */ |
| 2498 | |
| 2499 | /* |
| 2500 | * General service functions |
| 2501 | */ |
| 2502 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2503 | /* send the MCP a request, block until there is a reply */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2504 | u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param) |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2505 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2506 | int mb_idx = BP_FW_MB_IDX(bp); |
Dmitry Kravkov | a5971d4 | 2011-05-25 04:55:51 +0000 | [diff] [blame] | 2507 | u32 seq; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2508 | u32 rc = 0; |
| 2509 | u32 cnt = 1; |
| 2510 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; |
| 2511 | |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 2512 | mutex_lock(&bp->fw_mb_mutex); |
Dmitry Kravkov | a5971d4 | 2011-05-25 04:55:51 +0000 | [diff] [blame] | 2513 | seq = ++bp->fw_seq; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2514 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param); |
| 2515 | SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq)); |
| 2516 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2517 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq)); |
| 2518 | |
| 2519 | do { |
| 2520 | /* let the FW do it's magic ... */ |
| 2521 | msleep(delay); |
| 2522 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2523 | rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2524 | |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 2525 | /* Give the FW up to 5 second (500*10ms) */ |
| 2526 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2527 | |
| 2528 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", |
| 2529 | cnt*delay, rc, seq); |
| 2530 | |
| 2531 | /* is this a reply to our command? */ |
| 2532 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) |
| 2533 | rc &= FW_MSG_CODE_MASK; |
| 2534 | else { |
| 2535 | /* FW BUG! */ |
| 2536 | BNX2X_ERR("FW failed to respond!\n"); |
| 2537 | bnx2x_fw_dump(bp); |
| 2538 | rc = 0; |
| 2539 | } |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 2540 | mutex_unlock(&bp->fw_mb_mutex); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2541 | |
| 2542 | return rc; |
| 2543 | } |
| 2544 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2545 | static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp) |
| 2546 | { |
| 2547 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2548 | /* Statistics are not supported for CNIC Clients at the moment */ |
| 2549 | if (IS_FCOE_FP(fp)) |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2550 | return false; |
| 2551 | #endif |
| 2552 | return true; |
| 2553 | } |
| 2554 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2555 | void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2556 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2557 | if (CHIP_IS_E1x(bp)) { |
| 2558 | struct tstorm_eth_function_common_config tcfg = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2559 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2560 | storm_memset_func_cfg(bp, &tcfg, p->func_id); |
| 2561 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2562 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2563 | /* Enable the function in the FW */ |
| 2564 | storm_memset_vf_to_pf(bp, p->func_id, p->pf_id); |
| 2565 | storm_memset_func_en(bp, p->func_id, 1); |
| 2566 | |
| 2567 | /* spq */ |
| 2568 | if (p->func_flgs & FUNC_FLG_SPQ) { |
| 2569 | storm_memset_spq_addr(bp, p->spq_map, p->func_id); |
| 2570 | REG_WR(bp, XSEM_REG_FAST_MEMORY + |
| 2571 | XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod); |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp, |
| 2576 | struct bnx2x_fastpath *fp, |
| 2577 | bool leading) |
| 2578 | { |
| 2579 | unsigned long flags = 0; |
| 2580 | |
| 2581 | /* PF driver will always initialize the Queue to an ACTIVE state */ |
| 2582 | __set_bit(BNX2X_Q_FLG_ACTIVE, &flags); |
| 2583 | |
| 2584 | /* calculate other queue flags */ |
| 2585 | if (IS_MF_SD(bp)) |
| 2586 | __set_bit(BNX2X_Q_FLG_OV, &flags); |
| 2587 | |
| 2588 | if (IS_FCOE_FP(fp)) |
| 2589 | __set_bit(BNX2X_Q_FLG_FCOE, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2590 | |
| 2591 | if (!fp->disable_tpa) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2592 | __set_bit(BNX2X_Q_FLG_TPA, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2593 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2594 | if (stat_counter_valid(bp, fp)) { |
| 2595 | __set_bit(BNX2X_Q_FLG_STATS, &flags); |
| 2596 | __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags); |
| 2597 | } |
| 2598 | |
| 2599 | if (leading) { |
| 2600 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags); |
| 2601 | __set_bit(BNX2X_Q_FLG_MCAST, &flags); |
| 2602 | } |
| 2603 | |
| 2604 | /* Always set HW VLAN stripping */ |
| 2605 | __set_bit(BNX2X_Q_FLG_VLAN, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2606 | |
| 2607 | return flags; |
| 2608 | } |
| 2609 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2610 | static void bnx2x_pf_q_prep_general(struct bnx2x *bp, |
| 2611 | struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2612 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2613 | gen_init->stat_id = bnx2x_stats_id(fp); |
| 2614 | gen_init->spcl_id = fp->cl_id; |
| 2615 | |
| 2616 | /* Always use mini-jumbo MTU for FCoE L2 ring */ |
| 2617 | if (IS_FCOE_FP(fp)) |
| 2618 | gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU; |
| 2619 | else |
| 2620 | gen_init->mtu = bp->dev->mtu; |
| 2621 | } |
| 2622 | |
| 2623 | static void bnx2x_pf_rx_q_prep(struct bnx2x *bp, |
| 2624 | struct bnx2x_fastpath *fp, struct rxq_pause_params *pause, |
| 2625 | struct bnx2x_rxq_setup_params *rxq_init) |
| 2626 | { |
| 2627 | u8 max_sge = 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2628 | u16 sge_sz = 0; |
| 2629 | u16 tpa_agg_size = 0; |
| 2630 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2631 | if (!fp->disable_tpa) { |
| 2632 | pause->sge_th_hi = 250; |
| 2633 | pause->sge_th_lo = 150; |
| 2634 | tpa_agg_size = min_t(u32, |
| 2635 | (min_t(u32, 8, MAX_SKB_FRAGS) * |
| 2636 | SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff); |
| 2637 | max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >> |
| 2638 | SGE_PAGE_SHIFT; |
| 2639 | max_sge = ((max_sge + PAGES_PER_SGE - 1) & |
| 2640 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; |
| 2641 | sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE, |
| 2642 | 0xffff); |
| 2643 | } |
| 2644 | |
| 2645 | /* pause - not for e1 */ |
| 2646 | if (!CHIP_IS_E1(bp)) { |
| 2647 | pause->bd_th_hi = 350; |
| 2648 | pause->bd_th_lo = 250; |
| 2649 | pause->rcq_th_hi = 350; |
| 2650 | pause->rcq_th_lo = 250; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2651 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2652 | pause->pri_map = 1; |
| 2653 | } |
| 2654 | |
| 2655 | /* rxq setup */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2656 | rxq_init->dscr_map = fp->rx_desc_mapping; |
| 2657 | rxq_init->sge_map = fp->rx_sge_mapping; |
| 2658 | rxq_init->rcq_map = fp->rx_comp_mapping; |
| 2659 | rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE; |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 2660 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2661 | /* This should be a maximum number of data bytes that may be |
| 2662 | * placed on the BD (not including paddings). |
| 2663 | */ |
| 2664 | rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN - |
| 2665 | IP_HEADER_ALIGNMENT_PADDING; |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 2666 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2667 | rxq_init->cl_qzone_id = fp->cl_qzone_id; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2668 | rxq_init->tpa_agg_sz = tpa_agg_size; |
| 2669 | rxq_init->sge_buf_sz = sge_sz; |
| 2670 | rxq_init->max_sges_pkt = max_sge; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2671 | rxq_init->rss_engine_id = BP_FUNC(bp); |
| 2672 | |
| 2673 | /* Maximum number or simultaneous TPA aggregation for this Queue. |
| 2674 | * |
| 2675 | * For PF Clients it should be the maximum avaliable number. |
| 2676 | * VF driver(s) may want to define it to a smaller value. |
| 2677 | */ |
| 2678 | rxq_init->max_tpa_queues = |
| 2679 | (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 : |
| 2680 | ETH_MAX_AGGREGATION_QUEUES_E1H_E2); |
| 2681 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2682 | rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
| 2683 | rxq_init->fw_sb_id = fp->fw_sb_id; |
| 2684 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2685 | if (IS_FCOE_FP(fp)) |
| 2686 | rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS; |
| 2687 | else |
| 2688 | rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2691 | static void bnx2x_pf_tx_q_prep(struct bnx2x *bp, |
| 2692 | struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2693 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2694 | txq_init->dscr_map = fp->tx_desc_mapping; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2695 | txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX; |
| 2696 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; |
| 2697 | txq_init->fw_sb_id = fp->fw_sb_id; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2698 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2699 | /* |
| 2700 | * set the tss leading client id for TX classfication == |
| 2701 | * leading RSS client id |
| 2702 | */ |
| 2703 | txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id); |
| 2704 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2705 | if (IS_FCOE_FP(fp)) { |
| 2706 | txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS; |
| 2707 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE; |
| 2708 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 2711 | static void bnx2x_pf_init(struct bnx2x *bp) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2712 | { |
| 2713 | struct bnx2x_func_init_params func_init = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2714 | struct event_ring_data eq_data = { {0} }; |
| 2715 | u16 flags; |
| 2716 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2717 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2718 | /* reset IGU PF statistics: MSIX + ATTN */ |
| 2719 | /* PF */ |
| 2720 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + |
| 2721 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + |
| 2722 | (CHIP_MODE_IS_4_PORT(bp) ? |
| 2723 | BP_FUNC(bp) : BP_VN(bp))*4, 0); |
| 2724 | /* ATTN */ |
| 2725 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + |
| 2726 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + |
| 2727 | BNX2X_IGU_STAS_MSG_PF_CNT*4 + |
| 2728 | (CHIP_MODE_IS_4_PORT(bp) ? |
| 2729 | BP_FUNC(bp) : BP_VN(bp))*4, 0); |
| 2730 | } |
| 2731 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2732 | /* function setup flags */ |
| 2733 | flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); |
| 2734 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2735 | /* This flag is relevant for E1x only. |
| 2736 | * E2 doesn't have a TPA configuration in a function level. |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2737 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2738 | flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2739 | |
| 2740 | func_init.func_flgs = flags; |
| 2741 | func_init.pf_id = BP_FUNC(bp); |
| 2742 | func_init.func_id = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2743 | func_init.spq_map = bp->spq_mapping; |
| 2744 | func_init.spq_prod = bp->spq_prod_idx; |
| 2745 | |
| 2746 | bnx2x_func_init(bp, &func_init); |
| 2747 | |
| 2748 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); |
| 2749 | |
| 2750 | /* |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2751 | * Congestion management values depend on the link rate |
| 2752 | * There is no active link so initial link rate is set to 10 Gbps. |
| 2753 | * When the link comes up The congestion management values are |
| 2754 | * re-calculated according to the actual link rate. |
| 2755 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2756 | bp->link_vars.line_speed = SPEED_10000; |
| 2757 | bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp)); |
| 2758 | |
| 2759 | /* Only the PMF sets the HW */ |
| 2760 | if (bp->port.pmf) |
| 2761 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); |
| 2762 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2763 | /* init Event Queue */ |
| 2764 | eq_data.base_addr.hi = U64_HI(bp->eq_mapping); |
| 2765 | eq_data.base_addr.lo = U64_LO(bp->eq_mapping); |
| 2766 | eq_data.producer = bp->eq_prod; |
| 2767 | eq_data.index_id = HC_SP_INDEX_EQ_CONS; |
| 2768 | eq_data.sb_id = DEF_SB_ID; |
| 2769 | storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp)); |
| 2770 | } |
| 2771 | |
| 2772 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2773 | static void bnx2x_e1h_disable(struct bnx2x *bp) |
| 2774 | { |
| 2775 | int port = BP_PORT(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2776 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2777 | bnx2x_tx_disable(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2778 | |
| 2779 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | static void bnx2x_e1h_enable(struct bnx2x *bp) |
| 2783 | { |
| 2784 | int port = BP_PORT(bp); |
| 2785 | |
| 2786 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 2787 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2788 | /* Tx queue should be only reenabled */ |
| 2789 | netif_tx_wake_all_queues(bp->dev); |
| 2790 | |
Eilon Greenstein | 061bc70 | 2009-10-15 00:18:47 -0700 | [diff] [blame] | 2791 | /* |
| 2792 | * Should not call netif_carrier_on since it will be called if the link |
| 2793 | * is up when checking for link state |
| 2794 | */ |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2797 | /* called due to MCP event (on pmf): |
| 2798 | * reread new bandwidth configuration |
| 2799 | * configure FW |
| 2800 | * notify others function about the change |
| 2801 | */ |
| 2802 | static inline void bnx2x_config_mf_bw(struct bnx2x *bp) |
| 2803 | { |
| 2804 | if (bp->link_vars.link_up) { |
| 2805 | bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX); |
| 2806 | bnx2x_link_sync_notify(bp); |
| 2807 | } |
| 2808 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); |
| 2809 | } |
| 2810 | |
| 2811 | static inline void bnx2x_set_mf_bw(struct bnx2x *bp) |
| 2812 | { |
| 2813 | bnx2x_config_mf_bw(bp); |
| 2814 | bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0); |
| 2815 | } |
| 2816 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2817 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
| 2818 | { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2819 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2820 | |
| 2821 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { |
| 2822 | |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2823 | /* |
| 2824 | * This is the only place besides the function initialization |
| 2825 | * where the bp->flags can change so it is done without any |
| 2826 | * locks |
| 2827 | */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2828 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2829 | DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n"); |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2830 | bp->flags |= MF_FUNC_DIS; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2831 | |
| 2832 | bnx2x_e1h_disable(bp); |
| 2833 | } else { |
| 2834 | DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n"); |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2835 | bp->flags &= ~MF_FUNC_DIS; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2836 | |
| 2837 | bnx2x_e1h_enable(bp); |
| 2838 | } |
| 2839 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; |
| 2840 | } |
| 2841 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2842 | bnx2x_config_mf_bw(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2843 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
| 2844 | } |
| 2845 | |
| 2846 | /* Report results to MCP */ |
| 2847 | if (dcc_event) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2848 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2849 | else |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2850 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2853 | /* must be called under the spq lock */ |
| 2854 | static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp) |
| 2855 | { |
| 2856 | struct eth_spe *next_spe = bp->spq_prod_bd; |
| 2857 | |
| 2858 | if (bp->spq_prod_bd == bp->spq_last_bd) { |
| 2859 | bp->spq_prod_bd = bp->spq; |
| 2860 | bp->spq_prod_idx = 0; |
| 2861 | DP(NETIF_MSG_TIMER, "end of spq\n"); |
| 2862 | } else { |
| 2863 | bp->spq_prod_bd++; |
| 2864 | bp->spq_prod_idx++; |
| 2865 | } |
| 2866 | return next_spe; |
| 2867 | } |
| 2868 | |
| 2869 | /* must be called under the spq lock */ |
| 2870 | static inline void bnx2x_sp_prod_update(struct bnx2x *bp) |
| 2871 | { |
| 2872 | int func = BP_FUNC(bp); |
| 2873 | |
| 2874 | /* Make sure that BD data is updated before writing the producer */ |
| 2875 | wmb(); |
| 2876 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2877 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2878 | bp->spq_prod_idx); |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2879 | mmiowb(); |
| 2880 | } |
| 2881 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2882 | /** |
| 2883 | * bnx2x_is_contextless_ramrod - check if the current command ends on EQ |
| 2884 | * |
| 2885 | * @cmd: command to check |
| 2886 | * @cmd_type: command type |
| 2887 | */ |
| 2888 | static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type) |
| 2889 | { |
| 2890 | if ((cmd_type == NONE_CONNECTION_TYPE) || |
| 2891 | (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || |
| 2892 | (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || |
| 2893 | (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || |
| 2894 | (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || |
| 2895 | (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) |
| 2896 | return true; |
| 2897 | else |
| 2898 | return false; |
| 2899 | |
| 2900 | } |
| 2901 | |
| 2902 | |
| 2903 | /** |
| 2904 | * bnx2x_sp_post - place a single command on an SP ring |
| 2905 | * |
| 2906 | * @bp: driver handle |
| 2907 | * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) |
| 2908 | * @cid: SW CID the command is related to |
| 2909 | * @data_hi: command private data address (high 32 bits) |
| 2910 | * @data_lo: command private data address (low 32 bits) |
| 2911 | * @cmd_type: command type (e.g. NONE, ETH) |
| 2912 | * |
| 2913 | * SP data is handled as if it's always an address pair, thus data fields are |
| 2914 | * not swapped to little endian in upper functions. Instead this function swaps |
| 2915 | * data as if it's two u32 fields. |
| 2916 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2917 | int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2918 | u32 data_hi, u32 data_lo, int cmd_type) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2919 | { |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2920 | struct eth_spe *spe; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2921 | u16 type; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2922 | bool common = bnx2x_is_contextless_ramrod(command, cmd_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2923 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2924 | #ifdef BNX2X_STOP_ON_ERROR |
| 2925 | if (unlikely(bp->panic)) |
| 2926 | return -EIO; |
| 2927 | #endif |
| 2928 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2929 | spin_lock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2930 | |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2931 | if (common) { |
| 2932 | if (!atomic_read(&bp->eq_spq_left)) { |
| 2933 | BNX2X_ERR("BUG! EQ ring full!\n"); |
| 2934 | spin_unlock_bh(&bp->spq_lock); |
| 2935 | bnx2x_panic(); |
| 2936 | return -EBUSY; |
| 2937 | } |
| 2938 | } else if (!atomic_read(&bp->cq_spq_left)) { |
| 2939 | BNX2X_ERR("BUG! SPQ ring full!\n"); |
| 2940 | spin_unlock_bh(&bp->spq_lock); |
| 2941 | bnx2x_panic(); |
| 2942 | return -EBUSY; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2943 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2944 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2945 | spe = bnx2x_sp_get_next(bp); |
| 2946 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2947 | /* CID needs port number to be encoded int it */ |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2948 | spe->hdr.conn_and_cmd_data = |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2949 | cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) | |
| 2950 | HW_CID(bp, cid)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2951 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2952 | type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2953 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2954 | type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) & |
| 2955 | SPE_HDR_FUNCTION_ID); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2956 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2957 | spe->hdr.type = cpu_to_le16(type); |
| 2958 | |
| 2959 | spe->data.update_data_addr.hi = cpu_to_le32(data_hi); |
| 2960 | spe->data.update_data_addr.lo = cpu_to_le32(data_lo); |
| 2961 | |
| 2962 | /* stats ramrod has it's own slot on the spq */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2963 | if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2964 | /* |
| 2965 | * It's ok if the actual decrement is issued towards the memory |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2966 | * somewhere between the spin_lock and spin_unlock. Thus no |
| 2967 | * more explict memory barrier is needed. |
| 2968 | */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2969 | if (common) |
| 2970 | atomic_dec(&bp->eq_spq_left); |
| 2971 | else |
| 2972 | atomic_dec(&bp->cq_spq_left); |
| 2973 | } |
| 2974 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2975 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2976 | DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2977 | "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) " |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2978 | "type(0x%x) left (ETH, COMMON) (%x,%x)\n", |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2979 | bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping), |
| 2980 | (u32)(U64_LO(bp->spq_mapping) + |
| 2981 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2982 | HW_CID(bp, cid), data_hi, data_lo, type, |
| 2983 | atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left)); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2984 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2985 | bnx2x_sp_prod_update(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2986 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2987 | return 0; |
| 2988 | } |
| 2989 | |
| 2990 | /* acquire split MCP access lock register */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2991 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2992 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 2993 | u32 j, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2994 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2995 | |
| 2996 | might_sleep(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 2997 | for (j = 0; j < 1000; j++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2998 | val = (1UL << 31); |
| 2999 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 3000 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); |
| 3001 | if (val & (1L << 31)) |
| 3002 | break; |
| 3003 | |
| 3004 | msleep(5); |
| 3005 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3006 | if (!(val & (1L << 31))) { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 3007 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3008 | rc = -EBUSY; |
| 3009 | } |
| 3010 | |
| 3011 | return rc; |
| 3012 | } |
| 3013 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3014 | /* release split MCP access lock register */ |
| 3015 | static void bnx2x_release_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3016 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3017 | REG_WR(bp, GRCBASE_MCP + 0x9c, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3018 | } |
| 3019 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3020 | #define BNX2X_DEF_SB_ATT_IDX 0x0001 |
| 3021 | #define BNX2X_DEF_SB_IDX 0x0002 |
| 3022 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3023 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
| 3024 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3025 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3026 | u16 rc = 0; |
| 3027 | |
| 3028 | barrier(); /* status block is written to by the chip */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3029 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
| 3030 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3031 | rc |= BNX2X_DEF_SB_ATT_IDX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3032 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3033 | |
| 3034 | if (bp->def_idx != def_sb->sp_sb.running_index) { |
| 3035 | bp->def_idx = def_sb->sp_sb.running_index; |
| 3036 | rc |= BNX2X_DEF_SB_IDX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3037 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3038 | |
| 3039 | /* Do not reorder: indecies reading should complete before handling */ |
| 3040 | barrier(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3041 | return rc; |
| 3042 | } |
| 3043 | |
| 3044 | /* |
| 3045 | * slow path service functions |
| 3046 | */ |
| 3047 | |
| 3048 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) |
| 3049 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3050 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3051 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 3052 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3053 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
| 3054 | NIG_REG_MASK_INTERRUPT_PORT0; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3055 | u32 aeu_mask; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3056 | u32 nig_mask = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3057 | u32 reg_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3058 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3059 | if (bp->attn_state & asserted) |
| 3060 | BNX2X_ERR("IGU ERROR\n"); |
| 3061 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3062 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 3063 | aeu_mask = REG_RD(bp, aeu_addr); |
| 3064 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3065 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3066 | aeu_mask, asserted); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3067 | aeu_mask &= ~(asserted & 0x3ff); |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3068 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3069 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3070 | REG_WR(bp, aeu_addr, aeu_mask); |
| 3071 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3072 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3073 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3074 | bp->attn_state |= asserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3075 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3076 | |
| 3077 | if (asserted & ATTN_HARD_WIRED_MASK) { |
| 3078 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3079 | |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3080 | bnx2x_acquire_phy_lock(bp); |
| 3081 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3082 | /* save nig interrupt mask */ |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3083 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3084 | |
Yaniv Rosner | 361c391 | 2011-06-14 01:33:19 +0000 | [diff] [blame] | 3085 | /* If nig_mask is not set, no need to call the update |
| 3086 | * function. |
| 3087 | */ |
| 3088 | if (nig_mask) { |
| 3089 | REG_WR(bp, nig_int_mask_addr, 0); |
| 3090 | |
| 3091 | bnx2x_link_attn(bp); |
| 3092 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3093 | |
| 3094 | /* handle unicore attn? */ |
| 3095 | } |
| 3096 | if (asserted & ATTN_SW_TIMER_4_FUNC) |
| 3097 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); |
| 3098 | |
| 3099 | if (asserted & GPIO_2_FUNC) |
| 3100 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); |
| 3101 | |
| 3102 | if (asserted & GPIO_3_FUNC) |
| 3103 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); |
| 3104 | |
| 3105 | if (asserted & GPIO_4_FUNC) |
| 3106 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); |
| 3107 | |
| 3108 | if (port == 0) { |
| 3109 | if (asserted & ATTN_GENERAL_ATTN_1) { |
| 3110 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); |
| 3111 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); |
| 3112 | } |
| 3113 | if (asserted & ATTN_GENERAL_ATTN_2) { |
| 3114 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); |
| 3115 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); |
| 3116 | } |
| 3117 | if (asserted & ATTN_GENERAL_ATTN_3) { |
| 3118 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); |
| 3119 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); |
| 3120 | } |
| 3121 | } else { |
| 3122 | if (asserted & ATTN_GENERAL_ATTN_4) { |
| 3123 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); |
| 3124 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); |
| 3125 | } |
| 3126 | if (asserted & ATTN_GENERAL_ATTN_5) { |
| 3127 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); |
| 3128 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); |
| 3129 | } |
| 3130 | if (asserted & ATTN_GENERAL_ATTN_6) { |
| 3131 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); |
| 3132 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | } /* if hardwired */ |
| 3137 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3138 | if (bp->common.int_block == INT_BLOCK_HC) |
| 3139 | reg_addr = (HC_REG_COMMAND_REG + port*32 + |
| 3140 | COMMAND_REG_ATTN_BITS_SET); |
| 3141 | else |
| 3142 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); |
| 3143 | |
| 3144 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted, |
| 3145 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); |
| 3146 | REG_WR(bp, reg_addr, asserted); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3147 | |
| 3148 | /* now set back the mask */ |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3149 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3150 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3151 | bnx2x_release_phy_lock(bp); |
| 3152 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3153 | } |
| 3154 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3155 | static inline void bnx2x_fan_failure(struct bnx2x *bp) |
| 3156 | { |
| 3157 | int port = BP_PORT(bp); |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3158 | u32 ext_phy_config; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3159 | /* mark the failure */ |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3160 | ext_phy_config = |
| 3161 | SHMEM_RD(bp, |
| 3162 | dev_info.port_hw_config[port].external_phy_config); |
| 3163 | |
| 3164 | ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
| 3165 | ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3166 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3167 | ext_phy_config); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3168 | |
| 3169 | /* log the failure */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 3170 | netdev_err(bp->dev, "Fan Failure on Network Controller has caused" |
| 3171 | " the driver to shutdown the card to prevent permanent" |
| 3172 | " damage. Please contact OEM Support for assistance\n"); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3173 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 3174 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3175 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
| 3176 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3177 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3178 | int reg_offset; |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 3179 | u32 val; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3180 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3181 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 3182 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3183 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3184 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3185 | |
| 3186 | val = REG_RD(bp, reg_offset); |
| 3187 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; |
| 3188 | REG_WR(bp, reg_offset, val); |
| 3189 | |
| 3190 | BNX2X_ERR("SPIO5 hw attention\n"); |
| 3191 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3192 | /* Fan failure attention */ |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 3193 | bnx2x_hw_reset_phy(&bp->link_params); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3194 | bnx2x_fan_failure(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3195 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3196 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 3197 | if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 | |
| 3198 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) { |
| 3199 | bnx2x_acquire_phy_lock(bp); |
| 3200 | bnx2x_handle_module_detect_int(&bp->link_params); |
| 3201 | bnx2x_release_phy_lock(bp); |
| 3202 | } |
| 3203 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3204 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
| 3205 | |
| 3206 | val = REG_RD(bp, reg_offset); |
| 3207 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); |
| 3208 | REG_WR(bp, reg_offset, val); |
| 3209 | |
| 3210 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3211 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3212 | bnx2x_panic(); |
| 3213 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
| 3217 | { |
| 3218 | u32 val; |
| 3219 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 3220 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3221 | |
| 3222 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); |
| 3223 | BNX2X_ERR("DB hw attention 0x%x\n", val); |
| 3224 | /* DORQ discard attention */ |
| 3225 | if (val & 0x2) |
| 3226 | BNX2X_ERR("FATAL error from DORQ\n"); |
| 3227 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3228 | |
| 3229 | if (attn & HW_INTERRUT_ASSERT_SET_1) { |
| 3230 | |
| 3231 | int port = BP_PORT(bp); |
| 3232 | int reg_offset; |
| 3233 | |
| 3234 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : |
| 3235 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); |
| 3236 | |
| 3237 | val = REG_RD(bp, reg_offset); |
| 3238 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); |
| 3239 | REG_WR(bp, reg_offset, val); |
| 3240 | |
| 3241 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3242 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3243 | bnx2x_panic(); |
| 3244 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
| 3248 | { |
| 3249 | u32 val; |
| 3250 | |
| 3251 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { |
| 3252 | |
| 3253 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); |
| 3254 | BNX2X_ERR("CFC hw attention 0x%x\n", val); |
| 3255 | /* CFC error attention */ |
| 3256 | if (val & 0x2) |
| 3257 | BNX2X_ERR("FATAL error from CFC\n"); |
| 3258 | } |
| 3259 | |
| 3260 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3261 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3262 | BNX2X_ERR("PXP hw attention-0 0x%x\n", val); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3263 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
| 3264 | if (val & 0x18000) |
| 3265 | BNX2X_ERR("FATAL error from PXP\n"); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3266 | |
| 3267 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3268 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1); |
| 3269 | BNX2X_ERR("PXP hw attention-1 0x%x\n", val); |
| 3270 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3271 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3272 | |
| 3273 | if (attn & HW_INTERRUT_ASSERT_SET_2) { |
| 3274 | |
| 3275 | int port = BP_PORT(bp); |
| 3276 | int reg_offset; |
| 3277 | |
| 3278 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : |
| 3279 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); |
| 3280 | |
| 3281 | val = REG_RD(bp, reg_offset); |
| 3282 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); |
| 3283 | REG_WR(bp, reg_offset, val); |
| 3284 | |
| 3285 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3286 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3287 | bnx2x_panic(); |
| 3288 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
| 3292 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3293 | u32 val; |
| 3294 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3295 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
| 3296 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3297 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
| 3298 | int func = BP_FUNC(bp); |
| 3299 | |
| 3300 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3301 | bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp, |
| 3302 | func_mf_config[BP_ABS_FUNC(bp)].config); |
| 3303 | val = SHMEM_RD(bp, |
| 3304 | func_mb[BP_FW_MB_IDX(bp)].drv_status); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3305 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
| 3306 | bnx2x_dcc_event(bp, |
| 3307 | (val & DRV_STATUS_DCC_EVENT_MASK)); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 3308 | |
| 3309 | if (val & DRV_STATUS_SET_MF_BW) |
| 3310 | bnx2x_set_mf_bw(bp); |
| 3311 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3312 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3313 | bnx2x_pmf_update(bp); |
| 3314 | |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 3315 | /* Always call it here: bnx2x_link_report() will |
| 3316 | * prevent the link indication duplication. |
| 3317 | */ |
| 3318 | bnx2x__link_status_update(bp); |
| 3319 | |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 3320 | if (bp->port.pmf && |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 3321 | (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) && |
| 3322 | bp->dcbx_enabled > 0) |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 3323 | /* start dcbx state machine */ |
| 3324 | bnx2x_dcbx_set_params(bp, |
| 3325 | BNX2X_DCBX_STATE_NEG_RECEIVED); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3326 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3327 | |
| 3328 | BNX2X_ERR("MC assert!\n"); |
| 3329 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
| 3330 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); |
| 3331 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); |
| 3332 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); |
| 3333 | bnx2x_panic(); |
| 3334 | |
| 3335 | } else if (attn & BNX2X_MCP_ASSERT) { |
| 3336 | |
| 3337 | BNX2X_ERR("MCP assert!\n"); |
| 3338 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3339 | bnx2x_fw_dump(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3340 | |
| 3341 | } else |
| 3342 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); |
| 3343 | } |
| 3344 | |
| 3345 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3346 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
| 3347 | if (attn & BNX2X_GRC_TIMEOUT) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3348 | val = CHIP_IS_E1(bp) ? 0 : |
| 3349 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3350 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
| 3351 | } |
| 3352 | if (attn & BNX2X_GRC_RSV) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3353 | val = CHIP_IS_E1(bp) ? 0 : |
| 3354 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3355 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
| 3356 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3357 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3358 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3359 | } |
| 3360 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3361 | /* |
| 3362 | * Bits map: |
| 3363 | * 0-7 - Engine0 load counter. |
| 3364 | * 8-15 - Engine1 load counter. |
| 3365 | * 16 - Engine0 RESET_IN_PROGRESS bit. |
| 3366 | * 17 - Engine1 RESET_IN_PROGRESS bit. |
| 3367 | * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function |
| 3368 | * on the engine |
| 3369 | * 19 - Engine1 ONE_IS_LOADED. |
| 3370 | * 20 - Chip reset flow bit. When set none-leader must wait for both engines |
| 3371 | * leader to complete (check for both RESET_IN_PROGRESS bits and not for |
| 3372 | * just the one belonging to its engine). |
| 3373 | * |
| 3374 | */ |
| 3375 | #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 |
| 3376 | |
| 3377 | #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff |
| 3378 | #define BNX2X_PATH0_LOAD_CNT_SHIFT 0 |
| 3379 | #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 |
| 3380 | #define BNX2X_PATH1_LOAD_CNT_SHIFT 8 |
| 3381 | #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 |
| 3382 | #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 |
| 3383 | #define BNX2X_GLOBAL_RESET_BIT 0x00040000 |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 3384 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3385 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3386 | * Set the GLOBAL_RESET bit. |
| 3387 | * |
| 3388 | * Should be run under rtnl lock |
| 3389 | */ |
| 3390 | void bnx2x_set_reset_global(struct bnx2x *bp) |
| 3391 | { |
| 3392 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3393 | |
| 3394 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT); |
| 3395 | barrier(); |
| 3396 | mmiowb(); |
| 3397 | } |
| 3398 | |
| 3399 | /* |
| 3400 | * Clear the GLOBAL_RESET bit. |
| 3401 | * |
| 3402 | * Should be run under rtnl lock |
| 3403 | */ |
| 3404 | static inline void bnx2x_clear_reset_global(struct bnx2x *bp) |
| 3405 | { |
| 3406 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3407 | |
| 3408 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT)); |
| 3409 | barrier(); |
| 3410 | mmiowb(); |
| 3411 | } |
| 3412 | |
| 3413 | /* |
| 3414 | * Checks the GLOBAL_RESET bit. |
| 3415 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3416 | * should be run under rtnl lock |
| 3417 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3418 | static inline bool bnx2x_reset_is_global(struct bnx2x *bp) |
| 3419 | { |
| 3420 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3421 | |
| 3422 | DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val); |
| 3423 | return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false; |
| 3424 | } |
| 3425 | |
| 3426 | /* |
| 3427 | * Clear RESET_IN_PROGRESS bit for the current engine. |
| 3428 | * |
| 3429 | * Should be run under rtnl lock |
| 3430 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3431 | static inline void bnx2x_set_reset_done(struct bnx2x *bp) |
| 3432 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3433 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3434 | u32 bit = BP_PATH(bp) ? |
| 3435 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3436 | |
| 3437 | /* Clear the bit */ |
| 3438 | val &= ~bit; |
| 3439 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3440 | barrier(); |
| 3441 | mmiowb(); |
| 3442 | } |
| 3443 | |
| 3444 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3445 | * Set RESET_IN_PROGRESS for the current engine. |
| 3446 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3447 | * should be run under rtnl lock |
| 3448 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3449 | void bnx2x_set_reset_in_progress(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3450 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3451 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3452 | u32 bit = BP_PATH(bp) ? |
| 3453 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3454 | |
| 3455 | /* Set the bit */ |
| 3456 | val |= bit; |
| 3457 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3458 | barrier(); |
| 3459 | mmiowb(); |
| 3460 | } |
| 3461 | |
| 3462 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3463 | * Checks the RESET_IN_PROGRESS bit for the given engine. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3464 | * should be run under rtnl lock |
| 3465 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3466 | bool bnx2x_reset_is_done(struct bnx2x *bp, int engine) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3467 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3468 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3469 | u32 bit = engine ? |
| 3470 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3471 | |
| 3472 | /* return false if bit is set */ |
| 3473 | return (val & bit) ? false : true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3477 | * Increment the load counter for the current engine. |
| 3478 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3479 | * should be run under rtnl lock |
| 3480 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3481 | void bnx2x_inc_load_cnt(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3482 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3483 | u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3484 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3485 | BNX2X_PATH0_LOAD_CNT_MASK; |
| 3486 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3487 | BNX2X_PATH0_LOAD_CNT_SHIFT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3488 | |
| 3489 | DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val); |
| 3490 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3491 | /* get the current counter value */ |
| 3492 | val1 = (val & mask) >> shift; |
| 3493 | |
| 3494 | /* increment... */ |
| 3495 | val1++; |
| 3496 | |
| 3497 | /* clear the old value */ |
| 3498 | val &= ~mask; |
| 3499 | |
| 3500 | /* set the new one */ |
| 3501 | val |= ((val1 << shift) & mask); |
| 3502 | |
| 3503 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3504 | barrier(); |
| 3505 | mmiowb(); |
| 3506 | } |
| 3507 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3508 | /** |
| 3509 | * bnx2x_dec_load_cnt - decrement the load counter |
| 3510 | * |
| 3511 | * @bp: driver handle |
| 3512 | * |
| 3513 | * Should be run under rtnl lock. |
| 3514 | * Decrements the load counter for the current engine. Returns |
| 3515 | * the new counter value. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3516 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 3517 | u32 bnx2x_dec_load_cnt(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3518 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3519 | u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3520 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3521 | BNX2X_PATH0_LOAD_CNT_MASK; |
| 3522 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3523 | BNX2X_PATH0_LOAD_CNT_SHIFT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3524 | |
| 3525 | DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val); |
| 3526 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3527 | /* get the current counter value */ |
| 3528 | val1 = (val & mask) >> shift; |
| 3529 | |
| 3530 | /* decrement... */ |
| 3531 | val1--; |
| 3532 | |
| 3533 | /* clear the old value */ |
| 3534 | val &= ~mask; |
| 3535 | |
| 3536 | /* set the new one */ |
| 3537 | val |= ((val1 << shift) & mask); |
| 3538 | |
| 3539 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3540 | barrier(); |
| 3541 | mmiowb(); |
| 3542 | |
| 3543 | return val1; |
| 3544 | } |
| 3545 | |
| 3546 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3547 | * Read the load counter for the current engine. |
| 3548 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3549 | * should be run under rtnl lock |
| 3550 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3551 | static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3552 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3553 | u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3554 | BNX2X_PATH0_LOAD_CNT_MASK); |
| 3555 | u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3556 | BNX2X_PATH0_LOAD_CNT_SHIFT); |
| 3557 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3558 | |
| 3559 | DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val); |
| 3560 | |
| 3561 | val = (val & mask) >> shift; |
| 3562 | |
| 3563 | DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val); |
| 3564 | |
| 3565 | return val; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3568 | /* |
| 3569 | * Reset the load counter for the current engine. |
| 3570 | * |
| 3571 | * should be run under rtnl lock |
| 3572 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3573 | static inline void bnx2x_clear_load_cnt(struct bnx2x *bp) |
| 3574 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3575 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3576 | u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3577 | BNX2X_PATH0_LOAD_CNT_MASK); |
| 3578 | |
| 3579 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | static inline void _print_next_block(int idx, const char *blk) |
| 3583 | { |
| 3584 | if (idx) |
| 3585 | pr_cont(", "); |
| 3586 | pr_cont("%s", blk); |
| 3587 | } |
| 3588 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3589 | static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num, |
| 3590 | bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3591 | { |
| 3592 | int i = 0; |
| 3593 | u32 cur_bit = 0; |
| 3594 | for (i = 0; sig; i++) { |
| 3595 | cur_bit = ((u32)0x1 << i); |
| 3596 | if (sig & cur_bit) { |
| 3597 | switch (cur_bit) { |
| 3598 | case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3599 | if (print) |
| 3600 | _print_next_block(par_num++, "BRB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3601 | break; |
| 3602 | case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3603 | if (print) |
| 3604 | _print_next_block(par_num++, "PARSER"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3607 | if (print) |
| 3608 | _print_next_block(par_num++, "TSDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3609 | break; |
| 3610 | case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3611 | if (print) |
| 3612 | _print_next_block(par_num++, |
| 3613 | "SEARCHER"); |
| 3614 | break; |
| 3615 | case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: |
| 3616 | if (print) |
| 3617 | _print_next_block(par_num++, "TCM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3618 | break; |
| 3619 | case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3620 | if (print) |
| 3621 | _print_next_block(par_num++, "TSEMI"); |
| 3622 | break; |
| 3623 | case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: |
| 3624 | if (print) |
| 3625 | _print_next_block(par_num++, "XPB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| 3628 | |
| 3629 | /* Clear the bit */ |
| 3630 | sig &= ~cur_bit; |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | return par_num; |
| 3635 | } |
| 3636 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3637 | static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num, |
| 3638 | bool *global, bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3639 | { |
| 3640 | int i = 0; |
| 3641 | u32 cur_bit = 0; |
| 3642 | for (i = 0; sig; i++) { |
| 3643 | cur_bit = ((u32)0x1 << i); |
| 3644 | if (sig & cur_bit) { |
| 3645 | switch (cur_bit) { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3646 | case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: |
| 3647 | if (print) |
| 3648 | _print_next_block(par_num++, "PBF"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3649 | break; |
| 3650 | case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3651 | if (print) |
| 3652 | _print_next_block(par_num++, "QM"); |
| 3653 | break; |
| 3654 | case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: |
| 3655 | if (print) |
| 3656 | _print_next_block(par_num++, "TM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3657 | break; |
| 3658 | case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3659 | if (print) |
| 3660 | _print_next_block(par_num++, "XSDM"); |
| 3661 | break; |
| 3662 | case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: |
| 3663 | if (print) |
| 3664 | _print_next_block(par_num++, "XCM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3665 | break; |
| 3666 | case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3667 | if (print) |
| 3668 | _print_next_block(par_num++, "XSEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3669 | break; |
| 3670 | case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3671 | if (print) |
| 3672 | _print_next_block(par_num++, |
| 3673 | "DOORBELLQ"); |
| 3674 | break; |
| 3675 | case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: |
| 3676 | if (print) |
| 3677 | _print_next_block(par_num++, "NIG"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3678 | break; |
| 3679 | case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3680 | if (print) |
| 3681 | _print_next_block(par_num++, |
| 3682 | "VAUX PCI CORE"); |
| 3683 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3684 | break; |
| 3685 | case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3686 | if (print) |
| 3687 | _print_next_block(par_num++, "DEBUG"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3690 | if (print) |
| 3691 | _print_next_block(par_num++, "USDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3692 | break; |
| 3693 | case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3694 | if (print) |
| 3695 | _print_next_block(par_num++, "USEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3698 | if (print) |
| 3699 | _print_next_block(par_num++, "UPB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3700 | break; |
| 3701 | case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3702 | if (print) |
| 3703 | _print_next_block(par_num++, "CSDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3704 | break; |
| 3705 | } |
| 3706 | |
| 3707 | /* Clear the bit */ |
| 3708 | sig &= ~cur_bit; |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | return par_num; |
| 3713 | } |
| 3714 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3715 | static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num, |
| 3716 | bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3717 | { |
| 3718 | int i = 0; |
| 3719 | u32 cur_bit = 0; |
| 3720 | for (i = 0; sig; i++) { |
| 3721 | cur_bit = ((u32)0x1 << i); |
| 3722 | if (sig & cur_bit) { |
| 3723 | switch (cur_bit) { |
| 3724 | case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3725 | if (print) |
| 3726 | _print_next_block(par_num++, "CSEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3727 | break; |
| 3728 | case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3729 | if (print) |
| 3730 | _print_next_block(par_num++, "PXP"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3731 | break; |
| 3732 | case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3733 | if (print) |
| 3734 | _print_next_block(par_num++, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3735 | "PXPPCICLOCKCLIENT"); |
| 3736 | break; |
| 3737 | case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3738 | if (print) |
| 3739 | _print_next_block(par_num++, "CFC"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3740 | break; |
| 3741 | case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3742 | if (print) |
| 3743 | _print_next_block(par_num++, "CDU"); |
| 3744 | break; |
| 3745 | case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: |
| 3746 | if (print) |
| 3747 | _print_next_block(par_num++, "DMAE"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3748 | break; |
| 3749 | case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3750 | if (print) |
| 3751 | _print_next_block(par_num++, "IGU"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3752 | break; |
| 3753 | case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3754 | if (print) |
| 3755 | _print_next_block(par_num++, "MISC"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3756 | break; |
| 3757 | } |
| 3758 | |
| 3759 | /* Clear the bit */ |
| 3760 | sig &= ~cur_bit; |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | return par_num; |
| 3765 | } |
| 3766 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3767 | static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num, |
| 3768 | bool *global, bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3769 | { |
| 3770 | int i = 0; |
| 3771 | u32 cur_bit = 0; |
| 3772 | for (i = 0; sig; i++) { |
| 3773 | cur_bit = ((u32)0x1 << i); |
| 3774 | if (sig & cur_bit) { |
| 3775 | switch (cur_bit) { |
| 3776 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3777 | if (print) |
| 3778 | _print_next_block(par_num++, "MCP ROM"); |
| 3779 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3782 | if (print) |
| 3783 | _print_next_block(par_num++, |
| 3784 | "MCP UMP RX"); |
| 3785 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3788 | if (print) |
| 3789 | _print_next_block(par_num++, |
| 3790 | "MCP UMP TX"); |
| 3791 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3794 | if (print) |
| 3795 | _print_next_block(par_num++, |
| 3796 | "MCP SCPAD"); |
| 3797 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3798 | break; |
| 3799 | } |
| 3800 | |
| 3801 | /* Clear the bit */ |
| 3802 | sig &= ~cur_bit; |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | return par_num; |
| 3807 | } |
| 3808 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3809 | static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, |
| 3810 | u32 sig0, u32 sig1, u32 sig2, u32 sig3) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3811 | { |
| 3812 | if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) || |
| 3813 | (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) { |
| 3814 | int par_num = 0; |
| 3815 | DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: " |
| 3816 | "[0]:0x%08x [1]:0x%08x " |
| 3817 | "[2]:0x%08x [3]:0x%08x\n", |
| 3818 | sig0 & HW_PRTY_ASSERT_SET_0, |
| 3819 | sig1 & HW_PRTY_ASSERT_SET_1, |
| 3820 | sig2 & HW_PRTY_ASSERT_SET_2, |
| 3821 | sig3 & HW_PRTY_ASSERT_SET_3); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3822 | if (print) |
| 3823 | netdev_err(bp->dev, |
| 3824 | "Parity errors detected in blocks: "); |
| 3825 | par_num = bnx2x_check_blocks_with_parity0( |
| 3826 | sig0 & HW_PRTY_ASSERT_SET_0, par_num, print); |
| 3827 | par_num = bnx2x_check_blocks_with_parity1( |
| 3828 | sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print); |
| 3829 | par_num = bnx2x_check_blocks_with_parity2( |
| 3830 | sig2 & HW_PRTY_ASSERT_SET_2, par_num, print); |
| 3831 | par_num = bnx2x_check_blocks_with_parity3( |
| 3832 | sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print); |
| 3833 | if (print) |
| 3834 | pr_cont("\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3835 | return true; |
| 3836 | } else |
| 3837 | return false; |
| 3838 | } |
| 3839 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3840 | /** |
| 3841 | * bnx2x_chk_parity_attn - checks for parity attentions. |
| 3842 | * |
| 3843 | * @bp: driver handle |
| 3844 | * @global: true if there was a global attention |
| 3845 | * @print: show parity attention in syslog |
| 3846 | */ |
| 3847 | bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3848 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3849 | struct attn_route attn; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3850 | int port = BP_PORT(bp); |
| 3851 | |
| 3852 | attn.sig[0] = REG_RD(bp, |
| 3853 | MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + |
| 3854 | port*4); |
| 3855 | attn.sig[1] = REG_RD(bp, |
| 3856 | MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + |
| 3857 | port*4); |
| 3858 | attn.sig[2] = REG_RD(bp, |
| 3859 | MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + |
| 3860 | port*4); |
| 3861 | attn.sig[3] = REG_RD(bp, |
| 3862 | MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + |
| 3863 | port*4); |
| 3864 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3865 | return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1], |
| 3866 | attn.sig[2], attn.sig[3]); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3869 | |
| 3870 | static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn) |
| 3871 | { |
| 3872 | u32 val; |
| 3873 | if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { |
| 3874 | |
| 3875 | val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); |
| 3876 | BNX2X_ERR("PGLUE hw attention 0x%x\n", val); |
| 3877 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) |
| 3878 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3879 | "ADDRESS_ERROR\n"); |
| 3880 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) |
| 3881 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3882 | "INCORRECT_RCV_BEHAVIOR\n"); |
| 3883 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) |
| 3884 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3885 | "WAS_ERROR_ATTN\n"); |
| 3886 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) |
| 3887 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3888 | "VF_LENGTH_VIOLATION_ATTN\n"); |
| 3889 | if (val & |
| 3890 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) |
| 3891 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3892 | "VF_GRC_SPACE_VIOLATION_ATTN\n"); |
| 3893 | if (val & |
| 3894 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) |
| 3895 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3896 | "VF_MSIX_BAR_VIOLATION_ATTN\n"); |
| 3897 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) |
| 3898 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3899 | "TCPL_ERROR_ATTN\n"); |
| 3900 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) |
| 3901 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3902 | "TCPL_IN_TWO_RCBS_ATTN\n"); |
| 3903 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) |
| 3904 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3905 | "CSSNOOP_FIFO_OVERFLOW\n"); |
| 3906 | } |
| 3907 | if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { |
| 3908 | val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR); |
| 3909 | BNX2X_ERR("ATC hw attention 0x%x\n", val); |
| 3910 | if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) |
| 3911 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); |
| 3912 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) |
| 3913 | BNX2X_ERR("ATC_ATC_INT_STS_REG" |
| 3914 | "_ATC_TCPL_TO_NOT_PEND\n"); |
| 3915 | if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) |
| 3916 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3917 | "ATC_GPA_MULTIPLE_HITS\n"); |
| 3918 | if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) |
| 3919 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3920 | "ATC_RCPL_TO_EMPTY_CNT\n"); |
| 3921 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) |
| 3922 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); |
| 3923 | if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) |
| 3924 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3925 | "ATC_IREQ_LESS_THAN_STU\n"); |
| 3926 | } |
| 3927 | |
| 3928 | if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | |
| 3929 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { |
| 3930 | BNX2X_ERR("FATAL parity attention set4 0x%x\n", |
| 3931 | (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | |
| 3932 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); |
| 3933 | } |
| 3934 | |
| 3935 | } |
| 3936 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3937 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
| 3938 | { |
| 3939 | struct attn_route attn, *group_mask; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3940 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3941 | int index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3942 | u32 reg_addr; |
| 3943 | u32 val; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3944 | u32 aeu_mask; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3945 | bool global = false; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3946 | |
| 3947 | /* need to take HW lock because MCP or other port might also |
| 3948 | try to handle this event */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3949 | bnx2x_acquire_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3950 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3951 | if (bnx2x_chk_parity_attn(bp, &global, true)) { |
| 3952 | #ifndef BNX2X_STOP_ON_ERROR |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3953 | bp->recovery_state = BNX2X_RECOVERY_INIT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3954 | schedule_delayed_work(&bp->reset_task, 0); |
| 3955 | /* Disable HW interrupts */ |
| 3956 | bnx2x_int_disable(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3957 | /* In case of parity errors don't handle attentions so that |
| 3958 | * other function would "see" parity errors. |
| 3959 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3960 | #else |
| 3961 | bnx2x_panic(); |
| 3962 | #endif |
| 3963 | bnx2x_release_alr(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3964 | return; |
| 3965 | } |
| 3966 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3967 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
| 3968 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); |
| 3969 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); |
| 3970 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3971 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3972 | attn.sig[4] = |
| 3973 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); |
| 3974 | else |
| 3975 | attn.sig[4] = 0; |
| 3976 | |
| 3977 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n", |
| 3978 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3979 | |
| 3980 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
| 3981 | if (deasserted & (1 << index)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3982 | group_mask = &bp->attn_group[index]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3983 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3984 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x " |
| 3985 | "%08x %08x %08x\n", |
| 3986 | index, |
| 3987 | group_mask->sig[0], group_mask->sig[1], |
| 3988 | group_mask->sig[2], group_mask->sig[3], |
| 3989 | group_mask->sig[4]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3990 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3991 | bnx2x_attn_int_deasserted4(bp, |
| 3992 | attn.sig[4] & group_mask->sig[4]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3993 | bnx2x_attn_int_deasserted3(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3994 | attn.sig[3] & group_mask->sig[3]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3995 | bnx2x_attn_int_deasserted1(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3996 | attn.sig[1] & group_mask->sig[1]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3997 | bnx2x_attn_int_deasserted2(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3998 | attn.sig[2] & group_mask->sig[2]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3999 | bnx2x_attn_int_deasserted0(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 4000 | attn.sig[0] & group_mask->sig[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4001 | } |
| 4002 | } |
| 4003 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 4004 | bnx2x_release_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4005 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4006 | if (bp->common.int_block == INT_BLOCK_HC) |
| 4007 | reg_addr = (HC_REG_COMMAND_REG + port*32 + |
| 4008 | COMMAND_REG_ATTN_BITS_CLR); |
| 4009 | else |
| 4010 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4011 | |
| 4012 | val = ~deasserted; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4013 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val, |
| 4014 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4015 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4016 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4017 | if (~bp->attn_state & deasserted) |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4018 | BNX2X_ERR("IGU ERROR\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4019 | |
| 4020 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 4021 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 4022 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4023 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 4024 | aeu_mask = REG_RD(bp, reg_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4025 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4026 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", |
| 4027 | aeu_mask, deasserted); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 4028 | aeu_mask |= (deasserted & 0x3ff); |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4029 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
| 4030 | |
| 4031 | REG_WR(bp, reg_addr, aeu_mask); |
| 4032 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4033 | |
| 4034 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
| 4035 | bp->attn_state &= ~deasserted; |
| 4036 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
| 4037 | } |
| 4038 | |
| 4039 | static void bnx2x_attn_int(struct bnx2x *bp) |
| 4040 | { |
| 4041 | /* read local copy of bits */ |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 4042 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 4043 | attn_bits); |
| 4044 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 4045 | attn_bits_ack); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4046 | u32 attn_state = bp->attn_state; |
| 4047 | |
| 4048 | /* look for changed bits */ |
| 4049 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; |
| 4050 | u32 deasserted = ~attn_bits & attn_ack & attn_state; |
| 4051 | |
| 4052 | DP(NETIF_MSG_HW, |
| 4053 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", |
| 4054 | attn_bits, attn_ack, asserted, deasserted); |
| 4055 | |
| 4056 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4057 | BNX2X_ERR("BAD attention state\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4058 | |
| 4059 | /* handle bits that were raised */ |
| 4060 | if (asserted) |
| 4061 | bnx2x_attn_int_asserted(bp, asserted); |
| 4062 | |
| 4063 | if (deasserted) |
| 4064 | bnx2x_attn_int_deasserted(bp, deasserted); |
| 4065 | } |
| 4066 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4067 | void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
| 4068 | u16 index, u8 op, u8 update) |
| 4069 | { |
| 4070 | u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; |
| 4071 | |
| 4072 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, |
| 4073 | igu_addr); |
| 4074 | } |
| 4075 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4076 | static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod) |
| 4077 | { |
| 4078 | /* No memory barriers */ |
| 4079 | storm_memset_eq_prod(bp, prod, BP_FUNC(bp)); |
| 4080 | mmiowb(); /* keep prod updates ordered */ |
| 4081 | } |
| 4082 | |
| 4083 | #ifdef BCM_CNIC |
| 4084 | static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid, |
| 4085 | union event_ring_elem *elem) |
| 4086 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4087 | u8 err = elem->message.error; |
| 4088 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4089 | if (!bp->cnic_eth_dev.starting_cid || |
Vladislav Zolotarov | c3a8ce6 | 2011-05-22 10:08:09 +0000 | [diff] [blame] | 4090 | (cid < bp->cnic_eth_dev.starting_cid && |
| 4091 | cid != bp->cnic_eth_dev.iscsi_l2_cid)) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4092 | return 1; |
| 4093 | |
| 4094 | DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid); |
| 4095 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4096 | if (unlikely(err)) { |
| 4097 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4098 | BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n", |
| 4099 | cid); |
| 4100 | bnx2x_panic_dump(bp); |
| 4101 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4102 | bnx2x_cnic_cfc_comp(bp, cid, err); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4103 | return 0; |
| 4104 | } |
| 4105 | #endif |
| 4106 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4107 | static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp) |
| 4108 | { |
| 4109 | struct bnx2x_mcast_ramrod_params rparam; |
| 4110 | int rc; |
| 4111 | |
| 4112 | memset(&rparam, 0, sizeof(rparam)); |
| 4113 | |
| 4114 | rparam.mcast_obj = &bp->mcast_obj; |
| 4115 | |
| 4116 | netif_addr_lock_bh(bp->dev); |
| 4117 | |
| 4118 | /* Clear pending state for the last command */ |
| 4119 | bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw); |
| 4120 | |
| 4121 | /* If there are pending mcast commands - send them */ |
| 4122 | if (bp->mcast_obj.check_pending(&bp->mcast_obj)) { |
| 4123 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); |
| 4124 | if (rc < 0) |
| 4125 | BNX2X_ERR("Failed to send pending mcast commands: %d\n", |
| 4126 | rc); |
| 4127 | } |
| 4128 | |
| 4129 | netif_addr_unlock_bh(bp->dev); |
| 4130 | } |
| 4131 | |
| 4132 | static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp, |
| 4133 | union event_ring_elem *elem) |
| 4134 | { |
| 4135 | unsigned long ramrod_flags = 0; |
| 4136 | int rc = 0; |
| 4137 | u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK; |
| 4138 | struct bnx2x_vlan_mac_obj *vlan_mac_obj; |
| 4139 | |
| 4140 | /* Always push next commands out, don't wait here */ |
| 4141 | __set_bit(RAMROD_CONT, &ramrod_flags); |
| 4142 | |
| 4143 | switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) { |
| 4144 | case BNX2X_FILTER_MAC_PENDING: |
| 4145 | #ifdef BCM_CNIC |
| 4146 | if (cid == BNX2X_ISCSI_ETH_CID) |
| 4147 | vlan_mac_obj = &bp->iscsi_l2_mac_obj; |
| 4148 | else |
| 4149 | #endif |
| 4150 | vlan_mac_obj = &bp->fp[cid].mac_obj; |
| 4151 | |
| 4152 | break; |
| 4153 | vlan_mac_obj = &bp->fp[cid].mac_obj; |
| 4154 | |
| 4155 | case BNX2X_FILTER_MCAST_PENDING: |
| 4156 | /* This is only relevant for 57710 where multicast MACs are |
| 4157 | * configured as unicast MACs using the same ramrod. |
| 4158 | */ |
| 4159 | bnx2x_handle_mcast_eqe(bp); |
| 4160 | return; |
| 4161 | default: |
| 4162 | BNX2X_ERR("Unsupported classification command: %d\n", |
| 4163 | elem->message.data.eth_event.echo); |
| 4164 | return; |
| 4165 | } |
| 4166 | |
| 4167 | rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags); |
| 4168 | |
| 4169 | if (rc < 0) |
| 4170 | BNX2X_ERR("Failed to schedule new commands: %d\n", rc); |
| 4171 | else if (rc > 0) |
| 4172 | DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n"); |
| 4173 | |
| 4174 | } |
| 4175 | |
| 4176 | #ifdef BCM_CNIC |
| 4177 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start); |
| 4178 | #endif |
| 4179 | |
| 4180 | static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp) |
| 4181 | { |
| 4182 | netif_addr_lock_bh(bp->dev); |
| 4183 | |
| 4184 | clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); |
| 4185 | |
| 4186 | /* Send rx_mode command again if was requested */ |
| 4187 | if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state)) |
| 4188 | bnx2x_set_storm_rx_mode(bp); |
| 4189 | #ifdef BCM_CNIC |
| 4190 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, |
| 4191 | &bp->sp_state)) |
| 4192 | bnx2x_set_iscsi_eth_rx_mode(bp, true); |
| 4193 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, |
| 4194 | &bp->sp_state)) |
| 4195 | bnx2x_set_iscsi_eth_rx_mode(bp, false); |
| 4196 | #endif |
| 4197 | |
| 4198 | netif_addr_unlock_bh(bp->dev); |
| 4199 | } |
| 4200 | |
| 4201 | static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj( |
| 4202 | struct bnx2x *bp, u32 cid) |
| 4203 | { |
| 4204 | #ifdef BCM_CNIC |
| 4205 | if (cid == BNX2X_FCOE_ETH_CID) |
| 4206 | return &bnx2x_fcoe(bp, q_obj); |
| 4207 | else |
| 4208 | #endif |
| 4209 | return &bnx2x_fp(bp, cid, q_obj); |
| 4210 | } |
| 4211 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4212 | static void bnx2x_eq_int(struct bnx2x *bp) |
| 4213 | { |
| 4214 | u16 hw_cons, sw_cons, sw_prod; |
| 4215 | union event_ring_elem *elem; |
| 4216 | u32 cid; |
| 4217 | u8 opcode; |
| 4218 | int spqe_cnt = 0; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4219 | struct bnx2x_queue_sp_obj *q_obj; |
| 4220 | struct bnx2x_func_sp_obj *f_obj = &bp->func_obj; |
| 4221 | struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4222 | |
| 4223 | hw_cons = le16_to_cpu(*bp->eq_cons_sb); |
| 4224 | |
| 4225 | /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256. |
| 4226 | * when we get the the next-page we nned to adjust so the loop |
| 4227 | * condition below will be met. The next element is the size of a |
| 4228 | * regular element and hence incrementing by 1 |
| 4229 | */ |
| 4230 | if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) |
| 4231 | hw_cons++; |
| 4232 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4233 | /* This function may never run in parallel with itself for a |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4234 | * specific bp, thus there is no need in "paired" read memory |
| 4235 | * barrier here. |
| 4236 | */ |
| 4237 | sw_cons = bp->eq_cons; |
| 4238 | sw_prod = bp->eq_prod; |
| 4239 | |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4240 | DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n", |
| 4241 | hw_cons, sw_cons, atomic_read(&bp->eq_spq_left)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4242 | |
| 4243 | for (; sw_cons != hw_cons; |
| 4244 | sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { |
| 4245 | |
| 4246 | |
| 4247 | elem = &bp->eq_ring[EQ_DESC(sw_cons)]; |
| 4248 | |
| 4249 | cid = SW_CID(elem->message.data.cfc_del_event.cid); |
| 4250 | opcode = elem->message.opcode; |
| 4251 | |
| 4252 | |
| 4253 | /* handle eq element */ |
| 4254 | switch (opcode) { |
| 4255 | case EVENT_RING_OPCODE_STAT_QUERY: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4256 | DP(NETIF_MSG_TIMER, "got statistics comp event %d\n", |
| 4257 | bp->stats_comp++); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4258 | /* nothing to do with stats comp */ |
| 4259 | continue; |
| 4260 | |
| 4261 | case EVENT_RING_OPCODE_CFC_DEL: |
| 4262 | /* handle according to cid range */ |
| 4263 | /* |
| 4264 | * we may want to verify here that the bp state is |
| 4265 | * HALTING |
| 4266 | */ |
| 4267 | DP(NETIF_MSG_IFDOWN, |
| 4268 | "got delete ramrod for MULTI[%d]\n", cid); |
| 4269 | #ifdef BCM_CNIC |
| 4270 | if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem)) |
| 4271 | goto next_spqe; |
| 4272 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4273 | q_obj = bnx2x_cid_to_q_obj(bp, cid); |
| 4274 | |
| 4275 | if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL)) |
| 4276 | break; |
| 4277 | |
| 4278 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4279 | |
| 4280 | goto next_spqe; |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 4281 | |
| 4282 | case EVENT_RING_OPCODE_STOP_TRAFFIC: |
| 4283 | DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n"); |
| 4284 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED); |
| 4285 | goto next_spqe; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4286 | |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 4287 | case EVENT_RING_OPCODE_START_TRAFFIC: |
| 4288 | DP(NETIF_MSG_IFUP, "got START TRAFFIC\n"); |
| 4289 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED); |
| 4290 | goto next_spqe; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4291 | case EVENT_RING_OPCODE_FUNCTION_START: |
| 4292 | DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n"); |
| 4293 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START)) |
| 4294 | break; |
| 4295 | |
| 4296 | goto next_spqe; |
| 4297 | |
| 4298 | case EVENT_RING_OPCODE_FUNCTION_STOP: |
| 4299 | DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n"); |
| 4300 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP)) |
| 4301 | break; |
| 4302 | |
| 4303 | goto next_spqe; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | switch (opcode | bp->state) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4307 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
| 4308 | BNX2X_STATE_OPEN): |
| 4309 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4310 | BNX2X_STATE_OPENING_WAIT4_PORT): |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4311 | cid = elem->message.data.eth_event.echo & |
| 4312 | BNX2X_SWCID_MASK; |
| 4313 | DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n", |
| 4314 | cid); |
| 4315 | rss_raw->clear_pending(rss_raw); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4316 | break; |
| 4317 | |
| 4318 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN): |
| 4319 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG): |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4320 | case (EVENT_RING_OPCODE_SET_MAC | |
| 4321 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4322 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4323 | BNX2X_STATE_OPEN): |
| 4324 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4325 | BNX2X_STATE_DIAG): |
| 4326 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4327 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4328 | DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n"); |
| 4329 | bnx2x_handle_classification_eqe(bp, elem); |
| 4330 | break; |
| 4331 | |
| 4332 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4333 | BNX2X_STATE_OPEN): |
| 4334 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4335 | BNX2X_STATE_DIAG): |
| 4336 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4337 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4338 | DP(NETIF_MSG_IFUP, "got mcast ramrod\n"); |
| 4339 | bnx2x_handle_mcast_eqe(bp); |
| 4340 | break; |
| 4341 | |
| 4342 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4343 | BNX2X_STATE_OPEN): |
| 4344 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4345 | BNX2X_STATE_DIAG): |
| 4346 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4347 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4348 | DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n"); |
| 4349 | bnx2x_handle_rx_mode_eqe(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4350 | break; |
| 4351 | default: |
| 4352 | /* unknown event log error and continue */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4353 | BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n", |
| 4354 | elem->message.opcode, bp->state); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4355 | } |
| 4356 | next_spqe: |
| 4357 | spqe_cnt++; |
| 4358 | } /* for */ |
| 4359 | |
Dmitry Kravkov | 8fe23fb | 2010-10-06 03:27:41 +0000 | [diff] [blame] | 4360 | smp_mb__before_atomic_inc(); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4361 | atomic_add(spqe_cnt, &bp->eq_spq_left); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4362 | |
| 4363 | bp->eq_cons = sw_cons; |
| 4364 | bp->eq_prod = sw_prod; |
| 4365 | /* Make sure that above mem writes were issued towards the memory */ |
| 4366 | smp_wmb(); |
| 4367 | |
| 4368 | /* update producer */ |
| 4369 | bnx2x_update_eq_prod(bp, bp->eq_prod); |
| 4370 | } |
| 4371 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4372 | static void bnx2x_sp_task(struct work_struct *work) |
| 4373 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 4374 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4375 | u16 status; |
| 4376 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4377 | status = bnx2x_update_dsb_idx(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4378 | /* if (status == 0) */ |
| 4379 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4380 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4381 | DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4382 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 4383 | /* HW attentions */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4384 | if (status & BNX2X_DEF_SB_ATT_IDX) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4385 | bnx2x_attn_int(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4386 | status &= ~BNX2X_DEF_SB_ATT_IDX; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4387 | } |
| 4388 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4389 | /* SP events: STAT_QUERY and others */ |
| 4390 | if (status & BNX2X_DEF_SB_IDX) { |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4391 | #ifdef BCM_CNIC |
| 4392 | struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4393 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4394 | if ((!NO_FCOE(bp)) && |
| 4395 | (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) |
| 4396 | napi_schedule(&bnx2x_fcoe(bp, napi)); |
| 4397 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4398 | /* Handle EQ completions */ |
| 4399 | bnx2x_eq_int(bp); |
| 4400 | |
| 4401 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, |
| 4402 | le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1); |
| 4403 | |
| 4404 | status &= ~BNX2X_DEF_SB_IDX; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | if (unlikely(status)) |
| 4408 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", |
| 4409 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4410 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4411 | bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID, |
| 4412 | le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4413 | } |
| 4414 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 4415 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4416 | { |
| 4417 | struct net_device *dev = dev_instance; |
| 4418 | struct bnx2x *bp = netdev_priv(dev); |
| 4419 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4420 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, |
| 4421 | IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4422 | |
| 4423 | #ifdef BNX2X_STOP_ON_ERROR |
| 4424 | if (unlikely(bp->panic)) |
| 4425 | return IRQ_HANDLED; |
| 4426 | #endif |
| 4427 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 4428 | #ifdef BCM_CNIC |
| 4429 | { |
| 4430 | struct cnic_ops *c_ops; |
| 4431 | |
| 4432 | rcu_read_lock(); |
| 4433 | c_ops = rcu_dereference(bp->cnic_ops); |
| 4434 | if (c_ops) |
| 4435 | c_ops->cnic_handler(bp->cnic_data, NULL); |
| 4436 | rcu_read_unlock(); |
| 4437 | } |
| 4438 | #endif |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 4439 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4440 | |
| 4441 | return IRQ_HANDLED; |
| 4442 | } |
| 4443 | |
| 4444 | /* end of slow path */ |
| 4445 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4446 | |
| 4447 | void bnx2x_drv_pulse(struct bnx2x *bp) |
| 4448 | { |
| 4449 | SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb, |
| 4450 | bp->fw_drv_pulse_wr_seq); |
| 4451 | } |
| 4452 | |
| 4453 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4454 | static void bnx2x_timer(unsigned long data) |
| 4455 | { |
| 4456 | struct bnx2x *bp = (struct bnx2x *) data; |
| 4457 | |
| 4458 | if (!netif_running(bp->dev)) |
| 4459 | return; |
| 4460 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4461 | if (poll) { |
| 4462 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4463 | |
Eilon Greenstein | 7961f79 | 2009-03-02 07:59:31 +0000 | [diff] [blame] | 4464 | bnx2x_tx_int(fp); |
David S. Miller | b8ee832 | 2011-04-17 16:56:12 -0700 | [diff] [blame] | 4465 | bnx2x_rx_int(fp, 1000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4466 | } |
| 4467 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4468 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4469 | int mb_idx = BP_FW_MB_IDX(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4470 | u32 drv_pulse; |
| 4471 | u32 mcp_pulse; |
| 4472 | |
| 4473 | ++bp->fw_drv_pulse_wr_seq; |
| 4474 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; |
| 4475 | /* TBD - add SYSTEM_TIME */ |
| 4476 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4477 | bnx2x_drv_pulse(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4478 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4479 | mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4480 | MCP_PULSE_SEQ_MASK); |
| 4481 | /* The delta between driver pulse and mcp response |
| 4482 | * should be 1 (before mcp response) or 0 (after mcp response) |
| 4483 | */ |
| 4484 | if ((drv_pulse != mcp_pulse) && |
| 4485 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { |
| 4486 | /* someone lost a heartbeat... */ |
| 4487 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", |
| 4488 | drv_pulse, mcp_pulse); |
| 4489 | } |
| 4490 | } |
| 4491 | |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 4492 | if (bp->state == BNX2X_STATE_OPEN) |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4493 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4494 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4495 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 4496 | } |
| 4497 | |
| 4498 | /* end of Statistics */ |
| 4499 | |
| 4500 | /* nic init */ |
| 4501 | |
| 4502 | /* |
| 4503 | * nic init service functions |
| 4504 | */ |
| 4505 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4506 | static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4507 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4508 | u32 i; |
| 4509 | if (!(len%4) && !(addr%4)) |
| 4510 | for (i = 0; i < len; i += 4) |
| 4511 | REG_WR(bp, addr + i, fill); |
| 4512 | else |
| 4513 | for (i = 0; i < len; i++) |
| 4514 | REG_WR8(bp, addr + i, fill); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4515 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4516 | } |
| 4517 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4518 | /* helper: writes FP SP data to FW - data_size in dwords */ |
| 4519 | static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp, |
| 4520 | int fw_sb_id, |
| 4521 | u32 *sb_data_p, |
| 4522 | u32 data_size) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4523 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4524 | int index; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4525 | for (index = 0; index < data_size; index++) |
| 4526 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4527 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + |
| 4528 | sizeof(u32)*index, |
| 4529 | *(sb_data_p + index)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4532 | static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id) |
| 4533 | { |
| 4534 | u32 *sb_data_p; |
| 4535 | u32 data_size = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4536 | struct hc_status_block_data_e2 sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4537 | struct hc_status_block_data_e1x sb_data_e1x; |
| 4538 | |
| 4539 | /* disable the function first */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4540 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4541 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4542 | sb_data_e2.common.state = SB_DISABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4543 | sb_data_e2.common.p_func.vf_valid = false; |
| 4544 | sb_data_p = (u32 *)&sb_data_e2; |
| 4545 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); |
| 4546 | } else { |
| 4547 | memset(&sb_data_e1x, 0, |
| 4548 | sizeof(struct hc_status_block_data_e1x)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4549 | sb_data_e1x.common.state = SB_DISABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4550 | sb_data_e1x.common.p_func.vf_valid = false; |
| 4551 | sb_data_p = (u32 *)&sb_data_e1x; |
| 4552 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); |
| 4553 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4554 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
| 4555 | |
| 4556 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4557 | CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0, |
| 4558 | CSTORM_STATUS_BLOCK_SIZE); |
| 4559 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4560 | CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0, |
| 4561 | CSTORM_SYNC_BLOCK_SIZE); |
| 4562 | } |
| 4563 | |
| 4564 | /* helper: writes SP SB data to FW */ |
| 4565 | static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp, |
| 4566 | struct hc_sp_status_block_data *sp_sb_data) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4567 | { |
| 4568 | int func = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4569 | int i; |
| 4570 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) |
| 4571 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4572 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + |
| 4573 | i*sizeof(u32), |
| 4574 | *((u32 *)sp_sb_data + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4575 | } |
| 4576 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4577 | static inline void bnx2x_zero_sp_sb(struct bnx2x *bp) |
| 4578 | { |
| 4579 | int func = BP_FUNC(bp); |
| 4580 | struct hc_sp_status_block_data sp_sb_data; |
| 4581 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); |
| 4582 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4583 | sp_sb_data.state = SB_DISABLED; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4584 | sp_sb_data.p_func.vf_valid = false; |
| 4585 | |
| 4586 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
| 4587 | |
| 4588 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4589 | CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0, |
| 4590 | CSTORM_SP_STATUS_BLOCK_SIZE); |
| 4591 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4592 | CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0, |
| 4593 | CSTORM_SP_SYNC_BLOCK_SIZE); |
| 4594 | |
| 4595 | } |
| 4596 | |
| 4597 | |
| 4598 | static inline |
| 4599 | void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, |
| 4600 | int igu_sb_id, int igu_seg_id) |
| 4601 | { |
| 4602 | hc_sm->igu_sb_id = igu_sb_id; |
| 4603 | hc_sm->igu_seg_id = igu_seg_id; |
| 4604 | hc_sm->timer_value = 0xFF; |
| 4605 | hc_sm->time_to_expire = 0xFFFFFFFF; |
| 4606 | } |
| 4607 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 4608 | static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4609 | u8 vf_valid, int fw_sb_id, int igu_sb_id) |
| 4610 | { |
| 4611 | int igu_seg_id; |
| 4612 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4613 | struct hc_status_block_data_e2 sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4614 | struct hc_status_block_data_e1x sb_data_e1x; |
| 4615 | struct hc_status_block_sm *hc_sm_p; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4616 | int data_size; |
| 4617 | u32 *sb_data_p; |
| 4618 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4619 | if (CHIP_INT_MODE_IS_BC(bp)) |
| 4620 | igu_seg_id = HC_SEG_ACCESS_NORM; |
| 4621 | else |
| 4622 | igu_seg_id = IGU_SEG_ACCESS_NORM; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4623 | |
| 4624 | bnx2x_zero_fp_sb(bp, fw_sb_id); |
| 4625 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4626 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4627 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4628 | sb_data_e2.common.state = SB_ENABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4629 | sb_data_e2.common.p_func.pf_id = BP_FUNC(bp); |
| 4630 | sb_data_e2.common.p_func.vf_id = vfid; |
| 4631 | sb_data_e2.common.p_func.vf_valid = vf_valid; |
| 4632 | sb_data_e2.common.p_func.vnic_id = BP_VN(bp); |
| 4633 | sb_data_e2.common.same_igu_sb_1b = true; |
| 4634 | sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping); |
| 4635 | sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping); |
| 4636 | hc_sm_p = sb_data_e2.common.state_machine; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4637 | sb_data_p = (u32 *)&sb_data_e2; |
| 4638 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); |
| 4639 | } else { |
| 4640 | memset(&sb_data_e1x, 0, |
| 4641 | sizeof(struct hc_status_block_data_e1x)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4642 | sb_data_e1x.common.state = SB_ENABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4643 | sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp); |
| 4644 | sb_data_e1x.common.p_func.vf_id = 0xff; |
| 4645 | sb_data_e1x.common.p_func.vf_valid = false; |
| 4646 | sb_data_e1x.common.p_func.vnic_id = BP_VN(bp); |
| 4647 | sb_data_e1x.common.same_igu_sb_1b = true; |
| 4648 | sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping); |
| 4649 | sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping); |
| 4650 | hc_sm_p = sb_data_e1x.common.state_machine; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4651 | sb_data_p = (u32 *)&sb_data_e1x; |
| 4652 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); |
| 4653 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4654 | |
| 4655 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], |
| 4656 | igu_sb_id, igu_seg_id); |
| 4657 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], |
| 4658 | igu_sb_id, igu_seg_id); |
| 4659 | |
| 4660 | DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id); |
| 4661 | |
| 4662 | /* write indecies to HW */ |
| 4663 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
| 4664 | } |
| 4665 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4666 | static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4667 | u16 tx_usec, u16 rx_usec) |
| 4668 | { |
| 4669 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX, |
| 4670 | false, rx_usec); |
| 4671 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX, |
| 4672 | false, tx_usec); |
| 4673 | } |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4674 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4675 | static void bnx2x_init_def_sb(struct bnx2x *bp) |
| 4676 | { |
| 4677 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
| 4678 | dma_addr_t mapping = bp->def_status_blk_mapping; |
| 4679 | int igu_sp_sb_index; |
| 4680 | int igu_seg_id; |
| 4681 | int port = BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4682 | int func = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4683 | int reg_offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4684 | u64 section; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4685 | int index; |
| 4686 | struct hc_sp_status_block_data sp_sb_data; |
| 4687 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); |
| 4688 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4689 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 4690 | igu_sp_sb_index = DEF_SB_IGU_ID; |
| 4691 | igu_seg_id = HC_SEG_ACCESS_DEF; |
| 4692 | } else { |
| 4693 | igu_sp_sb_index = bp->igu_dsb_id; |
| 4694 | igu_seg_id = IGU_SEG_ACCESS_DEF; |
| 4695 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4696 | |
| 4697 | /* ATTN */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4698 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4699 | atten_status_block); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4700 | def_sb->atten_status_block.status_block_id = igu_sp_sb_index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4701 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4702 | bp->attn_state = 0; |
| 4703 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4704 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 4705 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4706 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4707 | int sindex; |
| 4708 | /* take care of sig[0]..sig[4] */ |
| 4709 | for (sindex = 0; sindex < 4; sindex++) |
| 4710 | bp->attn_group[index].sig[sindex] = |
| 4711 | REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4712 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4713 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4714 | /* |
| 4715 | * enable5 is separate from the rest of the registers, |
| 4716 | * and therefore the address skip is 4 |
| 4717 | * and not 16 between the different groups |
| 4718 | */ |
| 4719 | bp->attn_group[index].sig[4] = REG_RD(bp, |
| 4720 | reg_offset + 0x10 + 0x4*index); |
| 4721 | else |
| 4722 | bp->attn_group[index].sig[4] = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4723 | } |
| 4724 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4725 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 4726 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : |
| 4727 | HC_REG_ATTN_MSG0_ADDR_L); |
| 4728 | |
| 4729 | REG_WR(bp, reg_offset, U64_LO(section)); |
| 4730 | REG_WR(bp, reg_offset + 4, U64_HI(section)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4731 | } else if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4732 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); |
| 4733 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); |
| 4734 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4735 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4736 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
| 4737 | sp_sb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4738 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4739 | bnx2x_zero_sp_sb(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4740 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4741 | sp_sb_data.state = SB_ENABLED; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4742 | sp_sb_data.host_sb_addr.lo = U64_LO(section); |
| 4743 | sp_sb_data.host_sb_addr.hi = U64_HI(section); |
| 4744 | sp_sb_data.igu_sb_id = igu_sp_sb_index; |
| 4745 | sp_sb_data.igu_seg_id = igu_seg_id; |
| 4746 | sp_sb_data.p_func.pf_id = func; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4747 | sp_sb_data.p_func.vnic_id = BP_VN(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4748 | sp_sb_data.p_func.vf_id = 0xff; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4749 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4750 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4751 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4752 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4753 | } |
| 4754 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 4755 | void bnx2x_update_coalesce(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4756 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4757 | int i; |
| 4758 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4759 | for_each_eth_queue(bp, i) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4760 | bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id, |
Ariel Elior | 423cfa7e | 2011-03-14 13:43:22 -0700 | [diff] [blame] | 4761 | bp->tx_ticks, bp->rx_ticks); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4762 | } |
| 4763 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4764 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
| 4765 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4766 | spin_lock_init(&bp->spq_lock); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4767 | atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4768 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4769 | bp->spq_prod_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4770 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
| 4771 | bp->spq_prod_bd = bp->spq; |
| 4772 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4773 | } |
| 4774 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4775 | static void bnx2x_init_eq_ring(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4776 | { |
| 4777 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4778 | for (i = 1; i <= NUM_EQ_PAGES; i++) { |
| 4779 | union event_ring_elem *elem = |
| 4780 | &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4781 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4782 | elem->next_page.addr.hi = |
| 4783 | cpu_to_le32(U64_HI(bp->eq_mapping + |
| 4784 | BCM_PAGE_SIZE * (i % NUM_EQ_PAGES))); |
| 4785 | elem->next_page.addr.lo = |
| 4786 | cpu_to_le32(U64_LO(bp->eq_mapping + |
| 4787 | BCM_PAGE_SIZE*(i % NUM_EQ_PAGES))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4788 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4789 | bp->eq_cons = 0; |
| 4790 | bp->eq_prod = NUM_EQ_DESC; |
| 4791 | bp->eq_cons_sb = BNX2X_EQ_INDEX; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4792 | /* we want a warning message before it gets rought... */ |
| 4793 | atomic_set(&bp->eq_spq_left, |
| 4794 | min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4795 | } |
| 4796 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4797 | |
| 4798 | /* called with netif_addr_lock_bh() */ |
| 4799 | void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id, |
| 4800 | unsigned long rx_mode_flags, |
| 4801 | unsigned long rx_accept_flags, |
| 4802 | unsigned long tx_accept_flags, |
| 4803 | unsigned long ramrod_flags) |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4804 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4805 | struct bnx2x_rx_mode_ramrod_params ramrod_param; |
| 4806 | int rc; |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4807 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4808 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4809 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4810 | /* Prepare ramrod parameters */ |
| 4811 | ramrod_param.cid = 0; |
| 4812 | ramrod_param.cl_id = cl_id; |
| 4813 | ramrod_param.rx_mode_obj = &bp->rx_mode_obj; |
| 4814 | ramrod_param.func_id = BP_FUNC(bp); |
| 4815 | |
| 4816 | ramrod_param.pstate = &bp->sp_state; |
| 4817 | ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING; |
| 4818 | |
| 4819 | ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata); |
| 4820 | ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata); |
| 4821 | |
| 4822 | set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); |
| 4823 | |
| 4824 | ramrod_param.ramrod_flags = ramrod_flags; |
| 4825 | ramrod_param.rx_mode_flags = rx_mode_flags; |
| 4826 | |
| 4827 | ramrod_param.rx_accept_flags = rx_accept_flags; |
| 4828 | ramrod_param.tx_accept_flags = tx_accept_flags; |
| 4829 | |
| 4830 | rc = bnx2x_config_rx_mode(bp, &ramrod_param); |
| 4831 | if (rc < 0) { |
| 4832 | BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode); |
| 4833 | return; |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | /* called with netif_addr_lock_bh() */ |
| 4838 | void bnx2x_set_storm_rx_mode(struct bnx2x *bp) |
| 4839 | { |
| 4840 | unsigned long rx_mode_flags = 0, ramrod_flags = 0; |
| 4841 | unsigned long rx_accept_flags = 0, tx_accept_flags = 0; |
| 4842 | |
| 4843 | #ifdef BCM_CNIC |
| 4844 | if (!NO_FCOE(bp)) |
| 4845 | |
| 4846 | /* Configure rx_mode of FCoE Queue */ |
| 4847 | __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags); |
| 4848 | #endif |
| 4849 | |
| 4850 | switch (bp->rx_mode) { |
| 4851 | case BNX2X_RX_MODE_NONE: |
| 4852 | /* |
| 4853 | * 'drop all' supersedes any accept flags that may have been |
| 4854 | * passed to the function. |
| 4855 | */ |
| 4856 | break; |
| 4857 | case BNX2X_RX_MODE_NORMAL: |
| 4858 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4859 | __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags); |
| 4860 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4861 | |
| 4862 | /* internal switching mode */ |
| 4863 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4864 | __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags); |
| 4865 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4866 | |
| 4867 | break; |
| 4868 | case BNX2X_RX_MODE_ALLMULTI: |
| 4869 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4870 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); |
| 4871 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4872 | |
| 4873 | /* internal switching mode */ |
| 4874 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4875 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); |
| 4876 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4877 | |
| 4878 | break; |
| 4879 | case BNX2X_RX_MODE_PROMISC: |
| 4880 | /* According to deffinition of SI mode, iface in promisc mode |
| 4881 | * should receive matched and unmatched (in resolution of port) |
| 4882 | * unicast packets. |
| 4883 | */ |
| 4884 | __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags); |
| 4885 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4886 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); |
| 4887 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4888 | |
| 4889 | /* internal switching mode */ |
| 4890 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); |
| 4891 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4892 | |
| 4893 | if (IS_MF_SI(bp)) |
| 4894 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags); |
| 4895 | else |
| 4896 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4897 | |
| 4898 | break; |
| 4899 | default: |
| 4900 | BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode); |
| 4901 | return; |
| 4902 | } |
| 4903 | |
| 4904 | if (bp->rx_mode != BNX2X_RX_MODE_NONE) { |
| 4905 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags); |
| 4906 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags); |
| 4907 | } |
| 4908 | |
| 4909 | __set_bit(RAMROD_RX, &ramrod_flags); |
| 4910 | __set_bit(RAMROD_TX, &ramrod_flags); |
| 4911 | |
| 4912 | bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags, |
| 4913 | tx_accept_flags, ramrod_flags); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4914 | } |
| 4915 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4916 | static void bnx2x_init_internal_common(struct bnx2x *bp) |
| 4917 | { |
| 4918 | int i; |
| 4919 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 4920 | if (IS_MF_SI(bp)) |
| 4921 | /* |
| 4922 | * In switch independent mode, the TSTORM needs to accept |
| 4923 | * packets that failed classification, since approximate match |
| 4924 | * mac addresses aren't written to NIG LLH |
| 4925 | */ |
| 4926 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 4927 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4928 | else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */ |
| 4929 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 4930 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 4931 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4932 | /* Zero this manually as its initialization is |
| 4933 | currently missing in the initTool */ |
| 4934 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) |
| 4935 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4936 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4937 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4938 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET, |
| 4939 | CHIP_INT_MODE_IS_BC(bp) ? |
| 4940 | HC_IGU_BC_MODE : HC_IGU_NBC_MODE); |
| 4941 | } |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4944 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
| 4945 | { |
| 4946 | switch (load_code) { |
| 4947 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4948 | case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4949 | bnx2x_init_internal_common(bp); |
| 4950 | /* no break */ |
| 4951 | |
| 4952 | case FW_MSG_CODE_DRV_LOAD_PORT: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4953 | /* nothing to do */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4954 | /* no break */ |
| 4955 | |
| 4956 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4957 | /* internal memory per function is |
| 4958 | initialized inside bnx2x_pf_init */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4959 | break; |
| 4960 | |
| 4961 | default: |
| 4962 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 4963 | break; |
| 4964 | } |
| 4965 | } |
| 4966 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4967 | static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp) |
| 4968 | { |
| 4969 | return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE; |
| 4970 | } |
| 4971 | |
| 4972 | static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp) |
| 4973 | { |
| 4974 | return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE; |
| 4975 | } |
| 4976 | |
| 4977 | static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp) |
| 4978 | { |
| 4979 | if (CHIP_IS_E1x(fp->bp)) |
| 4980 | return BP_L_ID(fp->bp) + fp->index; |
| 4981 | else /* We want Client ID to be the same as IGU SB ID for 57712 */ |
| 4982 | return bnx2x_fp_igu_sb_id(fp); |
| 4983 | } |
| 4984 | |
| 4985 | static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4986 | { |
| 4987 | struct bnx2x_fastpath *fp = &bp->fp[fp_idx]; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4988 | unsigned long q_type = 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4989 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 4990 | fp->cid = fp_idx; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4991 | fp->cl_id = bnx2x_fp_cl_id(fp); |
| 4992 | fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp); |
| 4993 | fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4994 | /* qZone id equals to FW (per path) client id */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4995 | fp->cl_qzone_id = bnx2x_fp_qzone_id(fp); |
| 4996 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4997 | /* init shortcut */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4998 | fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4999 | /* Setup SB indicies */ |
| 5000 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
| 5001 | fp->tx_cons_sb = BNX2X_TX_SB_INDEX; |
| 5002 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5003 | /* Configure Queue State object */ |
| 5004 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); |
| 5005 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); |
| 5006 | bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp), |
| 5007 | bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata), |
| 5008 | q_type); |
| 5009 | |
| 5010 | /** |
| 5011 | * Configure classification DBs: Always enable Tx switching |
| 5012 | */ |
| 5013 | bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX); |
| 5014 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5015 | DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) " |
| 5016 | "cl_id %d fw_sb %d igu_sb %d\n", |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5017 | fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5018 | fp->igu_sb_id); |
| 5019 | bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false, |
| 5020 | fp->fw_sb_id, fp->igu_sb_id); |
| 5021 | |
| 5022 | bnx2x_update_fpsb_idx(fp); |
| 5023 | } |
| 5024 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 5025 | void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5026 | { |
| 5027 | int i; |
| 5028 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 5029 | for_each_eth_queue(bp, i) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5030 | bnx2x_init_fp(bp, i); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5031 | #ifdef BCM_CNIC |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 5032 | if (!NO_FCOE(bp)) |
| 5033 | bnx2x_init_fcoe_fp(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5034 | |
| 5035 | bnx2x_init_sb(bp, bp->cnic_sb_mapping, |
| 5036 | BNX2X_VF_ID_INVALID, false, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5037 | bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5038 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5039 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5040 | |
Yaniv Rosner | 020c7e3 | 2011-05-31 21:28:43 +0000 | [diff] [blame] | 5041 | /* Initialize MOD_ABS interrupts */ |
| 5042 | bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id, |
| 5043 | bp->common.shmem_base, bp->common.shmem2_base, |
| 5044 | BP_PORT(bp)); |
Eilon Greenstein | 1611978 | 2009-03-02 07:59:27 +0000 | [diff] [blame] | 5045 | /* ensure status block indices were read */ |
| 5046 | rmb(); |
| 5047 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5048 | bnx2x_init_def_sb(bp); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5049 | bnx2x_update_dsb_idx(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5050 | bnx2x_init_rx_rings(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5051 | bnx2x_init_tx_rings(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5052 | bnx2x_init_sp_ring(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5053 | bnx2x_init_eq_ring(bp); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5054 | bnx2x_init_internal(bp, load_code); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5055 | bnx2x_pf_init(bp); |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5056 | bnx2x_stats_init(bp); |
| 5057 | |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5058 | /* flush all before enabling interrupts */ |
| 5059 | mb(); |
| 5060 | mmiowb(); |
| 5061 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 5062 | bnx2x_int_enable(bp); |
Eilon Greenstein | eb8da20 | 2009-07-21 05:47:30 +0000 | [diff] [blame] | 5063 | |
| 5064 | /* Check for SPIO5 */ |
| 5065 | bnx2x_attn_int_deasserted0(bp, |
| 5066 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & |
| 5067 | AEU_INPUTS_ATTN_BITS_SPIO5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | /* end of nic init */ |
| 5071 | |
| 5072 | /* |
| 5073 | * gzip service functions |
| 5074 | */ |
| 5075 | |
| 5076 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
| 5077 | { |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5078 | bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE, |
| 5079 | &bp->gunzip_mapping, GFP_KERNEL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5080 | if (bp->gunzip_buf == NULL) |
| 5081 | goto gunzip_nomem1; |
| 5082 | |
| 5083 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); |
| 5084 | if (bp->strm == NULL) |
| 5085 | goto gunzip_nomem2; |
| 5086 | |
| 5087 | bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), |
| 5088 | GFP_KERNEL); |
| 5089 | if (bp->strm->workspace == NULL) |
| 5090 | goto gunzip_nomem3; |
| 5091 | |
| 5092 | return 0; |
| 5093 | |
| 5094 | gunzip_nomem3: |
| 5095 | kfree(bp->strm); |
| 5096 | bp->strm = NULL; |
| 5097 | |
| 5098 | gunzip_nomem2: |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5099 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5100 | bp->gunzip_mapping); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5101 | bp->gunzip_buf = NULL; |
| 5102 | |
| 5103 | gunzip_nomem1: |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5104 | netdev_err(bp->dev, "Cannot allocate firmware buffer for" |
| 5105 | " un-compression\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5106 | return -ENOMEM; |
| 5107 | } |
| 5108 | |
| 5109 | static void bnx2x_gunzip_end(struct bnx2x *bp) |
| 5110 | { |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 5111 | if (bp->strm) { |
| 5112 | kfree(bp->strm->workspace); |
| 5113 | kfree(bp->strm); |
| 5114 | bp->strm = NULL; |
| 5115 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5116 | |
| 5117 | if (bp->gunzip_buf) { |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5118 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5119 | bp->gunzip_mapping); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5120 | bp->gunzip_buf = NULL; |
| 5121 | } |
| 5122 | } |
| 5123 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5124 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5125 | { |
| 5126 | int n, rc; |
| 5127 | |
| 5128 | /* check gzip header */ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5129 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
| 5130 | BNX2X_ERR("Bad gzip header\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5131 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5132 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5133 | |
| 5134 | n = 10; |
| 5135 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5136 | #define FNAME 0x8 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5137 | |
| 5138 | if (zbuf[3] & FNAME) |
| 5139 | while ((zbuf[n++] != 0) && (n < len)); |
| 5140 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5141 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5142 | bp->strm->avail_in = len - n; |
| 5143 | bp->strm->next_out = bp->gunzip_buf; |
| 5144 | bp->strm->avail_out = FW_BUF_SIZE; |
| 5145 | |
| 5146 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); |
| 5147 | if (rc != Z_OK) |
| 5148 | return rc; |
| 5149 | |
| 5150 | rc = zlib_inflate(bp->strm, Z_FINISH); |
| 5151 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 5152 | netdev_err(bp->dev, "Firmware decompression error: %s\n", |
| 5153 | bp->strm->msg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5154 | |
| 5155 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); |
| 5156 | if (bp->gunzip_outlen & 0x3) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5157 | netdev_err(bp->dev, "Firmware decompression error:" |
| 5158 | " gunzip_outlen (%d) not aligned\n", |
| 5159 | bp->gunzip_outlen); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5160 | bp->gunzip_outlen >>= 2; |
| 5161 | |
| 5162 | zlib_inflateEnd(bp->strm); |
| 5163 | |
| 5164 | if (rc == Z_STREAM_END) |
| 5165 | return 0; |
| 5166 | |
| 5167 | return rc; |
| 5168 | } |
| 5169 | |
| 5170 | /* nic load/unload */ |
| 5171 | |
| 5172 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5173 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5174 | */ |
| 5175 | |
| 5176 | /* send a NIG loopback debug packet */ |
| 5177 | static void bnx2x_lb_pckt(struct bnx2x *bp) |
| 5178 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5179 | u32 wb_write[3]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5180 | |
| 5181 | /* Ethernet source and destination addresses */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5182 | wb_write[0] = 0x55555555; |
| 5183 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5184 | wb_write[2] = 0x20; /* SOP */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5185 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5186 | |
| 5187 | /* NON-IP protocol */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5188 | wb_write[0] = 0x09000000; |
| 5189 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5190 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5191 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | /* some of the internal memories |
| 5195 | * are not directly readable from the driver |
| 5196 | * to test them we send debug packets |
| 5197 | */ |
| 5198 | static int bnx2x_int_mem_test(struct bnx2x *bp) |
| 5199 | { |
| 5200 | int factor; |
| 5201 | int count, i; |
| 5202 | u32 val = 0; |
| 5203 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5204 | if (CHIP_REV_IS_FPGA(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5205 | factor = 120; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5206 | else if (CHIP_REV_IS_EMUL(bp)) |
| 5207 | factor = 200; |
| 5208 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5209 | factor = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5210 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5211 | /* Disable inputs of parser neighbor blocks */ |
| 5212 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5213 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5214 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5215 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5216 | |
| 5217 | /* Write 0 to parser credits for CFC search request */ |
| 5218 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5219 | |
| 5220 | /* send Ethernet packet */ |
| 5221 | bnx2x_lb_pckt(bp); |
| 5222 | |
| 5223 | /* TODO do i reset NIG statistic? */ |
| 5224 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5225 | count = 1000 * factor; |
| 5226 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5227 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5228 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5229 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5230 | if (val == 0x10) |
| 5231 | break; |
| 5232 | |
| 5233 | msleep(10); |
| 5234 | count--; |
| 5235 | } |
| 5236 | if (val != 0x10) { |
| 5237 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5238 | return -1; |
| 5239 | } |
| 5240 | |
| 5241 | /* Wait until PRS register shows 1 packet */ |
| 5242 | count = 1000 * factor; |
| 5243 | while (count) { |
| 5244 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5245 | if (val == 1) |
| 5246 | break; |
| 5247 | |
| 5248 | msleep(10); |
| 5249 | count--; |
| 5250 | } |
| 5251 | if (val != 0x1) { |
| 5252 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5253 | return -2; |
| 5254 | } |
| 5255 | |
| 5256 | /* Reset and init BRB, PRS */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5257 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5258 | msleep(50); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5259 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5260 | msleep(50); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5261 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
| 5262 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5263 | |
| 5264 | DP(NETIF_MSG_HW, "part2\n"); |
| 5265 | |
| 5266 | /* Disable inputs of parser neighbor blocks */ |
| 5267 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5268 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5269 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5270 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5271 | |
| 5272 | /* Write 0 to parser credits for CFC search request */ |
| 5273 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5274 | |
| 5275 | /* send 10 Ethernet packets */ |
| 5276 | for (i = 0; i < 10; i++) |
| 5277 | bnx2x_lb_pckt(bp); |
| 5278 | |
| 5279 | /* Wait until NIG register shows 10 + 1 |
| 5280 | packets of size 11*0x10 = 0xb0 */ |
| 5281 | count = 1000 * factor; |
| 5282 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5283 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5284 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5285 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5286 | if (val == 0xb0) |
| 5287 | break; |
| 5288 | |
| 5289 | msleep(10); |
| 5290 | count--; |
| 5291 | } |
| 5292 | if (val != 0xb0) { |
| 5293 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5294 | return -3; |
| 5295 | } |
| 5296 | |
| 5297 | /* Wait until PRS register shows 2 packets */ |
| 5298 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5299 | if (val != 2) |
| 5300 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5301 | |
| 5302 | /* Write 1 to parser credits for CFC search request */ |
| 5303 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); |
| 5304 | |
| 5305 | /* Wait until PRS register shows 3 packets */ |
| 5306 | msleep(10 * factor); |
| 5307 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5308 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5309 | if (val != 3) |
| 5310 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5311 | |
| 5312 | /* clear NIG EOP FIFO */ |
| 5313 | for (i = 0; i < 11; i++) |
| 5314 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); |
| 5315 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); |
| 5316 | if (val != 1) { |
| 5317 | BNX2X_ERR("clear of NIG failed\n"); |
| 5318 | return -4; |
| 5319 | } |
| 5320 | |
| 5321 | /* Reset and init BRB, PRS, NIG */ |
| 5322 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
| 5323 | msleep(50); |
| 5324 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
| 5325 | msleep(50); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5326 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
| 5327 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5328 | #ifndef BCM_CNIC |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5329 | /* set NIC mode */ |
| 5330 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 5331 | #endif |
| 5332 | |
| 5333 | /* Enable inputs of parser neighbor blocks */ |
| 5334 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); |
| 5335 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); |
| 5336 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5337 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5338 | |
| 5339 | DP(NETIF_MSG_HW, "done\n"); |
| 5340 | |
| 5341 | return 0; /* OK */ |
| 5342 | } |
| 5343 | |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5344 | static void bnx2x_enable_blocks_attention(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5345 | { |
| 5346 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5347 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5348 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40); |
| 5349 | else |
| 5350 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5351 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5352 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5353 | /* |
| 5354 | * mask read length error interrupts in brb for parser |
| 5355 | * (parsing unit and 'checksum and crc' unit) |
| 5356 | * these errors are legal (PU reads fixed length and CAC can cause |
| 5357 | * read length error on truncated packets) |
| 5358 | */ |
| 5359 | REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5360 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
| 5361 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); |
| 5362 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); |
| 5363 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); |
| 5364 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5365 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
| 5366 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5367 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
| 5368 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); |
| 5369 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5370 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
| 5371 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5372 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
| 5373 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); |
| 5374 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); |
| 5375 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5376 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
| 5377 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5378 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5379 | if (CHIP_REV_IS_FPGA(bp)) |
| 5380 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5381 | else if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5382 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, |
| 5383 | (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
| 5384 | | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
| 5385 | | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN |
| 5386 | | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
| 5387 | | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5388 | else |
| 5389 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5390 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
| 5391 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); |
| 5392 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5393 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5394 | |
| 5395 | if (!CHIP_IS_E1x(bp)) |
| 5396 | /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ |
| 5397 | REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); |
| 5398 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5399 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
| 5400 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5401 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5402 | REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5403 | } |
| 5404 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5405 | static void bnx2x_reset_common(struct bnx2x *bp) |
| 5406 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5407 | u32 val = 0x1400; |
| 5408 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5409 | /* reset_common */ |
| 5410 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5411 | 0xd3ffff7f); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5412 | |
| 5413 | if (CHIP_IS_E3(bp)) { |
| 5414 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 5415 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 5416 | } |
| 5417 | |
| 5418 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val); |
| 5419 | } |
| 5420 | |
| 5421 | static void bnx2x_setup_dmae(struct bnx2x *bp) |
| 5422 | { |
| 5423 | bp->dmae_ready = 0; |
| 5424 | spin_lock_init(&bp->dmae_lock); |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 5427 | static void bnx2x_init_pxp(struct bnx2x *bp) |
| 5428 | { |
| 5429 | u16 devctl; |
| 5430 | int r_order, w_order; |
| 5431 | |
| 5432 | pci_read_config_word(bp->pdev, |
| 5433 | bp->pcie_cap + PCI_EXP_DEVCTL, &devctl); |
| 5434 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
| 5435 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); |
| 5436 | if (bp->mrrs == -1) |
| 5437 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); |
| 5438 | else { |
| 5439 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); |
| 5440 | r_order = bp->mrrs; |
| 5441 | } |
| 5442 | |
| 5443 | bnx2x_init_pxp_arb(bp, r_order, w_order); |
| 5444 | } |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5445 | |
| 5446 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) |
| 5447 | { |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5448 | int is_required; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5449 | u32 val; |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5450 | int port; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5451 | |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5452 | if (BP_NOMCP(bp)) |
| 5453 | return; |
| 5454 | |
| 5455 | is_required = 0; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5456 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
| 5457 | SHARED_HW_CFG_FAN_FAILURE_MASK; |
| 5458 | |
| 5459 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) |
| 5460 | is_required = 1; |
| 5461 | |
| 5462 | /* |
| 5463 | * The fan failure mechanism is usually related to the PHY type since |
| 5464 | * the power consumption of the board is affected by the PHY. Currently, |
| 5465 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. |
| 5466 | */ |
| 5467 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) |
| 5468 | for (port = PORT_0; port < PORT_MAX; port++) { |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5469 | is_required |= |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 5470 | bnx2x_fan_failure_det_req( |
| 5471 | bp, |
| 5472 | bp->common.shmem_base, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 5473 | bp->common.shmem2_base, |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 5474 | port); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); |
| 5478 | |
| 5479 | if (is_required == 0) |
| 5480 | return; |
| 5481 | |
| 5482 | /* Fan failure is indicated by SPIO 5 */ |
| 5483 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, |
| 5484 | MISC_REGISTERS_SPIO_INPUT_HI_Z); |
| 5485 | |
| 5486 | /* set to active low mode */ |
| 5487 | val = REG_RD(bp, MISC_REG_SPIO_INT); |
| 5488 | val |= ((1 << MISC_REGISTERS_SPIO_5) << |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5489 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5490 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
| 5491 | |
| 5492 | /* enable interrupt to signal the IGU */ |
| 5493 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 5494 | val |= (1 << MISC_REGISTERS_SPIO_5); |
| 5495 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
| 5496 | } |
| 5497 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5498 | static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num) |
| 5499 | { |
| 5500 | u32 offset = 0; |
| 5501 | |
| 5502 | if (CHIP_IS_E1(bp)) |
| 5503 | return; |
| 5504 | if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX)) |
| 5505 | return; |
| 5506 | |
| 5507 | switch (BP_ABS_FUNC(bp)) { |
| 5508 | case 0: |
| 5509 | offset = PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 5510 | break; |
| 5511 | case 1: |
| 5512 | offset = PXP2_REG_PGL_PRETEND_FUNC_F1; |
| 5513 | break; |
| 5514 | case 2: |
| 5515 | offset = PXP2_REG_PGL_PRETEND_FUNC_F2; |
| 5516 | break; |
| 5517 | case 3: |
| 5518 | offset = PXP2_REG_PGL_PRETEND_FUNC_F3; |
| 5519 | break; |
| 5520 | case 4: |
| 5521 | offset = PXP2_REG_PGL_PRETEND_FUNC_F4; |
| 5522 | break; |
| 5523 | case 5: |
| 5524 | offset = PXP2_REG_PGL_PRETEND_FUNC_F5; |
| 5525 | break; |
| 5526 | case 6: |
| 5527 | offset = PXP2_REG_PGL_PRETEND_FUNC_F6; |
| 5528 | break; |
| 5529 | case 7: |
| 5530 | offset = PXP2_REG_PGL_PRETEND_FUNC_F7; |
| 5531 | break; |
| 5532 | default: |
| 5533 | return; |
| 5534 | } |
| 5535 | |
| 5536 | REG_WR(bp, offset, pretend_func_num); |
| 5537 | REG_RD(bp, offset); |
| 5538 | DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num); |
| 5539 | } |
| 5540 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 5541 | void bnx2x_pf_disable(struct bnx2x *bp) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5542 | { |
| 5543 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); |
| 5544 | val &= ~IGU_PF_CONF_FUNC_EN; |
| 5545 | |
| 5546 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); |
| 5547 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); |
| 5548 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0); |
| 5549 | } |
| 5550 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5551 | static inline void bnx2x__common_init_phy(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5552 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5553 | u32 shmem_base[2], shmem2_base[2]; |
| 5554 | shmem_base[0] = bp->common.shmem_base; |
| 5555 | shmem2_base[0] = bp->common.shmem2_base; |
| 5556 | if (!CHIP_IS_E1x(bp)) { |
| 5557 | shmem_base[1] = |
| 5558 | SHMEM2_RD(bp, other_shmem_base_addr); |
| 5559 | shmem2_base[1] = |
| 5560 | SHMEM2_RD(bp, other_shmem2_base_addr); |
| 5561 | } |
| 5562 | bnx2x_acquire_phy_lock(bp); |
| 5563 | bnx2x_common_init_phy(bp, shmem_base, shmem2_base, |
| 5564 | bp->common.chip_id); |
| 5565 | bnx2x_release_phy_lock(bp); |
| 5566 | } |
| 5567 | |
| 5568 | /** |
| 5569 | * bnx2x_init_hw_common - initialize the HW at the COMMON phase. |
| 5570 | * |
| 5571 | * @bp: driver handle |
| 5572 | */ |
| 5573 | static int bnx2x_init_hw_common(struct bnx2x *bp) |
| 5574 | { |
| 5575 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5576 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5577 | DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5578 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5579 | bnx2x_reset_common(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5580 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5581 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5582 | val = 0xfffc; |
| 5583 | if (CHIP_IS_E3(bp)) { |
| 5584 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 5585 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 5586 | } |
| 5587 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5588 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5589 | bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON); |
| 5590 | |
| 5591 | if (!CHIP_IS_E1x(bp)) { |
| 5592 | u8 abs_func_id; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5593 | |
| 5594 | /** |
| 5595 | * 4-port mode or 2-port mode we need to turn of master-enable |
| 5596 | * for everyone, after that, turn it back on for self. |
| 5597 | * so, we disregard multi-function or not, and always disable |
| 5598 | * for all functions on the given path, this means 0,2,4,6 for |
| 5599 | * path 0 and 1,3,5,7 for path 1 |
| 5600 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5601 | for (abs_func_id = BP_PATH(bp); |
| 5602 | abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) { |
| 5603 | if (abs_func_id == BP_ABS_FUNC(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5604 | REG_WR(bp, |
| 5605 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, |
| 5606 | 1); |
| 5607 | continue; |
| 5608 | } |
| 5609 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5610 | bnx2x_pretend_func(bp, abs_func_id); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5611 | /* clear pf enable */ |
| 5612 | bnx2x_pf_disable(bp); |
| 5613 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); |
| 5614 | } |
| 5615 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5616 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5617 | bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5618 | if (CHIP_IS_E1(bp)) { |
| 5619 | /* enable HW interrupt from PXP on USDM overflow |
| 5620 | bit 16 on INT_MASK_0 */ |
| 5621 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5622 | } |
| 5623 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5624 | bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5625 | bnx2x_init_pxp(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5626 | |
| 5627 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5628 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
| 5629 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); |
| 5630 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); |
| 5631 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); |
| 5632 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5633 | /* make sure this value is 0 */ |
| 5634 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5635 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5636 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ |
| 5637 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); |
| 5638 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); |
| 5639 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); |
| 5640 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5641 | #endif |
| 5642 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5643 | bnx2x_ilt_init_page_size(bp, INITOP_SET); |
| 5644 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5645 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
| 5646 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5647 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5648 | /* let the HW do it's magic ... */ |
| 5649 | msleep(100); |
| 5650 | /* finish PXP init */ |
| 5651 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); |
| 5652 | if (val != 1) { |
| 5653 | BNX2X_ERR("PXP2 CFG failed\n"); |
| 5654 | return -EBUSY; |
| 5655 | } |
| 5656 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); |
| 5657 | if (val != 1) { |
| 5658 | BNX2X_ERR("PXP2 RD_INIT failed\n"); |
| 5659 | return -EBUSY; |
| 5660 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5661 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5662 | /* Timers bug workaround E2 only. We need to set the entire ILT to |
| 5663 | * have entries with value "0" and valid bit on. |
| 5664 | * This needs to be done by the first PF that is loaded in a path |
| 5665 | * (i.e. common phase) |
| 5666 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5667 | if (!CHIP_IS_E1x(bp)) { |
| 5668 | /* In E2 there is a bug in the timers block that can cause function 6 / 7 |
| 5669 | * (i.e. vnic3) to start even if it is marked as "scan-off". |
| 5670 | * This occurs when a different function (func2,3) is being marked |
| 5671 | * as "scan-off". Real-life scenario for example: if a driver is being |
| 5672 | * load-unloaded while func6,7 are down. This will cause the timer to access |
| 5673 | * the ilt, translate to a logical address and send a request to read/write. |
| 5674 | * Since the ilt for the function that is down is not valid, this will cause |
| 5675 | * a translation error which is unrecoverable. |
| 5676 | * The Workaround is intended to make sure that when this happens nothing fatal |
| 5677 | * will occur. The workaround: |
| 5678 | * 1. First PF driver which loads on a path will: |
| 5679 | * a. After taking the chip out of reset, by using pretend, |
| 5680 | * it will write "0" to the following registers of |
| 5681 | * the other vnics. |
| 5682 | * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); |
| 5683 | * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); |
| 5684 | * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); |
| 5685 | * And for itself it will write '1' to |
| 5686 | * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable |
| 5687 | * dmae-operations (writing to pram for example.) |
| 5688 | * note: can be done for only function 6,7 but cleaner this |
| 5689 | * way. |
| 5690 | * b. Write zero+valid to the entire ILT. |
| 5691 | * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of |
| 5692 | * VNIC3 (of that port). The range allocated will be the |
| 5693 | * entire ILT. This is needed to prevent ILT range error. |
| 5694 | * 2. Any PF driver load flow: |
| 5695 | * a. ILT update with the physical addresses of the allocated |
| 5696 | * logical pages. |
| 5697 | * b. Wait 20msec. - note that this timeout is needed to make |
| 5698 | * sure there are no requests in one of the PXP internal |
| 5699 | * queues with "old" ILT addresses. |
| 5700 | * c. PF enable in the PGLC. |
| 5701 | * d. Clear the was_error of the PF in the PGLC. (could have |
| 5702 | * occured while driver was down) |
| 5703 | * e. PF enable in the CFC (WEAK + STRONG) |
| 5704 | * f. Timers scan enable |
| 5705 | * 3. PF driver unload flow: |
| 5706 | * a. Clear the Timers scan_en. |
| 5707 | * b. Polling for scan_on=0 for that PF. |
| 5708 | * c. Clear the PF enable bit in the PXP. |
| 5709 | * d. Clear the PF enable in the CFC (WEAK + STRONG) |
| 5710 | * e. Write zero+valid to all ILT entries (The valid bit must |
| 5711 | * stay set) |
| 5712 | * f. If this is VNIC 3 of a port then also init |
| 5713 | * first_timers_ilt_entry to zero and last_timers_ilt_entry |
| 5714 | * to the last enrty in the ILT. |
| 5715 | * |
| 5716 | * Notes: |
| 5717 | * Currently the PF error in the PGLC is non recoverable. |
| 5718 | * In the future the there will be a recovery routine for this error. |
| 5719 | * Currently attention is masked. |
| 5720 | * Having an MCP lock on the load/unload process does not guarantee that |
| 5721 | * there is no Timer disable during Func6/7 enable. This is because the |
| 5722 | * Timers scan is currently being cleared by the MCP on FLR. |
| 5723 | * Step 2.d can be done only for PF6/7 and the driver can also check if |
| 5724 | * there is error before clearing it. But the flow above is simpler and |
| 5725 | * more general. |
| 5726 | * All ILT entries are written by zero+valid and not just PF6/7 |
| 5727 | * ILT entries since in the future the ILT entries allocation for |
| 5728 | * PF-s might be dynamic. |
| 5729 | */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5730 | struct ilt_client_info ilt_cli; |
| 5731 | struct bnx2x_ilt ilt; |
| 5732 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); |
| 5733 | memset(&ilt, 0, sizeof(struct bnx2x_ilt)); |
| 5734 | |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 5735 | /* initialize dummy TM client */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5736 | ilt_cli.start = 0; |
| 5737 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; |
| 5738 | ilt_cli.client_num = ILT_CLIENT_TM; |
| 5739 | |
| 5740 | /* Step 1: set zeroes to all ilt page entries with valid bit on |
| 5741 | * Step 2: set the timers first/last ilt entry to point |
| 5742 | * to the entire range to prevent ILT range error for 3rd/4th |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5743 | * vnic (this code assumes existance of the vnic) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5744 | * |
| 5745 | * both steps performed by call to bnx2x_ilt_client_init_op() |
| 5746 | * with dummy TM client |
| 5747 | * |
| 5748 | * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT |
| 5749 | * and his brother are split registers |
| 5750 | */ |
| 5751 | bnx2x_pretend_func(bp, (BP_PATH(bp) + 6)); |
| 5752 | bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR); |
| 5753 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); |
| 5754 | |
| 5755 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN); |
| 5756 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN); |
| 5757 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); |
| 5758 | } |
| 5759 | |
| 5760 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5761 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
| 5762 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5763 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5764 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5765 | int factor = CHIP_REV_IS_EMUL(bp) ? 1000 : |
| 5766 | (CHIP_REV_IS_FPGA(bp) ? 400 : 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5767 | bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5768 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5769 | bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5770 | |
| 5771 | /* let the HW do it's magic ... */ |
| 5772 | do { |
| 5773 | msleep(200); |
| 5774 | val = REG_RD(bp, ATC_REG_ATC_INIT_DONE); |
| 5775 | } while (factor-- && (val != 1)); |
| 5776 | |
| 5777 | if (val != 1) { |
| 5778 | BNX2X_ERR("ATC_INIT failed\n"); |
| 5779 | return -EBUSY; |
| 5780 | } |
| 5781 | } |
| 5782 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5783 | bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5784 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5785 | /* clean the DMAE memory */ |
| 5786 | bp->dmae_ready = 1; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5787 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5788 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5789 | bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON); |
| 5790 | |
| 5791 | bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON); |
| 5792 | |
| 5793 | bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON); |
| 5794 | |
| 5795 | bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5796 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5797 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
| 5798 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); |
| 5799 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); |
| 5800 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); |
| 5801 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5802 | bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5803 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5804 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5805 | /* QM queues pointers table */ |
| 5806 | bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5807 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5808 | /* soft reset pulse */ |
| 5809 | REG_WR(bp, QM_REG_SOFT_RESET, 1); |
| 5810 | REG_WR(bp, QM_REG_SOFT_RESET, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5811 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5812 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5813 | bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5814 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5815 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5816 | bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5817 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5818 | if (!CHIP_REV_IS_SLOW(bp)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5819 | /* enable hw interrupt from doorbell Q */ |
| 5820 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5821 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5822 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5823 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5824 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5825 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5826 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5827 | if (!CHIP_IS_E1(bp)) |
| 5828 | REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan); |
| 5829 | |
| 5830 | if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) |
| 5831 | /* Bit-map indicating which L2 hdrs may appear |
| 5832 | * after the basic Ethernet header |
| 5833 | */ |
| 5834 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, |
| 5835 | bp->path_has_ovlan ? 7 : 6); |
| 5836 | |
| 5837 | bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON); |
| 5838 | bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON); |
| 5839 | bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON); |
| 5840 | bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON); |
| 5841 | |
| 5842 | if (!CHIP_IS_E1x(bp)) { |
| 5843 | /* reset VFC memories */ |
| 5844 | REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, |
| 5845 | VFC_MEMORIES_RST_REG_CAM_RST | |
| 5846 | VFC_MEMORIES_RST_REG_RAM_RST); |
| 5847 | REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, |
| 5848 | VFC_MEMORIES_RST_REG_CAM_RST | |
| 5849 | VFC_MEMORIES_RST_REG_RAM_RST); |
| 5850 | |
| 5851 | msleep(20); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5852 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5853 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5854 | bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON); |
| 5855 | bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON); |
| 5856 | bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON); |
| 5857 | bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5858 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5859 | /* sync semi rtc */ |
| 5860 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5861 | 0x80000000); |
| 5862 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 5863 | 0x80000000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5864 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5865 | bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON); |
| 5866 | bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON); |
| 5867 | bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5868 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5869 | if (!CHIP_IS_E1x(bp)) |
| 5870 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, |
| 5871 | bp->path_has_ovlan ? 7 : 6); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5872 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5873 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5874 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5875 | bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON); |
| 5876 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5877 | #ifdef BCM_CNIC |
| 5878 | REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672); |
| 5879 | REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); |
| 5880 | REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b); |
| 5881 | REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a); |
| 5882 | REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116); |
| 5883 | REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b); |
| 5884 | REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf); |
| 5885 | REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); |
| 5886 | REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f); |
| 5887 | REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7); |
| 5888 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5889 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5890 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5891 | if (sizeof(union cdu_context) != 1024) |
| 5892 | /* we currently assume that a context is 1024 bytes */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5893 | dev_alert(&bp->pdev->dev, "please adjust the size " |
| 5894 | "of cdu_context(%ld)\n", |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 5895 | (long)sizeof(union cdu_context)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5896 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5897 | bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5898 | val = (4 << 24) + (0 << 12) + 1024; |
| 5899 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5900 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5901 | bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5902 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5903 | /* enable context validation interrupt from CFC */ |
| 5904 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5905 | |
| 5906 | /* set the thresholds to prevent CFC/CDU race */ |
| 5907 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5908 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5909 | bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5910 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5911 | if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5912 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36); |
| 5913 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5914 | bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON); |
| 5915 | bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5916 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5917 | /* Reset PCIE errors for debug */ |
| 5918 | REG_WR(bp, 0x2814, 0xffffffff); |
| 5919 | REG_WR(bp, 0x3820, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5920 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5921 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5922 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, |
| 5923 | (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | |
| 5924 | PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); |
| 5925 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, |
| 5926 | (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | |
| 5927 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | |
| 5928 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); |
| 5929 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, |
| 5930 | (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | |
| 5931 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | |
| 5932 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); |
| 5933 | } |
| 5934 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5935 | bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5936 | if (!CHIP_IS_E1(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5937 | /* in E3 this done in per-port section */ |
| 5938 | if (!CHIP_IS_E3(bp)) |
| 5939 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp)); |
| 5940 | } |
| 5941 | if (CHIP_IS_E1H(bp)) |
| 5942 | /* not applicable for E2 (and above ...) */ |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 5943 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5944 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5945 | if (CHIP_REV_IS_SLOW(bp)) |
| 5946 | msleep(200); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5947 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5948 | /* finish CFC init */ |
| 5949 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); |
| 5950 | if (val != 1) { |
| 5951 | BNX2X_ERR("CFC LL_INIT failed\n"); |
| 5952 | return -EBUSY; |
| 5953 | } |
| 5954 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); |
| 5955 | if (val != 1) { |
| 5956 | BNX2X_ERR("CFC AC_INIT failed\n"); |
| 5957 | return -EBUSY; |
| 5958 | } |
| 5959 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); |
| 5960 | if (val != 1) { |
| 5961 | BNX2X_ERR("CFC CAM_INIT failed\n"); |
| 5962 | return -EBUSY; |
| 5963 | } |
| 5964 | REG_WR(bp, CFC_REG_DEBUG0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5965 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5966 | if (CHIP_IS_E1(bp)) { |
| 5967 | /* read NIG statistic |
| 5968 | to see if this is our first up since powerup */ |
| 5969 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5970 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5971 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5972 | /* do internal memory self test */ |
| 5973 | if ((val == 0) && bnx2x_int_mem_test(bp)) { |
| 5974 | BNX2X_ERR("internal mem self test failed\n"); |
| 5975 | return -EBUSY; |
| 5976 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5977 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5978 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5979 | bnx2x_setup_fan_failure_detection(bp); |
| 5980 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5981 | /* clear PXP2 attentions */ |
| 5982 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5983 | |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5984 | bnx2x_enable_blocks_attention(bp); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 5985 | bnx2x_enable_blocks_parity(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5986 | |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5987 | if (!BP_NOMCP(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5988 | if (CHIP_IS_E1x(bp)) |
| 5989 | bnx2x__common_init_phy(bp); |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5990 | } else |
| 5991 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
| 5992 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5993 | return 0; |
| 5994 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5995 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5996 | /** |
| 5997 | * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase. |
| 5998 | * |
| 5999 | * @bp: driver handle |
| 6000 | */ |
| 6001 | static int bnx2x_init_hw_common_chip(struct bnx2x *bp) |
| 6002 | { |
| 6003 | int rc = bnx2x_init_hw_common(bp); |
| 6004 | |
| 6005 | if (rc) |
| 6006 | return rc; |
| 6007 | |
| 6008 | /* In E2 2-PORT mode, same ext phy is used for the two paths */ |
| 6009 | if (!BP_NOMCP(bp)) |
| 6010 | bnx2x__common_init_phy(bp); |
| 6011 | |
| 6012 | return 0; |
| 6013 | } |
| 6014 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6015 | static int bnx2x_init_hw_port(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6016 | { |
| 6017 | int port = BP_PORT(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6018 | int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6019 | u32 low, high; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6020 | u32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6021 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6022 | bnx2x__link_reset(bp); |
| 6023 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6024 | DP(BNX2X_MSG_MCP, "starting port init port %d\n", port); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6025 | |
| 6026 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6027 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6028 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
| 6029 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
| 6030 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6031 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6032 | /* Timers bug workaround: disables the pf_master bit in pglue at |
| 6033 | * common phase, we need to enable it here before any dmae access are |
| 6034 | * attempted. Therefore we manually added the enable-master to the |
| 6035 | * port phase (it also happens in the function phase) |
| 6036 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6037 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6038 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
| 6039 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6040 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
| 6041 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); |
| 6042 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
| 6043 | bnx2x_init_block(bp, BLOCK_QM, init_phase); |
| 6044 | |
| 6045 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); |
| 6046 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); |
| 6047 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); |
| 6048 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6049 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6050 | /* QM cid (connection) count */ |
| 6051 | bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6052 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6053 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6054 | bnx2x_init_block(bp, BLOCK_TM, init_phase); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6055 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20); |
| 6056 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6057 | #endif |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6058 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6059 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6060 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6061 | if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6062 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
| 6063 | |
| 6064 | if (IS_MF(bp)) |
| 6065 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); |
| 6066 | else if (bp->dev->mtu > 4096) { |
| 6067 | if (bp->flags & ONE_PORT_FLAG) |
| 6068 | low = 160; |
| 6069 | else { |
| 6070 | val = bp->dev->mtu; |
| 6071 | /* (24*1024 + val*4)/256 */ |
| 6072 | low = 96 + (val/64) + |
| 6073 | ((val % 64) ? 1 : 0); |
| 6074 | } |
| 6075 | } else |
| 6076 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); |
| 6077 | high = low + 56; /* 14*1024/256 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6078 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
| 6079 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); |
| 6080 | } |
| 6081 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6082 | if (CHIP_MODE_IS_4_PORT(bp)) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6083 | REG_WR(bp, (BP_PORT(bp) ? |
| 6084 | BRB1_REG_MAC_GUARANTIED_1 : |
| 6085 | BRB1_REG_MAC_GUARANTIED_0), 40); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6086 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6087 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6088 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
| 6089 | if (CHIP_IS_E3B0(bp)) |
| 6090 | /* Ovlan exists only if we are in multi-function + |
| 6091 | * switch-dependent mode, in switch-independent there |
| 6092 | * is no ovlan headers |
| 6093 | */ |
| 6094 | REG_WR(bp, BP_PORT(bp) ? |
| 6095 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : |
| 6096 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, |
| 6097 | (bp->path_has_ovlan ? 7 : 6)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6098 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6099 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
| 6100 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); |
| 6101 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); |
| 6102 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); |
| 6103 | |
| 6104 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
| 6105 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); |
| 6106 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); |
| 6107 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); |
| 6108 | |
| 6109 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
| 6110 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); |
| 6111 | |
| 6112 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
| 6113 | |
| 6114 | if (CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6115 | /* configure PBF to work without PAUSE mtu 9000 */ |
| 6116 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6117 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6118 | /* update threshold */ |
| 6119 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); |
| 6120 | /* update init credit */ |
| 6121 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6122 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6123 | /* probe changes */ |
| 6124 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); |
| 6125 | udelay(50); |
| 6126 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); |
| 6127 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6128 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6129 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6130 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6131 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6132 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
| 6133 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6134 | |
| 6135 | if (CHIP_IS_E1(bp)) { |
| 6136 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6137 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6138 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6139 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6140 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6141 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6142 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6143 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6144 | /* init aeu_mask_attn_func_0/1: |
| 6145 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use |
| 6146 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF |
| 6147 | * bits 4-7 are used for "per vn group attention" */ |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 6148 | val = IS_MF(bp) ? 0xF7 : 0x7; |
| 6149 | /* Enable DCBX attention for all but E1 */ |
| 6150 | val |= CHIP_IS_E1(bp) ? 0 : 0x10; |
| 6151 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6152 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6153 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6154 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6155 | if (!CHIP_IS_E1x(bp)) { |
| 6156 | /* Bit-map indicating which L2 hdrs may appear after the |
| 6157 | * basic Ethernet header |
| 6158 | */ |
| 6159 | REG_WR(bp, BP_PORT(bp) ? |
| 6160 | NIG_REG_P1_HDRS_AFTER_BASIC : |
| 6161 | NIG_REG_P0_HDRS_AFTER_BASIC, |
| 6162 | IS_MF_SD(bp) ? 7 : 6); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6163 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6164 | if (CHIP_IS_E3(bp)) |
| 6165 | REG_WR(bp, BP_PORT(bp) ? |
| 6166 | NIG_REG_LLH1_MF_MODE : |
| 6167 | NIG_REG_LLH_MF_MODE, IS_MF(bp)); |
| 6168 | } |
| 6169 | if (!CHIP_IS_E3(bp)) |
| 6170 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6171 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6172 | if (!CHIP_IS_E1(bp)) { |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6173 | /* 0x2 disable mf_ov, 0x1 enable */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6174 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6175 | (IS_MF_SD(bp) ? 0x1 : 0x2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6176 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6177 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6178 | val = 0; |
| 6179 | switch (bp->mf_mode) { |
| 6180 | case MULTI_FUNCTION_SD: |
| 6181 | val = 1; |
| 6182 | break; |
| 6183 | case MULTI_FUNCTION_SI: |
| 6184 | val = 2; |
| 6185 | break; |
| 6186 | } |
| 6187 | |
| 6188 | REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE : |
| 6189 | NIG_REG_LLH0_CLS_TYPE), val); |
| 6190 | } |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6191 | { |
| 6192 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); |
| 6193 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); |
| 6194 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); |
| 6195 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6196 | } |
| 6197 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6198 | |
| 6199 | /* If SPIO5 is set to generate interrupts, enable it for this port */ |
| 6200 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 6201 | if (val & (1 << MISC_REGISTERS_SPIO_5)) { |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6202 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 6203 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 6204 | val = REG_RD(bp, reg_addr); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6205 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6206 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6207 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6208 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6209 | return 0; |
| 6210 | } |
| 6211 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6212 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
| 6213 | { |
| 6214 | int reg; |
| 6215 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6216 | if (CHIP_IS_E1(bp)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6217 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6218 | else |
| 6219 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6220 | |
| 6221 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); |
| 6222 | } |
| 6223 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6224 | static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id) |
| 6225 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6226 | bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func) |
| 6230 | { |
| 6231 | u32 i, base = FUNC_ILT_BASE(func); |
| 6232 | for (i = base; i < base + ILT_PER_FUNC; i++) |
| 6233 | bnx2x_ilt_wr(bp, i, 0); |
| 6234 | } |
| 6235 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6236 | static int bnx2x_init_hw_func(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6237 | { |
| 6238 | int port = BP_PORT(bp); |
| 6239 | int func = BP_FUNC(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6240 | int init_phase = PHASE_PF0 + func; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6241 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
| 6242 | u16 cdu_ilt_start; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6243 | u32 addr, val; |
Vladislav Zolotarov | f4a6689 | 2010-10-19 05:13:09 +0000 | [diff] [blame] | 6244 | u32 main_mem_base, main_mem_size, main_mem_prty_clr; |
| 6245 | int i, main_mem_width; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6246 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6247 | DP(BNX2X_MSG_MCP, "starting func init func %d\n", func); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6248 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6249 | /* FLR cleanup - hmmm */ |
| 6250 | if (!CHIP_IS_E1x(bp)) |
| 6251 | bnx2x_pf_flr_clnup(bp); |
| 6252 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6253 | /* set MSI reconfigure capability */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6254 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 6255 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); |
| 6256 | val = REG_RD(bp, addr); |
| 6257 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; |
| 6258 | REG_WR(bp, addr, val); |
| 6259 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6260 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6261 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
| 6262 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); |
| 6263 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6264 | ilt = BP_ILT(bp); |
| 6265 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6266 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6267 | for (i = 0; i < L2_ILT_LINES(bp); i++) { |
| 6268 | ilt->lines[cdu_ilt_start + i].page = |
| 6269 | bp->context.vcxt + (ILT_PAGE_CIDS * i); |
| 6270 | ilt->lines[cdu_ilt_start + i].page_mapping = |
| 6271 | bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i); |
| 6272 | /* cdu ilt pages are allocated manually so there's no need to |
| 6273 | set the size */ |
| 6274 | } |
| 6275 | bnx2x_ilt_init_op(bp, INITOP_SET); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6276 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6277 | #ifdef BCM_CNIC |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6278 | bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6279 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6280 | /* T1 hash bits value determines the T1 number of entries */ |
| 6281 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6282 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6283 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6284 | #ifndef BCM_CNIC |
| 6285 | /* set NIC mode */ |
| 6286 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 6287 | #endif /* BCM_CNIC */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6288 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6289 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6290 | u32 pf_conf = IGU_PF_CONF_FUNC_EN; |
| 6291 | |
| 6292 | /* Turn on a single ISR mode in IGU if driver is going to use |
| 6293 | * INT#x or MSI |
| 6294 | */ |
| 6295 | if (!(bp->flags & USING_MSIX_FLAG)) |
| 6296 | pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; |
| 6297 | /* |
| 6298 | * Timers workaround bug: function init part. |
| 6299 | * Need to wait 20msec after initializing ILT, |
| 6300 | * needed to make sure there are no requests in |
| 6301 | * one of the PXP internal queues with "old" ILT addresses |
| 6302 | */ |
| 6303 | msleep(20); |
| 6304 | /* |
| 6305 | * Master enable - Due to WB DMAE writes performed before this |
| 6306 | * register is re-initialized as part of the regular function |
| 6307 | * init |
| 6308 | */ |
| 6309 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
| 6310 | /* Enable the function in IGU */ |
| 6311 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf); |
| 6312 | } |
| 6313 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6314 | bp->dmae_ready = 1; |
| 6315 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6316 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6317 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6318 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6319 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); |
| 6320 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6321 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
| 6322 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); |
| 6323 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
| 6324 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); |
| 6325 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
| 6326 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); |
| 6327 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); |
| 6328 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); |
| 6329 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); |
| 6330 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
| 6331 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); |
| 6332 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); |
| 6333 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6334 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6335 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6336 | REG_WR(bp, QM_REG_PF_EN, 1); |
| 6337 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6338 | if (!CHIP_IS_E1x(bp)) { |
| 6339 | REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6340 | REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6341 | REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6342 | REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6343 | } |
| 6344 | bnx2x_init_block(bp, BLOCK_QM, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6345 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6346 | bnx2x_init_block(bp, BLOCK_TM, init_phase); |
| 6347 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
| 6348 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
| 6349 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
| 6350 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
| 6351 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); |
| 6352 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); |
| 6353 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); |
| 6354 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
| 6355 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); |
| 6356 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
| 6357 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6358 | REG_WR(bp, PBF_REG_DISABLE_PF, 0); |
| 6359 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6360 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6361 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6362 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6363 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6364 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6365 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1); |
| 6366 | |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6367 | if (IS_MF(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6368 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6369 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6372 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6373 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6374 | /* HC init per function */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6375 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 6376 | if (CHIP_IS_E1H(bp)) { |
| 6377 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6378 | |
| 6379 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6380 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6381 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6382 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6383 | |
| 6384 | } else { |
| 6385 | int num_segs, sb_idx, prod_offset; |
| 6386 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6387 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6388 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6389 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6390 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
| 6391 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); |
| 6392 | } |
| 6393 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6394 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6395 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6396 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6397 | int dsb_idx = 0; |
| 6398 | /** |
| 6399 | * Producer memory: |
| 6400 | * E2 mode: address 0-135 match to the mapping memory; |
| 6401 | * 136 - PF0 default prod; 137 - PF1 default prod; |
| 6402 | * 138 - PF2 default prod; 139 - PF3 default prod; |
| 6403 | * 140 - PF0 attn prod; 141 - PF1 attn prod; |
| 6404 | * 142 - PF2 attn prod; 143 - PF3 attn prod; |
| 6405 | * 144-147 reserved. |
| 6406 | * |
| 6407 | * E1.5 mode - In backward compatible mode; |
| 6408 | * for non default SB; each even line in the memory |
| 6409 | * holds the U producer and each odd line hold |
| 6410 | * the C producer. The first 128 producers are for |
| 6411 | * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 |
| 6412 | * producers are for the DSB for each PF. |
| 6413 | * Each PF has five segments: (the order inside each |
| 6414 | * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; |
| 6415 | * 132-135 C prods; 136-139 X prods; 140-143 T prods; |
| 6416 | * 144-147 attn prods; |
| 6417 | */ |
| 6418 | /* non-default-status-blocks */ |
| 6419 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? |
| 6420 | IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; |
| 6421 | for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) { |
| 6422 | prod_offset = (bp->igu_base_sb + sb_idx) * |
| 6423 | num_segs; |
| 6424 | |
| 6425 | for (i = 0; i < num_segs; i++) { |
| 6426 | addr = IGU_REG_PROD_CONS_MEMORY + |
| 6427 | (prod_offset + i) * 4; |
| 6428 | REG_WR(bp, addr, 0); |
| 6429 | } |
| 6430 | /* send consumer update with value 0 */ |
| 6431 | bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx, |
| 6432 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6433 | bnx2x_igu_clear_sb(bp, |
| 6434 | bp->igu_base_sb + sb_idx); |
| 6435 | } |
| 6436 | |
| 6437 | /* default-status-blocks */ |
| 6438 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? |
| 6439 | IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; |
| 6440 | |
| 6441 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 6442 | dsb_idx = BP_FUNC(bp); |
| 6443 | else |
| 6444 | dsb_idx = BP_E1HVN(bp); |
| 6445 | |
| 6446 | prod_offset = (CHIP_INT_MODE_IS_BC(bp) ? |
| 6447 | IGU_BC_BASE_DSB_PROD + dsb_idx : |
| 6448 | IGU_NORM_BASE_DSB_PROD + dsb_idx); |
| 6449 | |
| 6450 | for (i = 0; i < (num_segs * E1HVN_MAX); |
| 6451 | i += E1HVN_MAX) { |
| 6452 | addr = IGU_REG_PROD_CONS_MEMORY + |
| 6453 | (prod_offset + i)*4; |
| 6454 | REG_WR(bp, addr, 0); |
| 6455 | } |
| 6456 | /* send consumer update with 0 */ |
| 6457 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 6458 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6459 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6460 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6461 | CSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6462 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6463 | XSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6464 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6465 | TSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6466 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6467 | ATTENTION_ID, 0, IGU_INT_NOP, 1); |
| 6468 | } else { |
| 6469 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6470 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6471 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6472 | ATTENTION_ID, 0, IGU_INT_NOP, 1); |
| 6473 | } |
| 6474 | bnx2x_igu_clear_sb(bp, bp->igu_dsb_id); |
| 6475 | |
| 6476 | /* !!! these should become driver const once |
| 6477 | rf-tool supports split-68 const */ |
| 6478 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); |
| 6479 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); |
| 6480 | REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); |
| 6481 | REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); |
| 6482 | REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); |
| 6483 | REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); |
| 6484 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6485 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6486 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6487 | /* Reset PCIE errors for debug */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6488 | REG_WR(bp, 0x2114, 0xffffffff); |
| 6489 | REG_WR(bp, 0x2120, 0xffffffff); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6490 | |
Vladislav Zolotarov | f4a6689 | 2010-10-19 05:13:09 +0000 | [diff] [blame] | 6491 | if (CHIP_IS_E1x(bp)) { |
| 6492 | main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ |
| 6493 | main_mem_base = HC_REG_MAIN_MEMORY + |
| 6494 | BP_PORT(bp) * (main_mem_size * 4); |
| 6495 | main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; |
| 6496 | main_mem_width = 8; |
| 6497 | |
| 6498 | val = REG_RD(bp, main_mem_prty_clr); |
| 6499 | if (val) |
| 6500 | DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC " |
| 6501 | "block during " |
| 6502 | "function init (0x%x)!\n", val); |
| 6503 | |
| 6504 | /* Clear "false" parity errors in MSI-X table */ |
| 6505 | for (i = main_mem_base; |
| 6506 | i < main_mem_base + main_mem_size * 4; |
| 6507 | i += main_mem_width) { |
| 6508 | bnx2x_read_dmae(bp, i, main_mem_width / 4); |
| 6509 | bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), |
| 6510 | i, main_mem_width / 4); |
| 6511 | } |
| 6512 | /* Clear HC parity attention */ |
| 6513 | REG_RD(bp, main_mem_prty_clr); |
| 6514 | } |
| 6515 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6516 | #ifdef BNX2X_STOP_ON_ERROR |
| 6517 | /* Enable STORMs SP logging */ |
| 6518 | REG_WR8(bp, BAR_USTRORM_INTMEM + |
| 6519 | USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6520 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 6521 | TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6522 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 6523 | CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6524 | REG_WR8(bp, BAR_XSTRORM_INTMEM + |
| 6525 | XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6526 | #endif |
| 6527 | |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 6528 | bnx2x_phy_probe(&bp->link_params); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6529 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6530 | return 0; |
| 6531 | } |
| 6532 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6533 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 6534 | void bnx2x_free_mem(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6535 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6536 | /* fastpath */ |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 6537 | bnx2x_free_fp_mem(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6538 | /* end of fastpath */ |
| 6539 | |
| 6540 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6541 | sizeof(struct host_sp_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6542 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6543 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
| 6544 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6545 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6546 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6547 | sizeof(struct bnx2x_slowpath)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6548 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6549 | BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping, |
| 6550 | bp->context.size); |
| 6551 | |
| 6552 | bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE); |
| 6553 | |
| 6554 | BNX2X_FREE(bp->ilt->lines); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6555 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6556 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6557 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6558 | BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping, |
| 6559 | sizeof(struct host_hc_status_block_e2)); |
| 6560 | else |
| 6561 | BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping, |
| 6562 | sizeof(struct host_hc_status_block_e1x)); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6563 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6564 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6565 | #endif |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6566 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6567 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6568 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6569 | BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping, |
| 6570 | BCM_PAGE_SIZE * NUM_EQ_PAGES); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6571 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6572 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6573 | static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp) |
| 6574 | { |
| 6575 | int num_groups; |
| 6576 | |
| 6577 | /* number of eth_queues */ |
| 6578 | u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp); |
| 6579 | |
| 6580 | /* Total number of FW statistics requests = |
| 6581 | * 1 for port stats + 1 for PF stats + num_eth_queues */ |
| 6582 | bp->fw_stats_num = 2 + num_queue_stats; |
| 6583 | |
| 6584 | |
| 6585 | /* Request is built from stats_query_header and an array of |
| 6586 | * stats_query_cmd_group each of which contains |
| 6587 | * STATS_QUERY_CMD_COUNT rules. The real number or requests is |
| 6588 | * configured in the stats_query_header. |
| 6589 | */ |
| 6590 | num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT + |
| 6591 | (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0); |
| 6592 | |
| 6593 | bp->fw_stats_req_sz = sizeof(struct stats_query_header) + |
| 6594 | num_groups * sizeof(struct stats_query_cmd_group); |
| 6595 | |
| 6596 | /* Data for statistics requests + stats_conter |
| 6597 | * |
| 6598 | * stats_counter holds per-STORM counters that are incremented |
| 6599 | * when STORM has finished with the current request. |
| 6600 | */ |
| 6601 | bp->fw_stats_data_sz = sizeof(struct per_port_stats) + |
| 6602 | sizeof(struct per_pf_stats) + |
| 6603 | sizeof(struct per_queue_stats) * num_queue_stats + |
| 6604 | sizeof(struct stats_counter); |
| 6605 | |
| 6606 | BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping, |
| 6607 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6608 | |
| 6609 | /* Set shortcuts */ |
| 6610 | bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats; |
| 6611 | bp->fw_stats_req_mapping = bp->fw_stats_mapping; |
| 6612 | |
| 6613 | bp->fw_stats_data = (struct bnx2x_fw_stats_data *) |
| 6614 | ((u8 *)bp->fw_stats + bp->fw_stats_req_sz); |
| 6615 | |
| 6616 | bp->fw_stats_data_mapping = bp->fw_stats_mapping + |
| 6617 | bp->fw_stats_req_sz; |
| 6618 | return 0; |
| 6619 | |
| 6620 | alloc_mem_err: |
| 6621 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
| 6622 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6623 | return -ENOMEM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6624 | } |
| 6625 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6626 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 6627 | int bnx2x_alloc_mem(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6628 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6629 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6630 | if (!CHIP_IS_E1x(bp)) |
| 6631 | /* size = the status block + ramrod buffers */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6632 | BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, |
| 6633 | sizeof(struct host_hc_status_block_e2)); |
| 6634 | else |
| 6635 | BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping, |
| 6636 | sizeof(struct host_hc_status_block_e1x)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6637 | |
| 6638 | /* allocate searcher T2 table */ |
| 6639 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); |
| 6640 | #endif |
| 6641 | |
| 6642 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6643 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6644 | sizeof(struct host_sp_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6645 | |
| 6646 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
| 6647 | sizeof(struct bnx2x_slowpath)); |
| 6648 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6649 | /* Allocated memory for FW statistics */ |
| 6650 | if (bnx2x_alloc_fw_stats_mem(bp)) |
| 6651 | goto alloc_mem_err; |
| 6652 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6653 | bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6654 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6655 | BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping, |
| 6656 | bp->context.size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6657 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6658 | BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6659 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6660 | if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) |
| 6661 | goto alloc_mem_err; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6662 | |
| 6663 | /* Slow path ring */ |
| 6664 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); |
| 6665 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6666 | /* EQ */ |
| 6667 | BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, |
| 6668 | BCM_PAGE_SIZE * NUM_EQ_PAGES); |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 6669 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 6670 | |
| 6671 | /* fastpath */ |
| 6672 | /* need to be done at the end, since it's self adjusting to amount |
| 6673 | * of memory available for RSS queues |
| 6674 | */ |
| 6675 | if (bnx2x_alloc_fp_mem(bp)) |
| 6676 | goto alloc_mem_err; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6677 | return 0; |
| 6678 | |
| 6679 | alloc_mem_err: |
| 6680 | bnx2x_free_mem(bp); |
| 6681 | return -ENOMEM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6682 | } |
| 6683 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6684 | /* |
| 6685 | * Init service functions |
| 6686 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6687 | |
| 6688 | int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac, |
| 6689 | struct bnx2x_vlan_mac_obj *obj, bool set, |
| 6690 | int mac_type, unsigned long *ramrod_flags) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6691 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6692 | int rc; |
| 6693 | struct bnx2x_vlan_mac_ramrod_params ramrod_param; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6694 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6695 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6696 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6697 | /* Fill general parameters */ |
| 6698 | ramrod_param.vlan_mac_obj = obj; |
| 6699 | ramrod_param.ramrod_flags = *ramrod_flags; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6700 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6701 | /* Fill a user request section if needed */ |
| 6702 | if (!test_bit(RAMROD_CONT, ramrod_flags)) { |
| 6703 | memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6704 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6705 | __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6706 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6707 | /* Set the command: ADD or DEL */ |
| 6708 | if (set) |
| 6709 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD; |
| 6710 | else |
| 6711 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6712 | } |
| 6713 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6714 | rc = bnx2x_config_vlan_mac(bp, &ramrod_param); |
| 6715 | if (rc < 0) |
| 6716 | BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); |
| 6717 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6718 | } |
| 6719 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6720 | int bnx2x_del_all_macs(struct bnx2x *bp, |
| 6721 | struct bnx2x_vlan_mac_obj *mac_obj, |
| 6722 | int mac_type, bool wait_for_comp) |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6723 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6724 | int rc; |
| 6725 | unsigned long ramrod_flags = 0, vlan_mac_flags = 0; |
| 6726 | |
| 6727 | /* Wait for completion of requested */ |
| 6728 | if (wait_for_comp) |
| 6729 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 6730 | |
| 6731 | /* Set the mac type of addresses we want to clear */ |
| 6732 | __set_bit(mac_type, &vlan_mac_flags); |
| 6733 | |
| 6734 | rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags); |
| 6735 | if (rc < 0) |
| 6736 | BNX2X_ERR("Failed to delete MACs: %d\n", rc); |
| 6737 | |
| 6738 | return rc; |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6739 | } |
| 6740 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6741 | int bnx2x_set_eth_mac(struct bnx2x *bp, bool set) |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6742 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6743 | unsigned long ramrod_flags = 0; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6744 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6745 | DP(NETIF_MSG_IFUP, "Adding Eth MAC\n"); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6746 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6747 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 6748 | /* Eth MAC is set on RSS leading client (fp[0]) */ |
| 6749 | return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set, |
| 6750 | BNX2X_ETH_MAC, &ramrod_flags); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6751 | } |
| 6752 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6753 | int bnx2x_setup_leading(struct bnx2x *bp) |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6754 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6755 | return bnx2x_setup_queue(bp, &bp->fp[0], 1); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6756 | } |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 6757 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6758 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 6759 | * bnx2x_set_int_mode - configure interrupt mode |
| 6760 | * |
| 6761 | * @bp: driver handle |
| 6762 | * |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6763 | * In case of MSI-X it will also try to enable MSI-X. |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6764 | */ |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6765 | static void __devinit bnx2x_set_int_mode(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6766 | { |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6767 | switch (int_mode) { |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6768 | case INT_MODE_MSI: |
| 6769 | bnx2x_enable_msi(bp); |
| 6770 | /* falling through... */ |
| 6771 | case INT_MODE_INTx: |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6772 | bp->num_queues = 1 + NONE_ETH_CONTEXT_USE; |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6773 | DP(NETIF_MSG_IFUP, "set number of queues to 1\n"); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6774 | break; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6775 | default: |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6776 | /* Set number of queues according to bp->multi_mode value */ |
| 6777 | bnx2x_set_num_queues(bp); |
| 6778 | |
| 6779 | DP(NETIF_MSG_IFUP, "set number of queues to %d\n", |
| 6780 | bp->num_queues); |
| 6781 | |
| 6782 | /* if we can't use MSI-X we only need one fp, |
| 6783 | * so try to enable MSI-X with the requested number of fp's |
| 6784 | * and fallback to MSI or legacy INTx with one fp |
| 6785 | */ |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6786 | if (bnx2x_enable_msix(bp)) { |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6787 | /* failed to enable MSI-X */ |
| 6788 | if (bp->multi_mode) |
| 6789 | DP(NETIF_MSG_IFUP, |
| 6790 | "Multi requested but failed to " |
| 6791 | "enable MSI-X (%d), " |
| 6792 | "set number of queues to %d\n", |
| 6793 | bp->num_queues, |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6794 | 1 + NONE_ETH_CONTEXT_USE); |
| 6795 | bp->num_queues = 1 + NONE_ETH_CONTEXT_USE; |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6796 | |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6797 | /* Try to enable MSI */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6798 | if (!(bp->flags & DISABLE_MSI_FLAG)) |
| 6799 | bnx2x_enable_msi(bp); |
| 6800 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6801 | break; |
| 6802 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6803 | } |
| 6804 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 6805 | /* must be called prioir to any HW initializations */ |
| 6806 | static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp) |
| 6807 | { |
| 6808 | return L2_ILT_LINES(bp); |
| 6809 | } |
| 6810 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6811 | void bnx2x_ilt_set_info(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6812 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6813 | struct ilt_client_info *ilt_client; |
| 6814 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
| 6815 | u16 line = 0; |
| 6816 | |
| 6817 | ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp)); |
| 6818 | DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line); |
| 6819 | |
| 6820 | /* CDU */ |
| 6821 | ilt_client = &ilt->clients[ILT_CLIENT_CDU]; |
| 6822 | ilt_client->client_num = ILT_CLIENT_CDU; |
| 6823 | ilt_client->page_size = CDU_ILT_PAGE_SZ; |
| 6824 | ilt_client->flags = ILT_CLIENT_SKIP_MEM; |
| 6825 | ilt_client->start = line; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6826 | line += bnx2x_cid_ilt_lines(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6827 | #ifdef BCM_CNIC |
| 6828 | line += CNIC_ILT_LINES; |
| 6829 | #endif |
| 6830 | ilt_client->end = line - 1; |
| 6831 | |
| 6832 | DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, " |
| 6833 | "flags 0x%x, hw psz %d\n", |
| 6834 | ilt_client->start, |
| 6835 | ilt_client->end, |
| 6836 | ilt_client->page_size, |
| 6837 | ilt_client->flags, |
| 6838 | ilog2(ilt_client->page_size >> 12)); |
| 6839 | |
| 6840 | /* QM */ |
| 6841 | if (QM_INIT(bp->qm_cid_count)) { |
| 6842 | ilt_client = &ilt->clients[ILT_CLIENT_QM]; |
| 6843 | ilt_client->client_num = ILT_CLIENT_QM; |
| 6844 | ilt_client->page_size = QM_ILT_PAGE_SZ; |
| 6845 | ilt_client->flags = 0; |
| 6846 | ilt_client->start = line; |
| 6847 | |
| 6848 | /* 4 bytes for each cid */ |
| 6849 | line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4, |
| 6850 | QM_ILT_PAGE_SZ); |
| 6851 | |
| 6852 | ilt_client->end = line - 1; |
| 6853 | |
| 6854 | DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, " |
| 6855 | "flags 0x%x, hw psz %d\n", |
| 6856 | ilt_client->start, |
| 6857 | ilt_client->end, |
| 6858 | ilt_client->page_size, |
| 6859 | ilt_client->flags, |
| 6860 | ilog2(ilt_client->page_size >> 12)); |
| 6861 | |
| 6862 | } |
| 6863 | /* SRC */ |
| 6864 | ilt_client = &ilt->clients[ILT_CLIENT_SRC]; |
| 6865 | #ifdef BCM_CNIC |
| 6866 | ilt_client->client_num = ILT_CLIENT_SRC; |
| 6867 | ilt_client->page_size = SRC_ILT_PAGE_SZ; |
| 6868 | ilt_client->flags = 0; |
| 6869 | ilt_client->start = line; |
| 6870 | line += SRC_ILT_LINES; |
| 6871 | ilt_client->end = line - 1; |
| 6872 | |
| 6873 | DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, " |
| 6874 | "flags 0x%x, hw psz %d\n", |
| 6875 | ilt_client->start, |
| 6876 | ilt_client->end, |
| 6877 | ilt_client->page_size, |
| 6878 | ilt_client->flags, |
| 6879 | ilog2(ilt_client->page_size >> 12)); |
| 6880 | |
| 6881 | #else |
| 6882 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); |
| 6883 | #endif |
| 6884 | |
| 6885 | /* TM */ |
| 6886 | ilt_client = &ilt->clients[ILT_CLIENT_TM]; |
| 6887 | #ifdef BCM_CNIC |
| 6888 | ilt_client->client_num = ILT_CLIENT_TM; |
| 6889 | ilt_client->page_size = TM_ILT_PAGE_SZ; |
| 6890 | ilt_client->flags = 0; |
| 6891 | ilt_client->start = line; |
| 6892 | line += TM_ILT_LINES; |
| 6893 | ilt_client->end = line - 1; |
| 6894 | |
| 6895 | DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, " |
| 6896 | "flags 0x%x, hw psz %d\n", |
| 6897 | ilt_client->start, |
| 6898 | ilt_client->end, |
| 6899 | ilt_client->page_size, |
| 6900 | ilt_client->flags, |
| 6901 | ilog2(ilt_client->page_size >> 12)); |
| 6902 | |
| 6903 | #else |
| 6904 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); |
| 6905 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6906 | BUG_ON(line > ILT_MAX_LINES); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6907 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6908 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6909 | /** |
| 6910 | * bnx2x_pf_q_prep_init - prepare INIT transition parameters |
| 6911 | * |
| 6912 | * @bp: driver handle |
| 6913 | * @fp: pointer to fastpath |
| 6914 | * @init_params: pointer to parameters structure |
| 6915 | * |
| 6916 | * parameters configured: |
| 6917 | * - HC configuration |
| 6918 | * - Queue's CDU context |
| 6919 | */ |
| 6920 | static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp, |
| 6921 | struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6922 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6923 | /* FCoE Queue uses Default SB, thus has no HC capabilities */ |
| 6924 | if (!IS_FCOE_FP(fp)) { |
| 6925 | __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags); |
| 6926 | __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags); |
| 6927 | |
| 6928 | /* If HC is supporterd, enable host coalescing in the transition |
| 6929 | * to INIT state. |
| 6930 | */ |
| 6931 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags); |
| 6932 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags); |
| 6933 | |
| 6934 | /* HC rate */ |
| 6935 | init_params->rx.hc_rate = bp->rx_ticks ? |
| 6936 | (1000000 / bp->rx_ticks) : 0; |
| 6937 | init_params->tx.hc_rate = bp->tx_ticks ? |
| 6938 | (1000000 / bp->tx_ticks) : 0; |
| 6939 | |
| 6940 | /* FW SB ID */ |
| 6941 | init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = |
| 6942 | fp->fw_sb_id; |
| 6943 | |
| 6944 | /* |
| 6945 | * CQ index among the SB indices: FCoE clients uses the default |
| 6946 | * SB, therefore it's different. |
| 6947 | */ |
| 6948 | init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX; |
| 6949 | init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX; |
| 6950 | } |
| 6951 | |
| 6952 | init_params->cxt = &bp->context.vcxt[fp->cid].eth; |
| 6953 | } |
| 6954 | |
| 6955 | /** |
| 6956 | * bnx2x_setup_queue - setup queue |
| 6957 | * |
| 6958 | * @bp: driver handle |
| 6959 | * @fp: pointer to fastpath |
| 6960 | * @leading: is leading |
| 6961 | * |
| 6962 | * This function performs 2 steps in a Queue state machine |
| 6963 | * actually: 1) RESET->INIT 2) INIT->SETUP |
| 6964 | */ |
| 6965 | |
| 6966 | int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 6967 | bool leading) |
| 6968 | { |
| 6969 | struct bnx2x_queue_state_params q_params = {0}; |
| 6970 | struct bnx2x_queue_setup_params *setup_params = |
| 6971 | &q_params.params.setup; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6972 | int rc; |
| 6973 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6974 | /* reset IGU state skip FCoE L2 queue */ |
| 6975 | if (!IS_FCOE_FP(fp)) |
| 6976 | bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6977 | IGU_INT_ENABLE, 0); |
| 6978 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6979 | q_params.q_obj = &fp->q_obj; |
| 6980 | /* We want to wait for completion in this context */ |
| 6981 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6982 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6983 | /* Prepare the INIT parameters */ |
| 6984 | bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6985 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6986 | /* Set the command */ |
| 6987 | q_params.cmd = BNX2X_Q_CMD_INIT; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6988 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6989 | /* Change the state to INIT */ |
| 6990 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 6991 | if (rc) { |
| 6992 | BNX2X_ERR("Queue INIT failed\n"); |
| 6993 | return rc; |
| 6994 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6995 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6996 | /* Now move the Queue to the SETUP state... */ |
| 6997 | memset(setup_params, 0, sizeof(*setup_params)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6998 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6999 | /* Set QUEUE flags */ |
| 7000 | setup_params->flags = bnx2x_get_q_flags(bp, fp, leading); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7001 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7002 | /* Set general SETUP parameters */ |
| 7003 | bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params); |
| 7004 | |
| 7005 | bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause, |
| 7006 | &setup_params->rxq_params); |
| 7007 | |
| 7008 | bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params); |
| 7009 | |
| 7010 | /* Set the command */ |
| 7011 | q_params.cmd = BNX2X_Q_CMD_SETUP; |
| 7012 | |
| 7013 | /* Change the state to SETUP */ |
| 7014 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7015 | if (rc) |
| 7016 | BNX2X_ERR("Queue SETUP failed\n"); |
| 7017 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7018 | return rc; |
| 7019 | } |
| 7020 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7021 | static int bnx2x_stop_queue(struct bnx2x *bp, int index) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7022 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7023 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
| 7024 | struct bnx2x_queue_state_params q_params = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7025 | int rc; |
| 7026 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7027 | q_params.q_obj = &fp->q_obj; |
| 7028 | /* We want to wait for completion in this context */ |
| 7029 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7030 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7031 | /* halt the connection */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7032 | q_params.cmd = BNX2X_Q_CMD_HALT; |
| 7033 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7034 | if (rc) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7035 | return rc; |
| 7036 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7037 | /* terminate the connection */ |
| 7038 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; |
| 7039 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7040 | if (rc) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7041 | return rc; |
| 7042 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7043 | /* delete cfc entry */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7044 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; |
| 7045 | return bnx2x_queue_state_change(bp, &q_params); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7046 | } |
| 7047 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7048 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7049 | static void bnx2x_reset_func(struct bnx2x *bp) |
| 7050 | { |
| 7051 | int port = BP_PORT(bp); |
| 7052 | int func = BP_FUNC(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7053 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7054 | |
| 7055 | /* Disable the function in the FW */ |
| 7056 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); |
| 7057 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); |
| 7058 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); |
| 7059 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); |
| 7060 | |
| 7061 | /* FP SBs */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7062 | for_each_eth_queue(bp, i) { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7063 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7064 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7065 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), |
| 7066 | SB_DISABLED); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7067 | } |
| 7068 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7069 | #ifdef BCM_CNIC |
| 7070 | /* CNIC SB */ |
| 7071 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7072 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)), |
| 7073 | SB_DISABLED); |
| 7074 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7075 | /* SP SB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7076 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7077 | CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), |
| 7078 | SB_DISABLED); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7079 | |
| 7080 | for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) |
| 7081 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), |
| 7082 | 0); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7083 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7084 | /* Configure IGU */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7085 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 7086 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 7087 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 7088 | } else { |
| 7089 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
| 7090 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); |
| 7091 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7092 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 7093 | #ifdef BCM_CNIC |
| 7094 | /* Disable Timer scan */ |
| 7095 | REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0); |
| 7096 | /* |
| 7097 | * Wait for at least 10ms and up to 2 second for the timers scan to |
| 7098 | * complete |
| 7099 | */ |
| 7100 | for (i = 0; i < 200; i++) { |
| 7101 | msleep(10); |
| 7102 | if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4)) |
| 7103 | break; |
| 7104 | } |
| 7105 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7106 | /* Clear ILT */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7107 | bnx2x_clear_func_ilt(bp, func); |
| 7108 | |
| 7109 | /* Timers workaround bug for E2: if this is vnic-3, |
| 7110 | * we need to set the entire ilt range for this timers. |
| 7111 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7112 | if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7113 | struct ilt_client_info ilt_cli; |
| 7114 | /* use dummy TM client */ |
| 7115 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); |
| 7116 | ilt_cli.start = 0; |
| 7117 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; |
| 7118 | ilt_cli.client_num = ILT_CLIENT_TM; |
| 7119 | |
| 7120 | bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR); |
| 7121 | } |
| 7122 | |
| 7123 | /* this assumes that reset_port() called before reset_func()*/ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7124 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7125 | bnx2x_pf_disable(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7126 | |
| 7127 | bp->dmae_ready = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | static void bnx2x_reset_port(struct bnx2x *bp) |
| 7131 | { |
| 7132 | int port = BP_PORT(bp); |
| 7133 | u32 val; |
| 7134 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7135 | /* Reset physical Link */ |
| 7136 | bnx2x__link_reset(bp); |
| 7137 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7138 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
| 7139 | |
| 7140 | /* Do not rcv packets to BRB */ |
| 7141 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); |
| 7142 | /* Do not direct rcv packets that are not for MCP to the BRB */ |
| 7143 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7144 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7145 | |
| 7146 | /* Configure AEU */ |
| 7147 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); |
| 7148 | |
| 7149 | msleep(100); |
| 7150 | /* Check for BRB port occupancy */ |
| 7151 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); |
| 7152 | if (val) |
| 7153 | DP(NETIF_MSG_IFDOWN, |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7154 | "BRB1 is not empty %d blocks are occupied\n", val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7155 | |
| 7156 | /* TODO: Close Doorbell port? */ |
| 7157 | } |
| 7158 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7159 | static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7160 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7161 | struct bnx2x_func_state_params func_params = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7162 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7163 | /* Prepare parameters for function state transitions */ |
| 7164 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7165 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7166 | func_params.f_obj = &bp->func_obj; |
| 7167 | func_params.cmd = BNX2X_F_CMD_HW_RESET; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7168 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7169 | func_params.params.hw_init.load_phase = load_code; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7170 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7171 | return bnx2x_func_state_change(bp, &func_params); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7174 | static inline int bnx2x_func_stop(struct bnx2x *bp) |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7175 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7176 | struct bnx2x_func_state_params func_params = {0}; |
| 7177 | int rc; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7178 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7179 | /* Prepare parameters for function state transitions */ |
| 7180 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); |
| 7181 | func_params.f_obj = &bp->func_obj; |
| 7182 | func_params.cmd = BNX2X_F_CMD_STOP; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7183 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7184 | /* |
| 7185 | * Try to stop the function the 'good way'. If fails (in case |
| 7186 | * of a parity error during bnx2x_chip_cleanup()) and we are |
| 7187 | * not in a debug mode, perform a state transaction in order to |
| 7188 | * enable further HW_RESET transaction. |
| 7189 | */ |
| 7190 | rc = bnx2x_func_state_change(bp, &func_params); |
| 7191 | if (rc) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7192 | #ifdef BNX2X_STOP_ON_ERROR |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7193 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7194 | #else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7195 | BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry " |
| 7196 | "transaction\n"); |
| 7197 | __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); |
| 7198 | return bnx2x_func_state_change(bp, &func_params); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7199 | #endif |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7200 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7201 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7202 | return 0; |
| 7203 | } |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7204 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7205 | /** |
| 7206 | * bnx2x_send_unload_req - request unload mode from the MCP. |
| 7207 | * |
| 7208 | * @bp: driver handle |
| 7209 | * @unload_mode: requested function's unload mode |
| 7210 | * |
| 7211 | * Return unload mode returned by the MCP: COMMON, PORT or FUNC. |
| 7212 | */ |
| 7213 | u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode) |
| 7214 | { |
| 7215 | u32 reset_code = 0; |
| 7216 | int port = BP_PORT(bp); |
| 7217 | |
| 7218 | /* Select the UNLOAD request mode */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7219 | if (unload_mode == UNLOAD_NORMAL) |
| 7220 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7221 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7222 | else if (bp->flags & NO_WOL_FLAG) |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7223 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7224 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7225 | else if (bp->wol) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7226 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7227 | u8 *mac_addr = bp->dev->dev_addr; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7228 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7229 | /* The mac address is written to entries 1-4 to |
| 7230 | preserve entry 0 which is used by the PMF */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7231 | u8 entry = (BP_E1HVN(bp) + 1)*8; |
| 7232 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7233 | val = (mac_addr[0] << 8) | mac_addr[1]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7234 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7235 | |
| 7236 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 7237 | (mac_addr[4] << 8) | mac_addr[5]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7238 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7239 | |
| 7240 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7241 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7242 | } else |
| 7243 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
| 7244 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7245 | /* Send the request to the MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7246 | if (!BP_NOMCP(bp)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 7247 | reset_code = bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7248 | else { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7249 | int path = BP_PATH(bp); |
| 7250 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7251 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7252 | "%d, %d, %d\n", |
| 7253 | path, load_count[path][0], load_count[path][1], |
| 7254 | load_count[path][2]); |
| 7255 | load_count[path][0]--; |
| 7256 | load_count[path][1 + port]--; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7257 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7258 | "%d, %d, %d\n", |
| 7259 | path, load_count[path][0], load_count[path][1], |
| 7260 | load_count[path][2]); |
| 7261 | if (load_count[path][0] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7262 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7263 | else if (load_count[path][1 + port] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7264 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; |
| 7265 | else |
| 7266 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; |
| 7267 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7268 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7269 | return reset_code; |
| 7270 | } |
| 7271 | |
| 7272 | /** |
| 7273 | * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP. |
| 7274 | * |
| 7275 | * @bp: driver handle |
| 7276 | */ |
| 7277 | void bnx2x_send_unload_done(struct bnx2x *bp) |
| 7278 | { |
| 7279 | /* Report UNLOAD_DONE to MCP */ |
| 7280 | if (!BP_NOMCP(bp)) |
| 7281 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); |
| 7282 | } |
| 7283 | |
| 7284 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode) |
| 7285 | { |
| 7286 | int port = BP_PORT(bp); |
| 7287 | int i, rc; |
| 7288 | struct bnx2x_mcast_ramrod_params rparam = {0}; |
| 7289 | u32 reset_code; |
| 7290 | |
| 7291 | /* Wait until tx fastpath tasks complete */ |
| 7292 | for_each_tx_queue(bp, i) { |
| 7293 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 7294 | |
| 7295 | rc = bnx2x_clean_tx_queue(bp, fp); |
| 7296 | #ifdef BNX2X_STOP_ON_ERROR |
| 7297 | if (rc) |
| 7298 | return; |
| 7299 | #endif |
| 7300 | } |
| 7301 | |
| 7302 | /* Give HW time to discard old tx messages */ |
| 7303 | usleep_range(1000, 1000); |
| 7304 | |
| 7305 | /* Clean all ETH MACs */ |
| 7306 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false); |
| 7307 | if (rc < 0) |
| 7308 | BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc); |
| 7309 | |
| 7310 | /* Clean up UC list */ |
| 7311 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC, |
| 7312 | true); |
| 7313 | if (rc < 0) |
| 7314 | BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: " |
| 7315 | "%d\n", rc); |
| 7316 | |
| 7317 | /* Disable LLH */ |
| 7318 | if (!CHIP_IS_E1(bp)) |
| 7319 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 7320 | |
| 7321 | /* Set "drop all" (stop Rx). |
| 7322 | * We need to take a netif_addr_lock() here in order to prevent |
| 7323 | * a race between the completion code and this code. |
| 7324 | */ |
| 7325 | netif_addr_lock_bh(bp->dev); |
| 7326 | /* Schedule the rx_mode command */ |
| 7327 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) |
| 7328 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); |
| 7329 | else |
| 7330 | bnx2x_set_storm_rx_mode(bp); |
| 7331 | |
| 7332 | /* Cleanup multicast configuration */ |
| 7333 | rparam.mcast_obj = &bp->mcast_obj; |
| 7334 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); |
| 7335 | if (rc < 0) |
| 7336 | BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc); |
| 7337 | |
| 7338 | netif_addr_unlock_bh(bp->dev); |
| 7339 | |
| 7340 | |
| 7341 | /* Close multi and leading connections |
| 7342 | * Completions for ramrods are collected in a synchronous way |
| 7343 | */ |
| 7344 | for_each_queue(bp, i) |
| 7345 | if (bnx2x_stop_queue(bp, i)) |
| 7346 | #ifdef BNX2X_STOP_ON_ERROR |
| 7347 | return; |
| 7348 | #else |
| 7349 | goto unload_error; |
| 7350 | #endif |
| 7351 | /* If SP settings didn't get completed so far - something |
| 7352 | * very wrong has happen. |
| 7353 | */ |
| 7354 | if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) |
| 7355 | BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n"); |
| 7356 | |
| 7357 | #ifndef BNX2X_STOP_ON_ERROR |
| 7358 | unload_error: |
| 7359 | #endif |
| 7360 | rc = bnx2x_func_stop(bp); |
| 7361 | if (rc) { |
| 7362 | BNX2X_ERR("Function stop failed!\n"); |
| 7363 | #ifdef BNX2X_STOP_ON_ERROR |
| 7364 | return; |
| 7365 | #endif |
| 7366 | } |
| 7367 | |
| 7368 | /* |
| 7369 | * Send the UNLOAD_REQUEST to the MCP. This will return if |
| 7370 | * this function should perform FUNC, PORT or COMMON HW |
| 7371 | * reset. |
| 7372 | */ |
| 7373 | reset_code = bnx2x_send_unload_req(bp, unload_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7374 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7375 | /* Disable HW interrupts, NAPI */ |
| 7376 | bnx2x_netif_stop(bp, 1); |
| 7377 | |
| 7378 | /* Release IRQs */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 7379 | bnx2x_free_irq(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7380 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7381 | /* Reset the chip */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7382 | rc = bnx2x_reset_hw(bp, reset_code); |
| 7383 | if (rc) |
| 7384 | BNX2X_ERR("HW_RESET failed\n"); |
| 7385 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7386 | |
| 7387 | /* Report UNLOAD_DONE to MCP */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7388 | bnx2x_send_unload_done(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7389 | } |
| 7390 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 7391 | void bnx2x_disable_close_the_gate(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7392 | { |
| 7393 | u32 val; |
| 7394 | |
| 7395 | DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n"); |
| 7396 | |
| 7397 | if (CHIP_IS_E1(bp)) { |
| 7398 | int port = BP_PORT(bp); |
| 7399 | u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 7400 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 7401 | |
| 7402 | val = REG_RD(bp, addr); |
| 7403 | val &= ~(0x300); |
| 7404 | REG_WR(bp, addr, val); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7405 | } else { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7406 | val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK); |
| 7407 | val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | |
| 7408 | MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); |
| 7409 | REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val); |
| 7410 | } |
| 7411 | } |
| 7412 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7413 | /* Close gates #2, #3 and #4: */ |
| 7414 | static void bnx2x_set_234_gates(struct bnx2x *bp, bool close) |
| 7415 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7416 | u32 val; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7417 | |
| 7418 | /* Gates #2 and #4a are closed/opened for "not E1" only */ |
| 7419 | if (!CHIP_IS_E1(bp)) { |
| 7420 | /* #4 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7421 | REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7422 | /* #2 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7423 | REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
| 7426 | /* #3 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7427 | if (CHIP_IS_E1x(bp)) { |
| 7428 | /* Prevent interrupts from HC on both ports */ |
| 7429 | val = REG_RD(bp, HC_REG_CONFIG_1); |
| 7430 | REG_WR(bp, HC_REG_CONFIG_1, |
| 7431 | (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : |
| 7432 | (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); |
| 7433 | |
| 7434 | val = REG_RD(bp, HC_REG_CONFIG_0); |
| 7435 | REG_WR(bp, HC_REG_CONFIG_0, |
| 7436 | (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : |
| 7437 | (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); |
| 7438 | } else { |
| 7439 | /* Prevent incomming interrupts in IGU */ |
| 7440 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
| 7441 | |
| 7442 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, |
| 7443 | (!close) ? |
| 7444 | (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : |
| 7445 | (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); |
| 7446 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7447 | |
| 7448 | DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n", |
| 7449 | close ? "closing" : "opening"); |
| 7450 | mmiowb(); |
| 7451 | } |
| 7452 | |
| 7453 | #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */ |
| 7454 | |
| 7455 | static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val) |
| 7456 | { |
| 7457 | /* Do some magic... */ |
| 7458 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
| 7459 | *magic_val = val & SHARED_MF_CLP_MAGIC; |
| 7460 | MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); |
| 7461 | } |
| 7462 | |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7463 | /** |
| 7464 | * bnx2x_clp_reset_done - restore the value of the `magic' bit. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7465 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7466 | * @bp: driver handle |
| 7467 | * @magic_val: old value of the `magic' bit. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7468 | */ |
| 7469 | static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val) |
| 7470 | { |
| 7471 | /* Restore the `magic' bit value... */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7472 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
| 7473 | MF_CFG_WR(bp, shared_mf_config.clp_mb, |
| 7474 | (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); |
| 7475 | } |
| 7476 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 7477 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7478 | * bnx2x_reset_mcp_prep - prepare for MCP reset. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7479 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7480 | * @bp: driver handle |
| 7481 | * @magic_val: old value of 'magic' bit. |
| 7482 | * |
| 7483 | * Takes care of CLP configurations. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7484 | */ |
| 7485 | static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val) |
| 7486 | { |
| 7487 | u32 shmem; |
| 7488 | u32 validity_offset; |
| 7489 | |
| 7490 | DP(NETIF_MSG_HW, "Starting\n"); |
| 7491 | |
| 7492 | /* Set `magic' bit in order to save MF config */ |
| 7493 | if (!CHIP_IS_E1(bp)) |
| 7494 | bnx2x_clp_reset_prep(bp, magic_val); |
| 7495 | |
| 7496 | /* Get shmem offset */ |
| 7497 | shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7498 | validity_offset = offsetof(struct shmem_region, validity_map[0]); |
| 7499 | |
| 7500 | /* Clear validity map flags */ |
| 7501 | if (shmem > 0) |
| 7502 | REG_WR(bp, shmem + validity_offset, 0); |
| 7503 | } |
| 7504 | |
| 7505 | #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ |
| 7506 | #define MCP_ONE_TIMEOUT 100 /* 100 ms */ |
| 7507 | |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7508 | /** |
| 7509 | * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7510 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7511 | * @bp: driver handle |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7512 | */ |
| 7513 | static inline void bnx2x_mcp_wait_one(struct bnx2x *bp) |
| 7514 | { |
| 7515 | /* special handling for emulation and FPGA, |
| 7516 | wait 10 times longer */ |
| 7517 | if (CHIP_REV_IS_SLOW(bp)) |
| 7518 | msleep(MCP_ONE_TIMEOUT*10); |
| 7519 | else |
| 7520 | msleep(MCP_ONE_TIMEOUT); |
| 7521 | } |
| 7522 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7523 | /* |
| 7524 | * initializes bp->common.shmem_base and waits for validity signature to appear |
| 7525 | */ |
| 7526 | static int bnx2x_init_shmem(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7527 | { |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7528 | int cnt = 0; |
| 7529 | u32 val = 0; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7530 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7531 | do { |
| 7532 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7533 | if (bp->common.shmem_base) { |
| 7534 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 7535 | if (val & SHR_MEM_VALIDITY_MB) |
| 7536 | return 0; |
| 7537 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7538 | |
| 7539 | bnx2x_mcp_wait_one(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7540 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7541 | } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7542 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7543 | BNX2X_ERR("BAD MCP validity signature\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7544 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7545 | return -ENODEV; |
| 7546 | } |
| 7547 | |
| 7548 | static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val) |
| 7549 | { |
| 7550 | int rc = bnx2x_init_shmem(bp); |
| 7551 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7552 | /* Restore the `magic' bit value */ |
| 7553 | if (!CHIP_IS_E1(bp)) |
| 7554 | bnx2x_clp_reset_done(bp, magic_val); |
| 7555 | |
| 7556 | return rc; |
| 7557 | } |
| 7558 | |
| 7559 | static void bnx2x_pxp_prep(struct bnx2x *bp) |
| 7560 | { |
| 7561 | if (!CHIP_IS_E1(bp)) { |
| 7562 | REG_WR(bp, PXP2_REG_RD_START_INIT, 0); |
| 7563 | REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7564 | mmiowb(); |
| 7565 | } |
| 7566 | } |
| 7567 | |
| 7568 | /* |
| 7569 | * Reset the whole chip except for: |
| 7570 | * - PCIE core |
| 7571 | * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by |
| 7572 | * one reset bit) |
| 7573 | * - IGU |
| 7574 | * - MISC (including AEU) |
| 7575 | * - GRC |
| 7576 | * - RBCN, RBCP |
| 7577 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7578 | static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7579 | { |
| 7580 | u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7581 | u32 global_bits2; |
| 7582 | |
| 7583 | /* |
| 7584 | * Bits that have to be set in reset_mask2 if we want to reset 'global' |
| 7585 | * (per chip) blocks. |
| 7586 | */ |
| 7587 | global_bits2 = |
| 7588 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | |
| 7589 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7590 | |
| 7591 | not_reset_mask1 = |
| 7592 | MISC_REGISTERS_RESET_REG_1_RST_HC | |
| 7593 | MISC_REGISTERS_RESET_REG_1_RST_PXPV | |
| 7594 | MISC_REGISTERS_RESET_REG_1_RST_PXP; |
| 7595 | |
| 7596 | not_reset_mask2 = |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7597 | MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7598 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | |
| 7599 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | |
| 7600 | MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | |
| 7601 | MISC_REGISTERS_RESET_REG_2_RST_RBCN | |
| 7602 | MISC_REGISTERS_RESET_REG_2_RST_GRC | |
| 7603 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | |
| 7604 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B; |
| 7605 | |
| 7606 | reset_mask1 = 0xffffffff; |
| 7607 | |
| 7608 | if (CHIP_IS_E1(bp)) |
| 7609 | reset_mask2 = 0xffff; |
| 7610 | else |
| 7611 | reset_mask2 = 0x1ffff; |
| 7612 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7613 | if (CHIP_IS_E3(bp)) { |
| 7614 | reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 7615 | reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 7616 | } |
| 7617 | |
| 7618 | /* Don't reset global blocks unless we need to */ |
| 7619 | if (!global) |
| 7620 | reset_mask2 &= ~global_bits2; |
| 7621 | |
| 7622 | /* |
| 7623 | * In case of attention in the QM, we need to reset PXP |
| 7624 | * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM |
| 7625 | * because otherwise QM reset would release 'close the gates' shortly |
| 7626 | * before resetting the PXP, then the PSWRQ would send a write |
| 7627 | * request to PGLUE. Then when PXP is reset, PGLUE would try to |
| 7628 | * read the payload data from PSWWR, but PSWWR would not |
| 7629 | * respond. The write queue in PGLUE would stuck, dmae commands |
| 7630 | * would not return. Therefore it's important to reset the second |
| 7631 | * reset register (containing the |
| 7632 | * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the |
| 7633 | * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM |
| 7634 | * bit). |
| 7635 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7636 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
| 7637 | reset_mask2 & (~not_reset_mask2)); |
| 7638 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7639 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 7640 | reset_mask1 & (~not_reset_mask1)); |
| 7641 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7642 | barrier(); |
| 7643 | mmiowb(); |
| 7644 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7645 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7646 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7647 | mmiowb(); |
| 7648 | } |
| 7649 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7650 | /** |
| 7651 | * bnx2x_er_poll_igu_vq - poll for pending writes bit. |
| 7652 | * It should get cleared in no more than 1s. |
| 7653 | * |
| 7654 | * @bp: driver handle |
| 7655 | * |
| 7656 | * It should get cleared in no more than 1s. Returns 0 if |
| 7657 | * pending writes bit gets cleared. |
| 7658 | */ |
| 7659 | static int bnx2x_er_poll_igu_vq(struct bnx2x *bp) |
| 7660 | { |
| 7661 | u32 cnt = 1000; |
| 7662 | u32 pend_bits = 0; |
| 7663 | |
| 7664 | do { |
| 7665 | pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS); |
| 7666 | |
| 7667 | if (pend_bits == 0) |
| 7668 | break; |
| 7669 | |
| 7670 | usleep_range(1000, 1000); |
| 7671 | } while (cnt-- > 0); |
| 7672 | |
| 7673 | if (cnt <= 0) { |
| 7674 | BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n", |
| 7675 | pend_bits); |
| 7676 | return -EBUSY; |
| 7677 | } |
| 7678 | |
| 7679 | return 0; |
| 7680 | } |
| 7681 | |
| 7682 | static int bnx2x_process_kill(struct bnx2x *bp, bool global) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7683 | { |
| 7684 | int cnt = 1000; |
| 7685 | u32 val = 0; |
| 7686 | u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; |
| 7687 | |
| 7688 | |
| 7689 | /* Empty the Tetris buffer, wait for 1s */ |
| 7690 | do { |
| 7691 | sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT); |
| 7692 | blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT); |
| 7693 | port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0); |
| 7694 | port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1); |
| 7695 | pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2); |
| 7696 | if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && |
| 7697 | ((port_is_idle_0 & 0x1) == 0x1) && |
| 7698 | ((port_is_idle_1 & 0x1) == 0x1) && |
| 7699 | (pgl_exp_rom2 == 0xffffffff)) |
| 7700 | break; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7701 | usleep_range(1000, 1000); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7702 | } while (cnt-- > 0); |
| 7703 | |
| 7704 | if (cnt <= 0) { |
| 7705 | DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there" |
| 7706 | " are still" |
| 7707 | " outstanding read requests after 1s!\n"); |
| 7708 | DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x," |
| 7709 | " port_is_idle_0=0x%08x," |
| 7710 | " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n", |
| 7711 | sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, |
| 7712 | pgl_exp_rom2); |
| 7713 | return -EAGAIN; |
| 7714 | } |
| 7715 | |
| 7716 | barrier(); |
| 7717 | |
| 7718 | /* Close gates #2, #3 and #4 */ |
| 7719 | bnx2x_set_234_gates(bp, true); |
| 7720 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7721 | /* Poll for IGU VQs for 57712 and newer chips */ |
| 7722 | if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp)) |
| 7723 | return -EAGAIN; |
| 7724 | |
| 7725 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7726 | /* TBD: Indicate that "process kill" is in progress to MCP */ |
| 7727 | |
| 7728 | /* Clear "unprepared" bit */ |
| 7729 | REG_WR(bp, MISC_REG_UNPREPARED, 0); |
| 7730 | barrier(); |
| 7731 | |
| 7732 | /* Make sure all is written to the chip before the reset */ |
| 7733 | mmiowb(); |
| 7734 | |
| 7735 | /* Wait for 1ms to empty GLUE and PCI-E core queues, |
| 7736 | * PSWHST, GRC and PSWRD Tetris buffer. |
| 7737 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7738 | usleep_range(1000, 1000); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7739 | |
| 7740 | /* Prepare to chip reset: */ |
| 7741 | /* MCP */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7742 | if (global) |
| 7743 | bnx2x_reset_mcp_prep(bp, &val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7744 | |
| 7745 | /* PXP */ |
| 7746 | bnx2x_pxp_prep(bp); |
| 7747 | barrier(); |
| 7748 | |
| 7749 | /* reset the chip */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7750 | bnx2x_process_kill_chip_reset(bp, global); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7751 | barrier(); |
| 7752 | |
| 7753 | /* Recover after reset: */ |
| 7754 | /* MCP */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7755 | if (global && bnx2x_reset_mcp_comp(bp, val)) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7756 | return -EAGAIN; |
| 7757 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7758 | /* TBD: Add resetting the NO_MCP mode DB here */ |
| 7759 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7760 | /* PXP */ |
| 7761 | bnx2x_pxp_prep(bp); |
| 7762 | |
| 7763 | /* Open the gates #2, #3 and #4 */ |
| 7764 | bnx2x_set_234_gates(bp, false); |
| 7765 | |
| 7766 | /* TBD: IGU/AEU preparation bring back the AEU/IGU to a |
| 7767 | * reset state, re-enable attentions. */ |
| 7768 | |
| 7769 | return 0; |
| 7770 | } |
| 7771 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7772 | int bnx2x_leader_reset(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7773 | { |
| 7774 | int rc = 0; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7775 | bool global = bnx2x_reset_is_global(bp); |
| 7776 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7777 | /* Try to recover after the failure */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7778 | if (bnx2x_process_kill(bp, global)) { |
| 7779 | netdev_err(bp->dev, "Something bad had happen on engine %d! " |
| 7780 | "Aii!\n", BP_PATH(bp)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7781 | rc = -EAGAIN; |
| 7782 | goto exit_leader_reset; |
| 7783 | } |
| 7784 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7785 | /* |
| 7786 | * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver |
| 7787 | * state. |
| 7788 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7789 | bnx2x_set_reset_done(bp); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7790 | if (global) |
| 7791 | bnx2x_clear_reset_global(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7792 | |
| 7793 | exit_leader_reset: |
| 7794 | bp->is_leader = 0; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7795 | bnx2x_release_leader_lock(bp); |
| 7796 | smp_mb(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7797 | return rc; |
| 7798 | } |
| 7799 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7800 | static inline void bnx2x_recovery_failed(struct bnx2x *bp) |
| 7801 | { |
| 7802 | netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n"); |
| 7803 | |
| 7804 | /* Disconnect this device */ |
| 7805 | netif_device_detach(bp->dev); |
| 7806 | |
| 7807 | /* |
| 7808 | * Block ifup for all function on this engine until "process kill" |
| 7809 | * or power cycle. |
| 7810 | */ |
| 7811 | bnx2x_set_reset_in_progress(bp); |
| 7812 | |
| 7813 | /* Shut down the power */ |
| 7814 | bnx2x_set_power_state(bp, PCI_D3hot); |
| 7815 | |
| 7816 | bp->recovery_state = BNX2X_RECOVERY_FAILED; |
| 7817 | |
| 7818 | smp_mb(); |
| 7819 | } |
| 7820 | |
| 7821 | /* |
| 7822 | * Assumption: runs under rtnl lock. This together with the fact |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7823 | * that it's called only from bnx2x_reset_task() ensure that it |
| 7824 | * will never be called when netif_running(bp->dev) is false. |
| 7825 | */ |
| 7826 | static void bnx2x_parity_recover(struct bnx2x *bp) |
| 7827 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7828 | bool global = false; |
| 7829 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7830 | DP(NETIF_MSG_HW, "Handling parity\n"); |
| 7831 | while (1) { |
| 7832 | switch (bp->recovery_state) { |
| 7833 | case BNX2X_RECOVERY_INIT: |
| 7834 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n"); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7835 | bnx2x_chk_parity_attn(bp, &global, false); |
| 7836 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7837 | /* Try to get a LEADER_LOCK HW lock */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7838 | if (bnx2x_trylock_leader_lock(bp)) { |
| 7839 | bnx2x_set_reset_in_progress(bp); |
| 7840 | /* |
| 7841 | * Check if there is a global attention and if |
| 7842 | * there was a global attention, set the global |
| 7843 | * reset bit. |
| 7844 | */ |
| 7845 | |
| 7846 | if (global) |
| 7847 | bnx2x_set_reset_global(bp); |
| 7848 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7849 | bp->is_leader = 1; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7850 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7851 | |
| 7852 | /* Stop the driver */ |
| 7853 | /* If interface has been removed - break */ |
| 7854 | if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY)) |
| 7855 | return; |
| 7856 | |
| 7857 | bp->recovery_state = BNX2X_RECOVERY_WAIT; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7858 | |
| 7859 | /* |
| 7860 | * Reset MCP command sequence number and MCP mail box |
| 7861 | * sequence as we are going to reset the MCP. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7862 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7863 | if (global) { |
| 7864 | bp->fw_seq = 0; |
| 7865 | bp->fw_drv_pulse_wr_seq = 0; |
| 7866 | } |
| 7867 | |
| 7868 | /* Ensure "is_leader", MCP command sequence and |
| 7869 | * "recovery_state" update values are seen on other |
| 7870 | * CPUs. |
| 7871 | */ |
| 7872 | smp_mb(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7873 | break; |
| 7874 | |
| 7875 | case BNX2X_RECOVERY_WAIT: |
| 7876 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n"); |
| 7877 | if (bp->is_leader) { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7878 | int other_engine = BP_PATH(bp) ? 0 : 1; |
| 7879 | u32 other_load_counter = |
| 7880 | bnx2x_get_load_cnt(bp, other_engine); |
| 7881 | u32 load_counter = |
| 7882 | bnx2x_get_load_cnt(bp, BP_PATH(bp)); |
| 7883 | global = bnx2x_reset_is_global(bp); |
| 7884 | |
| 7885 | /* |
| 7886 | * In case of a parity in a global block, let |
| 7887 | * the first leader that performs a |
| 7888 | * leader_reset() reset the global blocks in |
| 7889 | * order to clear global attentions. Otherwise |
| 7890 | * the the gates will remain closed for that |
| 7891 | * engine. |
| 7892 | */ |
| 7893 | if (load_counter || |
| 7894 | (global && other_load_counter)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7895 | /* Wait until all other functions get |
| 7896 | * down. |
| 7897 | */ |
| 7898 | schedule_delayed_work(&bp->reset_task, |
| 7899 | HZ/10); |
| 7900 | return; |
| 7901 | } else { |
| 7902 | /* If all other functions got down - |
| 7903 | * try to bring the chip back to |
| 7904 | * normal. In any case it's an exit |
| 7905 | * point for a leader. |
| 7906 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7907 | if (bnx2x_leader_reset(bp)) { |
| 7908 | bnx2x_recovery_failed(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7909 | return; |
| 7910 | } |
| 7911 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7912 | /* If we are here, means that the |
| 7913 | * leader has succeeded and doesn't |
| 7914 | * want to be a leader any more. Try |
| 7915 | * to continue as a none-leader. |
| 7916 | */ |
| 7917 | break; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7918 | } |
| 7919 | } else { /* non-leader */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7920 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7921 | /* Try to get a LEADER_LOCK HW lock as |
| 7922 | * long as a former leader may have |
| 7923 | * been unloaded by the user or |
| 7924 | * released a leadership by another |
| 7925 | * reason. |
| 7926 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7927 | if (bnx2x_trylock_leader_lock(bp)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7928 | /* I'm a leader now! Restart a |
| 7929 | * switch case. |
| 7930 | */ |
| 7931 | bp->is_leader = 1; |
| 7932 | break; |
| 7933 | } |
| 7934 | |
| 7935 | schedule_delayed_work(&bp->reset_task, |
| 7936 | HZ/10); |
| 7937 | return; |
| 7938 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7939 | } else { |
| 7940 | /* |
| 7941 | * If there was a global attention, wait |
| 7942 | * for it to be cleared. |
| 7943 | */ |
| 7944 | if (bnx2x_reset_is_global(bp)) { |
| 7945 | schedule_delayed_work( |
| 7946 | &bp->reset_task, HZ/10); |
| 7947 | return; |
| 7948 | } |
| 7949 | |
| 7950 | if (bnx2x_nic_load(bp, LOAD_NORMAL)) |
| 7951 | bnx2x_recovery_failed(bp); |
| 7952 | else { |
| 7953 | bp->recovery_state = |
| 7954 | BNX2X_RECOVERY_DONE; |
| 7955 | smp_mb(); |
| 7956 | } |
| 7957 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7958 | return; |
| 7959 | } |
| 7960 | } |
| 7961 | default: |
| 7962 | return; |
| 7963 | } |
| 7964 | } |
| 7965 | } |
| 7966 | |
| 7967 | /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is |
| 7968 | * scheduled on a general queue in order to prevent a dead lock. |
| 7969 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7970 | static void bnx2x_reset_task(struct work_struct *work) |
| 7971 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7972 | struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7973 | |
| 7974 | #ifdef BNX2X_STOP_ON_ERROR |
| 7975 | BNX2X_ERR("reset task called but STOP_ON_ERROR defined" |
| 7976 | " so reset not done to allow debug dump,\n" |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7977 | KERN_ERR " you will need to reboot when done\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7978 | return; |
| 7979 | #endif |
| 7980 | |
| 7981 | rtnl_lock(); |
| 7982 | |
| 7983 | if (!netif_running(bp->dev)) |
| 7984 | goto reset_task_exit; |
| 7985 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7986 | if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) |
| 7987 | bnx2x_parity_recover(bp); |
| 7988 | else { |
| 7989 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 7990 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 7991 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7992 | |
| 7993 | reset_task_exit: |
| 7994 | rtnl_unlock(); |
| 7995 | } |
| 7996 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7997 | /* end of nic load/unload */ |
| 7998 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7999 | /* |
| 8000 | * Init service functions |
| 8001 | */ |
| 8002 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 8003 | static u32 bnx2x_get_pretend_reg(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8004 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8005 | u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 8006 | u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; |
| 8007 | return base + (BP_ABS_FUNC(bp)) * stride; |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8008 | } |
| 8009 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8010 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8011 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8012 | u32 reg = bnx2x_get_pretend_reg(bp); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8013 | |
| 8014 | /* Flush all outstanding writes */ |
| 8015 | mmiowb(); |
| 8016 | |
| 8017 | /* Pretend to be function 0 */ |
| 8018 | REG_WR(bp, reg, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8019 | REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */ |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8020 | |
| 8021 | /* From now we are in the "like-E1" mode */ |
| 8022 | bnx2x_int_disable(bp); |
| 8023 | |
| 8024 | /* Flush all outstanding writes */ |
| 8025 | mmiowb(); |
| 8026 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8027 | /* Restore the original function */ |
| 8028 | REG_WR(bp, reg, BP_ABS_FUNC(bp)); |
| 8029 | REG_RD(bp, reg); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8030 | } |
| 8031 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8032 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8033 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8034 | if (CHIP_IS_E1(bp)) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8035 | bnx2x_int_disable(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8036 | else |
| 8037 | bnx2x_undi_int_disable_e1h(bp); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8038 | } |
| 8039 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8040 | static void __devinit bnx2x_undi_unload(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8041 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8042 | u32 val; |
| 8043 | |
| 8044 | /* Check if there is any driver already loaded */ |
| 8045 | val = REG_RD(bp, MISC_REG_UNPREPARED); |
| 8046 | if (val == 0x1) { |
| 8047 | /* Check if it is the UNDI driver |
| 8048 | * UNDI driver initializes CID offset for normal bell to 0x7 |
| 8049 | */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8050 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8051 | val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); |
| 8052 | if (val == 0x7) { |
| 8053 | u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8054 | /* save our pf_num */ |
| 8055 | int orig_pf_num = bp->pf_num; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8056 | int port; |
| 8057 | u32 swap_en, swap_val, value; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8058 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8059 | /* clear the UNDI indication */ |
| 8060 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); |
| 8061 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8062 | BNX2X_DEV_INFO("UNDI is active! reset device\n"); |
| 8063 | |
| 8064 | /* try unload UNDI on port 0 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8065 | bp->pf_num = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8066 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8067 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8068 | DRV_MSG_SEQ_NUMBER_MASK); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8069 | reset_code = bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8070 | |
| 8071 | /* if UNDI is loaded on the other port */ |
| 8072 | if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) { |
| 8073 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8074 | /* send "DONE" for previous unload */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8075 | bnx2x_fw_command(bp, |
| 8076 | DRV_MSG_CODE_UNLOAD_DONE, 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8077 | |
| 8078 | /* unload UNDI on port 1 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8079 | bp->pf_num = 1; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8080 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8081 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8082 | DRV_MSG_SEQ_NUMBER_MASK); |
| 8083 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8084 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8085 | bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8086 | } |
| 8087 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8088 | /* now it's safe to release the lock */ |
| 8089 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
| 8090 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8091 | bnx2x_undi_int_disable(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8092 | port = BP_PORT(bp); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8093 | |
| 8094 | /* close input traffic and wait for it */ |
| 8095 | /* Do not rcv packets to BRB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8096 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK : |
| 8097 | NIG_REG_LLH0_BRB1_DRV_MASK), 0x0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8098 | /* Do not direct rcv packets that are not for MCP to |
| 8099 | * the BRB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8100 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 8101 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8102 | /* clear AEU */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8103 | REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 8104 | MISC_REG_AEU_MASK_ATTN_FUNC_0), 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8105 | msleep(10); |
| 8106 | |
| 8107 | /* save NIG port swap info */ |
| 8108 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 8109 | swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8110 | /* reset device */ |
| 8111 | REG_WR(bp, |
| 8112 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8113 | 0xd3ffffff); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8114 | |
| 8115 | value = 0x1400; |
| 8116 | if (CHIP_IS_E3(bp)) { |
| 8117 | value |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 8118 | value |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 8119 | } |
| 8120 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8121 | REG_WR(bp, |
| 8122 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8123 | value); |
| 8124 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8125 | /* take the NIG out of reset and restore swap values */ |
| 8126 | REG_WR(bp, |
| 8127 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 8128 | MISC_REGISTERS_RESET_REG_1_RST_NIG); |
| 8129 | REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); |
| 8130 | REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en); |
| 8131 | |
| 8132 | /* send unload done to the MCP */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8133 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8134 | |
| 8135 | /* restore our func and fw_seq */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8136 | bp->pf_num = orig_pf_num; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8137 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8138 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8139 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8140 | } else |
| 8141 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8142 | } |
| 8143 | } |
| 8144 | |
| 8145 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) |
| 8146 | { |
| 8147 | u32 val, val2, val3, val4, id; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8148 | u16 pmc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8149 | |
| 8150 | /* Get the chip revision id and number. */ |
| 8151 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ |
| 8152 | val = REG_RD(bp, MISC_REG_CHIP_NUM); |
| 8153 | id = ((val & 0xffff) << 16); |
| 8154 | val = REG_RD(bp, MISC_REG_CHIP_REV); |
| 8155 | id |= ((val & 0xf) << 12); |
| 8156 | val = REG_RD(bp, MISC_REG_CHIP_METAL); |
| 8157 | id |= ((val & 0xff) << 4); |
Eilon Greenstein | 5a40e08 | 2009-01-14 06:44:04 +0000 | [diff] [blame] | 8158 | val = REG_RD(bp, MISC_REG_BOND_ID); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8159 | id |= (val & 0xf); |
| 8160 | bp->common.chip_id = id; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8161 | |
| 8162 | /* Set doorbell size */ |
| 8163 | bp->db_size = (1 << BNX2X_DB_SHIFT); |
| 8164 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8165 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8166 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR); |
| 8167 | if ((val & 1) == 0) |
| 8168 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN); |
| 8169 | else |
| 8170 | val = (val >> 1) & 1; |
| 8171 | BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" : |
| 8172 | "2_PORT_MODE"); |
| 8173 | bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE : |
| 8174 | CHIP_2_PORT_MODE; |
| 8175 | |
| 8176 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 8177 | bp->pfid = (bp->pf_num >> 1); /* 0..3 */ |
| 8178 | else |
| 8179 | bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */ |
| 8180 | } else { |
| 8181 | bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */ |
| 8182 | bp->pfid = bp->pf_num; /* 0..7 */ |
| 8183 | } |
| 8184 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8185 | bp->link_params.chip_id = bp->common.chip_id; |
| 8186 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8187 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 8188 | val = (REG_RD(bp, 0x2874) & 0x55); |
| 8189 | if ((bp->common.chip_id & 0x1) || |
| 8190 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { |
| 8191 | bp->flags |= ONE_PORT_FLAG; |
| 8192 | BNX2X_DEV_INFO("single port device\n"); |
| 8193 | } |
| 8194 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8195 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
| 8196 | bp->common.flash_size = (NVRAM_1MB_SIZE << |
| 8197 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
| 8198 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", |
| 8199 | bp->common.flash_size, bp->common.flash_size); |
| 8200 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 8201 | bnx2x_init_shmem(bp); |
| 8202 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8203 | |
| 8204 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8205 | bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ? |
| 8206 | MISC_REG_GENERIC_CR_1 : |
| 8207 | MISC_REG_GENERIC_CR_0)); |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 8208 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8209 | bp->link_params.shmem_base = bp->common.shmem_base; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8210 | bp->link_params.shmem2_base = bp->common.shmem2_base; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8211 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
| 8212 | bp->common.shmem_base, bp->common.shmem2_base); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8213 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8214 | if (!bp->common.shmem_base) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8215 | BNX2X_DEV_INFO("MCP not active\n"); |
| 8216 | bp->flags |= NO_MCP_FLAG; |
| 8217 | return; |
| 8218 | } |
| 8219 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8220 | bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config); |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 8221 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8222 | |
| 8223 | bp->link_params.hw_led_mode = ((bp->common.hw_config & |
| 8224 | SHARED_HW_CFG_LED_MODE_MASK) >> |
| 8225 | SHARED_HW_CFG_LED_MODE_SHIFT); |
| 8226 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8227 | bp->link_params.feature_config_flags = 0; |
| 8228 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); |
| 8229 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) |
| 8230 | bp->link_params.feature_config_flags |= |
| 8231 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8232 | else |
| 8233 | bp->link_params.feature_config_flags &= |
| 8234 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8235 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8236 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
| 8237 | bp->common.bc_ver = val; |
| 8238 | BNX2X_DEV_INFO("bc_ver %X\n", val); |
| 8239 | if (val < BNX2X_BC_VER) { |
| 8240 | /* for now only warn |
| 8241 | * later we might need to enforce this */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8242 | BNX2X_ERR("This driver needs bc_ver %X but found %X, " |
| 8243 | "please upgrade BC\n", BNX2X_BC_VER, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8244 | } |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8245 | bp->link_params.feature_config_flags |= |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8246 | (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ? |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8247 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
| 8248 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8249 | bp->link_params.feature_config_flags |= |
| 8250 | (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ? |
| 8251 | FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8252 | |
Dmitry Kravkov | f9a3ebb | 2011-05-04 23:49:11 +0000 | [diff] [blame] | 8253 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
| 8254 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
| 8255 | |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8256 | BNX2X_DEV_INFO("%sWoL capable\n", |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 8257 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8258 | |
| 8259 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); |
| 8260 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); |
| 8261 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); |
| 8262 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); |
| 8263 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8264 | dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n", |
| 8265 | val, val2, val3, val4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8266 | } |
| 8267 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8268 | #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) |
| 8269 | #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) |
| 8270 | |
| 8271 | static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp) |
| 8272 | { |
| 8273 | int pfid = BP_FUNC(bp); |
| 8274 | int vn = BP_E1HVN(bp); |
| 8275 | int igu_sb_id; |
| 8276 | u32 val; |
| 8277 | u8 fid; |
| 8278 | |
| 8279 | bp->igu_base_sb = 0xff; |
| 8280 | bp->igu_sb_cnt = 0; |
| 8281 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 8282 | bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x, |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8283 | NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8284 | |
| 8285 | bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) * |
| 8286 | FP_SB_MAX_E1x; |
| 8287 | |
| 8288 | bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x + |
| 8289 | (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn); |
| 8290 | |
| 8291 | return; |
| 8292 | } |
| 8293 | |
| 8294 | /* IGU in normal mode - read CAM */ |
| 8295 | for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; |
| 8296 | igu_sb_id++) { |
| 8297 | val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); |
| 8298 | if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) |
| 8299 | continue; |
| 8300 | fid = IGU_FID(val); |
| 8301 | if ((fid & IGU_FID_ENCODE_IS_PF)) { |
| 8302 | if ((fid & IGU_FID_PF_NUM_MASK) != pfid) |
| 8303 | continue; |
| 8304 | if (IGU_VEC(val) == 0) |
| 8305 | /* default status block */ |
| 8306 | bp->igu_dsb_id = igu_sb_id; |
| 8307 | else { |
| 8308 | if (bp->igu_base_sb == 0xff) |
| 8309 | bp->igu_base_sb = igu_sb_id; |
| 8310 | bp->igu_sb_cnt++; |
| 8311 | } |
| 8312 | } |
| 8313 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8314 | |
| 8315 | /* It's expected that number of CAM entries for this |
| 8316 | * functions is equal to the MSI-X table size (which was a |
| 8317 | * used during bp->l2_cid_count value calculation. |
| 8318 | * We want a harsh warning if these values are different! |
| 8319 | */ |
| 8320 | WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
| 8321 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8322 | if (bp->igu_sb_cnt == 0) |
| 8323 | BNX2X_ERR("CAM configuration error\n"); |
| 8324 | } |
| 8325 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8326 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
| 8327 | u32 switch_cfg) |
| 8328 | { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8329 | int cfg_size = 0, idx, port = BP_PORT(bp); |
| 8330 | |
| 8331 | /* Aggregation of supported attributes of all external phys */ |
| 8332 | bp->port.supported[0] = 0; |
| 8333 | bp->port.supported[1] = 0; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8334 | switch (bp->link_params.num_phys) { |
| 8335 | case 1: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8336 | bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported; |
| 8337 | cfg_size = 1; |
| 8338 | break; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8339 | case 2: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8340 | bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported; |
| 8341 | cfg_size = 1; |
| 8342 | break; |
| 8343 | case 3: |
| 8344 | if (bp->link_params.multi_phy_config & |
| 8345 | PORT_HW_CFG_PHY_SWAPPED_ENABLED) { |
| 8346 | bp->port.supported[1] = |
| 8347 | bp->link_params.phy[EXT_PHY1].supported; |
| 8348 | bp->port.supported[0] = |
| 8349 | bp->link_params.phy[EXT_PHY2].supported; |
| 8350 | } else { |
| 8351 | bp->port.supported[0] = |
| 8352 | bp->link_params.phy[EXT_PHY1].supported; |
| 8353 | bp->port.supported[1] = |
| 8354 | bp->link_params.phy[EXT_PHY2].supported; |
| 8355 | } |
| 8356 | cfg_size = 2; |
| 8357 | break; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8358 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8359 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8360 | if (!(bp->port.supported[0] || bp->port.supported[1])) { |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8361 | BNX2X_ERR("NVRAM config error. BAD phy config." |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8362 | "PHY1 config 0x%x, PHY2 config 0x%x\n", |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8363 | SHMEM_RD(bp, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8364 | dev_info.port_hw_config[port].external_phy_config), |
| 8365 | SHMEM_RD(bp, |
| 8366 | dev_info.port_hw_config[port].external_phy_config2)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8367 | return; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8368 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8369 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8370 | if (CHIP_IS_E3(bp)) |
| 8371 | bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR); |
| 8372 | else { |
| 8373 | switch (switch_cfg) { |
| 8374 | case SWITCH_CFG_1G: |
| 8375 | bp->port.phy_addr = REG_RD( |
| 8376 | bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); |
| 8377 | break; |
| 8378 | case SWITCH_CFG_10G: |
| 8379 | bp->port.phy_addr = REG_RD( |
| 8380 | bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); |
| 8381 | break; |
| 8382 | default: |
| 8383 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", |
| 8384 | bp->port.link_config[0]); |
| 8385 | return; |
| 8386 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8387 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8388 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8389 | /* mask what we support according to speed_cap_mask per configuration */ |
| 8390 | for (idx = 0; idx < cfg_size; idx++) { |
| 8391 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8392 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8393 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8394 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8395 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8396 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8397 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8398 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8399 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8400 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8401 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8402 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8403 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8404 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8405 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8406 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8407 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8408 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8409 | bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8410 | SUPPORTED_1000baseT_Full); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8411 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8412 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8413 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8414 | bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8415 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8416 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8417 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8418 | bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8419 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8420 | } |
| 8421 | |
| 8422 | BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0], |
| 8423 | bp->port.supported[1]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8424 | } |
| 8425 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8426 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8427 | { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8428 | u32 link_config, idx, cfg_size = 0; |
| 8429 | bp->port.advertising[0] = 0; |
| 8430 | bp->port.advertising[1] = 0; |
| 8431 | switch (bp->link_params.num_phys) { |
| 8432 | case 1: |
| 8433 | case 2: |
| 8434 | cfg_size = 1; |
| 8435 | break; |
| 8436 | case 3: |
| 8437 | cfg_size = 2; |
| 8438 | break; |
| 8439 | } |
| 8440 | for (idx = 0; idx < cfg_size; idx++) { |
| 8441 | bp->link_params.req_duplex[idx] = DUPLEX_FULL; |
| 8442 | link_config = bp->port.link_config[idx]; |
| 8443 | switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8444 | case PORT_FEATURE_LINK_SPEED_AUTO: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8445 | if (bp->port.supported[idx] & SUPPORTED_Autoneg) { |
| 8446 | bp->link_params.req_line_speed[idx] = |
| 8447 | SPEED_AUTO_NEG; |
| 8448 | bp->port.advertising[idx] |= |
| 8449 | bp->port.supported[idx]; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8450 | } else { |
| 8451 | /* force 10G, no AN */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8452 | bp->link_params.req_line_speed[idx] = |
| 8453 | SPEED_10000; |
| 8454 | bp->port.advertising[idx] |= |
| 8455 | (ADVERTISED_10000baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8456 | ADVERTISED_FIBRE); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8457 | continue; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8458 | } |
| 8459 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8460 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8461 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8462 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) { |
| 8463 | bp->link_params.req_line_speed[idx] = |
| 8464 | SPEED_10; |
| 8465 | bp->port.advertising[idx] |= |
| 8466 | (ADVERTISED_10baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8467 | ADVERTISED_TP); |
| 8468 | } else { |
| 8469 | BNX2X_ERROR("NVRAM config error. " |
| 8470 | "Invalid link_config 0x%x" |
| 8471 | " speed_cap_mask 0x%x\n", |
| 8472 | link_config, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8473 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8474 | return; |
| 8475 | } |
| 8476 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8477 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8478 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8479 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) { |
| 8480 | bp->link_params.req_line_speed[idx] = |
| 8481 | SPEED_10; |
| 8482 | bp->link_params.req_duplex[idx] = |
| 8483 | DUPLEX_HALF; |
| 8484 | bp->port.advertising[idx] |= |
| 8485 | (ADVERTISED_10baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8486 | ADVERTISED_TP); |
| 8487 | } else { |
| 8488 | BNX2X_ERROR("NVRAM config error. " |
| 8489 | "Invalid link_config 0x%x" |
| 8490 | " speed_cap_mask 0x%x\n", |
| 8491 | link_config, |
| 8492 | bp->link_params.speed_cap_mask[idx]); |
| 8493 | return; |
| 8494 | } |
| 8495 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8496 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8497 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
| 8498 | if (bp->port.supported[idx] & |
| 8499 | SUPPORTED_100baseT_Full) { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8500 | bp->link_params.req_line_speed[idx] = |
| 8501 | SPEED_100; |
| 8502 | bp->port.advertising[idx] |= |
| 8503 | (ADVERTISED_100baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8504 | ADVERTISED_TP); |
| 8505 | } else { |
| 8506 | BNX2X_ERROR("NVRAM config error. " |
| 8507 | "Invalid link_config 0x%x" |
| 8508 | " speed_cap_mask 0x%x\n", |
| 8509 | link_config, |
| 8510 | bp->link_params.speed_cap_mask[idx]); |
| 8511 | return; |
| 8512 | } |
| 8513 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8514 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8515 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
| 8516 | if (bp->port.supported[idx] & |
| 8517 | SUPPORTED_100baseT_Half) { |
| 8518 | bp->link_params.req_line_speed[idx] = |
| 8519 | SPEED_100; |
| 8520 | bp->link_params.req_duplex[idx] = |
| 8521 | DUPLEX_HALF; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8522 | bp->port.advertising[idx] |= |
| 8523 | (ADVERTISED_100baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8524 | ADVERTISED_TP); |
| 8525 | } else { |
| 8526 | BNX2X_ERROR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8527 | "Invalid link_config 0x%x" |
| 8528 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8529 | link_config, |
| 8530 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8531 | return; |
| 8532 | } |
| 8533 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8534 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8535 | case PORT_FEATURE_LINK_SPEED_1G: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8536 | if (bp->port.supported[idx] & |
| 8537 | SUPPORTED_1000baseT_Full) { |
| 8538 | bp->link_params.req_line_speed[idx] = |
| 8539 | SPEED_1000; |
| 8540 | bp->port.advertising[idx] |= |
| 8541 | (ADVERTISED_1000baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8542 | ADVERTISED_TP); |
| 8543 | } else { |
| 8544 | BNX2X_ERROR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8545 | "Invalid link_config 0x%x" |
| 8546 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8547 | link_config, |
| 8548 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8549 | return; |
| 8550 | } |
| 8551 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8552 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8553 | case PORT_FEATURE_LINK_SPEED_2_5G: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8554 | if (bp->port.supported[idx] & |
| 8555 | SUPPORTED_2500baseX_Full) { |
| 8556 | bp->link_params.req_line_speed[idx] = |
| 8557 | SPEED_2500; |
| 8558 | bp->port.advertising[idx] |= |
| 8559 | (ADVERTISED_2500baseX_Full | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8560 | ADVERTISED_TP); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8561 | } else { |
| 8562 | BNX2X_ERROR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8563 | "Invalid link_config 0x%x" |
| 8564 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8565 | link_config, |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8566 | bp->link_params.speed_cap_mask[idx]); |
| 8567 | return; |
| 8568 | } |
| 8569 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8570 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8571 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8572 | if (bp->port.supported[idx] & |
| 8573 | SUPPORTED_10000baseT_Full) { |
| 8574 | bp->link_params.req_line_speed[idx] = |
| 8575 | SPEED_10000; |
| 8576 | bp->port.advertising[idx] |= |
| 8577 | (ADVERTISED_10000baseT_Full | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8578 | ADVERTISED_FIBRE); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8579 | } else { |
| 8580 | BNX2X_ERROR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8581 | "Invalid link_config 0x%x" |
| 8582 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8583 | link_config, |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8584 | bp->link_params.speed_cap_mask[idx]); |
| 8585 | return; |
| 8586 | } |
| 8587 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8588 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8589 | default: |
| 8590 | BNX2X_ERROR("NVRAM config error. " |
| 8591 | "BAD link speed link_config 0x%x\n", |
| 8592 | link_config); |
| 8593 | bp->link_params.req_line_speed[idx] = |
| 8594 | SPEED_AUTO_NEG; |
| 8595 | bp->port.advertising[idx] = |
| 8596 | bp->port.supported[idx]; |
| 8597 | break; |
| 8598 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8599 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8600 | bp->link_params.req_flow_ctrl[idx] = (link_config & |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8601 | PORT_FEATURE_FLOW_CONTROL_MASK); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8602 | if ((bp->link_params.req_flow_ctrl[idx] == |
| 8603 | BNX2X_FLOW_CTRL_AUTO) && |
| 8604 | !(bp->port.supported[idx] & SUPPORTED_Autoneg)) { |
| 8605 | bp->link_params.req_flow_ctrl[idx] = |
| 8606 | BNX2X_FLOW_CTRL_NONE; |
| 8607 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8608 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8609 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl" |
| 8610 | " 0x%x advertising 0x%x\n", |
| 8611 | bp->link_params.req_line_speed[idx], |
| 8612 | bp->link_params.req_duplex[idx], |
| 8613 | bp->link_params.req_flow_ctrl[idx], |
| 8614 | bp->port.advertising[idx]); |
| 8615 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8616 | } |
| 8617 | |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 8618 | static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi) |
| 8619 | { |
| 8620 | mac_hi = cpu_to_be16(mac_hi); |
| 8621 | mac_lo = cpu_to_be32(mac_lo); |
| 8622 | memcpy(mac_buf, &mac_hi, sizeof(mac_hi)); |
| 8623 | memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo)); |
| 8624 | } |
| 8625 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8626 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8627 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8628 | int port = BP_PORT(bp); |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8629 | u32 config; |
Joe Perches | 6f38ad9 | 2010-11-14 17:04:31 +0000 | [diff] [blame] | 8630 | u32 ext_phy_type, ext_phy_config; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8631 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8632 | bp->link_params.bp = bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8633 | bp->link_params.port = port; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8634 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8635 | bp->link_params.lane_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8636 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8637 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8638 | bp->link_params.speed_cap_mask[0] = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8639 | SHMEM_RD(bp, |
| 8640 | dev_info.port_hw_config[port].speed_capability_mask); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8641 | bp->link_params.speed_cap_mask[1] = |
| 8642 | SHMEM_RD(bp, |
| 8643 | dev_info.port_hw_config[port].speed_capability_mask2); |
| 8644 | bp->port.link_config[0] = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8645 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
| 8646 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8647 | bp->port.link_config[1] = |
| 8648 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2); |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8649 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8650 | bp->link_params.multi_phy_config = |
| 8651 | SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config); |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8652 | /* If the device is capable of WoL, set the default state according |
| 8653 | * to the HW |
| 8654 | */ |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8655 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8656 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
| 8657 | (config & PORT_FEATURE_WOL_ENABLED)); |
| 8658 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8659 | BNX2X_DEV_INFO("lane_config 0x%08x " |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8660 | "speed_cap_mask0 0x%08x link_config0 0x%08x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8661 | bp->link_params.lane_config, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8662 | bp->link_params.speed_cap_mask[0], |
| 8663 | bp->port.link_config[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8664 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8665 | bp->link_params.switch_cfg = (bp->port.link_config[0] & |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8666 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8667 | bnx2x_phy_probe(&bp->link_params); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8668 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8669 | |
| 8670 | bnx2x_link_settings_requested(bp); |
| 8671 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8672 | /* |
| 8673 | * If connected directly, work with the internal PHY, otherwise, work |
| 8674 | * with the external PHY |
| 8675 | */ |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8676 | ext_phy_config = |
| 8677 | SHMEM_RD(bp, |
| 8678 | dev_info.port_hw_config[port].external_phy_config); |
| 8679 | ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8680 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8681 | bp->mdio.prtad = bp->port.phy_addr; |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8682 | |
| 8683 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && |
| 8684 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) |
| 8685 | bp->mdio.prtad = |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8686 | XGXS_EXT_PHY_ADDR(ext_phy_config); |
Yaniv Rosner | 5866df6 | 2011-01-30 04:15:07 +0000 | [diff] [blame] | 8687 | |
| 8688 | /* |
| 8689 | * Check if hw lock is required to access MDC/MDIO bus to the PHY(s) |
| 8690 | * In MF mode, it is set to cover self test cases |
| 8691 | */ |
| 8692 | if (IS_MF(bp)) |
| 8693 | bp->port.need_hw_lock = 1; |
| 8694 | else |
| 8695 | bp->port.need_hw_lock = bnx2x_hw_lock_required(bp, |
| 8696 | bp->common.shmem_base, |
| 8697 | bp->common.shmem2_base); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8698 | } |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8699 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8700 | #ifdef BCM_CNIC |
| 8701 | static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp) |
| 8702 | { |
| 8703 | u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
| 8704 | drv_lic_key[BP_PORT(bp)].max_iscsi_conn); |
| 8705 | u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
| 8706 | drv_lic_key[BP_PORT(bp)].max_fcoe_conn); |
| 8707 | |
| 8708 | /* Get the number of maximum allowed iSCSI and FCoE connections */ |
| 8709 | bp->cnic_eth_dev.max_iscsi_conn = |
| 8710 | (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >> |
| 8711 | BNX2X_MAX_ISCSI_INIT_CONN_SHIFT; |
| 8712 | |
| 8713 | bp->cnic_eth_dev.max_fcoe_conn = |
| 8714 | (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >> |
| 8715 | BNX2X_MAX_FCOE_INIT_CONN_SHIFT; |
| 8716 | |
| 8717 | BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n", |
| 8718 | bp->cnic_eth_dev.max_iscsi_conn, |
| 8719 | bp->cnic_eth_dev.max_fcoe_conn); |
| 8720 | |
| 8721 | /* If mamimum allowed number of connections is zero - |
| 8722 | * disable the feature. |
| 8723 | */ |
| 8724 | if (!bp->cnic_eth_dev.max_iscsi_conn) |
| 8725 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
| 8726 | |
| 8727 | if (!bp->cnic_eth_dev.max_fcoe_conn) |
| 8728 | bp->flags |= NO_FCOE_FLAG; |
| 8729 | } |
| 8730 | #endif |
| 8731 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8732 | static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp) |
| 8733 | { |
| 8734 | u32 val, val2; |
| 8735 | int func = BP_ABS_FUNC(bp); |
| 8736 | int port = BP_PORT(bp); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8737 | #ifdef BCM_CNIC |
| 8738 | u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac; |
| 8739 | u8 *fip_mac = bp->fip_mac; |
| 8740 | #endif |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8741 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8742 | /* Zero primary MAC configuration */ |
| 8743 | memset(bp->dev->dev_addr, 0, ETH_ALEN); |
| 8744 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8745 | if (BP_NOMCP(bp)) { |
| 8746 | BNX2X_ERROR("warning: random MAC workaround active\n"); |
| 8747 | random_ether_addr(bp->dev->dev_addr); |
| 8748 | } else if (IS_MF(bp)) { |
| 8749 | val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); |
| 8750 | val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); |
| 8751 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && |
| 8752 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) |
| 8753 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); |
| 8754 | |
| 8755 | #ifdef BCM_CNIC |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8756 | /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or |
| 8757 | * FCoE MAC then the appropriate feature should be disabled. |
| 8758 | */ |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8759 | if (IS_MF_SI(bp)) { |
| 8760 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); |
| 8761 | if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { |
| 8762 | val2 = MF_CFG_RD(bp, func_ext_config[func]. |
| 8763 | iscsi_mac_addr_upper); |
| 8764 | val = MF_CFG_RD(bp, func_ext_config[func]. |
| 8765 | iscsi_mac_addr_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8766 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8767 | BNX2X_DEV_INFO("Read iSCSI MAC: " |
| 8768 | BNX2X_MAC_FMT"\n", |
| 8769 | BNX2X_MAC_PRN_LIST(iscsi_mac)); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8770 | } else |
| 8771 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
| 8772 | |
| 8773 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { |
| 8774 | val2 = MF_CFG_RD(bp, func_ext_config[func]. |
| 8775 | fcoe_mac_addr_upper); |
| 8776 | val = MF_CFG_RD(bp, func_ext_config[func]. |
| 8777 | fcoe_mac_addr_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8778 | bnx2x_set_mac_buf(fip_mac, val, val2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8779 | BNX2X_DEV_INFO("Read FCoE L2 MAC to " |
| 8780 | BNX2X_MAC_FMT"\n", |
| 8781 | BNX2X_MAC_PRN_LIST(fip_mac)); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8782 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8783 | } else |
| 8784 | bp->flags |= NO_FCOE_FLAG; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8785 | } |
| 8786 | #endif |
| 8787 | } else { |
| 8788 | /* in SF read MACs from port configuration */ |
| 8789 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); |
| 8790 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); |
| 8791 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); |
| 8792 | |
| 8793 | #ifdef BCM_CNIC |
| 8794 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
| 8795 | iscsi_mac_upper); |
| 8796 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
| 8797 | iscsi_mac_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8798 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8799 | #endif |
| 8800 | } |
| 8801 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8802 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8803 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 8804 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8805 | #ifdef BCM_CNIC |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8806 | /* Set the FCoE MAC in modes other then MF_SI */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8807 | if (!CHIP_IS_E1x(bp)) { |
| 8808 | if (IS_MF_SD(bp)) |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8809 | memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN); |
| 8810 | else if (!IS_MF(bp)) |
| 8811 | memcpy(fip_mac, iscsi_mac, ETH_ALEN); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8812 | } |
Dmitry Kravkov | 426b924 | 2011-05-04 23:49:53 +0000 | [diff] [blame] | 8813 | |
| 8814 | /* Disable iSCSI if MAC configuration is |
| 8815 | * invalid. |
| 8816 | */ |
| 8817 | if (!is_valid_ether_addr(iscsi_mac)) { |
| 8818 | bp->flags |= NO_ISCSI_FLAG; |
| 8819 | memset(iscsi_mac, 0, ETH_ALEN); |
| 8820 | } |
| 8821 | |
| 8822 | /* Disable FCoE if MAC configuration is |
| 8823 | * invalid. |
| 8824 | */ |
| 8825 | if (!is_valid_ether_addr(fip_mac)) { |
| 8826 | bp->flags |= NO_FCOE_FLAG; |
| 8827 | memset(bp->fip_mac, 0, ETH_ALEN); |
| 8828 | } |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8829 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8830 | |
| 8831 | if (!is_valid_ether_addr(bp->dev->dev_addr)) |
| 8832 | dev_err(&bp->pdev->dev, |
| 8833 | "bad Ethernet MAC address configuration: " |
| 8834 | BNX2X_MAC_FMT", change it manually before bringing up " |
| 8835 | "the appropriate network interface\n", |
| 8836 | BNX2X_MAC_PRN_LIST(bp->dev->dev_addr)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8837 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8838 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8839 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) |
| 8840 | { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8841 | int /*abs*/func = BP_ABS_FUNC(bp); |
David S. Miller | b8ee832 | 2011-04-17 16:56:12 -0700 | [diff] [blame] | 8842 | int vn; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8843 | u32 val = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8844 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8845 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8846 | bnx2x_get_common_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8847 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8848 | if (CHIP_IS_E1x(bp)) { |
| 8849 | bp->common.int_block = INT_BLOCK_HC; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8850 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8851 | bp->igu_dsb_id = DEF_SB_IGU_ID; |
| 8852 | bp->igu_base_sb = 0; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8853 | bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x, |
| 8854 | NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8855 | } else { |
| 8856 | bp->common.int_block = INT_BLOCK_IGU; |
| 8857 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8858 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8859 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8860 | int tout = 5000; |
| 8861 | |
| 8862 | BNX2X_DEV_INFO("FORCING Normal Mode\n"); |
| 8863 | |
| 8864 | val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); |
| 8865 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val); |
| 8866 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f); |
| 8867 | |
| 8868 | while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) { |
| 8869 | tout--; |
| 8870 | usleep_range(1000, 1000); |
| 8871 | } |
| 8872 | |
| 8873 | if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) { |
| 8874 | dev_err(&bp->pdev->dev, |
| 8875 | "FORCING Normal Mode failed!!!\n"); |
| 8876 | return -EPERM; |
| 8877 | } |
| 8878 | } |
| 8879 | |
| 8880 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
| 8881 | BNX2X_DEV_INFO("IGU Backward Compatible Mode\n"); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8882 | bp->common.int_block |= INT_BLOCK_MODE_BW_COMP; |
| 8883 | } else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8884 | BNX2X_DEV_INFO("IGU Normal Mode\n"); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8885 | |
| 8886 | bnx2x_get_igu_cam_info(bp); |
| 8887 | |
| 8888 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8889 | |
| 8890 | /* |
| 8891 | * set base FW non-default (fast path) status block id, this value is |
| 8892 | * used to initialize the fw_sb_id saved on the fp/queue structure to |
| 8893 | * determine the id used by the FW. |
| 8894 | */ |
| 8895 | if (CHIP_IS_E1x(bp)) |
| 8896 | bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp); |
| 8897 | else /* |
| 8898 | * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of |
| 8899 | * the same queue are indicated on the same IGU SB). So we prefer |
| 8900 | * FW and IGU SBs to be the same value. |
| 8901 | */ |
| 8902 | bp->base_fw_ndsb = bp->igu_base_sb; |
| 8903 | |
| 8904 | BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n" |
| 8905 | "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb, |
| 8906 | bp->igu_sb_cnt, bp->base_fw_ndsb); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8907 | |
| 8908 | /* |
| 8909 | * Initialize MF configuration |
| 8910 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8911 | |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8912 | bp->mf_ov = 0; |
| 8913 | bp->mf_mode = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8914 | vn = BP_E1HVN(bp); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8915 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8916 | if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8917 | BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n", |
| 8918 | bp->common.shmem2_base, SHMEM2_RD(bp, size), |
| 8919 | (u32)offsetof(struct shmem2_region, mf_cfg_addr)); |
| 8920 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8921 | if (SHMEM2_HAS(bp, mf_cfg_addr)) |
| 8922 | bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr); |
| 8923 | else |
| 8924 | bp->common.mf_cfg_base = bp->common.shmem_base + |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8925 | offsetof(struct shmem_region, func_mb) + |
| 8926 | E1H_FUNC_MAX * sizeof(struct drv_func_mb); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8927 | /* |
| 8928 | * get mf configuration: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8929 | * 1. existence of MF configuration |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8930 | * 2. MAC address must be legal (check only upper bytes) |
| 8931 | * for Switch-Independent mode; |
| 8932 | * OVLAN must be legal for Switch-Dependent mode |
| 8933 | * 3. SF_MODE configures specific MF mode |
| 8934 | */ |
| 8935 | if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { |
| 8936 | /* get mf configuration */ |
| 8937 | val = SHMEM_RD(bp, |
| 8938 | dev_info.shared_feature_config.config); |
| 8939 | val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8940 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8941 | switch (val) { |
| 8942 | case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: |
| 8943 | val = MF_CFG_RD(bp, func_mf_config[func]. |
| 8944 | mac_upper); |
| 8945 | /* check for legal mac (upper bytes)*/ |
| 8946 | if (val != 0xffff) { |
| 8947 | bp->mf_mode = MULTI_FUNCTION_SI; |
| 8948 | bp->mf_config[vn] = MF_CFG_RD(bp, |
| 8949 | func_mf_config[func].config); |
| 8950 | } else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8951 | BNX2X_DEV_INFO("illegal MAC address " |
| 8952 | "for SI\n"); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8953 | break; |
| 8954 | case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: |
| 8955 | /* get OV configuration */ |
| 8956 | val = MF_CFG_RD(bp, |
| 8957 | func_mf_config[FUNC_0].e1hov_tag); |
| 8958 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; |
| 8959 | |
| 8960 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
| 8961 | bp->mf_mode = MULTI_FUNCTION_SD; |
| 8962 | bp->mf_config[vn] = MF_CFG_RD(bp, |
| 8963 | func_mf_config[func].config); |
| 8964 | } else |
| 8965 | DP(NETIF_MSG_PROBE, "illegal OV for " |
| 8966 | "SD\n"); |
| 8967 | break; |
| 8968 | default: |
| 8969 | /* Unknown configuration: reset mf_config */ |
| 8970 | bp->mf_config[vn] = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8971 | DP(NETIF_MSG_PROBE, "Unknown MF mode 0x%x\n", |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8972 | val); |
| 8973 | } |
| 8974 | } |
| 8975 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8976 | BNX2X_DEV_INFO("%s function mode\n", |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8977 | IS_MF(bp) ? "multi" : "single"); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8978 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8979 | switch (bp->mf_mode) { |
| 8980 | case MULTI_FUNCTION_SD: |
| 8981 | val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & |
| 8982 | FUNC_MF_CFG_E1HOV_TAG_MASK; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8983 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8984 | bp->mf_ov = val; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8985 | bp->path_has_ovlan = true; |
| 8986 | |
| 8987 | BNX2X_DEV_INFO("MF OV for func %d is %d " |
| 8988 | "(0x%04x)\n", func, bp->mf_ov, |
| 8989 | bp->mf_ov); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8990 | } else { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8991 | dev_err(&bp->pdev->dev, |
| 8992 | "No valid MF OV for func %d, " |
| 8993 | "aborting\n", func); |
| 8994 | return -EPERM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8995 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8996 | break; |
| 8997 | case MULTI_FUNCTION_SI: |
| 8998 | BNX2X_DEV_INFO("func %d is in MF " |
| 8999 | "switch-independent mode\n", func); |
| 9000 | break; |
| 9001 | default: |
| 9002 | if (vn) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9003 | dev_err(&bp->pdev->dev, |
| 9004 | "VN %d is in a single function mode, " |
| 9005 | "aborting\n", vn); |
| 9006 | return -EPERM; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 9007 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9008 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9009 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9010 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9011 | /* check if other port on the path needs ovlan: |
| 9012 | * Since MF configuration is shared between ports |
| 9013 | * Possible mixed modes are only |
| 9014 | * {SF, SI} {SF, SD} {SD, SF} {SI, SF} |
| 9015 | */ |
| 9016 | if (CHIP_MODE_IS_4_PORT(bp) && |
| 9017 | !bp->path_has_ovlan && |
| 9018 | !IS_MF(bp) && |
| 9019 | bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { |
| 9020 | u8 other_port = !BP_PORT(bp); |
| 9021 | u8 other_func = BP_PATH(bp) + 2*other_port; |
| 9022 | val = MF_CFG_RD(bp, |
| 9023 | func_mf_config[other_func].e1hov_tag); |
| 9024 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) |
| 9025 | bp->path_has_ovlan = true; |
| 9026 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9027 | } |
| 9028 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9029 | /* adjust igu_sb_cnt to MF for E1x */ |
| 9030 | if (CHIP_IS_E1x(bp) && IS_MF(bp)) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9031 | bp->igu_sb_cnt /= E1HVN_MAX; |
| 9032 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9033 | /* port info */ |
| 9034 | bnx2x_get_port_hwinfo(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9035 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9036 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9037 | bp->fw_seq = |
| 9038 | (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & |
| 9039 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9040 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 9041 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9042 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9043 | /* Get MAC addresses */ |
| 9044 | bnx2x_get_mac_hwinfo(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9045 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 9046 | #ifdef BCM_CNIC |
| 9047 | bnx2x_get_cnic_info(bp); |
| 9048 | #endif |
| 9049 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9050 | /* Get current FW pulse sequence */ |
| 9051 | if (!BP_NOMCP(bp)) { |
| 9052 | int mb_idx = BP_FW_MB_IDX(bp); |
| 9053 | |
| 9054 | bp->fw_drv_pulse_wr_seq = |
| 9055 | (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) & |
| 9056 | DRV_PULSE_SEQ_MASK); |
| 9057 | BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq); |
| 9058 | } |
| 9059 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9060 | return rc; |
| 9061 | } |
| 9062 | |
Vladislav Zolotarov | 34f24c7 | 2010-04-19 01:13:23 +0000 | [diff] [blame] | 9063 | static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp) |
| 9064 | { |
| 9065 | int cnt, i, block_end, rodi; |
| 9066 | char vpd_data[BNX2X_VPD_LEN+1]; |
| 9067 | char str_id_reg[VENDOR_ID_LEN+1]; |
| 9068 | char str_id_cap[VENDOR_ID_LEN+1]; |
| 9069 | u8 len; |
| 9070 | |
| 9071 | cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data); |
| 9072 | memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); |
| 9073 | |
| 9074 | if (cnt < BNX2X_VPD_LEN) |
| 9075 | goto out_not_found; |
| 9076 | |
| 9077 | i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN, |
| 9078 | PCI_VPD_LRDT_RO_DATA); |
| 9079 | if (i < 0) |
| 9080 | goto out_not_found; |
| 9081 | |
| 9082 | |
| 9083 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + |
| 9084 | pci_vpd_lrdt_size(&vpd_data[i]); |
| 9085 | |
| 9086 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 9087 | |
| 9088 | if (block_end > BNX2X_VPD_LEN) |
| 9089 | goto out_not_found; |
| 9090 | |
| 9091 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, |
| 9092 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 9093 | if (rodi < 0) |
| 9094 | goto out_not_found; |
| 9095 | |
| 9096 | len = pci_vpd_info_field_size(&vpd_data[rodi]); |
| 9097 | |
| 9098 | if (len != VENDOR_ID_LEN) |
| 9099 | goto out_not_found; |
| 9100 | |
| 9101 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 9102 | |
| 9103 | /* vendor specific info */ |
| 9104 | snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); |
| 9105 | snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); |
| 9106 | if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || |
| 9107 | !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { |
| 9108 | |
| 9109 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, |
| 9110 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 9111 | if (rodi >= 0) { |
| 9112 | len = pci_vpd_info_field_size(&vpd_data[rodi]); |
| 9113 | |
| 9114 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 9115 | |
| 9116 | if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { |
| 9117 | memcpy(bp->fw_ver, &vpd_data[rodi], len); |
| 9118 | bp->fw_ver[len] = ' '; |
| 9119 | } |
| 9120 | } |
| 9121 | return; |
| 9122 | } |
| 9123 | out_not_found: |
| 9124 | return; |
| 9125 | } |
| 9126 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9127 | static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp) |
| 9128 | { |
| 9129 | u32 flags = 0; |
| 9130 | |
| 9131 | if (CHIP_REV_IS_FPGA(bp)) |
| 9132 | SET_FLAGS(flags, MODE_FPGA); |
| 9133 | else if (CHIP_REV_IS_EMUL(bp)) |
| 9134 | SET_FLAGS(flags, MODE_EMUL); |
| 9135 | else |
| 9136 | SET_FLAGS(flags, MODE_ASIC); |
| 9137 | |
| 9138 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 9139 | SET_FLAGS(flags, MODE_PORT4); |
| 9140 | else |
| 9141 | SET_FLAGS(flags, MODE_PORT2); |
| 9142 | |
| 9143 | if (CHIP_IS_E2(bp)) |
| 9144 | SET_FLAGS(flags, MODE_E2); |
| 9145 | else if (CHIP_IS_E3(bp)) { |
| 9146 | SET_FLAGS(flags, MODE_E3); |
| 9147 | if (CHIP_REV(bp) == CHIP_REV_Ax) |
| 9148 | SET_FLAGS(flags, MODE_E3_A0); |
| 9149 | else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/ |
| 9150 | SET_FLAGS(flags, MODE_E3_B0); |
| 9151 | SET_FLAGS(flags, MODE_COS_BC); |
| 9152 | } |
| 9153 | } |
| 9154 | |
| 9155 | if (IS_MF(bp)) { |
| 9156 | SET_FLAGS(flags, MODE_MF); |
| 9157 | switch (bp->mf_mode) { |
| 9158 | case MULTI_FUNCTION_SD: |
| 9159 | SET_FLAGS(flags, MODE_MF_SD); |
| 9160 | break; |
| 9161 | case MULTI_FUNCTION_SI: |
| 9162 | SET_FLAGS(flags, MODE_MF_SI); |
| 9163 | break; |
| 9164 | } |
| 9165 | } else |
| 9166 | SET_FLAGS(flags, MODE_SF); |
| 9167 | |
| 9168 | #if defined(__LITTLE_ENDIAN) |
| 9169 | SET_FLAGS(flags, MODE_LITTLE_ENDIAN); |
| 9170 | #else /*(__BIG_ENDIAN)*/ |
| 9171 | SET_FLAGS(flags, MODE_BIG_ENDIAN); |
| 9172 | #endif |
| 9173 | INIT_MODE_FLAGS(bp) = flags; |
| 9174 | } |
| 9175 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9176 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
| 9177 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9178 | int func; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 9179 | int timer_interval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9180 | int rc; |
| 9181 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9182 | mutex_init(&bp->port.phy_mutex); |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 9183 | mutex_init(&bp->fw_mb_mutex); |
David S. Miller | bb7e95c | 2010-07-27 21:01:35 -0700 | [diff] [blame] | 9184 | spin_lock_init(&bp->stats_lock); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 9185 | #ifdef BCM_CNIC |
| 9186 | mutex_init(&bp->cnic_mutex); |
| 9187 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9188 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 9189 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9190 | INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9191 | |
| 9192 | rc = bnx2x_get_hwinfo(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9193 | if (rc) |
| 9194 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9195 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9196 | bnx2x_set_modes_bitmap(bp); |
| 9197 | |
| 9198 | rc = bnx2x_alloc_mem_bp(bp); |
| 9199 | if (rc) |
| 9200 | return rc; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9201 | |
Vladislav Zolotarov | 34f24c7 | 2010-04-19 01:13:23 +0000 | [diff] [blame] | 9202 | bnx2x_read_fwinfo(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9203 | |
| 9204 | func = BP_FUNC(bp); |
| 9205 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9206 | /* need to reset chip if undi was active */ |
| 9207 | if (!BP_NOMCP(bp)) |
| 9208 | bnx2x_undi_unload(bp); |
| 9209 | |
| 9210 | if (CHIP_REV_IS_FPGA(bp)) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9211 | dev_err(&bp->pdev->dev, "FPGA detected\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9212 | |
| 9213 | if (BP_NOMCP(bp) && (func == 0)) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9214 | dev_err(&bp->pdev->dev, "MCP disabled, " |
| 9215 | "must load devices in order!\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9216 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 9217 | bp->multi_mode = multi_mode; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 9218 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9219 | /* Set TPA flags */ |
| 9220 | if (disable_tpa) { |
| 9221 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 9222 | bp->dev->features &= ~NETIF_F_LRO; |
| 9223 | } else { |
| 9224 | bp->flags |= TPA_ENABLE_FLAG; |
| 9225 | bp->dev->features |= NETIF_F_LRO; |
| 9226 | } |
Dmitry Kravkov | 5d7cd49 | 2010-07-27 12:32:19 +0000 | [diff] [blame] | 9227 | bp->disable_tpa = disable_tpa; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9228 | |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 9229 | if (CHIP_IS_E1(bp)) |
| 9230 | bp->dropless_fc = 0; |
| 9231 | else |
| 9232 | bp->dropless_fc = dropless_fc; |
| 9233 | |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 9234 | bp->mrrs = mrrs; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9235 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9236 | bp->tx_ring_size = MAX_TX_AVAIL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9237 | |
Eilon Greenstein | 7d323bf | 2009-11-09 06:09:35 +0000 | [diff] [blame] | 9238 | /* make sure that the numbers are in the right granularity */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9239 | bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR; |
| 9240 | bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9241 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 9242 | timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ); |
| 9243 | bp->current_interval = (poll ? poll : timer_interval); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9244 | |
| 9245 | init_timer(&bp->timer); |
| 9246 | bp->timer.expires = jiffies + bp->current_interval; |
| 9247 | bp->timer.data = (unsigned long) bp; |
| 9248 | bp->timer.function = bnx2x_timer; |
| 9249 | |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 9250 | bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON); |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 9251 | bnx2x_dcbx_init_params(bp); |
| 9252 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9253 | #ifdef BCM_CNIC |
| 9254 | if (CHIP_IS_E1x(bp)) |
| 9255 | bp->cnic_base_cl_id = FP_SB_MAX_E1x; |
| 9256 | else |
| 9257 | bp->cnic_base_cl_id = FP_SB_MAX_E2; |
| 9258 | #endif |
| 9259 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9260 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9261 | } |
| 9262 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9263 | |
Dmitry Kravkov | de0c62d | 2010-07-27 12:35:24 +0000 | [diff] [blame] | 9264 | /**************************************************************************** |
| 9265 | * General service functions |
| 9266 | ****************************************************************************/ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9267 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9268 | /* |
| 9269 | * net_device service functions |
| 9270 | */ |
| 9271 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9272 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9273 | static int bnx2x_open(struct net_device *dev) |
| 9274 | { |
| 9275 | struct bnx2x *bp = netdev_priv(dev); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9276 | bool global = false; |
| 9277 | int other_engine = BP_PATH(bp) ? 0 : 1; |
| 9278 | u32 other_load_counter, load_counter; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9279 | |
Eilon Greenstein | 6eccabb | 2009-01-22 03:37:48 +0000 | [diff] [blame] | 9280 | netif_carrier_off(dev); |
| 9281 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9282 | bnx2x_set_power_state(bp, PCI_D0); |
| 9283 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9284 | other_load_counter = bnx2x_get_load_cnt(bp, other_engine); |
| 9285 | load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9286 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9287 | /* |
| 9288 | * If parity had happen during the unload, then attentions |
| 9289 | * and/or RECOVERY_IN_PROGRES may still be set. In this case we |
| 9290 | * want the first function loaded on the current engine to |
| 9291 | * complete the recovery. |
| 9292 | */ |
| 9293 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || |
| 9294 | bnx2x_chk_parity_attn(bp, &global, true)) |
| 9295 | do { |
| 9296 | /* |
| 9297 | * If there are attentions and they are in a global |
| 9298 | * blocks, set the GLOBAL_RESET bit regardless whether |
| 9299 | * it will be this function that will complete the |
| 9300 | * recovery or not. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9301 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9302 | if (global) |
| 9303 | bnx2x_set_reset_global(bp); |
| 9304 | |
| 9305 | /* |
| 9306 | * Only the first function on the current engine should |
| 9307 | * try to recover in open. In case of attentions in |
| 9308 | * global blocks only the first in the chip should try |
| 9309 | * to recover. |
| 9310 | */ |
| 9311 | if ((!load_counter && |
| 9312 | (!global || !other_load_counter)) && |
| 9313 | bnx2x_trylock_leader_lock(bp) && |
| 9314 | !bnx2x_leader_reset(bp)) { |
| 9315 | netdev_info(bp->dev, "Recovered in open\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9316 | break; |
| 9317 | } |
| 9318 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9319 | /* recovery has failed... */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9320 | bnx2x_set_power_state(bp, PCI_D3hot); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9321 | bp->recovery_state = BNX2X_RECOVERY_FAILED; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9322 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9323 | netdev_err(bp->dev, "Recovery flow hasn't been properly" |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9324 | " completed yet. Try again later. If u still see this" |
| 9325 | " message after a few retries then power cycle is" |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9326 | " required.\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9327 | |
| 9328 | return -EAGAIN; |
| 9329 | } while (0); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9330 | |
| 9331 | bp->recovery_state = BNX2X_RECOVERY_DONE; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9332 | return bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9333 | } |
| 9334 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9335 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9336 | static int bnx2x_close(struct net_device *dev) |
| 9337 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9338 | struct bnx2x *bp = netdev_priv(dev); |
| 9339 | |
| 9340 | /* Unload the driver, release IRQs */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9341 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9342 | |
| 9343 | /* Power off */ |
Vladislav Zolotarov | d3dbfee | 2010-04-19 01:14:49 +0000 | [diff] [blame] | 9344 | bnx2x_set_power_state(bp, PCI_D3hot); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9345 | |
| 9346 | return 0; |
| 9347 | } |
| 9348 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9349 | static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp, |
| 9350 | struct bnx2x_mcast_ramrod_params *p) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9351 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9352 | int mc_count = netdev_mc_count(bp->dev); |
| 9353 | struct bnx2x_mcast_list_elem *mc_mac = |
| 9354 | kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9355 | struct netdev_hw_addr *ha; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9356 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9357 | if (!mc_mac) |
| 9358 | return -ENOMEM; |
| 9359 | |
| 9360 | INIT_LIST_HEAD(&p->mcast_list); |
| 9361 | |
| 9362 | netdev_for_each_mc_addr(ha, bp->dev) { |
| 9363 | mc_mac->mac = bnx2x_mc_addr(ha); |
| 9364 | list_add_tail(&mc_mac->link, &p->mcast_list); |
| 9365 | mc_mac++; |
| 9366 | } |
| 9367 | |
| 9368 | p->mcast_list_len = mc_count; |
| 9369 | |
| 9370 | return 0; |
| 9371 | } |
| 9372 | |
| 9373 | static inline void bnx2x_free_mcast_macs_list( |
| 9374 | struct bnx2x_mcast_ramrod_params *p) |
| 9375 | { |
| 9376 | struct bnx2x_mcast_list_elem *mc_mac = |
| 9377 | list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem, |
| 9378 | link); |
| 9379 | |
| 9380 | WARN_ON(!mc_mac); |
| 9381 | kfree(mc_mac); |
| 9382 | } |
| 9383 | |
| 9384 | /** |
| 9385 | * bnx2x_set_uc_list - configure a new unicast MACs list. |
| 9386 | * |
| 9387 | * @bp: driver handle |
| 9388 | * |
| 9389 | * We will use zero (0) as a MAC type for these MACs. |
| 9390 | */ |
| 9391 | static inline int bnx2x_set_uc_list(struct bnx2x *bp) |
| 9392 | { |
| 9393 | int rc; |
| 9394 | struct net_device *dev = bp->dev; |
| 9395 | struct netdev_hw_addr *ha; |
| 9396 | struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj; |
| 9397 | unsigned long ramrod_flags = 0; |
| 9398 | |
| 9399 | /* First schedule a cleanup up of old configuration */ |
| 9400 | rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false); |
| 9401 | if (rc < 0) { |
| 9402 | BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc); |
| 9403 | return rc; |
| 9404 | } |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9405 | |
| 9406 | netdev_for_each_uc_addr(ha, dev) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9407 | rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, |
| 9408 | BNX2X_UC_LIST_MAC, &ramrod_flags); |
| 9409 | if (rc < 0) { |
| 9410 | BNX2X_ERR("Failed to schedule ADD operations: %d\n", |
| 9411 | rc); |
| 9412 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9413 | } |
| 9414 | } |
| 9415 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9416 | /* Execute the pending commands */ |
| 9417 | __set_bit(RAMROD_CONT, &ramrod_flags); |
| 9418 | return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */, |
| 9419 | BNX2X_UC_LIST_MAC, &ramrod_flags); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9420 | } |
| 9421 | |
| 9422 | static inline int bnx2x_set_mc_list(struct bnx2x *bp) |
| 9423 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9424 | struct net_device *dev = bp->dev; |
| 9425 | struct bnx2x_mcast_ramrod_params rparam = {0}; |
| 9426 | int rc = 0; |
| 9427 | |
| 9428 | rparam.mcast_obj = &bp->mcast_obj; |
| 9429 | |
| 9430 | /* first, clear all configured multicast MACs */ |
| 9431 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); |
| 9432 | if (rc < 0) { |
| 9433 | BNX2X_ERR("Failed to clear multicast " |
| 9434 | "configuration: %d\n", rc); |
| 9435 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9436 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9437 | |
| 9438 | /* then, configure a new MACs list */ |
| 9439 | if (netdev_mc_count(dev)) { |
| 9440 | rc = bnx2x_init_mcast_macs_list(bp, &rparam); |
| 9441 | if (rc) { |
| 9442 | BNX2X_ERR("Failed to create multicast MACs " |
| 9443 | "list: %d\n", rc); |
| 9444 | return rc; |
| 9445 | } |
| 9446 | |
| 9447 | /* Now add the new MACs */ |
| 9448 | rc = bnx2x_config_mcast(bp, &rparam, |
| 9449 | BNX2X_MCAST_CMD_ADD); |
| 9450 | if (rc < 0) |
| 9451 | BNX2X_ERR("Failed to set a new multicast " |
| 9452 | "configuration: %d\n", rc); |
| 9453 | |
| 9454 | bnx2x_free_mcast_macs_list(&rparam); |
| 9455 | } |
| 9456 | |
| 9457 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9458 | } |
| 9459 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9460 | |
| 9461 | /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 9462 | void bnx2x_set_rx_mode(struct net_device *dev) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9463 | { |
| 9464 | struct bnx2x *bp = netdev_priv(dev); |
| 9465 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9466 | |
| 9467 | if (bp->state != BNX2X_STATE_OPEN) { |
| 9468 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 9469 | return; |
| 9470 | } |
| 9471 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9472 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9473 | |
| 9474 | if (dev->flags & IFF_PROMISC) |
| 9475 | rx_mode = BNX2X_RX_MODE_PROMISC; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9476 | else if ((dev->flags & IFF_ALLMULTI) || |
| 9477 | ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) && |
| 9478 | CHIP_IS_E1(bp))) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9479 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9480 | else { |
| 9481 | /* some multicasts */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9482 | if (bnx2x_set_mc_list(bp) < 0) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9483 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9484 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9485 | if (bnx2x_set_uc_list(bp) < 0) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9486 | rx_mode = BNX2X_RX_MODE_PROMISC; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9487 | } |
| 9488 | |
| 9489 | bp->rx_mode = rx_mode; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9490 | |
| 9491 | /* Schedule the rx_mode command */ |
| 9492 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) { |
| 9493 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); |
| 9494 | return; |
| 9495 | } |
| 9496 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9497 | bnx2x_set_storm_rx_mode(bp); |
| 9498 | } |
| 9499 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9500 | /* called with rtnl_lock */ |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9501 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
| 9502 | int devad, u16 addr) |
| 9503 | { |
| 9504 | struct bnx2x *bp = netdev_priv(netdev); |
| 9505 | u16 value; |
| 9506 | int rc; |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9507 | |
| 9508 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
| 9509 | prtad, devad, addr); |
| 9510 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9511 | /* The HW expects different devad if CL22 is used */ |
| 9512 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 9513 | |
| 9514 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | e10bc84 | 2010-09-07 11:40:50 +0000 | [diff] [blame] | 9515 | rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9516 | bnx2x_release_phy_lock(bp); |
| 9517 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); |
| 9518 | |
| 9519 | if (!rc) |
| 9520 | rc = value; |
| 9521 | return rc; |
| 9522 | } |
| 9523 | |
| 9524 | /* called with rtnl_lock */ |
| 9525 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 9526 | u16 addr, u16 value) |
| 9527 | { |
| 9528 | struct bnx2x *bp = netdev_priv(netdev); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9529 | int rc; |
| 9530 | |
| 9531 | DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x," |
| 9532 | " value 0x%x\n", prtad, devad, addr, value); |
| 9533 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9534 | /* The HW expects different devad if CL22 is used */ |
| 9535 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 9536 | |
| 9537 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | e10bc84 | 2010-09-07 11:40:50 +0000 | [diff] [blame] | 9538 | rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9539 | bnx2x_release_phy_lock(bp); |
| 9540 | return rc; |
| 9541 | } |
| 9542 | |
| 9543 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9544 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 9545 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9546 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9547 | struct mii_ioctl_data *mdio = if_mii(ifr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9548 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9549 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
| 9550 | mdio->phy_id, mdio->reg_num, mdio->val_in); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9551 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9552 | if (!netif_running(dev)) |
| 9553 | return -EAGAIN; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9554 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9555 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9556 | } |
| 9557 | |
Alexey Dobriyan | 257ddbd | 2010-01-27 10:17:41 +0000 | [diff] [blame] | 9558 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9559 | static void poll_bnx2x(struct net_device *dev) |
| 9560 | { |
| 9561 | struct bnx2x *bp = netdev_priv(dev); |
| 9562 | |
| 9563 | disable_irq(bp->pdev->irq); |
| 9564 | bnx2x_interrupt(bp->pdev->irq, dev); |
| 9565 | enable_irq(bp->pdev->irq); |
| 9566 | } |
| 9567 | #endif |
| 9568 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9569 | static const struct net_device_ops bnx2x_netdev_ops = { |
| 9570 | .ndo_open = bnx2x_open, |
| 9571 | .ndo_stop = bnx2x_close, |
| 9572 | .ndo_start_xmit = bnx2x_start_xmit, |
Vladislav Zolotarov | 8307fa3 | 2010-12-13 05:44:09 +0000 | [diff] [blame] | 9573 | .ndo_select_queue = bnx2x_select_queue, |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9574 | .ndo_set_rx_mode = bnx2x_set_rx_mode, |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9575 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
| 9576 | .ndo_validate_addr = eth_validate_addr, |
| 9577 | .ndo_do_ioctl = bnx2x_ioctl, |
| 9578 | .ndo_change_mtu = bnx2x_change_mtu, |
Michał Mirosław | 66371c4 | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 9579 | .ndo_fix_features = bnx2x_fix_features, |
| 9580 | .ndo_set_features = bnx2x_set_features, |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9581 | .ndo_tx_timeout = bnx2x_tx_timeout, |
Alexey Dobriyan | 257ddbd | 2010-01-27 10:17:41 +0000 | [diff] [blame] | 9582 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9583 | .ndo_poll_controller = poll_bnx2x, |
| 9584 | #endif |
| 9585 | }; |
| 9586 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9587 | static inline int bnx2x_set_coherency_mask(struct bnx2x *bp) |
| 9588 | { |
| 9589 | struct device *dev = &bp->pdev->dev; |
| 9590 | |
| 9591 | if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { |
| 9592 | bp->flags |= USING_DAC_FLAG; |
| 9593 | if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { |
| 9594 | dev_err(dev, "dma_set_coherent_mask failed, " |
| 9595 | "aborting\n"); |
| 9596 | return -EIO; |
| 9597 | } |
| 9598 | } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) { |
| 9599 | dev_err(dev, "System does not support DMA, aborting\n"); |
| 9600 | return -EIO; |
| 9601 | } |
| 9602 | |
| 9603 | return 0; |
| 9604 | } |
| 9605 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9606 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9607 | struct net_device *dev, |
| 9608 | unsigned long board_type) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9609 | { |
| 9610 | struct bnx2x *bp; |
| 9611 | int rc; |
| 9612 | |
| 9613 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 9614 | bp = netdev_priv(dev); |
| 9615 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9616 | bp->dev = dev; |
| 9617 | bp->pdev = pdev; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9618 | bp->flags = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9619 | bp->pf_num = PCI_FUNC(pdev->devfn); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9620 | |
| 9621 | rc = pci_enable_device(pdev); |
| 9622 | if (rc) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9623 | dev_err(&bp->pdev->dev, |
| 9624 | "Cannot enable PCI device, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9625 | goto err_out; |
| 9626 | } |
| 9627 | |
| 9628 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9629 | dev_err(&bp->pdev->dev, |
| 9630 | "Cannot find PCI device base address, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9631 | rc = -ENODEV; |
| 9632 | goto err_out_disable; |
| 9633 | } |
| 9634 | |
| 9635 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9636 | dev_err(&bp->pdev->dev, "Cannot find second PCI device" |
| 9637 | " base address, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9638 | rc = -ENODEV; |
| 9639 | goto err_out_disable; |
| 9640 | } |
| 9641 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9642 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 9643 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 9644 | if (rc) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9645 | dev_err(&bp->pdev->dev, |
| 9646 | "Cannot obtain PCI resources, aborting\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9647 | goto err_out_disable; |
| 9648 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9649 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9650 | pci_set_master(pdev); |
| 9651 | pci_save_state(pdev); |
| 9652 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9653 | |
| 9654 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 9655 | if (bp->pm_cap == 0) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9656 | dev_err(&bp->pdev->dev, |
| 9657 | "Cannot find power management capability, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9658 | rc = -EIO; |
| 9659 | goto err_out_release; |
| 9660 | } |
| 9661 | |
| 9662 | bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 9663 | if (bp->pcie_cap == 0) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9664 | dev_err(&bp->pdev->dev, |
| 9665 | "Cannot find PCI Express capability, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9666 | rc = -EIO; |
| 9667 | goto err_out_release; |
| 9668 | } |
| 9669 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9670 | rc = bnx2x_set_coherency_mask(bp); |
| 9671 | if (rc) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9672 | goto err_out_release; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9673 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9674 | dev->mem_start = pci_resource_start(pdev, 0); |
| 9675 | dev->base_addr = dev->mem_start; |
| 9676 | dev->mem_end = pci_resource_end(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9677 | |
| 9678 | dev->irq = pdev->irq; |
| 9679 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 9680 | bp->regview = pci_ioremap_bar(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9681 | if (!bp->regview) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9682 | dev_err(&bp->pdev->dev, |
| 9683 | "Cannot map register space, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9684 | rc = -ENOMEM; |
| 9685 | goto err_out_release; |
| 9686 | } |
| 9687 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9688 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9689 | min_t(u64, BNX2X_DB_SIZE(bp), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9690 | pci_resource_len(pdev, 2))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9691 | if (!bp->doorbells) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9692 | dev_err(&bp->pdev->dev, |
| 9693 | "Cannot map doorbell space, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9694 | rc = -ENOMEM; |
| 9695 | goto err_out_unmap; |
| 9696 | } |
| 9697 | |
| 9698 | bnx2x_set_power_state(bp, PCI_D0); |
| 9699 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9700 | /* clean indirect addresses */ |
| 9701 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 9702 | PCICFG_VENDOR_ID_OFFSET); |
| 9703 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0); |
| 9704 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0); |
| 9705 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0); |
| 9706 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9707 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9708 | /** |
| 9709 | * Enable internal target-read (in case we are probed after PF FLR). |
| 9710 | * Must be done prior to any BAR read access |
| 9711 | */ |
| 9712 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); |
| 9713 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9714 | /* Reset the load counter */ |
| 9715 | bnx2x_clear_load_cnt(bp); |
| 9716 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9717 | dev->watchdog_timeo = TX_TIMEOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9718 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9719 | dev->netdev_ops = &bnx2x_netdev_ops; |
Dmitry Kravkov | de0c62d | 2010-07-27 12:35:24 +0000 | [diff] [blame] | 9720 | bnx2x_set_ethtool_ops(dev); |
Michał Mirosław | 66371c4 | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 9721 | |
| 9722 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 9723 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | |
| 9724 | NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX; |
| 9725 | |
| 9726 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 9727 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; |
| 9728 | |
| 9729 | dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9730 | if (bp->flags & USING_DAC_FLAG) |
| 9731 | dev->features |= NETIF_F_HIGHDMA; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9732 | |
Mahesh Bandewar | 538dd2e | 2011-05-13 15:08:49 +0000 | [diff] [blame] | 9733 | /* Add Loopback capability to the device */ |
| 9734 | dev->hw_features |= NETIF_F_LOOPBACK; |
| 9735 | |
Shmulik Ravid | 9850767 | 2011-02-28 12:19:55 -0800 | [diff] [blame] | 9736 | #ifdef BCM_DCBNL |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 9737 | dev->dcbnl_ops = &bnx2x_dcbnl_ops; |
| 9738 | #endif |
| 9739 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9740 | /* get_port_hwinfo() will set prtad and mmds properly */ |
| 9741 | bp->mdio.prtad = MDIO_PRTAD_NONE; |
| 9742 | bp->mdio.mmds = 0; |
| 9743 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9744 | bp->mdio.dev = dev; |
| 9745 | bp->mdio.mdio_read = bnx2x_mdio_read; |
| 9746 | bp->mdio.mdio_write = bnx2x_mdio_write; |
| 9747 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9748 | return 0; |
| 9749 | |
| 9750 | err_out_unmap: |
| 9751 | if (bp->regview) { |
| 9752 | iounmap(bp->regview); |
| 9753 | bp->regview = NULL; |
| 9754 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9755 | if (bp->doorbells) { |
| 9756 | iounmap(bp->doorbells); |
| 9757 | bp->doorbells = NULL; |
| 9758 | } |
| 9759 | |
| 9760 | err_out_release: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9761 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 9762 | pci_release_regions(pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9763 | |
| 9764 | err_out_disable: |
| 9765 | pci_disable_device(pdev); |
| 9766 | pci_set_drvdata(pdev, NULL); |
| 9767 | |
| 9768 | err_out: |
| 9769 | return rc; |
| 9770 | } |
| 9771 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9772 | static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp, |
| 9773 | int *width, int *speed) |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 9774 | { |
| 9775 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 9776 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9777 | *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
| 9778 | |
| 9779 | /* return value of 1=2.5GHz 2=5GHz */ |
| 9780 | *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 9781 | } |
| 9782 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9783 | static int bnx2x_check_firmware(struct bnx2x *bp) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9784 | { |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9785 | const struct firmware *firmware = bp->firmware; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9786 | struct bnx2x_fw_file_hdr *fw_hdr; |
| 9787 | struct bnx2x_fw_file_section *sections; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9788 | u32 offset, len, num_ops; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9789 | u16 *ops_offsets; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9790 | int i; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9791 | const u8 *fw_ver; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9792 | |
| 9793 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) |
| 9794 | return -EINVAL; |
| 9795 | |
| 9796 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; |
| 9797 | sections = (struct bnx2x_fw_file_section *)fw_hdr; |
| 9798 | |
| 9799 | /* Make sure none of the offsets and sizes make us read beyond |
| 9800 | * the end of the firmware data */ |
| 9801 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { |
| 9802 | offset = be32_to_cpu(sections[i].offset); |
| 9803 | len = be32_to_cpu(sections[i].len); |
| 9804 | if (offset + len > firmware->size) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9805 | dev_err(&bp->pdev->dev, |
| 9806 | "Section %d length is out of bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9807 | return -EINVAL; |
| 9808 | } |
| 9809 | } |
| 9810 | |
| 9811 | /* Likewise for the init_ops offsets */ |
| 9812 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); |
| 9813 | ops_offsets = (u16 *)(firmware->data + offset); |
| 9814 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); |
| 9815 | |
| 9816 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { |
| 9817 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9818 | dev_err(&bp->pdev->dev, |
| 9819 | "Section offset %d is out of bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9820 | return -EINVAL; |
| 9821 | } |
| 9822 | } |
| 9823 | |
| 9824 | /* Check FW version */ |
| 9825 | offset = be32_to_cpu(fw_hdr->fw_version.offset); |
| 9826 | fw_ver = firmware->data + offset; |
| 9827 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || |
| 9828 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || |
| 9829 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || |
| 9830 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9831 | dev_err(&bp->pdev->dev, |
| 9832 | "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n", |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9833 | fw_ver[0], fw_ver[1], fw_ver[2], |
| 9834 | fw_ver[3], BCM_5710_FW_MAJOR_VERSION, |
| 9835 | BCM_5710_FW_MINOR_VERSION, |
| 9836 | BCM_5710_FW_REVISION_VERSION, |
| 9837 | BCM_5710_FW_ENGINEERING_VERSION); |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9838 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9839 | } |
| 9840 | |
| 9841 | return 0; |
| 9842 | } |
| 9843 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9844 | static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9845 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9846 | const __be32 *source = (const __be32 *)_source; |
| 9847 | u32 *target = (u32 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9848 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9849 | |
| 9850 | for (i = 0; i < n/4; i++) |
| 9851 | target[i] = be32_to_cpu(source[i]); |
| 9852 | } |
| 9853 | |
| 9854 | /* |
| 9855 | Ops array is stored in the following format: |
| 9856 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} |
| 9857 | */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9858 | static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9859 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9860 | const __be32 *source = (const __be32 *)_source; |
| 9861 | struct raw_op *target = (struct raw_op *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9862 | u32 i, j, tmp; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9863 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9864 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9865 | tmp = be32_to_cpu(source[j]); |
| 9866 | target[i].op = (tmp >> 24) & 0xff; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9867 | target[i].offset = tmp & 0xffffff; |
| 9868 | target[i].raw_data = be32_to_cpu(source[j + 1]); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9869 | } |
| 9870 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9871 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9872 | /** |
| 9873 | * IRO array is stored in the following format: |
| 9874 | * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) } |
| 9875 | */ |
| 9876 | static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n) |
| 9877 | { |
| 9878 | const __be32 *source = (const __be32 *)_source; |
| 9879 | struct iro *target = (struct iro *)_target; |
| 9880 | u32 i, j, tmp; |
| 9881 | |
| 9882 | for (i = 0, j = 0; i < n/sizeof(struct iro); i++) { |
| 9883 | target[i].base = be32_to_cpu(source[j]); |
| 9884 | j++; |
| 9885 | tmp = be32_to_cpu(source[j]); |
| 9886 | target[i].m1 = (tmp >> 16) & 0xffff; |
| 9887 | target[i].m2 = tmp & 0xffff; |
| 9888 | j++; |
| 9889 | tmp = be32_to_cpu(source[j]); |
| 9890 | target[i].m3 = (tmp >> 16) & 0xffff; |
| 9891 | target[i].size = tmp & 0xffff; |
| 9892 | j++; |
| 9893 | } |
| 9894 | } |
| 9895 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9896 | static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9897 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9898 | const __be16 *source = (const __be16 *)_source; |
| 9899 | u16 *target = (u16 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9900 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9901 | |
| 9902 | for (i = 0; i < n/2; i++) |
| 9903 | target[i] = be16_to_cpu(source[i]); |
| 9904 | } |
| 9905 | |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 9906 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
| 9907 | do { \ |
| 9908 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ |
| 9909 | bp->arr = kmalloc(len, GFP_KERNEL); \ |
| 9910 | if (!bp->arr) { \ |
| 9911 | pr_err("Failed to allocate %d bytes for "#arr"\n", len); \ |
| 9912 | goto lbl; \ |
| 9913 | } \ |
| 9914 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
| 9915 | (u8 *)bp->arr, len); \ |
| 9916 | } while (0) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9917 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9918 | int bnx2x_init_firmware(struct bnx2x *bp) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9919 | { |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9920 | const char *fw_file_name; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9921 | struct bnx2x_fw_file_hdr *fw_hdr; |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9922 | int rc; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9923 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9924 | if (CHIP_IS_E1(bp)) |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9925 | fw_file_name = FW_FILE_NAME_E1; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9926 | else if (CHIP_IS_E1H(bp)) |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9927 | fw_file_name = FW_FILE_NAME_E1H; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9928 | else if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9929 | fw_file_name = FW_FILE_NAME_E2; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9930 | else { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9931 | BNX2X_ERR("Unsupported chip revision\n"); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9932 | return -EINVAL; |
| 9933 | } |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9934 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9935 | BNX2X_DEV_INFO("Loading %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9936 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9937 | rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9938 | if (rc) { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9939 | BNX2X_ERR("Can't load firmware file %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9940 | goto request_firmware_exit; |
| 9941 | } |
| 9942 | |
| 9943 | rc = bnx2x_check_firmware(bp); |
| 9944 | if (rc) { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9945 | BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9946 | goto request_firmware_exit; |
| 9947 | } |
| 9948 | |
| 9949 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; |
| 9950 | |
| 9951 | /* Initialize the pointers to the init arrays */ |
| 9952 | /* Blob */ |
| 9953 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); |
| 9954 | |
| 9955 | /* Opcodes */ |
| 9956 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); |
| 9957 | |
| 9958 | /* Offsets */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9959 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
| 9960 | be16_to_cpu_n); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9961 | |
| 9962 | /* STORMs firmware */ |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 9963 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9964 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); |
| 9965 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9966 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); |
| 9967 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9968 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); |
| 9969 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9970 | be32_to_cpu(fw_hdr->usem_pram_data.offset); |
| 9971 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9972 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); |
| 9973 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9974 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); |
| 9975 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9976 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); |
| 9977 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9978 | be32_to_cpu(fw_hdr->csem_pram_data.offset); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9979 | /* IRO */ |
| 9980 | BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9981 | |
| 9982 | return 0; |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9983 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9984 | iro_alloc_err: |
| 9985 | kfree(bp->init_ops_offsets); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9986 | init_offsets_alloc_err: |
| 9987 | kfree(bp->init_ops); |
| 9988 | init_ops_alloc_err: |
| 9989 | kfree(bp->init_data); |
| 9990 | request_firmware_exit: |
| 9991 | release_firmware(bp->firmware); |
| 9992 | |
| 9993 | return rc; |
| 9994 | } |
| 9995 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9996 | static void bnx2x_release_firmware(struct bnx2x *bp) |
| 9997 | { |
| 9998 | kfree(bp->init_ops_offsets); |
| 9999 | kfree(bp->init_ops); |
| 10000 | kfree(bp->init_data); |
| 10001 | release_firmware(bp->firmware); |
| 10002 | } |
| 10003 | |
| 10004 | |
| 10005 | static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = { |
| 10006 | .init_hw_cmn_chip = bnx2x_init_hw_common_chip, |
| 10007 | .init_hw_cmn = bnx2x_init_hw_common, |
| 10008 | .init_hw_port = bnx2x_init_hw_port, |
| 10009 | .init_hw_func = bnx2x_init_hw_func, |
| 10010 | |
| 10011 | .reset_hw_cmn = bnx2x_reset_common, |
| 10012 | .reset_hw_port = bnx2x_reset_port, |
| 10013 | .reset_hw_func = bnx2x_reset_func, |
| 10014 | |
| 10015 | .gunzip_init = bnx2x_gunzip_init, |
| 10016 | .gunzip_end = bnx2x_gunzip_end, |
| 10017 | |
| 10018 | .init_fw = bnx2x_init_firmware, |
| 10019 | .release_fw = bnx2x_release_firmware, |
| 10020 | }; |
| 10021 | |
| 10022 | void bnx2x__init_func_obj(struct bnx2x *bp) |
| 10023 | { |
| 10024 | /* Prepare DMAE related driver resources */ |
| 10025 | bnx2x_setup_dmae(bp); |
| 10026 | |
| 10027 | bnx2x_init_func_obj(bp, &bp->func_obj, |
| 10028 | bnx2x_sp(bp, func_rdata), |
| 10029 | bnx2x_sp_mapping(bp, func_rdata), |
| 10030 | &bnx2x_func_sp_drv); |
| 10031 | } |
| 10032 | |
| 10033 | /* must be called after sriov-enable */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10034 | static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count) |
| 10035 | { |
| 10036 | int cid_count = L2_FP_COUNT(l2_cid_count); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 10037 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10038 | #ifdef BCM_CNIC |
| 10039 | cid_count += CNIC_CID_MAX; |
| 10040 | #endif |
| 10041 | return roundup(cid_count, QM_CID_ROUND); |
| 10042 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10043 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10044 | /** |
| 10045 | * bnx2x_pci_msix_table_size - get the size of the MSI-X table. |
| 10046 | * |
| 10047 | * @dev: pci device |
| 10048 | * |
| 10049 | */ |
| 10050 | static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev) |
| 10051 | { |
| 10052 | int pos; |
| 10053 | u16 control; |
| 10054 | |
| 10055 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 10056 | if (!pos) |
| 10057 | return 0; |
| 10058 | |
| 10059 | pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control); |
| 10060 | return (control & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 10061 | } |
| 10062 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10063 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
| 10064 | const struct pci_device_id *ent) |
| 10065 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10066 | struct net_device *dev = NULL; |
| 10067 | struct bnx2x *bp; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 10068 | int pcie_width, pcie_speed; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10069 | int rc, cid_count; |
| 10070 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10071 | switch (ent->driver_data) { |
| 10072 | case BCM57710: |
| 10073 | case BCM57711: |
| 10074 | case BCM57711E: |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10075 | case BCM57712: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10076 | case BCM57712_MF: |
| 10077 | case BCM57800: |
| 10078 | case BCM57800_MF: |
| 10079 | case BCM57810: |
| 10080 | case BCM57810_MF: |
| 10081 | case BCM57840: |
| 10082 | case BCM57840_MF: |
| 10083 | /* The size requested for the MSI-X table corresponds to the |
| 10084 | * actual amount of avaliable IGU/HC status blocks. It includes |
| 10085 | * the default SB vector but we want cid_count to contain the |
| 10086 | * amount of only non-default SBs, that's what '-1' stands for. |
| 10087 | */ |
| 10088 | cid_count = bnx2x_pci_msix_table_size(pdev) - 1; |
| 10089 | |
| 10090 | /* do not allow initial cid_count grow above 16 |
| 10091 | * since Special CIDs starts from this number |
| 10092 | * use old FP_SB_MAX_E1x define for this matter |
| 10093 | */ |
| 10094 | cid_count = min_t(int, FP_SB_MAX_E1x, cid_count); |
| 10095 | |
| 10096 | WARN_ON(!cid_count); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10097 | break; |
| 10098 | |
| 10099 | default: |
| 10100 | pr_err("Unknown board_type (%ld), aborting\n", |
| 10101 | ent->driver_data); |
Vasiliy Kulikov | 870634b | 2010-11-14 10:08:34 +0000 | [diff] [blame] | 10102 | return -ENODEV; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10103 | } |
| 10104 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10105 | cid_count += FCOE_CONTEXT_USE; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10106 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10107 | /* dev zeroed in init_etherdev */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10108 | dev = alloc_etherdev_mq(sizeof(*bp), cid_count); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10109 | if (!dev) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10110 | dev_err(&pdev->dev, "Cannot allocate net device\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10111 | return -ENOMEM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10112 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10113 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10114 | /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring, |
| 10115 | * so update a cid_count after a netdev allocation. |
| 10116 | */ |
| 10117 | cid_count += CNIC_CONTEXT_USE; |
| 10118 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10119 | bp = netdev_priv(dev); |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10120 | bp->msg_enable = debug; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10121 | |
Eilon Greenstein | df4770de | 2009-08-12 08:23:28 +0000 | [diff] [blame] | 10122 | pci_set_drvdata(pdev, dev); |
| 10123 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10124 | bp->l2_cid_count = cid_count; |
| 10125 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10126 | rc = bnx2x_init_dev(pdev, dev, ent->driver_data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10127 | if (rc < 0) { |
| 10128 | free_netdev(dev); |
| 10129 | return rc; |
| 10130 | } |
| 10131 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10132 | BNX2X_DEV_INFO("cid_count=%d\n", cid_count); |
| 10133 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10134 | rc = bnx2x_init_bp(bp); |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 10135 | if (rc) |
| 10136 | goto init_one_exit; |
| 10137 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10138 | /* calc qm_cid_count */ |
| 10139 | bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count); |
| 10140 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10141 | #ifdef BCM_CNIC |
| 10142 | /* disable FCOE L2 queue for E1x*/ |
| 10143 | if (CHIP_IS_E1x(bp)) |
| 10144 | bp->flags |= NO_FCOE_FLAG; |
| 10145 | |
| 10146 | #endif |
| 10147 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10148 | /* Configure interrupt mode: try to enable MSI-X/MSI if |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10149 | * needed, set bp->num_queues appropriately. |
| 10150 | */ |
| 10151 | bnx2x_set_int_mode(bp); |
| 10152 | |
| 10153 | /* Add all NAPI objects */ |
| 10154 | bnx2x_add_all_napi(bp); |
| 10155 | |
Vladislav Zolotarov | b340007 | 2010-11-24 11:09:50 -0800 | [diff] [blame] | 10156 | rc = register_netdev(dev); |
| 10157 | if (rc) { |
| 10158 | dev_err(&pdev->dev, "Cannot register net device\n"); |
| 10159 | goto init_one_exit; |
| 10160 | } |
| 10161 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10162 | #ifdef BCM_CNIC |
| 10163 | if (!NO_FCOE(bp)) { |
| 10164 | /* Add storage MAC address */ |
| 10165 | rtnl_lock(); |
| 10166 | dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); |
| 10167 | rtnl_unlock(); |
| 10168 | } |
| 10169 | #endif |
| 10170 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 10171 | bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed); |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10172 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10173 | netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx," |
| 10174 | " IRQ %d, ", board_info[ent->driver_data].name, |
| 10175 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10176 | pcie_width, |
| 10177 | ((!CHIP_IS_E2(bp) && pcie_speed == 2) || |
| 10178 | (CHIP_IS_E2(bp) && pcie_speed == 1)) ? |
| 10179 | "5GHz (Gen2)" : "2.5GHz", |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10180 | dev->base_addr, bp->pdev->irq); |
| 10181 | pr_cont("node addr %pM\n", dev->dev_addr); |
Eilon Greenstein | c016201 | 2009-03-02 08:01:05 +0000 | [diff] [blame] | 10182 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10183 | return 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10184 | |
| 10185 | init_one_exit: |
| 10186 | if (bp->regview) |
| 10187 | iounmap(bp->regview); |
| 10188 | |
| 10189 | if (bp->doorbells) |
| 10190 | iounmap(bp->doorbells); |
| 10191 | |
| 10192 | free_netdev(dev); |
| 10193 | |
| 10194 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10195 | pci_release_regions(pdev); |
| 10196 | |
| 10197 | pci_disable_device(pdev); |
| 10198 | pci_set_drvdata(pdev, NULL); |
| 10199 | |
| 10200 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10201 | } |
| 10202 | |
| 10203 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) |
| 10204 | { |
| 10205 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10206 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10207 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10208 | if (!dev) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10209 | dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n"); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10210 | return; |
| 10211 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10212 | bp = netdev_priv(dev); |
| 10213 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10214 | #ifdef BCM_CNIC |
| 10215 | /* Delete storage MAC address */ |
| 10216 | if (!NO_FCOE(bp)) { |
| 10217 | rtnl_lock(); |
| 10218 | dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); |
| 10219 | rtnl_unlock(); |
| 10220 | } |
| 10221 | #endif |
| 10222 | |
Shmulik Ravid | 9850767 | 2011-02-28 12:19:55 -0800 | [diff] [blame] | 10223 | #ifdef BCM_DCBNL |
| 10224 | /* Delete app tlvs from dcbnl */ |
| 10225 | bnx2x_dcbnl_update_applist(bp, true); |
| 10226 | #endif |
| 10227 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10228 | unregister_netdev(dev); |
| 10229 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10230 | /* Delete all NAPI objects */ |
| 10231 | bnx2x_del_all_napi(bp); |
| 10232 | |
Vladislav Zolotarov | 084d6cb | 2011-01-09 02:20:19 +0000 | [diff] [blame] | 10233 | /* Power on: we can't let PCI layer write to us while we are in D3 */ |
| 10234 | bnx2x_set_power_state(bp, PCI_D0); |
| 10235 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10236 | /* Disable MSI/MSI-X */ |
| 10237 | bnx2x_disable_msi(bp); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10238 | |
Vladislav Zolotarov | 084d6cb | 2011-01-09 02:20:19 +0000 | [diff] [blame] | 10239 | /* Power off */ |
| 10240 | bnx2x_set_power_state(bp, PCI_D3hot); |
| 10241 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10242 | /* Make sure RESET task is not scheduled before continuing */ |
| 10243 | cancel_delayed_work_sync(&bp->reset_task); |
| 10244 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10245 | if (bp->regview) |
| 10246 | iounmap(bp->regview); |
| 10247 | |
| 10248 | if (bp->doorbells) |
| 10249 | iounmap(bp->doorbells); |
| 10250 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10251 | bnx2x_free_mem_bp(bp); |
| 10252 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10253 | free_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10254 | |
| 10255 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10256 | pci_release_regions(pdev); |
| 10257 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10258 | pci_disable_device(pdev); |
| 10259 | pci_set_drvdata(pdev, NULL); |
| 10260 | } |
| 10261 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10262 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
| 10263 | { |
| 10264 | int i; |
| 10265 | |
| 10266 | bp->state = BNX2X_STATE_ERROR; |
| 10267 | |
| 10268 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 10269 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10270 | #ifdef BCM_CNIC |
| 10271 | bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD); |
| 10272 | #endif |
| 10273 | /* Stop Tx */ |
| 10274 | bnx2x_tx_disable(bp); |
| 10275 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10276 | bnx2x_netif_stop(bp, 0); |
| 10277 | |
| 10278 | del_timer_sync(&bp->timer); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10279 | |
| 10280 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10281 | |
| 10282 | /* Release IRQs */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10283 | bnx2x_free_irq(bp); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10284 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10285 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 10286 | bnx2x_free_skbs(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10287 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10288 | for_each_rx_queue(bp, i) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10289 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10290 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10291 | bnx2x_free_mem(bp); |
| 10292 | |
| 10293 | bp->state = BNX2X_STATE_CLOSED; |
| 10294 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10295 | netif_carrier_off(bp->dev); |
| 10296 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10297 | return 0; |
| 10298 | } |
| 10299 | |
| 10300 | static void bnx2x_eeh_recover(struct bnx2x *bp) |
| 10301 | { |
| 10302 | u32 val; |
| 10303 | |
| 10304 | mutex_init(&bp->port.phy_mutex); |
| 10305 | |
| 10306 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 10307 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 10308 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 10309 | |
| 10310 | if (!bp->common.shmem_base || |
| 10311 | (bp->common.shmem_base < 0xA0000) || |
| 10312 | (bp->common.shmem_base >= 0xC0000)) { |
| 10313 | BNX2X_DEV_INFO("MCP not active\n"); |
| 10314 | bp->flags |= NO_MCP_FLAG; |
| 10315 | return; |
| 10316 | } |
| 10317 | |
| 10318 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 10319 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 10320 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 10321 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 10322 | |
| 10323 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10324 | bp->fw_seq = |
| 10325 | (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & |
| 10326 | DRV_MSG_SEQ_NUMBER_MASK); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10327 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 10328 | } |
| 10329 | } |
| 10330 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10331 | /** |
| 10332 | * bnx2x_io_error_detected - called when PCI error is detected |
| 10333 | * @pdev: Pointer to PCI device |
| 10334 | * @state: The current pci connection state |
| 10335 | * |
| 10336 | * This function is called after a PCI bus error affecting |
| 10337 | * this device has been detected. |
| 10338 | */ |
| 10339 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, |
| 10340 | pci_channel_state_t state) |
| 10341 | { |
| 10342 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10343 | struct bnx2x *bp = netdev_priv(dev); |
| 10344 | |
| 10345 | rtnl_lock(); |
| 10346 | |
| 10347 | netif_device_detach(dev); |
| 10348 | |
Dean Nelson | 07ce50e | 2009-07-31 09:13:25 +0000 | [diff] [blame] | 10349 | if (state == pci_channel_io_perm_failure) { |
| 10350 | rtnl_unlock(); |
| 10351 | return PCI_ERS_RESULT_DISCONNECT; |
| 10352 | } |
| 10353 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10354 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10355 | bnx2x_eeh_nic_unload(bp); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10356 | |
| 10357 | pci_disable_device(pdev); |
| 10358 | |
| 10359 | rtnl_unlock(); |
| 10360 | |
| 10361 | /* Request a slot reset */ |
| 10362 | return PCI_ERS_RESULT_NEED_RESET; |
| 10363 | } |
| 10364 | |
| 10365 | /** |
| 10366 | * bnx2x_io_slot_reset - called after the PCI bus has been reset |
| 10367 | * @pdev: Pointer to PCI device |
| 10368 | * |
| 10369 | * Restart the card from scratch, as if from a cold-boot. |
| 10370 | */ |
| 10371 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) |
| 10372 | { |
| 10373 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10374 | struct bnx2x *bp = netdev_priv(dev); |
| 10375 | |
| 10376 | rtnl_lock(); |
| 10377 | |
| 10378 | if (pci_enable_device(pdev)) { |
| 10379 | dev_err(&pdev->dev, |
| 10380 | "Cannot re-enable PCI device after reset\n"); |
| 10381 | rtnl_unlock(); |
| 10382 | return PCI_ERS_RESULT_DISCONNECT; |
| 10383 | } |
| 10384 | |
| 10385 | pci_set_master(pdev); |
| 10386 | pci_restore_state(pdev); |
| 10387 | |
| 10388 | if (netif_running(dev)) |
| 10389 | bnx2x_set_power_state(bp, PCI_D0); |
| 10390 | |
| 10391 | rtnl_unlock(); |
| 10392 | |
| 10393 | return PCI_ERS_RESULT_RECOVERED; |
| 10394 | } |
| 10395 | |
| 10396 | /** |
| 10397 | * bnx2x_io_resume - called when traffic can start flowing again |
| 10398 | * @pdev: Pointer to PCI device |
| 10399 | * |
| 10400 | * This callback is called when the error recovery driver tells us that |
| 10401 | * its OK to resume normal operation. |
| 10402 | */ |
| 10403 | static void bnx2x_io_resume(struct pci_dev *pdev) |
| 10404 | { |
| 10405 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10406 | struct bnx2x *bp = netdev_priv(dev); |
| 10407 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10408 | if (bp->recovery_state != BNX2X_RECOVERY_DONE) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10409 | printk(KERN_ERR "Handling parity error recovery. " |
| 10410 | "Try again later\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10411 | return; |
| 10412 | } |
| 10413 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10414 | rtnl_lock(); |
| 10415 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10416 | bnx2x_eeh_recover(bp); |
| 10417 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10418 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10419 | bnx2x_nic_load(bp, LOAD_NORMAL); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10420 | |
| 10421 | netif_device_attach(dev); |
| 10422 | |
| 10423 | rtnl_unlock(); |
| 10424 | } |
| 10425 | |
| 10426 | static struct pci_error_handlers bnx2x_err_handler = { |
| 10427 | .error_detected = bnx2x_io_error_detected, |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 10428 | .slot_reset = bnx2x_io_slot_reset, |
| 10429 | .resume = bnx2x_io_resume, |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10430 | }; |
| 10431 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10432 | static struct pci_driver bnx2x_pci_driver = { |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10433 | .name = DRV_MODULE_NAME, |
| 10434 | .id_table = bnx2x_pci_tbl, |
| 10435 | .probe = bnx2x_init_one, |
| 10436 | .remove = __devexit_p(bnx2x_remove_one), |
| 10437 | .suspend = bnx2x_suspend, |
| 10438 | .resume = bnx2x_resume, |
| 10439 | .err_handler = &bnx2x_err_handler, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10440 | }; |
| 10441 | |
| 10442 | static int __init bnx2x_init(void) |
| 10443 | { |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10444 | int ret; |
| 10445 | |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10446 | pr_info("%s", version); |
Eilon Greenstein | 938cf54 | 2009-08-12 08:23:37 +0000 | [diff] [blame] | 10447 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10448 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
| 10449 | if (bnx2x_wq == NULL) { |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10450 | pr_err("Cannot create workqueue\n"); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10451 | return -ENOMEM; |
| 10452 | } |
| 10453 | |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10454 | ret = pci_register_driver(&bnx2x_pci_driver); |
| 10455 | if (ret) { |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10456 | pr_err("Cannot register driver\n"); |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10457 | destroy_workqueue(bnx2x_wq); |
| 10458 | } |
| 10459 | return ret; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10460 | } |
| 10461 | |
| 10462 | static void __exit bnx2x_cleanup(void) |
| 10463 | { |
| 10464 | pci_unregister_driver(&bnx2x_pci_driver); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10465 | |
| 10466 | destroy_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10467 | } |
| 10468 | |
| 10469 | module_init(bnx2x_init); |
| 10470 | module_exit(bnx2x_cleanup); |
| 10471 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10472 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10473 | /** |
| 10474 | * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s). |
| 10475 | * |
| 10476 | * @bp: driver handle |
| 10477 | * @set: set or clear the CAM entry |
| 10478 | * |
| 10479 | * This function will wait until the ramdord completion returns. |
| 10480 | * Return 0 if success, -ENODEV if ramrod doesn't return. |
| 10481 | */ |
| 10482 | static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp) |
| 10483 | { |
| 10484 | unsigned long ramrod_flags = 0; |
| 10485 | |
| 10486 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 10487 | return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac, |
| 10488 | &bp->iscsi_l2_mac_obj, true, |
| 10489 | BNX2X_ISCSI_ETH_MAC, &ramrod_flags); |
| 10490 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10491 | |
| 10492 | /* count denotes the number of new completions we have seen */ |
| 10493 | static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count) |
| 10494 | { |
| 10495 | struct eth_spe *spe; |
| 10496 | |
| 10497 | #ifdef BNX2X_STOP_ON_ERROR |
| 10498 | if (unlikely(bp->panic)) |
| 10499 | return; |
| 10500 | #endif |
| 10501 | |
| 10502 | spin_lock_bh(&bp->spq_lock); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10503 | BUG_ON(bp->cnic_spq_pending < count); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10504 | bp->cnic_spq_pending -= count; |
| 10505 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10506 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10507 | for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) { |
| 10508 | u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type) |
| 10509 | & SPE_HDR_CONN_TYPE) >> |
| 10510 | SPE_HDR_CONN_TYPE_SHIFT; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10511 | u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data) |
| 10512 | >> SPE_HDR_CMD_ID_SHIFT) & 0xff; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10513 | |
| 10514 | /* Set validation for iSCSI L2 client before sending SETUP |
| 10515 | * ramrod |
| 10516 | */ |
| 10517 | if (type == ETH_CONNECTION_TYPE) { |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10518 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10519 | bnx2x_set_ctx_validation(bp, &bp->context. |
| 10520 | vcxt[BNX2X_ISCSI_ETH_CID].eth, |
| 10521 | BNX2X_ISCSI_ETH_CID); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10522 | } |
| 10523 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10524 | /* |
| 10525 | * There may be not more than 8 L2, not more than 8 L5 SPEs |
| 10526 | * and in the air. We also check that number of outstanding |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10527 | * COMMON ramrods is not more than the EQ and SPQ can |
| 10528 | * accommodate. |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10529 | */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10530 | if (type == ETH_CONNECTION_TYPE) { |
| 10531 | if (!atomic_read(&bp->cq_spq_left)) |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10532 | break; |
| 10533 | else |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10534 | atomic_dec(&bp->cq_spq_left); |
| 10535 | } else if (type == NONE_CONNECTION_TYPE) { |
| 10536 | if (!atomic_read(&bp->eq_spq_left)) |
| 10537 | break; |
| 10538 | else |
| 10539 | atomic_dec(&bp->eq_spq_left); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10540 | } else if ((type == ISCSI_CONNECTION_TYPE) || |
| 10541 | (type == FCOE_CONNECTION_TYPE)) { |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10542 | if (bp->cnic_spq_pending >= |
| 10543 | bp->cnic_eth_dev.max_kwqe_pending) |
| 10544 | break; |
| 10545 | else |
| 10546 | bp->cnic_spq_pending++; |
| 10547 | } else { |
| 10548 | BNX2X_ERR("Unknown SPE type: %d\n", type); |
| 10549 | bnx2x_panic(); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10550 | break; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10551 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10552 | |
| 10553 | spe = bnx2x_sp_get_next(bp); |
| 10554 | *spe = *bp->cnic_kwq_cons; |
| 10555 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10556 | DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n", |
| 10557 | bp->cnic_spq_pending, bp->cnic_kwq_pending, count); |
| 10558 | |
| 10559 | if (bp->cnic_kwq_cons == bp->cnic_kwq_last) |
| 10560 | bp->cnic_kwq_cons = bp->cnic_kwq; |
| 10561 | else |
| 10562 | bp->cnic_kwq_cons++; |
| 10563 | } |
| 10564 | bnx2x_sp_prod_update(bp); |
| 10565 | spin_unlock_bh(&bp->spq_lock); |
| 10566 | } |
| 10567 | |
| 10568 | static int bnx2x_cnic_sp_queue(struct net_device *dev, |
| 10569 | struct kwqe_16 *kwqes[], u32 count) |
| 10570 | { |
| 10571 | struct bnx2x *bp = netdev_priv(dev); |
| 10572 | int i; |
| 10573 | |
| 10574 | #ifdef BNX2X_STOP_ON_ERROR |
| 10575 | if (unlikely(bp->panic)) |
| 10576 | return -EIO; |
| 10577 | #endif |
| 10578 | |
| 10579 | spin_lock_bh(&bp->spq_lock); |
| 10580 | |
| 10581 | for (i = 0; i < count; i++) { |
| 10582 | struct eth_spe *spe = (struct eth_spe *)kwqes[i]; |
| 10583 | |
| 10584 | if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT) |
| 10585 | break; |
| 10586 | |
| 10587 | *bp->cnic_kwq_prod = *spe; |
| 10588 | |
| 10589 | bp->cnic_kwq_pending++; |
| 10590 | |
| 10591 | DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n", |
| 10592 | spe->hdr.conn_and_cmd_data, spe->hdr.type, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10593 | spe->data.update_data_addr.hi, |
| 10594 | spe->data.update_data_addr.lo, |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10595 | bp->cnic_kwq_pending); |
| 10596 | |
| 10597 | if (bp->cnic_kwq_prod == bp->cnic_kwq_last) |
| 10598 | bp->cnic_kwq_prod = bp->cnic_kwq; |
| 10599 | else |
| 10600 | bp->cnic_kwq_prod++; |
| 10601 | } |
| 10602 | |
| 10603 | spin_unlock_bh(&bp->spq_lock); |
| 10604 | |
| 10605 | if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending) |
| 10606 | bnx2x_cnic_sp_post(bp, 0); |
| 10607 | |
| 10608 | return i; |
| 10609 | } |
| 10610 | |
| 10611 | static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl) |
| 10612 | { |
| 10613 | struct cnic_ops *c_ops; |
| 10614 | int rc = 0; |
| 10615 | |
| 10616 | mutex_lock(&bp->cnic_mutex); |
Eric Dumazet | 13707f9 | 2011-01-26 19:28:23 +0000 | [diff] [blame] | 10617 | c_ops = rcu_dereference_protected(bp->cnic_ops, |
| 10618 | lockdep_is_held(&bp->cnic_mutex)); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10619 | if (c_ops) |
| 10620 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); |
| 10621 | mutex_unlock(&bp->cnic_mutex); |
| 10622 | |
| 10623 | return rc; |
| 10624 | } |
| 10625 | |
| 10626 | static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl) |
| 10627 | { |
| 10628 | struct cnic_ops *c_ops; |
| 10629 | int rc = 0; |
| 10630 | |
| 10631 | rcu_read_lock(); |
| 10632 | c_ops = rcu_dereference(bp->cnic_ops); |
| 10633 | if (c_ops) |
| 10634 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); |
| 10635 | rcu_read_unlock(); |
| 10636 | |
| 10637 | return rc; |
| 10638 | } |
| 10639 | |
| 10640 | /* |
| 10641 | * for commands that have no data |
| 10642 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 10643 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd) |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10644 | { |
| 10645 | struct cnic_ctl_info ctl = {0}; |
| 10646 | |
| 10647 | ctl.cmd = cmd; |
| 10648 | |
| 10649 | return bnx2x_cnic_ctl_send(bp, &ctl); |
| 10650 | } |
| 10651 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10652 | static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err) |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10653 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10654 | struct cnic_ctl_info ctl = {0}; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10655 | |
| 10656 | /* first we tell CNIC and only then we count this as a completion */ |
| 10657 | ctl.cmd = CNIC_CTL_COMPLETION_CMD; |
| 10658 | ctl.data.comp.cid = cid; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10659 | ctl.data.comp.error = err; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10660 | |
| 10661 | bnx2x_cnic_ctl_send_bh(bp, &ctl); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10662 | bnx2x_cnic_sp_post(bp, 0); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10663 | } |
| 10664 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10665 | |
| 10666 | /* Called with netif_addr_lock_bh() taken. |
| 10667 | * Sets an rx_mode config for an iSCSI ETH client. |
| 10668 | * Doesn't block. |
| 10669 | * Completion should be checked outside. |
| 10670 | */ |
| 10671 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start) |
| 10672 | { |
| 10673 | unsigned long accept_flags = 0, ramrod_flags = 0; |
| 10674 | u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); |
| 10675 | int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED; |
| 10676 | |
| 10677 | if (start) { |
| 10678 | /* Start accepting on iSCSI L2 ring. Accept all multicasts |
| 10679 | * because it's the only way for UIO Queue to accept |
| 10680 | * multicasts (in non-promiscuous mode only one Queue per |
| 10681 | * function will receive multicast packets (leading in our |
| 10682 | * case). |
| 10683 | */ |
| 10684 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags); |
| 10685 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags); |
| 10686 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags); |
| 10687 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); |
| 10688 | |
| 10689 | /* Clear STOP_PENDING bit if START is requested */ |
| 10690 | clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state); |
| 10691 | |
| 10692 | sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED; |
| 10693 | } else |
| 10694 | /* Clear START_PENDING bit if STOP is requested */ |
| 10695 | clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state); |
| 10696 | |
| 10697 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) |
| 10698 | set_bit(sched_state, &bp->sp_state); |
| 10699 | else { |
| 10700 | __set_bit(RAMROD_RX, &ramrod_flags); |
| 10701 | bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0, |
| 10702 | ramrod_flags); |
| 10703 | } |
| 10704 | } |
| 10705 | |
| 10706 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10707 | static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl) |
| 10708 | { |
| 10709 | struct bnx2x *bp = netdev_priv(dev); |
| 10710 | int rc = 0; |
| 10711 | |
| 10712 | switch (ctl->cmd) { |
| 10713 | case DRV_CTL_CTXTBL_WR_CMD: { |
| 10714 | u32 index = ctl->data.io.offset; |
| 10715 | dma_addr_t addr = ctl->data.io.dma_addr; |
| 10716 | |
| 10717 | bnx2x_ilt_wr(bp, index, addr); |
| 10718 | break; |
| 10719 | } |
| 10720 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10721 | case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: { |
| 10722 | int count = ctl->data.credit.credit_count; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10723 | |
| 10724 | bnx2x_cnic_sp_post(bp, count); |
| 10725 | break; |
| 10726 | } |
| 10727 | |
| 10728 | /* rtnl_lock is held. */ |
| 10729 | case DRV_CTL_START_L2_CMD: { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10730 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10731 | unsigned long sp_bits = 0; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10732 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10733 | /* Configure the iSCSI classification object */ |
| 10734 | bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj, |
| 10735 | cp->iscsi_l2_client_id, |
| 10736 | cp->iscsi_l2_cid, BP_FUNC(bp), |
| 10737 | bnx2x_sp(bp, mac_rdata), |
| 10738 | bnx2x_sp_mapping(bp, mac_rdata), |
| 10739 | BNX2X_FILTER_MAC_PENDING, |
| 10740 | &bp->sp_state, BNX2X_OBJ_TYPE_RX, |
| 10741 | &bp->macs_pool); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10742 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10743 | /* Set iSCSI MAC address */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10744 | rc = bnx2x_set_iscsi_eth_mac_addr(bp); |
| 10745 | if (rc) |
| 10746 | break; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10747 | |
| 10748 | mmiowb(); |
| 10749 | barrier(); |
| 10750 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10751 | /* Start accepting on iSCSI L2 ring */ |
| 10752 | |
| 10753 | netif_addr_lock_bh(dev); |
| 10754 | bnx2x_set_iscsi_eth_rx_mode(bp, true); |
| 10755 | netif_addr_unlock_bh(dev); |
| 10756 | |
| 10757 | /* bits to wait on */ |
| 10758 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); |
| 10759 | __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits); |
| 10760 | |
| 10761 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) |
| 10762 | BNX2X_ERR("rx_mode completion timed out!\n"); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10763 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10764 | break; |
| 10765 | } |
| 10766 | |
| 10767 | /* rtnl_lock is held. */ |
| 10768 | case DRV_CTL_STOP_L2_CMD: { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10769 | unsigned long sp_bits = 0; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10770 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10771 | /* Stop accepting on iSCSI L2 ring */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10772 | netif_addr_lock_bh(dev); |
| 10773 | bnx2x_set_iscsi_eth_rx_mode(bp, false); |
| 10774 | netif_addr_unlock_bh(dev); |
| 10775 | |
| 10776 | /* bits to wait on */ |
| 10777 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); |
| 10778 | __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits); |
| 10779 | |
| 10780 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) |
| 10781 | BNX2X_ERR("rx_mode completion timed out!\n"); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10782 | |
| 10783 | mmiowb(); |
| 10784 | barrier(); |
| 10785 | |
| 10786 | /* Unset iSCSI L2 MAC */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10787 | rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj, |
| 10788 | BNX2X_ISCSI_ETH_MAC, true); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10789 | break; |
| 10790 | } |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10791 | case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: { |
| 10792 | int count = ctl->data.credit.credit_count; |
| 10793 | |
| 10794 | smp_mb__before_atomic_inc(); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10795 | atomic_add(count, &bp->cq_spq_left); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10796 | smp_mb__after_atomic_inc(); |
| 10797 | break; |
| 10798 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10799 | |
| 10800 | default: |
| 10801 | BNX2X_ERR("unknown command %x\n", ctl->cmd); |
| 10802 | rc = -EINVAL; |
| 10803 | } |
| 10804 | |
| 10805 | return rc; |
| 10806 | } |
| 10807 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 10808 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10809 | { |
| 10810 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10811 | |
| 10812 | if (bp->flags & USING_MSIX_FLAG) { |
| 10813 | cp->drv_state |= CNIC_DRV_STATE_USING_MSIX; |
| 10814 | cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX; |
| 10815 | cp->irq_arr[0].vector = bp->msix_table[1].vector; |
| 10816 | } else { |
| 10817 | cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX; |
| 10818 | cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX; |
| 10819 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10820 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10821 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb; |
| 10822 | else |
| 10823 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; |
| 10824 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10825 | cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); |
| 10826 | cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10827 | cp->irq_arr[1].status_blk = bp->def_status_blk; |
| 10828 | cp->irq_arr[1].status_blk_num = DEF_SB_ID; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10829 | cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10830 | |
| 10831 | cp->num_irq = 2; |
| 10832 | } |
| 10833 | |
| 10834 | static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops, |
| 10835 | void *data) |
| 10836 | { |
| 10837 | struct bnx2x *bp = netdev_priv(dev); |
| 10838 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10839 | |
| 10840 | if (ops == NULL) |
| 10841 | return -EINVAL; |
| 10842 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10843 | bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 10844 | if (!bp->cnic_kwq) |
| 10845 | return -ENOMEM; |
| 10846 | |
| 10847 | bp->cnic_kwq_cons = bp->cnic_kwq; |
| 10848 | bp->cnic_kwq_prod = bp->cnic_kwq; |
| 10849 | bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT; |
| 10850 | |
| 10851 | bp->cnic_spq_pending = 0; |
| 10852 | bp->cnic_kwq_pending = 0; |
| 10853 | |
| 10854 | bp->cnic_data = data; |
| 10855 | |
| 10856 | cp->num_irq = 0; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10857 | cp->drv_state |= CNIC_DRV_STATE_REGD; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10858 | cp->iro_arr = bp->iro_arr; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10859 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10860 | bnx2x_setup_cnic_irq_info(bp); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10861 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10862 | rcu_assign_pointer(bp->cnic_ops, ops); |
| 10863 | |
| 10864 | return 0; |
| 10865 | } |
| 10866 | |
| 10867 | static int bnx2x_unregister_cnic(struct net_device *dev) |
| 10868 | { |
| 10869 | struct bnx2x *bp = netdev_priv(dev); |
| 10870 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10871 | |
| 10872 | mutex_lock(&bp->cnic_mutex); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10873 | cp->drv_state = 0; |
| 10874 | rcu_assign_pointer(bp->cnic_ops, NULL); |
| 10875 | mutex_unlock(&bp->cnic_mutex); |
| 10876 | synchronize_rcu(); |
| 10877 | kfree(bp->cnic_kwq); |
| 10878 | bp->cnic_kwq = NULL; |
| 10879 | |
| 10880 | return 0; |
| 10881 | } |
| 10882 | |
| 10883 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev) |
| 10884 | { |
| 10885 | struct bnx2x *bp = netdev_priv(dev); |
| 10886 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10887 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 10888 | /* If both iSCSI and FCoE are disabled - return NULL in |
| 10889 | * order to indicate CNIC that it should not try to work |
| 10890 | * with this device. |
| 10891 | */ |
| 10892 | if (NO_ISCSI(bp) && NO_FCOE(bp)) |
| 10893 | return NULL; |
| 10894 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10895 | cp->drv_owner = THIS_MODULE; |
| 10896 | cp->chip_id = CHIP_ID(bp); |
| 10897 | cp->pdev = bp->pdev; |
| 10898 | cp->io_base = bp->regview; |
| 10899 | cp->io_base2 = bp->doorbells; |
| 10900 | cp->max_kwqe_pending = 8; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10901 | cp->ctx_blk_size = CDU_ILT_PAGE_SZ; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10902 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
| 10903 | bnx2x_cid_ilt_lines(bp); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10904 | cp->ctx_tbl_len = CNIC_ILT_LINES; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10905 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10906 | cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue; |
| 10907 | cp->drv_ctl = bnx2x_drv_ctl; |
| 10908 | cp->drv_register_cnic = bnx2x_register_cnic; |
| 10909 | cp->drv_unregister_cnic = bnx2x_unregister_cnic; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10910 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10911 | cp->iscsi_l2_client_id = |
| 10912 | bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10913 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10914 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 10915 | if (NO_ISCSI_OOO(bp)) |
| 10916 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; |
| 10917 | |
| 10918 | if (NO_ISCSI(bp)) |
| 10919 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI; |
| 10920 | |
| 10921 | if (NO_FCOE(bp)) |
| 10922 | cp->drv_state |= CNIC_DRV_STATE_NO_FCOE; |
| 10923 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10924 | DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, " |
| 10925 | "starting cid %d\n", |
| 10926 | cp->ctx_blk_size, |
| 10927 | cp->ctx_tbl_offset, |
| 10928 | cp->ctx_tbl_len, |
| 10929 | cp->starting_cid); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10930 | return cp; |
| 10931 | } |
| 10932 | EXPORT_SYMBOL(bnx2x_cnic_probe); |
| 10933 | |
| 10934 | #endif /* BCM_CNIC */ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 10935 | |