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