Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Vasundhara Volam | 4026382 | 2014-02-12 16:09:07 +0530 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2014 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 | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 23 | #include <linux/aer.h> |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 24 | #include <linux/if_bridge.h> |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 25 | #include <net/busy_poll.h> |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 26 | #include <net/vxlan.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 27 | |
| 28 | MODULE_VERSION(DRV_VER); |
| 29 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
| 30 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
Sarveshwar Bandi | 00d3d51 | 2013-01-28 04:17:01 +0000 | [diff] [blame] | 31 | MODULE_AUTHOR("Emulex Corporation"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 32 | MODULE_LICENSE("GPL"); |
| 33 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 34 | static unsigned int num_vfs; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 35 | module_param(num_vfs, uint, S_IRUGO); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 36 | MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 37 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 38 | static ushort rx_frag_size = 2048; |
| 39 | module_param(rx_frag_size, ushort, S_IRUGO); |
| 40 | MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data."); |
| 41 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 42 | static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 43 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Ajit Khaparde | 59fd5d8 | 2009-10-29 01:11:06 -0700 | [diff] [blame] | 44 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 45 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 46 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 47 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)}, |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 48 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)}, |
Ajit Khaparde | ecedb6a | 2011-12-15 06:31:38 +0000 | [diff] [blame] | 49 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID5)}, |
Padmanabh Ratnakar | 76b7353 | 2012-10-20 06:04:40 +0000 | [diff] [blame] | 50 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID6)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 51 | { 0 } |
| 52 | }; |
| 53 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 54 | /* UE Status Low CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 55 | static const char * const ue_status_low_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 56 | "CEV", |
| 57 | "CTX", |
| 58 | "DBUF", |
| 59 | "ERX", |
| 60 | "Host", |
| 61 | "MPU", |
| 62 | "NDMA", |
| 63 | "PTC ", |
| 64 | "RDMA ", |
| 65 | "RXF ", |
| 66 | "RXIPS ", |
| 67 | "RXULP0 ", |
| 68 | "RXULP1 ", |
| 69 | "RXULP2 ", |
| 70 | "TIM ", |
| 71 | "TPOST ", |
| 72 | "TPRE ", |
| 73 | "TXIPS ", |
| 74 | "TXULP0 ", |
| 75 | "TXULP1 ", |
| 76 | "UC ", |
| 77 | "WDMA ", |
| 78 | "TXULP2 ", |
| 79 | "HOST1 ", |
| 80 | "P0_OB_LINK ", |
| 81 | "P1_OB_LINK ", |
| 82 | "HOST_GPIO ", |
| 83 | "MBOX ", |
| 84 | "AXGMAC0", |
| 85 | "AXGMAC1", |
| 86 | "JTAG", |
| 87 | "MPU_INTPEND" |
| 88 | }; |
| 89 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 90 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 91 | "LPCMEMHOST", |
| 92 | "MGMT_MAC", |
| 93 | "PCS0ONLINE", |
| 94 | "MPU_IRAM", |
| 95 | "PCS1ONLINE", |
| 96 | "PCTL0", |
| 97 | "PCTL1", |
| 98 | "PMEM", |
| 99 | "RR", |
| 100 | "TXPB", |
| 101 | "RXPP", |
| 102 | "XAUI", |
| 103 | "TXP", |
| 104 | "ARM", |
| 105 | "IPC", |
| 106 | "HOST2", |
| 107 | "HOST3", |
| 108 | "HOST4", |
| 109 | "HOST5", |
| 110 | "HOST6", |
| 111 | "HOST7", |
| 112 | "HOST8", |
| 113 | "HOST9", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 114 | "NETC", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 115 | "Unknown", |
| 116 | "Unknown", |
| 117 | "Unknown", |
| 118 | "Unknown", |
| 119 | "Unknown", |
| 120 | "Unknown", |
| 121 | "Unknown", |
| 122 | "Unknown" |
| 123 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 124 | |
Sathya Perla | 752961a | 2011-10-24 02:45:03 +0000 | [diff] [blame] | 125 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 126 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 127 | { |
| 128 | struct be_dma_mem *mem = &q->dma_mem; |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 129 | if (mem->va) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 130 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 131 | mem->dma); |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 132 | mem->va = NULL; |
| 133 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q, |
| 137 | u16 len, u16 entry_size) |
| 138 | { |
| 139 | struct be_dma_mem *mem = &q->dma_mem; |
| 140 | |
| 141 | memset(q, 0, sizeof(*q)); |
| 142 | q->len = len; |
| 143 | q->entry_size = entry_size; |
| 144 | mem->size = len * entry_size; |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 145 | mem->va = dma_zalloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 146 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 147 | if (!mem->va) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 148 | return -ENOMEM; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 152 | static void be_reg_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 153 | { |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 154 | u32 reg, enabled; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 155 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 156 | pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, |
| 157 | ®); |
| 158 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 159 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 160 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 161 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 162 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 163 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 164 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 165 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 166 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 167 | pci_write_config_dword(adapter->pdev, |
| 168 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 171 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
| 172 | { |
| 173 | int status = 0; |
| 174 | |
| 175 | /* On lancer interrupts can't be controlled via this register */ |
| 176 | if (lancer_chip(adapter)) |
| 177 | return; |
| 178 | |
| 179 | if (adapter->eeh_error) |
| 180 | return; |
| 181 | |
| 182 | status = be_cmd_intr_set(adapter, enable); |
| 183 | if (status) |
| 184 | be_reg_intr_set(adapter, enable); |
| 185 | } |
| 186 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 187 | 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] | 188 | { |
| 189 | u32 val = 0; |
| 190 | val |= qid & DB_RQ_RING_ID_MASK; |
| 191 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 192 | |
| 193 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 194 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 197 | static void be_txq_notify(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 198 | u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 199 | { |
| 200 | u32 val = 0; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 201 | val |= txo->q.id & DB_TXULP_RING_ID_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 202 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 203 | |
| 204 | wmb(); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 205 | iowrite32(val, adapter->db + txo->db_offset); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 208 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 209 | bool arm, bool clear_int, u16 num_popped) |
| 210 | { |
| 211 | u32 val = 0; |
| 212 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 213 | val |= ((qid & DB_EQ_RING_ID_EXT_MASK) << |
| 214 | DB_EQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 215 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 216 | if (adapter->eeh_error) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 217 | return; |
| 218 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 219 | if (arm) |
| 220 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 221 | if (clear_int) |
| 222 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 223 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 224 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 225 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 228 | 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] | 229 | { |
| 230 | u32 val = 0; |
| 231 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 232 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 233 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 234 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 235 | if (adapter->eeh_error) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 236 | return; |
| 237 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 238 | if (arm) |
| 239 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 240 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 241 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 244 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 245 | { |
| 246 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 247 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 248 | struct sockaddr *addr = p; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 249 | int status; |
| 250 | u8 mac[ETH_ALEN]; |
| 251 | u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 252 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 253 | if (!is_valid_ether_addr(addr->sa_data)) |
| 254 | return -EADDRNOTAVAIL; |
| 255 | |
Vasundhara Volam | ff32f8a | 2014-01-15 13:23:35 +0530 | [diff] [blame] | 256 | /* Proceed further only if, User provided MAC is different |
| 257 | * from active MAC |
| 258 | */ |
| 259 | if (ether_addr_equal(addr->sa_data, netdev->dev_addr)) |
| 260 | return 0; |
| 261 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 262 | /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT |
| 263 | * privilege or if PF did not provision the new MAC address. |
| 264 | * On BE3, this cmd will always fail if the VF doesn't have the |
| 265 | * FILTMGMT privilege. This failure is OK, only if the PF programmed |
| 266 | * the MAC for the VF. |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 267 | */ |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 268 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
| 269 | adapter->if_handle, &adapter->pmac_id[0], 0); |
| 270 | if (!status) { |
| 271 | curr_pmac_id = adapter->pmac_id[0]; |
| 272 | |
| 273 | /* Delete the old programmed MAC. This call may fail if the |
| 274 | * old MAC was already deleted by the PF driver. |
| 275 | */ |
| 276 | if (adapter->pmac_id[0] != old_pmac_id) |
| 277 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 278 | old_pmac_id, 0); |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 281 | /* Decide if the new MAC is successfully activated only after |
| 282 | * querying the FW |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 283 | */ |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 284 | status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac, |
| 285 | adapter->if_handle, true, 0); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 286 | if (status) |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 287 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 288 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 289 | /* The MAC change did not happen, either due to lack of privilege |
| 290 | * or PF didn't pre-provision. |
| 291 | */ |
dingtianhong | 61d23e9 | 2013-12-30 15:40:43 +0800 | [diff] [blame] | 292 | if (!ether_addr_equal(addr->sa_data, mac)) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 293 | status = -EPERM; |
| 294 | goto err; |
| 295 | } |
| 296 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 297 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 298 | dev_info(dev, "MAC address changed to %pM\n", mac); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 299 | return 0; |
| 300 | err: |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 301 | dev_warn(dev, "MAC address change to %pM failed\n", addr->sa_data); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 302 | return status; |
| 303 | } |
| 304 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 305 | /* BE2 supports only v0 cmd */ |
| 306 | static void *hw_stats_from_cmd(struct be_adapter *adapter) |
| 307 | { |
| 308 | if (BE2_chip(adapter)) { |
| 309 | struct be_cmd_resp_get_stats_v0 *cmd = adapter->stats_cmd.va; |
| 310 | |
| 311 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 312 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 313 | struct be_cmd_resp_get_stats_v1 *cmd = adapter->stats_cmd.va; |
| 314 | |
| 315 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 316 | } else { |
| 317 | struct be_cmd_resp_get_stats_v2 *cmd = adapter->stats_cmd.va; |
| 318 | |
| 319 | return &cmd->hw_stats; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | /* BE2 supports only v0 cmd */ |
| 324 | static void *be_erx_stats_from_cmd(struct be_adapter *adapter) |
| 325 | { |
| 326 | if (BE2_chip(adapter)) { |
| 327 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 328 | |
| 329 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 330 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 331 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 332 | |
| 333 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 334 | } else { |
| 335 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 336 | |
| 337 | return &hw_stats->erx; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | static void populate_be_v0_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 342 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 343 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 344 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 345 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 346 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 347 | &rxf_stats->port[adapter->port_num]; |
| 348 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 349 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 350 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 351 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 352 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 353 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 354 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 355 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 356 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 357 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 358 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 359 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 360 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 361 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 362 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 363 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 364 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 365 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 366 | drvs->rx_dropped_header_too_small = |
| 367 | port_stats->rx_dropped_header_too_small; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 368 | drvs->rx_address_filtered = |
| 369 | port_stats->rx_address_filtered + |
| 370 | port_stats->rx_vlan_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 371 | drvs->rx_alignment_symbol_errors = |
| 372 | port_stats->rx_alignment_symbol_errors; |
| 373 | |
| 374 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 375 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 376 | |
| 377 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 378 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 379 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 380 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 381 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 382 | 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] | 383 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 384 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 385 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 386 | 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] | 387 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 388 | } |
| 389 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 390 | static void populate_be_v1_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 391 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 392 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 393 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 394 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 395 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 396 | &rxf_stats->port[adapter->port_num]; |
| 397 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 398 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 399 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 02fe702 | 2011-12-09 13:53:09 +0000 | [diff] [blame] | 400 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 401 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 402 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 403 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 404 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 405 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 406 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 407 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 408 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 409 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 410 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 411 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 412 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 413 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 414 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 415 | drvs->rx_dropped_header_too_small = |
| 416 | port_stats->rx_dropped_header_too_small; |
| 417 | drvs->rx_input_fifo_overflow_drop = |
| 418 | port_stats->rx_input_fifo_overflow_drop; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 419 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 420 | drvs->rx_alignment_symbol_errors = |
| 421 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 422 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 423 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 424 | drvs->tx_controlframes = port_stats->tx_controlframes; |
Ajit Khaparde | b5adffc4 | 2013-05-01 09:38:00 +0000 | [diff] [blame] | 425 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 426 | drvs->jabber_events = port_stats->jabber_events; |
| 427 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 428 | 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] | 429 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 430 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 431 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 432 | 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] | 433 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 434 | } |
| 435 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 436 | static void populate_be_v2_stats(struct be_adapter *adapter) |
| 437 | { |
| 438 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 439 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 440 | struct be_rxf_stats_v2 *rxf_stats = &hw_stats->rxf; |
| 441 | struct be_port_rxf_stats_v2 *port_stats = |
| 442 | &rxf_stats->port[adapter->port_num]; |
| 443 | struct be_drv_stats *drvs = &adapter->drv_stats; |
| 444 | |
| 445 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
| 446 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 447 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
| 448 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 449 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 450 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 451 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 452 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 453 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 454 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 455 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 456 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 457 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 458 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 459 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 460 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 461 | drvs->rx_dropped_header_too_small = |
| 462 | port_stats->rx_dropped_header_too_small; |
| 463 | drvs->rx_input_fifo_overflow_drop = |
| 464 | port_stats->rx_input_fifo_overflow_drop; |
| 465 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
| 466 | drvs->rx_alignment_symbol_errors = |
| 467 | port_stats->rx_alignment_symbol_errors; |
| 468 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
| 469 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 470 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 471 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
| 472 | drvs->jabber_events = port_stats->jabber_events; |
| 473 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 474 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 475 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 476 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
| 477 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 478 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
| 479 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
Ajit Khaparde | 461ae37 | 2013-10-03 16:16:50 -0500 | [diff] [blame] | 480 | if (be_roce_supported(adapter)) { |
| 481 | drvs->rx_roce_bytes_lsd = port_stats->roce_bytes_received_lsd; |
| 482 | drvs->rx_roce_bytes_msd = port_stats->roce_bytes_received_msd; |
| 483 | drvs->rx_roce_frames = port_stats->roce_frames_received; |
| 484 | drvs->roce_drops_crc = port_stats->roce_drops_crc; |
| 485 | drvs->roce_drops_payload_len = |
| 486 | port_stats->roce_drops_payload_len; |
| 487 | } |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 488 | } |
| 489 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 490 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 491 | { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 492 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 493 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 494 | struct lancer_pport_stats *pport_stats = |
| 495 | pport_stats_from_cmd(adapter); |
| 496 | |
| 497 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 498 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 499 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 500 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 501 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 502 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 503 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 504 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 505 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 506 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 507 | drvs->rx_dropped_tcp_length = |
| 508 | pport_stats->rx_dropped_invalid_tcp_length; |
| 509 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 510 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 511 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 512 | drvs->rx_dropped_header_too_small = |
| 513 | pport_stats->rx_dropped_header_too_small; |
| 514 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 515 | drvs->rx_address_filtered = |
| 516 | pport_stats->rx_address_filtered + |
| 517 | pport_stats->rx_vlan_filtered; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 518 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 519 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 520 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 521 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 522 | drvs->jabber_events = pport_stats->rx_jabbers; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 523 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 524 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 525 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 526 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 527 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 528 | |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 529 | static void accumulate_16bit_val(u32 *acc, u16 val) |
| 530 | { |
| 531 | #define lo(x) (x & 0xFFFF) |
| 532 | #define hi(x) (x & 0xFFFF0000) |
| 533 | bool wrapped = val < lo(*acc); |
| 534 | u32 newacc = hi(*acc) + val; |
| 535 | |
| 536 | if (wrapped) |
| 537 | newacc += 65536; |
| 538 | ACCESS_ONCE(*acc) = newacc; |
| 539 | } |
| 540 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 541 | static void populate_erx_stats(struct be_adapter *adapter, |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 542 | struct be_rx_obj *rxo, |
| 543 | u32 erx_stat) |
| 544 | { |
| 545 | if (!BEx_chip(adapter)) |
| 546 | rx_stats(rxo)->rx_drops_no_frags = erx_stat; |
| 547 | else |
| 548 | /* below erx HW counter can actually wrap around after |
| 549 | * 65535. Driver accumulates a 32-bit value |
| 550 | */ |
| 551 | accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags, |
| 552 | (u16)erx_stat); |
| 553 | } |
| 554 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 555 | void be_parse_stats(struct be_adapter *adapter) |
| 556 | { |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 557 | struct be_erx_stats_v2 *erx = be_erx_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 558 | struct be_rx_obj *rxo; |
| 559 | int i; |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 560 | u32 erx_stat; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 561 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 562 | if (lancer_chip(adapter)) { |
| 563 | populate_lancer_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 564 | } else { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 565 | if (BE2_chip(adapter)) |
| 566 | populate_be_v0_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 567 | else if (BE3_chip(adapter)) |
| 568 | /* for BE3 */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 569 | populate_be_v1_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 570 | else |
| 571 | populate_be_v2_stats(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 572 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 573 | /* erx_v2 is longer than v0, v1. use v2 for v0, v1 access */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 574 | for_all_rx_queues(adapter, rxo, i) { |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 575 | erx_stat = erx->rx_drops_no_fragments[rxo->q.id]; |
| 576 | populate_erx_stats(adapter, rxo, erx_stat); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 577 | } |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 578 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 581 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
| 582 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 583 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 584 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 585 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 586 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 587 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 588 | u64 pkts, bytes; |
| 589 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 590 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 591 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 592 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 593 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
| 594 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 595 | start = u64_stats_fetch_begin_irq(&rx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 596 | pkts = rx_stats(rxo)->rx_pkts; |
| 597 | bytes = rx_stats(rxo)->rx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 598 | } while (u64_stats_fetch_retry_irq(&rx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 599 | stats->rx_packets += pkts; |
| 600 | stats->rx_bytes += bytes; |
| 601 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 602 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 603 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 606 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 607 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
| 608 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 609 | start = u64_stats_fetch_begin_irq(&tx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 610 | pkts = tx_stats(txo)->tx_pkts; |
| 611 | bytes = tx_stats(txo)->tx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 612 | } while (u64_stats_fetch_retry_irq(&tx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 613 | stats->tx_packets += pkts; |
| 614 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 615 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 616 | |
| 617 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 618 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 619 | drvs->rx_alignment_symbol_errors + |
| 620 | drvs->rx_in_range_errors + |
| 621 | drvs->rx_out_range_errors + |
| 622 | drvs->rx_frame_too_long + |
| 623 | drvs->rx_dropped_too_small + |
| 624 | drvs->rx_dropped_too_short + |
| 625 | drvs->rx_dropped_header_too_small + |
| 626 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 627 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 628 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 629 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 630 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 631 | drvs->rx_out_range_errors + |
| 632 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 633 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 634 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 635 | |
| 636 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 637 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 638 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 639 | /* receiver fifo overrun */ |
| 640 | /* 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] | 641 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 642 | drvs->rx_input_fifo_overflow_drop + |
| 643 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 644 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 647 | void be_link_status_update(struct be_adapter *adapter, u8 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 648 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 649 | struct net_device *netdev = adapter->netdev; |
| 650 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 651 | if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) { |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 652 | netif_carrier_off(netdev); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 653 | adapter->flags |= BE_FLAGS_LINK_STATUS_INIT; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 654 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 655 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 656 | if (link_status) |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 657 | netif_carrier_on(netdev); |
| 658 | else |
| 659 | netif_carrier_off(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 662 | static void be_tx_stats_update(struct be_tx_obj *txo, |
Ajit Khaparde | 91992e4 | 2010-02-19 13:57:12 +0000 | [diff] [blame] | 663 | u32 wrb_cnt, u32 copied, u32 gso_segs, bool stopped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 664 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 665 | struct be_tx_stats *stats = tx_stats(txo); |
| 666 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 667 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 668 | stats->tx_reqs++; |
| 669 | stats->tx_wrbs += wrb_cnt; |
| 670 | stats->tx_bytes += copied; |
| 671 | stats->tx_pkts += (gso_segs ? gso_segs : 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 672 | if (stopped) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 673 | stats->tx_stops++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 674 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /* Determine number of WRB entries needed to xmit data in an skb */ |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 678 | static u32 wrb_cnt_for_skb(struct be_adapter *adapter, struct sk_buff *skb, |
| 679 | bool *dummy) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 680 | { |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 681 | int cnt = (skb->len > skb->data_len); |
| 682 | |
| 683 | cnt += skb_shinfo(skb)->nr_frags; |
| 684 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 685 | /* to account for hdr wrb */ |
| 686 | cnt++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 687 | if (lancer_chip(adapter) || !(cnt & 1)) { |
| 688 | *dummy = false; |
| 689 | } else { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 690 | /* add a dummy to make it an even num */ |
| 691 | cnt++; |
| 692 | *dummy = true; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 693 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 694 | BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT); |
| 695 | return cnt; |
| 696 | } |
| 697 | |
| 698 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 699 | { |
| 700 | wrb->frag_pa_hi = upper_32_bits(addr); |
| 701 | wrb->frag_pa_lo = addr & 0xFFFFFFFF; |
| 702 | wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK; |
Somnath Kotur | 89b1f49 | 2012-06-24 19:40:55 +0000 | [diff] [blame] | 703 | wrb->rsvd0 = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 706 | static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter, |
| 707 | struct sk_buff *skb) |
| 708 | { |
| 709 | u8 vlan_prio; |
| 710 | u16 vlan_tag; |
| 711 | |
| 712 | vlan_tag = vlan_tx_tag_get(skb); |
| 713 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 714 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 715 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 716 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
| 717 | adapter->recommended_prio; |
| 718 | |
| 719 | return vlan_tag; |
| 720 | } |
| 721 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 722 | /* Used only for IP tunnel packets */ |
| 723 | static u16 skb_inner_ip_proto(struct sk_buff *skb) |
| 724 | { |
| 725 | return (inner_ip_hdr(skb)->version == 4) ? |
| 726 | inner_ip_hdr(skb)->protocol : inner_ipv6_hdr(skb)->nexthdr; |
| 727 | } |
| 728 | |
| 729 | static u16 skb_ip_proto(struct sk_buff *skb) |
| 730 | { |
| 731 | return (ip_hdr(skb)->version == 4) ? |
| 732 | ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr; |
| 733 | } |
| 734 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 735 | static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr, |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 736 | struct sk_buff *skb, u32 wrb_cnt, u32 len, bool skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 737 | { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 738 | u16 vlan_tag, proto; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 739 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 740 | memset(hdr, 0, sizeof(*hdr)); |
| 741 | |
| 742 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1); |
| 743 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 744 | if (skb_is_gso(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 745 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1); |
| 746 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss, |
| 747 | hdr, skb_shinfo(skb)->gso_size); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 748 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 749 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso6, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 750 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 751 | if (skb->encapsulation) { |
| 752 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, ipcs, hdr, 1); |
| 753 | proto = skb_inner_ip_proto(skb); |
| 754 | } else { |
| 755 | proto = skb_ip_proto(skb); |
| 756 | } |
| 757 | if (proto == IPPROTO_TCP) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 758 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 759 | else if (proto == IPPROTO_UDP) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 760 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1); |
| 761 | } |
| 762 | |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 763 | if (vlan_tx_tag_present(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 764 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 765 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 766 | 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] | 767 | } |
| 768 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 769 | /* To skip HW VLAN tagging: evt = 1, compl = 0 */ |
| 770 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, !skip_hw_vlan); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 771 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 772 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt); |
| 773 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len); |
| 774 | } |
| 775 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 776 | 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] | 777 | bool unmap_single) |
| 778 | { |
| 779 | dma_addr_t dma; |
| 780 | |
| 781 | be_dws_le_to_cpu(wrb, sizeof(*wrb)); |
| 782 | |
| 783 | dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo; |
FUJITA Tomonori | b681ee7 | 2010-04-04 21:40:18 +0000 | [diff] [blame] | 784 | if (wrb->frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 785 | if (unmap_single) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 786 | dma_unmap_single(dev, dma, wrb->frag_len, |
| 787 | DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 788 | else |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 789 | dma_unmap_page(dev, dma, wrb->frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 790 | } |
| 791 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 792 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 793 | static int make_tx_wrbs(struct be_adapter *adapter, struct be_queue_info *txq, |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 794 | struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb, |
| 795 | bool skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 796 | { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 797 | dma_addr_t busaddr; |
| 798 | int i, copied = 0; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 799 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 800 | struct sk_buff *first_skb = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 801 | struct be_eth_wrb *wrb; |
| 802 | struct be_eth_hdr_wrb *hdr; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 803 | bool map_single = false; |
| 804 | u16 map_head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 805 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 806 | hdr = queue_head_node(txq); |
| 807 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 808 | map_head = txq->head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 809 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 810 | if (skb->len > skb->data_len) { |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 811 | int len = skb_headlen(skb); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 812 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 813 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 814 | goto dma_err; |
| 815 | map_single = true; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 816 | wrb = queue_head_node(txq); |
| 817 | wrb_fill(wrb, busaddr, len); |
| 818 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 819 | queue_head_inc(txq); |
| 820 | copied += len; |
| 821 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 822 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 823 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 824 | const struct skb_frag_struct *frag = |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 825 | &skb_shinfo(skb)->frags[i]; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 826 | busaddr = skb_frag_dma_map(dev, frag, 0, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 827 | skb_frag_size(frag), DMA_TO_DEVICE); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 828 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 829 | goto dma_err; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 830 | wrb = queue_head_node(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 831 | wrb_fill(wrb, busaddr, skb_frag_size(frag)); |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 832 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 833 | queue_head_inc(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 834 | copied += skb_frag_size(frag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | if (dummy_wrb) { |
| 838 | wrb = queue_head_node(txq); |
| 839 | wrb_fill(wrb, 0, 0); |
| 840 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 841 | queue_head_inc(txq); |
| 842 | } |
| 843 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 844 | wrb_fill_hdr(adapter, hdr, first_skb, wrb_cnt, copied, skip_hw_vlan); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 845 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 846 | |
| 847 | return copied; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 848 | dma_err: |
| 849 | txq->head = map_head; |
| 850 | while (copied) { |
| 851 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 852 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 853 | map_single = false; |
| 854 | copied -= wrb->frag_len; |
| 855 | queue_head_inc(txq); |
| 856 | } |
| 857 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 860 | static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter, |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 861 | struct sk_buff *skb, |
| 862 | bool *skip_hw_vlan) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 863 | { |
| 864 | u16 vlan_tag = 0; |
| 865 | |
| 866 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 867 | if (unlikely(!skb)) |
| 868 | return skb; |
| 869 | |
Sarveshwar Bandi | efee8e8 | 2013-05-13 20:28:20 +0000 | [diff] [blame] | 870 | if (vlan_tx_tag_present(skb)) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 871 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 872 | |
| 873 | if (qnq_async_evt_rcvd(adapter) && adapter->pvid) { |
| 874 | if (!vlan_tag) |
| 875 | vlan_tag = adapter->pvid; |
| 876 | /* f/w workaround to set skip_hw_vlan = 1, informs the F/W to |
| 877 | * skip VLAN insertion |
| 878 | */ |
| 879 | if (skip_hw_vlan) |
| 880 | *skip_hw_vlan = true; |
| 881 | } |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 882 | |
| 883 | if (vlan_tag) { |
David S. Miller | 5871768 | 2013-04-30 03:50:54 -0400 | [diff] [blame] | 884 | skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 885 | if (unlikely(!skb)) |
| 886 | return skb; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 887 | skb->vlan_tci = 0; |
| 888 | } |
| 889 | |
| 890 | /* Insert the outer VLAN, if any */ |
| 891 | if (adapter->qnq_vid) { |
| 892 | vlan_tag = adapter->qnq_vid; |
David S. Miller | 5871768 | 2013-04-30 03:50:54 -0400 | [diff] [blame] | 893 | skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 894 | if (unlikely(!skb)) |
| 895 | return skb; |
| 896 | if (skip_hw_vlan) |
| 897 | *skip_hw_vlan = true; |
| 898 | } |
| 899 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 900 | return skb; |
| 901 | } |
| 902 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 903 | static bool be_ipv6_exthdr_check(struct sk_buff *skb) |
| 904 | { |
| 905 | struct ethhdr *eh = (struct ethhdr *)skb->data; |
| 906 | u16 offset = ETH_HLEN; |
| 907 | |
| 908 | if (eh->h_proto == htons(ETH_P_IPV6)) { |
| 909 | struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + offset); |
| 910 | |
| 911 | offset += sizeof(struct ipv6hdr); |
| 912 | if (ip6h->nexthdr != NEXTHDR_TCP && |
| 913 | ip6h->nexthdr != NEXTHDR_UDP) { |
| 914 | struct ipv6_opt_hdr *ehdr = |
| 915 | (struct ipv6_opt_hdr *) (skb->data + offset); |
| 916 | |
| 917 | /* offending pkt: 2nd byte following IPv6 hdr is 0xff */ |
| 918 | if (ehdr->hdrlen == 0xff) |
| 919 | return true; |
| 920 | } |
| 921 | } |
| 922 | return false; |
| 923 | } |
| 924 | |
| 925 | static int be_vlan_tag_tx_chk(struct be_adapter *adapter, struct sk_buff *skb) |
| 926 | { |
| 927 | return vlan_tx_tag_present(skb) || adapter->pvid || adapter->qnq_vid; |
| 928 | } |
| 929 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 930 | static int be_ipv6_tx_stall_chk(struct be_adapter *adapter, |
| 931 | struct sk_buff *skb) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 932 | { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 933 | return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 936 | static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter, |
| 937 | struct sk_buff *skb, |
| 938 | bool *skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 939 | { |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 940 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 941 | unsigned int eth_hdr_len; |
| 942 | struct iphdr *ip; |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 943 | |
Ajit Khaparde | 1297f9d | 2013-04-24 11:52:28 +0000 | [diff] [blame] | 944 | /* For padded packets, BE HW modifies tot_len field in IP header |
| 945 | * incorrecly when VLAN tag is inserted by HW. |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 946 | * For padded packets, Lancer computes incorrect checksum. |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 947 | */ |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 948 | eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ? |
| 949 | VLAN_ETH_HLEN : ETH_HLEN; |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 950 | if (skb->len <= 60 && |
| 951 | (lancer_chip(adapter) || vlan_tx_tag_present(skb)) && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 952 | is_ipv4_pkt(skb)) { |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 953 | ip = (struct iphdr *)ip_hdr(skb); |
| 954 | pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len)); |
| 955 | } |
| 956 | |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 957 | /* If vlan tag is already inlined in the packet, skip HW VLAN |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 958 | * tagging in pvid-tagging mode |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 959 | */ |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 960 | if (be_pvid_tagging_enabled(adapter) && |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 961 | veh->h_vlan_proto == htons(ETH_P_8021Q)) |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 962 | *skip_hw_vlan = true; |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 963 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 964 | /* HW has a bug wherein it will calculate CSUM for VLAN |
| 965 | * pkts even though it is disabled. |
| 966 | * Manually insert VLAN in pkt. |
| 967 | */ |
| 968 | if (skb->ip_summed != CHECKSUM_PARTIAL && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 969 | vlan_tx_tag_present(skb)) { |
| 970 | skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 971 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 972 | goto err; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /* HW may lockup when VLAN HW tagging is requested on |
| 976 | * certain ipv6 packets. Drop such pkts if the HW workaround to |
| 977 | * skip HW tagging is not enabled by FW. |
| 978 | */ |
| 979 | if (unlikely(be_ipv6_tx_stall_chk(adapter, skb) && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 980 | (adapter->pvid || adapter->qnq_vid) && |
| 981 | !qnq_async_evt_rcvd(adapter))) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 982 | goto tx_drop; |
| 983 | |
| 984 | /* Manual VLAN tag insertion to prevent: |
| 985 | * ASIC lockup when the ASIC inserts VLAN tag into |
| 986 | * certain ipv6 packets. Insert VLAN tags in driver, |
| 987 | * and set event, completion, vlan bits accordingly |
| 988 | * in the Tx WRB. |
| 989 | */ |
| 990 | if (be_ipv6_tx_stall_chk(adapter, skb) && |
| 991 | be_vlan_tag_tx_chk(adapter, skb)) { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 992 | skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 993 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 994 | goto err; |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 997 | return skb; |
| 998 | tx_drop: |
| 999 | dev_kfree_skb_any(skb); |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1000 | err: |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1001 | return NULL; |
| 1002 | } |
| 1003 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1004 | static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, |
| 1005 | struct sk_buff *skb, |
| 1006 | bool *skip_hw_vlan) |
| 1007 | { |
| 1008 | /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or |
| 1009 | * less may cause a transmit stall on that port. So the work-around is |
| 1010 | * to pad short packets (<= 32 bytes) to a 36-byte length. |
| 1011 | */ |
| 1012 | if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) { |
| 1013 | if (skb_padto(skb, 36)) |
| 1014 | return NULL; |
| 1015 | skb->len = 36; |
| 1016 | } |
| 1017 | |
| 1018 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
| 1019 | skb = be_lancer_xmit_workarounds(adapter, skb, skip_hw_vlan); |
| 1020 | if (!skb) |
| 1021 | return NULL; |
| 1022 | } |
| 1023 | |
| 1024 | return skb; |
| 1025 | } |
| 1026 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1027 | static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1028 | { |
| 1029 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1030 | struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)]; |
| 1031 | struct be_queue_info *txq = &txo->q; |
| 1032 | bool dummy_wrb, stopped = false; |
| 1033 | u32 wrb_cnt = 0, copied = 0; |
| 1034 | bool skip_hw_vlan = false; |
| 1035 | u32 start = txq->head; |
| 1036 | |
| 1037 | skb = be_xmit_workarounds(adapter, skb, &skip_hw_vlan); |
Sathya Perla | bc61752 | 2013-10-01 16:00:01 +0530 | [diff] [blame] | 1038 | if (!skb) { |
| 1039 | tx_stats(txo)->tx_drv_drops++; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1040 | return NETDEV_TX_OK; |
Sathya Perla | bc61752 | 2013-10-01 16:00:01 +0530 | [diff] [blame] | 1041 | } |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1042 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1043 | wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1044 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1045 | copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb, |
| 1046 | skip_hw_vlan); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1047 | if (copied) { |
Eric Dumazet | cd8f76c | 2012-06-07 22:59:59 +0000 | [diff] [blame] | 1048 | int gso_segs = skb_shinfo(skb)->gso_segs; |
| 1049 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1050 | /* record the sent skb in the sent_skb table */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1051 | BUG_ON(txo->sent_skb_list[start]); |
| 1052 | txo->sent_skb_list[start] = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1053 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1054 | /* Ensure txq has space for the next skb; Else stop the queue |
| 1055 | * *BEFORE* ringing the tx doorbell, so that we serialze the |
| 1056 | * tx compls of the current transmit which'll wake up the queue |
| 1057 | */ |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 1058 | atomic_add(wrb_cnt, &txq->used); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1059 | if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >= |
| 1060 | txq->len) { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1061 | netif_stop_subqueue(netdev, skb_get_queue_mapping(skb)); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1062 | stopped = true; |
| 1063 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1064 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1065 | be_txq_notify(adapter, txo, wrb_cnt); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1066 | |
Eric Dumazet | cd8f76c | 2012-06-07 22:59:59 +0000 | [diff] [blame] | 1067 | be_tx_stats_update(txo, wrb_cnt, copied, gso_segs, stopped); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1068 | } else { |
| 1069 | txq->head = start; |
Sathya Perla | bc61752 | 2013-10-01 16:00:01 +0530 | [diff] [blame] | 1070 | tx_stats(txo)->tx_drv_drops++; |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1071 | dev_kfree_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1072 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1073 | return NETDEV_TX_OK; |
| 1074 | } |
| 1075 | |
| 1076 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 1077 | { |
| 1078 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1079 | if (new_mtu < BE_MIN_MTU || |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 1080 | new_mtu > (BE_MAX_JUMBO_FRAME_SIZE - |
| 1081 | (ETH_HLEN + ETH_FCS_LEN))) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1082 | dev_info(&adapter->pdev->dev, |
| 1083 | "MTU must be between %d and %d bytes\n", |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 1084 | BE_MIN_MTU, |
| 1085 | (BE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN))); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1086 | return -EINVAL; |
| 1087 | } |
| 1088 | dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n", |
| 1089 | netdev->mtu, new_mtu); |
| 1090 | netdev->mtu = new_mtu; |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1095 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 1096 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1097 | */ |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1098 | static int be_vid_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1099 | { |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1100 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
| 1101 | u16 num = 0, i; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1102 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1103 | |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1104 | /* No need to further configure vids if in promiscuous mode */ |
| 1105 | if (adapter->promiscuous) |
| 1106 | return 0; |
| 1107 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1108 | if (adapter->vlans_added > be_max_vlans(adapter)) |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1109 | goto set_vlan_promisc; |
| 1110 | |
| 1111 | /* Construct VLAN Table to give to HW */ |
| 1112 | for (i = 0; i < VLAN_N_VID; i++) |
| 1113 | if (adapter->vlan_tag[i]) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1114 | vids[num++] = cpu_to_le16(i); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1115 | |
| 1116 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
Ajit Khaparde | 012bd38 | 2013-11-18 10:44:24 -0600 | [diff] [blame] | 1117 | vids, num, 0); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1118 | |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1119 | if (status) { |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1120 | /* Set to VLAN promisc mode as setting VLAN filter failed */ |
| 1121 | if (status == MCC_ADDL_STS_INSUFFICIENT_RESOURCES) |
| 1122 | goto set_vlan_promisc; |
| 1123 | dev_err(&adapter->pdev->dev, |
| 1124 | "Setting HW VLAN filtering failed.\n"); |
| 1125 | } else { |
| 1126 | if (adapter->flags & BE_FLAGS_VLAN_PROMISC) { |
| 1127 | /* hw VLAN filtering re-enabled. */ |
| 1128 | status = be_cmd_rx_filter(adapter, |
| 1129 | BE_FLAGS_VLAN_PROMISC, OFF); |
| 1130 | if (!status) { |
| 1131 | dev_info(&adapter->pdev->dev, |
| 1132 | "Disabling VLAN Promiscuous mode.\n"); |
| 1133 | adapter->flags &= ~BE_FLAGS_VLAN_PROMISC; |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1134 | } |
| 1135 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1136 | } |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1137 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1138 | return status; |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1139 | |
| 1140 | set_vlan_promisc: |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1141 | if (adapter->flags & BE_FLAGS_VLAN_PROMISC) |
| 1142 | return 0; |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1143 | |
| 1144 | status = be_cmd_rx_filter(adapter, BE_FLAGS_VLAN_PROMISC, ON); |
| 1145 | if (!status) { |
| 1146 | dev_info(&adapter->pdev->dev, "Enable VLAN Promiscuous mode\n"); |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1147 | adapter->flags |= BE_FLAGS_VLAN_PROMISC; |
| 1148 | } else |
| 1149 | dev_err(&adapter->pdev->dev, |
| 1150 | "Failed to enable VLAN Promiscuous mode.\n"); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1151 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1154 | static int be_vlan_add_vid(struct net_device *netdev, __be16 proto, u16 vid) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1155 | { |
| 1156 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1157 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1158 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1159 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1160 | if (lancer_chip(adapter) && vid == 0) |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1161 | return status; |
| 1162 | |
| 1163 | if (adapter->vlan_tag[vid]) |
| 1164 | return status; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1165 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1166 | adapter->vlan_tag[vid] = 1; |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1167 | adapter->vlans_added++; |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1168 | |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1169 | status = be_vid_config(adapter); |
| 1170 | if (status) { |
| 1171 | adapter->vlans_added--; |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1172 | adapter->vlan_tag[vid] = 0; |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1173 | } |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1174 | |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1175 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1178 | static int be_vlan_rem_vid(struct net_device *netdev, __be16 proto, u16 vid) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1179 | { |
| 1180 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1181 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1182 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1183 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1184 | if (lancer_chip(adapter) && vid == 0) |
| 1185 | goto ret; |
| 1186 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1187 | adapter->vlan_tag[vid] = 0; |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1188 | status = be_vid_config(adapter); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1189 | if (!status) |
| 1190 | adapter->vlans_added--; |
| 1191 | else |
| 1192 | adapter->vlan_tag[vid] = 1; |
| 1193 | ret: |
| 1194 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1197 | static void be_clear_promisc(struct be_adapter *adapter) |
| 1198 | { |
| 1199 | adapter->promiscuous = false; |
| 1200 | adapter->flags &= ~BE_FLAGS_VLAN_PROMISC; |
| 1201 | |
| 1202 | be_cmd_rx_filter(adapter, IFF_PROMISC, OFF); |
| 1203 | } |
| 1204 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 1205 | static void be_set_rx_mode(struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1206 | { |
| 1207 | struct be_adapter *adapter = netdev_priv(netdev); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1208 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1209 | |
| 1210 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1211 | be_cmd_rx_filter(adapter, IFF_PROMISC, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1212 | adapter->promiscuous = true; |
| 1213 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1214 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1215 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1216 | /* BE was previously in promiscuous mode; disable it */ |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1217 | if (adapter->promiscuous) { |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1218 | be_clear_promisc(adapter); |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1219 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1220 | be_vid_config(adapter); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1223 | /* Enable multicast promisc if num configured exceeds what we support */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1224 | if (netdev->flags & IFF_ALLMULTI || |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1225 | netdev_mc_count(netdev) > be_max_mc(adapter)) { |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1226 | be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1227 | goto done; |
| 1228 | } |
| 1229 | |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 1230 | if (netdev_uc_count(netdev) != adapter->uc_macs) { |
| 1231 | struct netdev_hw_addr *ha; |
| 1232 | int i = 1; /* First slot is claimed by the Primary MAC */ |
| 1233 | |
| 1234 | for (; adapter->uc_macs > 0; adapter->uc_macs--, i++) { |
| 1235 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 1236 | adapter->pmac_id[i], 0); |
| 1237 | } |
| 1238 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1239 | if (netdev_uc_count(netdev) > be_max_uc(adapter)) { |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 1240 | be_cmd_rx_filter(adapter, IFF_PROMISC, ON); |
| 1241 | adapter->promiscuous = true; |
| 1242 | goto done; |
| 1243 | } |
| 1244 | |
| 1245 | netdev_for_each_uc_addr(ha, adapter->netdev) { |
| 1246 | adapter->uc_macs++; /* First slot is for Primary MAC */ |
| 1247 | be_cmd_pmac_add(adapter, (u8 *)ha->addr, |
| 1248 | adapter->if_handle, |
| 1249 | &adapter->pmac_id[adapter->uc_macs], 0); |
| 1250 | } |
| 1251 | } |
| 1252 | |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1253 | status = be_cmd_rx_filter(adapter, IFF_MULTICAST, ON); |
| 1254 | |
| 1255 | /* Set to MCAST promisc mode if setting MULTICAST address fails */ |
| 1256 | if (status) { |
| 1257 | dev_info(&adapter->pdev->dev, "Exhausted multicast HW filters.\n"); |
| 1258 | dev_info(&adapter->pdev->dev, "Disabling HW multicast filtering.\n"); |
| 1259 | be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON); |
| 1260 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1261 | done: |
| 1262 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1265 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 1266 | { |
| 1267 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1268 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1269 | int status; |
| 1270 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1271 | if (!sriov_enabled(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1272 | return -EPERM; |
| 1273 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1274 | if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1275 | return -EINVAL; |
| 1276 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1277 | if (BEx_chip(adapter)) { |
| 1278 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, vf_cfg->pmac_id, |
| 1279 | vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1280 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1281 | status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle, |
| 1282 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1283 | } else { |
| 1284 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 1285 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1288 | if (status) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1289 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n", |
| 1290 | mac, vf); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1291 | else |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1292 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1293 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1294 | return status; |
| 1295 | } |
| 1296 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1297 | static int be_get_vf_config(struct net_device *netdev, int vf, |
| 1298 | struct ifla_vf_info *vi) |
| 1299 | { |
| 1300 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1301 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1302 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1303 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1304 | return -EPERM; |
| 1305 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1306 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1307 | return -EINVAL; |
| 1308 | |
| 1309 | vi->vf = vf; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1310 | vi->tx_rate = vf_cfg->tx_rate; |
Ajit Khaparde | a60b3a1 | 2013-09-27 15:18:56 -0500 | [diff] [blame] | 1311 | vi->vlan = vf_cfg->vlan_tag & VLAN_VID_MASK; |
| 1312 | vi->qos = vf_cfg->vlan_tag >> VLAN_PRIO_SHIFT; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1313 | memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1314 | vi->linkstate = adapter->vf_cfg[vf].plink_tracking; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1315 | |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1319 | static int be_set_vf_vlan(struct net_device *netdev, |
| 1320 | int vf, u16 vlan, u8 qos) |
| 1321 | { |
| 1322 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1323 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1324 | int status = 0; |
| 1325 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1326 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1327 | return -EPERM; |
| 1328 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1329 | if (vf >= adapter->num_vfs || vlan > 4095 || qos > 7) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1330 | return -EINVAL; |
| 1331 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1332 | if (vlan || qos) { |
| 1333 | vlan |= qos << VLAN_PRIO_SHIFT; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1334 | if (vf_cfg->vlan_tag != vlan) |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1335 | status = be_cmd_set_hsw_config(adapter, vlan, vf + 1, |
| 1336 | vf_cfg->if_handle, 0); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1337 | } else { |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 1338 | /* Reset Transparent Vlan Tagging. */ |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1339 | status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID, |
| 1340 | vf + 1, vf_cfg->if_handle, 0); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1343 | if (!status) |
| 1344 | vf_cfg->vlan_tag = vlan; |
| 1345 | else |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1346 | dev_info(&adapter->pdev->dev, |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1347 | "VLAN %d config on VF %d failed\n", vlan, vf); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1348 | return status; |
| 1349 | } |
| 1350 | |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1351 | static int be_set_vf_tx_rate(struct net_device *netdev, |
| 1352 | int vf, int rate) |
| 1353 | { |
| 1354 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1355 | int status = 0; |
| 1356 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1357 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1358 | return -EPERM; |
| 1359 | |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1360 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1361 | return -EINVAL; |
| 1362 | |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1363 | if (rate < 100 || rate > 10000) { |
| 1364 | dev_err(&adapter->pdev->dev, |
| 1365 | "tx rate must be between 100 and 10000 Mbps\n"); |
| 1366 | return -EINVAL; |
| 1367 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1368 | |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 1369 | status = be_cmd_config_qos(adapter, rate / 10, vf + 1); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1370 | if (status) |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1371 | dev_err(&adapter->pdev->dev, |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1372 | "tx rate %d on VF %d failed\n", rate, vf); |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1373 | else |
| 1374 | adapter->vf_cfg[vf].tx_rate = rate; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1375 | return status; |
| 1376 | } |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1377 | static int be_set_vf_link_state(struct net_device *netdev, int vf, |
| 1378 | int link_state) |
| 1379 | { |
| 1380 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1381 | int status; |
| 1382 | |
| 1383 | if (!sriov_enabled(adapter)) |
| 1384 | return -EPERM; |
| 1385 | |
| 1386 | if (vf >= adapter->num_vfs) |
| 1387 | return -EINVAL; |
| 1388 | |
| 1389 | status = be_cmd_set_logical_link_config(adapter, link_state, vf+1); |
| 1390 | if (!status) |
| 1391 | adapter->vf_cfg[vf].plink_tracking = link_state; |
| 1392 | |
| 1393 | return status; |
| 1394 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1395 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1396 | static void be_aic_update(struct be_aic_obj *aic, u64 rx_pkts, u64 tx_pkts, |
| 1397 | ulong now) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1398 | { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1399 | aic->rx_pkts_prev = rx_pkts; |
| 1400 | aic->tx_reqs_prev = tx_pkts; |
| 1401 | aic->jiffies = now; |
| 1402 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1403 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1404 | static void be_eqd_update(struct be_adapter *adapter) |
| 1405 | { |
| 1406 | struct be_set_eqd set_eqd[MAX_EVT_QS]; |
| 1407 | int eqd, i, num = 0, start; |
| 1408 | struct be_aic_obj *aic; |
| 1409 | struct be_eq_obj *eqo; |
| 1410 | struct be_rx_obj *rxo; |
| 1411 | struct be_tx_obj *txo; |
| 1412 | u64 rx_pkts, tx_pkts; |
| 1413 | ulong now; |
| 1414 | u32 pps, delta; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1415 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1416 | for_all_evt_queues(adapter, eqo, i) { |
| 1417 | aic = &adapter->aic_obj[eqo->idx]; |
| 1418 | if (!aic->enable) { |
| 1419 | if (aic->jiffies) |
| 1420 | aic->jiffies = 0; |
| 1421 | eqd = aic->et_eqd; |
| 1422 | goto modify_eqd; |
| 1423 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1424 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1425 | rxo = &adapter->rx_obj[eqo->idx]; |
| 1426 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1427 | start = u64_stats_fetch_begin_irq(&rxo->stats.sync); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1428 | rx_pkts = rxo->stats.rx_pkts; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1429 | } while (u64_stats_fetch_retry_irq(&rxo->stats.sync, start)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1430 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1431 | txo = &adapter->tx_obj[eqo->idx]; |
| 1432 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1433 | start = u64_stats_fetch_begin_irq(&txo->stats.sync); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1434 | tx_pkts = txo->stats.tx_reqs; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1435 | } while (u64_stats_fetch_retry_irq(&txo->stats.sync, start)); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1436 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1437 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1438 | /* Skip, if wrapped around or first calculation */ |
| 1439 | now = jiffies; |
| 1440 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
| 1441 | rx_pkts < aic->rx_pkts_prev || |
| 1442 | tx_pkts < aic->tx_reqs_prev) { |
| 1443 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 1444 | continue; |
| 1445 | } |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1446 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1447 | delta = jiffies_to_msecs(now - aic->jiffies); |
| 1448 | pps = (((u32)(rx_pkts - aic->rx_pkts_prev) * 1000) / delta) + |
| 1449 | (((u32)(tx_pkts - aic->tx_reqs_prev) * 1000) / delta); |
| 1450 | eqd = (pps / 15000) << 2; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1451 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1452 | if (eqd < 8) |
| 1453 | eqd = 0; |
| 1454 | eqd = min_t(u32, eqd, aic->max_eqd); |
| 1455 | eqd = max_t(u32, eqd, aic->min_eqd); |
| 1456 | |
| 1457 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1458 | modify_eqd: |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1459 | if (eqd != aic->prev_eqd) { |
| 1460 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 1461 | set_eqd[num].eq_id = eqo->q.id; |
| 1462 | aic->prev_eqd = eqd; |
| 1463 | num++; |
| 1464 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1465 | } |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1466 | |
| 1467 | if (num) |
| 1468 | be_cmd_modify_eqd(adapter, set_eqd, num); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1471 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1472 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1473 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1474 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1475 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1476 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1477 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1478 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1479 | stats->rx_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1480 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1481 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1482 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1483 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1484 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1487 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1488 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 1489 | /* L4 checksum is not reliable for non TCP/UDP packets. |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1490 | * Also ignore ipcksm for ipv6 pkts |
| 1491 | */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1492 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1493 | (rxcp->ip_csum || rxcp->ipv6) && !rxcp->err; |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1496 | static struct be_rx_page_info *get_rx_page_info(struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1497 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1498 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1499 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1500 | struct be_queue_info *rxq = &rxo->q; |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1501 | u16 frag_idx = rxq->tail; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1502 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1503 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1504 | BUG_ON(!rx_page_info->page); |
| 1505 | |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1506 | if (rx_page_info->last_frag) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1507 | dma_unmap_page(&adapter->pdev->dev, |
| 1508 | dma_unmap_addr(rx_page_info, bus), |
| 1509 | adapter->big_page_size, DMA_FROM_DEVICE); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1510 | rx_page_info->last_frag = false; |
| 1511 | } else { |
| 1512 | dma_sync_single_for_cpu(&adapter->pdev->dev, |
| 1513 | dma_unmap_addr(rx_page_info, bus), |
| 1514 | rx_frag_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1515 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1516 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1517 | queue_tail_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1518 | atomic_dec(&rxq->used); |
| 1519 | return rx_page_info; |
| 1520 | } |
| 1521 | |
| 1522 | /* Throwaway the data in the Rx completion */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1523 | static void be_rx_compl_discard(struct be_rx_obj *rxo, |
| 1524 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1525 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1526 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1527 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1528 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1529 | for (i = 0; i < num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1530 | page_info = get_rx_page_info(rxo); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1531 | put_page(page_info->page); |
| 1532 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 1538 | * indicated by rxcp. |
| 1539 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1540 | static void skb_fill_rx_data(struct be_rx_obj *rxo, struct sk_buff *skb, |
| 1541 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1542 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1543 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1544 | u16 i, j; |
| 1545 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1546 | u8 *start; |
| 1547 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1548 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1549 | start = page_address(page_info->page) + page_info->page_offset; |
| 1550 | prefetch(start); |
| 1551 | |
| 1552 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1553 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1554 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1555 | skb->len = curr_frag_len; |
| 1556 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1557 | memcpy(skb->data, start, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1558 | /* Complete packet has now been moved to data */ |
| 1559 | put_page(page_info->page); |
| 1560 | skb->data_len = 0; |
| 1561 | skb->tail += curr_frag_len; |
| 1562 | } else { |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1563 | hdr_len = ETH_HLEN; |
| 1564 | memcpy(skb->data, start, hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1565 | skb_shinfo(skb)->nr_frags = 1; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1566 | skb_frag_set_page(skb, 0, page_info->page); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1567 | skb_shinfo(skb)->frags[0].page_offset = |
| 1568 | page_info->page_offset + hdr_len; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1569 | 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] | 1570 | skb->data_len = curr_frag_len - hdr_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1571 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1572 | skb->tail += hdr_len; |
| 1573 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1574 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1575 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1576 | if (rxcp->pkt_size <= rx_frag_size) { |
| 1577 | BUG_ON(rxcp->num_rcvd != 1); |
| 1578 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1582 | remaining = rxcp->pkt_size - curr_frag_len; |
| 1583 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1584 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1585 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1586 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1587 | /* Coalesce all frags from the same physical page in one slot */ |
| 1588 | if (page_info->page_offset == 0) { |
| 1589 | /* Fresh page */ |
| 1590 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1591 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1592 | skb_shinfo(skb)->frags[j].page_offset = |
| 1593 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1594 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1595 | skb_shinfo(skb)->nr_frags++; |
| 1596 | } else { |
| 1597 | put_page(page_info->page); |
| 1598 | } |
| 1599 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1600 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1601 | skb->len += curr_frag_len; |
| 1602 | skb->data_len += curr_frag_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1603 | skb->truesize += rx_frag_size; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1604 | remaining -= curr_frag_len; |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1605 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1606 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1607 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1610 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1611 | static void be_rx_compl_process(struct be_rx_obj *rxo, struct napi_struct *napi, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1612 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1613 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1614 | struct be_adapter *adapter = rxo->adapter; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1615 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1616 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1617 | |
Eric Dumazet | bb349bb | 2012-01-25 03:56:30 +0000 | [diff] [blame] | 1618 | skb = netdev_alloc_skb_ip_align(netdev, BE_RX_SKB_ALLOC_SIZE); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 1619 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1620 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1621 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1622 | return; |
| 1623 | } |
| 1624 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1625 | skb_fill_rx_data(rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1626 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1627 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1628 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 1629 | else |
| 1630 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1631 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1632 | skb->protocol = eth_type_trans(skb, netdev); |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 1633 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1634 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 1635 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1636 | |
| 1637 | skb->encapsulation = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1638 | skb_mark_napi_id(skb, napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1639 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1640 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1641 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1642 | |
| 1643 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1646 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1647 | static void be_rx_compl_process_gro(struct be_rx_obj *rxo, |
| 1648 | struct napi_struct *napi, |
| 1649 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1650 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1651 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1652 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1653 | struct sk_buff *skb = NULL; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1654 | u16 remaining, curr_frag_len; |
| 1655 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 1656 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1657 | skb = napi_get_frags(napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1658 | if (!skb) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1659 | be_rx_compl_discard(rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1660 | return; |
| 1661 | } |
| 1662 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1663 | remaining = rxcp->pkt_size; |
| 1664 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1665 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1666 | |
| 1667 | curr_frag_len = min(remaining, rx_frag_size); |
| 1668 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1669 | /* Coalesce all frags from the same physical page in one slot */ |
| 1670 | if (i == 0 || page_info->page_offset == 0) { |
| 1671 | /* First frag or Fresh page */ |
| 1672 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1673 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1674 | skb_shinfo(skb)->frags[j].page_offset = |
| 1675 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1676 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1677 | } else { |
| 1678 | put_page(page_info->page); |
| 1679 | } |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1680 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1681 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1682 | remaining -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1683 | memset(page_info, 0, sizeof(*page_info)); |
| 1684 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1685 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1686 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1687 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1688 | skb->len = rxcp->pkt_size; |
| 1689 | skb->data_len = rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1690 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 1691 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1692 | if (adapter->netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 1693 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1694 | |
| 1695 | skb->encapsulation = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1696 | skb_mark_napi_id(skb, napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1697 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1698 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1699 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1700 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1701 | napi_gro_frags(napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1704 | static void be_parse_rx_compl_v1(struct be_eth_rx_compl *compl, |
| 1705 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1706 | { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1707 | rxcp->pkt_size = |
| 1708 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, pktsize, compl); |
| 1709 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtp, compl); |
| 1710 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, err, compl); |
| 1711 | 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] | 1712 | 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] | 1713 | rxcp->ip_csum = |
| 1714 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ipcksm, compl); |
| 1715 | rxcp->l4_csum = |
| 1716 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, l4_cksm, compl); |
| 1717 | rxcp->ipv6 = |
| 1718 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ip_version, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1719 | rxcp->num_rcvd = |
| 1720 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, numfrags, compl); |
| 1721 | rxcp->pkt_type = |
| 1722 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1723 | rxcp->rss_hash = |
Sarveshwar Bandi | c297977 | 2012-07-25 21:29:50 +0000 | [diff] [blame] | 1724 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1725 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1726 | rxcp->qnq = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, qnq, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1727 | compl); |
| 1728 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vlan_tag, |
| 1729 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1730 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1731 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, port, compl); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1732 | rxcp->tunneled = |
| 1733 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, tunneled, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1734 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1735 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1736 | static void be_parse_rx_compl_v0(struct be_eth_rx_compl *compl, |
| 1737 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1738 | { |
| 1739 | rxcp->pkt_size = |
| 1740 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, pktsize, compl); |
| 1741 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtp, compl); |
| 1742 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, err, compl); |
| 1743 | 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] | 1744 | 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] | 1745 | rxcp->ip_csum = |
| 1746 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ipcksm, compl); |
| 1747 | rxcp->l4_csum = |
| 1748 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, l4_cksm, compl); |
| 1749 | rxcp->ipv6 = |
| 1750 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ip_version, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1751 | rxcp->num_rcvd = |
| 1752 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, numfrags, compl); |
| 1753 | rxcp->pkt_type = |
| 1754 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1755 | rxcp->rss_hash = |
Sarveshwar Bandi | c297977 | 2012-07-25 21:29:50 +0000 | [diff] [blame] | 1756 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1757 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1758 | rxcp->qnq = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, qnq, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1759 | compl); |
| 1760 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vlan_tag, |
| 1761 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1762 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1763 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, port, compl); |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 1764 | rxcp->ip_frag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, |
| 1765 | ip_frag, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 1769 | { |
| 1770 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 1771 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 1772 | struct be_adapter *adapter = rxo->adapter; |
| 1773 | |
| 1774 | /* For checking the valid bit it is Ok to use either definition as the |
| 1775 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 1776 | 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] | 1777 | return NULL; |
| 1778 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1779 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1780 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 1781 | |
| 1782 | if (adapter->be3_native) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1783 | be_parse_rx_compl_v1(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1784 | else |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1785 | be_parse_rx_compl_v0(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1786 | |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 1787 | if (rxcp->ip_frag) |
| 1788 | rxcp->l4_csum = 0; |
| 1789 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1790 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1791 | /* In QNQ modes, if qnq bit is not set, then the packet was |
| 1792 | * tagged only with the transparent outer vlan-tag and must |
| 1793 | * not be treated as a vlan packet by host |
| 1794 | */ |
| 1795 | if (be_is_qnq_mode(adapter) && !rxcp->qnq) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1796 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1797 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1798 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1799 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1800 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 1801 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1802 | !adapter->vlan_tag[rxcp->vlan_tag]) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1803 | rxcp->vlanf = 0; |
| 1804 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1805 | |
| 1806 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 1807 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1808 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1809 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1810 | return rxcp; |
| 1811 | } |
| 1812 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1813 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1814 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1815 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1816 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1817 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1818 | gfp |= __GFP_COMP; |
| 1819 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | /* |
| 1823 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 1824 | * receive buffers to BE |
| 1825 | */ |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1826 | 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] | 1827 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1828 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1829 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1830 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1831 | struct page *pagep = NULL; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1832 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1833 | struct be_eth_rx_d *rxd; |
| 1834 | u64 page_dmaaddr = 0, frag_dmaaddr; |
| 1835 | u32 posted, page_offset = 0; |
| 1836 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1837 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1838 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { |
| 1839 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1840 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1841 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1842 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1843 | break; |
| 1844 | } |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1845 | page_dmaaddr = dma_map_page(dev, pagep, 0, |
| 1846 | adapter->big_page_size, |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1847 | DMA_FROM_DEVICE); |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1848 | if (dma_mapping_error(dev, page_dmaaddr)) { |
| 1849 | put_page(pagep); |
| 1850 | pagep = NULL; |
| 1851 | rx_stats(rxo)->rx_post_fail++; |
| 1852 | break; |
| 1853 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1854 | page_offset = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1855 | } else { |
| 1856 | get_page(pagep); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1857 | page_offset += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1858 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1859 | page_info->page_offset = page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1860 | page_info->page = pagep; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1861 | |
| 1862 | rxd = queue_head_node(rxq); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1863 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1864 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 1865 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1866 | |
| 1867 | /* Any space left in the current big page for another frag? */ |
| 1868 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 1869 | adapter->big_page_size) { |
| 1870 | pagep = NULL; |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1871 | page_info->last_frag = true; |
| 1872 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
| 1873 | } else { |
| 1874 | dma_unmap_addr_set(page_info, bus, frag_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1875 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1876 | |
| 1877 | prev_page_info = page_info; |
| 1878 | queue_head_inc(rxq); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1879 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1880 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1881 | |
| 1882 | /* Mark the last frag of a page when we break out of the above loop |
| 1883 | * with no more slots available in the RXQ |
| 1884 | */ |
| 1885 | if (pagep) { |
| 1886 | prev_page_info->last_frag = true; |
| 1887 | dma_unmap_addr_set(prev_page_info, bus, page_dmaaddr); |
| 1888 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1889 | |
| 1890 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1891 | atomic_add(posted, &rxq->used); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1892 | if (rxo->rx_post_starved) |
| 1893 | rxo->rx_post_starved = false; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1894 | be_rxq_notify(adapter, rxq->id, posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1895 | } else if (atomic_read(&rxq->used) == 0) { |
| 1896 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1897 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1898 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1901 | 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] | 1902 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1903 | struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq); |
| 1904 | |
| 1905 | if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
| 1906 | return NULL; |
| 1907 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1908 | rmb(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1909 | be_dws_le_to_cpu(txcp, sizeof(*txcp)); |
| 1910 | |
| 1911 | txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
| 1912 | |
| 1913 | queue_tail_inc(tx_cq); |
| 1914 | return txcp; |
| 1915 | } |
| 1916 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1917 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
| 1918 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1919 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1920 | struct be_queue_info *txq = &txo->q; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1921 | struct be_eth_wrb *wrb; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1922 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1923 | struct sk_buff *sent_skb; |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1924 | u16 cur_index, num_wrbs = 1; /* account for hdr wrb */ |
| 1925 | bool unmap_skb_hdr = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1926 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1927 | sent_skb = sent_skbs[txq->tail]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1928 | BUG_ON(!sent_skb); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1929 | sent_skbs[txq->tail] = NULL; |
| 1930 | |
| 1931 | /* skip header wrb */ |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1932 | queue_tail_inc(txq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1933 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1934 | do { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1935 | cur_index = txq->tail; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1936 | wrb = queue_tail_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1937 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
| 1938 | (unmap_skb_hdr && skb_headlen(sent_skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1939 | unmap_skb_hdr = false; |
| 1940 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1941 | num_wrbs++; |
| 1942 | queue_tail_inc(txq); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1943 | } while (cur_index != last_index); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1944 | |
Eric W. Biederman | d8ec2c0 | 2014-03-11 14:19:50 -0700 | [diff] [blame] | 1945 | dev_kfree_skb_any(sent_skb); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1946 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1949 | /* Return the number of events in the event queue */ |
| 1950 | static inline int events_get(struct be_eq_obj *eqo) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1951 | { |
| 1952 | struct be_eq_entry *eqe; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1953 | int num = 0; |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1954 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1955 | do { |
| 1956 | eqe = queue_tail_node(&eqo->q); |
| 1957 | if (eqe->evt == 0) |
| 1958 | break; |
| 1959 | |
| 1960 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1961 | eqe->evt = 0; |
| 1962 | num++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1963 | queue_tail_inc(&eqo->q); |
| 1964 | } while (true); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1965 | |
| 1966 | return num; |
| 1967 | } |
| 1968 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1969 | /* Leaves the EQ is disarmed state */ |
| 1970 | static void be_eq_clean(struct be_eq_obj *eqo) |
| 1971 | { |
| 1972 | int num = events_get(eqo); |
| 1973 | |
| 1974 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, num); |
| 1975 | } |
| 1976 | |
| 1977 | static void be_rx_cq_clean(struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1978 | { |
| 1979 | struct be_rx_page_info *page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1980 | struct be_queue_info *rxq = &rxo->q; |
| 1981 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1982 | struct be_rx_compl_info *rxcp; |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 1983 | struct be_adapter *adapter = rxo->adapter; |
| 1984 | int flush_wait = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1985 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 1986 | /* Consume pending rx completions. |
| 1987 | * Wait for the flush completion (identified by zero num_rcvd) |
| 1988 | * to arrive. Notify CQ even when there are no more CQ entries |
| 1989 | * for HW to flush partially coalesced CQ entries. |
| 1990 | * In Lancer, there is no need to wait for flush compl. |
| 1991 | */ |
| 1992 | for (;;) { |
| 1993 | rxcp = be_rx_compl_get(rxo); |
| 1994 | if (rxcp == NULL) { |
| 1995 | if (lancer_chip(adapter)) |
| 1996 | break; |
| 1997 | |
| 1998 | if (flush_wait++ > 10 || be_hw_error(adapter)) { |
| 1999 | dev_warn(&adapter->pdev->dev, |
| 2000 | "did not receive flush compl\n"); |
| 2001 | break; |
| 2002 | } |
| 2003 | be_cq_notify(adapter, rx_cq->id, true, 0); |
| 2004 | mdelay(1); |
| 2005 | } else { |
| 2006 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 3f5dffe | 2013-05-08 02:05:49 +0000 | [diff] [blame] | 2007 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2008 | if (rxcp->num_rcvd == 0) |
| 2009 | break; |
| 2010 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2013 | /* After cleanup, leave the CQ in unarmed state */ |
| 2014 | be_cq_notify(adapter, rx_cq->id, false, 0); |
| 2015 | |
| 2016 | /* Then free posted rx buffers that were not used */ |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2017 | while (atomic_read(&rxq->used) > 0) { |
| 2018 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2019 | put_page(page_info->page); |
| 2020 | memset(page_info, 0, sizeof(*page_info)); |
| 2021 | } |
| 2022 | BUG_ON(atomic_read(&rxq->used)); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2023 | rxq->tail = rxq->head = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2026 | static void be_tx_compl_clean(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2027 | { |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2028 | struct be_tx_obj *txo; |
| 2029 | struct be_queue_info *txq; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2030 | struct be_eth_tx_compl *txcp; |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 2031 | u16 end_idx, cmpl = 0, timeo = 0, num_wrbs = 0; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2032 | struct sk_buff *sent_skb; |
| 2033 | bool dummy_wrb; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2034 | int i, pending_txqs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2035 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2036 | /* Stop polling for compls when HW has been silent for 10ms */ |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2037 | do { |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2038 | pending_txqs = adapter->num_tx_qs; |
| 2039 | |
| 2040 | for_all_tx_queues(adapter, txo, i) { |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2041 | cmpl = 0; |
| 2042 | num_wrbs = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2043 | txq = &txo->q; |
| 2044 | while ((txcp = be_tx_compl_get(&txo->cq))) { |
| 2045 | end_idx = |
| 2046 | AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 2047 | wrb_index, txcp); |
| 2048 | num_wrbs += be_tx_compl_process(adapter, txo, |
| 2049 | end_idx); |
| 2050 | cmpl++; |
| 2051 | } |
| 2052 | if (cmpl) { |
| 2053 | be_cq_notify(adapter, txo->cq.id, false, cmpl); |
| 2054 | atomic_sub(num_wrbs, &txq->used); |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2055 | timeo = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2056 | } |
| 2057 | if (atomic_read(&txq->used) == 0) |
| 2058 | pending_txqs--; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2061 | if (pending_txqs == 0 || ++timeo > 10 || be_hw_error(adapter)) |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2062 | break; |
| 2063 | |
| 2064 | mdelay(1); |
| 2065 | } while (true); |
| 2066 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2067 | for_all_tx_queues(adapter, txo, i) { |
| 2068 | txq = &txo->q; |
| 2069 | if (atomic_read(&txq->used)) |
| 2070 | dev_err(&adapter->pdev->dev, "%d pending tx-compls\n", |
| 2071 | atomic_read(&txq->used)); |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2072 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2073 | /* free posted tx for which compls will never arrive */ |
| 2074 | while (atomic_read(&txq->used)) { |
| 2075 | sent_skb = txo->sent_skb_list[txq->tail]; |
| 2076 | end_idx = txq->tail; |
| 2077 | num_wrbs = wrb_cnt_for_skb(adapter, sent_skb, |
| 2078 | &dummy_wrb); |
| 2079 | index_adv(&end_idx, num_wrbs - 1, txq->len); |
| 2080 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
| 2081 | atomic_sub(num_wrbs, &txq->used); |
| 2082 | } |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2083 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2086 | static void be_evt_queues_destroy(struct be_adapter *adapter) |
| 2087 | { |
| 2088 | struct be_eq_obj *eqo; |
| 2089 | int i; |
| 2090 | |
| 2091 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2092 | if (eqo->q.created) { |
| 2093 | be_eq_clean(eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2094 | be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2095 | napi_hash_del(&eqo->napi); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2096 | netif_napi_del(&eqo->napi); |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2097 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2098 | be_queue_free(adapter, &eqo->q); |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | static int be_evt_queues_create(struct be_adapter *adapter) |
| 2103 | { |
| 2104 | struct be_queue_info *eq; |
| 2105 | struct be_eq_obj *eqo; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2106 | struct be_aic_obj *aic; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2107 | int i, rc; |
| 2108 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2109 | adapter->num_evt_qs = min_t(u16, num_irqs(adapter), |
| 2110 | adapter->cfg_num_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2111 | |
| 2112 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2113 | netif_napi_add(adapter->netdev, &eqo->napi, be_poll, |
| 2114 | BE_NAPI_WEIGHT); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2115 | napi_hash_add(&eqo->napi); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2116 | aic = &adapter->aic_obj[i]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2117 | eqo->adapter = adapter; |
| 2118 | eqo->tx_budget = BE_TX_BUDGET; |
| 2119 | eqo->idx = i; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2120 | aic->max_eqd = BE_MAX_EQD; |
| 2121 | aic->enable = true; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2122 | |
| 2123 | eq = &eqo->q; |
| 2124 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 2125 | sizeof(struct be_eq_entry)); |
| 2126 | if (rc) |
| 2127 | return rc; |
| 2128 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2129 | rc = be_cmd_eq_create(adapter, eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2130 | if (rc) |
| 2131 | return rc; |
| 2132 | } |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 2133 | return 0; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2136 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 2137 | { |
| 2138 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2139 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2140 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2141 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2142 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2143 | be_queue_free(adapter, q); |
| 2144 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2145 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2146 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2147 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2148 | be_queue_free(adapter, q); |
| 2149 | } |
| 2150 | |
| 2151 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 2152 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 2153 | { |
| 2154 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2155 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2156 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2157 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 2158 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2159 | goto err; |
| 2160 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2161 | /* Use the default EQ for MCC completions */ |
| 2162 | 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] | 2163 | goto mcc_cq_free; |
| 2164 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2165 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2166 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 2167 | goto mcc_cq_destroy; |
| 2168 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2169 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2170 | goto mcc_q_free; |
| 2171 | |
| 2172 | return 0; |
| 2173 | |
| 2174 | mcc_q_free: |
| 2175 | be_queue_free(adapter, q); |
| 2176 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2177 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2178 | mcc_cq_free: |
| 2179 | be_queue_free(adapter, cq); |
| 2180 | err: |
| 2181 | return -1; |
| 2182 | } |
| 2183 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2184 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 2185 | { |
| 2186 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2187 | struct be_tx_obj *txo; |
| 2188 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2189 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2190 | for_all_tx_queues(adapter, txo, i) { |
| 2191 | q = &txo->q; |
| 2192 | if (q->created) |
| 2193 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 2194 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2195 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2196 | q = &txo->cq; |
| 2197 | if (q->created) |
| 2198 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2199 | be_queue_free(adapter, q); |
| 2200 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 2203 | static int be_tx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2204 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2205 | struct be_queue_info *cq, *eq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2206 | struct be_tx_obj *txo; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2207 | int status, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2208 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2209 | adapter->num_tx_qs = min(adapter->num_evt_qs, be_max_txqs(adapter)); |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 2210 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2211 | for_all_tx_queues(adapter, txo, i) { |
| 2212 | cq = &txo->cq; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2213 | status = be_queue_alloc(adapter, cq, TX_CQ_LEN, |
| 2214 | sizeof(struct be_eth_tx_compl)); |
| 2215 | if (status) |
| 2216 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2217 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2218 | u64_stats_init(&txo->stats.sync); |
| 2219 | u64_stats_init(&txo->stats.sync_compl); |
| 2220 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2221 | /* If num_evt_qs is less than num_tx_qs, then more than |
| 2222 | * one txq share an eq |
| 2223 | */ |
| 2224 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 2225 | status = be_cmd_cq_create(adapter, cq, eq, false, 3); |
| 2226 | if (status) |
| 2227 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2228 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2229 | status = be_queue_alloc(adapter, &txo->q, TX_Q_LEN, |
| 2230 | sizeof(struct be_eth_wrb)); |
| 2231 | if (status) |
| 2232 | return status; |
| 2233 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 2234 | status = be_cmd_txq_create(adapter, txo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2235 | if (status) |
| 2236 | return status; |
| 2237 | } |
| 2238 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2239 | dev_info(&adapter->pdev->dev, "created %d TX queue(s)\n", |
| 2240 | adapter->num_tx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | static void be_rx_cqs_destroy(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2245 | { |
| 2246 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2247 | struct be_rx_obj *rxo; |
| 2248 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2249 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2250 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2251 | q = &rxo->cq; |
| 2252 | if (q->created) |
| 2253 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2254 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2255 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2258 | static int be_rx_cqs_create(struct be_adapter *adapter) |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2259 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2260 | struct be_queue_info *eq, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2261 | struct be_rx_obj *rxo; |
| 2262 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2263 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2264 | /* We can create as many RSS rings as there are EQs. */ |
| 2265 | adapter->num_rx_qs = adapter->num_evt_qs; |
| 2266 | |
| 2267 | /* We'll use RSS only if atleast 2 RSS rings are supported. |
| 2268 | * When RSS is used, we'll need a default RXQ for non-IP traffic. |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2269 | */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2270 | if (adapter->num_rx_qs > 1) |
| 2271 | adapter->num_rx_qs++; |
| 2272 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2273 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2274 | for_all_rx_queues(adapter, rxo, i) { |
| 2275 | rxo->adapter = adapter; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2276 | cq = &rxo->cq; |
| 2277 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
| 2278 | sizeof(struct be_eth_rx_compl)); |
| 2279 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2280 | return rc; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2281 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2282 | u64_stats_init(&rxo->stats.sync); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2283 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 2284 | rc = be_cmd_cq_create(adapter, cq, eq, false, 3); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2285 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2286 | return rc; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2287 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2288 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2289 | dev_info(&adapter->pdev->dev, |
| 2290 | "created %d RSS queue(s) and 1 default RX queue\n", |
| 2291 | adapter->num_rx_qs - 1); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2292 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2295 | static irqreturn_t be_intx(int irq, void *dev) |
| 2296 | { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2297 | struct be_eq_obj *eqo = dev; |
| 2298 | struct be_adapter *adapter = eqo->adapter; |
| 2299 | int num_evts = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2300 | |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2301 | /* IRQ is not expected when NAPI is scheduled as the EQ |
| 2302 | * will not be armed. |
| 2303 | * But, this can happen on Lancer INTx where it takes |
| 2304 | * a while to de-assert INTx or in BE2 where occasionaly |
| 2305 | * an interrupt may be raised even when EQ is unarmed. |
| 2306 | * If NAPI is already scheduled, then counting & notifying |
| 2307 | * events will orphan them. |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2308 | */ |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2309 | if (napi_schedule_prep(&eqo->napi)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2310 | num_evts = events_get(eqo); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2311 | __napi_schedule(&eqo->napi); |
| 2312 | if (num_evts) |
| 2313 | eqo->spurious_intr = 0; |
| 2314 | } |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2315 | be_eq_notify(adapter, eqo->q.id, false, true, num_evts); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2316 | |
| 2317 | /* Return IRQ_HANDLED only for the the first spurious intr |
| 2318 | * after a valid intr to stop the kernel from branding |
| 2319 | * this irq as a bad one! |
| 2320 | */ |
| 2321 | if (num_evts || eqo->spurious_intr++ == 0) |
| 2322 | return IRQ_HANDLED; |
| 2323 | else |
| 2324 | return IRQ_NONE; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2327 | static irqreturn_t be_msix(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2328 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2329 | struct be_eq_obj *eqo = dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2330 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2331 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0); |
| 2332 | napi_schedule(&eqo->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2333 | return IRQ_HANDLED; |
| 2334 | } |
| 2335 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2336 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2337 | { |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 2338 | return (rxcp->tcpf && !rxcp->err && rxcp->l4_csum) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2341 | static int be_process_rx(struct be_rx_obj *rxo, struct napi_struct *napi, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2342 | int budget, int polling) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2343 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2344 | struct be_adapter *adapter = rxo->adapter; |
| 2345 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2346 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2347 | u32 work_done; |
| 2348 | |
| 2349 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2350 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2351 | if (!rxcp) |
| 2352 | break; |
| 2353 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2354 | /* Is it a flush compl that has no data */ |
| 2355 | if (unlikely(rxcp->num_rcvd == 0)) |
| 2356 | goto loop_continue; |
| 2357 | |
| 2358 | /* Discard compl with partial DMA Lancer B0 */ |
| 2359 | if (unlikely(!rxcp->pkt_size)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2360 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2361 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 2362 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 2363 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2364 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 2365 | * promiscuous mode on some skews |
| 2366 | */ |
| 2367 | if (unlikely(rxcp->port != adapter->port_num && |
| 2368 | !lancer_chip(adapter))) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2369 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2370 | goto loop_continue; |
| 2371 | } |
| 2372 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2373 | /* Don't do gro when we're busy_polling */ |
| 2374 | if (do_gro(rxcp) && polling != BUSY_POLLING) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2375 | be_rx_compl_process_gro(rxo, napi, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2376 | else |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2377 | be_rx_compl_process(rxo, napi, rxcp); |
| 2378 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2379 | loop_continue: |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2380 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2383 | if (work_done) { |
| 2384 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 2385 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2386 | /* When an rx-obj gets into post_starved state, just |
| 2387 | * let be_worker do the posting. |
| 2388 | */ |
| 2389 | if (atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM && |
| 2390 | !rxo->rx_post_starved) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2391 | be_post_rx_frags(rxo, GFP_ATOMIC); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2392 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2393 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2394 | return work_done; |
| 2395 | } |
| 2396 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2397 | static bool be_process_tx(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 2398 | int budget, int idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2399 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2400 | struct be_eth_tx_compl *txcp; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2401 | int num_wrbs = 0, work_done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2402 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2403 | for (work_done = 0; work_done < budget; work_done++) { |
| 2404 | txcp = be_tx_compl_get(&txo->cq); |
| 2405 | if (!txcp) |
| 2406 | break; |
| 2407 | num_wrbs += be_tx_compl_process(adapter, txo, |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2408 | AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 2409 | wrb_index, txcp)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | if (work_done) { |
| 2413 | be_cq_notify(adapter, txo->cq.id, true, work_done); |
| 2414 | atomic_sub(num_wrbs, &txo->q.used); |
| 2415 | |
| 2416 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 2417 | * if it was stopped due to lack of tx wrbs. */ |
| 2418 | if (__netif_subqueue_stopped(adapter->netdev, idx) && |
| 2419 | atomic_read(&txo->q.used) < txo->q.len / 2) { |
| 2420 | netif_wake_subqueue(adapter->netdev, idx); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2421 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2422 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2423 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
| 2424 | tx_stats(txo)->tx_compl += work_done; |
| 2425 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
| 2426 | } |
| 2427 | return (work_done < budget); /* Done */ |
| 2428 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2429 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2430 | int be_poll(struct napi_struct *napi, int budget) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2431 | { |
| 2432 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2433 | struct be_adapter *adapter = eqo->adapter; |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2434 | int max_work = 0, work, i, num_evts; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2435 | struct be_rx_obj *rxo; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2436 | bool tx_done; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2437 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2438 | num_evts = events_get(eqo); |
| 2439 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2440 | /* Process all TXQs serviced by this EQ */ |
| 2441 | for (i = eqo->idx; i < adapter->num_tx_qs; i += adapter->num_evt_qs) { |
| 2442 | tx_done = be_process_tx(adapter, &adapter->tx_obj[i], |
| 2443 | eqo->tx_budget, i); |
| 2444 | if (!tx_done) |
| 2445 | max_work = budget; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2448 | if (be_lock_napi(eqo)) { |
| 2449 | /* This loop will iterate twice for EQ0 in which |
| 2450 | * completions of the last RXQ (default one) are also processed |
| 2451 | * For other EQs the loop iterates only once |
| 2452 | */ |
| 2453 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2454 | work = be_process_rx(rxo, napi, budget, NAPI_POLLING); |
| 2455 | max_work = max(work, max_work); |
| 2456 | } |
| 2457 | be_unlock_napi(eqo); |
| 2458 | } else { |
| 2459 | max_work = budget; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 2460 | } |
| 2461 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2462 | if (is_mcc_eqo(eqo)) |
| 2463 | be_process_mcc(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2464 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2465 | if (max_work < budget) { |
| 2466 | napi_complete(napi); |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2467 | be_eq_notify(adapter, eqo->q.id, true, false, num_evts); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2468 | } else { |
| 2469 | /* As we'll continue in polling mode, count and clear events */ |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2470 | be_eq_notify(adapter, eqo->q.id, false, false, num_evts); |
Padmanabh Ratnakar | 93c8670 | 2011-12-19 01:53:35 +0000 | [diff] [blame] | 2471 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2472 | return max_work; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2475 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2476 | static int be_busy_poll(struct napi_struct *napi) |
| 2477 | { |
| 2478 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2479 | struct be_adapter *adapter = eqo->adapter; |
| 2480 | struct be_rx_obj *rxo; |
| 2481 | int i, work = 0; |
| 2482 | |
| 2483 | if (!be_lock_busy_poll(eqo)) |
| 2484 | return LL_FLUSH_BUSY; |
| 2485 | |
| 2486 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2487 | work = be_process_rx(rxo, napi, 4, BUSY_POLLING); |
| 2488 | if (work) |
| 2489 | break; |
| 2490 | } |
| 2491 | |
| 2492 | be_unlock_busy_poll(eqo); |
| 2493 | return work; |
| 2494 | } |
| 2495 | #endif |
| 2496 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2497 | void be_detect_error(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2498 | { |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2499 | u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0; |
| 2500 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2501 | u32 i; |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2502 | bool error_detected = false; |
| 2503 | struct device *dev = &adapter->pdev->dev; |
| 2504 | struct net_device *netdev = adapter->netdev; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2505 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2506 | if (be_hw_error(adapter)) |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 2507 | return; |
| 2508 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2509 | if (lancer_chip(adapter)) { |
| 2510 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 2511 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
| 2512 | sliport_err1 = ioread32(adapter->db + |
| 2513 | SLIPORT_ERROR1_OFFSET); |
| 2514 | sliport_err2 = ioread32(adapter->db + |
| 2515 | SLIPORT_ERROR2_OFFSET); |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2516 | adapter->hw_error = true; |
| 2517 | /* Do not log error messages if its a FW reset */ |
| 2518 | if (sliport_err1 == SLIPORT_ERROR_FW_RESET1 && |
| 2519 | sliport_err2 == SLIPORT_ERROR_FW_RESET2) { |
| 2520 | dev_info(dev, "Firmware update in progress\n"); |
| 2521 | } else { |
| 2522 | error_detected = true; |
| 2523 | dev_err(dev, "Error detected in the card\n"); |
| 2524 | dev_err(dev, "ERR: sliport status 0x%x\n", |
| 2525 | sliport_status); |
| 2526 | dev_err(dev, "ERR: sliport error1 0x%x\n", |
| 2527 | sliport_err1); |
| 2528 | dev_err(dev, "ERR: sliport error2 0x%x\n", |
| 2529 | sliport_err2); |
| 2530 | } |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2531 | } |
| 2532 | } else { |
| 2533 | pci_read_config_dword(adapter->pdev, |
| 2534 | PCICFG_UE_STATUS_LOW, &ue_lo); |
| 2535 | pci_read_config_dword(adapter->pdev, |
| 2536 | PCICFG_UE_STATUS_HIGH, &ue_hi); |
| 2537 | pci_read_config_dword(adapter->pdev, |
| 2538 | PCICFG_UE_STATUS_LOW_MASK, &ue_lo_mask); |
| 2539 | pci_read_config_dword(adapter->pdev, |
| 2540 | PCICFG_UE_STATUS_HI_MASK, &ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2541 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2542 | ue_lo = (ue_lo & ~ue_lo_mask); |
| 2543 | ue_hi = (ue_hi & ~ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2544 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2545 | /* On certain platforms BE hardware can indicate spurious UEs. |
| 2546 | * Allow HW to stop working completely in case of a real UE. |
| 2547 | * Hence not setting the hw_error for UE detection. |
| 2548 | */ |
| 2549 | |
| 2550 | if (ue_lo || ue_hi) { |
| 2551 | error_detected = true; |
| 2552 | dev_err(dev, |
| 2553 | "Unrecoverable Error detected in the adapter"); |
| 2554 | dev_err(dev, "Please reboot server to recover"); |
| 2555 | if (skyhawk_chip(adapter)) |
| 2556 | adapter->hw_error = true; |
| 2557 | for (i = 0; ue_lo; ue_lo >>= 1, i++) { |
| 2558 | if (ue_lo & 1) |
| 2559 | dev_err(dev, "UE: %s bit set\n", |
| 2560 | ue_status_low_desc[i]); |
| 2561 | } |
| 2562 | for (i = 0; ue_hi; ue_hi >>= 1, i++) { |
| 2563 | if (ue_hi & 1) |
| 2564 | dev_err(dev, "UE: %s bit set\n", |
| 2565 | ue_status_hi_desc[i]); |
| 2566 | } |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 2567 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2568 | } |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2569 | if (error_detected) |
| 2570 | netif_carrier_off(netdev); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2573 | static void be_msix_disable(struct be_adapter *adapter) |
| 2574 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2575 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2576 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2577 | adapter->num_msix_vec = 0; |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2578 | adapter->num_msix_roce_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 2582 | static int be_msix_enable(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2583 | { |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2584 | int i, num_vec; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2585 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2586 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2587 | /* If RoCE is supported, program the max number of NIC vectors that |
| 2588 | * may be configured via set-channels, along with vectors needed for |
| 2589 | * RoCe. Else, just program the number we'll use initially. |
| 2590 | */ |
| 2591 | if (be_roce_supported(adapter)) |
| 2592 | num_vec = min_t(int, 2 * be_max_eqs(adapter), |
| 2593 | 2 * num_online_cpus()); |
| 2594 | else |
| 2595 | num_vec = adapter->cfg_num_qs; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2596 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2597 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2598 | adapter->msix_entries[i].entry = i; |
| 2599 | |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2600 | num_vec = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 2601 | MIN_MSIX_VECTORS, num_vec); |
| 2602 | if (num_vec < 0) |
| 2603 | goto fail; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2604 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2605 | if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) { |
| 2606 | adapter->num_msix_roce_vec = num_vec / 2; |
| 2607 | dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n", |
| 2608 | adapter->num_msix_roce_vec); |
| 2609 | } |
| 2610 | |
| 2611 | adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec; |
| 2612 | |
| 2613 | dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n", |
| 2614 | adapter->num_msix_vec); |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 2615 | return 0; |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2616 | |
| 2617 | fail: |
| 2618 | dev_warn(dev, "MSIx enable failed\n"); |
| 2619 | |
| 2620 | /* INTx is not supported in VFs, so fail probe if enable_msix fails */ |
| 2621 | if (!be_physfn(adapter)) |
| 2622 | return num_vec; |
| 2623 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2626 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2627 | struct be_eq_obj *eqo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2628 | { |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2629 | return adapter->msix_entries[eqo->msix_idx].vector; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | static int be_msix_register(struct be_adapter *adapter) |
| 2633 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2634 | struct net_device *netdev = adapter->netdev; |
| 2635 | struct be_eq_obj *eqo; |
| 2636 | int status, i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2637 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2638 | for_all_evt_queues(adapter, eqo, i) { |
| 2639 | sprintf(eqo->desc, "%s-q%d", netdev->name, i); |
| 2640 | vec = be_msix_vec_get(adapter, eqo); |
| 2641 | status = request_irq(vec, be_msix, 0, eqo->desc, eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2642 | if (status) |
| 2643 | goto err_msix; |
| 2644 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2645 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2646 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2647 | err_msix: |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2648 | for (i--, eqo = &adapter->eq_obj[i]; i >= 0; i--, eqo--) |
| 2649 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
| 2650 | dev_warn(&adapter->pdev->dev, "MSIX Request IRQ failed - err %d\n", |
| 2651 | status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2652 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2653 | return status; |
| 2654 | } |
| 2655 | |
| 2656 | static int be_irq_register(struct be_adapter *adapter) |
| 2657 | { |
| 2658 | struct net_device *netdev = adapter->netdev; |
| 2659 | int status; |
| 2660 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2661 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2662 | status = be_msix_register(adapter); |
| 2663 | if (status == 0) |
| 2664 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2665 | /* INTx is not supported for VF */ |
| 2666 | if (!be_physfn(adapter)) |
| 2667 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2670 | /* INTx: only the first EQ is used */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2671 | netdev->irq = adapter->pdev->irq; |
| 2672 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2673 | &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2674 | if (status) { |
| 2675 | dev_err(&adapter->pdev->dev, |
| 2676 | "INTx request IRQ failed - err %d\n", status); |
| 2677 | return status; |
| 2678 | } |
| 2679 | done: |
| 2680 | adapter->isr_registered = true; |
| 2681 | return 0; |
| 2682 | } |
| 2683 | |
| 2684 | static void be_irq_unregister(struct be_adapter *adapter) |
| 2685 | { |
| 2686 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2687 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2688 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2689 | |
| 2690 | if (!adapter->isr_registered) |
| 2691 | return; |
| 2692 | |
| 2693 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2694 | if (!msix_enabled(adapter)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2695 | free_irq(netdev->irq, &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2696 | goto done; |
| 2697 | } |
| 2698 | |
| 2699 | /* MSIx */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2700 | for_all_evt_queues(adapter, eqo, i) |
| 2701 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2702 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2703 | done: |
| 2704 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2707 | static void be_rx_qs_destroy(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2708 | { |
| 2709 | struct be_queue_info *q; |
| 2710 | struct be_rx_obj *rxo; |
| 2711 | int i; |
| 2712 | |
| 2713 | for_all_rx_queues(adapter, rxo, i) { |
| 2714 | q = &rxo->q; |
| 2715 | if (q->created) { |
| 2716 | be_cmd_rxq_destroy(adapter, q); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2717 | be_rx_cq_clean(rxo); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2718 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2719 | be_queue_free(adapter, q); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2723 | static int be_close(struct net_device *netdev) |
| 2724 | { |
| 2725 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2726 | struct be_eq_obj *eqo; |
| 2727 | int i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2728 | |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame^] | 2729 | /* This protection is needed as be_close() may be called even when the |
| 2730 | * adapter is in cleared state (after eeh perm failure) |
| 2731 | */ |
| 2732 | if (!(adapter->flags & BE_FLAGS_SETUP_DONE)) |
| 2733 | return 0; |
| 2734 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 2735 | be_roce_dev_close(adapter); |
| 2736 | |
Ivan Vecera | dff345c5 | 2013-11-27 08:59:32 +0100 | [diff] [blame] | 2737 | if (adapter->flags & BE_FLAGS_NAPI_ENABLED) { |
| 2738 | for_all_evt_queues(adapter, eqo, i) { |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 2739 | napi_disable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2740 | be_disable_busy_poll(eqo); |
| 2741 | } |
David S. Miller | 71237b6 | 2013-11-28 18:53:36 -0500 | [diff] [blame] | 2742 | adapter->flags &= ~BE_FLAGS_NAPI_ENABLED; |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 2743 | } |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2744 | |
| 2745 | be_async_mcc_disable(adapter); |
| 2746 | |
| 2747 | /* Wait for all pending tx completions to arrive so that |
| 2748 | * all tx skbs are freed. |
| 2749 | */ |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 2750 | netif_tx_disable(netdev); |
Sathya Perla | 6e1f997 | 2013-08-22 12:23:41 +0530 | [diff] [blame] | 2751 | be_tx_compl_clean(adapter); |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2752 | |
| 2753 | be_rx_qs_destroy(adapter); |
| 2754 | |
Ajit Khaparde | d11a347 | 2013-11-18 10:44:37 -0600 | [diff] [blame] | 2755 | for (i = 1; i < (adapter->uc_macs + 1); i++) |
| 2756 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 2757 | adapter->pmac_id[i], 0); |
| 2758 | adapter->uc_macs = 0; |
| 2759 | |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2760 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2761 | if (msix_enabled(adapter)) |
| 2762 | synchronize_irq(be_msix_vec_get(adapter, eqo)); |
| 2763 | else |
| 2764 | synchronize_irq(netdev->irq); |
| 2765 | be_eq_clean(eqo); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2768 | be_irq_unregister(adapter); |
| 2769 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2770 | return 0; |
| 2771 | } |
| 2772 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2773 | static int be_rx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2774 | { |
| 2775 | struct be_rx_obj *rxo; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 2776 | int rc, i, j; |
| 2777 | u8 rsstable[128]; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2778 | |
| 2779 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2780 | rc = be_queue_alloc(adapter, &rxo->q, RX_Q_LEN, |
| 2781 | sizeof(struct be_eth_rx_d)); |
| 2782 | if (rc) |
| 2783 | return rc; |
| 2784 | } |
| 2785 | |
| 2786 | /* The FW would like the default RXQ to be created first */ |
| 2787 | rxo = default_rxo(adapter); |
| 2788 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, rx_frag_size, |
| 2789 | adapter->if_handle, false, &rxo->rss_id); |
| 2790 | if (rc) |
| 2791 | return rc; |
| 2792 | |
| 2793 | for_all_rss_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2794 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2795 | rx_frag_size, adapter->if_handle, |
| 2796 | true, &rxo->rss_id); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2797 | if (rc) |
| 2798 | return rc; |
| 2799 | } |
| 2800 | |
| 2801 | if (be_multi_rxq(adapter)) { |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 2802 | for (j = 0; j < 128; j += adapter->num_rx_qs - 1) { |
| 2803 | for_all_rss_queues(adapter, rxo, i) { |
| 2804 | if ((j + i) >= 128) |
| 2805 | break; |
| 2806 | rsstable[j + i] = rxo->rss_id; |
| 2807 | } |
| 2808 | } |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2809 | adapter->rss_flags = RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 | |
| 2810 | RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6; |
| 2811 | |
| 2812 | if (!BEx_chip(adapter)) |
| 2813 | adapter->rss_flags |= RSS_ENABLE_UDP_IPV4 | |
| 2814 | RSS_ENABLE_UDP_IPV6; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 2815 | } else { |
| 2816 | /* Disable RSS, if only default RX Q is created */ |
| 2817 | adapter->rss_flags = RSS_ENABLE_NONE; |
| 2818 | } |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2819 | |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 2820 | rc = be_cmd_rss_config(adapter, rsstable, adapter->rss_flags, |
| 2821 | 128); |
| 2822 | if (rc) { |
| 2823 | adapter->rss_flags = RSS_ENABLE_NONE; |
| 2824 | return rc; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | /* First time posting */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2828 | for_all_rx_queues(adapter, rxo, i) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2829 | be_post_rx_frags(rxo, GFP_KERNEL); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2830 | return 0; |
| 2831 | } |
| 2832 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2833 | static int be_open(struct net_device *netdev) |
| 2834 | { |
| 2835 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2836 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2837 | struct be_rx_obj *rxo; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2838 | struct be_tx_obj *txo; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 2839 | u8 link_status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2840 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2841 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2842 | status = be_rx_qs_create(adapter); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2843 | if (status) |
| 2844 | goto err; |
| 2845 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 2846 | status = be_irq_register(adapter); |
| 2847 | if (status) |
| 2848 | goto err; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2849 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2850 | for_all_rx_queues(adapter, rxo, i) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2851 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2852 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2853 | for_all_tx_queues(adapter, txo, i) |
| 2854 | be_cq_notify(adapter, txo->cq.id, true, 0); |
| 2855 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 2856 | be_async_mcc_enable(adapter); |
| 2857 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2858 | for_all_evt_queues(adapter, eqo, i) { |
| 2859 | napi_enable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2860 | be_enable_busy_poll(eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2861 | be_eq_notify(adapter, eqo->q.id, true, false, 0); |
| 2862 | } |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 2863 | adapter->flags |= BE_FLAGS_NAPI_ENABLED; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2864 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 2865 | status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 2866 | if (!status) |
| 2867 | be_link_status_update(adapter, link_status); |
| 2868 | |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 2869 | netif_tx_start_all_queues(netdev); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 2870 | be_roce_dev_open(adapter); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2871 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 2872 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2873 | if (skyhawk_chip(adapter)) |
| 2874 | vxlan_get_rx_port(netdev); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 2875 | #endif |
| 2876 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2877 | return 0; |
| 2878 | err: |
| 2879 | be_close(adapter->netdev); |
| 2880 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2883 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 2884 | { |
| 2885 | struct be_dma_mem cmd; |
| 2886 | int status = 0; |
| 2887 | u8 mac[ETH_ALEN]; |
| 2888 | |
| 2889 | memset(mac, 0, ETH_ALEN); |
| 2890 | |
| 2891 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 2892 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 2893 | GFP_KERNEL); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2894 | if (cmd.va == NULL) |
| 2895 | return -1; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2896 | |
| 2897 | if (enable) { |
| 2898 | status = pci_write_config_dword(adapter->pdev, |
| 2899 | PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK); |
| 2900 | if (status) { |
| 2901 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 2902 | "Could not enable Wake-on-lan\n"); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2903 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 2904 | cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2905 | return status; |
| 2906 | } |
| 2907 | status = be_cmd_enable_magic_wol(adapter, |
| 2908 | adapter->netdev->dev_addr, &cmd); |
| 2909 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 2910 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 2911 | } else { |
| 2912 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 2913 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 2914 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 2915 | } |
| 2916 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2917 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2918 | return status; |
| 2919 | } |
| 2920 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2921 | /* |
| 2922 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 2923 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 2924 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 2925 | * queries for the MAC address during its probe. |
| 2926 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 2927 | static int be_vf_eth_addr_config(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2928 | { |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2929 | u32 vf; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2930 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2931 | u8 mac[ETH_ALEN]; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2932 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2933 | |
| 2934 | be_vf_eth_addr_generate(adapter, mac); |
| 2935 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2936 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2937 | if (BEx_chip(adapter)) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2938 | status = be_cmd_pmac_add(adapter, mac, |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2939 | vf_cfg->if_handle, |
| 2940 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2941 | else |
| 2942 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 2943 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2944 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2945 | if (status) |
| 2946 | dev_err(&adapter->pdev->dev, |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2947 | "Mac address assignment failed for VF %d\n", vf); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2948 | else |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2949 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2950 | |
| 2951 | mac[5] += 1; |
| 2952 | } |
| 2953 | return status; |
| 2954 | } |
| 2955 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 2956 | static int be_vfs_mac_query(struct be_adapter *adapter) |
| 2957 | { |
| 2958 | int status, vf; |
| 2959 | u8 mac[ETH_ALEN]; |
| 2960 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 2961 | |
| 2962 | for_all_vfs(adapter, vf_cfg, vf) { |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 2963 | status = be_cmd_get_active_mac(adapter, vf_cfg->pmac_id, |
| 2964 | mac, vf_cfg->if_handle, |
| 2965 | false, vf+1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 2966 | if (status) |
| 2967 | return status; |
| 2968 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
| 2969 | } |
| 2970 | return 0; |
| 2971 | } |
| 2972 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2973 | static void be_vf_clear(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2974 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2975 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2976 | u32 vf; |
| 2977 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 2978 | if (pci_vfs_assigned(adapter->pdev)) { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 2979 | dev_warn(&adapter->pdev->dev, |
| 2980 | "VFs are assigned to VMs: not disabling VFs\n"); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 2981 | goto done; |
| 2982 | } |
| 2983 | |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 2984 | pci_disable_sriov(adapter->pdev); |
| 2985 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2986 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2987 | if (BEx_chip(adapter)) |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2988 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, |
| 2989 | vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2990 | else |
| 2991 | be_cmd_set_mac(adapter, NULL, vf_cfg->if_handle, |
| 2992 | vf + 1); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 2993 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 2994 | be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1); |
| 2995 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 2996 | done: |
| 2997 | kfree(adapter->vf_cfg); |
| 2998 | adapter->num_vfs = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3001 | static void be_clear_queues(struct be_adapter *adapter) |
| 3002 | { |
| 3003 | be_mcc_queues_destroy(adapter); |
| 3004 | be_rx_cqs_destroy(adapter); |
| 3005 | be_tx_queues_destroy(adapter); |
| 3006 | be_evt_queues_destroy(adapter); |
| 3007 | } |
| 3008 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3009 | static void be_cancel_worker(struct be_adapter *adapter) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3010 | { |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3011 | if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) { |
| 3012 | cancel_delayed_work_sync(&adapter->work); |
| 3013 | adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED; |
| 3014 | } |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3015 | } |
| 3016 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3017 | static void be_mac_clear(struct be_adapter *adapter) |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3018 | { |
| 3019 | int i; |
| 3020 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3021 | if (adapter->pmac_id) { |
| 3022 | for (i = 0; i < (adapter->uc_macs + 1); i++) |
| 3023 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 3024 | adapter->pmac_id[i], 0); |
| 3025 | adapter->uc_macs = 0; |
| 3026 | |
| 3027 | kfree(adapter->pmac_id); |
| 3028 | adapter->pmac_id = NULL; |
| 3029 | } |
| 3030 | } |
| 3031 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3032 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3033 | static void be_disable_vxlan_offloads(struct be_adapter *adapter) |
| 3034 | { |
| 3035 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) |
| 3036 | be_cmd_manage_iface(adapter, adapter->if_handle, |
| 3037 | OP_CONVERT_TUNNEL_TO_NORMAL); |
| 3038 | |
| 3039 | if (adapter->vxlan_port) |
| 3040 | be_cmd_set_vxlan_port(adapter, 0); |
| 3041 | |
| 3042 | adapter->flags &= ~BE_FLAGS_VXLAN_OFFLOADS; |
| 3043 | adapter->vxlan_port = 0; |
| 3044 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3045 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3046 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3047 | static int be_clear(struct be_adapter *adapter) |
| 3048 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3049 | be_cancel_worker(adapter); |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3050 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3051 | if (sriov_enabled(adapter)) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3052 | be_vf_clear(adapter); |
| 3053 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3054 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3055 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3056 | #endif |
Sathya Perla | 2d17f40 | 2013-07-23 15:25:04 +0530 | [diff] [blame] | 3057 | /* delete the primary mac along with the uc-mac list */ |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3058 | be_mac_clear(adapter); |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 3059 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3060 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3061 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3062 | be_clear_queues(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3063 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3064 | be_msix_disable(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame^] | 3065 | adapter->flags &= ~BE_FLAGS_SETUP_DONE; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3066 | return 0; |
| 3067 | } |
| 3068 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3069 | static int be_vfs_if_create(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3070 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3071 | struct be_resources res = {0}; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3072 | struct be_vf_cfg *vf_cfg; |
| 3073 | u32 cap_flags, en_flags, vf; |
Antonio Alecrim Jr | 922bbe8 | 2013-09-13 14:05:49 -0300 | [diff] [blame] | 3074 | int status = 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3075 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3076 | cap_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 3077 | BE_IF_FLAGS_MULTICAST; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3078 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3079 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3080 | if (!BE3_chip(adapter)) { |
| 3081 | status = be_cmd_get_profile_config(adapter, &res, |
| 3082 | vf + 1); |
| 3083 | if (!status) |
| 3084 | cap_flags = res.if_cap_flags; |
| 3085 | } |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3086 | |
| 3087 | /* If a FW profile exists, then cap_flags are updated */ |
| 3088 | en_flags = cap_flags & (BE_IF_FLAGS_UNTAGGED | |
| 3089 | BE_IF_FLAGS_BROADCAST | BE_IF_FLAGS_MULTICAST); |
| 3090 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 3091 | &vf_cfg->if_handle, vf + 1); |
| 3092 | if (status) |
| 3093 | goto err; |
| 3094 | } |
| 3095 | err: |
| 3096 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3099 | static int be_vf_setup_init(struct be_adapter *adapter) |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3100 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3101 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3102 | int vf; |
| 3103 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3104 | adapter->vf_cfg = kcalloc(adapter->num_vfs, sizeof(*vf_cfg), |
| 3105 | GFP_KERNEL); |
| 3106 | if (!adapter->vf_cfg) |
| 3107 | return -ENOMEM; |
| 3108 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3109 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3110 | vf_cfg->if_handle = -1; |
| 3111 | vf_cfg->pmac_id = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3112 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3113 | return 0; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3116 | static int be_vf_setup(struct be_adapter *adapter) |
| 3117 | { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3118 | struct device *dev = &adapter->pdev->dev; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 3119 | struct be_vf_cfg *vf_cfg; |
| 3120 | int status, old_vfs, vf; |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3121 | u32 privileges; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 3122 | u16 lnk_speed; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3123 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3124 | old_vfs = pci_num_vf(adapter->pdev); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3125 | if (old_vfs) { |
| 3126 | dev_info(dev, "%d VFs are already enabled\n", old_vfs); |
| 3127 | if (old_vfs != num_vfs) |
| 3128 | dev_warn(dev, "Ignoring num_vfs=%d setting\n", num_vfs); |
| 3129 | adapter->num_vfs = old_vfs; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3130 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3131 | if (num_vfs > be_max_vfs(adapter)) |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3132 | dev_info(dev, "Device supports %d VFs and not %d\n", |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3133 | be_max_vfs(adapter), num_vfs); |
| 3134 | adapter->num_vfs = min_t(u16, num_vfs, be_max_vfs(adapter)); |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3135 | if (!adapter->num_vfs) |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3136 | return 0; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | status = be_vf_setup_init(adapter); |
| 3140 | if (status) |
| 3141 | goto err; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3142 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3143 | if (old_vfs) { |
| 3144 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3145 | status = be_cmd_get_if_id(adapter, vf_cfg, vf); |
| 3146 | if (status) |
| 3147 | goto err; |
| 3148 | } |
| 3149 | } else { |
| 3150 | status = be_vfs_if_create(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3151 | if (status) |
| 3152 | goto err; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3155 | if (old_vfs) { |
| 3156 | status = be_vfs_mac_query(adapter); |
| 3157 | if (status) |
| 3158 | goto err; |
| 3159 | } else { |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3160 | status = be_vf_eth_addr_config(adapter); |
| 3161 | if (status) |
| 3162 | goto err; |
| 3163 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3164 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3165 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3166 | /* Allow VFs to programs MAC/VLAN filters */ |
| 3167 | status = be_cmd_get_fn_privileges(adapter, &privileges, vf + 1); |
| 3168 | if (!status && !(privileges & BE_PRIV_FILTMGMT)) { |
| 3169 | status = be_cmd_set_fn_privileges(adapter, |
| 3170 | privileges | |
| 3171 | BE_PRIV_FILTMGMT, |
| 3172 | vf + 1); |
| 3173 | if (!status) |
| 3174 | dev_info(dev, "VF%d has FILTMGMT privilege\n", |
| 3175 | vf); |
| 3176 | } |
| 3177 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3178 | /* BE3 FW, by default, caps VF TX-rate to 100mbps. |
| 3179 | * Allow full available bandwidth |
| 3180 | */ |
| 3181 | if (BE3_chip(adapter) && !old_vfs) |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 3182 | be_cmd_config_qos(adapter, 1000, vf + 1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3183 | |
| 3184 | status = be_cmd_link_status_query(adapter, &lnk_speed, |
| 3185 | NULL, vf + 1); |
| 3186 | if (!status) |
| 3187 | vf_cfg->tx_rate = lnk_speed; |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3188 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3189 | if (!old_vfs) { |
Vasundhara Volam | 0599863 | 2013-10-01 15:59:59 +0530 | [diff] [blame] | 3190 | be_cmd_enable_vf(adapter, vf + 1); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3191 | be_cmd_set_logical_link_config(adapter, |
| 3192 | IFLA_VF_LINK_STATE_AUTO, |
| 3193 | vf+1); |
| 3194 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3195 | } |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3196 | |
| 3197 | if (!old_vfs) { |
| 3198 | status = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 3199 | if (status) { |
| 3200 | dev_err(dev, "SRIOV enable failed\n"); |
| 3201 | adapter->num_vfs = 0; |
| 3202 | goto err; |
| 3203 | } |
| 3204 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3205 | return 0; |
| 3206 | err: |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3207 | dev_err(dev, "VF setup failed\n"); |
| 3208 | be_vf_clear(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3209 | return status; |
| 3210 | } |
| 3211 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3212 | /* Converting function_mode bits on BE3 to SH mc_type enums */ |
| 3213 | |
| 3214 | static u8 be_convert_mc_type(u32 function_mode) |
| 3215 | { |
| 3216 | if (function_mode & VNIC_MODE && function_mode & FLEX10_MODE) |
| 3217 | return vNIC1; |
| 3218 | else if (function_mode & FLEX10_MODE) |
| 3219 | return FLEX10; |
| 3220 | else if (function_mode & VNIC_MODE) |
| 3221 | return vNIC2; |
| 3222 | else if (function_mode & UMC_ENABLED) |
| 3223 | return UMC; |
| 3224 | else |
| 3225 | return MC_NONE; |
| 3226 | } |
| 3227 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3228 | /* On BE2/BE3 FW does not suggest the supported limits */ |
| 3229 | static void BEx_get_resources(struct be_adapter *adapter, |
| 3230 | struct be_resources *res) |
| 3231 | { |
| 3232 | struct pci_dev *pdev = adapter->pdev; |
| 3233 | bool use_sriov = false; |
Suresh Reddy | ecf1f6e | 2014-03-11 18:53:03 +0530 | [diff] [blame] | 3234 | int max_vfs = 0; |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3235 | |
Suresh Reddy | ecf1f6e | 2014-03-11 18:53:03 +0530 | [diff] [blame] | 3236 | if (be_physfn(adapter) && BE3_chip(adapter)) { |
| 3237 | be_cmd_get_profile_config(adapter, res, 0); |
| 3238 | /* Some old versions of BE3 FW don't report max_vfs value */ |
| 3239 | if (res->max_vfs == 0) { |
| 3240 | max_vfs = pci_sriov_get_totalvfs(pdev); |
| 3241 | res->max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0; |
| 3242 | } |
| 3243 | use_sriov = res->max_vfs && sriov_want(adapter); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | if (be_physfn(adapter)) |
| 3247 | res->max_uc_mac = BE_UC_PMAC_COUNT; |
| 3248 | else |
| 3249 | res->max_uc_mac = BE_VF_UC_PMAC_COUNT; |
| 3250 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3251 | adapter->mc_type = be_convert_mc_type(adapter->function_mode); |
| 3252 | |
| 3253 | if (be_is_mc(adapter)) { |
| 3254 | /* Assuming that there are 4 channels per port, |
| 3255 | * when multi-channel is enabled |
| 3256 | */ |
| 3257 | if (be_is_qnq_mode(adapter)) |
| 3258 | res->max_vlans = BE_NUM_VLANS_SUPPORTED/8; |
| 3259 | else |
| 3260 | /* In a non-qnq multichannel mode, the pvid |
| 3261 | * takes up one vlan entry |
| 3262 | */ |
| 3263 | res->max_vlans = (BE_NUM_VLANS_SUPPORTED / 4) - 1; |
| 3264 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3265 | res->max_vlans = BE_NUM_VLANS_SUPPORTED; |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3266 | } |
| 3267 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3268 | res->max_mcast_mac = BE_MAX_MC; |
| 3269 | |
Vasundhara Volam | a5243da | 2014-03-11 18:53:07 +0530 | [diff] [blame] | 3270 | /* 1) For BE3 1Gb ports, FW does not support multiple TXQs |
| 3271 | * 2) Create multiple TX rings on a BE3-R multi-channel interface |
| 3272 | * *only* if it is RSS-capable. |
| 3273 | */ |
| 3274 | if (BE2_chip(adapter) || use_sriov || (adapter->port_num > 1) || |
| 3275 | !be_physfn(adapter) || (be_is_mc(adapter) && |
| 3276 | !(adapter->function_caps & BE_FUNCTION_CAPS_RSS))) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3277 | res->max_tx_qs = 1; |
| 3278 | else |
| 3279 | res->max_tx_qs = BE3_MAX_TX_QS; |
| 3280 | |
| 3281 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
| 3282 | !use_sriov && be_physfn(adapter)) |
| 3283 | res->max_rss_qs = (adapter->be3_native) ? |
| 3284 | BE3_MAX_RSS_QS : BE2_MAX_RSS_QS; |
| 3285 | res->max_rx_qs = res->max_rss_qs + 1; |
| 3286 | |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3287 | if (be_physfn(adapter)) |
Suresh Reddy | ecf1f6e | 2014-03-11 18:53:03 +0530 | [diff] [blame] | 3288 | res->max_evt_qs = (res->max_vfs > 0) ? |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3289 | BE3_SRIOV_MAX_EVT_QS : BE3_MAX_EVT_QS; |
| 3290 | else |
| 3291 | res->max_evt_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3292 | |
| 3293 | res->if_cap_flags = BE_IF_CAP_FLAGS_WANT; |
| 3294 | if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS)) |
| 3295 | res->if_cap_flags &= ~BE_IF_FLAGS_RSS; |
| 3296 | } |
| 3297 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3298 | static void be_setup_init(struct be_adapter *adapter) |
| 3299 | { |
| 3300 | adapter->vlan_prio_bmap = 0xff; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3301 | adapter->phy.link_speed = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3302 | adapter->if_handle = -1; |
| 3303 | adapter->be3_native = false; |
| 3304 | adapter->promiscuous = false; |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3305 | if (be_physfn(adapter)) |
| 3306 | adapter->cmd_privileges = MAX_PRIVILEGES; |
| 3307 | else |
| 3308 | adapter->cmd_privileges = MIN_PRIVILEGES; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3311 | static int be_get_resources(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3312 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3313 | struct device *dev = &adapter->pdev->dev; |
| 3314 | struct be_resources res = {0}; |
| 3315 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3316 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3317 | if (BEx_chip(adapter)) { |
| 3318 | BEx_get_resources(adapter, &res); |
| 3319 | adapter->res = res; |
| 3320 | } |
| 3321 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3322 | /* For Lancer, SH etc read per-function resource limits from FW. |
| 3323 | * GET_FUNC_CONFIG returns per function guaranteed limits. |
| 3324 | * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits |
| 3325 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3326 | if (!BEx_chip(adapter)) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3327 | status = be_cmd_get_func_config(adapter, &res); |
| 3328 | if (status) |
| 3329 | return status; |
| 3330 | |
| 3331 | /* If RoCE may be enabled stash away half the EQs for RoCE */ |
| 3332 | if (be_roce_supported(adapter)) |
| 3333 | res.max_evt_qs /= 2; |
| 3334 | adapter->res = res; |
| 3335 | |
| 3336 | if (be_physfn(adapter)) { |
| 3337 | status = be_cmd_get_profile_config(adapter, &res, 0); |
| 3338 | if (status) |
| 3339 | return status; |
| 3340 | adapter->res.max_vfs = res.max_vfs; |
| 3341 | } |
| 3342 | |
| 3343 | dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n", |
| 3344 | be_max_txqs(adapter), be_max_rxqs(adapter), |
| 3345 | be_max_rss(adapter), be_max_eqs(adapter), |
| 3346 | be_max_vfs(adapter)); |
| 3347 | dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n", |
| 3348 | be_max_uc(adapter), be_max_mc(adapter), |
| 3349 | be_max_vlans(adapter)); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3352 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3355 | /* Routine to query per function resource limits */ |
| 3356 | static int be_get_config(struct be_adapter *adapter) |
| 3357 | { |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 3358 | u16 profile_id; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3359 | int status; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3360 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3361 | status = be_cmd_query_fw_cfg(adapter, &adapter->port_num, |
| 3362 | &adapter->function_mode, |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 3363 | &adapter->function_caps, |
| 3364 | &adapter->asic_rev); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3365 | if (status) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3366 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3367 | |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 3368 | if (be_physfn(adapter)) { |
| 3369 | status = be_cmd_get_active_profile(adapter, &profile_id); |
| 3370 | if (!status) |
| 3371 | dev_info(&adapter->pdev->dev, |
| 3372 | "Using profile 0x%x\n", profile_id); |
| 3373 | } |
| 3374 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3375 | status = be_get_resources(adapter); |
| 3376 | if (status) |
| 3377 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3378 | |
Ravikumar Nelavelli | 46ee9c1 | 2014-03-11 18:53:06 +0530 | [diff] [blame] | 3379 | adapter->pmac_id = kcalloc(be_max_uc(adapter), |
| 3380 | sizeof(*adapter->pmac_id), GFP_KERNEL); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3381 | if (!adapter->pmac_id) |
| 3382 | return -ENOMEM; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3383 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3384 | /* Sanitize cfg_num_qs based on HW and platform limits */ |
| 3385 | adapter->cfg_num_qs = min(adapter->cfg_num_qs, be_max_qs(adapter)); |
| 3386 | |
| 3387 | return 0; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3390 | static int be_mac_setup(struct be_adapter *adapter) |
| 3391 | { |
| 3392 | u8 mac[ETH_ALEN]; |
| 3393 | int status; |
| 3394 | |
| 3395 | if (is_zero_ether_addr(adapter->netdev->dev_addr)) { |
| 3396 | status = be_cmd_get_perm_mac(adapter, mac); |
| 3397 | if (status) |
| 3398 | return status; |
| 3399 | |
| 3400 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 3401 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 3402 | } else { |
| 3403 | /* Maybe the HW was reset; dev_addr must be re-programmed */ |
| 3404 | memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN); |
| 3405 | } |
| 3406 | |
Ajit Khaparde | 2c7a9dc | 2013-11-22 12:51:28 -0600 | [diff] [blame] | 3407 | /* For BE3-R VFs, the PF programs the initial MAC address */ |
| 3408 | if (!(BEx_chip(adapter) && be_virtfn(adapter))) |
| 3409 | be_cmd_pmac_add(adapter, mac, adapter->if_handle, |
| 3410 | &adapter->pmac_id[0], 0); |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3414 | static void be_schedule_worker(struct be_adapter *adapter) |
| 3415 | { |
| 3416 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 3417 | adapter->flags |= BE_FLAGS_WORKER_SCHEDULED; |
| 3418 | } |
| 3419 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3420 | static int be_setup_queues(struct be_adapter *adapter) |
| 3421 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3422 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3423 | int status; |
| 3424 | |
| 3425 | status = be_evt_queues_create(adapter); |
| 3426 | if (status) |
| 3427 | goto err; |
| 3428 | |
| 3429 | status = be_tx_qs_create(adapter); |
| 3430 | if (status) |
| 3431 | goto err; |
| 3432 | |
| 3433 | status = be_rx_cqs_create(adapter); |
| 3434 | if (status) |
| 3435 | goto err; |
| 3436 | |
| 3437 | status = be_mcc_queues_create(adapter); |
| 3438 | if (status) |
| 3439 | goto err; |
| 3440 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3441 | status = netif_set_real_num_rx_queues(netdev, adapter->num_rx_qs); |
| 3442 | if (status) |
| 3443 | goto err; |
| 3444 | |
| 3445 | status = netif_set_real_num_tx_queues(netdev, adapter->num_tx_qs); |
| 3446 | if (status) |
| 3447 | goto err; |
| 3448 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3449 | return 0; |
| 3450 | err: |
| 3451 | dev_err(&adapter->pdev->dev, "queue_setup failed\n"); |
| 3452 | return status; |
| 3453 | } |
| 3454 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3455 | int be_update_queues(struct be_adapter *adapter) |
| 3456 | { |
| 3457 | struct net_device *netdev = adapter->netdev; |
| 3458 | int status; |
| 3459 | |
| 3460 | if (netif_running(netdev)) |
| 3461 | be_close(netdev); |
| 3462 | |
| 3463 | be_cancel_worker(adapter); |
| 3464 | |
| 3465 | /* If any vectors have been shared with RoCE we cannot re-program |
| 3466 | * the MSIx table. |
| 3467 | */ |
| 3468 | if (!adapter->num_msix_roce_vec) |
| 3469 | be_msix_disable(adapter); |
| 3470 | |
| 3471 | be_clear_queues(adapter); |
| 3472 | |
| 3473 | if (!msix_enabled(adapter)) { |
| 3474 | status = be_msix_enable(adapter); |
| 3475 | if (status) |
| 3476 | return status; |
| 3477 | } |
| 3478 | |
| 3479 | status = be_setup_queues(adapter); |
| 3480 | if (status) |
| 3481 | return status; |
| 3482 | |
| 3483 | be_schedule_worker(adapter); |
| 3484 | |
| 3485 | if (netif_running(netdev)) |
| 3486 | status = be_open(netdev); |
| 3487 | |
| 3488 | return status; |
| 3489 | } |
| 3490 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3491 | static int be_setup(struct be_adapter *adapter) |
| 3492 | { |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3493 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3494 | u32 tx_fc, rx_fc, en_flags; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3495 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3496 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3497 | be_setup_init(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3498 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3499 | if (!lancer_chip(adapter)) |
| 3500 | be_cmd_req_native_mode(adapter); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3501 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3502 | status = be_get_config(adapter); |
| 3503 | if (status) |
| 3504 | goto err; |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 3505 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3506 | status = be_msix_enable(adapter); |
| 3507 | if (status) |
| 3508 | goto err; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3509 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3510 | en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 3511 | BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
| 3512 | if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) |
| 3513 | en_flags |= BE_IF_FLAGS_RSS; |
| 3514 | en_flags = en_flags & be_if_cap_flags(adapter); |
| 3515 | status = be_cmd_if_create(adapter, be_if_cap_flags(adapter), en_flags, |
| 3516 | &adapter->if_handle, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3517 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3518 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3519 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3520 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 3521 | rtnl_lock(); |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3522 | status = be_setup_queues(adapter); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3523 | rtnl_unlock(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3524 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3525 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3526 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3527 | be_cmd_get_fn_privileges(adapter, &adapter->cmd_privileges, 0); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3528 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3529 | status = be_mac_setup(adapter); |
| 3530 | if (status) |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 3531 | goto err; |
| 3532 | |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 3533 | be_cmd_get_fw_ver(adapter, adapter->fw_ver, adapter->fw_on_flash); |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 3534 | |
Somnath Kotur | e9e2a90 | 2013-10-24 14:37:53 +0530 | [diff] [blame] | 3535 | if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) { |
| 3536 | dev_err(dev, "Firmware on card is old(%s), IRQs may not work.", |
| 3537 | adapter->fw_ver); |
| 3538 | dev_err(dev, "Please upgrade firmware to version >= 4.0\n"); |
| 3539 | } |
| 3540 | |
Sathya Perla | 1d1e9a4 | 2012-06-05 19:37:17 +0000 | [diff] [blame] | 3541 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 3542 | be_vid_config(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3543 | |
| 3544 | be_set_rx_mode(adapter->netdev); |
| 3545 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 3546 | be_cmd_get_acpi_wol_cap(adapter); |
| 3547 | |
Ajit Khaparde | ddc3f5c | 2012-04-26 15:42:31 +0000 | [diff] [blame] | 3548 | be_cmd_get_flow_control(adapter, &tx_fc, &rx_fc); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3549 | |
Ajit Khaparde | ddc3f5c | 2012-04-26 15:42:31 +0000 | [diff] [blame] | 3550 | if (rx_fc != adapter->rx_fc || tx_fc != adapter->tx_fc) |
| 3551 | be_cmd_set_flow_control(adapter, adapter->tx_fc, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3552 | adapter->rx_fc); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3553 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3554 | if (be_physfn(adapter)) |
| 3555 | be_cmd_set_logical_link_config(adapter, |
| 3556 | IFLA_VF_LINK_STATE_AUTO, 0); |
| 3557 | |
Vasundhara Volam | b905b5d | 2013-10-01 15:59:56 +0530 | [diff] [blame] | 3558 | if (sriov_want(adapter)) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3559 | if (be_max_vfs(adapter)) |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3560 | be_vf_setup(adapter); |
| 3561 | else |
| 3562 | dev_warn(dev, "device doesn't support SRIOV\n"); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3565 | status = be_cmd_get_phy_info(adapter); |
| 3566 | if (!status && be_pause_supported(adapter)) |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3567 | adapter->phy.fc_autoneg = 1; |
| 3568 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3569 | be_schedule_worker(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame^] | 3570 | adapter->flags |= BE_FLAGS_SETUP_DONE; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3571 | return 0; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3572 | err: |
| 3573 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3574 | return status; |
| 3575 | } |
| 3576 | |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3577 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3578 | static void be_netpoll(struct net_device *netdev) |
| 3579 | { |
| 3580 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3581 | struct be_eq_obj *eqo; |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3582 | int i; |
| 3583 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3584 | for_all_evt_queues(adapter, eqo, i) { |
| 3585 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0); |
| 3586 | napi_schedule(&eqo->napi); |
| 3587 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3588 | |
| 3589 | return; |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3590 | } |
| 3591 | #endif |
| 3592 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3593 | #define FW_FILE_HDR_SIGN "ServerEngines Corp. " |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 3594 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3595 | |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3596 | static bool be_flash_redboot(struct be_adapter *adapter, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3597 | const u8 *p, u32 img_start, int image_size, |
| 3598 | int hdr_size) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3599 | { |
| 3600 | u32 crc_offset; |
| 3601 | u8 flashed_crc[4]; |
| 3602 | int status; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3603 | |
| 3604 | crc_offset = hdr_size + img_start + image_size - 4; |
| 3605 | |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3606 | p += crc_offset; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3607 | |
| 3608 | status = be_cmd_get_flash_crc(adapter, flashed_crc, |
Ajit Khaparde | f510fc6 | 2010-03-31 01:47:45 +0000 | [diff] [blame] | 3609 | (image_size - 4)); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3610 | if (status) { |
| 3611 | dev_err(&adapter->pdev->dev, |
| 3612 | "could not get crc from flash, not flashing redboot\n"); |
| 3613 | return false; |
| 3614 | } |
| 3615 | |
| 3616 | /*update redboot only if crc does not match*/ |
| 3617 | if (!memcmp(flashed_crc, p, 4)) |
| 3618 | return false; |
| 3619 | else |
| 3620 | return true; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3623 | static bool phy_flashing_required(struct be_adapter *adapter) |
| 3624 | { |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3625 | return (adapter->phy.phy_type == TN_8022 && |
| 3626 | adapter->phy.interface_type == PHY_TYPE_BASET_10GB); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3629 | static bool is_comp_in_ufi(struct be_adapter *adapter, |
| 3630 | struct flash_section_info *fsec, int type) |
| 3631 | { |
| 3632 | int i = 0, img_type = 0; |
| 3633 | struct flash_section_info_g2 *fsec_g2 = NULL; |
| 3634 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3635 | if (BE2_chip(adapter)) |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3636 | fsec_g2 = (struct flash_section_info_g2 *)fsec; |
| 3637 | |
| 3638 | for (i = 0; i < MAX_FLASH_COMP; i++) { |
| 3639 | if (fsec_g2) |
| 3640 | img_type = le32_to_cpu(fsec_g2->fsec_entry[i].type); |
| 3641 | else |
| 3642 | img_type = le32_to_cpu(fsec->fsec_entry[i].type); |
| 3643 | |
| 3644 | if (img_type == type) |
| 3645 | return true; |
| 3646 | } |
| 3647 | return false; |
| 3648 | |
| 3649 | } |
| 3650 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 3651 | static struct flash_section_info *get_fsec_info(struct be_adapter *adapter, |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3652 | int header_size, |
| 3653 | const struct firmware *fw) |
| 3654 | { |
| 3655 | struct flash_section_info *fsec = NULL; |
| 3656 | const u8 *p = fw->data; |
| 3657 | |
| 3658 | p += header_size; |
| 3659 | while (p < (fw->data + fw->size)) { |
| 3660 | fsec = (struct flash_section_info *)p; |
| 3661 | if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie))) |
| 3662 | return fsec; |
| 3663 | p += 32; |
| 3664 | } |
| 3665 | return NULL; |
| 3666 | } |
| 3667 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3668 | static int be_flash(struct be_adapter *adapter, const u8 *img, |
| 3669 | struct be_dma_mem *flash_cmd, int optype, int img_size) |
| 3670 | { |
| 3671 | u32 total_bytes = 0, flash_op, num_bytes = 0; |
| 3672 | int status = 0; |
| 3673 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
| 3674 | |
| 3675 | total_bytes = img_size; |
| 3676 | while (total_bytes) { |
| 3677 | num_bytes = min_t(u32, 32*1024, total_bytes); |
| 3678 | |
| 3679 | total_bytes -= num_bytes; |
| 3680 | |
| 3681 | if (!total_bytes) { |
| 3682 | if (optype == OPTYPE_PHY_FW) |
| 3683 | flash_op = FLASHROM_OPER_PHY_FLASH; |
| 3684 | else |
| 3685 | flash_op = FLASHROM_OPER_FLASH; |
| 3686 | } else { |
| 3687 | if (optype == OPTYPE_PHY_FW) |
| 3688 | flash_op = FLASHROM_OPER_PHY_SAVE; |
| 3689 | else |
| 3690 | flash_op = FLASHROM_OPER_SAVE; |
| 3691 | } |
| 3692 | |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 3693 | memcpy(req->data_buf, img, num_bytes); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3694 | img += num_bytes; |
| 3695 | status = be_cmd_write_flashrom(adapter, flash_cmd, optype, |
| 3696 | flash_op, num_bytes); |
| 3697 | if (status) { |
| 3698 | if (status == ILLEGAL_IOCTL_REQ && |
| 3699 | optype == OPTYPE_PHY_FW) |
| 3700 | break; |
| 3701 | dev_err(&adapter->pdev->dev, |
| 3702 | "cmd to write to flash rom failed.\n"); |
| 3703 | return status; |
| 3704 | } |
| 3705 | } |
| 3706 | return 0; |
| 3707 | } |
| 3708 | |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 3709 | /* For BE2, BE3 and BE3-R */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3710 | static int be_flash_BEx(struct be_adapter *adapter, |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3711 | const struct firmware *fw, |
| 3712 | struct be_dma_mem *flash_cmd, |
| 3713 | int num_of_images) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3714 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3715 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3716 | int status = 0, i, filehdr_size = 0; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3717 | int img_hdrs_size = (num_of_images * sizeof(struct image_hdr)); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3718 | const u8 *p = fw->data; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 3719 | const struct flash_comp *pflashcomp; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3720 | int num_comp, redboot; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3721 | struct flash_section_info *fsec = NULL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3722 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3723 | struct flash_comp gen3_flash_types[] = { |
| 3724 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, OPTYPE_ISCSI_ACTIVE, |
| 3725 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_iSCSI}, |
| 3726 | { FLASH_REDBOOT_START_g3, OPTYPE_REDBOOT, |
| 3727 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3, IMAGE_BOOT_CODE}, |
| 3728 | { FLASH_iSCSI_BIOS_START_g3, OPTYPE_BIOS, |
| 3729 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_ISCSI}, |
| 3730 | { FLASH_PXE_BIOS_START_g3, OPTYPE_PXE_BIOS, |
| 3731 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_PXE}, |
| 3732 | { FLASH_FCoE_BIOS_START_g3, OPTYPE_FCOE_BIOS, |
| 3733 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_FCoE}, |
| 3734 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, OPTYPE_ISCSI_BACKUP, |
| 3735 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 3736 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, OPTYPE_FCOE_FW_ACTIVE, |
| 3737 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_FCoE}, |
| 3738 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, OPTYPE_FCOE_FW_BACKUP, |
| 3739 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_FCoE}, |
| 3740 | { FLASH_NCSI_START_g3, OPTYPE_NCSI_FW, |
| 3741 | FLASH_NCSI_IMAGE_MAX_SIZE_g3, IMAGE_NCSI}, |
| 3742 | { FLASH_PHY_FW_START_g3, OPTYPE_PHY_FW, |
| 3743 | FLASH_PHY_FW_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_PHY} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3744 | }; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3745 | |
| 3746 | struct flash_comp gen2_flash_types[] = { |
| 3747 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, OPTYPE_ISCSI_ACTIVE, |
| 3748 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_iSCSI}, |
| 3749 | { FLASH_REDBOOT_START_g2, OPTYPE_REDBOOT, |
| 3750 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2, IMAGE_BOOT_CODE}, |
| 3751 | { FLASH_iSCSI_BIOS_START_g2, OPTYPE_BIOS, |
| 3752 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_ISCSI}, |
| 3753 | { FLASH_PXE_BIOS_START_g2, OPTYPE_PXE_BIOS, |
| 3754 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_PXE}, |
| 3755 | { FLASH_FCoE_BIOS_START_g2, OPTYPE_FCOE_BIOS, |
| 3756 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_FCoE}, |
| 3757 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, OPTYPE_ISCSI_BACKUP, |
| 3758 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 3759 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, OPTYPE_FCOE_FW_ACTIVE, |
| 3760 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_FCoE}, |
| 3761 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, OPTYPE_FCOE_FW_BACKUP, |
| 3762 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_FCoE} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3763 | }; |
| 3764 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3765 | if (BE3_chip(adapter)) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3766 | pflashcomp = gen3_flash_types; |
| 3767 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 3768 | num_comp = ARRAY_SIZE(gen3_flash_types); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3769 | } else { |
| 3770 | pflashcomp = gen2_flash_types; |
| 3771 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 3772 | num_comp = ARRAY_SIZE(gen2_flash_types); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3773 | } |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3774 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3775 | /* Get flash section info*/ |
| 3776 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 3777 | if (!fsec) { |
| 3778 | dev_err(&adapter->pdev->dev, |
| 3779 | "Invalid Cookie. UFI corrupted ?\n"); |
| 3780 | return -1; |
| 3781 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 3782 | for (i = 0; i < num_comp; i++) { |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3783 | if (!is_comp_in_ufi(adapter, fsec, pflashcomp[i].img_type)) |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 3784 | continue; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3785 | |
| 3786 | if ((pflashcomp[i].optype == OPTYPE_NCSI_FW) && |
| 3787 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 3788 | continue; |
| 3789 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3790 | if (pflashcomp[i].optype == OPTYPE_PHY_FW && |
| 3791 | !phy_flashing_required(adapter)) |
| 3792 | continue; |
| 3793 | |
| 3794 | if (pflashcomp[i].optype == OPTYPE_REDBOOT) { |
| 3795 | redboot = be_flash_redboot(adapter, fw->data, |
| 3796 | pflashcomp[i].offset, pflashcomp[i].size, |
| 3797 | filehdr_size + img_hdrs_size); |
| 3798 | if (!redboot) |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3799 | continue; |
| 3800 | } |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3801 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3802 | p = fw->data; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3803 | p += filehdr_size + pflashcomp[i].offset + img_hdrs_size; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3804 | if (p + pflashcomp[i].size > fw->data + fw->size) |
| 3805 | return -1; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3806 | |
| 3807 | status = be_flash(adapter, p, flash_cmd, pflashcomp[i].optype, |
| 3808 | pflashcomp[i].size); |
| 3809 | if (status) { |
| 3810 | dev_err(&adapter->pdev->dev, |
| 3811 | "Flashing section type %d failed.\n", |
| 3812 | pflashcomp[i].img_type); |
| 3813 | return status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3814 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3815 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3816 | return 0; |
| 3817 | } |
| 3818 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3819 | static int be_flash_skyhawk(struct be_adapter *adapter, |
| 3820 | const struct firmware *fw, |
| 3821 | struct be_dma_mem *flash_cmd, int num_of_images) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3822 | { |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3823 | int status = 0, i, filehdr_size = 0; |
| 3824 | int img_offset, img_size, img_optype, redboot; |
| 3825 | int img_hdrs_size = num_of_images * sizeof(struct image_hdr); |
| 3826 | const u8 *p = fw->data; |
| 3827 | struct flash_section_info *fsec = NULL; |
| 3828 | |
| 3829 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
| 3830 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 3831 | if (!fsec) { |
| 3832 | dev_err(&adapter->pdev->dev, |
| 3833 | "Invalid Cookie. UFI corrupted ?\n"); |
| 3834 | return -1; |
| 3835 | } |
| 3836 | |
| 3837 | for (i = 0; i < le32_to_cpu(fsec->fsec_hdr.num_images); i++) { |
| 3838 | img_offset = le32_to_cpu(fsec->fsec_entry[i].offset); |
| 3839 | img_size = le32_to_cpu(fsec->fsec_entry[i].pad_size); |
| 3840 | |
| 3841 | switch (le32_to_cpu(fsec->fsec_entry[i].type)) { |
| 3842 | case IMAGE_FIRMWARE_iSCSI: |
| 3843 | img_optype = OPTYPE_ISCSI_ACTIVE; |
| 3844 | break; |
| 3845 | case IMAGE_BOOT_CODE: |
| 3846 | img_optype = OPTYPE_REDBOOT; |
| 3847 | break; |
| 3848 | case IMAGE_OPTION_ROM_ISCSI: |
| 3849 | img_optype = OPTYPE_BIOS; |
| 3850 | break; |
| 3851 | case IMAGE_OPTION_ROM_PXE: |
| 3852 | img_optype = OPTYPE_PXE_BIOS; |
| 3853 | break; |
| 3854 | case IMAGE_OPTION_ROM_FCoE: |
| 3855 | img_optype = OPTYPE_FCOE_BIOS; |
| 3856 | break; |
| 3857 | case IMAGE_FIRMWARE_BACKUP_iSCSI: |
| 3858 | img_optype = OPTYPE_ISCSI_BACKUP; |
| 3859 | break; |
| 3860 | case IMAGE_NCSI: |
| 3861 | img_optype = OPTYPE_NCSI_FW; |
| 3862 | break; |
| 3863 | default: |
| 3864 | continue; |
| 3865 | } |
| 3866 | |
| 3867 | if (img_optype == OPTYPE_REDBOOT) { |
| 3868 | redboot = be_flash_redboot(adapter, fw->data, |
| 3869 | img_offset, img_size, |
| 3870 | filehdr_size + img_hdrs_size); |
| 3871 | if (!redboot) |
| 3872 | continue; |
| 3873 | } |
| 3874 | |
| 3875 | p = fw->data; |
| 3876 | p += filehdr_size + img_offset + img_hdrs_size; |
| 3877 | if (p + img_size > fw->data + fw->size) |
| 3878 | return -1; |
| 3879 | |
| 3880 | status = be_flash(adapter, p, flash_cmd, img_optype, img_size); |
| 3881 | if (status) { |
| 3882 | dev_err(&adapter->pdev->dev, |
| 3883 | "Flashing section type %d failed.\n", |
| 3884 | fsec->fsec_entry[i].type); |
| 3885 | return status; |
| 3886 | } |
| 3887 | } |
| 3888 | return 0; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3891 | static int lancer_fw_download(struct be_adapter *adapter, |
| 3892 | const struct firmware *fw) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 3893 | { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3894 | #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024) |
| 3895 | #define LANCER_FW_DOWNLOAD_LOCATION "/prg" |
| 3896 | struct be_dma_mem flash_cmd; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3897 | const u8 *data_ptr = NULL; |
| 3898 | u8 *dest_image_ptr = NULL; |
| 3899 | size_t image_size = 0; |
| 3900 | u32 chunk_size = 0; |
| 3901 | u32 data_written = 0; |
| 3902 | u32 offset = 0; |
| 3903 | int status = 0; |
| 3904 | u8 add_status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3905 | u8 change_status; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3906 | |
| 3907 | if (!IS_ALIGNED(fw->size, sizeof(u32))) { |
| 3908 | dev_err(&adapter->pdev->dev, |
| 3909 | "FW Image not properly aligned. " |
| 3910 | "Length must be 4 byte aligned.\n"); |
| 3911 | status = -EINVAL; |
| 3912 | goto lancer_fw_exit; |
| 3913 | } |
| 3914 | |
| 3915 | flash_cmd.size = sizeof(struct lancer_cmd_req_write_object) |
| 3916 | + LANCER_FW_DOWNLOAD_CHUNK; |
| 3917 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 3918 | &flash_cmd.dma, GFP_KERNEL); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3919 | if (!flash_cmd.va) { |
| 3920 | status = -ENOMEM; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3921 | goto lancer_fw_exit; |
| 3922 | } |
| 3923 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3924 | dest_image_ptr = flash_cmd.va + |
| 3925 | sizeof(struct lancer_cmd_req_write_object); |
| 3926 | image_size = fw->size; |
| 3927 | data_ptr = fw->data; |
| 3928 | |
| 3929 | while (image_size) { |
| 3930 | chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK); |
| 3931 | |
| 3932 | /* Copy the image chunk content. */ |
| 3933 | memcpy(dest_image_ptr, data_ptr, chunk_size); |
| 3934 | |
| 3935 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3936 | chunk_size, offset, |
| 3937 | LANCER_FW_DOWNLOAD_LOCATION, |
| 3938 | &data_written, &change_status, |
| 3939 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3940 | if (status) |
| 3941 | break; |
| 3942 | |
| 3943 | offset += data_written; |
| 3944 | data_ptr += data_written; |
| 3945 | image_size -= data_written; |
| 3946 | } |
| 3947 | |
| 3948 | if (!status) { |
| 3949 | /* Commit the FW written */ |
| 3950 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3951 | 0, offset, |
| 3952 | LANCER_FW_DOWNLOAD_LOCATION, |
| 3953 | &data_written, &change_status, |
| 3954 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3955 | } |
| 3956 | |
| 3957 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 3958 | flash_cmd.dma); |
| 3959 | if (status) { |
| 3960 | dev_err(&adapter->pdev->dev, |
| 3961 | "Firmware load error. " |
| 3962 | "Status code: 0x%x Additional Status: 0x%x\n", |
| 3963 | status, add_status); |
| 3964 | goto lancer_fw_exit; |
| 3965 | } |
| 3966 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3967 | if (change_status == LANCER_FW_RESET_NEEDED) { |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 3968 | dev_info(&adapter->pdev->dev, |
| 3969 | "Resetting adapter to activate new FW\n"); |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 3970 | status = lancer_physdev_ctrl(adapter, |
| 3971 | PHYSDEV_CONTROL_FW_RESET_MASK); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3972 | if (status) { |
| 3973 | dev_err(&adapter->pdev->dev, |
| 3974 | "Adapter busy for FW reset.\n" |
| 3975 | "New FW will not be active.\n"); |
| 3976 | goto lancer_fw_exit; |
| 3977 | } |
| 3978 | } else if (change_status != LANCER_NO_RESET_NEEDED) { |
| 3979 | dev_err(&adapter->pdev->dev, |
| 3980 | "System reboot required for new FW" |
| 3981 | " to be active\n"); |
| 3982 | } |
| 3983 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 3984 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
| 3985 | lancer_fw_exit: |
| 3986 | return status; |
| 3987 | } |
| 3988 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3989 | #define UFI_TYPE2 2 |
| 3990 | #define UFI_TYPE3 3 |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 3991 | #define UFI_TYPE3R 10 |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3992 | #define UFI_TYPE4 4 |
| 3993 | static int be_get_ufi_type(struct be_adapter *adapter, |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 3994 | struct flash_file_hdr_g3 *fhdr) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3995 | { |
| 3996 | if (fhdr == NULL) |
| 3997 | goto be_get_ufi_exit; |
| 3998 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3999 | if (skyhawk_chip(adapter) && fhdr->build[0] == '4') |
| 4000 | return UFI_TYPE4; |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4001 | else if (BE3_chip(adapter) && fhdr->build[0] == '3') { |
| 4002 | if (fhdr->asic_type_rev == 0x10) |
| 4003 | return UFI_TYPE3R; |
| 4004 | else |
| 4005 | return UFI_TYPE3; |
| 4006 | } else if (BE2_chip(adapter) && fhdr->build[0] == '2') |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4007 | return UFI_TYPE2; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4008 | |
| 4009 | be_get_ufi_exit: |
| 4010 | dev_err(&adapter->pdev->dev, |
| 4011 | "UFI and Interface are not compatible for flashing\n"); |
| 4012 | return -1; |
| 4013 | } |
| 4014 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4015 | static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) |
| 4016 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4017 | struct flash_file_hdr_g3 *fhdr3; |
| 4018 | struct image_hdr *img_hdr_ptr = NULL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4019 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4020 | const u8 *p; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4021 | int status = 0, i = 0, num_imgs = 0, ufi_type = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4022 | |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 4023 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4024 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
| 4025 | &flash_cmd.dma, GFP_KERNEL); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4026 | if (!flash_cmd.va) { |
| 4027 | status = -ENOMEM; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4028 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4031 | p = fw->data; |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4032 | fhdr3 = (struct flash_file_hdr_g3 *)p; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4033 | |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4034 | ufi_type = be_get_ufi_type(adapter, fhdr3); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4035 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4036 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 4037 | for (i = 0; i < num_imgs; i++) { |
| 4038 | img_hdr_ptr = (struct image_hdr *)(fw->data + |
| 4039 | (sizeof(struct flash_file_hdr_g3) + |
| 4040 | i * sizeof(struct image_hdr))); |
| 4041 | if (le32_to_cpu(img_hdr_ptr->imageid) == 1) { |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4042 | switch (ufi_type) { |
| 4043 | case UFI_TYPE4: |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4044 | status = be_flash_skyhawk(adapter, fw, |
| 4045 | &flash_cmd, num_imgs); |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4046 | break; |
| 4047 | case UFI_TYPE3R: |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4048 | status = be_flash_BEx(adapter, fw, &flash_cmd, |
| 4049 | num_imgs); |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4050 | break; |
| 4051 | case UFI_TYPE3: |
| 4052 | /* Do not flash this ufi on BE3-R cards */ |
| 4053 | if (adapter->asic_rev < 0x10) |
| 4054 | status = be_flash_BEx(adapter, fw, |
| 4055 | &flash_cmd, |
| 4056 | num_imgs); |
| 4057 | else { |
| 4058 | status = -1; |
| 4059 | dev_err(&adapter->pdev->dev, |
| 4060 | "Can't load BE3 UFI on BE3R\n"); |
| 4061 | } |
| 4062 | } |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4063 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4066 | if (ufi_type == UFI_TYPE2) |
| 4067 | status = be_flash_BEx(adapter, fw, &flash_cmd, 0); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4068 | else if (ufi_type == -1) |
| 4069 | status = -1; |
| 4070 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4071 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 4072 | flash_cmd.dma); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4073 | if (status) { |
| 4074 | dev_err(&adapter->pdev->dev, "Firmware load error\n"); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4075 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 4078 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4079 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4080 | be_fw_exit: |
| 4081 | return status; |
| 4082 | } |
| 4083 | |
| 4084 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 4085 | { |
| 4086 | const struct firmware *fw; |
| 4087 | int status; |
| 4088 | |
| 4089 | if (!netif_running(adapter->netdev)) { |
| 4090 | dev_err(&adapter->pdev->dev, |
| 4091 | "Firmware load not allowed (interface is down)\n"); |
| 4092 | return -1; |
| 4093 | } |
| 4094 | |
| 4095 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 4096 | if (status) |
| 4097 | goto fw_exit; |
| 4098 | |
| 4099 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 4100 | |
| 4101 | if (lancer_chip(adapter)) |
| 4102 | status = lancer_fw_download(adapter, fw); |
| 4103 | else |
| 4104 | status = be_fw_download(adapter, fw); |
| 4105 | |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4106 | if (!status) |
| 4107 | be_cmd_get_fw_ver(adapter, adapter->fw_ver, |
| 4108 | adapter->fw_on_flash); |
| 4109 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4110 | fw_exit: |
| 4111 | release_firmware(fw); |
| 4112 | return status; |
| 4113 | } |
| 4114 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4115 | static int be_ndo_bridge_setlink(struct net_device *dev, |
| 4116 | struct nlmsghdr *nlh) |
| 4117 | { |
| 4118 | struct be_adapter *adapter = netdev_priv(dev); |
| 4119 | struct nlattr *attr, *br_spec; |
| 4120 | int rem; |
| 4121 | int status = 0; |
| 4122 | u16 mode = 0; |
| 4123 | |
| 4124 | if (!sriov_enabled(adapter)) |
| 4125 | return -EOPNOTSUPP; |
| 4126 | |
| 4127 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 4128 | |
| 4129 | nla_for_each_nested(attr, br_spec, rem) { |
| 4130 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 4131 | continue; |
| 4132 | |
| 4133 | mode = nla_get_u16(attr); |
| 4134 | if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) |
| 4135 | return -EINVAL; |
| 4136 | |
| 4137 | status = be_cmd_set_hsw_config(adapter, 0, 0, |
| 4138 | adapter->if_handle, |
| 4139 | mode == BRIDGE_MODE_VEPA ? |
| 4140 | PORT_FWD_TYPE_VEPA : |
| 4141 | PORT_FWD_TYPE_VEB); |
| 4142 | if (status) |
| 4143 | goto err; |
| 4144 | |
| 4145 | dev_info(&adapter->pdev->dev, "enabled switch mode: %s\n", |
| 4146 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4147 | |
| 4148 | return status; |
| 4149 | } |
| 4150 | err: |
| 4151 | dev_err(&adapter->pdev->dev, "Failed to set switch mode %s\n", |
| 4152 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4153 | |
| 4154 | return status; |
| 4155 | } |
| 4156 | |
| 4157 | static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 4158 | struct net_device *dev, |
| 4159 | u32 filter_mask) |
| 4160 | { |
| 4161 | struct be_adapter *adapter = netdev_priv(dev); |
| 4162 | int status = 0; |
| 4163 | u8 hsw_mode; |
| 4164 | |
| 4165 | if (!sriov_enabled(adapter)) |
| 4166 | return 0; |
| 4167 | |
| 4168 | /* BE and Lancer chips support VEB mode only */ |
| 4169 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
| 4170 | hsw_mode = PORT_FWD_TYPE_VEB; |
| 4171 | } else { |
| 4172 | status = be_cmd_get_hsw_config(adapter, NULL, 0, |
| 4173 | adapter->if_handle, &hsw_mode); |
| 4174 | if (status) |
| 4175 | return 0; |
| 4176 | } |
| 4177 | |
| 4178 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
| 4179 | hsw_mode == PORT_FWD_TYPE_VEPA ? |
| 4180 | BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB); |
| 4181 | } |
| 4182 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4183 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4184 | static void be_add_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 4185 | __be16 port) |
| 4186 | { |
| 4187 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4188 | struct device *dev = &adapter->pdev->dev; |
| 4189 | int status; |
| 4190 | |
| 4191 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 4192 | return; |
| 4193 | |
| 4194 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) { |
| 4195 | dev_warn(dev, "Cannot add UDP port %d for VxLAN offloads\n", |
| 4196 | be16_to_cpu(port)); |
| 4197 | dev_info(dev, |
| 4198 | "Only one UDP port supported for VxLAN offloads\n"); |
| 4199 | return; |
| 4200 | } |
| 4201 | |
| 4202 | status = be_cmd_manage_iface(adapter, adapter->if_handle, |
| 4203 | OP_CONVERT_NORMAL_TO_TUNNEL); |
| 4204 | if (status) { |
| 4205 | dev_warn(dev, "Failed to convert normal interface to tunnel\n"); |
| 4206 | goto err; |
| 4207 | } |
| 4208 | |
| 4209 | status = be_cmd_set_vxlan_port(adapter, port); |
| 4210 | if (status) { |
| 4211 | dev_warn(dev, "Failed to add VxLAN port\n"); |
| 4212 | goto err; |
| 4213 | } |
| 4214 | adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS; |
| 4215 | adapter->vxlan_port = port; |
| 4216 | |
| 4217 | dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n", |
| 4218 | be16_to_cpu(port)); |
| 4219 | return; |
| 4220 | err: |
| 4221 | be_disable_vxlan_offloads(adapter); |
| 4222 | return; |
| 4223 | } |
| 4224 | |
| 4225 | static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 4226 | __be16 port) |
| 4227 | { |
| 4228 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4229 | |
| 4230 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 4231 | return; |
| 4232 | |
| 4233 | if (adapter->vxlan_port != port) |
| 4234 | return; |
| 4235 | |
| 4236 | be_disable_vxlan_offloads(adapter); |
| 4237 | |
| 4238 | dev_info(&adapter->pdev->dev, |
| 4239 | "Disabled VxLAN offloads for UDP port %d\n", |
| 4240 | be16_to_cpu(port)); |
| 4241 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4242 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4243 | |
stephen hemminger | e5686ad | 2012-01-05 19:10:25 +0000 | [diff] [blame] | 4244 | static const struct net_device_ops be_netdev_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4245 | .ndo_open = be_open, |
| 4246 | .ndo_stop = be_close, |
| 4247 | .ndo_start_xmit = be_xmit, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4248 | .ndo_set_rx_mode = be_set_rx_mode, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4249 | .ndo_set_mac_address = be_mac_addr_set, |
| 4250 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 4251 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4252 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4253 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 4254 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 4255 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 4256 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 4257 | .ndo_set_vf_tx_rate = be_set_vf_tx_rate, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4258 | .ndo_get_vf_config = be_get_vf_config, |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4259 | .ndo_set_vf_link_state = be_set_vf_link_state, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4260 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4261 | .ndo_poll_controller = be_netpoll, |
| 4262 | #endif |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4263 | .ndo_bridge_setlink = be_ndo_bridge_setlink, |
| 4264 | .ndo_bridge_getlink = be_ndo_bridge_getlink, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 4265 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4266 | .ndo_busy_poll = be_busy_poll, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 4267 | #endif |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4268 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4269 | .ndo_add_vxlan_port = be_add_vxlan_port, |
| 4270 | .ndo_del_vxlan_port = be_del_vxlan_port, |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4271 | #endif |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4272 | }; |
| 4273 | |
| 4274 | static void be_netdev_init(struct net_device *netdev) |
| 4275 | { |
| 4276 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4277 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4278 | if (skyhawk_chip(adapter)) { |
| 4279 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4280 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 4281 | NETIF_F_GSO_UDP_TUNNEL; |
| 4282 | netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL; |
| 4283 | } |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 4284 | 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] | 4285 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4286 | NETIF_F_HW_VLAN_CTAG_TX; |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 4287 | if (be_multi_rxq(adapter)) |
| 4288 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 4289 | |
| 4290 | netdev->features |= netdev->hw_features | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4291 | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 4292 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 4293 | 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] | 4294 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 4295 | |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 4296 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 4297 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4298 | netdev->flags |= IFF_MULTICAST; |
| 4299 | |
Sarveshwar Bandi | b7e5887 | 2012-06-13 19:51:43 +0000 | [diff] [blame] | 4300 | netif_set_gso_max_size(netdev, 65535 - ETH_HLEN); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 4301 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4302 | netdev->netdev_ops = &be_netdev_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4303 | |
| 4304 | SET_ETHTOOL_OPS(netdev, &be_ethtool_ops); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 4308 | { |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4309 | if (adapter->csr) |
| 4310 | pci_iounmap(adapter->pdev, adapter->csr); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4311 | if (adapter->db) |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4312 | pci_iounmap(adapter->pdev, adapter->db); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4315 | static int db_bar(struct be_adapter *adapter) |
| 4316 | { |
| 4317 | if (lancer_chip(adapter) || !be_physfn(adapter)) |
| 4318 | return 0; |
| 4319 | else |
| 4320 | return 4; |
| 4321 | } |
| 4322 | |
| 4323 | static int be_roce_map_pci_bars(struct be_adapter *adapter) |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4324 | { |
Sathya Perla | dbf0f2a | 2012-11-06 17:49:00 +0000 | [diff] [blame] | 4325 | if (skyhawk_chip(adapter)) { |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4326 | adapter->roce_db.size = 4096; |
| 4327 | adapter->roce_db.io_addr = pci_resource_start(adapter->pdev, |
| 4328 | db_bar(adapter)); |
| 4329 | adapter->roce_db.total_size = pci_resource_len(adapter->pdev, |
| 4330 | db_bar(adapter)); |
| 4331 | } |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4332 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 4336 | { |
| 4337 | u8 __iomem *addr; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 4338 | |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4339 | if (BEx_chip(adapter) && be_physfn(adapter)) { |
| 4340 | adapter->csr = pci_iomap(adapter->pdev, 2, 0); |
| 4341 | if (adapter->csr == NULL) |
| 4342 | return -ENOMEM; |
| 4343 | } |
| 4344 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4345 | addr = pci_iomap(adapter->pdev, db_bar(adapter), 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4346 | if (addr == NULL) |
| 4347 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4348 | adapter->db = addr; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4349 | |
| 4350 | be_roce_map_pci_bars(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4351 | return 0; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4352 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4353 | pci_map_err: |
| 4354 | be_unmap_pci_bars(adapter); |
| 4355 | return -ENOMEM; |
| 4356 | } |
| 4357 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4358 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 4359 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4360 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4361 | |
| 4362 | be_unmap_pci_bars(adapter); |
| 4363 | |
| 4364 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4365 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 4366 | mem->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4367 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4368 | mem = &adapter->rx_filter; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4369 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4370 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 4371 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4372 | } |
| 4373 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4374 | static int be_ctrl_init(struct be_adapter *adapter) |
| 4375 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4376 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 4377 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4378 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4379 | u32 sli_intf; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4380 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4381 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4382 | pci_read_config_dword(adapter->pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 4383 | adapter->sli_family = (sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 4384 | SLI_INTF_FAMILY_SHIFT; |
| 4385 | adapter->virtfn = (sli_intf & SLI_INTF_FT_MASK) ? 1 : 0; |
| 4386 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4387 | status = be_map_pci_bars(adapter); |
| 4388 | if (status) |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4389 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4390 | |
| 4391 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4392 | mbox_mem_alloc->va = dma_alloc_coherent(&adapter->pdev->dev, |
| 4393 | mbox_mem_alloc->size, |
| 4394 | &mbox_mem_alloc->dma, |
| 4395 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4396 | if (!mbox_mem_alloc->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4397 | status = -ENOMEM; |
| 4398 | goto unmap_pci_bars; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4399 | } |
| 4400 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 4401 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 4402 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 4403 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4404 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4405 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 4406 | rx_filter->va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 4407 | rx_filter->size, &rx_filter->dma, |
| 4408 | GFP_KERNEL); |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4409 | if (rx_filter->va == NULL) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4410 | status = -ENOMEM; |
| 4411 | goto free_mbox; |
| 4412 | } |
Joe Perches | 1f9061d2 | 2013-03-15 07:23:58 +0000 | [diff] [blame] | 4413 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 4414 | mutex_init(&adapter->mbox_lock); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4415 | spin_lock_init(&adapter->mcc_lock); |
| 4416 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4417 | |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 4418 | init_completion(&adapter->et_cmd_compl); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4419 | pci_save_state(adapter->pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4420 | return 0; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4421 | |
| 4422 | free_mbox: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4423 | dma_free_coherent(&adapter->pdev->dev, mbox_mem_alloc->size, |
| 4424 | mbox_mem_alloc->va, mbox_mem_alloc->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4425 | |
| 4426 | unmap_pci_bars: |
| 4427 | be_unmap_pci_bars(adapter); |
| 4428 | |
| 4429 | done: |
| 4430 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 4434 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 4435 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4436 | |
| 4437 | if (cmd->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4438 | dma_free_coherent(&adapter->pdev->dev, cmd->size, |
| 4439 | cmd->va, cmd->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | static int be_stats_init(struct be_adapter *adapter) |
| 4443 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 4444 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4445 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4446 | if (lancer_chip(adapter)) |
| 4447 | cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 4448 | else if (BE2_chip(adapter)) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 4449 | cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 4450 | else if (BE3_chip(adapter)) |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4451 | cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 4452 | else |
| 4453 | /* ALL non-BE ASICs */ |
| 4454 | cmd->size = sizeof(struct be_cmd_req_get_stats_v2); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4455 | |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 4456 | cmd->va = dma_zalloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma, |
| 4457 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4458 | if (cmd->va == NULL) |
| 4459 | return -1; |
| 4460 | return 0; |
| 4461 | } |
| 4462 | |
Bill Pemberton | 3bc6b06 | 2012-12-03 09:23:09 -0500 | [diff] [blame] | 4463 | static void be_remove(struct pci_dev *pdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4464 | { |
| 4465 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 4466 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4467 | if (!adapter) |
| 4468 | return; |
| 4469 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4470 | be_roce_dev_remove(adapter); |
Somnath Kotur | 8cef7a7 | 2013-03-14 02:41:51 +0000 | [diff] [blame] | 4471 | be_intr_set(adapter, false); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4472 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4473 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
| 4474 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4475 | unregister_netdev(adapter->netdev); |
| 4476 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4477 | be_clear(adapter); |
| 4478 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 4479 | /* tell fw we're done with firing cmds */ |
| 4480 | be_cmd_fw_clean(adapter); |
| 4481 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4482 | be_stats_cleanup(adapter); |
| 4483 | |
| 4484 | be_ctrl_cleanup(adapter); |
| 4485 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 4486 | pci_disable_pcie_error_reporting(pdev); |
| 4487 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4488 | pci_release_regions(pdev); |
| 4489 | pci_disable_device(pdev); |
| 4490 | |
| 4491 | free_netdev(adapter->netdev); |
| 4492 | } |
| 4493 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4494 | static int be_get_initial_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4495 | { |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4496 | int status, level; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 4497 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 4498 | status = be_cmd_get_cntl_attributes(adapter); |
| 4499 | if (status) |
| 4500 | return status; |
| 4501 | |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 4502 | /* Must be a power of 2 or else MODULO will BUG_ON */ |
| 4503 | adapter->be_get_temp_freq = 64; |
| 4504 | |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4505 | if (BEx_chip(adapter)) { |
| 4506 | level = be_cmd_get_fw_log_level(adapter); |
| 4507 | adapter->msg_enable = |
| 4508 | level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0; |
| 4509 | } |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4510 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4511 | adapter->cfg_num_qs = netif_get_num_default_rss_queues(); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4512 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4515 | static int lancer_recover_func(struct be_adapter *adapter) |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4516 | { |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4517 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4518 | int status; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4519 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4520 | status = lancer_test_and_set_rdy_state(adapter); |
| 4521 | if (status) |
| 4522 | goto err; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4523 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4524 | if (netif_running(adapter->netdev)) |
| 4525 | be_close(adapter->netdev); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4526 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4527 | be_clear(adapter); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4528 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4529 | be_clear_all_error(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4530 | |
| 4531 | status = be_setup(adapter); |
| 4532 | if (status) |
| 4533 | goto err; |
| 4534 | |
| 4535 | if (netif_running(adapter->netdev)) { |
| 4536 | status = be_open(adapter->netdev); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4537 | if (status) |
| 4538 | goto err; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4539 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4540 | |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 4541 | dev_err(dev, "Adapter recovery successful\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4542 | return 0; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4543 | err: |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4544 | if (status == -EAGAIN) |
| 4545 | dev_err(dev, "Waiting for resource provisioning\n"); |
| 4546 | else |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 4547 | dev_err(dev, "Adapter recovery failed\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4548 | |
| 4549 | return status; |
| 4550 | } |
| 4551 | |
| 4552 | static void be_func_recovery_task(struct work_struct *work) |
| 4553 | { |
| 4554 | struct be_adapter *adapter = |
| 4555 | container_of(work, struct be_adapter, func_recovery_work.work); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4556 | int status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4557 | |
| 4558 | be_detect_error(adapter); |
| 4559 | |
| 4560 | if (adapter->hw_error && lancer_chip(adapter)) { |
| 4561 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4562 | rtnl_lock(); |
| 4563 | netif_device_detach(adapter->netdev); |
| 4564 | rtnl_unlock(); |
| 4565 | |
| 4566 | status = lancer_recover_func(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4567 | if (!status) |
| 4568 | netif_device_attach(adapter->netdev); |
| 4569 | } |
| 4570 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4571 | /* In Lancer, for all errors other than provisioning error (-EAGAIN), |
| 4572 | * no need to attempt further recovery. |
| 4573 | */ |
| 4574 | if (!status || status == -EAGAIN) |
| 4575 | schedule_delayed_work(&adapter->func_recovery_work, |
| 4576 | msecs_to_jiffies(1000)); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | static void be_worker(struct work_struct *work) |
| 4580 | { |
| 4581 | struct be_adapter *adapter = |
| 4582 | container_of(work, struct be_adapter, work.work); |
| 4583 | struct be_rx_obj *rxo; |
| 4584 | int i; |
| 4585 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4586 | /* when interrupts are not yet enabled, just reap any pending |
| 4587 | * mcc completions */ |
| 4588 | if (!netif_running(adapter->netdev)) { |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 4589 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4590 | be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 4591 | local_bh_enable(); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4592 | goto reschedule; |
| 4593 | } |
| 4594 | |
| 4595 | if (!adapter->stats_cmd_sent) { |
| 4596 | if (lancer_chip(adapter)) |
| 4597 | lancer_cmd_get_pport_stats(adapter, |
| 4598 | &adapter->stats_cmd); |
| 4599 | else |
| 4600 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 4601 | } |
| 4602 | |
Vasundhara Volam | d696b5e | 2013-08-06 09:27:16 +0530 | [diff] [blame] | 4603 | if (be_physfn(adapter) && |
| 4604 | MODULO(adapter->work_counter, adapter->be_get_temp_freq) == 0) |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 4605 | be_cmd_get_die_temperature(adapter); |
| 4606 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4607 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 4608 | /* Replenish RX-queues starved due to memory |
| 4609 | * allocation failures. |
| 4610 | */ |
| 4611 | if (rxo->rx_post_starved) |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4612 | be_post_rx_frags(rxo, GFP_KERNEL); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4613 | } |
| 4614 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 4615 | be_eqd_update(adapter); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4616 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4617 | reschedule: |
| 4618 | adapter->work_counter++; |
| 4619 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 4620 | } |
| 4621 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 4622 | /* If any VFs are already enabled don't FLR the PF */ |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4623 | static bool be_reset_required(struct be_adapter *adapter) |
| 4624 | { |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 4625 | return pci_num_vf(adapter->pdev) ? false : true; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 4628 | static char *mc_name(struct be_adapter *adapter) |
| 4629 | { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4630 | char *str = ""; /* default */ |
| 4631 | |
| 4632 | switch (adapter->mc_type) { |
| 4633 | case UMC: |
| 4634 | str = "UMC"; |
| 4635 | break; |
| 4636 | case FLEX10: |
| 4637 | str = "FLEX10"; |
| 4638 | break; |
| 4639 | case vNIC1: |
| 4640 | str = "vNIC-1"; |
| 4641 | break; |
| 4642 | case nPAR: |
| 4643 | str = "nPAR"; |
| 4644 | break; |
| 4645 | case UFP: |
| 4646 | str = "UFP"; |
| 4647 | break; |
| 4648 | case vNIC2: |
| 4649 | str = "vNIC-2"; |
| 4650 | break; |
| 4651 | default: |
| 4652 | str = ""; |
| 4653 | } |
| 4654 | |
| 4655 | return str; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | static inline char *func_name(struct be_adapter *adapter) |
| 4659 | { |
| 4660 | return be_physfn(adapter) ? "PF" : "VF"; |
| 4661 | } |
| 4662 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 4663 | static int be_probe(struct pci_dev *pdev, const struct pci_device_id *pdev_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4664 | { |
| 4665 | int status = 0; |
| 4666 | struct be_adapter *adapter; |
| 4667 | struct net_device *netdev; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4668 | char port_name; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4669 | |
| 4670 | status = pci_enable_device(pdev); |
| 4671 | if (status) |
| 4672 | goto do_none; |
| 4673 | |
| 4674 | status = pci_request_regions(pdev, DRV_NAME); |
| 4675 | if (status) |
| 4676 | goto disable_dev; |
| 4677 | pci_set_master(pdev); |
| 4678 | |
Sathya Perla | 7f64006 | 2012-06-05 19:37:20 +0000 | [diff] [blame] | 4679 | netdev = alloc_etherdev_mqs(sizeof(*adapter), MAX_TX_QS, MAX_RX_QS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4680 | if (netdev == NULL) { |
| 4681 | status = -ENOMEM; |
| 4682 | goto rel_reg; |
| 4683 | } |
| 4684 | adapter = netdev_priv(netdev); |
| 4685 | adapter->pdev = pdev; |
| 4686 | pci_set_drvdata(pdev, adapter); |
| 4687 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4688 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4689 | |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 4690 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4691 | if (!status) { |
| 4692 | netdev->features |= NETIF_F_HIGHDMA; |
| 4693 | } else { |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 4694 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4695 | if (status) { |
| 4696 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 4697 | goto free_netdev; |
| 4698 | } |
| 4699 | } |
| 4700 | |
Ajit Khaparde | ea58c18 | 2013-10-18 16:06:24 -0500 | [diff] [blame] | 4701 | if (be_physfn(adapter)) { |
| 4702 | status = pci_enable_pcie_error_reporting(pdev); |
| 4703 | if (!status) |
| 4704 | dev_info(&pdev->dev, "PCIe error reporting enabled\n"); |
| 4705 | } |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 4706 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4707 | status = be_ctrl_init(adapter); |
| 4708 | if (status) |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4709 | goto free_netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4710 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4711 | /* sync up with fw's ready state */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 4712 | if (be_physfn(adapter)) { |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 4713 | status = be_fw_wait_ready(adapter); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 4714 | if (status) |
| 4715 | goto ctrl_clean; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 4716 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4717 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4718 | if (be_reset_required(adapter)) { |
| 4719 | status = be_cmd_reset_function(adapter); |
| 4720 | if (status) |
| 4721 | goto ctrl_clean; |
Sarveshwar Bandi | 556ae19 | 2010-05-24 18:38:25 -0700 | [diff] [blame] | 4722 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 4723 | /* Wait for interrupts to quiesce after an FLR */ |
| 4724 | msleep(100); |
| 4725 | } |
Somnath Kotur | 8cef7a7 | 2013-03-14 02:41:51 +0000 | [diff] [blame] | 4726 | |
| 4727 | /* Allow interrupts for other ULPs running on NIC function */ |
| 4728 | be_intr_set(adapter, true); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4729 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 4730 | /* tell fw we're ready to fire cmds */ |
| 4731 | status = be_cmd_fw_init(adapter); |
| 4732 | if (status) |
| 4733 | goto ctrl_clean; |
| 4734 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4735 | status = be_stats_init(adapter); |
| 4736 | if (status) |
| 4737 | goto ctrl_clean; |
| 4738 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4739 | status = be_get_initial_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4740 | if (status) |
| 4741 | goto stats_clean; |
| 4742 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4743 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4744 | INIT_DELAYED_WORK(&adapter->func_recovery_work, be_func_recovery_task); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4745 | adapter->rx_fc = adapter->tx_fc = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4746 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4747 | status = be_setup(adapter); |
| 4748 | if (status) |
Sathya Perla | 55f5c3c | 2012-09-28 04:39:42 +0000 | [diff] [blame] | 4749 | goto stats_clean; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4750 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 4751 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4752 | status = register_netdev(netdev); |
| 4753 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4754 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4755 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4756 | be_roce_dev_add(adapter); |
| 4757 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4758 | schedule_delayed_work(&adapter->func_recovery_work, |
| 4759 | msecs_to_jiffies(1000)); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4760 | |
| 4761 | be_cmd_query_port_name(adapter, &port_name); |
| 4762 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 4763 | dev_info(&pdev->dev, "%s: %s %s port %c\n", nic_name(pdev), |
| 4764 | func_name(adapter), mc_name(adapter), port_name); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 4765 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4766 | return 0; |
| 4767 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4768 | unsetup: |
| 4769 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4770 | stats_clean: |
| 4771 | be_stats_cleanup(adapter); |
| 4772 | ctrl_clean: |
| 4773 | be_ctrl_cleanup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4774 | free_netdev: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 4775 | free_netdev(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4776 | rel_reg: |
| 4777 | pci_release_regions(pdev); |
| 4778 | disable_dev: |
| 4779 | pci_disable_device(pdev); |
| 4780 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 4781 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4782 | return status; |
| 4783 | } |
| 4784 | |
| 4785 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4786 | { |
| 4787 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 4788 | struct net_device *netdev = adapter->netdev; |
| 4789 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4790 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 4791 | be_setup_wol(adapter, true); |
| 4792 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 4793 | be_intr_set(adapter, false); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4794 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
| 4795 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4796 | netif_device_detach(netdev); |
| 4797 | if (netif_running(netdev)) { |
| 4798 | rtnl_lock(); |
| 4799 | be_close(netdev); |
| 4800 | rtnl_unlock(); |
| 4801 | } |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 4802 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4803 | |
| 4804 | pci_save_state(pdev); |
| 4805 | pci_disable_device(pdev); |
| 4806 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 4807 | return 0; |
| 4808 | } |
| 4809 | |
| 4810 | static int be_resume(struct pci_dev *pdev) |
| 4811 | { |
| 4812 | int status = 0; |
| 4813 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 4814 | struct net_device *netdev = adapter->netdev; |
| 4815 | |
| 4816 | netif_device_detach(netdev); |
| 4817 | |
| 4818 | status = pci_enable_device(pdev); |
| 4819 | if (status) |
| 4820 | return status; |
| 4821 | |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 4822 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4823 | pci_restore_state(pdev); |
| 4824 | |
Sarveshwar Bandi | dd5746b | 2013-08-23 14:59:33 +0530 | [diff] [blame] | 4825 | status = be_fw_wait_ready(adapter); |
| 4826 | if (status) |
| 4827 | return status; |
| 4828 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 4829 | be_intr_set(adapter, true); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4830 | /* tell fw we're ready to fire cmds */ |
| 4831 | status = be_cmd_fw_init(adapter); |
| 4832 | if (status) |
| 4833 | return status; |
| 4834 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 4835 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4836 | if (netif_running(netdev)) { |
| 4837 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4838 | be_open(netdev); |
| 4839 | rtnl_unlock(); |
| 4840 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4841 | |
| 4842 | schedule_delayed_work(&adapter->func_recovery_work, |
| 4843 | msecs_to_jiffies(1000)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4844 | netif_device_attach(netdev); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 4845 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4846 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 4847 | be_setup_wol(adapter, false); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 4848 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4849 | return 0; |
| 4850 | } |
| 4851 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4852 | /* |
| 4853 | * An FLR will stop BE from DMAing any data. |
| 4854 | */ |
| 4855 | static void be_shutdown(struct pci_dev *pdev) |
| 4856 | { |
| 4857 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4858 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 4859 | if (!adapter) |
| 4860 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4861 | |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 4862 | cancel_delayed_work_sync(&adapter->work); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4863 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 4864 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 4865 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4866 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 4867 | be_cmd_reset_function(adapter); |
| 4868 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4869 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4872 | static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev, |
| 4873 | pci_channel_state_t state) |
| 4874 | { |
| 4875 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 4876 | struct net_device *netdev = adapter->netdev; |
| 4877 | |
| 4878 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 4879 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4880 | if (!adapter->eeh_error) { |
| 4881 | adapter->eeh_error = true; |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4882 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4883 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4884 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4885 | rtnl_lock(); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4886 | netif_device_detach(netdev); |
| 4887 | if (netif_running(netdev)) |
| 4888 | be_close(netdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4889 | rtnl_unlock(); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4890 | |
| 4891 | be_clear(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4892 | } |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4893 | |
| 4894 | if (state == pci_channel_io_perm_failure) |
| 4895 | return PCI_ERS_RESULT_DISCONNECT; |
| 4896 | |
| 4897 | pci_disable_device(pdev); |
| 4898 | |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 4899 | /* The error could cause the FW to trigger a flash debug dump. |
| 4900 | * Resetting the card while flash dump is in progress |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 4901 | * can cause it not to recover; wait for it to finish. |
| 4902 | * Wait only for first function as it is needed only once per |
| 4903 | * adapter. |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 4904 | */ |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 4905 | if (pdev->devfn == 0) |
| 4906 | ssleep(30); |
| 4907 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4908 | return PCI_ERS_RESULT_NEED_RESET; |
| 4909 | } |
| 4910 | |
| 4911 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 4912 | { |
| 4913 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 4914 | int status; |
| 4915 | |
| 4916 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4917 | |
| 4918 | status = pci_enable_device(pdev); |
| 4919 | if (status) |
| 4920 | return PCI_ERS_RESULT_DISCONNECT; |
| 4921 | |
| 4922 | pci_set_master(pdev); |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 4923 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4924 | pci_restore_state(pdev); |
| 4925 | |
| 4926 | /* Check if card is ok and fw is ready */ |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4927 | dev_info(&adapter->pdev->dev, |
| 4928 | "Waiting for FW to be ready after EEH reset\n"); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 4929 | status = be_fw_wait_ready(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4930 | if (status) |
| 4931 | return PCI_ERS_RESULT_DISCONNECT; |
| 4932 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 4933 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4934 | be_clear_all_error(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4935 | return PCI_ERS_RESULT_RECOVERED; |
| 4936 | } |
| 4937 | |
| 4938 | static void be_eeh_resume(struct pci_dev *pdev) |
| 4939 | { |
| 4940 | int status = 0; |
| 4941 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 4942 | struct net_device *netdev = adapter->netdev; |
| 4943 | |
| 4944 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 4945 | |
| 4946 | pci_save_state(pdev); |
| 4947 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 4948 | status = be_cmd_reset_function(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4949 | if (status) |
| 4950 | goto err; |
| 4951 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 4952 | /* tell fw we're ready to fire cmds */ |
| 4953 | status = be_cmd_fw_init(adapter); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 4954 | if (status) |
| 4955 | goto err; |
| 4956 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4957 | status = be_setup(adapter); |
| 4958 | if (status) |
| 4959 | goto err; |
| 4960 | |
| 4961 | if (netif_running(netdev)) { |
| 4962 | status = be_open(netdev); |
| 4963 | if (status) |
| 4964 | goto err; |
| 4965 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4966 | |
| 4967 | schedule_delayed_work(&adapter->func_recovery_work, |
| 4968 | msecs_to_jiffies(1000)); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4969 | netif_device_attach(netdev); |
| 4970 | return; |
| 4971 | err: |
| 4972 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 4975 | static const struct pci_error_handlers be_eeh_handlers = { |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4976 | .error_detected = be_eeh_err_detected, |
| 4977 | .slot_reset = be_eeh_reset, |
| 4978 | .resume = be_eeh_resume, |
| 4979 | }; |
| 4980 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4981 | static struct pci_driver be_driver = { |
| 4982 | .name = DRV_NAME, |
| 4983 | .id_table = be_dev_ids, |
| 4984 | .probe = be_probe, |
| 4985 | .remove = be_remove, |
| 4986 | .suspend = be_suspend, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4987 | .resume = be_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 4988 | .shutdown = be_shutdown, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4989 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4990 | }; |
| 4991 | |
| 4992 | static int __init be_init_module(void) |
| 4993 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4994 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 4995 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4996 | printk(KERN_WARNING DRV_NAME |
| 4997 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 4998 | " Using 2048\n"); |
| 4999 | rx_frag_size = 2048; |
| 5000 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5001 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5002 | return pci_register_driver(&be_driver); |
| 5003 | } |
| 5004 | module_init(be_init_module); |
| 5005 | |
| 5006 | static void __exit be_exit_module(void) |
| 5007 | { |
| 5008 | pci_unregister_driver(&be_driver); |
| 5009 | } |
| 5010 | module_exit(be_exit_module); |