Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2011 Emulex |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 18 | #include <linux/prefetch.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 20 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 21 | #include "be_cmds.h" |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 22 | #include <asm/div64.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 23 | |
| 24 | MODULE_VERSION(DRV_VER); |
| 25 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
| 26 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
| 27 | MODULE_AUTHOR("ServerEngines Corporation"); |
| 28 | MODULE_LICENSE("GPL"); |
| 29 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 30 | static ushort rx_frag_size = 2048; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 31 | static unsigned int num_vfs; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 32 | module_param(rx_frag_size, ushort, S_IRUGO); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 33 | module_param(num_vfs, uint, S_IRUGO); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 34 | MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data."); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 35 | MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 36 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 37 | static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 38 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Ajit Khaparde | 59fd5d8 | 2009-10-29 01:11:06 -0700 | [diff] [blame] | 39 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 40 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 41 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 42 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)}, |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 43 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 44 | { 0 } |
| 45 | }; |
| 46 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 47 | /* UE Status Low CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 48 | static const char * const ue_status_low_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 49 | "CEV", |
| 50 | "CTX", |
| 51 | "DBUF", |
| 52 | "ERX", |
| 53 | "Host", |
| 54 | "MPU", |
| 55 | "NDMA", |
| 56 | "PTC ", |
| 57 | "RDMA ", |
| 58 | "RXF ", |
| 59 | "RXIPS ", |
| 60 | "RXULP0 ", |
| 61 | "RXULP1 ", |
| 62 | "RXULP2 ", |
| 63 | "TIM ", |
| 64 | "TPOST ", |
| 65 | "TPRE ", |
| 66 | "TXIPS ", |
| 67 | "TXULP0 ", |
| 68 | "TXULP1 ", |
| 69 | "UC ", |
| 70 | "WDMA ", |
| 71 | "TXULP2 ", |
| 72 | "HOST1 ", |
| 73 | "P0_OB_LINK ", |
| 74 | "P1_OB_LINK ", |
| 75 | "HOST_GPIO ", |
| 76 | "MBOX ", |
| 77 | "AXGMAC0", |
| 78 | "AXGMAC1", |
| 79 | "JTAG", |
| 80 | "MPU_INTPEND" |
| 81 | }; |
| 82 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 83 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 84 | "LPCMEMHOST", |
| 85 | "MGMT_MAC", |
| 86 | "PCS0ONLINE", |
| 87 | "MPU_IRAM", |
| 88 | "PCS1ONLINE", |
| 89 | "PCTL0", |
| 90 | "PCTL1", |
| 91 | "PMEM", |
| 92 | "RR", |
| 93 | "TXPB", |
| 94 | "RXPP", |
| 95 | "XAUI", |
| 96 | "TXP", |
| 97 | "ARM", |
| 98 | "IPC", |
| 99 | "HOST2", |
| 100 | "HOST3", |
| 101 | "HOST4", |
| 102 | "HOST5", |
| 103 | "HOST6", |
| 104 | "HOST7", |
| 105 | "HOST8", |
| 106 | "HOST9", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 107 | "NETC", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 108 | "Unknown", |
| 109 | "Unknown", |
| 110 | "Unknown", |
| 111 | "Unknown", |
| 112 | "Unknown", |
| 113 | "Unknown", |
| 114 | "Unknown", |
| 115 | "Unknown" |
| 116 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 117 | |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 118 | /* Is BE in a multi-channel mode */ |
| 119 | static inline bool be_is_mc(struct be_adapter *adapter) { |
| 120 | return (adapter->function_mode & FLEX10_MODE || |
| 121 | adapter->function_mode & VNIC_MODE || |
| 122 | adapter->function_mode & UMC_ENABLED); |
| 123 | } |
| 124 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 125 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 126 | { |
| 127 | struct be_dma_mem *mem = &q->dma_mem; |
| 128 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 129 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 130 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q, |
| 134 | u16 len, u16 entry_size) |
| 135 | { |
| 136 | struct be_dma_mem *mem = &q->dma_mem; |
| 137 | |
| 138 | memset(q, 0, sizeof(*q)); |
| 139 | q->len = len; |
| 140 | q->entry_size = entry_size; |
| 141 | mem->size = len * entry_size; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 142 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 143 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 144 | if (!mem->va) |
| 145 | return -1; |
| 146 | memset(mem->va, 0, mem->size); |
| 147 | return 0; |
| 148 | } |
| 149 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 150 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 151 | { |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 152 | u32 reg, enabled; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 153 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 154 | if (adapter->eeh_err) |
| 155 | return; |
| 156 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 157 | pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, |
| 158 | ®); |
| 159 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 160 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 161 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 162 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 163 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 164 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 165 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 166 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 167 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 168 | pci_write_config_dword(adapter->pdev, |
| 169 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 172 | static void be_rxq_notify(struct be_adapter *adapter, u16 qid, u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 173 | { |
| 174 | u32 val = 0; |
| 175 | val |= qid & DB_RQ_RING_ID_MASK; |
| 176 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 177 | |
| 178 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 179 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 182 | static void be_txq_notify(struct be_adapter *adapter, u16 qid, u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 183 | { |
| 184 | u32 val = 0; |
| 185 | val |= qid & DB_TXULP_RING_ID_MASK; |
| 186 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 187 | |
| 188 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 189 | iowrite32(val, adapter->db + DB_TXULP1_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 192 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 193 | bool arm, bool clear_int, u16 num_popped) |
| 194 | { |
| 195 | u32 val = 0; |
| 196 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 197 | val |= ((qid & DB_EQ_RING_ID_EXT_MASK) << |
| 198 | DB_EQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 199 | |
| 200 | if (adapter->eeh_err) |
| 201 | return; |
| 202 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 203 | if (arm) |
| 204 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 205 | if (clear_int) |
| 206 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 207 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 208 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 209 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 212 | void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 213 | { |
| 214 | u32 val = 0; |
| 215 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 216 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 217 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 218 | |
| 219 | if (adapter->eeh_err) |
| 220 | return; |
| 221 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 222 | if (arm) |
| 223 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 224 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 225 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 228 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 229 | { |
| 230 | struct be_adapter *adapter = netdev_priv(netdev); |
| 231 | struct sockaddr *addr = p; |
| 232 | int status = 0; |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 233 | u8 current_mac[ETH_ALEN]; |
| 234 | u32 pmac_id = adapter->pmac_id; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 235 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 236 | if (!is_valid_ether_addr(addr->sa_data)) |
| 237 | return -EADDRNOTAVAIL; |
| 238 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 239 | status = be_cmd_mac_addr_query(adapter, current_mac, |
| 240 | MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 241 | if (status) |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 242 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 243 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 244 | if (memcmp(addr->sa_data, current_mac, ETH_ALEN)) { |
| 245 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 246 | adapter->if_handle, &adapter->pmac_id, 0); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 247 | if (status) |
| 248 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 249 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 250 | be_cmd_pmac_del(adapter, adapter->if_handle, pmac_id, 0); |
| 251 | } |
| 252 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 253 | return 0; |
| 254 | err: |
| 255 | dev_err(&adapter->pdev->dev, "MAC %pM set Failed\n", addr->sa_data); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 256 | return status; |
| 257 | } |
| 258 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 259 | static void populate_be2_stats(struct be_adapter *adapter) |
| 260 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 261 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 262 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 263 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 264 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 265 | &rxf_stats->port[adapter->port_num]; |
| 266 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 267 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 268 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 269 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 270 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 271 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 272 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 273 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 274 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 275 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 276 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 277 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 278 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 279 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 280 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 281 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 282 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 283 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 284 | drvs->rx_dropped_header_too_small = |
| 285 | port_stats->rx_dropped_header_too_small; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 286 | drvs->rx_address_match_errors = port_stats->rx_address_match_errors; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 287 | drvs->rx_alignment_symbol_errors = |
| 288 | port_stats->rx_alignment_symbol_errors; |
| 289 | |
| 290 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 291 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 292 | |
| 293 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 294 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 295 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 296 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 297 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 298 | drvs->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb; |
| 299 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 300 | drvs->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring; |
| 301 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 302 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 303 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 304 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 305 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 306 | } |
| 307 | |
| 308 | static void populate_be3_stats(struct be_adapter *adapter) |
| 309 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 310 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 311 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 312 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 313 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 314 | &rxf_stats->port[adapter->port_num]; |
| 315 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 316 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 317 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 318 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 319 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 320 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 321 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 322 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 323 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 324 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 325 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 326 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 327 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 328 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 329 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 330 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 331 | drvs->rx_dropped_header_too_small = |
| 332 | port_stats->rx_dropped_header_too_small; |
| 333 | drvs->rx_input_fifo_overflow_drop = |
| 334 | port_stats->rx_input_fifo_overflow_drop; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 335 | drvs->rx_address_match_errors = port_stats->rx_address_match_errors; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 336 | drvs->rx_alignment_symbol_errors = |
| 337 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 338 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 339 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 340 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 341 | drvs->jabber_events = port_stats->jabber_events; |
| 342 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 343 | drvs->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb; |
| 344 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 345 | drvs->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring; |
| 346 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 347 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 348 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 349 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 350 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 351 | } |
| 352 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 353 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 354 | { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 355 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 356 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 357 | struct lancer_pport_stats *pport_stats = |
| 358 | pport_stats_from_cmd(adapter); |
| 359 | |
| 360 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 361 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 362 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 363 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 364 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 365 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 366 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 367 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 368 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 369 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 370 | drvs->rx_dropped_tcp_length = |
| 371 | pport_stats->rx_dropped_invalid_tcp_length; |
| 372 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 373 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 374 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 375 | drvs->rx_dropped_header_too_small = |
| 376 | pport_stats->rx_dropped_header_too_small; |
| 377 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
| 378 | drvs->rx_address_match_errors = pport_stats->rx_address_match_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 379 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 380 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 381 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 382 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 383 | drvs->jabber_events = pport_stats->rx_jabbers; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 384 | drvs->rx_drops_invalid_ring = pport_stats->rx_drops_invalid_queue; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 385 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 386 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 387 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 388 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 389 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 390 | |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 391 | static void accumulate_16bit_val(u32 *acc, u16 val) |
| 392 | { |
| 393 | #define lo(x) (x & 0xFFFF) |
| 394 | #define hi(x) (x & 0xFFFF0000) |
| 395 | bool wrapped = val < lo(*acc); |
| 396 | u32 newacc = hi(*acc) + val; |
| 397 | |
| 398 | if (wrapped) |
| 399 | newacc += 65536; |
| 400 | ACCESS_ONCE(*acc) = newacc; |
| 401 | } |
| 402 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 403 | void be_parse_stats(struct be_adapter *adapter) |
| 404 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 405 | struct be_erx_stats_v1 *erx = be_erx_stats_from_cmd(adapter); |
| 406 | struct be_rx_obj *rxo; |
| 407 | int i; |
| 408 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 409 | if (adapter->generation == BE_GEN3) { |
| 410 | if (lancer_chip(adapter)) |
| 411 | populate_lancer_stats(adapter); |
| 412 | else |
| 413 | populate_be3_stats(adapter); |
| 414 | } else { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 415 | populate_be2_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 416 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 417 | |
| 418 | /* as erx_v1 is longer than v0, ok to use v1 defn for v0 access */ |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 419 | for_all_rx_queues(adapter, rxo, i) { |
| 420 | /* below erx HW counter can actually wrap around after |
| 421 | * 65535. Driver accumulates a 32-bit value |
| 422 | */ |
| 423 | accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags, |
| 424 | (u16)erx->rx_drops_no_fragments[rxo->q.id]); |
| 425 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 428 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
| 429 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 430 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 431 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 432 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 433 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 434 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 435 | u64 pkts, bytes; |
| 436 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 437 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 438 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 439 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 440 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
| 441 | do { |
| 442 | start = u64_stats_fetch_begin_bh(&rx_stats->sync); |
| 443 | pkts = rx_stats(rxo)->rx_pkts; |
| 444 | bytes = rx_stats(rxo)->rx_bytes; |
| 445 | } while (u64_stats_fetch_retry_bh(&rx_stats->sync, start)); |
| 446 | stats->rx_packets += pkts; |
| 447 | stats->rx_bytes += bytes; |
| 448 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 449 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 450 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 453 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 454 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
| 455 | do { |
| 456 | start = u64_stats_fetch_begin_bh(&tx_stats->sync); |
| 457 | pkts = tx_stats(txo)->tx_pkts; |
| 458 | bytes = tx_stats(txo)->tx_bytes; |
| 459 | } while (u64_stats_fetch_retry_bh(&tx_stats->sync, start)); |
| 460 | stats->tx_packets += pkts; |
| 461 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 462 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 463 | |
| 464 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 465 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 466 | drvs->rx_alignment_symbol_errors + |
| 467 | drvs->rx_in_range_errors + |
| 468 | drvs->rx_out_range_errors + |
| 469 | drvs->rx_frame_too_long + |
| 470 | drvs->rx_dropped_too_small + |
| 471 | drvs->rx_dropped_too_short + |
| 472 | drvs->rx_dropped_header_too_small + |
| 473 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 474 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 475 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 476 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 477 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 478 | drvs->rx_out_range_errors + |
| 479 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 480 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 481 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 482 | |
| 483 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 484 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 485 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 486 | /* receiver fifo overrun */ |
| 487 | /* drops_no_pbuf is no per i/f, it's per BE card */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 488 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 489 | drvs->rx_input_fifo_overflow_drop + |
| 490 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 491 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 494 | void be_link_status_update(struct be_adapter *adapter, u32 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 495 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 496 | struct net_device *netdev = adapter->netdev; |
| 497 | |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 498 | /* when link status changes, link speed must be re-queried from card */ |
| 499 | adapter->link_speed = -1; |
| 500 | if ((link_status & LINK_STATUS_MASK) == LINK_UP) { |
| 501 | netif_carrier_on(netdev); |
| 502 | dev_info(&adapter->pdev->dev, "%s: Link up\n", netdev->name); |
| 503 | } else { |
| 504 | netif_carrier_off(netdev); |
| 505 | dev_info(&adapter->pdev->dev, "%s: Link down\n", netdev->name); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 506 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 509 | static void be_tx_stats_update(struct be_tx_obj *txo, |
Ajit Khaparde | 91992e4 | 2010-02-19 13:57:12 +0000 | [diff] [blame] | 510 | u32 wrb_cnt, u32 copied, u32 gso_segs, bool stopped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 511 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 512 | struct be_tx_stats *stats = tx_stats(txo); |
| 513 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 514 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 515 | stats->tx_reqs++; |
| 516 | stats->tx_wrbs += wrb_cnt; |
| 517 | stats->tx_bytes += copied; |
| 518 | stats->tx_pkts += (gso_segs ? gso_segs : 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 519 | if (stopped) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 520 | stats->tx_stops++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 521 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | /* Determine number of WRB entries needed to xmit data in an skb */ |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 525 | static u32 wrb_cnt_for_skb(struct be_adapter *adapter, struct sk_buff *skb, |
| 526 | bool *dummy) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 527 | { |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 528 | int cnt = (skb->len > skb->data_len); |
| 529 | |
| 530 | cnt += skb_shinfo(skb)->nr_frags; |
| 531 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 532 | /* to account for hdr wrb */ |
| 533 | cnt++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 534 | if (lancer_chip(adapter) || !(cnt & 1)) { |
| 535 | *dummy = false; |
| 536 | } else { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 537 | /* add a dummy to make it an even num */ |
| 538 | cnt++; |
| 539 | *dummy = true; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 540 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 541 | BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT); |
| 542 | return cnt; |
| 543 | } |
| 544 | |
| 545 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 546 | { |
| 547 | wrb->frag_pa_hi = upper_32_bits(addr); |
| 548 | wrb->frag_pa_lo = addr & 0xFFFFFFFF; |
| 549 | wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK; |
| 550 | } |
| 551 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 552 | static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr, |
| 553 | struct sk_buff *skb, u32 wrb_cnt, u32 len) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 554 | { |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 555 | u8 vlan_prio = 0; |
| 556 | u16 vlan_tag = 0; |
| 557 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 558 | memset(hdr, 0, sizeof(*hdr)); |
| 559 | |
| 560 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1); |
| 561 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 562 | if (skb_is_gso(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 563 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1); |
| 564 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss, |
| 565 | hdr, skb_shinfo(skb)->gso_size); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 566 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 567 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso6, hdr, 1); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 568 | if (lancer_chip(adapter) && adapter->sli_family == |
| 569 | LANCER_A0_SLI_FAMILY) { |
| 570 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, ipcs, hdr, 1); |
| 571 | if (is_tcp_pkt(skb)) |
| 572 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, |
| 573 | tcpcs, hdr, 1); |
| 574 | else if (is_udp_pkt(skb)) |
| 575 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, |
| 576 | udpcs, hdr, 1); |
| 577 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 578 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 579 | if (is_tcp_pkt(skb)) |
| 580 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1); |
| 581 | else if (is_udp_pkt(skb)) |
| 582 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1); |
| 583 | } |
| 584 | |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 585 | if (vlan_tx_tag_present(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 586 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 587 | vlan_tag = vlan_tx_tag_get(skb); |
| 588 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 589 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 590 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 591 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
| 592 | adapter->recommended_prio; |
| 593 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag, hdr, vlan_tag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1); |
| 597 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, 1); |
| 598 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt); |
| 599 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len); |
| 600 | } |
| 601 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 602 | static void unmap_tx_frag(struct device *dev, struct be_eth_wrb *wrb, |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 603 | bool unmap_single) |
| 604 | { |
| 605 | dma_addr_t dma; |
| 606 | |
| 607 | be_dws_le_to_cpu(wrb, sizeof(*wrb)); |
| 608 | |
| 609 | dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo; |
FUJITA Tomonori | b681ee7 | 2010-04-04 21:40:18 +0000 | [diff] [blame] | 610 | if (wrb->frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 611 | if (unmap_single) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 612 | dma_unmap_single(dev, dma, wrb->frag_len, |
| 613 | DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 614 | else |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 615 | dma_unmap_page(dev, dma, wrb->frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 618 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 619 | static int make_tx_wrbs(struct be_adapter *adapter, struct be_queue_info *txq, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 620 | struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb) |
| 621 | { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 622 | dma_addr_t busaddr; |
| 623 | int i, copied = 0; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 624 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 625 | struct sk_buff *first_skb = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 626 | struct be_eth_wrb *wrb; |
| 627 | struct be_eth_hdr_wrb *hdr; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 628 | bool map_single = false; |
| 629 | u16 map_head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 630 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 631 | hdr = queue_head_node(txq); |
| 632 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 633 | map_head = txq->head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 634 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 635 | if (skb->len > skb->data_len) { |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 636 | int len = skb_headlen(skb); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 637 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 638 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 639 | goto dma_err; |
| 640 | map_single = true; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 641 | wrb = queue_head_node(txq); |
| 642 | wrb_fill(wrb, busaddr, len); |
| 643 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 644 | queue_head_inc(txq); |
| 645 | copied += len; |
| 646 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 647 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 648 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 649 | const struct skb_frag_struct *frag = |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 650 | &skb_shinfo(skb)->frags[i]; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 651 | busaddr = skb_frag_dma_map(dev, frag, 0, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 652 | skb_frag_size(frag), DMA_TO_DEVICE); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 653 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 654 | goto dma_err; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 655 | wrb = queue_head_node(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 656 | wrb_fill(wrb, busaddr, skb_frag_size(frag)); |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 657 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 658 | queue_head_inc(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 659 | copied += skb_frag_size(frag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (dummy_wrb) { |
| 663 | wrb = queue_head_node(txq); |
| 664 | wrb_fill(wrb, 0, 0); |
| 665 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 666 | queue_head_inc(txq); |
| 667 | } |
| 668 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 669 | wrb_fill_hdr(adapter, hdr, first_skb, wrb_cnt, copied); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 670 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 671 | |
| 672 | return copied; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 673 | dma_err: |
| 674 | txq->head = map_head; |
| 675 | while (copied) { |
| 676 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 677 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 678 | map_single = false; |
| 679 | copied -= wrb->frag_len; |
| 680 | queue_head_inc(txq); |
| 681 | } |
| 682 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 685 | static netdev_tx_t be_xmit(struct sk_buff *skb, |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 686 | struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 687 | { |
| 688 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 689 | struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)]; |
| 690 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 691 | u32 wrb_cnt = 0, copied = 0; |
| 692 | u32 start = txq->head; |
| 693 | bool dummy_wrb, stopped = false; |
| 694 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 695 | wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 696 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 697 | copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 698 | if (copied) { |
| 699 | /* record the sent skb in the sent_skb table */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 700 | BUG_ON(txo->sent_skb_list[start]); |
| 701 | txo->sent_skb_list[start] = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 702 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 703 | /* Ensure txq has space for the next skb; Else stop the queue |
| 704 | * *BEFORE* ringing the tx doorbell, so that we serialze the |
| 705 | * tx compls of the current transmit which'll wake up the queue |
| 706 | */ |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 707 | atomic_add(wrb_cnt, &txq->used); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 708 | if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >= |
| 709 | txq->len) { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 710 | netif_stop_subqueue(netdev, skb_get_queue_mapping(skb)); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 711 | stopped = true; |
| 712 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 713 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 714 | be_txq_notify(adapter, txq->id, wrb_cnt); |
| 715 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 716 | be_tx_stats_update(txo, wrb_cnt, copied, |
Ajit Khaparde | 91992e4 | 2010-02-19 13:57:12 +0000 | [diff] [blame] | 717 | skb_shinfo(skb)->gso_segs, stopped); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 718 | } else { |
| 719 | txq->head = start; |
| 720 | dev_kfree_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 721 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 722 | return NETDEV_TX_OK; |
| 723 | } |
| 724 | |
| 725 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 726 | { |
| 727 | struct be_adapter *adapter = netdev_priv(netdev); |
| 728 | if (new_mtu < BE_MIN_MTU || |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 729 | new_mtu > (BE_MAX_JUMBO_FRAME_SIZE - |
| 730 | (ETH_HLEN + ETH_FCS_LEN))) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 731 | dev_info(&adapter->pdev->dev, |
| 732 | "MTU must be between %d and %d bytes\n", |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 733 | BE_MIN_MTU, |
| 734 | (BE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN))); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 735 | return -EINVAL; |
| 736 | } |
| 737 | dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n", |
| 738 | netdev->mtu, new_mtu); |
| 739 | netdev->mtu = new_mtu; |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 744 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 745 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 746 | */ |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 747 | static int be_vid_config(struct be_adapter *adapter, bool vf, u32 vf_num) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 748 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 749 | u16 vtag[BE_NUM_VLANS_SUPPORTED]; |
| 750 | u16 ntags = 0, i; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 751 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 752 | u32 if_handle; |
| 753 | |
| 754 | if (vf) { |
| 755 | if_handle = adapter->vf_cfg[vf_num].vf_if_handle; |
| 756 | vtag[0] = cpu_to_le16(adapter->vf_cfg[vf_num].vf_vlan_tag); |
| 757 | status = be_cmd_vlan_config(adapter, if_handle, vtag, 1, 1, 0); |
| 758 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 759 | |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 760 | /* No need to further configure vids if in promiscuous mode */ |
| 761 | if (adapter->promiscuous) |
| 762 | return 0; |
| 763 | |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 764 | if (adapter->vlans_added <= adapter->max_vlans) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 765 | /* Construct VLAN Table to give to HW */ |
Jesse Gross | b738127 | 2010-10-20 13:56:02 +0000 | [diff] [blame] | 766 | for (i = 0; i < VLAN_N_VID; i++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 767 | if (adapter->vlan_tag[i]) { |
| 768 | vtag[ntags] = cpu_to_le16(i); |
| 769 | ntags++; |
| 770 | } |
| 771 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 772 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 773 | vtag, ntags, 1, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 774 | } else { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 775 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 776 | NULL, 0, 1, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 777 | } |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 778 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 779 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 782 | static void be_vlan_add_vid(struct net_device *netdev, u16 vid) |
| 783 | { |
| 784 | struct be_adapter *adapter = netdev_priv(netdev); |
| 785 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 786 | adapter->vlans_added++; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 787 | if (!be_physfn(adapter)) |
| 788 | return; |
| 789 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 790 | adapter->vlan_tag[vid] = 1; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 791 | if (adapter->vlans_added <= (adapter->max_vlans + 1)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 792 | be_vid_config(adapter, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static void be_vlan_rem_vid(struct net_device *netdev, u16 vid) |
| 796 | { |
| 797 | struct be_adapter *adapter = netdev_priv(netdev); |
| 798 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 799 | adapter->vlans_added--; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 800 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 801 | if (!be_physfn(adapter)) |
| 802 | return; |
| 803 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 804 | adapter->vlan_tag[vid] = 0; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 805 | if (adapter->vlans_added <= adapter->max_vlans) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 806 | be_vid_config(adapter, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 809 | static void be_set_rx_mode(struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 810 | { |
| 811 | struct be_adapter *adapter = netdev_priv(netdev); |
| 812 | |
| 813 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 814 | be_cmd_rx_filter(adapter, IFF_PROMISC, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 815 | adapter->promiscuous = true; |
| 816 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 817 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 818 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 819 | /* BE was previously in promiscuous mode; disable it */ |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 820 | if (adapter->promiscuous) { |
| 821 | adapter->promiscuous = false; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 822 | be_cmd_rx_filter(adapter, IFF_PROMISC, OFF); |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 823 | |
| 824 | if (adapter->vlans_added) |
| 825 | be_vid_config(adapter, false, 0); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 828 | /* Enable multicast promisc if num configured exceeds what we support */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 829 | if (netdev->flags & IFF_ALLMULTI || |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 830 | netdev_mc_count(netdev) > BE_MAX_MC) { |
| 831 | be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 832 | goto done; |
| 833 | } |
| 834 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 835 | be_cmd_rx_filter(adapter, IFF_MULTICAST, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 836 | done: |
| 837 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 840 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 841 | { |
| 842 | struct be_adapter *adapter = netdev_priv(netdev); |
| 843 | int status; |
| 844 | |
| 845 | if (!adapter->sriov_enabled) |
| 846 | return -EPERM; |
| 847 | |
| 848 | if (!is_valid_ether_addr(mac) || (vf >= num_vfs)) |
| 849 | return -EINVAL; |
| 850 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 851 | status = be_cmd_pmac_del(adapter, adapter->vf_cfg[vf].vf_if_handle, |
| 852 | adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 853 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 854 | status = be_cmd_pmac_add(adapter, mac, adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 855 | &adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 856 | if (status) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 857 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n", |
| 858 | mac, vf); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 859 | else |
| 860 | memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN); |
| 861 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 862 | return status; |
| 863 | } |
| 864 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 865 | static int be_get_vf_config(struct net_device *netdev, int vf, |
| 866 | struct ifla_vf_info *vi) |
| 867 | { |
| 868 | struct be_adapter *adapter = netdev_priv(netdev); |
| 869 | |
| 870 | if (!adapter->sriov_enabled) |
| 871 | return -EPERM; |
| 872 | |
| 873 | if (vf >= num_vfs) |
| 874 | return -EINVAL; |
| 875 | |
| 876 | vi->vf = vf; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 877 | vi->tx_rate = adapter->vf_cfg[vf].vf_tx_rate; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 878 | vi->vlan = adapter->vf_cfg[vf].vf_vlan_tag; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 879 | vi->qos = 0; |
| 880 | memcpy(&vi->mac, adapter->vf_cfg[vf].vf_mac_addr, ETH_ALEN); |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 885 | static int be_set_vf_vlan(struct net_device *netdev, |
| 886 | int vf, u16 vlan, u8 qos) |
| 887 | { |
| 888 | struct be_adapter *adapter = netdev_priv(netdev); |
| 889 | int status = 0; |
| 890 | |
| 891 | if (!adapter->sriov_enabled) |
| 892 | return -EPERM; |
| 893 | |
| 894 | if ((vf >= num_vfs) || (vlan > 4095)) |
| 895 | return -EINVAL; |
| 896 | |
| 897 | if (vlan) { |
| 898 | adapter->vf_cfg[vf].vf_vlan_tag = vlan; |
| 899 | adapter->vlans_added++; |
| 900 | } else { |
| 901 | adapter->vf_cfg[vf].vf_vlan_tag = 0; |
| 902 | adapter->vlans_added--; |
| 903 | } |
| 904 | |
| 905 | status = be_vid_config(adapter, true, vf); |
| 906 | |
| 907 | if (status) |
| 908 | dev_info(&adapter->pdev->dev, |
| 909 | "VLAN %d config on VF %d failed\n", vlan, vf); |
| 910 | return status; |
| 911 | } |
| 912 | |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 913 | static int be_set_vf_tx_rate(struct net_device *netdev, |
| 914 | int vf, int rate) |
| 915 | { |
| 916 | struct be_adapter *adapter = netdev_priv(netdev); |
| 917 | int status = 0; |
| 918 | |
| 919 | if (!adapter->sriov_enabled) |
| 920 | return -EPERM; |
| 921 | |
| 922 | if ((vf >= num_vfs) || (rate < 0)) |
| 923 | return -EINVAL; |
| 924 | |
| 925 | if (rate > 10000) |
| 926 | rate = 10000; |
| 927 | |
| 928 | adapter->vf_cfg[vf].vf_tx_rate = rate; |
Ajit Khaparde | 856c401 | 2011-02-11 13:32:32 +0000 | [diff] [blame] | 929 | status = be_cmd_set_qos(adapter, rate / 10, vf + 1); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 930 | |
| 931 | if (status) |
| 932 | dev_info(&adapter->pdev->dev, |
| 933 | "tx rate %d on VF %d failed\n", rate, vf); |
| 934 | return status; |
| 935 | } |
| 936 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 937 | static void be_rx_eqd_update(struct be_adapter *adapter, struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 938 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 939 | struct be_eq_obj *rx_eq = &rxo->rx_eq; |
| 940 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 941 | ulong now = jiffies; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 942 | ulong delta = now - stats->rx_jiffies; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 943 | u64 pkts; |
| 944 | unsigned int start, eqd; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 945 | |
| 946 | if (!rx_eq->enable_aic) |
| 947 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 948 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 949 | /* Wrapped around */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 950 | if (time_before(now, stats->rx_jiffies)) { |
| 951 | stats->rx_jiffies = now; |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 952 | return; |
| 953 | } |
| 954 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 955 | /* Update once a second */ |
| 956 | if (delta < HZ) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 957 | return; |
| 958 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 959 | do { |
| 960 | start = u64_stats_fetch_begin_bh(&stats->sync); |
| 961 | pkts = stats->rx_pkts; |
| 962 | } while (u64_stats_fetch_retry_bh(&stats->sync, start)); |
| 963 | |
Eric Dumazet | 68c3e5a | 2011-08-09 06:23:07 +0000 | [diff] [blame] | 964 | stats->rx_pps = (unsigned long)(pkts - stats->rx_pkts_prev) / (delta / HZ); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 965 | stats->rx_pkts_prev = pkts; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 966 | stats->rx_jiffies = now; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 967 | eqd = stats->rx_pps / 110000; |
| 968 | eqd = eqd << 3; |
| 969 | if (eqd > rx_eq->max_eqd) |
| 970 | eqd = rx_eq->max_eqd; |
| 971 | if (eqd < rx_eq->min_eqd) |
| 972 | eqd = rx_eq->min_eqd; |
| 973 | if (eqd < 10) |
| 974 | eqd = 0; |
| 975 | if (eqd != rx_eq->cur_eqd) { |
| 976 | be_cmd_modify_eqd(adapter, rx_eq->q.id, eqd); |
| 977 | rx_eq->cur_eqd = eqd; |
| 978 | } |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 981 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 982 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 983 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 984 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 985 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 986 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 987 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 988 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 989 | stats->rx_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 990 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 991 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 992 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 993 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 994 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 997 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 998 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 999 | /* L4 checksum is not reliable for non TCP/UDP packets. |
| 1000 | * Also ignore ipcksm for ipv6 pkts */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1001 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
| 1002 | (rxcp->ip_csum || rxcp->ipv6); |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1005 | static struct be_rx_page_info * |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1006 | get_rx_page_info(struct be_adapter *adapter, |
| 1007 | struct be_rx_obj *rxo, |
| 1008 | u16 frag_idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1009 | { |
| 1010 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1011 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1012 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1013 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1014 | BUG_ON(!rx_page_info->page); |
| 1015 | |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1016 | if (rx_page_info->last_page_user) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1017 | dma_unmap_page(&adapter->pdev->dev, |
| 1018 | dma_unmap_addr(rx_page_info, bus), |
| 1019 | adapter->big_page_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1020 | rx_page_info->last_page_user = false; |
| 1021 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1022 | |
| 1023 | atomic_dec(&rxq->used); |
| 1024 | return rx_page_info; |
| 1025 | } |
| 1026 | |
| 1027 | /* Throwaway the data in the Rx completion */ |
| 1028 | static void be_rx_compl_discard(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1029 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1030 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1031 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1032 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1033 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1034 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1035 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1036 | for (i = 0; i < num_rcvd; i++) { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1037 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1038 | put_page(page_info->page); |
| 1039 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1040 | index_inc(&rxcp->rxq_idx, rxq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | /* |
| 1045 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 1046 | * indicated by rxcp. |
| 1047 | */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1048 | static void skb_fill_rx_data(struct be_adapter *adapter, struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1049 | struct sk_buff *skb, struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1050 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1051 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1052 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1053 | u16 i, j; |
| 1054 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1055 | u8 *start; |
| 1056 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1057 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1058 | start = page_address(page_info->page) + page_info->page_offset; |
| 1059 | prefetch(start); |
| 1060 | |
| 1061 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1062 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1063 | |
| 1064 | /* Copy the header portion into skb_data */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1065 | hdr_len = min(BE_HDR_LEN, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1066 | memcpy(skb->data, start, hdr_len); |
| 1067 | skb->len = curr_frag_len; |
| 1068 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
| 1069 | /* Complete packet has now been moved to data */ |
| 1070 | put_page(page_info->page); |
| 1071 | skb->data_len = 0; |
| 1072 | skb->tail += curr_frag_len; |
| 1073 | } else { |
| 1074 | skb_shinfo(skb)->nr_frags = 1; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1075 | skb_frag_set_page(skb, 0, page_info->page); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1076 | skb_shinfo(skb)->frags[0].page_offset = |
| 1077 | page_info->page_offset + hdr_len; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1078 | skb_frag_size_set(&skb_shinfo(skb)->frags[0], curr_frag_len - hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1079 | skb->data_len = curr_frag_len - hdr_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1080 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1081 | skb->tail += hdr_len; |
| 1082 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1083 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1084 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1085 | if (rxcp->pkt_size <= rx_frag_size) { |
| 1086 | BUG_ON(rxcp->num_rcvd != 1); |
| 1087 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1091 | index_inc(&rxcp->rxq_idx, rxq->len); |
| 1092 | remaining = rxcp->pkt_size - curr_frag_len; |
| 1093 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
| 1094 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
| 1095 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1096 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1097 | /* Coalesce all frags from the same physical page in one slot */ |
| 1098 | if (page_info->page_offset == 0) { |
| 1099 | /* Fresh page */ |
| 1100 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1101 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1102 | skb_shinfo(skb)->frags[j].page_offset = |
| 1103 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1104 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1105 | skb_shinfo(skb)->nr_frags++; |
| 1106 | } else { |
| 1107 | put_page(page_info->page); |
| 1108 | } |
| 1109 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1110 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1111 | skb->len += curr_frag_len; |
| 1112 | skb->data_len += curr_frag_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1113 | skb->truesize += rx_frag_size; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1114 | remaining -= curr_frag_len; |
| 1115 | index_inc(&rxcp->rxq_idx, rxq->len); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1116 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1117 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1118 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1121 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1122 | static void be_rx_compl_process(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1123 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1124 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1125 | { |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1126 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1127 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1128 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1129 | skb = netdev_alloc_skb_ip_align(netdev, BE_HDR_LEN); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 1130 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1131 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1132 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1133 | return; |
| 1134 | } |
| 1135 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1136 | skb_fill_rx_data(adapter, rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1137 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1138 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1139 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 1140 | else |
| 1141 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1142 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1143 | skb->protocol = eth_type_trans(skb, netdev); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1144 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1145 | skb->rxhash = rxcp->rss_hash; |
| 1146 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1147 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1148 | if (rxcp->vlanf) |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1149 | __vlan_hwaccel_put_tag(skb, rxcp->vlan_tag); |
| 1150 | |
| 1151 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1154 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
| 1155 | static void be_rx_compl_process_gro(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1156 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1157 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1158 | { |
| 1159 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1160 | struct sk_buff *skb = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1161 | struct be_queue_info *rxq = &rxo->q; |
| 1162 | struct be_eq_obj *eq_obj = &rxo->rx_eq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1163 | u16 remaining, curr_frag_len; |
| 1164 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 1165 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1166 | skb = napi_get_frags(&eq_obj->napi); |
| 1167 | if (!skb) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1168 | be_rx_compl_discard(adapter, rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1169 | return; |
| 1170 | } |
| 1171 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1172 | remaining = rxcp->pkt_size; |
| 1173 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
| 1174 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1175 | |
| 1176 | curr_frag_len = min(remaining, rx_frag_size); |
| 1177 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1178 | /* Coalesce all frags from the same physical page in one slot */ |
| 1179 | if (i == 0 || page_info->page_offset == 0) { |
| 1180 | /* First frag or Fresh page */ |
| 1181 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1182 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1183 | skb_shinfo(skb)->frags[j].page_offset = |
| 1184 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1185 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1186 | } else { |
| 1187 | put_page(page_info->page); |
| 1188 | } |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1189 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1190 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1191 | remaining -= curr_frag_len; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1192 | index_inc(&rxcp->rxq_idx, rxq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1193 | memset(page_info, 0, sizeof(*page_info)); |
| 1194 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1195 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1196 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1197 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1198 | skb->len = rxcp->pkt_size; |
| 1199 | skb->data_len = rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1200 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1201 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1202 | skb->rxhash = rxcp->rss_hash; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1203 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1204 | if (rxcp->vlanf) |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1205 | __vlan_hwaccel_put_tag(skb, rxcp->vlan_tag); |
| 1206 | |
| 1207 | napi_gro_frags(&eq_obj->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1210 | static void be_parse_rx_compl_v1(struct be_adapter *adapter, |
| 1211 | struct be_eth_rx_compl *compl, |
| 1212 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1213 | { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1214 | rxcp->pkt_size = |
| 1215 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, pktsize, compl); |
| 1216 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtp, compl); |
| 1217 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, err, compl); |
| 1218 | rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, tcpf, compl); |
Padmanabh Ratnakar | 9ecb42f | 2011-03-15 14:57:09 -0700 | [diff] [blame] | 1219 | rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, udpf, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1220 | rxcp->ip_csum = |
| 1221 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ipcksm, compl); |
| 1222 | rxcp->l4_csum = |
| 1223 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, l4_cksm, compl); |
| 1224 | rxcp->ipv6 = |
| 1225 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ip_version, compl); |
| 1226 | rxcp->rxq_idx = |
| 1227 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, fragndx, compl); |
| 1228 | rxcp->num_rcvd = |
| 1229 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, numfrags, compl); |
| 1230 | rxcp->pkt_type = |
| 1231 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1232 | rxcp->rss_hash = |
| 1233 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, rsshash, rxcp); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1234 | if (rxcp->vlanf) { |
| 1235 | rxcp->vtm = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtm, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1236 | compl); |
| 1237 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vlan_tag, |
| 1238 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1239 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1240 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, port, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1241 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1242 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1243 | static void be_parse_rx_compl_v0(struct be_adapter *adapter, |
| 1244 | struct be_eth_rx_compl *compl, |
| 1245 | struct be_rx_compl_info *rxcp) |
| 1246 | { |
| 1247 | rxcp->pkt_size = |
| 1248 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, pktsize, compl); |
| 1249 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtp, compl); |
| 1250 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, err, compl); |
| 1251 | rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, tcpf, compl); |
Padmanabh Ratnakar | 9ecb42f | 2011-03-15 14:57:09 -0700 | [diff] [blame] | 1252 | rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, udpf, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1253 | rxcp->ip_csum = |
| 1254 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ipcksm, compl); |
| 1255 | rxcp->l4_csum = |
| 1256 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, l4_cksm, compl); |
| 1257 | rxcp->ipv6 = |
| 1258 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ip_version, compl); |
| 1259 | rxcp->rxq_idx = |
| 1260 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, fragndx, compl); |
| 1261 | rxcp->num_rcvd = |
| 1262 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, numfrags, compl); |
| 1263 | rxcp->pkt_type = |
| 1264 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1265 | rxcp->rss_hash = |
| 1266 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, rsshash, rxcp); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1267 | if (rxcp->vlanf) { |
| 1268 | rxcp->vtm = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtm, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1269 | compl); |
| 1270 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vlan_tag, |
| 1271 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1272 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1273 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, port, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 1277 | { |
| 1278 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 1279 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 1280 | struct be_adapter *adapter = rxo->adapter; |
| 1281 | |
| 1282 | /* For checking the valid bit it is Ok to use either definition as the |
| 1283 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 1284 | if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] == 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1285 | return NULL; |
| 1286 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1287 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1288 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 1289 | |
| 1290 | if (adapter->be3_native) |
| 1291 | be_parse_rx_compl_v1(adapter, compl, rxcp); |
| 1292 | else |
| 1293 | be_parse_rx_compl_v0(adapter, compl, rxcp); |
| 1294 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1295 | if (rxcp->vlanf) { |
| 1296 | /* vlanf could be wrongly set in some cards. |
| 1297 | * ignore if vtm is not set */ |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 1298 | if ((adapter->function_mode & FLEX10_MODE) && !rxcp->vtm) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1299 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1300 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1301 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1302 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1303 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 1304 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1305 | !adapter->vlan_tag[rxcp->vlan_tag]) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1306 | rxcp->vlanf = 0; |
| 1307 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1308 | |
| 1309 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 1310 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1311 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1312 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1313 | return rxcp; |
| 1314 | } |
| 1315 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1316 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1317 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1318 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1319 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1320 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1321 | gfp |= __GFP_COMP; |
| 1322 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 1327 | * receive buffers to BE |
| 1328 | */ |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1329 | static void be_post_rx_frags(struct be_rx_obj *rxo, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1330 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1331 | struct be_adapter *adapter = rxo->adapter; |
| 1332 | struct be_rx_page_info *page_info_tbl = rxo->page_info_tbl; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1333 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1334 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1335 | struct page *pagep = NULL; |
| 1336 | struct be_eth_rx_d *rxd; |
| 1337 | u64 page_dmaaddr = 0, frag_dmaaddr; |
| 1338 | u32 posted, page_offset = 0; |
| 1339 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1340 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1341 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { |
| 1342 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1343 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1344 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1345 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1346 | break; |
| 1347 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1348 | page_dmaaddr = dma_map_page(&adapter->pdev->dev, pagep, |
| 1349 | 0, adapter->big_page_size, |
| 1350 | DMA_FROM_DEVICE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1351 | page_info->page_offset = 0; |
| 1352 | } else { |
| 1353 | get_page(pagep); |
| 1354 | page_info->page_offset = page_offset + rx_frag_size; |
| 1355 | } |
| 1356 | page_offset = page_info->page_offset; |
| 1357 | page_info->page = pagep; |
FUJITA Tomonori | fac6da5 | 2010-04-01 16:53:22 +0000 | [diff] [blame] | 1358 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1359 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
| 1360 | |
| 1361 | rxd = queue_head_node(rxq); |
| 1362 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 1363 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1364 | |
| 1365 | /* Any space left in the current big page for another frag? */ |
| 1366 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 1367 | adapter->big_page_size) { |
| 1368 | pagep = NULL; |
| 1369 | page_info->last_page_user = true; |
| 1370 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1371 | |
| 1372 | prev_page_info = page_info; |
| 1373 | queue_head_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1374 | page_info = &page_info_tbl[rxq->head]; |
| 1375 | } |
| 1376 | if (pagep) |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1377 | prev_page_info->last_page_user = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1378 | |
| 1379 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1380 | atomic_add(posted, &rxq->used); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1381 | be_rxq_notify(adapter, rxq->id, posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1382 | } else if (atomic_read(&rxq->used) == 0) { |
| 1383 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1384 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1385 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1388 | static struct be_eth_tx_compl *be_tx_compl_get(struct be_queue_info *tx_cq) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1389 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1390 | struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq); |
| 1391 | |
| 1392 | if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
| 1393 | return NULL; |
| 1394 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1395 | rmb(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1396 | be_dws_le_to_cpu(txcp, sizeof(*txcp)); |
| 1397 | |
| 1398 | txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
| 1399 | |
| 1400 | queue_tail_inc(tx_cq); |
| 1401 | return txcp; |
| 1402 | } |
| 1403 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1404 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
| 1405 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1406 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1407 | struct be_queue_info *txq = &txo->q; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1408 | struct be_eth_wrb *wrb; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1409 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1410 | struct sk_buff *sent_skb; |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1411 | u16 cur_index, num_wrbs = 1; /* account for hdr wrb */ |
| 1412 | bool unmap_skb_hdr = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1413 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1414 | sent_skb = sent_skbs[txq->tail]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1415 | BUG_ON(!sent_skb); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1416 | sent_skbs[txq->tail] = NULL; |
| 1417 | |
| 1418 | /* skip header wrb */ |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1419 | queue_tail_inc(txq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1420 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1421 | do { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1422 | cur_index = txq->tail; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1423 | wrb = queue_tail_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1424 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
| 1425 | (unmap_skb_hdr && skb_headlen(sent_skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1426 | unmap_skb_hdr = false; |
| 1427 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1428 | num_wrbs++; |
| 1429 | queue_tail_inc(txq); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1430 | } while (cur_index != last_index); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1431 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1432 | kfree_skb(sent_skb); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1433 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1436 | static inline struct be_eq_entry *event_get(struct be_eq_obj *eq_obj) |
| 1437 | { |
| 1438 | struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q); |
| 1439 | |
| 1440 | if (!eqe->evt) |
| 1441 | return NULL; |
| 1442 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1443 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1444 | eqe->evt = le32_to_cpu(eqe->evt); |
| 1445 | queue_tail_inc(&eq_obj->q); |
| 1446 | return eqe; |
| 1447 | } |
| 1448 | |
| 1449 | static int event_handle(struct be_adapter *adapter, |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1450 | struct be_eq_obj *eq_obj, |
| 1451 | bool rearm) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1452 | { |
| 1453 | struct be_eq_entry *eqe; |
| 1454 | u16 num = 0; |
| 1455 | |
| 1456 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1457 | eqe->evt = 0; |
| 1458 | num++; |
| 1459 | } |
| 1460 | |
| 1461 | /* Deal with any spurious interrupts that come |
| 1462 | * without events |
| 1463 | */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1464 | if (!num) |
| 1465 | rearm = true; |
| 1466 | |
| 1467 | be_eq_notify(adapter, eq_obj->q.id, rearm, true, num); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1468 | if (num) |
| 1469 | napi_schedule(&eq_obj->napi); |
| 1470 | |
| 1471 | return num; |
| 1472 | } |
| 1473 | |
| 1474 | /* Just read and notify events without processing them. |
| 1475 | * Used at the time of destroying event queues */ |
| 1476 | static void be_eq_clean(struct be_adapter *adapter, |
| 1477 | struct be_eq_obj *eq_obj) |
| 1478 | { |
| 1479 | struct be_eq_entry *eqe; |
| 1480 | u16 num = 0; |
| 1481 | |
| 1482 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1483 | eqe->evt = 0; |
| 1484 | num++; |
| 1485 | } |
| 1486 | |
| 1487 | if (num) |
| 1488 | be_eq_notify(adapter, eq_obj->q.id, false, true, num); |
| 1489 | } |
| 1490 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1491 | static void be_rx_q_clean(struct be_adapter *adapter, struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1492 | { |
| 1493 | struct be_rx_page_info *page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1494 | struct be_queue_info *rxq = &rxo->q; |
| 1495 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1496 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1497 | u16 tail; |
| 1498 | |
| 1499 | /* First cleanup pending rx completions */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1500 | while ((rxcp = be_rx_compl_get(rxo)) != NULL) { |
| 1501 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 1502 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /* Then free posted rx buffer that were not used */ |
| 1506 | tail = (rxq->head + rxq->len - atomic_read(&rxq->used)) % rxq->len; |
Sathya Perla | cdab23b | 2009-08-10 03:43:23 +0000 | [diff] [blame] | 1507 | for (; atomic_read(&rxq->used) > 0; index_inc(&tail, rxq->len)) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1508 | page_info = get_rx_page_info(adapter, rxo, tail); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1509 | put_page(page_info->page); |
| 1510 | memset(page_info, 0, sizeof(*page_info)); |
| 1511 | } |
| 1512 | BUG_ON(atomic_read(&rxq->used)); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1513 | rxq->tail = rxq->head = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1516 | static void be_tx_compl_clean(struct be_adapter *adapter, |
| 1517 | struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1518 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1519 | struct be_queue_info *tx_cq = &txo->cq; |
| 1520 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1521 | struct be_eth_tx_compl *txcp; |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1522 | u16 end_idx, cmpl = 0, timeo = 0, num_wrbs = 0; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1523 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1524 | struct sk_buff *sent_skb; |
| 1525 | bool dummy_wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1526 | |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1527 | /* Wait for a max of 200ms for all the tx-completions to arrive. */ |
| 1528 | do { |
| 1529 | while ((txcp = be_tx_compl_get(tx_cq))) { |
| 1530 | end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1531 | wrb_index, txcp); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1532 | num_wrbs += be_tx_compl_process(adapter, txo, end_idx); |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1533 | cmpl++; |
| 1534 | } |
| 1535 | if (cmpl) { |
| 1536 | be_cq_notify(adapter, tx_cq->id, false, cmpl); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1537 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1538 | cmpl = 0; |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1539 | num_wrbs = 0; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | if (atomic_read(&txq->used) == 0 || ++timeo > 200) |
| 1543 | break; |
| 1544 | |
| 1545 | mdelay(1); |
| 1546 | } while (true); |
| 1547 | |
| 1548 | if (atomic_read(&txq->used)) |
| 1549 | dev_err(&adapter->pdev->dev, "%d pending tx-completions\n", |
| 1550 | atomic_read(&txq->used)); |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1551 | |
| 1552 | /* free posted tx for which compls will never arrive */ |
| 1553 | while (atomic_read(&txq->used)) { |
| 1554 | sent_skb = sent_skbs[txq->tail]; |
| 1555 | end_idx = txq->tail; |
| 1556 | index_adv(&end_idx, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1557 | wrb_cnt_for_skb(adapter, sent_skb, &dummy_wrb) - 1, |
| 1558 | txq->len); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1559 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1560 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1561 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1564 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 1565 | { |
| 1566 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1567 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1568 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1569 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1570 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1571 | be_queue_free(adapter, q); |
| 1572 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1573 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1574 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1575 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1576 | be_queue_free(adapter, q); |
| 1577 | } |
| 1578 | |
| 1579 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 1580 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 1581 | { |
| 1582 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1583 | |
| 1584 | /* Alloc MCC compl queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1585 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1586 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 1587 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1588 | goto err; |
| 1589 | |
| 1590 | /* Ask BE to create MCC compl queue; share TX's eq */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1591 | if (be_cmd_cq_create(adapter, cq, &adapter->tx_eq.q, false, true, 0)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1592 | goto mcc_cq_free; |
| 1593 | |
| 1594 | /* Alloc MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1595 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1596 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 1597 | goto mcc_cq_destroy; |
| 1598 | |
| 1599 | /* Ask BE to create MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1600 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1601 | goto mcc_q_free; |
| 1602 | |
| 1603 | return 0; |
| 1604 | |
| 1605 | mcc_q_free: |
| 1606 | be_queue_free(adapter, q); |
| 1607 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1608 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1609 | mcc_cq_free: |
| 1610 | be_queue_free(adapter, cq); |
| 1611 | err: |
| 1612 | return -1; |
| 1613 | } |
| 1614 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1615 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 1616 | { |
| 1617 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1618 | struct be_tx_obj *txo; |
| 1619 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1620 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1621 | for_all_tx_queues(adapter, txo, i) { |
| 1622 | q = &txo->q; |
| 1623 | if (q->created) |
| 1624 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 1625 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1626 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1627 | q = &txo->cq; |
| 1628 | if (q->created) |
| 1629 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 1630 | be_queue_free(adapter, q); |
| 1631 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1632 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1633 | /* Clear any residual events */ |
| 1634 | be_eq_clean(adapter, &adapter->tx_eq); |
| 1635 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1636 | q = &adapter->tx_eq.q; |
| 1637 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1638 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1639 | be_queue_free(adapter, q); |
| 1640 | } |
| 1641 | |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 1642 | static int be_num_txqs_want(struct be_adapter *adapter) |
| 1643 | { |
| 1644 | if ((num_vfs && adapter->sriov_enabled) || |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 1645 | be_is_mc(adapter) || |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 1646 | lancer_chip(adapter) || !be_physfn(adapter) || |
| 1647 | adapter->generation == BE_GEN2) |
| 1648 | return 1; |
| 1649 | else |
| 1650 | return MAX_TX_QS; |
| 1651 | } |
| 1652 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1653 | /* One TX event queue is shared by all TX compl qs */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1654 | static int be_tx_queues_create(struct be_adapter *adapter) |
| 1655 | { |
| 1656 | struct be_queue_info *eq, *q, *cq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1657 | struct be_tx_obj *txo; |
| 1658 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1659 | |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 1660 | adapter->num_tx_qs = be_num_txqs_want(adapter); |
| 1661 | if (adapter->num_tx_qs != MAX_TX_QS) |
| 1662 | netif_set_real_num_tx_queues(adapter->netdev, |
| 1663 | adapter->num_tx_qs); |
| 1664 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1665 | adapter->tx_eq.max_eqd = 0; |
| 1666 | adapter->tx_eq.min_eqd = 0; |
| 1667 | adapter->tx_eq.cur_eqd = 96; |
| 1668 | adapter->tx_eq.enable_aic = false; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1669 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1670 | eq = &adapter->tx_eq.q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1671 | if (be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 1672 | sizeof(struct be_eq_entry))) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1673 | return -1; |
| 1674 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1675 | if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1676 | goto err; |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1677 | adapter->tx_eq.eq_idx = adapter->eq_next_idx++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1678 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1679 | for_all_tx_queues(adapter, txo, i) { |
| 1680 | cq = &txo->cq; |
| 1681 | if (be_queue_alloc(adapter, cq, TX_CQ_LEN, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1682 | sizeof(struct be_eth_tx_compl))) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1683 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1684 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1685 | if (be_cmd_cq_create(adapter, cq, eq, false, false, 3)) |
| 1686 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1687 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1688 | q = &txo->q; |
| 1689 | if (be_queue_alloc(adapter, q, TX_Q_LEN, |
| 1690 | sizeof(struct be_eth_wrb))) |
| 1691 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1692 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1693 | if (be_cmd_txq_create(adapter, q, cq)) |
| 1694 | goto err; |
| 1695 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1696 | return 0; |
| 1697 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1698 | err: |
| 1699 | be_tx_queues_destroy(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1700 | return -1; |
| 1701 | } |
| 1702 | |
| 1703 | static void be_rx_queues_destroy(struct be_adapter *adapter) |
| 1704 | { |
| 1705 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1706 | struct be_rx_obj *rxo; |
| 1707 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1708 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1709 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1710 | be_queue_free(adapter, &rxo->q); |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1711 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1712 | q = &rxo->cq; |
| 1713 | if (q->created) |
| 1714 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 1715 | be_queue_free(adapter, q); |
| 1716 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1717 | q = &rxo->rx_eq.q; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1718 | if (q->created) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1719 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1720 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1721 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1724 | static u32 be_num_rxqs_want(struct be_adapter *adapter) |
| 1725 | { |
Sathya Perla | c814fd3 | 2011-06-26 20:41:25 +0000 | [diff] [blame] | 1726 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 1727 | !adapter->sriov_enabled && be_physfn(adapter) && |
| 1728 | !be_is_mc(adapter)) { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1729 | return 1 + MAX_RSS_QS; /* one default non-RSS queue */ |
| 1730 | } else { |
| 1731 | dev_warn(&adapter->pdev->dev, |
| 1732 | "No support for multiple RX queues\n"); |
| 1733 | return 1; |
| 1734 | } |
| 1735 | } |
| 1736 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1737 | static int be_rx_queues_create(struct be_adapter *adapter) |
| 1738 | { |
| 1739 | struct be_queue_info *eq, *q, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1740 | struct be_rx_obj *rxo; |
| 1741 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1742 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1743 | adapter->num_rx_qs = min(be_num_rxqs_want(adapter), |
| 1744 | msix_enabled(adapter) ? |
| 1745 | adapter->num_msix_vec - 1 : 1); |
| 1746 | if (adapter->num_rx_qs != MAX_RX_QS) |
| 1747 | dev_warn(&adapter->pdev->dev, |
| 1748 | "Can create only %d RX queues", adapter->num_rx_qs); |
| 1749 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1750 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1751 | for_all_rx_queues(adapter, rxo, i) { |
| 1752 | rxo->adapter = adapter; |
| 1753 | rxo->rx_eq.max_eqd = BE_MAX_EQD; |
| 1754 | rxo->rx_eq.enable_aic = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1755 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1756 | /* EQ */ |
| 1757 | eq = &rxo->rx_eq.q; |
| 1758 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 1759 | sizeof(struct be_eq_entry)); |
| 1760 | if (rc) |
| 1761 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1762 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1763 | rc = be_cmd_eq_create(adapter, eq, rxo->rx_eq.cur_eqd); |
| 1764 | if (rc) |
| 1765 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1766 | |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1767 | rxo->rx_eq.eq_idx = adapter->eq_next_idx++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1768 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1769 | /* CQ */ |
| 1770 | cq = &rxo->cq; |
| 1771 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
| 1772 | sizeof(struct be_eth_rx_compl)); |
| 1773 | if (rc) |
| 1774 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1775 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1776 | rc = be_cmd_cq_create(adapter, cq, eq, false, false, 3); |
| 1777 | if (rc) |
| 1778 | goto err; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1779 | |
| 1780 | /* Rx Q - will be created in be_open() */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1781 | q = &rxo->q; |
| 1782 | rc = be_queue_alloc(adapter, q, RX_Q_LEN, |
| 1783 | sizeof(struct be_eth_rx_d)); |
| 1784 | if (rc) |
| 1785 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1786 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1787 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1788 | |
| 1789 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1790 | err: |
| 1791 | be_rx_queues_destroy(adapter); |
| 1792 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1793 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1794 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1795 | static bool event_peek(struct be_eq_obj *eq_obj) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1796 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1797 | struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q); |
| 1798 | if (!eqe->evt) |
| 1799 | return false; |
| 1800 | else |
| 1801 | return true; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1804 | static irqreturn_t be_intx(int irq, void *dev) |
| 1805 | { |
| 1806 | struct be_adapter *adapter = dev; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1807 | struct be_rx_obj *rxo; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1808 | int isr, i, tx = 0 , rx = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1809 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1810 | if (lancer_chip(adapter)) { |
| 1811 | if (event_peek(&adapter->tx_eq)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1812 | tx = event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1813 | for_all_rx_queues(adapter, rxo, i) { |
| 1814 | if (event_peek(&rxo->rx_eq)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1815 | rx |= event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1816 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1817 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1818 | if (!(tx || rx)) |
| 1819 | return IRQ_NONE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1820 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1821 | } else { |
| 1822 | isr = ioread32(adapter->csr + CEV_ISR0_OFFSET + |
| 1823 | (adapter->tx_eq.q.id / 8) * CEV_ISR_SIZE); |
| 1824 | if (!isr) |
| 1825 | return IRQ_NONE; |
| 1826 | |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1827 | if ((1 << adapter->tx_eq.eq_idx & isr)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1828 | event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1829 | |
| 1830 | for_all_rx_queues(adapter, rxo, i) { |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1831 | if ((1 << rxo->rx_eq.eq_idx & isr)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1832 | event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1833 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1834 | } |
Sathya Perla | c001c21 | 2009-07-01 01:06:07 +0000 | [diff] [blame] | 1835 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1836 | return IRQ_HANDLED; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | static irqreturn_t be_msix_rx(int irq, void *dev) |
| 1840 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1841 | struct be_rx_obj *rxo = dev; |
| 1842 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1843 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1844 | event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1845 | |
| 1846 | return IRQ_HANDLED; |
| 1847 | } |
| 1848 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1849 | static irqreturn_t be_msix_tx_mcc(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1850 | { |
| 1851 | struct be_adapter *adapter = dev; |
| 1852 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1853 | event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1854 | |
| 1855 | return IRQ_HANDLED; |
| 1856 | } |
| 1857 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1858 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1859 | { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1860 | return (rxcp->tcpf && !rxcp->err) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
stephen hemminger | 49b0522 | 2010-10-21 07:50:48 +0000 | [diff] [blame] | 1863 | static int be_poll_rx(struct napi_struct *napi, int budget) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1864 | { |
| 1865 | struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1866 | struct be_rx_obj *rxo = container_of(rx_eq, struct be_rx_obj, rx_eq); |
| 1867 | struct be_adapter *adapter = rxo->adapter; |
| 1868 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1869 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1870 | u32 work_done; |
| 1871 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1872 | rx_stats(rxo)->rx_polls++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1873 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1874 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1875 | if (!rxcp) |
| 1876 | break; |
| 1877 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1878 | /* Is it a flush compl that has no data */ |
| 1879 | if (unlikely(rxcp->num_rcvd == 0)) |
| 1880 | goto loop_continue; |
| 1881 | |
| 1882 | /* Discard compl with partial DMA Lancer B0 */ |
| 1883 | if (unlikely(!rxcp->pkt_size)) { |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 1884 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1885 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 1886 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 1887 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1888 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 1889 | * promiscuous mode on some skews |
| 1890 | */ |
| 1891 | if (unlikely(rxcp->port != adapter->port_num && |
| 1892 | !lancer_chip(adapter))) { |
| 1893 | be_rx_compl_discard(adapter, rxo, rxcp); |
| 1894 | goto loop_continue; |
| 1895 | } |
| 1896 | |
| 1897 | if (do_gro(rxcp)) |
| 1898 | be_rx_compl_process_gro(adapter, rxo, rxcp); |
| 1899 | else |
| 1900 | be_rx_compl_process(adapter, rxo, rxcp); |
| 1901 | loop_continue: |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1902 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 1905 | be_cq_notify(adapter, rx_cq->id, false, work_done); |
| 1906 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1907 | /* Refill the queue */ |
Sathya Perla | 857c990 | 2011-08-22 19:41:51 +0000 | [diff] [blame] | 1908 | if (work_done && atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1909 | be_post_rx_frags(rxo, GFP_ATOMIC); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1910 | |
| 1911 | /* All consumed */ |
| 1912 | if (work_done < budget) { |
| 1913 | napi_complete(napi); |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 1914 | /* Arm CQ */ |
| 1915 | be_cq_notify(adapter, rx_cq->id, true, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1916 | } |
| 1917 | return work_done; |
| 1918 | } |
| 1919 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1920 | /* As TX and MCC share the same EQ check for both TX and MCC completions. |
| 1921 | * For TX/MCC we don't honour budget; consume everything |
| 1922 | */ |
| 1923 | static int be_poll_tx_mcc(struct napi_struct *napi, int budget) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1924 | { |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1925 | struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi); |
| 1926 | struct be_adapter *adapter = |
| 1927 | container_of(tx_eq, struct be_adapter, tx_eq); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1928 | struct be_tx_obj *txo; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1929 | struct be_eth_tx_compl *txcp; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1930 | int tx_compl, mcc_compl, status = 0; |
| 1931 | u8 i; |
| 1932 | u16 num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1933 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1934 | for_all_tx_queues(adapter, txo, i) { |
| 1935 | tx_compl = 0; |
| 1936 | num_wrbs = 0; |
| 1937 | while ((txcp = be_tx_compl_get(&txo->cq))) { |
| 1938 | num_wrbs += be_tx_compl_process(adapter, txo, |
| 1939 | AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1940 | wrb_index, txcp)); |
| 1941 | tx_compl++; |
| 1942 | } |
| 1943 | if (tx_compl) { |
| 1944 | be_cq_notify(adapter, txo->cq.id, true, tx_compl); |
| 1945 | |
| 1946 | atomic_sub(num_wrbs, &txo->q.used); |
| 1947 | |
| 1948 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 1949 | * if it was stopped due to lack of tx wrbs. */ |
| 1950 | if (__netif_subqueue_stopped(adapter->netdev, i) && |
| 1951 | atomic_read(&txo->q.used) < txo->q.len / 2) { |
| 1952 | netif_wake_subqueue(adapter->netdev, i); |
| 1953 | } |
| 1954 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1955 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1956 | tx_stats(txo)->tx_compl += tx_compl; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1957 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1958 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1961 | mcc_compl = be_process_mcc(adapter, &status); |
| 1962 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1963 | if (mcc_compl) { |
| 1964 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
| 1965 | be_cq_notify(adapter, mcc_obj->cq.id, true, mcc_compl); |
| 1966 | } |
| 1967 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1968 | napi_complete(napi); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1969 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1970 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1971 | adapter->drv_stats.tx_events++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1972 | return 1; |
| 1973 | } |
| 1974 | |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 1975 | void be_detect_dump_ue(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 1976 | { |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 1977 | u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0; |
| 1978 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 1979 | u32 i; |
| 1980 | |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 1981 | if (adapter->eeh_err || adapter->ue_detected) |
| 1982 | return; |
| 1983 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 1984 | if (lancer_chip(adapter)) { |
| 1985 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 1986 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
| 1987 | sliport_err1 = ioread32(adapter->db + |
| 1988 | SLIPORT_ERROR1_OFFSET); |
| 1989 | sliport_err2 = ioread32(adapter->db + |
| 1990 | SLIPORT_ERROR2_OFFSET); |
| 1991 | } |
| 1992 | } else { |
| 1993 | pci_read_config_dword(adapter->pdev, |
| 1994 | PCICFG_UE_STATUS_LOW, &ue_lo); |
| 1995 | pci_read_config_dword(adapter->pdev, |
| 1996 | PCICFG_UE_STATUS_HIGH, &ue_hi); |
| 1997 | pci_read_config_dword(adapter->pdev, |
| 1998 | PCICFG_UE_STATUS_LOW_MASK, &ue_lo_mask); |
| 1999 | pci_read_config_dword(adapter->pdev, |
| 2000 | PCICFG_UE_STATUS_HI_MASK, &ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2001 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2002 | ue_lo = (ue_lo & (~ue_lo_mask)); |
| 2003 | ue_hi = (ue_hi & (~ue_hi_mask)); |
| 2004 | } |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2005 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2006 | if (ue_lo || ue_hi || |
| 2007 | sliport_status & SLIPORT_STATUS_ERR_MASK) { |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 2008 | adapter->ue_detected = true; |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 2009 | adapter->eeh_err = true; |
Sathya Perla | 434b364 | 2011-11-10 19:17:59 +0000 | [diff] [blame^] | 2010 | dev_err(&adapter->pdev->dev, |
| 2011 | "Unrecoverable error in the card\n"); |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2014 | if (ue_lo) { |
| 2015 | for (i = 0; ue_lo; ue_lo >>= 1, i++) { |
| 2016 | if (ue_lo & 1) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2017 | dev_err(&adapter->pdev->dev, |
| 2018 | "UE: %s bit set\n", ue_status_low_desc[i]); |
| 2019 | } |
| 2020 | } |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2021 | if (ue_hi) { |
| 2022 | for (i = 0; ue_hi; ue_hi >>= 1, i++) { |
| 2023 | if (ue_hi & 1) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2024 | dev_err(&adapter->pdev->dev, |
| 2025 | "UE: %s bit set\n", ue_status_hi_desc[i]); |
| 2026 | } |
| 2027 | } |
| 2028 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2029 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
| 2030 | dev_err(&adapter->pdev->dev, |
| 2031 | "sliport status 0x%x\n", sliport_status); |
| 2032 | dev_err(&adapter->pdev->dev, |
| 2033 | "sliport error1 0x%x\n", sliport_err1); |
| 2034 | dev_err(&adapter->pdev->dev, |
| 2035 | "sliport error2 0x%x\n", sliport_err2); |
| 2036 | } |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2039 | static void be_worker(struct work_struct *work) |
| 2040 | { |
| 2041 | struct be_adapter *adapter = |
| 2042 | container_of(work, struct be_adapter, work.work); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2043 | struct be_rx_obj *rxo; |
| 2044 | int i; |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2045 | |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 2046 | be_detect_dump_ue(adapter); |
Sathya Perla | 16da825 | 2011-03-21 20:49:27 +0000 | [diff] [blame] | 2047 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 2048 | /* when interrupts are not yet enabled, just reap any pending |
| 2049 | * mcc completions */ |
| 2050 | if (!netif_running(adapter->netdev)) { |
| 2051 | int mcc_compl, status = 0; |
| 2052 | |
| 2053 | mcc_compl = be_process_mcc(adapter, &status); |
| 2054 | |
| 2055 | if (mcc_compl) { |
| 2056 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
| 2057 | be_cq_notify(adapter, mcc_obj->cq.id, false, mcc_compl); |
| 2058 | } |
Ajit Khaparde | 9b037f3 | 2011-02-11 13:38:29 +0000 | [diff] [blame] | 2059 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 2060 | goto reschedule; |
| 2061 | } |
| 2062 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 2063 | if (!adapter->stats_cmd_sent) { |
| 2064 | if (lancer_chip(adapter)) |
| 2065 | lancer_cmd_get_pport_stats(adapter, |
| 2066 | &adapter->stats_cmd); |
| 2067 | else |
| 2068 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 2069 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2070 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2071 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2072 | be_rx_eqd_update(adapter, rxo); |
| 2073 | |
| 2074 | if (rxo->rx_post_starved) { |
| 2075 | rxo->rx_post_starved = false; |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2076 | be_post_rx_frags(rxo, GFP_KERNEL); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2077 | } |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 2080 | reschedule: |
Ivan Vecera | e74fbd03 | 2011-04-21 00:20:04 +0000 | [diff] [blame] | 2081 | adapter->work_counter++; |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2082 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 2083 | } |
| 2084 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2085 | static void be_msix_disable(struct be_adapter *adapter) |
| 2086 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2087 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2088 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2089 | adapter->num_msix_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2090 | } |
| 2091 | } |
| 2092 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2093 | static void be_msix_enable(struct be_adapter *adapter) |
| 2094 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2095 | #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2096 | int i, status, num_vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2097 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2098 | num_vec = be_num_rxqs_want(adapter) + 1; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2099 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2100 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2101 | adapter->msix_entries[i].entry = i; |
| 2102 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2103 | status = pci_enable_msix(adapter->pdev, adapter->msix_entries, num_vec); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2104 | if (status == 0) { |
| 2105 | goto done; |
| 2106 | } else if (status >= BE_MIN_MSIX_VECTORS) { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2107 | num_vec = status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2108 | if (pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2109 | num_vec) == 0) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2110 | goto done; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2111 | } |
| 2112 | return; |
| 2113 | done: |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2114 | adapter->num_msix_vec = num_vec; |
| 2115 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2118 | static int be_sriov_enable(struct be_adapter *adapter) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2119 | { |
Sarveshwar Bandi | 344dbf1 | 2010-07-09 01:43:55 +0000 | [diff] [blame] | 2120 | be_check_sriov_fn_type(adapter); |
Ajit Khaparde | 6dedec8 | 2010-07-29 06:15:32 +0000 | [diff] [blame] | 2121 | #ifdef CONFIG_PCI_IOV |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2122 | if (be_physfn(adapter) && num_vfs) { |
Ajit Khaparde | 81be8f0 | 2011-04-06 18:08:17 +0000 | [diff] [blame] | 2123 | int status, pos; |
| 2124 | u16 nvfs; |
| 2125 | |
| 2126 | pos = pci_find_ext_capability(adapter->pdev, |
| 2127 | PCI_EXT_CAP_ID_SRIOV); |
| 2128 | pci_read_config_word(adapter->pdev, |
| 2129 | pos + PCI_SRIOV_TOTAL_VF, &nvfs); |
| 2130 | |
| 2131 | if (num_vfs > nvfs) { |
| 2132 | dev_info(&adapter->pdev->dev, |
| 2133 | "Device supports %d VFs and not %d\n", |
| 2134 | nvfs, num_vfs); |
| 2135 | num_vfs = nvfs; |
| 2136 | } |
Ajit Khaparde | 6dedec8 | 2010-07-29 06:15:32 +0000 | [diff] [blame] | 2137 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2138 | status = pci_enable_sriov(adapter->pdev, num_vfs); |
| 2139 | adapter->sriov_enabled = status ? false : true; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2140 | |
| 2141 | if (adapter->sriov_enabled) { |
| 2142 | adapter->vf_cfg = kcalloc(num_vfs, |
| 2143 | sizeof(struct be_vf_cfg), |
| 2144 | GFP_KERNEL); |
| 2145 | if (!adapter->vf_cfg) |
| 2146 | return -ENOMEM; |
| 2147 | } |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2148 | } |
| 2149 | #endif |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2150 | return 0; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | static void be_sriov_disable(struct be_adapter *adapter) |
| 2154 | { |
| 2155 | #ifdef CONFIG_PCI_IOV |
| 2156 | if (adapter->sriov_enabled) { |
| 2157 | pci_disable_sriov(adapter->pdev); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2158 | kfree(adapter->vf_cfg); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2159 | adapter->sriov_enabled = false; |
| 2160 | } |
| 2161 | #endif |
| 2162 | } |
| 2163 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2164 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
| 2165 | struct be_eq_obj *eq_obj) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2166 | { |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 2167 | return adapter->msix_entries[eq_obj->eq_idx].vector; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static int be_request_irq(struct be_adapter *adapter, |
| 2171 | struct be_eq_obj *eq_obj, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2172 | void *handler, char *desc, void *context) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2173 | { |
| 2174 | struct net_device *netdev = adapter->netdev; |
| 2175 | int vec; |
| 2176 | |
| 2177 | sprintf(eq_obj->desc, "%s-%s", netdev->name, desc); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2178 | vec = be_msix_vec_get(adapter, eq_obj); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2179 | return request_irq(vec, handler, 0, eq_obj->desc, context); |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2182 | static void be_free_irq(struct be_adapter *adapter, struct be_eq_obj *eq_obj, |
| 2183 | void *context) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2184 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2185 | int vec = be_msix_vec_get(adapter, eq_obj); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2186 | free_irq(vec, context); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | static int be_msix_register(struct be_adapter *adapter) |
| 2190 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2191 | struct be_rx_obj *rxo; |
| 2192 | int status, i; |
| 2193 | char qname[10]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2194 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2195 | status = be_request_irq(adapter, &adapter->tx_eq, be_msix_tx_mcc, "tx", |
| 2196 | adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2197 | if (status) |
| 2198 | goto err; |
| 2199 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2200 | for_all_rx_queues(adapter, rxo, i) { |
| 2201 | sprintf(qname, "rxq%d", i); |
| 2202 | status = be_request_irq(adapter, &rxo->rx_eq, be_msix_rx, |
| 2203 | qname, rxo); |
| 2204 | if (status) |
| 2205 | goto err_msix; |
| 2206 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2207 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2208 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2209 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2210 | err_msix: |
| 2211 | be_free_irq(adapter, &adapter->tx_eq, adapter); |
| 2212 | |
| 2213 | for (i--, rxo = &adapter->rx_obj[i]; i >= 0; i--, rxo--) |
| 2214 | be_free_irq(adapter, &rxo->rx_eq, rxo); |
| 2215 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2216 | err: |
| 2217 | dev_warn(&adapter->pdev->dev, |
| 2218 | "MSIX Request IRQ failed - err %d\n", status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2219 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2220 | return status; |
| 2221 | } |
| 2222 | |
| 2223 | static int be_irq_register(struct be_adapter *adapter) |
| 2224 | { |
| 2225 | struct net_device *netdev = adapter->netdev; |
| 2226 | int status; |
| 2227 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2228 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2229 | status = be_msix_register(adapter); |
| 2230 | if (status == 0) |
| 2231 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2232 | /* INTx is not supported for VF */ |
| 2233 | if (!be_physfn(adapter)) |
| 2234 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | /* INTx */ |
| 2238 | netdev->irq = adapter->pdev->irq; |
| 2239 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
| 2240 | adapter); |
| 2241 | if (status) { |
| 2242 | dev_err(&adapter->pdev->dev, |
| 2243 | "INTx request IRQ failed - err %d\n", status); |
| 2244 | return status; |
| 2245 | } |
| 2246 | done: |
| 2247 | adapter->isr_registered = true; |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
| 2251 | static void be_irq_unregister(struct be_adapter *adapter) |
| 2252 | { |
| 2253 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2254 | struct be_rx_obj *rxo; |
| 2255 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2256 | |
| 2257 | if (!adapter->isr_registered) |
| 2258 | return; |
| 2259 | |
| 2260 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2261 | if (!msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2262 | free_irq(netdev->irq, adapter); |
| 2263 | goto done; |
| 2264 | } |
| 2265 | |
| 2266 | /* MSIx */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2267 | be_free_irq(adapter, &adapter->tx_eq, adapter); |
| 2268 | |
| 2269 | for_all_rx_queues(adapter, rxo, i) |
| 2270 | be_free_irq(adapter, &rxo->rx_eq, rxo); |
| 2271 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2272 | done: |
| 2273 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2276 | static void be_rx_queues_clear(struct be_adapter *adapter) |
| 2277 | { |
| 2278 | struct be_queue_info *q; |
| 2279 | struct be_rx_obj *rxo; |
| 2280 | int i; |
| 2281 | |
| 2282 | for_all_rx_queues(adapter, rxo, i) { |
| 2283 | q = &rxo->q; |
| 2284 | if (q->created) { |
| 2285 | be_cmd_rxq_destroy(adapter, q); |
| 2286 | /* After the rxq is invalidated, wait for a grace time |
| 2287 | * of 1ms for all dma to end and the flush compl to |
| 2288 | * arrive |
| 2289 | */ |
| 2290 | mdelay(1); |
| 2291 | be_rx_q_clean(adapter, rxo); |
| 2292 | } |
| 2293 | |
| 2294 | /* Clear any residual events */ |
| 2295 | q = &rxo->rx_eq.q; |
| 2296 | if (q->created) |
| 2297 | be_eq_clean(adapter, &rxo->rx_eq); |
| 2298 | } |
| 2299 | } |
| 2300 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2301 | static int be_close(struct net_device *netdev) |
| 2302 | { |
| 2303 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2304 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2305 | struct be_tx_obj *txo; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2306 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2307 | int vec, i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2308 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2309 | be_async_mcc_disable(adapter); |
| 2310 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2311 | if (!lancer_chip(adapter)) |
| 2312 | be_intr_set(adapter, false); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2313 | |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2314 | for_all_rx_queues(adapter, rxo, i) |
| 2315 | napi_disable(&rxo->rx_eq.napi); |
| 2316 | |
| 2317 | napi_disable(&tx_eq->napi); |
| 2318 | |
| 2319 | if (lancer_chip(adapter)) { |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2320 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0); |
| 2321 | for_all_rx_queues(adapter, rxo, i) |
| 2322 | be_cq_notify(adapter, rxo->cq.id, false, 0); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2323 | for_all_tx_queues(adapter, txo, i) |
| 2324 | be_cq_notify(adapter, txo->cq.id, false, 0); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2327 | if (msix_enabled(adapter)) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2328 | vec = be_msix_vec_get(adapter, tx_eq); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2329 | synchronize_irq(vec); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2330 | |
| 2331 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2332 | vec = be_msix_vec_get(adapter, &rxo->rx_eq); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2333 | synchronize_irq(vec); |
| 2334 | } |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2335 | } else { |
| 2336 | synchronize_irq(netdev->irq); |
| 2337 | } |
| 2338 | be_irq_unregister(adapter); |
| 2339 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2340 | /* Wait for all pending tx completions to arrive so that |
| 2341 | * all tx skbs are freed. |
| 2342 | */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2343 | for_all_tx_queues(adapter, txo, i) |
| 2344 | be_tx_compl_clean(adapter, txo); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2345 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2346 | be_rx_queues_clear(adapter); |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | static int be_rx_queues_setup(struct be_adapter *adapter) |
| 2351 | { |
| 2352 | struct be_rx_obj *rxo; |
| 2353 | int rc, i; |
| 2354 | u8 rsstable[MAX_RSS_QS]; |
| 2355 | |
| 2356 | for_all_rx_queues(adapter, rxo, i) { |
| 2357 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
| 2358 | rx_frag_size, BE_MAX_JUMBO_FRAME_SIZE, |
| 2359 | adapter->if_handle, |
| 2360 | (i > 0) ? 1 : 0/* rss enable */, &rxo->rss_id); |
| 2361 | if (rc) |
| 2362 | return rc; |
| 2363 | } |
| 2364 | |
| 2365 | if (be_multi_rxq(adapter)) { |
| 2366 | for_all_rss_queues(adapter, rxo, i) |
| 2367 | rsstable[i] = rxo->rss_id; |
| 2368 | |
| 2369 | rc = be_cmd_rss_config(adapter, rsstable, |
| 2370 | adapter->num_rx_qs - 1); |
| 2371 | if (rc) |
| 2372 | return rc; |
| 2373 | } |
| 2374 | |
| 2375 | /* First time posting */ |
| 2376 | for_all_rx_queues(adapter, rxo, i) { |
| 2377 | be_post_rx_frags(rxo, GFP_KERNEL); |
| 2378 | napi_enable(&rxo->rx_eq.napi); |
| 2379 | } |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2380 | return 0; |
| 2381 | } |
| 2382 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2383 | static int be_open(struct net_device *netdev) |
| 2384 | { |
| 2385 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2386 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2387 | struct be_rx_obj *rxo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2388 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2389 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2390 | status = be_rx_queues_setup(adapter); |
| 2391 | if (status) |
| 2392 | goto err; |
| 2393 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2394 | napi_enable(&tx_eq->napi); |
| 2395 | |
| 2396 | be_irq_register(adapter); |
| 2397 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2398 | if (!lancer_chip(adapter)) |
| 2399 | be_intr_set(adapter, true); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2400 | |
| 2401 | /* The evt queues are created in unarmed state; arm them */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2402 | for_all_rx_queues(adapter, rxo, i) { |
| 2403 | be_eq_notify(adapter, rxo->rx_eq.q.id, true, false, 0); |
| 2404 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
| 2405 | } |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2406 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2407 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 2408 | /* Now that interrupts are on we can process async mcc */ |
| 2409 | be_async_mcc_enable(adapter); |
| 2410 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2411 | return 0; |
| 2412 | err: |
| 2413 | be_close(adapter->netdev); |
| 2414 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2417 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 2418 | { |
| 2419 | struct be_dma_mem cmd; |
| 2420 | int status = 0; |
| 2421 | u8 mac[ETH_ALEN]; |
| 2422 | |
| 2423 | memset(mac, 0, ETH_ALEN); |
| 2424 | |
| 2425 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2426 | cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 2427 | GFP_KERNEL); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2428 | if (cmd.va == NULL) |
| 2429 | return -1; |
| 2430 | memset(cmd.va, 0, cmd.size); |
| 2431 | |
| 2432 | if (enable) { |
| 2433 | status = pci_write_config_dword(adapter->pdev, |
| 2434 | PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK); |
| 2435 | if (status) { |
| 2436 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 2437 | "Could not enable Wake-on-lan\n"); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2438 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 2439 | cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2440 | return status; |
| 2441 | } |
| 2442 | status = be_cmd_enable_magic_wol(adapter, |
| 2443 | adapter->netdev->dev_addr, &cmd); |
| 2444 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 2445 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 2446 | } else { |
| 2447 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 2448 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 2449 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 2450 | } |
| 2451 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2452 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2453 | return status; |
| 2454 | } |
| 2455 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2456 | /* |
| 2457 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 2458 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 2459 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 2460 | * queries for the MAC address during its probe. |
| 2461 | */ |
| 2462 | static inline int be_vf_eth_addr_config(struct be_adapter *adapter) |
| 2463 | { |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2464 | u32 vf; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2465 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2466 | u8 mac[ETH_ALEN]; |
| 2467 | |
| 2468 | be_vf_eth_addr_generate(adapter, mac); |
| 2469 | |
| 2470 | for (vf = 0; vf < num_vfs; vf++) { |
| 2471 | status = be_cmd_pmac_add(adapter, mac, |
| 2472 | adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 2473 | &adapter->vf_cfg[vf].vf_pmac_id, |
| 2474 | vf + 1); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2475 | if (status) |
| 2476 | dev_err(&adapter->pdev->dev, |
| 2477 | "Mac address add failed for VF %d\n", vf); |
| 2478 | else |
| 2479 | memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN); |
| 2480 | |
| 2481 | mac[5] += 1; |
| 2482 | } |
| 2483 | return status; |
| 2484 | } |
| 2485 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2486 | static void be_vf_clear(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2487 | { |
| 2488 | u32 vf; |
| 2489 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2490 | for (vf = 0; vf < num_vfs; vf++) |
| 2491 | be_cmd_pmac_del(adapter, adapter->vf_cfg[vf].vf_if_handle, |
| 2492 | adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2493 | |
| 2494 | for (vf = 0; vf < num_vfs; vf++) |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2495 | be_cmd_if_destroy(adapter, adapter->vf_cfg[vf].vf_if_handle, |
| 2496 | vf + 1); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2499 | static int be_clear(struct be_adapter *adapter) |
| 2500 | { |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2501 | if (be_physfn(adapter) && adapter->sriov_enabled) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2502 | be_vf_clear(adapter); |
| 2503 | |
| 2504 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2505 | |
| 2506 | be_mcc_queues_destroy(adapter); |
| 2507 | be_rx_queues_destroy(adapter); |
| 2508 | be_tx_queues_destroy(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2509 | |
| 2510 | /* tell fw we're done with firing cmds */ |
| 2511 | be_cmd_fw_clean(adapter); |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2515 | static void be_vf_setup_init(struct be_adapter *adapter) |
| 2516 | { |
| 2517 | int vf; |
| 2518 | |
| 2519 | for (vf = 0; vf < num_vfs; vf++) { |
| 2520 | adapter->vf_cfg[vf].vf_if_handle = -1; |
| 2521 | adapter->vf_cfg[vf].vf_pmac_id = -1; |
| 2522 | } |
| 2523 | } |
| 2524 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2525 | static int be_vf_setup(struct be_adapter *adapter) |
| 2526 | { |
| 2527 | u32 cap_flags, en_flags, vf; |
| 2528 | u16 lnk_speed; |
| 2529 | int status; |
| 2530 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2531 | be_vf_setup_init(adapter); |
| 2532 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2533 | cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST; |
| 2534 | for (vf = 0; vf < num_vfs; vf++) { |
| 2535 | status = be_cmd_if_create(adapter, cap_flags, en_flags, NULL, |
| 2536 | &adapter->vf_cfg[vf].vf_if_handle, |
| 2537 | NULL, vf+1); |
| 2538 | if (status) |
| 2539 | goto err; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | if (!lancer_chip(adapter)) { |
| 2543 | status = be_vf_eth_addr_config(adapter); |
| 2544 | if (status) |
| 2545 | goto err; |
| 2546 | } |
| 2547 | |
| 2548 | for (vf = 0; vf < num_vfs; vf++) { |
| 2549 | status = be_cmd_link_status_query(adapter, NULL, &lnk_speed, |
| 2550 | vf + 1); |
| 2551 | if (status) |
| 2552 | goto err; |
| 2553 | adapter->vf_cfg[vf].vf_tx_rate = lnk_speed * 10; |
| 2554 | } |
| 2555 | return 0; |
| 2556 | err: |
| 2557 | return status; |
| 2558 | } |
| 2559 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2560 | static void be_setup_init(struct be_adapter *adapter) |
| 2561 | { |
| 2562 | adapter->vlan_prio_bmap = 0xff; |
| 2563 | adapter->link_speed = -1; |
| 2564 | adapter->if_handle = -1; |
| 2565 | adapter->be3_native = false; |
| 2566 | adapter->promiscuous = false; |
| 2567 | adapter->eq_next_idx = 0; |
| 2568 | } |
| 2569 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2570 | static int be_setup(struct be_adapter *adapter) |
| 2571 | { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2572 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2573 | u32 cap_flags, en_flags; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2574 | u32 tx_fc, rx_fc; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2575 | int status; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2576 | u8 mac[ETH_ALEN]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2577 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 2578 | be_setup_init(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2579 | |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 2580 | be_cmd_req_native_mode(adapter); |
| 2581 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2582 | status = be_tx_queues_create(adapter); |
| 2583 | if (status != 0) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2584 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2585 | |
| 2586 | status = be_rx_queues_create(adapter); |
| 2587 | if (status != 0) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2588 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2589 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2590 | status = be_mcc_queues_create(adapter); |
| 2591 | if (status != 0) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2592 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2593 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2594 | memset(mac, 0, ETH_ALEN); |
| 2595 | status = be_cmd_mac_addr_query(adapter, mac, MAC_ADDRESS_TYPE_NETWORK, |
| 2596 | true /*permanent */, 0); |
| 2597 | if (status) |
| 2598 | return status; |
| 2599 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 2600 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 2601 | |
| 2602 | en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 2603 | BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
| 2604 | cap_flags = en_flags | BE_IF_FLAGS_MCAST_PROMISCUOUS | |
| 2605 | BE_IF_FLAGS_PROMISCUOUS; |
| 2606 | if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) { |
| 2607 | cap_flags |= BE_IF_FLAGS_RSS; |
| 2608 | en_flags |= BE_IF_FLAGS_RSS; |
| 2609 | } |
| 2610 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 2611 | netdev->dev_addr, &adapter->if_handle, |
| 2612 | &adapter->pmac_id, 0); |
| 2613 | if (status != 0) |
| 2614 | goto err; |
| 2615 | |
| 2616 | /* For BEx, the VF's permanent mac queried from card is incorrect. |
| 2617 | * Query the mac configued by the PF using if_handle |
| 2618 | */ |
| 2619 | if (!be_physfn(adapter) && !lancer_chip(adapter)) { |
| 2620 | status = be_cmd_mac_addr_query(adapter, mac, |
| 2621 | MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle); |
| 2622 | if (!status) { |
| 2623 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 2624 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 2625 | } |
| 2626 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 2627 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 2628 | be_cmd_get_fw_ver(adapter, adapter->fw_ver, NULL); |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 2629 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2630 | status = be_vid_config(adapter, false, 0); |
| 2631 | if (status) |
| 2632 | goto err; |
| 2633 | |
| 2634 | be_set_rx_mode(adapter->netdev); |
| 2635 | |
| 2636 | status = be_cmd_get_flow_control(adapter, &tx_fc, &rx_fc); |
| 2637 | if (status) |
| 2638 | goto err; |
| 2639 | if (rx_fc != adapter->rx_fc || tx_fc != adapter->tx_fc) { |
| 2640 | status = be_cmd_set_flow_control(adapter, adapter->tx_fc, |
| 2641 | adapter->rx_fc); |
| 2642 | if (status) |
| 2643 | goto err; |
| 2644 | } |
| 2645 | |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 2646 | pcie_set_readrq(adapter->pdev, 4096); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2647 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2648 | if (be_physfn(adapter) && adapter->sriov_enabled) { |
| 2649 | status = be_vf_setup(adapter); |
| 2650 | if (status) |
| 2651 | goto err; |
| 2652 | } |
| 2653 | |
| 2654 | return 0; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2655 | err: |
| 2656 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2657 | return status; |
| 2658 | } |
| 2659 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2660 | #define FW_FILE_HDR_SIGN "ServerEngines Corp. " |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2661 | static bool be_flash_redboot(struct be_adapter *adapter, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2662 | const u8 *p, u32 img_start, int image_size, |
| 2663 | int hdr_size) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2664 | { |
| 2665 | u32 crc_offset; |
| 2666 | u8 flashed_crc[4]; |
| 2667 | int status; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2668 | |
| 2669 | crc_offset = hdr_size + img_start + image_size - 4; |
| 2670 | |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2671 | p += crc_offset; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2672 | |
| 2673 | status = be_cmd_get_flash_crc(adapter, flashed_crc, |
Ajit Khaparde | f510fc6 | 2010-03-31 01:47:45 +0000 | [diff] [blame] | 2674 | (image_size - 4)); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2675 | if (status) { |
| 2676 | dev_err(&adapter->pdev->dev, |
| 2677 | "could not get crc from flash, not flashing redboot\n"); |
| 2678 | return false; |
| 2679 | } |
| 2680 | |
| 2681 | /*update redboot only if crc does not match*/ |
| 2682 | if (!memcmp(flashed_crc, p, 4)) |
| 2683 | return false; |
| 2684 | else |
| 2685 | return true; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2686 | } |
| 2687 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2688 | static bool phy_flashing_required(struct be_adapter *adapter) |
| 2689 | { |
| 2690 | int status = 0; |
| 2691 | struct be_phy_info phy_info; |
| 2692 | |
| 2693 | status = be_cmd_get_phy_info(adapter, &phy_info); |
| 2694 | if (status) |
| 2695 | return false; |
| 2696 | if ((phy_info.phy_type == TN_8022) && |
| 2697 | (phy_info.interface_type == PHY_TYPE_BASET_10GB)) { |
| 2698 | return true; |
| 2699 | } |
| 2700 | return false; |
| 2701 | } |
| 2702 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2703 | static int be_flash_data(struct be_adapter *adapter, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2704 | const struct firmware *fw, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2705 | struct be_dma_mem *flash_cmd, int num_of_images) |
| 2706 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2707 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2708 | int status = 0, i, filehdr_size = 0; |
| 2709 | u32 total_bytes = 0, flash_op; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2710 | int num_bytes; |
| 2711 | const u8 *p = fw->data; |
| 2712 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2713 | const struct flash_comp *pflashcomp; |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2714 | int num_comp; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2715 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2716 | static const struct flash_comp gen3_flash_types[10] = { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2717 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, IMG_TYPE_ISCSI_ACTIVE, |
| 2718 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2719 | { FLASH_REDBOOT_START_g3, IMG_TYPE_REDBOOT, |
| 2720 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3}, |
| 2721 | { FLASH_iSCSI_BIOS_START_g3, IMG_TYPE_BIOS, |
| 2722 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2723 | { FLASH_PXE_BIOS_START_g3, IMG_TYPE_PXE_BIOS, |
| 2724 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2725 | { FLASH_FCoE_BIOS_START_g3, IMG_TYPE_FCOE_BIOS, |
| 2726 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2727 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, IMG_TYPE_ISCSI_BACKUP, |
| 2728 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2729 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2730 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2731 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, IMG_TYPE_FCOE_FW_BACKUP, |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2732 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2733 | { FLASH_NCSI_START_g3, IMG_TYPE_NCSI_FW, |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2734 | FLASH_NCSI_IMAGE_MAX_SIZE_g3}, |
| 2735 | { FLASH_PHY_FW_START_g3, IMG_TYPE_PHY_FW, |
| 2736 | FLASH_PHY_FW_IMAGE_MAX_SIZE_g3} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2737 | }; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2738 | static const struct flash_comp gen2_flash_types[8] = { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2739 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, IMG_TYPE_ISCSI_ACTIVE, |
| 2740 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2741 | { FLASH_REDBOOT_START_g2, IMG_TYPE_REDBOOT, |
| 2742 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2}, |
| 2743 | { FLASH_iSCSI_BIOS_START_g2, IMG_TYPE_BIOS, |
| 2744 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2745 | { FLASH_PXE_BIOS_START_g2, IMG_TYPE_PXE_BIOS, |
| 2746 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2747 | { FLASH_FCoE_BIOS_START_g2, IMG_TYPE_FCOE_BIOS, |
| 2748 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2749 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, IMG_TYPE_ISCSI_BACKUP, |
| 2750 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2751 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2752 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2753 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, IMG_TYPE_FCOE_FW_BACKUP, |
| 2754 | FLASH_IMAGE_MAX_SIZE_g2} |
| 2755 | }; |
| 2756 | |
| 2757 | if (adapter->generation == BE_GEN3) { |
| 2758 | pflashcomp = gen3_flash_types; |
| 2759 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2760 | num_comp = ARRAY_SIZE(gen3_flash_types); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2761 | } else { |
| 2762 | pflashcomp = gen2_flash_types; |
| 2763 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2764 | num_comp = ARRAY_SIZE(gen2_flash_types); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2765 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2766 | for (i = 0; i < num_comp; i++) { |
| 2767 | if ((pflashcomp[i].optype == IMG_TYPE_NCSI_FW) && |
| 2768 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 2769 | continue; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2770 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) { |
| 2771 | if (!phy_flashing_required(adapter)) |
| 2772 | continue; |
| 2773 | } |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2774 | if ((pflashcomp[i].optype == IMG_TYPE_REDBOOT) && |
| 2775 | (!be_flash_redboot(adapter, fw->data, |
Ajit Khaparde | fae21a4 | 2011-02-11 13:37:42 +0000 | [diff] [blame] | 2776 | pflashcomp[i].offset, pflashcomp[i].size, filehdr_size + |
| 2777 | (num_of_images * sizeof(struct image_hdr))))) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2778 | continue; |
| 2779 | p = fw->data; |
| 2780 | p += filehdr_size + pflashcomp[i].offset |
| 2781 | + (num_of_images * sizeof(struct image_hdr)); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2782 | if (p + pflashcomp[i].size > fw->data + fw->size) |
| 2783 | return -1; |
| 2784 | total_bytes = pflashcomp[i].size; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2785 | while (total_bytes) { |
| 2786 | if (total_bytes > 32*1024) |
| 2787 | num_bytes = 32*1024; |
| 2788 | else |
| 2789 | num_bytes = total_bytes; |
| 2790 | total_bytes -= num_bytes; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2791 | if (!total_bytes) { |
| 2792 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) |
| 2793 | flash_op = FLASHROM_OPER_PHY_FLASH; |
| 2794 | else |
| 2795 | flash_op = FLASHROM_OPER_FLASH; |
| 2796 | } else { |
| 2797 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) |
| 2798 | flash_op = FLASHROM_OPER_PHY_SAVE; |
| 2799 | else |
| 2800 | flash_op = FLASHROM_OPER_SAVE; |
| 2801 | } |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2802 | memcpy(req->params.data_buf, p, num_bytes); |
| 2803 | p += num_bytes; |
| 2804 | status = be_cmd_write_flashrom(adapter, flash_cmd, |
| 2805 | pflashcomp[i].optype, flash_op, num_bytes); |
| 2806 | if (status) { |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2807 | if ((status == ILLEGAL_IOCTL_REQ) && |
| 2808 | (pflashcomp[i].optype == |
| 2809 | IMG_TYPE_PHY_FW)) |
| 2810 | break; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2811 | dev_err(&adapter->pdev->dev, |
| 2812 | "cmd to write to flash rom failed.\n"); |
| 2813 | return -1; |
| 2814 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2815 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2816 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2817 | return 0; |
| 2818 | } |
| 2819 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2820 | static int get_ufigen_type(struct flash_file_hdr_g2 *fhdr) |
| 2821 | { |
| 2822 | if (fhdr == NULL) |
| 2823 | return 0; |
| 2824 | if (fhdr->build[0] == '3') |
| 2825 | return BE_GEN3; |
| 2826 | else if (fhdr->build[0] == '2') |
| 2827 | return BE_GEN2; |
| 2828 | else |
| 2829 | return 0; |
| 2830 | } |
| 2831 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2832 | static int lancer_fw_download(struct be_adapter *adapter, |
| 2833 | const struct firmware *fw) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2834 | { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2835 | #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024) |
| 2836 | #define LANCER_FW_DOWNLOAD_LOCATION "/prg" |
| 2837 | struct be_dma_mem flash_cmd; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2838 | const u8 *data_ptr = NULL; |
| 2839 | u8 *dest_image_ptr = NULL; |
| 2840 | size_t image_size = 0; |
| 2841 | u32 chunk_size = 0; |
| 2842 | u32 data_written = 0; |
| 2843 | u32 offset = 0; |
| 2844 | int status = 0; |
| 2845 | u8 add_status = 0; |
| 2846 | |
| 2847 | if (!IS_ALIGNED(fw->size, sizeof(u32))) { |
| 2848 | dev_err(&adapter->pdev->dev, |
| 2849 | "FW Image not properly aligned. " |
| 2850 | "Length must be 4 byte aligned.\n"); |
| 2851 | status = -EINVAL; |
| 2852 | goto lancer_fw_exit; |
| 2853 | } |
| 2854 | |
| 2855 | flash_cmd.size = sizeof(struct lancer_cmd_req_write_object) |
| 2856 | + LANCER_FW_DOWNLOAD_CHUNK; |
| 2857 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
| 2858 | &flash_cmd.dma, GFP_KERNEL); |
| 2859 | if (!flash_cmd.va) { |
| 2860 | status = -ENOMEM; |
| 2861 | dev_err(&adapter->pdev->dev, |
| 2862 | "Memory allocation failure while flashing\n"); |
| 2863 | goto lancer_fw_exit; |
| 2864 | } |
| 2865 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2866 | dest_image_ptr = flash_cmd.va + |
| 2867 | sizeof(struct lancer_cmd_req_write_object); |
| 2868 | image_size = fw->size; |
| 2869 | data_ptr = fw->data; |
| 2870 | |
| 2871 | while (image_size) { |
| 2872 | chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK); |
| 2873 | |
| 2874 | /* Copy the image chunk content. */ |
| 2875 | memcpy(dest_image_ptr, data_ptr, chunk_size); |
| 2876 | |
| 2877 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
| 2878 | chunk_size, offset, LANCER_FW_DOWNLOAD_LOCATION, |
| 2879 | &data_written, &add_status); |
| 2880 | |
| 2881 | if (status) |
| 2882 | break; |
| 2883 | |
| 2884 | offset += data_written; |
| 2885 | data_ptr += data_written; |
| 2886 | image_size -= data_written; |
| 2887 | } |
| 2888 | |
| 2889 | if (!status) { |
| 2890 | /* Commit the FW written */ |
| 2891 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
| 2892 | 0, offset, LANCER_FW_DOWNLOAD_LOCATION, |
| 2893 | &data_written, &add_status); |
| 2894 | } |
| 2895 | |
| 2896 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 2897 | flash_cmd.dma); |
| 2898 | if (status) { |
| 2899 | dev_err(&adapter->pdev->dev, |
| 2900 | "Firmware load error. " |
| 2901 | "Status code: 0x%x Additional Status: 0x%x\n", |
| 2902 | status, add_status); |
| 2903 | goto lancer_fw_exit; |
| 2904 | } |
| 2905 | |
| 2906 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
| 2907 | lancer_fw_exit: |
| 2908 | return status; |
| 2909 | } |
| 2910 | |
| 2911 | static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) |
| 2912 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2913 | struct flash_file_hdr_g2 *fhdr; |
| 2914 | struct flash_file_hdr_g3 *fhdr3; |
| 2915 | struct image_hdr *img_hdr_ptr = NULL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2916 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2917 | const u8 *p; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2918 | int status = 0, i = 0, num_imgs = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2919 | |
| 2920 | p = fw->data; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2921 | fhdr = (struct flash_file_hdr_g2 *) p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2922 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2923 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2924 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
| 2925 | &flash_cmd.dma, GFP_KERNEL); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2926 | if (!flash_cmd.va) { |
| 2927 | status = -ENOMEM; |
| 2928 | dev_err(&adapter->pdev->dev, |
| 2929 | "Memory allocation failure while flashing\n"); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2930 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2933 | if ((adapter->generation == BE_GEN3) && |
| 2934 | (get_ufigen_type(fhdr) == BE_GEN3)) { |
| 2935 | fhdr3 = (struct flash_file_hdr_g3 *) fw->data; |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2936 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 2937 | for (i = 0; i < num_imgs; i++) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2938 | img_hdr_ptr = (struct image_hdr *) (fw->data + |
| 2939 | (sizeof(struct flash_file_hdr_g3) + |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2940 | i * sizeof(struct image_hdr))); |
| 2941 | if (le32_to_cpu(img_hdr_ptr->imageid) == 1) |
| 2942 | status = be_flash_data(adapter, fw, &flash_cmd, |
| 2943 | num_imgs); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2944 | } |
| 2945 | } else if ((adapter->generation == BE_GEN2) && |
| 2946 | (get_ufigen_type(fhdr) == BE_GEN2)) { |
| 2947 | status = be_flash_data(adapter, fw, &flash_cmd, 0); |
| 2948 | } else { |
| 2949 | dev_err(&adapter->pdev->dev, |
| 2950 | "UFI and Interface are not compatible for flashing\n"); |
| 2951 | status = -1; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2954 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 2955 | flash_cmd.dma); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2956 | if (status) { |
| 2957 | dev_err(&adapter->pdev->dev, "Firmware load error\n"); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2958 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2961 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2962 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2963 | be_fw_exit: |
| 2964 | return status; |
| 2965 | } |
| 2966 | |
| 2967 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 2968 | { |
| 2969 | const struct firmware *fw; |
| 2970 | int status; |
| 2971 | |
| 2972 | if (!netif_running(adapter->netdev)) { |
| 2973 | dev_err(&adapter->pdev->dev, |
| 2974 | "Firmware load not allowed (interface is down)\n"); |
| 2975 | return -1; |
| 2976 | } |
| 2977 | |
| 2978 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 2979 | if (status) |
| 2980 | goto fw_exit; |
| 2981 | |
| 2982 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 2983 | |
| 2984 | if (lancer_chip(adapter)) |
| 2985 | status = lancer_fw_download(adapter, fw); |
| 2986 | else |
| 2987 | status = be_fw_download(adapter, fw); |
| 2988 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2989 | fw_exit: |
| 2990 | release_firmware(fw); |
| 2991 | return status; |
| 2992 | } |
| 2993 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2994 | static struct net_device_ops be_netdev_ops = { |
| 2995 | .ndo_open = be_open, |
| 2996 | .ndo_stop = be_close, |
| 2997 | .ndo_start_xmit = be_xmit, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 2998 | .ndo_set_rx_mode = be_set_rx_mode, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2999 | .ndo_set_mac_address = be_mac_addr_set, |
| 3000 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 3001 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3002 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3003 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 3004 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 3005 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 3006 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3007 | .ndo_set_vf_tx_rate = be_set_vf_tx_rate, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 3008 | .ndo_get_vf_config = be_get_vf_config |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3009 | }; |
| 3010 | |
| 3011 | static void be_netdev_init(struct net_device *netdev) |
| 3012 | { |
| 3013 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3014 | struct be_rx_obj *rxo; |
| 3015 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3016 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 3017 | netdev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 3018 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
| 3019 | NETIF_F_HW_VLAN_TX; |
| 3020 | if (be_multi_rxq(adapter)) |
| 3021 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 3022 | |
| 3023 | netdev->features |= netdev->hw_features | |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 3024 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 3025 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 3026 | netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | |
Michał Mirosław | 7903264 | 2010-11-30 06:38:00 +0000 | [diff] [blame] | 3027 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 3028 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3029 | netdev->flags |= IFF_MULTICAST; |
| 3030 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 3031 | netif_set_gso_max_size(netdev, 65535); |
| 3032 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3033 | BE_SET_NETDEV_OPS(netdev, &be_netdev_ops); |
| 3034 | |
| 3035 | SET_ETHTOOL_OPS(netdev, &be_ethtool_ops); |
| 3036 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3037 | for_all_rx_queues(adapter, rxo, i) |
| 3038 | netif_napi_add(netdev, &rxo->rx_eq.napi, be_poll_rx, |
| 3039 | BE_NAPI_WEIGHT); |
| 3040 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3041 | netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3042 | BE_NAPI_WEIGHT); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 3046 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3047 | if (adapter->csr) |
| 3048 | iounmap(adapter->csr); |
| 3049 | if (adapter->db) |
| 3050 | iounmap(adapter->db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 3054 | { |
| 3055 | u8 __iomem *addr; |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 3056 | int db_reg; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3057 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3058 | if (lancer_chip(adapter)) { |
| 3059 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 0), |
| 3060 | pci_resource_len(adapter->pdev, 0)); |
| 3061 | if (addr == NULL) |
| 3062 | return -ENOMEM; |
| 3063 | adapter->db = addr; |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3067 | if (be_physfn(adapter)) { |
| 3068 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2), |
| 3069 | pci_resource_len(adapter->pdev, 2)); |
| 3070 | if (addr == NULL) |
| 3071 | return -ENOMEM; |
| 3072 | adapter->csr = addr; |
| 3073 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3074 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3075 | if (adapter->generation == BE_GEN2) { |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3076 | db_reg = 4; |
| 3077 | } else { |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3078 | if (be_physfn(adapter)) |
| 3079 | db_reg = 4; |
| 3080 | else |
| 3081 | db_reg = 0; |
| 3082 | } |
| 3083 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, db_reg), |
| 3084 | pci_resource_len(adapter->pdev, db_reg)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3085 | if (addr == NULL) |
| 3086 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3087 | adapter->db = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3088 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3089 | return 0; |
| 3090 | pci_map_err: |
| 3091 | be_unmap_pci_bars(adapter); |
| 3092 | return -ENOMEM; |
| 3093 | } |
| 3094 | |
| 3095 | |
| 3096 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 3097 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3098 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3099 | |
| 3100 | be_unmap_pci_bars(adapter); |
| 3101 | |
| 3102 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3103 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 3104 | mem->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3105 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3106 | mem = &adapter->rx_filter; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3107 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3108 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 3109 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3112 | static int be_ctrl_init(struct be_adapter *adapter) |
| 3113 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3114 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 3115 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3116 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3117 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3118 | |
| 3119 | status = be_map_pci_bars(adapter); |
| 3120 | if (status) |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3121 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3122 | |
| 3123 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3124 | mbox_mem_alloc->va = dma_alloc_coherent(&adapter->pdev->dev, |
| 3125 | mbox_mem_alloc->size, |
| 3126 | &mbox_mem_alloc->dma, |
| 3127 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3128 | if (!mbox_mem_alloc->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3129 | status = -ENOMEM; |
| 3130 | goto unmap_pci_bars; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3131 | } |
| 3132 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 3133 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 3134 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 3135 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3136 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3137 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
| 3138 | rx_filter->va = dma_alloc_coherent(&adapter->pdev->dev, rx_filter->size, |
| 3139 | &rx_filter->dma, GFP_KERNEL); |
| 3140 | if (rx_filter->va == NULL) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3141 | status = -ENOMEM; |
| 3142 | goto free_mbox; |
| 3143 | } |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3144 | memset(rx_filter->va, 0, rx_filter->size); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3145 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 3146 | mutex_init(&adapter->mbox_lock); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3147 | spin_lock_init(&adapter->mcc_lock); |
| 3148 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3149 | |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 3150 | init_completion(&adapter->flash_compl); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3151 | pci_save_state(adapter->pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3152 | return 0; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3153 | |
| 3154 | free_mbox: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3155 | dma_free_coherent(&adapter->pdev->dev, mbox_mem_alloc->size, |
| 3156 | mbox_mem_alloc->va, mbox_mem_alloc->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3157 | |
| 3158 | unmap_pci_bars: |
| 3159 | be_unmap_pci_bars(adapter); |
| 3160 | |
| 3161 | done: |
| 3162 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 3166 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3167 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3168 | |
| 3169 | if (cmd->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3170 | dma_free_coherent(&adapter->pdev->dev, cmd->size, |
| 3171 | cmd->va, cmd->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | static int be_stats_init(struct be_adapter *adapter) |
| 3175 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3176 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3177 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 3178 | if (adapter->generation == BE_GEN2) { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 3179 | cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 3180 | } else { |
| 3181 | if (lancer_chip(adapter)) |
| 3182 | cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 3183 | else |
| 3184 | cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
| 3185 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3186 | cmd->va = dma_alloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma, |
| 3187 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3188 | if (cmd->va == NULL) |
| 3189 | return -1; |
David S. Miller | d291b9a | 2010-01-28 21:36:21 -0800 | [diff] [blame] | 3190 | memset(cmd->va, 0, cmd->size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3191 | return 0; |
| 3192 | } |
| 3193 | |
| 3194 | static void __devexit be_remove(struct pci_dev *pdev) |
| 3195 | { |
| 3196 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3197 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3198 | if (!adapter) |
| 3199 | return; |
| 3200 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 3201 | cancel_delayed_work_sync(&adapter->work); |
| 3202 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3203 | unregister_netdev(adapter->netdev); |
| 3204 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3205 | be_clear(adapter); |
| 3206 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3207 | be_stats_cleanup(adapter); |
| 3208 | |
| 3209 | be_ctrl_cleanup(adapter); |
| 3210 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3211 | be_sriov_disable(adapter); |
| 3212 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3213 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3214 | |
| 3215 | pci_set_drvdata(pdev, NULL); |
| 3216 | pci_release_regions(pdev); |
| 3217 | pci_disable_device(pdev); |
| 3218 | |
| 3219 | free_netdev(adapter->netdev); |
| 3220 | } |
| 3221 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3222 | static int be_get_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3223 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3224 | int status; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 3225 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3226 | status = be_cmd_query_fw_cfg(adapter, &adapter->port_num, |
| 3227 | &adapter->function_mode, &adapter->function_caps); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3228 | if (status) |
| 3229 | return status; |
| 3230 | |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 3231 | if (adapter->function_mode & FLEX10_MODE) |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 3232 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/4; |
| 3233 | else |
| 3234 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED; |
| 3235 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3236 | status = be_cmd_get_cntl_attributes(adapter); |
| 3237 | if (status) |
| 3238 | return status; |
| 3239 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3240 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3243 | static int be_dev_family_check(struct be_adapter *adapter) |
| 3244 | { |
| 3245 | struct pci_dev *pdev = adapter->pdev; |
| 3246 | u32 sli_intf = 0, if_type; |
| 3247 | |
| 3248 | switch (pdev->device) { |
| 3249 | case BE_DEVICE_ID1: |
| 3250 | case OC_DEVICE_ID1: |
| 3251 | adapter->generation = BE_GEN2; |
| 3252 | break; |
| 3253 | case BE_DEVICE_ID2: |
| 3254 | case OC_DEVICE_ID2: |
| 3255 | adapter->generation = BE_GEN3; |
| 3256 | break; |
| 3257 | case OC_DEVICE_ID3: |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 3258 | case OC_DEVICE_ID4: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3259 | pci_read_config_dword(pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 3260 | if_type = (sli_intf & SLI_INTF_IF_TYPE_MASK) >> |
| 3261 | SLI_INTF_IF_TYPE_SHIFT; |
| 3262 | |
| 3263 | if (((sli_intf & SLI_INTF_VALID_MASK) != SLI_INTF_VALID) || |
| 3264 | if_type != 0x02) { |
| 3265 | dev_err(&pdev->dev, "SLI_INTF reg val is not valid\n"); |
| 3266 | return -EINVAL; |
| 3267 | } |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3268 | adapter->sli_family = ((sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 3269 | SLI_INTF_FAMILY_SHIFT); |
| 3270 | adapter->generation = BE_GEN3; |
| 3271 | break; |
| 3272 | default: |
| 3273 | adapter->generation = 0; |
| 3274 | } |
| 3275 | return 0; |
| 3276 | } |
| 3277 | |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3278 | static int lancer_wait_ready(struct be_adapter *adapter) |
| 3279 | { |
| 3280 | #define SLIPORT_READY_TIMEOUT 500 |
| 3281 | u32 sliport_status; |
| 3282 | int status = 0, i; |
| 3283 | |
| 3284 | for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) { |
| 3285 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3286 | if (sliport_status & SLIPORT_STATUS_RDY_MASK) |
| 3287 | break; |
| 3288 | |
| 3289 | msleep(20); |
| 3290 | } |
| 3291 | |
| 3292 | if (i == SLIPORT_READY_TIMEOUT) |
| 3293 | status = -1; |
| 3294 | |
| 3295 | return status; |
| 3296 | } |
| 3297 | |
| 3298 | static int lancer_test_and_set_rdy_state(struct be_adapter *adapter) |
| 3299 | { |
| 3300 | int status; |
| 3301 | u32 sliport_status, err, reset_needed; |
| 3302 | status = lancer_wait_ready(adapter); |
| 3303 | if (!status) { |
| 3304 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3305 | err = sliport_status & SLIPORT_STATUS_ERR_MASK; |
| 3306 | reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK; |
| 3307 | if (err && reset_needed) { |
| 3308 | iowrite32(SLI_PORT_CONTROL_IP_MASK, |
| 3309 | adapter->db + SLIPORT_CONTROL_OFFSET); |
| 3310 | |
| 3311 | /* check adapter has corrected the error */ |
| 3312 | status = lancer_wait_ready(adapter); |
| 3313 | sliport_status = ioread32(adapter->db + |
| 3314 | SLIPORT_STATUS_OFFSET); |
| 3315 | sliport_status &= (SLIPORT_STATUS_ERR_MASK | |
| 3316 | SLIPORT_STATUS_RN_MASK); |
| 3317 | if (status || sliport_status) |
| 3318 | status = -1; |
| 3319 | } else if (err || reset_needed) { |
| 3320 | status = -1; |
| 3321 | } |
| 3322 | } |
| 3323 | return status; |
| 3324 | } |
| 3325 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3326 | static int __devinit be_probe(struct pci_dev *pdev, |
| 3327 | const struct pci_device_id *pdev_id) |
| 3328 | { |
| 3329 | int status = 0; |
| 3330 | struct be_adapter *adapter; |
| 3331 | struct net_device *netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3332 | |
| 3333 | status = pci_enable_device(pdev); |
| 3334 | if (status) |
| 3335 | goto do_none; |
| 3336 | |
| 3337 | status = pci_request_regions(pdev, DRV_NAME); |
| 3338 | if (status) |
| 3339 | goto disable_dev; |
| 3340 | pci_set_master(pdev); |
| 3341 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3342 | netdev = alloc_etherdev_mq(sizeof(struct be_adapter), MAX_TX_QS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3343 | if (netdev == NULL) { |
| 3344 | status = -ENOMEM; |
| 3345 | goto rel_reg; |
| 3346 | } |
| 3347 | adapter = netdev_priv(netdev); |
| 3348 | adapter->pdev = pdev; |
| 3349 | pci_set_drvdata(pdev, adapter); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3350 | |
| 3351 | status = be_dev_family_check(adapter); |
Sathya Perla | 63657b9 | 2010-12-01 01:02:28 +0000 | [diff] [blame] | 3352 | if (status) |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3353 | goto free_netdev; |
| 3354 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3355 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3356 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3357 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3358 | status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3359 | if (!status) { |
| 3360 | netdev->features |= NETIF_F_HIGHDMA; |
| 3361 | } else { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3362 | status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3363 | if (status) { |
| 3364 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 3365 | goto free_netdev; |
| 3366 | } |
| 3367 | } |
| 3368 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3369 | status = be_sriov_enable(adapter); |
| 3370 | if (status) |
| 3371 | goto free_netdev; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3372 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3373 | status = be_ctrl_init(adapter); |
| 3374 | if (status) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3375 | goto disable_sriov; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3376 | |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3377 | if (lancer_chip(adapter)) { |
| 3378 | status = lancer_test_and_set_rdy_state(adapter); |
| 3379 | if (status) { |
| 3380 | dev_err(&pdev->dev, "Adapter in non recoverable error\n"); |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3381 | goto ctrl_clean; |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3385 | /* sync up with fw's ready state */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3386 | if (be_physfn(adapter)) { |
| 3387 | status = be_cmd_POST(adapter); |
| 3388 | if (status) |
| 3389 | goto ctrl_clean; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3390 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3391 | |
| 3392 | /* tell fw we're ready to fire cmds */ |
| 3393 | status = be_cmd_fw_init(adapter); |
| 3394 | if (status) |
| 3395 | goto ctrl_clean; |
| 3396 | |
Ajit Khaparde | a4b4dfa | 2011-02-11 13:36:57 +0000 | [diff] [blame] | 3397 | status = be_cmd_reset_function(adapter); |
| 3398 | if (status) |
| 3399 | goto ctrl_clean; |
Sarveshwar Bandi | 556ae19 | 2010-05-24 18:38:25 -0700 | [diff] [blame] | 3400 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3401 | status = be_stats_init(adapter); |
| 3402 | if (status) |
| 3403 | goto ctrl_clean; |
| 3404 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3405 | status = be_get_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3406 | if (status) |
| 3407 | goto stats_clean; |
| 3408 | |
Sathya Perla | b9ab82c | 2011-06-29 23:33:37 +0000 | [diff] [blame] | 3409 | /* The INTR bit may be set in the card when probed by a kdump kernel |
| 3410 | * after a crash. |
| 3411 | */ |
| 3412 | if (!lancer_chip(adapter)) |
| 3413 | be_intr_set(adapter, false); |
| 3414 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3415 | be_msix_enable(adapter); |
| 3416 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3417 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3418 | adapter->rx_fc = adapter->tx_fc = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3419 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3420 | status = be_setup(adapter); |
| 3421 | if (status) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3422 | goto msix_disable; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3423 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3424 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3425 | status = register_netdev(netdev); |
| 3426 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3427 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3428 | |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 3429 | dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 3430 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 3431 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3432 | return 0; |
| 3433 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3434 | unsetup: |
| 3435 | be_clear(adapter); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3436 | msix_disable: |
| 3437 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3438 | stats_clean: |
| 3439 | be_stats_cleanup(adapter); |
| 3440 | ctrl_clean: |
| 3441 | be_ctrl_cleanup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3442 | disable_sriov: |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3443 | be_sriov_disable(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3444 | free_netdev: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3445 | free_netdev(netdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3446 | pci_set_drvdata(pdev, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3447 | rel_reg: |
| 3448 | pci_release_regions(pdev); |
| 3449 | disable_dev: |
| 3450 | pci_disable_device(pdev); |
| 3451 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 3452 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3453 | return status; |
| 3454 | } |
| 3455 | |
| 3456 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3457 | { |
| 3458 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3459 | struct net_device *netdev = adapter->netdev; |
| 3460 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3461 | cancel_delayed_work_sync(&adapter->work); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3462 | if (adapter->wol) |
| 3463 | be_setup_wol(adapter, true); |
| 3464 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3465 | netif_device_detach(netdev); |
| 3466 | if (netif_running(netdev)) { |
| 3467 | rtnl_lock(); |
| 3468 | be_close(netdev); |
| 3469 | rtnl_unlock(); |
| 3470 | } |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 3471 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3472 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3473 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3474 | pci_save_state(pdev); |
| 3475 | pci_disable_device(pdev); |
| 3476 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3477 | return 0; |
| 3478 | } |
| 3479 | |
| 3480 | static int be_resume(struct pci_dev *pdev) |
| 3481 | { |
| 3482 | int status = 0; |
| 3483 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3484 | struct net_device *netdev = adapter->netdev; |
| 3485 | |
| 3486 | netif_device_detach(netdev); |
| 3487 | |
| 3488 | status = pci_enable_device(pdev); |
| 3489 | if (status) |
| 3490 | return status; |
| 3491 | |
| 3492 | pci_set_power_state(pdev, 0); |
| 3493 | pci_restore_state(pdev); |
| 3494 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3495 | be_msix_enable(adapter); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3496 | /* tell fw we're ready to fire cmds */ |
| 3497 | status = be_cmd_fw_init(adapter); |
| 3498 | if (status) |
| 3499 | return status; |
| 3500 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 3501 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3502 | if (netif_running(netdev)) { |
| 3503 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3504 | be_open(netdev); |
| 3505 | rtnl_unlock(); |
| 3506 | } |
| 3507 | netif_device_attach(netdev); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3508 | |
| 3509 | if (adapter->wol) |
| 3510 | be_setup_wol(adapter, false); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3511 | |
| 3512 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3513 | return 0; |
| 3514 | } |
| 3515 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3516 | /* |
| 3517 | * An FLR will stop BE from DMAing any data. |
| 3518 | */ |
| 3519 | static void be_shutdown(struct pci_dev *pdev) |
| 3520 | { |
| 3521 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3522 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 3523 | if (!adapter) |
| 3524 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3525 | |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 3526 | cancel_delayed_work_sync(&adapter->work); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3527 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 3528 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3529 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3530 | if (adapter->wol) |
| 3531 | be_setup_wol(adapter, true); |
| 3532 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 3533 | be_cmd_reset_function(adapter); |
| 3534 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3535 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3538 | static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev, |
| 3539 | pci_channel_state_t state) |
| 3540 | { |
| 3541 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3542 | struct net_device *netdev = adapter->netdev; |
| 3543 | |
| 3544 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 3545 | |
| 3546 | adapter->eeh_err = true; |
| 3547 | |
| 3548 | netif_device_detach(netdev); |
| 3549 | |
| 3550 | if (netif_running(netdev)) { |
| 3551 | rtnl_lock(); |
| 3552 | be_close(netdev); |
| 3553 | rtnl_unlock(); |
| 3554 | } |
| 3555 | be_clear(adapter); |
| 3556 | |
| 3557 | if (state == pci_channel_io_perm_failure) |
| 3558 | return PCI_ERS_RESULT_DISCONNECT; |
| 3559 | |
| 3560 | pci_disable_device(pdev); |
| 3561 | |
| 3562 | return PCI_ERS_RESULT_NEED_RESET; |
| 3563 | } |
| 3564 | |
| 3565 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 3566 | { |
| 3567 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3568 | int status; |
| 3569 | |
| 3570 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
| 3571 | adapter->eeh_err = false; |
| 3572 | |
| 3573 | status = pci_enable_device(pdev); |
| 3574 | if (status) |
| 3575 | return PCI_ERS_RESULT_DISCONNECT; |
| 3576 | |
| 3577 | pci_set_master(pdev); |
| 3578 | pci_set_power_state(pdev, 0); |
| 3579 | pci_restore_state(pdev); |
| 3580 | |
| 3581 | /* Check if card is ok and fw is ready */ |
| 3582 | status = be_cmd_POST(adapter); |
| 3583 | if (status) |
| 3584 | return PCI_ERS_RESULT_DISCONNECT; |
| 3585 | |
| 3586 | return PCI_ERS_RESULT_RECOVERED; |
| 3587 | } |
| 3588 | |
| 3589 | static void be_eeh_resume(struct pci_dev *pdev) |
| 3590 | { |
| 3591 | int status = 0; |
| 3592 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3593 | struct net_device *netdev = adapter->netdev; |
| 3594 | |
| 3595 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 3596 | |
| 3597 | pci_save_state(pdev); |
| 3598 | |
| 3599 | /* tell fw we're ready to fire cmds */ |
| 3600 | status = be_cmd_fw_init(adapter); |
| 3601 | if (status) |
| 3602 | goto err; |
| 3603 | |
| 3604 | status = be_setup(adapter); |
| 3605 | if (status) |
| 3606 | goto err; |
| 3607 | |
| 3608 | if (netif_running(netdev)) { |
| 3609 | status = be_open(netdev); |
| 3610 | if (status) |
| 3611 | goto err; |
| 3612 | } |
| 3613 | netif_device_attach(netdev); |
| 3614 | return; |
| 3615 | err: |
| 3616 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | static struct pci_error_handlers be_eeh_handlers = { |
| 3620 | .error_detected = be_eeh_err_detected, |
| 3621 | .slot_reset = be_eeh_reset, |
| 3622 | .resume = be_eeh_resume, |
| 3623 | }; |
| 3624 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3625 | static struct pci_driver be_driver = { |
| 3626 | .name = DRV_NAME, |
| 3627 | .id_table = be_dev_ids, |
| 3628 | .probe = be_probe, |
| 3629 | .remove = be_remove, |
| 3630 | .suspend = be_suspend, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3631 | .resume = be_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3632 | .shutdown = be_shutdown, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3633 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3634 | }; |
| 3635 | |
| 3636 | static int __init be_init_module(void) |
| 3637 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 3638 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 3639 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3640 | printk(KERN_WARNING DRV_NAME |
| 3641 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 3642 | " Using 2048\n"); |
| 3643 | rx_frag_size = 2048; |
| 3644 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3645 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3646 | return pci_register_driver(&be_driver); |
| 3647 | } |
| 3648 | module_init(be_init_module); |
| 3649 | |
| 3650 | static void __exit be_exit_module(void) |
| 3651 | { |
| 3652 | pci_unregister_driver(&be_driver); |
| 3653 | } |
| 3654 | module_exit(be_exit_module); |