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) |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 1560 | synchronize_irq(bp->msix_table[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 | |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 2517 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n", |
| 2518 | (command | seq), param); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2519 | |
| 2520 | do { |
| 2521 | /* let the FW do it's magic ... */ |
| 2522 | msleep(delay); |
| 2523 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2524 | rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2525 | |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 2526 | /* Give the FW up to 5 second (500*10ms) */ |
| 2527 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500)); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2528 | |
| 2529 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", |
| 2530 | cnt*delay, rc, seq); |
| 2531 | |
| 2532 | /* is this a reply to our command? */ |
| 2533 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) |
| 2534 | rc &= FW_MSG_CODE_MASK; |
| 2535 | else { |
| 2536 | /* FW BUG! */ |
| 2537 | BNX2X_ERR("FW failed to respond!\n"); |
| 2538 | bnx2x_fw_dump(bp); |
| 2539 | rc = 0; |
| 2540 | } |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 2541 | mutex_unlock(&bp->fw_mb_mutex); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2542 | |
| 2543 | return rc; |
| 2544 | } |
| 2545 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2546 | static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp) |
| 2547 | { |
| 2548 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2549 | /* Statistics are not supported for CNIC Clients at the moment */ |
| 2550 | if (IS_FCOE_FP(fp)) |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2551 | return false; |
| 2552 | #endif |
| 2553 | return true; |
| 2554 | } |
| 2555 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2556 | 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] | 2557 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2558 | if (CHIP_IS_E1x(bp)) { |
| 2559 | struct tstorm_eth_function_common_config tcfg = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2560 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2561 | storm_memset_func_cfg(bp, &tcfg, p->func_id); |
| 2562 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2563 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2564 | /* Enable the function in the FW */ |
| 2565 | storm_memset_vf_to_pf(bp, p->func_id, p->pf_id); |
| 2566 | storm_memset_func_en(bp, p->func_id, 1); |
| 2567 | |
| 2568 | /* spq */ |
| 2569 | if (p->func_flgs & FUNC_FLG_SPQ) { |
| 2570 | storm_memset_spq_addr(bp, p->spq_map, p->func_id); |
| 2571 | REG_WR(bp, XSEM_REG_FAST_MEMORY + |
| 2572 | XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod); |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp, |
| 2577 | struct bnx2x_fastpath *fp, |
| 2578 | bool leading) |
| 2579 | { |
| 2580 | unsigned long flags = 0; |
| 2581 | |
| 2582 | /* PF driver will always initialize the Queue to an ACTIVE state */ |
| 2583 | __set_bit(BNX2X_Q_FLG_ACTIVE, &flags); |
| 2584 | |
| 2585 | /* calculate other queue flags */ |
| 2586 | if (IS_MF_SD(bp)) |
| 2587 | __set_bit(BNX2X_Q_FLG_OV, &flags); |
| 2588 | |
| 2589 | if (IS_FCOE_FP(fp)) |
| 2590 | __set_bit(BNX2X_Q_FLG_FCOE, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2591 | |
| 2592 | if (!fp->disable_tpa) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2593 | __set_bit(BNX2X_Q_FLG_TPA, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2594 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2595 | if (stat_counter_valid(bp, fp)) { |
| 2596 | __set_bit(BNX2X_Q_FLG_STATS, &flags); |
| 2597 | __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags); |
| 2598 | } |
| 2599 | |
| 2600 | if (leading) { |
| 2601 | __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags); |
| 2602 | __set_bit(BNX2X_Q_FLG_MCAST, &flags); |
| 2603 | } |
| 2604 | |
| 2605 | /* Always set HW VLAN stripping */ |
| 2606 | __set_bit(BNX2X_Q_FLG_VLAN, &flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2607 | |
| 2608 | return flags; |
| 2609 | } |
| 2610 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2611 | static void bnx2x_pf_q_prep_general(struct bnx2x *bp, |
| 2612 | struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2613 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2614 | gen_init->stat_id = bnx2x_stats_id(fp); |
| 2615 | gen_init->spcl_id = fp->cl_id; |
| 2616 | |
| 2617 | /* Always use mini-jumbo MTU for FCoE L2 ring */ |
| 2618 | if (IS_FCOE_FP(fp)) |
| 2619 | gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU; |
| 2620 | else |
| 2621 | gen_init->mtu = bp->dev->mtu; |
| 2622 | } |
| 2623 | |
| 2624 | static void bnx2x_pf_rx_q_prep(struct bnx2x *bp, |
| 2625 | struct bnx2x_fastpath *fp, struct rxq_pause_params *pause, |
| 2626 | struct bnx2x_rxq_setup_params *rxq_init) |
| 2627 | { |
| 2628 | u8 max_sge = 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2629 | u16 sge_sz = 0; |
| 2630 | u16 tpa_agg_size = 0; |
| 2631 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2632 | if (!fp->disable_tpa) { |
| 2633 | pause->sge_th_hi = 250; |
| 2634 | pause->sge_th_lo = 150; |
| 2635 | tpa_agg_size = min_t(u32, |
| 2636 | (min_t(u32, 8, MAX_SKB_FRAGS) * |
| 2637 | SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff); |
| 2638 | max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >> |
| 2639 | SGE_PAGE_SHIFT; |
| 2640 | max_sge = ((max_sge + PAGES_PER_SGE - 1) & |
| 2641 | (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; |
| 2642 | sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE, |
| 2643 | 0xffff); |
| 2644 | } |
| 2645 | |
| 2646 | /* pause - not for e1 */ |
| 2647 | if (!CHIP_IS_E1(bp)) { |
| 2648 | pause->bd_th_hi = 350; |
| 2649 | pause->bd_th_lo = 250; |
| 2650 | pause->rcq_th_hi = 350; |
| 2651 | pause->rcq_th_lo = 250; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2652 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2653 | pause->pri_map = 1; |
| 2654 | } |
| 2655 | |
| 2656 | /* rxq setup */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2657 | rxq_init->dscr_map = fp->rx_desc_mapping; |
| 2658 | rxq_init->sge_map = fp->rx_sge_mapping; |
| 2659 | rxq_init->rcq_map = fp->rx_comp_mapping; |
| 2660 | rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE; |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 2661 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2662 | /* This should be a maximum number of data bytes that may be |
| 2663 | * placed on the BD (not including paddings). |
| 2664 | */ |
| 2665 | rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN - |
| 2666 | IP_HEADER_ALIGNMENT_PADDING; |
Vladislav Zolotarov | a8c94b9 | 2011-02-06 11:21:02 -0800 | [diff] [blame] | 2667 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2668 | rxq_init->cl_qzone_id = fp->cl_qzone_id; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2669 | rxq_init->tpa_agg_sz = tpa_agg_size; |
| 2670 | rxq_init->sge_buf_sz = sge_sz; |
| 2671 | rxq_init->max_sges_pkt = max_sge; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2672 | rxq_init->rss_engine_id = BP_FUNC(bp); |
| 2673 | |
| 2674 | /* Maximum number or simultaneous TPA aggregation for this Queue. |
| 2675 | * |
| 2676 | * For PF Clients it should be the maximum avaliable number. |
| 2677 | * VF driver(s) may want to define it to a smaller value. |
| 2678 | */ |
| 2679 | rxq_init->max_tpa_queues = |
| 2680 | (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 : |
| 2681 | ETH_MAX_AGGREGATION_QUEUES_E1H_E2); |
| 2682 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2683 | rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT; |
| 2684 | rxq_init->fw_sb_id = fp->fw_sb_id; |
| 2685 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2686 | if (IS_FCOE_FP(fp)) |
| 2687 | rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS; |
| 2688 | else |
| 2689 | rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2692 | static void bnx2x_pf_tx_q_prep(struct bnx2x *bp, |
| 2693 | struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2694 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2695 | txq_init->dscr_map = fp->tx_desc_mapping; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2696 | txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX; |
| 2697 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW; |
| 2698 | txq_init->fw_sb_id = fp->fw_sb_id; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2699 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2700 | /* |
| 2701 | * set the tss leading client id for TX classfication == |
| 2702 | * leading RSS client id |
| 2703 | */ |
| 2704 | txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id); |
| 2705 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 2706 | if (IS_FCOE_FP(fp)) { |
| 2707 | txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS; |
| 2708 | txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE; |
| 2709 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 2712 | static void bnx2x_pf_init(struct bnx2x *bp) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2713 | { |
| 2714 | struct bnx2x_func_init_params func_init = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2715 | struct event_ring_data eq_data = { {0} }; |
| 2716 | u16 flags; |
| 2717 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2718 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2719 | /* reset IGU PF statistics: MSIX + ATTN */ |
| 2720 | /* PF */ |
| 2721 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + |
| 2722 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + |
| 2723 | (CHIP_MODE_IS_4_PORT(bp) ? |
| 2724 | BP_FUNC(bp) : BP_VN(bp))*4, 0); |
| 2725 | /* ATTN */ |
| 2726 | REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + |
| 2727 | BNX2X_IGU_STAS_MSG_VF_CNT*4 + |
| 2728 | BNX2X_IGU_STAS_MSG_PF_CNT*4 + |
| 2729 | (CHIP_MODE_IS_4_PORT(bp) ? |
| 2730 | BP_FUNC(bp) : BP_VN(bp))*4, 0); |
| 2731 | } |
| 2732 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2733 | /* function setup flags */ |
| 2734 | flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ); |
| 2735 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2736 | /* This flag is relevant for E1x only. |
| 2737 | * E2 doesn't have a TPA configuration in a function level. |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2738 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2739 | flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2740 | |
| 2741 | func_init.func_flgs = flags; |
| 2742 | func_init.pf_id = BP_FUNC(bp); |
| 2743 | func_init.func_id = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2744 | func_init.spq_map = bp->spq_mapping; |
| 2745 | func_init.spq_prod = bp->spq_prod_idx; |
| 2746 | |
| 2747 | bnx2x_func_init(bp, &func_init); |
| 2748 | |
| 2749 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); |
| 2750 | |
| 2751 | /* |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2752 | * Congestion management values depend on the link rate |
| 2753 | * There is no active link so initial link rate is set to 10 Gbps. |
| 2754 | * When the link comes up The congestion management values are |
| 2755 | * re-calculated according to the actual link rate. |
| 2756 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2757 | bp->link_vars.line_speed = SPEED_10000; |
| 2758 | bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp)); |
| 2759 | |
| 2760 | /* Only the PMF sets the HW */ |
| 2761 | if (bp->port.pmf) |
| 2762 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); |
| 2763 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2764 | /* init Event Queue */ |
| 2765 | eq_data.base_addr.hi = U64_HI(bp->eq_mapping); |
| 2766 | eq_data.base_addr.lo = U64_LO(bp->eq_mapping); |
| 2767 | eq_data.producer = bp->eq_prod; |
| 2768 | eq_data.index_id = HC_SP_INDEX_EQ_CONS; |
| 2769 | eq_data.sb_id = DEF_SB_ID; |
| 2770 | storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp)); |
| 2771 | } |
| 2772 | |
| 2773 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2774 | static void bnx2x_e1h_disable(struct bnx2x *bp) |
| 2775 | { |
| 2776 | int port = BP_PORT(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2777 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2778 | bnx2x_tx_disable(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2779 | |
| 2780 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | static void bnx2x_e1h_enable(struct bnx2x *bp) |
| 2784 | { |
| 2785 | int port = BP_PORT(bp); |
| 2786 | |
| 2787 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 2788 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2789 | /* Tx queue should be only reenabled */ |
| 2790 | netif_tx_wake_all_queues(bp->dev); |
| 2791 | |
Eilon Greenstein | 061bc70 | 2009-10-15 00:18:47 -0700 | [diff] [blame] | 2792 | /* |
| 2793 | * Should not call netif_carrier_on since it will be called if the link |
| 2794 | * is up when checking for link state |
| 2795 | */ |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2798 | /* called due to MCP event (on pmf): |
| 2799 | * reread new bandwidth configuration |
| 2800 | * configure FW |
| 2801 | * notify others function about the change |
| 2802 | */ |
| 2803 | static inline void bnx2x_config_mf_bw(struct bnx2x *bp) |
| 2804 | { |
| 2805 | if (bp->link_vars.link_up) { |
| 2806 | bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX); |
| 2807 | bnx2x_link_sync_notify(bp); |
| 2808 | } |
| 2809 | storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp)); |
| 2810 | } |
| 2811 | |
| 2812 | static inline void bnx2x_set_mf_bw(struct bnx2x *bp) |
| 2813 | { |
| 2814 | bnx2x_config_mf_bw(bp); |
| 2815 | bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0); |
| 2816 | } |
| 2817 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2818 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
| 2819 | { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2820 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2821 | |
| 2822 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { |
| 2823 | |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2824 | /* |
| 2825 | * This is the only place besides the function initialization |
| 2826 | * where the bp->flags can change so it is done without any |
| 2827 | * locks |
| 2828 | */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 2829 | if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2830 | DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n"); |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2831 | bp->flags |= MF_FUNC_DIS; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2832 | |
| 2833 | bnx2x_e1h_disable(bp); |
| 2834 | } else { |
| 2835 | DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n"); |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 2836 | bp->flags &= ~MF_FUNC_DIS; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2837 | |
| 2838 | bnx2x_e1h_enable(bp); |
| 2839 | } |
| 2840 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; |
| 2841 | } |
| 2842 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 2843 | bnx2x_config_mf_bw(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2844 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
| 2845 | } |
| 2846 | |
| 2847 | /* Report results to MCP */ |
| 2848 | if (dcc_event) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2849 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2850 | else |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 2851 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2854 | /* must be called under the spq lock */ |
| 2855 | static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp) |
| 2856 | { |
| 2857 | struct eth_spe *next_spe = bp->spq_prod_bd; |
| 2858 | |
| 2859 | if (bp->spq_prod_bd == bp->spq_last_bd) { |
| 2860 | bp->spq_prod_bd = bp->spq; |
| 2861 | bp->spq_prod_idx = 0; |
| 2862 | DP(NETIF_MSG_TIMER, "end of spq\n"); |
| 2863 | } else { |
| 2864 | bp->spq_prod_bd++; |
| 2865 | bp->spq_prod_idx++; |
| 2866 | } |
| 2867 | return next_spe; |
| 2868 | } |
| 2869 | |
| 2870 | /* must be called under the spq lock */ |
| 2871 | static inline void bnx2x_sp_prod_update(struct bnx2x *bp) |
| 2872 | { |
| 2873 | int func = BP_FUNC(bp); |
| 2874 | |
| 2875 | /* Make sure that BD data is updated before writing the producer */ |
| 2876 | wmb(); |
| 2877 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2878 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 2879 | bp->spq_prod_idx); |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2880 | mmiowb(); |
| 2881 | } |
| 2882 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2883 | /** |
| 2884 | * bnx2x_is_contextless_ramrod - check if the current command ends on EQ |
| 2885 | * |
| 2886 | * @cmd: command to check |
| 2887 | * @cmd_type: command type |
| 2888 | */ |
| 2889 | static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type) |
| 2890 | { |
| 2891 | if ((cmd_type == NONE_CONNECTION_TYPE) || |
| 2892 | (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) || |
| 2893 | (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) || |
| 2894 | (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) || |
| 2895 | (cmd == RAMROD_CMD_ID_ETH_SET_MAC) || |
| 2896 | (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) |
| 2897 | return true; |
| 2898 | else |
| 2899 | return false; |
| 2900 | |
| 2901 | } |
| 2902 | |
| 2903 | |
| 2904 | /** |
| 2905 | * bnx2x_sp_post - place a single command on an SP ring |
| 2906 | * |
| 2907 | * @bp: driver handle |
| 2908 | * @command: command to place (e.g. SETUP, FILTER_RULES, etc.) |
| 2909 | * @cid: SW CID the command is related to |
| 2910 | * @data_hi: command private data address (high 32 bits) |
| 2911 | * @data_lo: command private data address (low 32 bits) |
| 2912 | * @cmd_type: command type (e.g. NONE, ETH) |
| 2913 | * |
| 2914 | * SP data is handled as if it's always an address pair, thus data fields are |
| 2915 | * not swapped to little endian in upper functions. Instead this function swaps |
| 2916 | * data as if it's two u32 fields. |
| 2917 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 2918 | int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2919 | u32 data_hi, u32 data_lo, int cmd_type) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2920 | { |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2921 | struct eth_spe *spe; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2922 | u16 type; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2923 | bool common = bnx2x_is_contextless_ramrod(command, cmd_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2924 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2925 | #ifdef BNX2X_STOP_ON_ERROR |
| 2926 | if (unlikely(bp->panic)) |
| 2927 | return -EIO; |
| 2928 | #endif |
| 2929 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2930 | spin_lock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2931 | |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2932 | if (common) { |
| 2933 | if (!atomic_read(&bp->eq_spq_left)) { |
| 2934 | BNX2X_ERR("BUG! EQ ring full!\n"); |
| 2935 | spin_unlock_bh(&bp->spq_lock); |
| 2936 | bnx2x_panic(); |
| 2937 | return -EBUSY; |
| 2938 | } |
| 2939 | } else if (!atomic_read(&bp->cq_spq_left)) { |
| 2940 | BNX2X_ERR("BUG! SPQ ring full!\n"); |
| 2941 | spin_unlock_bh(&bp->spq_lock); |
| 2942 | bnx2x_panic(); |
| 2943 | return -EBUSY; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2944 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2945 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2946 | spe = bnx2x_sp_get_next(bp); |
| 2947 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2948 | /* CID needs port number to be encoded int it */ |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2949 | spe->hdr.conn_and_cmd_data = |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2950 | cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) | |
| 2951 | HW_CID(bp, cid)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2952 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2953 | type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2954 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2955 | type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) & |
| 2956 | SPE_HDR_FUNCTION_ID); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2957 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2958 | spe->hdr.type = cpu_to_le16(type); |
| 2959 | |
| 2960 | spe->data.update_data_addr.hi = cpu_to_le32(data_hi); |
| 2961 | spe->data.update_data_addr.lo = cpu_to_le32(data_lo); |
| 2962 | |
| 2963 | /* stats ramrod has it's own slot on the spq */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2964 | if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 2965 | /* |
| 2966 | * It's ok if the actual decrement is issued towards the memory |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2967 | * somewhere between the spin_lock and spin_unlock. Thus no |
| 2968 | * more explict memory barrier is needed. |
| 2969 | */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2970 | if (common) |
| 2971 | atomic_dec(&bp->eq_spq_left); |
| 2972 | else |
| 2973 | atomic_dec(&bp->cq_spq_left); |
| 2974 | } |
| 2975 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2976 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2977 | DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2978 | "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) " |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2979 | "type(0x%x) left (ETH, COMMON) (%x,%x)\n", |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2980 | bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping), |
| 2981 | (u32)(U64_LO(bp->spq_mapping) + |
| 2982 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 2983 | HW_CID(bp, cid), data_hi, data_lo, type, |
| 2984 | atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left)); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 2985 | |
Michael Chan | 2891290 | 2009-10-10 13:46:53 +0000 | [diff] [blame] | 2986 | bnx2x_sp_prod_update(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2987 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2988 | return 0; |
| 2989 | } |
| 2990 | |
| 2991 | /* acquire split MCP access lock register */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2992 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2993 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 2994 | u32 j, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2995 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2996 | |
| 2997 | might_sleep(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 2998 | for (j = 0; j < 1000; j++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2999 | val = (1UL << 31); |
| 3000 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 3001 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); |
| 3002 | if (val & (1L << 31)) |
| 3003 | break; |
| 3004 | |
| 3005 | msleep(5); |
| 3006 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3007 | if (!(val & (1L << 31))) { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 3008 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3009 | rc = -EBUSY; |
| 3010 | } |
| 3011 | |
| 3012 | return rc; |
| 3013 | } |
| 3014 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3015 | /* release split MCP access lock register */ |
| 3016 | static void bnx2x_release_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3017 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3018 | REG_WR(bp, GRCBASE_MCP + 0x9c, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3019 | } |
| 3020 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3021 | #define BNX2X_DEF_SB_ATT_IDX 0x0001 |
| 3022 | #define BNX2X_DEF_SB_IDX 0x0002 |
| 3023 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3024 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
| 3025 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3026 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3027 | u16 rc = 0; |
| 3028 | |
| 3029 | barrier(); /* status block is written to by the chip */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3030 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
| 3031 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3032 | rc |= BNX2X_DEF_SB_ATT_IDX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3033 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3034 | |
| 3035 | if (bp->def_idx != def_sb->sp_sb.running_index) { |
| 3036 | bp->def_idx = def_sb->sp_sb.running_index; |
| 3037 | rc |= BNX2X_DEF_SB_IDX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3038 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3039 | |
| 3040 | /* Do not reorder: indecies reading should complete before handling */ |
| 3041 | barrier(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3042 | return rc; |
| 3043 | } |
| 3044 | |
| 3045 | /* |
| 3046 | * slow path service functions |
| 3047 | */ |
| 3048 | |
| 3049 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) |
| 3050 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3051 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3052 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 3053 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3054 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
| 3055 | NIG_REG_MASK_INTERRUPT_PORT0; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3056 | u32 aeu_mask; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3057 | u32 nig_mask = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3058 | u32 reg_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3059 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3060 | if (bp->attn_state & asserted) |
| 3061 | BNX2X_ERR("IGU ERROR\n"); |
| 3062 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3063 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 3064 | aeu_mask = REG_RD(bp, aeu_addr); |
| 3065 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3066 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3067 | aeu_mask, asserted); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3068 | aeu_mask &= ~(asserted & 0x3ff); |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3069 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3070 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3071 | REG_WR(bp, aeu_addr, aeu_mask); |
| 3072 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3073 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3074 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3075 | bp->attn_state |= asserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3076 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3077 | |
| 3078 | if (asserted & ATTN_HARD_WIRED_MASK) { |
| 3079 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3080 | |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3081 | bnx2x_acquire_phy_lock(bp); |
| 3082 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3083 | /* save nig interrupt mask */ |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3084 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3085 | |
Yaniv Rosner | 361c391 | 2011-06-14 01:33:19 +0000 | [diff] [blame] | 3086 | /* If nig_mask is not set, no need to call the update |
| 3087 | * function. |
| 3088 | */ |
| 3089 | if (nig_mask) { |
| 3090 | REG_WR(bp, nig_int_mask_addr, 0); |
| 3091 | |
| 3092 | bnx2x_link_attn(bp); |
| 3093 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3094 | |
| 3095 | /* handle unicore attn? */ |
| 3096 | } |
| 3097 | if (asserted & ATTN_SW_TIMER_4_FUNC) |
| 3098 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); |
| 3099 | |
| 3100 | if (asserted & GPIO_2_FUNC) |
| 3101 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); |
| 3102 | |
| 3103 | if (asserted & GPIO_3_FUNC) |
| 3104 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); |
| 3105 | |
| 3106 | if (asserted & GPIO_4_FUNC) |
| 3107 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); |
| 3108 | |
| 3109 | if (port == 0) { |
| 3110 | if (asserted & ATTN_GENERAL_ATTN_1) { |
| 3111 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); |
| 3112 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); |
| 3113 | } |
| 3114 | if (asserted & ATTN_GENERAL_ATTN_2) { |
| 3115 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); |
| 3116 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); |
| 3117 | } |
| 3118 | if (asserted & ATTN_GENERAL_ATTN_3) { |
| 3119 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); |
| 3120 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); |
| 3121 | } |
| 3122 | } else { |
| 3123 | if (asserted & ATTN_GENERAL_ATTN_4) { |
| 3124 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); |
| 3125 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); |
| 3126 | } |
| 3127 | if (asserted & ATTN_GENERAL_ATTN_5) { |
| 3128 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); |
| 3129 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); |
| 3130 | } |
| 3131 | if (asserted & ATTN_GENERAL_ATTN_6) { |
| 3132 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); |
| 3133 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | } /* if hardwired */ |
| 3138 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3139 | if (bp->common.int_block == INT_BLOCK_HC) |
| 3140 | reg_addr = (HC_REG_COMMAND_REG + port*32 + |
| 3141 | COMMAND_REG_ATTN_BITS_SET); |
| 3142 | else |
| 3143 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8); |
| 3144 | |
| 3145 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted, |
| 3146 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); |
| 3147 | REG_WR(bp, reg_addr, asserted); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3148 | |
| 3149 | /* now set back the mask */ |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3150 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 3151 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 3152 | bnx2x_release_phy_lock(bp); |
| 3153 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3156 | static inline void bnx2x_fan_failure(struct bnx2x *bp) |
| 3157 | { |
| 3158 | int port = BP_PORT(bp); |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3159 | u32 ext_phy_config; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3160 | /* mark the failure */ |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3161 | ext_phy_config = |
| 3162 | SHMEM_RD(bp, |
| 3163 | dev_info.port_hw_config[port].external_phy_config); |
| 3164 | |
| 3165 | ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
| 3166 | ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3167 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 3168 | ext_phy_config); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3169 | |
| 3170 | /* log the failure */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 3171 | netdev_err(bp->dev, "Fan Failure on Network Controller has caused" |
| 3172 | " the driver to shutdown the card to prevent permanent" |
| 3173 | " damage. Please contact OEM Support for assistance\n"); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3174 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 3175 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3176 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
| 3177 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3178 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3179 | int reg_offset; |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 3180 | u32 val; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3181 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3182 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 3183 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3184 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3185 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3186 | |
| 3187 | val = REG_RD(bp, reg_offset); |
| 3188 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; |
| 3189 | REG_WR(bp, reg_offset, val); |
| 3190 | |
| 3191 | BNX2X_ERR("SPIO5 hw attention\n"); |
| 3192 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3193 | /* Fan failure attention */ |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 3194 | bnx2x_hw_reset_phy(&bp->link_params); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 3195 | bnx2x_fan_failure(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3196 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3197 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 3198 | if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 | |
| 3199 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) { |
| 3200 | bnx2x_acquire_phy_lock(bp); |
| 3201 | bnx2x_handle_module_detect_int(&bp->link_params); |
| 3202 | bnx2x_release_phy_lock(bp); |
| 3203 | } |
| 3204 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3205 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
| 3206 | |
| 3207 | val = REG_RD(bp, reg_offset); |
| 3208 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); |
| 3209 | REG_WR(bp, reg_offset, val); |
| 3210 | |
| 3211 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3212 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3213 | bnx2x_panic(); |
| 3214 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
| 3218 | { |
| 3219 | u32 val; |
| 3220 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 3221 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3222 | |
| 3223 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); |
| 3224 | BNX2X_ERR("DB hw attention 0x%x\n", val); |
| 3225 | /* DORQ discard attention */ |
| 3226 | if (val & 0x2) |
| 3227 | BNX2X_ERR("FATAL error from DORQ\n"); |
| 3228 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3229 | |
| 3230 | if (attn & HW_INTERRUT_ASSERT_SET_1) { |
| 3231 | |
| 3232 | int port = BP_PORT(bp); |
| 3233 | int reg_offset; |
| 3234 | |
| 3235 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : |
| 3236 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); |
| 3237 | |
| 3238 | val = REG_RD(bp, reg_offset); |
| 3239 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); |
| 3240 | REG_WR(bp, reg_offset, val); |
| 3241 | |
| 3242 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3243 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3244 | bnx2x_panic(); |
| 3245 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
| 3249 | { |
| 3250 | u32 val; |
| 3251 | |
| 3252 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { |
| 3253 | |
| 3254 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); |
| 3255 | BNX2X_ERR("CFC hw attention 0x%x\n", val); |
| 3256 | /* CFC error attention */ |
| 3257 | if (val & 0x2) |
| 3258 | BNX2X_ERR("FATAL error from CFC\n"); |
| 3259 | } |
| 3260 | |
| 3261 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3262 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3263 | BNX2X_ERR("PXP hw attention-0 0x%x\n", val); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3264 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
| 3265 | if (val & 0x18000) |
| 3266 | BNX2X_ERR("FATAL error from PXP\n"); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3267 | |
| 3268 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3269 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1); |
| 3270 | BNX2X_ERR("PXP hw attention-1 0x%x\n", val); |
| 3271 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3272 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3273 | |
| 3274 | if (attn & HW_INTERRUT_ASSERT_SET_2) { |
| 3275 | |
| 3276 | int port = BP_PORT(bp); |
| 3277 | int reg_offset; |
| 3278 | |
| 3279 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : |
| 3280 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); |
| 3281 | |
| 3282 | val = REG_RD(bp, reg_offset); |
| 3283 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); |
| 3284 | REG_WR(bp, reg_offset, val); |
| 3285 | |
| 3286 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3287 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3288 | bnx2x_panic(); |
| 3289 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
| 3293 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3294 | u32 val; |
| 3295 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3296 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
| 3297 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3298 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
| 3299 | int func = BP_FUNC(bp); |
| 3300 | |
| 3301 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3302 | bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp, |
| 3303 | func_mf_config[BP_ABS_FUNC(bp)].config); |
| 3304 | val = SHMEM_RD(bp, |
| 3305 | func_mb[BP_FW_MB_IDX(bp)].drv_status); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3306 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
| 3307 | bnx2x_dcc_event(bp, |
| 3308 | (val & DRV_STATUS_DCC_EVENT_MASK)); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 3309 | |
| 3310 | if (val & DRV_STATUS_SET_MF_BW) |
| 3311 | bnx2x_set_mf_bw(bp); |
| 3312 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3313 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3314 | bnx2x_pmf_update(bp); |
| 3315 | |
Vladislav Zolotarov | 2ae17f6 | 2011-05-04 23:48:23 +0000 | [diff] [blame] | 3316 | /* Always call it here: bnx2x_link_report() will |
| 3317 | * prevent the link indication duplication. |
| 3318 | */ |
| 3319 | bnx2x__link_status_update(bp); |
| 3320 | |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 3321 | if (bp->port.pmf && |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 3322 | (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) && |
| 3323 | bp->dcbx_enabled > 0) |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 3324 | /* start dcbx state machine */ |
| 3325 | bnx2x_dcbx_set_params(bp, |
| 3326 | BNX2X_DCBX_STATE_NEG_RECEIVED); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3327 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3328 | |
| 3329 | BNX2X_ERR("MC assert!\n"); |
| 3330 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
| 3331 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); |
| 3332 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); |
| 3333 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); |
| 3334 | bnx2x_panic(); |
| 3335 | |
| 3336 | } else if (attn & BNX2X_MCP_ASSERT) { |
| 3337 | |
| 3338 | BNX2X_ERR("MCP assert!\n"); |
| 3339 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3340 | bnx2x_fw_dump(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3341 | |
| 3342 | } else |
| 3343 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); |
| 3344 | } |
| 3345 | |
| 3346 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3347 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
| 3348 | if (attn & BNX2X_GRC_TIMEOUT) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3349 | val = CHIP_IS_E1(bp) ? 0 : |
| 3350 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3351 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
| 3352 | } |
| 3353 | if (attn & BNX2X_GRC_RSV) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3354 | val = CHIP_IS_E1(bp) ? 0 : |
| 3355 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3356 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
| 3357 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3358 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3359 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3360 | } |
| 3361 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3362 | /* |
| 3363 | * Bits map: |
| 3364 | * 0-7 - Engine0 load counter. |
| 3365 | * 8-15 - Engine1 load counter. |
| 3366 | * 16 - Engine0 RESET_IN_PROGRESS bit. |
| 3367 | * 17 - Engine1 RESET_IN_PROGRESS bit. |
| 3368 | * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function |
| 3369 | * on the engine |
| 3370 | * 19 - Engine1 ONE_IS_LOADED. |
| 3371 | * 20 - Chip reset flow bit. When set none-leader must wait for both engines |
| 3372 | * leader to complete (check for both RESET_IN_PROGRESS bits and not for |
| 3373 | * just the one belonging to its engine). |
| 3374 | * |
| 3375 | */ |
| 3376 | #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1 |
| 3377 | |
| 3378 | #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff |
| 3379 | #define BNX2X_PATH0_LOAD_CNT_SHIFT 0 |
| 3380 | #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00 |
| 3381 | #define BNX2X_PATH1_LOAD_CNT_SHIFT 8 |
| 3382 | #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000 |
| 3383 | #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000 |
| 3384 | #define BNX2X_GLOBAL_RESET_BIT 0x00040000 |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 3385 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3386 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3387 | * Set the GLOBAL_RESET bit. |
| 3388 | * |
| 3389 | * Should be run under rtnl lock |
| 3390 | */ |
| 3391 | void bnx2x_set_reset_global(struct bnx2x *bp) |
| 3392 | { |
| 3393 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3394 | |
| 3395 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT); |
| 3396 | barrier(); |
| 3397 | mmiowb(); |
| 3398 | } |
| 3399 | |
| 3400 | /* |
| 3401 | * Clear the GLOBAL_RESET bit. |
| 3402 | * |
| 3403 | * Should be run under rtnl lock |
| 3404 | */ |
| 3405 | static inline void bnx2x_clear_reset_global(struct bnx2x *bp) |
| 3406 | { |
| 3407 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3408 | |
| 3409 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT)); |
| 3410 | barrier(); |
| 3411 | mmiowb(); |
| 3412 | } |
| 3413 | |
| 3414 | /* |
| 3415 | * Checks the GLOBAL_RESET bit. |
| 3416 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3417 | * should be run under rtnl lock |
| 3418 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3419 | static inline bool bnx2x_reset_is_global(struct bnx2x *bp) |
| 3420 | { |
| 3421 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3422 | |
| 3423 | DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val); |
| 3424 | return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false; |
| 3425 | } |
| 3426 | |
| 3427 | /* |
| 3428 | * Clear RESET_IN_PROGRESS bit for the current engine. |
| 3429 | * |
| 3430 | * Should be run under rtnl lock |
| 3431 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3432 | static inline void bnx2x_set_reset_done(struct bnx2x *bp) |
| 3433 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3434 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3435 | u32 bit = BP_PATH(bp) ? |
| 3436 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3437 | |
| 3438 | /* Clear the bit */ |
| 3439 | val &= ~bit; |
| 3440 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3441 | barrier(); |
| 3442 | mmiowb(); |
| 3443 | } |
| 3444 | |
| 3445 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3446 | * Set RESET_IN_PROGRESS for the current engine. |
| 3447 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3448 | * should be run under rtnl lock |
| 3449 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3450 | void bnx2x_set_reset_in_progress(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3451 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3452 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3453 | u32 bit = BP_PATH(bp) ? |
| 3454 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3455 | |
| 3456 | /* Set the bit */ |
| 3457 | val |= bit; |
| 3458 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3459 | barrier(); |
| 3460 | mmiowb(); |
| 3461 | } |
| 3462 | |
| 3463 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3464 | * Checks the RESET_IN_PROGRESS bit for the given engine. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3465 | * should be run under rtnl lock |
| 3466 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3467 | bool bnx2x_reset_is_done(struct bnx2x *bp, int engine) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3468 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3469 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3470 | u32 bit = engine ? |
| 3471 | BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT; |
| 3472 | |
| 3473 | /* return false if bit is set */ |
| 3474 | return (val & bit) ? false : true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3478 | * Increment the load counter for the current engine. |
| 3479 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3480 | * should be run under rtnl lock |
| 3481 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3482 | void bnx2x_inc_load_cnt(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3483 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3484 | u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3485 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3486 | BNX2X_PATH0_LOAD_CNT_MASK; |
| 3487 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3488 | BNX2X_PATH0_LOAD_CNT_SHIFT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3489 | |
| 3490 | DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val); |
| 3491 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3492 | /* get the current counter value */ |
| 3493 | val1 = (val & mask) >> shift; |
| 3494 | |
| 3495 | /* increment... */ |
| 3496 | val1++; |
| 3497 | |
| 3498 | /* clear the old value */ |
| 3499 | val &= ~mask; |
| 3500 | |
| 3501 | /* set the new one */ |
| 3502 | val |= ((val1 << shift) & mask); |
| 3503 | |
| 3504 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3505 | barrier(); |
| 3506 | mmiowb(); |
| 3507 | } |
| 3508 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3509 | /** |
| 3510 | * bnx2x_dec_load_cnt - decrement the load counter |
| 3511 | * |
| 3512 | * @bp: driver handle |
| 3513 | * |
| 3514 | * Should be run under rtnl lock. |
| 3515 | * Decrements the load counter for the current engine. Returns |
| 3516 | * the new counter value. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3517 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 3518 | u32 bnx2x_dec_load_cnt(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3519 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3520 | u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3521 | u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3522 | BNX2X_PATH0_LOAD_CNT_MASK; |
| 3523 | u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3524 | BNX2X_PATH0_LOAD_CNT_SHIFT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3525 | |
| 3526 | DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val); |
| 3527 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3528 | /* get the current counter value */ |
| 3529 | val1 = (val & mask) >> shift; |
| 3530 | |
| 3531 | /* decrement... */ |
| 3532 | val1--; |
| 3533 | |
| 3534 | /* clear the old value */ |
| 3535 | val &= ~mask; |
| 3536 | |
| 3537 | /* set the new one */ |
| 3538 | val |= ((val1 << shift) & mask); |
| 3539 | |
| 3540 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3541 | barrier(); |
| 3542 | mmiowb(); |
| 3543 | |
| 3544 | return val1; |
| 3545 | } |
| 3546 | |
| 3547 | /* |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3548 | * Read the load counter for the current engine. |
| 3549 | * |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3550 | * should be run under rtnl lock |
| 3551 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3552 | static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3553 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3554 | u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3555 | BNX2X_PATH0_LOAD_CNT_MASK); |
| 3556 | u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT : |
| 3557 | BNX2X_PATH0_LOAD_CNT_SHIFT); |
| 3558 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3559 | |
| 3560 | DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val); |
| 3561 | |
| 3562 | val = (val & mask) >> shift; |
| 3563 | |
| 3564 | DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val); |
| 3565 | |
| 3566 | return val; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3569 | /* |
| 3570 | * Reset the load counter for the current engine. |
| 3571 | * |
| 3572 | * should be run under rtnl lock |
| 3573 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3574 | static inline void bnx2x_clear_load_cnt(struct bnx2x *bp) |
| 3575 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3576 | u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG); |
| 3577 | u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK : |
| 3578 | BNX2X_PATH0_LOAD_CNT_MASK); |
| 3579 | |
| 3580 | REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static inline void _print_next_block(int idx, const char *blk) |
| 3584 | { |
| 3585 | if (idx) |
| 3586 | pr_cont(", "); |
| 3587 | pr_cont("%s", blk); |
| 3588 | } |
| 3589 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3590 | static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num, |
| 3591 | bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3592 | { |
| 3593 | int i = 0; |
| 3594 | u32 cur_bit = 0; |
| 3595 | for (i = 0; sig; i++) { |
| 3596 | cur_bit = ((u32)0x1 << i); |
| 3597 | if (sig & cur_bit) { |
| 3598 | switch (cur_bit) { |
| 3599 | case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3600 | if (print) |
| 3601 | _print_next_block(par_num++, "BRB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3602 | break; |
| 3603 | case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3604 | if (print) |
| 3605 | _print_next_block(par_num++, "PARSER"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3606 | break; |
| 3607 | case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3608 | if (print) |
| 3609 | _print_next_block(par_num++, "TSDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3612 | if (print) |
| 3613 | _print_next_block(par_num++, |
| 3614 | "SEARCHER"); |
| 3615 | break; |
| 3616 | case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: |
| 3617 | if (print) |
| 3618 | _print_next_block(par_num++, "TCM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3619 | break; |
| 3620 | case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3621 | if (print) |
| 3622 | _print_next_block(par_num++, "TSEMI"); |
| 3623 | break; |
| 3624 | case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: |
| 3625 | if (print) |
| 3626 | _print_next_block(par_num++, "XPB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3627 | break; |
| 3628 | } |
| 3629 | |
| 3630 | /* Clear the bit */ |
| 3631 | sig &= ~cur_bit; |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | return par_num; |
| 3636 | } |
| 3637 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3638 | static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num, |
| 3639 | bool *global, bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3640 | { |
| 3641 | int i = 0; |
| 3642 | u32 cur_bit = 0; |
| 3643 | for (i = 0; sig; i++) { |
| 3644 | cur_bit = ((u32)0x1 << i); |
| 3645 | if (sig & cur_bit) { |
| 3646 | switch (cur_bit) { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3647 | case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: |
| 3648 | if (print) |
| 3649 | _print_next_block(par_num++, "PBF"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3652 | if (print) |
| 3653 | _print_next_block(par_num++, "QM"); |
| 3654 | break; |
| 3655 | case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: |
| 3656 | if (print) |
| 3657 | _print_next_block(par_num++, "TM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3658 | break; |
| 3659 | case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3660 | if (print) |
| 3661 | _print_next_block(par_num++, "XSDM"); |
| 3662 | break; |
| 3663 | case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: |
| 3664 | if (print) |
| 3665 | _print_next_block(par_num++, "XCM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3666 | break; |
| 3667 | case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3668 | if (print) |
| 3669 | _print_next_block(par_num++, "XSEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3670 | break; |
| 3671 | case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3672 | if (print) |
| 3673 | _print_next_block(par_num++, |
| 3674 | "DOORBELLQ"); |
| 3675 | break; |
| 3676 | case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: |
| 3677 | if (print) |
| 3678 | _print_next_block(par_num++, "NIG"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3679 | break; |
| 3680 | case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3681 | if (print) |
| 3682 | _print_next_block(par_num++, |
| 3683 | "VAUX PCI CORE"); |
| 3684 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3685 | break; |
| 3686 | case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3687 | if (print) |
| 3688 | _print_next_block(par_num++, "DEBUG"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3691 | if (print) |
| 3692 | _print_next_block(par_num++, "USDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3693 | break; |
| 3694 | case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3695 | if (print) |
| 3696 | _print_next_block(par_num++, "USEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3699 | if (print) |
| 3700 | _print_next_block(par_num++, "UPB"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3701 | break; |
| 3702 | case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3703 | if (print) |
| 3704 | _print_next_block(par_num++, "CSDM"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3705 | break; |
| 3706 | } |
| 3707 | |
| 3708 | /* Clear the bit */ |
| 3709 | sig &= ~cur_bit; |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | return par_num; |
| 3714 | } |
| 3715 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3716 | static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num, |
| 3717 | bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3718 | { |
| 3719 | int i = 0; |
| 3720 | u32 cur_bit = 0; |
| 3721 | for (i = 0; sig; i++) { |
| 3722 | cur_bit = ((u32)0x1 << i); |
| 3723 | if (sig & cur_bit) { |
| 3724 | switch (cur_bit) { |
| 3725 | case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3726 | if (print) |
| 3727 | _print_next_block(par_num++, "CSEMI"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3728 | break; |
| 3729 | case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3730 | if (print) |
| 3731 | _print_next_block(par_num++, "PXP"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3732 | break; |
| 3733 | case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3734 | if (print) |
| 3735 | _print_next_block(par_num++, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3736 | "PXPPCICLOCKCLIENT"); |
| 3737 | break; |
| 3738 | case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3739 | if (print) |
| 3740 | _print_next_block(par_num++, "CFC"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3741 | break; |
| 3742 | case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3743 | if (print) |
| 3744 | _print_next_block(par_num++, "CDU"); |
| 3745 | break; |
| 3746 | case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: |
| 3747 | if (print) |
| 3748 | _print_next_block(par_num++, "DMAE"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3749 | break; |
| 3750 | case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3751 | if (print) |
| 3752 | _print_next_block(par_num++, "IGU"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3755 | if (print) |
| 3756 | _print_next_block(par_num++, "MISC"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | } |
| 3759 | |
| 3760 | /* Clear the bit */ |
| 3761 | sig &= ~cur_bit; |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | return par_num; |
| 3766 | } |
| 3767 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3768 | static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num, |
| 3769 | bool *global, bool print) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3770 | { |
| 3771 | int i = 0; |
| 3772 | u32 cur_bit = 0; |
| 3773 | for (i = 0; sig; i++) { |
| 3774 | cur_bit = ((u32)0x1 << i); |
| 3775 | if (sig & cur_bit) { |
| 3776 | switch (cur_bit) { |
| 3777 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3778 | if (print) |
| 3779 | _print_next_block(par_num++, "MCP ROM"); |
| 3780 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3783 | if (print) |
| 3784 | _print_next_block(par_num++, |
| 3785 | "MCP UMP RX"); |
| 3786 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3789 | if (print) |
| 3790 | _print_next_block(par_num++, |
| 3791 | "MCP UMP TX"); |
| 3792 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3793 | break; |
| 3794 | case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3795 | if (print) |
| 3796 | _print_next_block(par_num++, |
| 3797 | "MCP SCPAD"); |
| 3798 | *global = true; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3799 | break; |
| 3800 | } |
| 3801 | |
| 3802 | /* Clear the bit */ |
| 3803 | sig &= ~cur_bit; |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | return par_num; |
| 3808 | } |
| 3809 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3810 | static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, |
| 3811 | u32 sig0, u32 sig1, u32 sig2, u32 sig3) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3812 | { |
| 3813 | if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) || |
| 3814 | (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) { |
| 3815 | int par_num = 0; |
| 3816 | DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: " |
| 3817 | "[0]:0x%08x [1]:0x%08x " |
| 3818 | "[2]:0x%08x [3]:0x%08x\n", |
| 3819 | sig0 & HW_PRTY_ASSERT_SET_0, |
| 3820 | sig1 & HW_PRTY_ASSERT_SET_1, |
| 3821 | sig2 & HW_PRTY_ASSERT_SET_2, |
| 3822 | sig3 & HW_PRTY_ASSERT_SET_3); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3823 | if (print) |
| 3824 | netdev_err(bp->dev, |
| 3825 | "Parity errors detected in blocks: "); |
| 3826 | par_num = bnx2x_check_blocks_with_parity0( |
| 3827 | sig0 & HW_PRTY_ASSERT_SET_0, par_num, print); |
| 3828 | par_num = bnx2x_check_blocks_with_parity1( |
| 3829 | sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print); |
| 3830 | par_num = bnx2x_check_blocks_with_parity2( |
| 3831 | sig2 & HW_PRTY_ASSERT_SET_2, par_num, print); |
| 3832 | par_num = bnx2x_check_blocks_with_parity3( |
| 3833 | sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print); |
| 3834 | if (print) |
| 3835 | pr_cont("\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3836 | return true; |
| 3837 | } else |
| 3838 | return false; |
| 3839 | } |
| 3840 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3841 | /** |
| 3842 | * bnx2x_chk_parity_attn - checks for parity attentions. |
| 3843 | * |
| 3844 | * @bp: driver handle |
| 3845 | * @global: true if there was a global attention |
| 3846 | * @print: show parity attention in syslog |
| 3847 | */ |
| 3848 | bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3849 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3850 | struct attn_route attn; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3851 | int port = BP_PORT(bp); |
| 3852 | |
| 3853 | attn.sig[0] = REG_RD(bp, |
| 3854 | MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + |
| 3855 | port*4); |
| 3856 | attn.sig[1] = REG_RD(bp, |
| 3857 | MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + |
| 3858 | port*4); |
| 3859 | attn.sig[2] = REG_RD(bp, |
| 3860 | MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + |
| 3861 | port*4); |
| 3862 | attn.sig[3] = REG_RD(bp, |
| 3863 | MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + |
| 3864 | port*4); |
| 3865 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3866 | return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1], |
| 3867 | attn.sig[2], attn.sig[3]); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3870 | |
| 3871 | static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn) |
| 3872 | { |
| 3873 | u32 val; |
| 3874 | if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) { |
| 3875 | |
| 3876 | val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR); |
| 3877 | BNX2X_ERR("PGLUE hw attention 0x%x\n", val); |
| 3878 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR) |
| 3879 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3880 | "ADDRESS_ERROR\n"); |
| 3881 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR) |
| 3882 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3883 | "INCORRECT_RCV_BEHAVIOR\n"); |
| 3884 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) |
| 3885 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3886 | "WAS_ERROR_ATTN\n"); |
| 3887 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN) |
| 3888 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3889 | "VF_LENGTH_VIOLATION_ATTN\n"); |
| 3890 | if (val & |
| 3891 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN) |
| 3892 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3893 | "VF_GRC_SPACE_VIOLATION_ATTN\n"); |
| 3894 | if (val & |
| 3895 | PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN) |
| 3896 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3897 | "VF_MSIX_BAR_VIOLATION_ATTN\n"); |
| 3898 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN) |
| 3899 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3900 | "TCPL_ERROR_ATTN\n"); |
| 3901 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN) |
| 3902 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3903 | "TCPL_IN_TWO_RCBS_ATTN\n"); |
| 3904 | if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW) |
| 3905 | BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_" |
| 3906 | "CSSNOOP_FIFO_OVERFLOW\n"); |
| 3907 | } |
| 3908 | if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) { |
| 3909 | val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR); |
| 3910 | BNX2X_ERR("ATC hw attention 0x%x\n", val); |
| 3911 | if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR) |
| 3912 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n"); |
| 3913 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND) |
| 3914 | BNX2X_ERR("ATC_ATC_INT_STS_REG" |
| 3915 | "_ATC_TCPL_TO_NOT_PEND\n"); |
| 3916 | if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS) |
| 3917 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3918 | "ATC_GPA_MULTIPLE_HITS\n"); |
| 3919 | if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT) |
| 3920 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3921 | "ATC_RCPL_TO_EMPTY_CNT\n"); |
| 3922 | if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR) |
| 3923 | BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n"); |
| 3924 | if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU) |
| 3925 | BNX2X_ERR("ATC_ATC_INT_STS_REG_" |
| 3926 | "ATC_IREQ_LESS_THAN_STU\n"); |
| 3927 | } |
| 3928 | |
| 3929 | if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | |
| 3930 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) { |
| 3931 | BNX2X_ERR("FATAL parity attention set4 0x%x\n", |
| 3932 | (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | |
| 3933 | AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR))); |
| 3934 | } |
| 3935 | |
| 3936 | } |
| 3937 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3938 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
| 3939 | { |
| 3940 | struct attn_route attn, *group_mask; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3941 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3942 | int index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3943 | u32 reg_addr; |
| 3944 | u32 val; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3945 | u32 aeu_mask; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3946 | bool global = false; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3947 | |
| 3948 | /* need to take HW lock because MCP or other port might also |
| 3949 | try to handle this event */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3950 | bnx2x_acquire_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3951 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3952 | if (bnx2x_chk_parity_attn(bp, &global, true)) { |
| 3953 | #ifndef BNX2X_STOP_ON_ERROR |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3954 | bp->recovery_state = BNX2X_RECOVERY_INIT; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3955 | schedule_delayed_work(&bp->reset_task, 0); |
| 3956 | /* Disable HW interrupts */ |
| 3957 | bnx2x_int_disable(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3958 | /* In case of parity errors don't handle attentions so that |
| 3959 | * other function would "see" parity errors. |
| 3960 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 3961 | #else |
| 3962 | bnx2x_panic(); |
| 3963 | #endif |
| 3964 | bnx2x_release_alr(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3965 | return; |
| 3966 | } |
| 3967 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3968 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
| 3969 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); |
| 3970 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); |
| 3971 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 3972 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3973 | attn.sig[4] = |
| 3974 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4); |
| 3975 | else |
| 3976 | attn.sig[4] = 0; |
| 3977 | |
| 3978 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n", |
| 3979 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3980 | |
| 3981 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
| 3982 | if (deasserted & (1 << index)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3983 | group_mask = &bp->attn_group[index]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3984 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3985 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x " |
| 3986 | "%08x %08x %08x\n", |
| 3987 | index, |
| 3988 | group_mask->sig[0], group_mask->sig[1], |
| 3989 | group_mask->sig[2], group_mask->sig[3], |
| 3990 | group_mask->sig[4]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3991 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 3992 | bnx2x_attn_int_deasserted4(bp, |
| 3993 | attn.sig[4] & group_mask->sig[4]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3994 | bnx2x_attn_int_deasserted3(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3995 | attn.sig[3] & group_mask->sig[3]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3996 | bnx2x_attn_int_deasserted1(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3997 | attn.sig[1] & group_mask->sig[1]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3998 | bnx2x_attn_int_deasserted2(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 3999 | attn.sig[2] & group_mask->sig[2]); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 4000 | bnx2x_attn_int_deasserted0(bp, |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 4001 | attn.sig[0] & group_mask->sig[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 4005 | bnx2x_release_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4006 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4007 | if (bp->common.int_block == INT_BLOCK_HC) |
| 4008 | reg_addr = (HC_REG_COMMAND_REG + port*32 + |
| 4009 | COMMAND_REG_ATTN_BITS_CLR); |
| 4010 | else |
| 4011 | reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4012 | |
| 4013 | val = ~deasserted; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4014 | DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val, |
| 4015 | (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4016 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4017 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4018 | if (~bp->attn_state & deasserted) |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4019 | BNX2X_ERR("IGU ERROR\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4020 | |
| 4021 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 4022 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 4023 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4024 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 4025 | aeu_mask = REG_RD(bp, reg_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4026 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4027 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", |
| 4028 | aeu_mask, deasserted); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 4029 | aeu_mask |= (deasserted & 0x3ff); |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 4030 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
| 4031 | |
| 4032 | REG_WR(bp, reg_addr, aeu_mask); |
| 4033 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4034 | |
| 4035 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
| 4036 | bp->attn_state &= ~deasserted; |
| 4037 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
| 4038 | } |
| 4039 | |
| 4040 | static void bnx2x_attn_int(struct bnx2x *bp) |
| 4041 | { |
| 4042 | /* read local copy of bits */ |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 4043 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 4044 | attn_bits); |
| 4045 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 4046 | attn_bits_ack); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4047 | u32 attn_state = bp->attn_state; |
| 4048 | |
| 4049 | /* look for changed bits */ |
| 4050 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; |
| 4051 | u32 deasserted = ~attn_bits & attn_ack & attn_state; |
| 4052 | |
| 4053 | DP(NETIF_MSG_HW, |
| 4054 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", |
| 4055 | attn_bits, attn_ack, asserted, deasserted); |
| 4056 | |
| 4057 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4058 | BNX2X_ERR("BAD attention state\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4059 | |
| 4060 | /* handle bits that were raised */ |
| 4061 | if (asserted) |
| 4062 | bnx2x_attn_int_asserted(bp, asserted); |
| 4063 | |
| 4064 | if (deasserted) |
| 4065 | bnx2x_attn_int_deasserted(bp, deasserted); |
| 4066 | } |
| 4067 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4068 | void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment, |
| 4069 | u16 index, u8 op, u8 update) |
| 4070 | { |
| 4071 | u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8; |
| 4072 | |
| 4073 | bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update, |
| 4074 | igu_addr); |
| 4075 | } |
| 4076 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4077 | static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod) |
| 4078 | { |
| 4079 | /* No memory barriers */ |
| 4080 | storm_memset_eq_prod(bp, prod, BP_FUNC(bp)); |
| 4081 | mmiowb(); /* keep prod updates ordered */ |
| 4082 | } |
| 4083 | |
| 4084 | #ifdef BCM_CNIC |
| 4085 | static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid, |
| 4086 | union event_ring_elem *elem) |
| 4087 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4088 | u8 err = elem->message.error; |
| 4089 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4090 | if (!bp->cnic_eth_dev.starting_cid || |
Vladislav Zolotarov | c3a8ce6 | 2011-05-22 10:08:09 +0000 | [diff] [blame] | 4091 | (cid < bp->cnic_eth_dev.starting_cid && |
| 4092 | cid != bp->cnic_eth_dev.iscsi_l2_cid)) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4093 | return 1; |
| 4094 | |
| 4095 | DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid); |
| 4096 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4097 | if (unlikely(err)) { |
| 4098 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4099 | BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n", |
| 4100 | cid); |
| 4101 | bnx2x_panic_dump(bp); |
| 4102 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4103 | bnx2x_cnic_cfc_comp(bp, cid, err); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4104 | return 0; |
| 4105 | } |
| 4106 | #endif |
| 4107 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4108 | static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp) |
| 4109 | { |
| 4110 | struct bnx2x_mcast_ramrod_params rparam; |
| 4111 | int rc; |
| 4112 | |
| 4113 | memset(&rparam, 0, sizeof(rparam)); |
| 4114 | |
| 4115 | rparam.mcast_obj = &bp->mcast_obj; |
| 4116 | |
| 4117 | netif_addr_lock_bh(bp->dev); |
| 4118 | |
| 4119 | /* Clear pending state for the last command */ |
| 4120 | bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw); |
| 4121 | |
| 4122 | /* If there are pending mcast commands - send them */ |
| 4123 | if (bp->mcast_obj.check_pending(&bp->mcast_obj)) { |
| 4124 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); |
| 4125 | if (rc < 0) |
| 4126 | BNX2X_ERR("Failed to send pending mcast commands: %d\n", |
| 4127 | rc); |
| 4128 | } |
| 4129 | |
| 4130 | netif_addr_unlock_bh(bp->dev); |
| 4131 | } |
| 4132 | |
| 4133 | static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp, |
| 4134 | union event_ring_elem *elem) |
| 4135 | { |
| 4136 | unsigned long ramrod_flags = 0; |
| 4137 | int rc = 0; |
| 4138 | u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK; |
| 4139 | struct bnx2x_vlan_mac_obj *vlan_mac_obj; |
| 4140 | |
| 4141 | /* Always push next commands out, don't wait here */ |
| 4142 | __set_bit(RAMROD_CONT, &ramrod_flags); |
| 4143 | |
| 4144 | switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) { |
| 4145 | case BNX2X_FILTER_MAC_PENDING: |
| 4146 | #ifdef BCM_CNIC |
| 4147 | if (cid == BNX2X_ISCSI_ETH_CID) |
| 4148 | vlan_mac_obj = &bp->iscsi_l2_mac_obj; |
| 4149 | else |
| 4150 | #endif |
| 4151 | vlan_mac_obj = &bp->fp[cid].mac_obj; |
| 4152 | |
| 4153 | break; |
| 4154 | vlan_mac_obj = &bp->fp[cid].mac_obj; |
| 4155 | |
| 4156 | case BNX2X_FILTER_MCAST_PENDING: |
| 4157 | /* This is only relevant for 57710 where multicast MACs are |
| 4158 | * configured as unicast MACs using the same ramrod. |
| 4159 | */ |
| 4160 | bnx2x_handle_mcast_eqe(bp); |
| 4161 | return; |
| 4162 | default: |
| 4163 | BNX2X_ERR("Unsupported classification command: %d\n", |
| 4164 | elem->message.data.eth_event.echo); |
| 4165 | return; |
| 4166 | } |
| 4167 | |
| 4168 | rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags); |
| 4169 | |
| 4170 | if (rc < 0) |
| 4171 | BNX2X_ERR("Failed to schedule new commands: %d\n", rc); |
| 4172 | else if (rc > 0) |
| 4173 | DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n"); |
| 4174 | |
| 4175 | } |
| 4176 | |
| 4177 | #ifdef BCM_CNIC |
| 4178 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start); |
| 4179 | #endif |
| 4180 | |
| 4181 | static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp) |
| 4182 | { |
| 4183 | netif_addr_lock_bh(bp->dev); |
| 4184 | |
| 4185 | clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); |
| 4186 | |
| 4187 | /* Send rx_mode command again if was requested */ |
| 4188 | if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state)) |
| 4189 | bnx2x_set_storm_rx_mode(bp); |
| 4190 | #ifdef BCM_CNIC |
| 4191 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, |
| 4192 | &bp->sp_state)) |
| 4193 | bnx2x_set_iscsi_eth_rx_mode(bp, true); |
| 4194 | else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, |
| 4195 | &bp->sp_state)) |
| 4196 | bnx2x_set_iscsi_eth_rx_mode(bp, false); |
| 4197 | #endif |
| 4198 | |
| 4199 | netif_addr_unlock_bh(bp->dev); |
| 4200 | } |
| 4201 | |
| 4202 | static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj( |
| 4203 | struct bnx2x *bp, u32 cid) |
| 4204 | { |
| 4205 | #ifdef BCM_CNIC |
| 4206 | if (cid == BNX2X_FCOE_ETH_CID) |
| 4207 | return &bnx2x_fcoe(bp, q_obj); |
| 4208 | else |
| 4209 | #endif |
| 4210 | return &bnx2x_fp(bp, cid, q_obj); |
| 4211 | } |
| 4212 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4213 | static void bnx2x_eq_int(struct bnx2x *bp) |
| 4214 | { |
| 4215 | u16 hw_cons, sw_cons, sw_prod; |
| 4216 | union event_ring_elem *elem; |
| 4217 | u32 cid; |
| 4218 | u8 opcode; |
| 4219 | int spqe_cnt = 0; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4220 | struct bnx2x_queue_sp_obj *q_obj; |
| 4221 | struct bnx2x_func_sp_obj *f_obj = &bp->func_obj; |
| 4222 | struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4223 | |
| 4224 | hw_cons = le16_to_cpu(*bp->eq_cons_sb); |
| 4225 | |
| 4226 | /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256. |
| 4227 | * when we get the the next-page we nned to adjust so the loop |
| 4228 | * condition below will be met. The next element is the size of a |
| 4229 | * regular element and hence incrementing by 1 |
| 4230 | */ |
| 4231 | if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) |
| 4232 | hw_cons++; |
| 4233 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4234 | /* This function may never run in parallel with itself for a |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4235 | * specific bp, thus there is no need in "paired" read memory |
| 4236 | * barrier here. |
| 4237 | */ |
| 4238 | sw_cons = bp->eq_cons; |
| 4239 | sw_prod = bp->eq_prod; |
| 4240 | |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4241 | DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n", |
| 4242 | hw_cons, sw_cons, atomic_read(&bp->eq_spq_left)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4243 | |
| 4244 | for (; sw_cons != hw_cons; |
| 4245 | sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) { |
| 4246 | |
| 4247 | |
| 4248 | elem = &bp->eq_ring[EQ_DESC(sw_cons)]; |
| 4249 | |
| 4250 | cid = SW_CID(elem->message.data.cfc_del_event.cid); |
| 4251 | opcode = elem->message.opcode; |
| 4252 | |
| 4253 | |
| 4254 | /* handle eq element */ |
| 4255 | switch (opcode) { |
| 4256 | case EVENT_RING_OPCODE_STAT_QUERY: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4257 | DP(NETIF_MSG_TIMER, "got statistics comp event %d\n", |
| 4258 | bp->stats_comp++); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4259 | /* nothing to do with stats comp */ |
| 4260 | continue; |
| 4261 | |
| 4262 | case EVENT_RING_OPCODE_CFC_DEL: |
| 4263 | /* handle according to cid range */ |
| 4264 | /* |
| 4265 | * we may want to verify here that the bp state is |
| 4266 | * HALTING |
| 4267 | */ |
| 4268 | DP(NETIF_MSG_IFDOWN, |
| 4269 | "got delete ramrod for MULTI[%d]\n", cid); |
| 4270 | #ifdef BCM_CNIC |
| 4271 | if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem)) |
| 4272 | goto next_spqe; |
| 4273 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4274 | q_obj = bnx2x_cid_to_q_obj(bp, cid); |
| 4275 | |
| 4276 | if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL)) |
| 4277 | break; |
| 4278 | |
| 4279 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4280 | |
| 4281 | goto next_spqe; |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 4282 | |
| 4283 | case EVENT_RING_OPCODE_STOP_TRAFFIC: |
| 4284 | DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n"); |
| 4285 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED); |
| 4286 | goto next_spqe; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4287 | |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 4288 | case EVENT_RING_OPCODE_START_TRAFFIC: |
| 4289 | DP(NETIF_MSG_IFUP, "got START TRAFFIC\n"); |
| 4290 | bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED); |
| 4291 | goto next_spqe; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4292 | case EVENT_RING_OPCODE_FUNCTION_START: |
| 4293 | DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n"); |
| 4294 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START)) |
| 4295 | break; |
| 4296 | |
| 4297 | goto next_spqe; |
| 4298 | |
| 4299 | case EVENT_RING_OPCODE_FUNCTION_STOP: |
| 4300 | DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n"); |
| 4301 | if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP)) |
| 4302 | break; |
| 4303 | |
| 4304 | goto next_spqe; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | switch (opcode | bp->state) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4308 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
| 4309 | BNX2X_STATE_OPEN): |
| 4310 | case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4311 | BNX2X_STATE_OPENING_WAIT4_PORT): |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4312 | cid = elem->message.data.eth_event.echo & |
| 4313 | BNX2X_SWCID_MASK; |
| 4314 | DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n", |
| 4315 | cid); |
| 4316 | rss_raw->clear_pending(rss_raw); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4317 | break; |
| 4318 | |
| 4319 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN): |
| 4320 | case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG): |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4321 | case (EVENT_RING_OPCODE_SET_MAC | |
| 4322 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4323 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4324 | BNX2X_STATE_OPEN): |
| 4325 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4326 | BNX2X_STATE_DIAG): |
| 4327 | case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | |
| 4328 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4329 | DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n"); |
| 4330 | bnx2x_handle_classification_eqe(bp, elem); |
| 4331 | break; |
| 4332 | |
| 4333 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4334 | BNX2X_STATE_OPEN): |
| 4335 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4336 | BNX2X_STATE_DIAG): |
| 4337 | case (EVENT_RING_OPCODE_MULTICAST_RULES | |
| 4338 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4339 | DP(NETIF_MSG_IFUP, "got mcast ramrod\n"); |
| 4340 | bnx2x_handle_mcast_eqe(bp); |
| 4341 | break; |
| 4342 | |
| 4343 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4344 | BNX2X_STATE_OPEN): |
| 4345 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4346 | BNX2X_STATE_DIAG): |
| 4347 | case (EVENT_RING_OPCODE_FILTERS_RULES | |
| 4348 | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 4349 | DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n"); |
| 4350 | bnx2x_handle_rx_mode_eqe(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4351 | break; |
| 4352 | default: |
| 4353 | /* unknown event log error and continue */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4354 | BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n", |
| 4355 | elem->message.opcode, bp->state); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4356 | } |
| 4357 | next_spqe: |
| 4358 | spqe_cnt++; |
| 4359 | } /* for */ |
| 4360 | |
Dmitry Kravkov | 8fe23fb | 2010-10-06 03:27:41 +0000 | [diff] [blame] | 4361 | smp_mb__before_atomic_inc(); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4362 | atomic_add(spqe_cnt, &bp->eq_spq_left); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4363 | |
| 4364 | bp->eq_cons = sw_cons; |
| 4365 | bp->eq_prod = sw_prod; |
| 4366 | /* Make sure that above mem writes were issued towards the memory */ |
| 4367 | smp_wmb(); |
| 4368 | |
| 4369 | /* update producer */ |
| 4370 | bnx2x_update_eq_prod(bp, bp->eq_prod); |
| 4371 | } |
| 4372 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4373 | static void bnx2x_sp_task(struct work_struct *work) |
| 4374 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 4375 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4376 | u16 status; |
| 4377 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4378 | status = bnx2x_update_dsb_idx(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4379 | /* if (status == 0) */ |
| 4380 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4381 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4382 | 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] | 4383 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 4384 | /* HW attentions */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4385 | if (status & BNX2X_DEF_SB_ATT_IDX) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4386 | bnx2x_attn_int(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4387 | status &= ~BNX2X_DEF_SB_ATT_IDX; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4390 | /* SP events: STAT_QUERY and others */ |
| 4391 | if (status & BNX2X_DEF_SB_IDX) { |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4392 | #ifdef BCM_CNIC |
| 4393 | struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4394 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4395 | if ((!NO_FCOE(bp)) && |
| 4396 | (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) |
| 4397 | napi_schedule(&bnx2x_fcoe(bp, napi)); |
| 4398 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4399 | /* Handle EQ completions */ |
| 4400 | bnx2x_eq_int(bp); |
| 4401 | |
| 4402 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, |
| 4403 | le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1); |
| 4404 | |
| 4405 | status &= ~BNX2X_DEF_SB_IDX; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | if (unlikely(status)) |
| 4409 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n", |
| 4410 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4411 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4412 | bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID, |
| 4413 | le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4414 | } |
| 4415 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 4416 | irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4417 | { |
| 4418 | struct net_device *dev = dev_instance; |
| 4419 | struct bnx2x *bp = netdev_priv(dev); |
| 4420 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4421 | bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, |
| 4422 | IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4423 | |
| 4424 | #ifdef BNX2X_STOP_ON_ERROR |
| 4425 | if (unlikely(bp->panic)) |
| 4426 | return IRQ_HANDLED; |
| 4427 | #endif |
| 4428 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 4429 | #ifdef BCM_CNIC |
| 4430 | { |
| 4431 | struct cnic_ops *c_ops; |
| 4432 | |
| 4433 | rcu_read_lock(); |
| 4434 | c_ops = rcu_dereference(bp->cnic_ops); |
| 4435 | if (c_ops) |
| 4436 | c_ops->cnic_handler(bp->cnic_data, NULL); |
| 4437 | rcu_read_unlock(); |
| 4438 | } |
| 4439 | #endif |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 4440 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4441 | |
| 4442 | return IRQ_HANDLED; |
| 4443 | } |
| 4444 | |
| 4445 | /* end of slow path */ |
| 4446 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4447 | |
| 4448 | void bnx2x_drv_pulse(struct bnx2x *bp) |
| 4449 | { |
| 4450 | SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb, |
| 4451 | bp->fw_drv_pulse_wr_seq); |
| 4452 | } |
| 4453 | |
| 4454 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4455 | static void bnx2x_timer(unsigned long data) |
| 4456 | { |
| 4457 | struct bnx2x *bp = (struct bnx2x *) data; |
| 4458 | |
| 4459 | if (!netif_running(bp->dev)) |
| 4460 | return; |
| 4461 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4462 | if (poll) { |
| 4463 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4464 | |
Eilon Greenstein | 7961f79 | 2009-03-02 07:59:31 +0000 | [diff] [blame] | 4465 | bnx2x_tx_int(fp); |
David S. Miller | b8ee832 | 2011-04-17 16:56:12 -0700 | [diff] [blame] | 4466 | bnx2x_rx_int(fp, 1000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4469 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4470 | int mb_idx = BP_FW_MB_IDX(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4471 | u32 drv_pulse; |
| 4472 | u32 mcp_pulse; |
| 4473 | |
| 4474 | ++bp->fw_drv_pulse_wr_seq; |
| 4475 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; |
| 4476 | /* TBD - add SYSTEM_TIME */ |
| 4477 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4478 | bnx2x_drv_pulse(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4479 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4480 | mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4481 | MCP_PULSE_SEQ_MASK); |
| 4482 | /* The delta between driver pulse and mcp response |
| 4483 | * should be 1 (before mcp response) or 0 (after mcp response) |
| 4484 | */ |
| 4485 | if ((drv_pulse != mcp_pulse) && |
| 4486 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { |
| 4487 | /* someone lost a heartbeat... */ |
| 4488 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", |
| 4489 | drv_pulse, mcp_pulse); |
| 4490 | } |
| 4491 | } |
| 4492 | |
Eilon Greenstein | f34d28e | 2009-10-15 00:18:08 -0700 | [diff] [blame] | 4493 | if (bp->state == BNX2X_STATE_OPEN) |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4494 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4495 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4496 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 4497 | } |
| 4498 | |
| 4499 | /* end of Statistics */ |
| 4500 | |
| 4501 | /* nic init */ |
| 4502 | |
| 4503 | /* |
| 4504 | * nic init service functions |
| 4505 | */ |
| 4506 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4507 | 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] | 4508 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4509 | u32 i; |
| 4510 | if (!(len%4) && !(addr%4)) |
| 4511 | for (i = 0; i < len; i += 4) |
| 4512 | REG_WR(bp, addr + i, fill); |
| 4513 | else |
| 4514 | for (i = 0; i < len; i++) |
| 4515 | REG_WR8(bp, addr + i, fill); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4516 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4519 | /* helper: writes FP SP data to FW - data_size in dwords */ |
| 4520 | static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp, |
| 4521 | int fw_sb_id, |
| 4522 | u32 *sb_data_p, |
| 4523 | u32 data_size) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4524 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4525 | int index; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4526 | for (index = 0; index < data_size; index++) |
| 4527 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4528 | CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) + |
| 4529 | sizeof(u32)*index, |
| 4530 | *(sb_data_p + index)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4533 | static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id) |
| 4534 | { |
| 4535 | u32 *sb_data_p; |
| 4536 | u32 data_size = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4537 | struct hc_status_block_data_e2 sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4538 | struct hc_status_block_data_e1x sb_data_e1x; |
| 4539 | |
| 4540 | /* disable the function first */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4541 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4542 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4543 | sb_data_e2.common.state = SB_DISABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4544 | sb_data_e2.common.p_func.vf_valid = false; |
| 4545 | sb_data_p = (u32 *)&sb_data_e2; |
| 4546 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); |
| 4547 | } else { |
| 4548 | memset(&sb_data_e1x, 0, |
| 4549 | sizeof(struct hc_status_block_data_e1x)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4550 | sb_data_e1x.common.state = SB_DISABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4551 | sb_data_e1x.common.p_func.vf_valid = false; |
| 4552 | sb_data_p = (u32 *)&sb_data_e1x; |
| 4553 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); |
| 4554 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4555 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
| 4556 | |
| 4557 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4558 | CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0, |
| 4559 | CSTORM_STATUS_BLOCK_SIZE); |
| 4560 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4561 | CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0, |
| 4562 | CSTORM_SYNC_BLOCK_SIZE); |
| 4563 | } |
| 4564 | |
| 4565 | /* helper: writes SP SB data to FW */ |
| 4566 | static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp, |
| 4567 | struct hc_sp_status_block_data *sp_sb_data) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4568 | { |
| 4569 | int func = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4570 | int i; |
| 4571 | for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++) |
| 4572 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4573 | CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) + |
| 4574 | i*sizeof(u32), |
| 4575 | *((u32 *)sp_sb_data + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4576 | } |
| 4577 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4578 | static inline void bnx2x_zero_sp_sb(struct bnx2x *bp) |
| 4579 | { |
| 4580 | int func = BP_FUNC(bp); |
| 4581 | struct hc_sp_status_block_data sp_sb_data; |
| 4582 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); |
| 4583 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4584 | sp_sb_data.state = SB_DISABLED; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4585 | sp_sb_data.p_func.vf_valid = false; |
| 4586 | |
| 4587 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
| 4588 | |
| 4589 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4590 | CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0, |
| 4591 | CSTORM_SP_STATUS_BLOCK_SIZE); |
| 4592 | bnx2x_fill(bp, BAR_CSTRORM_INTMEM + |
| 4593 | CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0, |
| 4594 | CSTORM_SP_SYNC_BLOCK_SIZE); |
| 4595 | |
| 4596 | } |
| 4597 | |
| 4598 | |
| 4599 | static inline |
| 4600 | void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, |
| 4601 | int igu_sb_id, int igu_seg_id) |
| 4602 | { |
| 4603 | hc_sm->igu_sb_id = igu_sb_id; |
| 4604 | hc_sm->igu_seg_id = igu_seg_id; |
| 4605 | hc_sm->timer_value = 0xFF; |
| 4606 | hc_sm->time_to_expire = 0xFFFFFFFF; |
| 4607 | } |
| 4608 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 4609 | 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] | 4610 | u8 vf_valid, int fw_sb_id, int igu_sb_id) |
| 4611 | { |
| 4612 | int igu_seg_id; |
| 4613 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4614 | struct hc_status_block_data_e2 sb_data_e2; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4615 | struct hc_status_block_data_e1x sb_data_e1x; |
| 4616 | struct hc_status_block_sm *hc_sm_p; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4617 | int data_size; |
| 4618 | u32 *sb_data_p; |
| 4619 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4620 | if (CHIP_INT_MODE_IS_BC(bp)) |
| 4621 | igu_seg_id = HC_SEG_ACCESS_NORM; |
| 4622 | else |
| 4623 | igu_seg_id = IGU_SEG_ACCESS_NORM; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4624 | |
| 4625 | bnx2x_zero_fp_sb(bp, fw_sb_id); |
| 4626 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4627 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4628 | memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4629 | sb_data_e2.common.state = SB_ENABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4630 | sb_data_e2.common.p_func.pf_id = BP_FUNC(bp); |
| 4631 | sb_data_e2.common.p_func.vf_id = vfid; |
| 4632 | sb_data_e2.common.p_func.vf_valid = vf_valid; |
| 4633 | sb_data_e2.common.p_func.vnic_id = BP_VN(bp); |
| 4634 | sb_data_e2.common.same_igu_sb_1b = true; |
| 4635 | sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping); |
| 4636 | sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping); |
| 4637 | hc_sm_p = sb_data_e2.common.state_machine; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4638 | sb_data_p = (u32 *)&sb_data_e2; |
| 4639 | data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32); |
| 4640 | } else { |
| 4641 | memset(&sb_data_e1x, 0, |
| 4642 | sizeof(struct hc_status_block_data_e1x)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4643 | sb_data_e1x.common.state = SB_ENABLED; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4644 | sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp); |
| 4645 | sb_data_e1x.common.p_func.vf_id = 0xff; |
| 4646 | sb_data_e1x.common.p_func.vf_valid = false; |
| 4647 | sb_data_e1x.common.p_func.vnic_id = BP_VN(bp); |
| 4648 | sb_data_e1x.common.same_igu_sb_1b = true; |
| 4649 | sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping); |
| 4650 | sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping); |
| 4651 | hc_sm_p = sb_data_e1x.common.state_machine; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4652 | sb_data_p = (u32 *)&sb_data_e1x; |
| 4653 | data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32); |
| 4654 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4655 | |
| 4656 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], |
| 4657 | igu_sb_id, igu_seg_id); |
| 4658 | bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], |
| 4659 | igu_sb_id, igu_seg_id); |
| 4660 | |
| 4661 | DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id); |
| 4662 | |
| 4663 | /* write indecies to HW */ |
| 4664 | bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size); |
| 4665 | } |
| 4666 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4667 | 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] | 4668 | u16 tx_usec, u16 rx_usec) |
| 4669 | { |
| 4670 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX, |
| 4671 | false, rx_usec); |
| 4672 | bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX, |
| 4673 | false, tx_usec); |
| 4674 | } |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4675 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4676 | static void bnx2x_init_def_sb(struct bnx2x *bp) |
| 4677 | { |
| 4678 | struct host_sp_status_block *def_sb = bp->def_status_blk; |
| 4679 | dma_addr_t mapping = bp->def_status_blk_mapping; |
| 4680 | int igu_sp_sb_index; |
| 4681 | int igu_seg_id; |
| 4682 | int port = BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4683 | int func = BP_FUNC(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4684 | int reg_offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4685 | u64 section; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4686 | int index; |
| 4687 | struct hc_sp_status_block_data sp_sb_data; |
| 4688 | memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data)); |
| 4689 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4690 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 4691 | igu_sp_sb_index = DEF_SB_IGU_ID; |
| 4692 | igu_seg_id = HC_SEG_ACCESS_DEF; |
| 4693 | } else { |
| 4694 | igu_sp_sb_index = bp->igu_dsb_id; |
| 4695 | igu_seg_id = IGU_SEG_ACCESS_DEF; |
| 4696 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4697 | |
| 4698 | /* ATTN */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4699 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4700 | atten_status_block); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4701 | def_sb->atten_status_block.status_block_id = igu_sp_sb_index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4702 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4703 | bp->attn_state = 0; |
| 4704 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4705 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 4706 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4707 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4708 | int sindex; |
| 4709 | /* take care of sig[0]..sig[4] */ |
| 4710 | for (sindex = 0; sindex < 4; sindex++) |
| 4711 | bp->attn_group[index].sig[sindex] = |
| 4712 | REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4713 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4714 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4715 | /* |
| 4716 | * enable5 is separate from the rest of the registers, |
| 4717 | * and therefore the address skip is 4 |
| 4718 | * and not 16 between the different groups |
| 4719 | */ |
| 4720 | bp->attn_group[index].sig[4] = REG_RD(bp, |
| 4721 | reg_offset + 0x10 + 0x4*index); |
| 4722 | else |
| 4723 | bp->attn_group[index].sig[4] = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4724 | } |
| 4725 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4726 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 4727 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : |
| 4728 | HC_REG_ATTN_MSG0_ADDR_L); |
| 4729 | |
| 4730 | REG_WR(bp, reg_offset, U64_LO(section)); |
| 4731 | REG_WR(bp, reg_offset + 4, U64_HI(section)); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4732 | } else if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4733 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section)); |
| 4734 | REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section)); |
| 4735 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4736 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4737 | section = ((u64)mapping) + offsetof(struct host_sp_status_block, |
| 4738 | sp_sb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4739 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4740 | bnx2x_zero_sp_sb(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4741 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4742 | sp_sb_data.state = SB_ENABLED; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4743 | sp_sb_data.host_sb_addr.lo = U64_LO(section); |
| 4744 | sp_sb_data.host_sb_addr.hi = U64_HI(section); |
| 4745 | sp_sb_data.igu_sb_id = igu_sp_sb_index; |
| 4746 | sp_sb_data.igu_seg_id = igu_seg_id; |
| 4747 | sp_sb_data.p_func.pf_id = func; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4748 | sp_sb_data.p_func.vnic_id = BP_VN(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4749 | sp_sb_data.p_func.vf_id = 0xff; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4750 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4751 | bnx2x_wr_sp_sb_data(bp, &sp_sb_data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4752 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4753 | 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] | 4754 | } |
| 4755 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 4756 | void bnx2x_update_coalesce(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4757 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4758 | int i; |
| 4759 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 4760 | for_each_eth_queue(bp, i) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4761 | bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id, |
Ariel Elior | 423cfa7e | 2011-03-14 13:43:22 -0700 | [diff] [blame] | 4762 | bp->tx_ticks, bp->rx_ticks); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4763 | } |
| 4764 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4765 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
| 4766 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4767 | spin_lock_init(&bp->spq_lock); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4768 | atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4769 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4770 | bp->spq_prod_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4771 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
| 4772 | bp->spq_prod_bd = bp->spq; |
| 4773 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4774 | } |
| 4775 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4776 | static void bnx2x_init_eq_ring(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4777 | { |
| 4778 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4779 | for (i = 1; i <= NUM_EQ_PAGES; i++) { |
| 4780 | union event_ring_elem *elem = |
| 4781 | &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4782 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4783 | elem->next_page.addr.hi = |
| 4784 | cpu_to_le32(U64_HI(bp->eq_mapping + |
| 4785 | BCM_PAGE_SIZE * (i % NUM_EQ_PAGES))); |
| 4786 | elem->next_page.addr.lo = |
| 4787 | cpu_to_le32(U64_LO(bp->eq_mapping + |
| 4788 | BCM_PAGE_SIZE*(i % NUM_EQ_PAGES))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4789 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4790 | bp->eq_cons = 0; |
| 4791 | bp->eq_prod = NUM_EQ_DESC; |
| 4792 | bp->eq_cons_sb = BNX2X_EQ_INDEX; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 4793 | /* we want a warning message before it gets rought... */ |
| 4794 | atomic_set(&bp->eq_spq_left, |
| 4795 | min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4796 | } |
| 4797 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4798 | |
| 4799 | /* called with netif_addr_lock_bh() */ |
| 4800 | void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id, |
| 4801 | unsigned long rx_mode_flags, |
| 4802 | unsigned long rx_accept_flags, |
| 4803 | unsigned long tx_accept_flags, |
| 4804 | unsigned long ramrod_flags) |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4805 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4806 | struct bnx2x_rx_mode_ramrod_params ramrod_param; |
| 4807 | int rc; |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4808 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4809 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 4810 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4811 | /* Prepare ramrod parameters */ |
| 4812 | ramrod_param.cid = 0; |
| 4813 | ramrod_param.cl_id = cl_id; |
| 4814 | ramrod_param.rx_mode_obj = &bp->rx_mode_obj; |
| 4815 | ramrod_param.func_id = BP_FUNC(bp); |
| 4816 | |
| 4817 | ramrod_param.pstate = &bp->sp_state; |
| 4818 | ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING; |
| 4819 | |
| 4820 | ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata); |
| 4821 | ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata); |
| 4822 | |
| 4823 | set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state); |
| 4824 | |
| 4825 | ramrod_param.ramrod_flags = ramrod_flags; |
| 4826 | ramrod_param.rx_mode_flags = rx_mode_flags; |
| 4827 | |
| 4828 | ramrod_param.rx_accept_flags = rx_accept_flags; |
| 4829 | ramrod_param.tx_accept_flags = tx_accept_flags; |
| 4830 | |
| 4831 | rc = bnx2x_config_rx_mode(bp, &ramrod_param); |
| 4832 | if (rc < 0) { |
| 4833 | BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode); |
| 4834 | return; |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | /* called with netif_addr_lock_bh() */ |
| 4839 | void bnx2x_set_storm_rx_mode(struct bnx2x *bp) |
| 4840 | { |
| 4841 | unsigned long rx_mode_flags = 0, ramrod_flags = 0; |
| 4842 | unsigned long rx_accept_flags = 0, tx_accept_flags = 0; |
| 4843 | |
| 4844 | #ifdef BCM_CNIC |
| 4845 | if (!NO_FCOE(bp)) |
| 4846 | |
| 4847 | /* Configure rx_mode of FCoE Queue */ |
| 4848 | __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags); |
| 4849 | #endif |
| 4850 | |
| 4851 | switch (bp->rx_mode) { |
| 4852 | case BNX2X_RX_MODE_NONE: |
| 4853 | /* |
| 4854 | * 'drop all' supersedes any accept flags that may have been |
| 4855 | * passed to the function. |
| 4856 | */ |
| 4857 | break; |
| 4858 | case BNX2X_RX_MODE_NORMAL: |
| 4859 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4860 | __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags); |
| 4861 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4862 | |
| 4863 | /* internal switching mode */ |
| 4864 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4865 | __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags); |
| 4866 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4867 | |
| 4868 | break; |
| 4869 | case BNX2X_RX_MODE_ALLMULTI: |
| 4870 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4871 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); |
| 4872 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4873 | |
| 4874 | /* internal switching mode */ |
| 4875 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4876 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); |
| 4877 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4878 | |
| 4879 | break; |
| 4880 | case BNX2X_RX_MODE_PROMISC: |
| 4881 | /* According to deffinition of SI mode, iface in promisc mode |
| 4882 | * should receive matched and unmatched (in resolution of port) |
| 4883 | * unicast packets. |
| 4884 | */ |
| 4885 | __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags); |
| 4886 | __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags); |
| 4887 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags); |
| 4888 | __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags); |
| 4889 | |
| 4890 | /* internal switching mode */ |
| 4891 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags); |
| 4892 | __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags); |
| 4893 | |
| 4894 | if (IS_MF_SI(bp)) |
| 4895 | __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags); |
| 4896 | else |
| 4897 | __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags); |
| 4898 | |
| 4899 | break; |
| 4900 | default: |
| 4901 | BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode); |
| 4902 | return; |
| 4903 | } |
| 4904 | |
| 4905 | if (bp->rx_mode != BNX2X_RX_MODE_NONE) { |
| 4906 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags); |
| 4907 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags); |
| 4908 | } |
| 4909 | |
| 4910 | __set_bit(RAMROD_RX, &ramrod_flags); |
| 4911 | __set_bit(RAMROD_TX, &ramrod_flags); |
| 4912 | |
| 4913 | bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags, |
| 4914 | tx_accept_flags, ramrod_flags); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4915 | } |
| 4916 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4917 | static void bnx2x_init_internal_common(struct bnx2x *bp) |
| 4918 | { |
| 4919 | int i; |
| 4920 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 4921 | if (IS_MF_SI(bp)) |
| 4922 | /* |
| 4923 | * In switch independent mode, the TSTORM needs to accept |
| 4924 | * packets that failed classification, since approximate match |
| 4925 | * mac addresses aren't written to NIG LLH |
| 4926 | */ |
| 4927 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 4928 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4929 | else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */ |
| 4930 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 4931 | TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 4932 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4933 | /* Zero this manually as its initialization is |
| 4934 | currently missing in the initTool */ |
| 4935 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) |
| 4936 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4937 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4938 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4939 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET, |
| 4940 | CHIP_INT_MODE_IS_BC(bp) ? |
| 4941 | HC_IGU_BC_MODE : HC_IGU_NBC_MODE); |
| 4942 | } |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4943 | } |
| 4944 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4945 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
| 4946 | { |
| 4947 | switch (load_code) { |
| 4948 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 4949 | case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4950 | bnx2x_init_internal_common(bp); |
| 4951 | /* no break */ |
| 4952 | |
| 4953 | case FW_MSG_CODE_DRV_LOAD_PORT: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4954 | /* nothing to do */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4955 | /* no break */ |
| 4956 | |
| 4957 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4958 | /* internal memory per function is |
| 4959 | initialized inside bnx2x_pf_init */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4960 | break; |
| 4961 | |
| 4962 | default: |
| 4963 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 4964 | break; |
| 4965 | } |
| 4966 | } |
| 4967 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4968 | static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp) |
| 4969 | { |
| 4970 | return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE; |
| 4971 | } |
| 4972 | |
| 4973 | static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp) |
| 4974 | { |
| 4975 | return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE; |
| 4976 | } |
| 4977 | |
| 4978 | static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp) |
| 4979 | { |
| 4980 | if (CHIP_IS_E1x(fp->bp)) |
| 4981 | return BP_L_ID(fp->bp) + fp->index; |
| 4982 | else /* We want Client ID to be the same as IGU SB ID for 57712 */ |
| 4983 | return bnx2x_fp_igu_sb_id(fp); |
| 4984 | } |
| 4985 | |
| 4986 | static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4987 | { |
| 4988 | struct bnx2x_fastpath *fp = &bp->fp[fp_idx]; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4989 | unsigned long q_type = 0; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4990 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 4991 | fp->cid = fp_idx; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4992 | fp->cl_id = bnx2x_fp_cl_id(fp); |
| 4993 | fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp); |
| 4994 | fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4995 | /* qZone id equals to FW (per path) client id */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4996 | fp->cl_qzone_id = bnx2x_fp_qzone_id(fp); |
| 4997 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4998 | /* init shortcut */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 4999 | fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5000 | /* Setup SB indicies */ |
| 5001 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
| 5002 | fp->tx_cons_sb = BNX2X_TX_SB_INDEX; |
| 5003 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5004 | /* Configure Queue State object */ |
| 5005 | __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); |
| 5006 | __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); |
| 5007 | bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp), |
| 5008 | bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata), |
| 5009 | q_type); |
| 5010 | |
| 5011 | /** |
| 5012 | * Configure classification DBs: Always enable Tx switching |
| 5013 | */ |
| 5014 | bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX); |
| 5015 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5016 | DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) " |
| 5017 | "cl_id %d fw_sb %d igu_sb %d\n", |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5018 | 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] | 5019 | fp->igu_sb_id); |
| 5020 | bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false, |
| 5021 | fp->fw_sb_id, fp->igu_sb_id); |
| 5022 | |
| 5023 | bnx2x_update_fpsb_idx(fp); |
| 5024 | } |
| 5025 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 5026 | void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5027 | { |
| 5028 | int i; |
| 5029 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 5030 | for_each_eth_queue(bp, i) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5031 | bnx2x_init_fp(bp, i); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5032 | #ifdef BCM_CNIC |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 5033 | if (!NO_FCOE(bp)) |
| 5034 | bnx2x_init_fcoe_fp(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5035 | |
| 5036 | bnx2x_init_sb(bp, bp->cnic_sb_mapping, |
| 5037 | BNX2X_VF_ID_INVALID, false, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5038 | bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5039 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5040 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5041 | |
Yaniv Rosner | 020c7e3 | 2011-05-31 21:28:43 +0000 | [diff] [blame] | 5042 | /* Initialize MOD_ABS interrupts */ |
| 5043 | bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id, |
| 5044 | bp->common.shmem_base, bp->common.shmem2_base, |
| 5045 | BP_PORT(bp)); |
Eilon Greenstein | 1611978 | 2009-03-02 07:59:27 +0000 | [diff] [blame] | 5046 | /* ensure status block indices were read */ |
| 5047 | rmb(); |
| 5048 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5049 | bnx2x_init_def_sb(bp); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5050 | bnx2x_update_dsb_idx(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5051 | bnx2x_init_rx_rings(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5052 | bnx2x_init_tx_rings(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5053 | bnx2x_init_sp_ring(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5054 | bnx2x_init_eq_ring(bp); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5055 | bnx2x_init_internal(bp, load_code); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5056 | bnx2x_pf_init(bp); |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5057 | bnx2x_stats_init(bp); |
| 5058 | |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5059 | /* flush all before enabling interrupts */ |
| 5060 | mb(); |
| 5061 | mmiowb(); |
| 5062 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 5063 | bnx2x_int_enable(bp); |
Eilon Greenstein | eb8da20 | 2009-07-21 05:47:30 +0000 | [diff] [blame] | 5064 | |
| 5065 | /* Check for SPIO5 */ |
| 5066 | bnx2x_attn_int_deasserted0(bp, |
| 5067 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & |
| 5068 | AEU_INPUTS_ATTN_BITS_SPIO5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /* end of nic init */ |
| 5072 | |
| 5073 | /* |
| 5074 | * gzip service functions |
| 5075 | */ |
| 5076 | |
| 5077 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
| 5078 | { |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5079 | bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE, |
| 5080 | &bp->gunzip_mapping, GFP_KERNEL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5081 | if (bp->gunzip_buf == NULL) |
| 5082 | goto gunzip_nomem1; |
| 5083 | |
| 5084 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); |
| 5085 | if (bp->strm == NULL) |
| 5086 | goto gunzip_nomem2; |
| 5087 | |
| 5088 | bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), |
| 5089 | GFP_KERNEL); |
| 5090 | if (bp->strm->workspace == NULL) |
| 5091 | goto gunzip_nomem3; |
| 5092 | |
| 5093 | return 0; |
| 5094 | |
| 5095 | gunzip_nomem3: |
| 5096 | kfree(bp->strm); |
| 5097 | bp->strm = NULL; |
| 5098 | |
| 5099 | gunzip_nomem2: |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5100 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5101 | bp->gunzip_mapping); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5102 | bp->gunzip_buf = NULL; |
| 5103 | |
| 5104 | gunzip_nomem1: |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5105 | netdev_err(bp->dev, "Cannot allocate firmware buffer for" |
| 5106 | " un-compression\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5107 | return -ENOMEM; |
| 5108 | } |
| 5109 | |
| 5110 | static void bnx2x_gunzip_end(struct bnx2x *bp) |
| 5111 | { |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 5112 | if (bp->strm) { |
| 5113 | kfree(bp->strm->workspace); |
| 5114 | kfree(bp->strm); |
| 5115 | bp->strm = NULL; |
| 5116 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5117 | |
| 5118 | if (bp->gunzip_buf) { |
FUJITA Tomonori | 1a98314 | 2010-04-04 01:51:03 +0000 | [diff] [blame] | 5119 | dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5120 | bp->gunzip_mapping); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5121 | bp->gunzip_buf = NULL; |
| 5122 | } |
| 5123 | } |
| 5124 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5125 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5126 | { |
| 5127 | int n, rc; |
| 5128 | |
| 5129 | /* check gzip header */ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5130 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
| 5131 | BNX2X_ERR("Bad gzip header\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5132 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5133 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5134 | |
| 5135 | n = 10; |
| 5136 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5137 | #define FNAME 0x8 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5138 | |
| 5139 | if (zbuf[3] & FNAME) |
| 5140 | while ((zbuf[n++] != 0) && (n < len)); |
| 5141 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5142 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5143 | bp->strm->avail_in = len - n; |
| 5144 | bp->strm->next_out = bp->gunzip_buf; |
| 5145 | bp->strm->avail_out = FW_BUF_SIZE; |
| 5146 | |
| 5147 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); |
| 5148 | if (rc != Z_OK) |
| 5149 | return rc; |
| 5150 | |
| 5151 | rc = zlib_inflate(bp->strm, Z_FINISH); |
| 5152 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 5153 | netdev_err(bp->dev, "Firmware decompression error: %s\n", |
| 5154 | bp->strm->msg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5155 | |
| 5156 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); |
| 5157 | if (bp->gunzip_outlen & 0x3) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5158 | netdev_err(bp->dev, "Firmware decompression error:" |
| 5159 | " gunzip_outlen (%d) not aligned\n", |
| 5160 | bp->gunzip_outlen); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5161 | bp->gunzip_outlen >>= 2; |
| 5162 | |
| 5163 | zlib_inflateEnd(bp->strm); |
| 5164 | |
| 5165 | if (rc == Z_STREAM_END) |
| 5166 | return 0; |
| 5167 | |
| 5168 | return rc; |
| 5169 | } |
| 5170 | |
| 5171 | /* nic load/unload */ |
| 5172 | |
| 5173 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5174 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5175 | */ |
| 5176 | |
| 5177 | /* send a NIG loopback debug packet */ |
| 5178 | static void bnx2x_lb_pckt(struct bnx2x *bp) |
| 5179 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5180 | u32 wb_write[3]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5181 | |
| 5182 | /* Ethernet source and destination addresses */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5183 | wb_write[0] = 0x55555555; |
| 5184 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5185 | wb_write[2] = 0x20; /* SOP */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5186 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5187 | |
| 5188 | /* NON-IP protocol */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5189 | wb_write[0] = 0x09000000; |
| 5190 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5191 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5192 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | /* some of the internal memories |
| 5196 | * are not directly readable from the driver |
| 5197 | * to test them we send debug packets |
| 5198 | */ |
| 5199 | static int bnx2x_int_mem_test(struct bnx2x *bp) |
| 5200 | { |
| 5201 | int factor; |
| 5202 | int count, i; |
| 5203 | u32 val = 0; |
| 5204 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5205 | if (CHIP_REV_IS_FPGA(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5206 | factor = 120; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5207 | else if (CHIP_REV_IS_EMUL(bp)) |
| 5208 | factor = 200; |
| 5209 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5210 | factor = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5211 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5212 | /* Disable inputs of parser neighbor blocks */ |
| 5213 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5214 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5215 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5216 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5217 | |
| 5218 | /* Write 0 to parser credits for CFC search request */ |
| 5219 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5220 | |
| 5221 | /* send Ethernet packet */ |
| 5222 | bnx2x_lb_pckt(bp); |
| 5223 | |
| 5224 | /* TODO do i reset NIG statistic? */ |
| 5225 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5226 | count = 1000 * factor; |
| 5227 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5228 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5229 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5230 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5231 | if (val == 0x10) |
| 5232 | break; |
| 5233 | |
| 5234 | msleep(10); |
| 5235 | count--; |
| 5236 | } |
| 5237 | if (val != 0x10) { |
| 5238 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5239 | return -1; |
| 5240 | } |
| 5241 | |
| 5242 | /* Wait until PRS register shows 1 packet */ |
| 5243 | count = 1000 * factor; |
| 5244 | while (count) { |
| 5245 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5246 | if (val == 1) |
| 5247 | break; |
| 5248 | |
| 5249 | msleep(10); |
| 5250 | count--; |
| 5251 | } |
| 5252 | if (val != 0x1) { |
| 5253 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5254 | return -2; |
| 5255 | } |
| 5256 | |
| 5257 | /* Reset and init BRB, PRS */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5258 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5259 | msleep(50); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5260 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5261 | msleep(50); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5262 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
| 5263 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5264 | |
| 5265 | DP(NETIF_MSG_HW, "part2\n"); |
| 5266 | |
| 5267 | /* Disable inputs of parser neighbor blocks */ |
| 5268 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5269 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5270 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5271 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5272 | |
| 5273 | /* Write 0 to parser credits for CFC search request */ |
| 5274 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5275 | |
| 5276 | /* send 10 Ethernet packets */ |
| 5277 | for (i = 0; i < 10; i++) |
| 5278 | bnx2x_lb_pckt(bp); |
| 5279 | |
| 5280 | /* Wait until NIG register shows 10 + 1 |
| 5281 | packets of size 11*0x10 = 0xb0 */ |
| 5282 | count = 1000 * factor; |
| 5283 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5284 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5285 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5286 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5287 | if (val == 0xb0) |
| 5288 | break; |
| 5289 | |
| 5290 | msleep(10); |
| 5291 | count--; |
| 5292 | } |
| 5293 | if (val != 0xb0) { |
| 5294 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5295 | return -3; |
| 5296 | } |
| 5297 | |
| 5298 | /* Wait until PRS register shows 2 packets */ |
| 5299 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5300 | if (val != 2) |
| 5301 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5302 | |
| 5303 | /* Write 1 to parser credits for CFC search request */ |
| 5304 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); |
| 5305 | |
| 5306 | /* Wait until PRS register shows 3 packets */ |
| 5307 | msleep(10 * factor); |
| 5308 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5309 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5310 | if (val != 3) |
| 5311 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5312 | |
| 5313 | /* clear NIG EOP FIFO */ |
| 5314 | for (i = 0; i < 11; i++) |
| 5315 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); |
| 5316 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); |
| 5317 | if (val != 1) { |
| 5318 | BNX2X_ERR("clear of NIG failed\n"); |
| 5319 | return -4; |
| 5320 | } |
| 5321 | |
| 5322 | /* Reset and init BRB, PRS, NIG */ |
| 5323 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
| 5324 | msleep(50); |
| 5325 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
| 5326 | msleep(50); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5327 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
| 5328 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5329 | #ifndef BCM_CNIC |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5330 | /* set NIC mode */ |
| 5331 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 5332 | #endif |
| 5333 | |
| 5334 | /* Enable inputs of parser neighbor blocks */ |
| 5335 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); |
| 5336 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); |
| 5337 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5338 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5339 | |
| 5340 | DP(NETIF_MSG_HW, "done\n"); |
| 5341 | |
| 5342 | return 0; /* OK */ |
| 5343 | } |
| 5344 | |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5345 | static void bnx2x_enable_blocks_attention(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5346 | { |
| 5347 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5348 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5349 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40); |
| 5350 | else |
| 5351 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5352 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5353 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5354 | /* |
| 5355 | * mask read length error interrupts in brb for parser |
| 5356 | * (parsing unit and 'checksum and crc' unit) |
| 5357 | * these errors are legal (PU reads fixed length and CAC can cause |
| 5358 | * read length error on truncated packets) |
| 5359 | */ |
| 5360 | REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5361 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
| 5362 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); |
| 5363 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); |
| 5364 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); |
| 5365 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5366 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
| 5367 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5368 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
| 5369 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); |
| 5370 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5371 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
| 5372 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5373 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
| 5374 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); |
| 5375 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); |
| 5376 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5377 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
| 5378 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5379 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5380 | if (CHIP_REV_IS_FPGA(bp)) |
| 5381 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5382 | else if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5383 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, |
| 5384 | (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
| 5385 | | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
| 5386 | | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN |
| 5387 | | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
| 5388 | | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5389 | else |
| 5390 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5391 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
| 5392 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); |
| 5393 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5394 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5395 | |
| 5396 | if (!CHIP_IS_E1x(bp)) |
| 5397 | /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */ |
| 5398 | REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff); |
| 5399 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5400 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
| 5401 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5402 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5403 | 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] | 5404 | } |
| 5405 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5406 | static void bnx2x_reset_common(struct bnx2x *bp) |
| 5407 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5408 | u32 val = 0x1400; |
| 5409 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5410 | /* reset_common */ |
| 5411 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5412 | 0xd3ffff7f); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5413 | |
| 5414 | if (CHIP_IS_E3(bp)) { |
| 5415 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 5416 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 5417 | } |
| 5418 | |
| 5419 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val); |
| 5420 | } |
| 5421 | |
| 5422 | static void bnx2x_setup_dmae(struct bnx2x *bp) |
| 5423 | { |
| 5424 | bp->dmae_ready = 0; |
| 5425 | spin_lock_init(&bp->dmae_lock); |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5426 | } |
| 5427 | |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 5428 | static void bnx2x_init_pxp(struct bnx2x *bp) |
| 5429 | { |
| 5430 | u16 devctl; |
| 5431 | int r_order, w_order; |
| 5432 | |
| 5433 | pci_read_config_word(bp->pdev, |
| 5434 | bp->pcie_cap + PCI_EXP_DEVCTL, &devctl); |
| 5435 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
| 5436 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); |
| 5437 | if (bp->mrrs == -1) |
| 5438 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); |
| 5439 | else { |
| 5440 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); |
| 5441 | r_order = bp->mrrs; |
| 5442 | } |
| 5443 | |
| 5444 | bnx2x_init_pxp_arb(bp, r_order, w_order); |
| 5445 | } |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5446 | |
| 5447 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) |
| 5448 | { |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5449 | int is_required; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5450 | u32 val; |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5451 | int port; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5452 | |
Vladislav Zolotarov | 2145a92 | 2010-04-19 01:13:49 +0000 | [diff] [blame] | 5453 | if (BP_NOMCP(bp)) |
| 5454 | return; |
| 5455 | |
| 5456 | is_required = 0; |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5457 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
| 5458 | SHARED_HW_CFG_FAN_FAILURE_MASK; |
| 5459 | |
| 5460 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) |
| 5461 | is_required = 1; |
| 5462 | |
| 5463 | /* |
| 5464 | * The fan failure mechanism is usually related to the PHY type since |
| 5465 | * the power consumption of the board is affected by the PHY. Currently, |
| 5466 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. |
| 5467 | */ |
| 5468 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) |
| 5469 | for (port = PORT_0; port < PORT_MAX; port++) { |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5470 | is_required |= |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 5471 | bnx2x_fan_failure_det_req( |
| 5472 | bp, |
| 5473 | bp->common.shmem_base, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 5474 | bp->common.shmem2_base, |
Yaniv Rosner | d90d96b | 2010-09-07 11:41:04 +0000 | [diff] [blame] | 5475 | port); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); |
| 5479 | |
| 5480 | if (is_required == 0) |
| 5481 | return; |
| 5482 | |
| 5483 | /* Fan failure is indicated by SPIO 5 */ |
| 5484 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, |
| 5485 | MISC_REGISTERS_SPIO_INPUT_HI_Z); |
| 5486 | |
| 5487 | /* set to active low mode */ |
| 5488 | val = REG_RD(bp, MISC_REG_SPIO_INT); |
| 5489 | val |= ((1 << MISC_REGISTERS_SPIO_5) << |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5490 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5491 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
| 5492 | |
| 5493 | /* enable interrupt to signal the IGU */ |
| 5494 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 5495 | val |= (1 << MISC_REGISTERS_SPIO_5); |
| 5496 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
| 5497 | } |
| 5498 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5499 | static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num) |
| 5500 | { |
| 5501 | u32 offset = 0; |
| 5502 | |
| 5503 | if (CHIP_IS_E1(bp)) |
| 5504 | return; |
| 5505 | if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX)) |
| 5506 | return; |
| 5507 | |
| 5508 | switch (BP_ABS_FUNC(bp)) { |
| 5509 | case 0: |
| 5510 | offset = PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 5511 | break; |
| 5512 | case 1: |
| 5513 | offset = PXP2_REG_PGL_PRETEND_FUNC_F1; |
| 5514 | break; |
| 5515 | case 2: |
| 5516 | offset = PXP2_REG_PGL_PRETEND_FUNC_F2; |
| 5517 | break; |
| 5518 | case 3: |
| 5519 | offset = PXP2_REG_PGL_PRETEND_FUNC_F3; |
| 5520 | break; |
| 5521 | case 4: |
| 5522 | offset = PXP2_REG_PGL_PRETEND_FUNC_F4; |
| 5523 | break; |
| 5524 | case 5: |
| 5525 | offset = PXP2_REG_PGL_PRETEND_FUNC_F5; |
| 5526 | break; |
| 5527 | case 6: |
| 5528 | offset = PXP2_REG_PGL_PRETEND_FUNC_F6; |
| 5529 | break; |
| 5530 | case 7: |
| 5531 | offset = PXP2_REG_PGL_PRETEND_FUNC_F7; |
| 5532 | break; |
| 5533 | default: |
| 5534 | return; |
| 5535 | } |
| 5536 | |
| 5537 | REG_WR(bp, offset, pretend_func_num); |
| 5538 | REG_RD(bp, offset); |
| 5539 | DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num); |
| 5540 | } |
| 5541 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 5542 | void bnx2x_pf_disable(struct bnx2x *bp) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5543 | { |
| 5544 | u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION); |
| 5545 | val &= ~IGU_PF_CONF_FUNC_EN; |
| 5546 | |
| 5547 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, val); |
| 5548 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); |
| 5549 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0); |
| 5550 | } |
| 5551 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5552 | static inline void bnx2x__common_init_phy(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5553 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5554 | u32 shmem_base[2], shmem2_base[2]; |
| 5555 | shmem_base[0] = bp->common.shmem_base; |
| 5556 | shmem2_base[0] = bp->common.shmem2_base; |
| 5557 | if (!CHIP_IS_E1x(bp)) { |
| 5558 | shmem_base[1] = |
| 5559 | SHMEM2_RD(bp, other_shmem_base_addr); |
| 5560 | shmem2_base[1] = |
| 5561 | SHMEM2_RD(bp, other_shmem2_base_addr); |
| 5562 | } |
| 5563 | bnx2x_acquire_phy_lock(bp); |
| 5564 | bnx2x_common_init_phy(bp, shmem_base, shmem2_base, |
| 5565 | bp->common.chip_id); |
| 5566 | bnx2x_release_phy_lock(bp); |
| 5567 | } |
| 5568 | |
| 5569 | /** |
| 5570 | * bnx2x_init_hw_common - initialize the HW at the COMMON phase. |
| 5571 | * |
| 5572 | * @bp: driver handle |
| 5573 | */ |
| 5574 | static int bnx2x_init_hw_common(struct bnx2x *bp) |
| 5575 | { |
| 5576 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5577 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5578 | 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] | 5579 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5580 | bnx2x_reset_common(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5581 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5582 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5583 | val = 0xfffc; |
| 5584 | if (CHIP_IS_E3(bp)) { |
| 5585 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 5586 | val |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 5587 | } |
| 5588 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5589 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5590 | bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON); |
| 5591 | |
| 5592 | if (!CHIP_IS_E1x(bp)) { |
| 5593 | u8 abs_func_id; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5594 | |
| 5595 | /** |
| 5596 | * 4-port mode or 2-port mode we need to turn of master-enable |
| 5597 | * for everyone, after that, turn it back on for self. |
| 5598 | * so, we disregard multi-function or not, and always disable |
| 5599 | * for all functions on the given path, this means 0,2,4,6 for |
| 5600 | * path 0 and 1,3,5,7 for path 1 |
| 5601 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5602 | for (abs_func_id = BP_PATH(bp); |
| 5603 | abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) { |
| 5604 | if (abs_func_id == BP_ABS_FUNC(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5605 | REG_WR(bp, |
| 5606 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, |
| 5607 | 1); |
| 5608 | continue; |
| 5609 | } |
| 5610 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5611 | bnx2x_pretend_func(bp, abs_func_id); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5612 | /* clear pf enable */ |
| 5613 | bnx2x_pf_disable(bp); |
| 5614 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); |
| 5615 | } |
| 5616 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5617 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5618 | bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5619 | if (CHIP_IS_E1(bp)) { |
| 5620 | /* enable HW interrupt from PXP on USDM overflow |
| 5621 | bit 16 on INT_MASK_0 */ |
| 5622 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5623 | } |
| 5624 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5625 | bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5626 | bnx2x_init_pxp(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5627 | |
| 5628 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5629 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
| 5630 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); |
| 5631 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); |
| 5632 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); |
| 5633 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5634 | /* make sure this value is 0 */ |
| 5635 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5636 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5637 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ |
| 5638 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); |
| 5639 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); |
| 5640 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); |
| 5641 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5642 | #endif |
| 5643 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5644 | bnx2x_ilt_init_page_size(bp, INITOP_SET); |
| 5645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5646 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
| 5647 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5648 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5649 | /* let the HW do it's magic ... */ |
| 5650 | msleep(100); |
| 5651 | /* finish PXP init */ |
| 5652 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); |
| 5653 | if (val != 1) { |
| 5654 | BNX2X_ERR("PXP2 CFG failed\n"); |
| 5655 | return -EBUSY; |
| 5656 | } |
| 5657 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); |
| 5658 | if (val != 1) { |
| 5659 | BNX2X_ERR("PXP2 RD_INIT failed\n"); |
| 5660 | return -EBUSY; |
| 5661 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5662 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5663 | /* Timers bug workaround E2 only. We need to set the entire ILT to |
| 5664 | * have entries with value "0" and valid bit on. |
| 5665 | * This needs to be done by the first PF that is loaded in a path |
| 5666 | * (i.e. common phase) |
| 5667 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5668 | if (!CHIP_IS_E1x(bp)) { |
| 5669 | /* In E2 there is a bug in the timers block that can cause function 6 / 7 |
| 5670 | * (i.e. vnic3) to start even if it is marked as "scan-off". |
| 5671 | * This occurs when a different function (func2,3) is being marked |
| 5672 | * as "scan-off". Real-life scenario for example: if a driver is being |
| 5673 | * load-unloaded while func6,7 are down. This will cause the timer to access |
| 5674 | * the ilt, translate to a logical address and send a request to read/write. |
| 5675 | * Since the ilt for the function that is down is not valid, this will cause |
| 5676 | * a translation error which is unrecoverable. |
| 5677 | * The Workaround is intended to make sure that when this happens nothing fatal |
| 5678 | * will occur. The workaround: |
| 5679 | * 1. First PF driver which loads on a path will: |
| 5680 | * a. After taking the chip out of reset, by using pretend, |
| 5681 | * it will write "0" to the following registers of |
| 5682 | * the other vnics. |
| 5683 | * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0); |
| 5684 | * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0); |
| 5685 | * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0); |
| 5686 | * And for itself it will write '1' to |
| 5687 | * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable |
| 5688 | * dmae-operations (writing to pram for example.) |
| 5689 | * note: can be done for only function 6,7 but cleaner this |
| 5690 | * way. |
| 5691 | * b. Write zero+valid to the entire ILT. |
| 5692 | * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of |
| 5693 | * VNIC3 (of that port). The range allocated will be the |
| 5694 | * entire ILT. This is needed to prevent ILT range error. |
| 5695 | * 2. Any PF driver load flow: |
| 5696 | * a. ILT update with the physical addresses of the allocated |
| 5697 | * logical pages. |
| 5698 | * b. Wait 20msec. - note that this timeout is needed to make |
| 5699 | * sure there are no requests in one of the PXP internal |
| 5700 | * queues with "old" ILT addresses. |
| 5701 | * c. PF enable in the PGLC. |
| 5702 | * d. Clear the was_error of the PF in the PGLC. (could have |
| 5703 | * occured while driver was down) |
| 5704 | * e. PF enable in the CFC (WEAK + STRONG) |
| 5705 | * f. Timers scan enable |
| 5706 | * 3. PF driver unload flow: |
| 5707 | * a. Clear the Timers scan_en. |
| 5708 | * b. Polling for scan_on=0 for that PF. |
| 5709 | * c. Clear the PF enable bit in the PXP. |
| 5710 | * d. Clear the PF enable in the CFC (WEAK + STRONG) |
| 5711 | * e. Write zero+valid to all ILT entries (The valid bit must |
| 5712 | * stay set) |
| 5713 | * f. If this is VNIC 3 of a port then also init |
| 5714 | * first_timers_ilt_entry to zero and last_timers_ilt_entry |
| 5715 | * to the last enrty in the ILT. |
| 5716 | * |
| 5717 | * Notes: |
| 5718 | * Currently the PF error in the PGLC is non recoverable. |
| 5719 | * In the future the there will be a recovery routine for this error. |
| 5720 | * Currently attention is masked. |
| 5721 | * Having an MCP lock on the load/unload process does not guarantee that |
| 5722 | * there is no Timer disable during Func6/7 enable. This is because the |
| 5723 | * Timers scan is currently being cleared by the MCP on FLR. |
| 5724 | * Step 2.d can be done only for PF6/7 and the driver can also check if |
| 5725 | * there is error before clearing it. But the flow above is simpler and |
| 5726 | * more general. |
| 5727 | * All ILT entries are written by zero+valid and not just PF6/7 |
| 5728 | * ILT entries since in the future the ILT entries allocation for |
| 5729 | * PF-s might be dynamic. |
| 5730 | */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5731 | struct ilt_client_info ilt_cli; |
| 5732 | struct bnx2x_ilt ilt; |
| 5733 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); |
| 5734 | memset(&ilt, 0, sizeof(struct bnx2x_ilt)); |
| 5735 | |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 5736 | /* initialize dummy TM client */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5737 | ilt_cli.start = 0; |
| 5738 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; |
| 5739 | ilt_cli.client_num = ILT_CLIENT_TM; |
| 5740 | |
| 5741 | /* Step 1: set zeroes to all ilt page entries with valid bit on |
| 5742 | * Step 2: set the timers first/last ilt entry to point |
| 5743 | * to the entire range to prevent ILT range error for 3rd/4th |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5744 | * vnic (this code assumes existance of the vnic) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5745 | * |
| 5746 | * both steps performed by call to bnx2x_ilt_client_init_op() |
| 5747 | * with dummy TM client |
| 5748 | * |
| 5749 | * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT |
| 5750 | * and his brother are split registers |
| 5751 | */ |
| 5752 | bnx2x_pretend_func(bp, (BP_PATH(bp) + 6)); |
| 5753 | bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR); |
| 5754 | bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); |
| 5755 | |
| 5756 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN); |
| 5757 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN); |
| 5758 | REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1); |
| 5759 | } |
| 5760 | |
| 5761 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5762 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
| 5763 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5764 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5765 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5766 | int factor = CHIP_REV_IS_EMUL(bp) ? 1000 : |
| 5767 | (CHIP_REV_IS_FPGA(bp) ? 400 : 0); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5768 | bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5769 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5770 | bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5771 | |
| 5772 | /* let the HW do it's magic ... */ |
| 5773 | do { |
| 5774 | msleep(200); |
| 5775 | val = REG_RD(bp, ATC_REG_ATC_INIT_DONE); |
| 5776 | } while (factor-- && (val != 1)); |
| 5777 | |
| 5778 | if (val != 1) { |
| 5779 | BNX2X_ERR("ATC_INIT failed\n"); |
| 5780 | return -EBUSY; |
| 5781 | } |
| 5782 | } |
| 5783 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5784 | bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5785 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5786 | /* clean the DMAE memory */ |
| 5787 | bp->dmae_ready = 1; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5788 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5789 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5790 | bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON); |
| 5791 | |
| 5792 | bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON); |
| 5793 | |
| 5794 | bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON); |
| 5795 | |
| 5796 | bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5797 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5798 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
| 5799 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); |
| 5800 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); |
| 5801 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); |
| 5802 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5803 | bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5804 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5805 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5806 | /* QM queues pointers table */ |
| 5807 | bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5808 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5809 | /* soft reset pulse */ |
| 5810 | REG_WR(bp, QM_REG_SOFT_RESET, 1); |
| 5811 | REG_WR(bp, QM_REG_SOFT_RESET, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5812 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5813 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5814 | bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5815 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5816 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5817 | bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 5818 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5819 | if (!CHIP_REV_IS_SLOW(bp)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5820 | /* enable hw interrupt from doorbell Q */ |
| 5821 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5822 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5823 | bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5824 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5825 | bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON); |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5826 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5827 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5828 | if (!CHIP_IS_E1(bp)) |
| 5829 | REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan); |
| 5830 | |
| 5831 | if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) |
| 5832 | /* Bit-map indicating which L2 hdrs may appear |
| 5833 | * after the basic Ethernet header |
| 5834 | */ |
| 5835 | REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, |
| 5836 | bp->path_has_ovlan ? 7 : 6); |
| 5837 | |
| 5838 | bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON); |
| 5839 | bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON); |
| 5840 | bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON); |
| 5841 | bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON); |
| 5842 | |
| 5843 | if (!CHIP_IS_E1x(bp)) { |
| 5844 | /* reset VFC memories */ |
| 5845 | REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, |
| 5846 | VFC_MEMORIES_RST_REG_CAM_RST | |
| 5847 | VFC_MEMORIES_RST_REG_RAM_RST); |
| 5848 | REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST, |
| 5849 | VFC_MEMORIES_RST_REG_CAM_RST | |
| 5850 | VFC_MEMORIES_RST_REG_RAM_RST); |
| 5851 | |
| 5852 | msleep(20); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5853 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5854 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5855 | bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON); |
| 5856 | bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON); |
| 5857 | bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON); |
| 5858 | bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5859 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5860 | /* sync semi rtc */ |
| 5861 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5862 | 0x80000000); |
| 5863 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 5864 | 0x80000000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5865 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5866 | bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON); |
| 5867 | bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON); |
| 5868 | bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5869 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5870 | if (!CHIP_IS_E1x(bp)) |
| 5871 | REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, |
| 5872 | bp->path_has_ovlan ? 7 : 6); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5873 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5874 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 5875 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5876 | bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON); |
| 5877 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 5878 | #ifdef BCM_CNIC |
| 5879 | REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672); |
| 5880 | REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc); |
| 5881 | REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b); |
| 5882 | REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a); |
| 5883 | REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116); |
| 5884 | REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b); |
| 5885 | REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf); |
| 5886 | REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09); |
| 5887 | REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f); |
| 5888 | REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7); |
| 5889 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5890 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5891 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5892 | if (sizeof(union cdu_context) != 1024) |
| 5893 | /* we currently assume that a context is 1024 bytes */ |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 5894 | dev_alert(&bp->pdev->dev, "please adjust the size " |
| 5895 | "of cdu_context(%ld)\n", |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 5896 | (long)sizeof(union cdu_context)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5897 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5898 | bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5899 | val = (4 << 24) + (0 << 12) + 1024; |
| 5900 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5901 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5902 | bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5903 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5904 | /* enable context validation interrupt from CFC */ |
| 5905 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5906 | |
| 5907 | /* set the thresholds to prevent CFC/CDU race */ |
| 5908 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5909 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5910 | bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5911 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5912 | if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5913 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36); |
| 5914 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5915 | bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON); |
| 5916 | bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5917 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5918 | /* Reset PCIE errors for debug */ |
| 5919 | REG_WR(bp, 0x2814, 0xffffffff); |
| 5920 | REG_WR(bp, 0x3820, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5921 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5922 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5923 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5, |
| 5924 | (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 | |
| 5925 | PXPCS_TL_CONTROL_5_ERR_UNSPPORT)); |
| 5926 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT, |
| 5927 | (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 | |
| 5928 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 | |
| 5929 | PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2)); |
| 5930 | REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT, |
| 5931 | (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 | |
| 5932 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 | |
| 5933 | PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5)); |
| 5934 | } |
| 5935 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5936 | bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5937 | if (!CHIP_IS_E1(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5938 | /* in E3 this done in per-port section */ |
| 5939 | if (!CHIP_IS_E3(bp)) |
| 5940 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp)); |
| 5941 | } |
| 5942 | if (CHIP_IS_E1H(bp)) |
| 5943 | /* not applicable for E2 (and above ...) */ |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 5944 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5945 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5946 | if (CHIP_REV_IS_SLOW(bp)) |
| 5947 | msleep(200); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5948 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5949 | /* finish CFC init */ |
| 5950 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); |
| 5951 | if (val != 1) { |
| 5952 | BNX2X_ERR("CFC LL_INIT failed\n"); |
| 5953 | return -EBUSY; |
| 5954 | } |
| 5955 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); |
| 5956 | if (val != 1) { |
| 5957 | BNX2X_ERR("CFC AC_INIT failed\n"); |
| 5958 | return -EBUSY; |
| 5959 | } |
| 5960 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); |
| 5961 | if (val != 1) { |
| 5962 | BNX2X_ERR("CFC CAM_INIT failed\n"); |
| 5963 | return -EBUSY; |
| 5964 | } |
| 5965 | REG_WR(bp, CFC_REG_DEBUG0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5966 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5967 | if (CHIP_IS_E1(bp)) { |
| 5968 | /* read NIG statistic |
| 5969 | to see if this is our first up since powerup */ |
| 5970 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5971 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5972 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 5973 | /* do internal memory self test */ |
| 5974 | if ((val == 0) && bnx2x_int_mem_test(bp)) { |
| 5975 | BNX2X_ERR("internal mem self test failed\n"); |
| 5976 | return -EBUSY; |
| 5977 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5978 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5979 | |
Eilon Greenstein | fd4ef40d | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5980 | bnx2x_setup_fan_failure_detection(bp); |
| 5981 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5982 | /* clear PXP2 attentions */ |
| 5983 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5984 | |
Vladislav Zolotarov | 4a33bc0 | 2011-01-09 02:20:04 +0000 | [diff] [blame] | 5985 | bnx2x_enable_blocks_attention(bp); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 5986 | bnx2x_enable_blocks_parity(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5987 | |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5988 | if (!BP_NOMCP(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5989 | if (CHIP_IS_E1x(bp)) |
| 5990 | bnx2x__common_init_phy(bp); |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5991 | } else |
| 5992 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
| 5993 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5994 | return 0; |
| 5995 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5996 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 5997 | /** |
| 5998 | * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase. |
| 5999 | * |
| 6000 | * @bp: driver handle |
| 6001 | */ |
| 6002 | static int bnx2x_init_hw_common_chip(struct bnx2x *bp) |
| 6003 | { |
| 6004 | int rc = bnx2x_init_hw_common(bp); |
| 6005 | |
| 6006 | if (rc) |
| 6007 | return rc; |
| 6008 | |
| 6009 | /* In E2 2-PORT mode, same ext phy is used for the two paths */ |
| 6010 | if (!BP_NOMCP(bp)) |
| 6011 | bnx2x__common_init_phy(bp); |
| 6012 | |
| 6013 | return 0; |
| 6014 | } |
| 6015 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6016 | static int bnx2x_init_hw_port(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6017 | { |
| 6018 | int port = BP_PORT(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6019 | int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6020 | u32 low, high; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6021 | u32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6022 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6023 | bnx2x__link_reset(bp); |
| 6024 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6025 | DP(BNX2X_MSG_MCP, "starting port init port %d\n", port); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6026 | |
| 6027 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6028 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6029 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
| 6030 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
| 6031 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6032 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6033 | /* Timers bug workaround: disables the pf_master bit in pglue at |
| 6034 | * common phase, we need to enable it here before any dmae access are |
| 6035 | * attempted. Therefore we manually added the enable-master to the |
| 6036 | * port phase (it also happens in the function phase) |
| 6037 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6038 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6039 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
| 6040 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6041 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
| 6042 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); |
| 6043 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
| 6044 | bnx2x_init_block(bp, BLOCK_QM, init_phase); |
| 6045 | |
| 6046 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); |
| 6047 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); |
| 6048 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); |
| 6049 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6050 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6051 | /* QM cid (connection) count */ |
| 6052 | bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6053 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6054 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6055 | bnx2x_init_block(bp, BLOCK_TM, init_phase); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6056 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20); |
| 6057 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6058 | #endif |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6059 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6060 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6061 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6062 | if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6063 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
| 6064 | |
| 6065 | if (IS_MF(bp)) |
| 6066 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); |
| 6067 | else if (bp->dev->mtu > 4096) { |
| 6068 | if (bp->flags & ONE_PORT_FLAG) |
| 6069 | low = 160; |
| 6070 | else { |
| 6071 | val = bp->dev->mtu; |
| 6072 | /* (24*1024 + val*4)/256 */ |
| 6073 | low = 96 + (val/64) + |
| 6074 | ((val % 64) ? 1 : 0); |
| 6075 | } |
| 6076 | } else |
| 6077 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); |
| 6078 | high = low + 56; /* 14*1024/256 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6079 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
| 6080 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); |
| 6081 | } |
| 6082 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6083 | if (CHIP_MODE_IS_4_PORT(bp)) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6084 | REG_WR(bp, (BP_PORT(bp) ? |
| 6085 | BRB1_REG_MAC_GUARANTIED_1 : |
| 6086 | BRB1_REG_MAC_GUARANTIED_0), 40); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6087 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6088 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6089 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
| 6090 | if (CHIP_IS_E3B0(bp)) |
| 6091 | /* Ovlan exists only if we are in multi-function + |
| 6092 | * switch-dependent mode, in switch-independent there |
| 6093 | * is no ovlan headers |
| 6094 | */ |
| 6095 | REG_WR(bp, BP_PORT(bp) ? |
| 6096 | PRS_REG_HDRS_AFTER_BASIC_PORT_1 : |
| 6097 | PRS_REG_HDRS_AFTER_BASIC_PORT_0, |
| 6098 | (bp->path_has_ovlan ? 7 : 6)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6099 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6100 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
| 6101 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); |
| 6102 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); |
| 6103 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); |
| 6104 | |
| 6105 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
| 6106 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); |
| 6107 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); |
| 6108 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); |
| 6109 | |
| 6110 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
| 6111 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); |
| 6112 | |
| 6113 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
| 6114 | |
| 6115 | if (CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6116 | /* configure PBF to work without PAUSE mtu 9000 */ |
| 6117 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6118 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6119 | /* update threshold */ |
| 6120 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); |
| 6121 | /* update init credit */ |
| 6122 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6123 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6124 | /* probe changes */ |
| 6125 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); |
| 6126 | udelay(50); |
| 6127 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); |
| 6128 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6129 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6130 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6131 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6132 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6133 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
| 6134 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6135 | |
| 6136 | if (CHIP_IS_E1(bp)) { |
| 6137 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6138 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6139 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6140 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6141 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6142 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6143 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6144 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6145 | /* init aeu_mask_attn_func_0/1: |
| 6146 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use |
| 6147 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF |
| 6148 | * bits 4-7 are used for "per vn group attention" */ |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 6149 | val = IS_MF(bp) ? 0xF7 : 0x7; |
| 6150 | /* Enable DCBX attention for all but E1 */ |
| 6151 | val |= CHIP_IS_E1(bp) ? 0 : 0x10; |
| 6152 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6153 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6154 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6155 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6156 | if (!CHIP_IS_E1x(bp)) { |
| 6157 | /* Bit-map indicating which L2 hdrs may appear after the |
| 6158 | * basic Ethernet header |
| 6159 | */ |
| 6160 | REG_WR(bp, BP_PORT(bp) ? |
| 6161 | NIG_REG_P1_HDRS_AFTER_BASIC : |
| 6162 | NIG_REG_P0_HDRS_AFTER_BASIC, |
| 6163 | IS_MF_SD(bp) ? 7 : 6); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6164 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6165 | if (CHIP_IS_E3(bp)) |
| 6166 | REG_WR(bp, BP_PORT(bp) ? |
| 6167 | NIG_REG_LLH1_MF_MODE : |
| 6168 | NIG_REG_LLH_MF_MODE, IS_MF(bp)); |
| 6169 | } |
| 6170 | if (!CHIP_IS_E3(bp)) |
| 6171 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6172 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6173 | if (!CHIP_IS_E1(bp)) { |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6174 | /* 0x2 disable mf_ov, 0x1 enable */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6175 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6176 | (IS_MF_SD(bp) ? 0x1 : 0x2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6177 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6178 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6179 | val = 0; |
| 6180 | switch (bp->mf_mode) { |
| 6181 | case MULTI_FUNCTION_SD: |
| 6182 | val = 1; |
| 6183 | break; |
| 6184 | case MULTI_FUNCTION_SI: |
| 6185 | val = 2; |
| 6186 | break; |
| 6187 | } |
| 6188 | |
| 6189 | REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE : |
| 6190 | NIG_REG_LLH0_CLS_TYPE), val); |
| 6191 | } |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6192 | { |
| 6193 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); |
| 6194 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); |
| 6195 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); |
| 6196 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6199 | |
| 6200 | /* If SPIO5 is set to generate interrupts, enable it for this port */ |
| 6201 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 6202 | if (val & (1 << MISC_REGISTERS_SPIO_5)) { |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6203 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 6204 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 6205 | val = REG_RD(bp, reg_addr); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6206 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6207 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6208 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6209 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6210 | return 0; |
| 6211 | } |
| 6212 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6213 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
| 6214 | { |
| 6215 | int reg; |
| 6216 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6217 | if (CHIP_IS_E1(bp)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6218 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6219 | else |
| 6220 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6221 | |
| 6222 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); |
| 6223 | } |
| 6224 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6225 | static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id) |
| 6226 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6227 | 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] | 6228 | } |
| 6229 | |
| 6230 | static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func) |
| 6231 | { |
| 6232 | u32 i, base = FUNC_ILT_BASE(func); |
| 6233 | for (i = base; i < base + ILT_PER_FUNC; i++) |
| 6234 | bnx2x_ilt_wr(bp, i, 0); |
| 6235 | } |
| 6236 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6237 | static int bnx2x_init_hw_func(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6238 | { |
| 6239 | int port = BP_PORT(bp); |
| 6240 | int func = BP_FUNC(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6241 | int init_phase = PHASE_PF0 + func; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6242 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
| 6243 | u16 cdu_ilt_start; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6244 | u32 addr, val; |
Vladislav Zolotarov | f4a6689 | 2010-10-19 05:13:09 +0000 | [diff] [blame] | 6245 | u32 main_mem_base, main_mem_size, main_mem_prty_clr; |
| 6246 | int i, main_mem_width; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6247 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 6248 | DP(BNX2X_MSG_MCP, "starting func init func %d\n", func); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6249 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6250 | /* FLR cleanup - hmmm */ |
| 6251 | if (!CHIP_IS_E1x(bp)) |
| 6252 | bnx2x_pf_flr_clnup(bp); |
| 6253 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6254 | /* set MSI reconfigure capability */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6255 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 6256 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); |
| 6257 | val = REG_RD(bp, addr); |
| 6258 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; |
| 6259 | REG_WR(bp, addr, val); |
| 6260 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6261 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6262 | bnx2x_init_block(bp, BLOCK_PXP, init_phase); |
| 6263 | bnx2x_init_block(bp, BLOCK_PXP2, init_phase); |
| 6264 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6265 | ilt = BP_ILT(bp); |
| 6266 | cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6267 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6268 | for (i = 0; i < L2_ILT_LINES(bp); i++) { |
| 6269 | ilt->lines[cdu_ilt_start + i].page = |
| 6270 | bp->context.vcxt + (ILT_PAGE_CIDS * i); |
| 6271 | ilt->lines[cdu_ilt_start + i].page_mapping = |
| 6272 | bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i); |
| 6273 | /* cdu ilt pages are allocated manually so there's no need to |
| 6274 | set the size */ |
| 6275 | } |
| 6276 | bnx2x_ilt_init_op(bp, INITOP_SET); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6277 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6278 | #ifdef BCM_CNIC |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6279 | 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] | 6280 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6281 | /* T1 hash bits value determines the T1 number of entries */ |
| 6282 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6283 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6284 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6285 | #ifndef BCM_CNIC |
| 6286 | /* set NIC mode */ |
| 6287 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 6288 | #endif /* BCM_CNIC */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6289 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6290 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6291 | u32 pf_conf = IGU_PF_CONF_FUNC_EN; |
| 6292 | |
| 6293 | /* Turn on a single ISR mode in IGU if driver is going to use |
| 6294 | * INT#x or MSI |
| 6295 | */ |
| 6296 | if (!(bp->flags & USING_MSIX_FLAG)) |
| 6297 | pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN; |
| 6298 | /* |
| 6299 | * Timers workaround bug: function init part. |
| 6300 | * Need to wait 20msec after initializing ILT, |
| 6301 | * needed to make sure there are no requests in |
| 6302 | * one of the PXP internal queues with "old" ILT addresses |
| 6303 | */ |
| 6304 | msleep(20); |
| 6305 | /* |
| 6306 | * Master enable - Due to WB DMAE writes performed before this |
| 6307 | * register is re-initialized as part of the regular function |
| 6308 | * init |
| 6309 | */ |
| 6310 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1); |
| 6311 | /* Enable the function in IGU */ |
| 6312 | REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf); |
| 6313 | } |
| 6314 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6315 | bp->dmae_ready = 1; |
| 6316 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6317 | bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6318 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6319 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6320 | REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func); |
| 6321 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6322 | bnx2x_init_block(bp, BLOCK_ATC, init_phase); |
| 6323 | bnx2x_init_block(bp, BLOCK_DMAE, init_phase); |
| 6324 | bnx2x_init_block(bp, BLOCK_NIG, init_phase); |
| 6325 | bnx2x_init_block(bp, BLOCK_SRC, init_phase); |
| 6326 | bnx2x_init_block(bp, BLOCK_MISC, init_phase); |
| 6327 | bnx2x_init_block(bp, BLOCK_TCM, init_phase); |
| 6328 | bnx2x_init_block(bp, BLOCK_UCM, init_phase); |
| 6329 | bnx2x_init_block(bp, BLOCK_CCM, init_phase); |
| 6330 | bnx2x_init_block(bp, BLOCK_XCM, init_phase); |
| 6331 | bnx2x_init_block(bp, BLOCK_TSEM, init_phase); |
| 6332 | bnx2x_init_block(bp, BLOCK_USEM, init_phase); |
| 6333 | bnx2x_init_block(bp, BLOCK_CSEM, init_phase); |
| 6334 | bnx2x_init_block(bp, BLOCK_XSEM, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6335 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6336 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6337 | REG_WR(bp, QM_REG_PF_EN, 1); |
| 6338 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6339 | if (!CHIP_IS_E1x(bp)) { |
| 6340 | REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6341 | REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6342 | REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6343 | REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func); |
| 6344 | } |
| 6345 | bnx2x_init_block(bp, BLOCK_QM, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6346 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6347 | bnx2x_init_block(bp, BLOCK_TM, init_phase); |
| 6348 | bnx2x_init_block(bp, BLOCK_DORQ, init_phase); |
| 6349 | bnx2x_init_block(bp, BLOCK_BRB1, init_phase); |
| 6350 | bnx2x_init_block(bp, BLOCK_PRS, init_phase); |
| 6351 | bnx2x_init_block(bp, BLOCK_TSDM, init_phase); |
| 6352 | bnx2x_init_block(bp, BLOCK_CSDM, init_phase); |
| 6353 | bnx2x_init_block(bp, BLOCK_USDM, init_phase); |
| 6354 | bnx2x_init_block(bp, BLOCK_XSDM, init_phase); |
| 6355 | bnx2x_init_block(bp, BLOCK_UPB, init_phase); |
| 6356 | bnx2x_init_block(bp, BLOCK_XPB, init_phase); |
| 6357 | bnx2x_init_block(bp, BLOCK_PBF, init_phase); |
| 6358 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6359 | REG_WR(bp, PBF_REG_DISABLE_PF, 0); |
| 6360 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6361 | bnx2x_init_block(bp, BLOCK_CDU, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6362 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6363 | bnx2x_init_block(bp, BLOCK_CFC, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6364 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6365 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6366 | REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1); |
| 6367 | |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6368 | if (IS_MF(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6369 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 6370 | 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] | 6371 | } |
| 6372 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6373 | bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6374 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6375 | /* HC init per function */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6376 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 6377 | if (CHIP_IS_E1H(bp)) { |
| 6378 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6379 | |
| 6380 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6381 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6382 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6383 | bnx2x_init_block(bp, BLOCK_HC, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6384 | |
| 6385 | } else { |
| 6386 | int num_segs, sb_idx, prod_offset; |
| 6387 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6388 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6389 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6390 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6391 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
| 6392 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); |
| 6393 | } |
| 6394 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6395 | bnx2x_init_block(bp, BLOCK_IGU, init_phase); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6396 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6397 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6398 | int dsb_idx = 0; |
| 6399 | /** |
| 6400 | * Producer memory: |
| 6401 | * E2 mode: address 0-135 match to the mapping memory; |
| 6402 | * 136 - PF0 default prod; 137 - PF1 default prod; |
| 6403 | * 138 - PF2 default prod; 139 - PF3 default prod; |
| 6404 | * 140 - PF0 attn prod; 141 - PF1 attn prod; |
| 6405 | * 142 - PF2 attn prod; 143 - PF3 attn prod; |
| 6406 | * 144-147 reserved. |
| 6407 | * |
| 6408 | * E1.5 mode - In backward compatible mode; |
| 6409 | * for non default SB; each even line in the memory |
| 6410 | * holds the U producer and each odd line hold |
| 6411 | * the C producer. The first 128 producers are for |
| 6412 | * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20 |
| 6413 | * producers are for the DSB for each PF. |
| 6414 | * Each PF has five segments: (the order inside each |
| 6415 | * segment is PF0; PF1; PF2; PF3) - 128-131 U prods; |
| 6416 | * 132-135 C prods; 136-139 X prods; 140-143 T prods; |
| 6417 | * 144-147 attn prods; |
| 6418 | */ |
| 6419 | /* non-default-status-blocks */ |
| 6420 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? |
| 6421 | IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS; |
| 6422 | for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) { |
| 6423 | prod_offset = (bp->igu_base_sb + sb_idx) * |
| 6424 | num_segs; |
| 6425 | |
| 6426 | for (i = 0; i < num_segs; i++) { |
| 6427 | addr = IGU_REG_PROD_CONS_MEMORY + |
| 6428 | (prod_offset + i) * 4; |
| 6429 | REG_WR(bp, addr, 0); |
| 6430 | } |
| 6431 | /* send consumer update with value 0 */ |
| 6432 | bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx, |
| 6433 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6434 | bnx2x_igu_clear_sb(bp, |
| 6435 | bp->igu_base_sb + sb_idx); |
| 6436 | } |
| 6437 | |
| 6438 | /* default-status-blocks */ |
| 6439 | num_segs = CHIP_INT_MODE_IS_BC(bp) ? |
| 6440 | IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS; |
| 6441 | |
| 6442 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 6443 | dsb_idx = BP_FUNC(bp); |
| 6444 | else |
| 6445 | dsb_idx = BP_E1HVN(bp); |
| 6446 | |
| 6447 | prod_offset = (CHIP_INT_MODE_IS_BC(bp) ? |
| 6448 | IGU_BC_BASE_DSB_PROD + dsb_idx : |
| 6449 | IGU_NORM_BASE_DSB_PROD + dsb_idx); |
| 6450 | |
| 6451 | for (i = 0; i < (num_segs * E1HVN_MAX); |
| 6452 | i += E1HVN_MAX) { |
| 6453 | addr = IGU_REG_PROD_CONS_MEMORY + |
| 6454 | (prod_offset + i)*4; |
| 6455 | REG_WR(bp, addr, 0); |
| 6456 | } |
| 6457 | /* send consumer update with 0 */ |
| 6458 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 6459 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6460 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6461 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6462 | CSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6463 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6464 | XSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6465 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6466 | TSTORM_ID, 0, IGU_INT_NOP, 1); |
| 6467 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6468 | ATTENTION_ID, 0, IGU_INT_NOP, 1); |
| 6469 | } else { |
| 6470 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6471 | USTORM_ID, 0, IGU_INT_NOP, 1); |
| 6472 | bnx2x_ack_sb(bp, bp->igu_dsb_id, |
| 6473 | ATTENTION_ID, 0, IGU_INT_NOP, 1); |
| 6474 | } |
| 6475 | bnx2x_igu_clear_sb(bp, bp->igu_dsb_id); |
| 6476 | |
| 6477 | /* !!! these should become driver const once |
| 6478 | rf-tool supports split-68 const */ |
| 6479 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); |
| 6480 | REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); |
| 6481 | REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); |
| 6482 | REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); |
| 6483 | REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); |
| 6484 | REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); |
| 6485 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6486 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6487 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6488 | /* Reset PCIE errors for debug */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6489 | REG_WR(bp, 0x2114, 0xffffffff); |
| 6490 | REG_WR(bp, 0x2120, 0xffffffff); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6491 | |
Vladislav Zolotarov | f4a6689 | 2010-10-19 05:13:09 +0000 | [diff] [blame] | 6492 | if (CHIP_IS_E1x(bp)) { |
| 6493 | main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/ |
| 6494 | main_mem_base = HC_REG_MAIN_MEMORY + |
| 6495 | BP_PORT(bp) * (main_mem_size * 4); |
| 6496 | main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR; |
| 6497 | main_mem_width = 8; |
| 6498 | |
| 6499 | val = REG_RD(bp, main_mem_prty_clr); |
| 6500 | if (val) |
| 6501 | DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC " |
| 6502 | "block during " |
| 6503 | "function init (0x%x)!\n", val); |
| 6504 | |
| 6505 | /* Clear "false" parity errors in MSI-X table */ |
| 6506 | for (i = main_mem_base; |
| 6507 | i < main_mem_base + main_mem_size * 4; |
| 6508 | i += main_mem_width) { |
| 6509 | bnx2x_read_dmae(bp, i, main_mem_width / 4); |
| 6510 | bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), |
| 6511 | i, main_mem_width / 4); |
| 6512 | } |
| 6513 | /* Clear HC parity attention */ |
| 6514 | REG_RD(bp, main_mem_prty_clr); |
| 6515 | } |
| 6516 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6517 | #ifdef BNX2X_STOP_ON_ERROR |
| 6518 | /* Enable STORMs SP logging */ |
| 6519 | REG_WR8(bp, BAR_USTRORM_INTMEM + |
| 6520 | USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6521 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
| 6522 | TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6523 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 6524 | CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6525 | REG_WR8(bp, BAR_XSTRORM_INTMEM + |
| 6526 | XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1); |
| 6527 | #endif |
| 6528 | |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 6529 | bnx2x_phy_probe(&bp->link_params); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6530 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6531 | return 0; |
| 6532 | } |
| 6533 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6534 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 6535 | void bnx2x_free_mem(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6536 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6537 | /* fastpath */ |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 6538 | bnx2x_free_fp_mem(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6539 | /* end of fastpath */ |
| 6540 | |
| 6541 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6542 | sizeof(struct host_sp_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6543 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6544 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
| 6545 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6546 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6547 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6548 | sizeof(struct bnx2x_slowpath)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6549 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6550 | BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping, |
| 6551 | bp->context.size); |
| 6552 | |
| 6553 | bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE); |
| 6554 | |
| 6555 | BNX2X_FREE(bp->ilt->lines); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6556 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 6557 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6558 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6559 | BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping, |
| 6560 | sizeof(struct host_hc_status_block_e2)); |
| 6561 | else |
| 6562 | BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping, |
| 6563 | sizeof(struct host_hc_status_block_e1x)); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6564 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6565 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6566 | #endif |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6567 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6568 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6569 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6570 | BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping, |
| 6571 | BCM_PAGE_SIZE * NUM_EQ_PAGES); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6572 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6573 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6574 | static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp) |
| 6575 | { |
| 6576 | int num_groups; |
| 6577 | |
| 6578 | /* number of eth_queues */ |
| 6579 | u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp); |
| 6580 | |
| 6581 | /* Total number of FW statistics requests = |
| 6582 | * 1 for port stats + 1 for PF stats + num_eth_queues */ |
| 6583 | bp->fw_stats_num = 2 + num_queue_stats; |
| 6584 | |
| 6585 | |
| 6586 | /* Request is built from stats_query_header and an array of |
| 6587 | * stats_query_cmd_group each of which contains |
| 6588 | * STATS_QUERY_CMD_COUNT rules. The real number or requests is |
| 6589 | * configured in the stats_query_header. |
| 6590 | */ |
| 6591 | num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT + |
| 6592 | (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0); |
| 6593 | |
| 6594 | bp->fw_stats_req_sz = sizeof(struct stats_query_header) + |
| 6595 | num_groups * sizeof(struct stats_query_cmd_group); |
| 6596 | |
| 6597 | /* Data for statistics requests + stats_conter |
| 6598 | * |
| 6599 | * stats_counter holds per-STORM counters that are incremented |
| 6600 | * when STORM has finished with the current request. |
| 6601 | */ |
| 6602 | bp->fw_stats_data_sz = sizeof(struct per_port_stats) + |
| 6603 | sizeof(struct per_pf_stats) + |
| 6604 | sizeof(struct per_queue_stats) * num_queue_stats + |
| 6605 | sizeof(struct stats_counter); |
| 6606 | |
| 6607 | BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping, |
| 6608 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6609 | |
| 6610 | /* Set shortcuts */ |
| 6611 | bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats; |
| 6612 | bp->fw_stats_req_mapping = bp->fw_stats_mapping; |
| 6613 | |
| 6614 | bp->fw_stats_data = (struct bnx2x_fw_stats_data *) |
| 6615 | ((u8 *)bp->fw_stats + bp->fw_stats_req_sz); |
| 6616 | |
| 6617 | bp->fw_stats_data_mapping = bp->fw_stats_mapping + |
| 6618 | bp->fw_stats_req_sz; |
| 6619 | return 0; |
| 6620 | |
| 6621 | alloc_mem_err: |
| 6622 | BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping, |
| 6623 | bp->fw_stats_data_sz + bp->fw_stats_req_sz); |
| 6624 | return -ENOMEM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6625 | } |
| 6626 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6627 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 6628 | int bnx2x_alloc_mem(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6629 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6630 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6631 | if (!CHIP_IS_E1x(bp)) |
| 6632 | /* size = the status block + ramrod buffers */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 6633 | BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping, |
| 6634 | sizeof(struct host_hc_status_block_e2)); |
| 6635 | else |
| 6636 | BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping, |
| 6637 | sizeof(struct host_hc_status_block_e1x)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6638 | |
| 6639 | /* allocate searcher T2 table */ |
| 6640 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ); |
| 6641 | #endif |
| 6642 | |
| 6643 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6644 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6645 | sizeof(struct host_sp_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6646 | |
| 6647 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
| 6648 | sizeof(struct bnx2x_slowpath)); |
| 6649 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6650 | /* Allocated memory for FW statistics */ |
| 6651 | if (bnx2x_alloc_fw_stats_mem(bp)) |
| 6652 | goto alloc_mem_err; |
| 6653 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6654 | bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6655 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6656 | BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping, |
| 6657 | bp->context.size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6658 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6659 | BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6660 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6661 | if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC)) |
| 6662 | goto alloc_mem_err; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6663 | |
| 6664 | /* Slow path ring */ |
| 6665 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); |
| 6666 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6667 | /* EQ */ |
| 6668 | BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping, |
| 6669 | BCM_PAGE_SIZE * NUM_EQ_PAGES); |
Tom Herbert | ab532cf | 2011-02-16 10:27:02 +0000 | [diff] [blame] | 6670 | |
Dmitry Kravkov | b3b83c3 | 2011-05-04 23:50:33 +0000 | [diff] [blame] | 6671 | |
| 6672 | /* fastpath */ |
| 6673 | /* need to be done at the end, since it's self adjusting to amount |
| 6674 | * of memory available for RSS queues |
| 6675 | */ |
| 6676 | if (bnx2x_alloc_fp_mem(bp)) |
| 6677 | goto alloc_mem_err; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6678 | return 0; |
| 6679 | |
| 6680 | alloc_mem_err: |
| 6681 | bnx2x_free_mem(bp); |
| 6682 | return -ENOMEM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6685 | /* |
| 6686 | * Init service functions |
| 6687 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6688 | |
| 6689 | int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac, |
| 6690 | struct bnx2x_vlan_mac_obj *obj, bool set, |
| 6691 | int mac_type, unsigned long *ramrod_flags) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6692 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6693 | int rc; |
| 6694 | struct bnx2x_vlan_mac_ramrod_params ramrod_param; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6695 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6696 | memset(&ramrod_param, 0, sizeof(ramrod_param)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6697 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6698 | /* Fill general parameters */ |
| 6699 | ramrod_param.vlan_mac_obj = obj; |
| 6700 | ramrod_param.ramrod_flags = *ramrod_flags; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6701 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6702 | /* Fill a user request section if needed */ |
| 6703 | if (!test_bit(RAMROD_CONT, ramrod_flags)) { |
| 6704 | memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6705 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6706 | __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6707 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6708 | /* Set the command: ADD or DEL */ |
| 6709 | if (set) |
| 6710 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD; |
| 6711 | else |
| 6712 | ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6713 | } |
| 6714 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6715 | rc = bnx2x_config_vlan_mac(bp, &ramrod_param); |
| 6716 | if (rc < 0) |
| 6717 | BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del")); |
| 6718 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6719 | } |
| 6720 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6721 | int bnx2x_del_all_macs(struct bnx2x *bp, |
| 6722 | struct bnx2x_vlan_mac_obj *mac_obj, |
| 6723 | int mac_type, bool wait_for_comp) |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6724 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6725 | int rc; |
| 6726 | unsigned long ramrod_flags = 0, vlan_mac_flags = 0; |
| 6727 | |
| 6728 | /* Wait for completion of requested */ |
| 6729 | if (wait_for_comp) |
| 6730 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 6731 | |
| 6732 | /* Set the mac type of addresses we want to clear */ |
| 6733 | __set_bit(mac_type, &vlan_mac_flags); |
| 6734 | |
| 6735 | rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags); |
| 6736 | if (rc < 0) |
| 6737 | BNX2X_ERR("Failed to delete MACs: %d\n", rc); |
| 6738 | |
| 6739 | return rc; |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6740 | } |
| 6741 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6742 | int bnx2x_set_eth_mac(struct bnx2x *bp, bool set) |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6743 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6744 | unsigned long ramrod_flags = 0; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6745 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6746 | DP(NETIF_MSG_IFUP, "Adding Eth MAC\n"); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6747 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6748 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 6749 | /* Eth MAC is set on RSS leading client (fp[0]) */ |
| 6750 | return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set, |
| 6751 | BNX2X_ETH_MAC, &ramrod_flags); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 6752 | } |
| 6753 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6754 | int bnx2x_setup_leading(struct bnx2x *bp) |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 6755 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6756 | return bnx2x_setup_queue(bp, &bp->fp[0], 1); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6757 | } |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 6758 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6759 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 6760 | * bnx2x_set_int_mode - configure interrupt mode |
| 6761 | * |
| 6762 | * @bp: driver handle |
| 6763 | * |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6764 | * 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] | 6765 | */ |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6766 | static void __devinit bnx2x_set_int_mode(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6767 | { |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6768 | switch (int_mode) { |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6769 | case INT_MODE_MSI: |
| 6770 | bnx2x_enable_msi(bp); |
| 6771 | /* falling through... */ |
| 6772 | case INT_MODE_INTx: |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6773 | bp->num_queues = 1 + NONE_ETH_CONTEXT_USE; |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6774 | DP(NETIF_MSG_IFUP, "set number of queues to 1\n"); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6775 | break; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6776 | default: |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6777 | /* Set number of queues according to bp->multi_mode value */ |
| 6778 | bnx2x_set_num_queues(bp); |
| 6779 | |
| 6780 | DP(NETIF_MSG_IFUP, "set number of queues to %d\n", |
| 6781 | bp->num_queues); |
| 6782 | |
| 6783 | /* if we can't use MSI-X we only need one fp, |
| 6784 | * so try to enable MSI-X with the requested number of fp's |
| 6785 | * and fallback to MSI or legacy INTx with one fp |
| 6786 | */ |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6787 | if (bnx2x_enable_msix(bp)) { |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6788 | /* failed to enable MSI-X */ |
| 6789 | if (bp->multi_mode) |
| 6790 | DP(NETIF_MSG_IFUP, |
| 6791 | "Multi requested but failed to " |
| 6792 | "enable MSI-X (%d), " |
| 6793 | "set number of queues to %d\n", |
| 6794 | bp->num_queues, |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6795 | 1 + NONE_ETH_CONTEXT_USE); |
| 6796 | bp->num_queues = 1 + NONE_ETH_CONTEXT_USE; |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6797 | |
Dmitry Kravkov | 9ee3d37 | 2011-06-14 01:33:34 +0000 | [diff] [blame] | 6798 | /* Try to enable MSI */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 6799 | if (!(bp->flags & DISABLE_MSI_FLAG)) |
| 6800 | bnx2x_enable_msi(bp); |
| 6801 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6802 | break; |
| 6803 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6804 | } |
| 6805 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 6806 | /* must be called prioir to any HW initializations */ |
| 6807 | static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp) |
| 6808 | { |
| 6809 | return L2_ILT_LINES(bp); |
| 6810 | } |
| 6811 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6812 | void bnx2x_ilt_set_info(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6813 | { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6814 | struct ilt_client_info *ilt_client; |
| 6815 | struct bnx2x_ilt *ilt = BP_ILT(bp); |
| 6816 | u16 line = 0; |
| 6817 | |
| 6818 | ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp)); |
| 6819 | DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line); |
| 6820 | |
| 6821 | /* CDU */ |
| 6822 | ilt_client = &ilt->clients[ILT_CLIENT_CDU]; |
| 6823 | ilt_client->client_num = ILT_CLIENT_CDU; |
| 6824 | ilt_client->page_size = CDU_ILT_PAGE_SZ; |
| 6825 | ilt_client->flags = ILT_CLIENT_SKIP_MEM; |
| 6826 | ilt_client->start = line; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6827 | line += bnx2x_cid_ilt_lines(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6828 | #ifdef BCM_CNIC |
| 6829 | line += CNIC_ILT_LINES; |
| 6830 | #endif |
| 6831 | ilt_client->end = line - 1; |
| 6832 | |
| 6833 | DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, " |
| 6834 | "flags 0x%x, hw psz %d\n", |
| 6835 | ilt_client->start, |
| 6836 | ilt_client->end, |
| 6837 | ilt_client->page_size, |
| 6838 | ilt_client->flags, |
| 6839 | ilog2(ilt_client->page_size >> 12)); |
| 6840 | |
| 6841 | /* QM */ |
| 6842 | if (QM_INIT(bp->qm_cid_count)) { |
| 6843 | ilt_client = &ilt->clients[ILT_CLIENT_QM]; |
| 6844 | ilt_client->client_num = ILT_CLIENT_QM; |
| 6845 | ilt_client->page_size = QM_ILT_PAGE_SZ; |
| 6846 | ilt_client->flags = 0; |
| 6847 | ilt_client->start = line; |
| 6848 | |
| 6849 | /* 4 bytes for each cid */ |
| 6850 | line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4, |
| 6851 | QM_ILT_PAGE_SZ); |
| 6852 | |
| 6853 | ilt_client->end = line - 1; |
| 6854 | |
| 6855 | DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, " |
| 6856 | "flags 0x%x, hw psz %d\n", |
| 6857 | ilt_client->start, |
| 6858 | ilt_client->end, |
| 6859 | ilt_client->page_size, |
| 6860 | ilt_client->flags, |
| 6861 | ilog2(ilt_client->page_size >> 12)); |
| 6862 | |
| 6863 | } |
| 6864 | /* SRC */ |
| 6865 | ilt_client = &ilt->clients[ILT_CLIENT_SRC]; |
| 6866 | #ifdef BCM_CNIC |
| 6867 | ilt_client->client_num = ILT_CLIENT_SRC; |
| 6868 | ilt_client->page_size = SRC_ILT_PAGE_SZ; |
| 6869 | ilt_client->flags = 0; |
| 6870 | ilt_client->start = line; |
| 6871 | line += SRC_ILT_LINES; |
| 6872 | ilt_client->end = line - 1; |
| 6873 | |
| 6874 | DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, " |
| 6875 | "flags 0x%x, hw psz %d\n", |
| 6876 | ilt_client->start, |
| 6877 | ilt_client->end, |
| 6878 | ilt_client->page_size, |
| 6879 | ilt_client->flags, |
| 6880 | ilog2(ilt_client->page_size >> 12)); |
| 6881 | |
| 6882 | #else |
| 6883 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); |
| 6884 | #endif |
| 6885 | |
| 6886 | /* TM */ |
| 6887 | ilt_client = &ilt->clients[ILT_CLIENT_TM]; |
| 6888 | #ifdef BCM_CNIC |
| 6889 | ilt_client->client_num = ILT_CLIENT_TM; |
| 6890 | ilt_client->page_size = TM_ILT_PAGE_SZ; |
| 6891 | ilt_client->flags = 0; |
| 6892 | ilt_client->start = line; |
| 6893 | line += TM_ILT_LINES; |
| 6894 | ilt_client->end = line - 1; |
| 6895 | |
| 6896 | DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, " |
| 6897 | "flags 0x%x, hw psz %d\n", |
| 6898 | ilt_client->start, |
| 6899 | ilt_client->end, |
| 6900 | ilt_client->page_size, |
| 6901 | ilt_client->flags, |
| 6902 | ilog2(ilt_client->page_size >> 12)); |
| 6903 | |
| 6904 | #else |
| 6905 | ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM); |
| 6906 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6907 | BUG_ON(line > ILT_MAX_LINES); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6908 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 6909 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6910 | /** |
| 6911 | * bnx2x_pf_q_prep_init - prepare INIT transition parameters |
| 6912 | * |
| 6913 | * @bp: driver handle |
| 6914 | * @fp: pointer to fastpath |
| 6915 | * @init_params: pointer to parameters structure |
| 6916 | * |
| 6917 | * parameters configured: |
| 6918 | * - HC configuration |
| 6919 | * - Queue's CDU context |
| 6920 | */ |
| 6921 | static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp, |
| 6922 | struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6923 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6924 | /* FCoE Queue uses Default SB, thus has no HC capabilities */ |
| 6925 | if (!IS_FCOE_FP(fp)) { |
| 6926 | __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags); |
| 6927 | __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags); |
| 6928 | |
| 6929 | /* If HC is supporterd, enable host coalescing in the transition |
| 6930 | * to INIT state. |
| 6931 | */ |
| 6932 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags); |
| 6933 | __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags); |
| 6934 | |
| 6935 | /* HC rate */ |
| 6936 | init_params->rx.hc_rate = bp->rx_ticks ? |
| 6937 | (1000000 / bp->rx_ticks) : 0; |
| 6938 | init_params->tx.hc_rate = bp->tx_ticks ? |
| 6939 | (1000000 / bp->tx_ticks) : 0; |
| 6940 | |
| 6941 | /* FW SB ID */ |
| 6942 | init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = |
| 6943 | fp->fw_sb_id; |
| 6944 | |
| 6945 | /* |
| 6946 | * CQ index among the SB indices: FCoE clients uses the default |
| 6947 | * SB, therefore it's different. |
| 6948 | */ |
| 6949 | init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX; |
| 6950 | init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX; |
| 6951 | } |
| 6952 | |
| 6953 | init_params->cxt = &bp->context.vcxt[fp->cid].eth; |
| 6954 | } |
| 6955 | |
| 6956 | /** |
| 6957 | * bnx2x_setup_queue - setup queue |
| 6958 | * |
| 6959 | * @bp: driver handle |
| 6960 | * @fp: pointer to fastpath |
| 6961 | * @leading: is leading |
| 6962 | * |
| 6963 | * This function performs 2 steps in a Queue state machine |
| 6964 | * actually: 1) RESET->INIT 2) INIT->SETUP |
| 6965 | */ |
| 6966 | |
| 6967 | int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 6968 | bool leading) |
| 6969 | { |
| 6970 | struct bnx2x_queue_state_params q_params = {0}; |
| 6971 | struct bnx2x_queue_setup_params *setup_params = |
| 6972 | &q_params.params.setup; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6973 | int rc; |
| 6974 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6975 | /* reset IGU state skip FCoE L2 queue */ |
| 6976 | if (!IS_FCOE_FP(fp)) |
| 6977 | bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6978 | IGU_INT_ENABLE, 0); |
| 6979 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6980 | q_params.q_obj = &fp->q_obj; |
| 6981 | /* We want to wait for completion in this context */ |
| 6982 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6983 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6984 | /* Prepare the INIT parameters */ |
| 6985 | bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6986 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6987 | /* Set the command */ |
| 6988 | q_params.cmd = BNX2X_Q_CMD_INIT; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 6989 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6990 | /* Change the state to INIT */ |
| 6991 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 6992 | if (rc) { |
| 6993 | BNX2X_ERR("Queue INIT failed\n"); |
| 6994 | return rc; |
| 6995 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6996 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 6997 | /* Now move the Queue to the SETUP state... */ |
| 6998 | memset(setup_params, 0, sizeof(*setup_params)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 6999 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7000 | /* Set QUEUE flags */ |
| 7001 | setup_params->flags = bnx2x_get_q_flags(bp, fp, leading); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7002 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7003 | /* Set general SETUP parameters */ |
| 7004 | bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params); |
| 7005 | |
| 7006 | bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause, |
| 7007 | &setup_params->rxq_params); |
| 7008 | |
| 7009 | bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params); |
| 7010 | |
| 7011 | /* Set the command */ |
| 7012 | q_params.cmd = BNX2X_Q_CMD_SETUP; |
| 7013 | |
| 7014 | /* Change the state to SETUP */ |
| 7015 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7016 | if (rc) |
| 7017 | BNX2X_ERR("Queue SETUP failed\n"); |
| 7018 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7019 | return rc; |
| 7020 | } |
| 7021 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7022 | static int bnx2x_stop_queue(struct bnx2x *bp, int index) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7023 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7024 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
| 7025 | struct bnx2x_queue_state_params q_params = {0}; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7026 | int rc; |
| 7027 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7028 | q_params.q_obj = &fp->q_obj; |
| 7029 | /* We want to wait for completion in this context */ |
| 7030 | __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7031 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7032 | /* halt the connection */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7033 | q_params.cmd = BNX2X_Q_CMD_HALT; |
| 7034 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7035 | if (rc) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7036 | return rc; |
| 7037 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7038 | /* terminate the connection */ |
| 7039 | q_params.cmd = BNX2X_Q_CMD_TERMINATE; |
| 7040 | rc = bnx2x_queue_state_change(bp, &q_params); |
| 7041 | if (rc) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7042 | return rc; |
| 7043 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7044 | /* delete cfc entry */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7045 | q_params.cmd = BNX2X_Q_CMD_CFC_DEL; |
| 7046 | return bnx2x_queue_state_change(bp, &q_params); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7047 | } |
| 7048 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7049 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7050 | static void bnx2x_reset_func(struct bnx2x *bp) |
| 7051 | { |
| 7052 | int port = BP_PORT(bp); |
| 7053 | int func = BP_FUNC(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7054 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7055 | |
| 7056 | /* Disable the function in the FW */ |
| 7057 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0); |
| 7058 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0); |
| 7059 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0); |
| 7060 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0); |
| 7061 | |
| 7062 | /* FP SBs */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7063 | for_each_eth_queue(bp, i) { |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7064 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7065 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7066 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id), |
| 7067 | SB_DISABLED); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7068 | } |
| 7069 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7070 | #ifdef BCM_CNIC |
| 7071 | /* CNIC SB */ |
| 7072 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7073 | CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)), |
| 7074 | SB_DISABLED); |
| 7075 | #endif |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7076 | /* SP SB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7077 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 7078 | CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), |
| 7079 | SB_DISABLED); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7080 | |
| 7081 | for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) |
| 7082 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func), |
| 7083 | 0); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7084 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7085 | /* Configure IGU */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7086 | if (bp->common.int_block == INT_BLOCK_HC) { |
| 7087 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 7088 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 7089 | } else { |
| 7090 | REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0); |
| 7091 | REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0); |
| 7092 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7093 | |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 7094 | #ifdef BCM_CNIC |
| 7095 | /* Disable Timer scan */ |
| 7096 | REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0); |
| 7097 | /* |
| 7098 | * Wait for at least 10ms and up to 2 second for the timers scan to |
| 7099 | * complete |
| 7100 | */ |
| 7101 | for (i = 0; i < 200; i++) { |
| 7102 | msleep(10); |
| 7103 | if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4)) |
| 7104 | break; |
| 7105 | } |
| 7106 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7107 | /* Clear ILT */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7108 | bnx2x_clear_func_ilt(bp, func); |
| 7109 | |
| 7110 | /* Timers workaround bug for E2: if this is vnic-3, |
| 7111 | * we need to set the entire ilt range for this timers. |
| 7112 | */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7113 | if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7114 | struct ilt_client_info ilt_cli; |
| 7115 | /* use dummy TM client */ |
| 7116 | memset(&ilt_cli, 0, sizeof(struct ilt_client_info)); |
| 7117 | ilt_cli.start = 0; |
| 7118 | ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1; |
| 7119 | ilt_cli.client_num = ILT_CLIENT_TM; |
| 7120 | |
| 7121 | bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR); |
| 7122 | } |
| 7123 | |
| 7124 | /* this assumes that reset_port() called before reset_func()*/ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7125 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7126 | bnx2x_pf_disable(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7127 | |
| 7128 | bp->dmae_ready = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | static void bnx2x_reset_port(struct bnx2x *bp) |
| 7132 | { |
| 7133 | int port = BP_PORT(bp); |
| 7134 | u32 val; |
| 7135 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7136 | /* Reset physical Link */ |
| 7137 | bnx2x__link_reset(bp); |
| 7138 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7139 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
| 7140 | |
| 7141 | /* Do not rcv packets to BRB */ |
| 7142 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); |
| 7143 | /* Do not direct rcv packets that are not for MCP to the BRB */ |
| 7144 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7145 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7146 | |
| 7147 | /* Configure AEU */ |
| 7148 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); |
| 7149 | |
| 7150 | msleep(100); |
| 7151 | /* Check for BRB port occupancy */ |
| 7152 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); |
| 7153 | if (val) |
| 7154 | DP(NETIF_MSG_IFDOWN, |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7155 | "BRB1 is not empty %d blocks are occupied\n", val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7156 | |
| 7157 | /* TODO: Close Doorbell port? */ |
| 7158 | } |
| 7159 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7160 | static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7161 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7162 | struct bnx2x_func_state_params func_params = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7163 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7164 | /* Prepare parameters for function state transitions */ |
| 7165 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7166 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7167 | func_params.f_obj = &bp->func_obj; |
| 7168 | func_params.cmd = BNX2X_F_CMD_HW_RESET; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7169 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7170 | func_params.params.hw_init.load_phase = load_code; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7171 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7172 | return bnx2x_func_state_change(bp, &func_params); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7173 | } |
| 7174 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7175 | static inline int bnx2x_func_stop(struct bnx2x *bp) |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7176 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7177 | struct bnx2x_func_state_params func_params = {0}; |
| 7178 | int rc; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7179 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7180 | /* Prepare parameters for function state transitions */ |
| 7181 | __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags); |
| 7182 | func_params.f_obj = &bp->func_obj; |
| 7183 | func_params.cmd = BNX2X_F_CMD_STOP; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 7184 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7185 | /* |
| 7186 | * Try to stop the function the 'good way'. If fails (in case |
| 7187 | * of a parity error during bnx2x_chip_cleanup()) and we are |
| 7188 | * not in a debug mode, perform a state transaction in order to |
| 7189 | * enable further HW_RESET transaction. |
| 7190 | */ |
| 7191 | rc = bnx2x_func_state_change(bp, &func_params); |
| 7192 | if (rc) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7193 | #ifdef BNX2X_STOP_ON_ERROR |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7194 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7195 | #else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7196 | BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry " |
| 7197 | "transaction\n"); |
| 7198 | __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags); |
| 7199 | return bnx2x_func_state_change(bp, &func_params); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7200 | #endif |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7201 | } |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7202 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7203 | return 0; |
| 7204 | } |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7205 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7206 | /** |
| 7207 | * bnx2x_send_unload_req - request unload mode from the MCP. |
| 7208 | * |
| 7209 | * @bp: driver handle |
| 7210 | * @unload_mode: requested function's unload mode |
| 7211 | * |
| 7212 | * Return unload mode returned by the MCP: COMMON, PORT or FUNC. |
| 7213 | */ |
| 7214 | u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode) |
| 7215 | { |
| 7216 | u32 reset_code = 0; |
| 7217 | int port = BP_PORT(bp); |
| 7218 | |
| 7219 | /* Select the UNLOAD request mode */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7220 | if (unload_mode == UNLOAD_NORMAL) |
| 7221 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7222 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7223 | else if (bp->flags & NO_WOL_FLAG) |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7224 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7225 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7226 | else if (bp->wol) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7227 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7228 | u8 *mac_addr = bp->dev->dev_addr; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7229 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7230 | /* The mac address is written to entries 1-4 to |
| 7231 | preserve entry 0 which is used by the PMF */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7232 | u8 entry = (BP_E1HVN(bp) + 1)*8; |
| 7233 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7234 | val = (mac_addr[0] << 8) | mac_addr[1]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7235 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7236 | |
| 7237 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 7238 | (mac_addr[4] << 8) | mac_addr[5]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7239 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7240 | |
| 7241 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7242 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7243 | } else |
| 7244 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
| 7245 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7246 | /* Send the request to the MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7247 | if (!BP_NOMCP(bp)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 7248 | reset_code = bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7249 | else { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7250 | int path = BP_PATH(bp); |
| 7251 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7252 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7253 | "%d, %d, %d\n", |
| 7254 | path, load_count[path][0], load_count[path][1], |
| 7255 | load_count[path][2]); |
| 7256 | load_count[path][0]--; |
| 7257 | load_count[path][1 + port]--; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 7258 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] " |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7259 | "%d, %d, %d\n", |
| 7260 | path, load_count[path][0], load_count[path][1], |
| 7261 | load_count[path][2]); |
| 7262 | if (load_count[path][0] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7263 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7264 | else if (load_count[path][1 + port] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7265 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; |
| 7266 | else |
| 7267 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; |
| 7268 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7269 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7270 | return reset_code; |
| 7271 | } |
| 7272 | |
| 7273 | /** |
| 7274 | * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP. |
| 7275 | * |
| 7276 | * @bp: driver handle |
| 7277 | */ |
| 7278 | void bnx2x_send_unload_done(struct bnx2x *bp) |
| 7279 | { |
| 7280 | /* Report UNLOAD_DONE to MCP */ |
| 7281 | if (!BP_NOMCP(bp)) |
| 7282 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); |
| 7283 | } |
| 7284 | |
| 7285 | void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode) |
| 7286 | { |
| 7287 | int port = BP_PORT(bp); |
| 7288 | int i, rc; |
| 7289 | struct bnx2x_mcast_ramrod_params rparam = {0}; |
| 7290 | u32 reset_code; |
| 7291 | |
| 7292 | /* Wait until tx fastpath tasks complete */ |
| 7293 | for_each_tx_queue(bp, i) { |
| 7294 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 7295 | |
| 7296 | rc = bnx2x_clean_tx_queue(bp, fp); |
| 7297 | #ifdef BNX2X_STOP_ON_ERROR |
| 7298 | if (rc) |
| 7299 | return; |
| 7300 | #endif |
| 7301 | } |
| 7302 | |
| 7303 | /* Give HW time to discard old tx messages */ |
| 7304 | usleep_range(1000, 1000); |
| 7305 | |
| 7306 | /* Clean all ETH MACs */ |
| 7307 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false); |
| 7308 | if (rc < 0) |
| 7309 | BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc); |
| 7310 | |
| 7311 | /* Clean up UC list */ |
| 7312 | rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC, |
| 7313 | true); |
| 7314 | if (rc < 0) |
| 7315 | BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: " |
| 7316 | "%d\n", rc); |
| 7317 | |
| 7318 | /* Disable LLH */ |
| 7319 | if (!CHIP_IS_E1(bp)) |
| 7320 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 7321 | |
| 7322 | /* Set "drop all" (stop Rx). |
| 7323 | * We need to take a netif_addr_lock() here in order to prevent |
| 7324 | * a race between the completion code and this code. |
| 7325 | */ |
| 7326 | netif_addr_lock_bh(bp->dev); |
| 7327 | /* Schedule the rx_mode command */ |
| 7328 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) |
| 7329 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); |
| 7330 | else |
| 7331 | bnx2x_set_storm_rx_mode(bp); |
| 7332 | |
| 7333 | /* Cleanup multicast configuration */ |
| 7334 | rparam.mcast_obj = &bp->mcast_obj; |
| 7335 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); |
| 7336 | if (rc < 0) |
| 7337 | BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc); |
| 7338 | |
| 7339 | netif_addr_unlock_bh(bp->dev); |
| 7340 | |
| 7341 | |
| 7342 | /* Close multi and leading connections |
| 7343 | * Completions for ramrods are collected in a synchronous way |
| 7344 | */ |
| 7345 | for_each_queue(bp, i) |
| 7346 | if (bnx2x_stop_queue(bp, i)) |
| 7347 | #ifdef BNX2X_STOP_ON_ERROR |
| 7348 | return; |
| 7349 | #else |
| 7350 | goto unload_error; |
| 7351 | #endif |
| 7352 | /* If SP settings didn't get completed so far - something |
| 7353 | * very wrong has happen. |
| 7354 | */ |
| 7355 | if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) |
| 7356 | BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n"); |
| 7357 | |
| 7358 | #ifndef BNX2X_STOP_ON_ERROR |
| 7359 | unload_error: |
| 7360 | #endif |
| 7361 | rc = bnx2x_func_stop(bp); |
| 7362 | if (rc) { |
| 7363 | BNX2X_ERR("Function stop failed!\n"); |
| 7364 | #ifdef BNX2X_STOP_ON_ERROR |
| 7365 | return; |
| 7366 | #endif |
| 7367 | } |
| 7368 | |
| 7369 | /* |
| 7370 | * Send the UNLOAD_REQUEST to the MCP. This will return if |
| 7371 | * this function should perform FUNC, PORT or COMMON HW |
| 7372 | * reset. |
| 7373 | */ |
| 7374 | reset_code = bnx2x_send_unload_req(bp, unload_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7375 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7376 | /* Disable HW interrupts, NAPI */ |
| 7377 | bnx2x_netif_stop(bp, 1); |
| 7378 | |
| 7379 | /* Release IRQs */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 7380 | bnx2x_free_irq(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 7381 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7382 | /* Reset the chip */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7383 | rc = bnx2x_reset_hw(bp, reset_code); |
| 7384 | if (rc) |
| 7385 | BNX2X_ERR("HW_RESET failed\n"); |
| 7386 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7387 | |
| 7388 | /* Report UNLOAD_DONE to MCP */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7389 | bnx2x_send_unload_done(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 7392 | void bnx2x_disable_close_the_gate(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7393 | { |
| 7394 | u32 val; |
| 7395 | |
| 7396 | DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n"); |
| 7397 | |
| 7398 | if (CHIP_IS_E1(bp)) { |
| 7399 | int port = BP_PORT(bp); |
| 7400 | u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 7401 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 7402 | |
| 7403 | val = REG_RD(bp, addr); |
| 7404 | val &= ~(0x300); |
| 7405 | REG_WR(bp, addr, val); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 7406 | } else { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7407 | val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK); |
| 7408 | val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK | |
| 7409 | MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK); |
| 7410 | REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val); |
| 7411 | } |
| 7412 | } |
| 7413 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7414 | /* Close gates #2, #3 and #4: */ |
| 7415 | static void bnx2x_set_234_gates(struct bnx2x *bp, bool close) |
| 7416 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7417 | u32 val; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7418 | |
| 7419 | /* Gates #2 and #4a are closed/opened for "not E1" only */ |
| 7420 | if (!CHIP_IS_E1(bp)) { |
| 7421 | /* #4 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7422 | REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7423 | /* #2 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7424 | REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | /* #3 */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7428 | if (CHIP_IS_E1x(bp)) { |
| 7429 | /* Prevent interrupts from HC on both ports */ |
| 7430 | val = REG_RD(bp, HC_REG_CONFIG_1); |
| 7431 | REG_WR(bp, HC_REG_CONFIG_1, |
| 7432 | (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) : |
| 7433 | (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1)); |
| 7434 | |
| 7435 | val = REG_RD(bp, HC_REG_CONFIG_0); |
| 7436 | REG_WR(bp, HC_REG_CONFIG_0, |
| 7437 | (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) : |
| 7438 | (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0)); |
| 7439 | } else { |
| 7440 | /* Prevent incomming interrupts in IGU */ |
| 7441 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
| 7442 | |
| 7443 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, |
| 7444 | (!close) ? |
| 7445 | (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) : |
| 7446 | (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE)); |
| 7447 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7448 | |
| 7449 | DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n", |
| 7450 | close ? "closing" : "opening"); |
| 7451 | mmiowb(); |
| 7452 | } |
| 7453 | |
| 7454 | #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */ |
| 7455 | |
| 7456 | static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val) |
| 7457 | { |
| 7458 | /* Do some magic... */ |
| 7459 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
| 7460 | *magic_val = val & SHARED_MF_CLP_MAGIC; |
| 7461 | MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC); |
| 7462 | } |
| 7463 | |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7464 | /** |
| 7465 | * bnx2x_clp_reset_done - restore the value of the `magic' bit. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7466 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7467 | * @bp: driver handle |
| 7468 | * @magic_val: old value of the `magic' bit. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7469 | */ |
| 7470 | static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val) |
| 7471 | { |
| 7472 | /* Restore the `magic' bit value... */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7473 | u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb); |
| 7474 | MF_CFG_WR(bp, shared_mf_config.clp_mb, |
| 7475 | (val & (~SHARED_MF_CLP_MAGIC)) | magic_val); |
| 7476 | } |
| 7477 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 7478 | /** |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7479 | * bnx2x_reset_mcp_prep - prepare for MCP reset. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7480 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7481 | * @bp: driver handle |
| 7482 | * @magic_val: old value of 'magic' bit. |
| 7483 | * |
| 7484 | * Takes care of CLP configurations. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7485 | */ |
| 7486 | static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val) |
| 7487 | { |
| 7488 | u32 shmem; |
| 7489 | u32 validity_offset; |
| 7490 | |
| 7491 | DP(NETIF_MSG_HW, "Starting\n"); |
| 7492 | |
| 7493 | /* Set `magic' bit in order to save MF config */ |
| 7494 | if (!CHIP_IS_E1(bp)) |
| 7495 | bnx2x_clp_reset_prep(bp, magic_val); |
| 7496 | |
| 7497 | /* Get shmem offset */ |
| 7498 | shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7499 | validity_offset = offsetof(struct shmem_region, validity_map[0]); |
| 7500 | |
| 7501 | /* Clear validity map flags */ |
| 7502 | if (shmem > 0) |
| 7503 | REG_WR(bp, shmem + validity_offset, 0); |
| 7504 | } |
| 7505 | |
| 7506 | #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */ |
| 7507 | #define MCP_ONE_TIMEOUT 100 /* 100 ms */ |
| 7508 | |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7509 | /** |
| 7510 | * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7511 | * |
Dmitry Kravkov | e892067 | 2011-05-04 23:52:40 +0000 | [diff] [blame] | 7512 | * @bp: driver handle |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7513 | */ |
| 7514 | static inline void bnx2x_mcp_wait_one(struct bnx2x *bp) |
| 7515 | { |
| 7516 | /* special handling for emulation and FPGA, |
| 7517 | wait 10 times longer */ |
| 7518 | if (CHIP_REV_IS_SLOW(bp)) |
| 7519 | msleep(MCP_ONE_TIMEOUT*10); |
| 7520 | else |
| 7521 | msleep(MCP_ONE_TIMEOUT); |
| 7522 | } |
| 7523 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7524 | /* |
| 7525 | * initializes bp->common.shmem_base and waits for validity signature to appear |
| 7526 | */ |
| 7527 | static int bnx2x_init_shmem(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7528 | { |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7529 | int cnt = 0; |
| 7530 | u32 val = 0; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7531 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7532 | do { |
| 7533 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7534 | if (bp->common.shmem_base) { |
| 7535 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 7536 | if (val & SHR_MEM_VALIDITY_MB) |
| 7537 | return 0; |
| 7538 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7539 | |
| 7540 | bnx2x_mcp_wait_one(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7541 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7542 | } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7543 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7544 | BNX2X_ERR("BAD MCP validity signature\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7545 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 7546 | return -ENODEV; |
| 7547 | } |
| 7548 | |
| 7549 | static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val) |
| 7550 | { |
| 7551 | int rc = bnx2x_init_shmem(bp); |
| 7552 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7553 | /* Restore the `magic' bit value */ |
| 7554 | if (!CHIP_IS_E1(bp)) |
| 7555 | bnx2x_clp_reset_done(bp, magic_val); |
| 7556 | |
| 7557 | return rc; |
| 7558 | } |
| 7559 | |
| 7560 | static void bnx2x_pxp_prep(struct bnx2x *bp) |
| 7561 | { |
| 7562 | if (!CHIP_IS_E1(bp)) { |
| 7563 | REG_WR(bp, PXP2_REG_RD_START_INIT, 0); |
| 7564 | REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7565 | mmiowb(); |
| 7566 | } |
| 7567 | } |
| 7568 | |
| 7569 | /* |
| 7570 | * Reset the whole chip except for: |
| 7571 | * - PCIE core |
| 7572 | * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by |
| 7573 | * one reset bit) |
| 7574 | * - IGU |
| 7575 | * - MISC (including AEU) |
| 7576 | * - GRC |
| 7577 | * - RBCN, RBCP |
| 7578 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7579 | static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7580 | { |
| 7581 | u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7582 | u32 global_bits2; |
| 7583 | |
| 7584 | /* |
| 7585 | * Bits that have to be set in reset_mask2 if we want to reset 'global' |
| 7586 | * (per chip) blocks. |
| 7587 | */ |
| 7588 | global_bits2 = |
| 7589 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU | |
| 7590 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7591 | |
| 7592 | not_reset_mask1 = |
| 7593 | MISC_REGISTERS_RESET_REG_1_RST_HC | |
| 7594 | MISC_REGISTERS_RESET_REG_1_RST_PXPV | |
| 7595 | MISC_REGISTERS_RESET_REG_1_RST_PXP; |
| 7596 | |
| 7597 | not_reset_mask2 = |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7598 | MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7599 | MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE | |
| 7600 | MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE | |
| 7601 | MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE | |
| 7602 | MISC_REGISTERS_RESET_REG_2_RST_RBCN | |
| 7603 | MISC_REGISTERS_RESET_REG_2_RST_GRC | |
| 7604 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE | |
| 7605 | MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B; |
| 7606 | |
| 7607 | reset_mask1 = 0xffffffff; |
| 7608 | |
| 7609 | if (CHIP_IS_E1(bp)) |
| 7610 | reset_mask2 = 0xffff; |
| 7611 | else |
| 7612 | reset_mask2 = 0x1ffff; |
| 7613 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7614 | if (CHIP_IS_E3(bp)) { |
| 7615 | reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 7616 | reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 7617 | } |
| 7618 | |
| 7619 | /* Don't reset global blocks unless we need to */ |
| 7620 | if (!global) |
| 7621 | reset_mask2 &= ~global_bits2; |
| 7622 | |
| 7623 | /* |
| 7624 | * In case of attention in the QM, we need to reset PXP |
| 7625 | * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM |
| 7626 | * because otherwise QM reset would release 'close the gates' shortly |
| 7627 | * before resetting the PXP, then the PSWRQ would send a write |
| 7628 | * request to PGLUE. Then when PXP is reset, PGLUE would try to |
| 7629 | * read the payload data from PSWWR, but PSWWR would not |
| 7630 | * respond. The write queue in PGLUE would stuck, dmae commands |
| 7631 | * would not return. Therefore it's important to reset the second |
| 7632 | * reset register (containing the |
| 7633 | * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the |
| 7634 | * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM |
| 7635 | * bit). |
| 7636 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7637 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
| 7638 | reset_mask2 & (~not_reset_mask2)); |
| 7639 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7640 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 7641 | reset_mask1 & (~not_reset_mask1)); |
| 7642 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7643 | barrier(); |
| 7644 | mmiowb(); |
| 7645 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7646 | 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] | 7647 | 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] | 7648 | mmiowb(); |
| 7649 | } |
| 7650 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7651 | /** |
| 7652 | * bnx2x_er_poll_igu_vq - poll for pending writes bit. |
| 7653 | * It should get cleared in no more than 1s. |
| 7654 | * |
| 7655 | * @bp: driver handle |
| 7656 | * |
| 7657 | * It should get cleared in no more than 1s. Returns 0 if |
| 7658 | * pending writes bit gets cleared. |
| 7659 | */ |
| 7660 | static int bnx2x_er_poll_igu_vq(struct bnx2x *bp) |
| 7661 | { |
| 7662 | u32 cnt = 1000; |
| 7663 | u32 pend_bits = 0; |
| 7664 | |
| 7665 | do { |
| 7666 | pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS); |
| 7667 | |
| 7668 | if (pend_bits == 0) |
| 7669 | break; |
| 7670 | |
| 7671 | usleep_range(1000, 1000); |
| 7672 | } while (cnt-- > 0); |
| 7673 | |
| 7674 | if (cnt <= 0) { |
| 7675 | BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n", |
| 7676 | pend_bits); |
| 7677 | return -EBUSY; |
| 7678 | } |
| 7679 | |
| 7680 | return 0; |
| 7681 | } |
| 7682 | |
| 7683 | static int bnx2x_process_kill(struct bnx2x *bp, bool global) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7684 | { |
| 7685 | int cnt = 1000; |
| 7686 | u32 val = 0; |
| 7687 | u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2; |
| 7688 | |
| 7689 | |
| 7690 | /* Empty the Tetris buffer, wait for 1s */ |
| 7691 | do { |
| 7692 | sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT); |
| 7693 | blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT); |
| 7694 | port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0); |
| 7695 | port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1); |
| 7696 | pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2); |
| 7697 | if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) && |
| 7698 | ((port_is_idle_0 & 0x1) == 0x1) && |
| 7699 | ((port_is_idle_1 & 0x1) == 0x1) && |
| 7700 | (pgl_exp_rom2 == 0xffffffff)) |
| 7701 | break; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7702 | usleep_range(1000, 1000); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7703 | } while (cnt-- > 0); |
| 7704 | |
| 7705 | if (cnt <= 0) { |
| 7706 | DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there" |
| 7707 | " are still" |
| 7708 | " outstanding read requests after 1s!\n"); |
| 7709 | DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x," |
| 7710 | " port_is_idle_0=0x%08x," |
| 7711 | " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n", |
| 7712 | sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, |
| 7713 | pgl_exp_rom2); |
| 7714 | return -EAGAIN; |
| 7715 | } |
| 7716 | |
| 7717 | barrier(); |
| 7718 | |
| 7719 | /* Close gates #2, #3 and #4 */ |
| 7720 | bnx2x_set_234_gates(bp, true); |
| 7721 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7722 | /* Poll for IGU VQs for 57712 and newer chips */ |
| 7723 | if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp)) |
| 7724 | return -EAGAIN; |
| 7725 | |
| 7726 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7727 | /* TBD: Indicate that "process kill" is in progress to MCP */ |
| 7728 | |
| 7729 | /* Clear "unprepared" bit */ |
| 7730 | REG_WR(bp, MISC_REG_UNPREPARED, 0); |
| 7731 | barrier(); |
| 7732 | |
| 7733 | /* Make sure all is written to the chip before the reset */ |
| 7734 | mmiowb(); |
| 7735 | |
| 7736 | /* Wait for 1ms to empty GLUE and PCI-E core queues, |
| 7737 | * PSWHST, GRC and PSWRD Tetris buffer. |
| 7738 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7739 | usleep_range(1000, 1000); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7740 | |
| 7741 | /* Prepare to chip reset: */ |
| 7742 | /* MCP */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7743 | if (global) |
| 7744 | bnx2x_reset_mcp_prep(bp, &val); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7745 | |
| 7746 | /* PXP */ |
| 7747 | bnx2x_pxp_prep(bp); |
| 7748 | barrier(); |
| 7749 | |
| 7750 | /* reset the chip */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7751 | bnx2x_process_kill_chip_reset(bp, global); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7752 | barrier(); |
| 7753 | |
| 7754 | /* Recover after reset: */ |
| 7755 | /* MCP */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7756 | if (global && bnx2x_reset_mcp_comp(bp, val)) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7757 | return -EAGAIN; |
| 7758 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7759 | /* TBD: Add resetting the NO_MCP mode DB here */ |
| 7760 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7761 | /* PXP */ |
| 7762 | bnx2x_pxp_prep(bp); |
| 7763 | |
| 7764 | /* Open the gates #2, #3 and #4 */ |
| 7765 | bnx2x_set_234_gates(bp, false); |
| 7766 | |
| 7767 | /* TBD: IGU/AEU preparation bring back the AEU/IGU to a |
| 7768 | * reset state, re-enable attentions. */ |
| 7769 | |
| 7770 | return 0; |
| 7771 | } |
| 7772 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7773 | int bnx2x_leader_reset(struct bnx2x *bp) |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7774 | { |
| 7775 | int rc = 0; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7776 | bool global = bnx2x_reset_is_global(bp); |
| 7777 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7778 | /* Try to recover after the failure */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7779 | if (bnx2x_process_kill(bp, global)) { |
| 7780 | netdev_err(bp->dev, "Something bad had happen on engine %d! " |
| 7781 | "Aii!\n", BP_PATH(bp)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7782 | rc = -EAGAIN; |
| 7783 | goto exit_leader_reset; |
| 7784 | } |
| 7785 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7786 | /* |
| 7787 | * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver |
| 7788 | * state. |
| 7789 | */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7790 | bnx2x_set_reset_done(bp); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7791 | if (global) |
| 7792 | bnx2x_clear_reset_global(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7793 | |
| 7794 | exit_leader_reset: |
| 7795 | bp->is_leader = 0; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7796 | bnx2x_release_leader_lock(bp); |
| 7797 | smp_mb(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7798 | return rc; |
| 7799 | } |
| 7800 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7801 | static inline void bnx2x_recovery_failed(struct bnx2x *bp) |
| 7802 | { |
| 7803 | netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n"); |
| 7804 | |
| 7805 | /* Disconnect this device */ |
| 7806 | netif_device_detach(bp->dev); |
| 7807 | |
| 7808 | /* |
| 7809 | * Block ifup for all function on this engine until "process kill" |
| 7810 | * or power cycle. |
| 7811 | */ |
| 7812 | bnx2x_set_reset_in_progress(bp); |
| 7813 | |
| 7814 | /* Shut down the power */ |
| 7815 | bnx2x_set_power_state(bp, PCI_D3hot); |
| 7816 | |
| 7817 | bp->recovery_state = BNX2X_RECOVERY_FAILED; |
| 7818 | |
| 7819 | smp_mb(); |
| 7820 | } |
| 7821 | |
| 7822 | /* |
| 7823 | * Assumption: runs under rtnl lock. This together with the fact |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7824 | * that it's called only from bnx2x_reset_task() ensure that it |
| 7825 | * will never be called when netif_running(bp->dev) is false. |
| 7826 | */ |
| 7827 | static void bnx2x_parity_recover(struct bnx2x *bp) |
| 7828 | { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7829 | bool global = false; |
| 7830 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7831 | DP(NETIF_MSG_HW, "Handling parity\n"); |
| 7832 | while (1) { |
| 7833 | switch (bp->recovery_state) { |
| 7834 | case BNX2X_RECOVERY_INIT: |
| 7835 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n"); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7836 | bnx2x_chk_parity_attn(bp, &global, false); |
| 7837 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7838 | /* Try to get a LEADER_LOCK HW lock */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7839 | if (bnx2x_trylock_leader_lock(bp)) { |
| 7840 | bnx2x_set_reset_in_progress(bp); |
| 7841 | /* |
| 7842 | * Check if there is a global attention and if |
| 7843 | * there was a global attention, set the global |
| 7844 | * reset bit. |
| 7845 | */ |
| 7846 | |
| 7847 | if (global) |
| 7848 | bnx2x_set_reset_global(bp); |
| 7849 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7850 | bp->is_leader = 1; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7851 | } |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7852 | |
| 7853 | /* Stop the driver */ |
| 7854 | /* If interface has been removed - break */ |
| 7855 | if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY)) |
| 7856 | return; |
| 7857 | |
| 7858 | bp->recovery_state = BNX2X_RECOVERY_WAIT; |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7859 | |
| 7860 | /* |
| 7861 | * Reset MCP command sequence number and MCP mail box |
| 7862 | * sequence as we are going to reset the MCP. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7863 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7864 | if (global) { |
| 7865 | bp->fw_seq = 0; |
| 7866 | bp->fw_drv_pulse_wr_seq = 0; |
| 7867 | } |
| 7868 | |
| 7869 | /* Ensure "is_leader", MCP command sequence and |
| 7870 | * "recovery_state" update values are seen on other |
| 7871 | * CPUs. |
| 7872 | */ |
| 7873 | smp_mb(); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7874 | break; |
| 7875 | |
| 7876 | case BNX2X_RECOVERY_WAIT: |
| 7877 | DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n"); |
| 7878 | if (bp->is_leader) { |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7879 | int other_engine = BP_PATH(bp) ? 0 : 1; |
| 7880 | u32 other_load_counter = |
| 7881 | bnx2x_get_load_cnt(bp, other_engine); |
| 7882 | u32 load_counter = |
| 7883 | bnx2x_get_load_cnt(bp, BP_PATH(bp)); |
| 7884 | global = bnx2x_reset_is_global(bp); |
| 7885 | |
| 7886 | /* |
| 7887 | * In case of a parity in a global block, let |
| 7888 | * the first leader that performs a |
| 7889 | * leader_reset() reset the global blocks in |
| 7890 | * order to clear global attentions. Otherwise |
| 7891 | * the the gates will remain closed for that |
| 7892 | * engine. |
| 7893 | */ |
| 7894 | if (load_counter || |
| 7895 | (global && other_load_counter)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7896 | /* Wait until all other functions get |
| 7897 | * down. |
| 7898 | */ |
| 7899 | schedule_delayed_work(&bp->reset_task, |
| 7900 | HZ/10); |
| 7901 | return; |
| 7902 | } else { |
| 7903 | /* If all other functions got down - |
| 7904 | * try to bring the chip back to |
| 7905 | * normal. In any case it's an exit |
| 7906 | * point for a leader. |
| 7907 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7908 | if (bnx2x_leader_reset(bp)) { |
| 7909 | bnx2x_recovery_failed(bp); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7910 | return; |
| 7911 | } |
| 7912 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7913 | /* If we are here, means that the |
| 7914 | * leader has succeeded and doesn't |
| 7915 | * want to be a leader any more. Try |
| 7916 | * to continue as a none-leader. |
| 7917 | */ |
| 7918 | break; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7919 | } |
| 7920 | } else { /* non-leader */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7921 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7922 | /* Try to get a LEADER_LOCK HW lock as |
| 7923 | * long as a former leader may have |
| 7924 | * been unloaded by the user or |
| 7925 | * released a leadership by another |
| 7926 | * reason. |
| 7927 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7928 | if (bnx2x_trylock_leader_lock(bp)) { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7929 | /* I'm a leader now! Restart a |
| 7930 | * switch case. |
| 7931 | */ |
| 7932 | bp->is_leader = 1; |
| 7933 | break; |
| 7934 | } |
| 7935 | |
| 7936 | schedule_delayed_work(&bp->reset_task, |
| 7937 | HZ/10); |
| 7938 | return; |
| 7939 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 7940 | } else { |
| 7941 | /* |
| 7942 | * If there was a global attention, wait |
| 7943 | * for it to be cleared. |
| 7944 | */ |
| 7945 | if (bnx2x_reset_is_global(bp)) { |
| 7946 | schedule_delayed_work( |
| 7947 | &bp->reset_task, HZ/10); |
| 7948 | return; |
| 7949 | } |
| 7950 | |
| 7951 | if (bnx2x_nic_load(bp, LOAD_NORMAL)) |
| 7952 | bnx2x_recovery_failed(bp); |
| 7953 | else { |
| 7954 | bp->recovery_state = |
| 7955 | BNX2X_RECOVERY_DONE; |
| 7956 | smp_mb(); |
| 7957 | } |
| 7958 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7959 | return; |
| 7960 | } |
| 7961 | } |
| 7962 | default: |
| 7963 | return; |
| 7964 | } |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is |
| 7969 | * scheduled on a general queue in order to prevent a dead lock. |
| 7970 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7971 | static void bnx2x_reset_task(struct work_struct *work) |
| 7972 | { |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7973 | struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7974 | |
| 7975 | #ifdef BNX2X_STOP_ON_ERROR |
| 7976 | BNX2X_ERR("reset task called but STOP_ON_ERROR defined" |
| 7977 | " so reset not done to allow debug dump,\n" |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7978 | KERN_ERR " you will need to reboot when done\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7979 | return; |
| 7980 | #endif |
| 7981 | |
| 7982 | rtnl_lock(); |
| 7983 | |
| 7984 | if (!netif_running(bp->dev)) |
| 7985 | goto reset_task_exit; |
| 7986 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 7987 | if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) |
| 7988 | bnx2x_parity_recover(bp); |
| 7989 | else { |
| 7990 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 7991 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 7992 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7993 | |
| 7994 | reset_task_exit: |
| 7995 | rtnl_unlock(); |
| 7996 | } |
| 7997 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7998 | /* end of nic load/unload */ |
| 7999 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8000 | /* |
| 8001 | * Init service functions |
| 8002 | */ |
| 8003 | |
stephen hemminger | 8d96286 | 2010-10-21 07:50:56 +0000 | [diff] [blame] | 8004 | static u32 bnx2x_get_pretend_reg(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8005 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8006 | u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 8007 | u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; |
| 8008 | return base + (BP_ABS_FUNC(bp)) * stride; |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8009 | } |
| 8010 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8011 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8012 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8013 | u32 reg = bnx2x_get_pretend_reg(bp); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8014 | |
| 8015 | /* Flush all outstanding writes */ |
| 8016 | mmiowb(); |
| 8017 | |
| 8018 | /* Pretend to be function 0 */ |
| 8019 | REG_WR(bp, reg, 0); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8020 | REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */ |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8021 | |
| 8022 | /* From now we are in the "like-E1" mode */ |
| 8023 | bnx2x_int_disable(bp); |
| 8024 | |
| 8025 | /* Flush all outstanding writes */ |
| 8026 | mmiowb(); |
| 8027 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8028 | /* Restore the original function */ |
| 8029 | REG_WR(bp, reg, BP_ABS_FUNC(bp)); |
| 8030 | REG_RD(bp, reg); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8031 | } |
| 8032 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8033 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8034 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8035 | if (CHIP_IS_E1(bp)) |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8036 | bnx2x_int_disable(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8037 | else |
| 8038 | bnx2x_undi_int_disable_e1h(bp); |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 8039 | } |
| 8040 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8041 | static void __devinit bnx2x_undi_unload(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8042 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8043 | u32 val; |
| 8044 | |
| 8045 | /* Check if there is any driver already loaded */ |
| 8046 | val = REG_RD(bp, MISC_REG_UNPREPARED); |
| 8047 | if (val == 0x1) { |
| 8048 | /* Check if it is the UNDI driver |
| 8049 | * UNDI driver initializes CID offset for normal bell to 0x7 |
| 8050 | */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8051 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8052 | val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); |
| 8053 | if (val == 0x7) { |
| 8054 | u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8055 | /* save our pf_num */ |
| 8056 | int orig_pf_num = bp->pf_num; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8057 | int port; |
| 8058 | u32 swap_en, swap_val, value; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8059 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8060 | /* clear the UNDI indication */ |
| 8061 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); |
| 8062 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8063 | BNX2X_DEV_INFO("UNDI is active! reset device\n"); |
| 8064 | |
| 8065 | /* try unload UNDI on port 0 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8066 | bp->pf_num = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8067 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8068 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8069 | DRV_MSG_SEQ_NUMBER_MASK); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8070 | reset_code = bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8071 | |
| 8072 | /* if UNDI is loaded on the other port */ |
| 8073 | if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) { |
| 8074 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8075 | /* send "DONE" for previous unload */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8076 | bnx2x_fw_command(bp, |
| 8077 | DRV_MSG_CODE_UNLOAD_DONE, 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8078 | |
| 8079 | /* unload UNDI on port 1 */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8080 | bp->pf_num = 1; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8081 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8082 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8083 | DRV_MSG_SEQ_NUMBER_MASK); |
| 8084 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8085 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8086 | bnx2x_fw_command(bp, reset_code, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8087 | } |
| 8088 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8089 | /* now it's safe to release the lock */ |
| 8090 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
| 8091 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8092 | bnx2x_undi_int_disable(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8093 | port = BP_PORT(bp); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8094 | |
| 8095 | /* close input traffic and wait for it */ |
| 8096 | /* Do not rcv packets to BRB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8097 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK : |
| 8098 | NIG_REG_LLH0_BRB1_DRV_MASK), 0x0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8099 | /* Do not direct rcv packets that are not for MCP to |
| 8100 | * the BRB */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8101 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 8102 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8103 | /* clear AEU */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8104 | REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 8105 | MISC_REG_AEU_MASK_ATTN_FUNC_0), 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8106 | msleep(10); |
| 8107 | |
| 8108 | /* save NIG port swap info */ |
| 8109 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 8110 | swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8111 | /* reset device */ |
| 8112 | REG_WR(bp, |
| 8113 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8114 | 0xd3ffffff); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8115 | |
| 8116 | value = 0x1400; |
| 8117 | if (CHIP_IS_E3(bp)) { |
| 8118 | value |= MISC_REGISTERS_RESET_REG_2_MSTAT0; |
| 8119 | value |= MISC_REGISTERS_RESET_REG_2_MSTAT1; |
| 8120 | } |
| 8121 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8122 | REG_WR(bp, |
| 8123 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8124 | value); |
| 8125 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8126 | /* take the NIG out of reset and restore swap values */ |
| 8127 | REG_WR(bp, |
| 8128 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 8129 | MISC_REGISTERS_RESET_REG_1_RST_NIG); |
| 8130 | REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); |
| 8131 | REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en); |
| 8132 | |
| 8133 | /* send unload done to the MCP */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8134 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8135 | |
| 8136 | /* restore our func and fw_seq */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8137 | bp->pf_num = orig_pf_num; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8138 | bp->fw_seq = |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8139 | (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) & |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8140 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8141 | } else |
| 8142 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8143 | } |
| 8144 | } |
| 8145 | |
| 8146 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) |
| 8147 | { |
| 8148 | u32 val, val2, val3, val4, id; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8149 | u16 pmc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8150 | |
| 8151 | /* Get the chip revision id and number. */ |
| 8152 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ |
| 8153 | val = REG_RD(bp, MISC_REG_CHIP_NUM); |
| 8154 | id = ((val & 0xffff) << 16); |
| 8155 | val = REG_RD(bp, MISC_REG_CHIP_REV); |
| 8156 | id |= ((val & 0xf) << 12); |
| 8157 | val = REG_RD(bp, MISC_REG_CHIP_METAL); |
| 8158 | id |= ((val & 0xff) << 4); |
Eilon Greenstein | 5a40e08 | 2009-01-14 06:44:04 +0000 | [diff] [blame] | 8159 | val = REG_RD(bp, MISC_REG_BOND_ID); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8160 | id |= (val & 0xf); |
| 8161 | bp->common.chip_id = id; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8162 | |
| 8163 | /* Set doorbell size */ |
| 8164 | bp->db_size = (1 << BNX2X_DB_SHIFT); |
| 8165 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8166 | if (!CHIP_IS_E1x(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8167 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR); |
| 8168 | if ((val & 1) == 0) |
| 8169 | val = REG_RD(bp, MISC_REG_PORT4MODE_EN); |
| 8170 | else |
| 8171 | val = (val >> 1) & 1; |
| 8172 | BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" : |
| 8173 | "2_PORT_MODE"); |
| 8174 | bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE : |
| 8175 | CHIP_2_PORT_MODE; |
| 8176 | |
| 8177 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 8178 | bp->pfid = (bp->pf_num >> 1); /* 0..3 */ |
| 8179 | else |
| 8180 | bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */ |
| 8181 | } else { |
| 8182 | bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */ |
| 8183 | bp->pfid = bp->pf_num; /* 0..7 */ |
| 8184 | } |
| 8185 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8186 | bp->link_params.chip_id = bp->common.chip_id; |
| 8187 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8188 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 8189 | val = (REG_RD(bp, 0x2874) & 0x55); |
| 8190 | if ((bp->common.chip_id & 0x1) || |
| 8191 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { |
| 8192 | bp->flags |= ONE_PORT_FLAG; |
| 8193 | BNX2X_DEV_INFO("single port device\n"); |
| 8194 | } |
| 8195 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8196 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8197 | bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE << |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8198 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
| 8199 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", |
| 8200 | bp->common.flash_size, bp->common.flash_size); |
| 8201 | |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 8202 | bnx2x_init_shmem(bp); |
| 8203 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8204 | |
| 8205 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8206 | bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ? |
| 8207 | MISC_REG_GENERIC_CR_1 : |
| 8208 | MISC_REG_GENERIC_CR_0)); |
Dmitry Kravkov | 1b6e2ce | 2011-05-22 10:11:26 +0000 | [diff] [blame] | 8209 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8210 | bp->link_params.shmem_base = bp->common.shmem_base; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8211 | bp->link_params.shmem2_base = bp->common.shmem2_base; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8212 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
| 8213 | bp->common.shmem_base, bp->common.shmem2_base); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8214 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8215 | if (!bp->common.shmem_base) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8216 | BNX2X_DEV_INFO("MCP not active\n"); |
| 8217 | bp->flags |= NO_MCP_FLAG; |
| 8218 | return; |
| 8219 | } |
| 8220 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8221 | 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] | 8222 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8223 | |
| 8224 | bp->link_params.hw_led_mode = ((bp->common.hw_config & |
| 8225 | SHARED_HW_CFG_LED_MODE_MASK) >> |
| 8226 | SHARED_HW_CFG_LED_MODE_SHIFT); |
| 8227 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8228 | bp->link_params.feature_config_flags = 0; |
| 8229 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); |
| 8230 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) |
| 8231 | bp->link_params.feature_config_flags |= |
| 8232 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8233 | else |
| 8234 | bp->link_params.feature_config_flags &= |
| 8235 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8236 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8237 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
| 8238 | bp->common.bc_ver = val; |
| 8239 | BNX2X_DEV_INFO("bc_ver %X\n", val); |
| 8240 | if (val < BNX2X_BC_VER) { |
| 8241 | /* for now only warn |
| 8242 | * later we might need to enforce this */ |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8243 | BNX2X_ERR("This driver needs bc_ver %X but found %X, " |
| 8244 | "please upgrade BC\n", BNX2X_BC_VER, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8245 | } |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8246 | bp->link_params.feature_config_flags |= |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8247 | (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ? |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8248 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
| 8249 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8250 | bp->link_params.feature_config_flags |= |
| 8251 | (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ? |
| 8252 | FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8253 | |
Dmitry Kravkov | f9a3ebb | 2011-05-04 23:49:11 +0000 | [diff] [blame] | 8254 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
| 8255 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
| 8256 | |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8257 | BNX2X_DEV_INFO("%sWoL capable\n", |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 8258 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8259 | |
| 8260 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); |
| 8261 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); |
| 8262 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); |
| 8263 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); |
| 8264 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8265 | dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n", |
| 8266 | val, val2, val3, val4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8267 | } |
| 8268 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8269 | #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID) |
| 8270 | #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR) |
| 8271 | |
| 8272 | static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp) |
| 8273 | { |
| 8274 | int pfid = BP_FUNC(bp); |
| 8275 | int vn = BP_E1HVN(bp); |
| 8276 | int igu_sb_id; |
| 8277 | u32 val; |
| 8278 | u8 fid; |
| 8279 | |
| 8280 | bp->igu_base_sb = 0xff; |
| 8281 | bp->igu_sb_cnt = 0; |
| 8282 | if (CHIP_INT_MODE_IS_BC(bp)) { |
| 8283 | bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x, |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8284 | NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8285 | |
| 8286 | bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) * |
| 8287 | FP_SB_MAX_E1x; |
| 8288 | |
| 8289 | bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x + |
| 8290 | (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn); |
| 8291 | |
| 8292 | return; |
| 8293 | } |
| 8294 | |
| 8295 | /* IGU in normal mode - read CAM */ |
| 8296 | for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; |
| 8297 | igu_sb_id++) { |
| 8298 | val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4); |
| 8299 | if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) |
| 8300 | continue; |
| 8301 | fid = IGU_FID(val); |
| 8302 | if ((fid & IGU_FID_ENCODE_IS_PF)) { |
| 8303 | if ((fid & IGU_FID_PF_NUM_MASK) != pfid) |
| 8304 | continue; |
| 8305 | if (IGU_VEC(val) == 0) |
| 8306 | /* default status block */ |
| 8307 | bp->igu_dsb_id = igu_sb_id; |
| 8308 | else { |
| 8309 | if (bp->igu_base_sb == 0xff) |
| 8310 | bp->igu_base_sb = igu_sb_id; |
| 8311 | bp->igu_sb_cnt++; |
| 8312 | } |
| 8313 | } |
| 8314 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8315 | |
| 8316 | /* It's expected that number of CAM entries for this |
| 8317 | * functions is equal to the MSI-X table size (which was a |
| 8318 | * used during bp->l2_cid_count value calculation. |
| 8319 | * We want a harsh warning if these values are different! |
| 8320 | */ |
| 8321 | WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
| 8322 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8323 | if (bp->igu_sb_cnt == 0) |
| 8324 | BNX2X_ERR("CAM configuration error\n"); |
| 8325 | } |
| 8326 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8327 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
| 8328 | u32 switch_cfg) |
| 8329 | { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8330 | int cfg_size = 0, idx, port = BP_PORT(bp); |
| 8331 | |
| 8332 | /* Aggregation of supported attributes of all external phys */ |
| 8333 | bp->port.supported[0] = 0; |
| 8334 | bp->port.supported[1] = 0; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8335 | switch (bp->link_params.num_phys) { |
| 8336 | case 1: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8337 | bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported; |
| 8338 | cfg_size = 1; |
| 8339 | break; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8340 | case 2: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8341 | bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported; |
| 8342 | cfg_size = 1; |
| 8343 | break; |
| 8344 | case 3: |
| 8345 | if (bp->link_params.multi_phy_config & |
| 8346 | PORT_HW_CFG_PHY_SWAPPED_ENABLED) { |
| 8347 | bp->port.supported[1] = |
| 8348 | bp->link_params.phy[EXT_PHY1].supported; |
| 8349 | bp->port.supported[0] = |
| 8350 | bp->link_params.phy[EXT_PHY2].supported; |
| 8351 | } else { |
| 8352 | bp->port.supported[0] = |
| 8353 | bp->link_params.phy[EXT_PHY1].supported; |
| 8354 | bp->port.supported[1] = |
| 8355 | bp->link_params.phy[EXT_PHY2].supported; |
| 8356 | } |
| 8357 | cfg_size = 2; |
| 8358 | break; |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8359 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8360 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8361 | if (!(bp->port.supported[0] || bp->port.supported[1])) { |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8362 | BNX2X_ERR("NVRAM config error. BAD phy config." |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8363 | "PHY1 config 0x%x, PHY2 config 0x%x\n", |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8364 | SHMEM_RD(bp, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8365 | dev_info.port_hw_config[port].external_phy_config), |
| 8366 | SHMEM_RD(bp, |
| 8367 | dev_info.port_hw_config[port].external_phy_config2)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8368 | return; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8369 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8370 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8371 | if (CHIP_IS_E3(bp)) |
| 8372 | bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR); |
| 8373 | else { |
| 8374 | switch (switch_cfg) { |
| 8375 | case SWITCH_CFG_1G: |
| 8376 | bp->port.phy_addr = REG_RD( |
| 8377 | bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10); |
| 8378 | break; |
| 8379 | case SWITCH_CFG_10G: |
| 8380 | bp->port.phy_addr = REG_RD( |
| 8381 | bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18); |
| 8382 | break; |
| 8383 | default: |
| 8384 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", |
| 8385 | bp->port.link_config[0]); |
| 8386 | return; |
| 8387 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8388 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8389 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8390 | /* mask what we support according to speed_cap_mask per configuration */ |
| 8391 | for (idx = 0; idx < cfg_size; idx++) { |
| 8392 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8393 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8394 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8395 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8396 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8397 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8398 | bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8399 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8400 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8401 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8402 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8403 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8404 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8405 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8406 | bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8407 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8408 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8409 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8410 | bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8411 | SUPPORTED_1000baseT_Full); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8412 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8413 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8414 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8415 | bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8416 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8417 | if (!(bp->link_params.speed_cap_mask[idx] & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8418 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8419 | bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8420 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8421 | } |
| 8422 | |
| 8423 | BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0], |
| 8424 | bp->port.supported[1]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8425 | } |
| 8426 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8427 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8428 | { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8429 | u32 link_config, idx, cfg_size = 0; |
| 8430 | bp->port.advertising[0] = 0; |
| 8431 | bp->port.advertising[1] = 0; |
| 8432 | switch (bp->link_params.num_phys) { |
| 8433 | case 1: |
| 8434 | case 2: |
| 8435 | cfg_size = 1; |
| 8436 | break; |
| 8437 | case 3: |
| 8438 | cfg_size = 2; |
| 8439 | break; |
| 8440 | } |
| 8441 | for (idx = 0; idx < cfg_size; idx++) { |
| 8442 | bp->link_params.req_duplex[idx] = DUPLEX_FULL; |
| 8443 | link_config = bp->port.link_config[idx]; |
| 8444 | switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) { |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8445 | case PORT_FEATURE_LINK_SPEED_AUTO: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8446 | if (bp->port.supported[idx] & SUPPORTED_Autoneg) { |
| 8447 | bp->link_params.req_line_speed[idx] = |
| 8448 | SPEED_AUTO_NEG; |
| 8449 | bp->port.advertising[idx] |= |
| 8450 | bp->port.supported[idx]; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8451 | } else { |
| 8452 | /* force 10G, no AN */ |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8453 | bp->link_params.req_line_speed[idx] = |
| 8454 | SPEED_10000; |
| 8455 | bp->port.advertising[idx] |= |
| 8456 | (ADVERTISED_10000baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8457 | ADVERTISED_FIBRE); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8458 | continue; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8459 | } |
| 8460 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8461 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8462 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8463 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) { |
| 8464 | bp->link_params.req_line_speed[idx] = |
| 8465 | SPEED_10; |
| 8466 | bp->port.advertising[idx] |= |
| 8467 | (ADVERTISED_10baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8468 | ADVERTISED_TP); |
| 8469 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8470 | BNX2X_ERR("NVRAM config error. " |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8471 | "Invalid link_config 0x%x" |
| 8472 | " speed_cap_mask 0x%x\n", |
| 8473 | link_config, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8474 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8475 | return; |
| 8476 | } |
| 8477 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8478 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8479 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8480 | if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) { |
| 8481 | bp->link_params.req_line_speed[idx] = |
| 8482 | SPEED_10; |
| 8483 | bp->link_params.req_duplex[idx] = |
| 8484 | DUPLEX_HALF; |
| 8485 | bp->port.advertising[idx] |= |
| 8486 | (ADVERTISED_10baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8487 | ADVERTISED_TP); |
| 8488 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8489 | BNX2X_ERR("NVRAM config error. " |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8490 | "Invalid link_config 0x%x" |
| 8491 | " speed_cap_mask 0x%x\n", |
| 8492 | link_config, |
| 8493 | bp->link_params.speed_cap_mask[idx]); |
| 8494 | return; |
| 8495 | } |
| 8496 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8497 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8498 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
| 8499 | if (bp->port.supported[idx] & |
| 8500 | SUPPORTED_100baseT_Full) { |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8501 | bp->link_params.req_line_speed[idx] = |
| 8502 | SPEED_100; |
| 8503 | bp->port.advertising[idx] |= |
| 8504 | (ADVERTISED_100baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8505 | ADVERTISED_TP); |
| 8506 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8507 | BNX2X_ERR("NVRAM config error. " |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8508 | "Invalid link_config 0x%x" |
| 8509 | " speed_cap_mask 0x%x\n", |
| 8510 | link_config, |
| 8511 | bp->link_params.speed_cap_mask[idx]); |
| 8512 | return; |
| 8513 | } |
| 8514 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8515 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8516 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
| 8517 | if (bp->port.supported[idx] & |
| 8518 | SUPPORTED_100baseT_Half) { |
| 8519 | bp->link_params.req_line_speed[idx] = |
| 8520 | SPEED_100; |
| 8521 | bp->link_params.req_duplex[idx] = |
| 8522 | DUPLEX_HALF; |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8523 | bp->port.advertising[idx] |= |
| 8524 | (ADVERTISED_100baseT_Half | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8525 | ADVERTISED_TP); |
| 8526 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8527 | BNX2X_ERR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8528 | "Invalid link_config 0x%x" |
| 8529 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8530 | link_config, |
| 8531 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8532 | return; |
| 8533 | } |
| 8534 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8535 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8536 | case PORT_FEATURE_LINK_SPEED_1G: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8537 | if (bp->port.supported[idx] & |
| 8538 | SUPPORTED_1000baseT_Full) { |
| 8539 | bp->link_params.req_line_speed[idx] = |
| 8540 | SPEED_1000; |
| 8541 | bp->port.advertising[idx] |= |
| 8542 | (ADVERTISED_1000baseT_Full | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8543 | ADVERTISED_TP); |
| 8544 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8545 | BNX2X_ERR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8546 | "Invalid link_config 0x%x" |
| 8547 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8548 | link_config, |
| 8549 | bp->link_params.speed_cap_mask[idx]); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8550 | return; |
| 8551 | } |
| 8552 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8553 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8554 | case PORT_FEATURE_LINK_SPEED_2_5G: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8555 | if (bp->port.supported[idx] & |
| 8556 | SUPPORTED_2500baseX_Full) { |
| 8557 | bp->link_params.req_line_speed[idx] = |
| 8558 | SPEED_2500; |
| 8559 | bp->port.advertising[idx] |= |
| 8560 | (ADVERTISED_2500baseX_Full | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8561 | ADVERTISED_TP); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8562 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8563 | BNX2X_ERR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8564 | "Invalid link_config 0x%x" |
| 8565 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8566 | link_config, |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8567 | bp->link_params.speed_cap_mask[idx]); |
| 8568 | return; |
| 8569 | } |
| 8570 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8571 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8572 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8573 | if (bp->port.supported[idx] & |
| 8574 | SUPPORTED_10000baseT_Full) { |
| 8575 | bp->link_params.req_line_speed[idx] = |
| 8576 | SPEED_10000; |
| 8577 | bp->port.advertising[idx] |= |
| 8578 | (ADVERTISED_10000baseT_Full | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8579 | ADVERTISED_FIBRE); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8580 | } else { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8581 | BNX2X_ERR("NVRAM config error. " |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 8582 | "Invalid link_config 0x%x" |
| 8583 | " speed_cap_mask 0x%x\n", |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8584 | link_config, |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8585 | bp->link_params.speed_cap_mask[idx]); |
| 8586 | return; |
| 8587 | } |
| 8588 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8589 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8590 | default: |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8591 | BNX2X_ERR("NVRAM config error. " |
| 8592 | "BAD link speed link_config 0x%x\n", |
| 8593 | link_config); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8594 | bp->link_params.req_line_speed[idx] = |
| 8595 | SPEED_AUTO_NEG; |
| 8596 | bp->port.advertising[idx] = |
| 8597 | bp->port.supported[idx]; |
| 8598 | break; |
| 8599 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8600 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8601 | bp->link_params.req_flow_ctrl[idx] = (link_config & |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8602 | PORT_FEATURE_FLOW_CONTROL_MASK); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8603 | if ((bp->link_params.req_flow_ctrl[idx] == |
| 8604 | BNX2X_FLOW_CTRL_AUTO) && |
| 8605 | !(bp->port.supported[idx] & SUPPORTED_Autoneg)) { |
| 8606 | bp->link_params.req_flow_ctrl[idx] = |
| 8607 | BNX2X_FLOW_CTRL_NONE; |
| 8608 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8609 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8610 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl" |
| 8611 | " 0x%x advertising 0x%x\n", |
| 8612 | bp->link_params.req_line_speed[idx], |
| 8613 | bp->link_params.req_duplex[idx], |
| 8614 | bp->link_params.req_flow_ctrl[idx], |
| 8615 | bp->port.advertising[idx]); |
| 8616 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8617 | } |
| 8618 | |
Michael Chan | e665bfd | 2009-10-10 13:46:54 +0000 | [diff] [blame] | 8619 | static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi) |
| 8620 | { |
| 8621 | mac_hi = cpu_to_be16(mac_hi); |
| 8622 | mac_lo = cpu_to_be32(mac_lo); |
| 8623 | memcpy(mac_buf, &mac_hi, sizeof(mac_hi)); |
| 8624 | memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo)); |
| 8625 | } |
| 8626 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8627 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8628 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8629 | int port = BP_PORT(bp); |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8630 | u32 config; |
Joe Perches | 6f38ad9 | 2010-11-14 17:04:31 +0000 | [diff] [blame] | 8631 | u32 ext_phy_type, ext_phy_config; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8632 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8633 | bp->link_params.bp = bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8634 | bp->link_params.port = port; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8635 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8636 | bp->link_params.lane_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8637 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8638 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8639 | bp->link_params.speed_cap_mask[0] = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8640 | SHMEM_RD(bp, |
| 8641 | dev_info.port_hw_config[port].speed_capability_mask); |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8642 | bp->link_params.speed_cap_mask[1] = |
| 8643 | SHMEM_RD(bp, |
| 8644 | dev_info.port_hw_config[port].speed_capability_mask2); |
| 8645 | bp->port.link_config[0] = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8646 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
| 8647 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8648 | bp->port.link_config[1] = |
| 8649 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2); |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8650 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8651 | bp->link_params.multi_phy_config = |
| 8652 | SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config); |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8653 | /* If the device is capable of WoL, set the default state according |
| 8654 | * to the HW |
| 8655 | */ |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8656 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8657 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
| 8658 | (config & PORT_FEATURE_WOL_ENABLED)); |
| 8659 | |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8660 | BNX2X_DEV_INFO("lane_config 0x%08x " |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8661 | "speed_cap_mask0 0x%08x link_config0 0x%08x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8662 | bp->link_params.lane_config, |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8663 | bp->link_params.speed_cap_mask[0], |
| 8664 | bp->port.link_config[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8665 | |
Yaniv Rosner | a22f078 | 2010-09-07 11:41:20 +0000 | [diff] [blame] | 8666 | bp->link_params.switch_cfg = (bp->port.link_config[0] & |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 8667 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8668 | bnx2x_phy_probe(&bp->link_params); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8669 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8670 | |
| 8671 | bnx2x_link_settings_requested(bp); |
| 8672 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8673 | /* |
| 8674 | * If connected directly, work with the internal PHY, otherwise, work |
| 8675 | * with the external PHY |
| 8676 | */ |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8677 | ext_phy_config = |
| 8678 | SHMEM_RD(bp, |
| 8679 | dev_info.port_hw_config[port].external_phy_config); |
| 8680 | ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8681 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8682 | bp->mdio.prtad = bp->port.phy_addr; |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8683 | |
| 8684 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && |
| 8685 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) |
| 8686 | bp->mdio.prtad = |
Yaniv Rosner | b7737c9 | 2010-09-07 11:40:54 +0000 | [diff] [blame] | 8687 | XGXS_EXT_PHY_ADDR(ext_phy_config); |
Yaniv Rosner | 5866df6 | 2011-01-30 04:15:07 +0000 | [diff] [blame] | 8688 | |
| 8689 | /* |
| 8690 | * Check if hw lock is required to access MDC/MDIO bus to the PHY(s) |
| 8691 | * In MF mode, it is set to cover self test cases |
| 8692 | */ |
| 8693 | if (IS_MF(bp)) |
| 8694 | bp->port.need_hw_lock = 1; |
| 8695 | else |
| 8696 | bp->port.need_hw_lock = bnx2x_hw_lock_required(bp, |
| 8697 | bp->common.shmem_base, |
| 8698 | bp->common.shmem2_base); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8699 | } |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8700 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8701 | #ifdef BCM_CNIC |
| 8702 | static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp) |
| 8703 | { |
| 8704 | u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
| 8705 | drv_lic_key[BP_PORT(bp)].max_iscsi_conn); |
| 8706 | u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp, |
| 8707 | drv_lic_key[BP_PORT(bp)].max_fcoe_conn); |
| 8708 | |
| 8709 | /* Get the number of maximum allowed iSCSI and FCoE connections */ |
| 8710 | bp->cnic_eth_dev.max_iscsi_conn = |
| 8711 | (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >> |
| 8712 | BNX2X_MAX_ISCSI_INIT_CONN_SHIFT; |
| 8713 | |
| 8714 | bp->cnic_eth_dev.max_fcoe_conn = |
| 8715 | (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >> |
| 8716 | BNX2X_MAX_FCOE_INIT_CONN_SHIFT; |
| 8717 | |
| 8718 | BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n", |
| 8719 | bp->cnic_eth_dev.max_iscsi_conn, |
| 8720 | bp->cnic_eth_dev.max_fcoe_conn); |
| 8721 | |
| 8722 | /* If mamimum allowed number of connections is zero - |
| 8723 | * disable the feature. |
| 8724 | */ |
| 8725 | if (!bp->cnic_eth_dev.max_iscsi_conn) |
| 8726 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
| 8727 | |
| 8728 | if (!bp->cnic_eth_dev.max_fcoe_conn) |
| 8729 | bp->flags |= NO_FCOE_FLAG; |
| 8730 | } |
| 8731 | #endif |
| 8732 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8733 | static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp) |
| 8734 | { |
| 8735 | u32 val, val2; |
| 8736 | int func = BP_ABS_FUNC(bp); |
| 8737 | int port = BP_PORT(bp); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8738 | #ifdef BCM_CNIC |
| 8739 | u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac; |
| 8740 | u8 *fip_mac = bp->fip_mac; |
| 8741 | #endif |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8742 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8743 | /* Zero primary MAC configuration */ |
| 8744 | memset(bp->dev->dev_addr, 0, ETH_ALEN); |
| 8745 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8746 | if (BP_NOMCP(bp)) { |
| 8747 | BNX2X_ERROR("warning: random MAC workaround active\n"); |
| 8748 | random_ether_addr(bp->dev->dev_addr); |
| 8749 | } else if (IS_MF(bp)) { |
| 8750 | val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); |
| 8751 | val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); |
| 8752 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && |
| 8753 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) |
| 8754 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); |
| 8755 | |
| 8756 | #ifdef BCM_CNIC |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8757 | /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or |
| 8758 | * FCoE MAC then the appropriate feature should be disabled. |
| 8759 | */ |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8760 | if (IS_MF_SI(bp)) { |
| 8761 | u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg); |
| 8762 | if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) { |
| 8763 | val2 = MF_CFG_RD(bp, func_ext_config[func]. |
| 8764 | iscsi_mac_addr_upper); |
| 8765 | val = MF_CFG_RD(bp, func_ext_config[func]. |
| 8766 | iscsi_mac_addr_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8767 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8768 | BNX2X_DEV_INFO("Read iSCSI MAC: " |
| 8769 | BNX2X_MAC_FMT"\n", |
| 8770 | BNX2X_MAC_PRN_LIST(iscsi_mac)); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8771 | } else |
| 8772 | bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG; |
| 8773 | |
| 8774 | if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) { |
| 8775 | val2 = MF_CFG_RD(bp, func_ext_config[func]. |
| 8776 | fcoe_mac_addr_upper); |
| 8777 | val = MF_CFG_RD(bp, func_ext_config[func]. |
| 8778 | fcoe_mac_addr_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8779 | bnx2x_set_mac_buf(fip_mac, val, val2); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8780 | BNX2X_DEV_INFO("Read FCoE L2 MAC to " |
| 8781 | BNX2X_MAC_FMT"\n", |
| 8782 | BNX2X_MAC_PRN_LIST(fip_mac)); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8783 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8784 | } else |
| 8785 | bp->flags |= NO_FCOE_FLAG; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8786 | } |
| 8787 | #endif |
| 8788 | } else { |
| 8789 | /* in SF read MACs from port configuration */ |
| 8790 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); |
| 8791 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); |
| 8792 | bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2); |
| 8793 | |
| 8794 | #ifdef BCM_CNIC |
| 8795 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
| 8796 | iscsi_mac_upper); |
| 8797 | val = SHMEM_RD(bp, dev_info.port_hw_config[port]. |
| 8798 | iscsi_mac_lower); |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8799 | bnx2x_set_mac_buf(iscsi_mac, val, val2); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8800 | #endif |
| 8801 | } |
| 8802 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8803 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8804 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
Michael Chan | 37b091b | 2009-10-10 13:46:55 +0000 | [diff] [blame] | 8805 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8806 | #ifdef BCM_CNIC |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8807 | /* Set the FCoE MAC in modes other then MF_SI */ |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8808 | if (!CHIP_IS_E1x(bp)) { |
| 8809 | if (IS_MF_SD(bp)) |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 8810 | memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN); |
| 8811 | else if (!IS_MF(bp)) |
| 8812 | memcpy(fip_mac, iscsi_mac, ETH_ALEN); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8813 | } |
Dmitry Kravkov | 426b924 | 2011-05-04 23:49:53 +0000 | [diff] [blame] | 8814 | |
| 8815 | /* Disable iSCSI if MAC configuration is |
| 8816 | * invalid. |
| 8817 | */ |
| 8818 | if (!is_valid_ether_addr(iscsi_mac)) { |
| 8819 | bp->flags |= NO_ISCSI_FLAG; |
| 8820 | memset(iscsi_mac, 0, ETH_ALEN); |
| 8821 | } |
| 8822 | |
| 8823 | /* Disable FCoE if MAC configuration is |
| 8824 | * invalid. |
| 8825 | */ |
| 8826 | if (!is_valid_ether_addr(fip_mac)) { |
| 8827 | bp->flags |= NO_FCOE_FLAG; |
| 8828 | memset(bp->fip_mac, 0, ETH_ALEN); |
| 8829 | } |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8830 | #endif |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8831 | |
| 8832 | if (!is_valid_ether_addr(bp->dev->dev_addr)) |
| 8833 | dev_err(&bp->pdev->dev, |
| 8834 | "bad Ethernet MAC address configuration: " |
| 8835 | BNX2X_MAC_FMT", change it manually before bringing up " |
| 8836 | "the appropriate network interface\n", |
| 8837 | BNX2X_MAC_PRN_LIST(bp->dev->dev_addr)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8838 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8839 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8840 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) |
| 8841 | { |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8842 | int /*abs*/func = BP_ABS_FUNC(bp); |
David S. Miller | b8ee832 | 2011-04-17 16:56:12 -0700 | [diff] [blame] | 8843 | int vn; |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8844 | u32 val = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8845 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8846 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8847 | bnx2x_get_common_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8848 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8849 | if (CHIP_IS_E1x(bp)) { |
| 8850 | bp->common.int_block = INT_BLOCK_HC; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8851 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8852 | bp->igu_dsb_id = DEF_SB_IGU_ID; |
| 8853 | bp->igu_base_sb = 0; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 8854 | bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x, |
| 8855 | NUM_IGU_SB_REQUIRED(bp->l2_cid_count)); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8856 | } else { |
| 8857 | bp->common.int_block = INT_BLOCK_IGU; |
| 8858 | val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8859 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8860 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8861 | int tout = 5000; |
| 8862 | |
| 8863 | BNX2X_DEV_INFO("FORCING Normal Mode\n"); |
| 8864 | |
| 8865 | val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN); |
| 8866 | REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val); |
| 8867 | REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f); |
| 8868 | |
| 8869 | while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) { |
| 8870 | tout--; |
| 8871 | usleep_range(1000, 1000); |
| 8872 | } |
| 8873 | |
| 8874 | if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) { |
| 8875 | dev_err(&bp->pdev->dev, |
| 8876 | "FORCING Normal Mode failed!!!\n"); |
| 8877 | return -EPERM; |
| 8878 | } |
| 8879 | } |
| 8880 | |
| 8881 | if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) { |
| 8882 | BNX2X_DEV_INFO("IGU Backward Compatible Mode\n"); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8883 | bp->common.int_block |= INT_BLOCK_MODE_BW_COMP; |
| 8884 | } else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8885 | BNX2X_DEV_INFO("IGU Normal Mode\n"); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8886 | |
| 8887 | bnx2x_get_igu_cam_info(bp); |
| 8888 | |
| 8889 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8890 | |
| 8891 | /* |
| 8892 | * set base FW non-default (fast path) status block id, this value is |
| 8893 | * used to initialize the fw_sb_id saved on the fp/queue structure to |
| 8894 | * determine the id used by the FW. |
| 8895 | */ |
| 8896 | if (CHIP_IS_E1x(bp)) |
| 8897 | bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp); |
| 8898 | else /* |
| 8899 | * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of |
| 8900 | * the same queue are indicated on the same IGU SB). So we prefer |
| 8901 | * FW and IGU SBs to be the same value. |
| 8902 | */ |
| 8903 | bp->base_fw_ndsb = bp->igu_base_sb; |
| 8904 | |
| 8905 | BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n" |
| 8906 | "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb, |
| 8907 | bp->igu_sb_cnt, bp->base_fw_ndsb); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8908 | |
| 8909 | /* |
| 8910 | * Initialize MF configuration |
| 8911 | */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8912 | |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8913 | bp->mf_ov = 0; |
| 8914 | bp->mf_mode = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8915 | vn = BP_E1HVN(bp); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8916 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8917 | if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8918 | BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n", |
| 8919 | bp->common.shmem2_base, SHMEM2_RD(bp, size), |
| 8920 | (u32)offsetof(struct shmem2_region, mf_cfg_addr)); |
| 8921 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 8922 | if (SHMEM2_HAS(bp, mf_cfg_addr)) |
| 8923 | bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr); |
| 8924 | else |
| 8925 | bp->common.mf_cfg_base = bp->common.shmem_base + |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8926 | offsetof(struct shmem_region, func_mb) + |
| 8927 | E1H_FUNC_MAX * sizeof(struct drv_func_mb); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8928 | /* |
| 8929 | * get mf configuration: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8930 | * 1. existence of MF configuration |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8931 | * 2. MAC address must be legal (check only upper bytes) |
| 8932 | * for Switch-Independent mode; |
| 8933 | * OVLAN must be legal for Switch-Dependent mode |
| 8934 | * 3. SF_MODE configures specific MF mode |
| 8935 | */ |
| 8936 | if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { |
| 8937 | /* get mf configuration */ |
| 8938 | val = SHMEM_RD(bp, |
| 8939 | dev_info.shared_feature_config.config); |
| 8940 | val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 8941 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8942 | switch (val) { |
| 8943 | case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT: |
| 8944 | val = MF_CFG_RD(bp, func_mf_config[func]. |
| 8945 | mac_upper); |
| 8946 | /* check for legal mac (upper bytes)*/ |
| 8947 | if (val != 0xffff) { |
| 8948 | bp->mf_mode = MULTI_FUNCTION_SI; |
| 8949 | bp->mf_config[vn] = MF_CFG_RD(bp, |
| 8950 | func_mf_config[func].config); |
| 8951 | } else |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8952 | BNX2X_DEV_INFO("illegal MAC address " |
| 8953 | "for SI\n"); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8954 | break; |
| 8955 | case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED: |
| 8956 | /* get OV configuration */ |
| 8957 | val = MF_CFG_RD(bp, |
| 8958 | func_mf_config[FUNC_0].e1hov_tag); |
| 8959 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; |
| 8960 | |
| 8961 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
| 8962 | bp->mf_mode = MULTI_FUNCTION_SD; |
| 8963 | bp->mf_config[vn] = MF_CFG_RD(bp, |
| 8964 | func_mf_config[func].config); |
| 8965 | } else |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8966 | BNX2X_DEV_INFO("illegal OV for SD\n"); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8967 | break; |
| 8968 | default: |
| 8969 | /* Unknown configuration: reset mf_config */ |
| 8970 | bp->mf_config[vn] = 0; |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 8971 | BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val); |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8972 | } |
| 8973 | } |
| 8974 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8975 | BNX2X_DEV_INFO("%s function mode\n", |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8976 | IS_MF(bp) ? "multi" : "single"); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8977 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8978 | switch (bp->mf_mode) { |
| 8979 | case MULTI_FUNCTION_SD: |
| 8980 | val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) & |
| 8981 | FUNC_MF_CFG_E1HOV_TAG_MASK; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8982 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
Dmitry Kravkov | fb3bff1 | 2010-10-06 03:26:40 +0000 | [diff] [blame] | 8983 | bp->mf_ov = val; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8984 | bp->path_has_ovlan = true; |
| 8985 | |
| 8986 | BNX2X_DEV_INFO("MF OV for func %d is %d " |
| 8987 | "(0x%04x)\n", func, bp->mf_ov, |
| 8988 | bp->mf_ov); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8989 | } else { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 8990 | dev_err(&bp->pdev->dev, |
| 8991 | "No valid MF OV for func %d, " |
| 8992 | "aborting\n", func); |
| 8993 | return -EPERM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8994 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 8995 | break; |
| 8996 | case MULTI_FUNCTION_SI: |
| 8997 | BNX2X_DEV_INFO("func %d is in MF " |
| 8998 | "switch-independent mode\n", func); |
| 8999 | break; |
| 9000 | default: |
| 9001 | if (vn) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9002 | dev_err(&bp->pdev->dev, |
| 9003 | "VN %d is in a single function mode, " |
| 9004 | "aborting\n", vn); |
| 9005 | return -EPERM; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 9006 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9007 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9008 | } |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9009 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9010 | /* check if other port on the path needs ovlan: |
| 9011 | * Since MF configuration is shared between ports |
| 9012 | * Possible mixed modes are only |
| 9013 | * {SF, SI} {SF, SD} {SD, SF} {SI, SF} |
| 9014 | */ |
| 9015 | if (CHIP_MODE_IS_4_PORT(bp) && |
| 9016 | !bp->path_has_ovlan && |
| 9017 | !IS_MF(bp) && |
| 9018 | bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) { |
| 9019 | u8 other_port = !BP_PORT(bp); |
| 9020 | u8 other_func = BP_PATH(bp) + 2*other_port; |
| 9021 | val = MF_CFG_RD(bp, |
| 9022 | func_mf_config[other_func].e1hov_tag); |
| 9023 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) |
| 9024 | bp->path_has_ovlan = true; |
| 9025 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9026 | } |
| 9027 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9028 | /* adjust igu_sb_cnt to MF for E1x */ |
| 9029 | if (CHIP_IS_E1x(bp) && IS_MF(bp)) |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9030 | bp->igu_sb_cnt /= E1HVN_MAX; |
| 9031 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9032 | /* port info */ |
| 9033 | bnx2x_get_port_hwinfo(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9034 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9035 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9036 | bp->fw_seq = |
| 9037 | (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & |
| 9038 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9039 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 9040 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9041 | |
Dmitry Kravkov | 0793f83f | 2010-12-01 12:39:28 -0800 | [diff] [blame] | 9042 | /* Get MAC addresses */ |
| 9043 | bnx2x_get_mac_hwinfo(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9044 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 9045 | #ifdef BCM_CNIC |
| 9046 | bnx2x_get_cnic_info(bp); |
| 9047 | #endif |
| 9048 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9049 | /* Get current FW pulse sequence */ |
| 9050 | if (!BP_NOMCP(bp)) { |
| 9051 | int mb_idx = BP_FW_MB_IDX(bp); |
| 9052 | |
| 9053 | bp->fw_drv_pulse_wr_seq = |
| 9054 | (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) & |
| 9055 | DRV_PULSE_SEQ_MASK); |
| 9056 | BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq); |
| 9057 | } |
| 9058 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9059 | return rc; |
| 9060 | } |
| 9061 | |
Vladislav Zolotarov | 34f24c7 | 2010-04-19 01:13:23 +0000 | [diff] [blame] | 9062 | static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp) |
| 9063 | { |
| 9064 | int cnt, i, block_end, rodi; |
| 9065 | char vpd_data[BNX2X_VPD_LEN+1]; |
| 9066 | char str_id_reg[VENDOR_ID_LEN+1]; |
| 9067 | char str_id_cap[VENDOR_ID_LEN+1]; |
| 9068 | u8 len; |
| 9069 | |
| 9070 | cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data); |
| 9071 | memset(bp->fw_ver, 0, sizeof(bp->fw_ver)); |
| 9072 | |
| 9073 | if (cnt < BNX2X_VPD_LEN) |
| 9074 | goto out_not_found; |
| 9075 | |
| 9076 | i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN, |
| 9077 | PCI_VPD_LRDT_RO_DATA); |
| 9078 | if (i < 0) |
| 9079 | goto out_not_found; |
| 9080 | |
| 9081 | |
| 9082 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + |
| 9083 | pci_vpd_lrdt_size(&vpd_data[i]); |
| 9084 | |
| 9085 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 9086 | |
| 9087 | if (block_end > BNX2X_VPD_LEN) |
| 9088 | goto out_not_found; |
| 9089 | |
| 9090 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, |
| 9091 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 9092 | if (rodi < 0) |
| 9093 | goto out_not_found; |
| 9094 | |
| 9095 | len = pci_vpd_info_field_size(&vpd_data[rodi]); |
| 9096 | |
| 9097 | if (len != VENDOR_ID_LEN) |
| 9098 | goto out_not_found; |
| 9099 | |
| 9100 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 9101 | |
| 9102 | /* vendor specific info */ |
| 9103 | snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL); |
| 9104 | snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL); |
| 9105 | if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) || |
| 9106 | !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) { |
| 9107 | |
| 9108 | rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end, |
| 9109 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 9110 | if (rodi >= 0) { |
| 9111 | len = pci_vpd_info_field_size(&vpd_data[rodi]); |
| 9112 | |
| 9113 | rodi += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 9114 | |
| 9115 | if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) { |
| 9116 | memcpy(bp->fw_ver, &vpd_data[rodi], len); |
| 9117 | bp->fw_ver[len] = ' '; |
| 9118 | } |
| 9119 | } |
| 9120 | return; |
| 9121 | } |
| 9122 | out_not_found: |
| 9123 | return; |
| 9124 | } |
| 9125 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9126 | static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp) |
| 9127 | { |
| 9128 | u32 flags = 0; |
| 9129 | |
| 9130 | if (CHIP_REV_IS_FPGA(bp)) |
| 9131 | SET_FLAGS(flags, MODE_FPGA); |
| 9132 | else if (CHIP_REV_IS_EMUL(bp)) |
| 9133 | SET_FLAGS(flags, MODE_EMUL); |
| 9134 | else |
| 9135 | SET_FLAGS(flags, MODE_ASIC); |
| 9136 | |
| 9137 | if (CHIP_MODE_IS_4_PORT(bp)) |
| 9138 | SET_FLAGS(flags, MODE_PORT4); |
| 9139 | else |
| 9140 | SET_FLAGS(flags, MODE_PORT2); |
| 9141 | |
| 9142 | if (CHIP_IS_E2(bp)) |
| 9143 | SET_FLAGS(flags, MODE_E2); |
| 9144 | else if (CHIP_IS_E3(bp)) { |
| 9145 | SET_FLAGS(flags, MODE_E3); |
| 9146 | if (CHIP_REV(bp) == CHIP_REV_Ax) |
| 9147 | SET_FLAGS(flags, MODE_E3_A0); |
| 9148 | else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/ |
| 9149 | SET_FLAGS(flags, MODE_E3_B0); |
| 9150 | SET_FLAGS(flags, MODE_COS_BC); |
| 9151 | } |
| 9152 | } |
| 9153 | |
| 9154 | if (IS_MF(bp)) { |
| 9155 | SET_FLAGS(flags, MODE_MF); |
| 9156 | switch (bp->mf_mode) { |
| 9157 | case MULTI_FUNCTION_SD: |
| 9158 | SET_FLAGS(flags, MODE_MF_SD); |
| 9159 | break; |
| 9160 | case MULTI_FUNCTION_SI: |
| 9161 | SET_FLAGS(flags, MODE_MF_SI); |
| 9162 | break; |
| 9163 | } |
| 9164 | } else |
| 9165 | SET_FLAGS(flags, MODE_SF); |
| 9166 | |
| 9167 | #if defined(__LITTLE_ENDIAN) |
| 9168 | SET_FLAGS(flags, MODE_LITTLE_ENDIAN); |
| 9169 | #else /*(__BIG_ENDIAN)*/ |
| 9170 | SET_FLAGS(flags, MODE_BIG_ENDIAN); |
| 9171 | #endif |
| 9172 | INIT_MODE_FLAGS(bp) = flags; |
| 9173 | } |
| 9174 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9175 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
| 9176 | { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9177 | int func; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 9178 | int timer_interval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9179 | int rc; |
| 9180 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9181 | mutex_init(&bp->port.phy_mutex); |
Eilon Greenstein | c4ff7cb | 2009-10-15 00:18:27 -0700 | [diff] [blame] | 9182 | mutex_init(&bp->fw_mb_mutex); |
David S. Miller | bb7e95c | 2010-07-27 21:01:35 -0700 | [diff] [blame] | 9183 | spin_lock_init(&bp->stats_lock); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 9184 | #ifdef BCM_CNIC |
| 9185 | mutex_init(&bp->cnic_mutex); |
| 9186 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9187 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 9188 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9189 | INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9190 | |
| 9191 | rc = bnx2x_get_hwinfo(bp); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9192 | if (rc) |
| 9193 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9194 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9195 | bnx2x_set_modes_bitmap(bp); |
| 9196 | |
| 9197 | rc = bnx2x_alloc_mem_bp(bp); |
| 9198 | if (rc) |
| 9199 | return rc; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9200 | |
Vladislav Zolotarov | 34f24c7 | 2010-04-19 01:13:23 +0000 | [diff] [blame] | 9201 | bnx2x_read_fwinfo(bp); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9202 | |
| 9203 | func = BP_FUNC(bp); |
| 9204 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9205 | /* need to reset chip if undi was active */ |
| 9206 | if (!BP_NOMCP(bp)) |
| 9207 | bnx2x_undi_unload(bp); |
| 9208 | |
| 9209 | if (CHIP_REV_IS_FPGA(bp)) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9210 | dev_err(&bp->pdev->dev, "FPGA detected\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9211 | |
| 9212 | if (BP_NOMCP(bp) && (func == 0)) |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9213 | dev_err(&bp->pdev->dev, "MCP disabled, " |
| 9214 | "must load devices in order!\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9215 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 9216 | bp->multi_mode = multi_mode; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 9217 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9218 | /* Set TPA flags */ |
| 9219 | if (disable_tpa) { |
| 9220 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 9221 | bp->dev->features &= ~NETIF_F_LRO; |
| 9222 | } else { |
| 9223 | bp->flags |= TPA_ENABLE_FLAG; |
| 9224 | bp->dev->features |= NETIF_F_LRO; |
| 9225 | } |
Dmitry Kravkov | 5d7cd49 | 2010-07-27 12:32:19 +0000 | [diff] [blame] | 9226 | bp->disable_tpa = disable_tpa; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9227 | |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 9228 | if (CHIP_IS_E1(bp)) |
| 9229 | bp->dropless_fc = 0; |
| 9230 | else |
| 9231 | bp->dropless_fc = dropless_fc; |
| 9232 | |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 9233 | bp->mrrs = mrrs; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9234 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9235 | bp->tx_ring_size = MAX_TX_AVAIL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9236 | |
Eilon Greenstein | 7d323bf | 2009-11-09 06:09:35 +0000 | [diff] [blame] | 9237 | /* make sure that the numbers are in the right granularity */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9238 | bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR; |
| 9239 | bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9240 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 9241 | timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ); |
| 9242 | bp->current_interval = (poll ? poll : timer_interval); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9243 | |
| 9244 | init_timer(&bp->timer); |
| 9245 | bp->timer.expires = jiffies + bp->current_interval; |
| 9246 | bp->timer.data = (unsigned long) bp; |
| 9247 | bp->timer.function = bnx2x_timer; |
| 9248 | |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 9249 | bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON); |
Vladislav Zolotarov | e4901dd | 2010-12-13 05:44:18 +0000 | [diff] [blame] | 9250 | bnx2x_dcbx_init_params(bp); |
| 9251 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9252 | #ifdef BCM_CNIC |
| 9253 | if (CHIP_IS_E1x(bp)) |
| 9254 | bp->cnic_base_cl_id = FP_SB_MAX_E1x; |
| 9255 | else |
| 9256 | bp->cnic_base_cl_id = FP_SB_MAX_E2; |
| 9257 | #endif |
| 9258 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9259 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9260 | } |
| 9261 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9262 | |
Dmitry Kravkov | de0c62d | 2010-07-27 12:35:24 +0000 | [diff] [blame] | 9263 | /**************************************************************************** |
| 9264 | * General service functions |
| 9265 | ****************************************************************************/ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9266 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9267 | /* |
| 9268 | * net_device service functions |
| 9269 | */ |
| 9270 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9271 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9272 | static int bnx2x_open(struct net_device *dev) |
| 9273 | { |
| 9274 | struct bnx2x *bp = netdev_priv(dev); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9275 | bool global = false; |
| 9276 | int other_engine = BP_PATH(bp) ? 0 : 1; |
| 9277 | u32 other_load_counter, load_counter; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9278 | |
Eilon Greenstein | 6eccabb | 2009-01-22 03:37:48 +0000 | [diff] [blame] | 9279 | netif_carrier_off(dev); |
| 9280 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9281 | bnx2x_set_power_state(bp, PCI_D0); |
| 9282 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9283 | other_load_counter = bnx2x_get_load_cnt(bp, other_engine); |
| 9284 | load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp)); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9285 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9286 | /* |
| 9287 | * If parity had happen during the unload, then attentions |
| 9288 | * and/or RECOVERY_IN_PROGRES may still be set. In this case we |
| 9289 | * want the first function loaded on the current engine to |
| 9290 | * complete the recovery. |
| 9291 | */ |
| 9292 | if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || |
| 9293 | bnx2x_chk_parity_attn(bp, &global, true)) |
| 9294 | do { |
| 9295 | /* |
| 9296 | * If there are attentions and they are in a global |
| 9297 | * blocks, set the GLOBAL_RESET bit regardless whether |
| 9298 | * it will be this function that will complete the |
| 9299 | * recovery or not. |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9300 | */ |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9301 | if (global) |
| 9302 | bnx2x_set_reset_global(bp); |
| 9303 | |
| 9304 | /* |
| 9305 | * Only the first function on the current engine should |
| 9306 | * try to recover in open. In case of attentions in |
| 9307 | * global blocks only the first in the chip should try |
| 9308 | * to recover. |
| 9309 | */ |
| 9310 | if ((!load_counter && |
| 9311 | (!global || !other_load_counter)) && |
| 9312 | bnx2x_trylock_leader_lock(bp) && |
| 9313 | !bnx2x_leader_reset(bp)) { |
| 9314 | netdev_info(bp->dev, "Recovered in open\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9315 | break; |
| 9316 | } |
| 9317 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9318 | /* recovery has failed... */ |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9319 | bnx2x_set_power_state(bp, PCI_D3hot); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9320 | bp->recovery_state = BNX2X_RECOVERY_FAILED; |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9321 | |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9322 | netdev_err(bp->dev, "Recovery flow hasn't been properly" |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9323 | " completed yet. Try again later. If u still see this" |
| 9324 | " message after a few retries then power cycle is" |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9325 | " required.\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9326 | |
| 9327 | return -EAGAIN; |
| 9328 | } while (0); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9329 | |
| 9330 | bp->recovery_state = BNX2X_RECOVERY_DONE; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9331 | return bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9332 | } |
| 9333 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9334 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9335 | static int bnx2x_close(struct net_device *dev) |
| 9336 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9337 | struct bnx2x *bp = netdev_priv(dev); |
| 9338 | |
| 9339 | /* Unload the driver, release IRQs */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9340 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
Vladislav Zolotarov | c9ee920 | 2011-06-14 01:33:51 +0000 | [diff] [blame] | 9341 | |
| 9342 | /* Power off */ |
Vladislav Zolotarov | d3dbfee | 2010-04-19 01:14:49 +0000 | [diff] [blame] | 9343 | bnx2x_set_power_state(bp, PCI_D3hot); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9344 | |
| 9345 | return 0; |
| 9346 | } |
| 9347 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9348 | static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp, |
| 9349 | struct bnx2x_mcast_ramrod_params *p) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9350 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9351 | int mc_count = netdev_mc_count(bp->dev); |
| 9352 | struct bnx2x_mcast_list_elem *mc_mac = |
| 9353 | kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9354 | struct netdev_hw_addr *ha; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9355 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9356 | if (!mc_mac) |
| 9357 | return -ENOMEM; |
| 9358 | |
| 9359 | INIT_LIST_HEAD(&p->mcast_list); |
| 9360 | |
| 9361 | netdev_for_each_mc_addr(ha, bp->dev) { |
| 9362 | mc_mac->mac = bnx2x_mc_addr(ha); |
| 9363 | list_add_tail(&mc_mac->link, &p->mcast_list); |
| 9364 | mc_mac++; |
| 9365 | } |
| 9366 | |
| 9367 | p->mcast_list_len = mc_count; |
| 9368 | |
| 9369 | return 0; |
| 9370 | } |
| 9371 | |
| 9372 | static inline void bnx2x_free_mcast_macs_list( |
| 9373 | struct bnx2x_mcast_ramrod_params *p) |
| 9374 | { |
| 9375 | struct bnx2x_mcast_list_elem *mc_mac = |
| 9376 | list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem, |
| 9377 | link); |
| 9378 | |
| 9379 | WARN_ON(!mc_mac); |
| 9380 | kfree(mc_mac); |
| 9381 | } |
| 9382 | |
| 9383 | /** |
| 9384 | * bnx2x_set_uc_list - configure a new unicast MACs list. |
| 9385 | * |
| 9386 | * @bp: driver handle |
| 9387 | * |
| 9388 | * We will use zero (0) as a MAC type for these MACs. |
| 9389 | */ |
| 9390 | static inline int bnx2x_set_uc_list(struct bnx2x *bp) |
| 9391 | { |
| 9392 | int rc; |
| 9393 | struct net_device *dev = bp->dev; |
| 9394 | struct netdev_hw_addr *ha; |
| 9395 | struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj; |
| 9396 | unsigned long ramrod_flags = 0; |
| 9397 | |
| 9398 | /* First schedule a cleanup up of old configuration */ |
| 9399 | rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false); |
| 9400 | if (rc < 0) { |
| 9401 | BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc); |
| 9402 | return rc; |
| 9403 | } |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9404 | |
| 9405 | netdev_for_each_uc_addr(ha, dev) { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9406 | rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true, |
| 9407 | BNX2X_UC_LIST_MAC, &ramrod_flags); |
| 9408 | if (rc < 0) { |
| 9409 | BNX2X_ERR("Failed to schedule ADD operations: %d\n", |
| 9410 | rc); |
| 9411 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9412 | } |
| 9413 | } |
| 9414 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9415 | /* Execute the pending commands */ |
| 9416 | __set_bit(RAMROD_CONT, &ramrod_flags); |
| 9417 | return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */, |
| 9418 | BNX2X_UC_LIST_MAC, &ramrod_flags); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9419 | } |
| 9420 | |
| 9421 | static inline int bnx2x_set_mc_list(struct bnx2x *bp) |
| 9422 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9423 | struct net_device *dev = bp->dev; |
| 9424 | struct bnx2x_mcast_ramrod_params rparam = {0}; |
| 9425 | int rc = 0; |
| 9426 | |
| 9427 | rparam.mcast_obj = &bp->mcast_obj; |
| 9428 | |
| 9429 | /* first, clear all configured multicast MACs */ |
| 9430 | rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL); |
| 9431 | if (rc < 0) { |
| 9432 | BNX2X_ERR("Failed to clear multicast " |
| 9433 | "configuration: %d\n", rc); |
| 9434 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9435 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9436 | |
| 9437 | /* then, configure a new MACs list */ |
| 9438 | if (netdev_mc_count(dev)) { |
| 9439 | rc = bnx2x_init_mcast_macs_list(bp, &rparam); |
| 9440 | if (rc) { |
| 9441 | BNX2X_ERR("Failed to create multicast MACs " |
| 9442 | "list: %d\n", rc); |
| 9443 | return rc; |
| 9444 | } |
| 9445 | |
| 9446 | /* Now add the new MACs */ |
| 9447 | rc = bnx2x_config_mcast(bp, &rparam, |
| 9448 | BNX2X_MCAST_CMD_ADD); |
| 9449 | if (rc < 0) |
| 9450 | BNX2X_ERR("Failed to set a new multicast " |
| 9451 | "configuration: %d\n", rc); |
| 9452 | |
| 9453 | bnx2x_free_mcast_macs_list(&rparam); |
| 9454 | } |
| 9455 | |
| 9456 | return rc; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9457 | } |
| 9458 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9459 | |
| 9460 | /* 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] | 9461 | void bnx2x_set_rx_mode(struct net_device *dev) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9462 | { |
| 9463 | struct bnx2x *bp = netdev_priv(dev); |
| 9464 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9465 | |
| 9466 | if (bp->state != BNX2X_STATE_OPEN) { |
| 9467 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 9468 | return; |
| 9469 | } |
| 9470 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9471 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9472 | |
| 9473 | if (dev->flags & IFF_PROMISC) |
| 9474 | rx_mode = BNX2X_RX_MODE_PROMISC; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9475 | else if ((dev->flags & IFF_ALLMULTI) || |
| 9476 | ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) && |
| 9477 | CHIP_IS_E1(bp))) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9478 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9479 | else { |
| 9480 | /* some multicasts */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9481 | if (bnx2x_set_mc_list(bp) < 0) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9482 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9483 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9484 | if (bnx2x_set_uc_list(bp) < 0) |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9485 | rx_mode = BNX2X_RX_MODE_PROMISC; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9486 | } |
| 9487 | |
| 9488 | bp->rx_mode = rx_mode; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9489 | |
| 9490 | /* Schedule the rx_mode command */ |
| 9491 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) { |
| 9492 | set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state); |
| 9493 | return; |
| 9494 | } |
| 9495 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9496 | bnx2x_set_storm_rx_mode(bp); |
| 9497 | } |
| 9498 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9499 | /* called with rtnl_lock */ |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9500 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
| 9501 | int devad, u16 addr) |
| 9502 | { |
| 9503 | struct bnx2x *bp = netdev_priv(netdev); |
| 9504 | u16 value; |
| 9505 | int rc; |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9506 | |
| 9507 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
| 9508 | prtad, devad, addr); |
| 9509 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9510 | /* The HW expects different devad if CL22 is used */ |
| 9511 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 9512 | |
| 9513 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | e10bc84 | 2010-09-07 11:40:50 +0000 | [diff] [blame] | 9514 | rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9515 | bnx2x_release_phy_lock(bp); |
| 9516 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); |
| 9517 | |
| 9518 | if (!rc) |
| 9519 | rc = value; |
| 9520 | return rc; |
| 9521 | } |
| 9522 | |
| 9523 | /* called with rtnl_lock */ |
| 9524 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 9525 | u16 addr, u16 value) |
| 9526 | { |
| 9527 | struct bnx2x *bp = netdev_priv(netdev); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9528 | int rc; |
| 9529 | |
| 9530 | DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x," |
| 9531 | " value 0x%x\n", prtad, devad, addr, value); |
| 9532 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9533 | /* The HW expects different devad if CL22 is used */ |
| 9534 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 9535 | |
| 9536 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | e10bc84 | 2010-09-07 11:40:50 +0000 | [diff] [blame] | 9537 | rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9538 | bnx2x_release_phy_lock(bp); |
| 9539 | return rc; |
| 9540 | } |
| 9541 | |
| 9542 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9543 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 9544 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9545 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9546 | struct mii_ioctl_data *mdio = if_mii(ifr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9547 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9548 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
| 9549 | mdio->phy_id, mdio->reg_num, mdio->val_in); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9550 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9551 | if (!netif_running(dev)) |
| 9552 | return -EAGAIN; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9553 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9554 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9555 | } |
| 9556 | |
Alexey Dobriyan | 257ddbd | 2010-01-27 10:17:41 +0000 | [diff] [blame] | 9557 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9558 | static void poll_bnx2x(struct net_device *dev) |
| 9559 | { |
| 9560 | struct bnx2x *bp = netdev_priv(dev); |
| 9561 | |
| 9562 | disable_irq(bp->pdev->irq); |
| 9563 | bnx2x_interrupt(bp->pdev->irq, dev); |
| 9564 | enable_irq(bp->pdev->irq); |
| 9565 | } |
| 9566 | #endif |
| 9567 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9568 | static const struct net_device_ops bnx2x_netdev_ops = { |
| 9569 | .ndo_open = bnx2x_open, |
| 9570 | .ndo_stop = bnx2x_close, |
| 9571 | .ndo_start_xmit = bnx2x_start_xmit, |
Vladislav Zolotarov | 8307fa3 | 2010-12-13 05:44:09 +0000 | [diff] [blame] | 9572 | .ndo_select_queue = bnx2x_select_queue, |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 9573 | .ndo_set_rx_mode = bnx2x_set_rx_mode, |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9574 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
| 9575 | .ndo_validate_addr = eth_validate_addr, |
| 9576 | .ndo_do_ioctl = bnx2x_ioctl, |
| 9577 | .ndo_change_mtu = bnx2x_change_mtu, |
Michał Mirosław | 66371c4 | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 9578 | .ndo_fix_features = bnx2x_fix_features, |
| 9579 | .ndo_set_features = bnx2x_set_features, |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9580 | .ndo_tx_timeout = bnx2x_tx_timeout, |
Alexey Dobriyan | 257ddbd | 2010-01-27 10:17:41 +0000 | [diff] [blame] | 9581 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9582 | .ndo_poll_controller = poll_bnx2x, |
| 9583 | #endif |
| 9584 | }; |
| 9585 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9586 | static inline int bnx2x_set_coherency_mask(struct bnx2x *bp) |
| 9587 | { |
| 9588 | struct device *dev = &bp->pdev->dev; |
| 9589 | |
| 9590 | if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { |
| 9591 | bp->flags |= USING_DAC_FLAG; |
| 9592 | if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { |
| 9593 | dev_err(dev, "dma_set_coherent_mask failed, " |
| 9594 | "aborting\n"); |
| 9595 | return -EIO; |
| 9596 | } |
| 9597 | } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) { |
| 9598 | dev_err(dev, "System does not support DMA, aborting\n"); |
| 9599 | return -EIO; |
| 9600 | } |
| 9601 | |
| 9602 | return 0; |
| 9603 | } |
| 9604 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9605 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9606 | struct net_device *dev, |
| 9607 | unsigned long board_type) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9608 | { |
| 9609 | struct bnx2x *bp; |
| 9610 | int rc; |
| 9611 | |
| 9612 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 9613 | bp = netdev_priv(dev); |
| 9614 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9615 | bp->dev = dev; |
| 9616 | bp->pdev = pdev; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9617 | bp->flags = 0; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9618 | bp->pf_num = PCI_FUNC(pdev->devfn); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9619 | |
| 9620 | rc = pci_enable_device(pdev); |
| 9621 | if (rc) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9622 | dev_err(&bp->pdev->dev, |
| 9623 | "Cannot enable PCI device, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9624 | goto err_out; |
| 9625 | } |
| 9626 | |
| 9627 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9628 | dev_err(&bp->pdev->dev, |
| 9629 | "Cannot find PCI device base address, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9630 | rc = -ENODEV; |
| 9631 | goto err_out_disable; |
| 9632 | } |
| 9633 | |
| 9634 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9635 | dev_err(&bp->pdev->dev, "Cannot find second PCI device" |
| 9636 | " base address, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9637 | rc = -ENODEV; |
| 9638 | goto err_out_disable; |
| 9639 | } |
| 9640 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9641 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 9642 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 9643 | if (rc) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9644 | dev_err(&bp->pdev->dev, |
| 9645 | "Cannot obtain PCI resources, aborting\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9646 | goto err_out_disable; |
| 9647 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9648 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9649 | pci_set_master(pdev); |
| 9650 | pci_save_state(pdev); |
| 9651 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9652 | |
| 9653 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 9654 | if (bp->pm_cap == 0) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9655 | dev_err(&bp->pdev->dev, |
| 9656 | "Cannot find power management capability, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9657 | rc = -EIO; |
| 9658 | goto err_out_release; |
| 9659 | } |
| 9660 | |
| 9661 | bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 9662 | if (bp->pcie_cap == 0) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9663 | dev_err(&bp->pdev->dev, |
| 9664 | "Cannot find PCI Express capability, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9665 | rc = -EIO; |
| 9666 | goto err_out_release; |
| 9667 | } |
| 9668 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9669 | rc = bnx2x_set_coherency_mask(bp); |
| 9670 | if (rc) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9671 | goto err_out_release; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9672 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9673 | dev->mem_start = pci_resource_start(pdev, 0); |
| 9674 | dev->base_addr = dev->mem_start; |
| 9675 | dev->mem_end = pci_resource_end(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9676 | |
| 9677 | dev->irq = pdev->irq; |
| 9678 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 9679 | bp->regview = pci_ioremap_bar(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9680 | if (!bp->regview) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9681 | dev_err(&bp->pdev->dev, |
| 9682 | "Cannot map register space, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9683 | rc = -ENOMEM; |
| 9684 | goto err_out_release; |
| 9685 | } |
| 9686 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9687 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9688 | min_t(u64, BNX2X_DB_SIZE(bp), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9689 | pci_resource_len(pdev, 2))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9690 | if (!bp->doorbells) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9691 | dev_err(&bp->pdev->dev, |
| 9692 | "Cannot map doorbell space, aborting\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9693 | rc = -ENOMEM; |
| 9694 | goto err_out_unmap; |
| 9695 | } |
| 9696 | |
| 9697 | bnx2x_set_power_state(bp, PCI_D0); |
| 9698 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9699 | /* clean indirect addresses */ |
| 9700 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 9701 | PCICFG_VENDOR_ID_OFFSET); |
| 9702 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0); |
| 9703 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0); |
| 9704 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0); |
| 9705 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9706 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9707 | /** |
| 9708 | * Enable internal target-read (in case we are probed after PF FLR). |
| 9709 | * Must be done prior to any BAR read access |
| 9710 | */ |
| 9711 | REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); |
| 9712 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 9713 | /* Reset the load counter */ |
| 9714 | bnx2x_clear_load_cnt(bp); |
| 9715 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9716 | dev->watchdog_timeo = TX_TIMEOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9717 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 9718 | dev->netdev_ops = &bnx2x_netdev_ops; |
Dmitry Kravkov | de0c62d | 2010-07-27 12:35:24 +0000 | [diff] [blame] | 9719 | bnx2x_set_ethtool_ops(dev); |
Michał Mirosław | 66371c4 | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 9720 | |
| 9721 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 9722 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | |
| 9723 | NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX; |
| 9724 | |
| 9725 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 9726 | NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; |
| 9727 | |
| 9728 | dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9729 | if (bp->flags & USING_DAC_FLAG) |
| 9730 | dev->features |= NETIF_F_HIGHDMA; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9731 | |
Mahesh Bandewar | 538dd2e | 2011-05-13 15:08:49 +0000 | [diff] [blame] | 9732 | /* Add Loopback capability to the device */ |
| 9733 | dev->hw_features |= NETIF_F_LOOPBACK; |
| 9734 | |
Shmulik Ravid | 9850767 | 2011-02-28 12:19:55 -0800 | [diff] [blame] | 9735 | #ifdef BCM_DCBNL |
Shmulik Ravid | 785b9b1 | 2010-12-30 06:27:03 +0000 | [diff] [blame] | 9736 | dev->dcbnl_ops = &bnx2x_dcbnl_ops; |
| 9737 | #endif |
| 9738 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 9739 | /* get_port_hwinfo() will set prtad and mmds properly */ |
| 9740 | bp->mdio.prtad = MDIO_PRTAD_NONE; |
| 9741 | bp->mdio.mmds = 0; |
| 9742 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9743 | bp->mdio.dev = dev; |
| 9744 | bp->mdio.mdio_read = bnx2x_mdio_read; |
| 9745 | bp->mdio.mdio_write = bnx2x_mdio_write; |
| 9746 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9747 | return 0; |
| 9748 | |
| 9749 | err_out_unmap: |
| 9750 | if (bp->regview) { |
| 9751 | iounmap(bp->regview); |
| 9752 | bp->regview = NULL; |
| 9753 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9754 | if (bp->doorbells) { |
| 9755 | iounmap(bp->doorbells); |
| 9756 | bp->doorbells = NULL; |
| 9757 | } |
| 9758 | |
| 9759 | err_out_release: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9760 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 9761 | pci_release_regions(pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9762 | |
| 9763 | err_out_disable: |
| 9764 | pci_disable_device(pdev); |
| 9765 | pci_set_drvdata(pdev, NULL); |
| 9766 | |
| 9767 | err_out: |
| 9768 | return rc; |
| 9769 | } |
| 9770 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9771 | static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp, |
| 9772 | int *width, int *speed) |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 9773 | { |
| 9774 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 9775 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9776 | *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
| 9777 | |
| 9778 | /* return value of 1=2.5GHz 2=5GHz */ |
| 9779 | *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 9780 | } |
| 9781 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9782 | static int bnx2x_check_firmware(struct bnx2x *bp) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9783 | { |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9784 | const struct firmware *firmware = bp->firmware; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9785 | struct bnx2x_fw_file_hdr *fw_hdr; |
| 9786 | struct bnx2x_fw_file_section *sections; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9787 | u32 offset, len, num_ops; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9788 | u16 *ops_offsets; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9789 | int i; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 9790 | const u8 *fw_ver; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9791 | |
| 9792 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) |
| 9793 | return -EINVAL; |
| 9794 | |
| 9795 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; |
| 9796 | sections = (struct bnx2x_fw_file_section *)fw_hdr; |
| 9797 | |
| 9798 | /* Make sure none of the offsets and sizes make us read beyond |
| 9799 | * the end of the firmware data */ |
| 9800 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { |
| 9801 | offset = be32_to_cpu(sections[i].offset); |
| 9802 | len = be32_to_cpu(sections[i].len); |
| 9803 | if (offset + len > firmware->size) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9804 | dev_err(&bp->pdev->dev, |
| 9805 | "Section %d length is out of bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9806 | return -EINVAL; |
| 9807 | } |
| 9808 | } |
| 9809 | |
| 9810 | /* Likewise for the init_ops offsets */ |
| 9811 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); |
| 9812 | ops_offsets = (u16 *)(firmware->data + offset); |
| 9813 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); |
| 9814 | |
| 9815 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { |
| 9816 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9817 | dev_err(&bp->pdev->dev, |
| 9818 | "Section offset %d is out of bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9819 | return -EINVAL; |
| 9820 | } |
| 9821 | } |
| 9822 | |
| 9823 | /* Check FW version */ |
| 9824 | offset = be32_to_cpu(fw_hdr->fw_version.offset); |
| 9825 | fw_ver = firmware->data + offset; |
| 9826 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || |
| 9827 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || |
| 9828 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || |
| 9829 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9830 | dev_err(&bp->pdev->dev, |
| 9831 | "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] | 9832 | fw_ver[0], fw_ver[1], fw_ver[2], |
| 9833 | fw_ver[3], BCM_5710_FW_MAJOR_VERSION, |
| 9834 | BCM_5710_FW_MINOR_VERSION, |
| 9835 | BCM_5710_FW_REVISION_VERSION, |
| 9836 | BCM_5710_FW_ENGINEERING_VERSION); |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9837 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9838 | } |
| 9839 | |
| 9840 | return 0; |
| 9841 | } |
| 9842 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9843 | 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] | 9844 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9845 | const __be32 *source = (const __be32 *)_source; |
| 9846 | u32 *target = (u32 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9847 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9848 | |
| 9849 | for (i = 0; i < n/4; i++) |
| 9850 | target[i] = be32_to_cpu(source[i]); |
| 9851 | } |
| 9852 | |
| 9853 | /* |
| 9854 | Ops array is stored in the following format: |
| 9855 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} |
| 9856 | */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9857 | 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] | 9858 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9859 | const __be32 *source = (const __be32 *)_source; |
| 9860 | struct raw_op *target = (struct raw_op *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9861 | u32 i, j, tmp; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9862 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9863 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9864 | tmp = be32_to_cpu(source[j]); |
| 9865 | target[i].op = (tmp >> 24) & 0xff; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9866 | target[i].offset = tmp & 0xffffff; |
| 9867 | target[i].raw_data = be32_to_cpu(source[j + 1]); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9868 | } |
| 9869 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9870 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9871 | /** |
| 9872 | * IRO array is stored in the following format: |
| 9873 | * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) } |
| 9874 | */ |
| 9875 | static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n) |
| 9876 | { |
| 9877 | const __be32 *source = (const __be32 *)_source; |
| 9878 | struct iro *target = (struct iro *)_target; |
| 9879 | u32 i, j, tmp; |
| 9880 | |
| 9881 | for (i = 0, j = 0; i < n/sizeof(struct iro); i++) { |
| 9882 | target[i].base = be32_to_cpu(source[j]); |
| 9883 | j++; |
| 9884 | tmp = be32_to_cpu(source[j]); |
| 9885 | target[i].m1 = (tmp >> 16) & 0xffff; |
| 9886 | target[i].m2 = tmp & 0xffff; |
| 9887 | j++; |
| 9888 | tmp = be32_to_cpu(source[j]); |
| 9889 | target[i].m3 = (tmp >> 16) & 0xffff; |
| 9890 | target[i].size = tmp & 0xffff; |
| 9891 | j++; |
| 9892 | } |
| 9893 | } |
| 9894 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9895 | 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] | 9896 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9897 | const __be16 *source = (const __be16 *)_source; |
| 9898 | u16 *target = (u16 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9899 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9900 | |
| 9901 | for (i = 0; i < n/2; i++) |
| 9902 | target[i] = be16_to_cpu(source[i]); |
| 9903 | } |
| 9904 | |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 9905 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
| 9906 | do { \ |
| 9907 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ |
| 9908 | bp->arr = kmalloc(len, GFP_KERNEL); \ |
| 9909 | if (!bp->arr) { \ |
| 9910 | pr_err("Failed to allocate %d bytes for "#arr"\n", len); \ |
| 9911 | goto lbl; \ |
| 9912 | } \ |
| 9913 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
| 9914 | (u8 *)bp->arr, len); \ |
| 9915 | } while (0) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9916 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9917 | int bnx2x_init_firmware(struct bnx2x *bp) |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9918 | { |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9919 | const char *fw_file_name; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9920 | struct bnx2x_fw_file_hdr *fw_hdr; |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9921 | int rc; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9922 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9923 | if (CHIP_IS_E1(bp)) |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9924 | fw_file_name = FW_FILE_NAME_E1; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9925 | else if (CHIP_IS_E1H(bp)) |
Ben Hutchings | 45229b4 | 2009-11-07 11:53:39 +0000 | [diff] [blame] | 9926 | fw_file_name = FW_FILE_NAME_E1H; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9927 | else if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 9928 | fw_file_name = FW_FILE_NAME_E2; |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9929 | else { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9930 | BNX2X_ERR("Unsupported chip revision\n"); |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 9931 | return -EINVAL; |
| 9932 | } |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9933 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9934 | BNX2X_DEV_INFO("Loading %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9935 | |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9936 | rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9937 | if (rc) { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9938 | BNX2X_ERR("Can't load firmware file %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9939 | goto request_firmware_exit; |
| 9940 | } |
| 9941 | |
| 9942 | rc = bnx2x_check_firmware(bp); |
| 9943 | if (rc) { |
Dmitry Kravkov | 6891dd2 | 2010-08-03 21:49:40 +0000 | [diff] [blame] | 9944 | BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9945 | goto request_firmware_exit; |
| 9946 | } |
| 9947 | |
| 9948 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; |
| 9949 | |
| 9950 | /* Initialize the pointers to the init arrays */ |
| 9951 | /* Blob */ |
| 9952 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); |
| 9953 | |
| 9954 | /* Opcodes */ |
| 9955 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); |
| 9956 | |
| 9957 | /* Offsets */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9958 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
| 9959 | be16_to_cpu_n); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9960 | |
| 9961 | /* STORMs firmware */ |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 9962 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9963 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); |
| 9964 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9965 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); |
| 9966 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9967 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); |
| 9968 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9969 | be32_to_cpu(fw_hdr->usem_pram_data.offset); |
| 9970 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9971 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); |
| 9972 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9973 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); |
| 9974 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 9975 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); |
| 9976 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 9977 | be32_to_cpu(fw_hdr->csem_pram_data.offset); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9978 | /* IRO */ |
| 9979 | BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9980 | |
| 9981 | return 0; |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9982 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 9983 | iro_alloc_err: |
| 9984 | kfree(bp->init_ops_offsets); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 9985 | init_offsets_alloc_err: |
| 9986 | kfree(bp->init_ops); |
| 9987 | init_ops_alloc_err: |
| 9988 | kfree(bp->init_data); |
| 9989 | request_firmware_exit: |
| 9990 | release_firmware(bp->firmware); |
| 9991 | |
| 9992 | return rc; |
| 9993 | } |
| 9994 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 9995 | static void bnx2x_release_firmware(struct bnx2x *bp) |
| 9996 | { |
| 9997 | kfree(bp->init_ops_offsets); |
| 9998 | kfree(bp->init_ops); |
| 9999 | kfree(bp->init_data); |
| 10000 | release_firmware(bp->firmware); |
| 10001 | } |
| 10002 | |
| 10003 | |
| 10004 | static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = { |
| 10005 | .init_hw_cmn_chip = bnx2x_init_hw_common_chip, |
| 10006 | .init_hw_cmn = bnx2x_init_hw_common, |
| 10007 | .init_hw_port = bnx2x_init_hw_port, |
| 10008 | .init_hw_func = bnx2x_init_hw_func, |
| 10009 | |
| 10010 | .reset_hw_cmn = bnx2x_reset_common, |
| 10011 | .reset_hw_port = bnx2x_reset_port, |
| 10012 | .reset_hw_func = bnx2x_reset_func, |
| 10013 | |
| 10014 | .gunzip_init = bnx2x_gunzip_init, |
| 10015 | .gunzip_end = bnx2x_gunzip_end, |
| 10016 | |
| 10017 | .init_fw = bnx2x_init_firmware, |
| 10018 | .release_fw = bnx2x_release_firmware, |
| 10019 | }; |
| 10020 | |
| 10021 | void bnx2x__init_func_obj(struct bnx2x *bp) |
| 10022 | { |
| 10023 | /* Prepare DMAE related driver resources */ |
| 10024 | bnx2x_setup_dmae(bp); |
| 10025 | |
| 10026 | bnx2x_init_func_obj(bp, &bp->func_obj, |
| 10027 | bnx2x_sp(bp, func_rdata), |
| 10028 | bnx2x_sp_mapping(bp, func_rdata), |
| 10029 | &bnx2x_func_sp_drv); |
| 10030 | } |
| 10031 | |
| 10032 | /* must be called after sriov-enable */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10033 | static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count) |
| 10034 | { |
| 10035 | int cid_count = L2_FP_COUNT(l2_cid_count); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 10036 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10037 | #ifdef BCM_CNIC |
| 10038 | cid_count += CNIC_CID_MAX; |
| 10039 | #endif |
| 10040 | return roundup(cid_count, QM_CID_ROUND); |
| 10041 | } |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10042 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10043 | /** |
| 10044 | * bnx2x_pci_msix_table_size - get the size of the MSI-X table. |
| 10045 | * |
| 10046 | * @dev: pci device |
| 10047 | * |
| 10048 | */ |
| 10049 | static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev) |
| 10050 | { |
| 10051 | int pos; |
| 10052 | u16 control; |
| 10053 | |
| 10054 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 10055 | if (!pos) |
| 10056 | return 0; |
| 10057 | |
| 10058 | pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control); |
| 10059 | return (control & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 10060 | } |
| 10061 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10062 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
| 10063 | const struct pci_device_id *ent) |
| 10064 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10065 | struct net_device *dev = NULL; |
| 10066 | struct bnx2x *bp; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 10067 | int pcie_width, pcie_speed; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10068 | int rc, cid_count; |
| 10069 | |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10070 | switch (ent->driver_data) { |
| 10071 | case BCM57710: |
| 10072 | case BCM57711: |
| 10073 | case BCM57711E: |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10074 | case BCM57712: |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10075 | case BCM57712_MF: |
| 10076 | case BCM57800: |
| 10077 | case BCM57800_MF: |
| 10078 | case BCM57810: |
| 10079 | case BCM57810_MF: |
| 10080 | case BCM57840: |
| 10081 | case BCM57840_MF: |
| 10082 | /* The size requested for the MSI-X table corresponds to the |
| 10083 | * actual amount of avaliable IGU/HC status blocks. It includes |
| 10084 | * the default SB vector but we want cid_count to contain the |
| 10085 | * amount of only non-default SBs, that's what '-1' stands for. |
| 10086 | */ |
| 10087 | cid_count = bnx2x_pci_msix_table_size(pdev) - 1; |
| 10088 | |
| 10089 | /* do not allow initial cid_count grow above 16 |
| 10090 | * since Special CIDs starts from this number |
| 10091 | * use old FP_SB_MAX_E1x define for this matter |
| 10092 | */ |
| 10093 | cid_count = min_t(int, FP_SB_MAX_E1x, cid_count); |
| 10094 | |
| 10095 | WARN_ON(!cid_count); |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10096 | break; |
| 10097 | |
| 10098 | default: |
| 10099 | pr_err("Unknown board_type (%ld), aborting\n", |
| 10100 | ent->driver_data); |
Vasiliy Kulikov | 870634b | 2010-11-14 10:08:34 +0000 | [diff] [blame] | 10101 | return -ENODEV; |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10102 | } |
| 10103 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10104 | cid_count += FCOE_CONTEXT_USE; |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10105 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10106 | /* dev zeroed in init_etherdev */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10107 | dev = alloc_etherdev_mq(sizeof(*bp), cid_count); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10108 | if (!dev) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10109 | dev_err(&pdev->dev, "Cannot allocate net device\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10110 | return -ENOMEM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10111 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10112 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10113 | /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring, |
| 10114 | * so update a cid_count after a netdev allocation. |
| 10115 | */ |
| 10116 | cid_count += CNIC_CONTEXT_USE; |
| 10117 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10118 | bp = netdev_priv(dev); |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10119 | bp->msg_enable = debug; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10120 | |
Eilon Greenstein | df4770de | 2009-08-12 08:23:28 +0000 | [diff] [blame] | 10121 | pci_set_drvdata(pdev, dev); |
| 10122 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10123 | bp->l2_cid_count = cid_count; |
| 10124 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10125 | rc = bnx2x_init_dev(pdev, dev, ent->driver_data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10126 | if (rc < 0) { |
| 10127 | free_netdev(dev); |
| 10128 | return rc; |
| 10129 | } |
| 10130 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10131 | BNX2X_DEV_INFO("cid_count=%d\n", cid_count); |
| 10132 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10133 | rc = bnx2x_init_bp(bp); |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 10134 | if (rc) |
| 10135 | goto init_one_exit; |
| 10136 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10137 | /* calc qm_cid_count */ |
| 10138 | bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count); |
| 10139 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10140 | #ifdef BCM_CNIC |
| 10141 | /* disable FCOE L2 queue for E1x*/ |
| 10142 | if (CHIP_IS_E1x(bp)) |
| 10143 | bp->flags |= NO_FCOE_FLAG; |
| 10144 | |
| 10145 | #endif |
| 10146 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10147 | /* Configure interrupt mode: try to enable MSI-X/MSI if |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10148 | * needed, set bp->num_queues appropriately. |
| 10149 | */ |
| 10150 | bnx2x_set_int_mode(bp); |
| 10151 | |
| 10152 | /* Add all NAPI objects */ |
| 10153 | bnx2x_add_all_napi(bp); |
| 10154 | |
Vladislav Zolotarov | b340007 | 2010-11-24 11:09:50 -0800 | [diff] [blame] | 10155 | rc = register_netdev(dev); |
| 10156 | if (rc) { |
| 10157 | dev_err(&pdev->dev, "Cannot register net device\n"); |
| 10158 | goto init_one_exit; |
| 10159 | } |
| 10160 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10161 | #ifdef BCM_CNIC |
| 10162 | if (!NO_FCOE(bp)) { |
| 10163 | /* Add storage MAC address */ |
| 10164 | rtnl_lock(); |
| 10165 | dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); |
| 10166 | rtnl_unlock(); |
| 10167 | } |
| 10168 | #endif |
| 10169 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 10170 | bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed); |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10171 | |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10172 | netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx," |
| 10173 | " IRQ %d, ", board_info[ent->driver_data].name, |
| 10174 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10175 | pcie_width, |
| 10176 | ((!CHIP_IS_E2(bp) && pcie_speed == 2) || |
| 10177 | (CHIP_IS_E2(bp) && pcie_speed == 1)) ? |
| 10178 | "5GHz (Gen2)" : "2.5GHz", |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10179 | dev->base_addr, bp->pdev->irq); |
| 10180 | pr_cont("node addr %pM\n", dev->dev_addr); |
Eilon Greenstein | c016201 | 2009-03-02 08:01:05 +0000 | [diff] [blame] | 10181 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10182 | return 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10183 | |
| 10184 | init_one_exit: |
| 10185 | if (bp->regview) |
| 10186 | iounmap(bp->regview); |
| 10187 | |
| 10188 | if (bp->doorbells) |
| 10189 | iounmap(bp->doorbells); |
| 10190 | |
| 10191 | free_netdev(dev); |
| 10192 | |
| 10193 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10194 | pci_release_regions(pdev); |
| 10195 | |
| 10196 | pci_disable_device(pdev); |
| 10197 | pci_set_drvdata(pdev, NULL); |
| 10198 | |
| 10199 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10200 | } |
| 10201 | |
| 10202 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) |
| 10203 | { |
| 10204 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10205 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10206 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10207 | if (!dev) { |
Vladislav Zolotarov | cdaa7cb | 2010-04-19 01:13:57 +0000 | [diff] [blame] | 10208 | dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n"); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10209 | return; |
| 10210 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10211 | bp = netdev_priv(dev); |
| 10212 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10213 | #ifdef BCM_CNIC |
| 10214 | /* Delete storage MAC address */ |
| 10215 | if (!NO_FCOE(bp)) { |
| 10216 | rtnl_lock(); |
| 10217 | dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN); |
| 10218 | rtnl_unlock(); |
| 10219 | } |
| 10220 | #endif |
| 10221 | |
Shmulik Ravid | 9850767 | 2011-02-28 12:19:55 -0800 | [diff] [blame] | 10222 | #ifdef BCM_DCBNL |
| 10223 | /* Delete app tlvs from dcbnl */ |
| 10224 | bnx2x_dcbnl_update_applist(bp, true); |
| 10225 | #endif |
| 10226 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10227 | unregister_netdev(dev); |
| 10228 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10229 | /* Delete all NAPI objects */ |
| 10230 | bnx2x_del_all_napi(bp); |
| 10231 | |
Vladislav Zolotarov | 084d6cb | 2011-01-09 02:20:19 +0000 | [diff] [blame] | 10232 | /* Power on: we can't let PCI layer write to us while we are in D3 */ |
| 10233 | bnx2x_set_power_state(bp, PCI_D0); |
| 10234 | |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10235 | /* Disable MSI/MSI-X */ |
| 10236 | bnx2x_disable_msi(bp); |
Dmitry Kravkov | f85582f | 2010-10-06 03:34:21 +0000 | [diff] [blame] | 10237 | |
Vladislav Zolotarov | 084d6cb | 2011-01-09 02:20:19 +0000 | [diff] [blame] | 10238 | /* Power off */ |
| 10239 | bnx2x_set_power_state(bp, PCI_D3hot); |
| 10240 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10241 | /* Make sure RESET task is not scheduled before continuing */ |
| 10242 | cancel_delayed_work_sync(&bp->reset_task); |
| 10243 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10244 | if (bp->regview) |
| 10245 | iounmap(bp->regview); |
| 10246 | |
| 10247 | if (bp->doorbells) |
| 10248 | iounmap(bp->doorbells); |
| 10249 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10250 | bnx2x_free_mem_bp(bp); |
| 10251 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10252 | free_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10253 | |
| 10254 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10255 | pci_release_regions(pdev); |
| 10256 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10257 | pci_disable_device(pdev); |
| 10258 | pci_set_drvdata(pdev, NULL); |
| 10259 | } |
| 10260 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10261 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
| 10262 | { |
| 10263 | int i; |
| 10264 | |
| 10265 | bp->state = BNX2X_STATE_ERROR; |
| 10266 | |
| 10267 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 10268 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10269 | #ifdef BCM_CNIC |
| 10270 | bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD); |
| 10271 | #endif |
| 10272 | /* Stop Tx */ |
| 10273 | bnx2x_tx_disable(bp); |
| 10274 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10275 | bnx2x_netif_stop(bp, 0); |
| 10276 | |
| 10277 | del_timer_sync(&bp->timer); |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10278 | |
| 10279 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10280 | |
| 10281 | /* Release IRQs */ |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10282 | bnx2x_free_irq(bp); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10283 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10284 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 10285 | bnx2x_free_skbs(bp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10286 | |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10287 | for_each_rx_queue(bp, i) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10288 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Dmitry Kravkov | d6214d7 | 2010-10-06 03:32:10 +0000 | [diff] [blame] | 10289 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10290 | bnx2x_free_mem(bp); |
| 10291 | |
| 10292 | bp->state = BNX2X_STATE_CLOSED; |
| 10293 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10294 | netif_carrier_off(bp->dev); |
| 10295 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10296 | return 0; |
| 10297 | } |
| 10298 | |
| 10299 | static void bnx2x_eeh_recover(struct bnx2x *bp) |
| 10300 | { |
| 10301 | u32 val; |
| 10302 | |
| 10303 | mutex_init(&bp->port.phy_mutex); |
| 10304 | |
| 10305 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 10306 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 10307 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 10308 | |
| 10309 | if (!bp->common.shmem_base || |
| 10310 | (bp->common.shmem_base < 0xA0000) || |
| 10311 | (bp->common.shmem_base >= 0xC0000)) { |
| 10312 | BNX2X_DEV_INFO("MCP not active\n"); |
| 10313 | bp->flags |= NO_MCP_FLAG; |
| 10314 | return; |
| 10315 | } |
| 10316 | |
| 10317 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 10318 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 10319 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 10320 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 10321 | |
| 10322 | if (!BP_NOMCP(bp)) { |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10323 | bp->fw_seq = |
| 10324 | (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) & |
| 10325 | DRV_MSG_SEQ_NUMBER_MASK); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10326 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 10327 | } |
| 10328 | } |
| 10329 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10330 | /** |
| 10331 | * bnx2x_io_error_detected - called when PCI error is detected |
| 10332 | * @pdev: Pointer to PCI device |
| 10333 | * @state: The current pci connection state |
| 10334 | * |
| 10335 | * This function is called after a PCI bus error affecting |
| 10336 | * this device has been detected. |
| 10337 | */ |
| 10338 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, |
| 10339 | pci_channel_state_t state) |
| 10340 | { |
| 10341 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10342 | struct bnx2x *bp = netdev_priv(dev); |
| 10343 | |
| 10344 | rtnl_lock(); |
| 10345 | |
| 10346 | netif_device_detach(dev); |
| 10347 | |
Dean Nelson | 07ce50e | 2009-07-31 09:13:25 +0000 | [diff] [blame] | 10348 | if (state == pci_channel_io_perm_failure) { |
| 10349 | rtnl_unlock(); |
| 10350 | return PCI_ERS_RESULT_DISCONNECT; |
| 10351 | } |
| 10352 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10353 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10354 | bnx2x_eeh_nic_unload(bp); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10355 | |
| 10356 | pci_disable_device(pdev); |
| 10357 | |
| 10358 | rtnl_unlock(); |
| 10359 | |
| 10360 | /* Request a slot reset */ |
| 10361 | return PCI_ERS_RESULT_NEED_RESET; |
| 10362 | } |
| 10363 | |
| 10364 | /** |
| 10365 | * bnx2x_io_slot_reset - called after the PCI bus has been reset |
| 10366 | * @pdev: Pointer to PCI device |
| 10367 | * |
| 10368 | * Restart the card from scratch, as if from a cold-boot. |
| 10369 | */ |
| 10370 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) |
| 10371 | { |
| 10372 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10373 | struct bnx2x *bp = netdev_priv(dev); |
| 10374 | |
| 10375 | rtnl_lock(); |
| 10376 | |
| 10377 | if (pci_enable_device(pdev)) { |
| 10378 | dev_err(&pdev->dev, |
| 10379 | "Cannot re-enable PCI device after reset\n"); |
| 10380 | rtnl_unlock(); |
| 10381 | return PCI_ERS_RESULT_DISCONNECT; |
| 10382 | } |
| 10383 | |
| 10384 | pci_set_master(pdev); |
| 10385 | pci_restore_state(pdev); |
| 10386 | |
| 10387 | if (netif_running(dev)) |
| 10388 | bnx2x_set_power_state(bp, PCI_D0); |
| 10389 | |
| 10390 | rtnl_unlock(); |
| 10391 | |
| 10392 | return PCI_ERS_RESULT_RECOVERED; |
| 10393 | } |
| 10394 | |
| 10395 | /** |
| 10396 | * bnx2x_io_resume - called when traffic can start flowing again |
| 10397 | * @pdev: Pointer to PCI device |
| 10398 | * |
| 10399 | * This callback is called when the error recovery driver tells us that |
| 10400 | * its OK to resume normal operation. |
| 10401 | */ |
| 10402 | static void bnx2x_io_resume(struct pci_dev *pdev) |
| 10403 | { |
| 10404 | struct net_device *dev = pci_get_drvdata(pdev); |
| 10405 | struct bnx2x *bp = netdev_priv(dev); |
| 10406 | |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10407 | if (bp->recovery_state != BNX2X_RECOVERY_DONE) { |
Dmitry Kravkov | 754a2f5 | 2011-06-14 01:34:02 +0000 | [diff] [blame^] | 10408 | netdev_err(bp->dev, "Handling parity error recovery. " |
| 10409 | "Try again later\n"); |
Vladislav Zolotarov | 72fd071 | 2010-04-19 01:13:12 +0000 | [diff] [blame] | 10410 | return; |
| 10411 | } |
| 10412 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10413 | rtnl_lock(); |
| 10414 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10415 | bnx2x_eeh_recover(bp); |
| 10416 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10417 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10418 | bnx2x_nic_load(bp, LOAD_NORMAL); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10419 | |
| 10420 | netif_device_attach(dev); |
| 10421 | |
| 10422 | rtnl_unlock(); |
| 10423 | } |
| 10424 | |
| 10425 | static struct pci_error_handlers bnx2x_err_handler = { |
| 10426 | .error_detected = bnx2x_io_error_detected, |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 10427 | .slot_reset = bnx2x_io_slot_reset, |
| 10428 | .resume = bnx2x_io_resume, |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10429 | }; |
| 10430 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10431 | static struct pci_driver bnx2x_pci_driver = { |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 10432 | .name = DRV_MODULE_NAME, |
| 10433 | .id_table = bnx2x_pci_tbl, |
| 10434 | .probe = bnx2x_init_one, |
| 10435 | .remove = __devexit_p(bnx2x_remove_one), |
| 10436 | .suspend = bnx2x_suspend, |
| 10437 | .resume = bnx2x_resume, |
| 10438 | .err_handler = &bnx2x_err_handler, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10439 | }; |
| 10440 | |
| 10441 | static int __init bnx2x_init(void) |
| 10442 | { |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10443 | int ret; |
| 10444 | |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10445 | pr_info("%s", version); |
Eilon Greenstein | 938cf54 | 2009-08-12 08:23:37 +0000 | [diff] [blame] | 10446 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10447 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
| 10448 | if (bnx2x_wq == NULL) { |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10449 | pr_err("Cannot create workqueue\n"); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10450 | return -ENOMEM; |
| 10451 | } |
| 10452 | |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10453 | ret = pci_register_driver(&bnx2x_pci_driver); |
| 10454 | if (ret) { |
Joe Perches | 7995c64 | 2010-02-17 15:01:52 +0000 | [diff] [blame] | 10455 | pr_err("Cannot register driver\n"); |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 10456 | destroy_workqueue(bnx2x_wq); |
| 10457 | } |
| 10458 | return ret; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10459 | } |
| 10460 | |
| 10461 | static void __exit bnx2x_cleanup(void) |
| 10462 | { |
| 10463 | pci_unregister_driver(&bnx2x_pci_driver); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 10464 | |
| 10465 | destroy_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10466 | } |
| 10467 | |
| 10468 | module_init(bnx2x_init); |
| 10469 | module_exit(bnx2x_cleanup); |
| 10470 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10471 | #ifdef BCM_CNIC |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10472 | /** |
| 10473 | * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s). |
| 10474 | * |
| 10475 | * @bp: driver handle |
| 10476 | * @set: set or clear the CAM entry |
| 10477 | * |
| 10478 | * This function will wait until the ramdord completion returns. |
| 10479 | * Return 0 if success, -ENODEV if ramrod doesn't return. |
| 10480 | */ |
| 10481 | static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp) |
| 10482 | { |
| 10483 | unsigned long ramrod_flags = 0; |
| 10484 | |
| 10485 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); |
| 10486 | return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac, |
| 10487 | &bp->iscsi_l2_mac_obj, true, |
| 10488 | BNX2X_ISCSI_ETH_MAC, &ramrod_flags); |
| 10489 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10490 | |
| 10491 | /* count denotes the number of new completions we have seen */ |
| 10492 | static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count) |
| 10493 | { |
| 10494 | struct eth_spe *spe; |
| 10495 | |
| 10496 | #ifdef BNX2X_STOP_ON_ERROR |
| 10497 | if (unlikely(bp->panic)) |
| 10498 | return; |
| 10499 | #endif |
| 10500 | |
| 10501 | spin_lock_bh(&bp->spq_lock); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10502 | BUG_ON(bp->cnic_spq_pending < count); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10503 | bp->cnic_spq_pending -= count; |
| 10504 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10505 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10506 | for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) { |
| 10507 | u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type) |
| 10508 | & SPE_HDR_CONN_TYPE) >> |
| 10509 | SPE_HDR_CONN_TYPE_SHIFT; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10510 | u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data) |
| 10511 | >> SPE_HDR_CMD_ID_SHIFT) & 0xff; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10512 | |
| 10513 | /* Set validation for iSCSI L2 client before sending SETUP |
| 10514 | * ramrod |
| 10515 | */ |
| 10516 | if (type == ETH_CONNECTION_TYPE) { |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10517 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10518 | bnx2x_set_ctx_validation(bp, &bp->context. |
| 10519 | vcxt[BNX2X_ISCSI_ETH_CID].eth, |
| 10520 | BNX2X_ISCSI_ETH_CID); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10521 | } |
| 10522 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10523 | /* |
| 10524 | * There may be not more than 8 L2, not more than 8 L5 SPEs |
| 10525 | * and in the air. We also check that number of outstanding |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10526 | * COMMON ramrods is not more than the EQ and SPQ can |
| 10527 | * accommodate. |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10528 | */ |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10529 | if (type == ETH_CONNECTION_TYPE) { |
| 10530 | if (!atomic_read(&bp->cq_spq_left)) |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10531 | break; |
| 10532 | else |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10533 | atomic_dec(&bp->cq_spq_left); |
| 10534 | } else if (type == NONE_CONNECTION_TYPE) { |
| 10535 | if (!atomic_read(&bp->eq_spq_left)) |
| 10536 | break; |
| 10537 | else |
| 10538 | atomic_dec(&bp->eq_spq_left); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10539 | } else if ((type == ISCSI_CONNECTION_TYPE) || |
| 10540 | (type == FCOE_CONNECTION_TYPE)) { |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10541 | if (bp->cnic_spq_pending >= |
| 10542 | bp->cnic_eth_dev.max_kwqe_pending) |
| 10543 | break; |
| 10544 | else |
| 10545 | bp->cnic_spq_pending++; |
| 10546 | } else { |
| 10547 | BNX2X_ERR("Unknown SPE type: %d\n", type); |
| 10548 | bnx2x_panic(); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10549 | break; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10550 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10551 | |
| 10552 | spe = bnx2x_sp_get_next(bp); |
| 10553 | *spe = *bp->cnic_kwq_cons; |
| 10554 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10555 | DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n", |
| 10556 | bp->cnic_spq_pending, bp->cnic_kwq_pending, count); |
| 10557 | |
| 10558 | if (bp->cnic_kwq_cons == bp->cnic_kwq_last) |
| 10559 | bp->cnic_kwq_cons = bp->cnic_kwq; |
| 10560 | else |
| 10561 | bp->cnic_kwq_cons++; |
| 10562 | } |
| 10563 | bnx2x_sp_prod_update(bp); |
| 10564 | spin_unlock_bh(&bp->spq_lock); |
| 10565 | } |
| 10566 | |
| 10567 | static int bnx2x_cnic_sp_queue(struct net_device *dev, |
| 10568 | struct kwqe_16 *kwqes[], u32 count) |
| 10569 | { |
| 10570 | struct bnx2x *bp = netdev_priv(dev); |
| 10571 | int i; |
| 10572 | |
| 10573 | #ifdef BNX2X_STOP_ON_ERROR |
| 10574 | if (unlikely(bp->panic)) |
| 10575 | return -EIO; |
| 10576 | #endif |
| 10577 | |
| 10578 | spin_lock_bh(&bp->spq_lock); |
| 10579 | |
| 10580 | for (i = 0; i < count; i++) { |
| 10581 | struct eth_spe *spe = (struct eth_spe *)kwqes[i]; |
| 10582 | |
| 10583 | if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT) |
| 10584 | break; |
| 10585 | |
| 10586 | *bp->cnic_kwq_prod = *spe; |
| 10587 | |
| 10588 | bp->cnic_kwq_pending++; |
| 10589 | |
| 10590 | DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n", |
| 10591 | spe->hdr.conn_and_cmd_data, spe->hdr.type, |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10592 | spe->data.update_data_addr.hi, |
| 10593 | spe->data.update_data_addr.lo, |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10594 | bp->cnic_kwq_pending); |
| 10595 | |
| 10596 | if (bp->cnic_kwq_prod == bp->cnic_kwq_last) |
| 10597 | bp->cnic_kwq_prod = bp->cnic_kwq; |
| 10598 | else |
| 10599 | bp->cnic_kwq_prod++; |
| 10600 | } |
| 10601 | |
| 10602 | spin_unlock_bh(&bp->spq_lock); |
| 10603 | |
| 10604 | if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending) |
| 10605 | bnx2x_cnic_sp_post(bp, 0); |
| 10606 | |
| 10607 | return i; |
| 10608 | } |
| 10609 | |
| 10610 | static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl) |
| 10611 | { |
| 10612 | struct cnic_ops *c_ops; |
| 10613 | int rc = 0; |
| 10614 | |
| 10615 | mutex_lock(&bp->cnic_mutex); |
Eric Dumazet | 13707f9 | 2011-01-26 19:28:23 +0000 | [diff] [blame] | 10616 | c_ops = rcu_dereference_protected(bp->cnic_ops, |
| 10617 | lockdep_is_held(&bp->cnic_mutex)); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10618 | if (c_ops) |
| 10619 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); |
| 10620 | mutex_unlock(&bp->cnic_mutex); |
| 10621 | |
| 10622 | return rc; |
| 10623 | } |
| 10624 | |
| 10625 | static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl) |
| 10626 | { |
| 10627 | struct cnic_ops *c_ops; |
| 10628 | int rc = 0; |
| 10629 | |
| 10630 | rcu_read_lock(); |
| 10631 | c_ops = rcu_dereference(bp->cnic_ops); |
| 10632 | if (c_ops) |
| 10633 | rc = c_ops->cnic_ctl(bp->cnic_data, ctl); |
| 10634 | rcu_read_unlock(); |
| 10635 | |
| 10636 | return rc; |
| 10637 | } |
| 10638 | |
| 10639 | /* |
| 10640 | * for commands that have no data |
| 10641 | */ |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 10642 | int bnx2x_cnic_notify(struct bnx2x *bp, int cmd) |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10643 | { |
| 10644 | struct cnic_ctl_info ctl = {0}; |
| 10645 | |
| 10646 | ctl.cmd = cmd; |
| 10647 | |
| 10648 | return bnx2x_cnic_ctl_send(bp, &ctl); |
| 10649 | } |
| 10650 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10651 | 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] | 10652 | { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10653 | struct cnic_ctl_info ctl = {0}; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10654 | |
| 10655 | /* first we tell CNIC and only then we count this as a completion */ |
| 10656 | ctl.cmd = CNIC_CTL_COMPLETION_CMD; |
| 10657 | ctl.data.comp.cid = cid; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10658 | ctl.data.comp.error = err; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10659 | |
| 10660 | bnx2x_cnic_ctl_send_bh(bp, &ctl); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10661 | bnx2x_cnic_sp_post(bp, 0); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10662 | } |
| 10663 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10664 | |
| 10665 | /* Called with netif_addr_lock_bh() taken. |
| 10666 | * Sets an rx_mode config for an iSCSI ETH client. |
| 10667 | * Doesn't block. |
| 10668 | * Completion should be checked outside. |
| 10669 | */ |
| 10670 | static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start) |
| 10671 | { |
| 10672 | unsigned long accept_flags = 0, ramrod_flags = 0; |
| 10673 | u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); |
| 10674 | int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED; |
| 10675 | |
| 10676 | if (start) { |
| 10677 | /* Start accepting on iSCSI L2 ring. Accept all multicasts |
| 10678 | * because it's the only way for UIO Queue to accept |
| 10679 | * multicasts (in non-promiscuous mode only one Queue per |
| 10680 | * function will receive multicast packets (leading in our |
| 10681 | * case). |
| 10682 | */ |
| 10683 | __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags); |
| 10684 | __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags); |
| 10685 | __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags); |
| 10686 | __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); |
| 10687 | |
| 10688 | /* Clear STOP_PENDING bit if START is requested */ |
| 10689 | clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state); |
| 10690 | |
| 10691 | sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED; |
| 10692 | } else |
| 10693 | /* Clear START_PENDING bit if STOP is requested */ |
| 10694 | clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state); |
| 10695 | |
| 10696 | if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) |
| 10697 | set_bit(sched_state, &bp->sp_state); |
| 10698 | else { |
| 10699 | __set_bit(RAMROD_RX, &ramrod_flags); |
| 10700 | bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0, |
| 10701 | ramrod_flags); |
| 10702 | } |
| 10703 | } |
| 10704 | |
| 10705 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10706 | static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl) |
| 10707 | { |
| 10708 | struct bnx2x *bp = netdev_priv(dev); |
| 10709 | int rc = 0; |
| 10710 | |
| 10711 | switch (ctl->cmd) { |
| 10712 | case DRV_CTL_CTXTBL_WR_CMD: { |
| 10713 | u32 index = ctl->data.io.offset; |
| 10714 | dma_addr_t addr = ctl->data.io.dma_addr; |
| 10715 | |
| 10716 | bnx2x_ilt_wr(bp, index, addr); |
| 10717 | break; |
| 10718 | } |
| 10719 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10720 | case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: { |
| 10721 | int count = ctl->data.credit.credit_count; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10722 | |
| 10723 | bnx2x_cnic_sp_post(bp, count); |
| 10724 | break; |
| 10725 | } |
| 10726 | |
| 10727 | /* rtnl_lock is held. */ |
| 10728 | case DRV_CTL_START_L2_CMD: { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10729 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10730 | unsigned long sp_bits = 0; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10731 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10732 | /* Configure the iSCSI classification object */ |
| 10733 | bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj, |
| 10734 | cp->iscsi_l2_client_id, |
| 10735 | cp->iscsi_l2_cid, BP_FUNC(bp), |
| 10736 | bnx2x_sp(bp, mac_rdata), |
| 10737 | bnx2x_sp_mapping(bp, mac_rdata), |
| 10738 | BNX2X_FILTER_MAC_PENDING, |
| 10739 | &bp->sp_state, BNX2X_OBJ_TYPE_RX, |
| 10740 | &bp->macs_pool); |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10741 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10742 | /* Set iSCSI MAC address */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10743 | rc = bnx2x_set_iscsi_eth_mac_addr(bp); |
| 10744 | if (rc) |
| 10745 | break; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10746 | |
| 10747 | mmiowb(); |
| 10748 | barrier(); |
| 10749 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10750 | /* Start accepting on iSCSI L2 ring */ |
| 10751 | |
| 10752 | netif_addr_lock_bh(dev); |
| 10753 | bnx2x_set_iscsi_eth_rx_mode(bp, true); |
| 10754 | netif_addr_unlock_bh(dev); |
| 10755 | |
| 10756 | /* bits to wait on */ |
| 10757 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); |
| 10758 | __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits); |
| 10759 | |
| 10760 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) |
| 10761 | BNX2X_ERR("rx_mode completion timed out!\n"); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10762 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10763 | break; |
| 10764 | } |
| 10765 | |
| 10766 | /* rtnl_lock is held. */ |
| 10767 | case DRV_CTL_STOP_L2_CMD: { |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10768 | unsigned long sp_bits = 0; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10769 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10770 | /* Stop accepting on iSCSI L2 ring */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10771 | netif_addr_lock_bh(dev); |
| 10772 | bnx2x_set_iscsi_eth_rx_mode(bp, false); |
| 10773 | netif_addr_unlock_bh(dev); |
| 10774 | |
| 10775 | /* bits to wait on */ |
| 10776 | __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits); |
| 10777 | __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits); |
| 10778 | |
| 10779 | if (!bnx2x_wait_sp_comp(bp, sp_bits)) |
| 10780 | BNX2X_ERR("rx_mode completion timed out!\n"); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10781 | |
| 10782 | mmiowb(); |
| 10783 | barrier(); |
| 10784 | |
| 10785 | /* Unset iSCSI L2 MAC */ |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10786 | rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj, |
| 10787 | BNX2X_ISCSI_ETH_MAC, true); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10788 | break; |
| 10789 | } |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10790 | case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: { |
| 10791 | int count = ctl->data.credit.credit_count; |
| 10792 | |
| 10793 | smp_mb__before_atomic_inc(); |
Vladislav Zolotarov | 6e30dd4 | 2011-02-06 11:25:41 -0800 | [diff] [blame] | 10794 | atomic_add(count, &bp->cq_spq_left); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10795 | smp_mb__after_atomic_inc(); |
| 10796 | break; |
| 10797 | } |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10798 | |
| 10799 | default: |
| 10800 | BNX2X_ERR("unknown command %x\n", ctl->cmd); |
| 10801 | rc = -EINVAL; |
| 10802 | } |
| 10803 | |
| 10804 | return rc; |
| 10805 | } |
| 10806 | |
Dmitry Kravkov | 9f6c925 | 2010-07-27 12:34:34 +0000 | [diff] [blame] | 10807 | void bnx2x_setup_cnic_irq_info(struct bnx2x *bp) |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10808 | { |
| 10809 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10810 | |
| 10811 | if (bp->flags & USING_MSIX_FLAG) { |
| 10812 | cp->drv_state |= CNIC_DRV_STATE_USING_MSIX; |
| 10813 | cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX; |
| 10814 | cp->irq_arr[0].vector = bp->msix_table[1].vector; |
| 10815 | } else { |
| 10816 | cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX; |
| 10817 | cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX; |
| 10818 | } |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10819 | if (!CHIP_IS_E1x(bp)) |
Dmitry Kravkov | f2e0899 | 2010-10-06 03:28:26 +0000 | [diff] [blame] | 10820 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb; |
| 10821 | else |
| 10822 | cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb; |
| 10823 | |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10824 | cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp); |
| 10825 | cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10826 | cp->irq_arr[1].status_blk = bp->def_status_blk; |
| 10827 | cp->irq_arr[1].status_blk_num = DEF_SB_ID; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10828 | cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10829 | |
| 10830 | cp->num_irq = 2; |
| 10831 | } |
| 10832 | |
| 10833 | static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops, |
| 10834 | void *data) |
| 10835 | { |
| 10836 | struct bnx2x *bp = netdev_priv(dev); |
| 10837 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10838 | |
| 10839 | if (ops == NULL) |
| 10840 | return -EINVAL; |
| 10841 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10842 | bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 10843 | if (!bp->cnic_kwq) |
| 10844 | return -ENOMEM; |
| 10845 | |
| 10846 | bp->cnic_kwq_cons = bp->cnic_kwq; |
| 10847 | bp->cnic_kwq_prod = bp->cnic_kwq; |
| 10848 | bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT; |
| 10849 | |
| 10850 | bp->cnic_spq_pending = 0; |
| 10851 | bp->cnic_kwq_pending = 0; |
| 10852 | |
| 10853 | bp->cnic_data = data; |
| 10854 | |
| 10855 | cp->num_irq = 0; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10856 | cp->drv_state |= CNIC_DRV_STATE_REGD; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10857 | cp->iro_arr = bp->iro_arr; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10858 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10859 | bnx2x_setup_cnic_irq_info(bp); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10860 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10861 | rcu_assign_pointer(bp->cnic_ops, ops); |
| 10862 | |
| 10863 | return 0; |
| 10864 | } |
| 10865 | |
| 10866 | static int bnx2x_unregister_cnic(struct net_device *dev) |
| 10867 | { |
| 10868 | struct bnx2x *bp = netdev_priv(dev); |
| 10869 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10870 | |
| 10871 | mutex_lock(&bp->cnic_mutex); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10872 | cp->drv_state = 0; |
| 10873 | rcu_assign_pointer(bp->cnic_ops, NULL); |
| 10874 | mutex_unlock(&bp->cnic_mutex); |
| 10875 | synchronize_rcu(); |
| 10876 | kfree(bp->cnic_kwq); |
| 10877 | bp->cnic_kwq = NULL; |
| 10878 | |
| 10879 | return 0; |
| 10880 | } |
| 10881 | |
| 10882 | struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev) |
| 10883 | { |
| 10884 | struct bnx2x *bp = netdev_priv(dev); |
| 10885 | struct cnic_eth_dev *cp = &bp->cnic_eth_dev; |
| 10886 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 10887 | /* If both iSCSI and FCoE are disabled - return NULL in |
| 10888 | * order to indicate CNIC that it should not try to work |
| 10889 | * with this device. |
| 10890 | */ |
| 10891 | if (NO_ISCSI(bp) && NO_FCOE(bp)) |
| 10892 | return NULL; |
| 10893 | |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10894 | cp->drv_owner = THIS_MODULE; |
| 10895 | cp->chip_id = CHIP_ID(bp); |
| 10896 | cp->pdev = bp->pdev; |
| 10897 | cp->io_base = bp->regview; |
| 10898 | cp->io_base2 = bp->doorbells; |
| 10899 | cp->max_kwqe_pending = 8; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 10900 | cp->ctx_blk_size = CDU_ILT_PAGE_SZ; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10901 | cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + |
| 10902 | bnx2x_cid_ilt_lines(bp); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10903 | cp->ctx_tbl_len = CNIC_ILT_LINES; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10904 | cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10905 | cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue; |
| 10906 | cp->drv_ctl = bnx2x_drv_ctl; |
| 10907 | cp->drv_register_cnic = bnx2x_register_cnic; |
| 10908 | cp->drv_unregister_cnic = bnx2x_unregister_cnic; |
Vladislav Zolotarov | ec6ba94 | 2010-12-13 05:44:01 +0000 | [diff] [blame] | 10909 | cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID; |
Vlad Zolotarov | 619c5cb | 2011-06-14 14:33:44 +0300 | [diff] [blame] | 10910 | cp->iscsi_l2_client_id = |
| 10911 | bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10912 | cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID; |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10913 | |
Vladislav Zolotarov | 2ba4514 | 2011-01-31 14:39:17 +0000 | [diff] [blame] | 10914 | if (NO_ISCSI_OOO(bp)) |
| 10915 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO; |
| 10916 | |
| 10917 | if (NO_ISCSI(bp)) |
| 10918 | cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI; |
| 10919 | |
| 10920 | if (NO_FCOE(bp)) |
| 10921 | cp->drv_state |= CNIC_DRV_STATE_NO_FCOE; |
| 10922 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 10923 | DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, " |
| 10924 | "starting cid %d\n", |
| 10925 | cp->ctx_blk_size, |
| 10926 | cp->ctx_tbl_offset, |
| 10927 | cp->ctx_tbl_len, |
| 10928 | cp->starting_cid); |
Michael Chan | 993ac7b | 2009-10-10 13:46:56 +0000 | [diff] [blame] | 10929 | return cp; |
| 10930 | } |
| 10931 | EXPORT_SYMBOL(bnx2x_cnic_probe); |
| 10932 | |
| 10933 | #endif /* BCM_CNIC */ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 10934 | |