Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Somnath Kotur | 7dfbe7d | 2016-06-22 08:54:56 -0400 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2016 Broadcom |
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); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 29 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
Sarveshwar Bandi | 00d3d51 | 2013-01-28 04:17:01 +0000 | [diff] [blame] | 30 | MODULE_AUTHOR("Emulex Corporation"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 31 | MODULE_LICENSE("GPL"); |
| 32 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 33 | /* num_vfs module param is obsolete. |
| 34 | * Use sysfs method to enable/disable VFs. |
| 35 | */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 36 | static unsigned int num_vfs; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 37 | module_param(num_vfs, uint, S_IRUGO); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 38 | MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 39 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 40 | static ushort rx_frag_size = 2048; |
| 41 | module_param(rx_frag_size, ushort, S_IRUGO); |
| 42 | MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data."); |
| 43 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 44 | /* Per-module error detection/recovery workq shared across all functions. |
| 45 | * Each function schedules its own work request on this shared workq. |
| 46 | */ |
Wei Yongjun | e6053dd | 2016-09-25 15:40:36 +0000 | [diff] [blame] | 47 | static struct workqueue_struct *be_err_recovery_workq; |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 48 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 49 | static const struct pci_device_id be_dev_ids[] = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 50 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Ajit Khaparde | 59fd5d8 | 2009-10-29 01:11:06 -0700 | [diff] [blame] | 51 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 52 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 53 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 54 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)}, |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 55 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)}, |
Ajit Khaparde | ecedb6a | 2011-12-15 06:31:38 +0000 | [diff] [blame] | 56 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID5)}, |
Padmanabh Ratnakar | 76b7353 | 2012-10-20 06:04:40 +0000 | [diff] [blame] | 57 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID6)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 58 | { 0 } |
| 59 | }; |
| 60 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 61 | |
| 62 | /* Workqueue used by all functions for defering cmd calls to the adapter */ |
Wei Yongjun | e6053dd | 2016-09-25 15:40:36 +0000 | [diff] [blame] | 63 | static struct workqueue_struct *be_wq; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 64 | |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 65 | /* UE Status Low CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 66 | static const char * const ue_status_low_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 67 | "CEV", |
| 68 | "CTX", |
| 69 | "DBUF", |
| 70 | "ERX", |
| 71 | "Host", |
| 72 | "MPU", |
| 73 | "NDMA", |
| 74 | "PTC ", |
| 75 | "RDMA ", |
| 76 | "RXF ", |
| 77 | "RXIPS ", |
| 78 | "RXULP0 ", |
| 79 | "RXULP1 ", |
| 80 | "RXULP2 ", |
| 81 | "TIM ", |
| 82 | "TPOST ", |
| 83 | "TPRE ", |
| 84 | "TXIPS ", |
| 85 | "TXULP0 ", |
| 86 | "TXULP1 ", |
| 87 | "UC ", |
| 88 | "WDMA ", |
| 89 | "TXULP2 ", |
| 90 | "HOST1 ", |
| 91 | "P0_OB_LINK ", |
| 92 | "P1_OB_LINK ", |
| 93 | "HOST_GPIO ", |
| 94 | "MBOX ", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 95 | "ERX2 ", |
| 96 | "SPARE ", |
| 97 | "JTAG ", |
| 98 | "MPU_INTPEND " |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 99 | }; |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 100 | |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 101 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 102 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 103 | "LPCMEMHOST", |
| 104 | "MGMT_MAC", |
| 105 | "PCS0ONLINE", |
| 106 | "MPU_IRAM", |
| 107 | "PCS1ONLINE", |
| 108 | "PCTL0", |
| 109 | "PCTL1", |
| 110 | "PMEM", |
| 111 | "RR", |
| 112 | "TXPB", |
| 113 | "RXPP", |
| 114 | "XAUI", |
| 115 | "TXP", |
| 116 | "ARM", |
| 117 | "IPC", |
| 118 | "HOST2", |
| 119 | "HOST3", |
| 120 | "HOST4", |
| 121 | "HOST5", |
| 122 | "HOST6", |
| 123 | "HOST7", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 124 | "ECRC", |
| 125 | "Poison TLP", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 126 | "NETC", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 127 | "PERIPH", |
| 128 | "LLTXULP", |
| 129 | "D2P", |
| 130 | "RCON", |
| 131 | "LDMA", |
| 132 | "LLTXP", |
| 133 | "LLTXPB", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 134 | "Unknown" |
| 135 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 136 | |
Venkat Duvvuru | c1bb0a5 | 2016-03-02 06:00:28 -0500 | [diff] [blame] | 137 | #define BE_VF_IF_EN_FLAGS (BE_IF_FLAGS_UNTAGGED | \ |
| 138 | BE_IF_FLAGS_BROADCAST | \ |
| 139 | BE_IF_FLAGS_MULTICAST | \ |
| 140 | BE_IF_FLAGS_PASS_L3L4_ERRORS) |
| 141 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 142 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 143 | { |
| 144 | struct be_dma_mem *mem = &q->dma_mem; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 145 | |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 146 | if (mem->va) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 147 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 148 | mem->dma); |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 149 | mem->va = NULL; |
| 150 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | 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] | 154 | u16 len, u16 entry_size) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 155 | { |
| 156 | struct be_dma_mem *mem = &q->dma_mem; |
| 157 | |
| 158 | memset(q, 0, sizeof(*q)); |
| 159 | q->len = len; |
| 160 | q->entry_size = entry_size; |
| 161 | mem->size = len * entry_size; |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 162 | mem->va = dma_zalloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 163 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 164 | if (!mem->va) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 165 | return -ENOMEM; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 169 | static void be_reg_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 170 | { |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 171 | u32 reg, enabled; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 172 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 173 | pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 174 | ®); |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 175 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 176 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 177 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 178 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 179 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 180 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 181 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 182 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 183 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 184 | pci_write_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 185 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 188 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
| 189 | { |
| 190 | int status = 0; |
| 191 | |
| 192 | /* On lancer interrupts can't be controlled via this register */ |
| 193 | if (lancer_chip(adapter)) |
| 194 | return; |
| 195 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 196 | if (be_check_error(adapter, BE_ERROR_EEH)) |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 197 | return; |
| 198 | |
| 199 | status = be_cmd_intr_set(adapter, enable); |
| 200 | if (status) |
| 201 | be_reg_intr_set(adapter, enable); |
| 202 | } |
| 203 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 204 | 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] | 205 | { |
| 206 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 207 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 208 | if (be_check_error(adapter, BE_ERROR_HW)) |
| 209 | return; |
| 210 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 211 | val |= qid & DB_RQ_RING_ID_MASK; |
| 212 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 213 | |
| 214 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 215 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 218 | static void be_txq_notify(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 219 | u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 220 | { |
| 221 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 222 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 223 | if (be_check_error(adapter, BE_ERROR_HW)) |
| 224 | return; |
| 225 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 226 | val |= txo->q.id & DB_TXULP_RING_ID_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 227 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 228 | |
| 229 | wmb(); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 230 | iowrite32(val, adapter->db + txo->db_offset); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 233 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 234 | bool arm, bool clear_int, u16 num_popped, |
| 235 | u32 eq_delay_mult_enc) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 236 | { |
| 237 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 238 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 239 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 240 | 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] | 241 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 242 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 243 | return; |
| 244 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 245 | if (arm) |
| 246 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 247 | if (clear_int) |
| 248 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 249 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 250 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 251 | val |= eq_delay_mult_enc << DB_EQ_R2I_DLY_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 252 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 255 | 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] | 256 | { |
| 257 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 258 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 259 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 260 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 261 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 262 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 263 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 264 | return; |
| 265 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 266 | if (arm) |
| 267 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 268 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 269 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 272 | static int be_dev_mac_add(struct be_adapter *adapter, u8 *mac) |
| 273 | { |
| 274 | int i; |
| 275 | |
| 276 | /* Check if mac has already been added as part of uc-list */ |
| 277 | for (i = 0; i < adapter->uc_macs; i++) { |
| 278 | if (ether_addr_equal((u8 *)&adapter->uc_list[i * ETH_ALEN], |
| 279 | mac)) { |
| 280 | /* mac already added, skip addition */ |
| 281 | adapter->pmac_id[0] = adapter->pmac_id[i + 1]; |
| 282 | return 0; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | return be_cmd_pmac_add(adapter, mac, adapter->if_handle, |
| 287 | &adapter->pmac_id[0], 0); |
| 288 | } |
| 289 | |
| 290 | static void be_dev_mac_del(struct be_adapter *adapter, int pmac_id) |
| 291 | { |
| 292 | int i; |
| 293 | |
| 294 | /* Skip deletion if the programmed mac is |
| 295 | * being used in uc-list |
| 296 | */ |
| 297 | for (i = 0; i < adapter->uc_macs; i++) { |
| 298 | if (adapter->pmac_id[i + 1] == pmac_id) |
| 299 | return; |
| 300 | } |
| 301 | be_cmd_pmac_del(adapter, adapter->if_handle, pmac_id, 0); |
| 302 | } |
| 303 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 304 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 305 | { |
| 306 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 307 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 308 | struct sockaddr *addr = p; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 309 | int status; |
| 310 | u8 mac[ETH_ALEN]; |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 311 | u32 old_pmac_id = adapter->pmac_id[0]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 312 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 313 | if (!is_valid_ether_addr(addr->sa_data)) |
| 314 | return -EADDRNOTAVAIL; |
| 315 | |
Vasundhara Volam | ff32f8a | 2014-01-15 13:23:35 +0530 | [diff] [blame] | 316 | /* Proceed further only if, User provided MAC is different |
| 317 | * from active MAC |
| 318 | */ |
Suresh Reddy | c27ebf5 | 2016-09-07 19:57:53 +0530 | [diff] [blame] | 319 | if (ether_addr_equal(addr->sa_data, adapter->dev_mac)) |
Vasundhara Volam | ff32f8a | 2014-01-15 13:23:35 +0530 | [diff] [blame] | 320 | return 0; |
| 321 | |
Ivan Vecera | cc43996 | 2017-01-13 22:38:29 +0100 | [diff] [blame] | 322 | /* BE3 VFs without FILTMGMT privilege are not allowed to set its MAC |
| 323 | * address |
| 324 | */ |
| 325 | if (BEx_chip(adapter) && be_virtfn(adapter) && |
| 326 | !check_privilege(adapter, BE_PRIV_FILTMGMT)) |
| 327 | return -EPERM; |
| 328 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 329 | /* if device is not running, copy MAC to netdev->dev_addr */ |
| 330 | if (!netif_running(netdev)) |
| 331 | goto done; |
| 332 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 333 | /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT |
| 334 | * privilege or if PF did not provision the new MAC address. |
| 335 | * On BE3, this cmd will always fail if the VF doesn't have the |
| 336 | * FILTMGMT privilege. This failure is OK, only if the PF programmed |
| 337 | * the MAC for the VF. |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 338 | */ |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 339 | mutex_lock(&adapter->rx_filter_lock); |
| 340 | status = be_dev_mac_add(adapter, (u8 *)addr->sa_data); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 341 | if (!status) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 342 | |
| 343 | /* Delete the old programmed MAC. This call may fail if the |
| 344 | * old MAC was already deleted by the PF driver. |
| 345 | */ |
| 346 | if (adapter->pmac_id[0] != old_pmac_id) |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 347 | be_dev_mac_del(adapter, old_pmac_id); |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 350 | mutex_unlock(&adapter->rx_filter_lock); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 351 | /* Decide if the new MAC is successfully activated only after |
| 352 | * querying the FW |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 353 | */ |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 354 | status = be_cmd_get_active_mac(adapter, adapter->pmac_id[0], mac, |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 355 | adapter->if_handle, true, 0); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 356 | if (status) |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 357 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 358 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 359 | /* The MAC change did not happen, either due to lack of privilege |
| 360 | * or PF didn't pre-provision. |
| 361 | */ |
dingtianhong | 61d23e9 | 2013-12-30 15:40:43 +0800 | [diff] [blame] | 362 | if (!ether_addr_equal(addr->sa_data, mac)) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 363 | status = -EPERM; |
| 364 | goto err; |
| 365 | } |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 366 | done: |
Suresh Reddy | c27ebf5 | 2016-09-07 19:57:53 +0530 | [diff] [blame] | 367 | ether_addr_copy(adapter->dev_mac, addr->sa_data); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 368 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
| 369 | dev_info(dev, "MAC address changed to %pM\n", addr->sa_data); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 370 | return 0; |
| 371 | err: |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 372 | 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] | 373 | return status; |
| 374 | } |
| 375 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 376 | /* BE2 supports only v0 cmd */ |
| 377 | static void *hw_stats_from_cmd(struct be_adapter *adapter) |
| 378 | { |
| 379 | if (BE2_chip(adapter)) { |
| 380 | struct be_cmd_resp_get_stats_v0 *cmd = adapter->stats_cmd.va; |
| 381 | |
| 382 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 383 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 384 | struct be_cmd_resp_get_stats_v1 *cmd = adapter->stats_cmd.va; |
| 385 | |
| 386 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 387 | } else { |
| 388 | struct be_cmd_resp_get_stats_v2 *cmd = adapter->stats_cmd.va; |
| 389 | |
| 390 | return &cmd->hw_stats; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
| 394 | /* BE2 supports only v0 cmd */ |
| 395 | static void *be_erx_stats_from_cmd(struct be_adapter *adapter) |
| 396 | { |
| 397 | if (BE2_chip(adapter)) { |
| 398 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 399 | |
| 400 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 401 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 402 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 403 | |
| 404 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 405 | } else { |
| 406 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 407 | |
| 408 | return &hw_stats->erx; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | static void populate_be_v0_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 413 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 414 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 415 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 416 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 417 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 418 | &rxf_stats->port[adapter->port_num]; |
| 419 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 420 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 421 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 422 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 423 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 424 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 425 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 426 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 427 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 428 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 429 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 430 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 431 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 432 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 433 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 434 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 435 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 436 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 437 | drvs->rx_dropped_header_too_small = |
| 438 | port_stats->rx_dropped_header_too_small; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 439 | drvs->rx_address_filtered = |
| 440 | port_stats->rx_address_filtered + |
| 441 | port_stats->rx_vlan_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 442 | drvs->rx_alignment_symbol_errors = |
| 443 | port_stats->rx_alignment_symbol_errors; |
| 444 | |
| 445 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 446 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 447 | |
| 448 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 449 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 450 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 451 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 452 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 453 | 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] | 454 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 455 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 456 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 457 | 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] | 458 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 459 | } |
| 460 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 461 | static void populate_be_v1_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 462 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 463 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 464 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 465 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 466 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 467 | &rxf_stats->port[adapter->port_num]; |
| 468 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 469 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 470 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 02fe702 | 2011-12-09 13:53:09 +0000 | [diff] [blame] | 471 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 472 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 473 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 474 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 475 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 476 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 477 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 478 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 479 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 480 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 481 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 482 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 483 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 484 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 485 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 486 | drvs->rx_dropped_header_too_small = |
| 487 | port_stats->rx_dropped_header_too_small; |
| 488 | drvs->rx_input_fifo_overflow_drop = |
| 489 | port_stats->rx_input_fifo_overflow_drop; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 490 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 491 | drvs->rx_alignment_symbol_errors = |
| 492 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 493 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 494 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 495 | drvs->tx_controlframes = port_stats->tx_controlframes; |
Ajit Khaparde | b5adffc4 | 2013-05-01 09:38:00 +0000 | [diff] [blame] | 496 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 497 | drvs->jabber_events = port_stats->jabber_events; |
| 498 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 499 | 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] | 500 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 501 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 502 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 503 | 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] | 504 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 505 | } |
| 506 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 507 | static void populate_be_v2_stats(struct be_adapter *adapter) |
| 508 | { |
| 509 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 510 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 511 | struct be_rxf_stats_v2 *rxf_stats = &hw_stats->rxf; |
| 512 | struct be_port_rxf_stats_v2 *port_stats = |
| 513 | &rxf_stats->port[adapter->port_num]; |
| 514 | struct be_drv_stats *drvs = &adapter->drv_stats; |
| 515 | |
| 516 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
| 517 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 518 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
| 519 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 520 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 521 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 522 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 523 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 524 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 525 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 526 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 527 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 528 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 529 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 530 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 531 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 532 | drvs->rx_dropped_header_too_small = |
| 533 | port_stats->rx_dropped_header_too_small; |
| 534 | drvs->rx_input_fifo_overflow_drop = |
| 535 | port_stats->rx_input_fifo_overflow_drop; |
| 536 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
| 537 | drvs->rx_alignment_symbol_errors = |
| 538 | port_stats->rx_alignment_symbol_errors; |
| 539 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
| 540 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 541 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 542 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
| 543 | drvs->jabber_events = port_stats->jabber_events; |
| 544 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 545 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 546 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 547 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
| 548 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 549 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
| 550 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 551 | if (be_roce_supported(adapter)) { |
Ajit Khaparde | 461ae37 | 2013-10-03 16:16:50 -0500 | [diff] [blame] | 552 | drvs->rx_roce_bytes_lsd = port_stats->roce_bytes_received_lsd; |
| 553 | drvs->rx_roce_bytes_msd = port_stats->roce_bytes_received_msd; |
| 554 | drvs->rx_roce_frames = port_stats->roce_frames_received; |
| 555 | drvs->roce_drops_crc = port_stats->roce_drops_crc; |
| 556 | drvs->roce_drops_payload_len = |
| 557 | port_stats->roce_drops_payload_len; |
| 558 | } |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 559 | } |
| 560 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 561 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 562 | { |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 563 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 564 | struct lancer_pport_stats *pport_stats = pport_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 565 | |
| 566 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 567 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 568 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 569 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 570 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 571 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 572 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 573 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 574 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 575 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 576 | drvs->rx_dropped_tcp_length = |
| 577 | pport_stats->rx_dropped_invalid_tcp_length; |
| 578 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 579 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 580 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 581 | drvs->rx_dropped_header_too_small = |
| 582 | pport_stats->rx_dropped_header_too_small; |
| 583 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 584 | drvs->rx_address_filtered = |
| 585 | pport_stats->rx_address_filtered + |
| 586 | pport_stats->rx_vlan_filtered; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 587 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 588 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 589 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 590 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 591 | drvs->jabber_events = pport_stats->rx_jabbers; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 592 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 593 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 594 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 595 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 596 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 597 | |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 598 | static void accumulate_16bit_val(u32 *acc, u16 val) |
| 599 | { |
| 600 | #define lo(x) (x & 0xFFFF) |
| 601 | #define hi(x) (x & 0xFFFF0000) |
| 602 | bool wrapped = val < lo(*acc); |
| 603 | u32 newacc = hi(*acc) + val; |
| 604 | |
| 605 | if (wrapped) |
| 606 | newacc += 65536; |
| 607 | ACCESS_ONCE(*acc) = newacc; |
| 608 | } |
| 609 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 610 | static void populate_erx_stats(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 611 | struct be_rx_obj *rxo, u32 erx_stat) |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 612 | { |
| 613 | if (!BEx_chip(adapter)) |
| 614 | rx_stats(rxo)->rx_drops_no_frags = erx_stat; |
| 615 | else |
| 616 | /* below erx HW counter can actually wrap around after |
| 617 | * 65535. Driver accumulates a 32-bit value |
| 618 | */ |
| 619 | accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags, |
| 620 | (u16)erx_stat); |
| 621 | } |
| 622 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 623 | void be_parse_stats(struct be_adapter *adapter) |
| 624 | { |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 625 | struct be_erx_stats_v2 *erx = be_erx_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 626 | struct be_rx_obj *rxo; |
| 627 | int i; |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 628 | u32 erx_stat; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 629 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 630 | if (lancer_chip(adapter)) { |
| 631 | populate_lancer_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 632 | } else { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 633 | if (BE2_chip(adapter)) |
| 634 | populate_be_v0_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 635 | else if (BE3_chip(adapter)) |
| 636 | /* for BE3 */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 637 | populate_be_v1_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 638 | else |
| 639 | populate_be_v2_stats(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 640 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 641 | /* 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] | 642 | for_all_rx_queues(adapter, rxo, i) { |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 643 | erx_stat = erx->rx_drops_no_fragments[rxo->q.id]; |
| 644 | populate_erx_stats(adapter, rxo, erx_stat); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 645 | } |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 646 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 649 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 650 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 651 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 652 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 653 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 654 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 655 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 656 | u64 pkts, bytes; |
| 657 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 658 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 659 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 660 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 661 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 662 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 663 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 664 | start = u64_stats_fetch_begin_irq(&rx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 665 | pkts = rx_stats(rxo)->rx_pkts; |
| 666 | bytes = rx_stats(rxo)->rx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 667 | } while (u64_stats_fetch_retry_irq(&rx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 668 | stats->rx_packets += pkts; |
| 669 | stats->rx_bytes += bytes; |
| 670 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 671 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 672 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 675 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 676 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 677 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 678 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 679 | start = u64_stats_fetch_begin_irq(&tx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 680 | pkts = tx_stats(txo)->tx_pkts; |
| 681 | bytes = tx_stats(txo)->tx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 682 | } while (u64_stats_fetch_retry_irq(&tx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 683 | stats->tx_packets += pkts; |
| 684 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 685 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 686 | |
| 687 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 688 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 689 | drvs->rx_alignment_symbol_errors + |
| 690 | drvs->rx_in_range_errors + |
| 691 | drvs->rx_out_range_errors + |
| 692 | drvs->rx_frame_too_long + |
| 693 | drvs->rx_dropped_too_small + |
| 694 | drvs->rx_dropped_too_short + |
| 695 | drvs->rx_dropped_header_too_small + |
| 696 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 697 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 698 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 699 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 700 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 701 | drvs->rx_out_range_errors + |
| 702 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 703 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 704 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 705 | |
| 706 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 707 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 708 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 709 | /* receiver fifo overrun */ |
| 710 | /* 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] | 711 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 712 | drvs->rx_input_fifo_overflow_drop + |
| 713 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 714 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 717 | void be_link_status_update(struct be_adapter *adapter, u8 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 718 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 719 | struct net_device *netdev = adapter->netdev; |
| 720 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 721 | if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) { |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 722 | netif_carrier_off(netdev); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 723 | adapter->flags |= BE_FLAGS_LINK_STATUS_INIT; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 724 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 725 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 726 | if (link_status) |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 727 | netif_carrier_on(netdev); |
| 728 | else |
| 729 | netif_carrier_off(netdev); |
Ivan Vecera | 1882489 | 2015-04-30 11:59:49 +0200 | [diff] [blame] | 730 | |
| 731 | netdev_info(netdev, "Link is %s\n", link_status ? "Up" : "Down"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Sriharsha Basavapatna | f3d6ad8 | 2016-10-09 09:58:52 +0530 | [diff] [blame] | 734 | static int be_gso_hdr_len(struct sk_buff *skb) |
| 735 | { |
| 736 | if (skb->encapsulation) |
| 737 | return skb_inner_transport_offset(skb) + |
| 738 | inner_tcp_hdrlen(skb); |
| 739 | return skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 740 | } |
| 741 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 742 | 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] | 743 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 744 | struct be_tx_stats *stats = tx_stats(txo); |
Sriharsha Basavapatna | f3d6ad8 | 2016-10-09 09:58:52 +0530 | [diff] [blame] | 745 | u32 tx_pkts = skb_shinfo(skb)->gso_segs ? : 1; |
| 746 | /* Account for headers which get duplicated in TSO pkt */ |
| 747 | u32 dup_hdr_len = tx_pkts > 1 ? be_gso_hdr_len(skb) * (tx_pkts - 1) : 0; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 748 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 749 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 750 | stats->tx_reqs++; |
Sriharsha Basavapatna | f3d6ad8 | 2016-10-09 09:58:52 +0530 | [diff] [blame] | 751 | stats->tx_bytes += skb->len + dup_hdr_len; |
Sriharsha Basavapatna | 8670f2a | 2015-07-29 19:35:32 +0530 | [diff] [blame] | 752 | stats->tx_pkts += tx_pkts; |
| 753 | if (skb->encapsulation && skb->ip_summed == CHECKSUM_PARTIAL) |
| 754 | stats->tx_vxlan_offload_pkts += tx_pkts; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 755 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 758 | /* Returns number of WRBs needed for the skb */ |
| 759 | static u32 skb_wrb_cnt(struct sk_buff *skb) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 760 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 761 | /* +1 for the header wrb */ |
| 762 | return 1 + (skb_headlen(skb) ? 1 : 0) + skb_shinfo(skb)->nr_frags; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 766 | { |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 767 | wrb->frag_pa_hi = cpu_to_le32(upper_32_bits(addr)); |
| 768 | wrb->frag_pa_lo = cpu_to_le32(lower_32_bits(addr)); |
| 769 | wrb->frag_len = cpu_to_le32(len & ETH_WRB_FRAG_LEN_MASK); |
| 770 | wrb->rsvd0 = 0; |
| 771 | } |
| 772 | |
| 773 | /* A dummy wrb is just all zeros. Using a separate routine for dummy-wrb |
| 774 | * to avoid the swap and shift/mask operations in wrb_fill(). |
| 775 | */ |
| 776 | static inline void wrb_fill_dummy(struct be_eth_wrb *wrb) |
| 777 | { |
| 778 | wrb->frag_pa_hi = 0; |
| 779 | wrb->frag_pa_lo = 0; |
| 780 | wrb->frag_len = 0; |
Somnath Kotur | 89b1f49 | 2012-06-24 19:40:55 +0000 | [diff] [blame] | 781 | wrb->rsvd0 = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 784 | static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 785 | struct sk_buff *skb) |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 786 | { |
| 787 | u8 vlan_prio; |
| 788 | u16 vlan_tag; |
| 789 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 790 | vlan_tag = skb_vlan_tag_get(skb); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 791 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 792 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 793 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 794 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
Sathya Perla | fdf81bf | 2015-12-30 01:29:01 -0500 | [diff] [blame] | 795 | adapter->recommended_prio_bits; |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 796 | |
| 797 | return vlan_tag; |
| 798 | } |
| 799 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 800 | /* Used only for IP tunnel packets */ |
| 801 | static u16 skb_inner_ip_proto(struct sk_buff *skb) |
| 802 | { |
| 803 | return (inner_ip_hdr(skb)->version == 4) ? |
| 804 | inner_ip_hdr(skb)->protocol : inner_ipv6_hdr(skb)->nexthdr; |
| 805 | } |
| 806 | |
| 807 | static u16 skb_ip_proto(struct sk_buff *skb) |
| 808 | { |
| 809 | return (ip_hdr(skb)->version == 4) ? |
| 810 | ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr; |
| 811 | } |
| 812 | |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 813 | static inline bool be_is_txq_full(struct be_tx_obj *txo) |
| 814 | { |
| 815 | return atomic_read(&txo->q.used) + BE_MAX_TX_FRAG_COUNT >= txo->q.len; |
| 816 | } |
| 817 | |
| 818 | static inline bool be_can_txq_wake(struct be_tx_obj *txo) |
| 819 | { |
| 820 | return atomic_read(&txo->q.used) < txo->q.len / 2; |
| 821 | } |
| 822 | |
| 823 | static inline bool be_is_tx_compl_pending(struct be_tx_obj *txo) |
| 824 | { |
| 825 | return atomic_read(&txo->q.used) > txo->pend_wrb_cnt; |
| 826 | } |
| 827 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 828 | static void be_get_wrb_params_from_skb(struct be_adapter *adapter, |
| 829 | struct sk_buff *skb, |
| 830 | struct be_wrb_params *wrb_params) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 831 | { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 832 | u16 proto; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 833 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 834 | if (skb_is_gso(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 835 | BE_WRB_F_SET(wrb_params->features, LSO, 1); |
| 836 | wrb_params->lso_mss = skb_shinfo(skb)->gso_size; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 837 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 838 | BE_WRB_F_SET(wrb_params->features, LSO6, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 839 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 840 | if (skb->encapsulation) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 841 | BE_WRB_F_SET(wrb_params->features, IPCS, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 842 | proto = skb_inner_ip_proto(skb); |
| 843 | } else { |
| 844 | proto = skb_ip_proto(skb); |
| 845 | } |
| 846 | if (proto == IPPROTO_TCP) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 847 | BE_WRB_F_SET(wrb_params->features, TCPCS, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 848 | else if (proto == IPPROTO_UDP) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 849 | BE_WRB_F_SET(wrb_params->features, UDPCS, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 852 | if (skb_vlan_tag_present(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 853 | BE_WRB_F_SET(wrb_params->features, VLAN, 1); |
| 854 | wrb_params->vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 857 | BE_WRB_F_SET(wrb_params->features, CRC, 1); |
| 858 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 859 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 860 | static void wrb_fill_hdr(struct be_adapter *adapter, |
| 861 | struct be_eth_hdr_wrb *hdr, |
| 862 | struct be_wrb_params *wrb_params, |
| 863 | struct sk_buff *skb) |
| 864 | { |
| 865 | memset(hdr, 0, sizeof(*hdr)); |
| 866 | |
| 867 | SET_TX_WRB_HDR_BITS(crc, hdr, |
| 868 | BE_WRB_F_GET(wrb_params->features, CRC)); |
| 869 | SET_TX_WRB_HDR_BITS(ipcs, hdr, |
| 870 | BE_WRB_F_GET(wrb_params->features, IPCS)); |
| 871 | SET_TX_WRB_HDR_BITS(tcpcs, hdr, |
| 872 | BE_WRB_F_GET(wrb_params->features, TCPCS)); |
| 873 | SET_TX_WRB_HDR_BITS(udpcs, hdr, |
| 874 | BE_WRB_F_GET(wrb_params->features, UDPCS)); |
| 875 | |
| 876 | SET_TX_WRB_HDR_BITS(lso, hdr, |
| 877 | BE_WRB_F_GET(wrb_params->features, LSO)); |
| 878 | SET_TX_WRB_HDR_BITS(lso6, hdr, |
| 879 | BE_WRB_F_GET(wrb_params->features, LSO6)); |
| 880 | SET_TX_WRB_HDR_BITS(lso_mss, hdr, wrb_params->lso_mss); |
| 881 | |
| 882 | /* Hack to skip HW VLAN tagging needs evt = 1, compl = 0. When this |
| 883 | * hack is not needed, the evt bit is set while ringing DB. |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 884 | */ |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 885 | SET_TX_WRB_HDR_BITS(event, hdr, |
| 886 | BE_WRB_F_GET(wrb_params->features, VLAN_SKIP_HW)); |
| 887 | SET_TX_WRB_HDR_BITS(vlan, hdr, |
| 888 | BE_WRB_F_GET(wrb_params->features, VLAN)); |
| 889 | SET_TX_WRB_HDR_BITS(vlan_tag, hdr, wrb_params->vlan_tag); |
| 890 | |
| 891 | SET_TX_WRB_HDR_BITS(num_wrb, hdr, skb_wrb_cnt(skb)); |
| 892 | SET_TX_WRB_HDR_BITS(len, hdr, skb->len); |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 893 | SET_TX_WRB_HDR_BITS(mgmt, hdr, |
| 894 | BE_WRB_F_GET(wrb_params->features, OS2BMC)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 897 | 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] | 898 | bool unmap_single) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 899 | { |
| 900 | dma_addr_t dma; |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 901 | u32 frag_len = le32_to_cpu(wrb->frag_len); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 902 | |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 903 | |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 904 | dma = (u64)le32_to_cpu(wrb->frag_pa_hi) << 32 | |
| 905 | (u64)le32_to_cpu(wrb->frag_pa_lo); |
| 906 | if (frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 907 | if (unmap_single) |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 908 | dma_unmap_single(dev, dma, frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 909 | else |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 910 | dma_unmap_page(dev, dma, frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 911 | } |
| 912 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 913 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 914 | /* Grab a WRB header for xmit */ |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 915 | static u32 be_tx_get_wrb_hdr(struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 916 | { |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 917 | u32 head = txo->q.head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 918 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 919 | queue_head_inc(&txo->q); |
| 920 | return head; |
| 921 | } |
| 922 | |
| 923 | /* Set up the WRB header for xmit */ |
| 924 | static void be_tx_setup_wrb_hdr(struct be_adapter *adapter, |
| 925 | struct be_tx_obj *txo, |
| 926 | struct be_wrb_params *wrb_params, |
| 927 | struct sk_buff *skb, u16 head) |
| 928 | { |
| 929 | u32 num_frags = skb_wrb_cnt(skb); |
| 930 | struct be_queue_info *txq = &txo->q; |
| 931 | struct be_eth_hdr_wrb *hdr = queue_index_node(txq, head); |
| 932 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 933 | wrb_fill_hdr(adapter, hdr, wrb_params, skb); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 934 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 935 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 936 | BUG_ON(txo->sent_skb_list[head]); |
| 937 | txo->sent_skb_list[head] = skb; |
| 938 | txo->last_req_hdr = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 939 | atomic_add(num_frags, &txq->used); |
| 940 | txo->last_req_wrb_cnt = num_frags; |
| 941 | txo->pend_wrb_cnt += num_frags; |
| 942 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 943 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 944 | /* Setup a WRB fragment (buffer descriptor) for xmit */ |
| 945 | static void be_tx_setup_wrb_frag(struct be_tx_obj *txo, dma_addr_t busaddr, |
| 946 | int len) |
| 947 | { |
| 948 | struct be_eth_wrb *wrb; |
| 949 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 950 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 951 | wrb = queue_head_node(txq); |
| 952 | wrb_fill(wrb, busaddr, len); |
| 953 | queue_head_inc(txq); |
| 954 | } |
| 955 | |
| 956 | /* Bring the queue back to the state it was in before be_xmit_enqueue() routine |
| 957 | * was invoked. The producer index is restored to the previous packet and the |
| 958 | * WRBs of the current packet are unmapped. Invoked to handle tx setup errors. |
| 959 | */ |
| 960 | static void be_xmit_restore(struct be_adapter *adapter, |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 961 | struct be_tx_obj *txo, u32 head, bool map_single, |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 962 | u32 copied) |
| 963 | { |
| 964 | struct device *dev; |
| 965 | struct be_eth_wrb *wrb; |
| 966 | struct be_queue_info *txq = &txo->q; |
| 967 | |
| 968 | dev = &adapter->pdev->dev; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 969 | txq->head = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 970 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 971 | /* skip the first wrb (hdr); it's not mapped */ |
| 972 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 973 | while (copied) { |
| 974 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 975 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 976 | map_single = false; |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 977 | copied -= le32_to_cpu(wrb->frag_len); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 978 | queue_head_inc(txq); |
| 979 | } |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 980 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 981 | txq->head = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /* Enqueue the given packet for transmit. This routine allocates WRBs for the |
| 985 | * packet, dma maps the packet buffers and sets up the WRBs. Returns the number |
| 986 | * of WRBs used up by the packet. |
| 987 | */ |
| 988 | static u32 be_xmit_enqueue(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 989 | struct sk_buff *skb, |
| 990 | struct be_wrb_params *wrb_params) |
| 991 | { |
| 992 | u32 i, copied = 0, wrb_cnt = skb_wrb_cnt(skb); |
| 993 | struct device *dev = &adapter->pdev->dev; |
| 994 | struct be_queue_info *txq = &txo->q; |
| 995 | bool map_single = false; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 996 | u32 head = txq->head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 997 | dma_addr_t busaddr; |
| 998 | int len; |
| 999 | |
| 1000 | head = be_tx_get_wrb_hdr(txo); |
| 1001 | |
| 1002 | if (skb->len > skb->data_len) { |
| 1003 | len = skb_headlen(skb); |
| 1004 | |
| 1005 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 1006 | if (dma_mapping_error(dev, busaddr)) |
| 1007 | goto dma_err; |
| 1008 | map_single = true; |
| 1009 | be_tx_setup_wrb_frag(txo, busaddr, len); |
| 1010 | copied += len; |
| 1011 | } |
| 1012 | |
| 1013 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1014 | const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; |
| 1015 | len = skb_frag_size(frag); |
| 1016 | |
| 1017 | busaddr = skb_frag_dma_map(dev, frag, 0, len, DMA_TO_DEVICE); |
| 1018 | if (dma_mapping_error(dev, busaddr)) |
| 1019 | goto dma_err; |
| 1020 | be_tx_setup_wrb_frag(txo, busaddr, len); |
| 1021 | copied += len; |
| 1022 | } |
| 1023 | |
| 1024 | be_tx_setup_wrb_hdr(adapter, txo, wrb_params, skb, head); |
| 1025 | |
| 1026 | be_tx_stats_update(txo, skb); |
| 1027 | return wrb_cnt; |
| 1028 | |
| 1029 | dma_err: |
| 1030 | adapter->drv_stats.dma_map_errors++; |
| 1031 | be_xmit_restore(adapter, txo, head, map_single, copied); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 1032 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 1035 | static inline int qnq_async_evt_rcvd(struct be_adapter *adapter) |
| 1036 | { |
| 1037 | return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD; |
| 1038 | } |
| 1039 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1040 | 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] | 1041 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1042 | struct be_wrb_params |
| 1043 | *wrb_params) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1044 | { |
| 1045 | u16 vlan_tag = 0; |
| 1046 | |
| 1047 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 1048 | if (unlikely(!skb)) |
| 1049 | return skb; |
| 1050 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1051 | if (skb_vlan_tag_present(skb)) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1052 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 1053 | |
| 1054 | if (qnq_async_evt_rcvd(adapter) && adapter->pvid) { |
| 1055 | if (!vlan_tag) |
| 1056 | vlan_tag = adapter->pvid; |
| 1057 | /* f/w workaround to set skip_hw_vlan = 1, informs the F/W to |
| 1058 | * skip VLAN insertion |
| 1059 | */ |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1060 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 1061 | } |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1062 | |
| 1063 | if (vlan_tag) { |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 1064 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 1065 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1066 | if (unlikely(!skb)) |
| 1067 | return skb; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1068 | skb->vlan_tci = 0; |
| 1069 | } |
| 1070 | |
| 1071 | /* Insert the outer VLAN, if any */ |
| 1072 | if (adapter->qnq_vid) { |
| 1073 | vlan_tag = adapter->qnq_vid; |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 1074 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 1075 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1076 | if (unlikely(!skb)) |
| 1077 | return skb; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1078 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1081 | return skb; |
| 1082 | } |
| 1083 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1084 | static bool be_ipv6_exthdr_check(struct sk_buff *skb) |
| 1085 | { |
| 1086 | struct ethhdr *eh = (struct ethhdr *)skb->data; |
| 1087 | u16 offset = ETH_HLEN; |
| 1088 | |
| 1089 | if (eh->h_proto == htons(ETH_P_IPV6)) { |
| 1090 | struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + offset); |
| 1091 | |
| 1092 | offset += sizeof(struct ipv6hdr); |
| 1093 | if (ip6h->nexthdr != NEXTHDR_TCP && |
| 1094 | ip6h->nexthdr != NEXTHDR_UDP) { |
| 1095 | struct ipv6_opt_hdr *ehdr = |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 1096 | (struct ipv6_opt_hdr *)(skb->data + offset); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* offending pkt: 2nd byte following IPv6 hdr is 0xff */ |
| 1099 | if (ehdr->hdrlen == 0xff) |
| 1100 | return true; |
| 1101 | } |
| 1102 | } |
| 1103 | return false; |
| 1104 | } |
| 1105 | |
| 1106 | static int be_vlan_tag_tx_chk(struct be_adapter *adapter, struct sk_buff *skb) |
| 1107 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1108 | return skb_vlan_tag_present(skb) || adapter->pvid || adapter->qnq_vid; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1111 | 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] | 1112 | { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1113 | return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1116 | static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter, |
| 1117 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1118 | struct be_wrb_params |
| 1119 | *wrb_params) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1120 | { |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1121 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1122 | unsigned int eth_hdr_len; |
| 1123 | struct iphdr *ip; |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1124 | |
Ajit Khaparde | 1297f9d | 2013-04-24 11:52:28 +0000 | [diff] [blame] | 1125 | /* For padded packets, BE HW modifies tot_len field in IP header |
| 1126 | * incorrecly when VLAN tag is inserted by HW. |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 1127 | * For padded packets, Lancer computes incorrect checksum. |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1128 | */ |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1129 | eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ? |
| 1130 | VLAN_ETH_HLEN : ETH_HLEN; |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 1131 | if (skb->len <= 60 && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1132 | (lancer_chip(adapter) || skb_vlan_tag_present(skb)) && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1133 | is_ipv4_pkt(skb)) { |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1134 | ip = (struct iphdr *)ip_hdr(skb); |
| 1135 | pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len)); |
| 1136 | } |
| 1137 | |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1138 | /* If vlan tag is already inlined in the packet, skip HW VLAN |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1139 | * tagging in pvid-tagging mode |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1140 | */ |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1141 | if (be_pvid_tagging_enabled(adapter) && |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1142 | veh->h_vlan_proto == htons(ETH_P_8021Q)) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1143 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1144 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1145 | /* HW has a bug wherein it will calculate CSUM for VLAN |
| 1146 | * pkts even though it is disabled. |
| 1147 | * Manually insert VLAN in pkt. |
| 1148 | */ |
| 1149 | if (skb->ip_summed != CHECKSUM_PARTIAL && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1150 | skb_vlan_tag_present(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1151 | skb = be_insert_vlan_in_pkt(adapter, skb, wrb_params); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1152 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1153 | goto err; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* HW may lockup when VLAN HW tagging is requested on |
| 1157 | * certain ipv6 packets. Drop such pkts if the HW workaround to |
| 1158 | * skip HW tagging is not enabled by FW. |
| 1159 | */ |
| 1160 | if (unlikely(be_ipv6_tx_stall_chk(adapter, skb) && |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 1161 | (adapter->pvid || adapter->qnq_vid) && |
| 1162 | !qnq_async_evt_rcvd(adapter))) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1163 | goto tx_drop; |
| 1164 | |
| 1165 | /* Manual VLAN tag insertion to prevent: |
| 1166 | * ASIC lockup when the ASIC inserts VLAN tag into |
| 1167 | * certain ipv6 packets. Insert VLAN tags in driver, |
| 1168 | * and set event, completion, vlan bits accordingly |
| 1169 | * in the Tx WRB. |
| 1170 | */ |
| 1171 | if (be_ipv6_tx_stall_chk(adapter, skb) && |
| 1172 | be_vlan_tag_tx_chk(adapter, skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1173 | skb = be_insert_vlan_in_pkt(adapter, skb, wrb_params); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1174 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1175 | goto err; |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1178 | return skb; |
| 1179 | tx_drop: |
| 1180 | dev_kfree_skb_any(skb); |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1181 | err: |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1182 | return NULL; |
| 1183 | } |
| 1184 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1185 | static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, |
| 1186 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1187 | struct be_wrb_params *wrb_params) |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1188 | { |
ajit.khaparde@broadcom.com | 127bfce | 2016-02-23 00:35:01 +0530 | [diff] [blame] | 1189 | int err; |
| 1190 | |
Suresh Reddy | 8227e99 | 2015-10-12 03:47:19 -0400 | [diff] [blame] | 1191 | /* Lancer, SH and BE3 in SRIOV mode have a bug wherein |
| 1192 | * packets that are 32b or less may cause a transmit stall |
| 1193 | * on that port. The workaround is to pad such packets |
| 1194 | * (len <= 32 bytes) to a minimum length of 36b. |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1195 | */ |
Suresh Reddy | 8227e99 | 2015-10-12 03:47:19 -0400 | [diff] [blame] | 1196 | if (skb->len <= 32) { |
Alexander Duyck | 74b6939 | 2014-12-03 08:17:46 -0800 | [diff] [blame] | 1197 | if (skb_put_padto(skb, 36)) |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1198 | return NULL; |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1202 | skb = be_lancer_xmit_workarounds(adapter, skb, wrb_params); |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1203 | if (!skb) |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
ajit.khaparde@broadcom.com | 127bfce | 2016-02-23 00:35:01 +0530 | [diff] [blame] | 1207 | /* The stack can send us skbs with length greater than |
| 1208 | * what the HW can handle. Trim the extra bytes. |
| 1209 | */ |
| 1210 | WARN_ON_ONCE(skb->len > BE_MAX_GSO_SIZE); |
| 1211 | err = pskb_trim(skb, BE_MAX_GSO_SIZE); |
| 1212 | WARN_ON(err); |
| 1213 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1214 | return skb; |
| 1215 | } |
| 1216 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1217 | static void be_xmit_flush(struct be_adapter *adapter, struct be_tx_obj *txo) |
| 1218 | { |
| 1219 | struct be_queue_info *txq = &txo->q; |
| 1220 | struct be_eth_hdr_wrb *hdr = queue_index_node(txq, txo->last_req_hdr); |
| 1221 | |
| 1222 | /* Mark the last request eventable if it hasn't been marked already */ |
| 1223 | if (!(hdr->dw[2] & cpu_to_le32(TX_HDR_WRB_EVT))) |
| 1224 | hdr->dw[2] |= cpu_to_le32(TX_HDR_WRB_EVT | TX_HDR_WRB_COMPL); |
| 1225 | |
| 1226 | /* compose a dummy wrb if there are odd set of wrbs to notify */ |
| 1227 | if (!lancer_chip(adapter) && (txo->pend_wrb_cnt & 1)) { |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 1228 | wrb_fill_dummy(queue_head_node(txq)); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1229 | queue_head_inc(txq); |
| 1230 | atomic_inc(&txq->used); |
| 1231 | txo->pend_wrb_cnt++; |
| 1232 | hdr->dw[2] &= ~cpu_to_le32(TX_HDR_WRB_NUM_MASK << |
| 1233 | TX_HDR_WRB_NUM_SHIFT); |
| 1234 | hdr->dw[2] |= cpu_to_le32((txo->last_req_wrb_cnt + 1) << |
| 1235 | TX_HDR_WRB_NUM_SHIFT); |
| 1236 | } |
| 1237 | be_txq_notify(adapter, txo, txo->pend_wrb_cnt); |
| 1238 | txo->pend_wrb_cnt = 0; |
| 1239 | } |
| 1240 | |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 1241 | /* OS2BMC related */ |
| 1242 | |
| 1243 | #define DHCP_CLIENT_PORT 68 |
| 1244 | #define DHCP_SERVER_PORT 67 |
| 1245 | #define NET_BIOS_PORT1 137 |
| 1246 | #define NET_BIOS_PORT2 138 |
| 1247 | #define DHCPV6_RAS_PORT 547 |
| 1248 | |
| 1249 | #define is_mc_allowed_on_bmc(adapter, eh) \ |
| 1250 | (!is_multicast_filt_enabled(adapter) && \ |
| 1251 | is_multicast_ether_addr(eh->h_dest) && \ |
| 1252 | !is_broadcast_ether_addr(eh->h_dest)) |
| 1253 | |
| 1254 | #define is_bc_allowed_on_bmc(adapter, eh) \ |
| 1255 | (!is_broadcast_filt_enabled(adapter) && \ |
| 1256 | is_broadcast_ether_addr(eh->h_dest)) |
| 1257 | |
| 1258 | #define is_arp_allowed_on_bmc(adapter, skb) \ |
| 1259 | (is_arp(skb) && is_arp_filt_enabled(adapter)) |
| 1260 | |
| 1261 | #define is_broadcast_packet(eh, adapter) \ |
| 1262 | (is_multicast_ether_addr(eh->h_dest) && \ |
| 1263 | !compare_ether_addr(eh->h_dest, adapter->netdev->broadcast)) |
| 1264 | |
| 1265 | #define is_arp(skb) (skb->protocol == htons(ETH_P_ARP)) |
| 1266 | |
| 1267 | #define is_arp_filt_enabled(adapter) \ |
| 1268 | (adapter->bmc_filt_mask & (BMC_FILT_BROADCAST_ARP)) |
| 1269 | |
| 1270 | #define is_dhcp_client_filt_enabled(adapter) \ |
| 1271 | (adapter->bmc_filt_mask & BMC_FILT_BROADCAST_DHCP_CLIENT) |
| 1272 | |
| 1273 | #define is_dhcp_srvr_filt_enabled(adapter) \ |
| 1274 | (adapter->bmc_filt_mask & BMC_FILT_BROADCAST_DHCP_SERVER) |
| 1275 | |
| 1276 | #define is_nbios_filt_enabled(adapter) \ |
| 1277 | (adapter->bmc_filt_mask & BMC_FILT_BROADCAST_NET_BIOS) |
| 1278 | |
| 1279 | #define is_ipv6_na_filt_enabled(adapter) \ |
| 1280 | (adapter->bmc_filt_mask & \ |
| 1281 | BMC_FILT_MULTICAST_IPV6_NEIGH_ADVER) |
| 1282 | |
| 1283 | #define is_ipv6_ra_filt_enabled(adapter) \ |
| 1284 | (adapter->bmc_filt_mask & BMC_FILT_MULTICAST_IPV6_RA) |
| 1285 | |
| 1286 | #define is_ipv6_ras_filt_enabled(adapter) \ |
| 1287 | (adapter->bmc_filt_mask & BMC_FILT_MULTICAST_IPV6_RAS) |
| 1288 | |
| 1289 | #define is_broadcast_filt_enabled(adapter) \ |
| 1290 | (adapter->bmc_filt_mask & BMC_FILT_BROADCAST) |
| 1291 | |
| 1292 | #define is_multicast_filt_enabled(adapter) \ |
| 1293 | (adapter->bmc_filt_mask & BMC_FILT_MULTICAST) |
| 1294 | |
| 1295 | static bool be_send_pkt_to_bmc(struct be_adapter *adapter, |
| 1296 | struct sk_buff **skb) |
| 1297 | { |
| 1298 | struct ethhdr *eh = (struct ethhdr *)(*skb)->data; |
| 1299 | bool os2bmc = false; |
| 1300 | |
| 1301 | if (!be_is_os2bmc_enabled(adapter)) |
| 1302 | goto done; |
| 1303 | |
| 1304 | if (!is_multicast_ether_addr(eh->h_dest)) |
| 1305 | goto done; |
| 1306 | |
| 1307 | if (is_mc_allowed_on_bmc(adapter, eh) || |
| 1308 | is_bc_allowed_on_bmc(adapter, eh) || |
| 1309 | is_arp_allowed_on_bmc(adapter, (*skb))) { |
| 1310 | os2bmc = true; |
| 1311 | goto done; |
| 1312 | } |
| 1313 | |
| 1314 | if ((*skb)->protocol == htons(ETH_P_IPV6)) { |
| 1315 | struct ipv6hdr *hdr = ipv6_hdr((*skb)); |
| 1316 | u8 nexthdr = hdr->nexthdr; |
| 1317 | |
| 1318 | if (nexthdr == IPPROTO_ICMPV6) { |
| 1319 | struct icmp6hdr *icmp6 = icmp6_hdr((*skb)); |
| 1320 | |
| 1321 | switch (icmp6->icmp6_type) { |
| 1322 | case NDISC_ROUTER_ADVERTISEMENT: |
| 1323 | os2bmc = is_ipv6_ra_filt_enabled(adapter); |
| 1324 | goto done; |
| 1325 | case NDISC_NEIGHBOUR_ADVERTISEMENT: |
| 1326 | os2bmc = is_ipv6_na_filt_enabled(adapter); |
| 1327 | goto done; |
| 1328 | default: |
| 1329 | break; |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if (is_udp_pkt((*skb))) { |
| 1335 | struct udphdr *udp = udp_hdr((*skb)); |
| 1336 | |
Venkat Duvvuru | 1645d99 | 2015-07-10 05:32:47 -0400 | [diff] [blame] | 1337 | switch (ntohs(udp->dest)) { |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 1338 | case DHCP_CLIENT_PORT: |
| 1339 | os2bmc = is_dhcp_client_filt_enabled(adapter); |
| 1340 | goto done; |
| 1341 | case DHCP_SERVER_PORT: |
| 1342 | os2bmc = is_dhcp_srvr_filt_enabled(adapter); |
| 1343 | goto done; |
| 1344 | case NET_BIOS_PORT1: |
| 1345 | case NET_BIOS_PORT2: |
| 1346 | os2bmc = is_nbios_filt_enabled(adapter); |
| 1347 | goto done; |
| 1348 | case DHCPV6_RAS_PORT: |
| 1349 | os2bmc = is_ipv6_ras_filt_enabled(adapter); |
| 1350 | goto done; |
| 1351 | default: |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | done: |
| 1356 | /* For packets over a vlan, which are destined |
| 1357 | * to BMC, asic expects the vlan to be inline in the packet. |
| 1358 | */ |
| 1359 | if (os2bmc) |
| 1360 | *skb = be_insert_vlan_in_pkt(adapter, *skb, NULL); |
| 1361 | |
| 1362 | return os2bmc; |
| 1363 | } |
| 1364 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1365 | static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1366 | { |
| 1367 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1368 | u16 q_idx = skb_get_queue_mapping(skb); |
| 1369 | struct be_tx_obj *txo = &adapter->tx_obj[q_idx]; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1370 | struct be_wrb_params wrb_params = { 0 }; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1371 | bool flush = !skb->xmit_more; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1372 | u16 wrb_cnt; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1373 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1374 | skb = be_xmit_workarounds(adapter, skb, &wrb_params); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1375 | if (unlikely(!skb)) |
| 1376 | goto drop; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1377 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1378 | be_get_wrb_params_from_skb(adapter, skb, &wrb_params); |
| 1379 | |
| 1380 | wrb_cnt = be_xmit_enqueue(adapter, txo, skb, &wrb_params); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1381 | if (unlikely(!wrb_cnt)) { |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1382 | dev_kfree_skb_any(skb); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1383 | goto drop; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1384 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1385 | |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 1386 | /* if os2bmc is enabled and if the pkt is destined to bmc, |
| 1387 | * enqueue the pkt a 2nd time with mgmt bit set. |
| 1388 | */ |
| 1389 | if (be_send_pkt_to_bmc(adapter, &skb)) { |
| 1390 | BE_WRB_F_SET(wrb_params.features, OS2BMC, 1); |
| 1391 | wrb_cnt = be_xmit_enqueue(adapter, txo, skb, &wrb_params); |
| 1392 | if (unlikely(!wrb_cnt)) |
| 1393 | goto drop; |
| 1394 | else |
| 1395 | skb_get(skb); |
| 1396 | } |
| 1397 | |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 1398 | if (be_is_txq_full(txo)) { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1399 | netif_stop_subqueue(netdev, q_idx); |
| 1400 | tx_stats(txo)->tx_stops++; |
| 1401 | } |
| 1402 | |
| 1403 | if (flush || __netif_subqueue_stopped(netdev, q_idx)) |
| 1404 | be_xmit_flush(adapter, txo); |
| 1405 | |
| 1406 | return NETDEV_TX_OK; |
| 1407 | drop: |
| 1408 | tx_stats(txo)->tx_drv_drops++; |
| 1409 | /* Flush the already enqueued tx requests */ |
| 1410 | if (flush && txo->pend_wrb_cnt) |
| 1411 | be_xmit_flush(adapter, txo); |
| 1412 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1413 | return NETDEV_TX_OK; |
| 1414 | } |
| 1415 | |
| 1416 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 1417 | { |
| 1418 | struct be_adapter *adapter = netdev_priv(netdev); |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1419 | struct device *dev = &adapter->pdev->dev; |
| 1420 | |
| 1421 | if (new_mtu < BE_MIN_MTU || new_mtu > BE_MAX_MTU) { |
| 1422 | dev_info(dev, "MTU must be between %d and %d bytes\n", |
| 1423 | BE_MIN_MTU, BE_MAX_MTU); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1424 | return -EINVAL; |
| 1425 | } |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1426 | |
| 1427 | dev_info(dev, "MTU changed from %d to %d bytes\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1428 | netdev->mtu, new_mtu); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1429 | netdev->mtu = new_mtu; |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1433 | static inline bool be_in_all_promisc(struct be_adapter *adapter) |
| 1434 | { |
| 1435 | return (adapter->if_flags & BE_IF_FLAGS_ALL_PROMISCUOUS) == |
| 1436 | BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1437 | } |
| 1438 | |
| 1439 | static int be_set_vlan_promisc(struct be_adapter *adapter) |
| 1440 | { |
| 1441 | struct device *dev = &adapter->pdev->dev; |
| 1442 | int status; |
| 1443 | |
| 1444 | if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) |
| 1445 | return 0; |
| 1446 | |
| 1447 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, ON); |
| 1448 | if (!status) { |
| 1449 | dev_info(dev, "Enabled VLAN promiscuous mode\n"); |
| 1450 | adapter->if_flags |= BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1451 | } else { |
| 1452 | dev_err(dev, "Failed to enable VLAN promiscuous mode\n"); |
| 1453 | } |
| 1454 | return status; |
| 1455 | } |
| 1456 | |
| 1457 | static int be_clear_vlan_promisc(struct be_adapter *adapter) |
| 1458 | { |
| 1459 | struct device *dev = &adapter->pdev->dev; |
| 1460 | int status; |
| 1461 | |
| 1462 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, OFF); |
| 1463 | if (!status) { |
| 1464 | dev_info(dev, "Disabling VLAN promiscuous mode\n"); |
| 1465 | adapter->if_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1466 | } |
| 1467 | return status; |
| 1468 | } |
| 1469 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1470 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1471 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 1472 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1473 | */ |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1474 | static int be_vid_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1475 | { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 1476 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1477 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1478 | u16 num = 0, i = 0; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1479 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1480 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1481 | /* No need to change the VLAN state if the I/F is in promiscuous */ |
| 1482 | if (adapter->netdev->flags & IFF_PROMISC) |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1483 | return 0; |
| 1484 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1485 | if (adapter->vlans_added > be_max_vlans(adapter)) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1486 | return be_set_vlan_promisc(adapter); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1487 | |
Somnath Kotur | 841f60f | 2016-07-27 05:26:15 -0400 | [diff] [blame] | 1488 | if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) { |
| 1489 | status = be_clear_vlan_promisc(adapter); |
| 1490 | if (status) |
| 1491 | return status; |
| 1492 | } |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1493 | /* Construct VLAN Table to give to HW */ |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1494 | for_each_set_bit(i, adapter->vids, VLAN_N_VID) |
| 1495 | vids[num++] = cpu_to_le16(i); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1496 | |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1497 | status = be_cmd_vlan_config(adapter, adapter->if_handle, vids, num, 0); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1498 | if (status) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1499 | dev_err(dev, "Setting HW VLAN filtering failed\n"); |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1500 | /* Set to VLAN promisc mode as setting VLAN filter failed */ |
Kalesh AP | 77be8c1 | 2015-05-06 05:30:35 -0400 | [diff] [blame] | 1501 | if (addl_status(status) == MCC_ADDL_STATUS_INSUFFICIENT_VLANS || |
| 1502 | addl_status(status) == |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 1503 | MCC_ADDL_STATUS_INSUFFICIENT_RESOURCES) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1504 | return be_set_vlan_promisc(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1505 | } |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1506 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1509 | 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] | 1510 | { |
| 1511 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1512 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1513 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1514 | mutex_lock(&adapter->rx_filter_lock); |
| 1515 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1516 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1517 | if (lancer_chip(adapter) && vid == 0) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1518 | goto done; |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1519 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1520 | if (test_bit(vid, adapter->vids)) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1521 | goto done; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1522 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1523 | set_bit(vid, adapter->vids); |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1524 | adapter->vlans_added++; |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1525 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1526 | status = be_vid_config(adapter); |
| 1527 | done: |
| 1528 | mutex_unlock(&adapter->rx_filter_lock); |
| 1529 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1532 | 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] | 1533 | { |
| 1534 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1535 | int status = 0; |
| 1536 | |
| 1537 | mutex_lock(&adapter->rx_filter_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1538 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1539 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1540 | if (lancer_chip(adapter) && vid == 0) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1541 | goto done; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1542 | |
Sriharsha Basavapatna | 41dcdfb | 2016-02-03 09:49:18 +0530 | [diff] [blame] | 1543 | if (!test_bit(vid, adapter->vids)) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1544 | goto done; |
Sriharsha Basavapatna | 41dcdfb | 2016-02-03 09:49:18 +0530 | [diff] [blame] | 1545 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1546 | clear_bit(vid, adapter->vids); |
Kalesh AP | 9d4dfe4 | 2014-06-30 13:01:33 +0530 | [diff] [blame] | 1547 | adapter->vlans_added--; |
| 1548 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1549 | status = be_vid_config(adapter); |
| 1550 | done: |
| 1551 | mutex_unlock(&adapter->rx_filter_lock); |
| 1552 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1555 | static void be_set_all_promisc(struct be_adapter *adapter) |
| 1556 | { |
| 1557 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_ALL_PROMISCUOUS, ON); |
| 1558 | adapter->if_flags |= BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1559 | } |
| 1560 | |
| 1561 | static void be_set_mc_promisc(struct be_adapter *adapter) |
| 1562 | { |
| 1563 | int status; |
| 1564 | |
| 1565 | if (adapter->if_flags & BE_IF_FLAGS_MCAST_PROMISCUOUS) |
| 1566 | return; |
| 1567 | |
| 1568 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MCAST_PROMISCUOUS, ON); |
| 1569 | if (!status) |
| 1570 | adapter->if_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1571 | } |
| 1572 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1573 | static void be_set_uc_promisc(struct be_adapter *adapter) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1574 | { |
| 1575 | int status; |
| 1576 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1577 | if (adapter->if_flags & BE_IF_FLAGS_PROMISCUOUS) |
| 1578 | return; |
| 1579 | |
| 1580 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_PROMISCUOUS, ON); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1581 | if (!status) |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1582 | adapter->if_flags |= BE_IF_FLAGS_PROMISCUOUS; |
| 1583 | } |
| 1584 | |
| 1585 | static void be_clear_uc_promisc(struct be_adapter *adapter) |
| 1586 | { |
| 1587 | int status; |
| 1588 | |
| 1589 | if (!(adapter->if_flags & BE_IF_FLAGS_PROMISCUOUS)) |
| 1590 | return; |
| 1591 | |
| 1592 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_PROMISCUOUS, OFF); |
| 1593 | if (!status) |
| 1594 | adapter->if_flags &= ~BE_IF_FLAGS_PROMISCUOUS; |
| 1595 | } |
| 1596 | |
| 1597 | /* The below 2 functions are the callback args for __dev_mc_sync/dev_uc_sync(). |
| 1598 | * We use a single callback function for both sync and unsync. We really don't |
| 1599 | * add/remove addresses through this callback. But, we use it to detect changes |
| 1600 | * to the uc/mc lists. The entire uc/mc list is programmed in be_set_rx_mode(). |
| 1601 | */ |
| 1602 | static int be_uc_list_update(struct net_device *netdev, |
| 1603 | const unsigned char *addr) |
| 1604 | { |
| 1605 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1606 | |
| 1607 | adapter->update_uc_list = true; |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | static int be_mc_list_update(struct net_device *netdev, |
| 1612 | const unsigned char *addr) |
| 1613 | { |
| 1614 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1615 | |
| 1616 | adapter->update_mc_list = true; |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static void be_set_mc_list(struct be_adapter *adapter) |
| 1621 | { |
| 1622 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1623 | struct netdev_hw_addr *ha; |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1624 | bool mc_promisc = false; |
| 1625 | int status; |
| 1626 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1627 | netif_addr_lock_bh(netdev); |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1628 | __dev_mc_sync(netdev, be_mc_list_update, be_mc_list_update); |
| 1629 | |
| 1630 | if (netdev->flags & IFF_PROMISC) { |
| 1631 | adapter->update_mc_list = false; |
| 1632 | } else if (netdev->flags & IFF_ALLMULTI || |
| 1633 | netdev_mc_count(netdev) > be_max_mc(adapter)) { |
| 1634 | /* Enable multicast promisc if num configured exceeds |
| 1635 | * what we support |
| 1636 | */ |
| 1637 | mc_promisc = true; |
| 1638 | adapter->update_mc_list = false; |
| 1639 | } else if (adapter->if_flags & BE_IF_FLAGS_MCAST_PROMISCUOUS) { |
| 1640 | /* Update mc-list unconditionally if the iface was previously |
| 1641 | * in mc-promisc mode and now is out of that mode. |
| 1642 | */ |
| 1643 | adapter->update_mc_list = true; |
| 1644 | } |
| 1645 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1646 | if (adapter->update_mc_list) { |
| 1647 | int i = 0; |
| 1648 | |
| 1649 | /* cache the mc-list in adapter */ |
| 1650 | netdev_for_each_mc_addr(ha, netdev) { |
| 1651 | ether_addr_copy(adapter->mc_list[i].mac, ha->addr); |
| 1652 | i++; |
| 1653 | } |
| 1654 | adapter->mc_count = netdev_mc_count(netdev); |
| 1655 | } |
| 1656 | netif_addr_unlock_bh(netdev); |
| 1657 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1658 | if (mc_promisc) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1659 | be_set_mc_promisc(adapter); |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1660 | } else if (adapter->update_mc_list) { |
| 1661 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MULTICAST, ON); |
| 1662 | if (!status) |
| 1663 | adapter->if_flags &= ~BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1664 | else |
| 1665 | be_set_mc_promisc(adapter); |
| 1666 | |
| 1667 | adapter->update_mc_list = false; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | static void be_clear_mc_list(struct be_adapter *adapter) |
| 1672 | { |
| 1673 | struct net_device *netdev = adapter->netdev; |
| 1674 | |
| 1675 | __dev_mc_unsync(netdev, NULL); |
| 1676 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_MULTICAST, OFF); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1677 | adapter->mc_count = 0; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1678 | } |
| 1679 | |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 1680 | static int be_uc_mac_add(struct be_adapter *adapter, int uc_idx) |
| 1681 | { |
| 1682 | if (ether_addr_equal((u8 *)&adapter->uc_list[uc_idx * ETH_ALEN], |
Suresh Reddy | c27ebf5 | 2016-09-07 19:57:53 +0530 | [diff] [blame] | 1683 | adapter->dev_mac)) { |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 1684 | adapter->pmac_id[uc_idx + 1] = adapter->pmac_id[0]; |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
| 1688 | return be_cmd_pmac_add(adapter, |
| 1689 | (u8 *)&adapter->uc_list[uc_idx * ETH_ALEN], |
| 1690 | adapter->if_handle, |
| 1691 | &adapter->pmac_id[uc_idx + 1], 0); |
| 1692 | } |
| 1693 | |
| 1694 | static void be_uc_mac_del(struct be_adapter *adapter, int pmac_id) |
| 1695 | { |
| 1696 | if (pmac_id == adapter->pmac_id[0]) |
| 1697 | return; |
| 1698 | |
| 1699 | be_cmd_pmac_del(adapter, adapter->if_handle, pmac_id, 0); |
| 1700 | } |
| 1701 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1702 | static void be_set_uc_list(struct be_adapter *adapter) |
| 1703 | { |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1704 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1705 | struct netdev_hw_addr *ha; |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1706 | bool uc_promisc = false; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1707 | int curr_uc_macs = 0, i; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1708 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1709 | netif_addr_lock_bh(netdev); |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1710 | __dev_uc_sync(netdev, be_uc_list_update, be_uc_list_update); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1711 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1712 | if (netdev->flags & IFF_PROMISC) { |
| 1713 | adapter->update_uc_list = false; |
| 1714 | } else if (netdev_uc_count(netdev) > (be_max_uc(adapter) - 1)) { |
| 1715 | uc_promisc = true; |
| 1716 | adapter->update_uc_list = false; |
| 1717 | } else if (adapter->if_flags & BE_IF_FLAGS_PROMISCUOUS) { |
| 1718 | /* Update uc-list unconditionally if the iface was previously |
| 1719 | * in uc-promisc mode and now is out of that mode. |
| 1720 | */ |
| 1721 | adapter->update_uc_list = true; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1722 | } |
| 1723 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1724 | if (adapter->update_uc_list) { |
| 1725 | i = 1; /* First slot is claimed by the Primary MAC */ |
| 1726 | |
| 1727 | /* cache the uc-list in adapter array */ |
| 1728 | netdev_for_each_uc_addr(ha, netdev) { |
| 1729 | ether_addr_copy(adapter->uc_list[i].mac, ha->addr); |
| 1730 | i++; |
| 1731 | } |
| 1732 | curr_uc_macs = netdev_uc_count(netdev); |
| 1733 | } |
| 1734 | netif_addr_unlock_bh(netdev); |
| 1735 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1736 | if (uc_promisc) { |
| 1737 | be_set_uc_promisc(adapter); |
| 1738 | } else if (adapter->update_uc_list) { |
| 1739 | be_clear_uc_promisc(adapter); |
| 1740 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1741 | for (i = 0; i < adapter->uc_macs; i++) |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 1742 | be_uc_mac_del(adapter, adapter->pmac_id[i + 1]); |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1743 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1744 | for (i = 0; i < curr_uc_macs; i++) |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 1745 | be_uc_mac_add(adapter, i); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1746 | adapter->uc_macs = curr_uc_macs; |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1747 | adapter->update_uc_list = false; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | static void be_clear_uc_list(struct be_adapter *adapter) |
| 1752 | { |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1753 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1754 | int i; |
| 1755 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1756 | __dev_uc_unsync(netdev, NULL); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1757 | for (i = 0; i < adapter->uc_macs; i++) |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 1758 | be_uc_mac_del(adapter, adapter->pmac_id[i + 1]); |
| 1759 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1760 | adapter->uc_macs = 0; |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1761 | } |
| 1762 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1763 | static void __be_set_rx_mode(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1764 | { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1765 | struct net_device *netdev = adapter->netdev; |
| 1766 | |
| 1767 | mutex_lock(&adapter->rx_filter_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1768 | |
| 1769 | if (netdev->flags & IFF_PROMISC) { |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1770 | if (!be_in_all_promisc(adapter)) |
| 1771 | be_set_all_promisc(adapter); |
| 1772 | } else if (be_in_all_promisc(adapter)) { |
| 1773 | /* We need to re-program the vlan-list or clear |
| 1774 | * vlan-promisc mode (if needed) when the interface |
| 1775 | * comes out of promisc mode. |
| 1776 | */ |
| 1777 | be_vid_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1778 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1779 | |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 1780 | be_set_uc_list(adapter); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1781 | be_set_mc_list(adapter); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1782 | |
| 1783 | mutex_unlock(&adapter->rx_filter_lock); |
| 1784 | } |
| 1785 | |
| 1786 | static void be_work_set_rx_mode(struct work_struct *work) |
| 1787 | { |
| 1788 | struct be_cmd_work *cmd_work = |
| 1789 | container_of(work, struct be_cmd_work, work); |
| 1790 | |
| 1791 | __be_set_rx_mode(cmd_work->adapter); |
| 1792 | kfree(cmd_work); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1795 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 1796 | { |
| 1797 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1798 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1799 | int status; |
| 1800 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1801 | if (!sriov_enabled(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1802 | return -EPERM; |
| 1803 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1804 | if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1805 | return -EINVAL; |
| 1806 | |
Vasundhara Volam | 3c31aaf | 2014-08-01 17:47:31 +0530 | [diff] [blame] | 1807 | /* Proceed further only if user provided MAC is different |
| 1808 | * from active MAC |
| 1809 | */ |
| 1810 | if (ether_addr_equal(mac, vf_cfg->mac_addr)) |
| 1811 | return 0; |
| 1812 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1813 | if (BEx_chip(adapter)) { |
| 1814 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, vf_cfg->pmac_id, |
| 1815 | vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1816 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1817 | status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle, |
| 1818 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1819 | } else { |
| 1820 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 1821 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1824 | if (status) { |
| 1825 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed: %#x", |
| 1826 | mac, vf, status); |
| 1827 | return be_cmd_status(status); |
| 1828 | } |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1829 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1830 | ether_addr_copy(vf_cfg->mac_addr, mac); |
| 1831 | |
| 1832 | return 0; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1835 | static int be_get_vf_config(struct net_device *netdev, int vf, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1836 | struct ifla_vf_info *vi) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1837 | { |
| 1838 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1839 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1840 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1841 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1842 | return -EPERM; |
| 1843 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1844 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1845 | return -EINVAL; |
| 1846 | |
| 1847 | vi->vf = vf; |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1848 | vi->max_tx_rate = vf_cfg->tx_rate; |
| 1849 | vi->min_tx_rate = 0; |
Ajit Khaparde | a60b3a1 | 2013-09-27 15:18:56 -0500 | [diff] [blame] | 1850 | vi->vlan = vf_cfg->vlan_tag & VLAN_VID_MASK; |
| 1851 | vi->qos = vf_cfg->vlan_tag >> VLAN_PRIO_SHIFT; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1852 | memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1853 | vi->linkstate = adapter->vf_cfg[vf].plink_tracking; |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1854 | vi->spoofchk = adapter->vf_cfg[vf].spoofchk; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1859 | static int be_set_vf_tvt(struct be_adapter *adapter, int vf, u16 vlan) |
| 1860 | { |
| 1861 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 1862 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
| 1863 | int vf_if_id = vf_cfg->if_handle; |
| 1864 | int status; |
| 1865 | |
| 1866 | /* Enable Transparent VLAN Tagging */ |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1867 | status = be_cmd_set_hsw_config(adapter, vlan, vf + 1, vf_if_id, 0, 0); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1868 | if (status) |
| 1869 | return status; |
| 1870 | |
| 1871 | /* Clear pre-programmed VLAN filters on VF if any, if TVT is enabled */ |
| 1872 | vids[0] = 0; |
| 1873 | status = be_cmd_vlan_config(adapter, vf_if_id, vids, 1, vf + 1); |
| 1874 | if (!status) |
| 1875 | dev_info(&adapter->pdev->dev, |
| 1876 | "Cleared guest VLANs on VF%d", vf); |
| 1877 | |
| 1878 | /* After TVT is enabled, disallow VFs to program VLAN filters */ |
| 1879 | if (vf_cfg->privileges & BE_PRIV_FILTMGMT) { |
| 1880 | status = be_cmd_set_fn_privileges(adapter, vf_cfg->privileges & |
| 1881 | ~BE_PRIV_FILTMGMT, vf + 1); |
| 1882 | if (!status) |
| 1883 | vf_cfg->privileges &= ~BE_PRIV_FILTMGMT; |
| 1884 | } |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
| 1888 | static int be_clear_vf_tvt(struct be_adapter *adapter, int vf) |
| 1889 | { |
| 1890 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 1891 | struct device *dev = &adapter->pdev->dev; |
| 1892 | int status; |
| 1893 | |
| 1894 | /* Reset Transparent VLAN Tagging. */ |
| 1895 | status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID, vf + 1, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1896 | vf_cfg->if_handle, 0, 0); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1897 | if (status) |
| 1898 | return status; |
| 1899 | |
| 1900 | /* Allow VFs to program VLAN filtering */ |
| 1901 | if (!(vf_cfg->privileges & BE_PRIV_FILTMGMT)) { |
| 1902 | status = be_cmd_set_fn_privileges(adapter, vf_cfg->privileges | |
| 1903 | BE_PRIV_FILTMGMT, vf + 1); |
| 1904 | if (!status) { |
| 1905 | vf_cfg->privileges |= BE_PRIV_FILTMGMT; |
| 1906 | dev_info(dev, "VF%d: FILTMGMT priv enabled", vf); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | dev_info(dev, |
| 1911 | "Disable/re-enable i/f in VM to clear Transparent VLAN tag"); |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 1915 | static int be_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos, |
| 1916 | __be16 vlan_proto) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1917 | { |
| 1918 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1919 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1920 | int status; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1921 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1922 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1923 | return -EPERM; |
| 1924 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1925 | if (vf >= adapter->num_vfs || vlan > 4095 || qos > 7) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1926 | return -EINVAL; |
| 1927 | |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 1928 | if (vlan_proto != htons(ETH_P_8021Q)) |
| 1929 | return -EPROTONOSUPPORT; |
| 1930 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1931 | if (vlan || qos) { |
| 1932 | vlan |= qos << VLAN_PRIO_SHIFT; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1933 | status = be_set_vf_tvt(adapter, vf, vlan); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1934 | } else { |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1935 | status = be_clear_vf_tvt(adapter, vf); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1938 | if (status) { |
| 1939 | dev_err(&adapter->pdev->dev, |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1940 | "VLAN %d config on VF %d failed : %#x\n", vlan, vf, |
| 1941 | status); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1942 | return be_cmd_status(status); |
| 1943 | } |
| 1944 | |
| 1945 | vf_cfg->vlan_tag = vlan; |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1946 | return 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1949 | static int be_set_vf_tx_rate(struct net_device *netdev, int vf, |
| 1950 | int min_tx_rate, int max_tx_rate) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1951 | { |
| 1952 | struct be_adapter *adapter = netdev_priv(netdev); |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1953 | struct device *dev = &adapter->pdev->dev; |
| 1954 | int percent_rate, status = 0; |
| 1955 | u16 link_speed = 0; |
| 1956 | u8 link_status; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1957 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1958 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1959 | return -EPERM; |
| 1960 | |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1961 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1962 | return -EINVAL; |
| 1963 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1964 | if (min_tx_rate) |
| 1965 | return -EINVAL; |
| 1966 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1967 | if (!max_tx_rate) |
| 1968 | goto config_qos; |
| 1969 | |
| 1970 | status = be_cmd_link_status_query(adapter, &link_speed, |
| 1971 | &link_status, 0); |
| 1972 | if (status) |
| 1973 | goto err; |
| 1974 | |
| 1975 | if (!link_status) { |
| 1976 | 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] | 1977 | status = -ENETDOWN; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1978 | goto err; |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1979 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1980 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1981 | if (max_tx_rate < 100 || max_tx_rate > link_speed) { |
| 1982 | dev_err(dev, "TX-rate must be between 100 and %d Mbps\n", |
| 1983 | link_speed); |
| 1984 | status = -EINVAL; |
| 1985 | goto err; |
| 1986 | } |
| 1987 | |
| 1988 | /* On Skyhawk the QOS setting must be done only as a % value */ |
| 1989 | percent_rate = link_speed / 100; |
| 1990 | if (skyhawk_chip(adapter) && (max_tx_rate % percent_rate)) { |
| 1991 | dev_err(dev, "TX-rate must be a multiple of %d Mbps\n", |
| 1992 | percent_rate); |
| 1993 | status = -EINVAL; |
| 1994 | goto err; |
| 1995 | } |
| 1996 | |
| 1997 | config_qos: |
| 1998 | 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] | 1999 | if (status) |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 2000 | goto err; |
| 2001 | |
| 2002 | adapter->vf_cfg[vf].tx_rate = max_tx_rate; |
| 2003 | return 0; |
| 2004 | |
| 2005 | err: |
| 2006 | dev_err(dev, "TX-rate setting of %dMbps on VF%d failed\n", |
| 2007 | max_tx_rate, vf); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 2008 | return be_cmd_status(status); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2009 | } |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 2010 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 2011 | static int be_set_vf_link_state(struct net_device *netdev, int vf, |
| 2012 | int link_state) |
| 2013 | { |
| 2014 | struct be_adapter *adapter = netdev_priv(netdev); |
| 2015 | int status; |
| 2016 | |
| 2017 | if (!sriov_enabled(adapter)) |
| 2018 | return -EPERM; |
| 2019 | |
| 2020 | if (vf >= adapter->num_vfs) |
| 2021 | return -EINVAL; |
| 2022 | |
| 2023 | status = be_cmd_set_logical_link_config(adapter, link_state, vf+1); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 2024 | if (status) { |
| 2025 | dev_err(&adapter->pdev->dev, |
| 2026 | "Link state change on VF %d failed: %#x\n", vf, status); |
| 2027 | return be_cmd_status(status); |
| 2028 | } |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 2029 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 2030 | adapter->vf_cfg[vf].plink_tracking = link_state; |
| 2031 | |
| 2032 | return 0; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 2033 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2034 | |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 2035 | static int be_set_vf_spoofchk(struct net_device *netdev, int vf, bool enable) |
| 2036 | { |
| 2037 | struct be_adapter *adapter = netdev_priv(netdev); |
| 2038 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 2039 | u8 spoofchk; |
| 2040 | int status; |
| 2041 | |
| 2042 | if (!sriov_enabled(adapter)) |
| 2043 | return -EPERM; |
| 2044 | |
| 2045 | if (vf >= adapter->num_vfs) |
| 2046 | return -EINVAL; |
| 2047 | |
| 2048 | if (BEx_chip(adapter)) |
| 2049 | return -EOPNOTSUPP; |
| 2050 | |
| 2051 | if (enable == vf_cfg->spoofchk) |
| 2052 | return 0; |
| 2053 | |
| 2054 | spoofchk = enable ? ENABLE_MAC_SPOOFCHK : DISABLE_MAC_SPOOFCHK; |
| 2055 | |
| 2056 | status = be_cmd_set_hsw_config(adapter, 0, vf + 1, vf_cfg->if_handle, |
| 2057 | 0, spoofchk); |
| 2058 | if (status) { |
| 2059 | dev_err(&adapter->pdev->dev, |
| 2060 | "Spoofchk change on VF %d failed: %#x\n", vf, status); |
| 2061 | return be_cmd_status(status); |
| 2062 | } |
| 2063 | |
| 2064 | vf_cfg->spoofchk = enable; |
| 2065 | return 0; |
| 2066 | } |
| 2067 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2068 | static void be_aic_update(struct be_aic_obj *aic, u64 rx_pkts, u64 tx_pkts, |
| 2069 | ulong now) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2070 | { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2071 | aic->rx_pkts_prev = rx_pkts; |
| 2072 | aic->tx_reqs_prev = tx_pkts; |
| 2073 | aic->jiffies = now; |
| 2074 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2075 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2076 | static int be_get_new_eqd(struct be_eq_obj *eqo) |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2077 | { |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2078 | struct be_adapter *adapter = eqo->adapter; |
| 2079 | int eqd, start; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2080 | struct be_aic_obj *aic; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2081 | struct be_rx_obj *rxo; |
| 2082 | struct be_tx_obj *txo; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2083 | u64 rx_pkts = 0, tx_pkts = 0; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2084 | ulong now; |
| 2085 | u32 pps, delta; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2086 | int i; |
| 2087 | |
| 2088 | aic = &adapter->aic_obj[eqo->idx]; |
| 2089 | if (!aic->enable) { |
| 2090 | if (aic->jiffies) |
| 2091 | aic->jiffies = 0; |
| 2092 | eqd = aic->et_eqd; |
| 2093 | return eqd; |
| 2094 | } |
| 2095 | |
| 2096 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2097 | do { |
| 2098 | start = u64_stats_fetch_begin_irq(&rxo->stats.sync); |
| 2099 | rx_pkts += rxo->stats.rx_pkts; |
| 2100 | } while (u64_stats_fetch_retry_irq(&rxo->stats.sync, start)); |
| 2101 | } |
| 2102 | |
| 2103 | for_all_tx_queues_on_eq(adapter, eqo, txo, i) { |
| 2104 | do { |
| 2105 | start = u64_stats_fetch_begin_irq(&txo->stats.sync); |
| 2106 | tx_pkts += txo->stats.tx_reqs; |
| 2107 | } while (u64_stats_fetch_retry_irq(&txo->stats.sync, start)); |
| 2108 | } |
| 2109 | |
| 2110 | /* Skip, if wrapped around or first calculation */ |
| 2111 | now = jiffies; |
| 2112 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
| 2113 | rx_pkts < aic->rx_pkts_prev || |
| 2114 | tx_pkts < aic->tx_reqs_prev) { |
| 2115 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 2116 | return aic->prev_eqd; |
| 2117 | } |
| 2118 | |
| 2119 | delta = jiffies_to_msecs(now - aic->jiffies); |
| 2120 | if (delta == 0) |
| 2121 | return aic->prev_eqd; |
| 2122 | |
| 2123 | pps = (((u32)(rx_pkts - aic->rx_pkts_prev) * 1000) / delta) + |
| 2124 | (((u32)(tx_pkts - aic->tx_reqs_prev) * 1000) / delta); |
| 2125 | eqd = (pps / 15000) << 2; |
| 2126 | |
| 2127 | if (eqd < 8) |
| 2128 | eqd = 0; |
| 2129 | eqd = min_t(u32, eqd, aic->max_eqd); |
| 2130 | eqd = max_t(u32, eqd, aic->min_eqd); |
| 2131 | |
| 2132 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 2133 | |
| 2134 | return eqd; |
| 2135 | } |
| 2136 | |
| 2137 | /* For Skyhawk-R only */ |
| 2138 | static u32 be_get_eq_delay_mult_enc(struct be_eq_obj *eqo) |
| 2139 | { |
| 2140 | struct be_adapter *adapter = eqo->adapter; |
| 2141 | struct be_aic_obj *aic = &adapter->aic_obj[eqo->idx]; |
| 2142 | ulong now = jiffies; |
| 2143 | int eqd; |
| 2144 | u32 mult_enc; |
| 2145 | |
| 2146 | if (!aic->enable) |
| 2147 | return 0; |
| 2148 | |
Padmanabh Ratnakar | 3c0d49a | 2016-02-03 09:49:23 +0530 | [diff] [blame] | 2149 | if (jiffies_to_msecs(now - aic->jiffies) < 1) |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2150 | eqd = aic->prev_eqd; |
| 2151 | else |
| 2152 | eqd = be_get_new_eqd(eqo); |
| 2153 | |
| 2154 | if (eqd > 100) |
| 2155 | mult_enc = R2I_DLY_ENC_1; |
| 2156 | else if (eqd > 60) |
| 2157 | mult_enc = R2I_DLY_ENC_2; |
| 2158 | else if (eqd > 20) |
| 2159 | mult_enc = R2I_DLY_ENC_3; |
| 2160 | else |
| 2161 | mult_enc = R2I_DLY_ENC_0; |
| 2162 | |
| 2163 | aic->prev_eqd = eqd; |
| 2164 | |
| 2165 | return mult_enc; |
| 2166 | } |
| 2167 | |
| 2168 | void be_eqd_update(struct be_adapter *adapter, bool force_update) |
| 2169 | { |
| 2170 | struct be_set_eqd set_eqd[MAX_EVT_QS]; |
| 2171 | struct be_aic_obj *aic; |
| 2172 | struct be_eq_obj *eqo; |
| 2173 | int i, num = 0, eqd; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2174 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2175 | for_all_evt_queues(adapter, eqo, i) { |
| 2176 | aic = &adapter->aic_obj[eqo->idx]; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2177 | eqd = be_get_new_eqd(eqo); |
| 2178 | if (force_update || eqd != aic->prev_eqd) { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2179 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 2180 | set_eqd[num].eq_id = eqo->q.id; |
| 2181 | aic->prev_eqd = eqd; |
| 2182 | num++; |
| 2183 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2184 | } |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2185 | |
| 2186 | if (num) |
| 2187 | be_cmd_modify_eqd(adapter, set_eqd, num); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2190 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2191 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 2192 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2193 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 2194 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 2195 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2196 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2197 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2198 | stats->rx_pkts++; |
Sriharsha Basavapatna | 8670f2a | 2015-07-29 19:35:32 +0530 | [diff] [blame] | 2199 | if (rxcp->tunneled) |
| 2200 | stats->rx_vxlan_offload_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2201 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2202 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2203 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2204 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 2205 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2208 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 2209 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 2210 | /* L4 checksum is not reliable for non TCP/UDP packets. |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2211 | * Also ignore ipcksm for ipv6 pkts |
| 2212 | */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2213 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2214 | (rxcp->ip_csum || rxcp->ipv6) && !rxcp->err; |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2217 | 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] | 2218 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2219 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2220 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2221 | struct be_queue_info *rxq = &rxo->q; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 2222 | u32 frag_idx = rxq->tail; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2223 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2224 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2225 | BUG_ON(!rx_page_info->page); |
| 2226 | |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2227 | if (rx_page_info->last_frag) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2228 | dma_unmap_page(&adapter->pdev->dev, |
| 2229 | dma_unmap_addr(rx_page_info, bus), |
| 2230 | adapter->big_page_size, DMA_FROM_DEVICE); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2231 | rx_page_info->last_frag = false; |
| 2232 | } else { |
| 2233 | dma_sync_single_for_cpu(&adapter->pdev->dev, |
| 2234 | dma_unmap_addr(rx_page_info, bus), |
| 2235 | rx_frag_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 2236 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2237 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2238 | queue_tail_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2239 | atomic_dec(&rxq->used); |
| 2240 | return rx_page_info; |
| 2241 | } |
| 2242 | |
| 2243 | /* Throwaway the data in the Rx completion */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2244 | static void be_rx_compl_discard(struct be_rx_obj *rxo, |
| 2245 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2246 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2247 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2248 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2249 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 2250 | for (i = 0; i < num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2251 | page_info = get_rx_page_info(rxo); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 2252 | put_page(page_info->page); |
| 2253 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | /* |
| 2258 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 2259 | * indicated by rxcp. |
| 2260 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2261 | static void skb_fill_rx_data(struct be_rx_obj *rxo, struct sk_buff *skb, |
| 2262 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2263 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2264 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2265 | u16 i, j; |
| 2266 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2267 | u8 *start; |
| 2268 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2269 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2270 | start = page_address(page_info->page) + page_info->page_offset; |
| 2271 | prefetch(start); |
| 2272 | |
| 2273 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2274 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2275 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2276 | skb->len = curr_frag_len; |
| 2277 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 2278 | memcpy(skb->data, start, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2279 | /* Complete packet has now been moved to data */ |
| 2280 | put_page(page_info->page); |
| 2281 | skb->data_len = 0; |
| 2282 | skb->tail += curr_frag_len; |
| 2283 | } else { |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 2284 | hdr_len = ETH_HLEN; |
| 2285 | memcpy(skb->data, start, hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2286 | skb_shinfo(skb)->nr_frags = 1; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 2287 | skb_frag_set_page(skb, 0, page_info->page); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2288 | skb_shinfo(skb)->frags[0].page_offset = |
| 2289 | page_info->page_offset + hdr_len; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2290 | skb_frag_size_set(&skb_shinfo(skb)->frags[0], |
| 2291 | curr_frag_len - hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2292 | skb->data_len = curr_frag_len - hdr_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 2293 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2294 | skb->tail += hdr_len; |
| 2295 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 2296 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2297 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2298 | if (rxcp->pkt_size <= rx_frag_size) { |
| 2299 | BUG_ON(rxcp->num_rcvd != 1); |
| 2300 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2304 | remaining = rxcp->pkt_size - curr_frag_len; |
| 2305 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2306 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2307 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2308 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2309 | /* Coalesce all frags from the same physical page in one slot */ |
| 2310 | if (page_info->page_offset == 0) { |
| 2311 | /* Fresh page */ |
| 2312 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 2313 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2314 | skb_shinfo(skb)->frags[j].page_offset = |
| 2315 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2316 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2317 | skb_shinfo(skb)->nr_frags++; |
| 2318 | } else { |
| 2319 | put_page(page_info->page); |
| 2320 | } |
| 2321 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2322 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2323 | skb->len += curr_frag_len; |
| 2324 | skb->data_len += curr_frag_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 2325 | skb->truesize += rx_frag_size; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2326 | remaining -= curr_frag_len; |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 2327 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2328 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2329 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2332 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2333 | 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] | 2334 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2335 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2336 | struct be_adapter *adapter = rxo->adapter; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2337 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2338 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 2339 | |
Eric Dumazet | bb349bb | 2012-01-25 03:56:30 +0000 | [diff] [blame] | 2340 | skb = netdev_alloc_skb_ip_align(netdev, BE_RX_SKB_ALLOC_SIZE); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 2341 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2342 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2343 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2344 | return; |
| 2345 | } |
| 2346 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2347 | skb_fill_rx_data(rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2348 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2349 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 2350 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 2351 | else |
| 2352 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2353 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2354 | skb->protocol = eth_type_trans(skb, netdev); |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 2355 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2356 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 2357 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2358 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 2359 | skb->csum_level = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2360 | skb_mark_napi_id(skb, napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2361 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 2362 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2363 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 2364 | |
| 2365 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2368 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 2369 | static void be_rx_compl_process_gro(struct be_rx_obj *rxo, |
| 2370 | struct napi_struct *napi, |
| 2371 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2372 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2373 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2374 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2375 | struct sk_buff *skb = NULL; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2376 | u16 remaining, curr_frag_len; |
| 2377 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 2378 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2379 | skb = napi_get_frags(napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2380 | if (!skb) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2381 | be_rx_compl_discard(rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2382 | return; |
| 2383 | } |
| 2384 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2385 | remaining = rxcp->pkt_size; |
| 2386 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2387 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2388 | |
| 2389 | curr_frag_len = min(remaining, rx_frag_size); |
| 2390 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2391 | /* Coalesce all frags from the same physical page in one slot */ |
| 2392 | if (i == 0 || page_info->page_offset == 0) { |
| 2393 | /* First frag or Fresh page */ |
| 2394 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 2395 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2396 | skb_shinfo(skb)->frags[j].page_offset = |
| 2397 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2398 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2399 | } else { |
| 2400 | put_page(page_info->page); |
| 2401 | } |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2402 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 2403 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2404 | remaining -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2405 | memset(page_info, 0, sizeof(*page_info)); |
| 2406 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2407 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2408 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2409 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2410 | skb->len = rxcp->pkt_size; |
| 2411 | skb->data_len = rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2412 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 2413 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 2414 | if (adapter->netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 2415 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2416 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 2417 | skb->csum_level = rxcp->tunneled; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2418 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 2419 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2420 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 2421 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2422 | napi_gro_frags(napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2425 | static void be_parse_rx_compl_v1(struct be_eth_rx_compl *compl, |
| 2426 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2427 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2428 | rxcp->pkt_size = GET_RX_COMPL_V1_BITS(pktsize, compl); |
| 2429 | rxcp->vlanf = GET_RX_COMPL_V1_BITS(vtp, compl); |
| 2430 | rxcp->err = GET_RX_COMPL_V1_BITS(err, compl); |
| 2431 | rxcp->tcpf = GET_RX_COMPL_V1_BITS(tcpf, compl); |
| 2432 | rxcp->udpf = GET_RX_COMPL_V1_BITS(udpf, compl); |
| 2433 | rxcp->ip_csum = GET_RX_COMPL_V1_BITS(ipcksm, compl); |
| 2434 | rxcp->l4_csum = GET_RX_COMPL_V1_BITS(l4_cksm, compl); |
| 2435 | rxcp->ipv6 = GET_RX_COMPL_V1_BITS(ip_version, compl); |
| 2436 | rxcp->num_rcvd = GET_RX_COMPL_V1_BITS(numfrags, compl); |
| 2437 | rxcp->pkt_type = GET_RX_COMPL_V1_BITS(cast_enc, compl); |
| 2438 | rxcp->rss_hash = GET_RX_COMPL_V1_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2439 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2440 | rxcp->qnq = GET_RX_COMPL_V1_BITS(qnq, compl); |
| 2441 | rxcp->vlan_tag = GET_RX_COMPL_V1_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2442 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2443 | rxcp->port = GET_RX_COMPL_V1_BITS(port, compl); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2444 | rxcp->tunneled = |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2445 | GET_RX_COMPL_V1_BITS(tunneled, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2446 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2447 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2448 | static void be_parse_rx_compl_v0(struct be_eth_rx_compl *compl, |
| 2449 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2450 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2451 | rxcp->pkt_size = GET_RX_COMPL_V0_BITS(pktsize, compl); |
| 2452 | rxcp->vlanf = GET_RX_COMPL_V0_BITS(vtp, compl); |
| 2453 | rxcp->err = GET_RX_COMPL_V0_BITS(err, compl); |
| 2454 | rxcp->tcpf = GET_RX_COMPL_V0_BITS(tcpf, compl); |
| 2455 | rxcp->udpf = GET_RX_COMPL_V0_BITS(udpf, compl); |
| 2456 | rxcp->ip_csum = GET_RX_COMPL_V0_BITS(ipcksm, compl); |
| 2457 | rxcp->l4_csum = GET_RX_COMPL_V0_BITS(l4_cksm, compl); |
| 2458 | rxcp->ipv6 = GET_RX_COMPL_V0_BITS(ip_version, compl); |
| 2459 | rxcp->num_rcvd = GET_RX_COMPL_V0_BITS(numfrags, compl); |
| 2460 | rxcp->pkt_type = GET_RX_COMPL_V0_BITS(cast_enc, compl); |
| 2461 | rxcp->rss_hash = GET_RX_COMPL_V0_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2462 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2463 | rxcp->qnq = GET_RX_COMPL_V0_BITS(qnq, compl); |
| 2464 | rxcp->vlan_tag = GET_RX_COMPL_V0_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2465 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2466 | rxcp->port = GET_RX_COMPL_V0_BITS(port, compl); |
| 2467 | rxcp->ip_frag = GET_RX_COMPL_V0_BITS(ip_frag, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 2471 | { |
| 2472 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 2473 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 2474 | struct be_adapter *adapter = rxo->adapter; |
| 2475 | |
| 2476 | /* For checking the valid bit it is Ok to use either definition as the |
| 2477 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 2478 | 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] | 2479 | return NULL; |
| 2480 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 2481 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2482 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 2483 | |
| 2484 | if (adapter->be3_native) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2485 | be_parse_rx_compl_v1(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2486 | else |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2487 | be_parse_rx_compl_v0(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2488 | |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 2489 | if (rxcp->ip_frag) |
| 2490 | rxcp->l4_csum = 0; |
| 2491 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2492 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 2493 | /* In QNQ modes, if qnq bit is not set, then the packet was |
| 2494 | * tagged only with the transparent outer vlan-tag and must |
| 2495 | * not be treated as a vlan packet by host |
| 2496 | */ |
| 2497 | if (be_is_qnq_mode(adapter) && !rxcp->qnq) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2498 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2499 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2500 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 2501 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2502 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 2503 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 2504 | !test_bit(rxcp->vlan_tag, adapter->vids)) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2505 | rxcp->vlanf = 0; |
| 2506 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2507 | |
| 2508 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 2509 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2510 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2511 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2512 | return rxcp; |
| 2513 | } |
| 2514 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2515 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2516 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2517 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2518 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2519 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2520 | gfp |= __GFP_COMP; |
| 2521 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | /* |
| 2525 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 2526 | * receive buffers to BE |
| 2527 | */ |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2528 | 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] | 2529 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2530 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 2531 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2532 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2533 | struct page *pagep = NULL; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2534 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2535 | struct be_eth_rx_d *rxd; |
| 2536 | u64 page_dmaaddr = 0, frag_dmaaddr; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2537 | u32 posted, page_offset = 0, notify = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2538 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2539 | page_info = &rxo->page_info_tbl[rxq->head]; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2540 | for (posted = 0; posted < frags_needed && !page_info->page; posted++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2541 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2542 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2543 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2544 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2545 | break; |
| 2546 | } |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2547 | page_dmaaddr = dma_map_page(dev, pagep, 0, |
| 2548 | adapter->big_page_size, |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2549 | DMA_FROM_DEVICE); |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2550 | if (dma_mapping_error(dev, page_dmaaddr)) { |
| 2551 | put_page(pagep); |
| 2552 | pagep = NULL; |
Vasundhara Volam | d3de154 | 2014-09-02 09:56:50 +0530 | [diff] [blame] | 2553 | adapter->drv_stats.dma_map_errors++; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2554 | break; |
| 2555 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2556 | page_offset = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2557 | } else { |
| 2558 | get_page(pagep); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2559 | page_offset += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2560 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2561 | page_info->page_offset = page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2562 | page_info->page = pagep; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2563 | |
| 2564 | rxd = queue_head_node(rxq); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2565 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2566 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 2567 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2568 | |
| 2569 | /* Any space left in the current big page for another frag? */ |
| 2570 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 2571 | adapter->big_page_size) { |
| 2572 | pagep = NULL; |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2573 | page_info->last_frag = true; |
| 2574 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
| 2575 | } else { |
| 2576 | dma_unmap_addr_set(page_info, bus, frag_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2577 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 2578 | |
| 2579 | prev_page_info = page_info; |
| 2580 | queue_head_inc(rxq); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2581 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2582 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2583 | |
| 2584 | /* Mark the last frag of a page when we break out of the above loop |
| 2585 | * with no more slots available in the RXQ |
| 2586 | */ |
| 2587 | if (pagep) { |
| 2588 | prev_page_info->last_frag = true; |
| 2589 | dma_unmap_addr_set(prev_page_info, bus, page_dmaaddr); |
| 2590 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2591 | |
| 2592 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2593 | atomic_add(posted, &rxq->used); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2594 | if (rxo->rx_post_starved) |
| 2595 | rxo->rx_post_starved = false; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2596 | do { |
Ajit Khaparde | 69304cc | 2015-04-08 16:59:48 -0500 | [diff] [blame] | 2597 | notify = min(MAX_NUM_POST_ERX_DB, posted); |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2598 | be_rxq_notify(adapter, rxq->id, notify); |
| 2599 | posted -= notify; |
| 2600 | } while (posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2601 | } else if (atomic_read(&rxq->used) == 0) { |
| 2602 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2603 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2604 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2607 | static struct be_tx_compl_info *be_tx_compl_get(struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2608 | { |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2609 | struct be_queue_info *tx_cq = &txo->cq; |
| 2610 | struct be_tx_compl_info *txcp = &txo->txcp; |
| 2611 | struct be_eth_tx_compl *compl = queue_tail_node(tx_cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2612 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2613 | if (compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2614 | return NULL; |
| 2615 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2616 | /* Ensure load ordering of valid bit dword and other dwords below */ |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 2617 | rmb(); |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2618 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2619 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2620 | txcp->status = GET_TX_COMPL_BITS(status, compl); |
| 2621 | txcp->end_index = GET_TX_COMPL_BITS(wrb_index, compl); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2622 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2623 | compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2624 | queue_tail_inc(tx_cq); |
| 2625 | return txcp; |
| 2626 | } |
| 2627 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2628 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2629 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2630 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2631 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2632 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2633 | struct sk_buff *skb = NULL; |
| 2634 | bool unmap_skb_hdr = false; |
| 2635 | struct be_eth_wrb *wrb; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 2636 | u16 num_wrbs = 0; |
| 2637 | u32 frag_index; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2638 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2639 | do { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2640 | if (sent_skbs[txq->tail]) { |
| 2641 | /* Free skb from prev req */ |
| 2642 | if (skb) |
| 2643 | dev_consume_skb_any(skb); |
| 2644 | skb = sent_skbs[txq->tail]; |
| 2645 | sent_skbs[txq->tail] = NULL; |
| 2646 | queue_tail_inc(txq); /* skip hdr wrb */ |
| 2647 | num_wrbs++; |
| 2648 | unmap_skb_hdr = true; |
| 2649 | } |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 2650 | wrb = queue_tail_node(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2651 | frag_index = txq->tail; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2652 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2653 | (unmap_skb_hdr && skb_headlen(skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2654 | unmap_skb_hdr = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2655 | queue_tail_inc(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2656 | num_wrbs++; |
| 2657 | } while (frag_index != last_index); |
| 2658 | dev_consume_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2659 | |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 2660 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2663 | /* Return the number of events in the event queue */ |
| 2664 | static inline int events_get(struct be_eq_obj *eqo) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2665 | { |
| 2666 | struct be_eq_entry *eqe; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2667 | int num = 0; |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2668 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2669 | do { |
| 2670 | eqe = queue_tail_node(&eqo->q); |
| 2671 | if (eqe->evt == 0) |
| 2672 | break; |
| 2673 | |
| 2674 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2675 | eqe->evt = 0; |
| 2676 | num++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2677 | queue_tail_inc(&eqo->q); |
| 2678 | } while (true); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2679 | |
| 2680 | return num; |
| 2681 | } |
| 2682 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2683 | /* Leaves the EQ is disarmed state */ |
| 2684 | static void be_eq_clean(struct be_eq_obj *eqo) |
| 2685 | { |
| 2686 | int num = events_get(eqo); |
| 2687 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2688 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, num, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
Kalesh AP | 99b4430 | 2015-08-05 03:27:49 -0400 | [diff] [blame] | 2691 | /* Free posted rx buffers that were not used */ |
| 2692 | static void be_rxq_clean(struct be_rx_obj *rxo) |
| 2693 | { |
| 2694 | struct be_queue_info *rxq = &rxo->q; |
| 2695 | struct be_rx_page_info *page_info; |
| 2696 | |
| 2697 | while (atomic_read(&rxq->used) > 0) { |
| 2698 | page_info = get_rx_page_info(rxo); |
| 2699 | put_page(page_info->page); |
| 2700 | memset(page_info, 0, sizeof(*page_info)); |
| 2701 | } |
| 2702 | BUG_ON(atomic_read(&rxq->used)); |
| 2703 | rxq->tail = 0; |
| 2704 | rxq->head = 0; |
| 2705 | } |
| 2706 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2707 | static void be_rx_cq_clean(struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2708 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2709 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2710 | struct be_rx_compl_info *rxcp; |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2711 | struct be_adapter *adapter = rxo->adapter; |
| 2712 | int flush_wait = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2713 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2714 | /* Consume pending rx completions. |
| 2715 | * Wait for the flush completion (identified by zero num_rcvd) |
| 2716 | * to arrive. Notify CQ even when there are no more CQ entries |
| 2717 | * for HW to flush partially coalesced CQ entries. |
| 2718 | * In Lancer, there is no need to wait for flush compl. |
| 2719 | */ |
| 2720 | for (;;) { |
| 2721 | rxcp = be_rx_compl_get(rxo); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 2722 | if (!rxcp) { |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2723 | if (lancer_chip(adapter)) |
| 2724 | break; |
| 2725 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 2726 | if (flush_wait++ > 50 || |
| 2727 | be_check_error(adapter, |
| 2728 | BE_ERROR_HW)) { |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2729 | dev_warn(&adapter->pdev->dev, |
| 2730 | "did not receive flush compl\n"); |
| 2731 | break; |
| 2732 | } |
| 2733 | be_cq_notify(adapter, rx_cq->id, true, 0); |
| 2734 | mdelay(1); |
| 2735 | } else { |
| 2736 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 3f5dffe | 2013-05-08 02:05:49 +0000 | [diff] [blame] | 2737 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2738 | if (rxcp->num_rcvd == 0) |
| 2739 | break; |
| 2740 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2743 | /* After cleanup, leave the CQ in unarmed state */ |
| 2744 | be_cq_notify(adapter, rx_cq->id, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2747 | static void be_tx_compl_clean(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2748 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2749 | struct device *dev = &adapter->pdev->dev; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 2750 | u16 cmpl = 0, timeo = 0, num_wrbs = 0; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2751 | struct be_tx_compl_info *txcp; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2752 | struct be_queue_info *txq; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 2753 | u32 end_idx, notified_idx; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2754 | struct be_tx_obj *txo; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2755 | int i, pending_txqs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2756 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2757 | /* Stop polling for compls when HW has been silent for 10ms */ |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2758 | do { |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2759 | pending_txqs = adapter->num_tx_qs; |
| 2760 | |
| 2761 | for_all_tx_queues(adapter, txo, i) { |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2762 | cmpl = 0; |
| 2763 | num_wrbs = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2764 | txq = &txo->q; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2765 | while ((txcp = be_tx_compl_get(txo))) { |
| 2766 | num_wrbs += |
| 2767 | be_tx_compl_process(adapter, txo, |
| 2768 | txcp->end_index); |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2769 | cmpl++; |
| 2770 | } |
| 2771 | if (cmpl) { |
| 2772 | be_cq_notify(adapter, txo->cq.id, false, cmpl); |
| 2773 | atomic_sub(num_wrbs, &txq->used); |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2774 | timeo = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2775 | } |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 2776 | if (!be_is_tx_compl_pending(txo)) |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2777 | pending_txqs--; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 2780 | if (pending_txqs == 0 || ++timeo > 10 || |
| 2781 | be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2782 | break; |
| 2783 | |
| 2784 | mdelay(1); |
| 2785 | } while (true); |
| 2786 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2787 | /* Free enqueued TX that was never notified to HW */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2788 | for_all_tx_queues(adapter, txo, i) { |
| 2789 | txq = &txo->q; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2790 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2791 | if (atomic_read(&txq->used)) { |
| 2792 | dev_info(dev, "txq%d: cleaning %d pending tx-wrbs\n", |
| 2793 | i, atomic_read(&txq->used)); |
| 2794 | notified_idx = txq->tail; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2795 | end_idx = txq->tail; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2796 | index_adv(&end_idx, atomic_read(&txq->used) - 1, |
| 2797 | txq->len); |
| 2798 | /* Use the tx-compl process logic to handle requests |
| 2799 | * that were not sent to the HW. |
| 2800 | */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2801 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
| 2802 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2803 | BUG_ON(atomic_read(&txq->used)); |
| 2804 | txo->pend_wrb_cnt = 0; |
| 2805 | /* Since hw was never notified of these requests, |
| 2806 | * reset TXQ indices |
| 2807 | */ |
| 2808 | txq->head = notified_idx; |
| 2809 | txq->tail = notified_idx; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2810 | } |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2811 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2814 | static void be_evt_queues_destroy(struct be_adapter *adapter) |
| 2815 | { |
| 2816 | struct be_eq_obj *eqo; |
| 2817 | int i; |
| 2818 | |
| 2819 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2820 | if (eqo->q.created) { |
| 2821 | be_eq_clean(eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2822 | be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2823 | netif_napi_del(&eqo->napi); |
Kalesh AP | 649886a | 2015-08-05 03:27:50 -0400 | [diff] [blame] | 2824 | free_cpumask_var(eqo->affinity_mask); |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2825 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2826 | be_queue_free(adapter, &eqo->q); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | static int be_evt_queues_create(struct be_adapter *adapter) |
| 2831 | { |
| 2832 | struct be_queue_info *eq; |
| 2833 | struct be_eq_obj *eqo; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2834 | struct be_aic_obj *aic; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2835 | int i, rc; |
| 2836 | |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 2837 | /* need enough EQs to service both RX and TX queues */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2838 | adapter->num_evt_qs = min_t(u16, num_irqs(adapter), |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 2839 | max(adapter->cfg_num_rx_irqs, |
| 2840 | adapter->cfg_num_tx_irqs)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2841 | |
| 2842 | for_all_evt_queues(adapter, eqo, i) { |
Rusty Russell | f36963c | 2015-05-09 03:14:13 +0930 | [diff] [blame] | 2843 | int numa_node = dev_to_node(&adapter->pdev->dev); |
Kalesh AP | 649886a | 2015-08-05 03:27:50 -0400 | [diff] [blame] | 2844 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2845 | aic = &adapter->aic_obj[i]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2846 | eqo->adapter = adapter; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2847 | eqo->idx = i; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2848 | aic->max_eqd = BE_MAX_EQD; |
| 2849 | aic->enable = true; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2850 | |
| 2851 | eq = &eqo->q; |
| 2852 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2853 | sizeof(struct be_eq_entry)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2854 | if (rc) |
| 2855 | return rc; |
| 2856 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2857 | rc = be_cmd_eq_create(adapter, eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2858 | if (rc) |
| 2859 | return rc; |
Kalesh AP | 649886a | 2015-08-05 03:27:50 -0400 | [diff] [blame] | 2860 | |
| 2861 | if (!zalloc_cpumask_var(&eqo->affinity_mask, GFP_KERNEL)) |
| 2862 | return -ENOMEM; |
| 2863 | cpumask_set_cpu(cpumask_local_spread(i, numa_node), |
| 2864 | eqo->affinity_mask); |
| 2865 | netif_napi_add(adapter->netdev, &eqo->napi, be_poll, |
| 2866 | BE_NAPI_WEIGHT); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2867 | } |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 2868 | return 0; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2871 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 2872 | { |
| 2873 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2874 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2875 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2876 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2877 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2878 | be_queue_free(adapter, q); |
| 2879 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2880 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2881 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2882 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2883 | be_queue_free(adapter, q); |
| 2884 | } |
| 2885 | |
| 2886 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 2887 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 2888 | { |
| 2889 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2890 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2891 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2892 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2893 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2894 | goto err; |
| 2895 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2896 | /* Use the default EQ for MCC completions */ |
| 2897 | 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] | 2898 | goto mcc_cq_free; |
| 2899 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2900 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2901 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 2902 | goto mcc_cq_destroy; |
| 2903 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2904 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2905 | goto mcc_q_free; |
| 2906 | |
| 2907 | return 0; |
| 2908 | |
| 2909 | mcc_q_free: |
| 2910 | be_queue_free(adapter, q); |
| 2911 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2912 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2913 | mcc_cq_free: |
| 2914 | be_queue_free(adapter, cq); |
| 2915 | err: |
| 2916 | return -1; |
| 2917 | } |
| 2918 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2919 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 2920 | { |
| 2921 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2922 | struct be_tx_obj *txo; |
| 2923 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2924 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2925 | for_all_tx_queues(adapter, txo, i) { |
| 2926 | q = &txo->q; |
| 2927 | if (q->created) |
| 2928 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 2929 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2930 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2931 | q = &txo->cq; |
| 2932 | if (q->created) |
| 2933 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2934 | be_queue_free(adapter, q); |
| 2935 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 2938 | static int be_tx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2939 | { |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2940 | struct be_queue_info *cq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2941 | struct be_tx_obj *txo; |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2942 | struct be_eq_obj *eqo; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2943 | int status, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2944 | |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 2945 | adapter->num_tx_qs = min(adapter->num_evt_qs, adapter->cfg_num_tx_irqs); |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 2946 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2947 | for_all_tx_queues(adapter, txo, i) { |
| 2948 | cq = &txo->cq; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2949 | status = be_queue_alloc(adapter, cq, TX_CQ_LEN, |
| 2950 | sizeof(struct be_eth_tx_compl)); |
| 2951 | if (status) |
| 2952 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2953 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2954 | u64_stats_init(&txo->stats.sync); |
| 2955 | u64_stats_init(&txo->stats.sync_compl); |
| 2956 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2957 | /* If num_evt_qs is less than num_tx_qs, then more than |
| 2958 | * one txq share an eq |
| 2959 | */ |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2960 | eqo = &adapter->eq_obj[i % adapter->num_evt_qs]; |
| 2961 | status = be_cmd_cq_create(adapter, cq, &eqo->q, false, 3); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2962 | if (status) |
| 2963 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2964 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2965 | status = be_queue_alloc(adapter, &txo->q, TX_Q_LEN, |
| 2966 | sizeof(struct be_eth_wrb)); |
| 2967 | if (status) |
| 2968 | return status; |
| 2969 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 2970 | status = be_cmd_txq_create(adapter, txo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2971 | if (status) |
| 2972 | return status; |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2973 | |
| 2974 | netif_set_xps_queue(adapter->netdev, eqo->affinity_mask, |
| 2975 | eqo->idx); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2976 | } |
| 2977 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2978 | dev_info(&adapter->pdev->dev, "created %d TX queue(s)\n", |
| 2979 | adapter->num_tx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2980 | return 0; |
| 2981 | } |
| 2982 | |
| 2983 | static void be_rx_cqs_destroy(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2984 | { |
| 2985 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2986 | struct be_rx_obj *rxo; |
| 2987 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2988 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2989 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2990 | q = &rxo->cq; |
| 2991 | if (q->created) |
| 2992 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2993 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2994 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2997 | static int be_rx_cqs_create(struct be_adapter *adapter) |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2998 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2999 | struct be_queue_info *eq, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3000 | struct be_rx_obj *rxo; |
| 3001 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3002 | |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 3003 | adapter->num_rss_qs = |
| 3004 | min(adapter->num_evt_qs, adapter->cfg_num_rx_irqs); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3005 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3006 | /* We'll use RSS only if atleast 2 RSS rings are supported. */ |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 3007 | if (adapter->num_rss_qs < 2) |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3008 | adapter->num_rss_qs = 0; |
| 3009 | |
| 3010 | adapter->num_rx_qs = adapter->num_rss_qs + adapter->need_def_rxq; |
| 3011 | |
| 3012 | /* When the interface is not capable of RSS rings (and there is no |
| 3013 | * need to create a default RXQ) we'll still need one RXQ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3014 | */ |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3015 | if (adapter->num_rx_qs == 0) |
| 3016 | adapter->num_rx_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3017 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3018 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3019 | for_all_rx_queues(adapter, rxo, i) { |
| 3020 | rxo->adapter = adapter; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3021 | cq = &rxo->cq; |
| 3022 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3023 | sizeof(struct be_eth_rx_compl)); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3024 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3025 | return rc; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3026 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 3027 | u64_stats_init(&rxo->stats.sync); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3028 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 3029 | rc = be_cmd_cq_create(adapter, cq, eq, false, 3); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3030 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3031 | return rc; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3032 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3033 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3034 | dev_info(&adapter->pdev->dev, |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3035 | "created %d RX queue(s)\n", adapter->num_rx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3036 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3039 | static irqreturn_t be_intx(int irq, void *dev) |
| 3040 | { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3041 | struct be_eq_obj *eqo = dev; |
| 3042 | struct be_adapter *adapter = eqo->adapter; |
| 3043 | int num_evts = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3044 | |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 3045 | /* IRQ is not expected when NAPI is scheduled as the EQ |
| 3046 | * will not be armed. |
| 3047 | * But, this can happen on Lancer INTx where it takes |
| 3048 | * a while to de-assert INTx or in BE2 where occasionaly |
| 3049 | * an interrupt may be raised even when EQ is unarmed. |
| 3050 | * If NAPI is already scheduled, then counting & notifying |
| 3051 | * events will orphan them. |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3052 | */ |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 3053 | if (napi_schedule_prep(&eqo->napi)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3054 | num_evts = events_get(eqo); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 3055 | __napi_schedule(&eqo->napi); |
| 3056 | if (num_evts) |
| 3057 | eqo->spurious_intr = 0; |
| 3058 | } |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3059 | be_eq_notify(adapter, eqo->q.id, false, true, num_evts, 0); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 3060 | |
| 3061 | /* Return IRQ_HANDLED only for the the first spurious intr |
| 3062 | * after a valid intr to stop the kernel from branding |
| 3063 | * this irq as a bad one! |
| 3064 | */ |
| 3065 | if (num_evts || eqo->spurious_intr++ == 0) |
| 3066 | return IRQ_HANDLED; |
| 3067 | else |
| 3068 | return IRQ_NONE; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3071 | static irqreturn_t be_msix(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3072 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3073 | struct be_eq_obj *eqo = dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3074 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3075 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0, 0); |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 3076 | napi_schedule(&eqo->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3077 | return IRQ_HANDLED; |
| 3078 | } |
| 3079 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3080 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3081 | { |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 3082 | return (rxcp->tcpf && !rxcp->err && rxcp->l4_csum) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3085 | 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] | 3086 | int budget, int polling) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3087 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3088 | struct be_adapter *adapter = rxo->adapter; |
| 3089 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3090 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3091 | u32 work_done; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 3092 | u32 frags_consumed = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3093 | |
| 3094 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3095 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3096 | if (!rxcp) |
| 3097 | break; |
| 3098 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3099 | /* Is it a flush compl that has no data */ |
| 3100 | if (unlikely(rxcp->num_rcvd == 0)) |
| 3101 | goto loop_continue; |
| 3102 | |
| 3103 | /* Discard compl with partial DMA Lancer B0 */ |
| 3104 | if (unlikely(!rxcp->pkt_size)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3105 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3106 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 3107 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 3108 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3109 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 3110 | * promiscuous mode on some skews |
| 3111 | */ |
| 3112 | if (unlikely(rxcp->port != adapter->port_num && |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3113 | !lancer_chip(adapter))) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3114 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3115 | goto loop_continue; |
| 3116 | } |
| 3117 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3118 | /* Don't do gro when we're busy_polling */ |
| 3119 | if (do_gro(rxcp) && polling != BUSY_POLLING) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3120 | be_rx_compl_process_gro(rxo, napi, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3121 | else |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3122 | be_rx_compl_process(rxo, napi, rxcp); |
| 3123 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 3124 | loop_continue: |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 3125 | frags_consumed += rxcp->num_rcvd; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3126 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3129 | if (work_done) { |
| 3130 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 3131 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3132 | /* When an rx-obj gets into post_starved state, just |
| 3133 | * let be_worker do the posting. |
| 3134 | */ |
| 3135 | if (atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM && |
| 3136 | !rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 3137 | be_post_rx_frags(rxo, GFP_ATOMIC, |
| 3138 | max_t(u32, MAX_RX_POST, |
| 3139 | frags_consumed)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3140 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3141 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3142 | return work_done; |
| 3143 | } |
| 3144 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3145 | static inline void be_update_tx_err(struct be_tx_obj *txo, u8 status) |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 3146 | { |
| 3147 | switch (status) { |
| 3148 | case BE_TX_COMP_HDR_PARSE_ERR: |
| 3149 | tx_stats(txo)->tx_hdr_parse_err++; |
| 3150 | break; |
| 3151 | case BE_TX_COMP_NDMA_ERR: |
| 3152 | tx_stats(txo)->tx_dma_err++; |
| 3153 | break; |
| 3154 | case BE_TX_COMP_ACL_ERR: |
| 3155 | tx_stats(txo)->tx_spoof_check_err++; |
| 3156 | break; |
| 3157 | } |
| 3158 | } |
| 3159 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3160 | static inline void lancer_update_tx_err(struct be_tx_obj *txo, u8 status) |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 3161 | { |
| 3162 | switch (status) { |
| 3163 | case LANCER_TX_COMP_LSO_ERR: |
| 3164 | tx_stats(txo)->tx_tso_err++; |
| 3165 | break; |
| 3166 | case LANCER_TX_COMP_HSW_DROP_MAC_ERR: |
| 3167 | case LANCER_TX_COMP_HSW_DROP_VLAN_ERR: |
| 3168 | tx_stats(txo)->tx_spoof_check_err++; |
| 3169 | break; |
| 3170 | case LANCER_TX_COMP_QINQ_ERR: |
| 3171 | tx_stats(txo)->tx_qinq_err++; |
| 3172 | break; |
| 3173 | case LANCER_TX_COMP_PARITY_ERR: |
| 3174 | tx_stats(txo)->tx_internal_parity_err++; |
| 3175 | break; |
| 3176 | case LANCER_TX_COMP_DMA_ERR: |
| 3177 | tx_stats(txo)->tx_dma_err++; |
| 3178 | break; |
| 3179 | } |
| 3180 | } |
| 3181 | |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 3182 | static void be_process_tx(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 3183 | int idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3184 | { |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 3185 | int num_wrbs = 0, work_done = 0; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3186 | struct be_tx_compl_info *txcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3187 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3188 | while ((txcp = be_tx_compl_get(txo))) { |
| 3189 | num_wrbs += be_tx_compl_process(adapter, txo, txcp->end_index); |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 3190 | work_done++; |
| 3191 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3192 | if (txcp->status) { |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 3193 | if (lancer_chip(adapter)) |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3194 | lancer_update_tx_err(txo, txcp->status); |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 3195 | else |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 3196 | be_update_tx_err(txo, txcp->status); |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 3197 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | if (work_done) { |
| 3201 | be_cq_notify(adapter, txo->cq.id, true, work_done); |
| 3202 | atomic_sub(num_wrbs, &txo->q.used); |
| 3203 | |
| 3204 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 3205 | * if it was stopped due to lack of tx wrbs. */ |
| 3206 | if (__netif_subqueue_stopped(adapter->netdev, idx) && |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 3207 | be_can_txq_wake(txo)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3208 | netif_wake_subqueue(adapter->netdev, idx); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3209 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3210 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3211 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
| 3212 | tx_stats(txo)->tx_compl += work_done; |
| 3213 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
| 3214 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3215 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3216 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 3217 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 3218 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 3219 | { |
| 3220 | bool status = true; |
| 3221 | |
| 3222 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 3223 | if (eqo->state & BE_EQ_LOCKED) { |
| 3224 | WARN_ON(eqo->state & BE_EQ_NAPI); |
| 3225 | eqo->state |= BE_EQ_NAPI_YIELD; |
| 3226 | status = false; |
| 3227 | } else { |
| 3228 | eqo->state = BE_EQ_NAPI; |
| 3229 | } |
| 3230 | spin_unlock(&eqo->lock); |
| 3231 | return status; |
| 3232 | } |
| 3233 | |
| 3234 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 3235 | { |
| 3236 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 3237 | |
| 3238 | WARN_ON(eqo->state & (BE_EQ_POLL | BE_EQ_NAPI_YIELD)); |
| 3239 | eqo->state = BE_EQ_IDLE; |
| 3240 | |
| 3241 | spin_unlock(&eqo->lock); |
| 3242 | } |
| 3243 | |
| 3244 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 3245 | { |
| 3246 | bool status = true; |
| 3247 | |
| 3248 | spin_lock_bh(&eqo->lock); |
| 3249 | if (eqo->state & BE_EQ_LOCKED) { |
| 3250 | eqo->state |= BE_EQ_POLL_YIELD; |
| 3251 | status = false; |
| 3252 | } else { |
| 3253 | eqo->state |= BE_EQ_POLL; |
| 3254 | } |
| 3255 | spin_unlock_bh(&eqo->lock); |
| 3256 | return status; |
| 3257 | } |
| 3258 | |
| 3259 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 3260 | { |
| 3261 | spin_lock_bh(&eqo->lock); |
| 3262 | |
| 3263 | WARN_ON(eqo->state & (BE_EQ_NAPI)); |
| 3264 | eqo->state = BE_EQ_IDLE; |
| 3265 | |
| 3266 | spin_unlock_bh(&eqo->lock); |
| 3267 | } |
| 3268 | |
| 3269 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 3270 | { |
| 3271 | spin_lock_init(&eqo->lock); |
| 3272 | eqo->state = BE_EQ_IDLE; |
| 3273 | } |
| 3274 | |
| 3275 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 3276 | { |
| 3277 | local_bh_disable(); |
| 3278 | |
| 3279 | /* It's enough to just acquire napi lock on the eqo to stop |
| 3280 | * be_busy_poll() from processing any queueus. |
| 3281 | */ |
| 3282 | while (!be_lock_napi(eqo)) |
| 3283 | mdelay(1); |
| 3284 | |
| 3285 | local_bh_enable(); |
| 3286 | } |
| 3287 | |
| 3288 | #else /* CONFIG_NET_RX_BUSY_POLL */ |
| 3289 | |
| 3290 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 3291 | { |
| 3292 | return true; |
| 3293 | } |
| 3294 | |
| 3295 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 3296 | { |
| 3297 | } |
| 3298 | |
| 3299 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 3300 | { |
| 3301 | return false; |
| 3302 | } |
| 3303 | |
| 3304 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 3305 | { |
| 3306 | } |
| 3307 | |
| 3308 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 3309 | { |
| 3310 | } |
| 3311 | |
| 3312 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 3313 | { |
| 3314 | } |
| 3315 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
| 3316 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3317 | int be_poll(struct napi_struct *napi, int budget) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3318 | { |
| 3319 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 3320 | struct be_adapter *adapter = eqo->adapter; |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 3321 | int max_work = 0, work, i, num_evts; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3322 | struct be_rx_obj *rxo; |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 3323 | struct be_tx_obj *txo; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3324 | u32 mult_enc = 0; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3325 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 3326 | num_evts = events_get(eqo); |
| 3327 | |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 3328 | for_all_tx_queues_on_eq(adapter, eqo, txo, i) |
| 3329 | be_process_tx(adapter, txo, i); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3330 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3331 | if (be_lock_napi(eqo)) { |
| 3332 | /* This loop will iterate twice for EQ0 in which |
| 3333 | * completions of the last RXQ (default one) are also processed |
| 3334 | * For other EQs the loop iterates only once |
| 3335 | */ |
| 3336 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 3337 | work = be_process_rx(rxo, napi, budget, NAPI_POLLING); |
| 3338 | max_work = max(work, max_work); |
| 3339 | } |
| 3340 | be_unlock_napi(eqo); |
| 3341 | } else { |
| 3342 | max_work = budget; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 3343 | } |
| 3344 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3345 | if (is_mcc_eqo(eqo)) |
| 3346 | be_process_mcc(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3347 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3348 | if (max_work < budget) { |
| 3349 | napi_complete(napi); |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3350 | |
| 3351 | /* Skyhawk EQ_DB has a provision to set the rearm to interrupt |
| 3352 | * delay via a delay multiplier encoding value |
| 3353 | */ |
| 3354 | if (skyhawk_chip(adapter)) |
| 3355 | mult_enc = be_get_eq_delay_mult_enc(eqo); |
| 3356 | |
| 3357 | be_eq_notify(adapter, eqo->q.id, true, false, num_evts, |
| 3358 | mult_enc); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3359 | } else { |
| 3360 | /* As we'll continue in polling mode, count and clear events */ |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3361 | be_eq_notify(adapter, eqo->q.id, false, false, num_evts, 0); |
Padmanabh Ratnakar | 93c8670 | 2011-12-19 01:53:35 +0000 | [diff] [blame] | 3362 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3363 | return max_work; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3366 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 3367 | static int be_busy_poll(struct napi_struct *napi) |
| 3368 | { |
| 3369 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 3370 | struct be_adapter *adapter = eqo->adapter; |
| 3371 | struct be_rx_obj *rxo; |
| 3372 | int i, work = 0; |
| 3373 | |
| 3374 | if (!be_lock_busy_poll(eqo)) |
| 3375 | return LL_FLUSH_BUSY; |
| 3376 | |
| 3377 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 3378 | work = be_process_rx(rxo, napi, 4, BUSY_POLLING); |
| 3379 | if (work) |
| 3380 | break; |
| 3381 | } |
| 3382 | |
| 3383 | be_unlock_busy_poll(eqo); |
| 3384 | return work; |
| 3385 | } |
| 3386 | #endif |
| 3387 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3388 | void be_detect_error(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3389 | { |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3390 | u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0; |
| 3391 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3392 | u32 i; |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3393 | struct device *dev = &adapter->pdev->dev; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3394 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 3395 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 3396 | return; |
| 3397 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3398 | if (lancer_chip(adapter)) { |
| 3399 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3400 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 3401 | be_set_error(adapter, BE_ERROR_UE); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3402 | sliport_err1 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3403 | SLIPORT_ERROR1_OFFSET); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3404 | sliport_err2 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3405 | SLIPORT_ERROR2_OFFSET); |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3406 | /* Do not log error messages if its a FW reset */ |
| 3407 | if (sliport_err1 == SLIPORT_ERROR_FW_RESET1 && |
| 3408 | sliport_err2 == SLIPORT_ERROR_FW_RESET2) { |
| 3409 | dev_info(dev, "Firmware update in progress\n"); |
| 3410 | } else { |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3411 | dev_err(dev, "Error detected in the card\n"); |
| 3412 | dev_err(dev, "ERR: sliport status 0x%x\n", |
| 3413 | sliport_status); |
| 3414 | dev_err(dev, "ERR: sliport error1 0x%x\n", |
| 3415 | sliport_err1); |
| 3416 | dev_err(dev, "ERR: sliport error2 0x%x\n", |
| 3417 | sliport_err2); |
| 3418 | } |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3419 | } |
| 3420 | } else { |
Suresh Reddy | 25848c9 | 2015-03-20 06:28:25 -0400 | [diff] [blame] | 3421 | ue_lo = ioread32(adapter->pcicfg + PCICFG_UE_STATUS_LOW); |
| 3422 | ue_hi = ioread32(adapter->pcicfg + PCICFG_UE_STATUS_HIGH); |
| 3423 | ue_lo_mask = ioread32(adapter->pcicfg + |
| 3424 | PCICFG_UE_STATUS_LOW_MASK); |
| 3425 | ue_hi_mask = ioread32(adapter->pcicfg + |
| 3426 | PCICFG_UE_STATUS_HI_MASK); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3427 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3428 | ue_lo = (ue_lo & ~ue_lo_mask); |
| 3429 | ue_hi = (ue_hi & ~ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3430 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3431 | /* On certain platforms BE hardware can indicate spurious UEs. |
| 3432 | * Allow HW to stop working completely in case of a real UE. |
| 3433 | * Hence not setting the hw_error for UE detection. |
| 3434 | */ |
| 3435 | |
| 3436 | if (ue_lo || ue_hi) { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 3437 | dev_err(dev, "Error detected in the adapter"); |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3438 | if (skyhawk_chip(adapter)) |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 3439 | be_set_error(adapter, BE_ERROR_UE); |
| 3440 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3441 | for (i = 0; ue_lo; ue_lo >>= 1, i++) { |
| 3442 | if (ue_lo & 1) |
| 3443 | dev_err(dev, "UE: %s bit set\n", |
| 3444 | ue_status_low_desc[i]); |
| 3445 | } |
| 3446 | for (i = 0; ue_hi; ue_hi >>= 1, i++) { |
| 3447 | if (ue_hi & 1) |
| 3448 | dev_err(dev, "UE: %s bit set\n", |
| 3449 | ue_status_hi_desc[i]); |
| 3450 | } |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 3451 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3452 | } |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3455 | static void be_msix_disable(struct be_adapter *adapter) |
| 3456 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3457 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3458 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3459 | adapter->num_msix_vec = 0; |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3460 | adapter->num_msix_roce_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3461 | } |
| 3462 | } |
| 3463 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3464 | static int be_msix_enable(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3465 | { |
Dan Carpenter | 6fde0e6 | 2016-06-29 17:39:43 +0300 | [diff] [blame] | 3466 | unsigned int i, max_roce_eqs; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3467 | struct device *dev = &adapter->pdev->dev; |
Dan Carpenter | 6fde0e6 | 2016-06-29 17:39:43 +0300 | [diff] [blame] | 3468 | int num_vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3469 | |
Sathya Perla | ce7faf0 | 2016-06-22 08:54:53 -0400 | [diff] [blame] | 3470 | /* If RoCE is supported, program the max number of vectors that |
| 3471 | * could be used for NIC and RoCE, else, just program the number |
| 3472 | * we'll use initially. |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3473 | */ |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 3474 | if (be_roce_supported(adapter)) { |
| 3475 | max_roce_eqs = |
| 3476 | be_max_func_eqs(adapter) - be_max_nic_eqs(adapter); |
| 3477 | max_roce_eqs = min(max_roce_eqs, num_online_cpus()); |
| 3478 | num_vec = be_max_any_irqs(adapter) + max_roce_eqs; |
| 3479 | } else { |
| 3480 | num_vec = max(adapter->cfg_num_rx_irqs, |
| 3481 | adapter->cfg_num_tx_irqs); |
| 3482 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3483 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3484 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3485 | adapter->msix_entries[i].entry = i; |
| 3486 | |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3487 | num_vec = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 3488 | MIN_MSIX_VECTORS, num_vec); |
| 3489 | if (num_vec < 0) |
| 3490 | goto fail; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3491 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3492 | if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) { |
| 3493 | adapter->num_msix_roce_vec = num_vec / 2; |
| 3494 | dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n", |
| 3495 | adapter->num_msix_roce_vec); |
| 3496 | } |
| 3497 | |
| 3498 | adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec; |
| 3499 | |
| 3500 | dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n", |
| 3501 | adapter->num_msix_vec); |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3502 | return 0; |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3503 | |
| 3504 | fail: |
| 3505 | dev_warn(dev, "MSIx enable failed\n"); |
| 3506 | |
| 3507 | /* INTx is not supported in VFs, so fail probe if enable_msix fails */ |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 3508 | if (be_virtfn(adapter)) |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3509 | return num_vec; |
| 3510 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3513 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3514 | struct be_eq_obj *eqo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3515 | { |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 3516 | return adapter->msix_entries[eqo->msix_idx].vector; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | static int be_msix_register(struct be_adapter *adapter) |
| 3520 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3521 | struct net_device *netdev = adapter->netdev; |
| 3522 | struct be_eq_obj *eqo; |
| 3523 | int status, i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3524 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3525 | for_all_evt_queues(adapter, eqo, i) { |
| 3526 | sprintf(eqo->desc, "%s-q%d", netdev->name, i); |
| 3527 | vec = be_msix_vec_get(adapter, eqo); |
| 3528 | status = request_irq(vec, be_msix, 0, eqo->desc, eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3529 | if (status) |
| 3530 | goto err_msix; |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3531 | |
| 3532 | irq_set_affinity_hint(vec, eqo->affinity_mask); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3533 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 3534 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3535 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3536 | err_msix: |
Venkat Duvvuru | 6e3cd5f | 2015-12-18 01:40:50 +0530 | [diff] [blame] | 3537 | for (i--; i >= 0; i--) { |
| 3538 | eqo = &adapter->eq_obj[i]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3539 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
Venkat Duvvuru | 6e3cd5f | 2015-12-18 01:40:50 +0530 | [diff] [blame] | 3540 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3541 | dev_warn(&adapter->pdev->dev, "MSIX Request IRQ failed - err %d\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3542 | status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3543 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3544 | return status; |
| 3545 | } |
| 3546 | |
| 3547 | static int be_irq_register(struct be_adapter *adapter) |
| 3548 | { |
| 3549 | struct net_device *netdev = adapter->netdev; |
| 3550 | int status; |
| 3551 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3552 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3553 | status = be_msix_register(adapter); |
| 3554 | if (status == 0) |
| 3555 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3556 | /* INTx is not supported for VF */ |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 3557 | if (be_virtfn(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3558 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3561 | /* INTx: only the first EQ is used */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3562 | netdev->irq = adapter->pdev->irq; |
| 3563 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3564 | &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3565 | if (status) { |
| 3566 | dev_err(&adapter->pdev->dev, |
| 3567 | "INTx request IRQ failed - err %d\n", status); |
| 3568 | return status; |
| 3569 | } |
| 3570 | done: |
| 3571 | adapter->isr_registered = true; |
| 3572 | return 0; |
| 3573 | } |
| 3574 | |
| 3575 | static void be_irq_unregister(struct be_adapter *adapter) |
| 3576 | { |
| 3577 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3578 | struct be_eq_obj *eqo; |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3579 | int i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3580 | |
| 3581 | if (!adapter->isr_registered) |
| 3582 | return; |
| 3583 | |
| 3584 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3585 | if (!msix_enabled(adapter)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3586 | free_irq(netdev->irq, &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3587 | goto done; |
| 3588 | } |
| 3589 | |
| 3590 | /* MSIx */ |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3591 | for_all_evt_queues(adapter, eqo, i) { |
| 3592 | vec = be_msix_vec_get(adapter, eqo); |
| 3593 | irq_set_affinity_hint(vec, NULL); |
| 3594 | free_irq(vec, eqo); |
| 3595 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3596 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3597 | done: |
| 3598 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3601 | static void be_rx_qs_destroy(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3602 | { |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 3603 | struct rss_info *rss = &adapter->rss_info; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3604 | struct be_queue_info *q; |
| 3605 | struct be_rx_obj *rxo; |
| 3606 | int i; |
| 3607 | |
| 3608 | for_all_rx_queues(adapter, rxo, i) { |
| 3609 | q = &rxo->q; |
| 3610 | if (q->created) { |
Kalesh AP | 99b4430 | 2015-08-05 03:27:49 -0400 | [diff] [blame] | 3611 | /* If RXQs are destroyed while in an "out of buffer" |
| 3612 | * state, there is a possibility of an HW stall on |
| 3613 | * Lancer. So, post 64 buffers to each queue to relieve |
| 3614 | * the "out of buffer" condition. |
| 3615 | * Make sure there's space in the RXQ before posting. |
| 3616 | */ |
| 3617 | if (lancer_chip(adapter)) { |
| 3618 | be_rx_cq_clean(rxo); |
| 3619 | if (atomic_read(&q->used) == 0) |
| 3620 | be_post_rx_frags(rxo, GFP_KERNEL, |
| 3621 | MAX_RX_POST); |
| 3622 | } |
| 3623 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3624 | be_cmd_rxq_destroy(adapter, q); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3625 | be_rx_cq_clean(rxo); |
Kalesh AP | 99b4430 | 2015-08-05 03:27:49 -0400 | [diff] [blame] | 3626 | be_rxq_clean(rxo); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3627 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3628 | be_queue_free(adapter, q); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3629 | } |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 3630 | |
| 3631 | if (rss->rss_flags) { |
| 3632 | rss->rss_flags = RSS_ENABLE_NONE; |
| 3633 | be_cmd_rss_config(adapter, rss->rsstable, rss->rss_flags, |
| 3634 | 128, rss->rss_hkey); |
| 3635 | } |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3638 | static void be_disable_if_filters(struct be_adapter *adapter) |
| 3639 | { |
Ivan Vecera | 02434de | 2017-01-13 22:38:28 +0100 | [diff] [blame] | 3640 | /* Don't delete MAC on BE3 VFs without FILTMGMT privilege */ |
| 3641 | if (!BEx_chip(adapter) || !be_virtfn(adapter) || |
| 3642 | check_privilege(adapter, BE_PRIV_FILTMGMT)) |
| 3643 | be_dev_mac_del(adapter, adapter->pmac_id[0]); |
| 3644 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3645 | be_clear_uc_list(adapter); |
Sriharsha Basavapatna | 92fbb1d | 2016-07-27 05:26:17 -0400 | [diff] [blame] | 3646 | be_clear_mc_list(adapter); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3647 | |
| 3648 | /* The IFACE flags are enabled in the open path and cleared |
| 3649 | * in the close path. When a VF gets detached from the host and |
| 3650 | * assigned to a VM the following happens: |
| 3651 | * - VF's IFACE flags get cleared in the detach path |
| 3652 | * - IFACE create is issued by the VF in the attach path |
| 3653 | * Due to a bug in the BE3/Skyhawk-R FW |
| 3654 | * (Lancer FW doesn't have the bug), the IFACE capability flags |
| 3655 | * specified along with the IFACE create cmd issued by a VF are not |
| 3656 | * honoured by FW. As a consequence, if a *new* driver |
| 3657 | * (that enables/disables IFACE flags in open/close) |
| 3658 | * is loaded in the host and an *old* driver is * used by a VM/VF, |
| 3659 | * the IFACE gets created *without* the needed flags. |
| 3660 | * To avoid this, disable RX-filter flags only for Lancer. |
| 3661 | */ |
| 3662 | if (lancer_chip(adapter)) { |
| 3663 | be_cmd_rx_filter(adapter, BE_IF_ALL_FILT_FLAGS, OFF); |
| 3664 | adapter->if_flags &= ~BE_IF_ALL_FILT_FLAGS; |
| 3665 | } |
| 3666 | } |
| 3667 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3668 | static int be_close(struct net_device *netdev) |
| 3669 | { |
| 3670 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3671 | struct be_eq_obj *eqo; |
| 3672 | int i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3673 | |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 3674 | /* This protection is needed as be_close() may be called even when the |
| 3675 | * adapter is in cleared state (after eeh perm failure) |
| 3676 | */ |
| 3677 | if (!(adapter->flags & BE_FLAGS_SETUP_DONE)) |
| 3678 | return 0; |
| 3679 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3680 | /* Before attempting cleanup ensure all the pending cmds in the |
| 3681 | * config_wq have finished execution |
| 3682 | */ |
| 3683 | flush_workqueue(be_wq); |
| 3684 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3685 | be_disable_if_filters(adapter); |
| 3686 | |
Ivan Vecera | dff345c5 | 2013-11-27 08:59:32 +0100 | [diff] [blame] | 3687 | if (adapter->flags & BE_FLAGS_NAPI_ENABLED) { |
| 3688 | for_all_evt_queues(adapter, eqo, i) { |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3689 | napi_disable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3690 | be_disable_busy_poll(eqo); |
| 3691 | } |
David S. Miller | 71237b6 | 2013-11-28 18:53:36 -0500 | [diff] [blame] | 3692 | adapter->flags &= ~BE_FLAGS_NAPI_ENABLED; |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3693 | } |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3694 | |
| 3695 | be_async_mcc_disable(adapter); |
| 3696 | |
| 3697 | /* Wait for all pending tx completions to arrive so that |
| 3698 | * all tx skbs are freed. |
| 3699 | */ |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 3700 | netif_tx_disable(netdev); |
Sathya Perla | 6e1f997 | 2013-08-22 12:23:41 +0530 | [diff] [blame] | 3701 | be_tx_compl_clean(adapter); |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3702 | |
| 3703 | be_rx_qs_destroy(adapter); |
Ajit Khaparde | d11a347 | 2013-11-18 10:44:37 -0600 | [diff] [blame] | 3704 | |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3705 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3706 | if (msix_enabled(adapter)) |
| 3707 | synchronize_irq(be_msix_vec_get(adapter, eqo)); |
| 3708 | else |
| 3709 | synchronize_irq(netdev->irq); |
| 3710 | be_eq_clean(eqo); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3713 | be_irq_unregister(adapter); |
| 3714 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3715 | return 0; |
| 3716 | } |
| 3717 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3718 | static int be_rx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3719 | { |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3720 | struct rss_info *rss = &adapter->rss_info; |
| 3721 | u8 rss_key[RSS_HASH_KEY_LEN]; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3722 | struct be_rx_obj *rxo; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3723 | int rc, i, j; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3724 | |
| 3725 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3726 | rc = be_queue_alloc(adapter, &rxo->q, RX_Q_LEN, |
| 3727 | sizeof(struct be_eth_rx_d)); |
| 3728 | if (rc) |
| 3729 | return rc; |
| 3730 | } |
| 3731 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3732 | if (adapter->need_def_rxq || !adapter->num_rss_qs) { |
| 3733 | rxo = default_rxo(adapter); |
| 3734 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
| 3735 | rx_frag_size, adapter->if_handle, |
| 3736 | false, &rxo->rss_id); |
| 3737 | if (rc) |
| 3738 | return rc; |
| 3739 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3740 | |
| 3741 | for_all_rss_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3742 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3743 | rx_frag_size, adapter->if_handle, |
| 3744 | true, &rxo->rss_id); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3745 | if (rc) |
| 3746 | return rc; |
| 3747 | } |
| 3748 | |
| 3749 | if (be_multi_rxq(adapter)) { |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3750 | for (j = 0; j < RSS_INDIR_TABLE_LEN; j += adapter->num_rss_qs) { |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3751 | for_all_rss_queues(adapter, rxo, i) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3752 | if ((j + i) >= RSS_INDIR_TABLE_LEN) |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3753 | break; |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3754 | rss->rsstable[j + i] = rxo->rss_id; |
| 3755 | rss->rss_queue[j + i] = i; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3756 | } |
| 3757 | } |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3758 | rss->rss_flags = RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 | |
| 3759 | RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6; |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3760 | |
| 3761 | if (!BEx_chip(adapter)) |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3762 | rss->rss_flags |= RSS_ENABLE_UDP_IPV4 | |
| 3763 | RSS_ENABLE_UDP_IPV6; |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 3764 | |
| 3765 | netdev_rss_key_fill(rss_key, RSS_HASH_KEY_LEN); |
| 3766 | rc = be_cmd_rss_config(adapter, rss->rsstable, rss->rss_flags, |
| 3767 | RSS_INDIR_TABLE_LEN, rss_key); |
| 3768 | if (rc) { |
| 3769 | rss->rss_flags = RSS_ENABLE_NONE; |
| 3770 | return rc; |
| 3771 | } |
| 3772 | |
| 3773 | memcpy(rss->rss_hkey, rss_key, RSS_HASH_KEY_LEN); |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3774 | } else { |
| 3775 | /* Disable RSS, if only default RX Q is created */ |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3776 | rss->rss_flags = RSS_ENABLE_NONE; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3777 | } |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3778 | |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3779 | |
Suresh Reddy | b02e60c | 2015-05-06 05:30:36 -0400 | [diff] [blame] | 3780 | /* Post 1 less than RXQ-len to avoid head being equal to tail, |
| 3781 | * which is a queue empty condition |
| 3782 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3783 | for_all_rx_queues(adapter, rxo, i) |
Suresh Reddy | b02e60c | 2015-05-06 05:30:36 -0400 | [diff] [blame] | 3784 | be_post_rx_frags(rxo, GFP_KERNEL, RX_Q_LEN - 1); |
| 3785 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3786 | return 0; |
| 3787 | } |
| 3788 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3789 | static int be_enable_if_filters(struct be_adapter *adapter) |
| 3790 | { |
| 3791 | int status; |
| 3792 | |
Venkat Duvvuru | c1bb0a5 | 2016-03-02 06:00:28 -0500 | [diff] [blame] | 3793 | status = be_cmd_rx_filter(adapter, BE_IF_FILT_FLAGS_BASIC, ON); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3794 | if (status) |
| 3795 | return status; |
| 3796 | |
Ivan Vecera | cc43996 | 2017-01-13 22:38:29 +0100 | [diff] [blame] | 3797 | /* Don't add MAC on BE3 VFs without FILTMGMT privilege */ |
| 3798 | if (!BEx_chip(adapter) || !be_virtfn(adapter) || |
| 3799 | check_privilege(adapter, BE_PRIV_FILTMGMT)) { |
Suresh Reddy | 988d44b | 2016-09-07 19:57:52 +0530 | [diff] [blame] | 3800 | status = be_dev_mac_add(adapter, adapter->netdev->dev_addr); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3801 | if (status) |
| 3802 | return status; |
Suresh Reddy | c27ebf5 | 2016-09-07 19:57:53 +0530 | [diff] [blame] | 3803 | ether_addr_copy(adapter->dev_mac, adapter->netdev->dev_addr); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | if (adapter->vlans_added) |
| 3807 | be_vid_config(adapter); |
| 3808 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3809 | __be_set_rx_mode(adapter); |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3810 | |
| 3811 | return 0; |
| 3812 | } |
| 3813 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3814 | static int be_open(struct net_device *netdev) |
| 3815 | { |
| 3816 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3817 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3818 | struct be_rx_obj *rxo; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3819 | struct be_tx_obj *txo; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3820 | u8 link_status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3821 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3822 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3823 | status = be_rx_qs_create(adapter); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3824 | if (status) |
| 3825 | goto err; |
| 3826 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 3827 | status = be_enable_if_filters(adapter); |
| 3828 | if (status) |
| 3829 | goto err; |
| 3830 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3831 | status = be_irq_register(adapter); |
| 3832 | if (status) |
| 3833 | goto err; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3834 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3835 | for_all_rx_queues(adapter, rxo, i) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3836 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3837 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3838 | for_all_tx_queues(adapter, txo, i) |
| 3839 | be_cq_notify(adapter, txo->cq.id, true, 0); |
| 3840 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 3841 | be_async_mcc_enable(adapter); |
| 3842 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3843 | for_all_evt_queues(adapter, eqo, i) { |
| 3844 | napi_enable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3845 | be_enable_busy_poll(eqo); |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3846 | be_eq_notify(adapter, eqo->q.id, true, true, 0, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3847 | } |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3848 | adapter->flags |= BE_FLAGS_NAPI_ENABLED; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3849 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 3850 | status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3851 | if (!status) |
| 3852 | be_link_status_update(adapter, link_status); |
| 3853 | |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 3854 | netif_tx_start_all_queues(netdev); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3855 | if (skyhawk_chip(adapter)) |
Alexander Duyck | bde6b7c | 2016-06-16 12:21:43 -0700 | [diff] [blame] | 3856 | udp_tunnel_get_rx_info(netdev); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3857 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3858 | return 0; |
| 3859 | err: |
| 3860 | be_close(adapter->netdev); |
| 3861 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 3864 | static void be_vf_eth_addr_generate(struct be_adapter *adapter, u8 *mac) |
| 3865 | { |
| 3866 | u32 addr; |
| 3867 | |
| 3868 | addr = jhash(adapter->netdev->dev_addr, ETH_ALEN, 0); |
| 3869 | |
| 3870 | mac[5] = (u8)(addr & 0xFF); |
| 3871 | mac[4] = (u8)((addr >> 8) & 0xFF); |
| 3872 | mac[3] = (u8)((addr >> 16) & 0xFF); |
| 3873 | /* Use the OUI from the current MAC address */ |
| 3874 | memcpy(mac, adapter->netdev->dev_addr, 3); |
| 3875 | } |
| 3876 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3877 | /* |
| 3878 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 3879 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 3880 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 3881 | * queries for the MAC address during its probe. |
| 3882 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3883 | static int be_vf_eth_addr_config(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3884 | { |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3885 | u32 vf; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3886 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3887 | u8 mac[ETH_ALEN]; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3888 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3889 | |
| 3890 | be_vf_eth_addr_generate(adapter, mac); |
| 3891 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3892 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3893 | if (BEx_chip(adapter)) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3894 | status = be_cmd_pmac_add(adapter, mac, |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3895 | vf_cfg->if_handle, |
| 3896 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3897 | else |
| 3898 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 3899 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3900 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3901 | if (status) |
| 3902 | dev_err(&adapter->pdev->dev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3903 | "Mac address assignment failed for VF %d\n", |
| 3904 | vf); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3905 | else |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3906 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3907 | |
| 3908 | mac[5] += 1; |
| 3909 | } |
| 3910 | return status; |
| 3911 | } |
| 3912 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3913 | static int be_vfs_mac_query(struct be_adapter *adapter) |
| 3914 | { |
| 3915 | int status, vf; |
| 3916 | u8 mac[ETH_ALEN]; |
| 3917 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3918 | |
| 3919 | for_all_vfs(adapter, vf_cfg, vf) { |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3920 | status = be_cmd_get_active_mac(adapter, vf_cfg->pmac_id, |
| 3921 | mac, vf_cfg->if_handle, |
| 3922 | false, vf+1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3923 | if (status) |
| 3924 | return status; |
| 3925 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
| 3926 | } |
| 3927 | return 0; |
| 3928 | } |
| 3929 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3930 | static void be_vf_clear(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3931 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3932 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3933 | u32 vf; |
| 3934 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3935 | if (pci_vfs_assigned(adapter->pdev)) { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3936 | dev_warn(&adapter->pdev->dev, |
| 3937 | "VFs are assigned to VMs: not disabling VFs\n"); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3938 | goto done; |
| 3939 | } |
| 3940 | |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3941 | pci_disable_sriov(adapter->pdev); |
| 3942 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3943 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3944 | if (BEx_chip(adapter)) |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3945 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, |
| 3946 | vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3947 | else |
| 3948 | be_cmd_set_mac(adapter, NULL, vf_cfg->if_handle, |
| 3949 | vf + 1); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3950 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3951 | be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1); |
| 3952 | } |
Somnath Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 3953 | |
| 3954 | if (BE3_chip(adapter)) |
| 3955 | be_cmd_set_hsw_config(adapter, 0, 0, |
| 3956 | adapter->if_handle, |
| 3957 | PORT_FWD_TYPE_PASSTHRU, 0); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3958 | done: |
| 3959 | kfree(adapter->vf_cfg); |
| 3960 | adapter->num_vfs = 0; |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 3961 | adapter->flags &= ~BE_FLAGS_SRIOV_ENABLED; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3964 | static void be_clear_queues(struct be_adapter *adapter) |
| 3965 | { |
| 3966 | be_mcc_queues_destroy(adapter); |
| 3967 | be_rx_cqs_destroy(adapter); |
| 3968 | be_tx_queues_destroy(adapter); |
| 3969 | be_evt_queues_destroy(adapter); |
| 3970 | } |
| 3971 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3972 | static void be_cancel_worker(struct be_adapter *adapter) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3973 | { |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3974 | if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) { |
| 3975 | cancel_delayed_work_sync(&adapter->work); |
| 3976 | adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED; |
| 3977 | } |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3978 | } |
| 3979 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 3980 | static void be_cancel_err_detection(struct be_adapter *adapter) |
| 3981 | { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 3982 | struct be_error_recovery *err_rec = &adapter->error_recovery; |
| 3983 | |
| 3984 | if (!be_err_recovery_workq) |
| 3985 | return; |
| 3986 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 3987 | if (adapter->flags & BE_FLAGS_ERR_DETECTION_SCHEDULED) { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 3988 | cancel_delayed_work_sync(&err_rec->err_detection_work); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 3989 | adapter->flags &= ~BE_FLAGS_ERR_DETECTION_SCHEDULED; |
| 3990 | } |
| 3991 | } |
| 3992 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3993 | static void be_disable_vxlan_offloads(struct be_adapter *adapter) |
| 3994 | { |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 3995 | struct net_device *netdev = adapter->netdev; |
| 3996 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3997 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) |
| 3998 | be_cmd_manage_iface(adapter, adapter->if_handle, |
| 3999 | OP_CONVERT_TUNNEL_TO_NORMAL); |
| 4000 | |
| 4001 | if (adapter->vxlan_port) |
| 4002 | be_cmd_set_vxlan_port(adapter, 0); |
| 4003 | |
| 4004 | adapter->flags &= ~BE_FLAGS_VXLAN_OFFLOADS; |
| 4005 | adapter->vxlan_port = 0; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4006 | |
| 4007 | netdev->hw_enc_features = 0; |
| 4008 | netdev->hw_features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 4009 | netdev->features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4010 | } |
| 4011 | |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4012 | static void be_calculate_vf_res(struct be_adapter *adapter, u16 num_vfs, |
| 4013 | struct be_resources *vft_res) |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4014 | { |
| 4015 | struct be_resources res = adapter->pool_res; |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4016 | u32 vf_if_cap_flags = res.vf_if_cap_flags; |
| 4017 | struct be_resources res_mod = {0}; |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4018 | u16 num_vf_qs = 1; |
| 4019 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4020 | /* Distribute the queue resources among the PF and it's VFs */ |
| 4021 | if (num_vfs) { |
| 4022 | /* Divide the rx queues evenly among the VFs and the PF, capped |
| 4023 | * at VF-EQ-count. Any remainder queues belong to the PF. |
| 4024 | */ |
Sriharsha Basavapatna | ee9ad28 | 2016-02-03 09:49:19 +0530 | [diff] [blame] | 4025 | num_vf_qs = min(SH_VF_MAX_NIC_EQS, |
| 4026 | res.max_rss_qs / (num_vfs + 1)); |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4027 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4028 | /* Skyhawk-R chip supports only MAX_PORT_RSS_TABLES |
| 4029 | * RSS Tables per port. Provide RSS on VFs, only if number of |
| 4030 | * VFs requested is less than it's PF Pool's RSS Tables limit. |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4031 | */ |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4032 | if (num_vfs >= be_max_pf_pool_rss_tables(adapter)) |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4033 | num_vf_qs = 1; |
| 4034 | } |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4035 | |
| 4036 | /* Resource with fields set to all '1's by GET_PROFILE_CONFIG cmd, |
| 4037 | * which are modifiable using SET_PROFILE_CONFIG cmd. |
| 4038 | */ |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4039 | be_cmd_get_profile_config(adapter, &res_mod, NULL, ACTIVE_PROFILE_TYPE, |
| 4040 | RESOURCE_MODIFIABLE, 0); |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4041 | |
| 4042 | /* If RSS IFACE capability flags are modifiable for a VF, set the |
| 4043 | * capability flag as valid and set RSS and DEFQ_RSS IFACE flags if |
| 4044 | * more than 1 RSSQ is available for a VF. |
| 4045 | * Otherwise, provision only 1 queue pair for VF. |
| 4046 | */ |
| 4047 | if (res_mod.vf_if_cap_flags & BE_IF_FLAGS_RSS) { |
| 4048 | vft_res->flags |= BIT(IF_CAPS_FLAGS_VALID_SHIFT); |
| 4049 | if (num_vf_qs > 1) { |
| 4050 | vf_if_cap_flags |= BE_IF_FLAGS_RSS; |
| 4051 | if (res.if_cap_flags & BE_IF_FLAGS_DEFQ_RSS) |
| 4052 | vf_if_cap_flags |= BE_IF_FLAGS_DEFQ_RSS; |
| 4053 | } else { |
| 4054 | vf_if_cap_flags &= ~(BE_IF_FLAGS_RSS | |
| 4055 | BE_IF_FLAGS_DEFQ_RSS); |
| 4056 | } |
| 4057 | } else { |
| 4058 | num_vf_qs = 1; |
| 4059 | } |
| 4060 | |
| 4061 | if (res_mod.vf_if_cap_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) { |
| 4062 | vft_res->flags |= BIT(IF_CAPS_FLAGS_VALID_SHIFT); |
| 4063 | vf_if_cap_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 4064 | } |
| 4065 | |
| 4066 | vft_res->vf_if_cap_flags = vf_if_cap_flags; |
| 4067 | vft_res->max_rx_qs = num_vf_qs; |
| 4068 | vft_res->max_rss_qs = num_vf_qs; |
| 4069 | vft_res->max_tx_qs = res.max_tx_qs / (num_vfs + 1); |
| 4070 | vft_res->max_cq_count = res.max_cq_count / (num_vfs + 1); |
| 4071 | |
| 4072 | /* Distribute unicast MACs, VLANs, IFACE count and MCCQ count equally |
| 4073 | * among the PF and it's VFs, if the fields are changeable |
| 4074 | */ |
| 4075 | if (res_mod.max_uc_mac == FIELD_MODIFIABLE) |
| 4076 | vft_res->max_uc_mac = res.max_uc_mac / (num_vfs + 1); |
| 4077 | |
| 4078 | if (res_mod.max_vlans == FIELD_MODIFIABLE) |
| 4079 | vft_res->max_vlans = res.max_vlans / (num_vfs + 1); |
| 4080 | |
| 4081 | if (res_mod.max_iface_count == FIELD_MODIFIABLE) |
| 4082 | vft_res->max_iface_count = res.max_iface_count / (num_vfs + 1); |
| 4083 | |
| 4084 | if (res_mod.max_mcc_count == FIELD_MODIFIABLE) |
| 4085 | vft_res->max_mcc_count = res.max_mcc_count / (num_vfs + 1); |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4086 | } |
| 4087 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4088 | static void be_if_destroy(struct be_adapter *adapter) |
| 4089 | { |
| 4090 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
| 4091 | |
| 4092 | kfree(adapter->pmac_id); |
| 4093 | adapter->pmac_id = NULL; |
| 4094 | |
| 4095 | kfree(adapter->mc_list); |
| 4096 | adapter->mc_list = NULL; |
| 4097 | |
| 4098 | kfree(adapter->uc_list); |
| 4099 | adapter->uc_list = NULL; |
| 4100 | } |
| 4101 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 4102 | static int be_clear(struct be_adapter *adapter) |
| 4103 | { |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4104 | struct pci_dev *pdev = adapter->pdev; |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4105 | struct be_resources vft_res = {0}; |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4106 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4107 | be_cancel_worker(adapter); |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 4108 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4109 | flush_workqueue(be_wq); |
| 4110 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 4111 | if (sriov_enabled(adapter)) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4112 | be_vf_clear(adapter); |
| 4113 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4114 | /* Re-configure FW to distribute resources evenly across max-supported |
| 4115 | * number of VFs, only when VFs are not already enabled. |
| 4116 | */ |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4117 | if (skyhawk_chip(adapter) && be_physfn(adapter) && |
| 4118 | !pci_vfs_assigned(pdev)) { |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4119 | be_calculate_vf_res(adapter, |
| 4120 | pci_sriov_get_totalvfs(pdev), |
| 4121 | &vft_res); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4122 | be_cmd_set_sriov_config(adapter, adapter->pool_res, |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4123 | pci_sriov_get_totalvfs(pdev), |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4124 | &vft_res); |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4125 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4126 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4127 | be_disable_vxlan_offloads(adapter); |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 4128 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4129 | be_if_destroy(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4130 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4131 | be_clear_queues(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4132 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4133 | be_msix_disable(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 4134 | adapter->flags &= ~BE_FLAGS_SETUP_DONE; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4135 | return 0; |
| 4136 | } |
| 4137 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4138 | static int be_vfs_if_create(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4139 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4140 | struct be_resources res = {0}; |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 4141 | u32 cap_flags, en_flags, vf; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4142 | struct be_vf_cfg *vf_cfg; |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 4143 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4144 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 4145 | /* If a FW profile exists, then cap_flags are updated */ |
Venkat Duvvuru | c1bb0a5 | 2016-03-02 06:00:28 -0500 | [diff] [blame] | 4146 | cap_flags = BE_VF_IF_EN_FLAGS; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4147 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4148 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4149 | if (!BE3_chip(adapter)) { |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4150 | status = be_cmd_get_profile_config(adapter, &res, NULL, |
| 4151 | ACTIVE_PROFILE_TYPE, |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4152 | RESOURCE_LIMITS, |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4153 | vf + 1); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4154 | if (!status) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4155 | cap_flags = res.if_cap_flags; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4156 | /* Prevent VFs from enabling VLAN promiscuous |
| 4157 | * mode |
| 4158 | */ |
| 4159 | cap_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 4160 | } |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4161 | } |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4162 | |
Venkat Duvvuru | c1bb0a5 | 2016-03-02 06:00:28 -0500 | [diff] [blame] | 4163 | /* PF should enable IF flags during proxy if_create call */ |
| 4164 | en_flags = cap_flags & BE_VF_IF_EN_FLAGS; |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 4165 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 4166 | &vf_cfg->if_handle, vf + 1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4167 | if (status) |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 4168 | return status; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4169 | } |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 4170 | |
| 4171 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4172 | } |
| 4173 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4174 | static int be_vf_setup_init(struct be_adapter *adapter) |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4175 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 4176 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4177 | int vf; |
| 4178 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4179 | adapter->vf_cfg = kcalloc(adapter->num_vfs, sizeof(*vf_cfg), |
| 4180 | GFP_KERNEL); |
| 4181 | if (!adapter->vf_cfg) |
| 4182 | return -ENOMEM; |
| 4183 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 4184 | for_all_vfs(adapter, vf_cfg, vf) { |
| 4185 | vf_cfg->if_handle = -1; |
| 4186 | vf_cfg->pmac_id = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4187 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4188 | return 0; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4191 | static int be_vf_setup(struct be_adapter *adapter) |
| 4192 | { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4193 | struct device *dev = &adapter->pdev->dev; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 4194 | struct be_vf_cfg *vf_cfg; |
| 4195 | int status, old_vfs, vf; |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4196 | bool spoofchk; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4197 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 4198 | old_vfs = pci_num_vf(adapter->pdev); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4199 | |
| 4200 | status = be_vf_setup_init(adapter); |
| 4201 | if (status) |
| 4202 | goto err; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4203 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4204 | if (old_vfs) { |
| 4205 | for_all_vfs(adapter, vf_cfg, vf) { |
| 4206 | status = be_cmd_get_if_id(adapter, vf_cfg, vf); |
| 4207 | if (status) |
| 4208 | goto err; |
| 4209 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4210 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4211 | status = be_vfs_mac_query(adapter); |
| 4212 | if (status) |
| 4213 | goto err; |
| 4214 | } else { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4215 | status = be_vfs_if_create(adapter); |
| 4216 | if (status) |
| 4217 | goto err; |
| 4218 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4219 | status = be_vf_eth_addr_config(adapter); |
| 4220 | if (status) |
| 4221 | goto err; |
| 4222 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4223 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 4224 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 4225 | /* Allow VFs to programs MAC/VLAN filters */ |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4226 | status = be_cmd_get_fn_privileges(adapter, &vf_cfg->privileges, |
| 4227 | vf + 1); |
| 4228 | if (!status && !(vf_cfg->privileges & BE_PRIV_FILTMGMT)) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 4229 | status = be_cmd_set_fn_privileges(adapter, |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4230 | vf_cfg->privileges | |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 4231 | BE_PRIV_FILTMGMT, |
| 4232 | vf + 1); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4233 | if (!status) { |
| 4234 | vf_cfg->privileges |= BE_PRIV_FILTMGMT; |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 4235 | dev_info(dev, "VF%d has FILTMGMT privilege\n", |
| 4236 | vf); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 4237 | } |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 4238 | } |
| 4239 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4240 | /* Allow full available bandwidth */ |
| 4241 | if (!old_vfs) |
| 4242 | be_cmd_config_qos(adapter, 0, 0, vf + 1); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 4243 | |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4244 | status = be_cmd_get_hsw_config(adapter, NULL, vf + 1, |
| 4245 | vf_cfg->if_handle, NULL, |
| 4246 | &spoofchk); |
| 4247 | if (!status) |
| 4248 | vf_cfg->spoofchk = spoofchk; |
| 4249 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4250 | if (!old_vfs) { |
Vasundhara Volam | 0599863 | 2013-10-01 15:59:59 +0530 | [diff] [blame] | 4251 | be_cmd_enable_vf(adapter, vf + 1); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4252 | be_cmd_set_logical_link_config(adapter, |
| 4253 | IFLA_VF_LINK_STATE_AUTO, |
| 4254 | vf+1); |
| 4255 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4256 | } |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 4257 | |
| 4258 | if (!old_vfs) { |
| 4259 | status = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 4260 | if (status) { |
| 4261 | dev_err(dev, "SRIOV enable failed\n"); |
| 4262 | adapter->num_vfs = 0; |
| 4263 | goto err; |
| 4264 | } |
| 4265 | } |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 4266 | |
Somnath Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 4267 | if (BE3_chip(adapter)) { |
| 4268 | /* On BE3, enable VEB only when SRIOV is enabled */ |
| 4269 | status = be_cmd_set_hsw_config(adapter, 0, 0, |
| 4270 | adapter->if_handle, |
| 4271 | PORT_FWD_TYPE_VEB, 0); |
| 4272 | if (status) |
| 4273 | goto err; |
| 4274 | } |
| 4275 | |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 4276 | adapter->flags |= BE_FLAGS_SRIOV_ENABLED; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4277 | return 0; |
| 4278 | err: |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4279 | dev_err(dev, "VF setup failed\n"); |
| 4280 | be_vf_clear(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4281 | return status; |
| 4282 | } |
| 4283 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4284 | /* Converting function_mode bits on BE3 to SH mc_type enums */ |
| 4285 | |
| 4286 | static u8 be_convert_mc_type(u32 function_mode) |
| 4287 | { |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 4288 | if (function_mode & VNIC_MODE && function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4289 | return vNIC1; |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 4290 | else if (function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4291 | return FLEX10; |
| 4292 | else if (function_mode & VNIC_MODE) |
| 4293 | return vNIC2; |
| 4294 | else if (function_mode & UMC_ENABLED) |
| 4295 | return UMC; |
| 4296 | else |
| 4297 | return MC_NONE; |
| 4298 | } |
| 4299 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4300 | /* On BE2/BE3 FW does not suggest the supported limits */ |
| 4301 | static void BEx_get_resources(struct be_adapter *adapter, |
| 4302 | struct be_resources *res) |
| 4303 | { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4304 | bool use_sriov = adapter->num_vfs ? 1 : 0; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4305 | |
| 4306 | if (be_physfn(adapter)) |
| 4307 | res->max_uc_mac = BE_UC_PMAC_COUNT; |
| 4308 | else |
| 4309 | res->max_uc_mac = BE_VF_UC_PMAC_COUNT; |
| 4310 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4311 | adapter->mc_type = be_convert_mc_type(adapter->function_mode); |
| 4312 | |
| 4313 | if (be_is_mc(adapter)) { |
| 4314 | /* Assuming that there are 4 channels per port, |
| 4315 | * when multi-channel is enabled |
| 4316 | */ |
| 4317 | if (be_is_qnq_mode(adapter)) |
| 4318 | res->max_vlans = BE_NUM_VLANS_SUPPORTED/8; |
| 4319 | else |
| 4320 | /* In a non-qnq multichannel mode, the pvid |
| 4321 | * takes up one vlan entry |
| 4322 | */ |
| 4323 | res->max_vlans = (BE_NUM_VLANS_SUPPORTED / 4) - 1; |
| 4324 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4325 | res->max_vlans = BE_NUM_VLANS_SUPPORTED; |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4326 | } |
| 4327 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4328 | res->max_mcast_mac = BE_MAX_MC; |
| 4329 | |
Vasundhara Volam | a5243da | 2014-03-11 18:53:07 +0530 | [diff] [blame] | 4330 | /* 1) For BE3 1Gb ports, FW does not support multiple TXQs |
| 4331 | * 2) Create multiple TX rings on a BE3-R multi-channel interface |
| 4332 | * *only* if it is RSS-capable. |
| 4333 | */ |
| 4334 | if (BE2_chip(adapter) || use_sriov || (adapter->port_num > 1) || |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 4335 | be_virtfn(adapter) || |
| 4336 | (be_is_mc(adapter) && |
| 4337 | !(adapter->function_caps & BE_FUNCTION_CAPS_RSS))) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4338 | res->max_tx_qs = 1; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 4339 | } else if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { |
| 4340 | struct be_resources super_nic_res = {0}; |
| 4341 | |
| 4342 | /* On a SuperNIC profile, the driver needs to use the |
| 4343 | * GET_PROFILE_CONFIG cmd to query the per-function TXQ limits |
| 4344 | */ |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4345 | be_cmd_get_profile_config(adapter, &super_nic_res, NULL, |
| 4346 | ACTIVE_PROFILE_TYPE, RESOURCE_LIMITS, |
| 4347 | 0); |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 4348 | /* Some old versions of BE3 FW don't report max_tx_qs value */ |
| 4349 | res->max_tx_qs = super_nic_res.max_tx_qs ? : BE3_MAX_TX_QS; |
| 4350 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4351 | res->max_tx_qs = BE3_MAX_TX_QS; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 4352 | } |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4353 | |
| 4354 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
| 4355 | !use_sriov && be_physfn(adapter)) |
| 4356 | res->max_rss_qs = (adapter->be3_native) ? |
| 4357 | BE3_MAX_RSS_QS : BE2_MAX_RSS_QS; |
| 4358 | res->max_rx_qs = res->max_rss_qs + 1; |
| 4359 | |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 4360 | if (be_physfn(adapter)) |
Vasundhara Volam | d3518e2 | 2014-07-17 16:20:29 +0530 | [diff] [blame] | 4361 | res->max_evt_qs = (be_max_vfs(adapter) > 0) ? |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 4362 | BE3_SRIOV_MAX_EVT_QS : BE3_MAX_EVT_QS; |
| 4363 | else |
| 4364 | res->max_evt_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4365 | |
| 4366 | res->if_cap_flags = BE_IF_CAP_FLAGS_WANT; |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 4367 | res->if_cap_flags &= ~BE_IF_FLAGS_DEFQ_RSS; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4368 | if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS)) |
| 4369 | res->if_cap_flags &= ~BE_IF_FLAGS_RSS; |
| 4370 | } |
| 4371 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4372 | static void be_setup_init(struct be_adapter *adapter) |
| 4373 | { |
| 4374 | adapter->vlan_prio_bmap = 0xff; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 4375 | adapter->phy.link_speed = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4376 | adapter->if_handle = -1; |
| 4377 | adapter->be3_native = false; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 4378 | adapter->if_flags = 0; |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 4379 | adapter->phy_state = BE_UNKNOWN_PHY_STATE; |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4380 | if (be_physfn(adapter)) |
| 4381 | adapter->cmd_privileges = MAX_PRIVILEGES; |
| 4382 | else |
| 4383 | adapter->cmd_privileges = MIN_PRIVILEGES; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4386 | /* HW supports only MAX_PORT_RSS_TABLES RSS Policy Tables per port. |
| 4387 | * However, this HW limitation is not exposed to the host via any SLI cmd. |
| 4388 | * As a result, in the case of SRIOV and in particular multi-partition configs |
| 4389 | * the driver needs to calcuate a proportional share of RSS Tables per PF-pool |
| 4390 | * for distribution between the VFs. This self-imposed limit will determine the |
| 4391 | * no: of VFs for which RSS can be enabled. |
| 4392 | */ |
Baoyou Xie | d766e7e | 2016-09-18 16:35:29 +0800 | [diff] [blame] | 4393 | static void be_calculate_pf_pool_rss_tables(struct be_adapter *adapter) |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4394 | { |
| 4395 | struct be_port_resources port_res = {0}; |
| 4396 | u8 rss_tables_on_port; |
| 4397 | u16 max_vfs = be_max_vfs(adapter); |
| 4398 | |
| 4399 | be_cmd_get_profile_config(adapter, NULL, &port_res, SAVED_PROFILE_TYPE, |
| 4400 | RESOURCE_LIMITS, 0); |
| 4401 | |
| 4402 | rss_tables_on_port = MAX_PORT_RSS_TABLES - port_res.nic_pfs; |
| 4403 | |
| 4404 | /* Each PF Pool's RSS Tables limit = |
| 4405 | * PF's Max VFs / Total_Max_VFs on Port * RSS Tables on Port |
| 4406 | */ |
| 4407 | adapter->pool_res.max_rss_tables = |
| 4408 | max_vfs * rss_tables_on_port / port_res.max_vfs; |
| 4409 | } |
| 4410 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4411 | static int be_get_sriov_config(struct be_adapter *adapter) |
| 4412 | { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4413 | struct be_resources res = {0}; |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 4414 | int max_vfs, old_vfs; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4415 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4416 | be_cmd_get_profile_config(adapter, &res, NULL, ACTIVE_PROFILE_TYPE, |
| 4417 | RESOURCE_LIMITS, 0); |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 4418 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4419 | /* Some old versions of BE3 FW don't report max_vfs value */ |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4420 | if (BE3_chip(adapter) && !res.max_vfs) { |
| 4421 | max_vfs = pci_sriov_get_totalvfs(adapter->pdev); |
| 4422 | res.max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0; |
| 4423 | } |
| 4424 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 4425 | adapter->pool_res = res; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4426 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4427 | /* If during previous unload of the driver, the VFs were not disabled, |
| 4428 | * then we cannot rely on the PF POOL limits for the TotalVFs value. |
| 4429 | * Instead use the TotalVFs value stored in the pci-dev struct. |
| 4430 | */ |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4431 | old_vfs = pci_num_vf(adapter->pdev); |
| 4432 | if (old_vfs) { |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4433 | dev_info(&adapter->pdev->dev, "%d VFs are already enabled\n", |
| 4434 | old_vfs); |
| 4435 | |
| 4436 | adapter->pool_res.max_vfs = |
| 4437 | pci_sriov_get_totalvfs(adapter->pdev); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4438 | adapter->num_vfs = old_vfs; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4439 | } |
| 4440 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4441 | if (skyhawk_chip(adapter) && be_max_vfs(adapter) && !old_vfs) { |
| 4442 | be_calculate_pf_pool_rss_tables(adapter); |
| 4443 | dev_info(&adapter->pdev->dev, |
| 4444 | "RSS can be enabled for all VFs if num_vfs <= %d\n", |
| 4445 | be_max_pf_pool_rss_tables(adapter)); |
| 4446 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4447 | return 0; |
| 4448 | } |
| 4449 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4450 | static void be_alloc_sriov_res(struct be_adapter *adapter) |
| 4451 | { |
| 4452 | int old_vfs = pci_num_vf(adapter->pdev); |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4453 | struct be_resources vft_res = {0}; |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4454 | int status; |
| 4455 | |
| 4456 | be_get_sriov_config(adapter); |
| 4457 | |
| 4458 | if (!old_vfs) |
| 4459 | pci_sriov_set_totalvfs(adapter->pdev, be_max_vfs(adapter)); |
| 4460 | |
| 4461 | /* When the HW is in SRIOV capable configuration, the PF-pool |
| 4462 | * resources are given to PF during driver load, if there are no |
| 4463 | * old VFs. This facility is not available in BE3 FW. |
| 4464 | * Also, this is done by FW in Lancer chip. |
| 4465 | */ |
| 4466 | if (skyhawk_chip(adapter) && be_max_vfs(adapter) && !old_vfs) { |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4467 | be_calculate_vf_res(adapter, 0, &vft_res); |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4468 | status = be_cmd_set_sriov_config(adapter, adapter->pool_res, 0, |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4469 | &vft_res); |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4470 | if (status) |
| 4471 | dev_err(&adapter->pdev->dev, |
| 4472 | "Failed to optimize SRIOV resources\n"); |
| 4473 | } |
| 4474 | } |
| 4475 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4476 | static int be_get_resources(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4477 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4478 | struct device *dev = &adapter->pdev->dev; |
| 4479 | struct be_resources res = {0}; |
| 4480 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4481 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4482 | /* For Lancer, SH etc read per-function resource limits from FW. |
| 4483 | * GET_FUNC_CONFIG returns per function guaranteed limits. |
| 4484 | * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits |
| 4485 | */ |
Sathya Perla | ce7faf0 | 2016-06-22 08:54:53 -0400 | [diff] [blame] | 4486 | if (BEx_chip(adapter)) { |
| 4487 | BEx_get_resources(adapter, &res); |
| 4488 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4489 | status = be_cmd_get_func_config(adapter, &res); |
| 4490 | if (status) |
| 4491 | return status; |
| 4492 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 4493 | /* If a deafault RXQ must be created, we'll use up one RSSQ*/ |
| 4494 | if (res.max_rss_qs && res.max_rss_qs == res.max_rx_qs && |
| 4495 | !(res.if_cap_flags & BE_IF_FLAGS_DEFQ_RSS)) |
| 4496 | res.max_rss_qs -= 1; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
Sathya Perla | ce7faf0 | 2016-06-22 08:54:53 -0400 | [diff] [blame] | 4499 | /* If RoCE is supported stash away half the EQs for RoCE */ |
| 4500 | res.max_nic_evt_qs = be_roce_supported(adapter) ? |
| 4501 | res.max_evt_qs / 2 : res.max_evt_qs; |
| 4502 | adapter->res = res; |
| 4503 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 4504 | /* If FW supports RSS default queue, then skip creating non-RSS |
| 4505 | * queue for non-IP traffic. |
| 4506 | */ |
| 4507 | adapter->need_def_rxq = (be_if_cap_flags(adapter) & |
| 4508 | BE_IF_FLAGS_DEFQ_RSS) ? 0 : 1; |
| 4509 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 4510 | dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n", |
| 4511 | be_max_txqs(adapter), be_max_rxqs(adapter), |
Sathya Perla | ce7faf0 | 2016-06-22 08:54:53 -0400 | [diff] [blame] | 4512 | be_max_rss(adapter), be_max_nic_eqs(adapter), |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 4513 | be_max_vfs(adapter)); |
| 4514 | dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n", |
| 4515 | be_max_uc(adapter), be_max_mc(adapter), |
| 4516 | be_max_vlans(adapter)); |
| 4517 | |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 4518 | /* Ensure RX and TX queues are created in pairs at init time */ |
| 4519 | adapter->cfg_num_rx_irqs = |
| 4520 | min_t(u16, netif_get_num_default_rss_queues(), |
| 4521 | be_max_qp_irqs(adapter)); |
| 4522 | adapter->cfg_num_tx_irqs = adapter->cfg_num_rx_irqs; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4523 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4526 | static int be_get_config(struct be_adapter *adapter) |
| 4527 | { |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4528 | int status, level; |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4529 | u16 profile_id; |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4530 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4531 | status = be_cmd_get_cntl_attributes(adapter); |
| 4532 | if (status) |
| 4533 | return status; |
| 4534 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4535 | status = be_cmd_query_fw_cfg(adapter); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4536 | if (status) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4537 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4538 | |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 4539 | if (!lancer_chip(adapter) && be_physfn(adapter)) |
| 4540 | be_cmd_get_fat_dump_len(adapter, &adapter->fat_dump_len); |
| 4541 | |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4542 | if (BEx_chip(adapter)) { |
| 4543 | level = be_cmd_get_fw_log_level(adapter); |
| 4544 | adapter->msg_enable = |
| 4545 | level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0; |
| 4546 | } |
| 4547 | |
| 4548 | be_cmd_get_acpi_wol_cap(adapter); |
Sriharsha Basavapatna | 45f13df | 2016-06-06 07:22:09 -0400 | [diff] [blame] | 4549 | pci_enable_wake(adapter->pdev, PCI_D3hot, adapter->wol_en); |
| 4550 | pci_enable_wake(adapter->pdev, PCI_D3cold, adapter->wol_en); |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4551 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4552 | be_cmd_query_port_name(adapter); |
| 4553 | |
| 4554 | if (be_physfn(adapter)) { |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4555 | status = be_cmd_get_active_profile(adapter, &profile_id); |
| 4556 | if (!status) |
| 4557 | dev_info(&adapter->pdev->dev, |
| 4558 | "Using profile 0x%x\n", profile_id); |
Vasundhara Volam | 962bcb7 | 2014-07-17 16:20:30 +0530 | [diff] [blame] | 4559 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4560 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4561 | return 0; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4562 | } |
| 4563 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4564 | static int be_mac_setup(struct be_adapter *adapter) |
| 4565 | { |
| 4566 | u8 mac[ETH_ALEN]; |
| 4567 | int status; |
| 4568 | |
| 4569 | if (is_zero_ether_addr(adapter->netdev->dev_addr)) { |
| 4570 | status = be_cmd_get_perm_mac(adapter, mac); |
| 4571 | if (status) |
| 4572 | return status; |
| 4573 | |
| 4574 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 4575 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4576 | } |
| 4577 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4578 | return 0; |
| 4579 | } |
| 4580 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4581 | static void be_schedule_worker(struct be_adapter *adapter) |
| 4582 | { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4583 | queue_delayed_work(be_wq, &adapter->work, msecs_to_jiffies(1000)); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4584 | adapter->flags |= BE_FLAGS_WORKER_SCHEDULED; |
| 4585 | } |
| 4586 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4587 | static void be_destroy_err_recovery_workq(void) |
| 4588 | { |
| 4589 | if (!be_err_recovery_workq) |
| 4590 | return; |
| 4591 | |
| 4592 | flush_workqueue(be_err_recovery_workq); |
| 4593 | destroy_workqueue(be_err_recovery_workq); |
| 4594 | be_err_recovery_workq = NULL; |
| 4595 | } |
| 4596 | |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 4597 | static void be_schedule_err_detection(struct be_adapter *adapter, u32 delay) |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 4598 | { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4599 | struct be_error_recovery *err_rec = &adapter->error_recovery; |
| 4600 | |
| 4601 | if (!be_err_recovery_workq) |
| 4602 | return; |
| 4603 | |
| 4604 | queue_delayed_work(be_err_recovery_workq, &err_rec->err_detection_work, |
| 4605 | msecs_to_jiffies(delay)); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 4606 | adapter->flags |= BE_FLAGS_ERR_DETECTION_SCHEDULED; |
| 4607 | } |
| 4608 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4609 | static int be_setup_queues(struct be_adapter *adapter) |
| 4610 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4611 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4612 | int status; |
| 4613 | |
| 4614 | status = be_evt_queues_create(adapter); |
| 4615 | if (status) |
| 4616 | goto err; |
| 4617 | |
| 4618 | status = be_tx_qs_create(adapter); |
| 4619 | if (status) |
| 4620 | goto err; |
| 4621 | |
| 4622 | status = be_rx_cqs_create(adapter); |
| 4623 | if (status) |
| 4624 | goto err; |
| 4625 | |
| 4626 | status = be_mcc_queues_create(adapter); |
| 4627 | if (status) |
| 4628 | goto err; |
| 4629 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4630 | status = netif_set_real_num_rx_queues(netdev, adapter->num_rx_qs); |
| 4631 | if (status) |
| 4632 | goto err; |
| 4633 | |
| 4634 | status = netif_set_real_num_tx_queues(netdev, adapter->num_tx_qs); |
| 4635 | if (status) |
| 4636 | goto err; |
| 4637 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4638 | return 0; |
| 4639 | err: |
| 4640 | dev_err(&adapter->pdev->dev, "queue_setup failed\n"); |
| 4641 | return status; |
| 4642 | } |
| 4643 | |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4644 | static int be_if_create(struct be_adapter *adapter) |
| 4645 | { |
| 4646 | u32 en_flags = BE_IF_FLAGS_RSS | BE_IF_FLAGS_DEFQ_RSS; |
| 4647 | u32 cap_flags = be_if_cap_flags(adapter); |
| 4648 | int status; |
| 4649 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4650 | /* alloc required memory for other filtering fields */ |
| 4651 | adapter->pmac_id = kcalloc(be_max_uc(adapter), |
| 4652 | sizeof(*adapter->pmac_id), GFP_KERNEL); |
| 4653 | if (!adapter->pmac_id) |
| 4654 | return -ENOMEM; |
| 4655 | |
| 4656 | adapter->mc_list = kcalloc(be_max_mc(adapter), |
| 4657 | sizeof(*adapter->mc_list), GFP_KERNEL); |
| 4658 | if (!adapter->mc_list) |
| 4659 | return -ENOMEM; |
| 4660 | |
| 4661 | adapter->uc_list = kcalloc(be_max_uc(adapter), |
| 4662 | sizeof(*adapter->uc_list), GFP_KERNEL); |
| 4663 | if (!adapter->uc_list) |
| 4664 | return -ENOMEM; |
| 4665 | |
Sathya Perla | e261768 | 2016-06-22 08:54:54 -0400 | [diff] [blame] | 4666 | if (adapter->cfg_num_rx_irqs == 1) |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4667 | cap_flags &= ~(BE_IF_FLAGS_DEFQ_RSS | BE_IF_FLAGS_RSS); |
| 4668 | |
| 4669 | en_flags &= cap_flags; |
| 4670 | /* will enable all the needed filter flags in be_open() */ |
| 4671 | status = be_cmd_if_create(adapter, be_if_cap_flags(adapter), en_flags, |
| 4672 | &adapter->if_handle, 0); |
| 4673 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4674 | if (status) |
| 4675 | return status; |
| 4676 | |
| 4677 | return 0; |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4678 | } |
| 4679 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4680 | int be_update_queues(struct be_adapter *adapter) |
| 4681 | { |
| 4682 | struct net_device *netdev = adapter->netdev; |
| 4683 | int status; |
| 4684 | |
| 4685 | if (netif_running(netdev)) |
| 4686 | be_close(netdev); |
| 4687 | |
| 4688 | be_cancel_worker(adapter); |
| 4689 | |
| 4690 | /* If any vectors have been shared with RoCE we cannot re-program |
| 4691 | * the MSIx table. |
| 4692 | */ |
| 4693 | if (!adapter->num_msix_roce_vec) |
| 4694 | be_msix_disable(adapter); |
| 4695 | |
| 4696 | be_clear_queues(adapter); |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4697 | status = be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
| 4698 | if (status) |
| 4699 | return status; |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4700 | |
| 4701 | if (!msix_enabled(adapter)) { |
| 4702 | status = be_msix_enable(adapter); |
| 4703 | if (status) |
| 4704 | return status; |
| 4705 | } |
| 4706 | |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4707 | status = be_if_create(adapter); |
| 4708 | if (status) |
| 4709 | return status; |
| 4710 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4711 | status = be_setup_queues(adapter); |
| 4712 | if (status) |
| 4713 | return status; |
| 4714 | |
| 4715 | be_schedule_worker(adapter); |
| 4716 | |
| 4717 | if (netif_running(netdev)) |
| 4718 | status = be_open(netdev); |
| 4719 | |
| 4720 | return status; |
| 4721 | } |
| 4722 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 4723 | static inline int fw_major_num(const char *fw_ver) |
| 4724 | { |
| 4725 | int fw_major = 0, i; |
| 4726 | |
| 4727 | i = sscanf(fw_ver, "%d.", &fw_major); |
| 4728 | if (i != 1) |
| 4729 | return 0; |
| 4730 | |
| 4731 | return fw_major; |
| 4732 | } |
| 4733 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4734 | /* If it is error recovery, FLR the PF |
| 4735 | * Else if any VFs are already enabled don't FLR the PF |
| 4736 | */ |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4737 | static bool be_reset_required(struct be_adapter *adapter) |
| 4738 | { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4739 | if (be_error_recovering(adapter)) |
| 4740 | return true; |
| 4741 | else |
| 4742 | return pci_num_vf(adapter->pdev) == 0; |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | /* Wait for the FW to be ready and perform the required initialization */ |
| 4746 | static int be_func_init(struct be_adapter *adapter) |
| 4747 | { |
| 4748 | int status; |
| 4749 | |
| 4750 | status = be_fw_wait_ready(adapter); |
| 4751 | if (status) |
| 4752 | return status; |
| 4753 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4754 | /* FW is now ready; clear errors to allow cmds/doorbell */ |
| 4755 | be_clear_error(adapter, BE_CLEAR_ALL); |
| 4756 | |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4757 | if (be_reset_required(adapter)) { |
| 4758 | status = be_cmd_reset_function(adapter); |
| 4759 | if (status) |
| 4760 | return status; |
| 4761 | |
| 4762 | /* Wait for interrupts to quiesce after an FLR */ |
| 4763 | msleep(100); |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | /* Tell FW we're ready to fire cmds */ |
| 4767 | status = be_cmd_fw_init(adapter); |
| 4768 | if (status) |
| 4769 | return status; |
| 4770 | |
| 4771 | /* Allow interrupts for other ULPs running on NIC function */ |
| 4772 | be_intr_set(adapter, true); |
| 4773 | |
| 4774 | return 0; |
| 4775 | } |
| 4776 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4777 | static int be_setup(struct be_adapter *adapter) |
| 4778 | { |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4779 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4780 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4781 | |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4782 | status = be_func_init(adapter); |
| 4783 | if (status) |
| 4784 | return status; |
| 4785 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4786 | be_setup_init(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4787 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4788 | if (!lancer_chip(adapter)) |
| 4789 | be_cmd_req_native_mode(adapter); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4790 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4791 | /* invoke this cmd first to get pf_num and vf_num which are needed |
| 4792 | * for issuing profile related cmds |
| 4793 | */ |
| 4794 | if (!BEx_chip(adapter)) { |
| 4795 | status = be_cmd_get_func_config(adapter, NULL); |
| 4796 | if (status) |
| 4797 | return status; |
| 4798 | } |
Somnath Kotur | 72ef3a8 | 2015-10-12 03:47:20 -0400 | [diff] [blame] | 4799 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4800 | status = be_get_config(adapter); |
| 4801 | if (status) |
| 4802 | goto err; |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 4803 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4804 | if (!BE2_chip(adapter) && be_physfn(adapter)) |
| 4805 | be_alloc_sriov_res(adapter); |
| 4806 | |
| 4807 | status = be_get_resources(adapter); |
| 4808 | if (status) |
| 4809 | goto err; |
| 4810 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 4811 | status = be_msix_enable(adapter); |
| 4812 | if (status) |
| 4813 | goto err; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4814 | |
Kalesh AP | bcc8414 | 2015-08-05 03:27:48 -0400 | [diff] [blame] | 4815 | /* will enable all the needed filter flags in be_open() */ |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 4816 | status = be_if_create(adapter); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4817 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4818 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4819 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4820 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 4821 | rtnl_lock(); |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4822 | status = be_setup_queues(adapter); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4823 | rtnl_unlock(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4824 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4825 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4826 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4827 | be_cmd_get_fn_privileges(adapter, &adapter->cmd_privileges, 0); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4828 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4829 | status = be_mac_setup(adapter); |
| 4830 | if (status) |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 4831 | goto err; |
| 4832 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4833 | be_cmd_get_fw_ver(adapter); |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 4834 | dev_info(dev, "FW version is %s\n", adapter->fw_ver); |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 4835 | |
Somnath Kotur | e9e2a90 | 2013-10-24 14:37:53 +0530 | [diff] [blame] | 4836 | if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 4837 | 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] | 4838 | adapter->fw_ver); |
| 4839 | dev_err(dev, "Please upgrade firmware to version >= 4.0\n"); |
| 4840 | } |
| 4841 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 4842 | status = be_cmd_set_flow_control(adapter, adapter->tx_fc, |
| 4843 | adapter->rx_fc); |
| 4844 | if (status) |
| 4845 | be_cmd_get_flow_control(adapter, &adapter->tx_fc, |
| 4846 | &adapter->rx_fc); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 4847 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 4848 | dev_info(&adapter->pdev->dev, "HW Flow control - TX:%d RX:%d\n", |
| 4849 | adapter->tx_fc, adapter->rx_fc); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4850 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4851 | if (be_physfn(adapter)) |
| 4852 | be_cmd_set_logical_link_config(adapter, |
| 4853 | IFLA_VF_LINK_STATE_AUTO, 0); |
| 4854 | |
Somnath Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 4855 | /* BE3 EVB echoes broadcast/multicast packets back to PF's vport |
| 4856 | * confusing a linux bridge or OVS that it might be connected to. |
| 4857 | * Set the EVB to PASSTHRU mode which effectively disables the EVB |
| 4858 | * when SRIOV is not enabled. |
| 4859 | */ |
| 4860 | if (BE3_chip(adapter)) |
| 4861 | be_cmd_set_hsw_config(adapter, 0, 0, adapter->if_handle, |
| 4862 | PORT_FWD_TYPE_PASSTHRU, 0); |
| 4863 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4864 | if (adapter->num_vfs) |
| 4865 | be_vf_setup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4866 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4867 | status = be_cmd_get_phy_info(adapter); |
| 4868 | if (!status && be_pause_supported(adapter)) |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 4869 | adapter->phy.fc_autoneg = 1; |
| 4870 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4871 | if (be_physfn(adapter) && !lancer_chip(adapter)) |
| 4872 | be_cmd_set_features(adapter); |
| 4873 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4874 | be_schedule_worker(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 4875 | adapter->flags |= BE_FLAGS_SETUP_DONE; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4876 | return 0; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4877 | err: |
| 4878 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4879 | return status; |
| 4880 | } |
| 4881 | |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4882 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4883 | static void be_netpoll(struct net_device *netdev) |
| 4884 | { |
| 4885 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4886 | struct be_eq_obj *eqo; |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4887 | int i; |
| 4888 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 4889 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 4890 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0, 0); |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 4891 | napi_schedule(&eqo->napi); |
| 4892 | } |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4893 | } |
| 4894 | #endif |
| 4895 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4896 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 4897 | { |
| 4898 | const struct firmware *fw; |
| 4899 | int status; |
| 4900 | |
| 4901 | if (!netif_running(adapter->netdev)) { |
| 4902 | dev_err(&adapter->pdev->dev, |
| 4903 | "Firmware load not allowed (interface is down)\n"); |
Kalesh AP | 940a3fc | 2014-07-17 16:20:19 +0530 | [diff] [blame] | 4904 | return -ENETDOWN; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 4908 | if (status) |
| 4909 | goto fw_exit; |
| 4910 | |
| 4911 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 4912 | |
| 4913 | if (lancer_chip(adapter)) |
| 4914 | status = lancer_fw_download(adapter, fw); |
| 4915 | else |
| 4916 | status = be_fw_download(adapter, fw); |
| 4917 | |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4918 | if (!status) |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4919 | be_cmd_get_fw_ver(adapter); |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4920 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4921 | fw_exit: |
| 4922 | release_firmware(fw); |
| 4923 | return status; |
| 4924 | } |
| 4925 | |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 4926 | static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, |
| 4927 | u16 flags) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4928 | { |
| 4929 | struct be_adapter *adapter = netdev_priv(dev); |
| 4930 | struct nlattr *attr, *br_spec; |
| 4931 | int rem; |
| 4932 | int status = 0; |
| 4933 | u16 mode = 0; |
| 4934 | |
| 4935 | if (!sriov_enabled(adapter)) |
| 4936 | return -EOPNOTSUPP; |
| 4937 | |
| 4938 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 4939 | if (!br_spec) |
| 4940 | return -EINVAL; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4941 | |
| 4942 | nla_for_each_nested(attr, br_spec, rem) { |
| 4943 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 4944 | continue; |
| 4945 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 4946 | if (nla_len(attr) < sizeof(mode)) |
| 4947 | return -EINVAL; |
| 4948 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4949 | mode = nla_get_u16(attr); |
Suresh Reddy | ac0f5fb | 2015-12-30 01:28:57 -0500 | [diff] [blame] | 4950 | if (BE3_chip(adapter) && mode == BRIDGE_MODE_VEPA) |
| 4951 | return -EOPNOTSUPP; |
| 4952 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4953 | if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) |
| 4954 | return -EINVAL; |
| 4955 | |
| 4956 | status = be_cmd_set_hsw_config(adapter, 0, 0, |
| 4957 | adapter->if_handle, |
| 4958 | mode == BRIDGE_MODE_VEPA ? |
| 4959 | PORT_FWD_TYPE_VEPA : |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4960 | PORT_FWD_TYPE_VEB, 0); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4961 | if (status) |
| 4962 | goto err; |
| 4963 | |
| 4964 | dev_info(&adapter->pdev->dev, "enabled switch mode: %s\n", |
| 4965 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4966 | |
| 4967 | return status; |
| 4968 | } |
| 4969 | err: |
| 4970 | dev_err(&adapter->pdev->dev, "Failed to set switch mode %s\n", |
| 4971 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4972 | |
| 4973 | return status; |
| 4974 | } |
| 4975 | |
| 4976 | static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 4977 | struct net_device *dev, u32 filter_mask, |
| 4978 | int nlflags) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4979 | { |
| 4980 | struct be_adapter *adapter = netdev_priv(dev); |
| 4981 | int status = 0; |
| 4982 | u8 hsw_mode; |
| 4983 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4984 | /* BE and Lancer chips support VEB mode only */ |
| 4985 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
Ivan Vecera | 8431706 | 2016-02-11 12:42:26 +0100 | [diff] [blame] | 4986 | /* VEB is disabled in non-SR-IOV profiles on BE3/Lancer */ |
| 4987 | if (!pci_sriov_get_totalvfs(adapter->pdev)) |
| 4988 | return 0; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4989 | hsw_mode = PORT_FWD_TYPE_VEB; |
| 4990 | } else { |
| 4991 | status = be_cmd_get_hsw_config(adapter, NULL, 0, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4992 | adapter->if_handle, &hsw_mode, |
| 4993 | NULL); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4994 | if (status) |
| 4995 | return 0; |
Kalesh Purayil | ff9ed19 | 2015-07-10 05:32:44 -0400 | [diff] [blame] | 4996 | |
| 4997 | if (hsw_mode == PORT_FWD_TYPE_PASSTHRU) |
| 4998 | return 0; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
| 5002 | hsw_mode == PORT_FWD_TYPE_VEPA ? |
Scott Feldman | 2c3c031 | 2014-11-28 14:34:25 +0100 | [diff] [blame] | 5003 | BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 5004 | 0, 0, nlflags, filter_mask, NULL); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 5005 | } |
| 5006 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5007 | static struct be_cmd_work *be_alloc_work(struct be_adapter *adapter, |
| 5008 | void (*func)(struct work_struct *)) |
| 5009 | { |
| 5010 | struct be_cmd_work *work; |
| 5011 | |
| 5012 | work = kzalloc(sizeof(*work), GFP_ATOMIC); |
| 5013 | if (!work) { |
| 5014 | dev_err(&adapter->pdev->dev, |
| 5015 | "be_work memory allocation failed\n"); |
| 5016 | return NULL; |
| 5017 | } |
| 5018 | |
| 5019 | INIT_WORK(&work->work, func); |
| 5020 | work->adapter = adapter; |
| 5021 | return work; |
| 5022 | } |
| 5023 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5024 | /* VxLAN offload Notes: |
| 5025 | * |
| 5026 | * The stack defines tunnel offload flags (hw_enc_features) for IP and doesn't |
| 5027 | * distinguish various types of transports (VxLAN, GRE, NVGRE ..). So, offload |
| 5028 | * is expected to work across all types of IP tunnels once exported. Skyhawk |
| 5029 | * supports offloads for either VxLAN or NVGRE, exclusively. So we export VxLAN |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5030 | * offloads in hw_enc_features only when a VxLAN port is added. If other (non |
| 5031 | * VxLAN) tunnels are configured while VxLAN offloads are enabled, offloads for |
| 5032 | * those other tunnels are unexported on the fly through ndo_features_check(). |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5033 | * |
| 5034 | * Skyhawk supports VxLAN offloads only for one UDP dport. So, if the stack |
| 5035 | * adds more than one port, disable offloads and don't re-enable them again |
| 5036 | * until after all the tunnels are removed. |
| 5037 | */ |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5038 | static void be_work_add_vxlan_port(struct work_struct *work) |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5039 | { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5040 | struct be_cmd_work *cmd_work = |
| 5041 | container_of(work, struct be_cmd_work, work); |
| 5042 | struct be_adapter *adapter = cmd_work->adapter; |
| 5043 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5044 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5045 | __be16 port = cmd_work->info.vxlan_port; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5046 | int status; |
| 5047 | |
Jiri Benc | 1e5b311 | 2015-09-17 16:11:13 +0200 | [diff] [blame] | 5048 | if (adapter->vxlan_port == port && adapter->vxlan_port_count) { |
| 5049 | adapter->vxlan_port_aliases++; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5050 | goto done; |
Jiri Benc | 1e5b311 | 2015-09-17 16:11:13 +0200 | [diff] [blame] | 5051 | } |
| 5052 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5053 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5054 | dev_info(dev, |
| 5055 | "Only one UDP port supported for VxLAN offloads\n"); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5056 | dev_info(dev, "Disabling VxLAN offloads\n"); |
| 5057 | adapter->vxlan_port_count++; |
| 5058 | goto err; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5059 | } |
| 5060 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5061 | if (adapter->vxlan_port_count++ >= 1) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5062 | goto done; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5063 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5064 | status = be_cmd_manage_iface(adapter, adapter->if_handle, |
| 5065 | OP_CONVERT_NORMAL_TO_TUNNEL); |
| 5066 | if (status) { |
| 5067 | dev_warn(dev, "Failed to convert normal interface to tunnel\n"); |
| 5068 | goto err; |
| 5069 | } |
| 5070 | |
| 5071 | status = be_cmd_set_vxlan_port(adapter, port); |
| 5072 | if (status) { |
| 5073 | dev_warn(dev, "Failed to add VxLAN port\n"); |
| 5074 | goto err; |
| 5075 | } |
| 5076 | adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS; |
| 5077 | adapter->vxlan_port = port; |
| 5078 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5079 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 5080 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 5081 | NETIF_F_GSO_UDP_TUNNEL; |
| 5082 | netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 5083 | netdev->features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5084 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5085 | dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n", |
| 5086 | be16_to_cpu(port)); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5087 | goto done; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5088 | err: |
| 5089 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5090 | done: |
| 5091 | kfree(cmd_work); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5092 | } |
| 5093 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5094 | static void be_work_del_vxlan_port(struct work_struct *work) |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5095 | { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5096 | struct be_cmd_work *cmd_work = |
| 5097 | container_of(work, struct be_cmd_work, work); |
| 5098 | struct be_adapter *adapter = cmd_work->adapter; |
| 5099 | __be16 port = cmd_work->info.vxlan_port; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5100 | |
| 5101 | if (adapter->vxlan_port != port) |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5102 | goto done; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5103 | |
Jiri Benc | 1e5b311 | 2015-09-17 16:11:13 +0200 | [diff] [blame] | 5104 | if (adapter->vxlan_port_aliases) { |
| 5105 | adapter->vxlan_port_aliases--; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5106 | goto out; |
Jiri Benc | 1e5b311 | 2015-09-17 16:11:13 +0200 | [diff] [blame] | 5107 | } |
| 5108 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5109 | be_disable_vxlan_offloads(adapter); |
| 5110 | |
| 5111 | dev_info(&adapter->pdev->dev, |
| 5112 | "Disabled VxLAN offloads for UDP port %d\n", |
| 5113 | be16_to_cpu(port)); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5114 | done: |
| 5115 | adapter->vxlan_port_count--; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5116 | out: |
| 5117 | kfree(cmd_work); |
| 5118 | } |
| 5119 | |
| 5120 | static void be_cfg_vxlan_port(struct net_device *netdev, |
| 5121 | struct udp_tunnel_info *ti, |
| 5122 | void (*func)(struct work_struct *)) |
| 5123 | { |
| 5124 | struct be_adapter *adapter = netdev_priv(netdev); |
| 5125 | struct be_cmd_work *cmd_work; |
| 5126 | |
| 5127 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN) |
| 5128 | return; |
| 5129 | |
| 5130 | if (lancer_chip(adapter) || BEx_chip(adapter) || be_is_mc(adapter)) |
| 5131 | return; |
| 5132 | |
| 5133 | cmd_work = be_alloc_work(adapter, func); |
| 5134 | if (cmd_work) { |
| 5135 | cmd_work->info.vxlan_port = ti->port; |
| 5136 | queue_work(be_wq, &cmd_work->work); |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | static void be_del_vxlan_port(struct net_device *netdev, |
| 5141 | struct udp_tunnel_info *ti) |
| 5142 | { |
| 5143 | be_cfg_vxlan_port(netdev, ti, be_work_del_vxlan_port); |
| 5144 | } |
| 5145 | |
| 5146 | static void be_add_vxlan_port(struct net_device *netdev, |
| 5147 | struct udp_tunnel_info *ti) |
| 5148 | { |
| 5149 | be_cfg_vxlan_port(netdev, ti, be_work_add_vxlan_port); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5150 | } |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5151 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 5152 | static netdev_features_t be_features_check(struct sk_buff *skb, |
| 5153 | struct net_device *dev, |
| 5154 | netdev_features_t features) |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5155 | { |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5156 | struct be_adapter *adapter = netdev_priv(dev); |
| 5157 | u8 l4_hdr = 0; |
| 5158 | |
Vlad Yasevich | 9c6cfd5 | 2017-05-23 13:38:42 -0400 | [diff] [blame] | 5159 | /* The code below restricts offload features for some tunneled and |
| 5160 | * Q-in-Q packets. |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5161 | * Offload features for normal (non tunnel) packets are unchanged. |
| 5162 | */ |
Vlad Yasevich | 9c6cfd5 | 2017-05-23 13:38:42 -0400 | [diff] [blame] | 5163 | features = vlan_features_check(skb, features); |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5164 | if (!skb->encapsulation || |
| 5165 | !(adapter->flags & BE_FLAGS_VXLAN_OFFLOADS)) |
| 5166 | return features; |
| 5167 | |
| 5168 | /* It's an encapsulated packet and VxLAN offloads are enabled. We |
| 5169 | * should disable tunnel offload features if it's not a VxLAN packet, |
| 5170 | * as tunnel offloads have been enabled only for VxLAN. This is done to |
| 5171 | * allow other tunneled traffic like GRE work fine while VxLAN |
| 5172 | * offloads are configured in Skyhawk-R. |
| 5173 | */ |
| 5174 | switch (vlan_get_protocol(skb)) { |
| 5175 | case htons(ETH_P_IP): |
| 5176 | l4_hdr = ip_hdr(skb)->protocol; |
| 5177 | break; |
| 5178 | case htons(ETH_P_IPV6): |
| 5179 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 5180 | break; |
| 5181 | default: |
| 5182 | return features; |
| 5183 | } |
| 5184 | |
| 5185 | if (l4_hdr != IPPROTO_UDP || |
| 5186 | skb->inner_protocol_type != ENCAP_TYPE_ETHER || |
| 5187 | skb->inner_protocol != htons(ETH_P_TEB) || |
| 5188 | skb_inner_mac_header(skb) - skb_transport_header(skb) != |
| 5189 | sizeof(struct udphdr) + sizeof(struct vxlanhdr)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 5190 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5191 | |
| 5192 | return features; |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5193 | } |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5194 | |
Sriharsha Basavapatna | a155a5d | 2015-07-22 11:15:12 +0530 | [diff] [blame] | 5195 | static int be_get_phys_port_id(struct net_device *dev, |
| 5196 | struct netdev_phys_item_id *ppid) |
| 5197 | { |
| 5198 | int i, id_len = CNTL_SERIAL_NUM_WORDS * CNTL_SERIAL_NUM_WORD_SZ + 1; |
| 5199 | struct be_adapter *adapter = netdev_priv(dev); |
| 5200 | u8 *id; |
| 5201 | |
| 5202 | if (MAX_PHYS_ITEM_ID_LEN < id_len) |
| 5203 | return -ENOSPC; |
| 5204 | |
| 5205 | ppid->id[0] = adapter->hba_port_num + 1; |
| 5206 | id = &ppid->id[1]; |
| 5207 | for (i = CNTL_SERIAL_NUM_WORDS - 1; i >= 0; |
| 5208 | i--, id += CNTL_SERIAL_NUM_WORD_SZ) |
| 5209 | memcpy(id, &adapter->serial_num[i], CNTL_SERIAL_NUM_WORD_SZ); |
| 5210 | |
| 5211 | ppid->id_len = id_len; |
| 5212 | |
| 5213 | return 0; |
| 5214 | } |
| 5215 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5216 | static void be_set_rx_mode(struct net_device *dev) |
| 5217 | { |
| 5218 | struct be_adapter *adapter = netdev_priv(dev); |
| 5219 | struct be_cmd_work *work; |
| 5220 | |
| 5221 | work = be_alloc_work(adapter, be_work_set_rx_mode); |
| 5222 | if (work) |
| 5223 | queue_work(be_wq, &work->work); |
| 5224 | } |
| 5225 | |
stephen hemminger | e5686ad | 2012-01-05 19:10:25 +0000 | [diff] [blame] | 5226 | static const struct net_device_ops be_netdev_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5227 | .ndo_open = be_open, |
| 5228 | .ndo_stop = be_close, |
| 5229 | .ndo_start_xmit = be_xmit, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 5230 | .ndo_set_rx_mode = be_set_rx_mode, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5231 | .ndo_set_mac_address = be_mac_addr_set, |
| 5232 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 5233 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5234 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5235 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 5236 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 5237 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 5238 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 5239 | .ndo_set_vf_rate = be_set_vf_tx_rate, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 5240 | .ndo_get_vf_config = be_get_vf_config, |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 5241 | .ndo_set_vf_link_state = be_set_vf_link_state, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 5242 | .ndo_set_vf_spoofchk = be_set_vf_spoofchk, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 5243 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5244 | .ndo_poll_controller = be_netpoll, |
| 5245 | #endif |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 5246 | .ndo_bridge_setlink = be_ndo_bridge_setlink, |
| 5247 | .ndo_bridge_getlink = be_ndo_bridge_getlink, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5248 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5249 | .ndo_busy_poll = be_busy_poll, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5250 | #endif |
Alexander Duyck | bde6b7c | 2016-06-16 12:21:43 -0700 | [diff] [blame] | 5251 | .ndo_udp_tunnel_add = be_add_vxlan_port, |
| 5252 | .ndo_udp_tunnel_del = be_del_vxlan_port, |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 5253 | .ndo_features_check = be_features_check, |
Sriharsha Basavapatna | a155a5d | 2015-07-22 11:15:12 +0530 | [diff] [blame] | 5254 | .ndo_get_phys_port_id = be_get_phys_port_id, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5255 | }; |
| 5256 | |
| 5257 | static void be_netdev_init(struct net_device *netdev) |
| 5258 | { |
| 5259 | struct be_adapter *adapter = netdev_priv(netdev); |
| 5260 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 5261 | 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] | 5262 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 5263 | NETIF_F_HW_VLAN_CTAG_TX; |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 5264 | if ((be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS)) |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 5265 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 5266 | |
| 5267 | netdev->features |= netdev->hw_features | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 5268 | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 5269 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 5270 | 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] | 5271 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 5272 | |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 5273 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 5274 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5275 | netdev->flags |= IFF_MULTICAST; |
| 5276 | |
ajit.khaparde@broadcom.com | 127bfce | 2016-02-23 00:35:01 +0530 | [diff] [blame] | 5277 | netif_set_gso_max_size(netdev, BE_MAX_GSO_SIZE - ETH_HLEN); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 5278 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5279 | netdev->netdev_ops = &be_netdev_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5280 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 5281 | netdev->ethtool_ops = &be_ethtool_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5284 | static void be_cleanup(struct be_adapter *adapter) |
| 5285 | { |
| 5286 | struct net_device *netdev = adapter->netdev; |
| 5287 | |
| 5288 | rtnl_lock(); |
| 5289 | netif_device_detach(netdev); |
| 5290 | if (netif_running(netdev)) |
| 5291 | be_close(netdev); |
| 5292 | rtnl_unlock(); |
| 5293 | |
| 5294 | be_clear(adapter); |
| 5295 | } |
| 5296 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5297 | static int be_resume(struct be_adapter *adapter) |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5298 | { |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5299 | struct net_device *netdev = adapter->netdev; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5300 | int status; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5301 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5302 | status = be_setup(adapter); |
| 5303 | if (status) |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5304 | return status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5305 | |
Hannes Frederic Sowa | 08d9910 | 2016-04-18 21:19:42 +0200 | [diff] [blame] | 5306 | rtnl_lock(); |
| 5307 | if (netif_running(netdev)) |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5308 | status = be_open(netdev); |
Hannes Frederic Sowa | 08d9910 | 2016-04-18 21:19:42 +0200 | [diff] [blame] | 5309 | rtnl_unlock(); |
| 5310 | |
| 5311 | if (status) |
| 5312 | return status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5313 | |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5314 | netif_device_attach(netdev); |
| 5315 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5316 | return 0; |
| 5317 | } |
| 5318 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5319 | static void be_soft_reset(struct be_adapter *adapter) |
| 5320 | { |
| 5321 | u32 val; |
| 5322 | |
| 5323 | dev_info(&adapter->pdev->dev, "Initiating chip soft reset\n"); |
| 5324 | val = ioread32(adapter->pcicfg + SLIPORT_SOFTRESET_OFFSET); |
| 5325 | val |= SLIPORT_SOFTRESET_SR_MASK; |
| 5326 | iowrite32(val, adapter->pcicfg + SLIPORT_SOFTRESET_OFFSET); |
| 5327 | } |
| 5328 | |
| 5329 | static bool be_err_is_recoverable(struct be_adapter *adapter) |
| 5330 | { |
| 5331 | struct be_error_recovery *err_rec = &adapter->error_recovery; |
| 5332 | unsigned long initial_idle_time = |
| 5333 | msecs_to_jiffies(ERR_RECOVERY_IDLE_TIME); |
| 5334 | unsigned long recovery_interval = |
| 5335 | msecs_to_jiffies(ERR_RECOVERY_INTERVAL); |
| 5336 | u16 ue_err_code; |
| 5337 | u32 val; |
| 5338 | |
| 5339 | val = be_POST_stage_get(adapter); |
| 5340 | if ((val & POST_STAGE_RECOVERABLE_ERR) != POST_STAGE_RECOVERABLE_ERR) |
| 5341 | return false; |
| 5342 | ue_err_code = val & POST_ERR_RECOVERY_CODE_MASK; |
| 5343 | if (ue_err_code == 0) |
| 5344 | return false; |
| 5345 | |
| 5346 | dev_err(&adapter->pdev->dev, "Recoverable HW error code: 0x%x\n", |
| 5347 | ue_err_code); |
| 5348 | |
| 5349 | if (jiffies - err_rec->probe_time <= initial_idle_time) { |
| 5350 | dev_err(&adapter->pdev->dev, |
| 5351 | "Cannot recover within %lu sec from driver load\n", |
| 5352 | jiffies_to_msecs(initial_idle_time) / MSEC_PER_SEC); |
| 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | if (err_rec->last_recovery_time && |
| 5357 | (jiffies - err_rec->last_recovery_time <= recovery_interval)) { |
| 5358 | dev_err(&adapter->pdev->dev, |
| 5359 | "Cannot recover within %lu sec from last recovery\n", |
| 5360 | jiffies_to_msecs(recovery_interval) / MSEC_PER_SEC); |
| 5361 | return false; |
| 5362 | } |
| 5363 | |
| 5364 | if (ue_err_code == err_rec->last_err_code) { |
| 5365 | dev_err(&adapter->pdev->dev, |
| 5366 | "Cannot recover from a consecutive TPE error\n"); |
| 5367 | return false; |
| 5368 | } |
| 5369 | |
| 5370 | err_rec->last_recovery_time = jiffies; |
| 5371 | err_rec->last_err_code = ue_err_code; |
| 5372 | return true; |
| 5373 | } |
| 5374 | |
| 5375 | static int be_tpe_recover(struct be_adapter *adapter) |
| 5376 | { |
| 5377 | struct be_error_recovery *err_rec = &adapter->error_recovery; |
| 5378 | int status = -EAGAIN; |
| 5379 | u32 val; |
| 5380 | |
| 5381 | switch (err_rec->recovery_state) { |
| 5382 | case ERR_RECOVERY_ST_NONE: |
| 5383 | err_rec->recovery_state = ERR_RECOVERY_ST_DETECT; |
| 5384 | err_rec->resched_delay = ERR_RECOVERY_UE_DETECT_DURATION; |
| 5385 | break; |
| 5386 | |
| 5387 | case ERR_RECOVERY_ST_DETECT: |
| 5388 | val = be_POST_stage_get(adapter); |
| 5389 | if ((val & POST_STAGE_RECOVERABLE_ERR) != |
| 5390 | POST_STAGE_RECOVERABLE_ERR) { |
| 5391 | dev_err(&adapter->pdev->dev, |
| 5392 | "Unrecoverable HW error detected: 0x%x\n", val); |
| 5393 | status = -EINVAL; |
| 5394 | err_rec->resched_delay = 0; |
| 5395 | break; |
| 5396 | } |
| 5397 | |
| 5398 | dev_err(&adapter->pdev->dev, "Recoverable HW error detected\n"); |
| 5399 | |
| 5400 | /* Only PF0 initiates Chip Soft Reset. But PF0 must wait UE2SR |
| 5401 | * milliseconds before it checks for final error status in |
| 5402 | * SLIPORT_SEMAPHORE to determine if recovery criteria is met. |
| 5403 | * If it does, then PF0 initiates a Soft Reset. |
| 5404 | */ |
| 5405 | if (adapter->pf_num == 0) { |
| 5406 | err_rec->recovery_state = ERR_RECOVERY_ST_RESET; |
| 5407 | err_rec->resched_delay = err_rec->ue_to_reset_time - |
| 5408 | ERR_RECOVERY_UE_DETECT_DURATION; |
| 5409 | break; |
| 5410 | } |
| 5411 | |
| 5412 | err_rec->recovery_state = ERR_RECOVERY_ST_PRE_POLL; |
| 5413 | err_rec->resched_delay = err_rec->ue_to_poll_time - |
| 5414 | ERR_RECOVERY_UE_DETECT_DURATION; |
| 5415 | break; |
| 5416 | |
| 5417 | case ERR_RECOVERY_ST_RESET: |
| 5418 | if (!be_err_is_recoverable(adapter)) { |
| 5419 | dev_err(&adapter->pdev->dev, |
| 5420 | "Failed to meet recovery criteria\n"); |
| 5421 | status = -EIO; |
| 5422 | err_rec->resched_delay = 0; |
| 5423 | break; |
| 5424 | } |
| 5425 | be_soft_reset(adapter); |
| 5426 | err_rec->recovery_state = ERR_RECOVERY_ST_PRE_POLL; |
| 5427 | err_rec->resched_delay = err_rec->ue_to_poll_time - |
| 5428 | err_rec->ue_to_reset_time; |
| 5429 | break; |
| 5430 | |
| 5431 | case ERR_RECOVERY_ST_PRE_POLL: |
| 5432 | err_rec->recovery_state = ERR_RECOVERY_ST_REINIT; |
| 5433 | err_rec->resched_delay = 0; |
| 5434 | status = 0; /* done */ |
| 5435 | break; |
| 5436 | |
| 5437 | default: |
| 5438 | status = -EINVAL; |
| 5439 | err_rec->resched_delay = 0; |
| 5440 | break; |
| 5441 | } |
| 5442 | |
| 5443 | return status; |
| 5444 | } |
| 5445 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5446 | static int be_err_recover(struct be_adapter *adapter) |
| 5447 | { |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5448 | int status; |
| 5449 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5450 | if (!lancer_chip(adapter)) { |
| 5451 | if (!adapter->error_recovery.recovery_supported || |
| 5452 | adapter->priv_flags & BE_DISABLE_TPE_RECOVERY) |
| 5453 | return -EIO; |
| 5454 | status = be_tpe_recover(adapter); |
| 5455 | if (status) |
| 5456 | goto err; |
| 5457 | } |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5458 | |
| 5459 | /* Wait for adapter to reach quiescent state before |
| 5460 | * destroying queues |
| 5461 | */ |
| 5462 | status = be_fw_wait_ready(adapter); |
| 5463 | if (status) |
| 5464 | goto err; |
| 5465 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5466 | adapter->flags |= BE_FLAGS_TRY_RECOVERY; |
| 5467 | |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5468 | be_cleanup(adapter); |
| 5469 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5470 | status = be_resume(adapter); |
| 5471 | if (status) |
| 5472 | goto err; |
| 5473 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5474 | adapter->flags &= ~BE_FLAGS_TRY_RECOVERY; |
| 5475 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5476 | err: |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5477 | return status; |
| 5478 | } |
| 5479 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5480 | static void be_err_detection_task(struct work_struct *work) |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5481 | { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5482 | struct be_error_recovery *err_rec = |
| 5483 | container_of(work, struct be_error_recovery, |
| 5484 | err_detection_work.work); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5485 | struct be_adapter *adapter = |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5486 | container_of(err_rec, struct be_adapter, |
| 5487 | error_recovery); |
| 5488 | u32 resched_delay = ERR_RECOVERY_DETECTION_DELAY; |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5489 | struct device *dev = &adapter->pdev->dev; |
| 5490 | int recovery_status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5491 | |
| 5492 | be_detect_error(adapter); |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5493 | if (!be_check_error(adapter, BE_ERROR_HW)) |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5494 | goto reschedule_task; |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5495 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5496 | recovery_status = be_err_recover(adapter); |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5497 | if (!recovery_status) { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5498 | err_rec->recovery_retries = 0; |
| 5499 | err_rec->recovery_state = ERR_RECOVERY_ST_NONE; |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5500 | dev_info(dev, "Adapter recovery successful\n"); |
| 5501 | goto reschedule_task; |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5502 | } else if (!lancer_chip(adapter) && err_rec->resched_delay) { |
| 5503 | /* BEx/SH recovery state machine */ |
| 5504 | if (adapter->pf_num == 0 && |
| 5505 | err_rec->recovery_state > ERR_RECOVERY_ST_DETECT) |
| 5506 | dev_err(&adapter->pdev->dev, |
| 5507 | "Adapter recovery in progress\n"); |
| 5508 | resched_delay = err_rec->resched_delay; |
| 5509 | goto reschedule_task; |
| 5510 | } else if (lancer_chip(adapter) && be_virtfn(adapter)) { |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5511 | /* For VFs, check if PF have allocated resources |
| 5512 | * every second. |
| 5513 | */ |
| 5514 | dev_err(dev, "Re-trying adapter recovery\n"); |
| 5515 | goto reschedule_task; |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5516 | } else if (lancer_chip(adapter) && err_rec->recovery_retries++ < |
| 5517 | ERR_RECOVERY_MAX_RETRY_COUNT) { |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 5518 | /* In case of another error during recovery, it takes 30 sec |
| 5519 | * for adapter to come out of error. Retry error recovery after |
| 5520 | * this time interval. |
| 5521 | */ |
| 5522 | dev_err(&adapter->pdev->dev, "Re-trying adapter recovery\n"); |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5523 | resched_delay = ERR_RECOVERY_RETRY_DELAY; |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 5524 | goto reschedule_task; |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5525 | } else { |
| 5526 | dev_err(dev, "Adapter recovery failed\n"); |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5527 | dev_err(dev, "Please reboot server to recover\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5528 | } |
| 5529 | |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5530 | return; |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5531 | |
Padmanabh Ratnakar | 1babbad | 2016-02-03 09:49:21 +0530 | [diff] [blame] | 5532 | reschedule_task: |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5533 | be_schedule_err_detection(adapter, resched_delay); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5534 | } |
| 5535 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5536 | static void be_log_sfp_info(struct be_adapter *adapter) |
| 5537 | { |
| 5538 | int status; |
| 5539 | |
| 5540 | status = be_cmd_query_sfp_info(adapter); |
| 5541 | if (!status) { |
| 5542 | dev_err(&adapter->pdev->dev, |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 5543 | "Port %c: %s Vendor: %s part no: %s", |
| 5544 | adapter->port_name, |
| 5545 | be_misconfig_evt_port_state[adapter->phy_state], |
| 5546 | adapter->phy.vendor_name, |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5547 | adapter->phy.vendor_pn); |
| 5548 | } |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 5549 | adapter->flags &= ~BE_FLAGS_PHY_MISCONFIGURED; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5550 | } |
| 5551 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5552 | static void be_worker(struct work_struct *work) |
| 5553 | { |
| 5554 | struct be_adapter *adapter = |
| 5555 | container_of(work, struct be_adapter, work.work); |
| 5556 | struct be_rx_obj *rxo; |
| 5557 | int i; |
| 5558 | |
Guilherme G. Piccoli | d348061 | 2016-07-26 17:39:42 -0300 | [diff] [blame] | 5559 | if (be_physfn(adapter) && |
| 5560 | MODULO(adapter->work_counter, adapter->be_get_temp_freq) == 0) |
| 5561 | be_cmd_get_die_temperature(adapter); |
| 5562 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5563 | /* when interrupts are not yet enabled, just reap any pending |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5564 | * mcc completions |
| 5565 | */ |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5566 | if (!netif_running(adapter->netdev)) { |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5567 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5568 | be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5569 | local_bh_enable(); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5570 | goto reschedule; |
| 5571 | } |
| 5572 | |
| 5573 | if (!adapter->stats_cmd_sent) { |
| 5574 | if (lancer_chip(adapter)) |
| 5575 | lancer_cmd_get_pport_stats(adapter, |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 5576 | &adapter->stats_cmd); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5577 | else |
| 5578 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 5579 | } |
| 5580 | |
| 5581 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5582 | /* Replenish RX-queues starved due to memory |
| 5583 | * allocation failures. |
| 5584 | */ |
| 5585 | if (rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 5586 | be_post_rx_frags(rxo, GFP_KERNEL, MAX_RX_POST); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 5589 | /* EQ-delay update for Skyhawk is done while notifying EQ */ |
| 5590 | if (!skyhawk_chip(adapter)) |
| 5591 | be_eqd_update(adapter, false); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5592 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 5593 | if (adapter->flags & BE_FLAGS_PHY_MISCONFIGURED) |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5594 | be_log_sfp_info(adapter); |
| 5595 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5596 | reschedule: |
| 5597 | adapter->work_counter++; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5598 | queue_delayed_work(be_wq, &adapter->work, msecs_to_jiffies(1000)); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5601 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 5602 | { |
| 5603 | if (adapter->csr) |
| 5604 | pci_iounmap(adapter->pdev, adapter->csr); |
| 5605 | if (adapter->db) |
| 5606 | pci_iounmap(adapter->pdev, adapter->db); |
Douglas Miller | a69bf3c | 2016-03-04 15:36:56 -0600 | [diff] [blame] | 5607 | if (adapter->pcicfg && adapter->pcicfg_mapped) |
| 5608 | pci_iounmap(adapter->pdev, adapter->pcicfg); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | static int db_bar(struct be_adapter *adapter) |
| 5612 | { |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 5613 | if (lancer_chip(adapter) || be_virtfn(adapter)) |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5614 | return 0; |
| 5615 | else |
| 5616 | return 4; |
| 5617 | } |
| 5618 | |
| 5619 | static int be_roce_map_pci_bars(struct be_adapter *adapter) |
| 5620 | { |
| 5621 | if (skyhawk_chip(adapter)) { |
| 5622 | adapter->roce_db.size = 4096; |
| 5623 | adapter->roce_db.io_addr = pci_resource_start(adapter->pdev, |
| 5624 | db_bar(adapter)); |
| 5625 | adapter->roce_db.total_size = pci_resource_len(adapter->pdev, |
| 5626 | db_bar(adapter)); |
| 5627 | } |
| 5628 | return 0; |
| 5629 | } |
| 5630 | |
| 5631 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 5632 | { |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5633 | struct pci_dev *pdev = adapter->pdev; |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5634 | u8 __iomem *addr; |
| 5635 | u32 sli_intf; |
| 5636 | |
| 5637 | pci_read_config_dword(adapter->pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 5638 | adapter->sli_family = (sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 5639 | SLI_INTF_FAMILY_SHIFT; |
| 5640 | adapter->virtfn = (sli_intf & SLI_INTF_FT_MASK) ? 1 : 0; |
| 5641 | |
| 5642 | if (BEx_chip(adapter) && be_physfn(adapter)) { |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5643 | adapter->csr = pci_iomap(pdev, 2, 0); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5644 | if (!adapter->csr) |
| 5645 | return -ENOMEM; |
| 5646 | } |
| 5647 | |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5648 | addr = pci_iomap(pdev, db_bar(adapter), 0); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5649 | if (!addr) |
| 5650 | goto pci_map_err; |
| 5651 | adapter->db = addr; |
| 5652 | |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5653 | if (skyhawk_chip(adapter) || BEx_chip(adapter)) { |
| 5654 | if (be_physfn(adapter)) { |
| 5655 | /* PCICFG is the 2nd BAR in BE2 */ |
| 5656 | addr = pci_iomap(pdev, BE2_chip(adapter) ? 1 : 0, 0); |
| 5657 | if (!addr) |
| 5658 | goto pci_map_err; |
| 5659 | adapter->pcicfg = addr; |
Douglas Miller | a69bf3c | 2016-03-04 15:36:56 -0600 | [diff] [blame] | 5660 | adapter->pcicfg_mapped = true; |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5661 | } else { |
| 5662 | adapter->pcicfg = adapter->db + SRIOV_VF_PCICFG_OFFSET; |
Douglas Miller | a69bf3c | 2016-03-04 15:36:56 -0600 | [diff] [blame] | 5663 | adapter->pcicfg_mapped = false; |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5664 | } |
| 5665 | } |
| 5666 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5667 | be_roce_map_pci_bars(adapter); |
| 5668 | return 0; |
| 5669 | |
| 5670 | pci_map_err: |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5671 | dev_err(&pdev->dev, "Error in mapping PCI BARs\n"); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5672 | be_unmap_pci_bars(adapter); |
| 5673 | return -ENOMEM; |
| 5674 | } |
| 5675 | |
| 5676 | static void be_drv_cleanup(struct be_adapter *adapter) |
| 5677 | { |
| 5678 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
| 5679 | struct device *dev = &adapter->pdev->dev; |
| 5680 | |
| 5681 | if (mem->va) |
| 5682 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5683 | |
| 5684 | mem = &adapter->rx_filter; |
| 5685 | if (mem->va) |
| 5686 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5687 | |
| 5688 | mem = &adapter->stats_cmd; |
| 5689 | if (mem->va) |
| 5690 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5691 | } |
| 5692 | |
| 5693 | /* Allocate and initialize various fields in be_adapter struct */ |
| 5694 | static int be_drv_init(struct be_adapter *adapter) |
| 5695 | { |
| 5696 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 5697 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
| 5698 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
| 5699 | struct be_dma_mem *stats_cmd = &adapter->stats_cmd; |
| 5700 | struct device *dev = &adapter->pdev->dev; |
| 5701 | int status = 0; |
| 5702 | |
| 5703 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 5704 | mbox_mem_alloc->va = dma_zalloc_coherent(dev, mbox_mem_alloc->size, |
| 5705 | &mbox_mem_alloc->dma, |
| 5706 | GFP_KERNEL); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5707 | if (!mbox_mem_alloc->va) |
| 5708 | return -ENOMEM; |
| 5709 | |
| 5710 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 5711 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 5712 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5713 | |
| 5714 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
| 5715 | rx_filter->va = dma_zalloc_coherent(dev, rx_filter->size, |
| 5716 | &rx_filter->dma, GFP_KERNEL); |
| 5717 | if (!rx_filter->va) { |
| 5718 | status = -ENOMEM; |
| 5719 | goto free_mbox; |
| 5720 | } |
| 5721 | |
| 5722 | if (lancer_chip(adapter)) |
| 5723 | stats_cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 5724 | else if (BE2_chip(adapter)) |
| 5725 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
| 5726 | else if (BE3_chip(adapter)) |
| 5727 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
| 5728 | else |
| 5729 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v2); |
| 5730 | stats_cmd->va = dma_zalloc_coherent(dev, stats_cmd->size, |
| 5731 | &stats_cmd->dma, GFP_KERNEL); |
| 5732 | if (!stats_cmd->va) { |
| 5733 | status = -ENOMEM; |
| 5734 | goto free_rx_filter; |
| 5735 | } |
| 5736 | |
| 5737 | mutex_init(&adapter->mbox_lock); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5738 | mutex_init(&adapter->mcc_lock); |
| 5739 | mutex_init(&adapter->rx_filter_lock); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5740 | spin_lock_init(&adapter->mcc_cq_lock); |
| 5741 | init_completion(&adapter->et_cmd_compl); |
| 5742 | |
| 5743 | pci_save_state(adapter->pdev); |
| 5744 | |
| 5745 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5746 | |
| 5747 | adapter->error_recovery.recovery_state = ERR_RECOVERY_ST_NONE; |
| 5748 | adapter->error_recovery.resched_delay = 0; |
| 5749 | INIT_DELAYED_WORK(&adapter->error_recovery.err_detection_work, |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5750 | be_err_detection_task); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5751 | |
| 5752 | adapter->rx_fc = true; |
| 5753 | adapter->tx_fc = true; |
| 5754 | |
| 5755 | /* Must be a power of 2 or else MODULO will BUG_ON */ |
| 5756 | adapter->be_get_temp_freq = 64; |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5757 | |
| 5758 | return 0; |
| 5759 | |
| 5760 | free_rx_filter: |
| 5761 | dma_free_coherent(dev, rx_filter->size, rx_filter->va, rx_filter->dma); |
| 5762 | free_mbox: |
| 5763 | dma_free_coherent(dev, mbox_mem_alloc->size, mbox_mem_alloc->va, |
| 5764 | mbox_mem_alloc->dma); |
| 5765 | return status; |
| 5766 | } |
| 5767 | |
| 5768 | static void be_remove(struct pci_dev *pdev) |
| 5769 | { |
| 5770 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5771 | |
| 5772 | if (!adapter) |
| 5773 | return; |
| 5774 | |
| 5775 | be_roce_dev_remove(adapter); |
| 5776 | be_intr_set(adapter, false); |
| 5777 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5778 | be_cancel_err_detection(adapter); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5779 | |
| 5780 | unregister_netdev(adapter->netdev); |
| 5781 | |
| 5782 | be_clear(adapter); |
| 5783 | |
Somnath Kotur | f72099e | 2016-09-07 19:57:50 +0530 | [diff] [blame] | 5784 | if (!pci_vfs_assigned(adapter->pdev)) |
| 5785 | be_cmd_reset_function(adapter); |
| 5786 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5787 | /* tell fw we're done with firing cmds */ |
| 5788 | be_cmd_fw_clean(adapter); |
| 5789 | |
| 5790 | be_unmap_pci_bars(adapter); |
| 5791 | be_drv_cleanup(adapter); |
| 5792 | |
| 5793 | pci_disable_pcie_error_reporting(pdev); |
| 5794 | |
| 5795 | pci_release_regions(pdev); |
| 5796 | pci_disable_device(pdev); |
| 5797 | |
| 5798 | free_netdev(adapter->netdev); |
| 5799 | } |
| 5800 | |
Arnd Bergmann | 9a03259 | 2015-05-18 23:06:45 +0200 | [diff] [blame] | 5801 | static ssize_t be_hwmon_show_temp(struct device *dev, |
| 5802 | struct device_attribute *dev_attr, |
| 5803 | char *buf) |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 5804 | { |
| 5805 | struct be_adapter *adapter = dev_get_drvdata(dev); |
| 5806 | |
| 5807 | /* Unit: millidegree Celsius */ |
| 5808 | if (adapter->hwmon_info.be_on_die_temp == BE_INVALID_DIE_TEMP) |
| 5809 | return -EIO; |
| 5810 | else |
| 5811 | return sprintf(buf, "%u\n", |
| 5812 | adapter->hwmon_info.be_on_die_temp * 1000); |
| 5813 | } |
| 5814 | |
| 5815 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
| 5816 | be_hwmon_show_temp, NULL, 1); |
| 5817 | |
| 5818 | static struct attribute *be_hwmon_attrs[] = { |
| 5819 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 5820 | NULL |
| 5821 | }; |
| 5822 | |
| 5823 | ATTRIBUTE_GROUPS(be_hwmon); |
| 5824 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5825 | static char *mc_name(struct be_adapter *adapter) |
| 5826 | { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 5827 | char *str = ""; /* default */ |
| 5828 | |
| 5829 | switch (adapter->mc_type) { |
| 5830 | case UMC: |
| 5831 | str = "UMC"; |
| 5832 | break; |
| 5833 | case FLEX10: |
| 5834 | str = "FLEX10"; |
| 5835 | break; |
| 5836 | case vNIC1: |
| 5837 | str = "vNIC-1"; |
| 5838 | break; |
| 5839 | case nPAR: |
| 5840 | str = "nPAR"; |
| 5841 | break; |
| 5842 | case UFP: |
| 5843 | str = "UFP"; |
| 5844 | break; |
| 5845 | case vNIC2: |
| 5846 | str = "vNIC-2"; |
| 5847 | break; |
| 5848 | default: |
| 5849 | str = ""; |
| 5850 | } |
| 5851 | |
| 5852 | return str; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | static inline char *func_name(struct be_adapter *adapter) |
| 5856 | { |
| 5857 | return be_physfn(adapter) ? "PF" : "VF"; |
| 5858 | } |
| 5859 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 5860 | static inline char *nic_name(struct pci_dev *pdev) |
| 5861 | { |
| 5862 | switch (pdev->device) { |
| 5863 | case OC_DEVICE_ID1: |
| 5864 | return OC_NAME; |
| 5865 | case OC_DEVICE_ID2: |
| 5866 | return OC_NAME_BE; |
| 5867 | case OC_DEVICE_ID3: |
| 5868 | case OC_DEVICE_ID4: |
| 5869 | return OC_NAME_LANCER; |
| 5870 | case BE_DEVICE_ID2: |
| 5871 | return BE3_NAME; |
| 5872 | case OC_DEVICE_ID5: |
| 5873 | case OC_DEVICE_ID6: |
| 5874 | return OC_NAME_SH; |
| 5875 | default: |
| 5876 | return BE_NAME; |
| 5877 | } |
| 5878 | } |
| 5879 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 5880 | 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] | 5881 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5882 | struct be_adapter *adapter; |
| 5883 | struct net_device *netdev; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5884 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5885 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 5886 | dev_info(&pdev->dev, "%s version is %s\n", DRV_NAME, DRV_VER); |
| 5887 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5888 | status = pci_enable_device(pdev); |
| 5889 | if (status) |
| 5890 | goto do_none; |
| 5891 | |
| 5892 | status = pci_request_regions(pdev, DRV_NAME); |
| 5893 | if (status) |
| 5894 | goto disable_dev; |
| 5895 | pci_set_master(pdev); |
| 5896 | |
Sathya Perla | 7f64006 | 2012-06-05 19:37:20 +0000 | [diff] [blame] | 5897 | netdev = alloc_etherdev_mqs(sizeof(*adapter), MAX_TX_QS, MAX_RX_QS); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 5898 | if (!netdev) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5899 | status = -ENOMEM; |
| 5900 | goto rel_reg; |
| 5901 | } |
| 5902 | adapter = netdev_priv(netdev); |
| 5903 | adapter->pdev = pdev; |
| 5904 | pci_set_drvdata(pdev, adapter); |
| 5905 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5906 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5907 | |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5908 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5909 | if (!status) { |
| 5910 | netdev->features |= NETIF_F_HIGHDMA; |
| 5911 | } else { |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5912 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5913 | if (status) { |
| 5914 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 5915 | goto free_netdev; |
| 5916 | } |
| 5917 | } |
| 5918 | |
Kalesh AP | 2f951a9 | 2014-09-12 17:39:21 +0530 | [diff] [blame] | 5919 | status = pci_enable_pcie_error_reporting(pdev); |
| 5920 | if (!status) |
| 5921 | dev_info(&pdev->dev, "PCIe error reporting enabled\n"); |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 5922 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5923 | status = be_map_pci_bars(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5924 | if (status) |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5925 | goto free_netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5926 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5927 | status = be_drv_init(adapter); |
| 5928 | if (status) |
| 5929 | goto unmap_bars; |
| 5930 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5931 | status = be_setup(adapter); |
| 5932 | if (status) |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5933 | goto drv_cleanup; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5934 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 5935 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5936 | status = register_netdev(netdev); |
| 5937 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5938 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5939 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 5940 | be_roce_dev_add(adapter); |
| 5941 | |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 5942 | be_schedule_err_detection(adapter, ERR_DETECTION_DELAY); |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 5943 | adapter->error_recovery.probe_time = jiffies; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 5944 | |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 5945 | /* On Die temperature not supported for VF. */ |
Arnd Bergmann | 9a03259 | 2015-05-18 23:06:45 +0200 | [diff] [blame] | 5946 | if (be_physfn(adapter) && IS_ENABLED(CONFIG_BE2NET_HWMON)) { |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 5947 | adapter->hwmon_info.hwmon_dev = |
| 5948 | devm_hwmon_device_register_with_groups(&pdev->dev, |
| 5949 | DRV_NAME, |
| 5950 | adapter, |
| 5951 | be_hwmon_groups); |
| 5952 | adapter->hwmon_info.be_on_die_temp = BE_INVALID_DIE_TEMP; |
| 5953 | } |
| 5954 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5955 | dev_info(&pdev->dev, "%s: %s %s port %c\n", nic_name(pdev), |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5956 | func_name(adapter), mc_name(adapter), adapter->port_name); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 5957 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5958 | return 0; |
| 5959 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5960 | unsetup: |
| 5961 | be_clear(adapter); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5962 | drv_cleanup: |
| 5963 | be_drv_cleanup(adapter); |
| 5964 | unmap_bars: |
| 5965 | be_unmap_pci_bars(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 5966 | free_netdev: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 5967 | free_netdev(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5968 | rel_reg: |
| 5969 | pci_release_regions(pdev); |
| 5970 | disable_dev: |
| 5971 | pci_disable_device(pdev); |
| 5972 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 5973 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5974 | return status; |
| 5975 | } |
| 5976 | |
| 5977 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5978 | { |
| 5979 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5980 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 5981 | be_intr_set(adapter, false); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5982 | be_cancel_err_detection(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5983 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5984 | be_cleanup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5985 | |
| 5986 | pci_save_state(pdev); |
| 5987 | pci_disable_device(pdev); |
| 5988 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5989 | return 0; |
| 5990 | } |
| 5991 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5992 | static int be_pci_resume(struct pci_dev *pdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5993 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5994 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5995 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5996 | |
| 5997 | status = pci_enable_device(pdev); |
| 5998 | if (status) |
| 5999 | return status; |
| 6000 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6001 | pci_restore_state(pdev); |
| 6002 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 6003 | status = be_resume(adapter); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 6004 | if (status) |
| 6005 | return status; |
| 6006 | |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 6007 | be_schedule_err_detection(adapter, ERR_DETECTION_DELAY); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 6008 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6009 | return 0; |
| 6010 | } |
| 6011 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6012 | /* |
| 6013 | * An FLR will stop BE from DMAing any data. |
| 6014 | */ |
| 6015 | static void be_shutdown(struct pci_dev *pdev) |
| 6016 | { |
| 6017 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6018 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 6019 | if (!adapter) |
| 6020 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6021 | |
Devesh Sharma | d114f99 | 2014-06-10 19:32:15 +0530 | [diff] [blame] | 6022 | be_roce_dev_shutdown(adapter); |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 6023 | cancel_delayed_work_sync(&adapter->work); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 6024 | be_cancel_err_detection(adapter); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 6025 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 6026 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6027 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 6028 | be_cmd_reset_function(adapter); |
| 6029 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6030 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6033 | 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] | 6034 | pci_channel_state_t state) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6035 | { |
| 6036 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6037 | |
| 6038 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 6039 | |
Padmanabh Ratnakar | 68f2279 | 2016-02-18 03:09:34 +0530 | [diff] [blame] | 6040 | be_roce_dev_remove(adapter); |
| 6041 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 6042 | if (!be_check_error(adapter, BE_ERROR_EEH)) { |
| 6043 | be_set_error(adapter, BE_ERROR_EEH); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6044 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 6045 | be_cancel_err_detection(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 6046 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 6047 | be_cleanup(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6048 | } |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6049 | |
| 6050 | if (state == pci_channel_io_perm_failure) |
| 6051 | return PCI_ERS_RESULT_DISCONNECT; |
| 6052 | |
| 6053 | pci_disable_device(pdev); |
| 6054 | |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 6055 | /* The error could cause the FW to trigger a flash debug dump. |
| 6056 | * Resetting the card while flash dump is in progress |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 6057 | * can cause it not to recover; wait for it to finish. |
| 6058 | * Wait only for first function as it is needed only once per |
| 6059 | * adapter. |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 6060 | */ |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 6061 | if (pdev->devfn == 0) |
| 6062 | ssleep(30); |
| 6063 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6064 | return PCI_ERS_RESULT_NEED_RESET; |
| 6065 | } |
| 6066 | |
| 6067 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 6068 | { |
| 6069 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 6070 | int status; |
| 6071 | |
| 6072 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6073 | |
| 6074 | status = pci_enable_device(pdev); |
| 6075 | if (status) |
| 6076 | return PCI_ERS_RESULT_DISCONNECT; |
| 6077 | |
| 6078 | pci_set_master(pdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6079 | pci_restore_state(pdev); |
| 6080 | |
| 6081 | /* Check if card is ok and fw is ready */ |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 6082 | dev_info(&adapter->pdev->dev, |
| 6083 | "Waiting for FW to be ready after EEH reset\n"); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 6084 | status = be_fw_wait_ready(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6085 | if (status) |
| 6086 | return PCI_ERS_RESULT_DISCONNECT; |
| 6087 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 6088 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 6089 | be_clear_error(adapter, BE_CLEAR_ALL); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6090 | return PCI_ERS_RESULT_RECOVERED; |
| 6091 | } |
| 6092 | |
| 6093 | static void be_eeh_resume(struct pci_dev *pdev) |
| 6094 | { |
| 6095 | int status = 0; |
| 6096 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6097 | |
| 6098 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 6099 | |
| 6100 | pci_save_state(pdev); |
| 6101 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 6102 | status = be_resume(adapter); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 6103 | if (status) |
| 6104 | goto err; |
| 6105 | |
Padmanabh Ratnakar | 68f2279 | 2016-02-18 03:09:34 +0530 | [diff] [blame] | 6106 | be_roce_dev_add(adapter); |
| 6107 | |
Padmanabh Ratnakar | 972f37b | 2016-02-03 09:49:22 +0530 | [diff] [blame] | 6108 | be_schedule_err_detection(adapter, ERR_DETECTION_DELAY); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6109 | return; |
| 6110 | err: |
| 6111 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6112 | } |
| 6113 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6114 | static int be_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) |
| 6115 | { |
| 6116 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 6117 | struct be_resources vft_res = {0}; |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6118 | int status; |
| 6119 | |
| 6120 | if (!num_vfs) |
| 6121 | be_vf_clear(adapter); |
| 6122 | |
| 6123 | adapter->num_vfs = num_vfs; |
| 6124 | |
| 6125 | if (adapter->num_vfs == 0 && pci_vfs_assigned(pdev)) { |
| 6126 | dev_warn(&pdev->dev, |
| 6127 | "Cannot disable VFs while they are assigned\n"); |
| 6128 | return -EBUSY; |
| 6129 | } |
| 6130 | |
| 6131 | /* When the HW is in SRIOV capable configuration, the PF-pool resources |
| 6132 | * are equally distributed across the max-number of VFs. The user may |
| 6133 | * request only a subset of the max-vfs to be enabled. |
| 6134 | * Based on num_vfs, redistribute the resources across num_vfs so that |
| 6135 | * each VF will have access to more number of resources. |
| 6136 | * This facility is not available in BE3 FW. |
| 6137 | * Also, this is done by FW in Lancer chip. |
| 6138 | */ |
| 6139 | if (skyhawk_chip(adapter) && !pci_num_vf(pdev)) { |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 6140 | be_calculate_vf_res(adapter, adapter->num_vfs, |
| 6141 | &vft_res); |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6142 | status = be_cmd_set_sriov_config(adapter, adapter->pool_res, |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 6143 | adapter->num_vfs, &vft_res); |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6144 | if (status) |
| 6145 | dev_err(&pdev->dev, |
| 6146 | "Failed to optimize SR-IOV resources\n"); |
| 6147 | } |
| 6148 | |
| 6149 | status = be_get_resources(adapter); |
| 6150 | if (status) |
| 6151 | return be_cmd_status(status); |
| 6152 | |
| 6153 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 6154 | rtnl_lock(); |
| 6155 | status = be_update_queues(adapter); |
| 6156 | rtnl_unlock(); |
| 6157 | if (status) |
| 6158 | return be_cmd_status(status); |
| 6159 | |
| 6160 | if (adapter->num_vfs) |
| 6161 | status = be_vf_setup(adapter); |
| 6162 | |
| 6163 | if (!status) |
| 6164 | return adapter->num_vfs; |
| 6165 | |
| 6166 | return 0; |
| 6167 | } |
| 6168 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 6169 | static const struct pci_error_handlers be_eeh_handlers = { |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6170 | .error_detected = be_eeh_err_detected, |
| 6171 | .slot_reset = be_eeh_reset, |
| 6172 | .resume = be_eeh_resume, |
| 6173 | }; |
| 6174 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6175 | static struct pci_driver be_driver = { |
| 6176 | .name = DRV_NAME, |
| 6177 | .id_table = be_dev_ids, |
| 6178 | .probe = be_probe, |
| 6179 | .remove = be_remove, |
| 6180 | .suspend = be_suspend, |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 6181 | .resume = be_pci_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 6182 | .shutdown = be_shutdown, |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6183 | .sriov_configure = be_pci_sriov_configure, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 6184 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6185 | }; |
| 6186 | |
| 6187 | static int __init be_init_module(void) |
| 6188 | { |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 6189 | int status; |
| 6190 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 6191 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 6192 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6193 | printk(KERN_WARNING DRV_NAME |
| 6194 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 6195 | " Using 2048\n"); |
| 6196 | rx_frag_size = 2048; |
| 6197 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6198 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 6199 | if (num_vfs > 0) { |
| 6200 | pr_info(DRV_NAME " : Module param num_vfs is obsolete."); |
| 6201 | pr_info(DRV_NAME " : Use sysfs method to enable VFs\n"); |
| 6202 | } |
| 6203 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 6204 | be_wq = create_singlethread_workqueue("be_wq"); |
| 6205 | if (!be_wq) { |
| 6206 | pr_warn(DRV_NAME "workqueue creation failed\n"); |
| 6207 | return -1; |
| 6208 | } |
| 6209 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 6210 | be_err_recovery_workq = |
| 6211 | create_singlethread_workqueue("be_err_recover"); |
| 6212 | if (!be_err_recovery_workq) |
| 6213 | pr_warn(DRV_NAME "Could not create error recovery workqueue\n"); |
| 6214 | |
| 6215 | status = pci_register_driver(&be_driver); |
| 6216 | if (status) { |
| 6217 | destroy_workqueue(be_wq); |
| 6218 | be_destroy_err_recovery_workq(); |
| 6219 | } |
| 6220 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6221 | } |
| 6222 | module_init(be_init_module); |
| 6223 | |
| 6224 | static void __exit be_exit_module(void) |
| 6225 | { |
| 6226 | pci_unregister_driver(&be_driver); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 6227 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 6228 | be_destroy_err_recovery_workq(); |
| 6229 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 6230 | if (be_wq) |
| 6231 | destroy_workqueue(be_wq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 6232 | } |
| 6233 | module_exit(be_exit_module); |