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 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 42 | static const struct pci_device_id 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 ", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 84 | "ERX2 ", |
| 85 | "SPARE ", |
| 86 | "JTAG ", |
| 87 | "MPU_INTPEND " |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 88 | }; |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 89 | |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 90 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 91 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 92 | "LPCMEMHOST", |
| 93 | "MGMT_MAC", |
| 94 | "PCS0ONLINE", |
| 95 | "MPU_IRAM", |
| 96 | "PCS1ONLINE", |
| 97 | "PCTL0", |
| 98 | "PCTL1", |
| 99 | "PMEM", |
| 100 | "RR", |
| 101 | "TXPB", |
| 102 | "RXPP", |
| 103 | "XAUI", |
| 104 | "TXP", |
| 105 | "ARM", |
| 106 | "IPC", |
| 107 | "HOST2", |
| 108 | "HOST3", |
| 109 | "HOST4", |
| 110 | "HOST5", |
| 111 | "HOST6", |
| 112 | "HOST7", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 113 | "ECRC", |
| 114 | "Poison TLP", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 115 | "NETC", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 116 | "PERIPH", |
| 117 | "LLTXULP", |
| 118 | "D2P", |
| 119 | "RCON", |
| 120 | "LDMA", |
| 121 | "LLTXP", |
| 122 | "LLTXPB", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 123 | "Unknown" |
| 124 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 125 | |
| 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; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 129 | |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 130 | if (mem->va) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 131 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 132 | mem->dma); |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 133 | mem->va = NULL; |
| 134 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 138 | u16 len, u16 entry_size) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 139 | { |
| 140 | struct be_dma_mem *mem = &q->dma_mem; |
| 141 | |
| 142 | memset(q, 0, sizeof(*q)); |
| 143 | q->len = len; |
| 144 | q->entry_size = entry_size; |
| 145 | mem->size = len * entry_size; |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 146 | mem->va = dma_zalloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 147 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 148 | if (!mem->va) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 149 | return -ENOMEM; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 153 | static void be_reg_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 154 | { |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 155 | u32 reg, enabled; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 156 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 157 | pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 158 | ®); |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 159 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 160 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 161 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 162 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 163 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 164 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 165 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 166 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 167 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 168 | pci_write_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 169 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 172 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
| 173 | { |
| 174 | int status = 0; |
| 175 | |
| 176 | /* On lancer interrupts can't be controlled via this register */ |
| 177 | if (lancer_chip(adapter)) |
| 178 | return; |
| 179 | |
| 180 | if (adapter->eeh_error) |
| 181 | return; |
| 182 | |
| 183 | status = be_cmd_intr_set(adapter, enable); |
| 184 | if (status) |
| 185 | be_reg_intr_set(adapter, enable); |
| 186 | } |
| 187 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 188 | 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] | 189 | { |
| 190 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 191 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 192 | val |= qid & DB_RQ_RING_ID_MASK; |
| 193 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 194 | |
| 195 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 196 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 199 | static void be_txq_notify(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 200 | u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 201 | { |
| 202 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 203 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 204 | val |= txo->q.id & DB_TXULP_RING_ID_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 205 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 206 | |
| 207 | wmb(); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 208 | iowrite32(val, adapter->db + txo->db_offset); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 211 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 212 | bool arm, bool clear_int, u16 num_popped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 213 | { |
| 214 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 215 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 216 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 217 | val |= ((qid & DB_EQ_RING_ID_EXT_MASK) << DB_EQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 218 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 219 | if (adapter->eeh_error) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 220 | return; |
| 221 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 222 | if (arm) |
| 223 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 224 | if (clear_int) |
| 225 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 226 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 227 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 228 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 231 | 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] | 232 | { |
| 233 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 234 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 235 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 236 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 237 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 238 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 239 | if (adapter->eeh_error) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 240 | return; |
| 241 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 242 | if (arm) |
| 243 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 244 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 245 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 248 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 249 | { |
| 250 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 251 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 252 | struct sockaddr *addr = p; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 253 | int status; |
| 254 | u8 mac[ETH_ALEN]; |
| 255 | u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 256 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 257 | if (!is_valid_ether_addr(addr->sa_data)) |
| 258 | return -EADDRNOTAVAIL; |
| 259 | |
Vasundhara Volam | ff32f8a | 2014-01-15 13:23:35 +0530 | [diff] [blame] | 260 | /* Proceed further only if, User provided MAC is different |
| 261 | * from active MAC |
| 262 | */ |
| 263 | if (ether_addr_equal(addr->sa_data, netdev->dev_addr)) |
| 264 | return 0; |
| 265 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 266 | /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT |
| 267 | * privilege or if PF did not provision the new MAC address. |
| 268 | * On BE3, this cmd will always fail if the VF doesn't have the |
| 269 | * FILTMGMT privilege. This failure is OK, only if the PF programmed |
| 270 | * the MAC for the VF. |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 271 | */ |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 272 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
| 273 | adapter->if_handle, &adapter->pmac_id[0], 0); |
| 274 | if (!status) { |
| 275 | curr_pmac_id = adapter->pmac_id[0]; |
| 276 | |
| 277 | /* Delete the old programmed MAC. This call may fail if the |
| 278 | * old MAC was already deleted by the PF driver. |
| 279 | */ |
| 280 | if (adapter->pmac_id[0] != old_pmac_id) |
| 281 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 282 | old_pmac_id, 0); |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 285 | /* Decide if the new MAC is successfully activated only after |
| 286 | * querying the FW |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 287 | */ |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 288 | status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac, |
| 289 | adapter->if_handle, true, 0); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 290 | if (status) |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 291 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 292 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 293 | /* The MAC change did not happen, either due to lack of privilege |
| 294 | * or PF didn't pre-provision. |
| 295 | */ |
dingtianhong | 61d23e9 | 2013-12-30 15:40:43 +0800 | [diff] [blame] | 296 | if (!ether_addr_equal(addr->sa_data, mac)) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 297 | status = -EPERM; |
| 298 | goto err; |
| 299 | } |
| 300 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 301 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 302 | dev_info(dev, "MAC address changed to %pM\n", mac); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | err: |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 305 | 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] | 306 | return status; |
| 307 | } |
| 308 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 309 | /* BE2 supports only v0 cmd */ |
| 310 | static void *hw_stats_from_cmd(struct be_adapter *adapter) |
| 311 | { |
| 312 | if (BE2_chip(adapter)) { |
| 313 | struct be_cmd_resp_get_stats_v0 *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 if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 317 | struct be_cmd_resp_get_stats_v1 *cmd = adapter->stats_cmd.va; |
| 318 | |
| 319 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 320 | } else { |
| 321 | struct be_cmd_resp_get_stats_v2 *cmd = adapter->stats_cmd.va; |
| 322 | |
| 323 | return &cmd->hw_stats; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | /* BE2 supports only v0 cmd */ |
| 328 | static void *be_erx_stats_from_cmd(struct be_adapter *adapter) |
| 329 | { |
| 330 | if (BE2_chip(adapter)) { |
| 331 | struct be_hw_stats_v0 *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 if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 335 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 336 | |
| 337 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 338 | } else { |
| 339 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 340 | |
| 341 | return &hw_stats->erx; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | static void populate_be_v0_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 346 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 347 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 348 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 349 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 350 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 351 | &rxf_stats->port[adapter->port_num]; |
| 352 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 353 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 354 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 355 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 356 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 357 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 358 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 359 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 360 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 361 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 362 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 363 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 364 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 365 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 366 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 367 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 368 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 369 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 370 | drvs->rx_dropped_header_too_small = |
| 371 | port_stats->rx_dropped_header_too_small; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 372 | drvs->rx_address_filtered = |
| 373 | port_stats->rx_address_filtered + |
| 374 | port_stats->rx_vlan_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 375 | drvs->rx_alignment_symbol_errors = |
| 376 | port_stats->rx_alignment_symbol_errors; |
| 377 | |
| 378 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 379 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 380 | |
| 381 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 382 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 383 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 384 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 385 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 386 | 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] | 387 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 388 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 389 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 390 | 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] | 391 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 392 | } |
| 393 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 394 | static void populate_be_v1_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 395 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 396 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 397 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 398 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 399 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 400 | &rxf_stats->port[adapter->port_num]; |
| 401 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 402 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 403 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 02fe702 | 2011-12-09 13:53:09 +0000 | [diff] [blame] | 404 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 405 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 406 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 407 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 408 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 409 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 410 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 411 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 412 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 413 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 414 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 415 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 416 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 417 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 418 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 419 | drvs->rx_dropped_header_too_small = |
| 420 | port_stats->rx_dropped_header_too_small; |
| 421 | drvs->rx_input_fifo_overflow_drop = |
| 422 | port_stats->rx_input_fifo_overflow_drop; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 423 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 424 | drvs->rx_alignment_symbol_errors = |
| 425 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 426 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 427 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 428 | drvs->tx_controlframes = port_stats->tx_controlframes; |
Ajit Khaparde | b5adffc4 | 2013-05-01 09:38:00 +0000 | [diff] [blame] | 429 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 430 | drvs->jabber_events = port_stats->jabber_events; |
| 431 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 432 | 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] | 433 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 434 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 435 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 436 | 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] | 437 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 438 | } |
| 439 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 440 | static void populate_be_v2_stats(struct be_adapter *adapter) |
| 441 | { |
| 442 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 443 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 444 | struct be_rxf_stats_v2 *rxf_stats = &hw_stats->rxf; |
| 445 | struct be_port_rxf_stats_v2 *port_stats = |
| 446 | &rxf_stats->port[adapter->port_num]; |
| 447 | struct be_drv_stats *drvs = &adapter->drv_stats; |
| 448 | |
| 449 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
| 450 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 451 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
| 452 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 453 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 454 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 455 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 456 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 457 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 458 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 459 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 460 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 461 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 462 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 463 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 464 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 465 | drvs->rx_dropped_header_too_small = |
| 466 | port_stats->rx_dropped_header_too_small; |
| 467 | drvs->rx_input_fifo_overflow_drop = |
| 468 | port_stats->rx_input_fifo_overflow_drop; |
| 469 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
| 470 | drvs->rx_alignment_symbol_errors = |
| 471 | port_stats->rx_alignment_symbol_errors; |
| 472 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
| 473 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 474 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 475 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
| 476 | drvs->jabber_events = port_stats->jabber_events; |
| 477 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 478 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 479 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 480 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
| 481 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 482 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
| 483 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 484 | if (be_roce_supported(adapter)) { |
Ajit Khaparde | 461ae37 | 2013-10-03 16:16:50 -0500 | [diff] [blame] | 485 | drvs->rx_roce_bytes_lsd = port_stats->roce_bytes_received_lsd; |
| 486 | drvs->rx_roce_bytes_msd = port_stats->roce_bytes_received_msd; |
| 487 | drvs->rx_roce_frames = port_stats->roce_frames_received; |
| 488 | drvs->roce_drops_crc = port_stats->roce_drops_crc; |
| 489 | drvs->roce_drops_payload_len = |
| 490 | port_stats->roce_drops_payload_len; |
| 491 | } |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 492 | } |
| 493 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 494 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 495 | { |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 496 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 497 | struct lancer_pport_stats *pport_stats = pport_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 498 | |
| 499 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 500 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 501 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 502 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 503 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 504 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 505 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 506 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 507 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 508 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 509 | drvs->rx_dropped_tcp_length = |
| 510 | pport_stats->rx_dropped_invalid_tcp_length; |
| 511 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 512 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 513 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 514 | drvs->rx_dropped_header_too_small = |
| 515 | pport_stats->rx_dropped_header_too_small; |
| 516 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 517 | drvs->rx_address_filtered = |
| 518 | pport_stats->rx_address_filtered + |
| 519 | pport_stats->rx_vlan_filtered; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 520 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 521 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 522 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 523 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 524 | drvs->jabber_events = pport_stats->rx_jabbers; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 525 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 526 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 527 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 528 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 529 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 530 | |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 531 | static void accumulate_16bit_val(u32 *acc, u16 val) |
| 532 | { |
| 533 | #define lo(x) (x & 0xFFFF) |
| 534 | #define hi(x) (x & 0xFFFF0000) |
| 535 | bool wrapped = val < lo(*acc); |
| 536 | u32 newacc = hi(*acc) + val; |
| 537 | |
| 538 | if (wrapped) |
| 539 | newacc += 65536; |
| 540 | ACCESS_ONCE(*acc) = newacc; |
| 541 | } |
| 542 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 543 | static void populate_erx_stats(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 544 | struct be_rx_obj *rxo, u32 erx_stat) |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 545 | { |
| 546 | if (!BEx_chip(adapter)) |
| 547 | rx_stats(rxo)->rx_drops_no_frags = erx_stat; |
| 548 | else |
| 549 | /* below erx HW counter can actually wrap around after |
| 550 | * 65535. Driver accumulates a 32-bit value |
| 551 | */ |
| 552 | accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags, |
| 553 | (u16)erx_stat); |
| 554 | } |
| 555 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 556 | void be_parse_stats(struct be_adapter *adapter) |
| 557 | { |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 558 | struct be_erx_stats_v2 *erx = be_erx_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 559 | struct be_rx_obj *rxo; |
| 560 | int i; |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 561 | u32 erx_stat; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 562 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 563 | if (lancer_chip(adapter)) { |
| 564 | populate_lancer_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 565 | } else { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 566 | if (BE2_chip(adapter)) |
| 567 | populate_be_v0_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 568 | else if (BE3_chip(adapter)) |
| 569 | /* for BE3 */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 570 | populate_be_v1_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 571 | else |
| 572 | populate_be_v2_stats(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 573 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 574 | /* 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] | 575 | for_all_rx_queues(adapter, rxo, i) { |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 576 | erx_stat = erx->rx_drops_no_fragments[rxo->q.id]; |
| 577 | populate_erx_stats(adapter, rxo, erx_stat); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 578 | } |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 579 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 582 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 583 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 584 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 585 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 586 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 587 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 588 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 589 | u64 pkts, bytes; |
| 590 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 591 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 592 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 593 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 594 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 595 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 596 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 597 | start = u64_stats_fetch_begin_irq(&rx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 598 | pkts = rx_stats(rxo)->rx_pkts; |
| 599 | bytes = rx_stats(rxo)->rx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 600 | } while (u64_stats_fetch_retry_irq(&rx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 601 | stats->rx_packets += pkts; |
| 602 | stats->rx_bytes += bytes; |
| 603 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 604 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 605 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 608 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 609 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 610 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 611 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 612 | start = u64_stats_fetch_begin_irq(&tx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 613 | pkts = tx_stats(txo)->tx_pkts; |
| 614 | bytes = tx_stats(txo)->tx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 615 | } while (u64_stats_fetch_retry_irq(&tx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 616 | stats->tx_packets += pkts; |
| 617 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 618 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 619 | |
| 620 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 621 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 622 | drvs->rx_alignment_symbol_errors + |
| 623 | drvs->rx_in_range_errors + |
| 624 | drvs->rx_out_range_errors + |
| 625 | drvs->rx_frame_too_long + |
| 626 | drvs->rx_dropped_too_small + |
| 627 | drvs->rx_dropped_too_short + |
| 628 | drvs->rx_dropped_header_too_small + |
| 629 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 630 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 631 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 632 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 633 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 634 | drvs->rx_out_range_errors + |
| 635 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 636 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 637 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 638 | |
| 639 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 640 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 641 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 642 | /* receiver fifo overrun */ |
| 643 | /* 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] | 644 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 645 | drvs->rx_input_fifo_overflow_drop + |
| 646 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 647 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 650 | void be_link_status_update(struct be_adapter *adapter, u8 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 651 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 652 | struct net_device *netdev = adapter->netdev; |
| 653 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 654 | if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) { |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 655 | netif_carrier_off(netdev); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 656 | adapter->flags |= BE_FLAGS_LINK_STATUS_INIT; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 657 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 658 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 659 | if (link_status) |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 660 | netif_carrier_on(netdev); |
| 661 | else |
| 662 | netif_carrier_off(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 665 | static void be_tx_stats_update(struct be_tx_obj *txo, struct sk_buff *skb) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 666 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 667 | struct be_tx_stats *stats = tx_stats(txo); |
| 668 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 669 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 670 | stats->tx_reqs++; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 671 | stats->tx_bytes += skb->len; |
| 672 | stats->tx_pkts += (skb_shinfo(skb)->gso_segs ? : 1); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 673 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 676 | /* Returns number of WRBs needed for the skb */ |
| 677 | static u32 skb_wrb_cnt(struct sk_buff *skb) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 678 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 679 | /* +1 for the header wrb */ |
| 680 | return 1 + (skb_headlen(skb) ? 1 : 0) + skb_shinfo(skb)->nr_frags; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 684 | { |
| 685 | wrb->frag_pa_hi = upper_32_bits(addr); |
| 686 | wrb->frag_pa_lo = addr & 0xFFFFFFFF; |
| 687 | wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK; |
Somnath Kotur | 89b1f49 | 2012-06-24 19:40:55 +0000 | [diff] [blame] | 688 | wrb->rsvd0 = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 691 | static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 692 | struct sk_buff *skb) |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 693 | { |
| 694 | u8 vlan_prio; |
| 695 | u16 vlan_tag; |
| 696 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 697 | vlan_tag = skb_vlan_tag_get(skb); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 698 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 699 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 700 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 701 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
| 702 | adapter->recommended_prio; |
| 703 | |
| 704 | return vlan_tag; |
| 705 | } |
| 706 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 707 | /* Used only for IP tunnel packets */ |
| 708 | static u16 skb_inner_ip_proto(struct sk_buff *skb) |
| 709 | { |
| 710 | return (inner_ip_hdr(skb)->version == 4) ? |
| 711 | inner_ip_hdr(skb)->protocol : inner_ipv6_hdr(skb)->nexthdr; |
| 712 | } |
| 713 | |
| 714 | static u16 skb_ip_proto(struct sk_buff *skb) |
| 715 | { |
| 716 | return (ip_hdr(skb)->version == 4) ? |
| 717 | ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr; |
| 718 | } |
| 719 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 720 | static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 721 | struct sk_buff *skb, u32 wrb_cnt, u32 len, |
| 722 | bool skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 723 | { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 724 | u16 vlan_tag, proto; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 725 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 726 | memset(hdr, 0, sizeof(*hdr)); |
| 727 | |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 728 | SET_TX_WRB_HDR_BITS(crc, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 729 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 730 | if (skb_is_gso(skb)) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 731 | SET_TX_WRB_HDR_BITS(lso, hdr, 1); |
| 732 | SET_TX_WRB_HDR_BITS(lso_mss, hdr, skb_shinfo(skb)->gso_size); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 733 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 734 | SET_TX_WRB_HDR_BITS(lso6, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 735 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 736 | if (skb->encapsulation) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 737 | SET_TX_WRB_HDR_BITS(ipcs, hdr, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 738 | proto = skb_inner_ip_proto(skb); |
| 739 | } else { |
| 740 | proto = skb_ip_proto(skb); |
| 741 | } |
| 742 | if (proto == IPPROTO_TCP) |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 743 | SET_TX_WRB_HDR_BITS(tcpcs, hdr, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 744 | else if (proto == IPPROTO_UDP) |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 745 | SET_TX_WRB_HDR_BITS(udpcs, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 748 | if (skb_vlan_tag_present(skb)) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 749 | SET_TX_WRB_HDR_BITS(vlan, hdr, 1); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 750 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 751 | SET_TX_WRB_HDR_BITS(vlan_tag, hdr, vlan_tag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 754 | SET_TX_WRB_HDR_BITS(num_wrb, hdr, wrb_cnt); |
| 755 | SET_TX_WRB_HDR_BITS(len, hdr, len); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 756 | |
| 757 | /* Hack to skip HW VLAN tagging needs evt = 1, compl = 0 |
| 758 | * When this hack is not needed, the evt bit is set while ringing DB |
| 759 | */ |
| 760 | if (skip_hw_vlan) |
| 761 | SET_TX_WRB_HDR_BITS(event, hdr, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 764 | static void unmap_tx_frag(struct device *dev, struct be_eth_wrb *wrb, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 765 | bool unmap_single) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 766 | { |
| 767 | dma_addr_t dma; |
| 768 | |
| 769 | be_dws_le_to_cpu(wrb, sizeof(*wrb)); |
| 770 | |
| 771 | dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo; |
FUJITA Tomonori | b681ee7 | 2010-04-04 21:40:18 +0000 | [diff] [blame] | 772 | if (wrb->frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 773 | if (unmap_single) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 774 | dma_unmap_single(dev, dma, wrb->frag_len, |
| 775 | DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 776 | else |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 777 | dma_unmap_page(dev, dma, wrb->frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 778 | } |
| 779 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 780 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 781 | /* Returns the number of WRBs used up by the skb */ |
| 782 | static u32 be_xmit_enqueue(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 783 | struct sk_buff *skb, bool skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 784 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 785 | u32 i, copied = 0, wrb_cnt = skb_wrb_cnt(skb); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 786 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 787 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 788 | struct be_eth_hdr_wrb *hdr; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 789 | bool map_single = false; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 790 | struct be_eth_wrb *wrb; |
| 791 | dma_addr_t busaddr; |
| 792 | u16 head = txq->head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 793 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 794 | hdr = queue_head_node(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 795 | wrb_fill_hdr(adapter, hdr, skb, wrb_cnt, skb->len, skip_hw_vlan); |
| 796 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 797 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 798 | queue_head_inc(txq); |
| 799 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 800 | if (skb->len > skb->data_len) { |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 801 | int len = skb_headlen(skb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 802 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 803 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 804 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 805 | goto dma_err; |
| 806 | map_single = true; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 807 | wrb = queue_head_node(txq); |
| 808 | wrb_fill(wrb, busaddr, len); |
| 809 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 810 | queue_head_inc(txq); |
| 811 | copied += len; |
| 812 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 813 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 814 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 815 | const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 816 | |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 817 | busaddr = skb_frag_dma_map(dev, frag, 0, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 818 | skb_frag_size(frag), DMA_TO_DEVICE); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 819 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 820 | goto dma_err; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 821 | wrb = queue_head_node(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 822 | wrb_fill(wrb, busaddr, skb_frag_size(frag)); |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 823 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 824 | queue_head_inc(txq); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 825 | copied += skb_frag_size(frag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 828 | BUG_ON(txo->sent_skb_list[head]); |
| 829 | txo->sent_skb_list[head] = skb; |
| 830 | txo->last_req_hdr = head; |
| 831 | atomic_add(wrb_cnt, &txq->used); |
| 832 | txo->last_req_wrb_cnt = wrb_cnt; |
| 833 | txo->pend_wrb_cnt += wrb_cnt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 834 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 835 | be_tx_stats_update(txo, skb); |
| 836 | return wrb_cnt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 837 | |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 838 | dma_err: |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 839 | /* Bring the queue back to the state it was in before this |
| 840 | * routine was invoked. |
| 841 | */ |
| 842 | txq->head = head; |
| 843 | /* skip the first wrb (hdr); it's not mapped */ |
| 844 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 845 | while (copied) { |
| 846 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 847 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 848 | map_single = false; |
| 849 | copied -= wrb->frag_len; |
Vasundhara Volam | d3de154 | 2014-09-02 09:56:50 +0530 | [diff] [blame] | 850 | adapter->drv_stats.dma_map_errors++; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 851 | queue_head_inc(txq); |
| 852 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 853 | txq->head = head; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 854 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 857 | static inline int qnq_async_evt_rcvd(struct be_adapter *adapter) |
| 858 | { |
| 859 | return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD; |
| 860 | } |
| 861 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 862 | 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] | 863 | struct sk_buff *skb, |
| 864 | bool *skip_hw_vlan) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 865 | { |
| 866 | u16 vlan_tag = 0; |
| 867 | |
| 868 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 869 | if (unlikely(!skb)) |
| 870 | return skb; |
| 871 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 872 | if (skb_vlan_tag_present(skb)) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 873 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 874 | |
| 875 | if (qnq_async_evt_rcvd(adapter) && adapter->pvid) { |
| 876 | if (!vlan_tag) |
| 877 | vlan_tag = adapter->pvid; |
| 878 | /* f/w workaround to set skip_hw_vlan = 1, informs the F/W to |
| 879 | * skip VLAN insertion |
| 880 | */ |
| 881 | if (skip_hw_vlan) |
| 882 | *skip_hw_vlan = true; |
| 883 | } |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 884 | |
| 885 | if (vlan_tag) { |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 886 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 887 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 888 | if (unlikely(!skb)) |
| 889 | return skb; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 890 | skb->vlan_tci = 0; |
| 891 | } |
| 892 | |
| 893 | /* Insert the outer VLAN, if any */ |
| 894 | if (adapter->qnq_vid) { |
| 895 | vlan_tag = adapter->qnq_vid; |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 896 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 897 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 898 | if (unlikely(!skb)) |
| 899 | return skb; |
| 900 | if (skip_hw_vlan) |
| 901 | *skip_hw_vlan = true; |
| 902 | } |
| 903 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 904 | return skb; |
| 905 | } |
| 906 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 907 | static bool be_ipv6_exthdr_check(struct sk_buff *skb) |
| 908 | { |
| 909 | struct ethhdr *eh = (struct ethhdr *)skb->data; |
| 910 | u16 offset = ETH_HLEN; |
| 911 | |
| 912 | if (eh->h_proto == htons(ETH_P_IPV6)) { |
| 913 | struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + offset); |
| 914 | |
| 915 | offset += sizeof(struct ipv6hdr); |
| 916 | if (ip6h->nexthdr != NEXTHDR_TCP && |
| 917 | ip6h->nexthdr != NEXTHDR_UDP) { |
| 918 | struct ipv6_opt_hdr *ehdr = |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 919 | (struct ipv6_opt_hdr *)(skb->data + offset); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 920 | |
| 921 | /* offending pkt: 2nd byte following IPv6 hdr is 0xff */ |
| 922 | if (ehdr->hdrlen == 0xff) |
| 923 | return true; |
| 924 | } |
| 925 | } |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | static int be_vlan_tag_tx_chk(struct be_adapter *adapter, struct sk_buff *skb) |
| 930 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 931 | return skb_vlan_tag_present(skb) || adapter->pvid || adapter->qnq_vid; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 934 | static int be_ipv6_tx_stall_chk(struct be_adapter *adapter, struct sk_buff *skb) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 935 | { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 936 | return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 939 | static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter, |
| 940 | struct sk_buff *skb, |
| 941 | bool *skip_hw_vlan) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 942 | { |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 943 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 944 | unsigned int eth_hdr_len; |
| 945 | struct iphdr *ip; |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 946 | |
Ajit Khaparde | 1297f9d | 2013-04-24 11:52:28 +0000 | [diff] [blame] | 947 | /* For padded packets, BE HW modifies tot_len field in IP header |
| 948 | * incorrecly when VLAN tag is inserted by HW. |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 949 | * For padded packets, Lancer computes incorrect checksum. |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 950 | */ |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 951 | eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ? |
| 952 | VLAN_ETH_HLEN : ETH_HLEN; |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 953 | if (skb->len <= 60 && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 954 | (lancer_chip(adapter) || skb_vlan_tag_present(skb)) && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 955 | is_ipv4_pkt(skb)) { |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 956 | ip = (struct iphdr *)ip_hdr(skb); |
| 957 | pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len)); |
| 958 | } |
| 959 | |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 960 | /* If vlan tag is already inlined in the packet, skip HW VLAN |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 961 | * tagging in pvid-tagging mode |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 962 | */ |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 963 | if (be_pvid_tagging_enabled(adapter) && |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 964 | veh->h_vlan_proto == htons(ETH_P_8021Q)) |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 965 | *skip_hw_vlan = true; |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 966 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 967 | /* HW has a bug wherein it will calculate CSUM for VLAN |
| 968 | * pkts even though it is disabled. |
| 969 | * Manually insert VLAN in pkt. |
| 970 | */ |
| 971 | if (skb->ip_summed != CHECKSUM_PARTIAL && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 972 | skb_vlan_tag_present(skb)) { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 973 | skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 974 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 975 | goto err; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /* HW may lockup when VLAN HW tagging is requested on |
| 979 | * certain ipv6 packets. Drop such pkts if the HW workaround to |
| 980 | * skip HW tagging is not enabled by FW. |
| 981 | */ |
| 982 | if (unlikely(be_ipv6_tx_stall_chk(adapter, skb) && |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 983 | (adapter->pvid || adapter->qnq_vid) && |
| 984 | !qnq_async_evt_rcvd(adapter))) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 985 | goto tx_drop; |
| 986 | |
| 987 | /* Manual VLAN tag insertion to prevent: |
| 988 | * ASIC lockup when the ASIC inserts VLAN tag into |
| 989 | * certain ipv6 packets. Insert VLAN tags in driver, |
| 990 | * and set event, completion, vlan bits accordingly |
| 991 | * in the Tx WRB. |
| 992 | */ |
| 993 | if (be_ipv6_tx_stall_chk(adapter, skb) && |
| 994 | be_vlan_tag_tx_chk(adapter, skb)) { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 995 | skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 996 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 997 | goto err; |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1000 | return skb; |
| 1001 | tx_drop: |
| 1002 | dev_kfree_skb_any(skb); |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1003 | err: |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1004 | return NULL; |
| 1005 | } |
| 1006 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1007 | static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, |
| 1008 | struct sk_buff *skb, |
| 1009 | bool *skip_hw_vlan) |
| 1010 | { |
| 1011 | /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or |
| 1012 | * less may cause a transmit stall on that port. So the work-around is |
| 1013 | * to pad short packets (<= 32 bytes) to a 36-byte length. |
| 1014 | */ |
| 1015 | if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) { |
Alexander Duyck | 74b6939 | 2014-12-03 08:17:46 -0800 | [diff] [blame] | 1016 | if (skb_put_padto(skb, 36)) |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1017 | return NULL; |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
| 1021 | skb = be_lancer_xmit_workarounds(adapter, skb, skip_hw_vlan); |
| 1022 | if (!skb) |
| 1023 | return NULL; |
| 1024 | } |
| 1025 | |
| 1026 | return skb; |
| 1027 | } |
| 1028 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1029 | static void be_xmit_flush(struct be_adapter *adapter, struct be_tx_obj *txo) |
| 1030 | { |
| 1031 | struct be_queue_info *txq = &txo->q; |
| 1032 | struct be_eth_hdr_wrb *hdr = queue_index_node(txq, txo->last_req_hdr); |
| 1033 | |
| 1034 | /* Mark the last request eventable if it hasn't been marked already */ |
| 1035 | if (!(hdr->dw[2] & cpu_to_le32(TX_HDR_WRB_EVT))) |
| 1036 | hdr->dw[2] |= cpu_to_le32(TX_HDR_WRB_EVT | TX_HDR_WRB_COMPL); |
| 1037 | |
| 1038 | /* compose a dummy wrb if there are odd set of wrbs to notify */ |
| 1039 | if (!lancer_chip(adapter) && (txo->pend_wrb_cnt & 1)) { |
| 1040 | wrb_fill(queue_head_node(txq), 0, 0); |
| 1041 | queue_head_inc(txq); |
| 1042 | atomic_inc(&txq->used); |
| 1043 | txo->pend_wrb_cnt++; |
| 1044 | hdr->dw[2] &= ~cpu_to_le32(TX_HDR_WRB_NUM_MASK << |
| 1045 | TX_HDR_WRB_NUM_SHIFT); |
| 1046 | hdr->dw[2] |= cpu_to_le32((txo->last_req_wrb_cnt + 1) << |
| 1047 | TX_HDR_WRB_NUM_SHIFT); |
| 1048 | } |
| 1049 | be_txq_notify(adapter, txo, txo->pend_wrb_cnt); |
| 1050 | txo->pend_wrb_cnt = 0; |
| 1051 | } |
| 1052 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1053 | static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1054 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1055 | bool skip_hw_vlan = false, flush = !skb->xmit_more; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1056 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1057 | u16 q_idx = skb_get_queue_mapping(skb); |
| 1058 | struct be_tx_obj *txo = &adapter->tx_obj[q_idx]; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1059 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1060 | u16 wrb_cnt; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1061 | |
| 1062 | skb = be_xmit_workarounds(adapter, skb, &skip_hw_vlan); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1063 | if (unlikely(!skb)) |
| 1064 | goto drop; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1065 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1066 | wrb_cnt = be_xmit_enqueue(adapter, txo, skb, skip_hw_vlan); |
| 1067 | if (unlikely(!wrb_cnt)) { |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1068 | dev_kfree_skb_any(skb); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1069 | goto drop; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1070 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1071 | |
| 1072 | if ((atomic_read(&txq->used) + BE_MAX_TX_FRAG_COUNT) >= txq->len) { |
| 1073 | netif_stop_subqueue(netdev, q_idx); |
| 1074 | tx_stats(txo)->tx_stops++; |
| 1075 | } |
| 1076 | |
| 1077 | if (flush || __netif_subqueue_stopped(netdev, q_idx)) |
| 1078 | be_xmit_flush(adapter, txo); |
| 1079 | |
| 1080 | return NETDEV_TX_OK; |
| 1081 | drop: |
| 1082 | tx_stats(txo)->tx_drv_drops++; |
| 1083 | /* Flush the already enqueued tx requests */ |
| 1084 | if (flush && txo->pend_wrb_cnt) |
| 1085 | be_xmit_flush(adapter, txo); |
| 1086 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1087 | return NETDEV_TX_OK; |
| 1088 | } |
| 1089 | |
| 1090 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 1091 | { |
| 1092 | struct be_adapter *adapter = netdev_priv(netdev); |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1093 | struct device *dev = &adapter->pdev->dev; |
| 1094 | |
| 1095 | if (new_mtu < BE_MIN_MTU || new_mtu > BE_MAX_MTU) { |
| 1096 | dev_info(dev, "MTU must be between %d and %d bytes\n", |
| 1097 | BE_MIN_MTU, BE_MAX_MTU); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1098 | return -EINVAL; |
| 1099 | } |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1100 | |
| 1101 | dev_info(dev, "MTU changed from %d to %d bytes\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1102 | netdev->mtu, new_mtu); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1103 | netdev->mtu = new_mtu; |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1107 | static inline bool be_in_all_promisc(struct be_adapter *adapter) |
| 1108 | { |
| 1109 | return (adapter->if_flags & BE_IF_FLAGS_ALL_PROMISCUOUS) == |
| 1110 | BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1111 | } |
| 1112 | |
| 1113 | static int be_set_vlan_promisc(struct be_adapter *adapter) |
| 1114 | { |
| 1115 | struct device *dev = &adapter->pdev->dev; |
| 1116 | int status; |
| 1117 | |
| 1118 | if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) |
| 1119 | return 0; |
| 1120 | |
| 1121 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, ON); |
| 1122 | if (!status) { |
| 1123 | dev_info(dev, "Enabled VLAN promiscuous mode\n"); |
| 1124 | adapter->if_flags |= BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1125 | } else { |
| 1126 | dev_err(dev, "Failed to enable VLAN promiscuous mode\n"); |
| 1127 | } |
| 1128 | return status; |
| 1129 | } |
| 1130 | |
| 1131 | static int be_clear_vlan_promisc(struct be_adapter *adapter) |
| 1132 | { |
| 1133 | struct device *dev = &adapter->pdev->dev; |
| 1134 | int status; |
| 1135 | |
| 1136 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, OFF); |
| 1137 | if (!status) { |
| 1138 | dev_info(dev, "Disabling VLAN promiscuous mode\n"); |
| 1139 | adapter->if_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1140 | } |
| 1141 | return status; |
| 1142 | } |
| 1143 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1144 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1145 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 1146 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1147 | */ |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1148 | static int be_vid_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1149 | { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 1150 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1151 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1152 | u16 num = 0, i = 0; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1153 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1154 | |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1155 | /* No need to further configure vids if in promiscuous mode */ |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1156 | if (be_in_all_promisc(adapter)) |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1157 | return 0; |
| 1158 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1159 | if (adapter->vlans_added > be_max_vlans(adapter)) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1160 | return be_set_vlan_promisc(adapter); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1161 | |
| 1162 | /* Construct VLAN Table to give to HW */ |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1163 | for_each_set_bit(i, adapter->vids, VLAN_N_VID) |
| 1164 | vids[num++] = cpu_to_le16(i); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1165 | |
Kalesh AP | 4d567d9 | 2014-05-09 13:29:17 +0530 | [diff] [blame] | 1166 | status = be_cmd_vlan_config(adapter, adapter->if_handle, vids, num); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1167 | if (status) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1168 | dev_err(dev, "Setting HW VLAN filtering failed\n"); |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1169 | /* Set to VLAN promisc mode as setting VLAN filter failed */ |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 1170 | if (addl_status(status) == |
| 1171 | MCC_ADDL_STATUS_INSUFFICIENT_RESOURCES) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1172 | return be_set_vlan_promisc(adapter); |
| 1173 | } else if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) { |
| 1174 | status = be_clear_vlan_promisc(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1175 | } |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1176 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1179 | 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] | 1180 | { |
| 1181 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1182 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1183 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1184 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1185 | if (lancer_chip(adapter) && vid == 0) |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1186 | return status; |
| 1187 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1188 | if (test_bit(vid, adapter->vids)) |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1189 | return status; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1190 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1191 | set_bit(vid, adapter->vids); |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1192 | adapter->vlans_added++; |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1193 | |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1194 | status = be_vid_config(adapter); |
| 1195 | if (status) { |
| 1196 | adapter->vlans_added--; |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1197 | clear_bit(vid, adapter->vids); |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1198 | } |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1199 | |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1200 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1203 | 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] | 1204 | { |
| 1205 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1206 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1207 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1208 | if (lancer_chip(adapter) && vid == 0) |
Kalesh AP | 9d4dfe4 | 2014-06-30 13:01:33 +0530 | [diff] [blame] | 1209 | return 0; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1210 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1211 | clear_bit(vid, adapter->vids); |
Kalesh AP | 9d4dfe4 | 2014-06-30 13:01:33 +0530 | [diff] [blame] | 1212 | adapter->vlans_added--; |
| 1213 | |
| 1214 | return be_vid_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1217 | static void be_clear_all_promisc(struct be_adapter *adapter) |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1218 | { |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 1219 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_ALL_PROMISCUOUS, OFF); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1220 | adapter->if_flags &= ~BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1221 | } |
| 1222 | |
| 1223 | static void be_set_all_promisc(struct be_adapter *adapter) |
| 1224 | { |
| 1225 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_ALL_PROMISCUOUS, ON); |
| 1226 | adapter->if_flags |= BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1227 | } |
| 1228 | |
| 1229 | static void be_set_mc_promisc(struct be_adapter *adapter) |
| 1230 | { |
| 1231 | int status; |
| 1232 | |
| 1233 | if (adapter->if_flags & BE_IF_FLAGS_MCAST_PROMISCUOUS) |
| 1234 | return; |
| 1235 | |
| 1236 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MCAST_PROMISCUOUS, ON); |
| 1237 | if (!status) |
| 1238 | adapter->if_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1239 | } |
| 1240 | |
| 1241 | static void be_set_mc_list(struct be_adapter *adapter) |
| 1242 | { |
| 1243 | int status; |
| 1244 | |
| 1245 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MULTICAST, ON); |
| 1246 | if (!status) |
| 1247 | adapter->if_flags &= ~BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1248 | else |
| 1249 | be_set_mc_promisc(adapter); |
| 1250 | } |
| 1251 | |
| 1252 | static void be_set_uc_list(struct be_adapter *adapter) |
| 1253 | { |
| 1254 | struct netdev_hw_addr *ha; |
| 1255 | int i = 1; /* First slot is claimed by the Primary MAC */ |
| 1256 | |
| 1257 | for (; adapter->uc_macs > 0; adapter->uc_macs--, i++) |
| 1258 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 1259 | adapter->pmac_id[i], 0); |
| 1260 | |
| 1261 | if (netdev_uc_count(adapter->netdev) > be_max_uc(adapter)) { |
| 1262 | be_set_all_promisc(adapter); |
| 1263 | return; |
| 1264 | } |
| 1265 | |
| 1266 | netdev_for_each_uc_addr(ha, adapter->netdev) { |
| 1267 | adapter->uc_macs++; /* First slot is for Primary MAC */ |
| 1268 | be_cmd_pmac_add(adapter, (u8 *)ha->addr, adapter->if_handle, |
| 1269 | &adapter->pmac_id[adapter->uc_macs], 0); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static void be_clear_uc_list(struct be_adapter *adapter) |
| 1274 | { |
| 1275 | int i; |
| 1276 | |
| 1277 | for (i = 1; i < (adapter->uc_macs + 1); i++) |
| 1278 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 1279 | adapter->pmac_id[i], 0); |
| 1280 | adapter->uc_macs = 0; |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1281 | } |
| 1282 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 1283 | static void be_set_rx_mode(struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1284 | { |
| 1285 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1286 | |
| 1287 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1288 | be_set_all_promisc(adapter); |
| 1289 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1290 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1291 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1292 | /* Interface was previously in promiscuous mode; disable it */ |
| 1293 | if (be_in_all_promisc(adapter)) { |
| 1294 | be_clear_all_promisc(adapter); |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1295 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1296 | be_vid_config(adapter); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1299 | /* Enable multicast promisc if num configured exceeds what we support */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1300 | if (netdev->flags & IFF_ALLMULTI || |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1301 | netdev_mc_count(netdev) > be_max_mc(adapter)) { |
| 1302 | be_set_mc_promisc(adapter); |
Kalesh AP | a079488 | 2014-05-30 19:06:23 +0530 | [diff] [blame] | 1303 | return; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1304 | } |
Kalesh AP | a079488 | 2014-05-30 19:06:23 +0530 | [diff] [blame] | 1305 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 1306 | if (netdev_uc_count(netdev) != adapter->uc_macs) |
| 1307 | be_set_uc_list(adapter); |
| 1308 | |
| 1309 | be_set_mc_list(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1312 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 1313 | { |
| 1314 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1315 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1316 | int status; |
| 1317 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1318 | if (!sriov_enabled(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1319 | return -EPERM; |
| 1320 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1321 | if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1322 | return -EINVAL; |
| 1323 | |
Vasundhara Volam | 3c31aaf | 2014-08-01 17:47:31 +0530 | [diff] [blame] | 1324 | /* Proceed further only if user provided MAC is different |
| 1325 | * from active MAC |
| 1326 | */ |
| 1327 | if (ether_addr_equal(mac, vf_cfg->mac_addr)) |
| 1328 | return 0; |
| 1329 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1330 | if (BEx_chip(adapter)) { |
| 1331 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, vf_cfg->pmac_id, |
| 1332 | vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1333 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1334 | status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle, |
| 1335 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1336 | } else { |
| 1337 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 1338 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1341 | if (status) { |
| 1342 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed: %#x", |
| 1343 | mac, vf, status); |
| 1344 | return be_cmd_status(status); |
| 1345 | } |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1346 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1347 | ether_addr_copy(vf_cfg->mac_addr, mac); |
| 1348 | |
| 1349 | return 0; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1352 | static int be_get_vf_config(struct net_device *netdev, int vf, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1353 | struct ifla_vf_info *vi) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1354 | { |
| 1355 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1356 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1357 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1358 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1359 | return -EPERM; |
| 1360 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1361 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1362 | return -EINVAL; |
| 1363 | |
| 1364 | vi->vf = vf; |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1365 | vi->max_tx_rate = vf_cfg->tx_rate; |
| 1366 | vi->min_tx_rate = 0; |
Ajit Khaparde | a60b3a1 | 2013-09-27 15:18:56 -0500 | [diff] [blame] | 1367 | vi->vlan = vf_cfg->vlan_tag & VLAN_VID_MASK; |
| 1368 | vi->qos = vf_cfg->vlan_tag >> VLAN_PRIO_SHIFT; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1369 | memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1370 | vi->linkstate = adapter->vf_cfg[vf].plink_tracking; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1375 | static int be_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1376 | { |
| 1377 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1378 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1379 | int status = 0; |
| 1380 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1381 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1382 | return -EPERM; |
| 1383 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1384 | if (vf >= adapter->num_vfs || vlan > 4095 || qos > 7) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1385 | return -EINVAL; |
| 1386 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1387 | if (vlan || qos) { |
| 1388 | vlan |= qos << VLAN_PRIO_SHIFT; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1389 | if (vf_cfg->vlan_tag != vlan) |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1390 | status = be_cmd_set_hsw_config(adapter, vlan, vf + 1, |
| 1391 | vf_cfg->if_handle, 0); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1392 | } else { |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 1393 | /* Reset Transparent Vlan Tagging. */ |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 1394 | status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID, |
| 1395 | vf + 1, vf_cfg->if_handle, 0); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1398 | if (status) { |
| 1399 | dev_err(&adapter->pdev->dev, |
| 1400 | "VLAN %d config on VF %d failed : %#x\n", vlan, |
| 1401 | vf, status); |
| 1402 | return be_cmd_status(status); |
| 1403 | } |
| 1404 | |
| 1405 | vf_cfg->vlan_tag = vlan; |
| 1406 | |
| 1407 | return 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1410 | static int be_set_vf_tx_rate(struct net_device *netdev, int vf, |
| 1411 | int min_tx_rate, int max_tx_rate) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1412 | { |
| 1413 | struct be_adapter *adapter = netdev_priv(netdev); |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1414 | struct device *dev = &adapter->pdev->dev; |
| 1415 | int percent_rate, status = 0; |
| 1416 | u16 link_speed = 0; |
| 1417 | u8 link_status; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1418 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1419 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1420 | return -EPERM; |
| 1421 | |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1422 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1423 | return -EINVAL; |
| 1424 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1425 | if (min_tx_rate) |
| 1426 | return -EINVAL; |
| 1427 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1428 | if (!max_tx_rate) |
| 1429 | goto config_qos; |
| 1430 | |
| 1431 | status = be_cmd_link_status_query(adapter, &link_speed, |
| 1432 | &link_status, 0); |
| 1433 | if (status) |
| 1434 | goto err; |
| 1435 | |
| 1436 | if (!link_status) { |
| 1437 | dev_err(dev, "TX-rate setting not allowed when link is down\n"); |
Kalesh AP | 940a3fc | 2014-07-17 16:20:19 +0530 | [diff] [blame] | 1438 | status = -ENETDOWN; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1439 | goto err; |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1440 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1441 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1442 | if (max_tx_rate < 100 || max_tx_rate > link_speed) { |
| 1443 | dev_err(dev, "TX-rate must be between 100 and %d Mbps\n", |
| 1444 | link_speed); |
| 1445 | status = -EINVAL; |
| 1446 | goto err; |
| 1447 | } |
| 1448 | |
| 1449 | /* On Skyhawk the QOS setting must be done only as a % value */ |
| 1450 | percent_rate = link_speed / 100; |
| 1451 | if (skyhawk_chip(adapter) && (max_tx_rate % percent_rate)) { |
| 1452 | dev_err(dev, "TX-rate must be a multiple of %d Mbps\n", |
| 1453 | percent_rate); |
| 1454 | status = -EINVAL; |
| 1455 | goto err; |
| 1456 | } |
| 1457 | |
| 1458 | config_qos: |
| 1459 | status = be_cmd_config_qos(adapter, max_tx_rate, link_speed, vf + 1); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1460 | if (status) |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1461 | goto err; |
| 1462 | |
| 1463 | adapter->vf_cfg[vf].tx_rate = max_tx_rate; |
| 1464 | return 0; |
| 1465 | |
| 1466 | err: |
| 1467 | dev_err(dev, "TX-rate setting of %dMbps on VF%d failed\n", |
| 1468 | max_tx_rate, vf); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1469 | return be_cmd_status(status); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1470 | } |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 1471 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1472 | static int be_set_vf_link_state(struct net_device *netdev, int vf, |
| 1473 | int link_state) |
| 1474 | { |
| 1475 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1476 | int status; |
| 1477 | |
| 1478 | if (!sriov_enabled(adapter)) |
| 1479 | return -EPERM; |
| 1480 | |
| 1481 | if (vf >= adapter->num_vfs) |
| 1482 | return -EINVAL; |
| 1483 | |
| 1484 | status = be_cmd_set_logical_link_config(adapter, link_state, vf+1); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1485 | if (status) { |
| 1486 | dev_err(&adapter->pdev->dev, |
| 1487 | "Link state change on VF %d failed: %#x\n", vf, status); |
| 1488 | return be_cmd_status(status); |
| 1489 | } |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1490 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1491 | adapter->vf_cfg[vf].plink_tracking = link_state; |
| 1492 | |
| 1493 | return 0; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1494 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1495 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1496 | static void be_aic_update(struct be_aic_obj *aic, u64 rx_pkts, u64 tx_pkts, |
| 1497 | ulong now) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1498 | { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1499 | aic->rx_pkts_prev = rx_pkts; |
| 1500 | aic->tx_reqs_prev = tx_pkts; |
| 1501 | aic->jiffies = now; |
| 1502 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1503 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1504 | static void be_eqd_update(struct be_adapter *adapter) |
| 1505 | { |
| 1506 | struct be_set_eqd set_eqd[MAX_EVT_QS]; |
| 1507 | int eqd, i, num = 0, start; |
| 1508 | struct be_aic_obj *aic; |
| 1509 | struct be_eq_obj *eqo; |
| 1510 | struct be_rx_obj *rxo; |
| 1511 | struct be_tx_obj *txo; |
| 1512 | u64 rx_pkts, tx_pkts; |
| 1513 | ulong now; |
| 1514 | u32 pps, delta; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1515 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1516 | for_all_evt_queues(adapter, eqo, i) { |
| 1517 | aic = &adapter->aic_obj[eqo->idx]; |
| 1518 | if (!aic->enable) { |
| 1519 | if (aic->jiffies) |
| 1520 | aic->jiffies = 0; |
| 1521 | eqd = aic->et_eqd; |
| 1522 | goto modify_eqd; |
| 1523 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1524 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1525 | rxo = &adapter->rx_obj[eqo->idx]; |
| 1526 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1527 | start = u64_stats_fetch_begin_irq(&rxo->stats.sync); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1528 | rx_pkts = rxo->stats.rx_pkts; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1529 | } while (u64_stats_fetch_retry_irq(&rxo->stats.sync, start)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1530 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1531 | txo = &adapter->tx_obj[eqo->idx]; |
| 1532 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1533 | start = u64_stats_fetch_begin_irq(&txo->stats.sync); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1534 | tx_pkts = txo->stats.tx_reqs; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1535 | } while (u64_stats_fetch_retry_irq(&txo->stats.sync, start)); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1536 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1537 | /* Skip, if wrapped around or first calculation */ |
| 1538 | now = jiffies; |
| 1539 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
| 1540 | rx_pkts < aic->rx_pkts_prev || |
| 1541 | tx_pkts < aic->tx_reqs_prev) { |
| 1542 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 1543 | continue; |
| 1544 | } |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1545 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1546 | delta = jiffies_to_msecs(now - aic->jiffies); |
| 1547 | pps = (((u32)(rx_pkts - aic->rx_pkts_prev) * 1000) / delta) + |
| 1548 | (((u32)(tx_pkts - aic->tx_reqs_prev) * 1000) / delta); |
| 1549 | eqd = (pps / 15000) << 2; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1550 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1551 | if (eqd < 8) |
| 1552 | eqd = 0; |
| 1553 | eqd = min_t(u32, eqd, aic->max_eqd); |
| 1554 | eqd = max_t(u32, eqd, aic->min_eqd); |
| 1555 | |
| 1556 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1557 | modify_eqd: |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1558 | if (eqd != aic->prev_eqd) { |
| 1559 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 1560 | set_eqd[num].eq_id = eqo->q.id; |
| 1561 | aic->prev_eqd = eqd; |
| 1562 | num++; |
| 1563 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1564 | } |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1565 | |
| 1566 | if (num) |
| 1567 | be_cmd_modify_eqd(adapter, set_eqd, num); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1570 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1571 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1572 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1573 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1574 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1575 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1576 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1577 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1578 | stats->rx_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1579 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1580 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1581 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1582 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1583 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1586 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1587 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 1588 | /* L4 checksum is not reliable for non TCP/UDP packets. |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1589 | * Also ignore ipcksm for ipv6 pkts |
| 1590 | */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1591 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1592 | (rxcp->ip_csum || rxcp->ipv6) && !rxcp->err; |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1595 | 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] | 1596 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1597 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1598 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1599 | struct be_queue_info *rxq = &rxo->q; |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1600 | u16 frag_idx = rxq->tail; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1601 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1602 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1603 | BUG_ON(!rx_page_info->page); |
| 1604 | |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1605 | if (rx_page_info->last_frag) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1606 | dma_unmap_page(&adapter->pdev->dev, |
| 1607 | dma_unmap_addr(rx_page_info, bus), |
| 1608 | adapter->big_page_size, DMA_FROM_DEVICE); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1609 | rx_page_info->last_frag = false; |
| 1610 | } else { |
| 1611 | dma_sync_single_for_cpu(&adapter->pdev->dev, |
| 1612 | dma_unmap_addr(rx_page_info, bus), |
| 1613 | rx_frag_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1614 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1615 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1616 | queue_tail_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1617 | atomic_dec(&rxq->used); |
| 1618 | return rx_page_info; |
| 1619 | } |
| 1620 | |
| 1621 | /* Throwaway the data in the Rx completion */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1622 | static void be_rx_compl_discard(struct be_rx_obj *rxo, |
| 1623 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1624 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1625 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1626 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1627 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1628 | for (i = 0; i < num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1629 | page_info = get_rx_page_info(rxo); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1630 | put_page(page_info->page); |
| 1631 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 1637 | * indicated by rxcp. |
| 1638 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1639 | static void skb_fill_rx_data(struct be_rx_obj *rxo, struct sk_buff *skb, |
| 1640 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1641 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1642 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1643 | u16 i, j; |
| 1644 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1645 | u8 *start; |
| 1646 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1647 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1648 | start = page_address(page_info->page) + page_info->page_offset; |
| 1649 | prefetch(start); |
| 1650 | |
| 1651 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1652 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1653 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1654 | skb->len = curr_frag_len; |
| 1655 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1656 | memcpy(skb->data, start, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1657 | /* Complete packet has now been moved to data */ |
| 1658 | put_page(page_info->page); |
| 1659 | skb->data_len = 0; |
| 1660 | skb->tail += curr_frag_len; |
| 1661 | } else { |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1662 | hdr_len = ETH_HLEN; |
| 1663 | memcpy(skb->data, start, hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1664 | skb_shinfo(skb)->nr_frags = 1; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1665 | skb_frag_set_page(skb, 0, page_info->page); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1666 | skb_shinfo(skb)->frags[0].page_offset = |
| 1667 | page_info->page_offset + hdr_len; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1668 | skb_frag_size_set(&skb_shinfo(skb)->frags[0], |
| 1669 | curr_frag_len - hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1670 | skb->data_len = curr_frag_len - hdr_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1671 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1672 | skb->tail += hdr_len; |
| 1673 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1674 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1675 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1676 | if (rxcp->pkt_size <= rx_frag_size) { |
| 1677 | BUG_ON(rxcp->num_rcvd != 1); |
| 1678 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1682 | remaining = rxcp->pkt_size - curr_frag_len; |
| 1683 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1684 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1685 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1686 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1687 | /* Coalesce all frags from the same physical page in one slot */ |
| 1688 | if (page_info->page_offset == 0) { |
| 1689 | /* Fresh page */ |
| 1690 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1691 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1692 | skb_shinfo(skb)->frags[j].page_offset = |
| 1693 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1694 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1695 | skb_shinfo(skb)->nr_frags++; |
| 1696 | } else { |
| 1697 | put_page(page_info->page); |
| 1698 | } |
| 1699 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1700 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1701 | skb->len += curr_frag_len; |
| 1702 | skb->data_len += curr_frag_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1703 | skb->truesize += rx_frag_size; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1704 | remaining -= curr_frag_len; |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1705 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1706 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1707 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1710 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1711 | 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] | 1712 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1713 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1714 | struct be_adapter *adapter = rxo->adapter; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1715 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1716 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1717 | |
Eric Dumazet | bb349bb | 2012-01-25 03:56:30 +0000 | [diff] [blame] | 1718 | skb = netdev_alloc_skb_ip_align(netdev, BE_RX_SKB_ALLOC_SIZE); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 1719 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1720 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1721 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1722 | return; |
| 1723 | } |
| 1724 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1725 | skb_fill_rx_data(rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1726 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1727 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1728 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 1729 | else |
| 1730 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1731 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1732 | skb->protocol = eth_type_trans(skb, netdev); |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 1733 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1734 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 1735 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1736 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 1737 | skb->csum_level = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1738 | skb_mark_napi_id(skb, napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1739 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1740 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1741 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1742 | |
| 1743 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1746 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1747 | static void be_rx_compl_process_gro(struct be_rx_obj *rxo, |
| 1748 | struct napi_struct *napi, |
| 1749 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1750 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1751 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1752 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1753 | struct sk_buff *skb = NULL; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1754 | u16 remaining, curr_frag_len; |
| 1755 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 1756 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1757 | skb = napi_get_frags(napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1758 | if (!skb) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1759 | be_rx_compl_discard(rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1760 | return; |
| 1761 | } |
| 1762 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1763 | remaining = rxcp->pkt_size; |
| 1764 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1765 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1766 | |
| 1767 | curr_frag_len = min(remaining, rx_frag_size); |
| 1768 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1769 | /* Coalesce all frags from the same physical page in one slot */ |
| 1770 | if (i == 0 || page_info->page_offset == 0) { |
| 1771 | /* First frag or Fresh page */ |
| 1772 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1773 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1774 | skb_shinfo(skb)->frags[j].page_offset = |
| 1775 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1776 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1777 | } else { |
| 1778 | put_page(page_info->page); |
| 1779 | } |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1780 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1781 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1782 | remaining -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1783 | memset(page_info, 0, sizeof(*page_info)); |
| 1784 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1785 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1786 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1787 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1788 | skb->len = rxcp->pkt_size; |
| 1789 | skb->data_len = rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1790 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 1791 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1792 | if (adapter->netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 1793 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1794 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 1795 | skb->csum_level = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1796 | skb_mark_napi_id(skb, napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1797 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1798 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1799 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1800 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1801 | napi_gro_frags(napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1804 | static void be_parse_rx_compl_v1(struct be_eth_rx_compl *compl, |
| 1805 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1806 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1807 | rxcp->pkt_size = GET_RX_COMPL_V1_BITS(pktsize, compl); |
| 1808 | rxcp->vlanf = GET_RX_COMPL_V1_BITS(vtp, compl); |
| 1809 | rxcp->err = GET_RX_COMPL_V1_BITS(err, compl); |
| 1810 | rxcp->tcpf = GET_RX_COMPL_V1_BITS(tcpf, compl); |
| 1811 | rxcp->udpf = GET_RX_COMPL_V1_BITS(udpf, compl); |
| 1812 | rxcp->ip_csum = GET_RX_COMPL_V1_BITS(ipcksm, compl); |
| 1813 | rxcp->l4_csum = GET_RX_COMPL_V1_BITS(l4_cksm, compl); |
| 1814 | rxcp->ipv6 = GET_RX_COMPL_V1_BITS(ip_version, compl); |
| 1815 | rxcp->num_rcvd = GET_RX_COMPL_V1_BITS(numfrags, compl); |
| 1816 | rxcp->pkt_type = GET_RX_COMPL_V1_BITS(cast_enc, compl); |
| 1817 | rxcp->rss_hash = GET_RX_COMPL_V1_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1818 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1819 | rxcp->qnq = GET_RX_COMPL_V1_BITS(qnq, compl); |
| 1820 | rxcp->vlan_tag = GET_RX_COMPL_V1_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1821 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1822 | rxcp->port = GET_RX_COMPL_V1_BITS(port, compl); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1823 | rxcp->tunneled = |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1824 | GET_RX_COMPL_V1_BITS(tunneled, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1825 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1826 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1827 | static void be_parse_rx_compl_v0(struct be_eth_rx_compl *compl, |
| 1828 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1829 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1830 | rxcp->pkt_size = GET_RX_COMPL_V0_BITS(pktsize, compl); |
| 1831 | rxcp->vlanf = GET_RX_COMPL_V0_BITS(vtp, compl); |
| 1832 | rxcp->err = GET_RX_COMPL_V0_BITS(err, compl); |
| 1833 | rxcp->tcpf = GET_RX_COMPL_V0_BITS(tcpf, compl); |
| 1834 | rxcp->udpf = GET_RX_COMPL_V0_BITS(udpf, compl); |
| 1835 | rxcp->ip_csum = GET_RX_COMPL_V0_BITS(ipcksm, compl); |
| 1836 | rxcp->l4_csum = GET_RX_COMPL_V0_BITS(l4_cksm, compl); |
| 1837 | rxcp->ipv6 = GET_RX_COMPL_V0_BITS(ip_version, compl); |
| 1838 | rxcp->num_rcvd = GET_RX_COMPL_V0_BITS(numfrags, compl); |
| 1839 | rxcp->pkt_type = GET_RX_COMPL_V0_BITS(cast_enc, compl); |
| 1840 | rxcp->rss_hash = GET_RX_COMPL_V0_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1841 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1842 | rxcp->qnq = GET_RX_COMPL_V0_BITS(qnq, compl); |
| 1843 | rxcp->vlan_tag = GET_RX_COMPL_V0_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1844 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 1845 | rxcp->port = GET_RX_COMPL_V0_BITS(port, compl); |
| 1846 | rxcp->ip_frag = GET_RX_COMPL_V0_BITS(ip_frag, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 1850 | { |
| 1851 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 1852 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 1853 | struct be_adapter *adapter = rxo->adapter; |
| 1854 | |
| 1855 | /* For checking the valid bit it is Ok to use either definition as the |
| 1856 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 1857 | 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] | 1858 | return NULL; |
| 1859 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1860 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1861 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 1862 | |
| 1863 | if (adapter->be3_native) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1864 | be_parse_rx_compl_v1(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1865 | else |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1866 | be_parse_rx_compl_v0(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1867 | |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 1868 | if (rxcp->ip_frag) |
| 1869 | rxcp->l4_csum = 0; |
| 1870 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1871 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1872 | /* In QNQ modes, if qnq bit is not set, then the packet was |
| 1873 | * tagged only with the transparent outer vlan-tag and must |
| 1874 | * not be treated as a vlan packet by host |
| 1875 | */ |
| 1876 | if (be_is_qnq_mode(adapter) && !rxcp->qnq) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1877 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1878 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1879 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1880 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1881 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 1882 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1883 | !test_bit(rxcp->vlan_tag, adapter->vids)) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1884 | rxcp->vlanf = 0; |
| 1885 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1886 | |
| 1887 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 1888 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1889 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1890 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1891 | return rxcp; |
| 1892 | } |
| 1893 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1894 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1895 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1896 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1897 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1898 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1899 | gfp |= __GFP_COMP; |
| 1900 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 1905 | * receive buffers to BE |
| 1906 | */ |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 1907 | static void be_post_rx_frags(struct be_rx_obj *rxo, gfp_t gfp, u32 frags_needed) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1908 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1909 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1910 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1911 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1912 | struct page *pagep = NULL; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1913 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1914 | struct be_eth_rx_d *rxd; |
| 1915 | u64 page_dmaaddr = 0, frag_dmaaddr; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 1916 | u32 posted, page_offset = 0, notify = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1917 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1918 | page_info = &rxo->page_info_tbl[rxq->head]; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 1919 | for (posted = 0; posted < frags_needed && !page_info->page; posted++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1920 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1921 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1922 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1923 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1924 | break; |
| 1925 | } |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1926 | page_dmaaddr = dma_map_page(dev, pagep, 0, |
| 1927 | adapter->big_page_size, |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1928 | DMA_FROM_DEVICE); |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1929 | if (dma_mapping_error(dev, page_dmaaddr)) { |
| 1930 | put_page(pagep); |
| 1931 | pagep = NULL; |
Vasundhara Volam | d3de154 | 2014-09-02 09:56:50 +0530 | [diff] [blame] | 1932 | adapter->drv_stats.dma_map_errors++; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 1933 | break; |
| 1934 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1935 | page_offset = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1936 | } else { |
| 1937 | get_page(pagep); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1938 | page_offset += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1939 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1940 | page_info->page_offset = page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1941 | page_info->page = pagep; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1942 | |
| 1943 | rxd = queue_head_node(rxq); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1944 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1945 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 1946 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1947 | |
| 1948 | /* Any space left in the current big page for another frag? */ |
| 1949 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 1950 | adapter->big_page_size) { |
| 1951 | pagep = NULL; |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1952 | page_info->last_frag = true; |
| 1953 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
| 1954 | } else { |
| 1955 | dma_unmap_addr_set(page_info, bus, frag_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1956 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1957 | |
| 1958 | prev_page_info = page_info; |
| 1959 | queue_head_inc(rxq); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1960 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1961 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1962 | |
| 1963 | /* Mark the last frag of a page when we break out of the above loop |
| 1964 | * with no more slots available in the RXQ |
| 1965 | */ |
| 1966 | if (pagep) { |
| 1967 | prev_page_info->last_frag = true; |
| 1968 | dma_unmap_addr_set(prev_page_info, bus, page_dmaaddr); |
| 1969 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1970 | |
| 1971 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1972 | atomic_add(posted, &rxq->used); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1973 | if (rxo->rx_post_starved) |
| 1974 | rxo->rx_post_starved = false; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 1975 | do { |
| 1976 | notify = min(256u, posted); |
| 1977 | be_rxq_notify(adapter, rxq->id, notify); |
| 1978 | posted -= notify; |
| 1979 | } while (posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1980 | } else if (atomic_read(&rxq->used) == 0) { |
| 1981 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1982 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1983 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1986 | 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] | 1987 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1988 | struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq); |
| 1989 | |
| 1990 | if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
| 1991 | return NULL; |
| 1992 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1993 | rmb(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1994 | be_dws_le_to_cpu(txcp, sizeof(*txcp)); |
| 1995 | |
| 1996 | txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
| 1997 | |
| 1998 | queue_tail_inc(tx_cq); |
| 1999 | return txcp; |
| 2000 | } |
| 2001 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2002 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2003 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2004 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2005 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2006 | struct be_queue_info *txq = &txo->q; |
| 2007 | u16 frag_index, num_wrbs = 0; |
| 2008 | struct sk_buff *skb = NULL; |
| 2009 | bool unmap_skb_hdr = false; |
| 2010 | struct be_eth_wrb *wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2011 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2012 | do { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2013 | if (sent_skbs[txq->tail]) { |
| 2014 | /* Free skb from prev req */ |
| 2015 | if (skb) |
| 2016 | dev_consume_skb_any(skb); |
| 2017 | skb = sent_skbs[txq->tail]; |
| 2018 | sent_skbs[txq->tail] = NULL; |
| 2019 | queue_tail_inc(txq); /* skip hdr wrb */ |
| 2020 | num_wrbs++; |
| 2021 | unmap_skb_hdr = true; |
| 2022 | } |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 2023 | wrb = queue_tail_node(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2024 | frag_index = txq->tail; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2025 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2026 | (unmap_skb_hdr && skb_headlen(skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2027 | unmap_skb_hdr = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2028 | queue_tail_inc(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2029 | num_wrbs++; |
| 2030 | } while (frag_index != last_index); |
| 2031 | dev_consume_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2032 | |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 2033 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2036 | /* Return the number of events in the event queue */ |
| 2037 | static inline int events_get(struct be_eq_obj *eqo) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2038 | { |
| 2039 | struct be_eq_entry *eqe; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2040 | int num = 0; |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2041 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2042 | do { |
| 2043 | eqe = queue_tail_node(&eqo->q); |
| 2044 | if (eqe->evt == 0) |
| 2045 | break; |
| 2046 | |
| 2047 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2048 | eqe->evt = 0; |
| 2049 | num++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2050 | queue_tail_inc(&eqo->q); |
| 2051 | } while (true); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2052 | |
| 2053 | return num; |
| 2054 | } |
| 2055 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2056 | /* Leaves the EQ is disarmed state */ |
| 2057 | static void be_eq_clean(struct be_eq_obj *eqo) |
| 2058 | { |
| 2059 | int num = events_get(eqo); |
| 2060 | |
| 2061 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, num); |
| 2062 | } |
| 2063 | |
| 2064 | static void be_rx_cq_clean(struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2065 | { |
| 2066 | struct be_rx_page_info *page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2067 | struct be_queue_info *rxq = &rxo->q; |
| 2068 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2069 | struct be_rx_compl_info *rxcp; |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2070 | struct be_adapter *adapter = rxo->adapter; |
| 2071 | int flush_wait = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2072 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2073 | /* Consume pending rx completions. |
| 2074 | * Wait for the flush completion (identified by zero num_rcvd) |
| 2075 | * to arrive. Notify CQ even when there are no more CQ entries |
| 2076 | * for HW to flush partially coalesced CQ entries. |
| 2077 | * In Lancer, there is no need to wait for flush compl. |
| 2078 | */ |
| 2079 | for (;;) { |
| 2080 | rxcp = be_rx_compl_get(rxo); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 2081 | if (!rxcp) { |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2082 | if (lancer_chip(adapter)) |
| 2083 | break; |
| 2084 | |
| 2085 | if (flush_wait++ > 10 || be_hw_error(adapter)) { |
| 2086 | dev_warn(&adapter->pdev->dev, |
| 2087 | "did not receive flush compl\n"); |
| 2088 | break; |
| 2089 | } |
| 2090 | be_cq_notify(adapter, rx_cq->id, true, 0); |
| 2091 | mdelay(1); |
| 2092 | } else { |
| 2093 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 3f5dffe | 2013-05-08 02:05:49 +0000 | [diff] [blame] | 2094 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2095 | if (rxcp->num_rcvd == 0) |
| 2096 | break; |
| 2097 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2100 | /* After cleanup, leave the CQ in unarmed state */ |
| 2101 | be_cq_notify(adapter, rx_cq->id, false, 0); |
| 2102 | |
| 2103 | /* Then free posted rx buffers that were not used */ |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2104 | while (atomic_read(&rxq->used) > 0) { |
| 2105 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2106 | put_page(page_info->page); |
| 2107 | memset(page_info, 0, sizeof(*page_info)); |
| 2108 | } |
| 2109 | BUG_ON(atomic_read(&rxq->used)); |
Kalesh AP | 5f820b6 | 2014-09-19 15:47:01 +0530 | [diff] [blame] | 2110 | rxq->tail = 0; |
| 2111 | rxq->head = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2114 | static void be_tx_compl_clean(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2115 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2116 | u16 end_idx, notified_idx, cmpl = 0, timeo = 0, num_wrbs = 0; |
| 2117 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2118 | struct be_tx_obj *txo; |
| 2119 | struct be_queue_info *txq; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2120 | struct be_eth_tx_compl *txcp; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2121 | int i, pending_txqs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2122 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2123 | /* Stop polling for compls when HW has been silent for 10ms */ |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2124 | do { |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2125 | pending_txqs = adapter->num_tx_qs; |
| 2126 | |
| 2127 | for_all_tx_queues(adapter, txo, i) { |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2128 | cmpl = 0; |
| 2129 | num_wrbs = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2130 | txq = &txo->q; |
| 2131 | while ((txcp = be_tx_compl_get(&txo->cq))) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2132 | end_idx = GET_TX_COMPL_BITS(wrb_index, txcp); |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2133 | num_wrbs += be_tx_compl_process(adapter, txo, |
| 2134 | end_idx); |
| 2135 | cmpl++; |
| 2136 | } |
| 2137 | if (cmpl) { |
| 2138 | be_cq_notify(adapter, txo->cq.id, false, cmpl); |
| 2139 | atomic_sub(num_wrbs, &txq->used); |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2140 | timeo = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2141 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2142 | if (atomic_read(&txq->used) == txo->pend_wrb_cnt) |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2143 | pending_txqs--; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2146 | if (pending_txqs == 0 || ++timeo > 10 || be_hw_error(adapter)) |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2147 | break; |
| 2148 | |
| 2149 | mdelay(1); |
| 2150 | } while (true); |
| 2151 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2152 | /* Free enqueued TX that was never notified to HW */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2153 | for_all_tx_queues(adapter, txo, i) { |
| 2154 | txq = &txo->q; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2155 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2156 | if (atomic_read(&txq->used)) { |
| 2157 | dev_info(dev, "txq%d: cleaning %d pending tx-wrbs\n", |
| 2158 | i, atomic_read(&txq->used)); |
| 2159 | notified_idx = txq->tail; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2160 | end_idx = txq->tail; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2161 | index_adv(&end_idx, atomic_read(&txq->used) - 1, |
| 2162 | txq->len); |
| 2163 | /* Use the tx-compl process logic to handle requests |
| 2164 | * that were not sent to the HW. |
| 2165 | */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2166 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
| 2167 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2168 | BUG_ON(atomic_read(&txq->used)); |
| 2169 | txo->pend_wrb_cnt = 0; |
| 2170 | /* Since hw was never notified of these requests, |
| 2171 | * reset TXQ indices |
| 2172 | */ |
| 2173 | txq->head = notified_idx; |
| 2174 | txq->tail = notified_idx; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2175 | } |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2176 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2179 | static void be_evt_queues_destroy(struct be_adapter *adapter) |
| 2180 | { |
| 2181 | struct be_eq_obj *eqo; |
| 2182 | int i; |
| 2183 | |
| 2184 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2185 | if (eqo->q.created) { |
| 2186 | be_eq_clean(eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2187 | be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2188 | napi_hash_del(&eqo->napi); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2189 | netif_napi_del(&eqo->napi); |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2190 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2191 | be_queue_free(adapter, &eqo->q); |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | static int be_evt_queues_create(struct be_adapter *adapter) |
| 2196 | { |
| 2197 | struct be_queue_info *eq; |
| 2198 | struct be_eq_obj *eqo; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2199 | struct be_aic_obj *aic; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2200 | int i, rc; |
| 2201 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2202 | adapter->num_evt_qs = min_t(u16, num_irqs(adapter), |
| 2203 | adapter->cfg_num_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2204 | |
| 2205 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2206 | netif_napi_add(adapter->netdev, &eqo->napi, be_poll, |
| 2207 | BE_NAPI_WEIGHT); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2208 | napi_hash_add(&eqo->napi); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2209 | aic = &adapter->aic_obj[i]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2210 | eqo->adapter = adapter; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2211 | eqo->idx = i; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2212 | aic->max_eqd = BE_MAX_EQD; |
| 2213 | aic->enable = true; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2214 | |
| 2215 | eq = &eqo->q; |
| 2216 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2217 | sizeof(struct be_eq_entry)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2218 | if (rc) |
| 2219 | return rc; |
| 2220 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2221 | rc = be_cmd_eq_create(adapter, eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2222 | if (rc) |
| 2223 | return rc; |
| 2224 | } |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 2225 | return 0; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2228 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 2229 | { |
| 2230 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2231 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2232 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2233 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2234 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2235 | be_queue_free(adapter, q); |
| 2236 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2237 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2238 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2239 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2240 | be_queue_free(adapter, q); |
| 2241 | } |
| 2242 | |
| 2243 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 2244 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 2245 | { |
| 2246 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2247 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2248 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2249 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2250 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2251 | goto err; |
| 2252 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2253 | /* Use the default EQ for MCC completions */ |
| 2254 | 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] | 2255 | goto mcc_cq_free; |
| 2256 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2257 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2258 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 2259 | goto mcc_cq_destroy; |
| 2260 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2261 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2262 | goto mcc_q_free; |
| 2263 | |
| 2264 | return 0; |
| 2265 | |
| 2266 | mcc_q_free: |
| 2267 | be_queue_free(adapter, q); |
| 2268 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2269 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2270 | mcc_cq_free: |
| 2271 | be_queue_free(adapter, cq); |
| 2272 | err: |
| 2273 | return -1; |
| 2274 | } |
| 2275 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2276 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 2277 | { |
| 2278 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2279 | struct be_tx_obj *txo; |
| 2280 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2281 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2282 | for_all_tx_queues(adapter, txo, i) { |
| 2283 | q = &txo->q; |
| 2284 | if (q->created) |
| 2285 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 2286 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2287 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2288 | q = &txo->cq; |
| 2289 | if (q->created) |
| 2290 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2291 | be_queue_free(adapter, q); |
| 2292 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 2295 | static int be_tx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2296 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2297 | struct be_queue_info *cq, *eq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2298 | struct be_tx_obj *txo; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2299 | int status, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2300 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2301 | 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] | 2302 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2303 | for_all_tx_queues(adapter, txo, i) { |
| 2304 | cq = &txo->cq; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2305 | status = be_queue_alloc(adapter, cq, TX_CQ_LEN, |
| 2306 | sizeof(struct be_eth_tx_compl)); |
| 2307 | if (status) |
| 2308 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2309 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2310 | u64_stats_init(&txo->stats.sync); |
| 2311 | u64_stats_init(&txo->stats.sync_compl); |
| 2312 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2313 | /* If num_evt_qs is less than num_tx_qs, then more than |
| 2314 | * one txq share an eq |
| 2315 | */ |
| 2316 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 2317 | status = be_cmd_cq_create(adapter, cq, eq, false, 3); |
| 2318 | if (status) |
| 2319 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2320 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2321 | status = be_queue_alloc(adapter, &txo->q, TX_Q_LEN, |
| 2322 | sizeof(struct be_eth_wrb)); |
| 2323 | if (status) |
| 2324 | return status; |
| 2325 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 2326 | status = be_cmd_txq_create(adapter, txo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2327 | if (status) |
| 2328 | return status; |
| 2329 | } |
| 2330 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2331 | dev_info(&adapter->pdev->dev, "created %d TX queue(s)\n", |
| 2332 | adapter->num_tx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2333 | return 0; |
| 2334 | } |
| 2335 | |
| 2336 | static void be_rx_cqs_destroy(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2337 | { |
| 2338 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2339 | struct be_rx_obj *rxo; |
| 2340 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2341 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2342 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2343 | q = &rxo->cq; |
| 2344 | if (q->created) |
| 2345 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2346 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2347 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2350 | static int be_rx_cqs_create(struct be_adapter *adapter) |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2351 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2352 | struct be_queue_info *eq, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2353 | struct be_rx_obj *rxo; |
| 2354 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2355 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2356 | /* We can create as many RSS rings as there are EQs. */ |
| 2357 | adapter->num_rx_qs = adapter->num_evt_qs; |
| 2358 | |
| 2359 | /* We'll use RSS only if atleast 2 RSS rings are supported. |
| 2360 | * 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] | 2361 | */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2362 | if (adapter->num_rx_qs > 1) |
| 2363 | adapter->num_rx_qs++; |
| 2364 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2365 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2366 | for_all_rx_queues(adapter, rxo, i) { |
| 2367 | rxo->adapter = adapter; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2368 | cq = &rxo->cq; |
| 2369 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2370 | sizeof(struct be_eth_rx_compl)); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2371 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2372 | return rc; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2373 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2374 | u64_stats_init(&rxo->stats.sync); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2375 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 2376 | rc = be_cmd_cq_create(adapter, cq, eq, false, 3); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2377 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2378 | return rc; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2379 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2380 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2381 | dev_info(&adapter->pdev->dev, |
| 2382 | "created %d RSS queue(s) and 1 default RX queue\n", |
| 2383 | adapter->num_rx_qs - 1); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2384 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2387 | static irqreturn_t be_intx(int irq, void *dev) |
| 2388 | { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2389 | struct be_eq_obj *eqo = dev; |
| 2390 | struct be_adapter *adapter = eqo->adapter; |
| 2391 | int num_evts = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2392 | |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2393 | /* IRQ is not expected when NAPI is scheduled as the EQ |
| 2394 | * will not be armed. |
| 2395 | * But, this can happen on Lancer INTx where it takes |
| 2396 | * a while to de-assert INTx or in BE2 where occasionaly |
| 2397 | * an interrupt may be raised even when EQ is unarmed. |
| 2398 | * If NAPI is already scheduled, then counting & notifying |
| 2399 | * events will orphan them. |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2400 | */ |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2401 | if (napi_schedule_prep(&eqo->napi)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2402 | num_evts = events_get(eqo); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2403 | __napi_schedule(&eqo->napi); |
| 2404 | if (num_evts) |
| 2405 | eqo->spurious_intr = 0; |
| 2406 | } |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2407 | be_eq_notify(adapter, eqo->q.id, false, true, num_evts); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2408 | |
| 2409 | /* Return IRQ_HANDLED only for the the first spurious intr |
| 2410 | * after a valid intr to stop the kernel from branding |
| 2411 | * this irq as a bad one! |
| 2412 | */ |
| 2413 | if (num_evts || eqo->spurious_intr++ == 0) |
| 2414 | return IRQ_HANDLED; |
| 2415 | else |
| 2416 | return IRQ_NONE; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2419 | static irqreturn_t be_msix(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2420 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2421 | struct be_eq_obj *eqo = dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2422 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2423 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0); |
| 2424 | napi_schedule(&eqo->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2425 | return IRQ_HANDLED; |
| 2426 | } |
| 2427 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2428 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2429 | { |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 2430 | return (rxcp->tcpf && !rxcp->err && rxcp->l4_csum) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2433 | static int be_process_rx(struct be_rx_obj *rxo, struct napi_struct *napi, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2434 | int budget, int polling) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2435 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2436 | struct be_adapter *adapter = rxo->adapter; |
| 2437 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2438 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2439 | u32 work_done; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2440 | u32 frags_consumed = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2441 | |
| 2442 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2443 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2444 | if (!rxcp) |
| 2445 | break; |
| 2446 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2447 | /* Is it a flush compl that has no data */ |
| 2448 | if (unlikely(rxcp->num_rcvd == 0)) |
| 2449 | goto loop_continue; |
| 2450 | |
| 2451 | /* Discard compl with partial DMA Lancer B0 */ |
| 2452 | if (unlikely(!rxcp->pkt_size)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2453 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2454 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 2455 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 2456 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2457 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 2458 | * promiscuous mode on some skews |
| 2459 | */ |
| 2460 | if (unlikely(rxcp->port != adapter->port_num && |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2461 | !lancer_chip(adapter))) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2462 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2463 | goto loop_continue; |
| 2464 | } |
| 2465 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2466 | /* Don't do gro when we're busy_polling */ |
| 2467 | if (do_gro(rxcp) && polling != BUSY_POLLING) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2468 | be_rx_compl_process_gro(rxo, napi, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2469 | else |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2470 | be_rx_compl_process(rxo, napi, rxcp); |
| 2471 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2472 | loop_continue: |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2473 | frags_consumed += rxcp->num_rcvd; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2474 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2477 | if (work_done) { |
| 2478 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 2479 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2480 | /* When an rx-obj gets into post_starved state, just |
| 2481 | * let be_worker do the posting. |
| 2482 | */ |
| 2483 | if (atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM && |
| 2484 | !rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2485 | be_post_rx_frags(rxo, GFP_ATOMIC, |
| 2486 | max_t(u32, MAX_RX_POST, |
| 2487 | frags_consumed)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2488 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2489 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2490 | return work_done; |
| 2491 | } |
| 2492 | |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2493 | static inline void be_update_tx_err(struct be_tx_obj *txo, u32 status) |
| 2494 | { |
| 2495 | switch (status) { |
| 2496 | case BE_TX_COMP_HDR_PARSE_ERR: |
| 2497 | tx_stats(txo)->tx_hdr_parse_err++; |
| 2498 | break; |
| 2499 | case BE_TX_COMP_NDMA_ERR: |
| 2500 | tx_stats(txo)->tx_dma_err++; |
| 2501 | break; |
| 2502 | case BE_TX_COMP_ACL_ERR: |
| 2503 | tx_stats(txo)->tx_spoof_check_err++; |
| 2504 | break; |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | static inline void lancer_update_tx_err(struct be_tx_obj *txo, u32 status) |
| 2509 | { |
| 2510 | switch (status) { |
| 2511 | case LANCER_TX_COMP_LSO_ERR: |
| 2512 | tx_stats(txo)->tx_tso_err++; |
| 2513 | break; |
| 2514 | case LANCER_TX_COMP_HSW_DROP_MAC_ERR: |
| 2515 | case LANCER_TX_COMP_HSW_DROP_VLAN_ERR: |
| 2516 | tx_stats(txo)->tx_spoof_check_err++; |
| 2517 | break; |
| 2518 | case LANCER_TX_COMP_QINQ_ERR: |
| 2519 | tx_stats(txo)->tx_qinq_err++; |
| 2520 | break; |
| 2521 | case LANCER_TX_COMP_PARITY_ERR: |
| 2522 | tx_stats(txo)->tx_internal_parity_err++; |
| 2523 | break; |
| 2524 | case LANCER_TX_COMP_DMA_ERR: |
| 2525 | tx_stats(txo)->tx_dma_err++; |
| 2526 | break; |
| 2527 | } |
| 2528 | } |
| 2529 | |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2530 | static void be_process_tx(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 2531 | int idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2532 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2533 | struct be_eth_tx_compl *txcp; |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2534 | int num_wrbs = 0, work_done = 0; |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2535 | u32 compl_status; |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2536 | u16 last_idx; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2537 | |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2538 | while ((txcp = be_tx_compl_get(&txo->cq))) { |
| 2539 | last_idx = GET_TX_COMPL_BITS(wrb_index, txcp); |
| 2540 | num_wrbs += be_tx_compl_process(adapter, txo, last_idx); |
| 2541 | work_done++; |
| 2542 | |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2543 | compl_status = GET_TX_COMPL_BITS(status, txcp); |
| 2544 | if (compl_status) { |
| 2545 | if (lancer_chip(adapter)) |
| 2546 | lancer_update_tx_err(txo, compl_status); |
| 2547 | else |
| 2548 | be_update_tx_err(txo, compl_status); |
| 2549 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | if (work_done) { |
| 2553 | be_cq_notify(adapter, txo->cq.id, true, work_done); |
| 2554 | atomic_sub(num_wrbs, &txo->q.used); |
| 2555 | |
| 2556 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 2557 | * if it was stopped due to lack of tx wrbs. */ |
| 2558 | if (__netif_subqueue_stopped(adapter->netdev, idx) && |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2559 | atomic_read(&txo->q.used) < txo->q.len / 2) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2560 | netif_wake_subqueue(adapter->netdev, idx); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2561 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2562 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2563 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
| 2564 | tx_stats(txo)->tx_compl += work_done; |
| 2565 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
| 2566 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2567 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2568 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 2569 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2570 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 2571 | { |
| 2572 | bool status = true; |
| 2573 | |
| 2574 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 2575 | if (eqo->state & BE_EQ_LOCKED) { |
| 2576 | WARN_ON(eqo->state & BE_EQ_NAPI); |
| 2577 | eqo->state |= BE_EQ_NAPI_YIELD; |
| 2578 | status = false; |
| 2579 | } else { |
| 2580 | eqo->state = BE_EQ_NAPI; |
| 2581 | } |
| 2582 | spin_unlock(&eqo->lock); |
| 2583 | return status; |
| 2584 | } |
| 2585 | |
| 2586 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 2587 | { |
| 2588 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 2589 | |
| 2590 | WARN_ON(eqo->state & (BE_EQ_POLL | BE_EQ_NAPI_YIELD)); |
| 2591 | eqo->state = BE_EQ_IDLE; |
| 2592 | |
| 2593 | spin_unlock(&eqo->lock); |
| 2594 | } |
| 2595 | |
| 2596 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 2597 | { |
| 2598 | bool status = true; |
| 2599 | |
| 2600 | spin_lock_bh(&eqo->lock); |
| 2601 | if (eqo->state & BE_EQ_LOCKED) { |
| 2602 | eqo->state |= BE_EQ_POLL_YIELD; |
| 2603 | status = false; |
| 2604 | } else { |
| 2605 | eqo->state |= BE_EQ_POLL; |
| 2606 | } |
| 2607 | spin_unlock_bh(&eqo->lock); |
| 2608 | return status; |
| 2609 | } |
| 2610 | |
| 2611 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 2612 | { |
| 2613 | spin_lock_bh(&eqo->lock); |
| 2614 | |
| 2615 | WARN_ON(eqo->state & (BE_EQ_NAPI)); |
| 2616 | eqo->state = BE_EQ_IDLE; |
| 2617 | |
| 2618 | spin_unlock_bh(&eqo->lock); |
| 2619 | } |
| 2620 | |
| 2621 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 2622 | { |
| 2623 | spin_lock_init(&eqo->lock); |
| 2624 | eqo->state = BE_EQ_IDLE; |
| 2625 | } |
| 2626 | |
| 2627 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 2628 | { |
| 2629 | local_bh_disable(); |
| 2630 | |
| 2631 | /* It's enough to just acquire napi lock on the eqo to stop |
| 2632 | * be_busy_poll() from processing any queueus. |
| 2633 | */ |
| 2634 | while (!be_lock_napi(eqo)) |
| 2635 | mdelay(1); |
| 2636 | |
| 2637 | local_bh_enable(); |
| 2638 | } |
| 2639 | |
| 2640 | #else /* CONFIG_NET_RX_BUSY_POLL */ |
| 2641 | |
| 2642 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 2643 | { |
| 2644 | return true; |
| 2645 | } |
| 2646 | |
| 2647 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 2648 | { |
| 2649 | } |
| 2650 | |
| 2651 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 2652 | { |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
| 2656 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 2657 | { |
| 2658 | } |
| 2659 | |
| 2660 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 2661 | { |
| 2662 | } |
| 2663 | |
| 2664 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 2665 | { |
| 2666 | } |
| 2667 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
| 2668 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2669 | int be_poll(struct napi_struct *napi, int budget) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2670 | { |
| 2671 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2672 | struct be_adapter *adapter = eqo->adapter; |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2673 | int max_work = 0, work, i, num_evts; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2674 | struct be_rx_obj *rxo; |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 2675 | struct be_tx_obj *txo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2676 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2677 | num_evts = events_get(eqo); |
| 2678 | |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 2679 | for_all_tx_queues_on_eq(adapter, eqo, txo, i) |
| 2680 | be_process_tx(adapter, txo, i); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2681 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2682 | if (be_lock_napi(eqo)) { |
| 2683 | /* This loop will iterate twice for EQ0 in which |
| 2684 | * completions of the last RXQ (default one) are also processed |
| 2685 | * For other EQs the loop iterates only once |
| 2686 | */ |
| 2687 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2688 | work = be_process_rx(rxo, napi, budget, NAPI_POLLING); |
| 2689 | max_work = max(work, max_work); |
| 2690 | } |
| 2691 | be_unlock_napi(eqo); |
| 2692 | } else { |
| 2693 | max_work = budget; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 2694 | } |
| 2695 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2696 | if (is_mcc_eqo(eqo)) |
| 2697 | be_process_mcc(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2698 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2699 | if (max_work < budget) { |
| 2700 | napi_complete(napi); |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2701 | be_eq_notify(adapter, eqo->q.id, true, false, num_evts); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2702 | } else { |
| 2703 | /* As we'll continue in polling mode, count and clear events */ |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2704 | be_eq_notify(adapter, eqo->q.id, false, false, num_evts); |
Padmanabh Ratnakar | 93c8670 | 2011-12-19 01:53:35 +0000 | [diff] [blame] | 2705 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2706 | return max_work; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2709 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2710 | static int be_busy_poll(struct napi_struct *napi) |
| 2711 | { |
| 2712 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2713 | struct be_adapter *adapter = eqo->adapter; |
| 2714 | struct be_rx_obj *rxo; |
| 2715 | int i, work = 0; |
| 2716 | |
| 2717 | if (!be_lock_busy_poll(eqo)) |
| 2718 | return LL_FLUSH_BUSY; |
| 2719 | |
| 2720 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2721 | work = be_process_rx(rxo, napi, 4, BUSY_POLLING); |
| 2722 | if (work) |
| 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | be_unlock_busy_poll(eqo); |
| 2727 | return work; |
| 2728 | } |
| 2729 | #endif |
| 2730 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2731 | void be_detect_error(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2732 | { |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2733 | u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0; |
| 2734 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2735 | u32 i; |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2736 | bool error_detected = false; |
| 2737 | struct device *dev = &adapter->pdev->dev; |
| 2738 | struct net_device *netdev = adapter->netdev; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2739 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2740 | if (be_hw_error(adapter)) |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 2741 | return; |
| 2742 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2743 | if (lancer_chip(adapter)) { |
| 2744 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 2745 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
| 2746 | sliport_err1 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2747 | SLIPORT_ERROR1_OFFSET); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2748 | sliport_err2 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2749 | SLIPORT_ERROR2_OFFSET); |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2750 | adapter->hw_error = true; |
| 2751 | /* Do not log error messages if its a FW reset */ |
| 2752 | if (sliport_err1 == SLIPORT_ERROR_FW_RESET1 && |
| 2753 | sliport_err2 == SLIPORT_ERROR_FW_RESET2) { |
| 2754 | dev_info(dev, "Firmware update in progress\n"); |
| 2755 | } else { |
| 2756 | error_detected = true; |
| 2757 | dev_err(dev, "Error detected in the card\n"); |
| 2758 | dev_err(dev, "ERR: sliport status 0x%x\n", |
| 2759 | sliport_status); |
| 2760 | dev_err(dev, "ERR: sliport error1 0x%x\n", |
| 2761 | sliport_err1); |
| 2762 | dev_err(dev, "ERR: sliport error2 0x%x\n", |
| 2763 | sliport_err2); |
| 2764 | } |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2765 | } |
| 2766 | } else { |
| 2767 | pci_read_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2768 | PCICFG_UE_STATUS_LOW, &ue_lo); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2769 | pci_read_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2770 | PCICFG_UE_STATUS_HIGH, &ue_hi); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2771 | pci_read_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2772 | PCICFG_UE_STATUS_LOW_MASK, &ue_lo_mask); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 2773 | pci_read_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2774 | PCICFG_UE_STATUS_HI_MASK, &ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2775 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2776 | ue_lo = (ue_lo & ~ue_lo_mask); |
| 2777 | ue_hi = (ue_hi & ~ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2778 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2779 | /* On certain platforms BE hardware can indicate spurious UEs. |
| 2780 | * Allow HW to stop working completely in case of a real UE. |
| 2781 | * Hence not setting the hw_error for UE detection. |
| 2782 | */ |
| 2783 | |
| 2784 | if (ue_lo || ue_hi) { |
| 2785 | error_detected = true; |
| 2786 | dev_err(dev, |
| 2787 | "Unrecoverable Error detected in the adapter"); |
| 2788 | dev_err(dev, "Please reboot server to recover"); |
| 2789 | if (skyhawk_chip(adapter)) |
| 2790 | adapter->hw_error = true; |
| 2791 | for (i = 0; ue_lo; ue_lo >>= 1, i++) { |
| 2792 | if (ue_lo & 1) |
| 2793 | dev_err(dev, "UE: %s bit set\n", |
| 2794 | ue_status_low_desc[i]); |
| 2795 | } |
| 2796 | for (i = 0; ue_hi; ue_hi >>= 1, i++) { |
| 2797 | if (ue_hi & 1) |
| 2798 | dev_err(dev, "UE: %s bit set\n", |
| 2799 | ue_status_hi_desc[i]); |
| 2800 | } |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 2801 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2802 | } |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 2803 | if (error_detected) |
| 2804 | netif_carrier_off(netdev); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2807 | static void be_msix_disable(struct be_adapter *adapter) |
| 2808 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2809 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2810 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2811 | adapter->num_msix_vec = 0; |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2812 | adapter->num_msix_roce_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 2816 | static int be_msix_enable(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2817 | { |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2818 | int i, num_vec; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2819 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2820 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2821 | /* If RoCE is supported, program the max number of NIC vectors that |
| 2822 | * may be configured via set-channels, along with vectors needed for |
| 2823 | * RoCe. Else, just program the number we'll use initially. |
| 2824 | */ |
| 2825 | if (be_roce_supported(adapter)) |
| 2826 | num_vec = min_t(int, 2 * be_max_eqs(adapter), |
| 2827 | 2 * num_online_cpus()); |
| 2828 | else |
| 2829 | num_vec = adapter->cfg_num_qs; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2830 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2831 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2832 | adapter->msix_entries[i].entry = i; |
| 2833 | |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2834 | num_vec = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 2835 | MIN_MSIX_VECTORS, num_vec); |
| 2836 | if (num_vec < 0) |
| 2837 | goto fail; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2838 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2839 | if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) { |
| 2840 | adapter->num_msix_roce_vec = num_vec / 2; |
| 2841 | dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n", |
| 2842 | adapter->num_msix_roce_vec); |
| 2843 | } |
| 2844 | |
| 2845 | adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec; |
| 2846 | |
| 2847 | dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n", |
| 2848 | adapter->num_msix_vec); |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 2849 | return 0; |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 2850 | |
| 2851 | fail: |
| 2852 | dev_warn(dev, "MSIx enable failed\n"); |
| 2853 | |
| 2854 | /* INTx is not supported in VFs, so fail probe if enable_msix fails */ |
| 2855 | if (!be_physfn(adapter)) |
| 2856 | return num_vec; |
| 2857 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2860 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2861 | struct be_eq_obj *eqo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2862 | { |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2863 | return adapter->msix_entries[eqo->msix_idx].vector; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | static int be_msix_register(struct be_adapter *adapter) |
| 2867 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2868 | struct net_device *netdev = adapter->netdev; |
| 2869 | struct be_eq_obj *eqo; |
| 2870 | int status, i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2871 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2872 | for_all_evt_queues(adapter, eqo, i) { |
| 2873 | sprintf(eqo->desc, "%s-q%d", netdev->name, i); |
| 2874 | vec = be_msix_vec_get(adapter, eqo); |
| 2875 | status = request_irq(vec, be_msix, 0, eqo->desc, eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2876 | if (status) |
| 2877 | goto err_msix; |
| 2878 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2879 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2880 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2881 | err_msix: |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2882 | for (i--, eqo = &adapter->eq_obj[i]; i >= 0; i--, eqo--) |
| 2883 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
| 2884 | dev_warn(&adapter->pdev->dev, "MSIX Request IRQ failed - err %d\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2885 | status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2886 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2887 | return status; |
| 2888 | } |
| 2889 | |
| 2890 | static int be_irq_register(struct be_adapter *adapter) |
| 2891 | { |
| 2892 | struct net_device *netdev = adapter->netdev; |
| 2893 | int status; |
| 2894 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2895 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2896 | status = be_msix_register(adapter); |
| 2897 | if (status == 0) |
| 2898 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2899 | /* INTx is not supported for VF */ |
| 2900 | if (!be_physfn(adapter)) |
| 2901 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2904 | /* INTx: only the first EQ is used */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2905 | netdev->irq = adapter->pdev->irq; |
| 2906 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2907 | &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2908 | if (status) { |
| 2909 | dev_err(&adapter->pdev->dev, |
| 2910 | "INTx request IRQ failed - err %d\n", status); |
| 2911 | return status; |
| 2912 | } |
| 2913 | done: |
| 2914 | adapter->isr_registered = true; |
| 2915 | return 0; |
| 2916 | } |
| 2917 | |
| 2918 | static void be_irq_unregister(struct be_adapter *adapter) |
| 2919 | { |
| 2920 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2921 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2922 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2923 | |
| 2924 | if (!adapter->isr_registered) |
| 2925 | return; |
| 2926 | |
| 2927 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2928 | if (!msix_enabled(adapter)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2929 | free_irq(netdev->irq, &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2930 | goto done; |
| 2931 | } |
| 2932 | |
| 2933 | /* MSIx */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2934 | for_all_evt_queues(adapter, eqo, i) |
| 2935 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2936 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2937 | done: |
| 2938 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2941 | static void be_rx_qs_destroy(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2942 | { |
| 2943 | struct be_queue_info *q; |
| 2944 | struct be_rx_obj *rxo; |
| 2945 | int i; |
| 2946 | |
| 2947 | for_all_rx_queues(adapter, rxo, i) { |
| 2948 | q = &rxo->q; |
| 2949 | if (q->created) { |
| 2950 | be_cmd_rxq_destroy(adapter, q); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2951 | be_rx_cq_clean(rxo); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2952 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2953 | be_queue_free(adapter, q); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2954 | } |
| 2955 | } |
| 2956 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2957 | static int be_close(struct net_device *netdev) |
| 2958 | { |
| 2959 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2960 | struct be_eq_obj *eqo; |
| 2961 | int i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2962 | |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 2963 | /* This protection is needed as be_close() may be called even when the |
| 2964 | * adapter is in cleared state (after eeh perm failure) |
| 2965 | */ |
| 2966 | if (!(adapter->flags & BE_FLAGS_SETUP_DONE)) |
| 2967 | return 0; |
| 2968 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 2969 | be_roce_dev_close(adapter); |
| 2970 | |
Ivan Vecera | dff345c5 | 2013-11-27 08:59:32 +0100 | [diff] [blame] | 2971 | if (adapter->flags & BE_FLAGS_NAPI_ENABLED) { |
| 2972 | for_all_evt_queues(adapter, eqo, i) { |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 2973 | napi_disable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2974 | be_disable_busy_poll(eqo); |
| 2975 | } |
David S. Miller | 71237b6 | 2013-11-28 18:53:36 -0500 | [diff] [blame] | 2976 | adapter->flags &= ~BE_FLAGS_NAPI_ENABLED; |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 2977 | } |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2978 | |
| 2979 | be_async_mcc_disable(adapter); |
| 2980 | |
| 2981 | /* Wait for all pending tx completions to arrive so that |
| 2982 | * all tx skbs are freed. |
| 2983 | */ |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 2984 | netif_tx_disable(netdev); |
Sathya Perla | 6e1f997 | 2013-08-22 12:23:41 +0530 | [diff] [blame] | 2985 | be_tx_compl_clean(adapter); |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2986 | |
| 2987 | be_rx_qs_destroy(adapter); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 2988 | be_clear_uc_list(adapter); |
Ajit Khaparde | d11a347 | 2013-11-18 10:44:37 -0600 | [diff] [blame] | 2989 | |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 2990 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2991 | if (msix_enabled(adapter)) |
| 2992 | synchronize_irq(be_msix_vec_get(adapter, eqo)); |
| 2993 | else |
| 2994 | synchronize_irq(netdev->irq); |
| 2995 | be_eq_clean(eqo); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2996 | } |
| 2997 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2998 | be_irq_unregister(adapter); |
| 2999 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3000 | return 0; |
| 3001 | } |
| 3002 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3003 | static int be_rx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3004 | { |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3005 | struct rss_info *rss = &adapter->rss_info; |
| 3006 | u8 rss_key[RSS_HASH_KEY_LEN]; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3007 | struct be_rx_obj *rxo; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3008 | int rc, i, j; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3009 | |
| 3010 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3011 | rc = be_queue_alloc(adapter, &rxo->q, RX_Q_LEN, |
| 3012 | sizeof(struct be_eth_rx_d)); |
| 3013 | if (rc) |
| 3014 | return rc; |
| 3015 | } |
| 3016 | |
| 3017 | /* The FW would like the default RXQ to be created first */ |
| 3018 | rxo = default_rxo(adapter); |
| 3019 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, rx_frag_size, |
| 3020 | adapter->if_handle, false, &rxo->rss_id); |
| 3021 | if (rc) |
| 3022 | return rc; |
| 3023 | |
| 3024 | for_all_rss_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3025 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3026 | rx_frag_size, adapter->if_handle, |
| 3027 | true, &rxo->rss_id); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3028 | if (rc) |
| 3029 | return rc; |
| 3030 | } |
| 3031 | |
| 3032 | if (be_multi_rxq(adapter)) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3033 | for (j = 0; j < RSS_INDIR_TABLE_LEN; |
| 3034 | j += adapter->num_rx_qs - 1) { |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3035 | for_all_rss_queues(adapter, rxo, i) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3036 | if ((j + i) >= RSS_INDIR_TABLE_LEN) |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3037 | break; |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3038 | rss->rsstable[j + i] = rxo->rss_id; |
| 3039 | rss->rss_queue[j + i] = i; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3040 | } |
| 3041 | } |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3042 | rss->rss_flags = RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 | |
| 3043 | RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6; |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3044 | |
| 3045 | if (!BEx_chip(adapter)) |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3046 | rss->rss_flags |= RSS_ENABLE_UDP_IPV4 | |
| 3047 | RSS_ENABLE_UDP_IPV6; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3048 | } else { |
| 3049 | /* Disable RSS, if only default RX Q is created */ |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3050 | rss->rss_flags = RSS_ENABLE_NONE; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3051 | } |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3052 | |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3053 | netdev_rss_key_fill(rss_key, RSS_HASH_KEY_LEN); |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3054 | rc = be_cmd_rss_config(adapter, rss->rsstable, rss->rss_flags, |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3055 | 128, rss_key); |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3056 | if (rc) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3057 | rss->rss_flags = RSS_ENABLE_NONE; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3058 | return rc; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3061 | memcpy(rss->rss_hkey, rss_key, RSS_HASH_KEY_LEN); |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3062 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3063 | /* First time posting */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3064 | for_all_rx_queues(adapter, rxo, i) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 3065 | be_post_rx_frags(rxo, GFP_KERNEL, MAX_RX_POST); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3066 | return 0; |
| 3067 | } |
| 3068 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3069 | static int be_open(struct net_device *netdev) |
| 3070 | { |
| 3071 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3072 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3073 | struct be_rx_obj *rxo; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3074 | struct be_tx_obj *txo; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3075 | u8 link_status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3076 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3077 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3078 | status = be_rx_qs_create(adapter); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3079 | if (status) |
| 3080 | goto err; |
| 3081 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3082 | status = be_irq_register(adapter); |
| 3083 | if (status) |
| 3084 | goto err; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3085 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3086 | for_all_rx_queues(adapter, rxo, i) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3087 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3088 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3089 | for_all_tx_queues(adapter, txo, i) |
| 3090 | be_cq_notify(adapter, txo->cq.id, true, 0); |
| 3091 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 3092 | be_async_mcc_enable(adapter); |
| 3093 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3094 | for_all_evt_queues(adapter, eqo, i) { |
| 3095 | napi_enable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3096 | be_enable_busy_poll(eqo); |
Suresh Reddy | 4cad9f3 | 2014-07-11 14:03:01 +0530 | [diff] [blame] | 3097 | be_eq_notify(adapter, eqo->q.id, true, true, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3098 | } |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3099 | adapter->flags |= BE_FLAGS_NAPI_ENABLED; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3100 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 3101 | status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3102 | if (!status) |
| 3103 | be_link_status_update(adapter, link_status); |
| 3104 | |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 3105 | netif_tx_start_all_queues(netdev); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 3106 | be_roce_dev_open(adapter); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3107 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3108 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3109 | if (skyhawk_chip(adapter)) |
| 3110 | vxlan_get_rx_port(netdev); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3111 | #endif |
| 3112 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3113 | return 0; |
| 3114 | err: |
| 3115 | be_close(adapter->netdev); |
| 3116 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3119 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 3120 | { |
| 3121 | struct be_dma_mem cmd; |
| 3122 | int status = 0; |
| 3123 | u8 mac[ETH_ALEN]; |
| 3124 | |
| 3125 | memset(mac, 0, ETH_ALEN); |
| 3126 | |
| 3127 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 3128 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 3129 | GFP_KERNEL); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 3130 | if (!cmd.va) |
Kalesh AP | 6b56868 | 2014-07-17 16:20:22 +0530 | [diff] [blame] | 3131 | return -ENOMEM; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3132 | |
| 3133 | if (enable) { |
| 3134 | status = pci_write_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3135 | PCICFG_PM_CONTROL_OFFSET, |
| 3136 | PCICFG_PM_CONTROL_MASK); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3137 | if (status) { |
| 3138 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 3139 | "Could not enable Wake-on-lan\n"); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3140 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 3141 | cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3142 | return status; |
| 3143 | } |
| 3144 | status = be_cmd_enable_magic_wol(adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3145 | adapter->netdev->dev_addr, |
| 3146 | &cmd); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3147 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 3148 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 3149 | } else { |
| 3150 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 3151 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 3152 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 3153 | } |
| 3154 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3155 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3156 | return status; |
| 3157 | } |
| 3158 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 3159 | static void be_vf_eth_addr_generate(struct be_adapter *adapter, u8 *mac) |
| 3160 | { |
| 3161 | u32 addr; |
| 3162 | |
| 3163 | addr = jhash(adapter->netdev->dev_addr, ETH_ALEN, 0); |
| 3164 | |
| 3165 | mac[5] = (u8)(addr & 0xFF); |
| 3166 | mac[4] = (u8)((addr >> 8) & 0xFF); |
| 3167 | mac[3] = (u8)((addr >> 16) & 0xFF); |
| 3168 | /* Use the OUI from the current MAC address */ |
| 3169 | memcpy(mac, adapter->netdev->dev_addr, 3); |
| 3170 | } |
| 3171 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3172 | /* |
| 3173 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 3174 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 3175 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 3176 | * queries for the MAC address during its probe. |
| 3177 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3178 | static int be_vf_eth_addr_config(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3179 | { |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3180 | u32 vf; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3181 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3182 | u8 mac[ETH_ALEN]; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3183 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3184 | |
| 3185 | be_vf_eth_addr_generate(adapter, mac); |
| 3186 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3187 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3188 | if (BEx_chip(adapter)) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3189 | status = be_cmd_pmac_add(adapter, mac, |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3190 | vf_cfg->if_handle, |
| 3191 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3192 | else |
| 3193 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 3194 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3195 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3196 | if (status) |
| 3197 | dev_err(&adapter->pdev->dev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3198 | "Mac address assignment failed for VF %d\n", |
| 3199 | vf); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3200 | else |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3201 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3202 | |
| 3203 | mac[5] += 1; |
| 3204 | } |
| 3205 | return status; |
| 3206 | } |
| 3207 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3208 | static int be_vfs_mac_query(struct be_adapter *adapter) |
| 3209 | { |
| 3210 | int status, vf; |
| 3211 | u8 mac[ETH_ALEN]; |
| 3212 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3213 | |
| 3214 | for_all_vfs(adapter, vf_cfg, vf) { |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3215 | status = be_cmd_get_active_mac(adapter, vf_cfg->pmac_id, |
| 3216 | mac, vf_cfg->if_handle, |
| 3217 | false, vf+1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3218 | if (status) |
| 3219 | return status; |
| 3220 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
| 3221 | } |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3225 | static void be_vf_clear(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3226 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3227 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3228 | u32 vf; |
| 3229 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3230 | if (pci_vfs_assigned(adapter->pdev)) { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3231 | dev_warn(&adapter->pdev->dev, |
| 3232 | "VFs are assigned to VMs: not disabling VFs\n"); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3233 | goto done; |
| 3234 | } |
| 3235 | |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3236 | pci_disable_sriov(adapter->pdev); |
| 3237 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3238 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3239 | if (BEx_chip(adapter)) |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3240 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, |
| 3241 | vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3242 | else |
| 3243 | be_cmd_set_mac(adapter, NULL, vf_cfg->if_handle, |
| 3244 | vf + 1); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3245 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3246 | be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1); |
| 3247 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3248 | done: |
| 3249 | kfree(adapter->vf_cfg); |
| 3250 | adapter->num_vfs = 0; |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 3251 | adapter->flags &= ~BE_FLAGS_SRIOV_ENABLED; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3254 | static void be_clear_queues(struct be_adapter *adapter) |
| 3255 | { |
| 3256 | be_mcc_queues_destroy(adapter); |
| 3257 | be_rx_cqs_destroy(adapter); |
| 3258 | be_tx_queues_destroy(adapter); |
| 3259 | be_evt_queues_destroy(adapter); |
| 3260 | } |
| 3261 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3262 | static void be_cancel_worker(struct be_adapter *adapter) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3263 | { |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3264 | if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) { |
| 3265 | cancel_delayed_work_sync(&adapter->work); |
| 3266 | adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED; |
| 3267 | } |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3268 | } |
| 3269 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3270 | static void be_mac_clear(struct be_adapter *adapter) |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3271 | { |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3272 | if (adapter->pmac_id) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 3273 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 3274 | adapter->pmac_id[0], 0); |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3275 | kfree(adapter->pmac_id); |
| 3276 | adapter->pmac_id = NULL; |
| 3277 | } |
| 3278 | } |
| 3279 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3280 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3281 | static void be_disable_vxlan_offloads(struct be_adapter *adapter) |
| 3282 | { |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 3283 | struct net_device *netdev = adapter->netdev; |
| 3284 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3285 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) |
| 3286 | be_cmd_manage_iface(adapter, adapter->if_handle, |
| 3287 | OP_CONVERT_TUNNEL_TO_NORMAL); |
| 3288 | |
| 3289 | if (adapter->vxlan_port) |
| 3290 | be_cmd_set_vxlan_port(adapter, 0); |
| 3291 | |
| 3292 | adapter->flags &= ~BE_FLAGS_VXLAN_OFFLOADS; |
| 3293 | adapter->vxlan_port = 0; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 3294 | |
| 3295 | netdev->hw_enc_features = 0; |
| 3296 | netdev->hw_features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 3297 | netdev->features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3298 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3299 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3300 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3301 | static int be_clear(struct be_adapter *adapter) |
| 3302 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3303 | be_cancel_worker(adapter); |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3304 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3305 | if (sriov_enabled(adapter)) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3306 | be_vf_clear(adapter); |
| 3307 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3308 | /* Re-configure FW to distribute resources evenly across max-supported |
| 3309 | * number of VFs, only when VFs are not already enabled. |
| 3310 | */ |
| 3311 | if (be_physfn(adapter) && !pci_vfs_assigned(adapter->pdev)) |
| 3312 | be_cmd_set_sriov_config(adapter, adapter->pool_res, |
| 3313 | pci_sriov_get_totalvfs(adapter->pdev)); |
| 3314 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3315 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3316 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3317 | #endif |
Sathya Perla | 2d17f40 | 2013-07-23 15:25:04 +0530 | [diff] [blame] | 3318 | /* delete the primary mac along with the uc-mac list */ |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3319 | be_mac_clear(adapter); |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 3320 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3321 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3322 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3323 | be_clear_queues(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3324 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3325 | be_msix_disable(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 3326 | adapter->flags &= ~BE_FLAGS_SETUP_DONE; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3327 | return 0; |
| 3328 | } |
| 3329 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3330 | static int be_if_create(struct be_adapter *adapter, u32 *if_handle, |
| 3331 | u32 cap_flags, u32 vf) |
| 3332 | { |
| 3333 | u32 en_flags; |
| 3334 | int status; |
| 3335 | |
| 3336 | en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 3337 | BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS | |
| 3338 | BE_IF_FLAGS_RSS; |
| 3339 | |
| 3340 | en_flags &= cap_flags; |
| 3341 | |
| 3342 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 3343 | if_handle, vf); |
| 3344 | |
| 3345 | return status; |
| 3346 | } |
| 3347 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3348 | static int be_vfs_if_create(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3349 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3350 | struct be_resources res = {0}; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3351 | struct be_vf_cfg *vf_cfg; |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3352 | u32 cap_flags, vf; |
| 3353 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3354 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3355 | /* If a FW profile exists, then cap_flags are updated */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3356 | cap_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 3357 | BE_IF_FLAGS_MULTICAST; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3358 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3359 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3360 | if (!BE3_chip(adapter)) { |
| 3361 | status = be_cmd_get_profile_config(adapter, &res, |
| 3362 | vf + 1); |
| 3363 | if (!status) |
| 3364 | cap_flags = res.if_cap_flags; |
| 3365 | } |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3366 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3367 | status = be_if_create(adapter, &vf_cfg->if_handle, |
| 3368 | cap_flags, vf + 1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3369 | if (status) |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3370 | return status; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3371 | } |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3372 | |
| 3373 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3376 | static int be_vf_setup_init(struct be_adapter *adapter) |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3377 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3378 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3379 | int vf; |
| 3380 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3381 | adapter->vf_cfg = kcalloc(adapter->num_vfs, sizeof(*vf_cfg), |
| 3382 | GFP_KERNEL); |
| 3383 | if (!adapter->vf_cfg) |
| 3384 | return -ENOMEM; |
| 3385 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3386 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3387 | vf_cfg->if_handle = -1; |
| 3388 | vf_cfg->pmac_id = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3389 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3390 | return 0; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3393 | static int be_vf_setup(struct be_adapter *adapter) |
| 3394 | { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3395 | struct device *dev = &adapter->pdev->dev; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 3396 | struct be_vf_cfg *vf_cfg; |
| 3397 | int status, old_vfs, vf; |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3398 | u32 privileges; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3399 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3400 | old_vfs = pci_num_vf(adapter->pdev); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3401 | |
| 3402 | status = be_vf_setup_init(adapter); |
| 3403 | if (status) |
| 3404 | goto err; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3405 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3406 | if (old_vfs) { |
| 3407 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3408 | status = be_cmd_get_if_id(adapter, vf_cfg, vf); |
| 3409 | if (status) |
| 3410 | goto err; |
| 3411 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3412 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3413 | status = be_vfs_mac_query(adapter); |
| 3414 | if (status) |
| 3415 | goto err; |
| 3416 | } else { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3417 | status = be_vfs_if_create(adapter); |
| 3418 | if (status) |
| 3419 | goto err; |
| 3420 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3421 | status = be_vf_eth_addr_config(adapter); |
| 3422 | if (status) |
| 3423 | goto err; |
| 3424 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3425 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3426 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3427 | /* Allow VFs to programs MAC/VLAN filters */ |
| 3428 | status = be_cmd_get_fn_privileges(adapter, &privileges, vf + 1); |
| 3429 | if (!status && !(privileges & BE_PRIV_FILTMGMT)) { |
| 3430 | status = be_cmd_set_fn_privileges(adapter, |
| 3431 | privileges | |
| 3432 | BE_PRIV_FILTMGMT, |
| 3433 | vf + 1); |
| 3434 | if (!status) |
| 3435 | dev_info(dev, "VF%d has FILTMGMT privilege\n", |
| 3436 | vf); |
| 3437 | } |
| 3438 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 3439 | /* Allow full available bandwidth */ |
| 3440 | if (!old_vfs) |
| 3441 | be_cmd_config_qos(adapter, 0, 0, vf + 1); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3442 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3443 | if (!old_vfs) { |
Vasundhara Volam | 0599863 | 2013-10-01 15:59:59 +0530 | [diff] [blame] | 3444 | be_cmd_enable_vf(adapter, vf + 1); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3445 | be_cmd_set_logical_link_config(adapter, |
| 3446 | IFLA_VF_LINK_STATE_AUTO, |
| 3447 | vf+1); |
| 3448 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3449 | } |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3450 | |
| 3451 | if (!old_vfs) { |
| 3452 | status = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 3453 | if (status) { |
| 3454 | dev_err(dev, "SRIOV enable failed\n"); |
| 3455 | adapter->num_vfs = 0; |
| 3456 | goto err; |
| 3457 | } |
| 3458 | } |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 3459 | |
| 3460 | adapter->flags |= BE_FLAGS_SRIOV_ENABLED; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3461 | return 0; |
| 3462 | err: |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3463 | dev_err(dev, "VF setup failed\n"); |
| 3464 | be_vf_clear(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3465 | return status; |
| 3466 | } |
| 3467 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3468 | /* Converting function_mode bits on BE3 to SH mc_type enums */ |
| 3469 | |
| 3470 | static u8 be_convert_mc_type(u32 function_mode) |
| 3471 | { |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 3472 | if (function_mode & VNIC_MODE && function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3473 | return vNIC1; |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 3474 | else if (function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3475 | return FLEX10; |
| 3476 | else if (function_mode & VNIC_MODE) |
| 3477 | return vNIC2; |
| 3478 | else if (function_mode & UMC_ENABLED) |
| 3479 | return UMC; |
| 3480 | else |
| 3481 | return MC_NONE; |
| 3482 | } |
| 3483 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3484 | /* On BE2/BE3 FW does not suggest the supported limits */ |
| 3485 | static void BEx_get_resources(struct be_adapter *adapter, |
| 3486 | struct be_resources *res) |
| 3487 | { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3488 | bool use_sriov = adapter->num_vfs ? 1 : 0; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3489 | |
| 3490 | if (be_physfn(adapter)) |
| 3491 | res->max_uc_mac = BE_UC_PMAC_COUNT; |
| 3492 | else |
| 3493 | res->max_uc_mac = BE_VF_UC_PMAC_COUNT; |
| 3494 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3495 | adapter->mc_type = be_convert_mc_type(adapter->function_mode); |
| 3496 | |
| 3497 | if (be_is_mc(adapter)) { |
| 3498 | /* Assuming that there are 4 channels per port, |
| 3499 | * when multi-channel is enabled |
| 3500 | */ |
| 3501 | if (be_is_qnq_mode(adapter)) |
| 3502 | res->max_vlans = BE_NUM_VLANS_SUPPORTED/8; |
| 3503 | else |
| 3504 | /* In a non-qnq multichannel mode, the pvid |
| 3505 | * takes up one vlan entry |
| 3506 | */ |
| 3507 | res->max_vlans = (BE_NUM_VLANS_SUPPORTED / 4) - 1; |
| 3508 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3509 | res->max_vlans = BE_NUM_VLANS_SUPPORTED; |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3510 | } |
| 3511 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3512 | res->max_mcast_mac = BE_MAX_MC; |
| 3513 | |
Vasundhara Volam | a5243da | 2014-03-11 18:53:07 +0530 | [diff] [blame] | 3514 | /* 1) For BE3 1Gb ports, FW does not support multiple TXQs |
| 3515 | * 2) Create multiple TX rings on a BE3-R multi-channel interface |
| 3516 | * *only* if it is RSS-capable. |
| 3517 | */ |
| 3518 | if (BE2_chip(adapter) || use_sriov || (adapter->port_num > 1) || |
| 3519 | !be_physfn(adapter) || (be_is_mc(adapter) && |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3520 | !(adapter->function_caps & BE_FUNCTION_CAPS_RSS))) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3521 | res->max_tx_qs = 1; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3522 | } else if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { |
| 3523 | struct be_resources super_nic_res = {0}; |
| 3524 | |
| 3525 | /* On a SuperNIC profile, the driver needs to use the |
| 3526 | * GET_PROFILE_CONFIG cmd to query the per-function TXQ limits |
| 3527 | */ |
| 3528 | be_cmd_get_profile_config(adapter, &super_nic_res, 0); |
| 3529 | /* Some old versions of BE3 FW don't report max_tx_qs value */ |
| 3530 | res->max_tx_qs = super_nic_res.max_tx_qs ? : BE3_MAX_TX_QS; |
| 3531 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3532 | res->max_tx_qs = BE3_MAX_TX_QS; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3533 | } |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3534 | |
| 3535 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
| 3536 | !use_sriov && be_physfn(adapter)) |
| 3537 | res->max_rss_qs = (adapter->be3_native) ? |
| 3538 | BE3_MAX_RSS_QS : BE2_MAX_RSS_QS; |
| 3539 | res->max_rx_qs = res->max_rss_qs + 1; |
| 3540 | |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3541 | if (be_physfn(adapter)) |
Vasundhara Volam | d3518e2 | 2014-07-17 16:20:29 +0530 | [diff] [blame] | 3542 | res->max_evt_qs = (be_max_vfs(adapter) > 0) ? |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3543 | BE3_SRIOV_MAX_EVT_QS : BE3_MAX_EVT_QS; |
| 3544 | else |
| 3545 | res->max_evt_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3546 | |
| 3547 | res->if_cap_flags = BE_IF_CAP_FLAGS_WANT; |
| 3548 | if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS)) |
| 3549 | res->if_cap_flags &= ~BE_IF_FLAGS_RSS; |
| 3550 | } |
| 3551 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3552 | static void be_setup_init(struct be_adapter *adapter) |
| 3553 | { |
| 3554 | adapter->vlan_prio_bmap = 0xff; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3555 | adapter->phy.link_speed = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3556 | adapter->if_handle = -1; |
| 3557 | adapter->be3_native = false; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame^] | 3558 | adapter->if_flags = 0; |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3559 | if (be_physfn(adapter)) |
| 3560 | adapter->cmd_privileges = MAX_PRIVILEGES; |
| 3561 | else |
| 3562 | adapter->cmd_privileges = MIN_PRIVILEGES; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3565 | static int be_get_sriov_config(struct be_adapter *adapter) |
| 3566 | { |
| 3567 | struct device *dev = &adapter->pdev->dev; |
| 3568 | struct be_resources res = {0}; |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3569 | int max_vfs, old_vfs; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3570 | |
| 3571 | /* Some old versions of BE3 FW don't report max_vfs value */ |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3572 | be_cmd_get_profile_config(adapter, &res, 0); |
| 3573 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3574 | if (BE3_chip(adapter) && !res.max_vfs) { |
| 3575 | max_vfs = pci_sriov_get_totalvfs(adapter->pdev); |
| 3576 | res.max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0; |
| 3577 | } |
| 3578 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3579 | adapter->pool_res = res; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3580 | |
| 3581 | if (!be_max_vfs(adapter)) { |
| 3582 | if (num_vfs) |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 3583 | dev_warn(dev, "SRIOV is disabled. Ignoring num_vfs\n"); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3584 | adapter->num_vfs = 0; |
| 3585 | return 0; |
| 3586 | } |
| 3587 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3588 | pci_sriov_set_totalvfs(adapter->pdev, be_max_vfs(adapter)); |
| 3589 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3590 | /* validate num_vfs module param */ |
| 3591 | old_vfs = pci_num_vf(adapter->pdev); |
| 3592 | if (old_vfs) { |
| 3593 | dev_info(dev, "%d VFs are already enabled\n", old_vfs); |
| 3594 | if (old_vfs != num_vfs) |
| 3595 | dev_warn(dev, "Ignoring num_vfs=%d setting\n", num_vfs); |
| 3596 | adapter->num_vfs = old_vfs; |
| 3597 | } else { |
| 3598 | if (num_vfs > be_max_vfs(adapter)) { |
| 3599 | dev_info(dev, "Resources unavailable to init %d VFs\n", |
| 3600 | num_vfs); |
| 3601 | dev_info(dev, "Limiting to %d VFs\n", |
| 3602 | be_max_vfs(adapter)); |
| 3603 | } |
| 3604 | adapter->num_vfs = min_t(u16, num_vfs, be_max_vfs(adapter)); |
| 3605 | } |
| 3606 | |
| 3607 | return 0; |
| 3608 | } |
| 3609 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3610 | static int be_get_resources(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3611 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3612 | struct device *dev = &adapter->pdev->dev; |
| 3613 | struct be_resources res = {0}; |
| 3614 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3615 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3616 | if (BEx_chip(adapter)) { |
| 3617 | BEx_get_resources(adapter, &res); |
| 3618 | adapter->res = res; |
| 3619 | } |
| 3620 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3621 | /* For Lancer, SH etc read per-function resource limits from FW. |
| 3622 | * GET_FUNC_CONFIG returns per function guaranteed limits. |
| 3623 | * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits |
| 3624 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3625 | if (!BEx_chip(adapter)) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3626 | status = be_cmd_get_func_config(adapter, &res); |
| 3627 | if (status) |
| 3628 | return status; |
| 3629 | |
| 3630 | /* If RoCE may be enabled stash away half the EQs for RoCE */ |
| 3631 | if (be_roce_supported(adapter)) |
| 3632 | res.max_evt_qs /= 2; |
| 3633 | adapter->res = res; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 3636 | dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n", |
| 3637 | be_max_txqs(adapter), be_max_rxqs(adapter), |
| 3638 | be_max_rss(adapter), be_max_eqs(adapter), |
| 3639 | be_max_vfs(adapter)); |
| 3640 | dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n", |
| 3641 | be_max_uc(adapter), be_max_mc(adapter), |
| 3642 | be_max_vlans(adapter)); |
| 3643 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3644 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3647 | static void be_sriov_config(struct be_adapter *adapter) |
| 3648 | { |
| 3649 | struct device *dev = &adapter->pdev->dev; |
| 3650 | int status; |
| 3651 | |
| 3652 | status = be_get_sriov_config(adapter); |
| 3653 | if (status) { |
| 3654 | dev_err(dev, "Failed to query SR-IOV configuration\n"); |
| 3655 | dev_err(dev, "SR-IOV cannot be enabled\n"); |
| 3656 | return; |
| 3657 | } |
| 3658 | |
| 3659 | /* When the HW is in SRIOV capable configuration, the PF-pool |
| 3660 | * resources are equally distributed across the max-number of |
| 3661 | * VFs. The user may request only a subset of the max-vfs to be |
| 3662 | * enabled. Based on num_vfs, redistribute the resources across |
| 3663 | * num_vfs so that each VF will have access to more number of |
| 3664 | * resources. This facility is not available in BE3 FW. |
| 3665 | * Also, this is done by FW in Lancer chip. |
| 3666 | */ |
| 3667 | if (be_max_vfs(adapter) && !pci_num_vf(adapter->pdev)) { |
| 3668 | status = be_cmd_set_sriov_config(adapter, |
| 3669 | adapter->pool_res, |
| 3670 | adapter->num_vfs); |
| 3671 | if (status) |
| 3672 | dev_err(dev, "Failed to optimize SR-IOV resources\n"); |
| 3673 | } |
| 3674 | } |
| 3675 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3676 | static int be_get_config(struct be_adapter *adapter) |
| 3677 | { |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 3678 | u16 profile_id; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3679 | int status; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3680 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 3681 | status = be_cmd_query_fw_cfg(adapter); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3682 | if (status) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3683 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3684 | |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 3685 | if (be_physfn(adapter)) { |
| 3686 | status = be_cmd_get_active_profile(adapter, &profile_id); |
| 3687 | if (!status) |
| 3688 | dev_info(&adapter->pdev->dev, |
| 3689 | "Using profile 0x%x\n", profile_id); |
Vasundhara Volam | 962bcb7 | 2014-07-17 16:20:30 +0530 | [diff] [blame] | 3690 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3691 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3692 | if (!BE2_chip(adapter) && be_physfn(adapter)) |
| 3693 | be_sriov_config(adapter); |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 3694 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3695 | status = be_get_resources(adapter); |
| 3696 | if (status) |
| 3697 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3698 | |
Ravikumar Nelavelli | 46ee9c1 | 2014-03-11 18:53:06 +0530 | [diff] [blame] | 3699 | adapter->pmac_id = kcalloc(be_max_uc(adapter), |
| 3700 | sizeof(*adapter->pmac_id), GFP_KERNEL); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3701 | if (!adapter->pmac_id) |
| 3702 | return -ENOMEM; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3703 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3704 | /* Sanitize cfg_num_qs based on HW and platform limits */ |
| 3705 | adapter->cfg_num_qs = min(adapter->cfg_num_qs, be_max_qs(adapter)); |
| 3706 | |
| 3707 | return 0; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3708 | } |
| 3709 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3710 | static int be_mac_setup(struct be_adapter *adapter) |
| 3711 | { |
| 3712 | u8 mac[ETH_ALEN]; |
| 3713 | int status; |
| 3714 | |
| 3715 | if (is_zero_ether_addr(adapter->netdev->dev_addr)) { |
| 3716 | status = be_cmd_get_perm_mac(adapter, mac); |
| 3717 | if (status) |
| 3718 | return status; |
| 3719 | |
| 3720 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 3721 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 3722 | } else { |
| 3723 | /* Maybe the HW was reset; dev_addr must be re-programmed */ |
| 3724 | memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN); |
| 3725 | } |
| 3726 | |
Ajit Khaparde | 2c7a9dc | 2013-11-22 12:51:28 -0600 | [diff] [blame] | 3727 | /* For BE3-R VFs, the PF programs the initial MAC address */ |
| 3728 | if (!(BEx_chip(adapter) && be_virtfn(adapter))) |
| 3729 | be_cmd_pmac_add(adapter, mac, adapter->if_handle, |
| 3730 | &adapter->pmac_id[0], 0); |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3731 | return 0; |
| 3732 | } |
| 3733 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3734 | static void be_schedule_worker(struct be_adapter *adapter) |
| 3735 | { |
| 3736 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 3737 | adapter->flags |= BE_FLAGS_WORKER_SCHEDULED; |
| 3738 | } |
| 3739 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3740 | static int be_setup_queues(struct be_adapter *adapter) |
| 3741 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3742 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3743 | int status; |
| 3744 | |
| 3745 | status = be_evt_queues_create(adapter); |
| 3746 | if (status) |
| 3747 | goto err; |
| 3748 | |
| 3749 | status = be_tx_qs_create(adapter); |
| 3750 | if (status) |
| 3751 | goto err; |
| 3752 | |
| 3753 | status = be_rx_cqs_create(adapter); |
| 3754 | if (status) |
| 3755 | goto err; |
| 3756 | |
| 3757 | status = be_mcc_queues_create(adapter); |
| 3758 | if (status) |
| 3759 | goto err; |
| 3760 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3761 | status = netif_set_real_num_rx_queues(netdev, adapter->num_rx_qs); |
| 3762 | if (status) |
| 3763 | goto err; |
| 3764 | |
| 3765 | status = netif_set_real_num_tx_queues(netdev, adapter->num_tx_qs); |
| 3766 | if (status) |
| 3767 | goto err; |
| 3768 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3769 | return 0; |
| 3770 | err: |
| 3771 | dev_err(&adapter->pdev->dev, "queue_setup failed\n"); |
| 3772 | return status; |
| 3773 | } |
| 3774 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3775 | int be_update_queues(struct be_adapter *adapter) |
| 3776 | { |
| 3777 | struct net_device *netdev = adapter->netdev; |
| 3778 | int status; |
| 3779 | |
| 3780 | if (netif_running(netdev)) |
| 3781 | be_close(netdev); |
| 3782 | |
| 3783 | be_cancel_worker(adapter); |
| 3784 | |
| 3785 | /* If any vectors have been shared with RoCE we cannot re-program |
| 3786 | * the MSIx table. |
| 3787 | */ |
| 3788 | if (!adapter->num_msix_roce_vec) |
| 3789 | be_msix_disable(adapter); |
| 3790 | |
| 3791 | be_clear_queues(adapter); |
| 3792 | |
| 3793 | if (!msix_enabled(adapter)) { |
| 3794 | status = be_msix_enable(adapter); |
| 3795 | if (status) |
| 3796 | return status; |
| 3797 | } |
| 3798 | |
| 3799 | status = be_setup_queues(adapter); |
| 3800 | if (status) |
| 3801 | return status; |
| 3802 | |
| 3803 | be_schedule_worker(adapter); |
| 3804 | |
| 3805 | if (netif_running(netdev)) |
| 3806 | status = be_open(netdev); |
| 3807 | |
| 3808 | return status; |
| 3809 | } |
| 3810 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 3811 | static inline int fw_major_num(const char *fw_ver) |
| 3812 | { |
| 3813 | int fw_major = 0, i; |
| 3814 | |
| 3815 | i = sscanf(fw_ver, "%d.", &fw_major); |
| 3816 | if (i != 1) |
| 3817 | return 0; |
| 3818 | |
| 3819 | return fw_major; |
| 3820 | } |
| 3821 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3822 | static int be_setup(struct be_adapter *adapter) |
| 3823 | { |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3824 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3825 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3826 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3827 | be_setup_init(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3828 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3829 | if (!lancer_chip(adapter)) |
| 3830 | be_cmd_req_native_mode(adapter); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3831 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3832 | status = be_get_config(adapter); |
| 3833 | if (status) |
| 3834 | goto err; |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 3835 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3836 | status = be_msix_enable(adapter); |
| 3837 | if (status) |
| 3838 | goto err; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3839 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3840 | status = be_if_create(adapter, &adapter->if_handle, |
| 3841 | be_if_cap_flags(adapter), 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3842 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3843 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3844 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3845 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 3846 | rtnl_lock(); |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3847 | status = be_setup_queues(adapter); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3848 | rtnl_unlock(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3849 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3850 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3851 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3852 | be_cmd_get_fn_privileges(adapter, &adapter->cmd_privileges, 0); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3853 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3854 | status = be_mac_setup(adapter); |
| 3855 | if (status) |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 3856 | goto err; |
| 3857 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 3858 | be_cmd_get_fw_ver(adapter); |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 3859 | dev_info(dev, "FW version is %s\n", adapter->fw_ver); |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 3860 | |
Somnath Kotur | e9e2a90 | 2013-10-24 14:37:53 +0530 | [diff] [blame] | 3861 | if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 3862 | dev_err(dev, "Firmware on card is old(%s), IRQs may not work", |
Somnath Kotur | e9e2a90 | 2013-10-24 14:37:53 +0530 | [diff] [blame] | 3863 | adapter->fw_ver); |
| 3864 | dev_err(dev, "Please upgrade firmware to version >= 4.0\n"); |
| 3865 | } |
| 3866 | |
Sathya Perla | 1d1e9a4 | 2012-06-05 19:37:17 +0000 | [diff] [blame] | 3867 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 3868 | be_vid_config(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3869 | |
| 3870 | be_set_rx_mode(adapter->netdev); |
| 3871 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 3872 | be_cmd_get_acpi_wol_cap(adapter); |
| 3873 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 3874 | status = be_cmd_set_flow_control(adapter, adapter->tx_fc, |
| 3875 | adapter->rx_fc); |
| 3876 | if (status) |
| 3877 | be_cmd_get_flow_control(adapter, &adapter->tx_fc, |
| 3878 | &adapter->rx_fc); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3879 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 3880 | dev_info(&adapter->pdev->dev, "HW Flow control - TX:%d RX:%d\n", |
| 3881 | adapter->tx_fc, adapter->rx_fc); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3882 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3883 | if (be_physfn(adapter)) |
| 3884 | be_cmd_set_logical_link_config(adapter, |
| 3885 | IFLA_VF_LINK_STATE_AUTO, 0); |
| 3886 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3887 | if (adapter->num_vfs) |
| 3888 | be_vf_setup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3889 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3890 | status = be_cmd_get_phy_info(adapter); |
| 3891 | if (!status && be_pause_supported(adapter)) |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3892 | adapter->phy.fc_autoneg = 1; |
| 3893 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3894 | be_schedule_worker(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 3895 | adapter->flags |= BE_FLAGS_SETUP_DONE; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3896 | return 0; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3897 | err: |
| 3898 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3899 | return status; |
| 3900 | } |
| 3901 | |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3902 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3903 | static void be_netpoll(struct net_device *netdev) |
| 3904 | { |
| 3905 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3906 | struct be_eq_obj *eqo; |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3907 | int i; |
| 3908 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3909 | for_all_evt_queues(adapter, eqo, i) { |
| 3910 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0); |
| 3911 | napi_schedule(&eqo->napi); |
| 3912 | } |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 3913 | } |
| 3914 | #endif |
| 3915 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 3916 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 3917 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3918 | static bool phy_flashing_required(struct be_adapter *adapter) |
| 3919 | { |
Vasundhara Volam | e02cfd9 | 2015-01-20 03:51:48 -0500 | [diff] [blame] | 3920 | return (adapter->phy.phy_type == PHY_TYPE_TN_8022 && |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3921 | adapter->phy.interface_type == PHY_TYPE_BASET_10GB); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3924 | static bool is_comp_in_ufi(struct be_adapter *adapter, |
| 3925 | struct flash_section_info *fsec, int type) |
| 3926 | { |
| 3927 | int i = 0, img_type = 0; |
| 3928 | struct flash_section_info_g2 *fsec_g2 = NULL; |
| 3929 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 3930 | if (BE2_chip(adapter)) |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3931 | fsec_g2 = (struct flash_section_info_g2 *)fsec; |
| 3932 | |
| 3933 | for (i = 0; i < MAX_FLASH_COMP; i++) { |
| 3934 | if (fsec_g2) |
| 3935 | img_type = le32_to_cpu(fsec_g2->fsec_entry[i].type); |
| 3936 | else |
| 3937 | img_type = le32_to_cpu(fsec->fsec_entry[i].type); |
| 3938 | |
| 3939 | if (img_type == type) |
| 3940 | return true; |
| 3941 | } |
| 3942 | return false; |
| 3943 | |
| 3944 | } |
| 3945 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 3946 | static struct flash_section_info *get_fsec_info(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3947 | int header_size, |
| 3948 | const struct firmware *fw) |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 3949 | { |
| 3950 | struct flash_section_info *fsec = NULL; |
| 3951 | const u8 *p = fw->data; |
| 3952 | |
| 3953 | p += header_size; |
| 3954 | while (p < (fw->data + fw->size)) { |
| 3955 | fsec = (struct flash_section_info *)p; |
| 3956 | if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie))) |
| 3957 | return fsec; |
| 3958 | p += 32; |
| 3959 | } |
| 3960 | return NULL; |
| 3961 | } |
| 3962 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 3963 | static int be_check_flash_crc(struct be_adapter *adapter, const u8 *p, |
| 3964 | u32 img_offset, u32 img_size, int hdr_size, |
| 3965 | u16 img_optype, bool *crc_match) |
| 3966 | { |
| 3967 | u32 crc_offset; |
| 3968 | int status; |
| 3969 | u8 crc[4]; |
| 3970 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 3971 | status = be_cmd_get_flash_crc(adapter, crc, img_optype, img_offset, |
| 3972 | img_size - 4); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 3973 | if (status) |
| 3974 | return status; |
| 3975 | |
| 3976 | crc_offset = hdr_size + img_offset + img_size - 4; |
| 3977 | |
| 3978 | /* Skip flashing, if crc of flashed region matches */ |
| 3979 | if (!memcmp(crc, p + crc_offset, 4)) |
| 3980 | *crc_match = true; |
| 3981 | else |
| 3982 | *crc_match = false; |
| 3983 | |
| 3984 | return status; |
| 3985 | } |
| 3986 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3987 | static int be_flash(struct be_adapter *adapter, const u8 *img, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 3988 | struct be_dma_mem *flash_cmd, int optype, int img_size, |
| 3989 | u32 img_offset) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3990 | { |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 3991 | u32 flash_op, num_bytes, total_bytes = img_size, bytes_sent = 0; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3992 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 3993 | int status; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3994 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 3995 | while (total_bytes) { |
| 3996 | num_bytes = min_t(u32, 32*1024, total_bytes); |
| 3997 | |
| 3998 | total_bytes -= num_bytes; |
| 3999 | |
| 4000 | if (!total_bytes) { |
| 4001 | if (optype == OPTYPE_PHY_FW) |
| 4002 | flash_op = FLASHROM_OPER_PHY_FLASH; |
| 4003 | else |
| 4004 | flash_op = FLASHROM_OPER_FLASH; |
| 4005 | } else { |
| 4006 | if (optype == OPTYPE_PHY_FW) |
| 4007 | flash_op = FLASHROM_OPER_PHY_SAVE; |
| 4008 | else |
| 4009 | flash_op = FLASHROM_OPER_SAVE; |
| 4010 | } |
| 4011 | |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 4012 | memcpy(req->data_buf, img, num_bytes); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4013 | img += num_bytes; |
| 4014 | status = be_cmd_write_flashrom(adapter, flash_cmd, optype, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4015 | flash_op, img_offset + |
| 4016 | bytes_sent, num_bytes); |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4017 | if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST && |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4018 | optype == OPTYPE_PHY_FW) |
| 4019 | break; |
| 4020 | else if (status) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4021 | return status; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4022 | |
| 4023 | bytes_sent += num_bytes; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4024 | } |
| 4025 | return 0; |
| 4026 | } |
| 4027 | |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4028 | /* For BE2, BE3 and BE3-R */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4029 | static int be_flash_BEx(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4030 | const struct firmware *fw, |
| 4031 | struct be_dma_mem *flash_cmd, int num_of_images) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4032 | { |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4033 | int img_hdrs_size = (num_of_images * sizeof(struct image_hdr)); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4034 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4035 | struct flash_section_info *fsec = NULL; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4036 | int status, i, filehdr_size, num_comp; |
| 4037 | const struct flash_comp *pflashcomp; |
| 4038 | bool crc_match; |
| 4039 | const u8 *p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4040 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4041 | struct flash_comp gen3_flash_types[] = { |
| 4042 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, OPTYPE_ISCSI_ACTIVE, |
| 4043 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_iSCSI}, |
| 4044 | { FLASH_REDBOOT_START_g3, OPTYPE_REDBOOT, |
| 4045 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3, IMAGE_BOOT_CODE}, |
| 4046 | { FLASH_iSCSI_BIOS_START_g3, OPTYPE_BIOS, |
| 4047 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_ISCSI}, |
| 4048 | { FLASH_PXE_BIOS_START_g3, OPTYPE_PXE_BIOS, |
| 4049 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_PXE}, |
| 4050 | { FLASH_FCoE_BIOS_START_g3, OPTYPE_FCOE_BIOS, |
| 4051 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_FCoE}, |
| 4052 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, OPTYPE_ISCSI_BACKUP, |
| 4053 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 4054 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, OPTYPE_FCOE_FW_ACTIVE, |
| 4055 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_FCoE}, |
| 4056 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, OPTYPE_FCOE_FW_BACKUP, |
| 4057 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_FCoE}, |
| 4058 | { FLASH_NCSI_START_g3, OPTYPE_NCSI_FW, |
| 4059 | FLASH_NCSI_IMAGE_MAX_SIZE_g3, IMAGE_NCSI}, |
| 4060 | { FLASH_PHY_FW_START_g3, OPTYPE_PHY_FW, |
| 4061 | FLASH_PHY_FW_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_PHY} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4062 | }; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4063 | |
| 4064 | struct flash_comp gen2_flash_types[] = { |
| 4065 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, OPTYPE_ISCSI_ACTIVE, |
| 4066 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_iSCSI}, |
| 4067 | { FLASH_REDBOOT_START_g2, OPTYPE_REDBOOT, |
| 4068 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2, IMAGE_BOOT_CODE}, |
| 4069 | { FLASH_iSCSI_BIOS_START_g2, OPTYPE_BIOS, |
| 4070 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_ISCSI}, |
| 4071 | { FLASH_PXE_BIOS_START_g2, OPTYPE_PXE_BIOS, |
| 4072 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_PXE}, |
| 4073 | { FLASH_FCoE_BIOS_START_g2, OPTYPE_FCOE_BIOS, |
| 4074 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_FCoE}, |
| 4075 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, OPTYPE_ISCSI_BACKUP, |
| 4076 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 4077 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, OPTYPE_FCOE_FW_ACTIVE, |
| 4078 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_FCoE}, |
| 4079 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, OPTYPE_FCOE_FW_BACKUP, |
| 4080 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_FCoE} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4081 | }; |
| 4082 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4083 | if (BE3_chip(adapter)) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4084 | pflashcomp = gen3_flash_types; |
| 4085 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 4086 | num_comp = ARRAY_SIZE(gen3_flash_types); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4087 | } else { |
| 4088 | pflashcomp = gen2_flash_types; |
| 4089 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 4090 | num_comp = ARRAY_SIZE(gen2_flash_types); |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4091 | img_hdrs_size = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4092 | } |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4093 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4094 | /* Get flash section info*/ |
| 4095 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 4096 | if (!fsec) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4097 | dev_err(dev, "Invalid Cookie. FW image may be corrupted\n"); |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4098 | return -1; |
| 4099 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 4100 | for (i = 0; i < num_comp; i++) { |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4101 | if (!is_comp_in_ufi(adapter, fsec, pflashcomp[i].img_type)) |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 4102 | continue; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4103 | |
| 4104 | if ((pflashcomp[i].optype == OPTYPE_NCSI_FW) && |
| 4105 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 4106 | continue; |
| 4107 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4108 | if (pflashcomp[i].optype == OPTYPE_PHY_FW && |
| 4109 | !phy_flashing_required(adapter)) |
| 4110 | continue; |
| 4111 | |
| 4112 | if (pflashcomp[i].optype == OPTYPE_REDBOOT) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4113 | status = be_check_flash_crc(adapter, fw->data, |
| 4114 | pflashcomp[i].offset, |
| 4115 | pflashcomp[i].size, |
| 4116 | filehdr_size + |
| 4117 | img_hdrs_size, |
| 4118 | OPTYPE_REDBOOT, &crc_match); |
| 4119 | if (status) { |
| 4120 | dev_err(dev, |
| 4121 | "Could not get CRC for 0x%x region\n", |
| 4122 | pflashcomp[i].optype); |
| 4123 | continue; |
| 4124 | } |
| 4125 | |
| 4126 | if (crc_match) |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4127 | continue; |
| 4128 | } |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4129 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4130 | p = fw->data + filehdr_size + pflashcomp[i].offset + |
| 4131 | img_hdrs_size; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4132 | if (p + pflashcomp[i].size > fw->data + fw->size) |
| 4133 | return -1; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4134 | |
| 4135 | status = be_flash(adapter, p, flash_cmd, pflashcomp[i].optype, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4136 | pflashcomp[i].size, 0); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4137 | if (status) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4138 | dev_err(dev, "Flashing section type 0x%x failed\n", |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4139 | pflashcomp[i].img_type); |
| 4140 | return status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4141 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4142 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4143 | return 0; |
| 4144 | } |
| 4145 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4146 | static u16 be_get_img_optype(struct flash_section_entry fsec_entry) |
| 4147 | { |
| 4148 | u32 img_type = le32_to_cpu(fsec_entry.type); |
| 4149 | u16 img_optype = le16_to_cpu(fsec_entry.optype); |
| 4150 | |
| 4151 | if (img_optype != 0xFFFF) |
| 4152 | return img_optype; |
| 4153 | |
| 4154 | switch (img_type) { |
| 4155 | case IMAGE_FIRMWARE_iSCSI: |
| 4156 | img_optype = OPTYPE_ISCSI_ACTIVE; |
| 4157 | break; |
| 4158 | case IMAGE_BOOT_CODE: |
| 4159 | img_optype = OPTYPE_REDBOOT; |
| 4160 | break; |
| 4161 | case IMAGE_OPTION_ROM_ISCSI: |
| 4162 | img_optype = OPTYPE_BIOS; |
| 4163 | break; |
| 4164 | case IMAGE_OPTION_ROM_PXE: |
| 4165 | img_optype = OPTYPE_PXE_BIOS; |
| 4166 | break; |
| 4167 | case IMAGE_OPTION_ROM_FCoE: |
| 4168 | img_optype = OPTYPE_FCOE_BIOS; |
| 4169 | break; |
| 4170 | case IMAGE_FIRMWARE_BACKUP_iSCSI: |
| 4171 | img_optype = OPTYPE_ISCSI_BACKUP; |
| 4172 | break; |
| 4173 | case IMAGE_NCSI: |
| 4174 | img_optype = OPTYPE_NCSI_FW; |
| 4175 | break; |
| 4176 | case IMAGE_FLASHISM_JUMPVECTOR: |
| 4177 | img_optype = OPTYPE_FLASHISM_JUMPVECTOR; |
| 4178 | break; |
| 4179 | case IMAGE_FIRMWARE_PHY: |
| 4180 | img_optype = OPTYPE_SH_PHY_FW; |
| 4181 | break; |
| 4182 | case IMAGE_REDBOOT_DIR: |
| 4183 | img_optype = OPTYPE_REDBOOT_DIR; |
| 4184 | break; |
| 4185 | case IMAGE_REDBOOT_CONFIG: |
| 4186 | img_optype = OPTYPE_REDBOOT_CONFIG; |
| 4187 | break; |
| 4188 | case IMAGE_UFI_DIR: |
| 4189 | img_optype = OPTYPE_UFI_DIR; |
| 4190 | break; |
| 4191 | default: |
| 4192 | break; |
| 4193 | } |
| 4194 | |
| 4195 | return img_optype; |
| 4196 | } |
| 4197 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4198 | static int be_flash_skyhawk(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4199 | const struct firmware *fw, |
| 4200 | struct be_dma_mem *flash_cmd, int num_of_images) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4201 | { |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4202 | int img_hdrs_size = num_of_images * sizeof(struct image_hdr); |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4203 | bool crc_match, old_fw_img, flash_offset_support = true; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4204 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4205 | struct flash_section_info *fsec = NULL; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4206 | u32 img_offset, img_size, img_type; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4207 | u16 img_optype, flash_optype; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4208 | int status, i, filehdr_size; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4209 | const u8 *p; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4210 | |
| 4211 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
| 4212 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 4213 | if (!fsec) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4214 | dev_err(dev, "Invalid Cookie. FW image may be corrupted\n"); |
Kalesh AP | 56ace3a | 2014-07-17 16:20:20 +0530 | [diff] [blame] | 4215 | return -EINVAL; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4216 | } |
| 4217 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4218 | retry_flash: |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4219 | for (i = 0; i < le32_to_cpu(fsec->fsec_hdr.num_images); i++) { |
| 4220 | img_offset = le32_to_cpu(fsec->fsec_entry[i].offset); |
| 4221 | img_size = le32_to_cpu(fsec->fsec_entry[i].pad_size); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4222 | img_type = le32_to_cpu(fsec->fsec_entry[i].type); |
| 4223 | img_optype = be_get_img_optype(fsec->fsec_entry[i]); |
| 4224 | old_fw_img = fsec->fsec_entry[i].optype == 0xFFFF; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4225 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4226 | if (img_optype == 0xFFFF) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4227 | continue; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4228 | |
| 4229 | if (flash_offset_support) |
| 4230 | flash_optype = OPTYPE_OFFSET_SPECIFIED; |
| 4231 | else |
| 4232 | flash_optype = img_optype; |
| 4233 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4234 | /* Don't bother verifying CRC if an old FW image is being |
| 4235 | * flashed |
| 4236 | */ |
| 4237 | if (old_fw_img) |
| 4238 | goto flash; |
| 4239 | |
| 4240 | status = be_check_flash_crc(adapter, fw->data, img_offset, |
| 4241 | img_size, filehdr_size + |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4242 | img_hdrs_size, flash_optype, |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4243 | &crc_match); |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4244 | if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST || |
| 4245 | base_status(status) == MCC_STATUS_ILLEGAL_FIELD) { |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4246 | /* The current FW image on the card does not support |
| 4247 | * OFFSET based flashing. Retry using older mechanism |
| 4248 | * of OPTYPE based flashing |
| 4249 | */ |
| 4250 | if (flash_optype == OPTYPE_OFFSET_SPECIFIED) { |
| 4251 | flash_offset_support = false; |
| 4252 | goto retry_flash; |
| 4253 | } |
| 4254 | |
| 4255 | /* The current FW image on the card does not recognize |
| 4256 | * the new FLASH op_type. The FW download is partially |
| 4257 | * complete. Reboot the server now to enable FW image |
| 4258 | * to recognize the new FLASH op_type. To complete the |
| 4259 | * remaining process, download the same FW again after |
| 4260 | * the reboot. |
| 4261 | */ |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4262 | dev_err(dev, "Flash incomplete. Reset the server\n"); |
| 4263 | dev_err(dev, "Download FW image again after reset\n"); |
| 4264 | return -EAGAIN; |
| 4265 | } else if (status) { |
| 4266 | dev_err(dev, "Could not get CRC for 0x%x region\n", |
| 4267 | img_optype); |
| 4268 | return -EFAULT; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4271 | if (crc_match) |
| 4272 | continue; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4273 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4274 | flash: |
| 4275 | p = fw->data + filehdr_size + img_offset + img_hdrs_size; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4276 | if (p + img_size > fw->data + fw->size) |
| 4277 | return -1; |
| 4278 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4279 | status = be_flash(adapter, p, flash_cmd, flash_optype, img_size, |
| 4280 | img_offset); |
| 4281 | |
| 4282 | /* The current FW image on the card does not support OFFSET |
| 4283 | * based flashing. Retry using older mechanism of OPTYPE based |
| 4284 | * flashing |
| 4285 | */ |
| 4286 | if (base_status(status) == MCC_STATUS_ILLEGAL_FIELD && |
| 4287 | flash_optype == OPTYPE_OFFSET_SPECIFIED) { |
| 4288 | flash_offset_support = false; |
| 4289 | goto retry_flash; |
| 4290 | } |
| 4291 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4292 | /* For old FW images ignore ILLEGAL_FIELD error or errors on |
| 4293 | * UFI_DIR region |
| 4294 | */ |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4295 | if (old_fw_img && |
| 4296 | (base_status(status) == MCC_STATUS_ILLEGAL_FIELD || |
| 4297 | (img_optype == OPTYPE_UFI_DIR && |
| 4298 | base_status(status) == MCC_STATUS_FAILED))) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4299 | continue; |
| 4300 | } else if (status) { |
| 4301 | dev_err(dev, "Flashing section type 0x%x failed\n", |
| 4302 | img_type); |
| 4303 | return -EFAULT; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | return 0; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4307 | } |
| 4308 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4309 | static int lancer_fw_download(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4310 | const struct firmware *fw) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4311 | { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4312 | #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024) |
| 4313 | #define LANCER_FW_DOWNLOAD_LOCATION "/prg" |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4314 | struct device *dev = &adapter->pdev->dev; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4315 | struct be_dma_mem flash_cmd; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4316 | const u8 *data_ptr = NULL; |
| 4317 | u8 *dest_image_ptr = NULL; |
| 4318 | size_t image_size = 0; |
| 4319 | u32 chunk_size = 0; |
| 4320 | u32 data_written = 0; |
| 4321 | u32 offset = 0; |
| 4322 | int status = 0; |
| 4323 | u8 add_status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4324 | u8 change_status; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4325 | |
| 4326 | if (!IS_ALIGNED(fw->size, sizeof(u32))) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4327 | dev_err(dev, "FW image size should be multiple of 4\n"); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4328 | return -EINVAL; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | flash_cmd.size = sizeof(struct lancer_cmd_req_write_object) |
| 4332 | + LANCER_FW_DOWNLOAD_CHUNK; |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4333 | flash_cmd.va = dma_alloc_coherent(dev, flash_cmd.size, |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 4334 | &flash_cmd.dma, GFP_KERNEL); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4335 | if (!flash_cmd.va) |
| 4336 | return -ENOMEM; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4337 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4338 | dest_image_ptr = flash_cmd.va + |
| 4339 | sizeof(struct lancer_cmd_req_write_object); |
| 4340 | image_size = fw->size; |
| 4341 | data_ptr = fw->data; |
| 4342 | |
| 4343 | while (image_size) { |
| 4344 | chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK); |
| 4345 | |
| 4346 | /* Copy the image chunk content. */ |
| 4347 | memcpy(dest_image_ptr, data_ptr, chunk_size); |
| 4348 | |
| 4349 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4350 | chunk_size, offset, |
| 4351 | LANCER_FW_DOWNLOAD_LOCATION, |
| 4352 | &data_written, &change_status, |
| 4353 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4354 | if (status) |
| 4355 | break; |
| 4356 | |
| 4357 | offset += data_written; |
| 4358 | data_ptr += data_written; |
| 4359 | image_size -= data_written; |
| 4360 | } |
| 4361 | |
| 4362 | if (!status) { |
| 4363 | /* Commit the FW written */ |
| 4364 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4365 | 0, offset, |
| 4366 | LANCER_FW_DOWNLOAD_LOCATION, |
| 4367 | &data_written, &change_status, |
| 4368 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4371 | dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4372 | if (status) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4373 | dev_err(dev, "Firmware load error\n"); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4374 | return be_cmd_status(status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4377 | dev_info(dev, "Firmware flashed successfully\n"); |
| 4378 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4379 | if (change_status == LANCER_FW_RESET_NEEDED) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4380 | dev_info(dev, "Resetting adapter to activate new FW\n"); |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4381 | status = lancer_physdev_ctrl(adapter, |
| 4382 | PHYSDEV_CONTROL_FW_RESET_MASK); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4383 | if (status) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4384 | dev_err(dev, "Adapter busy, could not reset FW\n"); |
| 4385 | dev_err(dev, "Reboot server to activate new FW\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4386 | } |
| 4387 | } else if (change_status != LANCER_NO_RESET_NEEDED) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4388 | dev_info(dev, "Reboot server to activate new FW\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4389 | } |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4390 | |
| 4391 | return 0; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4394 | #define BE2_UFI 2 |
| 4395 | #define BE3_UFI 3 |
| 4396 | #define BE3R_UFI 10 |
| 4397 | #define SH_UFI 4 |
Vasundhara Volam | 81a9e22 | 2015-02-06 08:18:38 -0500 | [diff] [blame] | 4398 | #define SH_P2_UFI 11 |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4399 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4400 | static int be_get_ufi_type(struct be_adapter *adapter, |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4401 | struct flash_file_hdr_g3 *fhdr) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4402 | { |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4403 | if (!fhdr) { |
| 4404 | dev_err(&adapter->pdev->dev, "Invalid FW UFI file"); |
| 4405 | return -1; |
| 4406 | } |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4407 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4408 | /* First letter of the build version is used to identify |
| 4409 | * which chip this image file is meant for. |
| 4410 | */ |
| 4411 | switch (fhdr->build[0]) { |
| 4412 | case BLD_STR_UFI_TYPE_SH: |
Vasundhara Volam | 81a9e22 | 2015-02-06 08:18:38 -0500 | [diff] [blame] | 4413 | return (fhdr->asic_type_rev == ASIC_REV_P2) ? SH_P2_UFI : |
| 4414 | SH_UFI; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4415 | case BLD_STR_UFI_TYPE_BE3: |
| 4416 | return (fhdr->asic_type_rev == ASIC_REV_B0) ? BE3R_UFI : |
| 4417 | BE3_UFI; |
| 4418 | case BLD_STR_UFI_TYPE_BE2: |
| 4419 | return BE2_UFI; |
| 4420 | default: |
| 4421 | return -1; |
| 4422 | } |
| 4423 | } |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4424 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4425 | /* Check if the flash image file is compatible with the adapter that |
| 4426 | * is being flashed. |
| 4427 | * BE3 chips with asic-rev B0 must be flashed only with BE3R_UFI type. |
Vasundhara Volam | 81a9e22 | 2015-02-06 08:18:38 -0500 | [diff] [blame] | 4428 | * Skyhawk chips with asic-rev P2 must be flashed only with SH_P2_UFI type. |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4429 | */ |
| 4430 | static bool be_check_ufi_compatibility(struct be_adapter *adapter, |
| 4431 | struct flash_file_hdr_g3 *fhdr) |
| 4432 | { |
| 4433 | int ufi_type = be_get_ufi_type(adapter, fhdr); |
| 4434 | |
| 4435 | switch (ufi_type) { |
Vasundhara Volam | 81a9e22 | 2015-02-06 08:18:38 -0500 | [diff] [blame] | 4436 | case SH_P2_UFI: |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4437 | return skyhawk_chip(adapter); |
Vasundhara Volam | 81a9e22 | 2015-02-06 08:18:38 -0500 | [diff] [blame] | 4438 | case SH_UFI: |
| 4439 | return (skyhawk_chip(adapter) && |
| 4440 | adapter->asic_rev < ASIC_REV_P2); |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4441 | case BE3R_UFI: |
| 4442 | return BE3_chip(adapter); |
| 4443 | case BE3_UFI: |
| 4444 | return (BE3_chip(adapter) && adapter->asic_rev < ASIC_REV_B0); |
| 4445 | case BE2_UFI: |
| 4446 | return BE2_chip(adapter); |
| 4447 | default: |
| 4448 | return false; |
| 4449 | } |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4450 | } |
| 4451 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4452 | static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) |
| 4453 | { |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4454 | struct device *dev = &adapter->pdev->dev; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4455 | struct flash_file_hdr_g3 *fhdr3; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4456 | struct image_hdr *img_hdr_ptr; |
| 4457 | int status = 0, i, num_imgs; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4458 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4459 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4460 | fhdr3 = (struct flash_file_hdr_g3 *)fw->data; |
| 4461 | if (!be_check_ufi_compatibility(adapter, fhdr3)) { |
| 4462 | dev_err(dev, "Flash image is not compatible with adapter\n"); |
| 4463 | return -EINVAL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4464 | } |
| 4465 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4466 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom); |
| 4467 | flash_cmd.va = dma_alloc_coherent(dev, flash_cmd.size, &flash_cmd.dma, |
| 4468 | GFP_KERNEL); |
| 4469 | if (!flash_cmd.va) |
| 4470 | return -ENOMEM; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4471 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4472 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 4473 | for (i = 0; i < num_imgs; i++) { |
| 4474 | img_hdr_ptr = (struct image_hdr *)(fw->data + |
| 4475 | (sizeof(struct flash_file_hdr_g3) + |
| 4476 | i * sizeof(struct image_hdr))); |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4477 | if (!BE2_chip(adapter) && |
| 4478 | le32_to_cpu(img_hdr_ptr->imageid) != 1) |
| 4479 | continue; |
| 4480 | |
| 4481 | if (skyhawk_chip(adapter)) |
| 4482 | status = be_flash_skyhawk(adapter, fw, &flash_cmd, |
| 4483 | num_imgs); |
| 4484 | else |
| 4485 | status = be_flash_BEx(adapter, fw, &flash_cmd, |
| 4486 | num_imgs); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4489 | dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma); |
| 4490 | if (!status) |
| 4491 | dev_info(dev, "Firmware flashed successfully\n"); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4492 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4493 | return status; |
| 4494 | } |
| 4495 | |
| 4496 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 4497 | { |
| 4498 | const struct firmware *fw; |
| 4499 | int status; |
| 4500 | |
| 4501 | if (!netif_running(adapter->netdev)) { |
| 4502 | dev_err(&adapter->pdev->dev, |
| 4503 | "Firmware load not allowed (interface is down)\n"); |
Kalesh AP | 940a3fc | 2014-07-17 16:20:19 +0530 | [diff] [blame] | 4504 | return -ENETDOWN; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 4508 | if (status) |
| 4509 | goto fw_exit; |
| 4510 | |
| 4511 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 4512 | |
| 4513 | if (lancer_chip(adapter)) |
| 4514 | status = lancer_fw_download(adapter, fw); |
| 4515 | else |
| 4516 | status = be_fw_download(adapter, fw); |
| 4517 | |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4518 | if (!status) |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4519 | be_cmd_get_fw_ver(adapter); |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4520 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4521 | fw_exit: |
| 4522 | release_firmware(fw); |
| 4523 | return status; |
| 4524 | } |
| 4525 | |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 4526 | static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, |
| 4527 | u16 flags) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4528 | { |
| 4529 | struct be_adapter *adapter = netdev_priv(dev); |
| 4530 | struct nlattr *attr, *br_spec; |
| 4531 | int rem; |
| 4532 | int status = 0; |
| 4533 | u16 mode = 0; |
| 4534 | |
| 4535 | if (!sriov_enabled(adapter)) |
| 4536 | return -EOPNOTSUPP; |
| 4537 | |
| 4538 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 4539 | if (!br_spec) |
| 4540 | return -EINVAL; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4541 | |
| 4542 | nla_for_each_nested(attr, br_spec, rem) { |
| 4543 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 4544 | continue; |
| 4545 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 4546 | if (nla_len(attr) < sizeof(mode)) |
| 4547 | return -EINVAL; |
| 4548 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4549 | mode = nla_get_u16(attr); |
| 4550 | if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) |
| 4551 | return -EINVAL; |
| 4552 | |
| 4553 | status = be_cmd_set_hsw_config(adapter, 0, 0, |
| 4554 | adapter->if_handle, |
| 4555 | mode == BRIDGE_MODE_VEPA ? |
| 4556 | PORT_FWD_TYPE_VEPA : |
| 4557 | PORT_FWD_TYPE_VEB); |
| 4558 | if (status) |
| 4559 | goto err; |
| 4560 | |
| 4561 | dev_info(&adapter->pdev->dev, "enabled switch mode: %s\n", |
| 4562 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4563 | |
| 4564 | return status; |
| 4565 | } |
| 4566 | err: |
| 4567 | dev_err(&adapter->pdev->dev, "Failed to set switch mode %s\n", |
| 4568 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4569 | |
| 4570 | return status; |
| 4571 | } |
| 4572 | |
| 4573 | static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4574 | struct net_device *dev, u32 filter_mask) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4575 | { |
| 4576 | struct be_adapter *adapter = netdev_priv(dev); |
| 4577 | int status = 0; |
| 4578 | u8 hsw_mode; |
| 4579 | |
| 4580 | if (!sriov_enabled(adapter)) |
| 4581 | return 0; |
| 4582 | |
| 4583 | /* BE and Lancer chips support VEB mode only */ |
| 4584 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
| 4585 | hsw_mode = PORT_FWD_TYPE_VEB; |
| 4586 | } else { |
| 4587 | status = be_cmd_get_hsw_config(adapter, NULL, 0, |
| 4588 | adapter->if_handle, &hsw_mode); |
| 4589 | if (status) |
| 4590 | return 0; |
| 4591 | } |
| 4592 | |
| 4593 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
| 4594 | hsw_mode == PORT_FWD_TYPE_VEPA ? |
Scott Feldman | 2c3c031 | 2014-11-28 14:34:25 +0100 | [diff] [blame] | 4595 | BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB, |
| 4596 | 0, 0); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4597 | } |
| 4598 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4599 | #ifdef CONFIG_BE2NET_VXLAN |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4600 | /* VxLAN offload Notes: |
| 4601 | * |
| 4602 | * The stack defines tunnel offload flags (hw_enc_features) for IP and doesn't |
| 4603 | * distinguish various types of transports (VxLAN, GRE, NVGRE ..). So, offload |
| 4604 | * is expected to work across all types of IP tunnels once exported. Skyhawk |
| 4605 | * supports offloads for either VxLAN or NVGRE, exclusively. So we export VxLAN |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 4606 | * offloads in hw_enc_features only when a VxLAN port is added. If other (non |
| 4607 | * VxLAN) tunnels are configured while VxLAN offloads are enabled, offloads for |
| 4608 | * those other tunnels are unexported on the fly through ndo_features_check(). |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4609 | * |
| 4610 | * Skyhawk supports VxLAN offloads only for one UDP dport. So, if the stack |
| 4611 | * adds more than one port, disable offloads and don't re-enable them again |
| 4612 | * until after all the tunnels are removed. |
| 4613 | */ |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4614 | static void be_add_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 4615 | __be16 port) |
| 4616 | { |
| 4617 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4618 | struct device *dev = &adapter->pdev->dev; |
| 4619 | int status; |
| 4620 | |
| 4621 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 4622 | return; |
| 4623 | |
| 4624 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4625 | dev_info(dev, |
| 4626 | "Only one UDP port supported for VxLAN offloads\n"); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4627 | dev_info(dev, "Disabling VxLAN offloads\n"); |
| 4628 | adapter->vxlan_port_count++; |
| 4629 | goto err; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4630 | } |
| 4631 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4632 | if (adapter->vxlan_port_count++ >= 1) |
| 4633 | return; |
| 4634 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4635 | status = be_cmd_manage_iface(adapter, adapter->if_handle, |
| 4636 | OP_CONVERT_NORMAL_TO_TUNNEL); |
| 4637 | if (status) { |
| 4638 | dev_warn(dev, "Failed to convert normal interface to tunnel\n"); |
| 4639 | goto err; |
| 4640 | } |
| 4641 | |
| 4642 | status = be_cmd_set_vxlan_port(adapter, port); |
| 4643 | if (status) { |
| 4644 | dev_warn(dev, "Failed to add VxLAN port\n"); |
| 4645 | goto err; |
| 4646 | } |
| 4647 | adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS; |
| 4648 | adapter->vxlan_port = port; |
| 4649 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4650 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4651 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 4652 | NETIF_F_GSO_UDP_TUNNEL; |
| 4653 | netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 4654 | netdev->features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4655 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4656 | dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n", |
| 4657 | be16_to_cpu(port)); |
| 4658 | return; |
| 4659 | err: |
| 4660 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 4664 | __be16 port) |
| 4665 | { |
| 4666 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4667 | |
| 4668 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 4669 | return; |
| 4670 | |
| 4671 | if (adapter->vxlan_port != port) |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4672 | goto done; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4673 | |
| 4674 | be_disable_vxlan_offloads(adapter); |
| 4675 | |
| 4676 | dev_info(&adapter->pdev->dev, |
| 4677 | "Disabled VxLAN offloads for UDP port %d\n", |
| 4678 | be16_to_cpu(port)); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4679 | done: |
| 4680 | adapter->vxlan_port_count--; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4681 | } |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 4682 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 4683 | static netdev_features_t be_features_check(struct sk_buff *skb, |
| 4684 | struct net_device *dev, |
| 4685 | netdev_features_t features) |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 4686 | { |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 4687 | struct be_adapter *adapter = netdev_priv(dev); |
| 4688 | u8 l4_hdr = 0; |
| 4689 | |
| 4690 | /* The code below restricts offload features for some tunneled packets. |
| 4691 | * Offload features for normal (non tunnel) packets are unchanged. |
| 4692 | */ |
| 4693 | if (!skb->encapsulation || |
| 4694 | !(adapter->flags & BE_FLAGS_VXLAN_OFFLOADS)) |
| 4695 | return features; |
| 4696 | |
| 4697 | /* It's an encapsulated packet and VxLAN offloads are enabled. We |
| 4698 | * should disable tunnel offload features if it's not a VxLAN packet, |
| 4699 | * as tunnel offloads have been enabled only for VxLAN. This is done to |
| 4700 | * allow other tunneled traffic like GRE work fine while VxLAN |
| 4701 | * offloads are configured in Skyhawk-R. |
| 4702 | */ |
| 4703 | switch (vlan_get_protocol(skb)) { |
| 4704 | case htons(ETH_P_IP): |
| 4705 | l4_hdr = ip_hdr(skb)->protocol; |
| 4706 | break; |
| 4707 | case htons(ETH_P_IPV6): |
| 4708 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 4709 | break; |
| 4710 | default: |
| 4711 | return features; |
| 4712 | } |
| 4713 | |
| 4714 | if (l4_hdr != IPPROTO_UDP || |
| 4715 | skb->inner_protocol_type != ENCAP_TYPE_ETHER || |
| 4716 | skb->inner_protocol != htons(ETH_P_TEB) || |
| 4717 | skb_inner_mac_header(skb) - skb_transport_header(skb) != |
| 4718 | sizeof(struct udphdr) + sizeof(struct vxlanhdr)) |
| 4719 | return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK); |
| 4720 | |
| 4721 | return features; |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 4722 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4723 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4724 | |
stephen hemminger | e5686ad | 2012-01-05 19:10:25 +0000 | [diff] [blame] | 4725 | static const struct net_device_ops be_netdev_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4726 | .ndo_open = be_open, |
| 4727 | .ndo_stop = be_close, |
| 4728 | .ndo_start_xmit = be_xmit, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4729 | .ndo_set_rx_mode = be_set_rx_mode, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4730 | .ndo_set_mac_address = be_mac_addr_set, |
| 4731 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 4732 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4733 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4734 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 4735 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 4736 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 4737 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 4738 | .ndo_set_vf_rate = be_set_vf_tx_rate, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4739 | .ndo_get_vf_config = be_get_vf_config, |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4740 | .ndo_set_vf_link_state = be_set_vf_link_state, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4741 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4742 | .ndo_poll_controller = be_netpoll, |
| 4743 | #endif |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4744 | .ndo_bridge_setlink = be_ndo_bridge_setlink, |
| 4745 | .ndo_bridge_getlink = be_ndo_bridge_getlink, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 4746 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4747 | .ndo_busy_poll = be_busy_poll, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 4748 | #endif |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4749 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4750 | .ndo_add_vxlan_port = be_add_vxlan_port, |
| 4751 | .ndo_del_vxlan_port = be_del_vxlan_port, |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 4752 | .ndo_features_check = be_features_check, |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4753 | #endif |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4754 | }; |
| 4755 | |
| 4756 | static void be_netdev_init(struct net_device *netdev) |
| 4757 | { |
| 4758 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4759 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 4760 | 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] | 4761 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4762 | NETIF_F_HW_VLAN_CTAG_TX; |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 4763 | if (be_multi_rxq(adapter)) |
| 4764 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 4765 | |
| 4766 | netdev->features |= netdev->hw_features | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4767 | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 4768 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 4769 | 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] | 4770 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 4771 | |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 4772 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 4773 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4774 | netdev->flags |= IFF_MULTICAST; |
| 4775 | |
Sarveshwar Bandi | b7e5887 | 2012-06-13 19:51:43 +0000 | [diff] [blame] | 4776 | netif_set_gso_max_size(netdev, 65535 - ETH_HLEN); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 4777 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4778 | netdev->netdev_ops = &be_netdev_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4779 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 4780 | netdev->ethtool_ops = &be_ethtool_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 4784 | { |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4785 | if (adapter->csr) |
| 4786 | pci_iounmap(adapter->pdev, adapter->csr); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4787 | if (adapter->db) |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4788 | pci_iounmap(adapter->pdev, adapter->db); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4791 | static int db_bar(struct be_adapter *adapter) |
| 4792 | { |
| 4793 | if (lancer_chip(adapter) || !be_physfn(adapter)) |
| 4794 | return 0; |
| 4795 | else |
| 4796 | return 4; |
| 4797 | } |
| 4798 | |
| 4799 | static int be_roce_map_pci_bars(struct be_adapter *adapter) |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4800 | { |
Sathya Perla | dbf0f2a | 2012-11-06 17:49:00 +0000 | [diff] [blame] | 4801 | if (skyhawk_chip(adapter)) { |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4802 | adapter->roce_db.size = 4096; |
| 4803 | adapter->roce_db.io_addr = pci_resource_start(adapter->pdev, |
| 4804 | db_bar(adapter)); |
| 4805 | adapter->roce_db.total_size = pci_resource_len(adapter->pdev, |
| 4806 | db_bar(adapter)); |
| 4807 | } |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4808 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 4812 | { |
| 4813 | u8 __iomem *addr; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 4814 | |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4815 | if (BEx_chip(adapter) && be_physfn(adapter)) { |
| 4816 | adapter->csr = pci_iomap(adapter->pdev, 2, 0); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 4817 | if (!adapter->csr) |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 4818 | return -ENOMEM; |
| 4819 | } |
| 4820 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4821 | addr = pci_iomap(adapter->pdev, db_bar(adapter), 0); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 4822 | if (!addr) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4823 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4824 | adapter->db = addr; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4825 | |
| 4826 | be_roce_map_pci_bars(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4827 | return 0; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4828 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4829 | pci_map_err: |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 4830 | dev_err(&adapter->pdev->dev, "Error in mapping PCI BARs\n"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4831 | be_unmap_pci_bars(adapter); |
| 4832 | return -ENOMEM; |
| 4833 | } |
| 4834 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4835 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 4836 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4837 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4838 | |
| 4839 | be_unmap_pci_bars(adapter); |
| 4840 | |
| 4841 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4842 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 4843 | mem->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4844 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4845 | mem = &adapter->rx_filter; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4846 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4847 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 4848 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4849 | } |
| 4850 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4851 | static int be_ctrl_init(struct be_adapter *adapter) |
| 4852 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4853 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 4854 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4855 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4856 | u32 sli_intf; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4857 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4858 | |
Sathya Perla | ce66f78 | 2012-11-06 17:48:58 +0000 | [diff] [blame] | 4859 | pci_read_config_dword(adapter->pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 4860 | adapter->sli_family = (sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 4861 | SLI_INTF_FAMILY_SHIFT; |
| 4862 | adapter->virtfn = (sli_intf & SLI_INTF_FT_MASK) ? 1 : 0; |
| 4863 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4864 | status = be_map_pci_bars(adapter); |
| 4865 | if (status) |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4866 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4867 | |
| 4868 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4869 | mbox_mem_alloc->va = dma_alloc_coherent(&adapter->pdev->dev, |
| 4870 | mbox_mem_alloc->size, |
| 4871 | &mbox_mem_alloc->dma, |
| 4872 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4873 | if (!mbox_mem_alloc->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4874 | status = -ENOMEM; |
| 4875 | goto unmap_pci_bars; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4876 | } |
| 4877 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 4878 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 4879 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 4880 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4881 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 4882 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 4883 | rx_filter->va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 4884 | rx_filter->size, &rx_filter->dma, |
| 4885 | GFP_KERNEL); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 4886 | if (!rx_filter->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4887 | status = -ENOMEM; |
| 4888 | goto free_mbox; |
| 4889 | } |
Joe Perches | 1f9061d2 | 2013-03-15 07:23:58 +0000 | [diff] [blame] | 4890 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 4891 | mutex_init(&adapter->mbox_lock); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 4892 | spin_lock_init(&adapter->mcc_lock); |
| 4893 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4894 | |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 4895 | init_completion(&adapter->et_cmd_compl); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 4896 | pci_save_state(adapter->pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4897 | return 0; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4898 | |
| 4899 | free_mbox: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4900 | dma_free_coherent(&adapter->pdev->dev, mbox_mem_alloc->size, |
| 4901 | mbox_mem_alloc->va, mbox_mem_alloc->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 4902 | |
| 4903 | unmap_pci_bars: |
| 4904 | be_unmap_pci_bars(adapter); |
| 4905 | |
| 4906 | done: |
| 4907 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 4911 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 4912 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4913 | |
| 4914 | if (cmd->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 4915 | dma_free_coherent(&adapter->pdev->dev, cmd->size, |
| 4916 | cmd->va, cmd->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | static int be_stats_init(struct be_adapter *adapter) |
| 4920 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 4921 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4922 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4923 | if (lancer_chip(adapter)) |
| 4924 | cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 4925 | else if (BE2_chip(adapter)) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 4926 | cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 4927 | else if (BE3_chip(adapter)) |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4928 | cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 4929 | else |
| 4930 | /* ALL non-BE ASICs */ |
| 4931 | cmd->size = sizeof(struct be_cmd_req_get_stats_v2); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4932 | |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 4933 | cmd->va = dma_zalloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma, |
| 4934 | GFP_KERNEL); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 4935 | if (!cmd->va) |
Kalesh AP | 6b56868 | 2014-07-17 16:20:22 +0530 | [diff] [blame] | 4936 | return -ENOMEM; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4937 | return 0; |
| 4938 | } |
| 4939 | |
Bill Pemberton | 3bc6b06 | 2012-12-03 09:23:09 -0500 | [diff] [blame] | 4940 | static void be_remove(struct pci_dev *pdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4941 | { |
| 4942 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 4943 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4944 | if (!adapter) |
| 4945 | return; |
| 4946 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4947 | be_roce_dev_remove(adapter); |
Somnath Kotur | 8cef7a7 | 2013-03-14 02:41:51 +0000 | [diff] [blame] | 4948 | be_intr_set(adapter, false); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 4949 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4950 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
| 4951 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4952 | unregister_netdev(adapter->netdev); |
| 4953 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4954 | be_clear(adapter); |
| 4955 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 4956 | /* tell fw we're done with firing cmds */ |
| 4957 | be_cmd_fw_clean(adapter); |
| 4958 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4959 | be_stats_cleanup(adapter); |
| 4960 | |
| 4961 | be_ctrl_cleanup(adapter); |
| 4962 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 4963 | pci_disable_pcie_error_reporting(pdev); |
| 4964 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4965 | pci_release_regions(pdev); |
| 4966 | pci_disable_device(pdev); |
| 4967 | |
| 4968 | free_netdev(adapter->netdev); |
| 4969 | } |
| 4970 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4971 | static int be_get_initial_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4972 | { |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4973 | int status, level; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 4974 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 4975 | status = be_cmd_get_cntl_attributes(adapter); |
| 4976 | if (status) |
| 4977 | return status; |
| 4978 | |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 4979 | /* Must be a power of 2 or else MODULO will BUG_ON */ |
| 4980 | adapter->be_get_temp_freq = 64; |
| 4981 | |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4982 | if (BEx_chip(adapter)) { |
| 4983 | level = be_cmd_get_fw_log_level(adapter); |
| 4984 | adapter->msg_enable = |
| 4985 | level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0; |
| 4986 | } |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4987 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4988 | adapter->cfg_num_qs = netif_get_num_default_rss_queues(); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 4989 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4992 | static int lancer_recover_func(struct be_adapter *adapter) |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4993 | { |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 4994 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4995 | int status; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 4996 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4997 | status = lancer_test_and_set_rdy_state(adapter); |
| 4998 | if (status) |
| 4999 | goto err; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5000 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5001 | if (netif_running(adapter->netdev)) |
| 5002 | be_close(adapter->netdev); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5003 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5004 | be_clear(adapter); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5005 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5006 | be_clear_all_error(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5007 | |
| 5008 | status = be_setup(adapter); |
| 5009 | if (status) |
| 5010 | goto err; |
| 5011 | |
| 5012 | if (netif_running(adapter->netdev)) { |
| 5013 | status = be_open(adapter->netdev); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5014 | if (status) |
| 5015 | goto err; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5016 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5017 | |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 5018 | dev_err(dev, "Adapter recovery successful\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5019 | return 0; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5020 | err: |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5021 | if (status == -EAGAIN) |
| 5022 | dev_err(dev, "Waiting for resource provisioning\n"); |
| 5023 | else |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 5024 | dev_err(dev, "Adapter recovery failed\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5025 | |
| 5026 | return status; |
| 5027 | } |
| 5028 | |
| 5029 | static void be_func_recovery_task(struct work_struct *work) |
| 5030 | { |
| 5031 | struct be_adapter *adapter = |
| 5032 | container_of(work, struct be_adapter, func_recovery_work.work); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5033 | int status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5034 | |
| 5035 | be_detect_error(adapter); |
| 5036 | |
| 5037 | if (adapter->hw_error && lancer_chip(adapter)) { |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5038 | rtnl_lock(); |
| 5039 | netif_device_detach(adapter->netdev); |
| 5040 | rtnl_unlock(); |
| 5041 | |
| 5042 | status = lancer_recover_func(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5043 | if (!status) |
| 5044 | netif_device_attach(adapter->netdev); |
| 5045 | } |
| 5046 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5047 | /* In Lancer, for all errors other than provisioning error (-EAGAIN), |
| 5048 | * no need to attempt further recovery. |
| 5049 | */ |
| 5050 | if (!status || status == -EAGAIN) |
| 5051 | schedule_delayed_work(&adapter->func_recovery_work, |
| 5052 | msecs_to_jiffies(1000)); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | static void be_worker(struct work_struct *work) |
| 5056 | { |
| 5057 | struct be_adapter *adapter = |
| 5058 | container_of(work, struct be_adapter, work.work); |
| 5059 | struct be_rx_obj *rxo; |
| 5060 | int i; |
| 5061 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5062 | /* when interrupts are not yet enabled, just reap any pending |
| 5063 | * mcc completions */ |
| 5064 | if (!netif_running(adapter->netdev)) { |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5065 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5066 | be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5067 | local_bh_enable(); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5068 | goto reschedule; |
| 5069 | } |
| 5070 | |
| 5071 | if (!adapter->stats_cmd_sent) { |
| 5072 | if (lancer_chip(adapter)) |
| 5073 | lancer_cmd_get_pport_stats(adapter, |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 5074 | &adapter->stats_cmd); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5075 | else |
| 5076 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 5077 | } |
| 5078 | |
Vasundhara Volam | d696b5e | 2013-08-06 09:27:16 +0530 | [diff] [blame] | 5079 | if (be_physfn(adapter) && |
| 5080 | MODULO(adapter->work_counter, adapter->be_get_temp_freq) == 0) |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 5081 | be_cmd_get_die_temperature(adapter); |
| 5082 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5083 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5084 | /* Replenish RX-queues starved due to memory |
| 5085 | * allocation failures. |
| 5086 | */ |
| 5087 | if (rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 5088 | be_post_rx_frags(rxo, GFP_KERNEL, MAX_RX_POST); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 5091 | be_eqd_update(adapter); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5092 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5093 | reschedule: |
| 5094 | adapter->work_counter++; |
| 5095 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 5096 | } |
| 5097 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 5098 | /* If any VFs are already enabled don't FLR the PF */ |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5099 | static bool be_reset_required(struct be_adapter *adapter) |
| 5100 | { |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 5101 | return pci_num_vf(adapter->pdev) ? false : true; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5104 | static char *mc_name(struct be_adapter *adapter) |
| 5105 | { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 5106 | char *str = ""; /* default */ |
| 5107 | |
| 5108 | switch (adapter->mc_type) { |
| 5109 | case UMC: |
| 5110 | str = "UMC"; |
| 5111 | break; |
| 5112 | case FLEX10: |
| 5113 | str = "FLEX10"; |
| 5114 | break; |
| 5115 | case vNIC1: |
| 5116 | str = "vNIC-1"; |
| 5117 | break; |
| 5118 | case nPAR: |
| 5119 | str = "nPAR"; |
| 5120 | break; |
| 5121 | case UFP: |
| 5122 | str = "UFP"; |
| 5123 | break; |
| 5124 | case vNIC2: |
| 5125 | str = "vNIC-2"; |
| 5126 | break; |
| 5127 | default: |
| 5128 | str = ""; |
| 5129 | } |
| 5130 | |
| 5131 | return str; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | static inline char *func_name(struct be_adapter *adapter) |
| 5135 | { |
| 5136 | return be_physfn(adapter) ? "PF" : "VF"; |
| 5137 | } |
| 5138 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 5139 | static inline char *nic_name(struct pci_dev *pdev) |
| 5140 | { |
| 5141 | switch (pdev->device) { |
| 5142 | case OC_DEVICE_ID1: |
| 5143 | return OC_NAME; |
| 5144 | case OC_DEVICE_ID2: |
| 5145 | return OC_NAME_BE; |
| 5146 | case OC_DEVICE_ID3: |
| 5147 | case OC_DEVICE_ID4: |
| 5148 | return OC_NAME_LANCER; |
| 5149 | case BE_DEVICE_ID2: |
| 5150 | return BE3_NAME; |
| 5151 | case OC_DEVICE_ID5: |
| 5152 | case OC_DEVICE_ID6: |
| 5153 | return OC_NAME_SH; |
| 5154 | default: |
| 5155 | return BE_NAME; |
| 5156 | } |
| 5157 | } |
| 5158 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 5159 | 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] | 5160 | { |
| 5161 | int status = 0; |
| 5162 | struct be_adapter *adapter; |
| 5163 | struct net_device *netdev; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 5164 | char port_name; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5165 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 5166 | dev_info(&pdev->dev, "%s version is %s\n", DRV_NAME, DRV_VER); |
| 5167 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5168 | status = pci_enable_device(pdev); |
| 5169 | if (status) |
| 5170 | goto do_none; |
| 5171 | |
| 5172 | status = pci_request_regions(pdev, DRV_NAME); |
| 5173 | if (status) |
| 5174 | goto disable_dev; |
| 5175 | pci_set_master(pdev); |
| 5176 | |
Sathya Perla | 7f64006 | 2012-06-05 19:37:20 +0000 | [diff] [blame] | 5177 | netdev = alloc_etherdev_mqs(sizeof(*adapter), MAX_TX_QS, MAX_RX_QS); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 5178 | if (!netdev) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5179 | status = -ENOMEM; |
| 5180 | goto rel_reg; |
| 5181 | } |
| 5182 | adapter = netdev_priv(netdev); |
| 5183 | adapter->pdev = pdev; |
| 5184 | pci_set_drvdata(pdev, adapter); |
| 5185 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5186 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5187 | |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5188 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5189 | if (!status) { |
| 5190 | netdev->features |= NETIF_F_HIGHDMA; |
| 5191 | } else { |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5192 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5193 | if (status) { |
| 5194 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 5195 | goto free_netdev; |
| 5196 | } |
| 5197 | } |
| 5198 | |
Kalesh AP | 2f951a9 | 2014-09-12 17:39:21 +0530 | [diff] [blame] | 5199 | status = pci_enable_pcie_error_reporting(pdev); |
| 5200 | if (!status) |
| 5201 | dev_info(&pdev->dev, "PCIe error reporting enabled\n"); |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 5202 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5203 | status = be_ctrl_init(adapter); |
| 5204 | if (status) |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5205 | goto free_netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5206 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5207 | /* sync up with fw's ready state */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 5208 | if (be_physfn(adapter)) { |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 5209 | status = be_fw_wait_ready(adapter); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 5210 | if (status) |
| 5211 | goto ctrl_clean; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 5212 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5213 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5214 | if (be_reset_required(adapter)) { |
| 5215 | status = be_cmd_reset_function(adapter); |
| 5216 | if (status) |
| 5217 | goto ctrl_clean; |
Sarveshwar Bandi | 556ae19 | 2010-05-24 18:38:25 -0700 | [diff] [blame] | 5218 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 5219 | /* Wait for interrupts to quiesce after an FLR */ |
| 5220 | msleep(100); |
| 5221 | } |
Somnath Kotur | 8cef7a7 | 2013-03-14 02:41:51 +0000 | [diff] [blame] | 5222 | |
| 5223 | /* Allow interrupts for other ULPs running on NIC function */ |
| 5224 | be_intr_set(adapter, true); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5225 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 5226 | /* tell fw we're ready to fire cmds */ |
| 5227 | status = be_cmd_fw_init(adapter); |
| 5228 | if (status) |
| 5229 | goto ctrl_clean; |
| 5230 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5231 | status = be_stats_init(adapter); |
| 5232 | if (status) |
| 5233 | goto ctrl_clean; |
| 5234 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5235 | status = be_get_initial_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5236 | if (status) |
| 5237 | goto stats_clean; |
| 5238 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5239 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5240 | INIT_DELAYED_WORK(&adapter->func_recovery_work, be_func_recovery_task); |
Kalesh AP | 5f820b6 | 2014-09-19 15:47:01 +0530 | [diff] [blame] | 5241 | adapter->rx_fc = true; |
| 5242 | adapter->tx_fc = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5243 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5244 | status = be_setup(adapter); |
| 5245 | if (status) |
Sathya Perla | 55f5c3c | 2012-09-28 04:39:42 +0000 | [diff] [blame] | 5246 | goto stats_clean; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5247 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 5248 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5249 | status = register_netdev(netdev); |
| 5250 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5251 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5252 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 5253 | be_roce_dev_add(adapter); |
| 5254 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5255 | schedule_delayed_work(&adapter->func_recovery_work, |
| 5256 | msecs_to_jiffies(1000)); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 5257 | |
| 5258 | be_cmd_query_port_name(adapter, &port_name); |
| 5259 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5260 | dev_info(&pdev->dev, "%s: %s %s port %c\n", nic_name(pdev), |
| 5261 | func_name(adapter), mc_name(adapter), port_name); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 5262 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5263 | return 0; |
| 5264 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5265 | unsetup: |
| 5266 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5267 | stats_clean: |
| 5268 | be_stats_cleanup(adapter); |
| 5269 | ctrl_clean: |
| 5270 | be_ctrl_cleanup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 5271 | free_netdev: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 5272 | free_netdev(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5273 | rel_reg: |
| 5274 | pci_release_regions(pdev); |
| 5275 | disable_dev: |
| 5276 | pci_disable_device(pdev); |
| 5277 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 5278 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5279 | return status; |
| 5280 | } |
| 5281 | |
| 5282 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5283 | { |
| 5284 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5285 | struct net_device *netdev = adapter->netdev; |
| 5286 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 5287 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 5288 | be_setup_wol(adapter, true); |
| 5289 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 5290 | be_intr_set(adapter, false); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5291 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
| 5292 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5293 | netif_device_detach(netdev); |
| 5294 | if (netif_running(netdev)) { |
| 5295 | rtnl_lock(); |
| 5296 | be_close(netdev); |
| 5297 | rtnl_unlock(); |
| 5298 | } |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 5299 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5300 | |
| 5301 | pci_save_state(pdev); |
| 5302 | pci_disable_device(pdev); |
| 5303 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5304 | return 0; |
| 5305 | } |
| 5306 | |
| 5307 | static int be_resume(struct pci_dev *pdev) |
| 5308 | { |
| 5309 | int status = 0; |
| 5310 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5311 | struct net_device *netdev = adapter->netdev; |
| 5312 | |
| 5313 | netif_device_detach(netdev); |
| 5314 | |
| 5315 | status = pci_enable_device(pdev); |
| 5316 | if (status) |
| 5317 | return status; |
| 5318 | |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 5319 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5320 | pci_restore_state(pdev); |
| 5321 | |
Sarveshwar Bandi | dd5746b | 2013-08-23 14:59:33 +0530 | [diff] [blame] | 5322 | status = be_fw_wait_ready(adapter); |
| 5323 | if (status) |
| 5324 | return status; |
| 5325 | |
Kalesh AP | 9a6d73d | 2015-01-20 03:51:47 -0500 | [diff] [blame] | 5326 | status = be_cmd_reset_function(adapter); |
| 5327 | if (status) |
| 5328 | return status; |
| 5329 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 5330 | be_intr_set(adapter, true); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5331 | /* tell fw we're ready to fire cmds */ |
| 5332 | status = be_cmd_fw_init(adapter); |
| 5333 | if (status) |
| 5334 | return status; |
| 5335 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 5336 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5337 | if (netif_running(netdev)) { |
| 5338 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5339 | be_open(netdev); |
| 5340 | rtnl_unlock(); |
| 5341 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5342 | |
| 5343 | schedule_delayed_work(&adapter->func_recovery_work, |
| 5344 | msecs_to_jiffies(1000)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5345 | netif_device_attach(netdev); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 5346 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 5347 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 5348 | be_setup_wol(adapter, false); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 5349 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5350 | return 0; |
| 5351 | } |
| 5352 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5353 | /* |
| 5354 | * An FLR will stop BE from DMAing any data. |
| 5355 | */ |
| 5356 | static void be_shutdown(struct pci_dev *pdev) |
| 5357 | { |
| 5358 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5359 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 5360 | if (!adapter) |
| 5361 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5362 | |
Devesh Sharma | d114f99 | 2014-06-10 19:32:15 +0530 | [diff] [blame] | 5363 | be_roce_dev_shutdown(adapter); |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 5364 | cancel_delayed_work_sync(&adapter->work); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5365 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 5366 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 5367 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5368 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 5369 | be_cmd_reset_function(adapter); |
| 5370 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5371 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5372 | } |
| 5373 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5374 | static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 5375 | pci_channel_state_t state) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5376 | { |
| 5377 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5378 | struct net_device *netdev = adapter->netdev; |
| 5379 | |
| 5380 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 5381 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5382 | if (!adapter->eeh_error) { |
| 5383 | adapter->eeh_error = true; |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5384 | |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5385 | cancel_delayed_work_sync(&adapter->func_recovery_work); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5386 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5387 | rtnl_lock(); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5388 | netif_device_detach(netdev); |
| 5389 | if (netif_running(netdev)) |
| 5390 | be_close(netdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5391 | rtnl_unlock(); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5392 | |
| 5393 | be_clear(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5394 | } |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5395 | |
| 5396 | if (state == pci_channel_io_perm_failure) |
| 5397 | return PCI_ERS_RESULT_DISCONNECT; |
| 5398 | |
| 5399 | pci_disable_device(pdev); |
| 5400 | |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 5401 | /* The error could cause the FW to trigger a flash debug dump. |
| 5402 | * Resetting the card while flash dump is in progress |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 5403 | * can cause it not to recover; wait for it to finish. |
| 5404 | * Wait only for first function as it is needed only once per |
| 5405 | * adapter. |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 5406 | */ |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 5407 | if (pdev->devfn == 0) |
| 5408 | ssleep(30); |
| 5409 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5410 | return PCI_ERS_RESULT_NEED_RESET; |
| 5411 | } |
| 5412 | |
| 5413 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 5414 | { |
| 5415 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5416 | int status; |
| 5417 | |
| 5418 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5419 | |
| 5420 | status = pci_enable_device(pdev); |
| 5421 | if (status) |
| 5422 | return PCI_ERS_RESULT_DISCONNECT; |
| 5423 | |
| 5424 | pci_set_master(pdev); |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 5425 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5426 | pci_restore_state(pdev); |
| 5427 | |
| 5428 | /* Check if card is ok and fw is ready */ |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 5429 | dev_info(&adapter->pdev->dev, |
| 5430 | "Waiting for FW to be ready after EEH reset\n"); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 5431 | status = be_fw_wait_ready(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5432 | if (status) |
| 5433 | return PCI_ERS_RESULT_DISCONNECT; |
| 5434 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 5435 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5436 | be_clear_all_error(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5437 | return PCI_ERS_RESULT_RECOVERED; |
| 5438 | } |
| 5439 | |
| 5440 | static void be_eeh_resume(struct pci_dev *pdev) |
| 5441 | { |
| 5442 | int status = 0; |
| 5443 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5444 | struct net_device *netdev = adapter->netdev; |
| 5445 | |
| 5446 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 5447 | |
| 5448 | pci_save_state(pdev); |
| 5449 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 5450 | status = be_cmd_reset_function(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5451 | if (status) |
| 5452 | goto err; |
| 5453 | |
Kalesh AP | 03a58ba | 2014-05-13 14:03:11 +0530 | [diff] [blame] | 5454 | /* On some BE3 FW versions, after a HW reset, |
| 5455 | * interrupts will remain disabled for each function. |
| 5456 | * So, explicitly enable interrupts |
| 5457 | */ |
| 5458 | be_intr_set(adapter, true); |
| 5459 | |
Kalesh AP | 2d177be | 2013-04-28 22:22:29 +0000 | [diff] [blame] | 5460 | /* tell fw we're ready to fire cmds */ |
| 5461 | status = be_cmd_fw_init(adapter); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 5462 | if (status) |
| 5463 | goto err; |
| 5464 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5465 | status = be_setup(adapter); |
| 5466 | if (status) |
| 5467 | goto err; |
| 5468 | |
| 5469 | if (netif_running(netdev)) { |
| 5470 | status = be_open(netdev); |
| 5471 | if (status) |
| 5472 | goto err; |
| 5473 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5474 | |
| 5475 | schedule_delayed_work(&adapter->func_recovery_work, |
| 5476 | msecs_to_jiffies(1000)); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5477 | netif_device_attach(netdev); |
| 5478 | return; |
| 5479 | err: |
| 5480 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5481 | } |
| 5482 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 5483 | static const struct pci_error_handlers be_eeh_handlers = { |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5484 | .error_detected = be_eeh_err_detected, |
| 5485 | .slot_reset = be_eeh_reset, |
| 5486 | .resume = be_eeh_resume, |
| 5487 | }; |
| 5488 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5489 | static struct pci_driver be_driver = { |
| 5490 | .name = DRV_NAME, |
| 5491 | .id_table = be_dev_ids, |
| 5492 | .probe = be_probe, |
| 5493 | .remove = be_remove, |
| 5494 | .suspend = be_suspend, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5495 | .resume = be_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5496 | .shutdown = be_shutdown, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5497 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5498 | }; |
| 5499 | |
| 5500 | static int __init be_init_module(void) |
| 5501 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5502 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 5503 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5504 | printk(KERN_WARNING DRV_NAME |
| 5505 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 5506 | " Using 2048\n"); |
| 5507 | rx_frag_size = 2048; |
| 5508 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5509 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5510 | return pci_register_driver(&be_driver); |
| 5511 | } |
| 5512 | module_init(be_init_module); |
| 5513 | |
| 5514 | static void __exit be_exit_module(void) |
| 5515 | { |
| 5516 | pci_unregister_driver(&be_driver); |
| 5517 | } |
| 5518 | module_exit(be_exit_module); |