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 | * |
Eilon Greenstein | d05c26c | 2009-01-17 23:26:13 -0800 | [diff] [blame] | 3 | * Copyright (c) 2007-2009 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> |
| 26 | #include <linux/vmalloc.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/skbuff.h> |
| 33 | #include <linux/dma-mapping.h> |
| 34 | #include <linux/bitops.h> |
| 35 | #include <linux/irq.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <asm/byteorder.h> |
| 38 | #include <linux/time.h> |
| 39 | #include <linux/ethtool.h> |
| 40 | #include <linux/mii.h> |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 42 | #include <net/ip.h> |
| 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> |
| 52 | |
Eilon Greenstein | 359d8b1 | 2009-02-12 08:38:25 +0000 | [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" |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 57 | #include "bnx2x_dump.h" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 58 | |
Eilon Greenstein | c458bc5 | 2009-08-12 08:24:31 +0000 | [diff] [blame] | 59 | #define DRV_MODULE_VERSION "1.52.1" |
| 60 | #define DRV_MODULE_RELDATE "2009/08/12" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 61 | #define BNX2X_BC_VER 0x040200 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 62 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 63 | #include <linux/firmware.h> |
| 64 | #include "bnx2x_fw_file_hdr.h" |
| 65 | /* FW files */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 66 | #define FW_FILE_PREFIX_E1 "bnx2x-e1-" |
| 67 | #define FW_FILE_PREFIX_E1H "bnx2x-e1h-" |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 68 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 69 | /* Time in jiffies before concluding the transmitter is hung */ |
| 70 | #define TX_TIMEOUT (5*HZ) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 71 | |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 72 | static char version[] __devinitdata = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 73 | "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 74 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 75 | |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 76 | MODULE_AUTHOR("Eliezer Tamir"); |
Eilon Greenstein | e47d7e6 | 2009-01-14 06:44:28 +0000 | [diff] [blame] | 77 | MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 78 | MODULE_LICENSE("GPL"); |
| 79 | MODULE_VERSION(DRV_MODULE_VERSION); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 80 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 81 | static int multi_mode = 1; |
| 82 | module_param(multi_mode, int, 0); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 83 | MODULE_PARM_DESC(multi_mode, " Multi queue mode " |
| 84 | "(0 Disable; 1 Enable (default))"); |
| 85 | |
| 86 | static int num_rx_queues; |
| 87 | module_param(num_rx_queues, int, 0); |
| 88 | MODULE_PARM_DESC(num_rx_queues, " Number of Rx queues for multi_mode=1" |
| 89 | " (default is half number of CPUs)"); |
| 90 | |
| 91 | static int num_tx_queues; |
| 92 | module_param(num_tx_queues, int, 0); |
| 93 | MODULE_PARM_DESC(num_tx_queues, " Number of Tx queues for multi_mode=1" |
| 94 | " (default is half number of CPUs)"); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 95 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 96 | static int disable_tpa; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 97 | module_param(disable_tpa, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 98 | MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature"); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 99 | |
| 100 | static int int_mode; |
| 101 | module_param(int_mode, int, 0); |
| 102 | MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)"); |
| 103 | |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 104 | static int dropless_fc; |
| 105 | module_param(dropless_fc, int, 0); |
| 106 | MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring"); |
| 107 | |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 108 | static int poll; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 109 | module_param(poll, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 110 | MODULE_PARM_DESC(poll, " Use polling (for debug)"); |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 111 | |
| 112 | static int mrrs = -1; |
| 113 | module_param(mrrs, int, 0); |
| 114 | MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)"); |
| 115 | |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 116 | static int debug; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 117 | module_param(debug, int, 0); |
Eilon Greenstein | 9898f86 | 2009-02-12 08:38:27 +0000 | [diff] [blame] | 118 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
| 119 | |
| 120 | static int load_count[3]; /* 0-common, 1-port0, 2-port1 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 121 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 122 | static struct workqueue_struct *bnx2x_wq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 123 | |
| 124 | enum bnx2x_board_type { |
| 125 | BCM57710 = 0, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 126 | BCM57711 = 1, |
| 127 | BCM57711E = 2, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 130 | /* indexed by board_type, above */ |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 131 | static struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 132 | char *name; |
| 133 | } board_info[] __devinitdata = { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 134 | { "Broadcom NetXtreme II BCM57710 XGb" }, |
| 135 | { "Broadcom NetXtreme II BCM57711 XGb" }, |
| 136 | { "Broadcom NetXtreme II BCM57711E XGb" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 137 | }; |
| 138 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 139 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 140 | static const struct pci_device_id bnx2x_pci_tbl[] = { |
Eilon Greenstein | e4ed711 | 2009-08-12 08:24:10 +0000 | [diff] [blame] | 141 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, |
| 142 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, |
| 143 | { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E }, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 144 | { 0 } |
| 145 | }; |
| 146 | |
| 147 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); |
| 148 | |
| 149 | /**************************************************************************** |
| 150 | * General service functions |
| 151 | ****************************************************************************/ |
| 152 | |
| 153 | /* used only at init |
| 154 | * locking is done by mcp |
| 155 | */ |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 156 | void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 157 | { |
| 158 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 159 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); |
| 160 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 161 | PCICFG_VENDOR_ID_OFFSET); |
| 162 | } |
| 163 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 164 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
| 165 | { |
| 166 | u32 val; |
| 167 | |
| 168 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 169 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); |
| 170 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 171 | PCICFG_VENDOR_ID_OFFSET); |
| 172 | |
| 173 | return val; |
| 174 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 175 | |
| 176 | static const u32 dmae_reg_go_c[] = { |
| 177 | DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3, |
| 178 | DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7, |
| 179 | DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11, |
| 180 | DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15 |
| 181 | }; |
| 182 | |
| 183 | /* copy command into DMAE command memory and set DMAE command go */ |
| 184 | static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, |
| 185 | int idx) |
| 186 | { |
| 187 | u32 cmd_offset; |
| 188 | int i; |
| 189 | |
| 190 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); |
| 191 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { |
| 192 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
| 193 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 194 | DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n", |
| 195 | idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 196 | } |
| 197 | REG_WR(bp, dmae_reg_go_c[idx], 1); |
| 198 | } |
| 199 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 200 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, |
| 201 | u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 202 | { |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 203 | struct dmae_command dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 204 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 205 | int cnt = 200; |
| 206 | |
| 207 | if (!bp->dmae_ready) { |
| 208 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 209 | |
| 210 | DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)" |
| 211 | " using indirect\n", dst_addr, len32); |
| 212 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); |
| 213 | return; |
| 214 | } |
| 215 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 216 | memset(&dmae, 0, sizeof(struct dmae_command)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 217 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 218 | dmae.opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 219 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 220 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 221 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 222 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 223 | #else |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 224 | DMAE_CMD_ENDIANITY_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 225 | #endif |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 226 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 227 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 228 | dmae.src_addr_lo = U64_LO(dma_addr); |
| 229 | dmae.src_addr_hi = U64_HI(dma_addr); |
| 230 | dmae.dst_addr_lo = dst_addr >> 2; |
| 231 | dmae.dst_addr_hi = 0; |
| 232 | dmae.len = len32; |
| 233 | dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 234 | dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
| 235 | dmae.comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 236 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 237 | DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 238 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 239 | "dst_addr [%x:%08x (%08x)]\n" |
| 240 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 241 | dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo, |
| 242 | dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, dst_addr, |
| 243 | dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 244 | DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 245 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 246 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 247 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 248 | mutex_lock(&bp->dmae_mutex); |
| 249 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 250 | *wb_comp = 0; |
| 251 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 252 | bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 253 | |
| 254 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 255 | |
| 256 | while (*wb_comp != DMAE_COMP_VAL) { |
| 257 | DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp); |
| 258 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 259 | if (!cnt) { |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 260 | BNX2X_ERR("DMAE timeout!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 261 | break; |
| 262 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 263 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 264 | /* adjust delay for emulation/FPGA */ |
| 265 | if (CHIP_REV_IS_SLOW(bp)) |
| 266 | msleep(100); |
| 267 | else |
| 268 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 269 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 270 | |
| 271 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 274 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 275 | { |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 276 | struct dmae_command dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 277 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 278 | int cnt = 200; |
| 279 | |
| 280 | if (!bp->dmae_ready) { |
| 281 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 282 | int i; |
| 283 | |
| 284 | DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)" |
| 285 | " using indirect\n", src_addr, len32); |
| 286 | for (i = 0; i < len32; i++) |
| 287 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); |
| 288 | return; |
| 289 | } |
| 290 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 291 | memset(&dmae, 0, sizeof(struct dmae_command)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 292 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 293 | dmae.opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 294 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 295 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 296 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 297 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 298 | #else |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 299 | DMAE_CMD_ENDIANITY_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 300 | #endif |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 301 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 302 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 303 | dmae.src_addr_lo = src_addr >> 2; |
| 304 | dmae.src_addr_hi = 0; |
| 305 | dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); |
| 306 | dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); |
| 307 | dmae.len = len32; |
| 308 | dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 309 | dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
| 310 | dmae.comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 311 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 312 | DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 313 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 314 | "dst_addr [%x:%08x (%08x)]\n" |
| 315 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 316 | dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo, |
| 317 | dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, src_addr, |
| 318 | dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 319 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 320 | mutex_lock(&bp->dmae_mutex); |
| 321 | |
| 322 | memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 323 | *wb_comp = 0; |
| 324 | |
Eilon Greenstein | 5ff7b6d | 2009-08-12 08:23:44 +0000 | [diff] [blame] | 325 | bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 326 | |
| 327 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 328 | |
| 329 | while (*wb_comp != DMAE_COMP_VAL) { |
| 330 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 331 | if (!cnt) { |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 332 | BNX2X_ERR("DMAE timeout!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 333 | break; |
| 334 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 335 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 336 | /* adjust delay for emulation/FPGA */ |
| 337 | if (CHIP_REV_IS_SLOW(bp)) |
| 338 | msleep(100); |
| 339 | else |
| 340 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 341 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 342 | DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 343 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 344 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 345 | |
| 346 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 347 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 348 | |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 349 | void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, |
| 350 | u32 addr, u32 len) |
| 351 | { |
| 352 | int offset = 0; |
| 353 | |
| 354 | while (len > DMAE_LEN32_WR_MAX) { |
| 355 | bnx2x_write_dmae(bp, phys_addr + offset, |
| 356 | addr + offset, DMAE_LEN32_WR_MAX); |
| 357 | offset += DMAE_LEN32_WR_MAX * 4; |
| 358 | len -= DMAE_LEN32_WR_MAX; |
| 359 | } |
| 360 | |
| 361 | bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len); |
| 362 | } |
| 363 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 364 | /* used only for slowpath so not inlined */ |
| 365 | static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo) |
| 366 | { |
| 367 | u32 wb_write[2]; |
| 368 | |
| 369 | wb_write[0] = val_hi; |
| 370 | wb_write[1] = val_lo; |
| 371 | REG_WR_DMAE(bp, reg, wb_write, 2); |
| 372 | } |
| 373 | |
| 374 | #ifdef USE_WB_RD |
| 375 | static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg) |
| 376 | { |
| 377 | u32 wb_data[2]; |
| 378 | |
| 379 | REG_RD_DMAE(bp, reg, wb_data, 2); |
| 380 | |
| 381 | return HILO_U64(wb_data[0], wb_data[1]); |
| 382 | } |
| 383 | #endif |
| 384 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 385 | static int bnx2x_mc_assert(struct bnx2x *bp) |
| 386 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 387 | char last_idx; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 388 | int i, rc = 0; |
| 389 | u32 row0, row1, row2, row3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 390 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 391 | /* XSTORM */ |
| 392 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + |
| 393 | XSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 394 | if (last_idx) |
| 395 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 396 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 397 | /* print the asserts */ |
| 398 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 399 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 400 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 401 | XSTORM_ASSERT_LIST_OFFSET(i)); |
| 402 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 403 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 404 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 405 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 406 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 407 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 408 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 409 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 410 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 411 | " 0x%08x 0x%08x 0x%08x\n", |
| 412 | i, row3, row2, row1, row0); |
| 413 | rc++; |
| 414 | } else { |
| 415 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 416 | } |
| 417 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 418 | |
| 419 | /* TSTORM */ |
| 420 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + |
| 421 | TSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 422 | if (last_idx) |
| 423 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 424 | |
| 425 | /* print the asserts */ |
| 426 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 427 | |
| 428 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 429 | TSTORM_ASSERT_LIST_OFFSET(i)); |
| 430 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 431 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 432 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 433 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 434 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 435 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 436 | |
| 437 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 438 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 439 | " 0x%08x 0x%08x 0x%08x\n", |
| 440 | i, row3, row2, row1, row0); |
| 441 | rc++; |
| 442 | } else { |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /* CSTORM */ |
| 448 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + |
| 449 | CSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 450 | if (last_idx) |
| 451 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 452 | |
| 453 | /* print the asserts */ |
| 454 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 455 | |
| 456 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 457 | CSTORM_ASSERT_LIST_OFFSET(i)); |
| 458 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 459 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 460 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 461 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 462 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 463 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 464 | |
| 465 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 466 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 467 | " 0x%08x 0x%08x 0x%08x\n", |
| 468 | i, row3, row2, row1, row0); |
| 469 | rc++; |
| 470 | } else { |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | /* USTORM */ |
| 476 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + |
| 477 | USTORM_ASSERT_LIST_INDEX_OFFSET); |
| 478 | if (last_idx) |
| 479 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 480 | |
| 481 | /* print the asserts */ |
| 482 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 483 | |
| 484 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 485 | USTORM_ASSERT_LIST_OFFSET(i)); |
| 486 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 487 | USTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 488 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 489 | USTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 490 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 491 | USTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 492 | |
| 493 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 494 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 495 | " 0x%08x 0x%08x 0x%08x\n", |
| 496 | i, row3, row2, row1, row0); |
| 497 | rc++; |
| 498 | } else { |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 503 | return rc; |
| 504 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 505 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 506 | static void bnx2x_fw_dump(struct bnx2x *bp) |
| 507 | { |
| 508 | u32 mark, offset; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 509 | __be32 data[9]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 510 | int word; |
| 511 | |
| 512 | mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 513 | mark = ((mark + 0x3) & ~0x3); |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 514 | printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n", mark); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 515 | |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 516 | printk(KERN_ERR PFX); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 517 | for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) { |
| 518 | for (word = 0; word < 8; word++) |
| 519 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 520 | offset + 4*word)); |
| 521 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 522 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 523 | } |
| 524 | for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) { |
| 525 | for (word = 0; word < 8; word++) |
| 526 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 527 | offset + 4*word)); |
| 528 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 529 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 530 | } |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 531 | printk(KERN_ERR PFX "end of fw dump\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void bnx2x_panic_dump(struct bnx2x *bp) |
| 535 | { |
| 536 | int i; |
| 537 | u16 j, start, end; |
| 538 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 539 | bp->stats_state = STATS_STATE_DISABLED; |
| 540 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 541 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 542 | BNX2X_ERR("begin crash dump -----------------\n"); |
| 543 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 544 | /* Indices */ |
| 545 | /* Common */ |
| 546 | BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)" |
| 547 | " def_t_idx(%u) def_att_idx(%u) attn_state(%u)" |
| 548 | " spq_prod_idx(%u)\n", |
| 549 | bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx, |
| 550 | bp->def_att_idx, bp->attn_state, bp->spq_prod_idx); |
| 551 | |
| 552 | /* Rx */ |
| 553 | for_each_rx_queue(bp, i) { |
| 554 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 555 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 556 | BNX2X_ERR("fp%d: rx_bd_prod(%x) rx_bd_cons(%x)" |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 557 | " *rx_bd_cons_sb(%x) rx_comp_prod(%x)" |
| 558 | " rx_comp_cons(%x) *rx_cons_sb(%x)\n", |
| 559 | i, fp->rx_bd_prod, fp->rx_bd_cons, |
| 560 | le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod, |
| 561 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 562 | BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)" |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 563 | " fp_u_idx(%x) *sb_u_idx(%x)\n", |
| 564 | fp->rx_sge_prod, fp->last_max_sge, |
| 565 | le16_to_cpu(fp->fp_u_idx), |
| 566 | fp->status_blk->u_status_block.status_block_index); |
| 567 | } |
| 568 | |
| 569 | /* Tx */ |
| 570 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 571 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 572 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 573 | BNX2X_ERR("fp%d: tx_pkt_prod(%x) tx_pkt_cons(%x)" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 574 | " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 575 | 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] | 576 | fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb)); |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 577 | BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)" |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 578 | " tx_db_prod(%x)\n", le16_to_cpu(fp->fp_c_idx), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 579 | fp->status_blk->c_status_block.status_block_index, |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 580 | fp->tx_db.data.prod); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 581 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 582 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 583 | /* Rings */ |
| 584 | /* Rx */ |
| 585 | for_each_rx_queue(bp, i) { |
| 586 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 587 | |
| 588 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); |
| 589 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 590 | for (j = start; j != end; j = RX_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 591 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
| 592 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; |
| 593 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 594 | BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
| 595 | i, j, rx_bd[1], rx_bd[0], sw_bd->skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 598 | start = RX_SGE(fp->rx_sge_prod); |
| 599 | end = RX_SGE(fp->last_max_sge); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 600 | for (j = start; j != end; j = RX_SGE(j + 1)) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 601 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
| 602 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; |
| 603 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 604 | BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
| 605 | i, j, rx_sge[1], rx_sge[0], sw_page->page); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 608 | start = RCQ_BD(fp->rx_comp_cons - 10); |
| 609 | end = RCQ_BD(fp->rx_comp_cons + 503); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 610 | for (j = start; j != end; j = RCQ_BD(j + 1)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 611 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
| 612 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 613 | BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n", |
| 614 | i, j, cqe[0], cqe[1], cqe[2], cqe[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 618 | /* Tx */ |
| 619 | for_each_tx_queue(bp, i) { |
| 620 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 621 | |
| 622 | start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10); |
| 623 | end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245); |
| 624 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 625 | struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j]; |
| 626 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 627 | BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n", |
| 628 | i, j, sw_bd->skb, sw_bd->first_bd); |
Eilon Greenstein | 8440d2b | 2009-02-12 08:38:22 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | start = TX_BD(fp->tx_bd_cons - 10); |
| 632 | end = TX_BD(fp->tx_bd_cons + 254); |
| 633 | for (j = start; j != end; j = TX_BD(j + 1)) { |
| 634 | u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j]; |
| 635 | |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 636 | BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n", |
| 637 | 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] | 638 | } |
| 639 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 640 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 641 | bnx2x_fw_dump(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 642 | bnx2x_mc_assert(bp); |
| 643 | BNX2X_ERR("end crash dump -----------------\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 644 | } |
| 645 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 646 | static void bnx2x_int_enable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 647 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 648 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 649 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 650 | u32 val = REG_RD(bp, addr); |
| 651 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 652 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 653 | |
| 654 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 655 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 656 | HC_CONFIG_0_REG_INT_LINE_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 657 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 658 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 659 | } else if (msi) { |
| 660 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; |
| 661 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 662 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 663 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 664 | } else { |
| 665 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 666 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 667 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 668 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 669 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 670 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 671 | val, port, addr); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 672 | |
| 673 | REG_WR(bp, addr, val); |
| 674 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 675 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
| 676 | } |
| 677 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 678 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n", |
| 679 | val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 680 | |
| 681 | REG_WR(bp, addr, val); |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 682 | /* |
| 683 | * Ensure that HC_CONFIG is written before leading/trailing edge config |
| 684 | */ |
| 685 | mmiowb(); |
| 686 | barrier(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 687 | |
| 688 | if (CHIP_IS_E1H(bp)) { |
| 689 | /* init leading/trailing edge */ |
| 690 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 691 | val = (0xee0f | (1 << (BP_E1HVN(bp) + 4))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 692 | if (bp->port.pmf) |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 693 | /* enable nig and gpio3 attention */ |
| 694 | val |= 0x1100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 695 | } else |
| 696 | val = 0xffff; |
| 697 | |
| 698 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 699 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
| 700 | } |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 701 | |
| 702 | /* Make sure that interrupts are indeed enabled from here on */ |
| 703 | mmiowb(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 704 | } |
| 705 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 706 | static void bnx2x_int_disable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 707 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 708 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 709 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 710 | u32 val = REG_RD(bp, addr); |
| 711 | |
| 712 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 713 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 714 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 715 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
| 716 | |
| 717 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 718 | val, port, addr); |
| 719 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 720 | /* flush all outstanding writes */ |
| 721 | mmiowb(); |
| 722 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 723 | REG_WR(bp, addr, val); |
| 724 | if (REG_RD(bp, addr) != val) |
| 725 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); |
| 726 | } |
| 727 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 728 | static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 729 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 730 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 731 | int i, offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 732 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 733 | /* disable interrupt handling */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 734 | atomic_inc(&bp->intr_sem); |
Eilon Greenstein | e151070 | 2009-07-21 05:47:41 +0000 | [diff] [blame] | 735 | smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */ |
| 736 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 737 | if (disable_hw) |
| 738 | /* prevent the HW from sending interrupts */ |
| 739 | bnx2x_int_disable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 740 | |
| 741 | /* make sure all ISRs are done */ |
| 742 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 743 | synchronize_irq(bp->msix_table[0].vector); |
| 744 | offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 745 | for_each_queue(bp, i) |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 746 | synchronize_irq(bp->msix_table[i + offset].vector); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 747 | } else |
| 748 | synchronize_irq(bp->pdev->irq); |
| 749 | |
| 750 | /* make sure sp_task is not running */ |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 751 | cancel_delayed_work(&bp->sp_task); |
| 752 | flush_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 753 | } |
| 754 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 755 | /* fast path */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 756 | |
| 757 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 758 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 759 | */ |
| 760 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 761 | static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 762 | u8 storm, u16 index, u8 op, u8 update) |
| 763 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 764 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 765 | COMMAND_REG_INT_ACK); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 766 | struct igu_ack_register igu_ack; |
| 767 | |
| 768 | igu_ack.status_block_index = index; |
| 769 | igu_ack.sb_id_and_flags = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 770 | ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 771 | (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) | |
| 772 | (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) | |
| 773 | (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT)); |
| 774 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 775 | DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n", |
| 776 | (*(u32 *)&igu_ack), hc_addr); |
| 777 | REG_WR(bp, hc_addr, (*(u32 *)&igu_ack)); |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 778 | |
| 779 | /* Make sure that ACK is written */ |
| 780 | mmiowb(); |
| 781 | barrier(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp) |
| 785 | { |
| 786 | struct host_status_block *fpsb = fp->status_blk; |
| 787 | u16 rc = 0; |
| 788 | |
| 789 | barrier(); /* status block is written to by the chip */ |
| 790 | if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) { |
| 791 | fp->fp_c_idx = fpsb->c_status_block.status_block_index; |
| 792 | rc |= 1; |
| 793 | } |
| 794 | if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) { |
| 795 | fp->fp_u_idx = fpsb->u_status_block.status_block_index; |
| 796 | rc |= 2; |
| 797 | } |
| 798 | return rc; |
| 799 | } |
| 800 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 801 | static u16 bnx2x_ack_int(struct bnx2x *bp) |
| 802 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 803 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 804 | COMMAND_REG_SIMD_MASK); |
| 805 | u32 result = REG_RD(bp, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 806 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 807 | DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n", |
| 808 | result, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 809 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 810 | return result; |
| 811 | } |
| 812 | |
| 813 | |
| 814 | /* |
| 815 | * fast path service functions |
| 816 | */ |
| 817 | |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 818 | static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp) |
| 819 | { |
| 820 | /* Tell compiler that consumer and producer can change */ |
| 821 | barrier(); |
| 822 | return (fp->tx_pkt_prod != fp->tx_pkt_cons); |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 825 | /* free skb in the packet ring at pos idx |
| 826 | * return idx of last bd freed |
| 827 | */ |
| 828 | static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 829 | u16 idx) |
| 830 | { |
| 831 | struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx]; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 832 | struct eth_tx_start_bd *tx_start_bd; |
| 833 | struct eth_tx_bd *tx_data_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 834 | struct sk_buff *skb = tx_buf->skb; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 835 | u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 836 | int nbd; |
| 837 | |
| 838 | DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n", |
| 839 | idx, tx_buf, skb); |
| 840 | |
| 841 | /* unmap first bd */ |
| 842 | DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 843 | tx_start_bd = &fp->tx_desc_ring[bd_idx].start_bd; |
| 844 | pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_start_bd), |
| 845 | BD_UNMAP_LEN(tx_start_bd), PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 846 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 847 | nbd = le16_to_cpu(tx_start_bd->nbd) - 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 848 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 849 | if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 850 | BNX2X_ERR("BAD nbd!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 851 | bnx2x_panic(); |
| 852 | } |
| 853 | #endif |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 854 | new_cons = nbd + tx_buf->first_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 855 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 856 | /* Get the next bd */ |
| 857 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 858 | |
| 859 | /* Skip a parse bd... */ |
| 860 | --nbd; |
| 861 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 862 | |
| 863 | /* ...and the TSO split header bd since they have no mapping */ |
| 864 | if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) { |
| 865 | --nbd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 866 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /* now free frags */ |
| 870 | while (nbd > 0) { |
| 871 | |
| 872 | DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 873 | tx_data_bd = &fp->tx_desc_ring[bd_idx].reg_bd; |
| 874 | pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_data_bd), |
| 875 | BD_UNMAP_LEN(tx_data_bd), PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 876 | if (--nbd) |
| 877 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 878 | } |
| 879 | |
| 880 | /* release skb */ |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 881 | WARN_ON(!skb); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 882 | dev_kfree_skb_any(skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 883 | tx_buf->first_bd = 0; |
| 884 | tx_buf->skb = NULL; |
| 885 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 886 | return new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 887 | } |
| 888 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 889 | static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 890 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 891 | s16 used; |
| 892 | u16 prod; |
| 893 | u16 cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 894 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 895 | barrier(); /* Tell compiler that prod and cons can change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 896 | prod = fp->tx_bd_prod; |
| 897 | cons = fp->tx_bd_cons; |
| 898 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 899 | /* NUM_TX_RINGS = number of "next-page" entries |
| 900 | It will be used as a threshold */ |
| 901 | used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 902 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 903 | #ifdef BNX2X_STOP_ON_ERROR |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 904 | WARN_ON(used < 0); |
| 905 | WARN_ON(used > fp->bp->tx_ring_size); |
| 906 | WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 907 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 908 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 909 | return (s16)(fp->bp->tx_ring_size) - used; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 910 | } |
| 911 | |
Eilon Greenstein | 7961f79 | 2009-03-02 07:59:31 +0000 | [diff] [blame] | 912 | static void bnx2x_tx_int(struct bnx2x_fastpath *fp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 913 | { |
| 914 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 915 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 916 | u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons; |
| 917 | int done = 0; |
| 918 | |
| 919 | #ifdef BNX2X_STOP_ON_ERROR |
| 920 | if (unlikely(bp->panic)) |
| 921 | return; |
| 922 | #endif |
| 923 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 924 | txq = netdev_get_tx_queue(bp->dev, fp->index - bp->num_rx_queues); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 925 | hw_cons = le16_to_cpu(*fp->tx_cons_sb); |
| 926 | sw_cons = fp->tx_pkt_cons; |
| 927 | |
| 928 | while (sw_cons != hw_cons) { |
| 929 | u16 pkt_cons; |
| 930 | |
| 931 | pkt_cons = TX_BD(sw_cons); |
| 932 | |
| 933 | /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */ |
| 934 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 935 | DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 936 | hw_cons, sw_cons, pkt_cons); |
| 937 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 938 | /* if (NEXT_TX_IDX(sw_cons) != hw_cons) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 939 | rmb(); |
| 940 | prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb); |
| 941 | } |
| 942 | */ |
| 943 | bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons); |
| 944 | sw_cons++; |
| 945 | done++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | fp->tx_pkt_cons = sw_cons; |
| 949 | fp->tx_bd_cons = bd_cons; |
| 950 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 951 | /* TBD need a thresh? */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 952 | if (unlikely(netif_tx_queue_stopped(txq))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 953 | |
Eilon Greenstein | 6044735 | 2009-03-02 07:59:24 +0000 | [diff] [blame] | 954 | /* Need to make the tx_bd_cons update visible to start_xmit() |
| 955 | * before checking for netif_tx_queue_stopped(). Without the |
| 956 | * memory barrier, there is a small possibility that |
| 957 | * start_xmit() will miss it and cause the queue to be stopped |
| 958 | * forever. |
| 959 | */ |
| 960 | smp_mb(); |
| 961 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 962 | if ((netif_tx_queue_stopped(txq)) && |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 963 | (bp->state == BNX2X_STATE_OPEN) && |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 964 | (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 965 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 969 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 970 | static void bnx2x_sp_event(struct bnx2x_fastpath *fp, |
| 971 | union eth_rx_cqe *rr_cqe) |
| 972 | { |
| 973 | struct bnx2x *bp = fp->bp; |
| 974 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 975 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 976 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 977 | DP(BNX2X_MSG_SP, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 978 | "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] | 979 | fp->index, cid, command, bp->state, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 980 | rr_cqe->ramrod_cqe.ramrod_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 981 | |
| 982 | bp->spq_left++; |
| 983 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 984 | if (fp->index) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 985 | switch (command | fp->state) { |
| 986 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP | |
| 987 | BNX2X_FP_STATE_OPENING): |
| 988 | DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", |
| 989 | cid); |
| 990 | fp->state = BNX2X_FP_STATE_OPEN; |
| 991 | break; |
| 992 | |
| 993 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING): |
| 994 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", |
| 995 | cid); |
| 996 | fp->state = BNX2X_FP_STATE_HALTED; |
| 997 | break; |
| 998 | |
| 999 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1000 | BNX2X_ERR("unexpected MC reply (%d) " |
| 1001 | "fp->state is %x\n", command, fp->state); |
| 1002 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1003 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1004 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1005 | return; |
| 1006 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 1007 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1008 | switch (command | bp->state) { |
| 1009 | case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT): |
| 1010 | DP(NETIF_MSG_IFUP, "got setup ramrod\n"); |
| 1011 | bp->state = BNX2X_STATE_OPEN; |
| 1012 | break; |
| 1013 | |
| 1014 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 1015 | DP(NETIF_MSG_IFDOWN, "got halt ramrod\n"); |
| 1016 | bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE; |
| 1017 | fp->state = BNX2X_FP_STATE_HALTED; |
| 1018 | break; |
| 1019 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1020 | case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1021 | DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1022 | bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1023 | break; |
| 1024 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1025 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1026 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1027 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG): |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1028 | DP(NETIF_MSG_IFUP, "got set mac ramrod\n"); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 1029 | bp->set_mac_pending = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1030 | break; |
| 1031 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1032 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1033 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DISABLED): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1034 | DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n"); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 1035 | break; |
| 1036 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1037 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1038 | BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1039 | command, bp->state); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1040 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1041 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1042 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1045 | static inline void bnx2x_free_rx_sge(struct bnx2x *bp, |
| 1046 | struct bnx2x_fastpath *fp, u16 index) |
| 1047 | { |
| 1048 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 1049 | struct page *page = sw_buf->page; |
| 1050 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 1051 | |
| 1052 | /* Skip "next page" elements */ |
| 1053 | if (!page) |
| 1054 | return; |
| 1055 | |
| 1056 | pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1057 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1058 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1059 | |
| 1060 | sw_buf->page = NULL; |
| 1061 | sge->addr_hi = 0; |
| 1062 | sge->addr_lo = 0; |
| 1063 | } |
| 1064 | |
| 1065 | static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp, |
| 1066 | struct bnx2x_fastpath *fp, int last) |
| 1067 | { |
| 1068 | int i; |
| 1069 | |
| 1070 | for (i = 0; i < last; i++) |
| 1071 | bnx2x_free_rx_sge(bp, fp, i); |
| 1072 | } |
| 1073 | |
| 1074 | static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp, |
| 1075 | struct bnx2x_fastpath *fp, u16 index) |
| 1076 | { |
| 1077 | struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT); |
| 1078 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 1079 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 1080 | dma_addr_t mapping; |
| 1081 | |
| 1082 | if (unlikely(page == NULL)) |
| 1083 | return -ENOMEM; |
| 1084 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1085 | mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1086 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1087 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1088 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1089 | return -ENOMEM; |
| 1090 | } |
| 1091 | |
| 1092 | sw_buf->page = page; |
| 1093 | pci_unmap_addr_set(sw_buf, mapping, mapping); |
| 1094 | |
| 1095 | sge->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1096 | sge->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1101 | static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp, |
| 1102 | struct bnx2x_fastpath *fp, u16 index) |
| 1103 | { |
| 1104 | struct sk_buff *skb; |
| 1105 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index]; |
| 1106 | struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index]; |
| 1107 | dma_addr_t mapping; |
| 1108 | |
| 1109 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1110 | if (unlikely(skb == NULL)) |
| 1111 | return -ENOMEM; |
| 1112 | |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1113 | mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1114 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1115 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1116 | dev_kfree_skb(skb); |
| 1117 | return -ENOMEM; |
| 1118 | } |
| 1119 | |
| 1120 | rx_buf->skb = skb; |
| 1121 | pci_unmap_addr_set(rx_buf, mapping, mapping); |
| 1122 | |
| 1123 | rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1124 | rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1125 | |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | /* note that we are not allocating a new skb, |
| 1130 | * we are just moving one from cons to prod |
| 1131 | * we are not creating a new mapping, |
| 1132 | * so there is no need to check for dma_mapping_error(). |
| 1133 | */ |
| 1134 | static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp, |
| 1135 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1136 | { |
| 1137 | struct bnx2x *bp = fp->bp; |
| 1138 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1139 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1140 | struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons]; |
| 1141 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1142 | |
| 1143 | pci_dma_sync_single_for_device(bp->pdev, |
| 1144 | pci_unmap_addr(cons_rx_buf, mapping), |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 1145 | RX_COPY_THRESH, PCI_DMA_FROMDEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1146 | |
| 1147 | prod_rx_buf->skb = cons_rx_buf->skb; |
| 1148 | pci_unmap_addr_set(prod_rx_buf, mapping, |
| 1149 | pci_unmap_addr(cons_rx_buf, mapping)); |
| 1150 | *prod_bd = *cons_bd; |
| 1151 | } |
| 1152 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1153 | static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp, |
| 1154 | u16 idx) |
| 1155 | { |
| 1156 | u16 last_max = fp->last_max_sge; |
| 1157 | |
| 1158 | if (SUB_S16(idx, last_max) > 0) |
| 1159 | fp->last_max_sge = idx; |
| 1160 | } |
| 1161 | |
| 1162 | static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp) |
| 1163 | { |
| 1164 | int i, j; |
| 1165 | |
| 1166 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 1167 | int idx = RX_SGE_CNT * i - 1; |
| 1168 | |
| 1169 | for (j = 0; j < 2; j++) { |
| 1170 | SGE_MASK_CLEAR_BIT(fp, idx); |
| 1171 | idx--; |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp, |
| 1177 | struct eth_fast_path_rx_cqe *fp_cqe) |
| 1178 | { |
| 1179 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1180 | u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) - |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1181 | le16_to_cpu(fp_cqe->len_on_bd)) >> |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1182 | SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1183 | u16 last_max, last_elem, first_elem; |
| 1184 | u16 delta = 0; |
| 1185 | u16 i; |
| 1186 | |
| 1187 | if (!sge_len) |
| 1188 | return; |
| 1189 | |
| 1190 | /* First mark all used pages */ |
| 1191 | for (i = 0; i < sge_len; i++) |
| 1192 | SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i]))); |
| 1193 | |
| 1194 | DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n", |
| 1195 | sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1196 | |
| 1197 | /* Here we assume that the last SGE index is the biggest */ |
| 1198 | prefetch((void *)(fp->sge_mask)); |
| 1199 | bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1200 | |
| 1201 | last_max = RX_SGE(fp->last_max_sge); |
| 1202 | last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT; |
| 1203 | first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT; |
| 1204 | |
| 1205 | /* If ring is not full */ |
| 1206 | if (last_elem + 1 != first_elem) |
| 1207 | last_elem++; |
| 1208 | |
| 1209 | /* Now update the prod */ |
| 1210 | for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) { |
| 1211 | if (likely(fp->sge_mask[i])) |
| 1212 | break; |
| 1213 | |
| 1214 | fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK; |
| 1215 | delta += RX_SGE_MASK_ELEM_SZ; |
| 1216 | } |
| 1217 | |
| 1218 | if (delta > 0) { |
| 1219 | fp->rx_sge_prod += delta; |
| 1220 | /* clear page-end entries */ |
| 1221 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1222 | } |
| 1223 | |
| 1224 | DP(NETIF_MSG_RX_STATUS, |
| 1225 | "fp->last_max_sge = %d fp->rx_sge_prod = %d\n", |
| 1226 | fp->last_max_sge, fp->rx_sge_prod); |
| 1227 | } |
| 1228 | |
| 1229 | static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp) |
| 1230 | { |
| 1231 | /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */ |
| 1232 | memset(fp->sge_mask, 0xff, |
| 1233 | (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64)); |
| 1234 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 1235 | /* Clear the two last indices in the page to 1: |
| 1236 | these are the indices that correspond to the "next" element, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1237 | hence will never be indicated and should be removed from |
| 1238 | the calculations. */ |
| 1239 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1240 | } |
| 1241 | |
| 1242 | static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue, |
| 1243 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1244 | { |
| 1245 | struct bnx2x *bp = fp->bp; |
| 1246 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1247 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1248 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1249 | dma_addr_t mapping; |
| 1250 | |
| 1251 | /* move empty skb from pool to prod and map it */ |
| 1252 | prod_rx_buf->skb = fp->tpa_pool[queue].skb; |
| 1253 | mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data, |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1254 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1255 | pci_unmap_addr_set(prod_rx_buf, mapping, mapping); |
| 1256 | |
| 1257 | /* move partial skb from cons to pool (don't unmap yet) */ |
| 1258 | fp->tpa_pool[queue] = *cons_rx_buf; |
| 1259 | |
| 1260 | /* mark bin state as start - print error if current state != stop */ |
| 1261 | if (fp->tpa_state[queue] != BNX2X_TPA_STOP) |
| 1262 | BNX2X_ERR("start of bin not in stop [%d]\n", queue); |
| 1263 | |
| 1264 | fp->tpa_state[queue] = BNX2X_TPA_START; |
| 1265 | |
| 1266 | /* point prod_bd to new skb */ |
| 1267 | prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1268 | prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1269 | |
| 1270 | #ifdef BNX2X_STOP_ON_ERROR |
| 1271 | fp->tpa_queue_used |= (1 << queue); |
| 1272 | #ifdef __powerpc64__ |
| 1273 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n", |
| 1274 | #else |
| 1275 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n", |
| 1276 | #endif |
| 1277 | fp->tpa_queue_used); |
| 1278 | #endif |
| 1279 | } |
| 1280 | |
| 1281 | static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1282 | struct sk_buff *skb, |
| 1283 | struct eth_fast_path_rx_cqe *fp_cqe, |
| 1284 | u16 cqe_idx) |
| 1285 | { |
| 1286 | struct sw_rx_page *rx_pg, old_rx_pg; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1287 | u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd); |
| 1288 | u32 i, frag_len, frag_size, pages; |
| 1289 | int err; |
| 1290 | int j; |
| 1291 | |
| 1292 | frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1293 | pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1294 | |
| 1295 | /* This is needed in order to enable forwarding support */ |
| 1296 | if (frag_size) |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1297 | skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1298 | max(frag_size, (u32)len_on_bd)); |
| 1299 | |
| 1300 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1301 | if (pages > |
| 1302 | min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1303 | BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n", |
| 1304 | pages, cqe_idx); |
| 1305 | BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n", |
| 1306 | fp_cqe->pkt_len, len_on_bd); |
| 1307 | bnx2x_panic(); |
| 1308 | return -EINVAL; |
| 1309 | } |
| 1310 | #endif |
| 1311 | |
| 1312 | /* Run through the SGL and compose the fragmented skb */ |
| 1313 | for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) { |
| 1314 | u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j])); |
| 1315 | |
| 1316 | /* FW gives the indices of the SGE as if the ring is an array |
| 1317 | (meaning that "next" element will consume 2 indices) */ |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1318 | frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1319 | rx_pg = &fp->rx_page_ring[sge_idx]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1320 | old_rx_pg = *rx_pg; |
| 1321 | |
| 1322 | /* If we fail to allocate a substitute page, we simply stop |
| 1323 | where we are and drop the whole packet */ |
| 1324 | err = bnx2x_alloc_rx_sge(bp, fp, sge_idx); |
| 1325 | if (unlikely(err)) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1326 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1327 | return err; |
| 1328 | } |
| 1329 | |
| 1330 | /* Unmap the page as we r going to pass it to the stack */ |
| 1331 | pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1332 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1333 | |
| 1334 | /* Add one frag and update the appropriate fields in the skb */ |
| 1335 | skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len); |
| 1336 | |
| 1337 | skb->data_len += frag_len; |
| 1338 | skb->truesize += frag_len; |
| 1339 | skb->len += frag_len; |
| 1340 | |
| 1341 | frag_size -= frag_len; |
| 1342 | } |
| 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1348 | u16 queue, int pad, int len, union eth_rx_cqe *cqe, |
| 1349 | u16 cqe_idx) |
| 1350 | { |
| 1351 | struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue]; |
| 1352 | struct sk_buff *skb = rx_buf->skb; |
| 1353 | /* alloc new skb */ |
| 1354 | struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1355 | |
| 1356 | /* Unmap skb in the pool anyway, as we are going to change |
| 1357 | pool entry status to BNX2X_TPA_STOP even if new skb allocation |
| 1358 | fails. */ |
| 1359 | pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1360 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1361 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1362 | if (likely(new_skb)) { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1363 | /* fix ip xsum and give it to the stack */ |
| 1364 | /* (no need to map the new skb) */ |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1365 | #ifdef BCM_VLAN |
| 1366 | int is_vlan_cqe = |
| 1367 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1368 | PARSING_FLAGS_VLAN); |
| 1369 | int is_not_hwaccel_vlan_cqe = |
| 1370 | (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG))); |
| 1371 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | prefetch(skb); |
| 1374 | prefetch(((char *)(skb)) + 128); |
| 1375 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1376 | #ifdef BNX2X_STOP_ON_ERROR |
| 1377 | if (pad + len > bp->rx_buf_size) { |
| 1378 | BNX2X_ERR("skb_put is about to fail... " |
| 1379 | "pad %d len %d rx_buf_size %d\n", |
| 1380 | pad, len, bp->rx_buf_size); |
| 1381 | bnx2x_panic(); |
| 1382 | return; |
| 1383 | } |
| 1384 | #endif |
| 1385 | |
| 1386 | skb_reserve(skb, pad); |
| 1387 | skb_put(skb, len); |
| 1388 | |
| 1389 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1390 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1391 | |
| 1392 | { |
| 1393 | struct iphdr *iph; |
| 1394 | |
| 1395 | iph = (struct iphdr *)skb->data; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1396 | #ifdef BCM_VLAN |
| 1397 | /* If there is no Rx VLAN offloading - |
| 1398 | take VLAN tag into an account */ |
| 1399 | if (unlikely(is_not_hwaccel_vlan_cqe)) |
| 1400 | iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN); |
| 1401 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1402 | iph->check = 0; |
| 1403 | iph->check = ip_fast_csum((u8 *)iph, iph->ihl); |
| 1404 | } |
| 1405 | |
| 1406 | if (!bnx2x_fill_frag_skb(bp, fp, skb, |
| 1407 | &cqe->fast_path_cqe, cqe_idx)) { |
| 1408 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1409 | if ((bp->vlgrp != NULL) && is_vlan_cqe && |
| 1410 | (!is_not_hwaccel_vlan_cqe)) |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1411 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1412 | le16_to_cpu(cqe->fast_path_cqe. |
| 1413 | vlan_tag)); |
| 1414 | else |
| 1415 | #endif |
| 1416 | netif_receive_skb(skb); |
| 1417 | } else { |
| 1418 | DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages" |
| 1419 | " - dropping packet!\n"); |
| 1420 | dev_kfree_skb(skb); |
| 1421 | } |
| 1422 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1423 | |
| 1424 | /* put new skb in bin */ |
| 1425 | fp->tpa_pool[queue].skb = new_skb; |
| 1426 | |
| 1427 | } else { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1428 | /* else drop the packet and keep the buffer in the bin */ |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1429 | DP(NETIF_MSG_RX_STATUS, |
| 1430 | "Failed to allocate new skb - dropping packet!\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1431 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | fp->tpa_state[queue] = BNX2X_TPA_STOP; |
| 1435 | } |
| 1436 | |
| 1437 | static inline void bnx2x_update_rx_prod(struct bnx2x *bp, |
| 1438 | struct bnx2x_fastpath *fp, |
| 1439 | u16 bd_prod, u16 rx_comp_prod, |
| 1440 | u16 rx_sge_prod) |
| 1441 | { |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1442 | struct ustorm_eth_rx_producers rx_prods = {0}; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1443 | int i; |
| 1444 | |
| 1445 | /* Update producers */ |
| 1446 | rx_prods.bd_prod = bd_prod; |
| 1447 | rx_prods.cqe_prod = rx_comp_prod; |
| 1448 | rx_prods.sge_prod = rx_sge_prod; |
| 1449 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1450 | /* |
| 1451 | * Make sure that the BD and SGE data is updated before updating the |
| 1452 | * producers since FW might read the BD/SGE right after the producer |
| 1453 | * is updated. |
| 1454 | * This is only applicable for weak-ordered memory model archs such |
| 1455 | * as IA-64. The following barrier is also mandatory since FW will |
| 1456 | * assumes BDs must have buffers. |
| 1457 | */ |
| 1458 | wmb(); |
| 1459 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1460 | for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++) |
| 1461 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1462 | USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1463 | ((u32 *)&rx_prods)[i]); |
| 1464 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1465 | mmiowb(); /* keep prod updates ordered */ |
| 1466 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1467 | DP(NETIF_MSG_RX_STATUS, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1468 | "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n", |
| 1469 | fp->index, bd_prod, rx_comp_prod, rx_sge_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1472 | static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget) |
| 1473 | { |
| 1474 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1475 | u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1476 | u16 hw_comp_cons, sw_comp_cons, sw_comp_prod; |
| 1477 | int rx_pkt = 0; |
| 1478 | |
| 1479 | #ifdef BNX2X_STOP_ON_ERROR |
| 1480 | if (unlikely(bp->panic)) |
| 1481 | return 0; |
| 1482 | #endif |
| 1483 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1484 | /* CQ "next element" is of the size of the regular element, |
| 1485 | that's why it's ok here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1486 | hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb); |
| 1487 | if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 1488 | hw_comp_cons++; |
| 1489 | |
| 1490 | bd_cons = fp->rx_bd_cons; |
| 1491 | bd_prod = fp->rx_bd_prod; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1492 | bd_prod_fw = bd_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1493 | sw_comp_cons = fp->rx_comp_cons; |
| 1494 | sw_comp_prod = fp->rx_comp_prod; |
| 1495 | |
| 1496 | /* Memory barrier necessary as speculative reads of the rx |
| 1497 | * buffer can be ahead of the index in the status block |
| 1498 | */ |
| 1499 | rmb(); |
| 1500 | |
| 1501 | DP(NETIF_MSG_RX_STATUS, |
| 1502 | "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n", |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1503 | fp->index, hw_comp_cons, sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1504 | |
| 1505 | while (sw_comp_cons != hw_comp_cons) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1506 | struct sw_rx_bd *rx_buf = NULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1507 | struct sk_buff *skb; |
| 1508 | union eth_rx_cqe *cqe; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1509 | u8 cqe_fp_flags; |
| 1510 | u16 len, pad; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1511 | |
| 1512 | comp_ring_cons = RCQ_BD(sw_comp_cons); |
| 1513 | bd_prod = RX_BD(bd_prod); |
| 1514 | bd_cons = RX_BD(bd_cons); |
| 1515 | |
Eilon Greenstein | 619e7a6 | 2009-08-12 08:23:20 +0000 | [diff] [blame] | 1516 | /* Prefetch the page containing the BD descriptor |
| 1517 | at producer's index. It will be needed when new skb is |
| 1518 | allocated */ |
| 1519 | prefetch((void *)(PAGE_ALIGN((unsigned long) |
| 1520 | (&fp->rx_desc_ring[bd_prod])) - |
| 1521 | PAGE_SIZE + 1)); |
| 1522 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1523 | cqe = &fp->rx_comp_ring[comp_ring_cons]; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1524 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1525 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1526 | DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1527 | " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags), |
| 1528 | cqe_fp_flags, cqe->fast_path_cqe.status_flags, |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 1529 | le32_to_cpu(cqe->fast_path_cqe.rss_hash_result), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1530 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag), |
| 1531 | le16_to_cpu(cqe->fast_path_cqe.pkt_len)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1532 | |
| 1533 | /* is this a slowpath msg? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1534 | if (unlikely(CQE_TYPE(cqe_fp_flags))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1535 | bnx2x_sp_event(fp, cqe); |
| 1536 | goto next_cqe; |
| 1537 | |
| 1538 | /* this is an rx packet */ |
| 1539 | } else { |
| 1540 | rx_buf = &fp->rx_buf_ring[bd_cons]; |
| 1541 | skb = rx_buf->skb; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1542 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 1543 | pad = cqe->fast_path_cqe.placement_offset; |
| 1544 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1545 | /* If CQE is marked both TPA_START and TPA_END |
| 1546 | it is a non-TPA CQE */ |
| 1547 | if ((!fp->disable_tpa) && |
| 1548 | (TPA_TYPE(cqe_fp_flags) != |
| 1549 | (TPA_TYPE_START | TPA_TYPE_END))) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1550 | u16 queue = cqe->fast_path_cqe.queue_index; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1551 | |
| 1552 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) { |
| 1553 | DP(NETIF_MSG_RX_STATUS, |
| 1554 | "calling tpa_start on queue %d\n", |
| 1555 | queue); |
| 1556 | |
| 1557 | bnx2x_tpa_start(fp, queue, skb, |
| 1558 | bd_cons, bd_prod); |
| 1559 | goto next_rx; |
| 1560 | } |
| 1561 | |
| 1562 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) { |
| 1563 | DP(NETIF_MSG_RX_STATUS, |
| 1564 | "calling tpa_stop on queue %d\n", |
| 1565 | queue); |
| 1566 | |
| 1567 | if (!BNX2X_RX_SUM_FIX(cqe)) |
| 1568 | BNX2X_ERR("STOP on none TCP " |
| 1569 | "data\n"); |
| 1570 | |
| 1571 | /* This is a size of the linear data |
| 1572 | on this skb */ |
| 1573 | len = le16_to_cpu(cqe->fast_path_cqe. |
| 1574 | len_on_bd); |
| 1575 | bnx2x_tpa_stop(bp, fp, queue, pad, |
| 1576 | len, cqe, comp_ring_cons); |
| 1577 | #ifdef BNX2X_STOP_ON_ERROR |
| 1578 | if (bp->panic) |
Stanislaw Gruszka | 17cb4006 | 2009-05-05 23:22:12 +0000 | [diff] [blame] | 1579 | return 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1580 | #endif |
| 1581 | |
| 1582 | bnx2x_update_sge_prod(fp, |
| 1583 | &cqe->fast_path_cqe); |
| 1584 | goto next_cqe; |
| 1585 | } |
| 1586 | } |
| 1587 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1588 | pci_dma_sync_single_for_device(bp->pdev, |
| 1589 | pci_unmap_addr(rx_buf, mapping), |
| 1590 | pad + RX_COPY_THRESH, |
| 1591 | PCI_DMA_FROMDEVICE); |
| 1592 | prefetch(skb); |
| 1593 | prefetch(((char *)(skb)) + 128); |
| 1594 | |
| 1595 | /* is this an error packet? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1596 | if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1597 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1598 | "ERROR flags %x rx packet %u\n", |
| 1599 | cqe_fp_flags, sw_comp_cons); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1600 | fp->eth_q_stats.rx_err_discard_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1601 | goto reuse_rx; |
| 1602 | } |
| 1603 | |
| 1604 | /* Since we don't have a jumbo ring |
| 1605 | * copy small packets if mtu > 1500 |
| 1606 | */ |
| 1607 | if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) && |
| 1608 | (len <= RX_COPY_THRESH)) { |
| 1609 | struct sk_buff *new_skb; |
| 1610 | |
| 1611 | new_skb = netdev_alloc_skb(bp->dev, |
| 1612 | len + pad); |
| 1613 | if (new_skb == NULL) { |
| 1614 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1615 | "ERROR packet dropped " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1616 | "because of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1617 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1618 | goto reuse_rx; |
| 1619 | } |
| 1620 | |
| 1621 | /* aligned copy */ |
| 1622 | skb_copy_from_linear_data_offset(skb, pad, |
| 1623 | new_skb->data + pad, len); |
| 1624 | skb_reserve(new_skb, pad); |
| 1625 | skb_put(new_skb, len); |
| 1626 | |
| 1627 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1628 | |
| 1629 | skb = new_skb; |
| 1630 | |
Eilon Greenstein | a119a06 | 2009-08-12 08:23:23 +0000 | [diff] [blame] | 1631 | } else |
| 1632 | if (likely(bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1633 | pci_unmap_single(bp->pdev, |
| 1634 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1635 | bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1636 | PCI_DMA_FROMDEVICE); |
| 1637 | skb_reserve(skb, pad); |
| 1638 | skb_put(skb, len); |
| 1639 | |
| 1640 | } else { |
| 1641 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1642 | "ERROR packet dropped because " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1643 | "of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1644 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1645 | reuse_rx: |
| 1646 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1647 | goto next_rx; |
| 1648 | } |
| 1649 | |
| 1650 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1651 | |
| 1652 | skb->ip_summed = CHECKSUM_NONE; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1653 | if (bp->rx_csum) { |
Eilon Greenstein | 1adcd8b | 2008-08-13 15:48:29 -0700 | [diff] [blame] | 1654 | if (likely(BNX2X_RX_CSUM_OK(cqe))) |
| 1655 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1656 | else |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1657 | fp->eth_q_stats.hw_csum_err++; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1658 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1659 | } |
| 1660 | |
Eilon Greenstein | 748e543 | 2009-02-12 08:36:37 +0000 | [diff] [blame] | 1661 | skb_record_rx_queue(skb, fp->index); |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 1662 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1663 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1664 | if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) && |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1665 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1666 | PARSING_FLAGS_VLAN)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1667 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1668 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag)); |
| 1669 | else |
| 1670 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1671 | netif_receive_skb(skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1672 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1673 | |
| 1674 | next_rx: |
| 1675 | rx_buf->skb = NULL; |
| 1676 | |
| 1677 | bd_cons = NEXT_RX_IDX(bd_cons); |
| 1678 | bd_prod = NEXT_RX_IDX(bd_prod); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1679 | bd_prod_fw = NEXT_RX_IDX(bd_prod_fw); |
| 1680 | rx_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1681 | next_cqe: |
| 1682 | sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod); |
| 1683 | sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1684 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1685 | if (rx_pkt == budget) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1686 | break; |
| 1687 | } /* while */ |
| 1688 | |
| 1689 | fp->rx_bd_cons = bd_cons; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1690 | fp->rx_bd_prod = bd_prod_fw; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1691 | fp->rx_comp_cons = sw_comp_cons; |
| 1692 | fp->rx_comp_prod = sw_comp_prod; |
| 1693 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1694 | /* Update producers */ |
| 1695 | bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod, |
| 1696 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1697 | |
| 1698 | fp->rx_pkt += rx_pkt; |
| 1699 | fp->rx_calls++; |
| 1700 | |
| 1701 | return rx_pkt; |
| 1702 | } |
| 1703 | |
| 1704 | static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie) |
| 1705 | { |
| 1706 | struct bnx2x_fastpath *fp = fp_cookie; |
| 1707 | struct bnx2x *bp = fp->bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1708 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 1709 | /* Return here if interrupt is disabled */ |
| 1710 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1711 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1712 | return IRQ_HANDLED; |
| 1713 | } |
| 1714 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1715 | DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n", |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1716 | fp->index, fp->sb_id); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 1717 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1718 | |
| 1719 | #ifdef BNX2X_STOP_ON_ERROR |
| 1720 | if (unlikely(bp->panic)) |
| 1721 | return IRQ_HANDLED; |
| 1722 | #endif |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1723 | /* Handle Rx or Tx according to MSI-X vector */ |
| 1724 | if (fp->is_rx_queue) { |
| 1725 | prefetch(fp->rx_cons_sb); |
| 1726 | prefetch(&fp->status_blk->u_status_block.status_block_index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1727 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1728 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1729 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1730 | } else { |
| 1731 | prefetch(fp->tx_cons_sb); |
| 1732 | prefetch(&fp->status_blk->c_status_block.status_block_index); |
| 1733 | |
| 1734 | bnx2x_update_fpsb_idx(fp); |
| 1735 | rmb(); |
| 1736 | bnx2x_tx_int(fp); |
| 1737 | |
| 1738 | /* Re-enable interrupts */ |
| 1739 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, |
| 1740 | le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1); |
| 1741 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, |
| 1742 | le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1); |
| 1743 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1744 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1745 | return IRQ_HANDLED; |
| 1746 | } |
| 1747 | |
| 1748 | static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
| 1749 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1750 | struct bnx2x *bp = netdev_priv(dev_instance); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1751 | u16 status = bnx2x_ack_int(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1752 | u16 mask; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1753 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1754 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1755 | /* Return here if interrupt is shared and it's not for us */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1756 | if (unlikely(status == 0)) { |
| 1757 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); |
| 1758 | return IRQ_NONE; |
| 1759 | } |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 1760 | DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1761 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1762 | /* Return here if interrupt is disabled */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1763 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1764 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1765 | return IRQ_HANDLED; |
| 1766 | } |
| 1767 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1768 | #ifdef BNX2X_STOP_ON_ERROR |
| 1769 | if (unlikely(bp->panic)) |
| 1770 | return IRQ_HANDLED; |
| 1771 | #endif |
| 1772 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1773 | for (i = 0; i < BNX2X_NUM_QUEUES(bp); i++) { |
| 1774 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1775 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1776 | mask = 0x2 << fp->sb_id; |
| 1777 | if (status & mask) { |
| 1778 | /* Handle Rx or Tx according to SB id */ |
| 1779 | if (fp->is_rx_queue) { |
| 1780 | prefetch(fp->rx_cons_sb); |
| 1781 | prefetch(&fp->status_blk->u_status_block. |
| 1782 | status_block_index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1783 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1784 | napi_schedule(&bnx2x_fp(bp, fp->index, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1785 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 1786 | } else { |
| 1787 | prefetch(fp->tx_cons_sb); |
| 1788 | prefetch(&fp->status_blk->c_status_block. |
| 1789 | status_block_index); |
| 1790 | |
| 1791 | bnx2x_update_fpsb_idx(fp); |
| 1792 | rmb(); |
| 1793 | bnx2x_tx_int(fp); |
| 1794 | |
| 1795 | /* Re-enable interrupts */ |
| 1796 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, |
| 1797 | le16_to_cpu(fp->fp_u_idx), |
| 1798 | IGU_INT_NOP, 1); |
| 1799 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, |
| 1800 | le16_to_cpu(fp->fp_c_idx), |
| 1801 | IGU_INT_ENABLE, 1); |
| 1802 | } |
| 1803 | status &= ~mask; |
| 1804 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1807 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1808 | if (unlikely(status & 0x1)) { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 1809 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1810 | |
| 1811 | status &= ~0x1; |
| 1812 | if (!status) |
| 1813 | return IRQ_HANDLED; |
| 1814 | } |
| 1815 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1816 | if (status) |
| 1817 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n", |
| 1818 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1819 | |
| 1820 | return IRQ_HANDLED; |
| 1821 | } |
| 1822 | |
| 1823 | /* end of fast path */ |
| 1824 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 1825 | static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1826 | |
| 1827 | /* Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1828 | |
| 1829 | /* |
| 1830 | * General service functions |
| 1831 | */ |
| 1832 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1833 | static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1834 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1835 | u32 lock_status; |
| 1836 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1837 | int func = BP_FUNC(bp); |
| 1838 | u32 hw_lock_control_reg; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1839 | int cnt; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1840 | |
| 1841 | /* Validating that the resource is within range */ |
| 1842 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1843 | DP(NETIF_MSG_HW, |
| 1844 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1845 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1846 | return -EINVAL; |
| 1847 | } |
| 1848 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1849 | if (func <= 5) { |
| 1850 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1851 | } else { |
| 1852 | hw_lock_control_reg = |
| 1853 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1854 | } |
| 1855 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1856 | /* Validating that the resource is not already taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1857 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1858 | if (lock_status & resource_bit) { |
| 1859 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1860 | lock_status, resource_bit); |
| 1861 | return -EEXIST; |
| 1862 | } |
| 1863 | |
Eilon Greenstein | 46230476b | 2008-08-25 15:23:30 -0700 | [diff] [blame] | 1864 | /* Try for 5 second every 5ms */ |
| 1865 | for (cnt = 0; cnt < 1000; cnt++) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1866 | /* Try to acquire the lock */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1867 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
| 1868 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1869 | if (lock_status & resource_bit) |
| 1870 | return 0; |
| 1871 | |
| 1872 | msleep(5); |
| 1873 | } |
| 1874 | DP(NETIF_MSG_HW, "Timeout\n"); |
| 1875 | return -EAGAIN; |
| 1876 | } |
| 1877 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1878 | static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1879 | { |
| 1880 | u32 lock_status; |
| 1881 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1882 | int func = BP_FUNC(bp); |
| 1883 | u32 hw_lock_control_reg; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1884 | |
| 1885 | /* Validating that the resource is within range */ |
| 1886 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1887 | DP(NETIF_MSG_HW, |
| 1888 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1889 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1890 | return -EINVAL; |
| 1891 | } |
| 1892 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1893 | if (func <= 5) { |
| 1894 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1895 | } else { |
| 1896 | hw_lock_control_reg = |
| 1897 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1898 | } |
| 1899 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1900 | /* Validating that the resource is currently taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1901 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1902 | if (!(lock_status & resource_bit)) { |
| 1903 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1904 | lock_status, resource_bit); |
| 1905 | return -EFAULT; |
| 1906 | } |
| 1907 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1908 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1909 | return 0; |
| 1910 | } |
| 1911 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1912 | /* HW Lock for shared dual port PHYs */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1913 | static void bnx2x_acquire_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1914 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1915 | mutex_lock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1916 | |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 1917 | if (bp->port.need_hw_lock) |
| 1918 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1921 | static void bnx2x_release_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1922 | { |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 1923 | if (bp->port.need_hw_lock) |
| 1924 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1925 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1926 | mutex_unlock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 1929 | int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port) |
| 1930 | { |
| 1931 | /* The GPIO should be swapped if swap register is set and active */ |
| 1932 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 1933 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 1934 | int gpio_shift = gpio_num + |
| 1935 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1936 | u32 gpio_mask = (1 << gpio_shift); |
| 1937 | u32 gpio_reg; |
| 1938 | int value; |
| 1939 | |
| 1940 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1941 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1942 | return -EINVAL; |
| 1943 | } |
| 1944 | |
| 1945 | /* read GPIO value */ |
| 1946 | gpio_reg = REG_RD(bp, MISC_REG_GPIO); |
| 1947 | |
| 1948 | /* get the requested pin value */ |
| 1949 | if ((gpio_reg & gpio_mask) == gpio_mask) |
| 1950 | value = 1; |
| 1951 | else |
| 1952 | value = 0; |
| 1953 | |
| 1954 | DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value); |
| 1955 | |
| 1956 | return value; |
| 1957 | } |
| 1958 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1959 | 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] | 1960 | { |
| 1961 | /* The GPIO should be swapped if swap register is set and active */ |
| 1962 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1963 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1964 | int gpio_shift = gpio_num + |
| 1965 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1966 | u32 gpio_mask = (1 << gpio_shift); |
| 1967 | u32 gpio_reg; |
| 1968 | |
| 1969 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1970 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1971 | return -EINVAL; |
| 1972 | } |
| 1973 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1974 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1975 | /* read GPIO and mask except the float bits */ |
| 1976 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); |
| 1977 | |
| 1978 | switch (mode) { |
| 1979 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: |
| 1980 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n", |
| 1981 | gpio_num, gpio_shift); |
| 1982 | /* clear FLOAT and set CLR */ |
| 1983 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1984 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); |
| 1985 | break; |
| 1986 | |
| 1987 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
| 1988 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n", |
| 1989 | gpio_num, gpio_shift); |
| 1990 | /* clear FLOAT and set SET */ |
| 1991 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1992 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); |
| 1993 | break; |
| 1994 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1995 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1996 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n", |
| 1997 | gpio_num, gpio_shift); |
| 1998 | /* set FLOAT */ |
| 1999 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 2000 | break; |
| 2001 | |
| 2002 | default: |
| 2003 | break; |
| 2004 | } |
| 2005 | |
| 2006 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2007 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2008 | |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
Eilon Greenstein | 4acac6a | 2009-02-12 08:36:52 +0000 | [diff] [blame] | 2012 | int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
| 2013 | { |
| 2014 | /* The GPIO should be swapped if swap register is set and active */ |
| 2015 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
| 2016 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
| 2017 | int gpio_shift = gpio_num + |
| 2018 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 2019 | u32 gpio_mask = (1 << gpio_shift); |
| 2020 | u32 gpio_reg; |
| 2021 | |
| 2022 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 2023 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 2024 | return -EINVAL; |
| 2025 | } |
| 2026 | |
| 2027 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 2028 | /* read GPIO int */ |
| 2029 | gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT); |
| 2030 | |
| 2031 | switch (mode) { |
| 2032 | case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR: |
| 2033 | DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> " |
| 2034 | "output low\n", gpio_num, gpio_shift); |
| 2035 | /* clear SET and set CLR */ |
| 2036 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 2037 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 2038 | break; |
| 2039 | |
| 2040 | case MISC_REGISTERS_GPIO_INT_OUTPUT_SET: |
| 2041 | DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> " |
| 2042 | "output high\n", gpio_num, gpio_shift); |
| 2043 | /* clear CLR and set SET */ |
| 2044 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS); |
| 2045 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS); |
| 2046 | break; |
| 2047 | |
| 2048 | default: |
| 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg); |
| 2053 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
| 2054 | |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2058 | static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode) |
| 2059 | { |
| 2060 | u32 spio_mask = (1 << spio_num); |
| 2061 | u32 spio_reg; |
| 2062 | |
| 2063 | if ((spio_num < MISC_REGISTERS_SPIO_4) || |
| 2064 | (spio_num > MISC_REGISTERS_SPIO_7)) { |
| 2065 | BNX2X_ERR("Invalid SPIO %d\n", spio_num); |
| 2066 | return -EINVAL; |
| 2067 | } |
| 2068 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2069 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2070 | /* read SPIO and mask except the float bits */ |
| 2071 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT); |
| 2072 | |
| 2073 | switch (mode) { |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2074 | case MISC_REGISTERS_SPIO_OUTPUT_LOW: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2075 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num); |
| 2076 | /* clear FLOAT and set CLR */ |
| 2077 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2078 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS); |
| 2079 | break; |
| 2080 | |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2081 | case MISC_REGISTERS_SPIO_OUTPUT_HIGH: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2082 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num); |
| 2083 | /* clear FLOAT and set SET */ |
| 2084 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2085 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS); |
| 2086 | break; |
| 2087 | |
| 2088 | case MISC_REGISTERS_SPIO_INPUT_HI_Z: |
| 2089 | DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num); |
| 2090 | /* set FLOAT */ |
| 2091 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 2092 | break; |
| 2093 | |
| 2094 | default: |
| 2095 | break; |
| 2096 | } |
| 2097 | |
| 2098 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2099 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2100 | |
| 2101 | return 0; |
| 2102 | } |
| 2103 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2104 | static void bnx2x_calc_fc_adv(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2105 | { |
Eilon Greenstein | ad33ea3 | 2009-01-14 21:24:57 -0800 | [diff] [blame] | 2106 | switch (bp->link_vars.ieee_fc & |
| 2107 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2108 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2109 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2110 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2111 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2112 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2113 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2114 | bp->port.advertising |= (ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2115 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2116 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2117 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2118 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2119 | bp->port.advertising |= ADVERTISED_Asym_Pause; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2120 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2121 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2122 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2123 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2124 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2125 | break; |
| 2126 | } |
| 2127 | } |
| 2128 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2129 | static void bnx2x_link_report(struct bnx2x *bp) |
| 2130 | { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2131 | if (bp->state == BNX2X_STATE_DISABLED) { |
| 2132 | netif_carrier_off(bp->dev); |
| 2133 | printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name); |
| 2134 | return; |
| 2135 | } |
| 2136 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2137 | if (bp->link_vars.link_up) { |
| 2138 | if (bp->state == BNX2X_STATE_OPEN) |
| 2139 | netif_carrier_on(bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2140 | printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name); |
| 2141 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2142 | printk("%d Mbps ", bp->link_vars.line_speed); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2143 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2144 | if (bp->link_vars.duplex == DUPLEX_FULL) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2145 | printk("full duplex"); |
| 2146 | else |
| 2147 | printk("half duplex"); |
| 2148 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2149 | if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) { |
| 2150 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2151 | printk(", receive "); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 2152 | if (bp->link_vars.flow_ctrl & |
| 2153 | BNX2X_FLOW_CTRL_TX) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2154 | printk("& transmit "); |
| 2155 | } else { |
| 2156 | printk(", transmit "); |
| 2157 | } |
| 2158 | printk("flow control ON"); |
| 2159 | } |
| 2160 | printk("\n"); |
| 2161 | |
| 2162 | } else { /* link_down */ |
| 2163 | netif_carrier_off(bp->dev); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2164 | printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2168 | static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2169 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2170 | if (!BP_NOMCP(bp)) { |
| 2171 | u8 rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2172 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2173 | /* Initialize link parameters structure variables */ |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2174 | /* It is recommended to turn off RX FC for jumbo frames |
| 2175 | for better performance */ |
Eilon Greenstein | 0c59327 | 2009-08-12 08:22:13 +0000 | [diff] [blame] | 2176 | if (bp->dev->mtu > 5000) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2177 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2178 | else |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2179 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2180 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2181 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (load_mode == LOAD_DIAG) |
| 2184 | bp->link_params.loopback_mode = LOOPBACK_XGXS_10; |
| 2185 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2186 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2187 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2188 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2189 | |
Eilon Greenstein | 3c96c68 | 2009-01-14 21:25:31 -0800 | [diff] [blame] | 2190 | bnx2x_calc_fc_adv(bp); |
| 2191 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2192 | if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) { |
| 2193 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2194 | bnx2x_link_report(bp); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 2195 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2196 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2197 | return rc; |
| 2198 | } |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2199 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2200 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2201 | } |
| 2202 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2203 | static void bnx2x_link_set(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2204 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2205 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2206 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2207 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2208 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2209 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2210 | bnx2x_calc_fc_adv(bp); |
| 2211 | } else |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2212 | BNX2X_ERR("Bootcode is missing - can not set link\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2213 | } |
| 2214 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2215 | static void bnx2x__link_reset(struct bnx2x *bp) |
| 2216 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2217 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2218 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 2219 | bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2220 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2221 | } else |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 2222 | BNX2X_ERR("Bootcode is missing - can not reset link\n"); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | static u8 bnx2x_link_test(struct bnx2x *bp) |
| 2226 | { |
| 2227 | u8 rc; |
| 2228 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2229 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2230 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2231 | bnx2x_release_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2232 | |
| 2233 | return rc; |
| 2234 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2235 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2236 | static void bnx2x_init_port_minmax(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2237 | { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2238 | u32 r_param = bp->link_vars.line_speed / 8; |
| 2239 | u32 fair_periodic_timeout_usec; |
| 2240 | u32 t_fair; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2241 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2242 | memset(&(bp->cmng.rs_vars), 0, |
| 2243 | sizeof(struct rate_shaping_vars_per_port)); |
| 2244 | memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2245 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2246 | /* 100 usec in SDM ticks = 25 since each tick is 4 usec */ |
| 2247 | bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2248 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2249 | /* this is the threshold below which no timer arming will occur |
| 2250 | 1.25 coefficient is for the threshold to be a little bigger |
| 2251 | than the real time, to compensate for timer in-accuracy */ |
| 2252 | bp->cmng.rs_vars.rs_threshold = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2253 | (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4; |
| 2254 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2255 | /* resolution of fairness timer */ |
| 2256 | fair_periodic_timeout_usec = QM_ARB_BYTES / r_param; |
| 2257 | /* for 10G it is 1000usec. for 1G it is 10000usec. */ |
| 2258 | t_fair = T_FAIR_COEF / bp->link_vars.line_speed; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2259 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2260 | /* this is the threshold below which we won't arm the timer anymore */ |
| 2261 | bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2262 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2263 | /* we multiply by 1e3/8 to get bytes/msec. |
| 2264 | We don't want the credits to pass a credit |
| 2265 | of the t_fair*FAIR_MEM (algorithm resolution) */ |
| 2266 | bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM; |
| 2267 | /* since each tick is 4 usec */ |
| 2268 | bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2271 | /* Calculates the sum of vn_min_rates. |
| 2272 | It's needed for further normalizing of the min_rates. |
| 2273 | Returns: |
| 2274 | sum of vn_min_rates. |
| 2275 | or |
| 2276 | 0 - if all the min_rates are 0. |
| 2277 | In the later case fainess algorithm should be deactivated. |
| 2278 | If not all min_rates are zero then those that are zeroes will be set to 1. |
| 2279 | */ |
| 2280 | static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp) |
| 2281 | { |
| 2282 | int all_zero = 1; |
| 2283 | int port = BP_PORT(bp); |
| 2284 | int vn; |
| 2285 | |
| 2286 | bp->vn_weight_sum = 0; |
| 2287 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2288 | int func = 2*vn + port; |
| 2289 | u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2290 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2291 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
| 2292 | |
| 2293 | /* Skip hidden vns */ |
| 2294 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
| 2295 | continue; |
| 2296 | |
| 2297 | /* If min rate is zero - set it to 1 */ |
| 2298 | if (!vn_min_rate) |
| 2299 | vn_min_rate = DEF_MIN_RATE; |
| 2300 | else |
| 2301 | all_zero = 0; |
| 2302 | |
| 2303 | bp->vn_weight_sum += vn_min_rate; |
| 2304 | } |
| 2305 | |
| 2306 | /* ... only if all min rates are zeros - disable fairness */ |
| 2307 | if (all_zero) |
| 2308 | bp->vn_weight_sum = 0; |
| 2309 | } |
| 2310 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2311 | static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2312 | { |
| 2313 | struct rate_shaping_vars_per_vn m_rs_vn; |
| 2314 | struct fairness_vars_per_vn m_fair_vn; |
| 2315 | u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2316 | u16 vn_min_rate, vn_max_rate; |
| 2317 | int i; |
| 2318 | |
| 2319 | /* If function is hidden - set min and max to zeroes */ |
| 2320 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { |
| 2321 | vn_min_rate = 0; |
| 2322 | vn_max_rate = 0; |
| 2323 | |
| 2324 | } else { |
| 2325 | vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2326 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2327 | /* If fairness is enabled (not all min rates are zeroes) and |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2328 | if current min rate is zero - set it to 1. |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 2329 | This is a requirement of the algorithm. */ |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2330 | if (bp->vn_weight_sum && (vn_min_rate == 0)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2331 | vn_min_rate = DEF_MIN_RATE; |
| 2332 | vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 2333 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 2334 | } |
| 2335 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2336 | DP(NETIF_MSG_IFUP, |
| 2337 | "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n", |
| 2338 | func, vn_min_rate, vn_max_rate, bp->vn_weight_sum); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2339 | |
| 2340 | memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn)); |
| 2341 | memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn)); |
| 2342 | |
| 2343 | /* global vn counter - maximal Mbps for this vn */ |
| 2344 | m_rs_vn.vn_counter.rate = vn_max_rate; |
| 2345 | |
| 2346 | /* quota - number of bytes transmitted in this period */ |
| 2347 | m_rs_vn.vn_counter.quota = |
| 2348 | (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8; |
| 2349 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2350 | if (bp->vn_weight_sum) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2351 | /* credit for each period of the fairness algorithm: |
| 2352 | number of bytes in T_FAIR (the vn share the port rate). |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2353 | vn_weight_sum should not be larger than 10000, thus |
| 2354 | T_FAIR_COEF / (8 * vn_weight_sum) will always be greater |
| 2355 | than zero */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2356 | m_fair_vn.vn_credit_delta = |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2357 | max((u32)(vn_min_rate * (T_FAIR_COEF / |
| 2358 | (8 * bp->vn_weight_sum))), |
| 2359 | (u32)(bp->cmng.fair_vars.fair_threshold * 2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2360 | DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n", |
| 2361 | m_fair_vn.vn_credit_delta); |
| 2362 | } |
| 2363 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2364 | /* Store it to internal memory */ |
| 2365 | for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++) |
| 2366 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2367 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2368 | ((u32 *)(&m_rs_vn))[i]); |
| 2369 | |
| 2370 | for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++) |
| 2371 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2372 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2373 | ((u32 *)(&m_fair_vn))[i]); |
| 2374 | } |
| 2375 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2376 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2377 | /* This function is called upon link interrupt */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2378 | static void bnx2x_link_attn(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2379 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2380 | /* Make sure that we are synced with the current statistics */ |
| 2381 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2382 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2383 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2384 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2385 | if (bp->link_vars.link_up) { |
| 2386 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2387 | /* dropless flow control */ |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 2388 | if (CHIP_IS_E1H(bp) && bp->dropless_fc) { |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2389 | int port = BP_PORT(bp); |
| 2390 | u32 pause_enabled = 0; |
| 2391 | |
| 2392 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
| 2393 | pause_enabled = 1; |
| 2394 | |
| 2395 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 2396 | USTORM_ETH_PAUSE_ENABLED_OFFSET(port), |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2397 | pause_enabled); |
| 2398 | } |
| 2399 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2400 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
| 2401 | struct host_port_stats *pstats; |
| 2402 | |
| 2403 | pstats = bnx2x_sp(bp, port_stats); |
| 2404 | /* reset old bmac stats */ |
| 2405 | memset(&(pstats->mac_stx[0]), 0, |
| 2406 | sizeof(struct mac_stx)); |
| 2407 | } |
| 2408 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 2409 | (bp->state == BNX2X_STATE_DISABLED)) |
| 2410 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2411 | } |
| 2412 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2413 | /* indicate link status */ |
| 2414 | bnx2x_link_report(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2415 | |
| 2416 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2417 | int port = BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2418 | int func; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2419 | int vn; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2420 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 2421 | /* Set the attention towards other drivers on the same port */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2422 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2423 | if (vn == BP_E1HVN(bp)) |
| 2424 | continue; |
| 2425 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2426 | func = ((vn << 1) | port); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2427 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 + |
| 2428 | (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1); |
| 2429 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2430 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2431 | if (bp->link_vars.link_up) { |
| 2432 | int i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2433 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2434 | /* Init rate shaping and fairness contexts */ |
| 2435 | bnx2x_init_port_minmax(bp); |
| 2436 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2437 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2438 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 2439 | |
| 2440 | /* Store it to internal memory */ |
| 2441 | for (i = 0; |
| 2442 | i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 2443 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2444 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4, |
| 2445 | ((u32 *)(&bp->cmng))[i]); |
| 2446 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2447 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2448 | } |
| 2449 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2450 | static void bnx2x__link_status_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2451 | { |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2452 | int func = BP_FUNC(bp); |
| 2453 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2454 | if (bp->state != BNX2X_STATE_OPEN) |
| 2455 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2456 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2457 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); |
| 2458 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2459 | if (bp->link_vars.link_up) |
| 2460 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2461 | else |
| 2462 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2463 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2464 | bp->mf_config = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2465 | bnx2x_calc_vn_weight_sum(bp); |
| 2466 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2467 | /* indicate link status */ |
| 2468 | bnx2x_link_report(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2469 | } |
| 2470 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2471 | static void bnx2x_pmf_update(struct bnx2x *bp) |
| 2472 | { |
| 2473 | int port = BP_PORT(bp); |
| 2474 | u32 val; |
| 2475 | |
| 2476 | bp->port.pmf = 1; |
| 2477 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 2478 | |
| 2479 | /* enable nig attention */ |
| 2480 | val = (0xff0f | (1 << (BP_E1HVN(bp) + 4))); |
| 2481 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 2482 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2483 | |
| 2484 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2487 | /* end of Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2488 | |
| 2489 | /* slow path */ |
| 2490 | |
| 2491 | /* |
| 2492 | * General service functions |
| 2493 | */ |
| 2494 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 2495 | /* send the MCP a request, block until there is a reply */ |
| 2496 | u32 bnx2x_fw_command(struct bnx2x *bp, u32 command) |
| 2497 | { |
| 2498 | int func = BP_FUNC(bp); |
| 2499 | u32 seq = ++bp->fw_seq; |
| 2500 | u32 rc = 0; |
| 2501 | u32 cnt = 1; |
| 2502 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; |
| 2503 | |
| 2504 | SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq)); |
| 2505 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq)); |
| 2506 | |
| 2507 | do { |
| 2508 | /* let the FW do it's magic ... */ |
| 2509 | msleep(delay); |
| 2510 | |
| 2511 | rc = SHMEM_RD(bp, func_mb[func].fw_mb_header); |
| 2512 | |
| 2513 | /* Give the FW up to 2 second (200*10ms) */ |
| 2514 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200)); |
| 2515 | |
| 2516 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", |
| 2517 | cnt*delay, rc, seq); |
| 2518 | |
| 2519 | /* is this a reply to our command? */ |
| 2520 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) |
| 2521 | rc &= FW_MSG_CODE_MASK; |
| 2522 | else { |
| 2523 | /* FW BUG! */ |
| 2524 | BNX2X_ERR("FW failed to respond!\n"); |
| 2525 | bnx2x_fw_dump(bp); |
| 2526 | rc = 0; |
| 2527 | } |
| 2528 | |
| 2529 | return rc; |
| 2530 | } |
| 2531 | |
| 2532 | static void bnx2x_set_storm_rx_mode(struct bnx2x *bp); |
| 2533 | static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set); |
| 2534 | static void bnx2x_set_rx_mode(struct net_device *dev); |
| 2535 | |
| 2536 | static void bnx2x_e1h_disable(struct bnx2x *bp) |
| 2537 | { |
| 2538 | int port = BP_PORT(bp); |
| 2539 | int i; |
| 2540 | |
| 2541 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 2542 | bnx2x_set_storm_rx_mode(bp); |
| 2543 | |
| 2544 | netif_tx_disable(bp->dev); |
| 2545 | bp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 2546 | |
| 2547 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 2548 | |
| 2549 | bnx2x_set_mac_addr_e1h(bp, 0); |
| 2550 | |
| 2551 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 2552 | REG_WR(bp, MC_HASH_OFFSET(bp, i), 0); |
| 2553 | |
| 2554 | netif_carrier_off(bp->dev); |
| 2555 | } |
| 2556 | |
| 2557 | static void bnx2x_e1h_enable(struct bnx2x *bp) |
| 2558 | { |
| 2559 | int port = BP_PORT(bp); |
| 2560 | |
| 2561 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 2562 | |
| 2563 | bnx2x_set_mac_addr_e1h(bp, 1); |
| 2564 | |
| 2565 | /* Tx queue should be only reenabled */ |
| 2566 | netif_tx_wake_all_queues(bp->dev); |
| 2567 | |
| 2568 | /* Initialize the receive filter. */ |
| 2569 | bnx2x_set_rx_mode(bp->dev); |
| 2570 | } |
| 2571 | |
| 2572 | static void bnx2x_update_min_max(struct bnx2x *bp) |
| 2573 | { |
| 2574 | int port = BP_PORT(bp); |
| 2575 | int vn, i; |
| 2576 | |
| 2577 | /* Init rate shaping and fairness contexts */ |
| 2578 | bnx2x_init_port_minmax(bp); |
| 2579 | |
| 2580 | bnx2x_calc_vn_weight_sum(bp); |
| 2581 | |
| 2582 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
| 2583 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 2584 | |
| 2585 | if (bp->port.pmf) { |
| 2586 | int func; |
| 2587 | |
| 2588 | /* Set the attention towards other drivers on the same port */ |
| 2589 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2590 | if (vn == BP_E1HVN(bp)) |
| 2591 | continue; |
| 2592 | |
| 2593 | func = ((vn << 1) | port); |
| 2594 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 + |
| 2595 | (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1); |
| 2596 | } |
| 2597 | |
| 2598 | /* Store it to internal memory */ |
| 2599 | for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 2600 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2601 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4, |
| 2602 | ((u32 *)(&bp->cmng))[i]); |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event) |
| 2607 | { |
| 2608 | int func = BP_FUNC(bp); |
| 2609 | |
| 2610 | DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event); |
| 2611 | bp->mf_config = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2612 | |
| 2613 | if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) { |
| 2614 | |
| 2615 | if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) { |
| 2616 | DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n"); |
| 2617 | bp->state = BNX2X_STATE_DISABLED; |
| 2618 | |
| 2619 | bnx2x_e1h_disable(bp); |
| 2620 | } else { |
| 2621 | DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n"); |
| 2622 | bp->state = BNX2X_STATE_OPEN; |
| 2623 | |
| 2624 | bnx2x_e1h_enable(bp); |
| 2625 | } |
| 2626 | dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF; |
| 2627 | } |
| 2628 | if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) { |
| 2629 | |
| 2630 | bnx2x_update_min_max(bp); |
| 2631 | dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION; |
| 2632 | } |
| 2633 | |
| 2634 | /* Report results to MCP */ |
| 2635 | if (dcc_event) |
| 2636 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE); |
| 2637 | else |
| 2638 | bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK); |
| 2639 | } |
| 2640 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2641 | /* the slow path queue is odd since completions arrive on the fastpath ring */ |
| 2642 | static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
| 2643 | u32 data_hi, u32 data_lo, int common) |
| 2644 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2645 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2646 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2647 | DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/, |
| 2648 | "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2649 | (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) + |
| 2650 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, |
| 2651 | HW_CID(bp, cid), data_hi, data_lo, bp->spq_left); |
| 2652 | |
| 2653 | #ifdef BNX2X_STOP_ON_ERROR |
| 2654 | if (unlikely(bp->panic)) |
| 2655 | return -EIO; |
| 2656 | #endif |
| 2657 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2658 | spin_lock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2659 | |
| 2660 | if (!bp->spq_left) { |
| 2661 | BNX2X_ERR("BUG! SPQ ring full!\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2662 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2663 | bnx2x_panic(); |
| 2664 | return -EBUSY; |
| 2665 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2666 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2667 | /* CID needs port number to be encoded int it */ |
| 2668 | bp->spq_prod_bd->hdr.conn_and_cmd_data = |
| 2669 | cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) | |
| 2670 | HW_CID(bp, cid))); |
| 2671 | bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE); |
| 2672 | if (common) |
| 2673 | bp->spq_prod_bd->hdr.type |= |
| 2674 | cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT)); |
| 2675 | |
| 2676 | bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi); |
| 2677 | bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo); |
| 2678 | |
| 2679 | bp->spq_left--; |
| 2680 | |
| 2681 | if (bp->spq_prod_bd == bp->spq_last_bd) { |
| 2682 | bp->spq_prod_bd = bp->spq; |
| 2683 | bp->spq_prod_idx = 0; |
| 2684 | DP(NETIF_MSG_TIMER, "end of spq\n"); |
| 2685 | |
| 2686 | } else { |
| 2687 | bp->spq_prod_bd++; |
| 2688 | bp->spq_prod_idx++; |
| 2689 | } |
| 2690 | |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 2691 | /* Make sure that BD data is updated before writing the producer */ |
| 2692 | wmb(); |
| 2693 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2694 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2695 | bp->spq_prod_idx); |
| 2696 | |
Eilon Greenstein | 37dbbf3 | 2009-07-21 05:47:33 +0000 | [diff] [blame] | 2697 | mmiowb(); |
| 2698 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2699 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2700 | return 0; |
| 2701 | } |
| 2702 | |
| 2703 | /* acquire split MCP access lock register */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2704 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2705 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2706 | u32 i, j, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2707 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2708 | |
| 2709 | might_sleep(); |
| 2710 | i = 100; |
| 2711 | for (j = 0; j < i*10; j++) { |
| 2712 | val = (1UL << 31); |
| 2713 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2714 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); |
| 2715 | if (val & (1L << 31)) |
| 2716 | break; |
| 2717 | |
| 2718 | msleep(5); |
| 2719 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2720 | if (!(val & (1L << 31))) { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2721 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2722 | rc = -EBUSY; |
| 2723 | } |
| 2724 | |
| 2725 | return rc; |
| 2726 | } |
| 2727 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2728 | /* release split MCP access lock register */ |
| 2729 | static void bnx2x_release_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2730 | { |
| 2731 | u32 val = 0; |
| 2732 | |
| 2733 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2734 | } |
| 2735 | |
| 2736 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
| 2737 | { |
| 2738 | struct host_def_status_block *def_sb = bp->def_status_blk; |
| 2739 | u16 rc = 0; |
| 2740 | |
| 2741 | barrier(); /* status block is written to by the chip */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2742 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
| 2743 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; |
| 2744 | rc |= 1; |
| 2745 | } |
| 2746 | if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) { |
| 2747 | bp->def_c_idx = def_sb->c_def_status_block.status_block_index; |
| 2748 | rc |= 2; |
| 2749 | } |
| 2750 | if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) { |
| 2751 | bp->def_u_idx = def_sb->u_def_status_block.status_block_index; |
| 2752 | rc |= 4; |
| 2753 | } |
| 2754 | if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) { |
| 2755 | bp->def_x_idx = def_sb->x_def_status_block.status_block_index; |
| 2756 | rc |= 8; |
| 2757 | } |
| 2758 | if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) { |
| 2759 | bp->def_t_idx = def_sb->t_def_status_block.status_block_index; |
| 2760 | rc |= 16; |
| 2761 | } |
| 2762 | return rc; |
| 2763 | } |
| 2764 | |
| 2765 | /* |
| 2766 | * slow path service functions |
| 2767 | */ |
| 2768 | |
| 2769 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) |
| 2770 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2771 | int port = BP_PORT(bp); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2772 | u32 hc_addr = (HC_REG_COMMAND_REG + port*32 + |
| 2773 | COMMAND_REG_ATTN_BITS_SET); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2774 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 2775 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2776 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
| 2777 | NIG_REG_MASK_INTERRUPT_PORT0; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2778 | u32 aeu_mask; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2779 | u32 nig_mask = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2780 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2781 | if (bp->attn_state & asserted) |
| 2782 | BNX2X_ERR("IGU ERROR\n"); |
| 2783 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2784 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 2785 | aeu_mask = REG_RD(bp, aeu_addr); |
| 2786 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2787 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2788 | aeu_mask, asserted); |
| 2789 | aeu_mask &= ~(asserted & 0xff); |
| 2790 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2791 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2792 | REG_WR(bp, aeu_addr, aeu_mask); |
| 2793 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2794 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2795 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2796 | bp->attn_state |= asserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2797 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2798 | |
| 2799 | if (asserted & ATTN_HARD_WIRED_MASK) { |
| 2800 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2801 | |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2802 | bnx2x_acquire_phy_lock(bp); |
| 2803 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2804 | /* save nig interrupt mask */ |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2805 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2806 | REG_WR(bp, nig_int_mask_addr, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2807 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2808 | bnx2x_link_attn(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2809 | |
| 2810 | /* handle unicore attn? */ |
| 2811 | } |
| 2812 | if (asserted & ATTN_SW_TIMER_4_FUNC) |
| 2813 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); |
| 2814 | |
| 2815 | if (asserted & GPIO_2_FUNC) |
| 2816 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); |
| 2817 | |
| 2818 | if (asserted & GPIO_3_FUNC) |
| 2819 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); |
| 2820 | |
| 2821 | if (asserted & GPIO_4_FUNC) |
| 2822 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); |
| 2823 | |
| 2824 | if (port == 0) { |
| 2825 | if (asserted & ATTN_GENERAL_ATTN_1) { |
| 2826 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); |
| 2827 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); |
| 2828 | } |
| 2829 | if (asserted & ATTN_GENERAL_ATTN_2) { |
| 2830 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); |
| 2831 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); |
| 2832 | } |
| 2833 | if (asserted & ATTN_GENERAL_ATTN_3) { |
| 2834 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); |
| 2835 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); |
| 2836 | } |
| 2837 | } else { |
| 2838 | if (asserted & ATTN_GENERAL_ATTN_4) { |
| 2839 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); |
| 2840 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); |
| 2841 | } |
| 2842 | if (asserted & ATTN_GENERAL_ATTN_5) { |
| 2843 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); |
| 2844 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); |
| 2845 | } |
| 2846 | if (asserted & ATTN_GENERAL_ATTN_6) { |
| 2847 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); |
| 2848 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | } /* if hardwired */ |
| 2853 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2854 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 2855 | asserted, hc_addr); |
| 2856 | REG_WR(bp, hc_addr, asserted); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2857 | |
| 2858 | /* now set back the mask */ |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2859 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 2860 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2861 | bnx2x_release_phy_lock(bp); |
| 2862 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2863 | } |
| 2864 | |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 2865 | static inline void bnx2x_fan_failure(struct bnx2x *bp) |
| 2866 | { |
| 2867 | int port = BP_PORT(bp); |
| 2868 | |
| 2869 | /* mark the failure */ |
| 2870 | bp->link_params.ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
| 2871 | bp->link_params.ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; |
| 2872 | SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config, |
| 2873 | bp->link_params.ext_phy_config); |
| 2874 | |
| 2875 | /* log the failure */ |
| 2876 | printk(KERN_ERR PFX "Fan Failure on Network Controller %s has caused" |
| 2877 | " the driver to shutdown the card to prevent permanent" |
| 2878 | " damage. Please contact Dell Support for assistance\n", |
| 2879 | bp->dev->name); |
| 2880 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 2881 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2882 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
| 2883 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2884 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2885 | int reg_offset; |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 2886 | u32 val, swap_val, swap_override; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2887 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2888 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 2889 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2890 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2891 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2892 | |
| 2893 | val = REG_RD(bp, reg_offset); |
| 2894 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; |
| 2895 | REG_WR(bp, reg_offset, val); |
| 2896 | |
| 2897 | BNX2X_ERR("SPIO5 hw attention\n"); |
| 2898 | |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 2899 | /* Fan failure attention */ |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 2900 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
| 2901 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2902 | /* Low power mode is controlled by GPIO 2 */ |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2903 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2, |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2904 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 2905 | /* The PHY reset is controlled by GPIO 1 */ |
| 2906 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1, |
| 2907 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2908 | break; |
| 2909 | |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 2910 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727: |
| 2911 | /* The PHY reset is controlled by GPIO 1 */ |
| 2912 | /* fake the port number to cancel the swap done in |
| 2913 | set_gpio() */ |
| 2914 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 2915 | swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
| 2916 | port = (swap_val && swap_override) ^ 1; |
| 2917 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1, |
| 2918 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
| 2919 | break; |
| 2920 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2921 | default: |
| 2922 | break; |
| 2923 | } |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 2924 | bnx2x_fan_failure(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2925 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2926 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 2927 | if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 | |
| 2928 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) { |
| 2929 | bnx2x_acquire_phy_lock(bp); |
| 2930 | bnx2x_handle_module_detect_int(&bp->link_params); |
| 2931 | bnx2x_release_phy_lock(bp); |
| 2932 | } |
| 2933 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2934 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
| 2935 | |
| 2936 | val = REG_RD(bp, reg_offset); |
| 2937 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); |
| 2938 | REG_WR(bp, reg_offset, val); |
| 2939 | |
| 2940 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 2941 | (u32)(attn & HW_INTERRUT_ASSERT_SET_0)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2942 | bnx2x_panic(); |
| 2943 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
| 2947 | { |
| 2948 | u32 val; |
| 2949 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 2950 | if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2951 | |
| 2952 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); |
| 2953 | BNX2X_ERR("DB hw attention 0x%x\n", val); |
| 2954 | /* DORQ discard attention */ |
| 2955 | if (val & 0x2) |
| 2956 | BNX2X_ERR("FATAL error from DORQ\n"); |
| 2957 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2958 | |
| 2959 | if (attn & HW_INTERRUT_ASSERT_SET_1) { |
| 2960 | |
| 2961 | int port = BP_PORT(bp); |
| 2962 | int reg_offset; |
| 2963 | |
| 2964 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : |
| 2965 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); |
| 2966 | |
| 2967 | val = REG_RD(bp, reg_offset); |
| 2968 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); |
| 2969 | REG_WR(bp, reg_offset, val); |
| 2970 | |
| 2971 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 2972 | (u32)(attn & HW_INTERRUT_ASSERT_SET_1)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2973 | bnx2x_panic(); |
| 2974 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
| 2978 | { |
| 2979 | u32 val; |
| 2980 | |
| 2981 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { |
| 2982 | |
| 2983 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); |
| 2984 | BNX2X_ERR("CFC hw attention 0x%x\n", val); |
| 2985 | /* CFC error attention */ |
| 2986 | if (val & 0x2) |
| 2987 | BNX2X_ERR("FATAL error from CFC\n"); |
| 2988 | } |
| 2989 | |
| 2990 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { |
| 2991 | |
| 2992 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
| 2993 | BNX2X_ERR("PXP hw attention 0x%x\n", val); |
| 2994 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
| 2995 | if (val & 0x18000) |
| 2996 | BNX2X_ERR("FATAL error from PXP\n"); |
| 2997 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2998 | |
| 2999 | if (attn & HW_INTERRUT_ASSERT_SET_2) { |
| 3000 | |
| 3001 | int port = BP_PORT(bp); |
| 3002 | int reg_offset; |
| 3003 | |
| 3004 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : |
| 3005 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); |
| 3006 | |
| 3007 | val = REG_RD(bp, reg_offset); |
| 3008 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); |
| 3009 | REG_WR(bp, reg_offset, val); |
| 3010 | |
| 3011 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", |
Eilon Greenstein | 0fc5d00 | 2009-08-12 08:24:05 +0000 | [diff] [blame] | 3012 | (u32)(attn & HW_INTERRUT_ASSERT_SET_2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3013 | bnx2x_panic(); |
| 3014 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
| 3018 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3019 | u32 val; |
| 3020 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3021 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
| 3022 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3023 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
| 3024 | int func = BP_FUNC(bp); |
| 3025 | |
| 3026 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3027 | val = SHMEM_RD(bp, func_mb[func].drv_status); |
| 3028 | if (val & DRV_STATUS_DCC_EVENT_MASK) |
| 3029 | bnx2x_dcc_event(bp, |
| 3030 | (val & DRV_STATUS_DCC_EVENT_MASK)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3031 | bnx2x__link_status_update(bp); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 3032 | if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3033 | bnx2x_pmf_update(bp); |
| 3034 | |
| 3035 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3036 | |
| 3037 | BNX2X_ERR("MC assert!\n"); |
| 3038 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
| 3039 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); |
| 3040 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); |
| 3041 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); |
| 3042 | bnx2x_panic(); |
| 3043 | |
| 3044 | } else if (attn & BNX2X_MCP_ASSERT) { |
| 3045 | |
| 3046 | BNX2X_ERR("MCP assert!\n"); |
| 3047 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3048 | bnx2x_fw_dump(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3049 | |
| 3050 | } else |
| 3051 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); |
| 3052 | } |
| 3053 | |
| 3054 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3055 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
| 3056 | if (attn & BNX2X_GRC_TIMEOUT) { |
| 3057 | val = CHIP_IS_E1H(bp) ? |
| 3058 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0; |
| 3059 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
| 3060 | } |
| 3061 | if (attn & BNX2X_GRC_RSV) { |
| 3062 | val = CHIP_IS_E1H(bp) ? |
| 3063 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0; |
| 3064 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
| 3065 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3066 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3067 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
| 3071 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3072 | struct attn_route attn; |
| 3073 | struct attn_route group_mask; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3074 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3075 | int index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3076 | u32 reg_addr; |
| 3077 | u32 val; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3078 | u32 aeu_mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3079 | |
| 3080 | /* need to take HW lock because MCP or other port might also |
| 3081 | try to handle this event */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3082 | bnx2x_acquire_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3083 | |
| 3084 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
| 3085 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); |
| 3086 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); |
| 3087 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3088 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n", |
| 3089 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3090 | |
| 3091 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
| 3092 | if (deasserted & (1 << index)) { |
| 3093 | group_mask = bp->attn_group[index]; |
| 3094 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3095 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n", |
| 3096 | index, group_mask.sig[0], group_mask.sig[1], |
| 3097 | group_mask.sig[2], group_mask.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3098 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3099 | bnx2x_attn_int_deasserted3(bp, |
| 3100 | attn.sig[3] & group_mask.sig[3]); |
| 3101 | bnx2x_attn_int_deasserted1(bp, |
| 3102 | attn.sig[1] & group_mask.sig[1]); |
| 3103 | bnx2x_attn_int_deasserted2(bp, |
| 3104 | attn.sig[2] & group_mask.sig[2]); |
| 3105 | bnx2x_attn_int_deasserted0(bp, |
| 3106 | attn.sig[0] & group_mask.sig[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3107 | |
| 3108 | if ((attn.sig[0] & group_mask.sig[0] & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3109 | HW_PRTY_ASSERT_SET_0) || |
| 3110 | (attn.sig[1] & group_mask.sig[1] & |
| 3111 | HW_PRTY_ASSERT_SET_1) || |
| 3112 | (attn.sig[2] & group_mask.sig[2] & |
| 3113 | HW_PRTY_ASSERT_SET_2)) |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 3114 | BNX2X_ERR("FATAL HW block parity attention\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 3118 | bnx2x_release_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3119 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 3120 | reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3121 | |
| 3122 | val = ~deasserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3123 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 3124 | val, reg_addr); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 3125 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3126 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3127 | if (~bp->attn_state & deasserted) |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3128 | BNX2X_ERR("IGU ERROR\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3129 | |
| 3130 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 3131 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 3132 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3133 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 3134 | aeu_mask = REG_RD(bp, reg_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3135 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 3136 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", |
| 3137 | aeu_mask, deasserted); |
| 3138 | aeu_mask |= (deasserted & 0xff); |
| 3139 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
| 3140 | |
| 3141 | REG_WR(bp, reg_addr, aeu_mask); |
| 3142 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3143 | |
| 3144 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
| 3145 | bp->attn_state &= ~deasserted; |
| 3146 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
| 3147 | } |
| 3148 | |
| 3149 | static void bnx2x_attn_int(struct bnx2x *bp) |
| 3150 | { |
| 3151 | /* read local copy of bits */ |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 3152 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 3153 | attn_bits); |
| 3154 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 3155 | attn_bits_ack); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3156 | u32 attn_state = bp->attn_state; |
| 3157 | |
| 3158 | /* look for changed bits */ |
| 3159 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; |
| 3160 | u32 deasserted = ~attn_bits & attn_ack & attn_state; |
| 3161 | |
| 3162 | DP(NETIF_MSG_HW, |
| 3163 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", |
| 3164 | attn_bits, attn_ack, asserted, deasserted); |
| 3165 | |
| 3166 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3167 | BNX2X_ERR("BAD attention state\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3168 | |
| 3169 | /* handle bits that were raised */ |
| 3170 | if (asserted) |
| 3171 | bnx2x_attn_int_asserted(bp, asserted); |
| 3172 | |
| 3173 | if (deasserted) |
| 3174 | bnx2x_attn_int_deasserted(bp, deasserted); |
| 3175 | } |
| 3176 | |
| 3177 | static void bnx2x_sp_task(struct work_struct *work) |
| 3178 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 3179 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3180 | u16 status; |
| 3181 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3182 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3183 | /* Return here if interrupt is disabled */ |
| 3184 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 3185 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3186 | return; |
| 3187 | } |
| 3188 | |
| 3189 | status = bnx2x_update_dsb_idx(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3190 | /* if (status == 0) */ |
| 3191 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3192 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 3193 | DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3194 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3195 | /* HW attentions */ |
| 3196 | if (status & 0x1) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3197 | bnx2x_attn_int(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3198 | |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 3199 | bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3200 | IGU_INT_NOP, 1); |
| 3201 | bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx), |
| 3202 | IGU_INT_NOP, 1); |
| 3203 | bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx), |
| 3204 | IGU_INT_NOP, 1); |
| 3205 | bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx), |
| 3206 | IGU_INT_NOP, 1); |
| 3207 | bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx), |
| 3208 | IGU_INT_ENABLE, 1); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 3209 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
| 3213 | { |
| 3214 | struct net_device *dev = dev_instance; |
| 3215 | struct bnx2x *bp = netdev_priv(dev); |
| 3216 | |
| 3217 | /* Return here if interrupt is disabled */ |
| 3218 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 3219 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3220 | return IRQ_HANDLED; |
| 3221 | } |
| 3222 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 3223 | bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3224 | |
| 3225 | #ifdef BNX2X_STOP_ON_ERROR |
| 3226 | if (unlikely(bp->panic)) |
| 3227 | return IRQ_HANDLED; |
| 3228 | #endif |
| 3229 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 3230 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3231 | |
| 3232 | return IRQ_HANDLED; |
| 3233 | } |
| 3234 | |
| 3235 | /* end of slow path */ |
| 3236 | |
| 3237 | /* Statistics */ |
| 3238 | |
| 3239 | /**************************************************************************** |
| 3240 | * Macros |
| 3241 | ****************************************************************************/ |
| 3242 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3243 | /* sum[hi:lo] += add[hi:lo] */ |
| 3244 | #define ADD_64(s_hi, a_hi, s_lo, a_lo) \ |
| 3245 | do { \ |
| 3246 | s_lo += a_lo; \ |
Eilon Greenstein | f5ba677 | 2009-01-14 21:29:18 -0800 | [diff] [blame] | 3247 | s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3248 | } while (0) |
| 3249 | |
| 3250 | /* difference = minuend - subtrahend */ |
| 3251 | #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \ |
| 3252 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3253 | if (m_lo < s_lo) { \ |
| 3254 | /* underflow */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3255 | d_hi = m_hi - s_hi; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3256 | if (d_hi > 0) { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 3257 | /* we can 'loan' 1 */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3258 | d_hi--; \ |
| 3259 | d_lo = m_lo + (UINT_MAX - s_lo) + 1; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3260 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 3261 | /* m_hi <= s_hi */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3262 | d_hi = 0; \ |
| 3263 | d_lo = 0; \ |
| 3264 | } \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3265 | } else { \ |
| 3266 | /* m_lo >= s_lo */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3267 | if (m_hi < s_hi) { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3268 | d_hi = 0; \ |
| 3269 | d_lo = 0; \ |
| 3270 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 3271 | /* m_hi >= s_hi */ \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3272 | d_hi = m_hi - s_hi; \ |
| 3273 | d_lo = m_lo - s_lo; \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3274 | } \ |
| 3275 | } \ |
| 3276 | } while (0) |
| 3277 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3278 | #define UPDATE_STAT64(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3279 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3280 | DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \ |
| 3281 | diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \ |
| 3282 | pstats->mac_stx[0].t##_hi = new->s##_hi; \ |
| 3283 | pstats->mac_stx[0].t##_lo = new->s##_lo; \ |
| 3284 | ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \ |
| 3285 | pstats->mac_stx[1].t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3286 | } while (0) |
| 3287 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3288 | #define UPDATE_STAT64_NIG(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3289 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3290 | DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \ |
| 3291 | diff.lo, new->s##_lo, old->s##_lo); \ |
| 3292 | ADD_64(estats->t##_hi, diff.hi, \ |
| 3293 | estats->t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3294 | } while (0) |
| 3295 | |
| 3296 | /* sum[hi:lo] += add */ |
| 3297 | #define ADD_EXTEND_64(s_hi, s_lo, a) \ |
| 3298 | do { \ |
| 3299 | s_lo += a; \ |
| 3300 | s_hi += (s_lo < a) ? 1 : 0; \ |
| 3301 | } while (0) |
| 3302 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3303 | #define UPDATE_EXTEND_STAT(s) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3304 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3305 | ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \ |
| 3306 | pstats->mac_stx[1].s##_lo, \ |
| 3307 | new->s); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3308 | } while (0) |
| 3309 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3310 | #define UPDATE_EXTEND_TSTAT(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3311 | do { \ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3312 | diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \ |
| 3313 | old_tclient->s = tclient->s; \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3314 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 3315 | } while (0) |
| 3316 | |
| 3317 | #define UPDATE_EXTEND_USTAT(s, t) \ |
| 3318 | do { \ |
| 3319 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 3320 | old_uclient->s = uclient->s; \ |
| 3321 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3322 | } while (0) |
| 3323 | |
| 3324 | #define UPDATE_EXTEND_XSTAT(s, t) \ |
| 3325 | do { \ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3326 | diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \ |
| 3327 | old_xclient->s = xclient->s; \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3328 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 3329 | } while (0) |
| 3330 | |
| 3331 | /* minuend -= subtrahend */ |
| 3332 | #define SUB_64(m_hi, s_hi, m_lo, s_lo) \ |
| 3333 | do { \ |
| 3334 | DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \ |
| 3335 | } while (0) |
| 3336 | |
| 3337 | /* minuend[hi:lo] -= subtrahend */ |
| 3338 | #define SUB_EXTEND_64(m_hi, m_lo, s) \ |
| 3339 | do { \ |
| 3340 | SUB_64(m_hi, 0, m_lo, s); \ |
| 3341 | } while (0) |
| 3342 | |
| 3343 | #define SUB_EXTEND_USTAT(s, t) \ |
| 3344 | do { \ |
| 3345 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 3346 | SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3347 | } while (0) |
| 3348 | |
| 3349 | /* |
| 3350 | * General service functions |
| 3351 | */ |
| 3352 | |
| 3353 | static inline long bnx2x_hilo(u32 *hiref) |
| 3354 | { |
| 3355 | u32 lo = *(hiref + 1); |
| 3356 | #if (BITS_PER_LONG == 64) |
| 3357 | u32 hi = *hiref; |
| 3358 | |
| 3359 | return HILO_U64(hi, lo); |
| 3360 | #else |
| 3361 | return lo; |
| 3362 | #endif |
| 3363 | } |
| 3364 | |
| 3365 | /* |
| 3366 | * Init service functions |
| 3367 | */ |
| 3368 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3369 | static void bnx2x_storm_stats_post(struct bnx2x *bp) |
| 3370 | { |
| 3371 | if (!bp->stats_pending) { |
| 3372 | struct eth_query_ramrod_data ramrod_data = {0}; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3373 | int i, rc; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3374 | |
| 3375 | ramrod_data.drv_counter = bp->stats_counter++; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 3376 | ramrod_data.collect_port = bp->port.pmf ? 1 : 0; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3377 | for_each_queue(bp, i) |
| 3378 | ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3379 | |
| 3380 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0, |
| 3381 | ((u32 *)&ramrod_data)[1], |
| 3382 | ((u32 *)&ramrod_data)[0], 0); |
| 3383 | if (rc == 0) { |
| 3384 | /* stats ramrod has it's own slot on the spq */ |
| 3385 | bp->spq_left++; |
| 3386 | bp->stats_pending = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3387 | } |
| 3388 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3389 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3390 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3391 | static void bnx2x_hw_stats_post(struct bnx2x *bp) |
| 3392 | { |
| 3393 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3394 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3395 | |
| 3396 | *stats_comp = DMAE_COMP_VAL; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3397 | if (CHIP_REV_IS_SLOW(bp)) |
| 3398 | return; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3399 | |
| 3400 | /* loader */ |
| 3401 | if (bp->executer_idx) { |
| 3402 | int loader_idx = PMF_DMAE_C(bp); |
| 3403 | |
| 3404 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3405 | |
| 3406 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3407 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3408 | DMAE_CMD_DST_RESET | |
| 3409 | #ifdef __BIG_ENDIAN |
| 3410 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3411 | #else |
| 3412 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3413 | #endif |
| 3414 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : |
| 3415 | DMAE_CMD_PORT_0) | |
| 3416 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3417 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0])); |
| 3418 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0])); |
| 3419 | dmae->dst_addr_lo = (DMAE_REG_CMD_MEM + |
| 3420 | sizeof(struct dmae_command) * |
| 3421 | (loader_idx + 1)) >> 2; |
| 3422 | dmae->dst_addr_hi = 0; |
| 3423 | dmae->len = sizeof(struct dmae_command) >> 2; |
| 3424 | if (CHIP_IS_E1(bp)) |
| 3425 | dmae->len--; |
| 3426 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2; |
| 3427 | dmae->comp_addr_hi = 0; |
| 3428 | dmae->comp_val = 1; |
| 3429 | |
| 3430 | *stats_comp = 0; |
| 3431 | bnx2x_post_dmae(bp, dmae, loader_idx); |
| 3432 | |
| 3433 | } else if (bp->func_stx) { |
| 3434 | *stats_comp = 0; |
| 3435 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
| 3436 | } |
| 3437 | } |
| 3438 | |
| 3439 | static int bnx2x_stats_comp(struct bnx2x *bp) |
| 3440 | { |
| 3441 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3442 | int cnt = 10; |
| 3443 | |
| 3444 | might_sleep(); |
| 3445 | while (*stats_comp != DMAE_COMP_VAL) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3446 | if (!cnt) { |
| 3447 | BNX2X_ERR("timeout waiting for stats finished\n"); |
| 3448 | break; |
| 3449 | } |
| 3450 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 3451 | msleep(1); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3452 | } |
| 3453 | return 1; |
| 3454 | } |
| 3455 | |
| 3456 | /* |
| 3457 | * Statistics service functions |
| 3458 | */ |
| 3459 | |
| 3460 | static void bnx2x_stats_pmf_update(struct bnx2x *bp) |
| 3461 | { |
| 3462 | struct dmae_command *dmae; |
| 3463 | u32 opcode; |
| 3464 | int loader_idx = PMF_DMAE_C(bp); |
| 3465 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3466 | |
| 3467 | /* sanity */ |
| 3468 | if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) { |
| 3469 | BNX2X_ERR("BUG!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3470 | return; |
| 3471 | } |
| 3472 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3473 | bp->executer_idx = 0; |
| 3474 | |
| 3475 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3476 | DMAE_CMD_C_ENABLE | |
| 3477 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3478 | #ifdef __BIG_ENDIAN |
| 3479 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3480 | #else |
| 3481 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3482 | #endif |
| 3483 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3484 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3485 | |
| 3486 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3487 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 3488 | dmae->src_addr_lo = bp->port.port_stx >> 2; |
| 3489 | dmae->src_addr_hi = 0; |
| 3490 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3491 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3492 | dmae->len = DMAE_LEN32_RD_MAX; |
| 3493 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3494 | dmae->comp_addr_hi = 0; |
| 3495 | dmae->comp_val = 1; |
| 3496 | |
| 3497 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3498 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 3499 | dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX; |
| 3500 | dmae->src_addr_hi = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 3501 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) + |
| 3502 | DMAE_LEN32_RD_MAX * 4); |
| 3503 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) + |
| 3504 | DMAE_LEN32_RD_MAX * 4); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3505 | dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX; |
| 3506 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3507 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3508 | dmae->comp_val = DMAE_COMP_VAL; |
| 3509 | |
| 3510 | *stats_comp = 0; |
| 3511 | bnx2x_hw_stats_post(bp); |
| 3512 | bnx2x_stats_comp(bp); |
| 3513 | } |
| 3514 | |
| 3515 | static void bnx2x_port_stats_init(struct bnx2x *bp) |
| 3516 | { |
| 3517 | struct dmae_command *dmae; |
| 3518 | int port = BP_PORT(bp); |
| 3519 | int vn = BP_E1HVN(bp); |
| 3520 | u32 opcode; |
| 3521 | int loader_idx = PMF_DMAE_C(bp); |
| 3522 | u32 mac_addr; |
| 3523 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3524 | |
| 3525 | /* sanity */ |
| 3526 | if (!bp->link_vars.link_up || !bp->port.pmf) { |
| 3527 | BNX2X_ERR("BUG!\n"); |
| 3528 | return; |
| 3529 | } |
| 3530 | |
| 3531 | bp->executer_idx = 0; |
| 3532 | |
| 3533 | /* MCP */ |
| 3534 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3535 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3536 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3537 | #ifdef __BIG_ENDIAN |
| 3538 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3539 | #else |
| 3540 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3541 | #endif |
| 3542 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3543 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3544 | |
| 3545 | if (bp->port.port_stx) { |
| 3546 | |
| 3547 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3548 | dmae->opcode = opcode; |
| 3549 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3550 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3551 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
| 3552 | dmae->dst_addr_hi = 0; |
| 3553 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 3554 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3555 | dmae->comp_addr_hi = 0; |
| 3556 | dmae->comp_val = 1; |
| 3557 | } |
| 3558 | |
| 3559 | if (bp->func_stx) { |
| 3560 | |
| 3561 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3562 | dmae->opcode = opcode; |
| 3563 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3564 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3565 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3566 | dmae->dst_addr_hi = 0; |
| 3567 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3568 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3569 | dmae->comp_addr_hi = 0; |
| 3570 | dmae->comp_val = 1; |
| 3571 | } |
| 3572 | |
| 3573 | /* MAC */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3574 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3575 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3576 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3577 | #ifdef __BIG_ENDIAN |
| 3578 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3579 | #else |
| 3580 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3581 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3582 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3583 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3584 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3585 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3586 | |
| 3587 | mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM : |
| 3588 | NIG_REG_INGRESS_BMAC0_MEM); |
| 3589 | |
| 3590 | /* BIGMAC_REGISTER_TX_STAT_GTPKT .. |
| 3591 | BIGMAC_REGISTER_TX_STAT_GTBYT */ |
| 3592 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3593 | dmae->opcode = opcode; |
| 3594 | dmae->src_addr_lo = (mac_addr + |
| 3595 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3596 | dmae->src_addr_hi = 0; |
| 3597 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3598 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3599 | dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT - |
| 3600 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3601 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3602 | dmae->comp_addr_hi = 0; |
| 3603 | dmae->comp_val = 1; |
| 3604 | |
| 3605 | /* BIGMAC_REGISTER_RX_STAT_GR64 .. |
| 3606 | BIGMAC_REGISTER_RX_STAT_GRIPJ */ |
| 3607 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3608 | dmae->opcode = opcode; |
| 3609 | dmae->src_addr_lo = (mac_addr + |
| 3610 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3611 | dmae->src_addr_hi = 0; |
| 3612 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3613 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3614 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3615 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3616 | dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ - |
| 3617 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3618 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3619 | dmae->comp_addr_hi = 0; |
| 3620 | dmae->comp_val = 1; |
| 3621 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3622 | } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3623 | |
| 3624 | mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0); |
| 3625 | |
| 3626 | /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/ |
| 3627 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3628 | dmae->opcode = opcode; |
| 3629 | dmae->src_addr_lo = (mac_addr + |
| 3630 | EMAC_REG_EMAC_RX_STAT_AC) >> 2; |
| 3631 | dmae->src_addr_hi = 0; |
| 3632 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3633 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3634 | dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT; |
| 3635 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3636 | dmae->comp_addr_hi = 0; |
| 3637 | dmae->comp_val = 1; |
| 3638 | |
| 3639 | /* EMAC_REG_EMAC_RX_STAT_AC_28 */ |
| 3640 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3641 | dmae->opcode = opcode; |
| 3642 | dmae->src_addr_lo = (mac_addr + |
| 3643 | EMAC_REG_EMAC_RX_STAT_AC_28) >> 2; |
| 3644 | dmae->src_addr_hi = 0; |
| 3645 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3646 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3647 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3648 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3649 | dmae->len = 1; |
| 3650 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3651 | dmae->comp_addr_hi = 0; |
| 3652 | dmae->comp_val = 1; |
| 3653 | |
| 3654 | /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/ |
| 3655 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3656 | dmae->opcode = opcode; |
| 3657 | dmae->src_addr_lo = (mac_addr + |
| 3658 | EMAC_REG_EMAC_TX_STAT_AC) >> 2; |
| 3659 | dmae->src_addr_hi = 0; |
| 3660 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3661 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3662 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3663 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3664 | dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT; |
| 3665 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3666 | dmae->comp_addr_hi = 0; |
| 3667 | dmae->comp_val = 1; |
| 3668 | } |
| 3669 | |
| 3670 | /* NIG */ |
| 3671 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3672 | dmae->opcode = opcode; |
| 3673 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD : |
| 3674 | NIG_REG_STAT0_BRB_DISCARD) >> 2; |
| 3675 | dmae->src_addr_hi = 0; |
| 3676 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats)); |
| 3677 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats)); |
| 3678 | dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2; |
| 3679 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3680 | dmae->comp_addr_hi = 0; |
| 3681 | dmae->comp_val = 1; |
| 3682 | |
| 3683 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3684 | dmae->opcode = opcode; |
| 3685 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 : |
| 3686 | NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2; |
| 3687 | dmae->src_addr_hi = 0; |
| 3688 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3689 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3690 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3691 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3692 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3693 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3694 | dmae->comp_addr_hi = 0; |
| 3695 | dmae->comp_val = 1; |
| 3696 | |
| 3697 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3698 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3699 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3700 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3701 | #ifdef __BIG_ENDIAN |
| 3702 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3703 | #else |
| 3704 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3705 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3706 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3707 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3708 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 : |
| 3709 | NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3710 | dmae->src_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3711 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3712 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3713 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3714 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3715 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3716 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3717 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3718 | dmae->comp_val = DMAE_COMP_VAL; |
| 3719 | |
| 3720 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3721 | } |
| 3722 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3723 | static void bnx2x_func_stats_init(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3724 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3725 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3726 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3727 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3728 | /* sanity */ |
| 3729 | if (!bp->func_stx) { |
| 3730 | BNX2X_ERR("BUG!\n"); |
| 3731 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3732 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3733 | |
| 3734 | bp->executer_idx = 0; |
| 3735 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3736 | |
| 3737 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3738 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3739 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3740 | #ifdef __BIG_ENDIAN |
| 3741 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3742 | #else |
| 3743 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3744 | #endif |
| 3745 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3746 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3747 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3748 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3749 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3750 | dmae->dst_addr_hi = 0; |
| 3751 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3752 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3753 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3754 | dmae->comp_val = DMAE_COMP_VAL; |
| 3755 | |
| 3756 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3757 | } |
| 3758 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3759 | static void bnx2x_stats_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3760 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3761 | if (bp->port.pmf) |
| 3762 | bnx2x_port_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3763 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3764 | else if (bp->func_stx) |
| 3765 | bnx2x_func_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3766 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3767 | bnx2x_hw_stats_post(bp); |
| 3768 | bnx2x_storm_stats_post(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3769 | } |
| 3770 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3771 | static void bnx2x_stats_pmf_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3772 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3773 | bnx2x_stats_comp(bp); |
| 3774 | bnx2x_stats_pmf_update(bp); |
| 3775 | bnx2x_stats_start(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3776 | } |
| 3777 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3778 | static void bnx2x_stats_restart(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3779 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3780 | bnx2x_stats_comp(bp); |
| 3781 | bnx2x_stats_start(bp); |
| 3782 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3783 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3784 | static void bnx2x_bmac_stats_update(struct bnx2x *bp) |
| 3785 | { |
| 3786 | struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats); |
| 3787 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3788 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3789 | struct { |
| 3790 | u32 lo; |
| 3791 | u32 hi; |
| 3792 | } diff; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3793 | |
| 3794 | UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets); |
| 3795 | UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors); |
| 3796 | UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts); |
| 3797 | UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong); |
| 3798 | UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments); |
| 3799 | UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3800 | UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3801 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3802 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3803 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent); |
| 3804 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone); |
| 3805 | UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets); |
| 3806 | UPDATE_STAT64(tx_stat_gt127, |
| 3807 | tx_stat_etherstatspkts65octetsto127octets); |
| 3808 | UPDATE_STAT64(tx_stat_gt255, |
| 3809 | tx_stat_etherstatspkts128octetsto255octets); |
| 3810 | UPDATE_STAT64(tx_stat_gt511, |
| 3811 | tx_stat_etherstatspkts256octetsto511octets); |
| 3812 | UPDATE_STAT64(tx_stat_gt1023, |
| 3813 | tx_stat_etherstatspkts512octetsto1023octets); |
| 3814 | UPDATE_STAT64(tx_stat_gt1518, |
| 3815 | tx_stat_etherstatspkts1024octetsto1522octets); |
| 3816 | UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047); |
| 3817 | UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095); |
| 3818 | UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216); |
| 3819 | UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383); |
| 3820 | UPDATE_STAT64(tx_stat_gterr, |
| 3821 | tx_stat_dot3statsinternalmactransmiterrors); |
| 3822 | UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3823 | |
| 3824 | estats->pause_frames_received_hi = |
| 3825 | pstats->mac_stx[1].rx_stat_bmac_xpf_hi; |
| 3826 | estats->pause_frames_received_lo = |
| 3827 | pstats->mac_stx[1].rx_stat_bmac_xpf_lo; |
| 3828 | |
| 3829 | estats->pause_frames_sent_hi = |
| 3830 | pstats->mac_stx[1].tx_stat_outxoffsent_hi; |
| 3831 | estats->pause_frames_sent_lo = |
| 3832 | pstats->mac_stx[1].tx_stat_outxoffsent_lo; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | static void bnx2x_emac_stats_update(struct bnx2x *bp) |
| 3836 | { |
| 3837 | struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats); |
| 3838 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3839 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3840 | |
| 3841 | UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets); |
| 3842 | UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets); |
| 3843 | UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors); |
| 3844 | UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors); |
| 3845 | UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors); |
| 3846 | UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors); |
| 3847 | UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts); |
| 3848 | UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong); |
| 3849 | UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments); |
| 3850 | UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers); |
| 3851 | UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived); |
| 3852 | UPDATE_EXTEND_STAT(rx_stat_xoffstateentered); |
| 3853 | UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived); |
| 3854 | UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived); |
| 3855 | UPDATE_EXTEND_STAT(tx_stat_outxonsent); |
| 3856 | UPDATE_EXTEND_STAT(tx_stat_outxoffsent); |
| 3857 | UPDATE_EXTEND_STAT(tx_stat_flowcontroldone); |
| 3858 | UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions); |
| 3859 | UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes); |
| 3860 | UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes); |
| 3861 | UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions); |
| 3862 | UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions); |
| 3863 | UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions); |
| 3864 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets); |
| 3865 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets); |
| 3866 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets); |
| 3867 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets); |
| 3868 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets); |
| 3869 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets); |
| 3870 | UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets); |
| 3871 | UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3872 | |
| 3873 | estats->pause_frames_received_hi = |
| 3874 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi; |
| 3875 | estats->pause_frames_received_lo = |
| 3876 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo; |
| 3877 | ADD_64(estats->pause_frames_received_hi, |
| 3878 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi, |
| 3879 | estats->pause_frames_received_lo, |
| 3880 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo); |
| 3881 | |
| 3882 | estats->pause_frames_sent_hi = |
| 3883 | pstats->mac_stx[1].tx_stat_outxonsent_hi; |
| 3884 | estats->pause_frames_sent_lo = |
| 3885 | pstats->mac_stx[1].tx_stat_outxonsent_lo; |
| 3886 | ADD_64(estats->pause_frames_sent_hi, |
| 3887 | pstats->mac_stx[1].tx_stat_outxoffsent_hi, |
| 3888 | estats->pause_frames_sent_lo, |
| 3889 | pstats->mac_stx[1].tx_stat_outxoffsent_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | static int bnx2x_hw_stats_update(struct bnx2x *bp) |
| 3893 | { |
| 3894 | struct nig_stats *new = bnx2x_sp(bp, nig_stats); |
| 3895 | struct nig_stats *old = &(bp->port.old_nig_stats); |
| 3896 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
| 3897 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 3898 | struct { |
| 3899 | u32 lo; |
| 3900 | u32 hi; |
| 3901 | } diff; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3902 | u32 nig_timer_max; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3903 | |
| 3904 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) |
| 3905 | bnx2x_bmac_stats_update(bp); |
| 3906 | |
| 3907 | else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) |
| 3908 | bnx2x_emac_stats_update(bp); |
| 3909 | |
| 3910 | else { /* unreached */ |
Eilon Greenstein | c3eefaf | 2009-03-02 08:01:09 +0000 | [diff] [blame] | 3911 | BNX2X_ERR("stats updated by DMAE but no MAC active\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3912 | return -1; |
| 3913 | } |
| 3914 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3915 | ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo, |
| 3916 | new->brb_discard - old->brb_discard); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3917 | ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo, |
| 3918 | new->brb_truncate - old->brb_truncate); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3919 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3920 | UPDATE_STAT64_NIG(egress_mac_pkt0, |
| 3921 | etherstatspkts1024octetsto1522octets); |
| 3922 | UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3923 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3924 | memcpy(old, new, sizeof(struct nig_stats)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3925 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3926 | memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]), |
| 3927 | sizeof(struct mac_stx)); |
| 3928 | estats->brb_drop_hi = pstats->brb_drop_hi; |
| 3929 | estats->brb_drop_lo = pstats->brb_drop_lo; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3930 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3931 | pstats->host_port_stats_start = ++pstats->host_port_stats_end; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3932 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3933 | nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer); |
| 3934 | if (nig_timer_max != estats->nig_timer_max) { |
| 3935 | estats->nig_timer_max = nig_timer_max; |
| 3936 | BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max); |
| 3937 | } |
| 3938 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3939 | return 0; |
| 3940 | } |
| 3941 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3942 | static int bnx2x_storm_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3943 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3944 | struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3945 | struct tstorm_per_port_stats *tport = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3946 | &stats->tstorm_common.port_statistics; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3947 | struct host_func_stats *fstats = bnx2x_sp(bp, func_stats); |
| 3948 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3949 | int i; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3950 | |
Eilon Greenstein | 6fe49bb | 2009-08-12 08:23:17 +0000 | [diff] [blame] | 3951 | memcpy(&(fstats->total_bytes_received_hi), |
| 3952 | &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3953 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 3954 | estats->error_bytes_received_hi = 0; |
| 3955 | estats->error_bytes_received_lo = 0; |
| 3956 | estats->etherstatsoverrsizepkts_hi = 0; |
| 3957 | estats->etherstatsoverrsizepkts_lo = 0; |
| 3958 | estats->no_buff_discard_hi = 0; |
| 3959 | estats->no_buff_discard_lo = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3960 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 3961 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3962 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 3963 | int cl_id = fp->cl_id; |
| 3964 | struct tstorm_per_client_stats *tclient = |
| 3965 | &stats->tstorm_common.client_statistics[cl_id]; |
| 3966 | struct tstorm_per_client_stats *old_tclient = &fp->old_tclient; |
| 3967 | struct ustorm_per_client_stats *uclient = |
| 3968 | &stats->ustorm_common.client_statistics[cl_id]; |
| 3969 | struct ustorm_per_client_stats *old_uclient = &fp->old_uclient; |
| 3970 | struct xstorm_per_client_stats *xclient = |
| 3971 | &stats->xstorm_common.client_statistics[cl_id]; |
| 3972 | struct xstorm_per_client_stats *old_xclient = &fp->old_xclient; |
| 3973 | struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats; |
| 3974 | u32 diff; |
| 3975 | |
| 3976 | /* are storm stats valid? */ |
| 3977 | if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) != |
| 3978 | bp->stats_counter) { |
| 3979 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm" |
| 3980 | " xstorm counter (%d) != stats_counter (%d)\n", |
| 3981 | i, xclient->stats_counter, bp->stats_counter); |
| 3982 | return -1; |
| 3983 | } |
| 3984 | if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) != |
| 3985 | bp->stats_counter) { |
| 3986 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm" |
| 3987 | " tstorm counter (%d) != stats_counter (%d)\n", |
| 3988 | i, tclient->stats_counter, bp->stats_counter); |
| 3989 | return -2; |
| 3990 | } |
| 3991 | if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) != |
| 3992 | bp->stats_counter) { |
| 3993 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm" |
| 3994 | " ustorm counter (%d) != stats_counter (%d)\n", |
| 3995 | i, uclient->stats_counter, bp->stats_counter); |
| 3996 | return -4; |
| 3997 | } |
| 3998 | |
| 3999 | qstats->total_bytes_received_hi = |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4000 | le32_to_cpu(tclient->rcv_broadcast_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4001 | qstats->total_bytes_received_lo = |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4002 | le32_to_cpu(tclient->rcv_broadcast_bytes.lo); |
| 4003 | |
| 4004 | ADD_64(qstats->total_bytes_received_hi, |
| 4005 | le32_to_cpu(tclient->rcv_multicast_bytes.hi), |
| 4006 | qstats->total_bytes_received_lo, |
| 4007 | le32_to_cpu(tclient->rcv_multicast_bytes.lo)); |
| 4008 | |
| 4009 | ADD_64(qstats->total_bytes_received_hi, |
| 4010 | le32_to_cpu(tclient->rcv_unicast_bytes.hi), |
| 4011 | qstats->total_bytes_received_lo, |
| 4012 | le32_to_cpu(tclient->rcv_unicast_bytes.lo)); |
| 4013 | |
| 4014 | qstats->valid_bytes_received_hi = |
| 4015 | qstats->total_bytes_received_hi; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4016 | qstats->valid_bytes_received_lo = |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4017 | qstats->total_bytes_received_lo; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4018 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4019 | qstats->error_bytes_received_hi = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4020 | le32_to_cpu(tclient->rcv_error_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4021 | qstats->error_bytes_received_lo = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4022 | le32_to_cpu(tclient->rcv_error_bytes.lo); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4023 | |
| 4024 | ADD_64(qstats->total_bytes_received_hi, |
| 4025 | qstats->error_bytes_received_hi, |
| 4026 | qstats->total_bytes_received_lo, |
| 4027 | qstats->error_bytes_received_lo); |
| 4028 | |
| 4029 | UPDATE_EXTEND_TSTAT(rcv_unicast_pkts, |
| 4030 | total_unicast_packets_received); |
| 4031 | UPDATE_EXTEND_TSTAT(rcv_multicast_pkts, |
| 4032 | total_multicast_packets_received); |
| 4033 | UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts, |
| 4034 | total_broadcast_packets_received); |
| 4035 | UPDATE_EXTEND_TSTAT(packets_too_big_discard, |
| 4036 | etherstatsoverrsizepkts); |
| 4037 | UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard); |
| 4038 | |
| 4039 | SUB_EXTEND_USTAT(ucast_no_buff_pkts, |
| 4040 | total_unicast_packets_received); |
| 4041 | SUB_EXTEND_USTAT(mcast_no_buff_pkts, |
| 4042 | total_multicast_packets_received); |
| 4043 | SUB_EXTEND_USTAT(bcast_no_buff_pkts, |
| 4044 | total_broadcast_packets_received); |
| 4045 | UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard); |
| 4046 | UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard); |
| 4047 | UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard); |
| 4048 | |
| 4049 | qstats->total_bytes_transmitted_hi = |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4050 | le32_to_cpu(xclient->unicast_bytes_sent.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4051 | qstats->total_bytes_transmitted_lo = |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4052 | le32_to_cpu(xclient->unicast_bytes_sent.lo); |
| 4053 | |
| 4054 | ADD_64(qstats->total_bytes_transmitted_hi, |
| 4055 | le32_to_cpu(xclient->multicast_bytes_sent.hi), |
| 4056 | qstats->total_bytes_transmitted_lo, |
| 4057 | le32_to_cpu(xclient->multicast_bytes_sent.lo)); |
| 4058 | |
| 4059 | ADD_64(qstats->total_bytes_transmitted_hi, |
| 4060 | le32_to_cpu(xclient->broadcast_bytes_sent.hi), |
| 4061 | qstats->total_bytes_transmitted_lo, |
| 4062 | le32_to_cpu(xclient->broadcast_bytes_sent.lo)); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4063 | |
| 4064 | UPDATE_EXTEND_XSTAT(unicast_pkts_sent, |
| 4065 | total_unicast_packets_transmitted); |
| 4066 | UPDATE_EXTEND_XSTAT(multicast_pkts_sent, |
| 4067 | total_multicast_packets_transmitted); |
| 4068 | UPDATE_EXTEND_XSTAT(broadcast_pkts_sent, |
| 4069 | total_broadcast_packets_transmitted); |
| 4070 | |
| 4071 | old_tclient->checksum_discard = tclient->checksum_discard; |
| 4072 | old_tclient->ttl0_discard = tclient->ttl0_discard; |
| 4073 | |
| 4074 | ADD_64(fstats->total_bytes_received_hi, |
| 4075 | qstats->total_bytes_received_hi, |
| 4076 | fstats->total_bytes_received_lo, |
| 4077 | qstats->total_bytes_received_lo); |
| 4078 | ADD_64(fstats->total_bytes_transmitted_hi, |
| 4079 | qstats->total_bytes_transmitted_hi, |
| 4080 | fstats->total_bytes_transmitted_lo, |
| 4081 | qstats->total_bytes_transmitted_lo); |
| 4082 | ADD_64(fstats->total_unicast_packets_received_hi, |
| 4083 | qstats->total_unicast_packets_received_hi, |
| 4084 | fstats->total_unicast_packets_received_lo, |
| 4085 | qstats->total_unicast_packets_received_lo); |
| 4086 | ADD_64(fstats->total_multicast_packets_received_hi, |
| 4087 | qstats->total_multicast_packets_received_hi, |
| 4088 | fstats->total_multicast_packets_received_lo, |
| 4089 | qstats->total_multicast_packets_received_lo); |
| 4090 | ADD_64(fstats->total_broadcast_packets_received_hi, |
| 4091 | qstats->total_broadcast_packets_received_hi, |
| 4092 | fstats->total_broadcast_packets_received_lo, |
| 4093 | qstats->total_broadcast_packets_received_lo); |
| 4094 | ADD_64(fstats->total_unicast_packets_transmitted_hi, |
| 4095 | qstats->total_unicast_packets_transmitted_hi, |
| 4096 | fstats->total_unicast_packets_transmitted_lo, |
| 4097 | qstats->total_unicast_packets_transmitted_lo); |
| 4098 | ADD_64(fstats->total_multicast_packets_transmitted_hi, |
| 4099 | qstats->total_multicast_packets_transmitted_hi, |
| 4100 | fstats->total_multicast_packets_transmitted_lo, |
| 4101 | qstats->total_multicast_packets_transmitted_lo); |
| 4102 | ADD_64(fstats->total_broadcast_packets_transmitted_hi, |
| 4103 | qstats->total_broadcast_packets_transmitted_hi, |
| 4104 | fstats->total_broadcast_packets_transmitted_lo, |
| 4105 | qstats->total_broadcast_packets_transmitted_lo); |
| 4106 | ADD_64(fstats->valid_bytes_received_hi, |
| 4107 | qstats->valid_bytes_received_hi, |
| 4108 | fstats->valid_bytes_received_lo, |
| 4109 | qstats->valid_bytes_received_lo); |
| 4110 | |
| 4111 | ADD_64(estats->error_bytes_received_hi, |
| 4112 | qstats->error_bytes_received_hi, |
| 4113 | estats->error_bytes_received_lo, |
| 4114 | qstats->error_bytes_received_lo); |
| 4115 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 4116 | qstats->etherstatsoverrsizepkts_hi, |
| 4117 | estats->etherstatsoverrsizepkts_lo, |
| 4118 | qstats->etherstatsoverrsizepkts_lo); |
| 4119 | ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi, |
| 4120 | estats->no_buff_discard_lo, qstats->no_buff_discard_lo); |
| 4121 | } |
| 4122 | |
| 4123 | ADD_64(fstats->total_bytes_received_hi, |
| 4124 | estats->rx_stat_ifhcinbadoctets_hi, |
| 4125 | fstats->total_bytes_received_lo, |
| 4126 | estats->rx_stat_ifhcinbadoctets_lo); |
| 4127 | |
| 4128 | memcpy(estats, &(fstats->total_bytes_received_hi), |
| 4129 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 4130 | |
| 4131 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 4132 | estats->rx_stat_dot3statsframestoolong_hi, |
| 4133 | estats->etherstatsoverrsizepkts_lo, |
| 4134 | estats->rx_stat_dot3statsframestoolong_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4135 | ADD_64(estats->error_bytes_received_hi, |
| 4136 | estats->rx_stat_ifhcinbadoctets_hi, |
| 4137 | estats->error_bytes_received_lo, |
| 4138 | estats->rx_stat_ifhcinbadoctets_lo); |
| 4139 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4140 | if (bp->port.pmf) { |
| 4141 | estats->mac_filter_discard = |
| 4142 | le32_to_cpu(tport->mac_filter_discard); |
| 4143 | estats->xxoverflow_discard = |
| 4144 | le32_to_cpu(tport->xxoverflow_discard); |
| 4145 | estats->brb_truncate_discard = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4146 | le32_to_cpu(tport->brb_truncate_discard); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4147 | estats->mac_discard = le32_to_cpu(tport->mac_discard); |
| 4148 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4149 | |
| 4150 | fstats->host_func_stats_start = ++fstats->host_func_stats_end; |
| 4151 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4152 | bp->stats_pending = 0; |
| 4153 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4154 | return 0; |
| 4155 | } |
| 4156 | |
| 4157 | static void bnx2x_net_stats_update(struct bnx2x *bp) |
| 4158 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4159 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4160 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4161 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4162 | |
| 4163 | nstats->rx_packets = |
| 4164 | bnx2x_hilo(&estats->total_unicast_packets_received_hi) + |
| 4165 | bnx2x_hilo(&estats->total_multicast_packets_received_hi) + |
| 4166 | bnx2x_hilo(&estats->total_broadcast_packets_received_hi); |
| 4167 | |
| 4168 | nstats->tx_packets = |
| 4169 | bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) + |
| 4170 | bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) + |
| 4171 | bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi); |
| 4172 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4173 | nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4174 | |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 4175 | nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4176 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4177 | nstats->rx_dropped = estats->mac_discard; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4178 | for_each_rx_queue(bp, i) |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4179 | nstats->rx_dropped += |
| 4180 | le32_to_cpu(bp->fp[i].old_tclient.checksum_discard); |
| 4181 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4182 | nstats->tx_dropped = 0; |
| 4183 | |
| 4184 | nstats->multicast = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4185 | bnx2x_hilo(&estats->total_multicast_packets_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4186 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4187 | nstats->collisions = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4188 | bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4189 | |
| 4190 | nstats->rx_length_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4191 | bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) + |
| 4192 | bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi); |
| 4193 | nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) + |
| 4194 | bnx2x_hilo(&estats->brb_truncate_hi); |
| 4195 | nstats->rx_crc_errors = |
| 4196 | bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi); |
| 4197 | nstats->rx_frame_errors = |
| 4198 | bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi); |
| 4199 | nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4200 | nstats->rx_missed_errors = estats->xxoverflow_discard; |
| 4201 | |
| 4202 | nstats->rx_errors = nstats->rx_length_errors + |
| 4203 | nstats->rx_over_errors + |
| 4204 | nstats->rx_crc_errors + |
| 4205 | nstats->rx_frame_errors + |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 4206 | nstats->rx_fifo_errors + |
| 4207 | nstats->rx_missed_errors; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4208 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4209 | nstats->tx_aborted_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4210 | bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) + |
| 4211 | bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi); |
| 4212 | nstats->tx_carrier_errors = |
| 4213 | bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4214 | nstats->tx_fifo_errors = 0; |
| 4215 | nstats->tx_heartbeat_errors = 0; |
| 4216 | nstats->tx_window_errors = 0; |
| 4217 | |
| 4218 | nstats->tx_errors = nstats->tx_aborted_errors + |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4219 | nstats->tx_carrier_errors + |
| 4220 | bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi); |
| 4221 | } |
| 4222 | |
| 4223 | static void bnx2x_drv_stats_update(struct bnx2x *bp) |
| 4224 | { |
| 4225 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
| 4226 | int i; |
| 4227 | |
| 4228 | estats->driver_xoff = 0; |
| 4229 | estats->rx_err_discard_pkt = 0; |
| 4230 | estats->rx_skb_alloc_failed = 0; |
| 4231 | estats->hw_csum_err = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4232 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4233 | struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats; |
| 4234 | |
| 4235 | estats->driver_xoff += qstats->driver_xoff; |
| 4236 | estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt; |
| 4237 | estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed; |
| 4238 | estats->hw_csum_err += qstats->hw_csum_err; |
| 4239 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4240 | } |
| 4241 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4242 | static void bnx2x_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4243 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4244 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4245 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4246 | if (*stats_comp != DMAE_COMP_VAL) |
| 4247 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4248 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4249 | if (bp->port.pmf) |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4250 | bnx2x_hw_stats_update(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4251 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4252 | if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) { |
| 4253 | BNX2X_ERR("storm stats were not updated for 3 times\n"); |
| 4254 | bnx2x_panic(); |
| 4255 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4256 | } |
| 4257 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4258 | bnx2x_net_stats_update(bp); |
| 4259 | bnx2x_drv_stats_update(bp); |
| 4260 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4261 | if (bp->msglevel & NETIF_MSG_TIMER) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4262 | struct bnx2x_fastpath *fp0_rx = bp->fp; |
| 4263 | struct bnx2x_fastpath *fp0_tx = &(bp->fp[bp->num_rx_queues]); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4264 | struct tstorm_per_client_stats *old_tclient = |
| 4265 | &bp->fp->old_tclient; |
| 4266 | struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4267 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4268 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4269 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4270 | |
| 4271 | printk(KERN_DEBUG "%s:\n", bp->dev->name); |
| 4272 | printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)" |
| 4273 | " tx pkt (%lx)\n", |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4274 | bnx2x_tx_avail(fp0_tx), |
| 4275 | le16_to_cpu(*fp0_tx->tx_cons_sb), nstats->tx_packets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4276 | printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)" |
| 4277 | " rx pkt (%lx)\n", |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4278 | (u16)(le16_to_cpu(*fp0_rx->rx_cons_sb) - |
| 4279 | fp0_rx->rx_comp_cons), |
| 4280 | le16_to_cpu(*fp0_rx->rx_cons_sb), nstats->rx_packets); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4281 | printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u " |
| 4282 | "brb truncate %u\n", |
| 4283 | (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"), |
| 4284 | qstats->driver_xoff, |
| 4285 | estats->brb_drop_lo, estats->brb_truncate_lo); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4286 | printk(KERN_DEBUG "tstats: checksum_discard %u " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4287 | "packets_too_big_discard %lu no_buff_discard %lu " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4288 | "mac_discard %u mac_filter_discard %u " |
| 4289 | "xxovrflow_discard %u brb_truncate_discard %u " |
| 4290 | "ttl0_discard %u\n", |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 4291 | le32_to_cpu(old_tclient->checksum_discard), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4292 | bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi), |
| 4293 | bnx2x_hilo(&qstats->no_buff_discard_hi), |
| 4294 | estats->mac_discard, estats->mac_filter_discard, |
| 4295 | estats->xxoverflow_discard, estats->brb_truncate_discard, |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 4296 | le32_to_cpu(old_tclient->ttl0_discard)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4297 | |
| 4298 | for_each_queue(bp, i) { |
| 4299 | printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i, |
| 4300 | bnx2x_fp(bp, i, tx_pkt), |
| 4301 | bnx2x_fp(bp, i, rx_pkt), |
| 4302 | bnx2x_fp(bp, i, rx_calls)); |
| 4303 | } |
| 4304 | } |
| 4305 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4306 | bnx2x_hw_stats_post(bp); |
| 4307 | bnx2x_storm_stats_post(bp); |
| 4308 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4309 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4310 | static void bnx2x_port_stats_stop(struct bnx2x *bp) |
| 4311 | { |
| 4312 | struct dmae_command *dmae; |
| 4313 | u32 opcode; |
| 4314 | int loader_idx = PMF_DMAE_C(bp); |
| 4315 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4316 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4317 | bp->executer_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4318 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4319 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 4320 | DMAE_CMD_C_ENABLE | |
| 4321 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4322 | #ifdef __BIG_ENDIAN |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4323 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4324 | #else |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4325 | DMAE_CMD_ENDIANITY_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4326 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4327 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 4328 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 4329 | |
| 4330 | if (bp->port.port_stx) { |
| 4331 | |
| 4332 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 4333 | if (bp->func_stx) |
| 4334 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 4335 | else |
| 4336 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 4337 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 4338 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 4339 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4340 | dmae->dst_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4341 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 4342 | if (bp->func_stx) { |
| 4343 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 4344 | dmae->comp_addr_hi = 0; |
| 4345 | dmae->comp_val = 1; |
| 4346 | } else { |
| 4347 | dmae->comp_addr_lo = |
| 4348 | U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4349 | dmae->comp_addr_hi = |
| 4350 | U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4351 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4352 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4353 | *stats_comp = 0; |
| 4354 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4357 | if (bp->func_stx) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4358 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4359 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 4360 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 4361 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 4362 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 4363 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 4364 | dmae->dst_addr_hi = 0; |
| 4365 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 4366 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4367 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4368 | dmae->comp_val = DMAE_COMP_VAL; |
| 4369 | |
| 4370 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4374 | static void bnx2x_stats_stop(struct bnx2x *bp) |
| 4375 | { |
| 4376 | int update = 0; |
| 4377 | |
| 4378 | bnx2x_stats_comp(bp); |
| 4379 | |
| 4380 | if (bp->port.pmf) |
| 4381 | update = (bnx2x_hw_stats_update(bp) == 0); |
| 4382 | |
| 4383 | update |= (bnx2x_storm_stats_update(bp) == 0); |
| 4384 | |
| 4385 | if (update) { |
| 4386 | bnx2x_net_stats_update(bp); |
| 4387 | |
| 4388 | if (bp->port.pmf) |
| 4389 | bnx2x_port_stats_stop(bp); |
| 4390 | |
| 4391 | bnx2x_hw_stats_post(bp); |
| 4392 | bnx2x_stats_comp(bp); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | static void bnx2x_stats_do_nothing(struct bnx2x *bp) |
| 4397 | { |
| 4398 | } |
| 4399 | |
| 4400 | static const struct { |
| 4401 | void (*action)(struct bnx2x *bp); |
| 4402 | enum bnx2x_stats_state next_state; |
| 4403 | } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = { |
| 4404 | /* state event */ |
| 4405 | { |
| 4406 | /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED}, |
| 4407 | /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED}, |
| 4408 | /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}, |
| 4409 | /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED} |
| 4410 | }, |
| 4411 | { |
| 4412 | /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED}, |
| 4413 | /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED}, |
| 4414 | /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED}, |
| 4415 | /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED} |
| 4416 | } |
| 4417 | }; |
| 4418 | |
| 4419 | static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event) |
| 4420 | { |
| 4421 | enum bnx2x_stats_state state = bp->stats_state; |
| 4422 | |
| 4423 | bnx2x_stats_stm[state][event].action(bp); |
| 4424 | bp->stats_state = bnx2x_stats_stm[state][event].next_state; |
| 4425 | |
Eilon Greenstein | 8924665 | 2009-08-12 08:23:56 +0000 | [diff] [blame] | 4426 | /* Make sure the state has been "changed" */ |
| 4427 | smp_wmb(); |
| 4428 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4429 | if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER)) |
| 4430 | DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", |
| 4431 | state, event, bp->stats_state); |
| 4432 | } |
| 4433 | |
Eilon Greenstein | 6fe49bb | 2009-08-12 08:23:17 +0000 | [diff] [blame] | 4434 | static void bnx2x_port_stats_base_init(struct bnx2x *bp) |
| 4435 | { |
| 4436 | struct dmae_command *dmae; |
| 4437 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 4438 | |
| 4439 | /* sanity */ |
| 4440 | if (!bp->port.pmf || !bp->port.port_stx) { |
| 4441 | BNX2X_ERR("BUG!\n"); |
| 4442 | return; |
| 4443 | } |
| 4444 | |
| 4445 | bp->executer_idx = 0; |
| 4446 | |
| 4447 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 4448 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 4449 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 4450 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 4451 | #ifdef __BIG_ENDIAN |
| 4452 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 4453 | #else |
| 4454 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 4455 | #endif |
| 4456 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 4457 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 4458 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 4459 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 4460 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
| 4461 | dmae->dst_addr_hi = 0; |
| 4462 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 4463 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4464 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4465 | dmae->comp_val = DMAE_COMP_VAL; |
| 4466 | |
| 4467 | *stats_comp = 0; |
| 4468 | bnx2x_hw_stats_post(bp); |
| 4469 | bnx2x_stats_comp(bp); |
| 4470 | } |
| 4471 | |
| 4472 | static void bnx2x_func_stats_base_init(struct bnx2x *bp) |
| 4473 | { |
| 4474 | int vn, vn_max = IS_E1HMF(bp) ? E1HVN_MAX : E1VN_MAX; |
| 4475 | int port = BP_PORT(bp); |
| 4476 | int func; |
| 4477 | u32 func_stx; |
| 4478 | |
| 4479 | /* sanity */ |
| 4480 | if (!bp->port.pmf || !bp->func_stx) { |
| 4481 | BNX2X_ERR("BUG!\n"); |
| 4482 | return; |
| 4483 | } |
| 4484 | |
| 4485 | /* save our func_stx */ |
| 4486 | func_stx = bp->func_stx; |
| 4487 | |
| 4488 | for (vn = VN_0; vn < vn_max; vn++) { |
| 4489 | func = 2*vn + port; |
| 4490 | |
| 4491 | bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param); |
| 4492 | bnx2x_func_stats_init(bp); |
| 4493 | bnx2x_hw_stats_post(bp); |
| 4494 | bnx2x_stats_comp(bp); |
| 4495 | } |
| 4496 | |
| 4497 | /* restore our func_stx */ |
| 4498 | bp->func_stx = func_stx; |
| 4499 | } |
| 4500 | |
| 4501 | static void bnx2x_func_stats_base_update(struct bnx2x *bp) |
| 4502 | { |
| 4503 | struct dmae_command *dmae = &bp->stats_dmae; |
| 4504 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 4505 | |
| 4506 | /* sanity */ |
| 4507 | if (!bp->func_stx) { |
| 4508 | BNX2X_ERR("BUG!\n"); |
| 4509 | return; |
| 4510 | } |
| 4511 | |
| 4512 | bp->executer_idx = 0; |
| 4513 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 4514 | |
| 4515 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 4516 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 4517 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 4518 | #ifdef __BIG_ENDIAN |
| 4519 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 4520 | #else |
| 4521 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 4522 | #endif |
| 4523 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 4524 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 4525 | dmae->src_addr_lo = bp->func_stx >> 2; |
| 4526 | dmae->src_addr_hi = 0; |
| 4527 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats_base)); |
| 4528 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats_base)); |
| 4529 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 4530 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 4531 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 4532 | dmae->comp_val = DMAE_COMP_VAL; |
| 4533 | |
| 4534 | *stats_comp = 0; |
| 4535 | bnx2x_hw_stats_post(bp); |
| 4536 | bnx2x_stats_comp(bp); |
| 4537 | } |
| 4538 | |
| 4539 | static void bnx2x_stats_init(struct bnx2x *bp) |
| 4540 | { |
| 4541 | int port = BP_PORT(bp); |
| 4542 | int func = BP_FUNC(bp); |
| 4543 | int i; |
| 4544 | |
| 4545 | bp->stats_pending = 0; |
| 4546 | bp->executer_idx = 0; |
| 4547 | bp->stats_counter = 0; |
| 4548 | |
| 4549 | /* port and func stats for management */ |
| 4550 | if (!BP_NOMCP(bp)) { |
| 4551 | bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx); |
| 4552 | bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param); |
| 4553 | |
| 4554 | } else { |
| 4555 | bp->port.port_stx = 0; |
| 4556 | bp->func_stx = 0; |
| 4557 | } |
| 4558 | DP(BNX2X_MSG_STATS, "port_stx 0x%x func_stx 0x%x\n", |
| 4559 | bp->port.port_stx, bp->func_stx); |
| 4560 | |
| 4561 | /* port stats */ |
| 4562 | memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats)); |
| 4563 | bp->port.old_nig_stats.brb_discard = |
| 4564 | REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38); |
| 4565 | bp->port.old_nig_stats.brb_truncate = |
| 4566 | REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38); |
| 4567 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50, |
| 4568 | &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2); |
| 4569 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50, |
| 4570 | &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2); |
| 4571 | |
| 4572 | /* function stats */ |
| 4573 | for_each_queue(bp, i) { |
| 4574 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 4575 | |
| 4576 | memset(&fp->old_tclient, 0, |
| 4577 | sizeof(struct tstorm_per_client_stats)); |
| 4578 | memset(&fp->old_uclient, 0, |
| 4579 | sizeof(struct ustorm_per_client_stats)); |
| 4580 | memset(&fp->old_xclient, 0, |
| 4581 | sizeof(struct xstorm_per_client_stats)); |
| 4582 | memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats)); |
| 4583 | } |
| 4584 | |
| 4585 | memset(&bp->dev->stats, 0, sizeof(struct net_device_stats)); |
| 4586 | memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats)); |
| 4587 | |
| 4588 | bp->stats_state = STATS_STATE_DISABLED; |
| 4589 | |
| 4590 | if (bp->port.pmf) { |
| 4591 | if (bp->port.port_stx) |
| 4592 | bnx2x_port_stats_base_init(bp); |
| 4593 | |
| 4594 | if (bp->func_stx) |
| 4595 | bnx2x_func_stats_base_init(bp); |
| 4596 | |
| 4597 | } else if (bp->func_stx) |
| 4598 | bnx2x_func_stats_base_update(bp); |
| 4599 | } |
| 4600 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4601 | static void bnx2x_timer(unsigned long data) |
| 4602 | { |
| 4603 | struct bnx2x *bp = (struct bnx2x *) data; |
| 4604 | |
| 4605 | if (!netif_running(bp->dev)) |
| 4606 | return; |
| 4607 | |
| 4608 | if (atomic_read(&bp->intr_sem) != 0) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4609 | goto timer_restart; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4610 | |
| 4611 | if (poll) { |
| 4612 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 4613 | int rc; |
| 4614 | |
Eilon Greenstein | 7961f79 | 2009-03-02 07:59:31 +0000 | [diff] [blame] | 4615 | bnx2x_tx_int(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4616 | rc = bnx2x_rx_int(fp, 1000); |
| 4617 | } |
| 4618 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4619 | if (!BP_NOMCP(bp)) { |
| 4620 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4621 | u32 drv_pulse; |
| 4622 | u32 mcp_pulse; |
| 4623 | |
| 4624 | ++bp->fw_drv_pulse_wr_seq; |
| 4625 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; |
| 4626 | /* TBD - add SYSTEM_TIME */ |
| 4627 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4628 | SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4629 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4630 | mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4631 | MCP_PULSE_SEQ_MASK); |
| 4632 | /* The delta between driver pulse and mcp response |
| 4633 | * should be 1 (before mcp response) or 0 (after mcp response) |
| 4634 | */ |
| 4635 | if ((drv_pulse != mcp_pulse) && |
| 4636 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { |
| 4637 | /* someone lost a heartbeat... */ |
| 4638 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", |
| 4639 | drv_pulse, mcp_pulse); |
| 4640 | } |
| 4641 | } |
| 4642 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4643 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 4644 | (bp->state == BNX2X_STATE_DISABLED)) |
| 4645 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4646 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4647 | timer_restart: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4648 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 4649 | } |
| 4650 | |
| 4651 | /* end of Statistics */ |
| 4652 | |
| 4653 | /* nic init */ |
| 4654 | |
| 4655 | /* |
| 4656 | * nic init service functions |
| 4657 | */ |
| 4658 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4659 | static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4660 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4661 | int port = BP_PORT(bp); |
| 4662 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4663 | /* "CSTORM" */ |
| 4664 | bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY + |
| 4665 | CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), 0, |
| 4666 | CSTORM_SB_STATUS_BLOCK_U_SIZE / 4); |
| 4667 | bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY + |
| 4668 | CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), 0, |
| 4669 | CSTORM_SB_STATUS_BLOCK_C_SIZE / 4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4672 | static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb, |
| 4673 | dma_addr_t mapping, int sb_id) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4674 | { |
| 4675 | int port = BP_PORT(bp); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4676 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4677 | int index; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4678 | u64 section; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4679 | |
| 4680 | /* USTORM */ |
| 4681 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4682 | u_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4683 | sb->u_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4684 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4685 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4686 | CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id), U64_LO(section)); |
| 4687 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4688 | ((CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4689 | U64_HI(section)); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4690 | REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_USB_FUNC_OFF + |
| 4691 | CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4692 | |
| 4693 | for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++) |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4694 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
| 4695 | CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4696 | |
| 4697 | /* CSTORM */ |
| 4698 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4699 | c_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4700 | sb->c_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4701 | |
| 4702 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4703 | CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4704 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4705 | ((CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4706 | U64_HI(section)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4707 | REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4708 | CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4709 | |
| 4710 | for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++) |
| 4711 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4712 | CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4713 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4714 | bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
| 4715 | } |
| 4716 | |
| 4717 | static void bnx2x_zero_def_sb(struct bnx2x *bp) |
| 4718 | { |
| 4719 | int func = BP_FUNC(bp); |
| 4720 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4721 | bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4722 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4723 | sizeof(struct tstorm_def_status_block)/4); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4724 | bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY + |
| 4725 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), 0, |
| 4726 | sizeof(struct cstorm_def_status_block_u)/4); |
| 4727 | bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY + |
| 4728 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), 0, |
| 4729 | sizeof(struct cstorm_def_status_block_c)/4); |
| 4730 | bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY + |
Eilon Greenstein | 490c3c9 | 2009-03-02 07:59:52 +0000 | [diff] [blame] | 4731 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4732 | sizeof(struct xstorm_def_status_block)/4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | static void bnx2x_init_def_sb(struct bnx2x *bp, |
| 4736 | struct host_def_status_block *def_sb, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4737 | dma_addr_t mapping, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4738 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4739 | int port = BP_PORT(bp); |
| 4740 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4741 | int index, val, reg_offset; |
| 4742 | u64 section; |
| 4743 | |
| 4744 | /* ATTN */ |
| 4745 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4746 | atten_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4747 | def_sb->atten_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4748 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4749 | bp->attn_state = 0; |
| 4750 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4751 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 4752 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 4753 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4754 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4755 | bp->attn_group[index].sig[0] = REG_RD(bp, |
| 4756 | reg_offset + 0x10*index); |
| 4757 | bp->attn_group[index].sig[1] = REG_RD(bp, |
| 4758 | reg_offset + 0x4 + 0x10*index); |
| 4759 | bp->attn_group[index].sig[2] = REG_RD(bp, |
| 4760 | reg_offset + 0x8 + 0x10*index); |
| 4761 | bp->attn_group[index].sig[3] = REG_RD(bp, |
| 4762 | reg_offset + 0xc + 0x10*index); |
| 4763 | } |
| 4764 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4765 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : |
| 4766 | HC_REG_ATTN_MSG0_ADDR_L); |
| 4767 | |
| 4768 | REG_WR(bp, reg_offset, U64_LO(section)); |
| 4769 | REG_WR(bp, reg_offset + 4, U64_HI(section)); |
| 4770 | |
| 4771 | reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0); |
| 4772 | |
| 4773 | val = REG_RD(bp, reg_offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4774 | val |= sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4775 | REG_WR(bp, reg_offset, val); |
| 4776 | |
| 4777 | /* USTORM */ |
| 4778 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4779 | u_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4780 | def_sb->u_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4781 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4782 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4783 | CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func), U64_LO(section)); |
| 4784 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
| 4785 | ((CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4786 | U64_HI(section)); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4787 | REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_USB_FUNC_OFF + |
| 4788 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4789 | |
| 4790 | for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++) |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4791 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
| 4792 | CSTORM_DEF_SB_HC_DISABLE_U_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4793 | |
| 4794 | /* CSTORM */ |
| 4795 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4796 | c_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4797 | def_sb->c_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4798 | |
| 4799 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4800 | CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4801 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4802 | ((CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4803 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4804 | REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4805 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4806 | |
| 4807 | for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++) |
| 4808 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4809 | CSTORM_DEF_SB_HC_DISABLE_C_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4810 | |
| 4811 | /* TSTORM */ |
| 4812 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4813 | t_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4814 | def_sb->t_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4815 | |
| 4816 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4817 | TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4818 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4819 | ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4820 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4821 | REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4822 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4823 | |
| 4824 | for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++) |
| 4825 | REG_WR16(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4826 | TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4827 | |
| 4828 | /* XSTORM */ |
| 4829 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4830 | x_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4831 | def_sb->x_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4832 | |
| 4833 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4834 | XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4835 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4836 | ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4837 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4838 | REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4839 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4840 | |
| 4841 | for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++) |
| 4842 | REG_WR16(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4843 | XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4844 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4845 | bp->stats_pending = 0; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4846 | bp->set_mac_pending = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4847 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4848 | bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | static void bnx2x_update_coalesce(struct bnx2x *bp) |
| 4852 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4853 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4854 | int i; |
| 4855 | |
| 4856 | for_each_queue(bp, i) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4857 | int sb_id = bp->fp[i].sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4858 | |
| 4859 | /* HC_INDEX_U_ETH_RX_CQ_CONS */ |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4860 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
| 4861 | CSTORM_SB_HC_TIMEOUT_U_OFFSET(port, sb_id, |
| 4862 | U_SB_ETH_RX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4863 | bp->rx_ticks/12); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4864 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
| 4865 | CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id, |
| 4866 | U_SB_ETH_RX_CQ_INDEX), |
Eilon Greenstein | 3799cf4 | 2009-07-05 04:18:12 +0000 | [diff] [blame] | 4867 | (bp->rx_ticks/12) ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4868 | |
| 4869 | /* HC_INDEX_C_ETH_TX_CQ_CONS */ |
| 4870 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4871 | CSTORM_SB_HC_TIMEOUT_C_OFFSET(port, sb_id, |
| 4872 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4873 | bp->tx_ticks/12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4874 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4875 | CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id, |
| 4876 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 3799cf4 | 2009-07-05 04:18:12 +0000 | [diff] [blame] | 4877 | (bp->tx_ticks/12) ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4881 | static inline void bnx2x_free_tpa_pool(struct bnx2x *bp, |
| 4882 | struct bnx2x_fastpath *fp, int last) |
| 4883 | { |
| 4884 | int i; |
| 4885 | |
| 4886 | for (i = 0; i < last; i++) { |
| 4887 | struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]); |
| 4888 | struct sk_buff *skb = rx_buf->skb; |
| 4889 | |
| 4890 | if (skb == NULL) { |
| 4891 | DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i); |
| 4892 | continue; |
| 4893 | } |
| 4894 | |
| 4895 | if (fp->tpa_state[i] == BNX2X_TPA_START) |
| 4896 | pci_unmap_single(bp->pdev, |
| 4897 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 4898 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4899 | |
| 4900 | dev_kfree_skb(skb); |
| 4901 | rx_buf->skb = NULL; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4905 | static void bnx2x_init_rx_rings(struct bnx2x *bp) |
| 4906 | { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4907 | int func = BP_FUNC(bp); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4908 | int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 : |
| 4909 | ETH_MAX_AGGREGATION_QUEUES_E1H; |
| 4910 | u16 ring_prod, cqe_ring_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4911 | int i, j; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4912 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 4913 | bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN; |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 4914 | DP(NETIF_MSG_IFUP, |
| 4915 | "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4916 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4917 | if (bp->flags & TPA_ENABLE_FLAG) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4918 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4919 | for_each_rx_queue(bp, j) { |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4920 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4921 | |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4922 | for (i = 0; i < max_agg_queues; i++) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4923 | fp->tpa_pool[i].skb = |
| 4924 | netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 4925 | if (!fp->tpa_pool[i].skb) { |
| 4926 | BNX2X_ERR("Failed to allocate TPA " |
| 4927 | "skb pool for queue[%d] - " |
| 4928 | "disabling TPA on this " |
| 4929 | "queue!\n", j); |
| 4930 | bnx2x_free_tpa_pool(bp, fp, i); |
| 4931 | fp->disable_tpa = 1; |
| 4932 | break; |
| 4933 | } |
| 4934 | pci_unmap_addr_set((struct sw_rx_bd *) |
| 4935 | &bp->fp->tpa_pool[i], |
| 4936 | mapping, 0); |
| 4937 | fp->tpa_state[i] = BNX2X_TPA_STOP; |
| 4938 | } |
| 4939 | } |
| 4940 | } |
| 4941 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4942 | for_each_rx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4943 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 4944 | |
| 4945 | fp->rx_bd_cons = 0; |
| 4946 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4947 | fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4948 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 4949 | /* Mark queue as Rx */ |
| 4950 | fp->is_rx_queue = 1; |
| 4951 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4952 | /* "next page" elements initialization */ |
| 4953 | /* SGE ring */ |
| 4954 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 4955 | struct eth_rx_sge *sge; |
| 4956 | |
| 4957 | sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2]; |
| 4958 | sge->addr_hi = |
| 4959 | cpu_to_le32(U64_HI(fp->rx_sge_mapping + |
| 4960 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4961 | sge->addr_lo = |
| 4962 | cpu_to_le32(U64_LO(fp->rx_sge_mapping + |
| 4963 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4964 | } |
| 4965 | |
| 4966 | bnx2x_init_sge_ring_bit_mask(fp); |
| 4967 | |
| 4968 | /* RX BD ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4969 | for (i = 1; i <= NUM_RX_RINGS; i++) { |
| 4970 | struct eth_rx_bd *rx_bd; |
| 4971 | |
| 4972 | rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2]; |
| 4973 | rx_bd->addr_hi = |
| 4974 | cpu_to_le32(U64_HI(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4975 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4976 | rx_bd->addr_lo = |
| 4977 | cpu_to_le32(U64_LO(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4978 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4979 | } |
| 4980 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4981 | /* CQ ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4982 | for (i = 1; i <= NUM_RCQ_RINGS; i++) { |
| 4983 | struct eth_rx_cqe_next_page *nextpg; |
| 4984 | |
| 4985 | nextpg = (struct eth_rx_cqe_next_page *) |
| 4986 | &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1]; |
| 4987 | nextpg->addr_hi = |
| 4988 | cpu_to_le32(U64_HI(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4989 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4990 | nextpg->addr_lo = |
| 4991 | cpu_to_le32(U64_LO(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4992 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4993 | } |
| 4994 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4995 | /* Allocate SGEs and initialize the ring elements */ |
| 4996 | for (i = 0, ring_prod = 0; |
| 4997 | i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4998 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4999 | if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) { |
| 5000 | BNX2X_ERR("was only able to allocate " |
| 5001 | "%d rx sges\n", i); |
| 5002 | BNX2X_ERR("disabling TPA for queue[%d]\n", j); |
| 5003 | /* Cleanup already allocated elements */ |
| 5004 | bnx2x_free_rx_sge_range(bp, fp, ring_prod); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 5005 | bnx2x_free_tpa_pool(bp, fp, max_agg_queues); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5006 | fp->disable_tpa = 1; |
| 5007 | ring_prod = 0; |
| 5008 | break; |
| 5009 | } |
| 5010 | ring_prod = NEXT_SGE_IDX(ring_prod); |
| 5011 | } |
| 5012 | fp->rx_sge_prod = ring_prod; |
| 5013 | |
| 5014 | /* Allocate BDs and initialize BD ring */ |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5015 | fp->rx_comp_cons = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5016 | cqe_ring_prod = ring_prod = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5017 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 5018 | if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) { |
| 5019 | BNX2X_ERR("was only able to allocate " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5020 | "%d rx skbs on queue[%d]\n", i, j); |
| 5021 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | ring_prod = NEXT_RX_IDX(ring_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5025 | cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod); |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 5026 | WARN_ON(ring_prod <= i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5027 | } |
| 5028 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5029 | fp->rx_bd_prod = ring_prod; |
| 5030 | /* must not have more available CQEs than BDs */ |
| 5031 | fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT), |
| 5032 | cqe_ring_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5033 | fp->rx_pkt = fp->rx_calls = 0; |
| 5034 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5035 | /* Warning! |
| 5036 | * this will generate an interrupt (to the TSTORM) |
| 5037 | * must only be done after chip is initialized |
| 5038 | */ |
| 5039 | bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod, |
| 5040 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5041 | if (j != 0) |
| 5042 | continue; |
| 5043 | |
| 5044 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5045 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5046 | U64_LO(fp->rx_comp_mapping)); |
| 5047 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5048 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5049 | U64_HI(fp->rx_comp_mapping)); |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | static void bnx2x_init_tx_ring(struct bnx2x *bp) |
| 5054 | { |
| 5055 | int i, j; |
| 5056 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5057 | for_each_tx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5058 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 5059 | |
| 5060 | for (i = 1; i <= NUM_TX_RINGS; i++) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5061 | struct eth_tx_next_bd *tx_next_bd = |
| 5062 | &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5063 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5064 | tx_next_bd->addr_hi = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5065 | cpu_to_le32(U64_HI(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5066 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5067 | tx_next_bd->addr_lo = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5068 | cpu_to_le32(U64_LO(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5069 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5070 | } |
| 5071 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5072 | fp->tx_db.data.header.header = DOORBELL_HDR_DB_TYPE; |
| 5073 | fp->tx_db.data.zero_fill1 = 0; |
| 5074 | fp->tx_db.data.prod = 0; |
| 5075 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5076 | fp->tx_pkt_prod = 0; |
| 5077 | fp->tx_pkt_cons = 0; |
| 5078 | fp->tx_bd_prod = 0; |
| 5079 | fp->tx_bd_cons = 0; |
| 5080 | fp->tx_cons_sb = BNX2X_TX_SB_INDEX; |
| 5081 | fp->tx_pkt = 0; |
| 5082 | } |
Eilon Greenstein | 6fe49bb | 2009-08-12 08:23:17 +0000 | [diff] [blame] | 5083 | |
| 5084 | /* clean tx statistics */ |
| 5085 | for_each_rx_queue(bp, i) |
| 5086 | bnx2x_fp(bp, i, tx_pkt) = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
| 5090 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5091 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5092 | |
| 5093 | spin_lock_init(&bp->spq_lock); |
| 5094 | |
| 5095 | bp->spq_left = MAX_SPQ_PENDING; |
| 5096 | bp->spq_prod_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5097 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
| 5098 | bp->spq_prod_bd = bp->spq; |
| 5099 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; |
| 5100 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5101 | REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5102 | U64_LO(bp->spq_mapping)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5103 | REG_WR(bp, |
| 5104 | XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5105 | U64_HI(bp->spq_mapping)); |
| 5106 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5107 | REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5108 | bp->spq_prod_idx); |
| 5109 | } |
| 5110 | |
| 5111 | static void bnx2x_init_context(struct bnx2x *bp) |
| 5112 | { |
| 5113 | int i; |
| 5114 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5115 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5116 | struct eth_context *context = bnx2x_sp(bp, context[i].eth); |
| 5117 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5118 | u8 cl_id = fp->cl_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5119 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5120 | context->ustorm_st_context.common.sb_index_numbers = |
| 5121 | BNX2X_RX_SB_INDEX_NUM; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5122 | context->ustorm_st_context.common.clientId = cl_id; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5123 | context->ustorm_st_context.common.status_block_id = fp->sb_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5124 | context->ustorm_st_context.common.flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5125 | (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT | |
| 5126 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS); |
| 5127 | context->ustorm_st_context.common.statistics_counter_id = |
| 5128 | cl_id; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5129 | context->ustorm_st_context.common.mc_alignment_log_size = |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 5130 | BNX2X_RX_ALIGN_SHIFT; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5131 | context->ustorm_st_context.common.bd_buff_size = |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 5132 | bp->rx_buf_size; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5133 | context->ustorm_st_context.common.bd_page_base_hi = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5134 | U64_HI(fp->rx_desc_mapping); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5135 | context->ustorm_st_context.common.bd_page_base_lo = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5136 | U64_LO(fp->rx_desc_mapping); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5137 | if (!fp->disable_tpa) { |
| 5138 | context->ustorm_st_context.common.flags |= |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5139 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5140 | context->ustorm_st_context.common.sge_buff_size = |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5141 | (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE, |
| 5142 | (u32)0xffff); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5143 | context->ustorm_st_context.common.sge_page_base_hi = |
| 5144 | U64_HI(fp->rx_sge_mapping); |
| 5145 | context->ustorm_st_context.common.sge_page_base_lo = |
| 5146 | U64_LO(fp->rx_sge_mapping); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5147 | |
| 5148 | context->ustorm_st_context.common.max_sges_for_packet = |
| 5149 | SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT; |
| 5150 | context->ustorm_st_context.common.max_sges_for_packet = |
| 5151 | ((context->ustorm_st_context.common. |
| 5152 | max_sges_for_packet + PAGES_PER_SGE - 1) & |
| 5153 | (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5154 | } |
| 5155 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5156 | context->ustorm_ag_context.cdu_usage = |
| 5157 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 5158 | CDU_REGION_NUMBER_UCM_AG, |
| 5159 | ETH_CONNECTION_TYPE); |
| 5160 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5161 | context->xstorm_ag_context.cdu_reserved = |
| 5162 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 5163 | CDU_REGION_NUMBER_XCM_AG, |
| 5164 | ETH_CONNECTION_TYPE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5165 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5166 | |
| 5167 | for_each_tx_queue(bp, i) { |
| 5168 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5169 | struct eth_context *context = |
| 5170 | bnx2x_sp(bp, context[i - bp->num_rx_queues].eth); |
| 5171 | |
| 5172 | context->cstorm_st_context.sb_index_number = |
| 5173 | C_SB_ETH_TX_CQ_INDEX; |
| 5174 | context->cstorm_st_context.status_block_id = fp->sb_id; |
| 5175 | |
| 5176 | context->xstorm_st_context.tx_bd_page_base_hi = |
| 5177 | U64_HI(fp->tx_desc_mapping); |
| 5178 | context->xstorm_st_context.tx_bd_page_base_lo = |
| 5179 | U64_LO(fp->tx_desc_mapping); |
| 5180 | context->xstorm_st_context.statistics_data = (fp->cl_id | |
| 5181 | XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE); |
| 5182 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | static void bnx2x_init_ind_table(struct bnx2x *bp) |
| 5186 | { |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5187 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5188 | int i; |
| 5189 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5190 | if (bp->multi_mode == ETH_RSS_MODE_DISABLED) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5191 | return; |
| 5192 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5193 | DP(NETIF_MSG_IFUP, |
| 5194 | "Initializing indirection table multi_mode %d\n", bp->multi_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5195 | for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5196 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5197 | TSTORM_INDIRECTION_TABLE_OFFSET(func) + i, |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5198 | bp->fp->cl_id + (i % bp->num_rx_queues)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5199 | } |
| 5200 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5201 | static void bnx2x_set_client_config(struct bnx2x *bp) |
| 5202 | { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5203 | struct tstorm_eth_client_config tstorm_client = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5204 | int port = BP_PORT(bp); |
| 5205 | int i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5206 | |
Eilon Greenstein | e7799c5 | 2009-01-14 21:30:27 -0800 | [diff] [blame] | 5207 | tstorm_client.mtu = bp->dev->mtu; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5208 | tstorm_client.config_flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5209 | (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE | |
| 5210 | TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5211 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 5212 | if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5213 | tstorm_client.config_flags |= |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5214 | TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5215 | DP(NETIF_MSG_IFUP, "vlan removal enabled\n"); |
| 5216 | } |
| 5217 | #endif |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5218 | |
| 5219 | for_each_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5220 | tstorm_client.statistics_counter_id = bp->fp[i].cl_id; |
| 5221 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5222 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5223 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id), |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5224 | ((u32 *)&tstorm_client)[0]); |
| 5225 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5226 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4, |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5227 | ((u32 *)&tstorm_client)[1]); |
| 5228 | } |
| 5229 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5230 | DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n", |
| 5231 | ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5232 | } |
| 5233 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5234 | static void bnx2x_set_storm_rx_mode(struct bnx2x *bp) |
| 5235 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5236 | struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5237 | int mode = bp->rx_mode; |
| 5238 | int mask = (1 << BP_L_ID(bp)); |
| 5239 | int func = BP_FUNC(bp); |
Eilon Greenstein | 581ce43 | 2009-07-29 00:20:04 +0000 | [diff] [blame] | 5240 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5241 | int i; |
Eilon Greenstein | 581ce43 | 2009-07-29 00:20:04 +0000 | [diff] [blame] | 5242 | /* All but management unicast packets should pass to the host as well */ |
| 5243 | u32 llh_mask = |
| 5244 | NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_BRCST | |
| 5245 | NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_MLCST | |
| 5246 | NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_VLAN | |
| 5247 | NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_NO_VLAN; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5248 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5249 | DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5250 | |
| 5251 | switch (mode) { |
| 5252 | case BNX2X_RX_MODE_NONE: /* no Rx */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5253 | tstorm_mac_filter.ucast_drop_all = mask; |
| 5254 | tstorm_mac_filter.mcast_drop_all = mask; |
| 5255 | tstorm_mac_filter.bcast_drop_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5256 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 5257 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5258 | case BNX2X_RX_MODE_NORMAL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5259 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5260 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 5261 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5262 | case BNX2X_RX_MODE_ALLMULTI: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5263 | tstorm_mac_filter.mcast_accept_all = mask; |
| 5264 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5265 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 5266 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5267 | case BNX2X_RX_MODE_PROMISC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5268 | tstorm_mac_filter.ucast_accept_all = mask; |
| 5269 | tstorm_mac_filter.mcast_accept_all = mask; |
| 5270 | tstorm_mac_filter.bcast_accept_all = mask; |
Eilon Greenstein | 581ce43 | 2009-07-29 00:20:04 +0000 | [diff] [blame] | 5271 | /* pass management unicast packets as well */ |
| 5272 | llh_mask |= NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_UNCST; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5273 | break; |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 5274 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5275 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5276 | BNX2X_ERR("BAD rx mode (%d)\n", mode); |
| 5277 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5278 | } |
| 5279 | |
Eilon Greenstein | 581ce43 | 2009-07-29 00:20:04 +0000 | [diff] [blame] | 5280 | REG_WR(bp, |
| 5281 | (port ? NIG_REG_LLH1_BRB1_DRV_MASK : NIG_REG_LLH0_BRB1_DRV_MASK), |
| 5282 | llh_mask); |
| 5283 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5284 | for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) { |
| 5285 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5286 | TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5287 | ((u32 *)&tstorm_mac_filter)[i]); |
| 5288 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5289 | /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5290 | ((u32 *)&tstorm_mac_filter)[i]); */ |
| 5291 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5292 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 5293 | if (mode != BNX2X_RX_MODE_NONE) |
| 5294 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5295 | } |
| 5296 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5297 | static void bnx2x_init_internal_common(struct bnx2x *bp) |
| 5298 | { |
| 5299 | int i; |
| 5300 | |
| 5301 | /* Zero this manually as its initialization is |
| 5302 | currently missing in the initTool */ |
| 5303 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) |
| 5304 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 5305 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
| 5306 | } |
| 5307 | |
| 5308 | static void bnx2x_init_internal_port(struct bnx2x *bp) |
| 5309 | { |
| 5310 | int port = BP_PORT(bp); |
| 5311 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5312 | REG_WR(bp, |
| 5313 | BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_U_OFFSET(port), BNX2X_BTR); |
| 5314 | REG_WR(bp, |
| 5315 | BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_C_OFFSET(port), BNX2X_BTR); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5316 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 5317 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 5318 | } |
| 5319 | |
| 5320 | static void bnx2x_init_internal_func(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5321 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5322 | struct tstorm_eth_function_common_config tstorm_config = {0}; |
| 5323 | struct stats_indication_flags stats_flags = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5324 | int port = BP_PORT(bp); |
| 5325 | int func = BP_FUNC(bp); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5326 | int i, j; |
| 5327 | u32 offset; |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5328 | u16 max_agg_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5329 | |
| 5330 | if (is_multi(bp)) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5331 | tstorm_config.config_flags = MULTI_FLAGS(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5332 | tstorm_config.rss_result_mask = MULTI_MASK; |
| 5333 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5334 | |
| 5335 | /* Enable TPA if needed */ |
| 5336 | if (bp->flags & TPA_ENABLE_FLAG) |
| 5337 | tstorm_config.config_flags |= |
| 5338 | TSTORM_ETH_FUNCTION_COMMON_CONFIG_ENABLE_TPA; |
| 5339 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5340 | if (IS_E1HMF(bp)) |
| 5341 | tstorm_config.config_flags |= |
| 5342 | TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5343 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5344 | tstorm_config.leading_client_id = BP_L_ID(bp); |
| 5345 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5346 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5347 | TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5348 | (*(u32 *)&tstorm_config)); |
| 5349 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 5350 | bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5351 | bnx2x_set_storm_rx_mode(bp); |
| 5352 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5353 | for_each_queue(bp, i) { |
| 5354 | u8 cl_id = bp->fp[i].cl_id; |
| 5355 | |
| 5356 | /* reset xstorm per client statistics */ |
| 5357 | offset = BAR_XSTRORM_INTMEM + |
| 5358 | XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 5359 | for (j = 0; |
| 5360 | j < sizeof(struct xstorm_per_client_stats) / 4; j++) |
| 5361 | REG_WR(bp, offset + j*4, 0); |
| 5362 | |
| 5363 | /* reset tstorm per client statistics */ |
| 5364 | offset = BAR_TSTRORM_INTMEM + |
| 5365 | TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 5366 | for (j = 0; |
| 5367 | j < sizeof(struct tstorm_per_client_stats) / 4; j++) |
| 5368 | REG_WR(bp, offset + j*4, 0); |
| 5369 | |
| 5370 | /* reset ustorm per client statistics */ |
| 5371 | offset = BAR_USTRORM_INTMEM + |
| 5372 | USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 5373 | for (j = 0; |
| 5374 | j < sizeof(struct ustorm_per_client_stats) / 4; j++) |
| 5375 | REG_WR(bp, offset + j*4, 0); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | /* Init statistics related context */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5379 | stats_flags.collect_eth = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5380 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5381 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5382 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5383 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5384 | ((u32 *)&stats_flags)[1]); |
| 5385 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5386 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5387 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5388 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5389 | ((u32 *)&stats_flags)[1]); |
| 5390 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5391 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func), |
| 5392 | ((u32 *)&stats_flags)[0]); |
| 5393 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4, |
| 5394 | ((u32 *)&stats_flags)[1]); |
| 5395 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5396 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5397 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5398 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5399 | ((u32 *)&stats_flags)[1]); |
| 5400 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 5401 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 5402 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 5403 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 5404 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 5405 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 5406 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 5407 | |
| 5408 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 5409 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 5410 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 5411 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 5412 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 5413 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5414 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 5415 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 5416 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 5417 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 5418 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 5419 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 5420 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 5421 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5422 | if (CHIP_IS_E1H(bp)) { |
| 5423 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET, |
| 5424 | IS_E1HMF(bp)); |
| 5425 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET, |
| 5426 | IS_E1HMF(bp)); |
| 5427 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET, |
| 5428 | IS_E1HMF(bp)); |
| 5429 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET, |
| 5430 | IS_E1HMF(bp)); |
| 5431 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5432 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func), |
| 5433 | bp->e1hov); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 5436 | /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */ |
| 5437 | max_agg_size = |
| 5438 | min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) * |
| 5439 | SGE_PAGE_SIZE * PAGES_PER_SGE), |
| 5440 | (u32)0xffff); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 5441 | for_each_rx_queue(bp, i) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5442 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5443 | |
| 5444 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5445 | USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5446 | U64_LO(fp->rx_comp_mapping)); |
| 5447 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5448 | USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5449 | U64_HI(fp->rx_comp_mapping)); |
| 5450 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5451 | /* Next page */ |
| 5452 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 5453 | USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id), |
| 5454 | U64_LO(fp->rx_comp_mapping + BCM_PAGE_SIZE)); |
| 5455 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 5456 | USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id) + 4, |
| 5457 | U64_HI(fp->rx_comp_mapping + BCM_PAGE_SIZE)); |
| 5458 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5459 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5460 | USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 5461 | max_agg_size); |
| 5462 | } |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 5463 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5464 | /* dropless flow control */ |
| 5465 | if (CHIP_IS_E1H(bp)) { |
| 5466 | struct ustorm_eth_rx_pause_data_e1h rx_pause = {0}; |
| 5467 | |
| 5468 | rx_pause.bd_thr_low = 250; |
| 5469 | rx_pause.cqe_thr_low = 250; |
| 5470 | rx_pause.cos = 1; |
| 5471 | rx_pause.sge_thr_low = 0; |
| 5472 | rx_pause.bd_thr_high = 350; |
| 5473 | rx_pause.cqe_thr_high = 350; |
| 5474 | rx_pause.sge_thr_high = 0; |
| 5475 | |
| 5476 | for_each_rx_queue(bp, i) { |
| 5477 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5478 | |
| 5479 | if (!fp->disable_tpa) { |
| 5480 | rx_pause.sge_thr_low = 150; |
| 5481 | rx_pause.sge_thr_high = 250; |
| 5482 | } |
| 5483 | |
| 5484 | |
| 5485 | offset = BAR_USTRORM_INTMEM + |
| 5486 | USTORM_ETH_RING_PAUSE_DATA_OFFSET(port, |
| 5487 | fp->cl_id); |
| 5488 | for (j = 0; |
| 5489 | j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4; |
| 5490 | j++) |
| 5491 | REG_WR(bp, offset + j*4, |
| 5492 | ((u32 *)&rx_pause)[j]); |
| 5493 | } |
| 5494 | } |
| 5495 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 5496 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); |
| 5497 | |
| 5498 | /* Init rate shaping and fairness contexts */ |
| 5499 | if (IS_E1HMF(bp)) { |
| 5500 | int vn; |
| 5501 | |
| 5502 | /* During init there is no active link |
| 5503 | Until link is up, set link rate to 10Gbps */ |
| 5504 | bp->link_vars.line_speed = SPEED_10000; |
| 5505 | bnx2x_init_port_minmax(bp); |
| 5506 | |
| 5507 | bnx2x_calc_vn_weight_sum(bp); |
| 5508 | |
| 5509 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
| 5510 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 5511 | |
| 5512 | /* Enable rate shaping and fairness */ |
| 5513 | bp->cmng.flags.cmng_enables = |
| 5514 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
| 5515 | if (bp->vn_weight_sum) |
| 5516 | bp->cmng.flags.cmng_enables |= |
| 5517 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
| 5518 | else |
| 5519 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" |
| 5520 | " fairness will be disabled\n"); |
| 5521 | } else { |
| 5522 | /* rate shaping and fairness are disabled */ |
| 5523 | DP(NETIF_MSG_IFUP, |
| 5524 | "single function mode minmax will be disabled\n"); |
| 5525 | } |
| 5526 | |
| 5527 | |
| 5528 | /* Store it to internal memory */ |
| 5529 | if (bp->port.pmf) |
| 5530 | for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 5531 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 5532 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4, |
| 5533 | ((u32 *)(&bp->cmng))[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5534 | } |
| 5535 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5536 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
| 5537 | { |
| 5538 | switch (load_code) { |
| 5539 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 5540 | bnx2x_init_internal_common(bp); |
| 5541 | /* no break */ |
| 5542 | |
| 5543 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 5544 | bnx2x_init_internal_port(bp); |
| 5545 | /* no break */ |
| 5546 | |
| 5547 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 5548 | bnx2x_init_internal_func(bp); |
| 5549 | break; |
| 5550 | |
| 5551 | default: |
| 5552 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 5553 | break; |
| 5554 | } |
| 5555 | } |
| 5556 | |
| 5557 | static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5558 | { |
| 5559 | int i; |
| 5560 | |
| 5561 | for_each_queue(bp, i) { |
| 5562 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5563 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5564 | fp->bp = bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5565 | fp->state = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5566 | fp->index = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5567 | fp->cl_id = BP_L_ID(bp) + i; |
| 5568 | fp->sb_id = fp->cl_id; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 5569 | /* Suitable Rx and Tx SBs are served by the same client */ |
| 5570 | if (i >= bp->num_rx_queues) |
| 5571 | fp->cl_id -= bp->num_rx_queues; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5572 | DP(NETIF_MSG_IFUP, |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 5573 | "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n", |
| 5574 | i, bp, fp->status_blk, fp->cl_id, fp->sb_id); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5575 | bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping, |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 5576 | fp->sb_id); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5577 | bnx2x_update_fpsb_idx(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5578 | } |
| 5579 | |
Eilon Greenstein | 1611978 | 2009-03-02 07:59:27 +0000 | [diff] [blame] | 5580 | /* ensure status block indices were read */ |
| 5581 | rmb(); |
| 5582 | |
| 5583 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5584 | bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping, |
| 5585 | DEF_SB_ID); |
| 5586 | bnx2x_update_dsb_idx(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5587 | bnx2x_update_coalesce(bp); |
| 5588 | bnx2x_init_rx_rings(bp); |
| 5589 | bnx2x_init_tx_ring(bp); |
| 5590 | bnx2x_init_sp_ring(bp); |
| 5591 | bnx2x_init_context(bp); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5592 | bnx2x_init_internal(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5593 | bnx2x_init_ind_table(bp); |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5594 | bnx2x_stats_init(bp); |
| 5595 | |
| 5596 | /* At this point, we are ready for interrupts */ |
| 5597 | atomic_set(&bp->intr_sem, 0); |
| 5598 | |
| 5599 | /* flush all before enabling interrupts */ |
| 5600 | mb(); |
| 5601 | mmiowb(); |
| 5602 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 5603 | bnx2x_int_enable(bp); |
Eilon Greenstein | eb8da20 | 2009-07-21 05:47:30 +0000 | [diff] [blame] | 5604 | |
| 5605 | /* Check for SPIO5 */ |
| 5606 | bnx2x_attn_int_deasserted0(bp, |
| 5607 | REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) & |
| 5608 | AEU_INPUTS_ATTN_BITS_SPIO5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | /* end of nic init */ |
| 5612 | |
| 5613 | /* |
| 5614 | * gzip service functions |
| 5615 | */ |
| 5616 | |
| 5617 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
| 5618 | { |
| 5619 | bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE, |
| 5620 | &bp->gunzip_mapping); |
| 5621 | if (bp->gunzip_buf == NULL) |
| 5622 | goto gunzip_nomem1; |
| 5623 | |
| 5624 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); |
| 5625 | if (bp->strm == NULL) |
| 5626 | goto gunzip_nomem2; |
| 5627 | |
| 5628 | bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), |
| 5629 | GFP_KERNEL); |
| 5630 | if (bp->strm->workspace == NULL) |
| 5631 | goto gunzip_nomem3; |
| 5632 | |
| 5633 | return 0; |
| 5634 | |
| 5635 | gunzip_nomem3: |
| 5636 | kfree(bp->strm); |
| 5637 | bp->strm = NULL; |
| 5638 | |
| 5639 | gunzip_nomem2: |
| 5640 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5641 | bp->gunzip_mapping); |
| 5642 | bp->gunzip_buf = NULL; |
| 5643 | |
| 5644 | gunzip_nomem1: |
| 5645 | printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5646 | " un-compression\n", bp->dev->name); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5647 | return -ENOMEM; |
| 5648 | } |
| 5649 | |
| 5650 | static void bnx2x_gunzip_end(struct bnx2x *bp) |
| 5651 | { |
| 5652 | kfree(bp->strm->workspace); |
| 5653 | |
| 5654 | kfree(bp->strm); |
| 5655 | bp->strm = NULL; |
| 5656 | |
| 5657 | if (bp->gunzip_buf) { |
| 5658 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5659 | bp->gunzip_mapping); |
| 5660 | bp->gunzip_buf = NULL; |
| 5661 | } |
| 5662 | } |
| 5663 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5664 | static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5665 | { |
| 5666 | int n, rc; |
| 5667 | |
| 5668 | /* check gzip header */ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5669 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) { |
| 5670 | BNX2X_ERR("Bad gzip header\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5671 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5672 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5673 | |
| 5674 | n = 10; |
| 5675 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5676 | #define FNAME 0x8 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5677 | |
| 5678 | if (zbuf[3] & FNAME) |
| 5679 | while ((zbuf[n++] != 0) && (n < len)); |
| 5680 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5681 | bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5682 | bp->strm->avail_in = len - n; |
| 5683 | bp->strm->next_out = bp->gunzip_buf; |
| 5684 | bp->strm->avail_out = FW_BUF_SIZE; |
| 5685 | |
| 5686 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); |
| 5687 | if (rc != Z_OK) |
| 5688 | return rc; |
| 5689 | |
| 5690 | rc = zlib_inflate(bp->strm, Z_FINISH); |
| 5691 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) |
| 5692 | printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n", |
| 5693 | bp->dev->name, bp->strm->msg); |
| 5694 | |
| 5695 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); |
| 5696 | if (bp->gunzip_outlen & 0x3) |
| 5697 | printk(KERN_ERR PFX "%s: Firmware decompression error:" |
| 5698 | " gunzip_outlen (%d) not aligned\n", |
| 5699 | bp->dev->name, bp->gunzip_outlen); |
| 5700 | bp->gunzip_outlen >>= 2; |
| 5701 | |
| 5702 | zlib_inflateEnd(bp->strm); |
| 5703 | |
| 5704 | if (rc == Z_STREAM_END) |
| 5705 | return 0; |
| 5706 | |
| 5707 | return rc; |
| 5708 | } |
| 5709 | |
| 5710 | /* nic load/unload */ |
| 5711 | |
| 5712 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5713 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5714 | */ |
| 5715 | |
| 5716 | /* send a NIG loopback debug packet */ |
| 5717 | static void bnx2x_lb_pckt(struct bnx2x *bp) |
| 5718 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5719 | u32 wb_write[3]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5720 | |
| 5721 | /* Ethernet source and destination addresses */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5722 | wb_write[0] = 0x55555555; |
| 5723 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5724 | wb_write[2] = 0x20; /* SOP */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5725 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5726 | |
| 5727 | /* NON-IP protocol */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5728 | wb_write[0] = 0x09000000; |
| 5729 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5730 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5731 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | /* some of the internal memories |
| 5735 | * are not directly readable from the driver |
| 5736 | * to test them we send debug packets |
| 5737 | */ |
| 5738 | static int bnx2x_int_mem_test(struct bnx2x *bp) |
| 5739 | { |
| 5740 | int factor; |
| 5741 | int count, i; |
| 5742 | u32 val = 0; |
| 5743 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5744 | if (CHIP_REV_IS_FPGA(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5745 | factor = 120; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5746 | else if (CHIP_REV_IS_EMUL(bp)) |
| 5747 | factor = 200; |
| 5748 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5749 | factor = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5750 | |
| 5751 | DP(NETIF_MSG_HW, "start part1\n"); |
| 5752 | |
| 5753 | /* Disable inputs of parser neighbor blocks */ |
| 5754 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5755 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5756 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5757 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5758 | |
| 5759 | /* Write 0 to parser credits for CFC search request */ |
| 5760 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5761 | |
| 5762 | /* send Ethernet packet */ |
| 5763 | bnx2x_lb_pckt(bp); |
| 5764 | |
| 5765 | /* TODO do i reset NIG statistic? */ |
| 5766 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5767 | count = 1000 * factor; |
| 5768 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5769 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5770 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5771 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5772 | if (val == 0x10) |
| 5773 | break; |
| 5774 | |
| 5775 | msleep(10); |
| 5776 | count--; |
| 5777 | } |
| 5778 | if (val != 0x10) { |
| 5779 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5780 | return -1; |
| 5781 | } |
| 5782 | |
| 5783 | /* Wait until PRS register shows 1 packet */ |
| 5784 | count = 1000 * factor; |
| 5785 | while (count) { |
| 5786 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5787 | if (val == 1) |
| 5788 | break; |
| 5789 | |
| 5790 | msleep(10); |
| 5791 | count--; |
| 5792 | } |
| 5793 | if (val != 0x1) { |
| 5794 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5795 | return -2; |
| 5796 | } |
| 5797 | |
| 5798 | /* Reset and init BRB, PRS */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5799 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5800 | msleep(50); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5801 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5802 | msleep(50); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5803 | bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE); |
| 5804 | bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5805 | |
| 5806 | DP(NETIF_MSG_HW, "part2\n"); |
| 5807 | |
| 5808 | /* Disable inputs of parser neighbor blocks */ |
| 5809 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5810 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5811 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5812 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5813 | |
| 5814 | /* Write 0 to parser credits for CFC search request */ |
| 5815 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5816 | |
| 5817 | /* send 10 Ethernet packets */ |
| 5818 | for (i = 0; i < 10; i++) |
| 5819 | bnx2x_lb_pckt(bp); |
| 5820 | |
| 5821 | /* Wait until NIG register shows 10 + 1 |
| 5822 | packets of size 11*0x10 = 0xb0 */ |
| 5823 | count = 1000 * factor; |
| 5824 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5825 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5826 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5827 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5828 | if (val == 0xb0) |
| 5829 | break; |
| 5830 | |
| 5831 | msleep(10); |
| 5832 | count--; |
| 5833 | } |
| 5834 | if (val != 0xb0) { |
| 5835 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5836 | return -3; |
| 5837 | } |
| 5838 | |
| 5839 | /* Wait until PRS register shows 2 packets */ |
| 5840 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5841 | if (val != 2) |
| 5842 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5843 | |
| 5844 | /* Write 1 to parser credits for CFC search request */ |
| 5845 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); |
| 5846 | |
| 5847 | /* Wait until PRS register shows 3 packets */ |
| 5848 | msleep(10 * factor); |
| 5849 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5850 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5851 | if (val != 3) |
| 5852 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5853 | |
| 5854 | /* clear NIG EOP FIFO */ |
| 5855 | for (i = 0; i < 11; i++) |
| 5856 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); |
| 5857 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); |
| 5858 | if (val != 1) { |
| 5859 | BNX2X_ERR("clear of NIG failed\n"); |
| 5860 | return -4; |
| 5861 | } |
| 5862 | |
| 5863 | /* Reset and init BRB, PRS, NIG */ |
| 5864 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
| 5865 | msleep(50); |
| 5866 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
| 5867 | msleep(50); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 5868 | bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE); |
| 5869 | bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5870 | #ifndef BCM_ISCSI |
| 5871 | /* set NIC mode */ |
| 5872 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 5873 | #endif |
| 5874 | |
| 5875 | /* Enable inputs of parser neighbor blocks */ |
| 5876 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); |
| 5877 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); |
| 5878 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5879 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5880 | |
| 5881 | DP(NETIF_MSG_HW, "done\n"); |
| 5882 | |
| 5883 | return 0; /* OK */ |
| 5884 | } |
| 5885 | |
| 5886 | static void enable_blocks_attention(struct bnx2x *bp) |
| 5887 | { |
| 5888 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
| 5889 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); |
| 5890 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5891 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5892 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
| 5893 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); |
| 5894 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); |
| 5895 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); |
| 5896 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5897 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
| 5898 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5899 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
| 5900 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); |
| 5901 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5902 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
| 5903 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5904 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
| 5905 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); |
| 5906 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); |
| 5907 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5908 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
| 5909 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ |
| 5910 | if (CHIP_REV_IS_FPGA(bp)) |
| 5911 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); |
| 5912 | else |
| 5913 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5914 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
| 5915 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); |
| 5916 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5917 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
| 5918 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5919 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
| 5920 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5921 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
| 5922 | 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] | 5923 | } |
| 5924 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5925 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5926 | static void bnx2x_reset_common(struct bnx2x *bp) |
| 5927 | { |
| 5928 | /* reset_common */ |
| 5929 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5930 | 0xd3ffff7f); |
| 5931 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403); |
| 5932 | } |
| 5933 | |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 5934 | static void bnx2x_init_pxp(struct bnx2x *bp) |
| 5935 | { |
| 5936 | u16 devctl; |
| 5937 | int r_order, w_order; |
| 5938 | |
| 5939 | pci_read_config_word(bp->pdev, |
| 5940 | bp->pcie_cap + PCI_EXP_DEVCTL, &devctl); |
| 5941 | DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl); |
| 5942 | w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); |
| 5943 | if (bp->mrrs == -1) |
| 5944 | r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12); |
| 5945 | else { |
| 5946 | DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs); |
| 5947 | r_order = bp->mrrs; |
| 5948 | } |
| 5949 | |
| 5950 | bnx2x_init_pxp_arb(bp, r_order, w_order); |
| 5951 | } |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5952 | |
| 5953 | static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp) |
| 5954 | { |
| 5955 | u32 val; |
| 5956 | u8 port; |
| 5957 | u8 is_required = 0; |
| 5958 | |
| 5959 | val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) & |
| 5960 | SHARED_HW_CFG_FAN_FAILURE_MASK; |
| 5961 | |
| 5962 | if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) |
| 5963 | is_required = 1; |
| 5964 | |
| 5965 | /* |
| 5966 | * The fan failure mechanism is usually related to the PHY type since |
| 5967 | * the power consumption of the board is affected by the PHY. Currently, |
| 5968 | * fan is required for most designs with SFX7101, BCM8727 and BCM8481. |
| 5969 | */ |
| 5970 | else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) |
| 5971 | for (port = PORT_0; port < PORT_MAX; port++) { |
| 5972 | u32 phy_type = |
| 5973 | SHMEM_RD(bp, dev_info.port_hw_config[port]. |
| 5974 | external_phy_config) & |
| 5975 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
| 5976 | is_required |= |
| 5977 | ((phy_type == |
| 5978 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) || |
| 5979 | (phy_type == |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 5980 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) || |
| 5981 | (phy_type == |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 5982 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481)); |
| 5983 | } |
| 5984 | |
| 5985 | DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required); |
| 5986 | |
| 5987 | if (is_required == 0) |
| 5988 | return; |
| 5989 | |
| 5990 | /* Fan failure is indicated by SPIO 5 */ |
| 5991 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, |
| 5992 | MISC_REGISTERS_SPIO_INPUT_HI_Z); |
| 5993 | |
| 5994 | /* set to active low mode */ |
| 5995 | val = REG_RD(bp, MISC_REG_SPIO_INT); |
| 5996 | val |= ((1 << MISC_REGISTERS_SPIO_5) << |
| 5997 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
| 5998 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
| 5999 | |
| 6000 | /* enable interrupt to signal the IGU */ |
| 6001 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 6002 | val |= (1 << MISC_REGISTERS_SPIO_5); |
| 6003 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
| 6004 | } |
| 6005 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6006 | static int bnx2x_init_common(struct bnx2x *bp) |
| 6007 | { |
| 6008 | u32 val, i; |
| 6009 | |
| 6010 | DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp)); |
| 6011 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 6012 | bnx2x_reset_common(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6013 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
| 6014 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc); |
| 6015 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6016 | bnx2x_init_block(bp, MISC_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6017 | if (CHIP_IS_E1H(bp)) |
| 6018 | REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp)); |
| 6019 | |
| 6020 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100); |
| 6021 | msleep(30); |
| 6022 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0); |
| 6023 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6024 | bnx2x_init_block(bp, PXP_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6025 | if (CHIP_IS_E1(bp)) { |
| 6026 | /* enable HW interrupt from PXP on USDM overflow |
| 6027 | bit 16 on INT_MASK_0 */ |
| 6028 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6029 | } |
| 6030 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6031 | bnx2x_init_block(bp, PXP2_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6032 | bnx2x_init_pxp(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6033 | |
| 6034 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6035 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
| 6036 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); |
| 6037 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); |
| 6038 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); |
| 6039 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6040 | /* make sure this value is 0 */ |
| 6041 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6042 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6043 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ |
| 6044 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); |
| 6045 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); |
| 6046 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); |
| 6047 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6048 | #endif |
| 6049 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6050 | REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6051 | #ifdef BCM_ISCSI |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6052 | REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5); |
| 6053 | REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5); |
| 6054 | REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6055 | #endif |
| 6056 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6057 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
| 6058 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6059 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6060 | /* let the HW do it's magic ... */ |
| 6061 | msleep(100); |
| 6062 | /* finish PXP init */ |
| 6063 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); |
| 6064 | if (val != 1) { |
| 6065 | BNX2X_ERR("PXP2 CFG failed\n"); |
| 6066 | return -EBUSY; |
| 6067 | } |
| 6068 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); |
| 6069 | if (val != 1) { |
| 6070 | BNX2X_ERR("PXP2 RD_INIT failed\n"); |
| 6071 | return -EBUSY; |
| 6072 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6073 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6074 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
| 6075 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6076 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6077 | bnx2x_init_block(bp, DMAE_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6078 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6079 | /* clean the DMAE memory */ |
| 6080 | bp->dmae_ready = 1; |
| 6081 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6082 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6083 | bnx2x_init_block(bp, TCM_BLOCK, COMMON_STAGE); |
| 6084 | bnx2x_init_block(bp, UCM_BLOCK, COMMON_STAGE); |
| 6085 | bnx2x_init_block(bp, CCM_BLOCK, COMMON_STAGE); |
| 6086 | bnx2x_init_block(bp, XCM_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6087 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6088 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
| 6089 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); |
| 6090 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); |
| 6091 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); |
| 6092 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6093 | bnx2x_init_block(bp, QM_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6094 | /* soft reset pulse */ |
| 6095 | REG_WR(bp, QM_REG_SOFT_RESET, 1); |
| 6096 | REG_WR(bp, QM_REG_SOFT_RESET, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6097 | |
| 6098 | #ifdef BCM_ISCSI |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6099 | bnx2x_init_block(bp, TIMERS_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6100 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6101 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6102 | bnx2x_init_block(bp, DQ_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6103 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT); |
| 6104 | if (!CHIP_REV_IS_SLOW(bp)) { |
| 6105 | /* enable hw interrupt from doorbell Q */ |
| 6106 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 6107 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6108 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6109 | bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE); |
| 6110 | bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 6111 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 6112 | /* set NIC mode */ |
| 6113 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6114 | if (CHIP_IS_E1H(bp)) |
| 6115 | REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6116 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6117 | bnx2x_init_block(bp, TSDM_BLOCK, COMMON_STAGE); |
| 6118 | bnx2x_init_block(bp, CSDM_BLOCK, COMMON_STAGE); |
| 6119 | bnx2x_init_block(bp, USDM_BLOCK, COMMON_STAGE); |
| 6120 | bnx2x_init_block(bp, XSDM_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6121 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6122 | bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp)); |
| 6123 | bnx2x_init_fill(bp, USEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp)); |
| 6124 | bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp)); |
| 6125 | bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6126 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6127 | bnx2x_init_block(bp, TSEM_BLOCK, COMMON_STAGE); |
| 6128 | bnx2x_init_block(bp, USEM_BLOCK, COMMON_STAGE); |
| 6129 | bnx2x_init_block(bp, CSEM_BLOCK, COMMON_STAGE); |
| 6130 | bnx2x_init_block(bp, XSEM_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6131 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6132 | /* sync semi rtc */ |
| 6133 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 6134 | 0x80000000); |
| 6135 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 6136 | 0x80000000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6137 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6138 | bnx2x_init_block(bp, UPB_BLOCK, COMMON_STAGE); |
| 6139 | bnx2x_init_block(bp, XPB_BLOCK, COMMON_STAGE); |
| 6140 | bnx2x_init_block(bp, PBF_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6141 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6142 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
| 6143 | for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) { |
| 6144 | REG_WR(bp, i, 0xc0cac01a); |
| 6145 | /* TODO: replace with something meaningful */ |
| 6146 | } |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6147 | bnx2x_init_block(bp, SRCH_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6148 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6149 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6150 | if (sizeof(union cdu_context) != 1024) |
| 6151 | /* we currently assume that a context is 1024 bytes */ |
| 6152 | printk(KERN_ALERT PFX "please adjust the size of" |
| 6153 | " cdu_context(%ld)\n", (long)sizeof(union cdu_context)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6154 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6155 | bnx2x_init_block(bp, CDU_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6156 | val = (4 << 24) + (0 << 12) + 1024; |
| 6157 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6158 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6159 | bnx2x_init_block(bp, CFC_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6160 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 6161 | /* enable context validation interrupt from CFC */ |
| 6162 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 6163 | |
| 6164 | /* set the thresholds to prevent CFC/CDU race */ |
| 6165 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6166 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6167 | bnx2x_init_block(bp, HC_BLOCK, COMMON_STAGE); |
| 6168 | bnx2x_init_block(bp, MISC_AEU_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6169 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6170 | bnx2x_init_block(bp, PXPCS_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6171 | /* Reset PCIE errors for debug */ |
| 6172 | REG_WR(bp, 0x2814, 0xffffffff); |
| 6173 | REG_WR(bp, 0x3820, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6174 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6175 | bnx2x_init_block(bp, EMAC0_BLOCK, COMMON_STAGE); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6176 | bnx2x_init_block(bp, EMAC1_BLOCK, COMMON_STAGE); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6177 | bnx2x_init_block(bp, DBU_BLOCK, COMMON_STAGE); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6178 | bnx2x_init_block(bp, DBG_BLOCK, COMMON_STAGE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6179 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6180 | bnx2x_init_block(bp, NIG_BLOCK, COMMON_STAGE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6181 | if (CHIP_IS_E1H(bp)) { |
| 6182 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp)); |
| 6183 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp)); |
| 6184 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6185 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6186 | if (CHIP_REV_IS_SLOW(bp)) |
| 6187 | msleep(200); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6188 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6189 | /* finish CFC init */ |
| 6190 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); |
| 6191 | if (val != 1) { |
| 6192 | BNX2X_ERR("CFC LL_INIT failed\n"); |
| 6193 | return -EBUSY; |
| 6194 | } |
| 6195 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); |
| 6196 | if (val != 1) { |
| 6197 | BNX2X_ERR("CFC AC_INIT failed\n"); |
| 6198 | return -EBUSY; |
| 6199 | } |
| 6200 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); |
| 6201 | if (val != 1) { |
| 6202 | BNX2X_ERR("CFC CAM_INIT failed\n"); |
| 6203 | return -EBUSY; |
| 6204 | } |
| 6205 | REG_WR(bp, CFC_REG_DEBUG0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6206 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6207 | /* read NIG statistic |
| 6208 | to see if this is our first up since powerup */ |
| 6209 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 6210 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6211 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6212 | /* do internal memory self test */ |
| 6213 | if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) { |
| 6214 | BNX2X_ERR("internal mem self test failed\n"); |
| 6215 | return -EBUSY; |
| 6216 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6217 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 6218 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 6219 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
| 6220 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
| 6221 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6222 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727: |
Eilon Greenstein | 46c6a67 | 2009-02-12 08:36:58 +0000 | [diff] [blame] | 6223 | bp->port.need_hw_lock = 1; |
| 6224 | break; |
| 6225 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6226 | default: |
| 6227 | break; |
| 6228 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6229 | |
Eilon Greenstein | fd4ef40 | 2009-07-21 05:47:27 +0000 | [diff] [blame] | 6230 | bnx2x_setup_fan_failure_detection(bp); |
| 6231 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6232 | /* clear PXP2 attentions */ |
| 6233 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6234 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6235 | enable_blocks_attention(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6236 | |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 6237 | if (!BP_NOMCP(bp)) { |
| 6238 | bnx2x_acquire_phy_lock(bp); |
| 6239 | bnx2x_common_init_phy(bp, bp->common.shmem_base); |
| 6240 | bnx2x_release_phy_lock(bp); |
| 6241 | } else |
| 6242 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
| 6243 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6244 | return 0; |
| 6245 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6246 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6247 | static int bnx2x_init_port(struct bnx2x *bp) |
| 6248 | { |
| 6249 | int port = BP_PORT(bp); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6250 | int init_stage = port ? PORT1_STAGE : PORT0_STAGE; |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6251 | u32 low, high; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6252 | u32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6253 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6254 | DP(BNX2X_MSG_MCP, "starting port init port %x\n", port); |
| 6255 | |
| 6256 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6257 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6258 | bnx2x_init_block(bp, PXP_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6259 | bnx2x_init_block(bp, PXP2_BLOCK, init_stage); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6260 | |
| 6261 | bnx2x_init_block(bp, TCM_BLOCK, init_stage); |
| 6262 | bnx2x_init_block(bp, UCM_BLOCK, init_stage); |
| 6263 | bnx2x_init_block(bp, CCM_BLOCK, init_stage); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6264 | #ifdef BCM_ISCSI |
| 6265 | /* Port0 1 |
| 6266 | * Port1 385 */ |
| 6267 | i++; |
| 6268 | wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping); |
| 6269 | wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping); |
| 6270 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 6271 | REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 6272 | |
| 6273 | /* Port0 2 |
| 6274 | * Port1 386 */ |
| 6275 | i++; |
| 6276 | wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping); |
| 6277 | wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping); |
| 6278 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 6279 | REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 6280 | |
| 6281 | /* Port0 3 |
| 6282 | * Port1 387 */ |
| 6283 | i++; |
| 6284 | wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping); |
| 6285 | wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping); |
| 6286 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 6287 | REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i)); |
| 6288 | #endif |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6289 | bnx2x_init_block(bp, XCM_BLOCK, init_stage); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6290 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6291 | #ifdef BCM_ISCSI |
| 6292 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20); |
| 6293 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31); |
| 6294 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6295 | bnx2x_init_block(bp, TIMERS_BLOCK, init_stage); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6296 | #endif |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6297 | bnx2x_init_block(bp, DQ_BLOCK, init_stage); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6298 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6299 | bnx2x_init_block(bp, BRB1_BLOCK, init_stage); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6300 | if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) { |
| 6301 | /* no pause for emulation and FPGA */ |
| 6302 | low = 0; |
| 6303 | high = 513; |
| 6304 | } else { |
| 6305 | if (IS_E1HMF(bp)) |
| 6306 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); |
| 6307 | else if (bp->dev->mtu > 4096) { |
| 6308 | if (bp->flags & ONE_PORT_FLAG) |
| 6309 | low = 160; |
| 6310 | else { |
| 6311 | val = bp->dev->mtu; |
| 6312 | /* (24*1024 + val*4)/256 */ |
| 6313 | low = 96 + (val/64) + ((val % 64) ? 1 : 0); |
| 6314 | } |
| 6315 | } else |
| 6316 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); |
| 6317 | high = low + 56; /* 14*1024/256 */ |
| 6318 | } |
| 6319 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
| 6320 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); |
| 6321 | |
| 6322 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6323 | bnx2x_init_block(bp, PRS_BLOCK, init_stage); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6324 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6325 | bnx2x_init_block(bp, TSDM_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6326 | bnx2x_init_block(bp, CSDM_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6327 | bnx2x_init_block(bp, USDM_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6328 | bnx2x_init_block(bp, XSDM_BLOCK, init_stage); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6329 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6330 | bnx2x_init_block(bp, TSEM_BLOCK, init_stage); |
| 6331 | bnx2x_init_block(bp, USEM_BLOCK, init_stage); |
| 6332 | bnx2x_init_block(bp, CSEM_BLOCK, init_stage); |
| 6333 | bnx2x_init_block(bp, XSEM_BLOCK, init_stage); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6334 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6335 | bnx2x_init_block(bp, UPB_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6336 | bnx2x_init_block(bp, XPB_BLOCK, init_stage); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6337 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6338 | bnx2x_init_block(bp, PBF_BLOCK, init_stage); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6339 | |
| 6340 | /* configure PBF to work without PAUSE mtu 9000 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6341 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6342 | |
| 6343 | /* update threshold */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6344 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6345 | /* update init credit */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6346 | 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] | 6347 | |
| 6348 | /* probe changes */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6349 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6350 | msleep(5); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6351 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6352 | |
| 6353 | #ifdef BCM_ISCSI |
| 6354 | /* tell the searcher where the T2 table is */ |
| 6355 | REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64); |
| 6356 | |
| 6357 | wb_write[0] = U64_LO(bp->t2_mapping); |
| 6358 | wb_write[1] = U64_HI(bp->t2_mapping); |
| 6359 | REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2); |
| 6360 | wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64); |
| 6361 | wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64); |
| 6362 | REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2); |
| 6363 | |
| 6364 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6365 | #endif |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6366 | bnx2x_init_block(bp, CDU_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6367 | bnx2x_init_block(bp, CFC_BLOCK, init_stage); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6368 | |
| 6369 | if (CHIP_IS_E1(bp)) { |
| 6370 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6371 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6372 | } |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6373 | bnx2x_init_block(bp, HC_BLOCK, init_stage); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6374 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6375 | bnx2x_init_block(bp, MISC_AEU_BLOCK, init_stage); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6376 | /* init aeu_mask_attn_func_0/1: |
| 6377 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use |
| 6378 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF |
| 6379 | * bits 4-7 are used for "per vn group attention" */ |
| 6380 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, |
| 6381 | (IS_E1HMF(bp) ? 0xF7 : 0x7)); |
| 6382 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6383 | bnx2x_init_block(bp, PXPCS_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6384 | bnx2x_init_block(bp, EMAC0_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6385 | bnx2x_init_block(bp, EMAC1_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6386 | bnx2x_init_block(bp, DBU_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6387 | bnx2x_init_block(bp, DBG_BLOCK, init_stage); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6388 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6389 | bnx2x_init_block(bp, NIG_BLOCK, init_stage); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6390 | |
| 6391 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); |
| 6392 | |
| 6393 | if (CHIP_IS_E1H(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6394 | /* 0x2 disable e1hov, 0x1 enable */ |
| 6395 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
| 6396 | (IS_E1HMF(bp) ? 0x1 : 0x2)); |
| 6397 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 6398 | { |
| 6399 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); |
| 6400 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); |
| 6401 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); |
| 6402 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6403 | } |
| 6404 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6405 | bnx2x_init_block(bp, MCP_BLOCK, init_stage); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6406 | bnx2x_init_block(bp, DMAE_BLOCK, init_stage); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6407 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 6408 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 6409 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
| 6410 | { |
| 6411 | u32 swap_val, swap_override, aeu_gpio_mask, offset; |
| 6412 | |
| 6413 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3, |
| 6414 | MISC_REGISTERS_GPIO_INPUT_HI_Z, port); |
| 6415 | |
| 6416 | /* The GPIO should be swapped if the swap register is |
| 6417 | set and active */ |
| 6418 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 6419 | swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
| 6420 | |
| 6421 | /* Select function upon port-swap configuration */ |
| 6422 | if (port == 0) { |
| 6423 | offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0; |
| 6424 | aeu_gpio_mask = (swap_val && swap_override) ? |
| 6425 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 : |
| 6426 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0; |
| 6427 | } else { |
| 6428 | offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0; |
| 6429 | aeu_gpio_mask = (swap_val && swap_override) ? |
| 6430 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 : |
| 6431 | AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1; |
| 6432 | } |
| 6433 | val = REG_RD(bp, offset); |
| 6434 | /* add GPIO3 to group */ |
| 6435 | val |= aeu_gpio_mask; |
| 6436 | REG_WR(bp, offset, val); |
| 6437 | } |
| 6438 | break; |
| 6439 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 6440 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6441 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6442 | /* add SPIO 5 to group 0 */ |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6443 | { |
| 6444 | u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 6445 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 6446 | val = REG_RD(bp, reg_addr); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6447 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 6448 | REG_WR(bp, reg_addr, val); |
| 6449 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6450 | break; |
| 6451 | |
| 6452 | default: |
| 6453 | break; |
| 6454 | } |
| 6455 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 6456 | bnx2x__link_reset(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6457 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6458 | return 0; |
| 6459 | } |
| 6460 | |
| 6461 | #define ILT_PER_FUNC (768/2) |
| 6462 | #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC) |
| 6463 | /* the phys address is shifted right 12 bits and has an added |
| 6464 | 1=valid bit added to the 53rd bit |
| 6465 | then since this is a wide register(TM) |
| 6466 | we split it into two 32 bit writes |
| 6467 | */ |
| 6468 | #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF)) |
| 6469 | #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44))) |
| 6470 | #define PXP_ONE_ILT(x) (((x) << 10) | x) |
| 6471 | #define PXP_ILT_RANGE(f, l) (((l) << 10) | f) |
| 6472 | |
| 6473 | #define CNIC_ILT_LINES 0 |
| 6474 | |
| 6475 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
| 6476 | { |
| 6477 | int reg; |
| 6478 | |
| 6479 | if (CHIP_IS_E1H(bp)) |
| 6480 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; |
| 6481 | else /* E1 */ |
| 6482 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
| 6483 | |
| 6484 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); |
| 6485 | } |
| 6486 | |
| 6487 | static int bnx2x_init_func(struct bnx2x *bp) |
| 6488 | { |
| 6489 | int port = BP_PORT(bp); |
| 6490 | int func = BP_FUNC(bp); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6491 | u32 addr, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6492 | int i; |
| 6493 | |
| 6494 | DP(BNX2X_MSG_MCP, "starting func init func %x\n", func); |
| 6495 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6496 | /* set MSI reconfigure capability */ |
| 6497 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); |
| 6498 | val = REG_RD(bp, addr); |
| 6499 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; |
| 6500 | REG_WR(bp, addr, val); |
| 6501 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6502 | i = FUNC_ILT_BASE(func); |
| 6503 | |
| 6504 | bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context)); |
| 6505 | if (CHIP_IS_E1H(bp)) { |
| 6506 | REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i); |
| 6507 | REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES); |
| 6508 | } else /* E1 */ |
| 6509 | REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4, |
| 6510 | PXP_ILT_RANGE(i, i + CNIC_ILT_LINES)); |
| 6511 | |
| 6512 | |
| 6513 | if (CHIP_IS_E1H(bp)) { |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 6514 | bnx2x_init_block(bp, MISC_BLOCK, FUNC0_STAGE + func); |
| 6515 | bnx2x_init_block(bp, TCM_BLOCK, FUNC0_STAGE + func); |
| 6516 | bnx2x_init_block(bp, UCM_BLOCK, FUNC0_STAGE + func); |
| 6517 | bnx2x_init_block(bp, CCM_BLOCK, FUNC0_STAGE + func); |
| 6518 | bnx2x_init_block(bp, XCM_BLOCK, FUNC0_STAGE + func); |
| 6519 | bnx2x_init_block(bp, TSEM_BLOCK, FUNC0_STAGE + func); |
| 6520 | bnx2x_init_block(bp, USEM_BLOCK, FUNC0_STAGE + func); |
| 6521 | bnx2x_init_block(bp, CSEM_BLOCK, FUNC0_STAGE + func); |
| 6522 | bnx2x_init_block(bp, XSEM_BLOCK, FUNC0_STAGE + func); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6523 | |
| 6524 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 6525 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov); |
| 6526 | } |
| 6527 | |
| 6528 | /* HC init per function */ |
| 6529 | if (CHIP_IS_E1H(bp)) { |
| 6530 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 6531 | |
| 6532 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6533 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6534 | } |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 6535 | bnx2x_init_block(bp, HC_BLOCK, FUNC0_STAGE + func); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6536 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6537 | /* Reset PCIE errors for debug */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6538 | REG_WR(bp, 0x2114, 0xffffffff); |
| 6539 | REG_WR(bp, 0x2120, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6540 | |
| 6541 | return 0; |
| 6542 | } |
| 6543 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6544 | static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code) |
| 6545 | { |
| 6546 | int i, rc = 0; |
| 6547 | |
| 6548 | DP(BNX2X_MSG_MCP, "function %d load_code %x\n", |
| 6549 | BP_FUNC(bp), load_code); |
| 6550 | |
| 6551 | bp->dmae_ready = 0; |
| 6552 | mutex_init(&bp->dmae_mutex); |
Eilon Greenstein | 54016b2 | 2009-08-12 08:23:48 +0000 | [diff] [blame] | 6553 | rc = bnx2x_gunzip_init(bp); |
| 6554 | if (rc) |
| 6555 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6556 | |
| 6557 | switch (load_code) { |
| 6558 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 6559 | rc = bnx2x_init_common(bp); |
| 6560 | if (rc) |
| 6561 | goto init_hw_err; |
| 6562 | /* no break */ |
| 6563 | |
| 6564 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 6565 | bp->dmae_ready = 1; |
| 6566 | rc = bnx2x_init_port(bp); |
| 6567 | if (rc) |
| 6568 | goto init_hw_err; |
| 6569 | /* no break */ |
| 6570 | |
| 6571 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 6572 | bp->dmae_ready = 1; |
| 6573 | rc = bnx2x_init_func(bp); |
| 6574 | if (rc) |
| 6575 | goto init_hw_err; |
| 6576 | break; |
| 6577 | |
| 6578 | default: |
| 6579 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 6580 | break; |
| 6581 | } |
| 6582 | |
| 6583 | if (!BP_NOMCP(bp)) { |
| 6584 | int func = BP_FUNC(bp); |
| 6585 | |
| 6586 | bp->fw_drv_pulse_wr_seq = |
| 6587 | (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) & |
| 6588 | DRV_PULSE_SEQ_MASK); |
Eilon Greenstein | 6fe49bb | 2009-08-12 08:23:17 +0000 | [diff] [blame] | 6589 | DP(BNX2X_MSG_MCP, "drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq); |
| 6590 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6591 | |
| 6592 | /* this needs to be done before gunzip end */ |
| 6593 | bnx2x_zero_def_sb(bp); |
| 6594 | for_each_queue(bp, i) |
| 6595 | bnx2x_zero_sb(bp, BP_L_ID(bp) + i); |
| 6596 | |
| 6597 | init_hw_err: |
| 6598 | bnx2x_gunzip_end(bp); |
| 6599 | |
| 6600 | return rc; |
| 6601 | } |
| 6602 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6603 | static void bnx2x_free_mem(struct bnx2x *bp) |
| 6604 | { |
| 6605 | |
| 6606 | #define BNX2X_PCI_FREE(x, y, size) \ |
| 6607 | do { \ |
| 6608 | if (x) { \ |
| 6609 | pci_free_consistent(bp->pdev, size, x, y); \ |
| 6610 | x = NULL; \ |
| 6611 | y = 0; \ |
| 6612 | } \ |
| 6613 | } while (0) |
| 6614 | |
| 6615 | #define BNX2X_FREE(x) \ |
| 6616 | do { \ |
| 6617 | if (x) { \ |
| 6618 | vfree(x); \ |
| 6619 | x = NULL; \ |
| 6620 | } \ |
| 6621 | } while (0) |
| 6622 | |
| 6623 | int i; |
| 6624 | |
| 6625 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6626 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6627 | for_each_queue(bp, i) { |
| 6628 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6629 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6630 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk), |
| 6631 | bnx2x_fp(bp, i, status_blk_mapping), |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6632 | sizeof(struct host_status_block)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6633 | } |
| 6634 | /* Rx */ |
| 6635 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6636 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6637 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6638 | BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring)); |
| 6639 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring), |
| 6640 | bnx2x_fp(bp, i, rx_desc_mapping), |
| 6641 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6642 | |
| 6643 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring), |
| 6644 | bnx2x_fp(bp, i, rx_comp_mapping), |
| 6645 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6646 | NUM_RCQ_BD); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6647 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6648 | /* SGE ring */ |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6649 | BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6650 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring), |
| 6651 | bnx2x_fp(bp, i, rx_sge_mapping), |
| 6652 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
| 6653 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6654 | /* Tx */ |
| 6655 | for_each_tx_queue(bp, i) { |
| 6656 | |
| 6657 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6658 | BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring)); |
| 6659 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring), |
| 6660 | bnx2x_fp(bp, i, tx_desc_mapping), |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6661 | sizeof(union eth_tx_bd_types) * NUM_TX_BD); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6662 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6663 | /* end of fastpath */ |
| 6664 | |
| 6665 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6666 | sizeof(struct host_def_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6667 | |
| 6668 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6669 | sizeof(struct bnx2x_slowpath)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6670 | |
| 6671 | #ifdef BCM_ISCSI |
| 6672 | BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024); |
| 6673 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024); |
| 6674 | BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024); |
| 6675 | BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024); |
| 6676 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6677 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6678 | |
| 6679 | #undef BNX2X_PCI_FREE |
| 6680 | #undef BNX2X_KFREE |
| 6681 | } |
| 6682 | |
| 6683 | static int bnx2x_alloc_mem(struct bnx2x *bp) |
| 6684 | { |
| 6685 | |
| 6686 | #define BNX2X_PCI_ALLOC(x, y, size) \ |
| 6687 | do { \ |
| 6688 | x = pci_alloc_consistent(bp->pdev, size, y); \ |
| 6689 | if (x == NULL) \ |
| 6690 | goto alloc_mem_err; \ |
| 6691 | memset(x, 0, size); \ |
| 6692 | } while (0) |
| 6693 | |
| 6694 | #define BNX2X_ALLOC(x, size) \ |
| 6695 | do { \ |
| 6696 | x = vmalloc(size); \ |
| 6697 | if (x == NULL) \ |
| 6698 | goto alloc_mem_err; \ |
| 6699 | memset(x, 0, size); \ |
| 6700 | } while (0) |
| 6701 | |
| 6702 | int i; |
| 6703 | |
| 6704 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6705 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6706 | for_each_queue(bp, i) { |
| 6707 | bnx2x_fp(bp, i, bp) = bp; |
| 6708 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6709 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6710 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk), |
| 6711 | &bnx2x_fp(bp, i, status_blk_mapping), |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6712 | sizeof(struct host_status_block)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6713 | } |
| 6714 | /* Rx */ |
| 6715 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6716 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6717 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6718 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring), |
| 6719 | sizeof(struct sw_rx_bd) * NUM_RX_BD); |
| 6720 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring), |
| 6721 | &bnx2x_fp(bp, i, rx_desc_mapping), |
| 6722 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6723 | |
| 6724 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring), |
| 6725 | &bnx2x_fp(bp, i, rx_comp_mapping), |
| 6726 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6727 | NUM_RCQ_BD); |
| 6728 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6729 | /* SGE ring */ |
| 6730 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring), |
| 6731 | sizeof(struct sw_rx_page) * NUM_RX_SGE); |
| 6732 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring), |
| 6733 | &bnx2x_fp(bp, i, rx_sge_mapping), |
| 6734 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6735 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6736 | /* Tx */ |
| 6737 | for_each_tx_queue(bp, i) { |
| 6738 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6739 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6740 | BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring), |
| 6741 | sizeof(struct sw_tx_bd) * NUM_TX_BD); |
| 6742 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring), |
| 6743 | &bnx2x_fp(bp, i, tx_desc_mapping), |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6744 | sizeof(union eth_tx_bd_types) * NUM_TX_BD); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6745 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6746 | /* end of fastpath */ |
| 6747 | |
| 6748 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
| 6749 | sizeof(struct host_def_status_block)); |
| 6750 | |
| 6751 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
| 6752 | sizeof(struct bnx2x_slowpath)); |
| 6753 | |
| 6754 | #ifdef BCM_ISCSI |
| 6755 | BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024); |
| 6756 | |
| 6757 | /* Initialize T1 */ |
| 6758 | for (i = 0; i < 64*1024; i += 64) { |
| 6759 | *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL; |
| 6760 | *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL; |
| 6761 | } |
| 6762 | |
| 6763 | /* allocate searcher T2 table |
| 6764 | we allocate 1/4 of alloc num for T2 |
| 6765 | (which is not entered into the ILT) */ |
| 6766 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024); |
| 6767 | |
| 6768 | /* Initialize T2 */ |
| 6769 | for (i = 0; i < 16*1024; i += 64) |
| 6770 | * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64; |
| 6771 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6772 | /* now fixup the last line in the block to point to the next block */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6773 | *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping; |
| 6774 | |
| 6775 | /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */ |
| 6776 | BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024); |
| 6777 | |
| 6778 | /* QM queues (128*MAX_CONN) */ |
| 6779 | BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024); |
| 6780 | #endif |
| 6781 | |
| 6782 | /* Slow path ring */ |
| 6783 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); |
| 6784 | |
| 6785 | return 0; |
| 6786 | |
| 6787 | alloc_mem_err: |
| 6788 | bnx2x_free_mem(bp); |
| 6789 | return -ENOMEM; |
| 6790 | |
| 6791 | #undef BNX2X_PCI_ALLOC |
| 6792 | #undef BNX2X_ALLOC |
| 6793 | } |
| 6794 | |
| 6795 | static void bnx2x_free_tx_skbs(struct bnx2x *bp) |
| 6796 | { |
| 6797 | int i; |
| 6798 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6799 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6800 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6801 | |
| 6802 | u16 bd_cons = fp->tx_bd_cons; |
| 6803 | u16 sw_prod = fp->tx_pkt_prod; |
| 6804 | u16 sw_cons = fp->tx_pkt_cons; |
| 6805 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6806 | while (sw_cons != sw_prod) { |
| 6807 | bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons)); |
| 6808 | sw_cons++; |
| 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | |
| 6813 | static void bnx2x_free_rx_skbs(struct bnx2x *bp) |
| 6814 | { |
| 6815 | int i, j; |
| 6816 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6817 | for_each_rx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6818 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 6819 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6820 | for (i = 0; i < NUM_RX_BD; i++) { |
| 6821 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i]; |
| 6822 | struct sk_buff *skb = rx_buf->skb; |
| 6823 | |
| 6824 | if (skb == NULL) |
| 6825 | continue; |
| 6826 | |
| 6827 | pci_unmap_single(bp->pdev, |
| 6828 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 6829 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6830 | |
| 6831 | rx_buf->skb = NULL; |
| 6832 | dev_kfree_skb(skb); |
| 6833 | } |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6834 | if (!fp->disable_tpa) |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6835 | bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ? |
| 6836 | ETH_MAX_AGGREGATION_QUEUES_E1 : |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6837 | ETH_MAX_AGGREGATION_QUEUES_E1H); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | static void bnx2x_free_skbs(struct bnx2x *bp) |
| 6842 | { |
| 6843 | bnx2x_free_tx_skbs(bp); |
| 6844 | bnx2x_free_rx_skbs(bp); |
| 6845 | } |
| 6846 | |
| 6847 | static void bnx2x_free_msix_irqs(struct bnx2x *bp) |
| 6848 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6849 | int i, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6850 | |
| 6851 | free_irq(bp->msix_table[0].vector, bp->dev); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6852 | DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6853 | bp->msix_table[0].vector); |
| 6854 | |
| 6855 | for_each_queue(bp, i) { |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6856 | DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq " |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6857 | "state %x\n", i, bp->msix_table[i + offset].vector, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6858 | bnx2x_fp(bp, i, state)); |
| 6859 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6860 | free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6861 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | static void bnx2x_free_irq(struct bnx2x *bp) |
| 6865 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6866 | if (bp->flags & USING_MSIX_FLAG) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6867 | bnx2x_free_msix_irqs(bp); |
| 6868 | pci_disable_msix(bp->pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6869 | bp->flags &= ~USING_MSIX_FLAG; |
| 6870 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6871 | } else if (bp->flags & USING_MSI_FLAG) { |
| 6872 | free_irq(bp->pdev->irq, bp->dev); |
| 6873 | pci_disable_msi(bp->pdev); |
| 6874 | bp->flags &= ~USING_MSI_FLAG; |
| 6875 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6876 | } else |
| 6877 | free_irq(bp->pdev->irq, bp->dev); |
| 6878 | } |
| 6879 | |
| 6880 | static int bnx2x_enable_msix(struct bnx2x *bp) |
| 6881 | { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6882 | int i, rc, offset = 1; |
| 6883 | int igu_vec = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6884 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6885 | bp->msix_table[0].entry = igu_vec; |
| 6886 | DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6887 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6888 | for_each_queue(bp, i) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6889 | igu_vec = BP_L_ID(bp) + offset + i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6890 | bp->msix_table[i + offset].entry = igu_vec; |
| 6891 | DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d " |
| 6892 | "(fastpath #%u)\n", i + offset, igu_vec, i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6893 | } |
| 6894 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6895 | rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6896 | BNX2X_NUM_QUEUES(bp) + offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6897 | if (rc) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6898 | DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc); |
| 6899 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6900 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6901 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6902 | bp->flags |= USING_MSIX_FLAG; |
| 6903 | |
| 6904 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6905 | } |
| 6906 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6907 | static int bnx2x_req_msix_irqs(struct bnx2x *bp) |
| 6908 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6909 | int i, rc, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6910 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6911 | rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0, |
| 6912 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6913 | if (rc) { |
| 6914 | BNX2X_ERR("request sp irq failed\n"); |
| 6915 | return -EBUSY; |
| 6916 | } |
| 6917 | |
| 6918 | for_each_queue(bp, i) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6919 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6920 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6921 | if (i < bp->num_rx_queues) |
| 6922 | sprintf(fp->name, "%s-rx-%d", bp->dev->name, i); |
| 6923 | else |
| 6924 | sprintf(fp->name, "%s-tx-%d", |
| 6925 | bp->dev->name, i - bp->num_rx_queues); |
| 6926 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6927 | rc = request_irq(bp->msix_table[i + offset].vector, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6928 | bnx2x_msix_fp_int, 0, fp->name, fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6929 | if (rc) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6930 | BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6931 | bnx2x_free_msix_irqs(bp); |
| 6932 | return -EBUSY; |
| 6933 | } |
| 6934 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6935 | fp->state = BNX2X_FP_STATE_IRQ; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6936 | } |
| 6937 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6938 | i = BNX2X_NUM_QUEUES(bp); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 6939 | printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp[%d] %d" |
| 6940 | " ... fp[%d] %d\n", |
| 6941 | bp->dev->name, bp->msix_table[0].vector, |
| 6942 | 0, bp->msix_table[offset].vector, |
| 6943 | i - 1, bp->msix_table[offset + i - 1].vector); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6944 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6945 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6946 | } |
| 6947 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6948 | static int bnx2x_enable_msi(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6949 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6950 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6951 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6952 | rc = pci_enable_msi(bp->pdev); |
| 6953 | if (rc) { |
| 6954 | DP(NETIF_MSG_IFUP, "MSI is not attainable\n"); |
| 6955 | return -1; |
| 6956 | } |
| 6957 | bp->flags |= USING_MSI_FLAG; |
| 6958 | |
| 6959 | return 0; |
| 6960 | } |
| 6961 | |
| 6962 | static int bnx2x_req_irq(struct bnx2x *bp) |
| 6963 | { |
| 6964 | unsigned long flags; |
| 6965 | int rc; |
| 6966 | |
| 6967 | if (bp->flags & USING_MSI_FLAG) |
| 6968 | flags = 0; |
| 6969 | else |
| 6970 | flags = IRQF_SHARED; |
| 6971 | |
| 6972 | rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6973 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6974 | if (!rc) |
| 6975 | bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ; |
| 6976 | |
| 6977 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6978 | } |
| 6979 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6980 | static void bnx2x_napi_enable(struct bnx2x *bp) |
| 6981 | { |
| 6982 | int i; |
| 6983 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6984 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6985 | napi_enable(&bnx2x_fp(bp, i, napi)); |
| 6986 | } |
| 6987 | |
| 6988 | static void bnx2x_napi_disable(struct bnx2x *bp) |
| 6989 | { |
| 6990 | int i; |
| 6991 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6992 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6993 | napi_disable(&bnx2x_fp(bp, i, napi)); |
| 6994 | } |
| 6995 | |
| 6996 | static void bnx2x_netif_start(struct bnx2x *bp) |
| 6997 | { |
Eilon Greenstein | e151070 | 2009-07-21 05:47:41 +0000 | [diff] [blame] | 6998 | int intr_sem; |
| 6999 | |
| 7000 | intr_sem = atomic_dec_and_test(&bp->intr_sem); |
| 7001 | smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */ |
| 7002 | |
| 7003 | if (intr_sem) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7004 | if (netif_running(bp->dev)) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7005 | bnx2x_napi_enable(bp); |
| 7006 | bnx2x_int_enable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7007 | if (bp->state == BNX2X_STATE_OPEN) |
| 7008 | netif_tx_wake_all_queues(bp->dev); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7009 | } |
| 7010 | } |
| 7011 | } |
| 7012 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 7013 | static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7014 | { |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 7015 | bnx2x_int_disable_sync(bp, disable_hw); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 7016 | bnx2x_napi_disable(bp); |
Eilon Greenstein | 762d5f6 | 2009-03-02 07:59:56 +0000 | [diff] [blame] | 7017 | netif_tx_disable(bp->dev); |
| 7018 | bp->dev->trans_start = jiffies; /* prevent tx timeout */ |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7019 | } |
| 7020 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7021 | /* |
| 7022 | * Init service functions |
| 7023 | */ |
| 7024 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7025 | static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7026 | { |
| 7027 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7028 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7029 | |
| 7030 | /* CAM allocation |
| 7031 | * unicasts 0-31:port0 32-63:port1 |
| 7032 | * multicast 64-127:port0 128-191:port1 |
| 7033 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7034 | config->hdr.length = 2; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 7035 | config->hdr.offset = port ? 32 : 0; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7036 | config->hdr.client_id = bp->fp->cl_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7037 | config->hdr.reserved1 = 0; |
| 7038 | |
| 7039 | /* primary MAC */ |
| 7040 | config->config_table[0].cam_entry.msb_mac_addr = |
| 7041 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 7042 | config->config_table[0].cam_entry.middle_mac_addr = |
| 7043 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 7044 | config->config_table[0].cam_entry.lsb_mac_addr = |
| 7045 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7046 | config->config_table[0].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7047 | if (set) |
| 7048 | config->config_table[0].target_table_entry.flags = 0; |
| 7049 | else |
| 7050 | CAM_INVALIDATE(config->config_table[0]); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7051 | config->config_table[0].target_table_entry.clients_bit_vector = |
| 7052 | cpu_to_le32(1 << BP_L_ID(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7053 | config->config_table[0].target_table_entry.vlan_id = 0; |
| 7054 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7055 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n", |
| 7056 | (set ? "setting" : "clearing"), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7057 | config->config_table[0].cam_entry.msb_mac_addr, |
| 7058 | config->config_table[0].cam_entry.middle_mac_addr, |
| 7059 | config->config_table[0].cam_entry.lsb_mac_addr); |
| 7060 | |
| 7061 | /* broadcast */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 7062 | config->config_table[1].cam_entry.msb_mac_addr = cpu_to_le16(0xffff); |
| 7063 | config->config_table[1].cam_entry.middle_mac_addr = cpu_to_le16(0xffff); |
| 7064 | config->config_table[1].cam_entry.lsb_mac_addr = cpu_to_le16(0xffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7065 | config->config_table[1].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7066 | if (set) |
| 7067 | config->config_table[1].target_table_entry.flags = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7068 | TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST; |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7069 | else |
| 7070 | CAM_INVALIDATE(config->config_table[1]); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7071 | config->config_table[1].target_table_entry.clients_bit_vector = |
| 7072 | cpu_to_le32(1 << BP_L_ID(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7073 | config->config_table[1].target_table_entry.vlan_id = 0; |
| 7074 | |
| 7075 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 7076 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 7077 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 7078 | } |
| 7079 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7080 | static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7081 | { |
| 7082 | struct mac_configuration_cmd_e1h *config = |
| 7083 | (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config); |
| 7084 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7085 | /* CAM allocation for E1H |
| 7086 | * unicasts: by func number |
| 7087 | * multicast: 20+FUNC*20, 20 each |
| 7088 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7089 | config->hdr.length = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7090 | config->hdr.offset = BP_FUNC(bp); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7091 | config->hdr.client_id = bp->fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7092 | config->hdr.reserved1 = 0; |
| 7093 | |
| 7094 | /* primary MAC */ |
| 7095 | config->config_table[0].msb_mac_addr = |
| 7096 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 7097 | config->config_table[0].middle_mac_addr = |
| 7098 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 7099 | config->config_table[0].lsb_mac_addr = |
| 7100 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7101 | config->config_table[0].clients_bit_vector = |
| 7102 | cpu_to_le32(1 << BP_L_ID(bp)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7103 | config->config_table[0].vlan_id = 0; |
| 7104 | config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7105 | if (set) |
| 7106 | config->config_table[0].flags = BP_PORT(bp); |
| 7107 | else |
| 7108 | config->config_table[0].flags = |
| 7109 | MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7110 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7111 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n", |
| 7112 | (set ? "setting" : "clearing"), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7113 | config->config_table[0].msb_mac_addr, |
| 7114 | config->config_table[0].middle_mac_addr, |
| 7115 | config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp)); |
| 7116 | |
| 7117 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 7118 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 7119 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 7120 | } |
| 7121 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7122 | static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx, |
| 7123 | int *state_p, int poll) |
| 7124 | { |
| 7125 | /* can take a while if any port is running */ |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 7126 | int cnt = 5000; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7127 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7128 | DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n", |
| 7129 | poll ? "polling" : "waiting", state, idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7130 | |
| 7131 | might_sleep(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7132 | while (cnt--) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7133 | if (poll) { |
| 7134 | bnx2x_rx_int(bp->fp, 10); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7135 | /* if index is different from 0 |
| 7136 | * the reply for some commands will |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7137 | * be on the non default queue |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7138 | */ |
| 7139 | if (idx) |
| 7140 | bnx2x_rx_int(&bp->fp[idx], 10); |
| 7141 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7142 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 7143 | mb(); /* state is changed by bnx2x_sp_event() */ |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 7144 | if (*state_p == state) { |
| 7145 | #ifdef BNX2X_STOP_ON_ERROR |
| 7146 | DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt); |
| 7147 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7148 | return 0; |
Eilon Greenstein | 8b3a0f0 | 2009-02-12 08:37:23 +0000 | [diff] [blame] | 7149 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7150 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7151 | msleep(1); |
Eilon Greenstein | e3553b2 | 2009-08-12 08:23:31 +0000 | [diff] [blame] | 7152 | |
| 7153 | if (bp->panic) |
| 7154 | return -EIO; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7155 | } |
| 7156 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7157 | /* timeout! */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7158 | BNX2X_ERR("timeout %s for state %x on IDX [%d]\n", |
| 7159 | poll ? "polling" : "waiting", state, idx); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7160 | #ifdef BNX2X_STOP_ON_ERROR |
| 7161 | bnx2x_panic(); |
| 7162 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7163 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7164 | return -EBUSY; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7165 | } |
| 7166 | |
| 7167 | static int bnx2x_setup_leading(struct bnx2x *bp) |
| 7168 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7169 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7170 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7171 | /* reset IGU state */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7172 | bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7173 | |
| 7174 | /* SETUP ramrod */ |
| 7175 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0); |
| 7176 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7177 | /* Wait for completion */ |
| 7178 | rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7179 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7180 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | static int bnx2x_setup_multi(struct bnx2x *bp, int index) |
| 7184 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7185 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
| 7186 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7187 | /* reset IGU state */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7188 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7189 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7190 | /* SETUP ramrod */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7191 | fp->state = BNX2X_FP_STATE_OPENING; |
| 7192 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0, |
| 7193 | fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7194 | |
| 7195 | /* Wait for completion */ |
| 7196 | return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7197 | &(fp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7198 | } |
| 7199 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7200 | static int bnx2x_poll(struct napi_struct *napi, int budget); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7201 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7202 | static void bnx2x_set_int_mode_msix(struct bnx2x *bp, int *num_rx_queues_out, |
| 7203 | int *num_tx_queues_out) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7204 | { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7205 | int _num_rx_queues = 0, _num_tx_queues = 0; |
| 7206 | |
| 7207 | switch (bp->multi_mode) { |
| 7208 | case ETH_RSS_MODE_DISABLED: |
| 7209 | _num_rx_queues = 1; |
| 7210 | _num_tx_queues = 1; |
| 7211 | break; |
| 7212 | |
| 7213 | case ETH_RSS_MODE_REGULAR: |
| 7214 | if (num_rx_queues) |
| 7215 | _num_rx_queues = min_t(u32, num_rx_queues, |
| 7216 | BNX2X_MAX_QUEUES(bp)); |
| 7217 | else |
| 7218 | _num_rx_queues = min_t(u32, num_online_cpus(), |
| 7219 | BNX2X_MAX_QUEUES(bp)); |
| 7220 | |
| 7221 | if (num_tx_queues) |
| 7222 | _num_tx_queues = min_t(u32, num_tx_queues, |
| 7223 | BNX2X_MAX_QUEUES(bp)); |
| 7224 | else |
| 7225 | _num_tx_queues = min_t(u32, num_online_cpus(), |
| 7226 | BNX2X_MAX_QUEUES(bp)); |
| 7227 | |
| 7228 | /* There must be not more Tx queues than Rx queues */ |
| 7229 | if (_num_tx_queues > _num_rx_queues) { |
| 7230 | BNX2X_ERR("number of tx queues (%d) > " |
| 7231 | "number of rx queues (%d)" |
| 7232 | " defaulting to %d\n", |
| 7233 | _num_tx_queues, _num_rx_queues, |
| 7234 | _num_rx_queues); |
| 7235 | _num_tx_queues = _num_rx_queues; |
| 7236 | } |
| 7237 | break; |
| 7238 | |
| 7239 | |
| 7240 | default: |
| 7241 | _num_rx_queues = 1; |
| 7242 | _num_tx_queues = 1; |
| 7243 | break; |
| 7244 | } |
| 7245 | |
| 7246 | *num_rx_queues_out = _num_rx_queues; |
| 7247 | *num_tx_queues_out = _num_tx_queues; |
| 7248 | } |
| 7249 | |
| 7250 | static int bnx2x_set_int_mode(struct bnx2x *bp) |
| 7251 | { |
| 7252 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7253 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7254 | switch (int_mode) { |
| 7255 | case INT_MODE_INTx: |
| 7256 | case INT_MODE_MSI: |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7257 | bp->num_rx_queues = 1; |
| 7258 | bp->num_tx_queues = 1; |
| 7259 | DP(NETIF_MSG_IFUP, "set number of queues to 1\n"); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7260 | break; |
| 7261 | |
| 7262 | case INT_MODE_MSIX: |
| 7263 | default: |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7264 | /* Set interrupt mode according to bp->multi_mode value */ |
| 7265 | bnx2x_set_int_mode_msix(bp, &bp->num_rx_queues, |
| 7266 | &bp->num_tx_queues); |
| 7267 | |
| 7268 | DP(NETIF_MSG_IFUP, "set number of queues to: rx %d tx %d\n", |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7269 | bp->num_rx_queues, bp->num_tx_queues); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7270 | |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7271 | /* if we can't use MSI-X we only need one fp, |
| 7272 | * so try to enable MSI-X with the requested number of fp's |
| 7273 | * and fallback to MSI or legacy INTx with one fp |
| 7274 | */ |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7275 | rc = bnx2x_enable_msix(bp); |
| 7276 | if (rc) { |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7277 | /* failed to enable MSI-X */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7278 | if (bp->multi_mode) |
| 7279 | BNX2X_ERR("Multi requested but failed to " |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7280 | "enable MSI-X (rx %d tx %d), " |
| 7281 | "set number of queues to 1\n", |
| 7282 | bp->num_rx_queues, bp->num_tx_queues); |
| 7283 | bp->num_rx_queues = 1; |
| 7284 | bp->num_tx_queues = 1; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7285 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7286 | break; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7287 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7288 | bp->dev->real_num_tx_queues = bp->num_tx_queues; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7289 | return rc; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7290 | } |
| 7291 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7292 | |
| 7293 | /* must be called with rtnl_lock */ |
| 7294 | static int bnx2x_nic_load(struct bnx2x *bp, int load_mode) |
| 7295 | { |
| 7296 | u32 load_code; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7297 | int i, rc; |
| 7298 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7299 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7300 | if (unlikely(bp->panic)) |
| 7301 | return -EPERM; |
| 7302 | #endif |
| 7303 | |
| 7304 | bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD; |
| 7305 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7306 | rc = bnx2x_set_int_mode(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7307 | |
| 7308 | if (bnx2x_alloc_mem(bp)) |
| 7309 | return -ENOMEM; |
| 7310 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7311 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7312 | bnx2x_fp(bp, i, disable_tpa) = |
| 7313 | ((bp->flags & TPA_ENABLE_FLAG) == 0); |
| 7314 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7315 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7316 | netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi), |
| 7317 | bnx2x_poll, 128); |
| 7318 | |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7319 | bnx2x_napi_enable(bp); |
| 7320 | |
| 7321 | if (bp->flags & USING_MSIX_FLAG) { |
| 7322 | rc = bnx2x_req_msix_irqs(bp); |
| 7323 | if (rc) { |
| 7324 | pci_disable_msix(bp->pdev); |
| 7325 | goto load_error1; |
| 7326 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7327 | } else { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7328 | /* Fall to INTx if failed to enable MSI-X due to lack of |
| 7329 | memory (in bnx2x_set_int_mode()) */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7330 | if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx)) |
| 7331 | bnx2x_enable_msi(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7332 | bnx2x_ack_int(bp); |
| 7333 | rc = bnx2x_req_irq(bp); |
| 7334 | if (rc) { |
| 7335 | BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7336 | if (bp->flags & USING_MSI_FLAG) |
| 7337 | pci_disable_msi(bp->pdev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7338 | goto load_error1; |
| 7339 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7340 | if (bp->flags & USING_MSI_FLAG) { |
| 7341 | bp->dev->irq = bp->pdev->irq; |
| 7342 | printk(KERN_INFO PFX "%s: using MSI IRQ %d\n", |
| 7343 | bp->dev->name, bp->pdev->irq); |
| 7344 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7345 | } |
| 7346 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7347 | /* Send LOAD_REQUEST command to MCP |
| 7348 | Returns the type of LOAD command: |
| 7349 | if it is the first port to be initialized |
| 7350 | common blocks should be initialized, otherwise - not |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7351 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7352 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7353 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ); |
| 7354 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7355 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7356 | rc = -EBUSY; |
| 7357 | goto load_error2; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7358 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7359 | if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) { |
| 7360 | rc = -EBUSY; /* other port in diagnostic mode */ |
| 7361 | goto load_error2; |
| 7362 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7363 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7364 | } else { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7365 | int port = BP_PORT(bp); |
| 7366 | |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 7367 | DP(NETIF_MSG_IFUP, "NO MCP - load counts %d, %d, %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7368 | load_count[0], load_count[1], load_count[2]); |
| 7369 | load_count[0]++; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7370 | load_count[1 + port]++; |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 7371 | DP(NETIF_MSG_IFUP, "NO MCP - new load counts %d, %d, %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7372 | load_count[0], load_count[1], load_count[2]); |
| 7373 | if (load_count[0] == 1) |
| 7374 | load_code = FW_MSG_CODE_DRV_LOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7375 | else if (load_count[1 + port] == 1) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7376 | load_code = FW_MSG_CODE_DRV_LOAD_PORT; |
| 7377 | else |
| 7378 | load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7379 | } |
| 7380 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7381 | if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) || |
| 7382 | (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) |
| 7383 | bp->port.pmf = 1; |
| 7384 | else |
| 7385 | bp->port.pmf = 0; |
| 7386 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 7387 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7388 | /* Initialize HW */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7389 | rc = bnx2x_init_hw(bp, load_code); |
| 7390 | if (rc) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7391 | BNX2X_ERR("HW init failed, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7392 | goto load_error2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7393 | } |
| 7394 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7395 | /* Setup NIC internals and enable interrupts */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 7396 | bnx2x_nic_init(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7397 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 7398 | if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) && |
| 7399 | (bp->common.shmem2_base)) |
| 7400 | SHMEM2_WR(bp, dcc_support, |
| 7401 | (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV | |
| 7402 | SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV)); |
| 7403 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7404 | /* Send LOAD_DONE command to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7405 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7406 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE); |
| 7407 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7408 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7409 | rc = -EBUSY; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7410 | goto load_error3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7411 | } |
| 7412 | } |
| 7413 | |
| 7414 | bp->state = BNX2X_STATE_OPENING_WAIT4_PORT; |
| 7415 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7416 | rc = bnx2x_setup_leading(bp); |
| 7417 | if (rc) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7418 | BNX2X_ERR("Setup leading failed!\n"); |
Eilon Greenstein | e3553b2 | 2009-08-12 08:23:31 +0000 | [diff] [blame] | 7419 | #ifndef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7420 | goto load_error3; |
Eilon Greenstein | e3553b2 | 2009-08-12 08:23:31 +0000 | [diff] [blame] | 7421 | #else |
| 7422 | bp->panic = 1; |
| 7423 | return -EBUSY; |
| 7424 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7425 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7426 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7427 | if (CHIP_IS_E1H(bp)) |
| 7428 | if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) { |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 7429 | DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7430 | bp->state = BNX2X_STATE_DISABLED; |
| 7431 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7432 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7433 | if (bp->state == BNX2X_STATE_OPEN) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7434 | for_each_nondefault_queue(bp, i) { |
| 7435 | rc = bnx2x_setup_multi(bp, i); |
| 7436 | if (rc) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7437 | goto load_error3; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7438 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7439 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7440 | if (CHIP_IS_E1(bp)) |
| 7441 | bnx2x_set_mac_addr_e1(bp, 1); |
| 7442 | else |
| 7443 | bnx2x_set_mac_addr_e1h(bp, 1); |
| 7444 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7445 | |
| 7446 | if (bp->port.pmf) |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 7447 | bnx2x_initial_phy_init(bp, load_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7448 | |
| 7449 | /* Start fast path */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7450 | switch (load_mode) { |
| 7451 | case LOAD_NORMAL: |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7452 | if (bp->state == BNX2X_STATE_OPEN) { |
| 7453 | /* Tx queue should be only reenabled */ |
| 7454 | netif_tx_wake_all_queues(bp->dev); |
| 7455 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7456 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7457 | bnx2x_set_rx_mode(bp->dev); |
| 7458 | break; |
| 7459 | |
| 7460 | case LOAD_OPEN: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7461 | netif_tx_start_all_queues(bp->dev); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 7462 | if (bp->state != BNX2X_STATE_OPEN) |
| 7463 | netif_tx_disable(bp->dev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7464 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7465 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7466 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7467 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7468 | case LOAD_DIAG: |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7469 | /* Initialize the receive filter. */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7470 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7471 | bp->state = BNX2X_STATE_DIAG; |
| 7472 | break; |
| 7473 | |
| 7474 | default: |
| 7475 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7476 | } |
| 7477 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7478 | if (!bp->port.pmf) |
| 7479 | bnx2x__link_status_update(bp); |
| 7480 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7481 | /* start the timer */ |
| 7482 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 7483 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7484 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7485 | return 0; |
| 7486 | |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7487 | load_error3: |
| 7488 | bnx2x_int_disable_sync(bp, 1); |
| 7489 | if (!BP_NOMCP(bp)) { |
| 7490 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP); |
| 7491 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7492 | } |
| 7493 | bp->port.pmf = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7494 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 7495 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7496 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7497 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7498 | load_error2: |
Yitchak Gertner | d101463 | 2008-08-25 15:25:45 -0700 | [diff] [blame] | 7499 | /* Release IRQs */ |
| 7500 | bnx2x_free_irq(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 7501 | load_error1: |
| 7502 | bnx2x_napi_disable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7503 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 7504 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7505 | bnx2x_free_mem(bp); |
| 7506 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7507 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7508 | } |
| 7509 | |
| 7510 | static int bnx2x_stop_multi(struct bnx2x *bp, int index) |
| 7511 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7512 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7513 | int rc; |
| 7514 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7515 | /* halt the connection */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7516 | fp->state = BNX2X_FP_STATE_HALTING; |
| 7517 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7518 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7519 | /* Wait for completion */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7520 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7521 | &(fp->state), 1); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7522 | if (rc) /* timeout */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7523 | return rc; |
| 7524 | |
| 7525 | /* delete cfc entry */ |
| 7526 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1); |
| 7527 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7528 | /* Wait for completion */ |
| 7529 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7530 | &(fp->state), 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7531 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7532 | } |
| 7533 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7534 | static int bnx2x_stop_leading(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7535 | { |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 7536 | __le16 dsb_sp_prod_idx; |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 7537 | /* if the other port is handling traffic, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7538 | this can take a lot of time */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7539 | int cnt = 500; |
| 7540 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7541 | |
| 7542 | might_sleep(); |
| 7543 | |
| 7544 | /* Send HALT ramrod */ |
| 7545 | bp->fp[0].state = BNX2X_FP_STATE_HALTING; |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7546 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7547 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7548 | /* Wait for completion */ |
| 7549 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0, |
| 7550 | &(bp->fp[0].state), 1); |
| 7551 | if (rc) /* timeout */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7552 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7553 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7554 | dsb_sp_prod_idx = *bp->dsb_sp_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7555 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7556 | /* Send PORT_DELETE ramrod */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7557 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1); |
| 7558 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7559 | /* Wait for completion to arrive on default status block |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7560 | we are going to reset the chip anyway |
| 7561 | so there is not much to do if this times out |
| 7562 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7563 | while (dsb_sp_prod_idx == *bp->dsb_sp_prod) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7564 | if (!cnt) { |
| 7565 | DP(NETIF_MSG_IFDOWN, "timeout waiting for port del " |
| 7566 | "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n", |
| 7567 | *bp->dsb_sp_prod, dsb_sp_prod_idx); |
| 7568 | #ifdef BNX2X_STOP_ON_ERROR |
| 7569 | bnx2x_panic(); |
| 7570 | #endif |
Eilon Greenstein | 36e552ab | 2009-02-12 08:37:21 +0000 | [diff] [blame] | 7571 | rc = -EBUSY; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7572 | break; |
| 7573 | } |
| 7574 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7575 | msleep(1); |
Eilon Greenstein | 5650d9d | 2009-01-22 06:01:29 +0000 | [diff] [blame] | 7576 | rmb(); /* Refresh the dsb_sp_prod */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7577 | } |
| 7578 | bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD; |
| 7579 | bp->fp[0].state = BNX2X_FP_STATE_CLOSED; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7580 | |
| 7581 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7582 | } |
| 7583 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7584 | static void bnx2x_reset_func(struct bnx2x *bp) |
| 7585 | { |
| 7586 | int port = BP_PORT(bp); |
| 7587 | int func = BP_FUNC(bp); |
| 7588 | int base, i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 7589 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7590 | /* Configure IGU */ |
| 7591 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 7592 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 7593 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7594 | /* Clear ILT */ |
| 7595 | base = FUNC_ILT_BASE(func); |
| 7596 | for (i = base; i < base + ILT_PER_FUNC; i++) |
| 7597 | bnx2x_ilt_wr(bp, i, 0); |
| 7598 | } |
| 7599 | |
| 7600 | static void bnx2x_reset_port(struct bnx2x *bp) |
| 7601 | { |
| 7602 | int port = BP_PORT(bp); |
| 7603 | u32 val; |
| 7604 | |
| 7605 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
| 7606 | |
| 7607 | /* Do not rcv packets to BRB */ |
| 7608 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); |
| 7609 | /* Do not direct rcv packets that are not for MCP to the BRB */ |
| 7610 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7611 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7612 | |
| 7613 | /* Configure AEU */ |
| 7614 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); |
| 7615 | |
| 7616 | msleep(100); |
| 7617 | /* Check for BRB port occupancy */ |
| 7618 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); |
| 7619 | if (val) |
| 7620 | DP(NETIF_MSG_IFDOWN, |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7621 | "BRB1 is not empty %d blocks are occupied\n", val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7622 | |
| 7623 | /* TODO: Close Doorbell port? */ |
| 7624 | } |
| 7625 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7626 | static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code) |
| 7627 | { |
| 7628 | DP(BNX2X_MSG_MCP, "function %d reset_code %x\n", |
| 7629 | BP_FUNC(bp), reset_code); |
| 7630 | |
| 7631 | switch (reset_code) { |
| 7632 | case FW_MSG_CODE_DRV_UNLOAD_COMMON: |
| 7633 | bnx2x_reset_port(bp); |
| 7634 | bnx2x_reset_func(bp); |
| 7635 | bnx2x_reset_common(bp); |
| 7636 | break; |
| 7637 | |
| 7638 | case FW_MSG_CODE_DRV_UNLOAD_PORT: |
| 7639 | bnx2x_reset_port(bp); |
| 7640 | bnx2x_reset_func(bp); |
| 7641 | break; |
| 7642 | |
| 7643 | case FW_MSG_CODE_DRV_UNLOAD_FUNCTION: |
| 7644 | bnx2x_reset_func(bp); |
| 7645 | break; |
| 7646 | |
| 7647 | default: |
| 7648 | BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code); |
| 7649 | break; |
| 7650 | } |
| 7651 | } |
| 7652 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7653 | /* must be called with rtnl_lock */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7654 | static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7655 | { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7656 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7657 | u32 reset_code = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7658 | int i, cnt, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7659 | |
| 7660 | bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT; |
| 7661 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 7662 | /* Set "drop all" */ |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7663 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 7664 | bnx2x_set_storm_rx_mode(bp); |
| 7665 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 7666 | /* Disable HW interrupts, NAPI and Tx */ |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 7667 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 7668 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7669 | del_timer_sync(&bp->timer); |
| 7670 | SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb, |
| 7671 | (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 7672 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7673 | |
Eilon Greenstein | 70b9986 | 2009-01-14 06:43:48 +0000 | [diff] [blame] | 7674 | /* Release IRQs */ |
| 7675 | bnx2x_free_irq(bp); |
| 7676 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7677 | /* Wait until tx fastpath tasks complete */ |
| 7678 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7679 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 7680 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7681 | cnt = 1000; |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 7682 | while (bnx2x_has_tx_work_unload(fp)) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7683 | |
Eilon Greenstein | 7961f79 | 2009-03-02 07:59:31 +0000 | [diff] [blame] | 7684 | bnx2x_tx_int(fp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7685 | if (!cnt) { |
| 7686 | BNX2X_ERR("timeout waiting for queue[%d]\n", |
| 7687 | i); |
| 7688 | #ifdef BNX2X_STOP_ON_ERROR |
| 7689 | bnx2x_panic(); |
| 7690 | return -EBUSY; |
| 7691 | #else |
| 7692 | break; |
| 7693 | #endif |
| 7694 | } |
| 7695 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7696 | msleep(1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7697 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7698 | } |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7699 | /* Give HW time to discard old tx messages */ |
| 7700 | msleep(1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7701 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7702 | if (CHIP_IS_E1(bp)) { |
| 7703 | struct mac_configuration_cmd *config = |
| 7704 | bnx2x_sp(bp, mcast_config); |
| 7705 | |
| 7706 | bnx2x_set_mac_addr_e1(bp, 0); |
| 7707 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7708 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7709 | CAM_INVALIDATE(config->config_table[i]); |
| 7710 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7711 | config->hdr.length = i; |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7712 | if (CHIP_REV_IS_SLOW(bp)) |
| 7713 | config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 7714 | else |
| 7715 | config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 7716 | config->hdr.client_id = bp->fp->cl_id; |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7717 | config->hdr.reserved1 = 0; |
| 7718 | |
| 7719 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 7720 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 7721 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0); |
| 7722 | |
| 7723 | } else { /* E1H */ |
| 7724 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 7725 | |
| 7726 | bnx2x_set_mac_addr_e1h(bp, 0); |
| 7727 | |
| 7728 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 7729 | REG_WR(bp, MC_HASH_OFFSET(bp, i), 0); |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7730 | |
| 7731 | REG_WR(bp, MISC_REG_E1HMF_MODE, 0); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7732 | } |
| 7733 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7734 | if (unload_mode == UNLOAD_NORMAL) |
| 7735 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7736 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7737 | else if (bp->flags & NO_WOL_FLAG) |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7738 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7739 | |
Eilon Greenstein | 7d0446c | 2009-07-29 00:20:10 +0000 | [diff] [blame] | 7740 | else if (bp->wol) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7741 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7742 | u8 *mac_addr = bp->dev->dev_addr; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7743 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7744 | /* The mac address is written to entries 1-4 to |
| 7745 | preserve entry 0 which is used by the PMF */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7746 | u8 entry = (BP_E1HVN(bp) + 1)*8; |
| 7747 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7748 | val = (mac_addr[0] << 8) | mac_addr[1]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7749 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7750 | |
| 7751 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 7752 | (mac_addr[4] << 8) | mac_addr[5]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7753 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7754 | |
| 7755 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7756 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7757 | } else |
| 7758 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
| 7759 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7760 | /* Close multi and leading connections |
| 7761 | Completions for ramrods are collected in a synchronous way */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7762 | for_each_nondefault_queue(bp, i) |
| 7763 | if (bnx2x_stop_multi(bp, i)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7764 | goto unload_error; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7765 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7766 | rc = bnx2x_stop_leading(bp); |
| 7767 | if (rc) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7768 | BNX2X_ERR("Stop leading failed!\n"); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7769 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7770 | return -EBUSY; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7771 | #else |
| 7772 | goto unload_error; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7773 | #endif |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7774 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7775 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7776 | unload_error: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7777 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7778 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7779 | else { |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 7780 | DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7781 | load_count[0], load_count[1], load_count[2]); |
| 7782 | load_count[0]--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7783 | load_count[1 + port]--; |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 7784 | DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7785 | load_count[0], load_count[1], load_count[2]); |
| 7786 | if (load_count[0] == 0) |
| 7787 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7788 | else if (load_count[1 + port] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7789 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; |
| 7790 | else |
| 7791 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; |
| 7792 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7793 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7794 | if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) || |
| 7795 | (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT)) |
| 7796 | bnx2x__link_reset(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7797 | |
| 7798 | /* Reset the chip */ |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7799 | bnx2x_reset_chip(bp, reset_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7800 | |
| 7801 | /* Report UNLOAD_DONE to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7802 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7803 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 7804 | |
Eilon Greenstein | 9a03544 | 2008-11-03 16:45:55 -0800 | [diff] [blame] | 7805 | bp->port.pmf = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7806 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7807 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7808 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7809 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7810 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7811 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 7812 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7813 | bnx2x_free_mem(bp); |
| 7814 | |
| 7815 | bp->state = BNX2X_STATE_CLOSED; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7816 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7817 | netif_carrier_off(bp->dev); |
| 7818 | |
| 7819 | return 0; |
| 7820 | } |
| 7821 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7822 | static void bnx2x_reset_task(struct work_struct *work) |
| 7823 | { |
| 7824 | struct bnx2x *bp = container_of(work, struct bnx2x, reset_task); |
| 7825 | |
| 7826 | #ifdef BNX2X_STOP_ON_ERROR |
| 7827 | BNX2X_ERR("reset task called but STOP_ON_ERROR defined" |
| 7828 | " so reset not done to allow debug dump,\n" |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 7829 | " you will need to reboot when done\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7830 | return; |
| 7831 | #endif |
| 7832 | |
| 7833 | rtnl_lock(); |
| 7834 | |
| 7835 | if (!netif_running(bp->dev)) |
| 7836 | goto reset_task_exit; |
| 7837 | |
| 7838 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 7839 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 7840 | |
| 7841 | reset_task_exit: |
| 7842 | rtnl_unlock(); |
| 7843 | } |
| 7844 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7845 | /* end of nic load/unload */ |
| 7846 | |
| 7847 | /* ethtool_ops */ |
| 7848 | |
| 7849 | /* |
| 7850 | * Init service functions |
| 7851 | */ |
| 7852 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7853 | static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func) |
| 7854 | { |
| 7855 | switch (func) { |
| 7856 | case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 7857 | case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1; |
| 7858 | case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2; |
| 7859 | case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3; |
| 7860 | case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4; |
| 7861 | case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5; |
| 7862 | case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6; |
| 7863 | case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7; |
| 7864 | default: |
| 7865 | BNX2X_ERR("Unsupported function index: %d\n", func); |
| 7866 | return (u32)(-1); |
| 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func) |
| 7871 | { |
| 7872 | u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val; |
| 7873 | |
| 7874 | /* Flush all outstanding writes */ |
| 7875 | mmiowb(); |
| 7876 | |
| 7877 | /* Pretend to be function 0 */ |
| 7878 | REG_WR(bp, reg, 0); |
| 7879 | /* Flush the GRC transaction (in the chip) */ |
| 7880 | new_val = REG_RD(bp, reg); |
| 7881 | if (new_val != 0) { |
| 7882 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n", |
| 7883 | new_val); |
| 7884 | BUG(); |
| 7885 | } |
| 7886 | |
| 7887 | /* From now we are in the "like-E1" mode */ |
| 7888 | bnx2x_int_disable(bp); |
| 7889 | |
| 7890 | /* Flush all outstanding writes */ |
| 7891 | mmiowb(); |
| 7892 | |
| 7893 | /* Restore the original funtion settings */ |
| 7894 | REG_WR(bp, reg, orig_func); |
| 7895 | new_val = REG_RD(bp, reg); |
| 7896 | if (new_val != orig_func) { |
| 7897 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n", |
| 7898 | orig_func, new_val); |
| 7899 | BUG(); |
| 7900 | } |
| 7901 | } |
| 7902 | |
| 7903 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func) |
| 7904 | { |
| 7905 | if (CHIP_IS_E1H(bp)) |
| 7906 | bnx2x_undi_int_disable_e1h(bp, func); |
| 7907 | else |
| 7908 | bnx2x_int_disable(bp); |
| 7909 | } |
| 7910 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7911 | static void __devinit bnx2x_undi_unload(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7912 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7913 | u32 val; |
| 7914 | |
| 7915 | /* Check if there is any driver already loaded */ |
| 7916 | val = REG_RD(bp, MISC_REG_UNPREPARED); |
| 7917 | if (val == 0x1) { |
| 7918 | /* Check if it is the UNDI driver |
| 7919 | * UNDI driver initializes CID offset for normal bell to 0x7 |
| 7920 | */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 7921 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7922 | val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); |
| 7923 | if (val == 0x7) { |
| 7924 | u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7925 | /* save our func */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7926 | int func = BP_FUNC(bp); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7927 | u32 swap_en; |
| 7928 | u32 swap_val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7929 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7930 | /* clear the UNDI indication */ |
| 7931 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); |
| 7932 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7933 | BNX2X_DEV_INFO("UNDI is active! reset device\n"); |
| 7934 | |
| 7935 | /* try unload UNDI on port 0 */ |
| 7936 | bp->func = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7937 | bp->fw_seq = |
| 7938 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7939 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7940 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7941 | |
| 7942 | /* if UNDI is loaded on the other port */ |
| 7943 | if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) { |
| 7944 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7945 | /* send "DONE" for previous unload */ |
| 7946 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7947 | |
| 7948 | /* unload UNDI on port 1 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7949 | bp->func = 1; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7950 | bp->fw_seq = |
| 7951 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7952 | DRV_MSG_SEQ_NUMBER_MASK); |
| 7953 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7954 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7955 | bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7956 | } |
| 7957 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7958 | /* now it's safe to release the lock */ |
| 7959 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
| 7960 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7961 | bnx2x_undi_int_disable(bp, func); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7962 | |
| 7963 | /* close input traffic and wait for it */ |
| 7964 | /* Do not rcv packets to BRB */ |
| 7965 | REG_WR(bp, |
| 7966 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK : |
| 7967 | NIG_REG_LLH0_BRB1_DRV_MASK), 0x0); |
| 7968 | /* Do not direct rcv packets that are not for MCP to |
| 7969 | * the BRB */ |
| 7970 | REG_WR(bp, |
| 7971 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7972 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7973 | /* clear AEU */ |
| 7974 | REG_WR(bp, |
| 7975 | (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 7976 | MISC_REG_AEU_MASK_ATTN_FUNC_0), 0); |
| 7977 | msleep(10); |
| 7978 | |
| 7979 | /* save NIG port swap info */ |
| 7980 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 7981 | swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7982 | /* reset device */ |
| 7983 | REG_WR(bp, |
| 7984 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7985 | 0xd3ffffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7986 | REG_WR(bp, |
| 7987 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
| 7988 | 0x1403); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7989 | /* take the NIG out of reset and restore swap values */ |
| 7990 | REG_WR(bp, |
| 7991 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 7992 | MISC_REGISTERS_RESET_REG_1_RST_NIG); |
| 7993 | REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); |
| 7994 | REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en); |
| 7995 | |
| 7996 | /* send unload done to the MCP */ |
| 7997 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7998 | |
| 7999 | /* restore our func and fw_seq */ |
| 8000 | bp->func = func; |
| 8001 | bp->fw_seq = |
| 8002 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 8003 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 8004 | |
| 8005 | } else |
| 8006 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) |
| 8011 | { |
| 8012 | u32 val, val2, val3, val4, id; |
Eilon Greenstein | 72ce58c3 | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8013 | u16 pmc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8014 | |
| 8015 | /* Get the chip revision id and number. */ |
| 8016 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ |
| 8017 | val = REG_RD(bp, MISC_REG_CHIP_NUM); |
| 8018 | id = ((val & 0xffff) << 16); |
| 8019 | val = REG_RD(bp, MISC_REG_CHIP_REV); |
| 8020 | id |= ((val & 0xf) << 12); |
| 8021 | val = REG_RD(bp, MISC_REG_CHIP_METAL); |
| 8022 | id |= ((val & 0xff) << 4); |
Eilon Greenstein | 5a40e08 | 2009-01-14 06:44:04 +0000 | [diff] [blame] | 8023 | val = REG_RD(bp, MISC_REG_BOND_ID); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8024 | id |= (val & 0xf); |
| 8025 | bp->common.chip_id = id; |
| 8026 | bp->link_params.chip_id = bp->common.chip_id; |
| 8027 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); |
| 8028 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 8029 | val = (REG_RD(bp, 0x2874) & 0x55); |
| 8030 | if ((bp->common.chip_id & 0x1) || |
| 8031 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { |
| 8032 | bp->flags |= ONE_PORT_FLAG; |
| 8033 | BNX2X_DEV_INFO("single port device\n"); |
| 8034 | } |
| 8035 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8036 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
| 8037 | bp->common.flash_size = (NVRAM_1MB_SIZE << |
| 8038 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
| 8039 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", |
| 8040 | bp->common.flash_size, bp->common.flash_size); |
| 8041 | |
| 8042 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8043 | bp->common.shmem2_base = REG_RD(bp, MISC_REG_GENERIC_CR_0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8044 | bp->link_params.shmem_base = bp->common.shmem_base; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8045 | BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n", |
| 8046 | bp->common.shmem_base, bp->common.shmem2_base); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8047 | |
| 8048 | if (!bp->common.shmem_base || |
| 8049 | (bp->common.shmem_base < 0xA0000) || |
| 8050 | (bp->common.shmem_base >= 0xC0000)) { |
| 8051 | BNX2X_DEV_INFO("MCP not active\n"); |
| 8052 | bp->flags |= NO_MCP_FLAG; |
| 8053 | return; |
| 8054 | } |
| 8055 | |
| 8056 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 8057 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 8058 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 8059 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 8060 | |
| 8061 | 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] | 8062 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8063 | |
| 8064 | bp->link_params.hw_led_mode = ((bp->common.hw_config & |
| 8065 | SHARED_HW_CFG_LED_MODE_MASK) >> |
| 8066 | SHARED_HW_CFG_LED_MODE_SHIFT); |
| 8067 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8068 | bp->link_params.feature_config_flags = 0; |
| 8069 | val = SHMEM_RD(bp, dev_info.shared_feature_config.config); |
| 8070 | if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) |
| 8071 | bp->link_params.feature_config_flags |= |
| 8072 | FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8073 | else |
| 8074 | bp->link_params.feature_config_flags &= |
| 8075 | ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED; |
| 8076 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8077 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
| 8078 | bp->common.bc_ver = val; |
| 8079 | BNX2X_DEV_INFO("bc_ver %X\n", val); |
| 8080 | if (val < BNX2X_BC_VER) { |
| 8081 | /* for now only warn |
| 8082 | * later we might need to enforce this */ |
| 8083 | BNX2X_ERR("This driver needs bc_ver %X but found %X," |
| 8084 | " please upgrade BC\n", BNX2X_BC_VER, val); |
| 8085 | } |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8086 | bp->link_params.feature_config_flags |= |
| 8087 | (val >= REQ_BC_VER_4_VRFY_OPT_MDL) ? |
| 8088 | FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0; |
Eilon Greenstein | 72ce58c3 | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 8089 | |
| 8090 | if (BP_E1HVN(bp) == 0) { |
| 8091 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
| 8092 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
| 8093 | } else { |
| 8094 | /* no WOL capability for E1HVN != 0 */ |
| 8095 | bp->flags |= NO_WOL_FLAG; |
| 8096 | } |
| 8097 | BNX2X_DEV_INFO("%sWoL capable\n", |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 8098 | (bp->flags & NO_WOL_FLAG) ? "not " : ""); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8099 | |
| 8100 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); |
| 8101 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); |
| 8102 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); |
| 8103 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); |
| 8104 | |
| 8105 | printk(KERN_INFO PFX "part number %X-%X-%X-%X\n", |
| 8106 | val, val2, val3, val4); |
| 8107 | } |
| 8108 | |
| 8109 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
| 8110 | u32 switch_cfg) |
| 8111 | { |
| 8112 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8113 | u32 ext_phy_type; |
| 8114 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8115 | switch (switch_cfg) { |
| 8116 | case SWITCH_CFG_1G: |
| 8117 | BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg); |
| 8118 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8119 | ext_phy_type = |
| 8120 | SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8121 | switch (ext_phy_type) { |
| 8122 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT: |
| 8123 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 8124 | ext_phy_type); |
| 8125 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8126 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 8127 | SUPPORTED_10baseT_Full | |
| 8128 | SUPPORTED_100baseT_Half | |
| 8129 | SUPPORTED_100baseT_Full | |
| 8130 | SUPPORTED_1000baseT_Full | |
| 8131 | SUPPORTED_2500baseX_Full | |
| 8132 | SUPPORTED_TP | |
| 8133 | SUPPORTED_FIBRE | |
| 8134 | SUPPORTED_Autoneg | |
| 8135 | SUPPORTED_Pause | |
| 8136 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8137 | break; |
| 8138 | |
| 8139 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482: |
| 8140 | BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n", |
| 8141 | ext_phy_type); |
| 8142 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8143 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 8144 | SUPPORTED_10baseT_Full | |
| 8145 | SUPPORTED_100baseT_Half | |
| 8146 | SUPPORTED_100baseT_Full | |
| 8147 | SUPPORTED_1000baseT_Full | |
| 8148 | SUPPORTED_TP | |
| 8149 | SUPPORTED_FIBRE | |
| 8150 | SUPPORTED_Autoneg | |
| 8151 | SUPPORTED_Pause | |
| 8152 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8153 | break; |
| 8154 | |
| 8155 | default: |
| 8156 | BNX2X_ERR("NVRAM config error. " |
| 8157 | "BAD SerDes ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8158 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8159 | return; |
| 8160 | } |
| 8161 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8162 | bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + |
| 8163 | port*0x10); |
| 8164 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8165 | break; |
| 8166 | |
| 8167 | case SWITCH_CFG_10G: |
| 8168 | BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg); |
| 8169 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8170 | ext_phy_type = |
| 8171 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8172 | switch (ext_phy_type) { |
| 8173 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
| 8174 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 8175 | ext_phy_type); |
| 8176 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8177 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 8178 | SUPPORTED_10baseT_Full | |
| 8179 | SUPPORTED_100baseT_Half | |
| 8180 | SUPPORTED_100baseT_Full | |
| 8181 | SUPPORTED_1000baseT_Full | |
| 8182 | SUPPORTED_2500baseX_Full | |
| 8183 | SUPPORTED_10000baseT_Full | |
| 8184 | SUPPORTED_TP | |
| 8185 | SUPPORTED_FIBRE | |
| 8186 | SUPPORTED_Autoneg | |
| 8187 | SUPPORTED_Pause | |
| 8188 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8189 | break; |
| 8190 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8191 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
| 8192 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n", |
| 8193 | ext_phy_type); |
| 8194 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8195 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8196 | SUPPORTED_1000baseT_Full | |
| 8197 | SUPPORTED_FIBRE | |
| 8198 | SUPPORTED_Autoneg | |
| 8199 | SUPPORTED_Pause | |
| 8200 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8201 | break; |
| 8202 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8203 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
| 8204 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n", |
| 8205 | ext_phy_type); |
| 8206 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8207 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8208 | SUPPORTED_2500baseX_Full | |
| 8209 | SUPPORTED_1000baseT_Full | |
| 8210 | SUPPORTED_FIBRE | |
| 8211 | SUPPORTED_Autoneg | |
| 8212 | SUPPORTED_Pause | |
| 8213 | SUPPORTED_Asym_Pause); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8214 | break; |
| 8215 | |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8216 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
| 8217 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n", |
| 8218 | ext_phy_type); |
| 8219 | |
| 8220 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8221 | SUPPORTED_FIBRE | |
| 8222 | SUPPORTED_Pause | |
| 8223 | SUPPORTED_Asym_Pause); |
| 8224 | break; |
| 8225 | |
| 8226 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 8227 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n", |
| 8228 | ext_phy_type); |
| 8229 | |
| 8230 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8231 | SUPPORTED_1000baseT_Full | |
| 8232 | SUPPORTED_FIBRE | |
| 8233 | SUPPORTED_Pause | |
| 8234 | SUPPORTED_Asym_Pause); |
| 8235 | break; |
| 8236 | |
| 8237 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
| 8238 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n", |
| 8239 | ext_phy_type); |
| 8240 | |
| 8241 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8242 | SUPPORTED_1000baseT_Full | |
| 8243 | SUPPORTED_Autoneg | |
| 8244 | SUPPORTED_FIBRE | |
| 8245 | SUPPORTED_Pause | |
| 8246 | SUPPORTED_Asym_Pause); |
| 8247 | break; |
| 8248 | |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8249 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727: |
| 8250 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8727)\n", |
| 8251 | ext_phy_type); |
| 8252 | |
| 8253 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8254 | SUPPORTED_1000baseT_Full | |
| 8255 | SUPPORTED_Autoneg | |
| 8256 | SUPPORTED_FIBRE | |
| 8257 | SUPPORTED_Pause | |
| 8258 | SUPPORTED_Asym_Pause); |
| 8259 | break; |
| 8260 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8261 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
| 8262 | BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n", |
| 8263 | ext_phy_type); |
| 8264 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8265 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 8266 | SUPPORTED_TP | |
| 8267 | SUPPORTED_Autoneg | |
| 8268 | SUPPORTED_Pause | |
| 8269 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8270 | break; |
| 8271 | |
Eilon Greenstein | 2857718 | 2009-02-12 08:37:00 +0000 | [diff] [blame] | 8272 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481: |
| 8273 | BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n", |
| 8274 | ext_phy_type); |
| 8275 | |
| 8276 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 8277 | SUPPORTED_10baseT_Full | |
| 8278 | SUPPORTED_100baseT_Half | |
| 8279 | SUPPORTED_100baseT_Full | |
| 8280 | SUPPORTED_1000baseT_Full | |
| 8281 | SUPPORTED_10000baseT_Full | |
| 8282 | SUPPORTED_TP | |
| 8283 | SUPPORTED_Autoneg | |
| 8284 | SUPPORTED_Pause | |
| 8285 | SUPPORTED_Asym_Pause); |
| 8286 | break; |
| 8287 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8288 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 8289 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 8290 | bp->link_params.ext_phy_config); |
| 8291 | break; |
| 8292 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8293 | default: |
| 8294 | BNX2X_ERR("NVRAM config error. " |
| 8295 | "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8296 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8297 | return; |
| 8298 | } |
| 8299 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8300 | bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + |
| 8301 | port*0x18); |
| 8302 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8303 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8304 | break; |
| 8305 | |
| 8306 | default: |
| 8307 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8308 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8309 | return; |
| 8310 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8311 | bp->link_params.phy_addr = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8312 | |
| 8313 | /* mask what we support according to speed_cap_mask */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8314 | if (!(bp->link_params.speed_cap_mask & |
| 8315 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8316 | bp->port.supported &= ~SUPPORTED_10baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8317 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8318 | if (!(bp->link_params.speed_cap_mask & |
| 8319 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8320 | bp->port.supported &= ~SUPPORTED_10baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8321 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8322 | if (!(bp->link_params.speed_cap_mask & |
| 8323 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8324 | bp->port.supported &= ~SUPPORTED_100baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8325 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8326 | if (!(bp->link_params.speed_cap_mask & |
| 8327 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8328 | bp->port.supported &= ~SUPPORTED_100baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8329 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8330 | if (!(bp->link_params.speed_cap_mask & |
| 8331 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8332 | bp->port.supported &= ~(SUPPORTED_1000baseT_Half | |
| 8333 | SUPPORTED_1000baseT_Full); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8334 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8335 | if (!(bp->link_params.speed_cap_mask & |
| 8336 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8337 | bp->port.supported &= ~SUPPORTED_2500baseX_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8338 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8339 | if (!(bp->link_params.speed_cap_mask & |
| 8340 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8341 | bp->port.supported &= ~SUPPORTED_10000baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8342 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8343 | BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8344 | } |
| 8345 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8346 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8347 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8348 | bp->link_params.req_duplex = DUPLEX_FULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8349 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8350 | switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8351 | case PORT_FEATURE_LINK_SPEED_AUTO: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8352 | if (bp->port.supported & SUPPORTED_Autoneg) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8353 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8354 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8355 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8356 | u32 ext_phy_type = |
| 8357 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 8358 | |
| 8359 | if ((ext_phy_type == |
| 8360 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) || |
| 8361 | (ext_phy_type == |
| 8362 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8363 | /* force 10G, no AN */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8364 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8365 | bp->port.advertising = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8366 | (ADVERTISED_10000baseT_Full | |
| 8367 | ADVERTISED_FIBRE); |
| 8368 | break; |
| 8369 | } |
| 8370 | BNX2X_ERR("NVRAM config error. " |
| 8371 | "Invalid link_config 0x%x" |
| 8372 | " Autoneg not supported\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8373 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8374 | return; |
| 8375 | } |
| 8376 | break; |
| 8377 | |
| 8378 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8379 | if (bp->port.supported & SUPPORTED_10baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8380 | bp->link_params.req_line_speed = SPEED_10; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8381 | bp->port.advertising = (ADVERTISED_10baseT_Full | |
| 8382 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8383 | } else { |
| 8384 | BNX2X_ERR("NVRAM config error. " |
| 8385 | "Invalid link_config 0x%x" |
| 8386 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8387 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8388 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8389 | return; |
| 8390 | } |
| 8391 | break; |
| 8392 | |
| 8393 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8394 | if (bp->port.supported & SUPPORTED_10baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8395 | bp->link_params.req_line_speed = SPEED_10; |
| 8396 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8397 | bp->port.advertising = (ADVERTISED_10baseT_Half | |
| 8398 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8399 | } else { |
| 8400 | BNX2X_ERR("NVRAM config error. " |
| 8401 | "Invalid link_config 0x%x" |
| 8402 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8403 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8404 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8405 | return; |
| 8406 | } |
| 8407 | break; |
| 8408 | |
| 8409 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8410 | if (bp->port.supported & SUPPORTED_100baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8411 | bp->link_params.req_line_speed = SPEED_100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8412 | bp->port.advertising = (ADVERTISED_100baseT_Full | |
| 8413 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8414 | } else { |
| 8415 | BNX2X_ERR("NVRAM config error. " |
| 8416 | "Invalid link_config 0x%x" |
| 8417 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8418 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8419 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8420 | return; |
| 8421 | } |
| 8422 | break; |
| 8423 | |
| 8424 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8425 | if (bp->port.supported & SUPPORTED_100baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8426 | bp->link_params.req_line_speed = SPEED_100; |
| 8427 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8428 | bp->port.advertising = (ADVERTISED_100baseT_Half | |
| 8429 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8430 | } else { |
| 8431 | BNX2X_ERR("NVRAM config error. " |
| 8432 | "Invalid link_config 0x%x" |
| 8433 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8434 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8435 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8436 | return; |
| 8437 | } |
| 8438 | break; |
| 8439 | |
| 8440 | case PORT_FEATURE_LINK_SPEED_1G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8441 | if (bp->port.supported & SUPPORTED_1000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8442 | bp->link_params.req_line_speed = SPEED_1000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8443 | bp->port.advertising = (ADVERTISED_1000baseT_Full | |
| 8444 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8445 | } else { |
| 8446 | BNX2X_ERR("NVRAM config error. " |
| 8447 | "Invalid link_config 0x%x" |
| 8448 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8449 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8450 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8451 | return; |
| 8452 | } |
| 8453 | break; |
| 8454 | |
| 8455 | case PORT_FEATURE_LINK_SPEED_2_5G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8456 | if (bp->port.supported & SUPPORTED_2500baseX_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8457 | bp->link_params.req_line_speed = SPEED_2500; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8458 | bp->port.advertising = (ADVERTISED_2500baseX_Full | |
| 8459 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8460 | } else { |
| 8461 | BNX2X_ERR("NVRAM config error. " |
| 8462 | "Invalid link_config 0x%x" |
| 8463 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8464 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8465 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8466 | return; |
| 8467 | } |
| 8468 | break; |
| 8469 | |
| 8470 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
| 8471 | case PORT_FEATURE_LINK_SPEED_10G_KX4: |
| 8472 | case PORT_FEATURE_LINK_SPEED_10G_KR: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8473 | if (bp->port.supported & SUPPORTED_10000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8474 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8475 | bp->port.advertising = (ADVERTISED_10000baseT_Full | |
| 8476 | ADVERTISED_FIBRE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8477 | } else { |
| 8478 | BNX2X_ERR("NVRAM config error. " |
| 8479 | "Invalid link_config 0x%x" |
| 8480 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8481 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8482 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8483 | return; |
| 8484 | } |
| 8485 | break; |
| 8486 | |
| 8487 | default: |
| 8488 | BNX2X_ERR("NVRAM config error. " |
| 8489 | "BAD link speed link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8490 | bp->port.link_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8491 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8492 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8493 | break; |
| 8494 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8495 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8496 | bp->link_params.req_flow_ctrl = (bp->port.link_config & |
| 8497 | PORT_FEATURE_FLOW_CONTROL_MASK); |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8498 | if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) && |
Randy Dunlap | 4ab84d4 | 2008-08-07 20:33:19 -0700 | [diff] [blame] | 8499 | !(bp->port.supported & SUPPORTED_Autoneg)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8500 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8501 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8502 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x" |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8503 | " advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8504 | bp->link_params.req_line_speed, |
| 8505 | bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8506 | bp->link_params.req_flow_ctrl, bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8507 | } |
| 8508 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8509 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8510 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8511 | int port = BP_PORT(bp); |
| 8512 | u32 val, val2; |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8513 | u32 config; |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8514 | u16 i; |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8515 | u32 ext_phy_type; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8516 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8517 | bp->link_params.bp = bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8518 | bp->link_params.port = port; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8519 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8520 | bp->link_params.lane_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8521 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8522 | bp->link_params.ext_phy_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8523 | SHMEM_RD(bp, |
| 8524 | dev_info.port_hw_config[port].external_phy_config); |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8525 | /* BCM8727_NOC => BCM8727 no over current */ |
| 8526 | if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) == |
| 8527 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC) { |
| 8528 | bp->link_params.ext_phy_config &= |
| 8529 | ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
| 8530 | bp->link_params.ext_phy_config |= |
| 8531 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727; |
| 8532 | bp->link_params.feature_config_flags |= |
| 8533 | FEATURE_CONFIG_BCM8727_NOC; |
| 8534 | } |
| 8535 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8536 | bp->link_params.speed_cap_mask = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8537 | SHMEM_RD(bp, |
| 8538 | dev_info.port_hw_config[port].speed_capability_mask); |
| 8539 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8540 | bp->port.link_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8541 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
| 8542 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8543 | /* Get the 4 lanes xgxs config rx and tx */ |
| 8544 | for (i = 0; i < 2; i++) { |
| 8545 | val = SHMEM_RD(bp, |
| 8546 | dev_info.port_hw_config[port].xgxs_config_rx[i<<1]); |
| 8547 | bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff); |
| 8548 | bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff); |
| 8549 | |
| 8550 | val = SHMEM_RD(bp, |
| 8551 | dev_info.port_hw_config[port].xgxs_config_tx[i<<1]); |
| 8552 | bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff); |
| 8553 | bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff); |
| 8554 | } |
| 8555 | |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8556 | /* If the device is capable of WoL, set the default state according |
| 8557 | * to the HW |
| 8558 | */ |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8559 | config = SHMEM_RD(bp, dev_info.port_feature_config[port].config); |
Eilon Greenstein | 3ce2c3f | 2009-02-12 08:37:52 +0000 | [diff] [blame] | 8560 | bp->wol = (!(bp->flags & NO_WOL_FLAG) && |
| 8561 | (config & PORT_FEATURE_WOL_ENABLED)); |
| 8562 | |
Eilon Greenstein | c2c8b03 | 2009-02-12 08:37:14 +0000 | [diff] [blame] | 8563 | BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x" |
| 8564 | " speed_cap_mask 0x%08x link_config 0x%08x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8565 | bp->link_params.lane_config, |
| 8566 | bp->link_params.ext_phy_config, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8567 | bp->link_params.speed_cap_mask, bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8568 | |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8569 | bp->link_params.switch_cfg |= (bp->port.link_config & |
| 8570 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8571 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8572 | |
| 8573 | bnx2x_link_settings_requested(bp); |
| 8574 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8575 | /* |
| 8576 | * If connected directly, work with the internal PHY, otherwise, work |
| 8577 | * with the external PHY |
| 8578 | */ |
| 8579 | ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 8580 | if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) |
| 8581 | bp->mdio.prtad = bp->link_params.phy_addr; |
| 8582 | |
| 8583 | else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) && |
| 8584 | (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) |
| 8585 | bp->mdio.prtad = |
Eilon Greenstein | 659bc5c | 2009-08-12 08:24:02 +0000 | [diff] [blame] | 8586 | XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8587 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8588 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); |
| 8589 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); |
| 8590 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 8591 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 8592 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 8593 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 8594 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 8595 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8596 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8597 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8598 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8599 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8600 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) |
| 8601 | { |
| 8602 | int func = BP_FUNC(bp); |
| 8603 | u32 val, val2; |
| 8604 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8605 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8606 | bnx2x_get_common_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8607 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8608 | bp->e1hov = 0; |
| 8609 | bp->e1hmf = 0; |
| 8610 | if (CHIP_IS_E1H(bp)) { |
| 8611 | bp->mf_config = |
| 8612 | SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8613 | |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8614 | val = (SHMEM_RD(bp, mf_cfg.func_mf_config[FUNC_0].e1hov_tag) & |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 8615 | FUNC_MF_CFG_E1HOV_TAG_MASK); |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8616 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8617 | bp->e1hmf = 1; |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8618 | BNX2X_DEV_INFO("%s function mode\n", |
| 8619 | IS_E1HMF(bp) ? "multi" : "single"); |
| 8620 | |
| 8621 | if (IS_E1HMF(bp)) { |
| 8622 | val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func]. |
| 8623 | e1hov_tag) & |
| 8624 | FUNC_MF_CFG_E1HOV_TAG_MASK); |
| 8625 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
| 8626 | bp->e1hov = val; |
| 8627 | BNX2X_DEV_INFO("E1HOV for func %d is %d " |
| 8628 | "(0x%04x)\n", |
| 8629 | func, bp->e1hov, bp->e1hov); |
| 8630 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8631 | BNX2X_ERR("!!! No valid E1HOV for func %d," |
| 8632 | " aborting\n", func); |
| 8633 | rc = -EPERM; |
| 8634 | } |
Eilon Greenstein | 2691d51 | 2009-08-12 08:22:08 +0000 | [diff] [blame] | 8635 | } else { |
| 8636 | if (BP_E1HVN(bp)) { |
| 8637 | BNX2X_ERR("!!! VN %d in single function mode," |
| 8638 | " aborting\n", BP_E1HVN(bp)); |
| 8639 | rc = -EPERM; |
| 8640 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8641 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8642 | } |
| 8643 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8644 | if (!BP_NOMCP(bp)) { |
| 8645 | bnx2x_get_port_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8646 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8647 | bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) & |
| 8648 | DRV_MSG_SEQ_NUMBER_MASK); |
| 8649 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 8650 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8651 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8652 | if (IS_E1HMF(bp)) { |
| 8653 | val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper); |
| 8654 | val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower); |
| 8655 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && |
| 8656 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) { |
| 8657 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 8658 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 8659 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 8660 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 8661 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 8662 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
| 8663 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, |
| 8664 | ETH_ALEN); |
| 8665 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, |
| 8666 | ETH_ALEN); |
| 8667 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8668 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8669 | return rc; |
| 8670 | } |
| 8671 | |
| 8672 | if (BP_NOMCP(bp)) { |
| 8673 | /* only supposed to happen on emulation/FPGA */ |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 8674 | BNX2X_ERR("warning random MAC workaround active\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8675 | random_ether_addr(bp->dev->dev_addr); |
| 8676 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
| 8677 | } |
| 8678 | |
| 8679 | return rc; |
| 8680 | } |
| 8681 | |
| 8682 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
| 8683 | { |
| 8684 | int func = BP_FUNC(bp); |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 8685 | int timer_interval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8686 | int rc; |
| 8687 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8688 | /* Disable interrupt handling until HW is initialized */ |
| 8689 | atomic_set(&bp->intr_sem, 1); |
Eilon Greenstein | e151070 | 2009-07-21 05:47:41 +0000 | [diff] [blame] | 8690 | smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 8691 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8692 | mutex_init(&bp->port.phy_mutex); |
| 8693 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 8694 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8695 | INIT_WORK(&bp->reset_task, bnx2x_reset_task); |
| 8696 | |
| 8697 | rc = bnx2x_get_hwinfo(bp); |
| 8698 | |
| 8699 | /* need to reset chip if undi was active */ |
| 8700 | if (!BP_NOMCP(bp)) |
| 8701 | bnx2x_undi_unload(bp); |
| 8702 | |
| 8703 | if (CHIP_REV_IS_FPGA(bp)) |
| 8704 | printk(KERN_ERR PFX "FPGA detected\n"); |
| 8705 | |
| 8706 | if (BP_NOMCP(bp) && (func == 0)) |
| 8707 | printk(KERN_ERR PFX |
| 8708 | "MCP disabled, must load devices in order!\n"); |
| 8709 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8710 | /* Set multi queue mode */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 8711 | if ((multi_mode != ETH_RSS_MODE_DISABLED) && |
| 8712 | ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8713 | printk(KERN_ERR PFX |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 8714 | "Multi disabled since int_mode requested is not MSI-X\n"); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 8715 | multi_mode = ETH_RSS_MODE_DISABLED; |
| 8716 | } |
| 8717 | bp->multi_mode = multi_mode; |
| 8718 | |
| 8719 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 8720 | /* Set TPA flags */ |
| 8721 | if (disable_tpa) { |
| 8722 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 8723 | bp->dev->features &= ~NETIF_F_LRO; |
| 8724 | } else { |
| 8725 | bp->flags |= TPA_ENABLE_FLAG; |
| 8726 | bp->dev->features |= NETIF_F_LRO; |
| 8727 | } |
| 8728 | |
Eilon Greenstein | a18f512 | 2009-08-12 08:23:26 +0000 | [diff] [blame] | 8729 | if (CHIP_IS_E1(bp)) |
| 8730 | bp->dropless_fc = 0; |
| 8731 | else |
| 8732 | bp->dropless_fc = dropless_fc; |
| 8733 | |
Eilon Greenstein | 8d5726c | 2009-02-12 08:37:19 +0000 | [diff] [blame] | 8734 | bp->mrrs = mrrs; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 8735 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8736 | bp->tx_ring_size = MAX_TX_AVAIL; |
| 8737 | bp->rx_ring_size = MAX_RX_AVAIL; |
| 8738 | |
| 8739 | bp->rx_csum = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8740 | |
| 8741 | bp->tx_ticks = 50; |
| 8742 | bp->rx_ticks = 25; |
| 8743 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 8744 | timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ); |
| 8745 | bp->current_interval = (poll ? poll : timer_interval); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8746 | |
| 8747 | init_timer(&bp->timer); |
| 8748 | bp->timer.expires = jiffies + bp->current_interval; |
| 8749 | bp->timer.data = (unsigned long) bp; |
| 8750 | bp->timer.function = bnx2x_timer; |
| 8751 | |
| 8752 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8753 | } |
| 8754 | |
| 8755 | /* |
| 8756 | * ethtool service functions |
| 8757 | */ |
| 8758 | |
| 8759 | /* All ethtool functions called with rtnl_lock */ |
| 8760 | |
| 8761 | static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8762 | { |
| 8763 | struct bnx2x *bp = netdev_priv(dev); |
| 8764 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8765 | cmd->supported = bp->port.supported; |
| 8766 | cmd->advertising = bp->port.advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8767 | |
| 8768 | if (netif_carrier_ok(dev)) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8769 | cmd->speed = bp->link_vars.line_speed; |
| 8770 | cmd->duplex = bp->link_vars.duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8771 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8772 | cmd->speed = bp->link_params.req_line_speed; |
| 8773 | cmd->duplex = bp->link_params.req_duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8774 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8775 | if (IS_E1HMF(bp)) { |
| 8776 | u16 vn_max_rate; |
| 8777 | |
| 8778 | vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 8779 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 8780 | if (vn_max_rate < cmd->speed) |
| 8781 | cmd->speed = vn_max_rate; |
| 8782 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8783 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8784 | if (bp->link_params.switch_cfg == SWITCH_CFG_10G) { |
| 8785 | u32 ext_phy_type = |
| 8786 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8787 | |
| 8788 | switch (ext_phy_type) { |
| 8789 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8790 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8791 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
Eilon Greenstein | 589abe3 | 2009-02-12 08:36:55 +0000 | [diff] [blame] | 8792 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
| 8793 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 8794 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726: |
Eilon Greenstein | 4d295db | 2009-07-21 05:47:47 +0000 | [diff] [blame] | 8795 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8796 | cmd->port = PORT_FIBRE; |
| 8797 | break; |
| 8798 | |
| 8799 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 2857718 | 2009-02-12 08:37:00 +0000 | [diff] [blame] | 8800 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8801 | cmd->port = PORT_TP; |
| 8802 | break; |
| 8803 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8804 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 8805 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 8806 | bp->link_params.ext_phy_config); |
| 8807 | break; |
| 8808 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8809 | default: |
| 8810 | DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8811 | bp->link_params.ext_phy_config); |
| 8812 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8813 | } |
| 8814 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8815 | cmd->port = PORT_TP; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8816 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 8817 | cmd->phy_address = bp->mdio.prtad; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8818 | cmd->transceiver = XCVR_INTERNAL; |
| 8819 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8820 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8821 | cmd->autoneg = AUTONEG_ENABLE; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8822 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8823 | cmd->autoneg = AUTONEG_DISABLE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8824 | |
| 8825 | cmd->maxtxpkt = 0; |
| 8826 | cmd->maxrxpkt = 0; |
| 8827 | |
| 8828 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8829 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8830 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8831 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8832 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8833 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8834 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8835 | |
| 8836 | return 0; |
| 8837 | } |
| 8838 | |
| 8839 | static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8840 | { |
| 8841 | struct bnx2x *bp = netdev_priv(dev); |
| 8842 | u32 advertising; |
| 8843 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8844 | if (IS_E1HMF(bp)) |
| 8845 | return 0; |
| 8846 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8847 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8848 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8849 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8850 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8851 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8852 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8853 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8854 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8855 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8856 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
| 8857 | DP(NETIF_MSG_LINK, "Autoneg not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8858 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8859 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8860 | |
| 8861 | /* advertise the requested speed and duplex if supported */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8862 | cmd->advertising &= bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8863 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8864 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
| 8865 | bp->link_params.req_duplex = DUPLEX_FULL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8866 | bp->port.advertising |= (ADVERTISED_Autoneg | |
| 8867 | cmd->advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8868 | |
| 8869 | } else { /* forced speed */ |
| 8870 | /* advertise the requested speed and duplex if supported */ |
| 8871 | switch (cmd->speed) { |
| 8872 | case SPEED_10: |
| 8873 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8874 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8875 | SUPPORTED_10baseT_Full)) { |
| 8876 | DP(NETIF_MSG_LINK, |
| 8877 | "10M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8878 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8879 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8880 | |
| 8881 | advertising = (ADVERTISED_10baseT_Full | |
| 8882 | ADVERTISED_TP); |
| 8883 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8884 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8885 | SUPPORTED_10baseT_Half)) { |
| 8886 | DP(NETIF_MSG_LINK, |
| 8887 | "10M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8888 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8889 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8890 | |
| 8891 | advertising = (ADVERTISED_10baseT_Half | |
| 8892 | ADVERTISED_TP); |
| 8893 | } |
| 8894 | break; |
| 8895 | |
| 8896 | case SPEED_100: |
| 8897 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8898 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8899 | SUPPORTED_100baseT_Full)) { |
| 8900 | DP(NETIF_MSG_LINK, |
| 8901 | "100M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8902 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8903 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8904 | |
| 8905 | advertising = (ADVERTISED_100baseT_Full | |
| 8906 | ADVERTISED_TP); |
| 8907 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8908 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8909 | SUPPORTED_100baseT_Half)) { |
| 8910 | DP(NETIF_MSG_LINK, |
| 8911 | "100M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8912 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8913 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8914 | |
| 8915 | advertising = (ADVERTISED_100baseT_Half | |
| 8916 | ADVERTISED_TP); |
| 8917 | } |
| 8918 | break; |
| 8919 | |
| 8920 | case SPEED_1000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8921 | if (cmd->duplex != DUPLEX_FULL) { |
| 8922 | DP(NETIF_MSG_LINK, "1G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8923 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8924 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8925 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8926 | if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8927 | DP(NETIF_MSG_LINK, "1G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8928 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8929 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8930 | |
| 8931 | advertising = (ADVERTISED_1000baseT_Full | |
| 8932 | ADVERTISED_TP); |
| 8933 | break; |
| 8934 | |
| 8935 | case SPEED_2500: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8936 | if (cmd->duplex != DUPLEX_FULL) { |
| 8937 | DP(NETIF_MSG_LINK, |
| 8938 | "2.5G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8939 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8940 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8941 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8942 | if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8943 | DP(NETIF_MSG_LINK, |
| 8944 | "2.5G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8945 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8946 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8947 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8948 | advertising = (ADVERTISED_2500baseX_Full | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8949 | ADVERTISED_TP); |
| 8950 | break; |
| 8951 | |
| 8952 | case SPEED_10000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8953 | if (cmd->duplex != DUPLEX_FULL) { |
| 8954 | DP(NETIF_MSG_LINK, "10G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8955 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8956 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8957 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8958 | if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8959 | DP(NETIF_MSG_LINK, "10G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8960 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8961 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8962 | |
| 8963 | advertising = (ADVERTISED_10000baseT_Full | |
| 8964 | ADVERTISED_FIBRE); |
| 8965 | break; |
| 8966 | |
| 8967 | default: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8968 | DP(NETIF_MSG_LINK, "Unsupported speed\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8969 | return -EINVAL; |
| 8970 | } |
| 8971 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8972 | bp->link_params.req_line_speed = cmd->speed; |
| 8973 | bp->link_params.req_duplex = cmd->duplex; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8974 | bp->port.advertising = advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8975 | } |
| 8976 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8977 | DP(NETIF_MSG_LINK, "req_line_speed %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8978 | DP_LEVEL " req_duplex %d advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8979 | bp->link_params.req_line_speed, bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8980 | bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8981 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8982 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8983 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8984 | bnx2x_link_set(bp); |
| 8985 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8986 | |
| 8987 | return 0; |
| 8988 | } |
| 8989 | |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 8990 | #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE) |
| 8991 | #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE) |
| 8992 | |
| 8993 | static int bnx2x_get_regs_len(struct net_device *dev) |
| 8994 | { |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 8995 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 0d28e49 | 2009-08-12 08:23:40 +0000 | [diff] [blame] | 8996 | int regdump_len = 0; |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 8997 | int i; |
| 8998 | |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 8999 | if (CHIP_IS_E1(bp)) { |
| 9000 | for (i = 0; i < REGS_COUNT; i++) |
| 9001 | if (IS_E1_ONLINE(reg_addrs[i].info)) |
| 9002 | regdump_len += reg_addrs[i].size; |
| 9003 | |
| 9004 | for (i = 0; i < WREGS_COUNT_E1; i++) |
| 9005 | if (IS_E1_ONLINE(wreg_addrs_e1[i].info)) |
| 9006 | regdump_len += wreg_addrs_e1[i].size * |
| 9007 | (1 + wreg_addrs_e1[i].read_regs_count); |
| 9008 | |
| 9009 | } else { /* E1H */ |
| 9010 | for (i = 0; i < REGS_COUNT; i++) |
| 9011 | if (IS_E1H_ONLINE(reg_addrs[i].info)) |
| 9012 | regdump_len += reg_addrs[i].size; |
| 9013 | |
| 9014 | for (i = 0; i < WREGS_COUNT_E1H; i++) |
| 9015 | if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info)) |
| 9016 | regdump_len += wreg_addrs_e1h[i].size * |
| 9017 | (1 + wreg_addrs_e1h[i].read_regs_count); |
| 9018 | } |
| 9019 | regdump_len *= 4; |
| 9020 | regdump_len += sizeof(struct dump_hdr); |
| 9021 | |
| 9022 | return regdump_len; |
| 9023 | } |
| 9024 | |
| 9025 | static void bnx2x_get_regs(struct net_device *dev, |
| 9026 | struct ethtool_regs *regs, void *_p) |
| 9027 | { |
| 9028 | u32 *p = _p, i, j; |
| 9029 | struct bnx2x *bp = netdev_priv(dev); |
| 9030 | struct dump_hdr dump_hdr = {0}; |
| 9031 | |
| 9032 | regs->version = 0; |
| 9033 | memset(p, 0, regs->len); |
| 9034 | |
| 9035 | if (!netif_running(bp->dev)) |
| 9036 | return; |
| 9037 | |
| 9038 | dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1; |
| 9039 | dump_hdr.dump_sign = dump_sign_all; |
| 9040 | dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR); |
| 9041 | dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR); |
| 9042 | dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR); |
| 9043 | dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR); |
| 9044 | dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE; |
| 9045 | |
| 9046 | memcpy(p, &dump_hdr, sizeof(struct dump_hdr)); |
| 9047 | p += dump_hdr.hdr_size + 1; |
| 9048 | |
| 9049 | if (CHIP_IS_E1(bp)) { |
| 9050 | for (i = 0; i < REGS_COUNT; i++) |
| 9051 | if (IS_E1_ONLINE(reg_addrs[i].info)) |
| 9052 | for (j = 0; j < reg_addrs[i].size; j++) |
| 9053 | *p++ = REG_RD(bp, |
| 9054 | reg_addrs[i].addr + j*4); |
| 9055 | |
| 9056 | } else { /* E1H */ |
| 9057 | for (i = 0; i < REGS_COUNT; i++) |
| 9058 | if (IS_E1H_ONLINE(reg_addrs[i].info)) |
| 9059 | for (j = 0; j < reg_addrs[i].size; j++) |
| 9060 | *p++ = REG_RD(bp, |
| 9061 | reg_addrs[i].addr + j*4); |
| 9062 | } |
| 9063 | } |
| 9064 | |
Eilon Greenstein | 0d28e49 | 2009-08-12 08:23:40 +0000 | [diff] [blame] | 9065 | #define PHY_FW_VER_LEN 10 |
| 9066 | |
| 9067 | static void bnx2x_get_drvinfo(struct net_device *dev, |
| 9068 | struct ethtool_drvinfo *info) |
| 9069 | { |
| 9070 | struct bnx2x *bp = netdev_priv(dev); |
| 9071 | u8 phy_fw_ver[PHY_FW_VER_LEN]; |
| 9072 | |
| 9073 | strcpy(info->driver, DRV_MODULE_NAME); |
| 9074 | strcpy(info->version, DRV_MODULE_VERSION); |
| 9075 | |
| 9076 | phy_fw_ver[0] = '\0'; |
| 9077 | if (bp->port.pmf) { |
| 9078 | bnx2x_acquire_phy_lock(bp); |
| 9079 | bnx2x_get_ext_phy_fw_version(&bp->link_params, |
| 9080 | (bp->state != BNX2X_STATE_CLOSED), |
| 9081 | phy_fw_ver, PHY_FW_VER_LEN); |
| 9082 | bnx2x_release_phy_lock(bp); |
| 9083 | } |
| 9084 | |
| 9085 | snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s", |
| 9086 | (bp->common.bc_ver & 0xff0000) >> 16, |
| 9087 | (bp->common.bc_ver & 0xff00) >> 8, |
| 9088 | (bp->common.bc_ver & 0xff), |
| 9089 | ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver); |
| 9090 | strcpy(info->bus_info, pci_name(bp->pdev)); |
| 9091 | info->n_stats = BNX2X_NUM_STATS; |
| 9092 | info->testinfo_len = BNX2X_NUM_TESTS; |
| 9093 | info->eedump_len = bp->common.flash_size; |
| 9094 | info->regdump_len = bnx2x_get_regs_len(dev); |
| 9095 | } |
| 9096 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9097 | static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9098 | { |
| 9099 | struct bnx2x *bp = netdev_priv(dev); |
| 9100 | |
| 9101 | if (bp->flags & NO_WOL_FLAG) { |
| 9102 | wol->supported = 0; |
| 9103 | wol->wolopts = 0; |
| 9104 | } else { |
| 9105 | wol->supported = WAKE_MAGIC; |
| 9106 | if (bp->wol) |
| 9107 | wol->wolopts = WAKE_MAGIC; |
| 9108 | else |
| 9109 | wol->wolopts = 0; |
| 9110 | } |
| 9111 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 9112 | } |
| 9113 | |
| 9114 | static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9115 | { |
| 9116 | struct bnx2x *bp = netdev_priv(dev); |
| 9117 | |
| 9118 | if (wol->wolopts & ~WAKE_MAGIC) |
| 9119 | return -EINVAL; |
| 9120 | |
| 9121 | if (wol->wolopts & WAKE_MAGIC) { |
| 9122 | if (bp->flags & NO_WOL_FLAG) |
| 9123 | return -EINVAL; |
| 9124 | |
| 9125 | bp->wol = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9126 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9127 | bp->wol = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9128 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9129 | return 0; |
| 9130 | } |
| 9131 | |
| 9132 | static u32 bnx2x_get_msglevel(struct net_device *dev) |
| 9133 | { |
| 9134 | struct bnx2x *bp = netdev_priv(dev); |
| 9135 | |
| 9136 | return bp->msglevel; |
| 9137 | } |
| 9138 | |
| 9139 | static void bnx2x_set_msglevel(struct net_device *dev, u32 level) |
| 9140 | { |
| 9141 | struct bnx2x *bp = netdev_priv(dev); |
| 9142 | |
| 9143 | if (capable(CAP_NET_ADMIN)) |
| 9144 | bp->msglevel = level; |
| 9145 | } |
| 9146 | |
| 9147 | static int bnx2x_nway_reset(struct net_device *dev) |
| 9148 | { |
| 9149 | struct bnx2x *bp = netdev_priv(dev); |
| 9150 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9151 | if (!bp->port.pmf) |
| 9152 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9153 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9154 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9155 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9156 | bnx2x_link_set(bp); |
| 9157 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9158 | |
| 9159 | return 0; |
| 9160 | } |
| 9161 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 9162 | static u32 bnx2x_get_link(struct net_device *dev) |
Naohiro Ooiwa | 01e5329 | 2009-06-30 12:44:19 -0700 | [diff] [blame] | 9163 | { |
| 9164 | struct bnx2x *bp = netdev_priv(dev); |
| 9165 | |
| 9166 | return bp->link_vars.link_up; |
| 9167 | } |
| 9168 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9169 | static int bnx2x_get_eeprom_len(struct net_device *dev) |
| 9170 | { |
| 9171 | struct bnx2x *bp = netdev_priv(dev); |
| 9172 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9173 | return bp->common.flash_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9174 | } |
| 9175 | |
| 9176 | static int bnx2x_acquire_nvram_lock(struct bnx2x *bp) |
| 9177 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9178 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9179 | int count, i; |
| 9180 | u32 val = 0; |
| 9181 | |
| 9182 | /* adjust timeout for emulation/FPGA */ |
| 9183 | count = NVRAM_TIMEOUT_COUNT; |
| 9184 | if (CHIP_REV_IS_SLOW(bp)) |
| 9185 | count *= 100; |
| 9186 | |
| 9187 | /* request access to nvram interface */ |
| 9188 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 9189 | (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port)); |
| 9190 | |
| 9191 | for (i = 0; i < count*10; i++) { |
| 9192 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 9193 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) |
| 9194 | break; |
| 9195 | |
| 9196 | udelay(5); |
| 9197 | } |
| 9198 | |
| 9199 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9200 | DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9201 | return -EBUSY; |
| 9202 | } |
| 9203 | |
| 9204 | return 0; |
| 9205 | } |
| 9206 | |
| 9207 | static int bnx2x_release_nvram_lock(struct bnx2x *bp) |
| 9208 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9209 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9210 | int count, i; |
| 9211 | u32 val = 0; |
| 9212 | |
| 9213 | /* adjust timeout for emulation/FPGA */ |
| 9214 | count = NVRAM_TIMEOUT_COUNT; |
| 9215 | if (CHIP_REV_IS_SLOW(bp)) |
| 9216 | count *= 100; |
| 9217 | |
| 9218 | /* relinquish nvram interface */ |
| 9219 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 9220 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port)); |
| 9221 | |
| 9222 | for (i = 0; i < count*10; i++) { |
| 9223 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 9224 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) |
| 9225 | break; |
| 9226 | |
| 9227 | udelay(5); |
| 9228 | } |
| 9229 | |
| 9230 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9231 | DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9232 | return -EBUSY; |
| 9233 | } |
| 9234 | |
| 9235 | return 0; |
| 9236 | } |
| 9237 | |
| 9238 | static void bnx2x_enable_nvram_access(struct bnx2x *bp) |
| 9239 | { |
| 9240 | u32 val; |
| 9241 | |
| 9242 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 9243 | |
| 9244 | /* enable both bits, even on read */ |
| 9245 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 9246 | (val | MCPR_NVM_ACCESS_ENABLE_EN | |
| 9247 | MCPR_NVM_ACCESS_ENABLE_WR_EN)); |
| 9248 | } |
| 9249 | |
| 9250 | static void bnx2x_disable_nvram_access(struct bnx2x *bp) |
| 9251 | { |
| 9252 | u32 val; |
| 9253 | |
| 9254 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 9255 | |
| 9256 | /* disable both bits, even after read */ |
| 9257 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 9258 | (val & ~(MCPR_NVM_ACCESS_ENABLE_EN | |
| 9259 | MCPR_NVM_ACCESS_ENABLE_WR_EN))); |
| 9260 | } |
| 9261 | |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9262 | static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9263 | u32 cmd_flags) |
| 9264 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 9265 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9266 | u32 val; |
| 9267 | |
| 9268 | /* build the command word */ |
| 9269 | cmd_flags |= MCPR_NVM_COMMAND_DOIT; |
| 9270 | |
| 9271 | /* need to clear DONE bit separately */ |
| 9272 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 9273 | |
| 9274 | /* address of the NVRAM to read from */ |
| 9275 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 9276 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 9277 | |
| 9278 | /* issue a read command */ |
| 9279 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 9280 | |
| 9281 | /* adjust timeout for emulation/FPGA */ |
| 9282 | count = NVRAM_TIMEOUT_COUNT; |
| 9283 | if (CHIP_REV_IS_SLOW(bp)) |
| 9284 | count *= 100; |
| 9285 | |
| 9286 | /* wait for completion */ |
| 9287 | *ret_val = 0; |
| 9288 | rc = -EBUSY; |
| 9289 | for (i = 0; i < count; i++) { |
| 9290 | udelay(5); |
| 9291 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 9292 | |
| 9293 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 9294 | val = REG_RD(bp, MCP_REG_MCPR_NVM_READ); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9295 | /* we read nvram data in cpu order |
| 9296 | * but ethtool sees it as an array of bytes |
| 9297 | * converting to big-endian will do the work */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9298 | *ret_val = cpu_to_be32(val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9299 | rc = 0; |
| 9300 | break; |
| 9301 | } |
| 9302 | } |
| 9303 | |
| 9304 | return rc; |
| 9305 | } |
| 9306 | |
| 9307 | static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf, |
| 9308 | int buf_size) |
| 9309 | { |
| 9310 | int rc; |
| 9311 | u32 cmd_flags; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9312 | __be32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9313 | |
| 9314 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9315 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 9316 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9317 | offset, buf_size); |
| 9318 | return -EINVAL; |
| 9319 | } |
| 9320 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9321 | if (offset + buf_size > bp->common.flash_size) { |
| 9322 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9323 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9324 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9325 | return -EINVAL; |
| 9326 | } |
| 9327 | |
| 9328 | /* request access to nvram interface */ |
| 9329 | rc = bnx2x_acquire_nvram_lock(bp); |
| 9330 | if (rc) |
| 9331 | return rc; |
| 9332 | |
| 9333 | /* enable access to nvram interface */ |
| 9334 | bnx2x_enable_nvram_access(bp); |
| 9335 | |
| 9336 | /* read the first word(s) */ |
| 9337 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 9338 | while ((buf_size > sizeof(u32)) && (rc == 0)) { |
| 9339 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 9340 | memcpy(ret_buf, &val, 4); |
| 9341 | |
| 9342 | /* advance to the next dword */ |
| 9343 | offset += sizeof(u32); |
| 9344 | ret_buf += sizeof(u32); |
| 9345 | buf_size -= sizeof(u32); |
| 9346 | cmd_flags = 0; |
| 9347 | } |
| 9348 | |
| 9349 | if (rc == 0) { |
| 9350 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 9351 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 9352 | memcpy(ret_buf, &val, 4); |
| 9353 | } |
| 9354 | |
| 9355 | /* disable access to nvram interface */ |
| 9356 | bnx2x_disable_nvram_access(bp); |
| 9357 | bnx2x_release_nvram_lock(bp); |
| 9358 | |
| 9359 | return rc; |
| 9360 | } |
| 9361 | |
| 9362 | static int bnx2x_get_eeprom(struct net_device *dev, |
| 9363 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 9364 | { |
| 9365 | struct bnx2x *bp = netdev_priv(dev); |
| 9366 | int rc; |
| 9367 | |
Eilon Greenstein | 2add3ac | 2009-01-14 06:44:07 +0000 | [diff] [blame] | 9368 | if (!netif_running(dev)) |
| 9369 | return -EAGAIN; |
| 9370 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9371 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9372 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 9373 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 9374 | eeprom->len, eeprom->len); |
| 9375 | |
| 9376 | /* parameters already validated in ethtool_get_eeprom */ |
| 9377 | |
| 9378 | rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len); |
| 9379 | |
| 9380 | return rc; |
| 9381 | } |
| 9382 | |
| 9383 | static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val, |
| 9384 | u32 cmd_flags) |
| 9385 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 9386 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9387 | |
| 9388 | /* build the command word */ |
| 9389 | cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR; |
| 9390 | |
| 9391 | /* need to clear DONE bit separately */ |
| 9392 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 9393 | |
| 9394 | /* write the data */ |
| 9395 | REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val); |
| 9396 | |
| 9397 | /* address of the NVRAM to write to */ |
| 9398 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 9399 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 9400 | |
| 9401 | /* issue the write command */ |
| 9402 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 9403 | |
| 9404 | /* adjust timeout for emulation/FPGA */ |
| 9405 | count = NVRAM_TIMEOUT_COUNT; |
| 9406 | if (CHIP_REV_IS_SLOW(bp)) |
| 9407 | count *= 100; |
| 9408 | |
| 9409 | /* wait for completion */ |
| 9410 | rc = -EBUSY; |
| 9411 | for (i = 0; i < count; i++) { |
| 9412 | udelay(5); |
| 9413 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 9414 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 9415 | rc = 0; |
| 9416 | break; |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | return rc; |
| 9421 | } |
| 9422 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 9423 | #define BYTE_OFFSET(offset) (8 * (offset & 0x03)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9424 | |
| 9425 | static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 9426 | int buf_size) |
| 9427 | { |
| 9428 | int rc; |
| 9429 | u32 cmd_flags; |
| 9430 | u32 align_offset; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 9431 | __be32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9432 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9433 | if (offset + buf_size > bp->common.flash_size) { |
| 9434 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9435 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9436 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9437 | return -EINVAL; |
| 9438 | } |
| 9439 | |
| 9440 | /* request access to nvram interface */ |
| 9441 | rc = bnx2x_acquire_nvram_lock(bp); |
| 9442 | if (rc) |
| 9443 | return rc; |
| 9444 | |
| 9445 | /* enable access to nvram interface */ |
| 9446 | bnx2x_enable_nvram_access(bp); |
| 9447 | |
| 9448 | cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST); |
| 9449 | align_offset = (offset & ~0x03); |
| 9450 | rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags); |
| 9451 | |
| 9452 | if (rc == 0) { |
| 9453 | val &= ~(0xff << BYTE_OFFSET(offset)); |
| 9454 | val |= (*data_buf << BYTE_OFFSET(offset)); |
| 9455 | |
| 9456 | /* nvram data is returned as an array of bytes |
| 9457 | * convert it back to cpu order */ |
| 9458 | val = be32_to_cpu(val); |
| 9459 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9460 | rc = bnx2x_nvram_write_dword(bp, align_offset, val, |
| 9461 | cmd_flags); |
| 9462 | } |
| 9463 | |
| 9464 | /* disable access to nvram interface */ |
| 9465 | bnx2x_disable_nvram_access(bp); |
| 9466 | bnx2x_release_nvram_lock(bp); |
| 9467 | |
| 9468 | return rc; |
| 9469 | } |
| 9470 | |
| 9471 | static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 9472 | int buf_size) |
| 9473 | { |
| 9474 | int rc; |
| 9475 | u32 cmd_flags; |
| 9476 | u32 val; |
| 9477 | u32 written_so_far; |
| 9478 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9479 | if (buf_size == 1) /* ethtool */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9480 | return bnx2x_nvram_write1(bp, offset, data_buf, buf_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9481 | |
| 9482 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9483 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 9484 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9485 | offset, buf_size); |
| 9486 | return -EINVAL; |
| 9487 | } |
| 9488 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9489 | if (offset + buf_size > bp->common.flash_size) { |
| 9490 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9491 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9492 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9493 | return -EINVAL; |
| 9494 | } |
| 9495 | |
| 9496 | /* request access to nvram interface */ |
| 9497 | rc = bnx2x_acquire_nvram_lock(bp); |
| 9498 | if (rc) |
| 9499 | return rc; |
| 9500 | |
| 9501 | /* enable access to nvram interface */ |
| 9502 | bnx2x_enable_nvram_access(bp); |
| 9503 | |
| 9504 | written_so_far = 0; |
| 9505 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 9506 | while ((written_so_far < buf_size) && (rc == 0)) { |
| 9507 | if (written_so_far == (buf_size - sizeof(u32))) |
| 9508 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 9509 | else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) |
| 9510 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 9511 | else if ((offset % NVRAM_PAGE_SIZE) == 0) |
| 9512 | cmd_flags |= MCPR_NVM_COMMAND_FIRST; |
| 9513 | |
| 9514 | memcpy(&val, data_buf, 4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9515 | |
| 9516 | rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags); |
| 9517 | |
| 9518 | /* advance to the next dword */ |
| 9519 | offset += sizeof(u32); |
| 9520 | data_buf += sizeof(u32); |
| 9521 | written_so_far += sizeof(u32); |
| 9522 | cmd_flags = 0; |
| 9523 | } |
| 9524 | |
| 9525 | /* disable access to nvram interface */ |
| 9526 | bnx2x_disable_nvram_access(bp); |
| 9527 | bnx2x_release_nvram_lock(bp); |
| 9528 | |
| 9529 | return rc; |
| 9530 | } |
| 9531 | |
| 9532 | static int bnx2x_set_eeprom(struct net_device *dev, |
| 9533 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 9534 | { |
| 9535 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | f57a602 | 2009-08-12 08:23:11 +0000 | [diff] [blame] | 9536 | int port = BP_PORT(bp); |
| 9537 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9538 | |
Eilon Greenstein | 9f4c958 | 2009-01-08 11:21:43 -0800 | [diff] [blame] | 9539 | if (!netif_running(dev)) |
| 9540 | return -EAGAIN; |
| 9541 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9542 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9543 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 9544 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 9545 | eeprom->len, eeprom->len); |
| 9546 | |
| 9547 | /* parameters already validated in ethtool_set_eeprom */ |
| 9548 | |
Eilon Greenstein | f57a602 | 2009-08-12 08:23:11 +0000 | [diff] [blame] | 9549 | /* PHY eeprom can be accessed only by the PMF */ |
| 9550 | if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) && |
| 9551 | !bp->port.pmf) |
| 9552 | return -EINVAL; |
| 9553 | |
| 9554 | if (eeprom->magic == 0x50485950) { |
| 9555 | /* 'PHYP' (0x50485950): prepare phy for FW upgrade */ |
| 9556 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 9557 | |
| 9558 | bnx2x_acquire_phy_lock(bp); |
| 9559 | rc |= bnx2x_link_reset(&bp->link_params, |
| 9560 | &bp->link_vars, 0); |
| 9561 | if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) == |
| 9562 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) |
| 9563 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0, |
| 9564 | MISC_REGISTERS_GPIO_HIGH, port); |
| 9565 | bnx2x_release_phy_lock(bp); |
| 9566 | bnx2x_link_report(bp); |
| 9567 | |
| 9568 | } else if (eeprom->magic == 0x50485952) { |
| 9569 | /* 'PHYR' (0x50485952): re-init link after FW upgrade */ |
| 9570 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 9571 | (bp->state == BNX2X_STATE_DISABLED)) { |
| 9572 | bnx2x_acquire_phy_lock(bp); |
| 9573 | rc |= bnx2x_link_reset(&bp->link_params, |
| 9574 | &bp->link_vars, 1); |
| 9575 | |
| 9576 | rc |= bnx2x_phy_init(&bp->link_params, |
| 9577 | &bp->link_vars); |
| 9578 | bnx2x_release_phy_lock(bp); |
| 9579 | bnx2x_calc_fc_adv(bp); |
| 9580 | } |
| 9581 | } else if (eeprom->magic == 0x53985943) { |
| 9582 | /* 'PHYC' (0x53985943): PHY FW upgrade completed */ |
| 9583 | if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) == |
| 9584 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) { |
| 9585 | u8 ext_phy_addr = |
Eilon Greenstein | 659bc5c | 2009-08-12 08:24:02 +0000 | [diff] [blame] | 9586 | XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config); |
Eilon Greenstein | f57a602 | 2009-08-12 08:23:11 +0000 | [diff] [blame] | 9587 | |
| 9588 | /* DSP Remove Download Mode */ |
| 9589 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0, |
| 9590 | MISC_REGISTERS_GPIO_LOW, port); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9591 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 9592 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9593 | |
Eilon Greenstein | f57a602 | 2009-08-12 08:23:11 +0000 | [diff] [blame] | 9594 | bnx2x_sfx7101_sp_sw_reset(bp, port, ext_phy_addr); |
| 9595 | |
| 9596 | /* wait 0.5 sec to allow it to run */ |
| 9597 | msleep(500); |
| 9598 | bnx2x_ext_phy_hw_reset(bp, port); |
| 9599 | msleep(500); |
| 9600 | bnx2x_release_phy_lock(bp); |
| 9601 | } |
| 9602 | } else |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9603 | rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9604 | |
| 9605 | return rc; |
| 9606 | } |
| 9607 | |
| 9608 | static int bnx2x_get_coalesce(struct net_device *dev, |
| 9609 | struct ethtool_coalesce *coal) |
| 9610 | { |
| 9611 | struct bnx2x *bp = netdev_priv(dev); |
| 9612 | |
| 9613 | memset(coal, 0, sizeof(struct ethtool_coalesce)); |
| 9614 | |
| 9615 | coal->rx_coalesce_usecs = bp->rx_ticks; |
| 9616 | coal->tx_coalesce_usecs = bp->tx_ticks; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9617 | |
| 9618 | return 0; |
| 9619 | } |
| 9620 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9621 | #define BNX2X_MAX_COALES_TOUT (0xf0*12) /* Maximal coalescing timeout in us */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9622 | static int bnx2x_set_coalesce(struct net_device *dev, |
| 9623 | struct ethtool_coalesce *coal) |
| 9624 | { |
| 9625 | struct bnx2x *bp = netdev_priv(dev); |
| 9626 | |
| 9627 | bp->rx_ticks = (u16) coal->rx_coalesce_usecs; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9628 | if (bp->rx_ticks > BNX2X_MAX_COALES_TOUT) |
| 9629 | bp->rx_ticks = BNX2X_MAX_COALES_TOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9630 | |
| 9631 | bp->tx_ticks = (u16) coal->tx_coalesce_usecs; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9632 | if (bp->tx_ticks > BNX2X_MAX_COALES_TOUT) |
| 9633 | bp->tx_ticks = BNX2X_MAX_COALES_TOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9634 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9635 | if (netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9636 | bnx2x_update_coalesce(bp); |
| 9637 | |
| 9638 | return 0; |
| 9639 | } |
| 9640 | |
| 9641 | static void bnx2x_get_ringparam(struct net_device *dev, |
| 9642 | struct ethtool_ringparam *ering) |
| 9643 | { |
| 9644 | struct bnx2x *bp = netdev_priv(dev); |
| 9645 | |
| 9646 | ering->rx_max_pending = MAX_RX_AVAIL; |
| 9647 | ering->rx_mini_max_pending = 0; |
| 9648 | ering->rx_jumbo_max_pending = 0; |
| 9649 | |
| 9650 | ering->rx_pending = bp->rx_ring_size; |
| 9651 | ering->rx_mini_pending = 0; |
| 9652 | ering->rx_jumbo_pending = 0; |
| 9653 | |
| 9654 | ering->tx_max_pending = MAX_TX_AVAIL; |
| 9655 | ering->tx_pending = bp->tx_ring_size; |
| 9656 | } |
| 9657 | |
| 9658 | static int bnx2x_set_ringparam(struct net_device *dev, |
| 9659 | struct ethtool_ringparam *ering) |
| 9660 | { |
| 9661 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9662 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9663 | |
| 9664 | if ((ering->rx_pending > MAX_RX_AVAIL) || |
| 9665 | (ering->tx_pending > MAX_TX_AVAIL) || |
| 9666 | (ering->tx_pending <= MAX_SKB_FRAGS + 4)) |
| 9667 | return -EINVAL; |
| 9668 | |
| 9669 | bp->rx_ring_size = ering->rx_pending; |
| 9670 | bp->tx_ring_size = ering->tx_pending; |
| 9671 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9672 | if (netif_running(dev)) { |
| 9673 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9674 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9675 | } |
| 9676 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9677 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9678 | } |
| 9679 | |
| 9680 | static void bnx2x_get_pauseparam(struct net_device *dev, |
| 9681 | struct ethtool_pauseparam *epause) |
| 9682 | { |
| 9683 | struct bnx2x *bp = netdev_priv(dev); |
| 9684 | |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 9685 | epause->autoneg = (bp->link_params.req_flow_ctrl == |
| 9686 | BNX2X_FLOW_CTRL_AUTO) && |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9687 | (bp->link_params.req_line_speed == SPEED_AUTO_NEG); |
| 9688 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9689 | epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) == |
| 9690 | BNX2X_FLOW_CTRL_RX); |
| 9691 | epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) == |
| 9692 | BNX2X_FLOW_CTRL_TX); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9693 | |
| 9694 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 9695 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 9696 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 9697 | } |
| 9698 | |
| 9699 | static int bnx2x_set_pauseparam(struct net_device *dev, |
| 9700 | struct ethtool_pauseparam *epause) |
| 9701 | { |
| 9702 | struct bnx2x *bp = netdev_priv(dev); |
| 9703 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9704 | if (IS_E1HMF(bp)) |
| 9705 | return 0; |
| 9706 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9707 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 9708 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 9709 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 9710 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9711 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9712 | |
| 9713 | if (epause->rx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9714 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9715 | |
| 9716 | if (epause->tx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9717 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9718 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9719 | if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) |
| 9720 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9721 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9722 | if (epause->autoneg) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9723 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 9724 | DP(NETIF_MSG_LINK, "autoneg not supported\n"); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 9725 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9726 | } |
| 9727 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9728 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 9729 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9730 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9731 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9732 | DP(NETIF_MSG_LINK, |
| 9733 | "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9734 | |
| 9735 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9736 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9737 | bnx2x_link_set(bp); |
| 9738 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9739 | |
| 9740 | return 0; |
| 9741 | } |
| 9742 | |
Vladislav Zolotarov | df0f2343 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9743 | static int bnx2x_set_flags(struct net_device *dev, u32 data) |
| 9744 | { |
| 9745 | struct bnx2x *bp = netdev_priv(dev); |
| 9746 | int changed = 0; |
| 9747 | int rc = 0; |
| 9748 | |
| 9749 | /* TPA requires Rx CSUM offloading */ |
| 9750 | if ((data & ETH_FLAG_LRO) && bp->rx_csum) { |
| 9751 | if (!(dev->features & NETIF_F_LRO)) { |
| 9752 | dev->features |= NETIF_F_LRO; |
| 9753 | bp->flags |= TPA_ENABLE_FLAG; |
| 9754 | changed = 1; |
| 9755 | } |
| 9756 | |
| 9757 | } else if (dev->features & NETIF_F_LRO) { |
| 9758 | dev->features &= ~NETIF_F_LRO; |
| 9759 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 9760 | changed = 1; |
| 9761 | } |
| 9762 | |
| 9763 | if (changed && netif_running(dev)) { |
| 9764 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9765 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
| 9766 | } |
| 9767 | |
| 9768 | return rc; |
| 9769 | } |
| 9770 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9771 | static u32 bnx2x_get_rx_csum(struct net_device *dev) |
| 9772 | { |
| 9773 | struct bnx2x *bp = netdev_priv(dev); |
| 9774 | |
| 9775 | return bp->rx_csum; |
| 9776 | } |
| 9777 | |
| 9778 | static int bnx2x_set_rx_csum(struct net_device *dev, u32 data) |
| 9779 | { |
| 9780 | struct bnx2x *bp = netdev_priv(dev); |
Vladislav Zolotarov | df0f2343 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9781 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9782 | |
| 9783 | bp->rx_csum = data; |
Vladislav Zolotarov | df0f2343 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 9784 | |
| 9785 | /* Disable TPA, when Rx CSUM is disabled. Otherwise all |
| 9786 | TPA'ed packets will be discarded due to wrong TCP CSUM */ |
| 9787 | if (!data) { |
| 9788 | u32 flags = ethtool_op_get_flags(dev); |
| 9789 | |
| 9790 | rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO)); |
| 9791 | } |
| 9792 | |
| 9793 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9794 | } |
| 9795 | |
| 9796 | static int bnx2x_set_tso(struct net_device *dev, u32 data) |
| 9797 | { |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9798 | if (data) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9799 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9800 | dev->features |= NETIF_F_TSO6; |
| 9801 | } else { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9802 | dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9803 | dev->features &= ~NETIF_F_TSO6; |
| 9804 | } |
| 9805 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9806 | return 0; |
| 9807 | } |
| 9808 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9809 | static const struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9810 | char string[ETH_GSTRING_LEN]; |
| 9811 | } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9812 | { "register_test (offline)" }, |
| 9813 | { "memory_test (offline)" }, |
| 9814 | { "loopback_test (offline)" }, |
| 9815 | { "nvram_test (online)" }, |
| 9816 | { "interrupt_test (online)" }, |
| 9817 | { "link_test (online)" }, |
Eilon Greenstein | d3d4f49 | 2009-02-12 08:36:27 +0000 | [diff] [blame] | 9818 | { "idle check (online)" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9819 | }; |
| 9820 | |
| 9821 | static int bnx2x_self_test_count(struct net_device *dev) |
| 9822 | { |
| 9823 | return BNX2X_NUM_TESTS; |
| 9824 | } |
| 9825 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9826 | static int bnx2x_test_registers(struct bnx2x *bp) |
| 9827 | { |
| 9828 | int idx, i, rc = -ENODEV; |
| 9829 | u32 wr_val = 0; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9830 | int port = BP_PORT(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9831 | static const struct { |
| 9832 | u32 offset0; |
| 9833 | u32 offset1; |
| 9834 | u32 mask; |
| 9835 | } reg_tbl[] = { |
| 9836 | /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff }, |
| 9837 | { DORQ_REG_DB_ADDR0, 4, 0xffffffff }, |
| 9838 | { HC_REG_AGG_INT_0, 4, 0x000003ff }, |
| 9839 | { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 }, |
| 9840 | { PBF_REG_P0_INIT_CRD, 4, 0x000007ff }, |
| 9841 | { PRS_REG_CID_PORT_0, 4, 0x00ffffff }, |
| 9842 | { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff }, |
| 9843 | { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 9844 | { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff }, |
| 9845 | { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 9846 | /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff }, |
| 9847 | { QM_REG_CONNNUM_0, 4, 0x000fffff }, |
| 9848 | { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff }, |
| 9849 | { SRC_REG_KEYRSS0_0, 40, 0xffffffff }, |
| 9850 | { SRC_REG_KEYRSS0_7, 40, 0xffffffff }, |
| 9851 | { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 }, |
| 9852 | { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 }, |
| 9853 | { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9854 | { NIG_REG_LLH0_T_BIT, 4, 0x00000001 }, |
Eilon Greenstein | c1f1a06 | 2009-07-29 00:20:08 +0000 | [diff] [blame] | 9855 | { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 }, |
| 9856 | /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9857 | { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 }, |
| 9858 | { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 }, |
| 9859 | { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 }, |
| 9860 | { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff }, |
| 9861 | { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff }, |
| 9862 | { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff }, |
| 9863 | { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff }, |
| 9864 | { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 }, |
Eilon Greenstein | c1f1a06 | 2009-07-29 00:20:08 +0000 | [diff] [blame] | 9865 | { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff }, |
| 9866 | /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9867 | { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff }, |
| 9868 | { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 }, |
| 9869 | { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 }, |
| 9870 | { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff }, |
| 9871 | { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 }, |
| 9872 | { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f }, |
| 9873 | |
| 9874 | { 0xffffffff, 0, 0x00000000 } |
| 9875 | }; |
| 9876 | |
| 9877 | if (!netif_running(bp->dev)) |
| 9878 | return rc; |
| 9879 | |
| 9880 | /* Repeat the test twice: |
| 9881 | First by writing 0x00000000, second by writing 0xffffffff */ |
| 9882 | for (idx = 0; idx < 2; idx++) { |
| 9883 | |
| 9884 | switch (idx) { |
| 9885 | case 0: |
| 9886 | wr_val = 0; |
| 9887 | break; |
| 9888 | case 1: |
| 9889 | wr_val = 0xffffffff; |
| 9890 | break; |
| 9891 | } |
| 9892 | |
| 9893 | for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) { |
| 9894 | u32 offset, mask, save_val, val; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9895 | |
| 9896 | offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1; |
| 9897 | mask = reg_tbl[i].mask; |
| 9898 | |
| 9899 | save_val = REG_RD(bp, offset); |
| 9900 | |
| 9901 | REG_WR(bp, offset, wr_val); |
| 9902 | val = REG_RD(bp, offset); |
| 9903 | |
| 9904 | /* Restore the original register's value */ |
| 9905 | REG_WR(bp, offset, save_val); |
| 9906 | |
| 9907 | /* verify that value is as expected value */ |
| 9908 | if ((val & mask) != (wr_val & mask)) |
| 9909 | goto test_reg_exit; |
| 9910 | } |
| 9911 | } |
| 9912 | |
| 9913 | rc = 0; |
| 9914 | |
| 9915 | test_reg_exit: |
| 9916 | return rc; |
| 9917 | } |
| 9918 | |
| 9919 | static int bnx2x_test_memory(struct bnx2x *bp) |
| 9920 | { |
| 9921 | int i, j, rc = -ENODEV; |
| 9922 | u32 val; |
| 9923 | static const struct { |
| 9924 | u32 offset; |
| 9925 | int size; |
| 9926 | } mem_tbl[] = { |
| 9927 | { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9928 | { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE }, |
| 9929 | { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE }, |
| 9930 | { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE }, |
| 9931 | { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9932 | { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9933 | { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9934 | |
| 9935 | { 0xffffffff, 0 } |
| 9936 | }; |
| 9937 | static const struct { |
| 9938 | char *name; |
| 9939 | u32 offset; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9940 | u32 e1_mask; |
| 9941 | u32 e1h_mask; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9942 | } prty_tbl[] = { |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9943 | { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9944 | { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 }, |
| 9945 | { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 }, |
| 9946 | { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9947 | { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9948 | { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9949 | |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9950 | { NULL, 0xffffffff, 0, 0 } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9951 | }; |
| 9952 | |
| 9953 | if (!netif_running(bp->dev)) |
| 9954 | return rc; |
| 9955 | |
| 9956 | /* Go through all the memories */ |
| 9957 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) |
| 9958 | for (j = 0; j < mem_tbl[i].size; j++) |
| 9959 | REG_RD(bp, mem_tbl[i].offset + j*4); |
| 9960 | |
| 9961 | /* Check the parity status */ |
| 9962 | for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) { |
| 9963 | val = REG_RD(bp, prty_tbl[i].offset); |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9964 | if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) || |
| 9965 | (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9966 | DP(NETIF_MSG_HW, |
| 9967 | "%s is 0x%x\n", prty_tbl[i].name, val); |
| 9968 | goto test_mem_exit; |
| 9969 | } |
| 9970 | } |
| 9971 | |
| 9972 | rc = 0; |
| 9973 | |
| 9974 | test_mem_exit: |
| 9975 | return rc; |
| 9976 | } |
| 9977 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9978 | static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up) |
| 9979 | { |
| 9980 | int cnt = 1000; |
| 9981 | |
| 9982 | if (link_up) |
| 9983 | while (bnx2x_link_test(bp) && cnt--) |
| 9984 | msleep(10); |
| 9985 | } |
| 9986 | |
| 9987 | static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up) |
| 9988 | { |
| 9989 | unsigned int pkt_size, num_pkts, i; |
| 9990 | struct sk_buff *skb; |
| 9991 | unsigned char *packet; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9992 | struct bnx2x_fastpath *fp_rx = &bp->fp[0]; |
| 9993 | struct bnx2x_fastpath *fp_tx = &bp->fp[bp->num_rx_queues]; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9994 | u16 tx_start_idx, tx_idx; |
| 9995 | u16 rx_start_idx, rx_idx; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9996 | u16 pkt_prod, bd_prod; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9997 | struct sw_tx_bd *tx_buf; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 9998 | struct eth_tx_start_bd *tx_start_bd; |
| 9999 | struct eth_tx_parse_bd *pbd = NULL; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10000 | dma_addr_t mapping; |
| 10001 | union eth_rx_cqe *cqe; |
| 10002 | u8 cqe_fp_flags; |
| 10003 | struct sw_rx_bd *rx_buf; |
| 10004 | u16 len; |
| 10005 | int rc = -ENODEV; |
| 10006 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10007 | /* check the loopback mode */ |
| 10008 | switch (loopback_mode) { |
| 10009 | case BNX2X_PHY_LOOPBACK: |
| 10010 | if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10) |
| 10011 | return -EINVAL; |
| 10012 | break; |
| 10013 | case BNX2X_MAC_LOOPBACK: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10014 | bp->link_params.loopback_mode = LOOPBACK_BMAC; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10015 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10016 | break; |
| 10017 | default: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10018 | return -EINVAL; |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10019 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10020 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10021 | /* prepare the loopback packet */ |
| 10022 | pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ? |
| 10023 | bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10024 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 10025 | if (!skb) { |
| 10026 | rc = -ENOMEM; |
| 10027 | goto test_loopback_exit; |
| 10028 | } |
| 10029 | packet = skb_put(skb, pkt_size); |
| 10030 | memcpy(packet, bp->dev->dev_addr, ETH_ALEN); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10031 | memset(packet + ETH_ALEN, 0, ETH_ALEN); |
| 10032 | memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN)); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10033 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 10034 | packet[i] = (unsigned char) (i & 0xff); |
| 10035 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10036 | /* send the loopback packet */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10037 | num_pkts = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10038 | tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb); |
| 10039 | rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10040 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10041 | pkt_prod = fp_tx->tx_pkt_prod++; |
| 10042 | tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)]; |
| 10043 | tx_buf->first_bd = fp_tx->tx_bd_prod; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10044 | tx_buf->skb = skb; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10045 | tx_buf->flags = 0; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10046 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10047 | bd_prod = TX_BD(fp_tx->tx_bd_prod); |
| 10048 | tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10049 | mapping = pci_map_single(bp->pdev, skb->data, |
| 10050 | skb_headlen(skb), PCI_DMA_TODEVICE); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10051 | tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10052 | tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 10053 | tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */ |
| 10054 | tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 10055 | tx_start_bd->vlan = cpu_to_le16(pkt_prod); |
| 10056 | tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; |
| 10057 | tx_start_bd->general_data = ((UNICAST_ADDRESS << |
| 10058 | ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1); |
| 10059 | |
| 10060 | /* turn on parsing and get a BD */ |
| 10061 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10062 | pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd; |
| 10063 | |
| 10064 | memset(pbd, 0, sizeof(struct eth_tx_parse_bd)); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10065 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 10066 | wmb(); |
| 10067 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10068 | fp_tx->tx_db.data.prod += 2; |
| 10069 | barrier(); |
| 10070 | DOORBELL(bp, fp_tx->index - bp->num_rx_queues, fp_tx->tx_db.raw); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10071 | |
| 10072 | mmiowb(); |
| 10073 | |
| 10074 | num_pkts++; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10075 | fp_tx->tx_bd_prod += 2; /* start + pbd */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10076 | bp->dev->trans_start = jiffies; |
| 10077 | |
| 10078 | udelay(100); |
| 10079 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10080 | tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10081 | if (tx_idx != tx_start_idx + num_pkts) |
| 10082 | goto test_loopback_exit; |
| 10083 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10084 | rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10085 | if (rx_idx != rx_start_idx + num_pkts) |
| 10086 | goto test_loopback_exit; |
| 10087 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10088 | cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)]; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10089 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
| 10090 | if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS)) |
| 10091 | goto test_loopback_rx_exit; |
| 10092 | |
| 10093 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 10094 | if (len != pkt_size) |
| 10095 | goto test_loopback_rx_exit; |
| 10096 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10097 | rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)]; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10098 | skb = rx_buf->skb; |
| 10099 | skb_reserve(skb, cqe->fast_path_cqe.placement_offset); |
| 10100 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 10101 | if (*(skb->data + i) != (unsigned char) (i & 0xff)) |
| 10102 | goto test_loopback_rx_exit; |
| 10103 | |
| 10104 | rc = 0; |
| 10105 | |
| 10106 | test_loopback_rx_exit: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10107 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10108 | fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons); |
| 10109 | fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod); |
| 10110 | fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons); |
| 10111 | fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10112 | |
| 10113 | /* Update producers */ |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10114 | bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod, |
| 10115 | fp_rx->rx_sge_prod); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10116 | |
| 10117 | test_loopback_exit: |
| 10118 | bp->link_params.loopback_mode = LOOPBACK_NONE; |
| 10119 | |
| 10120 | return rc; |
| 10121 | } |
| 10122 | |
| 10123 | static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up) |
| 10124 | { |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10125 | int rc = 0, res; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10126 | |
| 10127 | if (!netif_running(bp->dev)) |
| 10128 | return BNX2X_LOOPBACK_FAILED; |
| 10129 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10130 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 10131 | bnx2x_acquire_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10132 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10133 | res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up); |
| 10134 | if (res) { |
| 10135 | DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res); |
| 10136 | rc |= BNX2X_PHY_LOOPBACK_FAILED; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10137 | } |
| 10138 | |
Eilon Greenstein | b5bf906 | 2009-02-12 08:38:08 +0000 | [diff] [blame] | 10139 | res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up); |
| 10140 | if (res) { |
| 10141 | DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res); |
| 10142 | rc |= BNX2X_MAC_LOOPBACK_FAILED; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10143 | } |
| 10144 | |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 10145 | bnx2x_release_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10146 | bnx2x_netif_start(bp); |
| 10147 | |
| 10148 | return rc; |
| 10149 | } |
| 10150 | |
| 10151 | #define CRC32_RESIDUAL 0xdebb20e3 |
| 10152 | |
| 10153 | static int bnx2x_test_nvram(struct bnx2x *bp) |
| 10154 | { |
| 10155 | static const struct { |
| 10156 | int offset; |
| 10157 | int size; |
| 10158 | } nvram_tbl[] = { |
| 10159 | { 0, 0x14 }, /* bootstrap */ |
| 10160 | { 0x14, 0xec }, /* dir */ |
| 10161 | { 0x100, 0x350 }, /* manuf_info */ |
| 10162 | { 0x450, 0xf0 }, /* feature_info */ |
| 10163 | { 0x640, 0x64 }, /* upgrade_key_info */ |
| 10164 | { 0x6a4, 0x64 }, |
| 10165 | { 0x708, 0x70 }, /* manuf_key_info */ |
| 10166 | { 0x778, 0x70 }, |
| 10167 | { 0, 0 } |
| 10168 | }; |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10169 | __be32 buf[0x350 / 4]; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10170 | u8 *data = (u8 *)buf; |
| 10171 | int i, rc; |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 10172 | u32 magic, crc; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10173 | |
| 10174 | rc = bnx2x_nvram_read(bp, 0, data, 4); |
| 10175 | if (rc) { |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 10176 | DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10177 | goto test_nvram_exit; |
| 10178 | } |
| 10179 | |
| 10180 | magic = be32_to_cpu(buf[0]); |
| 10181 | if (magic != 0x669955aa) { |
| 10182 | DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic); |
| 10183 | rc = -ENODEV; |
| 10184 | goto test_nvram_exit; |
| 10185 | } |
| 10186 | |
| 10187 | for (i = 0; nvram_tbl[i].size; i++) { |
| 10188 | |
| 10189 | rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data, |
| 10190 | nvram_tbl[i].size); |
| 10191 | if (rc) { |
| 10192 | DP(NETIF_MSG_PROBE, |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 10193 | "nvram_tbl[%d] read data (rc %d)\n", i, rc); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10194 | goto test_nvram_exit; |
| 10195 | } |
| 10196 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 10197 | crc = ether_crc_le(nvram_tbl[i].size, data); |
| 10198 | if (crc != CRC32_RESIDUAL) { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10199 | DP(NETIF_MSG_PROBE, |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 10200 | "nvram_tbl[%d] crc value (0x%08x)\n", i, crc); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10201 | rc = -ENODEV; |
| 10202 | goto test_nvram_exit; |
| 10203 | } |
| 10204 | } |
| 10205 | |
| 10206 | test_nvram_exit: |
| 10207 | return rc; |
| 10208 | } |
| 10209 | |
| 10210 | static int bnx2x_test_intr(struct bnx2x *bp) |
| 10211 | { |
| 10212 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
| 10213 | int i, rc; |
| 10214 | |
| 10215 | if (!netif_running(bp->dev)) |
| 10216 | return -ENODEV; |
| 10217 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10218 | config->hdr.length = 0; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 10219 | if (CHIP_IS_E1(bp)) |
| 10220 | config->hdr.offset = (BP_PORT(bp) ? 32 : 0); |
| 10221 | else |
| 10222 | config->hdr.offset = BP_FUNC(bp); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10223 | config->hdr.client_id = bp->fp->cl_id; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10224 | config->hdr.reserved1 = 0; |
| 10225 | |
| 10226 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 10227 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 10228 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 10229 | if (rc == 0) { |
| 10230 | bp->set_mac_pending++; |
| 10231 | for (i = 0; i < 10; i++) { |
| 10232 | if (!bp->set_mac_pending) |
| 10233 | break; |
| 10234 | msleep_interruptible(10); |
| 10235 | } |
| 10236 | if (i == 10) |
| 10237 | rc = -ENODEV; |
| 10238 | } |
| 10239 | |
| 10240 | return rc; |
| 10241 | } |
| 10242 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10243 | static void bnx2x_self_test(struct net_device *dev, |
| 10244 | struct ethtool_test *etest, u64 *buf) |
| 10245 | { |
| 10246 | struct bnx2x *bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10247 | |
| 10248 | memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS); |
| 10249 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10250 | if (!netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10251 | return; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10252 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10253 | /* offline tests are not supported in MF mode */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10254 | if (IS_E1HMF(bp)) |
| 10255 | etest->flags &= ~ETH_TEST_FL_OFFLINE; |
| 10256 | |
| 10257 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Eilon Greenstein | 279abdf | 2009-07-21 05:47:22 +0000 | [diff] [blame] | 10258 | int port = BP_PORT(bp); |
| 10259 | u32 val; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10260 | u8 link_up; |
| 10261 | |
Eilon Greenstein | 279abdf | 2009-07-21 05:47:22 +0000 | [diff] [blame] | 10262 | /* save current value of input enable for TX port IF */ |
| 10263 | val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4); |
| 10264 | /* disable input for TX port IF */ |
| 10265 | REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0); |
| 10266 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10267 | link_up = bp->link_vars.link_up; |
| 10268 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 10269 | bnx2x_nic_load(bp, LOAD_DIAG); |
| 10270 | /* wait until link state is restored */ |
| 10271 | bnx2x_wait_for_link(bp, link_up); |
| 10272 | |
| 10273 | if (bnx2x_test_registers(bp) != 0) { |
| 10274 | buf[0] = 1; |
| 10275 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10276 | } |
| 10277 | if (bnx2x_test_memory(bp) != 0) { |
| 10278 | buf[1] = 1; |
| 10279 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10280 | } |
| 10281 | buf[2] = bnx2x_test_loopback(bp, link_up); |
| 10282 | if (buf[2] != 0) |
| 10283 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10284 | |
| 10285 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
Eilon Greenstein | 279abdf | 2009-07-21 05:47:22 +0000 | [diff] [blame] | 10286 | |
| 10287 | /* restore input for TX port IF */ |
| 10288 | REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val); |
| 10289 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10290 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 10291 | /* wait until link state is restored */ |
| 10292 | bnx2x_wait_for_link(bp, link_up); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10293 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10294 | if (bnx2x_test_nvram(bp) != 0) { |
| 10295 | buf[3] = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10296 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10297 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10298 | if (bnx2x_test_intr(bp) != 0) { |
| 10299 | buf[4] = 1; |
| 10300 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10301 | } |
| 10302 | if (bp->port.pmf) |
| 10303 | if (bnx2x_link_test(bp) != 0) { |
| 10304 | buf[5] = 1; |
| 10305 | etest->flags |= ETH_TEST_FL_FAILED; |
| 10306 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 10307 | |
| 10308 | #ifdef BNX2X_EXTRA_DEBUG |
| 10309 | bnx2x_panic_dump(bp); |
| 10310 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10311 | } |
| 10312 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10313 | static const struct { |
| 10314 | long offset; |
| 10315 | int size; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10316 | u8 string[ETH_GSTRING_LEN]; |
| 10317 | } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = { |
| 10318 | /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" }, |
| 10319 | { Q_STATS_OFFSET32(error_bytes_received_hi), |
| 10320 | 8, "[%d]: rx_error_bytes" }, |
| 10321 | { Q_STATS_OFFSET32(total_unicast_packets_received_hi), |
| 10322 | 8, "[%d]: rx_ucast_packets" }, |
| 10323 | { Q_STATS_OFFSET32(total_multicast_packets_received_hi), |
| 10324 | 8, "[%d]: rx_mcast_packets" }, |
| 10325 | { Q_STATS_OFFSET32(total_broadcast_packets_received_hi), |
| 10326 | 8, "[%d]: rx_bcast_packets" }, |
| 10327 | { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" }, |
| 10328 | { Q_STATS_OFFSET32(rx_err_discard_pkt), |
| 10329 | 4, "[%d]: rx_phy_ip_err_discards"}, |
| 10330 | { Q_STATS_OFFSET32(rx_skb_alloc_failed), |
| 10331 | 4, "[%d]: rx_skb_alloc_discard" }, |
| 10332 | { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" }, |
| 10333 | |
| 10334 | /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" }, |
| 10335 | { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 10336 | 8, "[%d]: tx_packets" } |
| 10337 | }; |
| 10338 | |
| 10339 | static const struct { |
| 10340 | long offset; |
| 10341 | int size; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10342 | u32 flags; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10343 | #define STATS_FLAGS_PORT 1 |
| 10344 | #define STATS_FLAGS_FUNC 2 |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10345 | #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10346 | u8 string[ETH_GSTRING_LEN]; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10347 | } bnx2x_stats_arr[BNX2X_NUM_STATS] = { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10348 | /* 1 */ { STATS_OFFSET32(total_bytes_received_hi), |
| 10349 | 8, STATS_FLAGS_BOTH, "rx_bytes" }, |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10350 | { STATS_OFFSET32(error_bytes_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10351 | 8, STATS_FLAGS_BOTH, "rx_error_bytes" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10352 | { STATS_OFFSET32(total_unicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10353 | 8, STATS_FLAGS_BOTH, "rx_ucast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10354 | { STATS_OFFSET32(total_multicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10355 | 8, STATS_FLAGS_BOTH, "rx_mcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10356 | { STATS_OFFSET32(total_broadcast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10357 | 8, STATS_FLAGS_BOTH, "rx_bcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10358 | { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10359 | 8, STATS_FLAGS_PORT, "rx_crc_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10360 | { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10361 | 8, STATS_FLAGS_PORT, "rx_align_errors" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10362 | { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi), |
| 10363 | 8, STATS_FLAGS_PORT, "rx_undersize_packets" }, |
| 10364 | { STATS_OFFSET32(etherstatsoverrsizepkts_hi), |
| 10365 | 8, STATS_FLAGS_PORT, "rx_oversize_packets" }, |
| 10366 | /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi), |
| 10367 | 8, STATS_FLAGS_PORT, "rx_fragments" }, |
| 10368 | { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi), |
| 10369 | 8, STATS_FLAGS_PORT, "rx_jabbers" }, |
| 10370 | { STATS_OFFSET32(no_buff_discard_hi), |
| 10371 | 8, STATS_FLAGS_BOTH, "rx_discards" }, |
| 10372 | { STATS_OFFSET32(mac_filter_discard), |
| 10373 | 4, STATS_FLAGS_PORT, "rx_filtered_packets" }, |
| 10374 | { STATS_OFFSET32(xxoverflow_discard), |
| 10375 | 4, STATS_FLAGS_PORT, "rx_fw_discards" }, |
| 10376 | { STATS_OFFSET32(brb_drop_hi), |
| 10377 | 8, STATS_FLAGS_PORT, "rx_brb_discard" }, |
| 10378 | { STATS_OFFSET32(brb_truncate_hi), |
| 10379 | 8, STATS_FLAGS_PORT, "rx_brb_truncate" }, |
| 10380 | { STATS_OFFSET32(pause_frames_received_hi), |
| 10381 | 8, STATS_FLAGS_PORT, "rx_pause_frames" }, |
| 10382 | { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi), |
| 10383 | 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" }, |
| 10384 | { STATS_OFFSET32(nig_timer_max), |
| 10385 | 4, STATS_FLAGS_PORT, "rx_constant_pause_events" }, |
| 10386 | /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt), |
| 10387 | 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"}, |
| 10388 | { STATS_OFFSET32(rx_skb_alloc_failed), |
| 10389 | 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" }, |
| 10390 | { STATS_OFFSET32(hw_csum_err), |
| 10391 | 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" }, |
| 10392 | |
| 10393 | { STATS_OFFSET32(total_bytes_transmitted_hi), |
| 10394 | 8, STATS_FLAGS_BOTH, "tx_bytes" }, |
| 10395 | { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi), |
| 10396 | 8, STATS_FLAGS_PORT, "tx_error_bytes" }, |
| 10397 | { STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 10398 | 8, STATS_FLAGS_BOTH, "tx_packets" }, |
| 10399 | { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi), |
| 10400 | 8, STATS_FLAGS_PORT, "tx_mac_errors" }, |
| 10401 | { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi), |
| 10402 | 8, STATS_FLAGS_PORT, "tx_carrier_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10403 | { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10404 | 8, STATS_FLAGS_PORT, "tx_single_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10405 | { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10406 | 8, STATS_FLAGS_PORT, "tx_multi_collisions" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10407 | /* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10408 | 8, STATS_FLAGS_PORT, "tx_deferred" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10409 | { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10410 | 8, STATS_FLAGS_PORT, "tx_excess_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10411 | { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10412 | 8, STATS_FLAGS_PORT, "tx_late_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10413 | { STATS_OFFSET32(tx_stat_etherstatscollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10414 | 8, STATS_FLAGS_PORT, "tx_total_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10415 | { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10416 | 8, STATS_FLAGS_PORT, "tx_64_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10417 | { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10418 | 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10419 | { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10420 | 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10421 | { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10422 | 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10423 | { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10424 | 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10425 | { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10426 | 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10427 | /* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10428 | 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10429 | { STATS_OFFSET32(pause_frames_sent_hi), |
| 10430 | 8, STATS_FLAGS_PORT, "tx_pause_frames" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10431 | }; |
| 10432 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10433 | #define IS_PORT_STAT(i) \ |
| 10434 | ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT) |
| 10435 | #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC) |
| 10436 | #define IS_E1HMF_MODE_STAT(bp) \ |
| 10437 | (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS)) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 10438 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10439 | static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
| 10440 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10441 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10442 | int i, j, k; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10443 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10444 | switch (stringset) { |
| 10445 | case ETH_SS_STATS: |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10446 | if (is_multi(bp)) { |
| 10447 | k = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10448 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10449 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) |
| 10450 | sprintf(buf + (k + j)*ETH_GSTRING_LEN, |
| 10451 | bnx2x_q_stats_arr[j].string, i); |
| 10452 | k += BNX2X_NUM_Q_STATS; |
| 10453 | } |
| 10454 | if (IS_E1HMF_MODE_STAT(bp)) |
| 10455 | break; |
| 10456 | for (j = 0; j < BNX2X_NUM_STATS; j++) |
| 10457 | strcpy(buf + (k + j)*ETH_GSTRING_LEN, |
| 10458 | bnx2x_stats_arr[j].string); |
| 10459 | } else { |
| 10460 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 10461 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 10462 | continue; |
| 10463 | strcpy(buf + j*ETH_GSTRING_LEN, |
| 10464 | bnx2x_stats_arr[i].string); |
| 10465 | j++; |
| 10466 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10467 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10468 | break; |
| 10469 | |
| 10470 | case ETH_SS_TEST: |
| 10471 | memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr)); |
| 10472 | break; |
| 10473 | } |
| 10474 | } |
| 10475 | |
| 10476 | static int bnx2x_get_stats_count(struct net_device *dev) |
| 10477 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10478 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10479 | int i, num_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10480 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10481 | if (is_multi(bp)) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10482 | num_stats = BNX2X_NUM_Q_STATS * bp->num_rx_queues; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10483 | if (!IS_E1HMF_MODE_STAT(bp)) |
| 10484 | num_stats += BNX2X_NUM_STATS; |
| 10485 | } else { |
| 10486 | if (IS_E1HMF_MODE_STAT(bp)) { |
| 10487 | num_stats = 0; |
| 10488 | for (i = 0; i < BNX2X_NUM_STATS; i++) |
| 10489 | if (IS_FUNC_STAT(i)) |
| 10490 | num_stats++; |
| 10491 | } else |
| 10492 | num_stats = BNX2X_NUM_STATS; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10493 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10494 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10495 | return num_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10496 | } |
| 10497 | |
| 10498 | static void bnx2x_get_ethtool_stats(struct net_device *dev, |
| 10499 | struct ethtool_stats *stats, u64 *buf) |
| 10500 | { |
| 10501 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10502 | u32 *hw_stats, *offset; |
| 10503 | int i, j, k; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10504 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10505 | if (is_multi(bp)) { |
| 10506 | k = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10507 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10508 | hw_stats = (u32 *)&bp->fp[i].eth_q_stats; |
| 10509 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) { |
| 10510 | if (bnx2x_q_stats_arr[j].size == 0) { |
| 10511 | /* skip this counter */ |
| 10512 | buf[k + j] = 0; |
| 10513 | continue; |
| 10514 | } |
| 10515 | offset = (hw_stats + |
| 10516 | bnx2x_q_stats_arr[j].offset); |
| 10517 | if (bnx2x_q_stats_arr[j].size == 4) { |
| 10518 | /* 4-byte counter */ |
| 10519 | buf[k + j] = (u64) *offset; |
| 10520 | continue; |
| 10521 | } |
| 10522 | /* 8-byte counter */ |
| 10523 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
| 10524 | } |
| 10525 | k += BNX2X_NUM_Q_STATS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10526 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10527 | if (IS_E1HMF_MODE_STAT(bp)) |
| 10528 | return; |
| 10529 | hw_stats = (u32 *)&bp->eth_stats; |
| 10530 | for (j = 0; j < BNX2X_NUM_STATS; j++) { |
| 10531 | if (bnx2x_stats_arr[j].size == 0) { |
| 10532 | /* skip this counter */ |
| 10533 | buf[k + j] = 0; |
| 10534 | continue; |
| 10535 | } |
| 10536 | offset = (hw_stats + bnx2x_stats_arr[j].offset); |
| 10537 | if (bnx2x_stats_arr[j].size == 4) { |
| 10538 | /* 4-byte counter */ |
| 10539 | buf[k + j] = (u64) *offset; |
| 10540 | continue; |
| 10541 | } |
| 10542 | /* 8-byte counter */ |
| 10543 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10544 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10545 | } else { |
| 10546 | hw_stats = (u32 *)&bp->eth_stats; |
| 10547 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 10548 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 10549 | continue; |
| 10550 | if (bnx2x_stats_arr[i].size == 0) { |
| 10551 | /* skip this counter */ |
| 10552 | buf[j] = 0; |
| 10553 | j++; |
| 10554 | continue; |
| 10555 | } |
| 10556 | offset = (hw_stats + bnx2x_stats_arr[i].offset); |
| 10557 | if (bnx2x_stats_arr[i].size == 4) { |
| 10558 | /* 4-byte counter */ |
| 10559 | buf[j] = (u64) *offset; |
| 10560 | j++; |
| 10561 | continue; |
| 10562 | } |
| 10563 | /* 8-byte counter */ |
| 10564 | buf[j] = HILO_U64(*offset, *(offset + 1)); |
| 10565 | j++; |
| 10566 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10567 | } |
| 10568 | } |
| 10569 | |
| 10570 | static int bnx2x_phys_id(struct net_device *dev, u32 data) |
| 10571 | { |
| 10572 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10573 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10574 | int i; |
| 10575 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10576 | if (!netif_running(dev)) |
| 10577 | return 0; |
| 10578 | |
| 10579 | if (!bp->port.pmf) |
| 10580 | return 0; |
| 10581 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10582 | if (data == 0) |
| 10583 | data = 2; |
| 10584 | |
| 10585 | for (i = 0; i < (data * 2); i++) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10586 | if ((i % 2) == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10587 | bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10588 | bp->link_params.hw_led_mode, |
| 10589 | bp->link_params.chip_id); |
| 10590 | else |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10591 | bnx2x_set_led(bp, port, LED_MODE_OFF, 0, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10592 | bp->link_params.hw_led_mode, |
| 10593 | bp->link_params.chip_id); |
| 10594 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10595 | msleep_interruptible(500); |
| 10596 | if (signal_pending(current)) |
| 10597 | break; |
| 10598 | } |
| 10599 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10600 | if (bp->link_vars.link_up) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10601 | bnx2x_set_led(bp, port, LED_MODE_OPER, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10602 | bp->link_vars.line_speed, |
| 10603 | bp->link_params.hw_led_mode, |
| 10604 | bp->link_params.chip_id); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10605 | |
| 10606 | return 0; |
| 10607 | } |
| 10608 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame^] | 10609 | static const struct ethtool_ops bnx2x_ethtool_ops = { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 10610 | .get_settings = bnx2x_get_settings, |
| 10611 | .set_settings = bnx2x_set_settings, |
| 10612 | .get_drvinfo = bnx2x_get_drvinfo, |
Eilon Greenstein | 0a64ea5 | 2009-03-02 08:01:12 +0000 | [diff] [blame] | 10613 | .get_regs_len = bnx2x_get_regs_len, |
| 10614 | .get_regs = bnx2x_get_regs, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10615 | .get_wol = bnx2x_get_wol, |
| 10616 | .set_wol = bnx2x_set_wol, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 10617 | .get_msglevel = bnx2x_get_msglevel, |
| 10618 | .set_msglevel = bnx2x_set_msglevel, |
| 10619 | .nway_reset = bnx2x_nway_reset, |
Naohiro Ooiwa | 01e5329 | 2009-06-30 12:44:19 -0700 | [diff] [blame] | 10620 | .get_link = bnx2x_get_link, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 10621 | .get_eeprom_len = bnx2x_get_eeprom_len, |
| 10622 | .get_eeprom = bnx2x_get_eeprom, |
| 10623 | .set_eeprom = bnx2x_set_eeprom, |
| 10624 | .get_coalesce = bnx2x_get_coalesce, |
| 10625 | .set_coalesce = bnx2x_set_coalesce, |
| 10626 | .get_ringparam = bnx2x_get_ringparam, |
| 10627 | .set_ringparam = bnx2x_set_ringparam, |
| 10628 | .get_pauseparam = bnx2x_get_pauseparam, |
| 10629 | .set_pauseparam = bnx2x_set_pauseparam, |
| 10630 | .get_rx_csum = bnx2x_get_rx_csum, |
| 10631 | .set_rx_csum = bnx2x_set_rx_csum, |
| 10632 | .get_tx_csum = ethtool_op_get_tx_csum, |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10633 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 10634 | .set_flags = bnx2x_set_flags, |
| 10635 | .get_flags = ethtool_op_get_flags, |
| 10636 | .get_sg = ethtool_op_get_sg, |
| 10637 | .set_sg = ethtool_op_set_sg, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10638 | .get_tso = ethtool_op_get_tso, |
| 10639 | .set_tso = bnx2x_set_tso, |
| 10640 | .self_test_count = bnx2x_self_test_count, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 10641 | .self_test = bnx2x_self_test, |
| 10642 | .get_strings = bnx2x_get_strings, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10643 | .phys_id = bnx2x_phys_id, |
| 10644 | .get_stats_count = bnx2x_get_stats_count, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10645 | .get_ethtool_stats = bnx2x_get_ethtool_stats, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10646 | }; |
| 10647 | |
| 10648 | /* end of ethtool_ops */ |
| 10649 | |
| 10650 | /**************************************************************************** |
| 10651 | * General service functions |
| 10652 | ****************************************************************************/ |
| 10653 | |
| 10654 | static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state) |
| 10655 | { |
| 10656 | u16 pmcsr; |
| 10657 | |
| 10658 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 10659 | |
| 10660 | switch (state) { |
| 10661 | case PCI_D0: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10662 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10663 | ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) | |
| 10664 | PCI_PM_CTRL_PME_STATUS)); |
| 10665 | |
| 10666 | if (pmcsr & PCI_PM_CTRL_STATE_MASK) |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10667 | /* delay required during transition out of D3hot */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10668 | msleep(20); |
| 10669 | break; |
| 10670 | |
| 10671 | case PCI_D3hot: |
| 10672 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 10673 | pmcsr |= 3; |
| 10674 | |
| 10675 | if (bp->wol) |
| 10676 | pmcsr |= PCI_PM_CTRL_PME_ENABLE; |
| 10677 | |
| 10678 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
| 10679 | pmcsr); |
| 10680 | |
| 10681 | /* No more memory access after this point until |
| 10682 | * device is brought back to D0. |
| 10683 | */ |
| 10684 | break; |
| 10685 | |
| 10686 | default: |
| 10687 | return -EINVAL; |
| 10688 | } |
| 10689 | return 0; |
| 10690 | } |
| 10691 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 10692 | static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp) |
| 10693 | { |
| 10694 | u16 rx_cons_sb; |
| 10695 | |
| 10696 | /* Tell compiler that status block fields can change */ |
| 10697 | barrier(); |
| 10698 | rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb); |
| 10699 | if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 10700 | rx_cons_sb++; |
| 10701 | return (fp->rx_comp_cons != rx_cons_sb); |
| 10702 | } |
| 10703 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10704 | /* |
| 10705 | * net_device service functions |
| 10706 | */ |
| 10707 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10708 | static int bnx2x_poll(struct napi_struct *napi, int budget) |
| 10709 | { |
| 10710 | struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath, |
| 10711 | napi); |
| 10712 | struct bnx2x *bp = fp->bp; |
| 10713 | int work_done = 0; |
| 10714 | |
| 10715 | #ifdef BNX2X_STOP_ON_ERROR |
| 10716 | if (unlikely(bp->panic)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10717 | goto poll_panic; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10718 | #endif |
| 10719 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10720 | prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb); |
| 10721 | prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256); |
| 10722 | |
| 10723 | bnx2x_update_fpsb_idx(fp); |
| 10724 | |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10725 | if (bnx2x_has_rx_work(fp)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10726 | work_done = bnx2x_rx_int(fp, budget); |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 10727 | |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10728 | /* must not complete if we consumed full budget */ |
| 10729 | if (work_done >= budget) |
| 10730 | goto poll_again; |
| 10731 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10732 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10733 | /* bnx2x_has_rx_work() reads the status block, thus we need to |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10734 | * ensure that status block indices have been actually read |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10735 | * (bnx2x_update_fpsb_idx) prior to this check (bnx2x_has_rx_work) |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10736 | * so that we won't write the "newer" value of the status block to IGU |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10737 | * (if there was a DMA right after bnx2x_has_rx_work and |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10738 | * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx) |
| 10739 | * may be postponed to right before bnx2x_ack_sb). In this case |
| 10740 | * there will never be another interrupt until there is another update |
| 10741 | * of the status block, while there is still unhandled work. |
| 10742 | */ |
| 10743 | rmb(); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10744 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10745 | if (!bnx2x_has_rx_work(fp)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10746 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10747 | poll_panic: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10748 | #endif |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 10749 | napi_complete(napi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10750 | |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10751 | bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10752 | le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1); |
Eilon Greenstein | 0626b89 | 2009-02-12 08:38:14 +0000 | [diff] [blame] | 10753 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10754 | le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1); |
| 10755 | } |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 10756 | |
Eilon Greenstein | 8534f32 | 2009-03-02 07:59:45 +0000 | [diff] [blame] | 10757 | poll_again: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10758 | return work_done; |
| 10759 | } |
| 10760 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10761 | |
| 10762 | /* we split the first BD into headers and data BDs |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10763 | * to ease the pain of our fellow microcode engineers |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10764 | * we use one mapping for both BDs |
| 10765 | * So far this has only been observed to happen |
| 10766 | * in Other Operating Systems(TM) |
| 10767 | */ |
| 10768 | static noinline u16 bnx2x_tx_split(struct bnx2x *bp, |
| 10769 | struct bnx2x_fastpath *fp, |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10770 | struct sw_tx_bd *tx_buf, |
| 10771 | struct eth_tx_start_bd **tx_bd, u16 hlen, |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10772 | u16 bd_prod, int nbd) |
| 10773 | { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10774 | struct eth_tx_start_bd *h_tx_bd = *tx_bd; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10775 | struct eth_tx_bd *d_tx_bd; |
| 10776 | dma_addr_t mapping; |
| 10777 | int old_len = le16_to_cpu(h_tx_bd->nbytes); |
| 10778 | |
| 10779 | /* first fix first BD */ |
| 10780 | h_tx_bd->nbd = cpu_to_le16(nbd); |
| 10781 | h_tx_bd->nbytes = cpu_to_le16(hlen); |
| 10782 | |
| 10783 | DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d " |
| 10784 | "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi, |
| 10785 | h_tx_bd->addr_lo, h_tx_bd->nbd); |
| 10786 | |
| 10787 | /* now get a new data BD |
| 10788 | * (after the pbd) and fill it */ |
| 10789 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10790 | d_tx_bd = &fp->tx_desc_ring[bd_prod].reg_bd; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10791 | |
| 10792 | mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi), |
| 10793 | le32_to_cpu(h_tx_bd->addr_lo)) + hlen; |
| 10794 | |
| 10795 | d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10796 | d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 10797 | d_tx_bd->nbytes = cpu_to_le16(old_len - hlen); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10798 | |
| 10799 | /* this marks the BD as one that has no individual mapping */ |
| 10800 | tx_buf->flags |= BNX2X_TSO_SPLIT_BD; |
| 10801 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10802 | DP(NETIF_MSG_TX_QUEUED, |
| 10803 | "TSO split data size is %d (%x:%x)\n", |
| 10804 | d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo); |
| 10805 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10806 | /* update tx_bd */ |
| 10807 | *tx_bd = (struct eth_tx_start_bd *)d_tx_bd; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10808 | |
| 10809 | return bd_prod; |
| 10810 | } |
| 10811 | |
| 10812 | static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix) |
| 10813 | { |
| 10814 | if (fix > 0) |
| 10815 | csum = (u16) ~csum_fold(csum_sub(csum, |
| 10816 | csum_partial(t_header - fix, fix, 0))); |
| 10817 | |
| 10818 | else if (fix < 0) |
| 10819 | csum = (u16) ~csum_fold(csum_add(csum, |
| 10820 | csum_partial(t_header, -fix, 0))); |
| 10821 | |
| 10822 | return swab16(csum); |
| 10823 | } |
| 10824 | |
| 10825 | static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb) |
| 10826 | { |
| 10827 | u32 rc; |
| 10828 | |
| 10829 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 10830 | rc = XMIT_PLAIN; |
| 10831 | |
| 10832 | else { |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 10833 | if (skb->protocol == htons(ETH_P_IPV6)) { |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10834 | rc = XMIT_CSUM_V6; |
| 10835 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 10836 | rc |= XMIT_CSUM_TCP; |
| 10837 | |
| 10838 | } else { |
| 10839 | rc = XMIT_CSUM_V4; |
| 10840 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 10841 | rc |= XMIT_CSUM_TCP; |
| 10842 | } |
| 10843 | } |
| 10844 | |
| 10845 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) |
| 10846 | rc |= XMIT_GSO_V4; |
| 10847 | |
| 10848 | else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 10849 | rc |= XMIT_GSO_V6; |
| 10850 | |
| 10851 | return rc; |
| 10852 | } |
| 10853 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10854 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 10855 | /* check if packet requires linearization (packet is too fragmented) |
| 10856 | no need to check fragmentation if page size > 8K (there will be no |
| 10857 | violation to FW restrictions) */ |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10858 | static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb, |
| 10859 | u32 xmit_type) |
| 10860 | { |
| 10861 | int to_copy = 0; |
| 10862 | int hlen = 0; |
| 10863 | int first_bd_sz = 0; |
| 10864 | |
| 10865 | /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */ |
| 10866 | if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) { |
| 10867 | |
| 10868 | if (xmit_type & XMIT_GSO) { |
| 10869 | unsigned short lso_mss = skb_shinfo(skb)->gso_size; |
| 10870 | /* Check if LSO packet needs to be copied: |
| 10871 | 3 = 1 (for headers BD) + 2 (for PBD and last BD) */ |
| 10872 | int wnd_size = MAX_FETCH_BD - 3; |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10873 | /* Number of windows to check */ |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10874 | int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size; |
| 10875 | int wnd_idx = 0; |
| 10876 | int frag_idx = 0; |
| 10877 | u32 wnd_sum = 0; |
| 10878 | |
| 10879 | /* Headers length */ |
| 10880 | hlen = (int)(skb_transport_header(skb) - skb->data) + |
| 10881 | tcp_hdrlen(skb); |
| 10882 | |
| 10883 | /* Amount of data (w/o headers) on linear part of SKB*/ |
| 10884 | first_bd_sz = skb_headlen(skb) - hlen; |
| 10885 | |
| 10886 | wnd_sum = first_bd_sz; |
| 10887 | |
| 10888 | /* Calculate the first sum - it's special */ |
| 10889 | for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++) |
| 10890 | wnd_sum += |
| 10891 | skb_shinfo(skb)->frags[frag_idx].size; |
| 10892 | |
| 10893 | /* If there was data on linear skb data - check it */ |
| 10894 | if (first_bd_sz > 0) { |
| 10895 | if (unlikely(wnd_sum < lso_mss)) { |
| 10896 | to_copy = 1; |
| 10897 | goto exit_lbl; |
| 10898 | } |
| 10899 | |
| 10900 | wnd_sum -= first_bd_sz; |
| 10901 | } |
| 10902 | |
| 10903 | /* Others are easier: run through the frag list and |
| 10904 | check all windows */ |
| 10905 | for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) { |
| 10906 | wnd_sum += |
| 10907 | skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size; |
| 10908 | |
| 10909 | if (unlikely(wnd_sum < lso_mss)) { |
| 10910 | to_copy = 1; |
| 10911 | break; |
| 10912 | } |
| 10913 | wnd_sum -= |
| 10914 | skb_shinfo(skb)->frags[wnd_idx].size; |
| 10915 | } |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10916 | } else { |
| 10917 | /* in non-LSO too fragmented packet should always |
| 10918 | be linearized */ |
| 10919 | to_copy = 1; |
| 10920 | } |
| 10921 | } |
| 10922 | |
| 10923 | exit_lbl: |
| 10924 | if (unlikely(to_copy)) |
| 10925 | DP(NETIF_MSG_TX_QUEUED, |
| 10926 | "Linearization IS REQUIRED for %s packet. " |
| 10927 | "num_frags %d hlen %d first_bd_sz %d\n", |
| 10928 | (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO", |
| 10929 | skb_shinfo(skb)->nr_frags, hlen, first_bd_sz); |
| 10930 | |
| 10931 | return to_copy; |
| 10932 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10933 | #endif |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10934 | |
| 10935 | /* called with netif_tx_lock |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10936 | * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10937 | * netif_wake_queue() |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10938 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 10939 | static netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10940 | { |
| 10941 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10942 | struct bnx2x_fastpath *fp, *fp_stat; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10943 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10944 | struct sw_tx_bd *tx_buf; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10945 | struct eth_tx_start_bd *tx_start_bd; |
| 10946 | struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10947 | struct eth_tx_parse_bd *pbd = NULL; |
| 10948 | u16 pkt_prod, bd_prod; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10949 | int nbd, fp_index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10950 | dma_addr_t mapping; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10951 | u32 xmit_type = bnx2x_xmit_type(bp, skb); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10952 | int i; |
| 10953 | u8 hlen = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10954 | __le16 pkt_size = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10955 | |
| 10956 | #ifdef BNX2X_STOP_ON_ERROR |
| 10957 | if (unlikely(bp->panic)) |
| 10958 | return NETDEV_TX_BUSY; |
| 10959 | #endif |
| 10960 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10961 | fp_index = skb_get_queue_mapping(skb); |
| 10962 | txq = netdev_get_tx_queue(dev, fp_index); |
| 10963 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10964 | fp = &bp->fp[fp_index + bp->num_rx_queues]; |
| 10965 | fp_stat = &bp->fp[fp_index]; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10966 | |
Yitchak Gertner | 231fd58 | 2008-08-25 15:27:06 -0700 | [diff] [blame] | 10967 | if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10968 | fp_stat->eth_q_stats.driver_xoff++; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10969 | netif_tx_stop_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10970 | BNX2X_ERR("BUG! Tx ring full when queue awake!\n"); |
| 10971 | return NETDEV_TX_BUSY; |
| 10972 | } |
| 10973 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10974 | DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)" |
| 10975 | " gso type %x xmit_type %x\n", |
| 10976 | skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr, |
| 10977 | ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type); |
| 10978 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10979 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 10980 | /* First, check if we need to linearize the skb (due to FW |
| 10981 | restrictions). No need to check fragmentation if page size > 8K |
| 10982 | (there will be no violation to FW restrictions) */ |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10983 | if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) { |
| 10984 | /* Statistics of linearization */ |
| 10985 | bp->lin_cnt++; |
| 10986 | if (skb_linearize(skb) != 0) { |
| 10987 | DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - " |
| 10988 | "silently dropping this SKB\n"); |
| 10989 | dev_kfree_skb_any(skb); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10990 | return NETDEV_TX_OK; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10991 | } |
| 10992 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10993 | #endif |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10994 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10995 | /* |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10996 | Please read carefully. First we use one BD which we mark as start, |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 10997 | then we have a parsing info BD (used for TSO or xsum), |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10998 | and only then we have the rest of the TSO BDs. |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10999 | (don't forget to mark the last one as last, |
| 11000 | and to unmap only AFTER you write to the BD ...) |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11001 | And above all, all pdb sizes are in words - NOT DWORDS! |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11002 | */ |
| 11003 | |
| 11004 | pkt_prod = fp->tx_pkt_prod++; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11005 | bd_prod = TX_BD(fp->tx_bd_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11006 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11007 | /* get a tx_buf and first BD */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11008 | tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)]; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11009 | tx_start_bd = &fp->tx_desc_ring[bd_prod].start_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11010 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11011 | tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; |
| 11012 | tx_start_bd->general_data = (UNICAST_ADDRESS << |
| 11013 | ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 11014 | /* header nbd */ |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11015 | tx_start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11016 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11017 | /* remember the first BD of the packet */ |
| 11018 | tx_buf->first_bd = fp->tx_bd_prod; |
| 11019 | tx_buf->skb = skb; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11020 | tx_buf->flags = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11021 | |
| 11022 | DP(NETIF_MSG_TX_QUEUED, |
| 11023 | "sending pkt %u @%p next_idx %u bd %u @%p\n", |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11024 | pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11025 | |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 11026 | #ifdef BCM_VLAN |
| 11027 | if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) && |
| 11028 | (bp->flags & HW_VLAN_TX_FLAG)) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11029 | tx_start_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb)); |
| 11030 | tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11031 | } else |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 11032 | #endif |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11033 | tx_start_bd->vlan = cpu_to_le16(pkt_prod); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11034 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11035 | /* turn on parsing and get a BD */ |
| 11036 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 11037 | pbd = &fp->tx_desc_ring[bd_prod].parse_bd; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11038 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11039 | memset(pbd, 0, sizeof(struct eth_tx_parse_bd)); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11040 | |
| 11041 | if (xmit_type & XMIT_CSUM) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11042 | hlen = (skb_network_header(skb) - skb->data) / 2; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11043 | |
| 11044 | /* for now NS flag is not used in Linux */ |
Eilon Greenstein | 4781bfa | 2009-02-12 08:38:17 +0000 | [diff] [blame] | 11045 | pbd->global_data = |
| 11046 | (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) << |
| 11047 | ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT)); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11048 | |
| 11049 | pbd->ip_hlen = (skb_transport_header(skb) - |
| 11050 | skb_network_header(skb)) / 2; |
| 11051 | |
| 11052 | hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2; |
| 11053 | |
| 11054 | pbd->total_hlen = cpu_to_le16(hlen); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11055 | hlen = hlen*2; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11056 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11057 | tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11058 | |
| 11059 | if (xmit_type & XMIT_CSUM_V4) |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11060 | tx_start_bd->bd_flags.as_bitfield |= |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11061 | ETH_TX_BD_FLAGS_IP_CSUM; |
| 11062 | else |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11063 | tx_start_bd->bd_flags.as_bitfield |= |
| 11064 | ETH_TX_BD_FLAGS_IPV6; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11065 | |
| 11066 | if (xmit_type & XMIT_CSUM_TCP) { |
| 11067 | pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check); |
| 11068 | |
| 11069 | } else { |
| 11070 | s8 fix = SKB_CS_OFF(skb); /* signed! */ |
| 11071 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11072 | pbd->global_data |= ETH_TX_PARSE_BD_UDP_CS_FLG; |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11073 | |
| 11074 | DP(NETIF_MSG_TX_QUEUED, |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11075 | "hlen %d fix %d csum before fix %x\n", |
| 11076 | le16_to_cpu(pbd->total_hlen), fix, SKB_CS(skb)); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11077 | |
| 11078 | /* HW bug: fixup the CSUM */ |
| 11079 | pbd->tcp_pseudo_csum = |
| 11080 | bnx2x_csum_fix(skb_transport_header(skb), |
| 11081 | SKB_CS(skb), fix); |
| 11082 | |
| 11083 | DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n", |
| 11084 | pbd->tcp_pseudo_csum); |
| 11085 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11086 | } |
| 11087 | |
| 11088 | mapping = pci_map_single(bp->pdev, skb->data, |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11089 | skb_headlen(skb), PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11090 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11091 | tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 11092 | tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 11093 | nbd = skb_shinfo(skb)->nr_frags + 2; /* start_bd + pbd + frags */ |
| 11094 | tx_start_bd->nbd = cpu_to_le16(nbd); |
| 11095 | tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 11096 | pkt_size = tx_start_bd->nbytes; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11097 | |
| 11098 | DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d" |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11099 | " nbytes %d flags %x vlan %x\n", |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11100 | tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo, |
| 11101 | le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes), |
| 11102 | tx_start_bd->bd_flags.as_bitfield, le16_to_cpu(tx_start_bd->vlan)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11103 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11104 | if (xmit_type & XMIT_GSO) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11105 | |
| 11106 | DP(NETIF_MSG_TX_QUEUED, |
| 11107 | "TSO packet len %d hlen %d total len %d tso size %d\n", |
| 11108 | skb->len, hlen, skb_headlen(skb), |
| 11109 | skb_shinfo(skb)->gso_size); |
| 11110 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11111 | tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11112 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11113 | if (unlikely(skb_headlen(skb) > hlen)) |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11114 | bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd, |
| 11115 | hlen, bd_prod, ++nbd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11116 | |
| 11117 | pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 11118 | pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11119 | pbd->tcp_flags = pbd_tcp_flags(skb); |
| 11120 | |
| 11121 | if (xmit_type & XMIT_GSO_V4) { |
| 11122 | pbd->ip_id = swab16(ip_hdr(skb)->id); |
| 11123 | pbd->tcp_pseudo_csum = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11124 | swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 11125 | ip_hdr(skb)->daddr, |
| 11126 | 0, IPPROTO_TCP, 0)); |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11127 | |
| 11128 | } else |
| 11129 | pbd->tcp_pseudo_csum = |
| 11130 | swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 11131 | &ipv6_hdr(skb)->daddr, |
| 11132 | 0, IPPROTO_TCP, 0)); |
| 11133 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11134 | pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN; |
| 11135 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11136 | tx_data_bd = (struct eth_tx_bd *)tx_start_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11137 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11138 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 11139 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11140 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11141 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11142 | tx_data_bd = &fp->tx_desc_ring[bd_prod].reg_bd; |
| 11143 | if (total_pkt_bd == NULL) |
| 11144 | total_pkt_bd = &fp->tx_desc_ring[bd_prod].reg_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11145 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11146 | mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset, |
| 11147 | frag->size, PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11148 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11149 | tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 11150 | tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 11151 | tx_data_bd->nbytes = cpu_to_le16(frag->size); |
| 11152 | le16_add_cpu(&pkt_size, frag->size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11153 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11154 | DP(NETIF_MSG_TX_QUEUED, |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11155 | "frag %d bd @%p addr (%x:%x) nbytes %d\n", |
| 11156 | i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo, |
| 11157 | le16_to_cpu(tx_data_bd->nbytes)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11158 | } |
| 11159 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11160 | DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11161 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11162 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 11163 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11164 | /* now send a tx doorbell, counting the next BD |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11165 | * if the packet contains or ends with it |
| 11166 | */ |
| 11167 | if (TX_BD_POFF(bd_prod) < nbd) |
| 11168 | nbd++; |
| 11169 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11170 | if (total_pkt_bd != NULL) |
| 11171 | total_pkt_bd->total_pkt_bytes = pkt_size; |
| 11172 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11173 | if (pbd) |
| 11174 | DP(NETIF_MSG_TX_QUEUED, |
| 11175 | "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u" |
| 11176 | " tcp_flags %x xsum %x seq %u hlen %u\n", |
| 11177 | pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id, |
| 11178 | pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum, |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11179 | pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11180 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11181 | DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11182 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 11183 | /* |
| 11184 | * Make sure that the BD data is updated before updating the producer |
| 11185 | * since FW might read the BD right after the producer is updated. |
| 11186 | * This is only applicable for weak-ordered memory model archs such |
| 11187 | * as IA-64. The following barrier is also mandatory since FW will |
| 11188 | * assumes packets must have BDs. |
| 11189 | */ |
| 11190 | wmb(); |
| 11191 | |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11192 | fp->tx_db.data.prod += nbd; |
| 11193 | barrier(); |
| 11194 | DOORBELL(bp, fp->index - bp->num_rx_queues, fp->tx_db.raw); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11195 | |
| 11196 | mmiowb(); |
| 11197 | |
Eilon Greenstein | 755735e | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 11198 | fp->tx_bd_prod += nbd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11199 | |
| 11200 | if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) { |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11201 | netif_tx_stop_queue(txq); |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 11202 | /* We want bnx2x_tx_int to "see" the updated tx_bd_prod |
| 11203 | if we put Tx into XOFF state. */ |
| 11204 | smp_mb(); |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11205 | fp_stat->eth_q_stats.driver_xoff++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11206 | if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 11207 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11208 | } |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11209 | fp_stat->tx_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11210 | |
| 11211 | return NETDEV_TX_OK; |
| 11212 | } |
| 11213 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 11214 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11215 | static int bnx2x_open(struct net_device *dev) |
| 11216 | { |
| 11217 | struct bnx2x *bp = netdev_priv(dev); |
| 11218 | |
Eilon Greenstein | 6eccabb | 2009-01-22 03:37:48 +0000 | [diff] [blame] | 11219 | netif_carrier_off(dev); |
| 11220 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11221 | bnx2x_set_power_state(bp, PCI_D0); |
| 11222 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 11223 | return bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11224 | } |
| 11225 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 11226 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11227 | static int bnx2x_close(struct net_device *dev) |
| 11228 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11229 | struct bnx2x *bp = netdev_priv(dev); |
| 11230 | |
| 11231 | /* Unload the driver, release IRQs */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 11232 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
| 11233 | if (atomic_read(&bp->pdev->enable_cnt) == 1) |
| 11234 | if (!CHIP_REV_IS_SLOW(bp)) |
| 11235 | bnx2x_set_power_state(bp, PCI_D3hot); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11236 | |
| 11237 | return 0; |
| 11238 | } |
| 11239 | |
Eilon Greenstein | f537225 | 2009-02-12 08:38:30 +0000 | [diff] [blame] | 11240 | /* called with netif_tx_lock from dev_mcast.c */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11241 | static void bnx2x_set_rx_mode(struct net_device *dev) |
| 11242 | { |
| 11243 | struct bnx2x *bp = netdev_priv(dev); |
| 11244 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; |
| 11245 | int port = BP_PORT(bp); |
| 11246 | |
| 11247 | if (bp->state != BNX2X_STATE_OPEN) { |
| 11248 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 11249 | return; |
| 11250 | } |
| 11251 | |
| 11252 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); |
| 11253 | |
| 11254 | if (dev->flags & IFF_PROMISC) |
| 11255 | rx_mode = BNX2X_RX_MODE_PROMISC; |
| 11256 | |
| 11257 | else if ((dev->flags & IFF_ALLMULTI) || |
| 11258 | ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp))) |
| 11259 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
| 11260 | |
| 11261 | else { /* some multicasts */ |
| 11262 | if (CHIP_IS_E1(bp)) { |
| 11263 | int i, old, offset; |
| 11264 | struct dev_mc_list *mclist; |
| 11265 | struct mac_configuration_cmd *config = |
| 11266 | bnx2x_sp(bp, mcast_config); |
| 11267 | |
| 11268 | for (i = 0, mclist = dev->mc_list; |
| 11269 | mclist && (i < dev->mc_count); |
| 11270 | i++, mclist = mclist->next) { |
| 11271 | |
| 11272 | config->config_table[i]. |
| 11273 | cam_entry.msb_mac_addr = |
| 11274 | swab16(*(u16 *)&mclist->dmi_addr[0]); |
| 11275 | config->config_table[i]. |
| 11276 | cam_entry.middle_mac_addr = |
| 11277 | swab16(*(u16 *)&mclist->dmi_addr[2]); |
| 11278 | config->config_table[i]. |
| 11279 | cam_entry.lsb_mac_addr = |
| 11280 | swab16(*(u16 *)&mclist->dmi_addr[4]); |
| 11281 | config->config_table[i].cam_entry.flags = |
| 11282 | cpu_to_le16(port); |
| 11283 | config->config_table[i]. |
| 11284 | target_table_entry.flags = 0; |
Eilon Greenstein | ca00392 | 2009-08-12 22:53:28 -0700 | [diff] [blame] | 11285 | config->config_table[i].target_table_entry. |
| 11286 | clients_bit_vector = |
| 11287 | cpu_to_le32(1 << BP_L_ID(bp)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11288 | config->config_table[i]. |
| 11289 | target_table_entry.vlan_id = 0; |
| 11290 | |
| 11291 | DP(NETIF_MSG_IFUP, |
| 11292 | "setting MCAST[%d] (%04x:%04x:%04x)\n", i, |
| 11293 | config->config_table[i]. |
| 11294 | cam_entry.msb_mac_addr, |
| 11295 | config->config_table[i]. |
| 11296 | cam_entry.middle_mac_addr, |
| 11297 | config->config_table[i]. |
| 11298 | cam_entry.lsb_mac_addr); |
| 11299 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 11300 | old = config->hdr.length; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11301 | if (old > i) { |
| 11302 | for (; i < old; i++) { |
| 11303 | if (CAM_IS_INVALID(config-> |
| 11304 | config_table[i])) { |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 11305 | /* already invalidated */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11306 | break; |
| 11307 | } |
| 11308 | /* invalidate */ |
| 11309 | CAM_INVALIDATE(config-> |
| 11310 | config_table[i]); |
| 11311 | } |
| 11312 | } |
| 11313 | |
| 11314 | if (CHIP_REV_IS_SLOW(bp)) |
| 11315 | offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 11316 | else |
| 11317 | offset = BNX2X_MAX_MULTICAST*(1 + port); |
| 11318 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 11319 | config->hdr.length = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11320 | config->hdr.offset = offset; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 11321 | config->hdr.client_id = bp->fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11322 | config->hdr.reserved1 = 0; |
| 11323 | |
| 11324 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 11325 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 11326 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), |
| 11327 | 0); |
| 11328 | } else { /* E1H */ |
| 11329 | /* Accept one or more multicasts */ |
| 11330 | struct dev_mc_list *mclist; |
| 11331 | u32 mc_filter[MC_HASH_SIZE]; |
| 11332 | u32 crc, bit, regidx; |
| 11333 | int i; |
| 11334 | |
| 11335 | memset(mc_filter, 0, 4 * MC_HASH_SIZE); |
| 11336 | |
| 11337 | for (i = 0, mclist = dev->mc_list; |
| 11338 | mclist && (i < dev->mc_count); |
| 11339 | i++, mclist = mclist->next) { |
| 11340 | |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 11341 | DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", |
| 11342 | mclist->dmi_addr); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11343 | |
| 11344 | crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN); |
| 11345 | bit = (crc >> 24) & 0xff; |
| 11346 | regidx = bit >> 5; |
| 11347 | bit &= 0x1f; |
| 11348 | mc_filter[regidx] |= (1 << bit); |
| 11349 | } |
| 11350 | |
| 11351 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 11352 | REG_WR(bp, MC_HASH_OFFSET(bp, i), |
| 11353 | mc_filter[i]); |
| 11354 | } |
| 11355 | } |
| 11356 | |
| 11357 | bp->rx_mode = rx_mode; |
| 11358 | bnx2x_set_storm_rx_mode(bp); |
| 11359 | } |
| 11360 | |
| 11361 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11362 | static int bnx2x_change_mac_addr(struct net_device *dev, void *p) |
| 11363 | { |
| 11364 | struct sockaddr *addr = p; |
| 11365 | struct bnx2x *bp = netdev_priv(dev); |
| 11366 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11367 | if (!is_valid_ether_addr((u8 *)(addr->sa_data))) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11368 | return -EINVAL; |
| 11369 | |
| 11370 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11371 | if (netif_running(dev)) { |
| 11372 | if (CHIP_IS_E1(bp)) |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 11373 | bnx2x_set_mac_addr_e1(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11374 | else |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 11375 | bnx2x_set_mac_addr_e1h(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11376 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11377 | |
| 11378 | return 0; |
| 11379 | } |
| 11380 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 11381 | /* called with rtnl_lock */ |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11382 | static int bnx2x_mdio_read(struct net_device *netdev, int prtad, |
| 11383 | int devad, u16 addr) |
| 11384 | { |
| 11385 | struct bnx2x *bp = netdev_priv(netdev); |
| 11386 | u16 value; |
| 11387 | int rc; |
| 11388 | u32 phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 11389 | |
| 11390 | DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n", |
| 11391 | prtad, devad, addr); |
| 11392 | |
| 11393 | if (prtad != bp->mdio.prtad) { |
| 11394 | DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n", |
| 11395 | prtad, bp->mdio.prtad); |
| 11396 | return -EINVAL; |
| 11397 | } |
| 11398 | |
| 11399 | /* The HW expects different devad if CL22 is used */ |
| 11400 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 11401 | |
| 11402 | bnx2x_acquire_phy_lock(bp); |
| 11403 | rc = bnx2x_cl45_read(bp, BP_PORT(bp), phy_type, prtad, |
| 11404 | devad, addr, &value); |
| 11405 | bnx2x_release_phy_lock(bp); |
| 11406 | DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc); |
| 11407 | |
| 11408 | if (!rc) |
| 11409 | rc = value; |
| 11410 | return rc; |
| 11411 | } |
| 11412 | |
| 11413 | /* called with rtnl_lock */ |
| 11414 | static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 11415 | u16 addr, u16 value) |
| 11416 | { |
| 11417 | struct bnx2x *bp = netdev_priv(netdev); |
| 11418 | u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 11419 | int rc; |
| 11420 | |
| 11421 | DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x," |
| 11422 | " value 0x%x\n", prtad, devad, addr, value); |
| 11423 | |
| 11424 | if (prtad != bp->mdio.prtad) { |
| 11425 | DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n", |
| 11426 | prtad, bp->mdio.prtad); |
| 11427 | return -EINVAL; |
| 11428 | } |
| 11429 | |
| 11430 | /* The HW expects different devad if CL22 is used */ |
| 11431 | devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad; |
| 11432 | |
| 11433 | bnx2x_acquire_phy_lock(bp); |
| 11434 | rc = bnx2x_cl45_write(bp, BP_PORT(bp), ext_phy_type, prtad, |
| 11435 | devad, addr, value); |
| 11436 | bnx2x_release_phy_lock(bp); |
| 11437 | return rc; |
| 11438 | } |
| 11439 | |
| 11440 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11441 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 11442 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11443 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11444 | struct mii_ioctl_data *mdio = if_mii(ifr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11445 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11446 | DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", |
| 11447 | mdio->phy_id, mdio->reg_num, mdio->val_in); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11448 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11449 | if (!netif_running(dev)) |
| 11450 | return -EAGAIN; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 11451 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11452 | return mdio_mii_ioctl(&bp->mdio, mdio, cmd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11453 | } |
| 11454 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11455 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11456 | static int bnx2x_change_mtu(struct net_device *dev, int new_mtu) |
| 11457 | { |
| 11458 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11459 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11460 | |
| 11461 | if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) || |
| 11462 | ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) |
| 11463 | return -EINVAL; |
| 11464 | |
| 11465 | /* This does not race with packet allocation |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 11466 | * because the actual alloc size is |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11467 | * only updated as part of load |
| 11468 | */ |
| 11469 | dev->mtu = new_mtu; |
| 11470 | |
| 11471 | if (netif_running(dev)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11472 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 11473 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11474 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11475 | |
| 11476 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11477 | } |
| 11478 | |
| 11479 | static void bnx2x_tx_timeout(struct net_device *dev) |
| 11480 | { |
| 11481 | struct bnx2x *bp = netdev_priv(dev); |
| 11482 | |
| 11483 | #ifdef BNX2X_STOP_ON_ERROR |
| 11484 | if (!bp->panic) |
| 11485 | bnx2x_panic(); |
| 11486 | #endif |
| 11487 | /* This allows the netif to be shutdown gracefully before resetting */ |
| 11488 | schedule_work(&bp->reset_task); |
| 11489 | } |
| 11490 | |
| 11491 | #ifdef BCM_VLAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11492 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11493 | static void bnx2x_vlan_rx_register(struct net_device *dev, |
| 11494 | struct vlan_group *vlgrp) |
| 11495 | { |
| 11496 | struct bnx2x *bp = netdev_priv(dev); |
| 11497 | |
| 11498 | bp->vlgrp = vlgrp; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 11499 | |
| 11500 | /* Set flags according to the required capabilities */ |
| 11501 | bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
| 11502 | |
| 11503 | if (dev->features & NETIF_F_HW_VLAN_TX) |
| 11504 | bp->flags |= HW_VLAN_TX_FLAG; |
| 11505 | |
| 11506 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 11507 | bp->flags |= HW_VLAN_RX_FLAG; |
| 11508 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11509 | if (netif_running(dev)) |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 11510 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11511 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11512 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11513 | #endif |
| 11514 | |
| 11515 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 11516 | static void poll_bnx2x(struct net_device *dev) |
| 11517 | { |
| 11518 | struct bnx2x *bp = netdev_priv(dev); |
| 11519 | |
| 11520 | disable_irq(bp->pdev->irq); |
| 11521 | bnx2x_interrupt(bp->pdev->irq, dev); |
| 11522 | enable_irq(bp->pdev->irq); |
| 11523 | } |
| 11524 | #endif |
| 11525 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 11526 | static const struct net_device_ops bnx2x_netdev_ops = { |
| 11527 | .ndo_open = bnx2x_open, |
| 11528 | .ndo_stop = bnx2x_close, |
| 11529 | .ndo_start_xmit = bnx2x_start_xmit, |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 11530 | .ndo_set_multicast_list = bnx2x_set_rx_mode, |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 11531 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
| 11532 | .ndo_validate_addr = eth_validate_addr, |
| 11533 | .ndo_do_ioctl = bnx2x_ioctl, |
| 11534 | .ndo_change_mtu = bnx2x_change_mtu, |
| 11535 | .ndo_tx_timeout = bnx2x_tx_timeout, |
| 11536 | #ifdef BCM_VLAN |
| 11537 | .ndo_vlan_rx_register = bnx2x_vlan_rx_register, |
| 11538 | #endif |
| 11539 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 11540 | .ndo_poll_controller = poll_bnx2x, |
| 11541 | #endif |
| 11542 | }; |
| 11543 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11544 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
| 11545 | struct net_device *dev) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11546 | { |
| 11547 | struct bnx2x *bp; |
| 11548 | int rc; |
| 11549 | |
| 11550 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 11551 | bp = netdev_priv(dev); |
| 11552 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11553 | bp->dev = dev; |
| 11554 | bp->pdev = pdev; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11555 | bp->flags = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11556 | bp->func = PCI_FUNC(pdev->devfn); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11557 | |
| 11558 | rc = pci_enable_device(pdev); |
| 11559 | if (rc) { |
| 11560 | printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n"); |
| 11561 | goto err_out; |
| 11562 | } |
| 11563 | |
| 11564 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 11565 | printk(KERN_ERR PFX "Cannot find PCI device base address," |
| 11566 | " aborting\n"); |
| 11567 | rc = -ENODEV; |
| 11568 | goto err_out_disable; |
| 11569 | } |
| 11570 | |
| 11571 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
| 11572 | printk(KERN_ERR PFX "Cannot find second PCI device" |
| 11573 | " base address, aborting\n"); |
| 11574 | rc = -ENODEV; |
| 11575 | goto err_out_disable; |
| 11576 | } |
| 11577 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11578 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 11579 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 11580 | if (rc) { |
| 11581 | printk(KERN_ERR PFX "Cannot obtain PCI resources," |
| 11582 | " aborting\n"); |
| 11583 | goto err_out_disable; |
| 11584 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11585 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11586 | pci_set_master(pdev); |
| 11587 | pci_save_state(pdev); |
| 11588 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11589 | |
| 11590 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 11591 | if (bp->pm_cap == 0) { |
| 11592 | printk(KERN_ERR PFX "Cannot find power management" |
| 11593 | " capability, aborting\n"); |
| 11594 | rc = -EIO; |
| 11595 | goto err_out_release; |
| 11596 | } |
| 11597 | |
| 11598 | bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 11599 | if (bp->pcie_cap == 0) { |
| 11600 | printk(KERN_ERR PFX "Cannot find PCI Express capability," |
| 11601 | " aborting\n"); |
| 11602 | rc = -EIO; |
| 11603 | goto err_out_release; |
| 11604 | } |
| 11605 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 11606 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11607 | bp->flags |= USING_DAC_FLAG; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 11608 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11609 | printk(KERN_ERR PFX "pci_set_consistent_dma_mask" |
| 11610 | " failed, aborting\n"); |
| 11611 | rc = -EIO; |
| 11612 | goto err_out_release; |
| 11613 | } |
| 11614 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 11615 | } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11616 | printk(KERN_ERR PFX "System does not support DMA," |
| 11617 | " aborting\n"); |
| 11618 | rc = -EIO; |
| 11619 | goto err_out_release; |
| 11620 | } |
| 11621 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11622 | dev->mem_start = pci_resource_start(pdev, 0); |
| 11623 | dev->base_addr = dev->mem_start; |
| 11624 | dev->mem_end = pci_resource_end(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11625 | |
| 11626 | dev->irq = pdev->irq; |
| 11627 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 11628 | bp->regview = pci_ioremap_bar(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11629 | if (!bp->regview) { |
| 11630 | printk(KERN_ERR PFX "Cannot map register space, aborting\n"); |
| 11631 | rc = -ENOMEM; |
| 11632 | goto err_out_release; |
| 11633 | } |
| 11634 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11635 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), |
| 11636 | min_t(u64, BNX2X_DB_SIZE, |
| 11637 | pci_resource_len(pdev, 2))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11638 | if (!bp->doorbells) { |
| 11639 | printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n"); |
| 11640 | rc = -ENOMEM; |
| 11641 | goto err_out_unmap; |
| 11642 | } |
| 11643 | |
| 11644 | bnx2x_set_power_state(bp, PCI_D0); |
| 11645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11646 | /* clean indirect addresses */ |
| 11647 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 11648 | PCICFG_VENDOR_ID_OFFSET); |
| 11649 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0); |
| 11650 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0); |
| 11651 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0); |
| 11652 | 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] | 11653 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11654 | dev->watchdog_timeo = TX_TIMEOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11655 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 11656 | dev->netdev_ops = &bnx2x_netdev_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11657 | dev->ethtool_ops = &bnx2x_ethtool_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11658 | dev->features |= NETIF_F_SG; |
| 11659 | dev->features |= NETIF_F_HW_CSUM; |
| 11660 | if (bp->flags & USING_DAC_FLAG) |
| 11661 | dev->features |= NETIF_F_HIGHDMA; |
Eilon Greenstein | 5316bc0 | 2009-07-21 05:47:43 +0000 | [diff] [blame] | 11662 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
| 11663 | dev->features |= NETIF_F_TSO6; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11664 | #ifdef BCM_VLAN |
| 11665 | dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX); |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 11666 | bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
Eilon Greenstein | 5316bc0 | 2009-07-21 05:47:43 +0000 | [diff] [blame] | 11667 | |
| 11668 | dev->vlan_features |= NETIF_F_SG; |
| 11669 | dev->vlan_features |= NETIF_F_HW_CSUM; |
| 11670 | if (bp->flags & USING_DAC_FLAG) |
| 11671 | dev->vlan_features |= NETIF_F_HIGHDMA; |
| 11672 | dev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
| 11673 | dev->vlan_features |= NETIF_F_TSO6; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11674 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11675 | |
Eilon Greenstein | 01cd452 | 2009-08-12 08:23:08 +0000 | [diff] [blame] | 11676 | /* get_port_hwinfo() will set prtad and mmds properly */ |
| 11677 | bp->mdio.prtad = MDIO_PRTAD_NONE; |
| 11678 | bp->mdio.mmds = 0; |
| 11679 | bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 11680 | bp->mdio.dev = dev; |
| 11681 | bp->mdio.mdio_read = bnx2x_mdio_read; |
| 11682 | bp->mdio.mdio_write = bnx2x_mdio_write; |
| 11683 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11684 | return 0; |
| 11685 | |
| 11686 | err_out_unmap: |
| 11687 | if (bp->regview) { |
| 11688 | iounmap(bp->regview); |
| 11689 | bp->regview = NULL; |
| 11690 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11691 | if (bp->doorbells) { |
| 11692 | iounmap(bp->doorbells); |
| 11693 | bp->doorbells = NULL; |
| 11694 | } |
| 11695 | |
| 11696 | err_out_release: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11697 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 11698 | pci_release_regions(pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11699 | |
| 11700 | err_out_disable: |
| 11701 | pci_disable_device(pdev); |
| 11702 | pci_set_drvdata(pdev, NULL); |
| 11703 | |
| 11704 | err_out: |
| 11705 | return rc; |
| 11706 | } |
| 11707 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11708 | static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp, |
| 11709 | int *width, int *speed) |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11710 | { |
| 11711 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 11712 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11713 | *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
| 11714 | |
| 11715 | /* return value of 1=2.5GHz 2=5GHz */ |
| 11716 | *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11717 | } |
| 11718 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11719 | static int __devinit bnx2x_check_firmware(struct bnx2x *bp) |
| 11720 | { |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11721 | const struct firmware *firmware = bp->firmware; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11722 | struct bnx2x_fw_file_hdr *fw_hdr; |
| 11723 | struct bnx2x_fw_file_section *sections; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11724 | u32 offset, len, num_ops; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11725 | u16 *ops_offsets; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11726 | int i; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11727 | const u8 *fw_ver; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11728 | |
| 11729 | if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) |
| 11730 | return -EINVAL; |
| 11731 | |
| 11732 | fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data; |
| 11733 | sections = (struct bnx2x_fw_file_section *)fw_hdr; |
| 11734 | |
| 11735 | /* Make sure none of the offsets and sizes make us read beyond |
| 11736 | * the end of the firmware data */ |
| 11737 | for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) { |
| 11738 | offset = be32_to_cpu(sections[i].offset); |
| 11739 | len = be32_to_cpu(sections[i].len); |
| 11740 | if (offset + len > firmware->size) { |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11741 | printk(KERN_ERR PFX "Section %d length is out of " |
| 11742 | "bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11743 | return -EINVAL; |
| 11744 | } |
| 11745 | } |
| 11746 | |
| 11747 | /* Likewise for the init_ops offsets */ |
| 11748 | offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset); |
| 11749 | ops_offsets = (u16 *)(firmware->data + offset); |
| 11750 | num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op); |
| 11751 | |
| 11752 | for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) { |
| 11753 | if (be16_to_cpu(ops_offsets[i]) > num_ops) { |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11754 | printk(KERN_ERR PFX "Section offset %d is out of " |
| 11755 | "bounds\n", i); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11756 | return -EINVAL; |
| 11757 | } |
| 11758 | } |
| 11759 | |
| 11760 | /* Check FW version */ |
| 11761 | offset = be32_to_cpu(fw_hdr->fw_version.offset); |
| 11762 | fw_ver = firmware->data + offset; |
| 11763 | if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) || |
| 11764 | (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) || |
| 11765 | (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) || |
| 11766 | (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) { |
| 11767 | printk(KERN_ERR PFX "Bad FW version:%d.%d.%d.%d." |
| 11768 | " Should be %d.%d.%d.%d\n", |
| 11769 | fw_ver[0], fw_ver[1], fw_ver[2], |
| 11770 | fw_ver[3], BCM_5710_FW_MAJOR_VERSION, |
| 11771 | BCM_5710_FW_MINOR_VERSION, |
| 11772 | BCM_5710_FW_REVISION_VERSION, |
| 11773 | BCM_5710_FW_ENGINEERING_VERSION); |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11774 | return -EINVAL; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11775 | } |
| 11776 | |
| 11777 | return 0; |
| 11778 | } |
| 11779 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11780 | 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] | 11781 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11782 | const __be32 *source = (const __be32 *)_source; |
| 11783 | u32 *target = (u32 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11784 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11785 | |
| 11786 | for (i = 0; i < n/4; i++) |
| 11787 | target[i] = be32_to_cpu(source[i]); |
| 11788 | } |
| 11789 | |
| 11790 | /* |
| 11791 | Ops array is stored in the following format: |
| 11792 | {op(8bit), offset(24bit, big endian), data(32bit, big endian)} |
| 11793 | */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11794 | 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] | 11795 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11796 | const __be32 *source = (const __be32 *)_source; |
| 11797 | struct raw_op *target = (struct raw_op *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11798 | u32 i, j, tmp; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11799 | |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11800 | for (i = 0, j = 0; i < n/8; i++, j += 2) { |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11801 | tmp = be32_to_cpu(source[j]); |
| 11802 | target[i].op = (tmp >> 24) & 0xff; |
| 11803 | target[i].offset = tmp & 0xffffff; |
| 11804 | target[i].raw_data = be32_to_cpu(source[j+1]); |
| 11805 | } |
| 11806 | } |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11807 | |
| 11808 | 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] | 11809 | { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11810 | const __be16 *source = (const __be16 *)_source; |
| 11811 | u16 *target = (u16 *)_target; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11812 | u32 i; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11813 | |
| 11814 | for (i = 0; i < n/2; i++) |
| 11815 | target[i] = be16_to_cpu(source[i]); |
| 11816 | } |
| 11817 | |
| 11818 | #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11819 | do { \ |
| 11820 | u32 len = be32_to_cpu(fw_hdr->arr.len); \ |
| 11821 | bp->arr = kmalloc(len, GFP_KERNEL); \ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11822 | if (!bp->arr) { \ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11823 | printk(KERN_ERR PFX "Failed to allocate %d bytes " \ |
| 11824 | "for "#arr"\n", len); \ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11825 | goto lbl; \ |
| 11826 | } \ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11827 | func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \ |
| 11828 | (u8 *)bp->arr, len); \ |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11829 | } while (0) |
| 11830 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11831 | static int __devinit bnx2x_init_firmware(struct bnx2x *bp, struct device *dev) |
| 11832 | { |
| 11833 | char fw_file_name[40] = {0}; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11834 | struct bnx2x_fw_file_hdr *fw_hdr; |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11835 | int rc, offset; |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11836 | |
| 11837 | /* Create a FW file name */ |
| 11838 | if (CHIP_IS_E1(bp)) |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11839 | offset = sprintf(fw_file_name, FW_FILE_PREFIX_E1); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11840 | else |
| 11841 | offset = sprintf(fw_file_name, FW_FILE_PREFIX_E1H); |
| 11842 | |
| 11843 | sprintf(fw_file_name + offset, "%d.%d.%d.%d.fw", |
| 11844 | BCM_5710_FW_MAJOR_VERSION, |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11845 | BCM_5710_FW_MINOR_VERSION, |
| 11846 | BCM_5710_FW_REVISION_VERSION, |
| 11847 | BCM_5710_FW_ENGINEERING_VERSION); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11848 | |
| 11849 | printk(KERN_INFO PFX "Loading %s\n", fw_file_name); |
| 11850 | |
| 11851 | rc = request_firmware(&bp->firmware, fw_file_name, dev); |
| 11852 | if (rc) { |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11853 | printk(KERN_ERR PFX "Can't load firmware file %s\n", |
| 11854 | fw_file_name); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11855 | goto request_firmware_exit; |
| 11856 | } |
| 11857 | |
| 11858 | rc = bnx2x_check_firmware(bp); |
| 11859 | if (rc) { |
| 11860 | printk(KERN_ERR PFX "Corrupt firmware file %s\n", fw_file_name); |
| 11861 | goto request_firmware_exit; |
| 11862 | } |
| 11863 | |
| 11864 | fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; |
| 11865 | |
| 11866 | /* Initialize the pointers to the init arrays */ |
| 11867 | /* Blob */ |
| 11868 | BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); |
| 11869 | |
| 11870 | /* Opcodes */ |
| 11871 | BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops); |
| 11872 | |
| 11873 | /* Offsets */ |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11874 | BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err, |
| 11875 | be16_to_cpu_n); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11876 | |
| 11877 | /* STORMs firmware */ |
Eilon Greenstein | 573f203 | 2009-08-12 08:24:14 +0000 | [diff] [blame] | 11878 | INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 11879 | be32_to_cpu(fw_hdr->tsem_int_table_data.offset); |
| 11880 | INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 11881 | be32_to_cpu(fw_hdr->tsem_pram_data.offset); |
| 11882 | INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 11883 | be32_to_cpu(fw_hdr->usem_int_table_data.offset); |
| 11884 | INIT_USEM_PRAM_DATA(bp) = bp->firmware->data + |
| 11885 | be32_to_cpu(fw_hdr->usem_pram_data.offset); |
| 11886 | INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 11887 | be32_to_cpu(fw_hdr->xsem_int_table_data.offset); |
| 11888 | INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 11889 | be32_to_cpu(fw_hdr->xsem_pram_data.offset); |
| 11890 | INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data + |
| 11891 | be32_to_cpu(fw_hdr->csem_int_table_data.offset); |
| 11892 | INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data + |
| 11893 | be32_to_cpu(fw_hdr->csem_pram_data.offset); |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11894 | |
| 11895 | return 0; |
Eilon Greenstein | ab6ad5a | 2009-08-12 08:24:29 +0000 | [diff] [blame] | 11896 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11897 | init_offsets_alloc_err: |
| 11898 | kfree(bp->init_ops); |
| 11899 | init_ops_alloc_err: |
| 11900 | kfree(bp->init_data); |
| 11901 | request_firmware_exit: |
| 11902 | release_firmware(bp->firmware); |
| 11903 | |
| 11904 | return rc; |
| 11905 | } |
| 11906 | |
| 11907 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11908 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
| 11909 | const struct pci_device_id *ent) |
| 11910 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11911 | struct net_device *dev = NULL; |
| 11912 | struct bnx2x *bp; |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11913 | int pcie_width, pcie_speed; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11914 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11915 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11916 | /* dev zeroed in init_etherdev */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 11917 | dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11918 | if (!dev) { |
| 11919 | printk(KERN_ERR PFX "Cannot allocate net device\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11920 | return -ENOMEM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11921 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11922 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11923 | bp = netdev_priv(dev); |
| 11924 | bp->msglevel = debug; |
| 11925 | |
Eilon Greenstein | df4770de | 2009-08-12 08:23:28 +0000 | [diff] [blame] | 11926 | pci_set_drvdata(pdev, dev); |
| 11927 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11928 | rc = bnx2x_init_dev(pdev, dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11929 | if (rc < 0) { |
| 11930 | free_netdev(dev); |
| 11931 | return rc; |
| 11932 | } |
| 11933 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11934 | rc = bnx2x_init_bp(bp); |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 11935 | if (rc) |
| 11936 | goto init_one_exit; |
| 11937 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11938 | /* Set init arrays */ |
| 11939 | rc = bnx2x_init_firmware(bp, &pdev->dev); |
| 11940 | if (rc) { |
| 11941 | printk(KERN_ERR PFX "Error loading firmware\n"); |
| 11942 | goto init_one_exit; |
| 11943 | } |
| 11944 | |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 11945 | rc = register_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11946 | if (rc) { |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 11947 | dev_err(&pdev->dev, "Cannot register net device\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11948 | goto init_one_exit; |
| 11949 | } |
| 11950 | |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11951 | bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed); |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11952 | printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx," |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame] | 11953 | " IRQ %d, ", dev->name, board_info[ent->driver_data].name, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11954 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), |
Eilon Greenstein | 37f9ce6 | 2009-08-12 08:23:34 +0000 | [diff] [blame] | 11955 | pcie_width, (pcie_speed == 2) ? "5GHz (Gen2)" : "2.5GHz", |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 11956 | dev->base_addr, bp->pdev->irq); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 11957 | printk(KERN_CONT "node addr %pM\n", dev->dev_addr); |
Eilon Greenstein | c016201 | 2009-03-02 08:01:05 +0000 | [diff] [blame] | 11958 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11959 | return 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 11960 | |
| 11961 | init_one_exit: |
| 11962 | if (bp->regview) |
| 11963 | iounmap(bp->regview); |
| 11964 | |
| 11965 | if (bp->doorbells) |
| 11966 | iounmap(bp->doorbells); |
| 11967 | |
| 11968 | free_netdev(dev); |
| 11969 | |
| 11970 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 11971 | pci_release_regions(pdev); |
| 11972 | |
| 11973 | pci_disable_device(pdev); |
| 11974 | pci_set_drvdata(pdev, NULL); |
| 11975 | |
| 11976 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11977 | } |
| 11978 | |
| 11979 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) |
| 11980 | { |
| 11981 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11982 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11983 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11984 | if (!dev) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11985 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 11986 | return; |
| 11987 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 11988 | bp = netdev_priv(dev); |
| 11989 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11990 | unregister_netdev(dev); |
| 11991 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 11992 | kfree(bp->init_ops_offsets); |
| 11993 | kfree(bp->init_ops); |
| 11994 | kfree(bp->init_data); |
| 11995 | release_firmware(bp->firmware); |
| 11996 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11997 | if (bp->regview) |
| 11998 | iounmap(bp->regview); |
| 11999 | |
| 12000 | if (bp->doorbells) |
| 12001 | iounmap(bp->doorbells); |
| 12002 | |
| 12003 | free_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12004 | |
| 12005 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 12006 | pci_release_regions(pdev); |
| 12007 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12008 | pci_disable_device(pdev); |
| 12009 | pci_set_drvdata(pdev, NULL); |
| 12010 | } |
| 12011 | |
| 12012 | static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state) |
| 12013 | { |
| 12014 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12015 | struct bnx2x *bp; |
| 12016 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12017 | if (!dev) { |
| 12018 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 12019 | return -ENODEV; |
| 12020 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12021 | bp = netdev_priv(dev); |
| 12022 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12023 | rtnl_lock(); |
| 12024 | |
| 12025 | pci_save_state(pdev); |
| 12026 | |
| 12027 | if (!netif_running(dev)) { |
| 12028 | rtnl_unlock(); |
| 12029 | return 0; |
| 12030 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12031 | |
| 12032 | netif_device_detach(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12033 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 12034 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12035 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12036 | bnx2x_set_power_state(bp, pci_choose_state(pdev, state)); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12037 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12038 | rtnl_unlock(); |
| 12039 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12040 | return 0; |
| 12041 | } |
| 12042 | |
| 12043 | static int bnx2x_resume(struct pci_dev *pdev) |
| 12044 | { |
| 12045 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12046 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12047 | int rc; |
| 12048 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12049 | if (!dev) { |
| 12050 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 12051 | return -ENODEV; |
| 12052 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12053 | bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12054 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12055 | rtnl_lock(); |
| 12056 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 12057 | pci_restore_state(pdev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12058 | |
| 12059 | if (!netif_running(dev)) { |
| 12060 | rtnl_unlock(); |
| 12061 | return 0; |
| 12062 | } |
| 12063 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12064 | bnx2x_set_power_state(bp, PCI_D0); |
| 12065 | netif_device_attach(dev); |
| 12066 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 12067 | rc = bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12068 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 12069 | rtnl_unlock(); |
| 12070 | |
| 12071 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12072 | } |
| 12073 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12074 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
| 12075 | { |
| 12076 | int i; |
| 12077 | |
| 12078 | bp->state = BNX2X_STATE_ERROR; |
| 12079 | |
| 12080 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 12081 | |
| 12082 | bnx2x_netif_stop(bp, 0); |
| 12083 | |
| 12084 | del_timer_sync(&bp->timer); |
| 12085 | bp->stats_state = STATS_STATE_DISABLED; |
| 12086 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 12087 | |
| 12088 | /* Release IRQs */ |
| 12089 | bnx2x_free_irq(bp); |
| 12090 | |
| 12091 | if (CHIP_IS_E1(bp)) { |
| 12092 | struct mac_configuration_cmd *config = |
| 12093 | bnx2x_sp(bp, mcast_config); |
| 12094 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 12095 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12096 | CAM_INVALIDATE(config->config_table[i]); |
| 12097 | } |
| 12098 | |
| 12099 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 12100 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 12101 | for_each_rx_queue(bp, i) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12102 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 12103 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 12104 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12105 | bnx2x_free_mem(bp); |
| 12106 | |
| 12107 | bp->state = BNX2X_STATE_CLOSED; |
| 12108 | |
| 12109 | netif_carrier_off(bp->dev); |
| 12110 | |
| 12111 | return 0; |
| 12112 | } |
| 12113 | |
| 12114 | static void bnx2x_eeh_recover(struct bnx2x *bp) |
| 12115 | { |
| 12116 | u32 val; |
| 12117 | |
| 12118 | mutex_init(&bp->port.phy_mutex); |
| 12119 | |
| 12120 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 12121 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 12122 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 12123 | |
| 12124 | if (!bp->common.shmem_base || |
| 12125 | (bp->common.shmem_base < 0xA0000) || |
| 12126 | (bp->common.shmem_base >= 0xC0000)) { |
| 12127 | BNX2X_DEV_INFO("MCP not active\n"); |
| 12128 | bp->flags |= NO_MCP_FLAG; |
| 12129 | return; |
| 12130 | } |
| 12131 | |
| 12132 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 12133 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 12134 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 12135 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 12136 | |
| 12137 | if (!BP_NOMCP(bp)) { |
| 12138 | bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header) |
| 12139 | & DRV_MSG_SEQ_NUMBER_MASK); |
| 12140 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 12141 | } |
| 12142 | } |
| 12143 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12144 | /** |
| 12145 | * bnx2x_io_error_detected - called when PCI error is detected |
| 12146 | * @pdev: Pointer to PCI device |
| 12147 | * @state: The current pci connection state |
| 12148 | * |
| 12149 | * This function is called after a PCI bus error affecting |
| 12150 | * this device has been detected. |
| 12151 | */ |
| 12152 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, |
| 12153 | pci_channel_state_t state) |
| 12154 | { |
| 12155 | struct net_device *dev = pci_get_drvdata(pdev); |
| 12156 | struct bnx2x *bp = netdev_priv(dev); |
| 12157 | |
| 12158 | rtnl_lock(); |
| 12159 | |
| 12160 | netif_device_detach(dev); |
| 12161 | |
Dean Nelson | 07ce50e4 | 2009-07-31 09:13:25 +0000 | [diff] [blame] | 12162 | if (state == pci_channel_io_perm_failure) { |
| 12163 | rtnl_unlock(); |
| 12164 | return PCI_ERS_RESULT_DISCONNECT; |
| 12165 | } |
| 12166 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12167 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12168 | bnx2x_eeh_nic_unload(bp); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12169 | |
| 12170 | pci_disable_device(pdev); |
| 12171 | |
| 12172 | rtnl_unlock(); |
| 12173 | |
| 12174 | /* Request a slot reset */ |
| 12175 | return PCI_ERS_RESULT_NEED_RESET; |
| 12176 | } |
| 12177 | |
| 12178 | /** |
| 12179 | * bnx2x_io_slot_reset - called after the PCI bus has been reset |
| 12180 | * @pdev: Pointer to PCI device |
| 12181 | * |
| 12182 | * Restart the card from scratch, as if from a cold-boot. |
| 12183 | */ |
| 12184 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) |
| 12185 | { |
| 12186 | struct net_device *dev = pci_get_drvdata(pdev); |
| 12187 | struct bnx2x *bp = netdev_priv(dev); |
| 12188 | |
| 12189 | rtnl_lock(); |
| 12190 | |
| 12191 | if (pci_enable_device(pdev)) { |
| 12192 | dev_err(&pdev->dev, |
| 12193 | "Cannot re-enable PCI device after reset\n"); |
| 12194 | rtnl_unlock(); |
| 12195 | return PCI_ERS_RESULT_DISCONNECT; |
| 12196 | } |
| 12197 | |
| 12198 | pci_set_master(pdev); |
| 12199 | pci_restore_state(pdev); |
| 12200 | |
| 12201 | if (netif_running(dev)) |
| 12202 | bnx2x_set_power_state(bp, PCI_D0); |
| 12203 | |
| 12204 | rtnl_unlock(); |
| 12205 | |
| 12206 | return PCI_ERS_RESULT_RECOVERED; |
| 12207 | } |
| 12208 | |
| 12209 | /** |
| 12210 | * bnx2x_io_resume - called when traffic can start flowing again |
| 12211 | * @pdev: Pointer to PCI device |
| 12212 | * |
| 12213 | * This callback is called when the error recovery driver tells us that |
| 12214 | * its OK to resume normal operation. |
| 12215 | */ |
| 12216 | static void bnx2x_io_resume(struct pci_dev *pdev) |
| 12217 | { |
| 12218 | struct net_device *dev = pci_get_drvdata(pdev); |
| 12219 | struct bnx2x *bp = netdev_priv(dev); |
| 12220 | |
| 12221 | rtnl_lock(); |
| 12222 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12223 | bnx2x_eeh_recover(bp); |
| 12224 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12225 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 12226 | bnx2x_nic_load(bp, LOAD_NORMAL); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12227 | |
| 12228 | netif_device_attach(dev); |
| 12229 | |
| 12230 | rtnl_unlock(); |
| 12231 | } |
| 12232 | |
| 12233 | static struct pci_error_handlers bnx2x_err_handler = { |
| 12234 | .error_detected = bnx2x_io_error_detected, |
Eilon Greenstein | 356e238 | 2009-02-12 08:38:32 +0000 | [diff] [blame] | 12235 | .slot_reset = bnx2x_io_slot_reset, |
| 12236 | .resume = bnx2x_io_resume, |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12237 | }; |
| 12238 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12239 | static struct pci_driver bnx2x_pci_driver = { |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 12240 | .name = DRV_MODULE_NAME, |
| 12241 | .id_table = bnx2x_pci_tbl, |
| 12242 | .probe = bnx2x_init_one, |
| 12243 | .remove = __devexit_p(bnx2x_remove_one), |
| 12244 | .suspend = bnx2x_suspend, |
| 12245 | .resume = bnx2x_resume, |
| 12246 | .err_handler = &bnx2x_err_handler, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12247 | }; |
| 12248 | |
| 12249 | static int __init bnx2x_init(void) |
| 12250 | { |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 12251 | int ret; |
| 12252 | |
Eilon Greenstein | 938cf54 | 2009-08-12 08:23:37 +0000 | [diff] [blame] | 12253 | printk(KERN_INFO "%s", version); |
| 12254 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 12255 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
| 12256 | if (bnx2x_wq == NULL) { |
| 12257 | printk(KERN_ERR PFX "Cannot create workqueue\n"); |
| 12258 | return -ENOMEM; |
| 12259 | } |
| 12260 | |
Stanislaw Gruszka | dd21ca6 | 2009-05-05 23:22:01 +0000 | [diff] [blame] | 12261 | ret = pci_register_driver(&bnx2x_pci_driver); |
| 12262 | if (ret) { |
| 12263 | printk(KERN_ERR PFX "Cannot register driver\n"); |
| 12264 | destroy_workqueue(bnx2x_wq); |
| 12265 | } |
| 12266 | return ret; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12267 | } |
| 12268 | |
| 12269 | static void __exit bnx2x_cleanup(void) |
| 12270 | { |
| 12271 | pci_unregister_driver(&bnx2x_pci_driver); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 12272 | |
| 12273 | destroy_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 12274 | } |
| 12275 | |
| 12276 | module_init(bnx2x_init); |
| 12277 | module_exit(bnx2x_cleanup); |
| 12278 | |
Vladislav Zolotarov | 94a78b7 | 2009-04-27 03:27:43 -0700 | [diff] [blame] | 12279 | |