Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Vasundhara Volam | d19261b | 2015-05-06 05:30:39 -0400 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2015 Emulex |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 18 | #include <linux/prefetch.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 20 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 21 | #include "be_cmds.h" |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 22 | #include <asm/div64.h> |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 23 | #include <linux/aer.h> |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 24 | #include <linux/if_bridge.h> |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 25 | #include <net/busy_poll.h> |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 26 | #include <net/vxlan.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 27 | |
| 28 | MODULE_VERSION(DRV_VER); |
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 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 44 | static const struct pci_device_id be_dev_ids[] = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 45 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Ajit Khaparde | 59fd5d8 | 2009-10-29 01:11:06 -0700 | [diff] [blame] | 46 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 47 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 48 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 49 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)}, |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 50 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)}, |
Ajit Khaparde | ecedb6a | 2011-12-15 06:31:38 +0000 | [diff] [blame] | 51 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID5)}, |
Padmanabh Ratnakar | 76b7353 | 2012-10-20 06:04:40 +0000 | [diff] [blame] | 52 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID6)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 53 | { 0 } |
| 54 | }; |
| 55 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 56 | /* UE Status Low CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 57 | static const char * const ue_status_low_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 58 | "CEV", |
| 59 | "CTX", |
| 60 | "DBUF", |
| 61 | "ERX", |
| 62 | "Host", |
| 63 | "MPU", |
| 64 | "NDMA", |
| 65 | "PTC ", |
| 66 | "RDMA ", |
| 67 | "RXF ", |
| 68 | "RXIPS ", |
| 69 | "RXULP0 ", |
| 70 | "RXULP1 ", |
| 71 | "RXULP2 ", |
| 72 | "TIM ", |
| 73 | "TPOST ", |
| 74 | "TPRE ", |
| 75 | "TXIPS ", |
| 76 | "TXULP0 ", |
| 77 | "TXULP1 ", |
| 78 | "UC ", |
| 79 | "WDMA ", |
| 80 | "TXULP2 ", |
| 81 | "HOST1 ", |
| 82 | "P0_OB_LINK ", |
| 83 | "P1_OB_LINK ", |
| 84 | "HOST_GPIO ", |
| 85 | "MBOX ", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 86 | "ERX2 ", |
| 87 | "SPARE ", |
| 88 | "JTAG ", |
| 89 | "MPU_INTPEND " |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 90 | }; |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 91 | |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 92 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 93 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 94 | "LPCMEMHOST", |
| 95 | "MGMT_MAC", |
| 96 | "PCS0ONLINE", |
| 97 | "MPU_IRAM", |
| 98 | "PCS1ONLINE", |
| 99 | "PCTL0", |
| 100 | "PCTL1", |
| 101 | "PMEM", |
| 102 | "RR", |
| 103 | "TXPB", |
| 104 | "RXPP", |
| 105 | "XAUI", |
| 106 | "TXP", |
| 107 | "ARM", |
| 108 | "IPC", |
| 109 | "HOST2", |
| 110 | "HOST3", |
| 111 | "HOST4", |
| 112 | "HOST5", |
| 113 | "HOST6", |
| 114 | "HOST7", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 115 | "ECRC", |
| 116 | "Poison TLP", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 117 | "NETC", |
Vasundhara Volam | 6bdf8f5 | 2014-07-17 16:20:25 +0530 | [diff] [blame] | 118 | "PERIPH", |
| 119 | "LLTXULP", |
| 120 | "D2P", |
| 121 | "RCON", |
| 122 | "LDMA", |
| 123 | "LLTXP", |
| 124 | "LLTXPB", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 125 | "Unknown" |
| 126 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 127 | |
| 128 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 129 | { |
| 130 | struct be_dma_mem *mem = &q->dma_mem; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 131 | |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 132 | if (mem->va) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 133 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 134 | mem->dma); |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 135 | mem->va = NULL; |
| 136 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | 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] | 140 | u16 len, u16 entry_size) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 141 | { |
| 142 | struct be_dma_mem *mem = &q->dma_mem; |
| 143 | |
| 144 | memset(q, 0, sizeof(*q)); |
| 145 | q->len = len; |
| 146 | q->entry_size = entry_size; |
| 147 | mem->size = len * entry_size; |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 148 | mem->va = dma_zalloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 149 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 150 | if (!mem->va) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 151 | return -ENOMEM; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 155 | static void be_reg_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 156 | { |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 157 | u32 reg, enabled; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 158 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 159 | pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 160 | ®); |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 161 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 162 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 163 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 164 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 165 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 166 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 167 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 168 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 169 | |
Sathya Perla | db3ea78 | 2011-08-22 19:41:52 +0000 | [diff] [blame] | 170 | pci_write_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 171 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 174 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
| 175 | { |
| 176 | int status = 0; |
| 177 | |
| 178 | /* On lancer interrupts can't be controlled via this register */ |
| 179 | if (lancer_chip(adapter)) |
| 180 | return; |
| 181 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 182 | if (be_check_error(adapter, BE_ERROR_EEH)) |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 183 | return; |
| 184 | |
| 185 | status = be_cmd_intr_set(adapter, enable); |
| 186 | if (status) |
| 187 | be_reg_intr_set(adapter, enable); |
| 188 | } |
| 189 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 190 | 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] | 191 | { |
| 192 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 193 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 194 | if (be_check_error(adapter, BE_ERROR_HW)) |
| 195 | return; |
| 196 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 197 | val |= qid & DB_RQ_RING_ID_MASK; |
| 198 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 199 | |
| 200 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 201 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 204 | static void be_txq_notify(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 205 | u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 206 | { |
| 207 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 208 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 209 | if (be_check_error(adapter, BE_ERROR_HW)) |
| 210 | return; |
| 211 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 212 | val |= txo->q.id & DB_TXULP_RING_ID_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 213 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 214 | |
| 215 | wmb(); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 216 | iowrite32(val, adapter->db + txo->db_offset); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 219 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 220 | bool arm, bool clear_int, u16 num_popped, |
| 221 | u32 eq_delay_mult_enc) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 222 | { |
| 223 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 224 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 225 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 226 | 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] | 227 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 228 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 229 | return; |
| 230 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 231 | if (arm) |
| 232 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 233 | if (clear_int) |
| 234 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 235 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 236 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 237 | val |= eq_delay_mult_enc << DB_EQ_R2I_DLY_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 238 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 241 | 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] | 242 | { |
| 243 | u32 val = 0; |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 244 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 245 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 246 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 247 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 248 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 249 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 250 | return; |
| 251 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 252 | if (arm) |
| 253 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 254 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 255 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 258 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 259 | { |
| 260 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 261 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 262 | struct sockaddr *addr = p; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 263 | int status; |
| 264 | u8 mac[ETH_ALEN]; |
| 265 | u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 266 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 267 | if (!is_valid_ether_addr(addr->sa_data)) |
| 268 | return -EADDRNOTAVAIL; |
| 269 | |
Vasundhara Volam | ff32f8a | 2014-01-15 13:23:35 +0530 | [diff] [blame] | 270 | /* Proceed further only if, User provided MAC is different |
| 271 | * from active MAC |
| 272 | */ |
| 273 | if (ether_addr_equal(addr->sa_data, netdev->dev_addr)) |
| 274 | return 0; |
| 275 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 276 | /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT |
| 277 | * privilege or if PF did not provision the new MAC address. |
| 278 | * On BE3, this cmd will always fail if the VF doesn't have the |
| 279 | * FILTMGMT privilege. This failure is OK, only if the PF programmed |
| 280 | * the MAC for the VF. |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 281 | */ |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 282 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
| 283 | adapter->if_handle, &adapter->pmac_id[0], 0); |
| 284 | if (!status) { |
| 285 | curr_pmac_id = adapter->pmac_id[0]; |
| 286 | |
| 287 | /* Delete the old programmed MAC. This call may fail if the |
| 288 | * old MAC was already deleted by the PF driver. |
| 289 | */ |
| 290 | if (adapter->pmac_id[0] != old_pmac_id) |
| 291 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 292 | old_pmac_id, 0); |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 295 | /* Decide if the new MAC is successfully activated only after |
| 296 | * querying the FW |
Padmanabh Ratnakar | 704e4c8 | 2012-10-20 06:02:13 +0000 | [diff] [blame] | 297 | */ |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 298 | status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac, |
| 299 | adapter->if_handle, true, 0); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 300 | if (status) |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 301 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 302 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 303 | /* The MAC change did not happen, either due to lack of privilege |
| 304 | * or PF didn't pre-provision. |
| 305 | */ |
dingtianhong | 61d23e9 | 2013-12-30 15:40:43 +0800 | [diff] [blame] | 306 | if (!ether_addr_equal(addr->sa_data, mac)) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 307 | status = -EPERM; |
| 308 | goto err; |
| 309 | } |
| 310 | |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 311 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 312 | dev_info(dev, "MAC address changed to %pM\n", mac); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 313 | return 0; |
| 314 | err: |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 315 | 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] | 316 | return status; |
| 317 | } |
| 318 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 319 | /* BE2 supports only v0 cmd */ |
| 320 | static void *hw_stats_from_cmd(struct be_adapter *adapter) |
| 321 | { |
| 322 | if (BE2_chip(adapter)) { |
| 323 | struct be_cmd_resp_get_stats_v0 *cmd = adapter->stats_cmd.va; |
| 324 | |
| 325 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 326 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 327 | struct be_cmd_resp_get_stats_v1 *cmd = adapter->stats_cmd.va; |
| 328 | |
| 329 | return &cmd->hw_stats; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 330 | } else { |
| 331 | struct be_cmd_resp_get_stats_v2 *cmd = adapter->stats_cmd.va; |
| 332 | |
| 333 | return &cmd->hw_stats; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | /* BE2 supports only v0 cmd */ |
| 338 | static void *be_erx_stats_from_cmd(struct be_adapter *adapter) |
| 339 | { |
| 340 | if (BE2_chip(adapter)) { |
| 341 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 342 | |
| 343 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 344 | } else if (BE3_chip(adapter)) { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 345 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 346 | |
| 347 | return &hw_stats->erx; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 348 | } else { |
| 349 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 350 | |
| 351 | return &hw_stats->erx; |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
| 355 | static void populate_be_v0_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 356 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 357 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 358 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 359 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 360 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 361 | &rxf_stats->port[adapter->port_num]; |
| 362 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 363 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 364 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 365 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 366 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 367 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 368 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 369 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 370 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 371 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 372 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 373 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 374 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 375 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 376 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 377 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 378 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 379 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 380 | drvs->rx_dropped_header_too_small = |
| 381 | port_stats->rx_dropped_header_too_small; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 382 | drvs->rx_address_filtered = |
| 383 | port_stats->rx_address_filtered + |
| 384 | port_stats->rx_vlan_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 385 | drvs->rx_alignment_symbol_errors = |
| 386 | port_stats->rx_alignment_symbol_errors; |
| 387 | |
| 388 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 389 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 390 | |
| 391 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 392 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 393 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 394 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 395 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 396 | 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] | 397 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 398 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 399 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 400 | 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] | 401 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 402 | } |
| 403 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 404 | static void populate_be_v1_stats(struct be_adapter *adapter) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 405 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 406 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 407 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 408 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 409 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 410 | &rxf_stats->port[adapter->port_num]; |
| 411 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 412 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 413 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 02fe702 | 2011-12-09 13:53:09 +0000 | [diff] [blame] | 414 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 415 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 416 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 417 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 418 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 419 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 420 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 421 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 422 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 423 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 424 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 425 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 426 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 427 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 428 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 429 | drvs->rx_dropped_header_too_small = |
| 430 | port_stats->rx_dropped_header_too_small; |
| 431 | drvs->rx_input_fifo_overflow_drop = |
| 432 | port_stats->rx_input_fifo_overflow_drop; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 433 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 434 | drvs->rx_alignment_symbol_errors = |
| 435 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 436 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 437 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 438 | drvs->tx_controlframes = port_stats->tx_controlframes; |
Ajit Khaparde | b5adffc4 | 2013-05-01 09:38:00 +0000 | [diff] [blame] | 439 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 440 | drvs->jabber_events = port_stats->jabber_events; |
| 441 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 442 | 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] | 443 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 444 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 445 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 446 | 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] | 447 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 448 | } |
| 449 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 450 | static void populate_be_v2_stats(struct be_adapter *adapter) |
| 451 | { |
| 452 | struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter); |
| 453 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 454 | struct be_rxf_stats_v2 *rxf_stats = &hw_stats->rxf; |
| 455 | struct be_port_rxf_stats_v2 *port_stats = |
| 456 | &rxf_stats->port[adapter->port_num]; |
| 457 | struct be_drv_stats *drvs = &adapter->drv_stats; |
| 458 | |
| 459 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
| 460 | drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop; |
| 461 | drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames; |
| 462 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 463 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 464 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 465 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 466 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 467 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 468 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 469 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 470 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 471 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 472 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 473 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 474 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 475 | drvs->rx_dropped_header_too_small = |
| 476 | port_stats->rx_dropped_header_too_small; |
| 477 | drvs->rx_input_fifo_overflow_drop = |
| 478 | port_stats->rx_input_fifo_overflow_drop; |
| 479 | drvs->rx_address_filtered = port_stats->rx_address_filtered; |
| 480 | drvs->rx_alignment_symbol_errors = |
| 481 | port_stats->rx_alignment_symbol_errors; |
| 482 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
| 483 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 484 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 485 | drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes; |
| 486 | drvs->jabber_events = port_stats->jabber_events; |
| 487 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 488 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 489 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 490 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
| 491 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 492 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
| 493 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 494 | if (be_roce_supported(adapter)) { |
Ajit Khaparde | 461ae37 | 2013-10-03 16:16:50 -0500 | [diff] [blame] | 495 | drvs->rx_roce_bytes_lsd = port_stats->roce_bytes_received_lsd; |
| 496 | drvs->rx_roce_bytes_msd = port_stats->roce_bytes_received_msd; |
| 497 | drvs->rx_roce_frames = port_stats->roce_frames_received; |
| 498 | drvs->roce_drops_crc = port_stats->roce_drops_crc; |
| 499 | drvs->roce_drops_payload_len = |
| 500 | port_stats->roce_drops_payload_len; |
| 501 | } |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 504 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 505 | { |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 506 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 507 | struct lancer_pport_stats *pport_stats = pport_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 508 | |
| 509 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 510 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 511 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 512 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 513 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 514 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 515 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 516 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 517 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 518 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 519 | drvs->rx_dropped_tcp_length = |
| 520 | pport_stats->rx_dropped_invalid_tcp_length; |
| 521 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 522 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 523 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 524 | drvs->rx_dropped_header_too_small = |
| 525 | pport_stats->rx_dropped_header_too_small; |
| 526 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Suresh Reddy | 18fb06a | 2013-04-25 23:03:21 +0000 | [diff] [blame] | 527 | drvs->rx_address_filtered = |
| 528 | pport_stats->rx_address_filtered + |
| 529 | pport_stats->rx_vlan_filtered; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 530 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 531 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 532 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 533 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 534 | drvs->jabber_events = pport_stats->rx_jabbers; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 535 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 536 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 537 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 538 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 539 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 540 | |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 541 | static void accumulate_16bit_val(u32 *acc, u16 val) |
| 542 | { |
| 543 | #define lo(x) (x & 0xFFFF) |
| 544 | #define hi(x) (x & 0xFFFF0000) |
| 545 | bool wrapped = val < lo(*acc); |
| 546 | u32 newacc = hi(*acc) + val; |
| 547 | |
| 548 | if (wrapped) |
| 549 | newacc += 65536; |
| 550 | ACCESS_ONCE(*acc) = newacc; |
| 551 | } |
| 552 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 553 | static void populate_erx_stats(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 554 | struct be_rx_obj *rxo, u32 erx_stat) |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 555 | { |
| 556 | if (!BEx_chip(adapter)) |
| 557 | rx_stats(rxo)->rx_drops_no_frags = erx_stat; |
| 558 | else |
| 559 | /* below erx HW counter can actually wrap around after |
| 560 | * 65535. Driver accumulates a 32-bit value |
| 561 | */ |
| 562 | accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags, |
| 563 | (u16)erx_stat); |
| 564 | } |
| 565 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 566 | void be_parse_stats(struct be_adapter *adapter) |
| 567 | { |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 568 | struct be_erx_stats_v2 *erx = be_erx_stats_from_cmd(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 569 | struct be_rx_obj *rxo; |
| 570 | int i; |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 571 | u32 erx_stat; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 572 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 573 | if (lancer_chip(adapter)) { |
| 574 | populate_lancer_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 575 | } else { |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 576 | if (BE2_chip(adapter)) |
| 577 | populate_be_v0_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 578 | else if (BE3_chip(adapter)) |
| 579 | /* for BE3 */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 580 | populate_be_v1_stats(adapter); |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 581 | else |
| 582 | populate_be_v2_stats(adapter); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 583 | |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 584 | /* 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] | 585 | for_all_rx_queues(adapter, rxo, i) { |
Ajit Khaparde | a6c578e | 2013-05-01 09:37:27 +0000 | [diff] [blame] | 586 | erx_stat = erx->rx_drops_no_fragments[rxo->q.id]; |
| 587 | populate_erx_stats(adapter, rxo, erx_stat); |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 588 | } |
Sathya Perla | 09c1c68 | 2011-08-22 19:41:53 +0000 | [diff] [blame] | 589 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 592 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 593 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 594 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 595 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 596 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 597 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 598 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 599 | u64 pkts, bytes; |
| 600 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 601 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 602 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 603 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 604 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 605 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 606 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 607 | start = u64_stats_fetch_begin_irq(&rx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 608 | pkts = rx_stats(rxo)->rx_pkts; |
| 609 | bytes = rx_stats(rxo)->rx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 610 | } while (u64_stats_fetch_retry_irq(&rx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 611 | stats->rx_packets += pkts; |
| 612 | stats->rx_bytes += bytes; |
| 613 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 614 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 615 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 618 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 619 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 620 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 621 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 622 | start = u64_stats_fetch_begin_irq(&tx_stats->sync); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 623 | pkts = tx_stats(txo)->tx_pkts; |
| 624 | bytes = tx_stats(txo)->tx_bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 625 | } while (u64_stats_fetch_retry_irq(&tx_stats->sync, start)); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 626 | stats->tx_packets += pkts; |
| 627 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 628 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 629 | |
| 630 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 631 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 632 | drvs->rx_alignment_symbol_errors + |
| 633 | drvs->rx_in_range_errors + |
| 634 | drvs->rx_out_range_errors + |
| 635 | drvs->rx_frame_too_long + |
| 636 | drvs->rx_dropped_too_small + |
| 637 | drvs->rx_dropped_too_short + |
| 638 | drvs->rx_dropped_header_too_small + |
| 639 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 640 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 641 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 642 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 643 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 644 | drvs->rx_out_range_errors + |
| 645 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 646 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 647 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 648 | |
| 649 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 650 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 651 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 652 | /* receiver fifo overrun */ |
| 653 | /* 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] | 654 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 655 | drvs->rx_input_fifo_overflow_drop + |
| 656 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 657 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 660 | void be_link_status_update(struct be_adapter *adapter, u8 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 661 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 662 | struct net_device *netdev = adapter->netdev; |
| 663 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 664 | if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) { |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 665 | netif_carrier_off(netdev); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 666 | adapter->flags |= BE_FLAGS_LINK_STATUS_INIT; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 667 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 668 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 669 | if (link_status) |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 670 | netif_carrier_on(netdev); |
| 671 | else |
| 672 | netif_carrier_off(netdev); |
Ivan Vecera | 1882489 | 2015-04-30 11:59:49 +0200 | [diff] [blame] | 673 | |
| 674 | netdev_info(netdev, "Link is %s\n", link_status ? "Up" : "Down"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 677 | 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] | 678 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 679 | struct be_tx_stats *stats = tx_stats(txo); |
| 680 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 681 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 682 | stats->tx_reqs++; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 683 | stats->tx_bytes += skb->len; |
| 684 | stats->tx_pkts += (skb_shinfo(skb)->gso_segs ? : 1); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 685 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 688 | /* Returns number of WRBs needed for the skb */ |
| 689 | static u32 skb_wrb_cnt(struct sk_buff *skb) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 690 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 691 | /* +1 for the header wrb */ |
| 692 | return 1 + (skb_headlen(skb) ? 1 : 0) + skb_shinfo(skb)->nr_frags; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 696 | { |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 697 | wrb->frag_pa_hi = cpu_to_le32(upper_32_bits(addr)); |
| 698 | wrb->frag_pa_lo = cpu_to_le32(lower_32_bits(addr)); |
| 699 | wrb->frag_len = cpu_to_le32(len & ETH_WRB_FRAG_LEN_MASK); |
| 700 | wrb->rsvd0 = 0; |
| 701 | } |
| 702 | |
| 703 | /* A dummy wrb is just all zeros. Using a separate routine for dummy-wrb |
| 704 | * to avoid the swap and shift/mask operations in wrb_fill(). |
| 705 | */ |
| 706 | static inline void wrb_fill_dummy(struct be_eth_wrb *wrb) |
| 707 | { |
| 708 | wrb->frag_pa_hi = 0; |
| 709 | wrb->frag_pa_lo = 0; |
| 710 | wrb->frag_len = 0; |
Somnath Kotur | 89b1f49 | 2012-06-24 19:40:55 +0000 | [diff] [blame] | 711 | wrb->rsvd0 = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 714 | static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 715 | struct sk_buff *skb) |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 716 | { |
| 717 | u8 vlan_prio; |
| 718 | u16 vlan_tag; |
| 719 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 720 | vlan_tag = skb_vlan_tag_get(skb); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 721 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 722 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 723 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 724 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
| 725 | adapter->recommended_prio; |
| 726 | |
| 727 | return vlan_tag; |
| 728 | } |
| 729 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 730 | /* Used only for IP tunnel packets */ |
| 731 | static u16 skb_inner_ip_proto(struct sk_buff *skb) |
| 732 | { |
| 733 | return (inner_ip_hdr(skb)->version == 4) ? |
| 734 | inner_ip_hdr(skb)->protocol : inner_ipv6_hdr(skb)->nexthdr; |
| 735 | } |
| 736 | |
| 737 | static u16 skb_ip_proto(struct sk_buff *skb) |
| 738 | { |
| 739 | return (ip_hdr(skb)->version == 4) ? |
| 740 | ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr; |
| 741 | } |
| 742 | |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 743 | static inline bool be_is_txq_full(struct be_tx_obj *txo) |
| 744 | { |
| 745 | return atomic_read(&txo->q.used) + BE_MAX_TX_FRAG_COUNT >= txo->q.len; |
| 746 | } |
| 747 | |
| 748 | static inline bool be_can_txq_wake(struct be_tx_obj *txo) |
| 749 | { |
| 750 | return atomic_read(&txo->q.used) < txo->q.len / 2; |
| 751 | } |
| 752 | |
| 753 | static inline bool be_is_tx_compl_pending(struct be_tx_obj *txo) |
| 754 | { |
| 755 | return atomic_read(&txo->q.used) > txo->pend_wrb_cnt; |
| 756 | } |
| 757 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 758 | static void be_get_wrb_params_from_skb(struct be_adapter *adapter, |
| 759 | struct sk_buff *skb, |
| 760 | struct be_wrb_params *wrb_params) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 761 | { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 762 | u16 proto; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 763 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 764 | if (skb_is_gso(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 765 | BE_WRB_F_SET(wrb_params->features, LSO, 1); |
| 766 | wrb_params->lso_mss = skb_shinfo(skb)->gso_size; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 767 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 768 | BE_WRB_F_SET(wrb_params->features, LSO6, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 769 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 770 | if (skb->encapsulation) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 771 | BE_WRB_F_SET(wrb_params->features, IPCS, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 772 | proto = skb_inner_ip_proto(skb); |
| 773 | } else { |
| 774 | proto = skb_ip_proto(skb); |
| 775 | } |
| 776 | if (proto == IPPROTO_TCP) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 777 | BE_WRB_F_SET(wrb_params->features, TCPCS, 1); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 778 | else if (proto == IPPROTO_UDP) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 779 | BE_WRB_F_SET(wrb_params->features, UDPCS, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 782 | if (skb_vlan_tag_present(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 783 | BE_WRB_F_SET(wrb_params->features, VLAN, 1); |
| 784 | wrb_params->vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 787 | BE_WRB_F_SET(wrb_params->features, CRC, 1); |
| 788 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 789 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 790 | static void wrb_fill_hdr(struct be_adapter *adapter, |
| 791 | struct be_eth_hdr_wrb *hdr, |
| 792 | struct be_wrb_params *wrb_params, |
| 793 | struct sk_buff *skb) |
| 794 | { |
| 795 | memset(hdr, 0, sizeof(*hdr)); |
| 796 | |
| 797 | SET_TX_WRB_HDR_BITS(crc, hdr, |
| 798 | BE_WRB_F_GET(wrb_params->features, CRC)); |
| 799 | SET_TX_WRB_HDR_BITS(ipcs, hdr, |
| 800 | BE_WRB_F_GET(wrb_params->features, IPCS)); |
| 801 | SET_TX_WRB_HDR_BITS(tcpcs, hdr, |
| 802 | BE_WRB_F_GET(wrb_params->features, TCPCS)); |
| 803 | SET_TX_WRB_HDR_BITS(udpcs, hdr, |
| 804 | BE_WRB_F_GET(wrb_params->features, UDPCS)); |
| 805 | |
| 806 | SET_TX_WRB_HDR_BITS(lso, hdr, |
| 807 | BE_WRB_F_GET(wrb_params->features, LSO)); |
| 808 | SET_TX_WRB_HDR_BITS(lso6, hdr, |
| 809 | BE_WRB_F_GET(wrb_params->features, LSO6)); |
| 810 | SET_TX_WRB_HDR_BITS(lso_mss, hdr, wrb_params->lso_mss); |
| 811 | |
| 812 | /* Hack to skip HW VLAN tagging needs evt = 1, compl = 0. When this |
| 813 | * hack is not needed, the evt bit is set while ringing DB. |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 814 | */ |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 815 | SET_TX_WRB_HDR_BITS(event, hdr, |
| 816 | BE_WRB_F_GET(wrb_params->features, VLAN_SKIP_HW)); |
| 817 | SET_TX_WRB_HDR_BITS(vlan, hdr, |
| 818 | BE_WRB_F_GET(wrb_params->features, VLAN)); |
| 819 | SET_TX_WRB_HDR_BITS(vlan_tag, hdr, wrb_params->vlan_tag); |
| 820 | |
| 821 | SET_TX_WRB_HDR_BITS(num_wrb, hdr, skb_wrb_cnt(skb)); |
| 822 | SET_TX_WRB_HDR_BITS(len, hdr, skb->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 825 | 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] | 826 | bool unmap_single) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 827 | { |
| 828 | dma_addr_t dma; |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 829 | u32 frag_len = le32_to_cpu(wrb->frag_len); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 830 | |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 831 | |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 832 | dma = (u64)le32_to_cpu(wrb->frag_pa_hi) << 32 | |
| 833 | (u64)le32_to_cpu(wrb->frag_pa_lo); |
| 834 | if (frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 835 | if (unmap_single) |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 836 | dma_unmap_single(dev, dma, frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 837 | else |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 838 | dma_unmap_page(dev, dma, frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 839 | } |
| 840 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 841 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 842 | /* Grab a WRB header for xmit */ |
| 843 | static u16 be_tx_get_wrb_hdr(struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 844 | { |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 845 | u16 head = txo->q.head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 846 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 847 | queue_head_inc(&txo->q); |
| 848 | return head; |
| 849 | } |
| 850 | |
| 851 | /* Set up the WRB header for xmit */ |
| 852 | static void be_tx_setup_wrb_hdr(struct be_adapter *adapter, |
| 853 | struct be_tx_obj *txo, |
| 854 | struct be_wrb_params *wrb_params, |
| 855 | struct sk_buff *skb, u16 head) |
| 856 | { |
| 857 | u32 num_frags = skb_wrb_cnt(skb); |
| 858 | struct be_queue_info *txq = &txo->q; |
| 859 | struct be_eth_hdr_wrb *hdr = queue_index_node(txq, head); |
| 860 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 861 | wrb_fill_hdr(adapter, hdr, wrb_params, skb); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 862 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 863 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 864 | BUG_ON(txo->sent_skb_list[head]); |
| 865 | txo->sent_skb_list[head] = skb; |
| 866 | txo->last_req_hdr = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 867 | atomic_add(num_frags, &txq->used); |
| 868 | txo->last_req_wrb_cnt = num_frags; |
| 869 | txo->pend_wrb_cnt += num_frags; |
| 870 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 871 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 872 | /* Setup a WRB fragment (buffer descriptor) for xmit */ |
| 873 | static void be_tx_setup_wrb_frag(struct be_tx_obj *txo, dma_addr_t busaddr, |
| 874 | int len) |
| 875 | { |
| 876 | struct be_eth_wrb *wrb; |
| 877 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 878 | |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 879 | wrb = queue_head_node(txq); |
| 880 | wrb_fill(wrb, busaddr, len); |
| 881 | queue_head_inc(txq); |
| 882 | } |
| 883 | |
| 884 | /* Bring the queue back to the state it was in before be_xmit_enqueue() routine |
| 885 | * was invoked. The producer index is restored to the previous packet and the |
| 886 | * WRBs of the current packet are unmapped. Invoked to handle tx setup errors. |
| 887 | */ |
| 888 | static void be_xmit_restore(struct be_adapter *adapter, |
| 889 | struct be_tx_obj *txo, u16 head, bool map_single, |
| 890 | u32 copied) |
| 891 | { |
| 892 | struct device *dev; |
| 893 | struct be_eth_wrb *wrb; |
| 894 | struct be_queue_info *txq = &txo->q; |
| 895 | |
| 896 | dev = &adapter->pdev->dev; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 897 | txq->head = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 898 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 899 | /* skip the first wrb (hdr); it's not mapped */ |
| 900 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 901 | while (copied) { |
| 902 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 903 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 904 | map_single = false; |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 905 | copied -= le32_to_cpu(wrb->frag_len); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 906 | queue_head_inc(txq); |
| 907 | } |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 908 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 909 | txq->head = head; |
Sriharsha Basavapatna | 79a0d7d | 2015-02-16 08:03:46 +0530 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /* Enqueue the given packet for transmit. This routine allocates WRBs for the |
| 913 | * packet, dma maps the packet buffers and sets up the WRBs. Returns the number |
| 914 | * of WRBs used up by the packet. |
| 915 | */ |
| 916 | static u32 be_xmit_enqueue(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 917 | struct sk_buff *skb, |
| 918 | struct be_wrb_params *wrb_params) |
| 919 | { |
| 920 | u32 i, copied = 0, wrb_cnt = skb_wrb_cnt(skb); |
| 921 | struct device *dev = &adapter->pdev->dev; |
| 922 | struct be_queue_info *txq = &txo->q; |
| 923 | bool map_single = false; |
| 924 | u16 head = txq->head; |
| 925 | dma_addr_t busaddr; |
| 926 | int len; |
| 927 | |
| 928 | head = be_tx_get_wrb_hdr(txo); |
| 929 | |
| 930 | if (skb->len > skb->data_len) { |
| 931 | len = skb_headlen(skb); |
| 932 | |
| 933 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 934 | if (dma_mapping_error(dev, busaddr)) |
| 935 | goto dma_err; |
| 936 | map_single = true; |
| 937 | be_tx_setup_wrb_frag(txo, busaddr, len); |
| 938 | copied += len; |
| 939 | } |
| 940 | |
| 941 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 942 | const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; |
| 943 | len = skb_frag_size(frag); |
| 944 | |
| 945 | busaddr = skb_frag_dma_map(dev, frag, 0, len, DMA_TO_DEVICE); |
| 946 | if (dma_mapping_error(dev, busaddr)) |
| 947 | goto dma_err; |
| 948 | be_tx_setup_wrb_frag(txo, busaddr, len); |
| 949 | copied += len; |
| 950 | } |
| 951 | |
| 952 | be_tx_setup_wrb_hdr(adapter, txo, wrb_params, skb, head); |
| 953 | |
| 954 | be_tx_stats_update(txo, skb); |
| 955 | return wrb_cnt; |
| 956 | |
| 957 | dma_err: |
| 958 | adapter->drv_stats.dma_map_errors++; |
| 959 | be_xmit_restore(adapter, txo, head, map_single, copied); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 960 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 963 | static inline int qnq_async_evt_rcvd(struct be_adapter *adapter) |
| 964 | { |
| 965 | return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD; |
| 966 | } |
| 967 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 968 | 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] | 969 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 970 | struct be_wrb_params |
| 971 | *wrb_params) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 972 | { |
| 973 | u16 vlan_tag = 0; |
| 974 | |
| 975 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 976 | if (unlikely(!skb)) |
| 977 | return skb; |
| 978 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 979 | if (skb_vlan_tag_present(skb)) |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 980 | vlan_tag = be_get_tx_vlan_tag(adapter, skb); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 981 | |
| 982 | if (qnq_async_evt_rcvd(adapter) && adapter->pvid) { |
| 983 | if (!vlan_tag) |
| 984 | vlan_tag = adapter->pvid; |
| 985 | /* f/w workaround to set skip_hw_vlan = 1, informs the F/W to |
| 986 | * skip VLAN insertion |
| 987 | */ |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 988 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Sarveshwar Bandi | 52fe29e | 2013-07-16 12:44:02 +0530 | [diff] [blame] | 989 | } |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 990 | |
| 991 | if (vlan_tag) { |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 992 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 993 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 994 | if (unlikely(!skb)) |
| 995 | return skb; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 996 | skb->vlan_tci = 0; |
| 997 | } |
| 998 | |
| 999 | /* Insert the outer VLAN, if any */ |
| 1000 | if (adapter->qnq_vid) { |
| 1001 | vlan_tag = adapter->qnq_vid; |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 1002 | skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q), |
| 1003 | vlan_tag); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1004 | if (unlikely(!skb)) |
| 1005 | return skb; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1006 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1009 | return skb; |
| 1010 | } |
| 1011 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1012 | static bool be_ipv6_exthdr_check(struct sk_buff *skb) |
| 1013 | { |
| 1014 | struct ethhdr *eh = (struct ethhdr *)skb->data; |
| 1015 | u16 offset = ETH_HLEN; |
| 1016 | |
| 1017 | if (eh->h_proto == htons(ETH_P_IPV6)) { |
| 1018 | struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + offset); |
| 1019 | |
| 1020 | offset += sizeof(struct ipv6hdr); |
| 1021 | if (ip6h->nexthdr != NEXTHDR_TCP && |
| 1022 | ip6h->nexthdr != NEXTHDR_UDP) { |
| 1023 | struct ipv6_opt_hdr *ehdr = |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 1024 | (struct ipv6_opt_hdr *)(skb->data + offset); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* offending pkt: 2nd byte following IPv6 hdr is 0xff */ |
| 1027 | if (ehdr->hdrlen == 0xff) |
| 1028 | return true; |
| 1029 | } |
| 1030 | } |
| 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | static int be_vlan_tag_tx_chk(struct be_adapter *adapter, struct sk_buff *skb) |
| 1035 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1036 | return skb_vlan_tag_present(skb) || adapter->pvid || adapter->qnq_vid; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1039 | 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] | 1040 | { |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1041 | return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1044 | static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter, |
| 1045 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1046 | struct be_wrb_params |
| 1047 | *wrb_params) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1048 | { |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1049 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1050 | unsigned int eth_hdr_len; |
| 1051 | struct iphdr *ip; |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1052 | |
Ajit Khaparde | 1297f9d | 2013-04-24 11:52:28 +0000 | [diff] [blame] | 1053 | /* For padded packets, BE HW modifies tot_len field in IP header |
| 1054 | * incorrecly when VLAN tag is inserted by HW. |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 1055 | * For padded packets, Lancer computes incorrect checksum. |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1056 | */ |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1057 | eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ? |
| 1058 | VLAN_ETH_HLEN : ETH_HLEN; |
Somnath Kotur | 3904dcc | 2013-05-26 21:09:06 +0000 | [diff] [blame] | 1059 | if (skb->len <= 60 && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1060 | (lancer_chip(adapter) || skb_vlan_tag_present(skb)) && |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1061 | is_ipv4_pkt(skb)) { |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1062 | ip = (struct iphdr *)ip_hdr(skb); |
| 1063 | pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len)); |
| 1064 | } |
| 1065 | |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1066 | /* If vlan tag is already inlined in the packet, skip HW VLAN |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1067 | * tagging in pvid-tagging mode |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1068 | */ |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 1069 | if (be_pvid_tagging_enabled(adapter) && |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1070 | veh->h_vlan_proto == htons(ETH_P_8021Q)) |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1071 | BE_WRB_F_SET(wrb_params->features, VLAN_SKIP_HW, 1); |
Ajit Khaparde | d2cb6ce | 2013-04-24 11:53:08 +0000 | [diff] [blame] | 1072 | |
Somnath Kotur | 93040ae | 2012-06-26 22:32:10 +0000 | [diff] [blame] | 1073 | /* HW has a bug wherein it will calculate CSUM for VLAN |
| 1074 | * pkts even though it is disabled. |
| 1075 | * Manually insert VLAN in pkt. |
| 1076 | */ |
| 1077 | if (skb->ip_summed != CHECKSUM_PARTIAL && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1078 | skb_vlan_tag_present(skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1079 | skb = be_insert_vlan_in_pkt(adapter, skb, wrb_params); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1080 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1081 | goto err; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /* HW may lockup when VLAN HW tagging is requested on |
| 1085 | * certain ipv6 packets. Drop such pkts if the HW workaround to |
| 1086 | * skip HW tagging is not enabled by FW. |
| 1087 | */ |
| 1088 | if (unlikely(be_ipv6_tx_stall_chk(adapter, skb) && |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 1089 | (adapter->pvid || adapter->qnq_vid) && |
| 1090 | !qnq_async_evt_rcvd(adapter))) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1091 | goto tx_drop; |
| 1092 | |
| 1093 | /* Manual VLAN tag insertion to prevent: |
| 1094 | * ASIC lockup when the ASIC inserts VLAN tag into |
| 1095 | * certain ipv6 packets. Insert VLAN tags in driver, |
| 1096 | * and set event, completion, vlan bits accordingly |
| 1097 | * in the Tx WRB. |
| 1098 | */ |
| 1099 | if (be_ipv6_tx_stall_chk(adapter, skb) && |
| 1100 | be_vlan_tag_tx_chk(adapter, skb)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1101 | skb = be_insert_vlan_in_pkt(adapter, skb, wrb_params); |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1102 | if (unlikely(!skb)) |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1103 | goto err; |
Ajit Khaparde | 1ded132 | 2011-12-09 13:53:17 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1106 | return skb; |
| 1107 | tx_drop: |
| 1108 | dev_kfree_skb_any(skb); |
Vasundhara Volam | c912895 | 2014-03-03 14:25:07 +0530 | [diff] [blame] | 1109 | err: |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1110 | return NULL; |
| 1111 | } |
| 1112 | |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1113 | static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, |
| 1114 | struct sk_buff *skb, |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1115 | struct be_wrb_params *wrb_params) |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1116 | { |
| 1117 | /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or |
| 1118 | * less may cause a transmit stall on that port. So the work-around is |
| 1119 | * to pad short packets (<= 32 bytes) to a 36-byte length. |
| 1120 | */ |
| 1121 | if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) { |
Alexander Duyck | 74b6939 | 2014-12-03 08:17:46 -0800 | [diff] [blame] | 1122 | if (skb_put_padto(skb, 36)) |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1123 | return NULL; |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1127 | skb = be_lancer_xmit_workarounds(adapter, skb, wrb_params); |
Vasundhara Volam | ec495fa | 2014-03-03 14:25:38 +0530 | [diff] [blame] | 1128 | if (!skb) |
| 1129 | return NULL; |
| 1130 | } |
| 1131 | |
| 1132 | return skb; |
| 1133 | } |
| 1134 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1135 | static void be_xmit_flush(struct be_adapter *adapter, struct be_tx_obj *txo) |
| 1136 | { |
| 1137 | struct be_queue_info *txq = &txo->q; |
| 1138 | struct be_eth_hdr_wrb *hdr = queue_index_node(txq, txo->last_req_hdr); |
| 1139 | |
| 1140 | /* Mark the last request eventable if it hasn't been marked already */ |
| 1141 | if (!(hdr->dw[2] & cpu_to_le32(TX_HDR_WRB_EVT))) |
| 1142 | hdr->dw[2] |= cpu_to_le32(TX_HDR_WRB_EVT | TX_HDR_WRB_COMPL); |
| 1143 | |
| 1144 | /* compose a dummy wrb if there are odd set of wrbs to notify */ |
| 1145 | if (!lancer_chip(adapter) && (txo->pend_wrb_cnt & 1)) { |
Sathya Perla | f986afc | 2015-02-06 08:18:43 -0500 | [diff] [blame] | 1146 | wrb_fill_dummy(queue_head_node(txq)); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1147 | queue_head_inc(txq); |
| 1148 | atomic_inc(&txq->used); |
| 1149 | txo->pend_wrb_cnt++; |
| 1150 | hdr->dw[2] &= ~cpu_to_le32(TX_HDR_WRB_NUM_MASK << |
| 1151 | TX_HDR_WRB_NUM_SHIFT); |
| 1152 | hdr->dw[2] |= cpu_to_le32((txo->last_req_wrb_cnt + 1) << |
| 1153 | TX_HDR_WRB_NUM_SHIFT); |
| 1154 | } |
| 1155 | be_txq_notify(adapter, txo, txo->pend_wrb_cnt); |
| 1156 | txo->pend_wrb_cnt = 0; |
| 1157 | } |
| 1158 | |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1159 | static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1160 | { |
| 1161 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1162 | u16 q_idx = skb_get_queue_mapping(skb); |
| 1163 | struct be_tx_obj *txo = &adapter->tx_obj[q_idx]; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1164 | struct be_wrb_params wrb_params = { 0 }; |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1165 | bool flush = !skb->xmit_more; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1166 | u16 wrb_cnt; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1167 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1168 | skb = be_xmit_workarounds(adapter, skb, &wrb_params); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1169 | if (unlikely(!skb)) |
| 1170 | goto drop; |
Sathya Perla | ee9c799 | 2013-05-22 23:04:55 +0000 | [diff] [blame] | 1171 | |
Sriharsha Basavapatna | 804abcd | 2015-02-16 08:03:45 +0530 | [diff] [blame] | 1172 | be_get_wrb_params_from_skb(adapter, skb, &wrb_params); |
| 1173 | |
| 1174 | wrb_cnt = be_xmit_enqueue(adapter, txo, skb, &wrb_params); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1175 | if (unlikely(!wrb_cnt)) { |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1176 | dev_kfree_skb_any(skb); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1177 | goto drop; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1178 | } |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1179 | |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 1180 | if (be_is_txq_full(txo)) { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 1181 | netif_stop_subqueue(netdev, q_idx); |
| 1182 | tx_stats(txo)->tx_stops++; |
| 1183 | } |
| 1184 | |
| 1185 | if (flush || __netif_subqueue_stopped(netdev, q_idx)) |
| 1186 | be_xmit_flush(adapter, txo); |
| 1187 | |
| 1188 | return NETDEV_TX_OK; |
| 1189 | drop: |
| 1190 | tx_stats(txo)->tx_drv_drops++; |
| 1191 | /* Flush the already enqueued tx requests */ |
| 1192 | if (flush && txo->pend_wrb_cnt) |
| 1193 | be_xmit_flush(adapter, txo); |
| 1194 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1195 | return NETDEV_TX_OK; |
| 1196 | } |
| 1197 | |
| 1198 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 1199 | { |
| 1200 | struct be_adapter *adapter = netdev_priv(netdev); |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1201 | struct device *dev = &adapter->pdev->dev; |
| 1202 | |
| 1203 | if (new_mtu < BE_MIN_MTU || new_mtu > BE_MAX_MTU) { |
| 1204 | dev_info(dev, "MTU must be between %d and %d bytes\n", |
| 1205 | BE_MIN_MTU, BE_MAX_MTU); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1206 | return -EINVAL; |
| 1207 | } |
Kalesh AP | 0d3f5cc | 2014-09-02 09:56:53 +0530 | [diff] [blame] | 1208 | |
| 1209 | dev_info(dev, "MTU changed from %d to %d bytes\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1210 | netdev->mtu, new_mtu); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1211 | netdev->mtu = new_mtu; |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1215 | static inline bool be_in_all_promisc(struct be_adapter *adapter) |
| 1216 | { |
| 1217 | return (adapter->if_flags & BE_IF_FLAGS_ALL_PROMISCUOUS) == |
| 1218 | BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1219 | } |
| 1220 | |
| 1221 | static int be_set_vlan_promisc(struct be_adapter *adapter) |
| 1222 | { |
| 1223 | struct device *dev = &adapter->pdev->dev; |
| 1224 | int status; |
| 1225 | |
| 1226 | if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) |
| 1227 | return 0; |
| 1228 | |
| 1229 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, ON); |
| 1230 | if (!status) { |
| 1231 | dev_info(dev, "Enabled VLAN promiscuous mode\n"); |
| 1232 | adapter->if_flags |= BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1233 | } else { |
| 1234 | dev_err(dev, "Failed to enable VLAN promiscuous mode\n"); |
| 1235 | } |
| 1236 | return status; |
| 1237 | } |
| 1238 | |
| 1239 | static int be_clear_vlan_promisc(struct be_adapter *adapter) |
| 1240 | { |
| 1241 | struct device *dev = &adapter->pdev->dev; |
| 1242 | int status; |
| 1243 | |
| 1244 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_VLAN_PROMISCUOUS, OFF); |
| 1245 | if (!status) { |
| 1246 | dev_info(dev, "Disabling VLAN promiscuous mode\n"); |
| 1247 | adapter->if_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 1248 | } |
| 1249 | return status; |
| 1250 | } |
| 1251 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1252 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1253 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 1254 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1255 | */ |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1256 | static int be_vid_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1257 | { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 1258 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1259 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1260 | u16 num = 0, i = 0; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 1261 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1262 | |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1263 | /* No need to further configure vids if in promiscuous mode */ |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1264 | if (be_in_all_promisc(adapter)) |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1265 | return 0; |
| 1266 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1267 | if (adapter->vlans_added > be_max_vlans(adapter)) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1268 | return be_set_vlan_promisc(adapter); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1269 | |
| 1270 | /* Construct VLAN Table to give to HW */ |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1271 | for_each_set_bit(i, adapter->vids, VLAN_N_VID) |
| 1272 | vids[num++] = cpu_to_le16(i); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1273 | |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1274 | status = be_cmd_vlan_config(adapter, adapter->if_handle, vids, num, 0); |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1275 | if (status) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1276 | dev_err(dev, "Setting HW VLAN filtering failed\n"); |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 1277 | /* Set to VLAN promisc mode as setting VLAN filter failed */ |
Kalesh AP | 77be8c1 | 2015-05-06 05:30:35 -0400 | [diff] [blame] | 1278 | if (addl_status(status) == MCC_ADDL_STATUS_INSUFFICIENT_VLANS || |
| 1279 | addl_status(status) == |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 1280 | MCC_ADDL_STATUS_INSUFFICIENT_RESOURCES) |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1281 | return be_set_vlan_promisc(adapter); |
| 1282 | } else if (adapter->if_flags & BE_IF_FLAGS_VLAN_PROMISCUOUS) { |
| 1283 | status = be_clear_vlan_promisc(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1284 | } |
Padmanabh Ratnakar | 0fc16eb | 2012-04-25 01:46:06 +0000 | [diff] [blame] | 1285 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1288 | 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] | 1289 | { |
| 1290 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1291 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1292 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1293 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1294 | if (lancer_chip(adapter) && vid == 0) |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1295 | return status; |
| 1296 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1297 | if (test_bit(vid, adapter->vids)) |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1298 | return status; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1299 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1300 | set_bit(vid, adapter->vids); |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1301 | adapter->vlans_added++; |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1302 | |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1303 | status = be_vid_config(adapter); |
| 1304 | if (status) { |
| 1305 | adapter->vlans_added--; |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1306 | clear_bit(vid, adapter->vids); |
Somnath Kotur | a6b74e0 | 2014-01-21 15:50:55 +0530 | [diff] [blame] | 1307 | } |
Vasundhara Volam | 48291c2 | 2014-03-11 18:53:08 +0530 | [diff] [blame] | 1308 | |
Ajit Khaparde | 80817cb | 2011-12-30 12:15:12 +0000 | [diff] [blame] | 1309 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1312 | 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] | 1313 | { |
| 1314 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1315 | |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1316 | /* Packets with VID 0 are always received by Lancer by default */ |
| 1317 | if (lancer_chip(adapter) && vid == 0) |
Kalesh AP | 9d4dfe4 | 2014-06-30 13:01:33 +0530 | [diff] [blame] | 1318 | return 0; |
Padmanabh Ratnakar | a85e998 | 2012-10-20 06:02:40 +0000 | [diff] [blame] | 1319 | |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 1320 | clear_bit(vid, adapter->vids); |
Kalesh AP | 9d4dfe4 | 2014-06-30 13:01:33 +0530 | [diff] [blame] | 1321 | adapter->vlans_added--; |
| 1322 | |
| 1323 | return be_vid_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1326 | static void be_clear_all_promisc(struct be_adapter *adapter) |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1327 | { |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 1328 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_ALL_PROMISCUOUS, OFF); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1329 | adapter->if_flags &= ~BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1330 | } |
| 1331 | |
| 1332 | static void be_set_all_promisc(struct be_adapter *adapter) |
| 1333 | { |
| 1334 | be_cmd_rx_filter(adapter, BE_IF_FLAGS_ALL_PROMISCUOUS, ON); |
| 1335 | adapter->if_flags |= BE_IF_FLAGS_ALL_PROMISCUOUS; |
| 1336 | } |
| 1337 | |
| 1338 | static void be_set_mc_promisc(struct be_adapter *adapter) |
| 1339 | { |
| 1340 | int status; |
| 1341 | |
| 1342 | if (adapter->if_flags & BE_IF_FLAGS_MCAST_PROMISCUOUS) |
| 1343 | return; |
| 1344 | |
| 1345 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MCAST_PROMISCUOUS, ON); |
| 1346 | if (!status) |
| 1347 | adapter->if_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1348 | } |
| 1349 | |
| 1350 | static void be_set_mc_list(struct be_adapter *adapter) |
| 1351 | { |
| 1352 | int status; |
| 1353 | |
| 1354 | status = be_cmd_rx_filter(adapter, BE_IF_FLAGS_MULTICAST, ON); |
| 1355 | if (!status) |
| 1356 | adapter->if_flags &= ~BE_IF_FLAGS_MCAST_PROMISCUOUS; |
| 1357 | else |
| 1358 | be_set_mc_promisc(adapter); |
| 1359 | } |
| 1360 | |
| 1361 | static void be_set_uc_list(struct be_adapter *adapter) |
| 1362 | { |
| 1363 | struct netdev_hw_addr *ha; |
| 1364 | int i = 1; /* First slot is claimed by the Primary MAC */ |
| 1365 | |
| 1366 | for (; adapter->uc_macs > 0; adapter->uc_macs--, i++) |
| 1367 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 1368 | adapter->pmac_id[i], 0); |
| 1369 | |
| 1370 | if (netdev_uc_count(adapter->netdev) > be_max_uc(adapter)) { |
| 1371 | be_set_all_promisc(adapter); |
| 1372 | return; |
| 1373 | } |
| 1374 | |
| 1375 | netdev_for_each_uc_addr(ha, adapter->netdev) { |
| 1376 | adapter->uc_macs++; /* First slot is for Primary MAC */ |
| 1377 | be_cmd_pmac_add(adapter, (u8 *)ha->addr, adapter->if_handle, |
| 1378 | &adapter->pmac_id[adapter->uc_macs], 0); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | static void be_clear_uc_list(struct be_adapter *adapter) |
| 1383 | { |
| 1384 | int i; |
| 1385 | |
| 1386 | for (i = 1; i < (adapter->uc_macs + 1); i++) |
| 1387 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 1388 | adapter->pmac_id[i], 0); |
| 1389 | adapter->uc_macs = 0; |
Somnath kotur | 7ad0945 | 2014-03-03 14:24:43 +0530 | [diff] [blame] | 1390 | } |
| 1391 | |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 1392 | static void be_set_rx_mode(struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1393 | { |
| 1394 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1395 | |
| 1396 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1397 | be_set_all_promisc(adapter); |
| 1398 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1399 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1400 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1401 | /* Interface was previously in promiscuous mode; disable it */ |
| 1402 | if (be_in_all_promisc(adapter)) { |
| 1403 | be_clear_all_promisc(adapter); |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 1404 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 1405 | be_vid_config(adapter); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1408 | /* Enable multicast promisc if num configured exceeds what we support */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1409 | if (netdev->flags & IFF_ALLMULTI || |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1410 | netdev_mc_count(netdev) > be_max_mc(adapter)) { |
| 1411 | be_set_mc_promisc(adapter); |
Kalesh AP | a079488 | 2014-05-30 19:06:23 +0530 | [diff] [blame] | 1412 | return; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1413 | } |
Kalesh AP | a079488 | 2014-05-30 19:06:23 +0530 | [diff] [blame] | 1414 | |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 1415 | if (netdev_uc_count(netdev) != adapter->uc_macs) |
| 1416 | be_set_uc_list(adapter); |
| 1417 | |
| 1418 | be_set_mc_list(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1421 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 1422 | { |
| 1423 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1424 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1425 | int status; |
| 1426 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1427 | if (!sriov_enabled(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1428 | return -EPERM; |
| 1429 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1430 | if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1431 | return -EINVAL; |
| 1432 | |
Vasundhara Volam | 3c31aaf | 2014-08-01 17:47:31 +0530 | [diff] [blame] | 1433 | /* Proceed further only if user provided MAC is different |
| 1434 | * from active MAC |
| 1435 | */ |
| 1436 | if (ether_addr_equal(mac, vf_cfg->mac_addr)) |
| 1437 | return 0; |
| 1438 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1439 | if (BEx_chip(adapter)) { |
| 1440 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, vf_cfg->pmac_id, |
| 1441 | vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1442 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1443 | status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle, |
| 1444 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 1445 | } else { |
| 1446 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 1447 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1450 | if (status) { |
| 1451 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed: %#x", |
| 1452 | mac, vf, status); |
| 1453 | return be_cmd_status(status); |
| 1454 | } |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1455 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1456 | ether_addr_copy(vf_cfg->mac_addr, mac); |
| 1457 | |
| 1458 | return 0; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1461 | static int be_get_vf_config(struct net_device *netdev, int vf, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1462 | struct ifla_vf_info *vi) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1463 | { |
| 1464 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1465 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1466 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1467 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1468 | return -EPERM; |
| 1469 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1470 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1471 | return -EINVAL; |
| 1472 | |
| 1473 | vi->vf = vf; |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1474 | vi->max_tx_rate = vf_cfg->tx_rate; |
| 1475 | vi->min_tx_rate = 0; |
Ajit Khaparde | a60b3a1 | 2013-09-27 15:18:56 -0500 | [diff] [blame] | 1476 | vi->vlan = vf_cfg->vlan_tag & VLAN_VID_MASK; |
| 1477 | vi->qos = vf_cfg->vlan_tag >> VLAN_PRIO_SHIFT; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1478 | memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1479 | vi->linkstate = adapter->vf_cfg[vf].plink_tracking; |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1480 | vi->spoofchk = adapter->vf_cfg[vf].spoofchk; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1485 | static int be_set_vf_tvt(struct be_adapter *adapter, int vf, u16 vlan) |
| 1486 | { |
| 1487 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 1488 | u16 vids[BE_NUM_VLANS_SUPPORTED]; |
| 1489 | int vf_if_id = vf_cfg->if_handle; |
| 1490 | int status; |
| 1491 | |
| 1492 | /* Enable Transparent VLAN Tagging */ |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1493 | 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] | 1494 | if (status) |
| 1495 | return status; |
| 1496 | |
| 1497 | /* Clear pre-programmed VLAN filters on VF if any, if TVT is enabled */ |
| 1498 | vids[0] = 0; |
| 1499 | status = be_cmd_vlan_config(adapter, vf_if_id, vids, 1, vf + 1); |
| 1500 | if (!status) |
| 1501 | dev_info(&adapter->pdev->dev, |
| 1502 | "Cleared guest VLANs on VF%d", vf); |
| 1503 | |
| 1504 | /* After TVT is enabled, disallow VFs to program VLAN filters */ |
| 1505 | if (vf_cfg->privileges & BE_PRIV_FILTMGMT) { |
| 1506 | status = be_cmd_set_fn_privileges(adapter, vf_cfg->privileges & |
| 1507 | ~BE_PRIV_FILTMGMT, vf + 1); |
| 1508 | if (!status) |
| 1509 | vf_cfg->privileges &= ~BE_PRIV_FILTMGMT; |
| 1510 | } |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | static int be_clear_vf_tvt(struct be_adapter *adapter, int vf) |
| 1515 | { |
| 1516 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 1517 | struct device *dev = &adapter->pdev->dev; |
| 1518 | int status; |
| 1519 | |
| 1520 | /* Reset Transparent VLAN Tagging. */ |
| 1521 | 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] | 1522 | vf_cfg->if_handle, 0, 0); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1523 | if (status) |
| 1524 | return status; |
| 1525 | |
| 1526 | /* Allow VFs to program VLAN filtering */ |
| 1527 | if (!(vf_cfg->privileges & BE_PRIV_FILTMGMT)) { |
| 1528 | status = be_cmd_set_fn_privileges(adapter, vf_cfg->privileges | |
| 1529 | BE_PRIV_FILTMGMT, vf + 1); |
| 1530 | if (!status) { |
| 1531 | vf_cfg->privileges |= BE_PRIV_FILTMGMT; |
| 1532 | dev_info(dev, "VF%d: FILTMGMT priv enabled", vf); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | dev_info(dev, |
| 1537 | "Disable/re-enable i/f in VM to clear Transparent VLAN tag"); |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1541 | static int be_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1542 | { |
| 1543 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1544 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1545 | int status; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1546 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1547 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1548 | return -EPERM; |
| 1549 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1550 | if (vf >= adapter->num_vfs || vlan > 4095 || qos > 7) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1551 | return -EINVAL; |
| 1552 | |
Ajit Khaparde | b9fc0e53 | 2013-09-27 15:18:46 -0500 | [diff] [blame] | 1553 | if (vlan || qos) { |
| 1554 | vlan |= qos << VLAN_PRIO_SHIFT; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1555 | status = be_set_vf_tvt(adapter, vf, vlan); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1556 | } else { |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1557 | status = be_clear_vf_tvt(adapter, vf); |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1560 | if (status) { |
| 1561 | dev_err(&adapter->pdev->dev, |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1562 | "VLAN %d config on VF %d failed : %#x\n", vlan, vf, |
| 1563 | status); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1564 | return be_cmd_status(status); |
| 1565 | } |
| 1566 | |
| 1567 | vf_cfg->vlan_tag = vlan; |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1568 | return 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1571 | static int be_set_vf_tx_rate(struct net_device *netdev, int vf, |
| 1572 | int min_tx_rate, int max_tx_rate) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1573 | { |
| 1574 | struct be_adapter *adapter = netdev_priv(netdev); |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1575 | struct device *dev = &adapter->pdev->dev; |
| 1576 | int percent_rate, status = 0; |
| 1577 | u16 link_speed = 0; |
| 1578 | u8 link_status; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1579 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 1580 | if (!sriov_enabled(adapter)) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1581 | return -EPERM; |
| 1582 | |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1583 | if (vf >= adapter->num_vfs) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1584 | return -EINVAL; |
| 1585 | |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1586 | if (min_tx_rate) |
| 1587 | return -EINVAL; |
| 1588 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1589 | if (!max_tx_rate) |
| 1590 | goto config_qos; |
| 1591 | |
| 1592 | status = be_cmd_link_status_query(adapter, &link_speed, |
| 1593 | &link_status, 0); |
| 1594 | if (status) |
| 1595 | goto err; |
| 1596 | |
| 1597 | if (!link_status) { |
| 1598 | 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] | 1599 | status = -ENETDOWN; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1600 | goto err; |
Ajit Khaparde | 94f434c | 2011-12-30 12:15:30 +0000 | [diff] [blame] | 1601 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1602 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1603 | if (max_tx_rate < 100 || max_tx_rate > link_speed) { |
| 1604 | dev_err(dev, "TX-rate must be between 100 and %d Mbps\n", |
| 1605 | link_speed); |
| 1606 | status = -EINVAL; |
| 1607 | goto err; |
| 1608 | } |
| 1609 | |
| 1610 | /* On Skyhawk the QOS setting must be done only as a % value */ |
| 1611 | percent_rate = link_speed / 100; |
| 1612 | if (skyhawk_chip(adapter) && (max_tx_rate % percent_rate)) { |
| 1613 | dev_err(dev, "TX-rate must be a multiple of %d Mbps\n", |
| 1614 | percent_rate); |
| 1615 | status = -EINVAL; |
| 1616 | goto err; |
| 1617 | } |
| 1618 | |
| 1619 | config_qos: |
| 1620 | 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] | 1621 | if (status) |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 1622 | goto err; |
| 1623 | |
| 1624 | adapter->vf_cfg[vf].tx_rate = max_tx_rate; |
| 1625 | return 0; |
| 1626 | |
| 1627 | err: |
| 1628 | dev_err(dev, "TX-rate setting of %dMbps on VF%d failed\n", |
| 1629 | max_tx_rate, vf); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1630 | return be_cmd_status(status); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1631 | } |
Kalesh AP | e2fb1af | 2014-09-19 15:46:58 +0530 | [diff] [blame] | 1632 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1633 | static int be_set_vf_link_state(struct net_device *netdev, int vf, |
| 1634 | int link_state) |
| 1635 | { |
| 1636 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1637 | int status; |
| 1638 | |
| 1639 | if (!sriov_enabled(adapter)) |
| 1640 | return -EPERM; |
| 1641 | |
| 1642 | if (vf >= adapter->num_vfs) |
| 1643 | return -EINVAL; |
| 1644 | |
| 1645 | status = be_cmd_set_logical_link_config(adapter, link_state, vf+1); |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1646 | if (status) { |
| 1647 | dev_err(&adapter->pdev->dev, |
| 1648 | "Link state change on VF %d failed: %#x\n", vf, status); |
| 1649 | return be_cmd_status(status); |
| 1650 | } |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1651 | |
Kalesh AP | abccf23 | 2014-07-17 16:20:24 +0530 | [diff] [blame] | 1652 | adapter->vf_cfg[vf].plink_tracking = link_state; |
| 1653 | |
| 1654 | return 0; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 1655 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1656 | |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 1657 | static int be_set_vf_spoofchk(struct net_device *netdev, int vf, bool enable) |
| 1658 | { |
| 1659 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1660 | struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf]; |
| 1661 | u8 spoofchk; |
| 1662 | int status; |
| 1663 | |
| 1664 | if (!sriov_enabled(adapter)) |
| 1665 | return -EPERM; |
| 1666 | |
| 1667 | if (vf >= adapter->num_vfs) |
| 1668 | return -EINVAL; |
| 1669 | |
| 1670 | if (BEx_chip(adapter)) |
| 1671 | return -EOPNOTSUPP; |
| 1672 | |
| 1673 | if (enable == vf_cfg->spoofchk) |
| 1674 | return 0; |
| 1675 | |
| 1676 | spoofchk = enable ? ENABLE_MAC_SPOOFCHK : DISABLE_MAC_SPOOFCHK; |
| 1677 | |
| 1678 | status = be_cmd_set_hsw_config(adapter, 0, vf + 1, vf_cfg->if_handle, |
| 1679 | 0, spoofchk); |
| 1680 | if (status) { |
| 1681 | dev_err(&adapter->pdev->dev, |
| 1682 | "Spoofchk change on VF %d failed: %#x\n", vf, status); |
| 1683 | return be_cmd_status(status); |
| 1684 | } |
| 1685 | |
| 1686 | vf_cfg->spoofchk = enable; |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1690 | static void be_aic_update(struct be_aic_obj *aic, u64 rx_pkts, u64 tx_pkts, |
| 1691 | ulong now) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1692 | { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1693 | aic->rx_pkts_prev = rx_pkts; |
| 1694 | aic->tx_reqs_prev = tx_pkts; |
| 1695 | aic->jiffies = now; |
| 1696 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1697 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 1698 | static int be_get_new_eqd(struct be_eq_obj *eqo) |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1699 | { |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 1700 | struct be_adapter *adapter = eqo->adapter; |
| 1701 | int eqd, start; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1702 | struct be_aic_obj *aic; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1703 | struct be_rx_obj *rxo; |
| 1704 | struct be_tx_obj *txo; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 1705 | u64 rx_pkts = 0, tx_pkts = 0; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1706 | ulong now; |
| 1707 | u32 pps, delta; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 1708 | int i; |
| 1709 | |
| 1710 | aic = &adapter->aic_obj[eqo->idx]; |
| 1711 | if (!aic->enable) { |
| 1712 | if (aic->jiffies) |
| 1713 | aic->jiffies = 0; |
| 1714 | eqd = aic->et_eqd; |
| 1715 | return eqd; |
| 1716 | } |
| 1717 | |
| 1718 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 1719 | do { |
| 1720 | start = u64_stats_fetch_begin_irq(&rxo->stats.sync); |
| 1721 | rx_pkts += rxo->stats.rx_pkts; |
| 1722 | } while (u64_stats_fetch_retry_irq(&rxo->stats.sync, start)); |
| 1723 | } |
| 1724 | |
| 1725 | for_all_tx_queues_on_eq(adapter, eqo, txo, i) { |
| 1726 | do { |
| 1727 | start = u64_stats_fetch_begin_irq(&txo->stats.sync); |
| 1728 | tx_pkts += txo->stats.tx_reqs; |
| 1729 | } while (u64_stats_fetch_retry_irq(&txo->stats.sync, start)); |
| 1730 | } |
| 1731 | |
| 1732 | /* Skip, if wrapped around or first calculation */ |
| 1733 | now = jiffies; |
| 1734 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
| 1735 | rx_pkts < aic->rx_pkts_prev || |
| 1736 | tx_pkts < aic->tx_reqs_prev) { |
| 1737 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 1738 | return aic->prev_eqd; |
| 1739 | } |
| 1740 | |
| 1741 | delta = jiffies_to_msecs(now - aic->jiffies); |
| 1742 | if (delta == 0) |
| 1743 | return aic->prev_eqd; |
| 1744 | |
| 1745 | pps = (((u32)(rx_pkts - aic->rx_pkts_prev) * 1000) / delta) + |
| 1746 | (((u32)(tx_pkts - aic->tx_reqs_prev) * 1000) / delta); |
| 1747 | eqd = (pps / 15000) << 2; |
| 1748 | |
| 1749 | if (eqd < 8) |
| 1750 | eqd = 0; |
| 1751 | eqd = min_t(u32, eqd, aic->max_eqd); |
| 1752 | eqd = max_t(u32, eqd, aic->min_eqd); |
| 1753 | |
| 1754 | be_aic_update(aic, rx_pkts, tx_pkts, now); |
| 1755 | |
| 1756 | return eqd; |
| 1757 | } |
| 1758 | |
| 1759 | /* For Skyhawk-R only */ |
| 1760 | static u32 be_get_eq_delay_mult_enc(struct be_eq_obj *eqo) |
| 1761 | { |
| 1762 | struct be_adapter *adapter = eqo->adapter; |
| 1763 | struct be_aic_obj *aic = &adapter->aic_obj[eqo->idx]; |
| 1764 | ulong now = jiffies; |
| 1765 | int eqd; |
| 1766 | u32 mult_enc; |
| 1767 | |
| 1768 | if (!aic->enable) |
| 1769 | return 0; |
| 1770 | |
| 1771 | if (time_before_eq(now, aic->jiffies) || |
| 1772 | jiffies_to_msecs(now - aic->jiffies) < 1) |
| 1773 | eqd = aic->prev_eqd; |
| 1774 | else |
| 1775 | eqd = be_get_new_eqd(eqo); |
| 1776 | |
| 1777 | if (eqd > 100) |
| 1778 | mult_enc = R2I_DLY_ENC_1; |
| 1779 | else if (eqd > 60) |
| 1780 | mult_enc = R2I_DLY_ENC_2; |
| 1781 | else if (eqd > 20) |
| 1782 | mult_enc = R2I_DLY_ENC_3; |
| 1783 | else |
| 1784 | mult_enc = R2I_DLY_ENC_0; |
| 1785 | |
| 1786 | aic->prev_eqd = eqd; |
| 1787 | |
| 1788 | return mult_enc; |
| 1789 | } |
| 1790 | |
| 1791 | void be_eqd_update(struct be_adapter *adapter, bool force_update) |
| 1792 | { |
| 1793 | struct be_set_eqd set_eqd[MAX_EVT_QS]; |
| 1794 | struct be_aic_obj *aic; |
| 1795 | struct be_eq_obj *eqo; |
| 1796 | int i, num = 0, eqd; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1797 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1798 | for_all_evt_queues(adapter, eqo, i) { |
| 1799 | aic = &adapter->aic_obj[eqo->idx]; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 1800 | eqd = be_get_new_eqd(eqo); |
| 1801 | if (force_update || eqd != aic->prev_eqd) { |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1802 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 1803 | set_eqd[num].eq_id = eqo->q.id; |
| 1804 | aic->prev_eqd = eqd; |
| 1805 | num++; |
| 1806 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1807 | } |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1808 | |
| 1809 | if (num) |
| 1810 | be_cmd_modify_eqd(adapter, set_eqd, num); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1813 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1814 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1815 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1816 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1817 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1818 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1819 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1820 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1821 | stats->rx_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1822 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1823 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1824 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1825 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1826 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1829 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1830 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 1831 | /* L4 checksum is not reliable for non TCP/UDP packets. |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1832 | * Also ignore ipcksm for ipv6 pkts |
| 1833 | */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1834 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1835 | (rxcp->ip_csum || rxcp->ipv6) && !rxcp->err; |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1838 | 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] | 1839 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1840 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1841 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1842 | struct be_queue_info *rxq = &rxo->q; |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1843 | u16 frag_idx = rxq->tail; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1844 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1845 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1846 | BUG_ON(!rx_page_info->page); |
| 1847 | |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1848 | if (rx_page_info->last_frag) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1849 | dma_unmap_page(&adapter->pdev->dev, |
| 1850 | dma_unmap_addr(rx_page_info, bus), |
| 1851 | adapter->big_page_size, DMA_FROM_DEVICE); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 1852 | rx_page_info->last_frag = false; |
| 1853 | } else { |
| 1854 | dma_sync_single_for_cpu(&adapter->pdev->dev, |
| 1855 | dma_unmap_addr(rx_page_info, bus), |
| 1856 | rx_frag_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1857 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1858 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1859 | queue_tail_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1860 | atomic_dec(&rxq->used); |
| 1861 | return rx_page_info; |
| 1862 | } |
| 1863 | |
| 1864 | /* Throwaway the data in the Rx completion */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1865 | static void be_rx_compl_discard(struct be_rx_obj *rxo, |
| 1866 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1867 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1868 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1869 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1870 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1871 | for (i = 0; i < num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1872 | page_info = get_rx_page_info(rxo); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1873 | put_page(page_info->page); |
| 1874 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | /* |
| 1879 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 1880 | * indicated by rxcp. |
| 1881 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1882 | static void skb_fill_rx_data(struct be_rx_obj *rxo, struct sk_buff *skb, |
| 1883 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1884 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1885 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1886 | u16 i, j; |
| 1887 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1888 | u8 *start; |
| 1889 | |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1890 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1891 | start = page_address(page_info->page) + page_info->page_offset; |
| 1892 | prefetch(start); |
| 1893 | |
| 1894 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1895 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1896 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1897 | skb->len = curr_frag_len; |
| 1898 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1899 | memcpy(skb->data, start, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1900 | /* Complete packet has now been moved to data */ |
| 1901 | put_page(page_info->page); |
| 1902 | skb->data_len = 0; |
| 1903 | skb->tail += curr_frag_len; |
| 1904 | } else { |
Eric Dumazet | ac1ae5f | 2012-07-13 03:19:41 +0000 | [diff] [blame] | 1905 | hdr_len = ETH_HLEN; |
| 1906 | memcpy(skb->data, start, hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1907 | skb_shinfo(skb)->nr_frags = 1; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1908 | skb_frag_set_page(skb, 0, page_info->page); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1909 | skb_shinfo(skb)->frags[0].page_offset = |
| 1910 | page_info->page_offset + hdr_len; |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 1911 | skb_frag_size_set(&skb_shinfo(skb)->frags[0], |
| 1912 | curr_frag_len - hdr_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1913 | skb->data_len = curr_frag_len - hdr_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1914 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1915 | skb->tail += hdr_len; |
| 1916 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1917 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1918 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1919 | if (rxcp->pkt_size <= rx_frag_size) { |
| 1920 | BUG_ON(rxcp->num_rcvd != 1); |
| 1921 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1925 | remaining = rxcp->pkt_size - curr_frag_len; |
| 1926 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 1927 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1928 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1929 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1930 | /* Coalesce all frags from the same physical page in one slot */ |
| 1931 | if (page_info->page_offset == 0) { |
| 1932 | /* Fresh page */ |
| 1933 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 1934 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1935 | skb_shinfo(skb)->frags[j].page_offset = |
| 1936 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1937 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1938 | skb_shinfo(skb)->nr_frags++; |
| 1939 | } else { |
| 1940 | put_page(page_info->page); |
| 1941 | } |
| 1942 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1943 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1944 | skb->len += curr_frag_len; |
| 1945 | skb->data_len += curr_frag_len; |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 1946 | skb->truesize += rx_frag_size; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1947 | remaining -= curr_frag_len; |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1948 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1949 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1950 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1953 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1954 | 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] | 1955 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1956 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1957 | struct be_adapter *adapter = rxo->adapter; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1958 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1959 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1960 | |
Eric Dumazet | bb349bb | 2012-01-25 03:56:30 +0000 | [diff] [blame] | 1961 | skb = netdev_alloc_skb_ip_align(netdev, BE_RX_SKB_ALLOC_SIZE); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 1962 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1963 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1964 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1965 | return; |
| 1966 | } |
| 1967 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1968 | skb_fill_rx_data(rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1969 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1970 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1971 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 1972 | else |
| 1973 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1974 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1975 | skb->protocol = eth_type_trans(skb, netdev); |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 1976 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1977 | if (netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 1978 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 1979 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 1980 | skb->csum_level = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 1981 | skb_mark_napi_id(skb, napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1982 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 1983 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1984 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1985 | |
| 1986 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1989 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1990 | static void be_rx_compl_process_gro(struct be_rx_obj *rxo, |
| 1991 | struct napi_struct *napi, |
| 1992 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1993 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1994 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1995 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1996 | struct sk_buff *skb = NULL; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1997 | u16 remaining, curr_frag_len; |
| 1998 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 1999 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2000 | skb = napi_get_frags(napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2001 | if (!skb) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2002 | be_rx_compl_discard(rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2003 | return; |
| 2004 | } |
| 2005 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2006 | remaining = rxcp->pkt_size; |
| 2007 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2008 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2009 | |
| 2010 | curr_frag_len = min(remaining, rx_frag_size); |
| 2011 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2012 | /* Coalesce all frags from the same physical page in one slot */ |
| 2013 | if (i == 0 || page_info->page_offset == 0) { |
| 2014 | /* First frag or Fresh page */ |
| 2015 | j++; |
Ian Campbell | b061b39 | 2011-08-29 23:18:23 +0000 | [diff] [blame] | 2016 | skb_frag_set_page(skb, j, page_info->page); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2017 | skb_shinfo(skb)->frags[j].page_offset = |
| 2018 | page_info->page_offset; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2019 | skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0); |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2020 | } else { |
| 2021 | put_page(page_info->page); |
| 2022 | } |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2023 | skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len); |
Eric Dumazet | bdb28a9 | 2011-10-13 06:31:02 +0000 | [diff] [blame] | 2024 | skb->truesize += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2025 | remaining -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2026 | memset(page_info, 0, sizeof(*page_info)); |
| 2027 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 2028 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2029 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2030 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2031 | skb->len = rxcp->pkt_size; |
| 2032 | skb->data_len = rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2033 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | aaa6dae | 2012-05-02 03:40:49 +0000 | [diff] [blame] | 2034 | skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 2035 | if (adapter->netdev->features & NETIF_F_RXHASH) |
Tom Herbert | d2464c8 | 2013-12-17 23:23:51 -0800 | [diff] [blame] | 2036 | skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2037 | |
Tom Herbert | b6c0e89 | 2014-08-27 21:27:17 -0700 | [diff] [blame] | 2038 | skb->csum_level = rxcp->tunneled; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2039 | skb_mark_napi_id(skb, napi); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 2040 | |
Jiri Pirko | 343e43c | 2011-08-25 02:50:51 +0000 | [diff] [blame] | 2041 | if (rxcp->vlanf) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2042 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag); |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 2043 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2044 | napi_gro_frags(napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2047 | static void be_parse_rx_compl_v1(struct be_eth_rx_compl *compl, |
| 2048 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2049 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2050 | rxcp->pkt_size = GET_RX_COMPL_V1_BITS(pktsize, compl); |
| 2051 | rxcp->vlanf = GET_RX_COMPL_V1_BITS(vtp, compl); |
| 2052 | rxcp->err = GET_RX_COMPL_V1_BITS(err, compl); |
| 2053 | rxcp->tcpf = GET_RX_COMPL_V1_BITS(tcpf, compl); |
| 2054 | rxcp->udpf = GET_RX_COMPL_V1_BITS(udpf, compl); |
| 2055 | rxcp->ip_csum = GET_RX_COMPL_V1_BITS(ipcksm, compl); |
| 2056 | rxcp->l4_csum = GET_RX_COMPL_V1_BITS(l4_cksm, compl); |
| 2057 | rxcp->ipv6 = GET_RX_COMPL_V1_BITS(ip_version, compl); |
| 2058 | rxcp->num_rcvd = GET_RX_COMPL_V1_BITS(numfrags, compl); |
| 2059 | rxcp->pkt_type = GET_RX_COMPL_V1_BITS(cast_enc, compl); |
| 2060 | rxcp->rss_hash = GET_RX_COMPL_V1_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2061 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2062 | rxcp->qnq = GET_RX_COMPL_V1_BITS(qnq, compl); |
| 2063 | rxcp->vlan_tag = GET_RX_COMPL_V1_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2064 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2065 | rxcp->port = GET_RX_COMPL_V1_BITS(port, compl); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 2066 | rxcp->tunneled = |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2067 | GET_RX_COMPL_V1_BITS(tunneled, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2068 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2069 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2070 | static void be_parse_rx_compl_v0(struct be_eth_rx_compl *compl, |
| 2071 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2072 | { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2073 | rxcp->pkt_size = GET_RX_COMPL_V0_BITS(pktsize, compl); |
| 2074 | rxcp->vlanf = GET_RX_COMPL_V0_BITS(vtp, compl); |
| 2075 | rxcp->err = GET_RX_COMPL_V0_BITS(err, compl); |
| 2076 | rxcp->tcpf = GET_RX_COMPL_V0_BITS(tcpf, compl); |
| 2077 | rxcp->udpf = GET_RX_COMPL_V0_BITS(udpf, compl); |
| 2078 | rxcp->ip_csum = GET_RX_COMPL_V0_BITS(ipcksm, compl); |
| 2079 | rxcp->l4_csum = GET_RX_COMPL_V0_BITS(l4_cksm, compl); |
| 2080 | rxcp->ipv6 = GET_RX_COMPL_V0_BITS(ip_version, compl); |
| 2081 | rxcp->num_rcvd = GET_RX_COMPL_V0_BITS(numfrags, compl); |
| 2082 | rxcp->pkt_type = GET_RX_COMPL_V0_BITS(cast_enc, compl); |
| 2083 | rxcp->rss_hash = GET_RX_COMPL_V0_BITS(rsshash, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2084 | if (rxcp->vlanf) { |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2085 | rxcp->qnq = GET_RX_COMPL_V0_BITS(qnq, compl); |
| 2086 | rxcp->vlan_tag = GET_RX_COMPL_V0_BITS(vlan_tag, compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2087 | } |
Sathya Perla | c3c18bc | 2014-09-02 09:56:47 +0530 | [diff] [blame] | 2088 | rxcp->port = GET_RX_COMPL_V0_BITS(port, compl); |
| 2089 | rxcp->ip_frag = GET_RX_COMPL_V0_BITS(ip_frag, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 2093 | { |
| 2094 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 2095 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 2096 | struct be_adapter *adapter = rxo->adapter; |
| 2097 | |
| 2098 | /* For checking the valid bit it is Ok to use either definition as the |
| 2099 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 2100 | 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] | 2101 | return NULL; |
| 2102 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 2103 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2104 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 2105 | |
| 2106 | if (adapter->be3_native) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2107 | be_parse_rx_compl_v1(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2108 | else |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2109 | be_parse_rx_compl_v0(compl, rxcp); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2110 | |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 2111 | if (rxcp->ip_frag) |
| 2112 | rxcp->l4_csum = 0; |
| 2113 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2114 | if (rxcp->vlanf) { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 2115 | /* In QNQ modes, if qnq bit is not set, then the packet was |
| 2116 | * tagged only with the transparent outer vlan-tag and must |
| 2117 | * not be treated as a vlan packet by host |
| 2118 | */ |
| 2119 | if (be_is_qnq_mode(adapter) && !rxcp->qnq) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2120 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2121 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2122 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 2123 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2124 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 2125 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
Ravikumar Nelavelli | f6cbd36 | 2014-05-09 13:29:16 +0530 | [diff] [blame] | 2126 | !test_bit(rxcp->vlan_tag, adapter->vids)) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 2127 | rxcp->vlanf = 0; |
| 2128 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2129 | |
| 2130 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 2131 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2132 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2133 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2134 | return rxcp; |
| 2135 | } |
| 2136 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2137 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2138 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2139 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2140 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2141 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2142 | gfp |= __GFP_COMP; |
| 2143 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | /* |
| 2147 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 2148 | * receive buffers to BE |
| 2149 | */ |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2150 | 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] | 2151 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2152 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 2153 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2154 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2155 | struct page *pagep = NULL; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2156 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2157 | struct be_eth_rx_d *rxd; |
| 2158 | u64 page_dmaaddr = 0, frag_dmaaddr; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2159 | u32 posted, page_offset = 0, notify = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2160 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2161 | page_info = &rxo->page_info_tbl[rxq->head]; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2162 | for (posted = 0; posted < frags_needed && !page_info->page; posted++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2163 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2164 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2165 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 2166 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2167 | break; |
| 2168 | } |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2169 | page_dmaaddr = dma_map_page(dev, pagep, 0, |
| 2170 | adapter->big_page_size, |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2171 | DMA_FROM_DEVICE); |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2172 | if (dma_mapping_error(dev, page_dmaaddr)) { |
| 2173 | put_page(pagep); |
| 2174 | pagep = NULL; |
Vasundhara Volam | d3de154 | 2014-09-02 09:56:50 +0530 | [diff] [blame] | 2175 | adapter->drv_stats.dma_map_errors++; |
Ivan Vecera | ba42fad | 2014-01-15 11:11:34 +0100 | [diff] [blame] | 2176 | break; |
| 2177 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2178 | page_offset = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2179 | } else { |
| 2180 | get_page(pagep); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2181 | page_offset += rx_frag_size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2182 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2183 | page_info->page_offset = page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2184 | page_info->page = pagep; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2185 | |
| 2186 | rxd = queue_head_node(rxq); |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2187 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2188 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 2189 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2190 | |
| 2191 | /* Any space left in the current big page for another frag? */ |
| 2192 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 2193 | adapter->big_page_size) { |
| 2194 | pagep = NULL; |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2195 | page_info->last_frag = true; |
| 2196 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
| 2197 | } else { |
| 2198 | dma_unmap_addr_set(page_info, bus, frag_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2199 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 2200 | |
| 2201 | prev_page_info = page_info; |
| 2202 | queue_head_inc(rxq); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2203 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2204 | } |
Sathya Perla | e50287b | 2014-03-04 12:14:38 +0530 | [diff] [blame] | 2205 | |
| 2206 | /* Mark the last frag of a page when we break out of the above loop |
| 2207 | * with no more slots available in the RXQ |
| 2208 | */ |
| 2209 | if (pagep) { |
| 2210 | prev_page_info->last_frag = true; |
| 2211 | dma_unmap_addr_set(prev_page_info, bus, page_dmaaddr); |
| 2212 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2213 | |
| 2214 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2215 | atomic_add(posted, &rxq->used); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2216 | if (rxo->rx_post_starved) |
| 2217 | rxo->rx_post_starved = false; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2218 | do { |
Ajit Khaparde | 69304cc | 2015-04-08 16:59:48 -0500 | [diff] [blame] | 2219 | notify = min(MAX_NUM_POST_ERX_DB, posted); |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2220 | be_rxq_notify(adapter, rxq->id, notify); |
| 2221 | posted -= notify; |
| 2222 | } while (posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2223 | } else if (atomic_read(&rxq->used) == 0) { |
| 2224 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2225 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2226 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2229 | 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] | 2230 | { |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2231 | struct be_queue_info *tx_cq = &txo->cq; |
| 2232 | struct be_tx_compl_info *txcp = &txo->txcp; |
| 2233 | struct be_eth_tx_compl *compl = queue_tail_node(tx_cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2234 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2235 | if (compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2236 | return NULL; |
| 2237 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2238 | /* Ensure load ordering of valid bit dword and other dwords below */ |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 2239 | rmb(); |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2240 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2241 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2242 | txcp->status = GET_TX_COMPL_BITS(status, compl); |
| 2243 | txcp->end_index = GET_TX_COMPL_BITS(wrb_index, compl); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2244 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2245 | compl->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2246 | queue_tail_inc(tx_cq); |
| 2247 | return txcp; |
| 2248 | } |
| 2249 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2250 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2251 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2252 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2253 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2254 | struct be_queue_info *txq = &txo->q; |
| 2255 | u16 frag_index, num_wrbs = 0; |
| 2256 | struct sk_buff *skb = NULL; |
| 2257 | bool unmap_skb_hdr = false; |
| 2258 | struct be_eth_wrb *wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2259 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2260 | do { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2261 | if (sent_skbs[txq->tail]) { |
| 2262 | /* Free skb from prev req */ |
| 2263 | if (skb) |
| 2264 | dev_consume_skb_any(skb); |
| 2265 | skb = sent_skbs[txq->tail]; |
| 2266 | sent_skbs[txq->tail] = NULL; |
| 2267 | queue_tail_inc(txq); /* skip hdr wrb */ |
| 2268 | num_wrbs++; |
| 2269 | unmap_skb_hdr = true; |
| 2270 | } |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 2271 | wrb = queue_tail_node(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2272 | frag_index = txq->tail; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2273 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2274 | (unmap_skb_hdr && skb_headlen(skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 2275 | unmap_skb_hdr = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2276 | queue_tail_inc(txq); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2277 | num_wrbs++; |
| 2278 | } while (frag_index != last_index); |
| 2279 | dev_consume_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2280 | |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 2281 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2284 | /* Return the number of events in the event queue */ |
| 2285 | static inline int events_get(struct be_eq_obj *eqo) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2286 | { |
| 2287 | struct be_eq_entry *eqe; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2288 | int num = 0; |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2289 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2290 | do { |
| 2291 | eqe = queue_tail_node(&eqo->q); |
| 2292 | if (eqe->evt == 0) |
| 2293 | break; |
| 2294 | |
| 2295 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2296 | eqe->evt = 0; |
| 2297 | num++; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2298 | queue_tail_inc(&eqo->q); |
| 2299 | } while (true); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 2300 | |
| 2301 | return num; |
| 2302 | } |
| 2303 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2304 | /* Leaves the EQ is disarmed state */ |
| 2305 | static void be_eq_clean(struct be_eq_obj *eqo) |
| 2306 | { |
| 2307 | int num = events_get(eqo); |
| 2308 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2309 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, num, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | static void be_rx_cq_clean(struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2313 | { |
| 2314 | struct be_rx_page_info *page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2315 | struct be_queue_info *rxq = &rxo->q; |
| 2316 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2317 | struct be_rx_compl_info *rxcp; |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2318 | struct be_adapter *adapter = rxo->adapter; |
| 2319 | int flush_wait = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2320 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2321 | /* Consume pending rx completions. |
| 2322 | * Wait for the flush completion (identified by zero num_rcvd) |
| 2323 | * to arrive. Notify CQ even when there are no more CQ entries |
| 2324 | * for HW to flush partially coalesced CQ entries. |
| 2325 | * In Lancer, there is no need to wait for flush compl. |
| 2326 | */ |
| 2327 | for (;;) { |
| 2328 | rxcp = be_rx_compl_get(rxo); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 2329 | if (!rxcp) { |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2330 | if (lancer_chip(adapter)) |
| 2331 | break; |
| 2332 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 2333 | if (flush_wait++ > 50 || |
| 2334 | be_check_error(adapter, |
| 2335 | BE_ERROR_HW)) { |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2336 | dev_warn(&adapter->pdev->dev, |
| 2337 | "did not receive flush compl\n"); |
| 2338 | break; |
| 2339 | } |
| 2340 | be_cq_notify(adapter, rx_cq->id, true, 0); |
| 2341 | mdelay(1); |
| 2342 | } else { |
| 2343 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 3f5dffe | 2013-05-08 02:05:49 +0000 | [diff] [blame] | 2344 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2345 | if (rxcp->num_rcvd == 0) |
| 2346 | break; |
| 2347 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Sathya Perla | d23e946 | 2012-12-17 19:38:51 +0000 | [diff] [blame] | 2350 | /* After cleanup, leave the CQ in unarmed state */ |
| 2351 | be_cq_notify(adapter, rx_cq->id, false, 0); |
| 2352 | |
| 2353 | /* Then free posted rx buffers that were not used */ |
Suresh Reddy | 0b0ef1d | 2014-01-15 13:23:38 +0530 | [diff] [blame] | 2354 | while (atomic_read(&rxq->used) > 0) { |
| 2355 | page_info = get_rx_page_info(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2356 | put_page(page_info->page); |
| 2357 | memset(page_info, 0, sizeof(*page_info)); |
| 2358 | } |
| 2359 | BUG_ON(atomic_read(&rxq->used)); |
Kalesh AP | 5f820b6 | 2014-09-19 15:47:01 +0530 | [diff] [blame] | 2360 | rxq->tail = 0; |
| 2361 | rxq->head = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2364 | static void be_tx_compl_clean(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2365 | { |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2366 | u16 end_idx, notified_idx, cmpl = 0, timeo = 0, num_wrbs = 0; |
| 2367 | struct device *dev = &adapter->pdev->dev; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2368 | struct be_tx_compl_info *txcp; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2369 | struct be_queue_info *txq; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2370 | struct be_tx_obj *txo; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2371 | int i, pending_txqs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2372 | |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2373 | /* Stop polling for compls when HW has been silent for 10ms */ |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2374 | do { |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2375 | pending_txqs = adapter->num_tx_qs; |
| 2376 | |
| 2377 | for_all_tx_queues(adapter, txo, i) { |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2378 | cmpl = 0; |
| 2379 | num_wrbs = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2380 | txq = &txo->q; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2381 | while ((txcp = be_tx_compl_get(txo))) { |
| 2382 | num_wrbs += |
| 2383 | be_tx_compl_process(adapter, txo, |
| 2384 | txcp->end_index); |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2385 | cmpl++; |
| 2386 | } |
| 2387 | if (cmpl) { |
| 2388 | be_cq_notify(adapter, txo->cq.id, false, cmpl); |
| 2389 | atomic_sub(num_wrbs, &txq->used); |
Vasundhara Volam | 1a3d071 | 2014-04-14 16:12:40 +0530 | [diff] [blame] | 2390 | timeo = 0; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2391 | } |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 2392 | if (!be_is_tx_compl_pending(txo)) |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2393 | pending_txqs--; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 2396 | if (pending_txqs == 0 || ++timeo > 10 || |
| 2397 | be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | |
| 2400 | mdelay(1); |
| 2401 | } while (true); |
| 2402 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2403 | /* Free enqueued TX that was never notified to HW */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2404 | for_all_tx_queues(adapter, txo, i) { |
| 2405 | txq = &txo->q; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2406 | |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2407 | if (atomic_read(&txq->used)) { |
| 2408 | dev_info(dev, "txq%d: cleaning %d pending tx-wrbs\n", |
| 2409 | i, atomic_read(&txq->used)); |
| 2410 | notified_idx = txq->tail; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2411 | end_idx = txq->tail; |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2412 | index_adv(&end_idx, atomic_read(&txq->used) - 1, |
| 2413 | txq->len); |
| 2414 | /* Use the tx-compl process logic to handle requests |
| 2415 | * that were not sent to the HW. |
| 2416 | */ |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2417 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
| 2418 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | 5f07b3c | 2015-01-05 05:48:34 -0500 | [diff] [blame] | 2419 | BUG_ON(atomic_read(&txq->used)); |
| 2420 | txo->pend_wrb_cnt = 0; |
| 2421 | /* Since hw was never notified of these requests, |
| 2422 | * reset TXQ indices |
| 2423 | */ |
| 2424 | txq->head = notified_idx; |
| 2425 | txq->tail = notified_idx; |
Sathya Perla | 0ae57bb | 2012-02-23 18:50:14 +0000 | [diff] [blame] | 2426 | } |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 2427 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2430 | static void be_evt_queues_destroy(struct be_adapter *adapter) |
| 2431 | { |
| 2432 | struct be_eq_obj *eqo; |
| 2433 | int i; |
| 2434 | |
| 2435 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2436 | if (eqo->q.created) { |
| 2437 | be_eq_clean(eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2438 | be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2439 | napi_hash_del(&eqo->napi); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2440 | netif_napi_del(&eqo->napi); |
Padmanabh Ratnakar | 19d59aa | 2012-07-12 03:57:21 +0000 | [diff] [blame] | 2441 | } |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 2442 | free_cpumask_var(eqo->affinity_mask); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2443 | be_queue_free(adapter, &eqo->q); |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | static int be_evt_queues_create(struct be_adapter *adapter) |
| 2448 | { |
| 2449 | struct be_queue_info *eq; |
| 2450 | struct be_eq_obj *eqo; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2451 | struct be_aic_obj *aic; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2452 | int i, rc; |
| 2453 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2454 | adapter->num_evt_qs = min_t(u16, num_irqs(adapter), |
| 2455 | adapter->cfg_num_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2456 | |
| 2457 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 2458 | if (!zalloc_cpumask_var(&eqo->affinity_mask, GFP_KERNEL)) |
| 2459 | return -ENOMEM; |
| 2460 | cpumask_set_cpu_local_first(i, dev_to_node(&adapter->pdev->dev), |
| 2461 | eqo->affinity_mask); |
| 2462 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2463 | netif_napi_add(adapter->netdev, &eqo->napi, be_poll, |
| 2464 | BE_NAPI_WEIGHT); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2465 | napi_hash_add(&eqo->napi); |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2466 | aic = &adapter->aic_obj[i]; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2467 | eqo->adapter = adapter; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2468 | eqo->idx = i; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 2469 | aic->max_eqd = BE_MAX_EQD; |
| 2470 | aic->enable = true; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2471 | |
| 2472 | eq = &eqo->q; |
| 2473 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2474 | sizeof(struct be_eq_entry)); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2475 | if (rc) |
| 2476 | return rc; |
| 2477 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 2478 | rc = be_cmd_eq_create(adapter, eqo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2479 | if (rc) |
| 2480 | return rc; |
| 2481 | } |
Sathya Perla | 1cfafab | 2012-02-23 18:50:15 +0000 | [diff] [blame] | 2482 | return 0; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2485 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 2486 | { |
| 2487 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2488 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2489 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2490 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2491 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2492 | be_queue_free(adapter, q); |
| 2493 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2494 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2495 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2496 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2497 | be_queue_free(adapter, q); |
| 2498 | } |
| 2499 | |
| 2500 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 2501 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 2502 | { |
| 2503 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2504 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2505 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2506 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2507 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2508 | goto err; |
| 2509 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2510 | /* Use the default EQ for MCC completions */ |
| 2511 | 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] | 2512 | goto mcc_cq_free; |
| 2513 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2514 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2515 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 2516 | goto mcc_cq_destroy; |
| 2517 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2518 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2519 | goto mcc_q_free; |
| 2520 | |
| 2521 | return 0; |
| 2522 | |
| 2523 | mcc_q_free: |
| 2524 | be_queue_free(adapter, q); |
| 2525 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2526 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2527 | mcc_cq_free: |
| 2528 | be_queue_free(adapter, cq); |
| 2529 | err: |
| 2530 | return -1; |
| 2531 | } |
| 2532 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2533 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 2534 | { |
| 2535 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2536 | struct be_tx_obj *txo; |
| 2537 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2538 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2539 | for_all_tx_queues(adapter, txo, i) { |
| 2540 | q = &txo->q; |
| 2541 | if (q->created) |
| 2542 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 2543 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2544 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2545 | q = &txo->cq; |
| 2546 | if (q->created) |
| 2547 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2548 | be_queue_free(adapter, q); |
| 2549 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 2552 | static int be_tx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2553 | { |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2554 | struct be_queue_info *cq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2555 | struct be_tx_obj *txo; |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2556 | struct be_eq_obj *eqo; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2557 | int status, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2558 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2559 | adapter->num_tx_qs = min(adapter->num_evt_qs, be_max_txqs(adapter)); |
Sathya Perla | dafc0fe | 2011-10-24 02:45:02 +0000 | [diff] [blame] | 2560 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2561 | for_all_tx_queues(adapter, txo, i) { |
| 2562 | cq = &txo->cq; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2563 | status = be_queue_alloc(adapter, cq, TX_CQ_LEN, |
| 2564 | sizeof(struct be_eth_tx_compl)); |
| 2565 | if (status) |
| 2566 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2567 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2568 | u64_stats_init(&txo->stats.sync); |
| 2569 | u64_stats_init(&txo->stats.sync_compl); |
| 2570 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2571 | /* If num_evt_qs is less than num_tx_qs, then more than |
| 2572 | * one txq share an eq |
| 2573 | */ |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2574 | eqo = &adapter->eq_obj[i % adapter->num_evt_qs]; |
| 2575 | status = be_cmd_cq_create(adapter, cq, &eqo->q, false, 3); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2576 | if (status) |
| 2577 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2578 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2579 | status = be_queue_alloc(adapter, &txo->q, TX_Q_LEN, |
| 2580 | sizeof(struct be_eth_wrb)); |
| 2581 | if (status) |
| 2582 | return status; |
| 2583 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 2584 | status = be_cmd_txq_create(adapter, txo); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2585 | if (status) |
| 2586 | return status; |
Sathya Perla | 73f394e | 2015-03-26 03:05:09 -0400 | [diff] [blame] | 2587 | |
| 2588 | netif_set_xps_queue(adapter->netdev, eqo->affinity_mask, |
| 2589 | eqo->idx); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2592 | dev_info(&adapter->pdev->dev, "created %d TX queue(s)\n", |
| 2593 | adapter->num_tx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2594 | return 0; |
| 2595 | } |
| 2596 | |
| 2597 | static void be_rx_cqs_destroy(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2598 | { |
| 2599 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2600 | struct be_rx_obj *rxo; |
| 2601 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2602 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2603 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2604 | q = &rxo->cq; |
| 2605 | if (q->created) |
| 2606 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 2607 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2608 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2611 | static int be_rx_cqs_create(struct be_adapter *adapter) |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2612 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2613 | struct be_queue_info *eq, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2614 | struct be_rx_obj *rxo; |
| 2615 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2616 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2617 | /* We can create as many RSS rings as there are EQs. */ |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 2618 | adapter->num_rss_qs = adapter->num_evt_qs; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2619 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 2620 | /* We'll use RSS only if atleast 2 RSS rings are supported. */ |
| 2621 | if (adapter->num_rss_qs <= 1) |
| 2622 | adapter->num_rss_qs = 0; |
| 2623 | |
| 2624 | adapter->num_rx_qs = adapter->num_rss_qs + adapter->need_def_rxq; |
| 2625 | |
| 2626 | /* When the interface is not capable of RSS rings (and there is no |
| 2627 | * need to create a default RXQ) we'll still need one RXQ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2628 | */ |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 2629 | if (adapter->num_rx_qs == 0) |
| 2630 | adapter->num_rx_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2631 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2632 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2633 | for_all_rx_queues(adapter, rxo, i) { |
| 2634 | rxo->adapter = adapter; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2635 | cq = &rxo->cq; |
| 2636 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2637 | sizeof(struct be_eth_rx_compl)); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2638 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2639 | return rc; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2640 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 2641 | u64_stats_init(&rxo->stats.sync); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2642 | eq = &adapter->eq_obj[i % adapter->num_evt_qs].q; |
| 2643 | rc = be_cmd_cq_create(adapter, cq, eq, false, 3); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2644 | if (rc) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2645 | return rc; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2646 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2647 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2648 | dev_info(&adapter->pdev->dev, |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 2649 | "created %d RX queue(s)\n", adapter->num_rx_qs); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2650 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2653 | static irqreturn_t be_intx(int irq, void *dev) |
| 2654 | { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2655 | struct be_eq_obj *eqo = dev; |
| 2656 | struct be_adapter *adapter = eqo->adapter; |
| 2657 | int num_evts = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2658 | |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2659 | /* IRQ is not expected when NAPI is scheduled as the EQ |
| 2660 | * will not be armed. |
| 2661 | * But, this can happen on Lancer INTx where it takes |
| 2662 | * a while to de-assert INTx or in BE2 where occasionaly |
| 2663 | * an interrupt may be raised even when EQ is unarmed. |
| 2664 | * If NAPI is already scheduled, then counting & notifying |
| 2665 | * events will orphan them. |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2666 | */ |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2667 | if (napi_schedule_prep(&eqo->napi)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 2668 | num_evts = events_get(eqo); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2669 | __napi_schedule(&eqo->napi); |
| 2670 | if (num_evts) |
| 2671 | eqo->spurious_intr = 0; |
| 2672 | } |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2673 | be_eq_notify(adapter, eqo->q.id, false, true, num_evts, 0); |
Sathya Perla | d0b9cec | 2013-01-11 22:47:02 +0000 | [diff] [blame] | 2674 | |
| 2675 | /* Return IRQ_HANDLED only for the the first spurious intr |
| 2676 | * after a valid intr to stop the kernel from branding |
| 2677 | * this irq as a bad one! |
| 2678 | */ |
| 2679 | if (num_evts || eqo->spurious_intr++ == 0) |
| 2680 | return IRQ_HANDLED; |
| 2681 | else |
| 2682 | return IRQ_NONE; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2685 | static irqreturn_t be_msix(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2686 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2687 | struct be_eq_obj *eqo = dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2688 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2689 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0, 0); |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2690 | napi_schedule(&eqo->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2691 | return IRQ_HANDLED; |
| 2692 | } |
| 2693 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2694 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2695 | { |
Somnath Kotur | e38b170 | 2013-05-29 22:55:56 +0000 | [diff] [blame] | 2696 | return (rxcp->tcpf && !rxcp->err && rxcp->l4_csum) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2699 | 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] | 2700 | int budget, int polling) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2701 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2702 | struct be_adapter *adapter = rxo->adapter; |
| 2703 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2704 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2705 | u32 work_done; |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2706 | u32 frags_consumed = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2707 | |
| 2708 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2709 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2710 | if (!rxcp) |
| 2711 | break; |
| 2712 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2713 | /* Is it a flush compl that has no data */ |
| 2714 | if (unlikely(rxcp->num_rcvd == 0)) |
| 2715 | goto loop_continue; |
| 2716 | |
| 2717 | /* Discard compl with partial DMA Lancer B0 */ |
| 2718 | if (unlikely(!rxcp->pkt_size)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2719 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2720 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 2721 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 2722 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2723 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 2724 | * promiscuous mode on some skews |
| 2725 | */ |
| 2726 | if (unlikely(rxcp->port != adapter->port_num && |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 2727 | !lancer_chip(adapter))) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2728 | be_rx_compl_discard(rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2729 | goto loop_continue; |
| 2730 | } |
| 2731 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2732 | /* Don't do gro when we're busy_polling */ |
| 2733 | if (do_gro(rxcp) && polling != BUSY_POLLING) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2734 | be_rx_compl_process_gro(rxo, napi, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2735 | else |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2736 | be_rx_compl_process(rxo, napi, rxcp); |
| 2737 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 2738 | loop_continue: |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2739 | frags_consumed += rxcp->num_rcvd; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2740 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2743 | if (work_done) { |
| 2744 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Padmanabh Ratnakar | 9372cac | 2011-11-03 01:49:55 +0000 | [diff] [blame] | 2745 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2746 | /* When an rx-obj gets into post_starved state, just |
| 2747 | * let be_worker do the posting. |
| 2748 | */ |
| 2749 | if (atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM && |
| 2750 | !rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 2751 | be_post_rx_frags(rxo, GFP_ATOMIC, |
| 2752 | max_t(u32, MAX_RX_POST, |
| 2753 | frags_consumed)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2754 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2755 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2756 | return work_done; |
| 2757 | } |
| 2758 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2759 | 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] | 2760 | { |
| 2761 | switch (status) { |
| 2762 | case BE_TX_COMP_HDR_PARSE_ERR: |
| 2763 | tx_stats(txo)->tx_hdr_parse_err++; |
| 2764 | break; |
| 2765 | case BE_TX_COMP_NDMA_ERR: |
| 2766 | tx_stats(txo)->tx_dma_err++; |
| 2767 | break; |
| 2768 | case BE_TX_COMP_ACL_ERR: |
| 2769 | tx_stats(txo)->tx_spoof_check_err++; |
| 2770 | break; |
| 2771 | } |
| 2772 | } |
| 2773 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2774 | 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] | 2775 | { |
| 2776 | switch (status) { |
| 2777 | case LANCER_TX_COMP_LSO_ERR: |
| 2778 | tx_stats(txo)->tx_tso_err++; |
| 2779 | break; |
| 2780 | case LANCER_TX_COMP_HSW_DROP_MAC_ERR: |
| 2781 | case LANCER_TX_COMP_HSW_DROP_VLAN_ERR: |
| 2782 | tx_stats(txo)->tx_spoof_check_err++; |
| 2783 | break; |
| 2784 | case LANCER_TX_COMP_QINQ_ERR: |
| 2785 | tx_stats(txo)->tx_qinq_err++; |
| 2786 | break; |
| 2787 | case LANCER_TX_COMP_PARITY_ERR: |
| 2788 | tx_stats(txo)->tx_internal_parity_err++; |
| 2789 | break; |
| 2790 | case LANCER_TX_COMP_DMA_ERR: |
| 2791 | tx_stats(txo)->tx_dma_err++; |
| 2792 | break; |
| 2793 | } |
| 2794 | } |
| 2795 | |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2796 | static void be_process_tx(struct be_adapter *adapter, struct be_tx_obj *txo, |
| 2797 | int idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2798 | { |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2799 | int num_wrbs = 0, work_done = 0; |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2800 | struct be_tx_compl_info *txcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2801 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2802 | while ((txcp = be_tx_compl_get(txo))) { |
| 2803 | num_wrbs += be_tx_compl_process(adapter, txo, txcp->end_index); |
Sathya Perla | c8f6461 | 2014-09-02 09:56:55 +0530 | [diff] [blame] | 2804 | work_done++; |
| 2805 | |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2806 | if (txcp->status) { |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2807 | if (lancer_chip(adapter)) |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2808 | lancer_update_tx_err(txo, txcp->status); |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2809 | else |
Sriharsha Basavapatna | 152ffe5 | 2015-02-16 08:03:47 +0530 | [diff] [blame] | 2810 | be_update_tx_err(txo, txcp->status); |
Kalesh AP | 512bb8a | 2014-09-02 09:56:49 +0530 | [diff] [blame] | 2811 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | if (work_done) { |
| 2815 | be_cq_notify(adapter, txo->cq.id, true, work_done); |
| 2816 | atomic_sub(num_wrbs, &txo->q.used); |
| 2817 | |
| 2818 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 2819 | * if it was stopped due to lack of tx wrbs. */ |
| 2820 | if (__netif_subqueue_stopped(adapter->netdev, idx) && |
Sriharsha Basavapatna | cf5671e | 2015-02-16 08:03:48 +0530 | [diff] [blame] | 2821 | be_can_txq_wake(txo)) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2822 | netif_wake_subqueue(adapter->netdev, idx); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2823 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2824 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2825 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
| 2826 | tx_stats(txo)->tx_compl += work_done; |
| 2827 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
| 2828 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2829 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2830 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 2831 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2832 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 2833 | { |
| 2834 | bool status = true; |
| 2835 | |
| 2836 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 2837 | if (eqo->state & BE_EQ_LOCKED) { |
| 2838 | WARN_ON(eqo->state & BE_EQ_NAPI); |
| 2839 | eqo->state |= BE_EQ_NAPI_YIELD; |
| 2840 | status = false; |
| 2841 | } else { |
| 2842 | eqo->state = BE_EQ_NAPI; |
| 2843 | } |
| 2844 | spin_unlock(&eqo->lock); |
| 2845 | return status; |
| 2846 | } |
| 2847 | |
| 2848 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 2849 | { |
| 2850 | spin_lock(&eqo->lock); /* BH is already disabled */ |
| 2851 | |
| 2852 | WARN_ON(eqo->state & (BE_EQ_POLL | BE_EQ_NAPI_YIELD)); |
| 2853 | eqo->state = BE_EQ_IDLE; |
| 2854 | |
| 2855 | spin_unlock(&eqo->lock); |
| 2856 | } |
| 2857 | |
| 2858 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 2859 | { |
| 2860 | bool status = true; |
| 2861 | |
| 2862 | spin_lock_bh(&eqo->lock); |
| 2863 | if (eqo->state & BE_EQ_LOCKED) { |
| 2864 | eqo->state |= BE_EQ_POLL_YIELD; |
| 2865 | status = false; |
| 2866 | } else { |
| 2867 | eqo->state |= BE_EQ_POLL; |
| 2868 | } |
| 2869 | spin_unlock_bh(&eqo->lock); |
| 2870 | return status; |
| 2871 | } |
| 2872 | |
| 2873 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 2874 | { |
| 2875 | spin_lock_bh(&eqo->lock); |
| 2876 | |
| 2877 | WARN_ON(eqo->state & (BE_EQ_NAPI)); |
| 2878 | eqo->state = BE_EQ_IDLE; |
| 2879 | |
| 2880 | spin_unlock_bh(&eqo->lock); |
| 2881 | } |
| 2882 | |
| 2883 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 2884 | { |
| 2885 | spin_lock_init(&eqo->lock); |
| 2886 | eqo->state = BE_EQ_IDLE; |
| 2887 | } |
| 2888 | |
| 2889 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 2890 | { |
| 2891 | local_bh_disable(); |
| 2892 | |
| 2893 | /* It's enough to just acquire napi lock on the eqo to stop |
| 2894 | * be_busy_poll() from processing any queueus. |
| 2895 | */ |
| 2896 | while (!be_lock_napi(eqo)) |
| 2897 | mdelay(1); |
| 2898 | |
| 2899 | local_bh_enable(); |
| 2900 | } |
| 2901 | |
| 2902 | #else /* CONFIG_NET_RX_BUSY_POLL */ |
| 2903 | |
| 2904 | static inline bool be_lock_napi(struct be_eq_obj *eqo) |
| 2905 | { |
| 2906 | return true; |
| 2907 | } |
| 2908 | |
| 2909 | static inline void be_unlock_napi(struct be_eq_obj *eqo) |
| 2910 | { |
| 2911 | } |
| 2912 | |
| 2913 | static inline bool be_lock_busy_poll(struct be_eq_obj *eqo) |
| 2914 | { |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
| 2918 | static inline void be_unlock_busy_poll(struct be_eq_obj *eqo) |
| 2919 | { |
| 2920 | } |
| 2921 | |
| 2922 | static inline void be_enable_busy_poll(struct be_eq_obj *eqo) |
| 2923 | { |
| 2924 | } |
| 2925 | |
| 2926 | static inline void be_disable_busy_poll(struct be_eq_obj *eqo) |
| 2927 | { |
| 2928 | } |
| 2929 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
| 2930 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 2931 | int be_poll(struct napi_struct *napi, int budget) |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2932 | { |
| 2933 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2934 | struct be_adapter *adapter = eqo->adapter; |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2935 | int max_work = 0, work, i, num_evts; |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2936 | struct be_rx_obj *rxo; |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 2937 | struct be_tx_obj *txo; |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2938 | u32 mult_enc = 0; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2939 | |
Sathya Perla | 0b545a6 | 2012-11-23 00:27:18 +0000 | [diff] [blame] | 2940 | num_evts = events_get(eqo); |
| 2941 | |
Sathya Perla | a4906ea | 2014-09-02 09:56:56 +0530 | [diff] [blame] | 2942 | for_all_tx_queues_on_eq(adapter, eqo, txo, i) |
| 2943 | be_process_tx(adapter, txo, i); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2944 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2945 | if (be_lock_napi(eqo)) { |
| 2946 | /* This loop will iterate twice for EQ0 in which |
| 2947 | * completions of the last RXQ (default one) are also processed |
| 2948 | * For other EQs the loop iterates only once |
| 2949 | */ |
| 2950 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2951 | work = be_process_rx(rxo, napi, budget, NAPI_POLLING); |
| 2952 | max_work = max(work, max_work); |
| 2953 | } |
| 2954 | be_unlock_napi(eqo); |
| 2955 | } else { |
| 2956 | max_work = budget; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 2957 | } |
| 2958 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2959 | if (is_mcc_eqo(eqo)) |
| 2960 | be_process_mcc(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2961 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2962 | if (max_work < budget) { |
| 2963 | napi_complete(napi); |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2964 | |
| 2965 | /* Skyhawk EQ_DB has a provision to set the rearm to interrupt |
| 2966 | * delay via a delay multiplier encoding value |
| 2967 | */ |
| 2968 | if (skyhawk_chip(adapter)) |
| 2969 | mult_enc = be_get_eq_delay_mult_enc(eqo); |
| 2970 | |
| 2971 | be_eq_notify(adapter, eqo->q.id, true, false, num_evts, |
| 2972 | mult_enc); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2973 | } else { |
| 2974 | /* As we'll continue in polling mode, count and clear events */ |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 2975 | be_eq_notify(adapter, eqo->q.id, false, false, num_evts, 0); |
Padmanabh Ratnakar | 93c8670 | 2011-12-19 01:53:35 +0000 | [diff] [blame] | 2976 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 2977 | return max_work; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 2980 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2981 | static int be_busy_poll(struct napi_struct *napi) |
| 2982 | { |
| 2983 | struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi); |
| 2984 | struct be_adapter *adapter = eqo->adapter; |
| 2985 | struct be_rx_obj *rxo; |
| 2986 | int i, work = 0; |
| 2987 | |
| 2988 | if (!be_lock_busy_poll(eqo)) |
| 2989 | return LL_FLUSH_BUSY; |
| 2990 | |
| 2991 | for_all_rx_queues_on_eq(adapter, eqo, rxo, i) { |
| 2992 | work = be_process_rx(rxo, napi, 4, BUSY_POLLING); |
| 2993 | if (work) |
| 2994 | break; |
| 2995 | } |
| 2996 | |
| 2997 | be_unlock_busy_poll(eqo); |
| 2998 | return work; |
| 2999 | } |
| 3000 | #endif |
| 3001 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3002 | void be_detect_error(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3003 | { |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3004 | u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0; |
| 3005 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3006 | u32 i; |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3007 | struct device *dev = &adapter->pdev->dev; |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3008 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 3009 | if (be_check_error(adapter, BE_ERROR_HW)) |
Sathya Perla | 72f0248 | 2011-11-10 19:17:58 +0000 | [diff] [blame] | 3010 | return; |
| 3011 | |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3012 | if (lancer_chip(adapter)) { |
| 3013 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3014 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 3015 | be_set_error(adapter, BE_ERROR_UE); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3016 | sliport_err1 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3017 | SLIPORT_ERROR1_OFFSET); |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3018 | sliport_err2 = ioread32(adapter->db + |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3019 | SLIPORT_ERROR2_OFFSET); |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3020 | /* Do not log error messages if its a FW reset */ |
| 3021 | if (sliport_err1 == SLIPORT_ERROR_FW_RESET1 && |
| 3022 | sliport_err2 == SLIPORT_ERROR_FW_RESET2) { |
| 3023 | dev_info(dev, "Firmware update in progress\n"); |
| 3024 | } else { |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3025 | dev_err(dev, "Error detected in the card\n"); |
| 3026 | dev_err(dev, "ERR: sliport status 0x%x\n", |
| 3027 | sliport_status); |
| 3028 | dev_err(dev, "ERR: sliport error1 0x%x\n", |
| 3029 | sliport_err1); |
| 3030 | dev_err(dev, "ERR: sliport error2 0x%x\n", |
| 3031 | sliport_err2); |
| 3032 | } |
Padmanabh Ratnakar | e1cfb67 | 2011-11-03 01:50:08 +0000 | [diff] [blame] | 3033 | } |
| 3034 | } else { |
Suresh Reddy | 25848c9 | 2015-03-20 06:28:25 -0400 | [diff] [blame] | 3035 | ue_lo = ioread32(adapter->pcicfg + PCICFG_UE_STATUS_LOW); |
| 3036 | ue_hi = ioread32(adapter->pcicfg + PCICFG_UE_STATUS_HIGH); |
| 3037 | ue_lo_mask = ioread32(adapter->pcicfg + |
| 3038 | PCICFG_UE_STATUS_LOW_MASK); |
| 3039 | ue_hi_mask = ioread32(adapter->pcicfg + |
| 3040 | PCICFG_UE_STATUS_HI_MASK); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3041 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3042 | ue_lo = (ue_lo & ~ue_lo_mask); |
| 3043 | ue_hi = (ue_hi & ~ue_hi_mask); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3044 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3045 | /* On certain platforms BE hardware can indicate spurious UEs. |
| 3046 | * Allow HW to stop working completely in case of a real UE. |
| 3047 | * Hence not setting the hw_error for UE detection. |
| 3048 | */ |
| 3049 | |
| 3050 | if (ue_lo || ue_hi) { |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3051 | dev_err(dev, |
| 3052 | "Unrecoverable Error detected in the adapter"); |
| 3053 | dev_err(dev, "Please reboot server to recover"); |
| 3054 | if (skyhawk_chip(adapter)) |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 3055 | be_set_error(adapter, BE_ERROR_UE); |
| 3056 | |
Somnath Kotur | eb0eecc | 2014-02-12 16:07:54 +0530 | [diff] [blame] | 3057 | for (i = 0; ue_lo; ue_lo >>= 1, i++) { |
| 3058 | if (ue_lo & 1) |
| 3059 | dev_err(dev, "UE: %s bit set\n", |
| 3060 | ue_status_low_desc[i]); |
| 3061 | } |
| 3062 | for (i = 0; ue_hi; ue_hi >>= 1, i++) { |
| 3063 | if (ue_hi & 1) |
| 3064 | dev_err(dev, "UE: %s bit set\n", |
| 3065 | ue_status_hi_desc[i]); |
| 3066 | } |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 3067 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 3068 | } |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3071 | static void be_msix_disable(struct be_adapter *adapter) |
| 3072 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3073 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3074 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3075 | adapter->num_msix_vec = 0; |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3076 | adapter->num_msix_roce_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3080 | static int be_msix_enable(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3081 | { |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3082 | int i, num_vec; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3083 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3084 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3085 | /* If RoCE is supported, program the max number of NIC vectors that |
| 3086 | * may be configured via set-channels, along with vectors needed for |
| 3087 | * RoCe. Else, just program the number we'll use initially. |
| 3088 | */ |
| 3089 | if (be_roce_supported(adapter)) |
| 3090 | num_vec = min_t(int, 2 * be_max_eqs(adapter), |
| 3091 | 2 * num_online_cpus()); |
| 3092 | else |
| 3093 | num_vec = adapter->cfg_num_qs; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3094 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3095 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3096 | adapter->msix_entries[i].entry = i; |
| 3097 | |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3098 | num_vec = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 3099 | MIN_MSIX_VECTORS, num_vec); |
| 3100 | if (num_vec < 0) |
| 3101 | goto fail; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3102 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3103 | if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) { |
| 3104 | adapter->num_msix_roce_vec = num_vec / 2; |
| 3105 | dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n", |
| 3106 | adapter->num_msix_roce_vec); |
| 3107 | } |
| 3108 | |
| 3109 | adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec; |
| 3110 | |
| 3111 | dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n", |
| 3112 | adapter->num_msix_vec); |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3113 | return 0; |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3114 | |
| 3115 | fail: |
| 3116 | dev_warn(dev, "MSIx enable failed\n"); |
| 3117 | |
| 3118 | /* 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] | 3119 | if (be_virtfn(adapter)) |
Alexander Gordeev | 7dc4c06 | 2014-02-18 11:11:40 +0100 | [diff] [blame] | 3120 | return num_vec; |
| 3121 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3124 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3125 | struct be_eq_obj *eqo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3126 | { |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 3127 | return adapter->msix_entries[eqo->msix_idx].vector; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | static int be_msix_register(struct be_adapter *adapter) |
| 3131 | { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3132 | struct net_device *netdev = adapter->netdev; |
| 3133 | struct be_eq_obj *eqo; |
| 3134 | int status, i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3135 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3136 | for_all_evt_queues(adapter, eqo, i) { |
| 3137 | sprintf(eqo->desc, "%s-q%d", netdev->name, i); |
| 3138 | vec = be_msix_vec_get(adapter, eqo); |
| 3139 | status = request_irq(vec, be_msix, 0, eqo->desc, eqo); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3140 | if (status) |
| 3141 | goto err_msix; |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3142 | |
| 3143 | irq_set_affinity_hint(vec, eqo->affinity_mask); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3144 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 3145 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3146 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3147 | err_msix: |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3148 | for (i--, eqo = &adapter->eq_obj[i]; i >= 0; i--, eqo--) |
| 3149 | free_irq(be_msix_vec_get(adapter, eqo), eqo); |
| 3150 | dev_warn(&adapter->pdev->dev, "MSIX Request IRQ failed - err %d\n", |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3151 | status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3152 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3153 | return status; |
| 3154 | } |
| 3155 | |
| 3156 | static int be_irq_register(struct be_adapter *adapter) |
| 3157 | { |
| 3158 | struct net_device *netdev = adapter->netdev; |
| 3159 | int status; |
| 3160 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3161 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3162 | status = be_msix_register(adapter); |
| 3163 | if (status == 0) |
| 3164 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3165 | /* INTx is not supported for VF */ |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 3166 | if (be_virtfn(adapter)) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3167 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3170 | /* INTx: only the first EQ is used */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3171 | netdev->irq = adapter->pdev->irq; |
| 3172 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3173 | &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3174 | if (status) { |
| 3175 | dev_err(&adapter->pdev->dev, |
| 3176 | "INTx request IRQ failed - err %d\n", status); |
| 3177 | return status; |
| 3178 | } |
| 3179 | done: |
| 3180 | adapter->isr_registered = true; |
| 3181 | return 0; |
| 3182 | } |
| 3183 | |
| 3184 | static void be_irq_unregister(struct be_adapter *adapter) |
| 3185 | { |
| 3186 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3187 | struct be_eq_obj *eqo; |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3188 | int i, vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3189 | |
| 3190 | if (!adapter->isr_registered) |
| 3191 | return; |
| 3192 | |
| 3193 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 3194 | if (!msix_enabled(adapter)) { |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 3195 | free_irq(netdev->irq, &adapter->eq_obj[0]); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3196 | goto done; |
| 3197 | } |
| 3198 | |
| 3199 | /* MSIx */ |
Padmanabh Ratnakar | d658d98 | 2015-03-26 03:05:08 -0400 | [diff] [blame] | 3200 | for_all_evt_queues(adapter, eqo, i) { |
| 3201 | vec = be_msix_vec_get(adapter, eqo); |
| 3202 | irq_set_affinity_hint(vec, NULL); |
| 3203 | free_irq(vec, eqo); |
| 3204 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3205 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3206 | done: |
| 3207 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3210 | static void be_rx_qs_destroy(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3211 | { |
| 3212 | struct be_queue_info *q; |
| 3213 | struct be_rx_obj *rxo; |
| 3214 | int i; |
| 3215 | |
| 3216 | for_all_rx_queues(adapter, rxo, i) { |
| 3217 | q = &rxo->q; |
| 3218 | if (q->created) { |
| 3219 | be_cmd_rxq_destroy(adapter, q); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3220 | be_rx_cq_clean(rxo); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3221 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3222 | be_queue_free(adapter, q); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3226 | static int be_close(struct net_device *netdev) |
| 3227 | { |
| 3228 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3229 | struct be_eq_obj *eqo; |
| 3230 | int i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3231 | |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 3232 | /* This protection is needed as be_close() may be called even when the |
| 3233 | * adapter is in cleared state (after eeh perm failure) |
| 3234 | */ |
| 3235 | if (!(adapter->flags & BE_FLAGS_SETUP_DONE)) |
| 3236 | return 0; |
| 3237 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 3238 | be_roce_dev_close(adapter); |
| 3239 | |
Ivan Vecera | dff345c5 | 2013-11-27 08:59:32 +0100 | [diff] [blame] | 3240 | if (adapter->flags & BE_FLAGS_NAPI_ENABLED) { |
| 3241 | for_all_evt_queues(adapter, eqo, i) { |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3242 | napi_disable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3243 | be_disable_busy_poll(eqo); |
| 3244 | } |
David S. Miller | 71237b6 | 2013-11-28 18:53:36 -0500 | [diff] [blame] | 3245 | adapter->flags &= ~BE_FLAGS_NAPI_ENABLED; |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3246 | } |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3247 | |
| 3248 | be_async_mcc_disable(adapter); |
| 3249 | |
| 3250 | /* Wait for all pending tx completions to arrive so that |
| 3251 | * all tx skbs are freed. |
| 3252 | */ |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 3253 | netif_tx_disable(netdev); |
Sathya Perla | 6e1f997 | 2013-08-22 12:23:41 +0530 | [diff] [blame] | 3254 | be_tx_compl_clean(adapter); |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3255 | |
| 3256 | be_rx_qs_destroy(adapter); |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 3257 | be_clear_uc_list(adapter); |
Ajit Khaparde | d11a347 | 2013-11-18 10:44:37 -0600 | [diff] [blame] | 3258 | |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 3259 | for_all_evt_queues(adapter, eqo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3260 | if (msix_enabled(adapter)) |
| 3261 | synchronize_irq(be_msix_vec_get(adapter, eqo)); |
| 3262 | else |
| 3263 | synchronize_irq(netdev->irq); |
| 3264 | be_eq_clean(eqo); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 3265 | } |
| 3266 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3267 | be_irq_unregister(adapter); |
| 3268 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3269 | return 0; |
| 3270 | } |
| 3271 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3272 | static int be_rx_qs_create(struct be_adapter *adapter) |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3273 | { |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3274 | struct rss_info *rss = &adapter->rss_info; |
| 3275 | u8 rss_key[RSS_HASH_KEY_LEN]; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3276 | struct be_rx_obj *rxo; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3277 | int rc, i, j; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3278 | |
| 3279 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3280 | rc = be_queue_alloc(adapter, &rxo->q, RX_Q_LEN, |
| 3281 | sizeof(struct be_eth_rx_d)); |
| 3282 | if (rc) |
| 3283 | return rc; |
| 3284 | } |
| 3285 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3286 | if (adapter->need_def_rxq || !adapter->num_rss_qs) { |
| 3287 | rxo = default_rxo(adapter); |
| 3288 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
| 3289 | rx_frag_size, adapter->if_handle, |
| 3290 | false, &rxo->rss_id); |
| 3291 | if (rc) |
| 3292 | return rc; |
| 3293 | } |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3294 | |
| 3295 | for_all_rss_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3296 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3297 | rx_frag_size, adapter->if_handle, |
| 3298 | true, &rxo->rss_id); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3299 | if (rc) |
| 3300 | return rc; |
| 3301 | } |
| 3302 | |
| 3303 | if (be_multi_rxq(adapter)) { |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3304 | 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] | 3305 | for_all_rss_queues(adapter, rxo, i) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3306 | if ((j + i) >= RSS_INDIR_TABLE_LEN) |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3307 | break; |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3308 | rss->rsstable[j + i] = rxo->rss_id; |
| 3309 | rss->rss_queue[j + i] = i; |
Padmanabh Ratnakar | e9008ee | 2011-11-25 05:48:53 +0000 | [diff] [blame] | 3310 | } |
| 3311 | } |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3312 | rss->rss_flags = RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 | |
| 3313 | RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6; |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3314 | |
| 3315 | if (!BEx_chip(adapter)) |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3316 | rss->rss_flags |= RSS_ENABLE_UDP_IPV4 | |
| 3317 | RSS_ENABLE_UDP_IPV6; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3318 | } else { |
| 3319 | /* Disable RSS, if only default RX Q is created */ |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3320 | rss->rss_flags = RSS_ENABLE_NONE; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3321 | } |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 3322 | |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3323 | netdev_rss_key_fill(rss_key, RSS_HASH_KEY_LEN); |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3324 | rc = be_cmd_rss_config(adapter, rss->rsstable, rss->rss_flags, |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3325 | 128, rss_key); |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3326 | if (rc) { |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3327 | rss->rss_flags = RSS_ENABLE_NONE; |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 3328 | return rc; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
Eric Dumazet | 1dcf7b1 | 2014-11-16 06:23:10 -0800 | [diff] [blame] | 3331 | memcpy(rss->rss_hkey, rss_key, RSS_HASH_KEY_LEN); |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 3332 | |
Suresh Reddy | b02e60c | 2015-05-06 05:30:36 -0400 | [diff] [blame] | 3333 | /* Post 1 less than RXQ-len to avoid head being equal to tail, |
| 3334 | * which is a queue empty condition |
| 3335 | */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3336 | for_all_rx_queues(adapter, rxo, i) |
Suresh Reddy | b02e60c | 2015-05-06 05:30:36 -0400 | [diff] [blame] | 3337 | be_post_rx_frags(rxo, GFP_KERNEL, RX_Q_LEN - 1); |
| 3338 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3339 | return 0; |
| 3340 | } |
| 3341 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3342 | static int be_open(struct net_device *netdev) |
| 3343 | { |
| 3344 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3345 | struct be_eq_obj *eqo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3346 | struct be_rx_obj *rxo; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3347 | struct be_tx_obj *txo; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3348 | u8 link_status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3349 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3350 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3351 | status = be_rx_qs_create(adapter); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 3352 | if (status) |
| 3353 | goto err; |
| 3354 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 3355 | status = be_irq_register(adapter); |
| 3356 | if (status) |
| 3357 | goto err; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3358 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3359 | for_all_rx_queues(adapter, rxo, i) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3360 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3361 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3362 | for_all_tx_queues(adapter, txo, i) |
| 3363 | be_cq_notify(adapter, txo->cq.id, true, 0); |
| 3364 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 3365 | be_async_mcc_enable(adapter); |
| 3366 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3367 | for_all_evt_queues(adapter, eqo, i) { |
| 3368 | napi_enable(&eqo->napi); |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 3369 | be_enable_busy_poll(eqo); |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 3370 | be_eq_notify(adapter, eqo->q.id, true, true, 0, 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3371 | } |
Somnath Kotur | 04d3d62 | 2013-05-02 03:36:55 +0000 | [diff] [blame] | 3372 | adapter->flags |= BE_FLAGS_NAPI_ENABLED; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3373 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 3374 | status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 3375 | if (!status) |
| 3376 | be_link_status_update(adapter, link_status); |
| 3377 | |
Sathya Perla | fba8755 | 2013-05-08 02:05:50 +0000 | [diff] [blame] | 3378 | netif_tx_start_all_queues(netdev); |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 3379 | be_roce_dev_open(adapter); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3380 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3381 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3382 | if (skyhawk_chip(adapter)) |
| 3383 | vxlan_get_rx_port(netdev); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3384 | #endif |
| 3385 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 3386 | return 0; |
| 3387 | err: |
| 3388 | be_close(adapter->netdev); |
| 3389 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3392 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 3393 | { |
| 3394 | struct be_dma_mem cmd; |
| 3395 | int status = 0; |
| 3396 | u8 mac[ETH_ALEN]; |
| 3397 | |
Joe Perches | c7bf716 | 2015-03-02 19:54:47 -0800 | [diff] [blame] | 3398 | eth_zero_addr(mac); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3399 | |
| 3400 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
Joe Perches | ede23fa | 2013-08-26 22:45:23 -0700 | [diff] [blame] | 3401 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 3402 | GFP_KERNEL); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 3403 | if (!cmd.va) |
Kalesh AP | 6b56868 | 2014-07-17 16:20:22 +0530 | [diff] [blame] | 3404 | return -ENOMEM; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3405 | |
| 3406 | if (enable) { |
| 3407 | status = pci_write_config_dword(adapter->pdev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3408 | PCICFG_PM_CONTROL_OFFSET, |
| 3409 | PCICFG_PM_CONTROL_MASK); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3410 | if (status) { |
| 3411 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 3412 | "Could not enable Wake-on-lan\n"); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3413 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 3414 | cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3415 | return status; |
| 3416 | } |
| 3417 | status = be_cmd_enable_magic_wol(adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3418 | adapter->netdev->dev_addr, |
| 3419 | &cmd); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3420 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 3421 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 3422 | } else { |
| 3423 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 3424 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 3425 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 3426 | } |
| 3427 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3428 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3429 | return status; |
| 3430 | } |
| 3431 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 3432 | static void be_vf_eth_addr_generate(struct be_adapter *adapter, u8 *mac) |
| 3433 | { |
| 3434 | u32 addr; |
| 3435 | |
| 3436 | addr = jhash(adapter->netdev->dev_addr, ETH_ALEN, 0); |
| 3437 | |
| 3438 | mac[5] = (u8)(addr & 0xFF); |
| 3439 | mac[4] = (u8)((addr >> 8) & 0xFF); |
| 3440 | mac[3] = (u8)((addr >> 16) & 0xFF); |
| 3441 | /* Use the OUI from the current MAC address */ |
| 3442 | memcpy(mac, adapter->netdev->dev_addr, 3); |
| 3443 | } |
| 3444 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3445 | /* |
| 3446 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 3447 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 3448 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 3449 | * queries for the MAC address during its probe. |
| 3450 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3451 | static int be_vf_eth_addr_config(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3452 | { |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3453 | u32 vf; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3454 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3455 | u8 mac[ETH_ALEN]; |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3456 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3457 | |
| 3458 | be_vf_eth_addr_generate(adapter, mac); |
| 3459 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3460 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3461 | if (BEx_chip(adapter)) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3462 | status = be_cmd_pmac_add(adapter, mac, |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3463 | vf_cfg->if_handle, |
| 3464 | &vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3465 | else |
| 3466 | status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle, |
| 3467 | vf + 1); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3468 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3469 | if (status) |
| 3470 | dev_err(&adapter->pdev->dev, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 3471 | "Mac address assignment failed for VF %d\n", |
| 3472 | vf); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3473 | else |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3474 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3475 | |
| 3476 | mac[5] += 1; |
| 3477 | } |
| 3478 | return status; |
| 3479 | } |
| 3480 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3481 | static int be_vfs_mac_query(struct be_adapter *adapter) |
| 3482 | { |
| 3483 | int status, vf; |
| 3484 | u8 mac[ETH_ALEN]; |
| 3485 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3486 | |
| 3487 | for_all_vfs(adapter, vf_cfg, vf) { |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3488 | status = be_cmd_get_active_mac(adapter, vf_cfg->pmac_id, |
| 3489 | mac, vf_cfg->if_handle, |
| 3490 | false, vf+1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3491 | if (status) |
| 3492 | return status; |
| 3493 | memcpy(vf_cfg->mac_addr, mac, ETH_ALEN); |
| 3494 | } |
| 3495 | return 0; |
| 3496 | } |
| 3497 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3498 | static void be_vf_clear(struct be_adapter *adapter) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3499 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3500 | struct be_vf_cfg *vf_cfg; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3501 | u32 vf; |
| 3502 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3503 | if (pci_vfs_assigned(adapter->pdev)) { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3504 | dev_warn(&adapter->pdev->dev, |
| 3505 | "VFs are assigned to VMs: not disabling VFs\n"); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3506 | goto done; |
| 3507 | } |
| 3508 | |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3509 | pci_disable_sriov(adapter->pdev); |
| 3510 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3511 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3512 | if (BEx_chip(adapter)) |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3513 | be_cmd_pmac_del(adapter, vf_cfg->if_handle, |
| 3514 | vf_cfg->pmac_id, vf + 1); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3515 | else |
| 3516 | be_cmd_set_mac(adapter, NULL, vf_cfg->if_handle, |
| 3517 | vf + 1); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3518 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3519 | be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1); |
| 3520 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3521 | done: |
| 3522 | kfree(adapter->vf_cfg); |
| 3523 | adapter->num_vfs = 0; |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 3524 | adapter->flags &= ~BE_FLAGS_SRIOV_ENABLED; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3527 | static void be_clear_queues(struct be_adapter *adapter) |
| 3528 | { |
| 3529 | be_mcc_queues_destroy(adapter); |
| 3530 | be_rx_cqs_destroy(adapter); |
| 3531 | be_tx_queues_destroy(adapter); |
| 3532 | be_evt_queues_destroy(adapter); |
| 3533 | } |
| 3534 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3535 | static void be_cancel_worker(struct be_adapter *adapter) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3536 | { |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3537 | if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) { |
| 3538 | cancel_delayed_work_sync(&adapter->work); |
| 3539 | adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED; |
| 3540 | } |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3541 | } |
| 3542 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 3543 | static void be_cancel_err_detection(struct be_adapter *adapter) |
| 3544 | { |
| 3545 | if (adapter->flags & BE_FLAGS_ERR_DETECTION_SCHEDULED) { |
| 3546 | cancel_delayed_work_sync(&adapter->be_err_detection_work); |
| 3547 | adapter->flags &= ~BE_FLAGS_ERR_DETECTION_SCHEDULED; |
| 3548 | } |
| 3549 | } |
| 3550 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3551 | static void be_mac_clear(struct be_adapter *adapter) |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3552 | { |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3553 | if (adapter->pmac_id) { |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 3554 | be_cmd_pmac_del(adapter, adapter->if_handle, |
| 3555 | adapter->pmac_id[0], 0); |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3556 | kfree(adapter->pmac_id); |
| 3557 | adapter->pmac_id = NULL; |
| 3558 | } |
| 3559 | } |
| 3560 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3561 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3562 | static void be_disable_vxlan_offloads(struct be_adapter *adapter) |
| 3563 | { |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 3564 | struct net_device *netdev = adapter->netdev; |
| 3565 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3566 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) |
| 3567 | be_cmd_manage_iface(adapter, adapter->if_handle, |
| 3568 | OP_CONVERT_TUNNEL_TO_NORMAL); |
| 3569 | |
| 3570 | if (adapter->vxlan_port) |
| 3571 | be_cmd_set_vxlan_port(adapter, 0); |
| 3572 | |
| 3573 | adapter->flags &= ~BE_FLAGS_VXLAN_OFFLOADS; |
| 3574 | adapter->vxlan_port = 0; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 3575 | |
| 3576 | netdev->hw_enc_features = 0; |
| 3577 | netdev->hw_features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 3578 | netdev->features &= ~(NETIF_F_GSO_UDP_TUNNEL); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3579 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3580 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3581 | |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3582 | static u16 be_calculate_vf_qs(struct be_adapter *adapter, u16 num_vfs) |
| 3583 | { |
| 3584 | struct be_resources res = adapter->pool_res; |
| 3585 | u16 num_vf_qs = 1; |
| 3586 | |
| 3587 | /* Distribute the queue resources equally among the PF and it's VFs |
| 3588 | * Do not distribute queue resources in multi-channel configuration. |
| 3589 | */ |
| 3590 | if (num_vfs && !be_is_mc(adapter)) { |
| 3591 | /* If number of VFs requested is 8 less than max supported, |
| 3592 | * assign 8 queue pairs to the PF and divide the remaining |
| 3593 | * resources evenly among the VFs |
| 3594 | */ |
| 3595 | if (num_vfs < (be_max_vfs(adapter) - 8)) |
| 3596 | num_vf_qs = (res.max_rss_qs - 8) / num_vfs; |
| 3597 | else |
| 3598 | num_vf_qs = res.max_rss_qs / num_vfs; |
| 3599 | |
| 3600 | /* Skyhawk-R chip supports only MAX_RSS_IFACES RSS capable |
| 3601 | * interfaces per port. Provide RSS on VFs, only if number |
| 3602 | * of VFs requested is less than MAX_RSS_IFACES limit. |
| 3603 | */ |
| 3604 | if (num_vfs >= MAX_RSS_IFACES) |
| 3605 | num_vf_qs = 1; |
| 3606 | } |
| 3607 | return num_vf_qs; |
| 3608 | } |
| 3609 | |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3610 | static int be_clear(struct be_adapter *adapter) |
| 3611 | { |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3612 | struct pci_dev *pdev = adapter->pdev; |
| 3613 | u16 num_vf_qs; |
| 3614 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 3615 | be_cancel_worker(adapter); |
Sathya Perla | 191eb75 | 2012-02-23 18:50:13 +0000 | [diff] [blame] | 3616 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3617 | if (sriov_enabled(adapter)) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3618 | be_vf_clear(adapter); |
| 3619 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3620 | /* Re-configure FW to distribute resources evenly across max-supported |
| 3621 | * number of VFs, only when VFs are not already enabled. |
| 3622 | */ |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3623 | if (skyhawk_chip(adapter) && be_physfn(adapter) && |
| 3624 | !pci_vfs_assigned(pdev)) { |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3625 | num_vf_qs = be_calculate_vf_qs(adapter, |
| 3626 | pci_sriov_get_totalvfs(pdev)); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3627 | be_cmd_set_sriov_config(adapter, adapter->pool_res, |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3628 | pci_sriov_get_totalvfs(pdev), |
| 3629 | num_vf_qs); |
| 3630 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3631 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3632 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 3633 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 3634 | #endif |
Sathya Perla | 2d17f40 | 2013-07-23 15:25:04 +0530 | [diff] [blame] | 3635 | /* delete the primary mac along with the uc-mac list */ |
Somnath Kotur | b05004a | 2013-12-05 12:08:16 +0530 | [diff] [blame] | 3636 | be_mac_clear(adapter); |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 3637 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3638 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3639 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 3640 | be_clear_queues(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3641 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 3642 | be_msix_disable(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 3643 | adapter->flags &= ~BE_FLAGS_SETUP_DONE; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 3644 | return 0; |
| 3645 | } |
| 3646 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3647 | static int be_if_create(struct be_adapter *adapter, u32 *if_handle, |
| 3648 | u32 cap_flags, u32 vf) |
| 3649 | { |
| 3650 | u32 en_flags; |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3651 | |
| 3652 | en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
| 3653 | BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3654 | BE_IF_FLAGS_RSS | BE_IF_FLAGS_DEFQ_RSS; |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3655 | |
| 3656 | en_flags &= cap_flags; |
| 3657 | |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3658 | return be_cmd_if_create(adapter, cap_flags, en_flags, if_handle, vf); |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3659 | } |
| 3660 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3661 | static int be_vfs_if_create(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3662 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3663 | struct be_resources res = {0}; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3664 | struct be_vf_cfg *vf_cfg; |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3665 | u32 cap_flags, vf; |
| 3666 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3667 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3668 | /* If a FW profile exists, then cap_flags are updated */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3669 | cap_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST | |
Somnath Kotur | 0ed7d74 | 2015-05-06 05:30:34 -0400 | [diff] [blame] | 3670 | BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3671 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3672 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3673 | if (!BE3_chip(adapter)) { |
| 3674 | status = be_cmd_get_profile_config(adapter, &res, |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3675 | RESOURCE_LIMITS, |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3676 | vf + 1); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3677 | if (!status) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3678 | cap_flags = res.if_cap_flags; |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3679 | /* Prevent VFs from enabling VLAN promiscuous |
| 3680 | * mode |
| 3681 | */ |
| 3682 | cap_flags &= ~BE_IF_FLAGS_VLAN_PROMISCUOUS; |
| 3683 | } |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3684 | } |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3685 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3686 | status = be_if_create(adapter, &vf_cfg->if_handle, |
| 3687 | cap_flags, vf + 1); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3688 | if (status) |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3689 | return status; |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3690 | } |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 3691 | |
| 3692 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3695 | static int be_vf_setup_init(struct be_adapter *adapter) |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3696 | { |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3697 | struct be_vf_cfg *vf_cfg; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3698 | int vf; |
| 3699 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3700 | adapter->vf_cfg = kcalloc(adapter->num_vfs, sizeof(*vf_cfg), |
| 3701 | GFP_KERNEL); |
| 3702 | if (!adapter->vf_cfg) |
| 3703 | return -ENOMEM; |
| 3704 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3705 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3706 | vf_cfg->if_handle = -1; |
| 3707 | vf_cfg->pmac_id = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3708 | } |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3709 | return 0; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3712 | static int be_vf_setup(struct be_adapter *adapter) |
| 3713 | { |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3714 | struct device *dev = &adapter->pdev->dev; |
Somnath Kotur | c502224 | 2014-03-03 14:24:20 +0530 | [diff] [blame] | 3715 | struct be_vf_cfg *vf_cfg; |
| 3716 | int status, old_vfs, vf; |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3717 | bool spoofchk; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3718 | |
Sathya Perla | 257a3fe | 2013-06-14 15:54:51 +0530 | [diff] [blame] | 3719 | old_vfs = pci_num_vf(adapter->pdev); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3720 | |
| 3721 | status = be_vf_setup_init(adapter); |
| 3722 | if (status) |
| 3723 | goto err; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3724 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3725 | if (old_vfs) { |
| 3726 | for_all_vfs(adapter, vf_cfg, vf) { |
| 3727 | status = be_cmd_get_if_id(adapter, vf_cfg, vf); |
| 3728 | if (status) |
| 3729 | goto err; |
| 3730 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3731 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3732 | status = be_vfs_mac_query(adapter); |
| 3733 | if (status) |
| 3734 | goto err; |
| 3735 | } else { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3736 | status = be_vfs_if_create(adapter); |
| 3737 | if (status) |
| 3738 | goto err; |
| 3739 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 3740 | status = be_vf_eth_addr_config(adapter); |
| 3741 | if (status) |
| 3742 | goto err; |
| 3743 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3744 | |
Sathya Perla | 11ac75e | 2011-12-13 00:58:50 +0000 | [diff] [blame] | 3745 | for_all_vfs(adapter, vf_cfg, vf) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3746 | /* Allow VFs to programs MAC/VLAN filters */ |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3747 | status = be_cmd_get_fn_privileges(adapter, &vf_cfg->privileges, |
| 3748 | vf + 1); |
| 3749 | if (!status && !(vf_cfg->privileges & BE_PRIV_FILTMGMT)) { |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3750 | status = be_cmd_set_fn_privileges(adapter, |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3751 | vf_cfg->privileges | |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3752 | BE_PRIV_FILTMGMT, |
| 3753 | vf + 1); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3754 | if (!status) { |
| 3755 | vf_cfg->privileges |= BE_PRIV_FILTMGMT; |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3756 | dev_info(dev, "VF%d has FILTMGMT privilege\n", |
| 3757 | vf); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 3758 | } |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3759 | } |
| 3760 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 3761 | /* Allow full available bandwidth */ |
| 3762 | if (!old_vfs) |
| 3763 | be_cmd_config_qos(adapter, 0, 0, vf + 1); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3764 | |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3765 | status = be_cmd_get_hsw_config(adapter, NULL, vf + 1, |
| 3766 | vf_cfg->if_handle, NULL, |
| 3767 | &spoofchk); |
| 3768 | if (!status) |
| 3769 | vf_cfg->spoofchk = spoofchk; |
| 3770 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3771 | if (!old_vfs) { |
Vasundhara Volam | 0599863 | 2013-10-01 15:59:59 +0530 | [diff] [blame] | 3772 | be_cmd_enable_vf(adapter, vf + 1); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 3773 | be_cmd_set_logical_link_config(adapter, |
| 3774 | IFLA_VF_LINK_STATE_AUTO, |
| 3775 | vf+1); |
| 3776 | } |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3777 | } |
Sathya Perla | b4c1df9 | 2013-05-08 02:05:47 +0000 | [diff] [blame] | 3778 | |
| 3779 | if (!old_vfs) { |
| 3780 | status = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 3781 | if (status) { |
| 3782 | dev_err(dev, "SRIOV enable failed\n"); |
| 3783 | adapter->num_vfs = 0; |
| 3784 | goto err; |
| 3785 | } |
| 3786 | } |
Vasundhara Volam | f174c7e | 2014-07-17 16:20:31 +0530 | [diff] [blame] | 3787 | |
| 3788 | adapter->flags |= BE_FLAGS_SRIOV_ENABLED; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3789 | return 0; |
| 3790 | err: |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3791 | dev_err(dev, "VF setup failed\n"); |
| 3792 | be_vf_clear(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 3793 | return status; |
| 3794 | } |
| 3795 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3796 | /* Converting function_mode bits on BE3 to SH mc_type enums */ |
| 3797 | |
| 3798 | static u8 be_convert_mc_type(u32 function_mode) |
| 3799 | { |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 3800 | if (function_mode & VNIC_MODE && function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3801 | return vNIC1; |
Suresh Reddy | 66064db | 2014-06-23 16:41:29 +0530 | [diff] [blame] | 3802 | else if (function_mode & QNQ_MODE) |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3803 | return FLEX10; |
| 3804 | else if (function_mode & VNIC_MODE) |
| 3805 | return vNIC2; |
| 3806 | else if (function_mode & UMC_ENABLED) |
| 3807 | return UMC; |
| 3808 | else |
| 3809 | return MC_NONE; |
| 3810 | } |
| 3811 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3812 | /* On BE2/BE3 FW does not suggest the supported limits */ |
| 3813 | static void BEx_get_resources(struct be_adapter *adapter, |
| 3814 | struct be_resources *res) |
| 3815 | { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3816 | bool use_sriov = adapter->num_vfs ? 1 : 0; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3817 | |
| 3818 | if (be_physfn(adapter)) |
| 3819 | res->max_uc_mac = BE_UC_PMAC_COUNT; |
| 3820 | else |
| 3821 | res->max_uc_mac = BE_VF_UC_PMAC_COUNT; |
| 3822 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3823 | adapter->mc_type = be_convert_mc_type(adapter->function_mode); |
| 3824 | |
| 3825 | if (be_is_mc(adapter)) { |
| 3826 | /* Assuming that there are 4 channels per port, |
| 3827 | * when multi-channel is enabled |
| 3828 | */ |
| 3829 | if (be_is_qnq_mode(adapter)) |
| 3830 | res->max_vlans = BE_NUM_VLANS_SUPPORTED/8; |
| 3831 | else |
| 3832 | /* In a non-qnq multichannel mode, the pvid |
| 3833 | * takes up one vlan entry |
| 3834 | */ |
| 3835 | res->max_vlans = (BE_NUM_VLANS_SUPPORTED / 4) - 1; |
| 3836 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3837 | res->max_vlans = BE_NUM_VLANS_SUPPORTED; |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 3838 | } |
| 3839 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3840 | res->max_mcast_mac = BE_MAX_MC; |
| 3841 | |
Vasundhara Volam | a5243da | 2014-03-11 18:53:07 +0530 | [diff] [blame] | 3842 | /* 1) For BE3 1Gb ports, FW does not support multiple TXQs |
| 3843 | * 2) Create multiple TX rings on a BE3-R multi-channel interface |
| 3844 | * *only* if it is RSS-capable. |
| 3845 | */ |
| 3846 | if (BE2_chip(adapter) || use_sriov || (adapter->port_num > 1) || |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 3847 | be_virtfn(adapter) || |
| 3848 | (be_is_mc(adapter) && |
| 3849 | !(adapter->function_caps & BE_FUNCTION_CAPS_RSS))) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3850 | res->max_tx_qs = 1; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3851 | } else if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { |
| 3852 | struct be_resources super_nic_res = {0}; |
| 3853 | |
| 3854 | /* On a SuperNIC profile, the driver needs to use the |
| 3855 | * GET_PROFILE_CONFIG cmd to query the per-function TXQ limits |
| 3856 | */ |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3857 | be_cmd_get_profile_config(adapter, &super_nic_res, |
| 3858 | RESOURCE_LIMITS, 0); |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3859 | /* Some old versions of BE3 FW don't report max_tx_qs value */ |
| 3860 | res->max_tx_qs = super_nic_res.max_tx_qs ? : BE3_MAX_TX_QS; |
| 3861 | } else { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3862 | res->max_tx_qs = BE3_MAX_TX_QS; |
Suresh Reddy | a28277d | 2014-09-02 09:56:57 +0530 | [diff] [blame] | 3863 | } |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3864 | |
| 3865 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
| 3866 | !use_sriov && be_physfn(adapter)) |
| 3867 | res->max_rss_qs = (adapter->be3_native) ? |
| 3868 | BE3_MAX_RSS_QS : BE2_MAX_RSS_QS; |
| 3869 | res->max_rx_qs = res->max_rss_qs + 1; |
| 3870 | |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3871 | if (be_physfn(adapter)) |
Vasundhara Volam | d3518e2 | 2014-07-17 16:20:29 +0530 | [diff] [blame] | 3872 | res->max_evt_qs = (be_max_vfs(adapter) > 0) ? |
Suresh Reddy | e3dc867 | 2014-01-06 13:02:25 +0530 | [diff] [blame] | 3873 | BE3_SRIOV_MAX_EVT_QS : BE3_MAX_EVT_QS; |
| 3874 | else |
| 3875 | res->max_evt_qs = 1; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3876 | |
| 3877 | res->if_cap_flags = BE_IF_CAP_FLAGS_WANT; |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3878 | res->if_cap_flags &= ~BE_IF_FLAGS_DEFQ_RSS; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3879 | if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS)) |
| 3880 | res->if_cap_flags &= ~BE_IF_FLAGS_RSS; |
| 3881 | } |
| 3882 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3883 | static void be_setup_init(struct be_adapter *adapter) |
| 3884 | { |
| 3885 | adapter->vlan_prio_bmap = 0xff; |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3886 | adapter->phy.link_speed = -1; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3887 | adapter->if_handle = -1; |
| 3888 | adapter->be3_native = false; |
Sathya Perla | f66b7cf | 2015-02-06 08:18:41 -0500 | [diff] [blame] | 3889 | adapter->if_flags = 0; |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3890 | if (be_physfn(adapter)) |
| 3891 | adapter->cmd_privileges = MAX_PRIVILEGES; |
| 3892 | else |
| 3893 | adapter->cmd_privileges = MIN_PRIVILEGES; |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3896 | static int be_get_sriov_config(struct be_adapter *adapter) |
| 3897 | { |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3898 | struct be_resources res = {0}; |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3899 | int max_vfs, old_vfs; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3900 | |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 3901 | be_cmd_get_profile_config(adapter, &res, RESOURCE_LIMITS, 0); |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3902 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3903 | /* Some old versions of BE3 FW don't report max_vfs value */ |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3904 | if (BE3_chip(adapter) && !res.max_vfs) { |
| 3905 | max_vfs = pci_sriov_get_totalvfs(adapter->pdev); |
| 3906 | res.max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0; |
| 3907 | } |
| 3908 | |
Sathya Perla | d3d1831 | 2014-08-01 17:47:30 +0530 | [diff] [blame] | 3909 | adapter->pool_res = res; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3910 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3911 | /* If during previous unload of the driver, the VFs were not disabled, |
| 3912 | * then we cannot rely on the PF POOL limits for the TotalVFs value. |
| 3913 | * Instead use the TotalVFs value stored in the pci-dev struct. |
| 3914 | */ |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3915 | old_vfs = pci_num_vf(adapter->pdev); |
| 3916 | if (old_vfs) { |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3917 | dev_info(&adapter->pdev->dev, "%d VFs are already enabled\n", |
| 3918 | old_vfs); |
| 3919 | |
| 3920 | adapter->pool_res.max_vfs = |
| 3921 | pci_sriov_get_totalvfs(adapter->pdev); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3922 | adapter->num_vfs = old_vfs; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | return 0; |
| 3926 | } |
| 3927 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3928 | static void be_alloc_sriov_res(struct be_adapter *adapter) |
| 3929 | { |
| 3930 | int old_vfs = pci_num_vf(adapter->pdev); |
| 3931 | u16 num_vf_qs; |
| 3932 | int status; |
| 3933 | |
| 3934 | be_get_sriov_config(adapter); |
| 3935 | |
| 3936 | if (!old_vfs) |
| 3937 | pci_sriov_set_totalvfs(adapter->pdev, be_max_vfs(adapter)); |
| 3938 | |
| 3939 | /* When the HW is in SRIOV capable configuration, the PF-pool |
| 3940 | * resources are given to PF during driver load, if there are no |
| 3941 | * old VFs. This facility is not available in BE3 FW. |
| 3942 | * Also, this is done by FW in Lancer chip. |
| 3943 | */ |
| 3944 | if (skyhawk_chip(adapter) && be_max_vfs(adapter) && !old_vfs) { |
| 3945 | num_vf_qs = be_calculate_vf_qs(adapter, 0); |
| 3946 | status = be_cmd_set_sriov_config(adapter, adapter->pool_res, 0, |
| 3947 | num_vf_qs); |
| 3948 | if (status) |
| 3949 | dev_err(&adapter->pdev->dev, |
| 3950 | "Failed to optimize SRIOV resources\n"); |
| 3951 | } |
| 3952 | } |
| 3953 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3954 | static int be_get_resources(struct be_adapter *adapter) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3955 | { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3956 | struct device *dev = &adapter->pdev->dev; |
| 3957 | struct be_resources res = {0}; |
| 3958 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3959 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3960 | if (BEx_chip(adapter)) { |
| 3961 | BEx_get_resources(adapter, &res); |
| 3962 | adapter->res = res; |
| 3963 | } |
| 3964 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3965 | /* For Lancer, SH etc read per-function resource limits from FW. |
| 3966 | * GET_FUNC_CONFIG returns per function guaranteed limits. |
| 3967 | * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits |
| 3968 | */ |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3969 | if (!BEx_chip(adapter)) { |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3970 | status = be_cmd_get_func_config(adapter, &res); |
| 3971 | if (status) |
| 3972 | return status; |
| 3973 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3974 | /* If a deafault RXQ must be created, we'll use up one RSSQ*/ |
| 3975 | if (res.max_rss_qs && res.max_rss_qs == res.max_rx_qs && |
| 3976 | !(res.if_cap_flags & BE_IF_FLAGS_DEFQ_RSS)) |
| 3977 | res.max_rss_qs -= 1; |
| 3978 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3979 | /* If RoCE may be enabled stash away half the EQs for RoCE */ |
| 3980 | if (be_roce_supported(adapter)) |
| 3981 | res.max_evt_qs /= 2; |
| 3982 | adapter->res = res; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
Vasundhara Volam | 71bb8bd | 2015-03-04 00:44:32 -0500 | [diff] [blame] | 3985 | /* If FW supports RSS default queue, then skip creating non-RSS |
| 3986 | * queue for non-IP traffic. |
| 3987 | */ |
| 3988 | adapter->need_def_rxq = (be_if_cap_flags(adapter) & |
| 3989 | BE_IF_FLAGS_DEFQ_RSS) ? 0 : 1; |
| 3990 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 3991 | dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n", |
| 3992 | be_max_txqs(adapter), be_max_rxqs(adapter), |
| 3993 | be_max_rss(adapter), be_max_eqs(adapter), |
| 3994 | be_max_vfs(adapter)); |
| 3995 | dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n", |
| 3996 | be_max_uc(adapter), be_max_mc(adapter), |
| 3997 | be_max_vlans(adapter)); |
| 3998 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 3999 | /* Sanitize cfg_num_qs based on HW and platform limits */ |
| 4000 | adapter->cfg_num_qs = min_t(u16, netif_get_num_default_rss_queues(), |
| 4001 | be_max_qs(adapter)); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4002 | return 0; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4005 | static int be_get_config(struct be_adapter *adapter) |
| 4006 | { |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4007 | int status, level; |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4008 | u16 profile_id; |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4009 | |
| 4010 | status = be_cmd_get_cntl_attributes(adapter); |
| 4011 | if (status) |
| 4012 | return status; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4013 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4014 | status = be_cmd_query_fw_cfg(adapter); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4015 | if (status) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4016 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4017 | |
Sathya Perla | 6b085ba | 2015-02-23 04:20:09 -0500 | [diff] [blame] | 4018 | if (BEx_chip(adapter)) { |
| 4019 | level = be_cmd_get_fw_log_level(adapter); |
| 4020 | adapter->msg_enable = |
| 4021 | level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0; |
| 4022 | } |
| 4023 | |
| 4024 | be_cmd_get_acpi_wol_cap(adapter); |
| 4025 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4026 | be_cmd_query_port_name(adapter); |
| 4027 | |
| 4028 | if (be_physfn(adapter)) { |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4029 | status = be_cmd_get_active_profile(adapter, &profile_id); |
| 4030 | if (!status) |
| 4031 | dev_info(&adapter->pdev->dev, |
| 4032 | "Using profile 0x%x\n", profile_id); |
Vasundhara Volam | 962bcb7 | 2014-07-17 16:20:30 +0530 | [diff] [blame] | 4033 | } |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4034 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4035 | status = be_get_resources(adapter); |
| 4036 | if (status) |
| 4037 | return status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4038 | |
Ravikumar Nelavelli | 46ee9c1 | 2014-03-11 18:53:06 +0530 | [diff] [blame] | 4039 | adapter->pmac_id = kcalloc(be_max_uc(adapter), |
| 4040 | sizeof(*adapter->pmac_id), GFP_KERNEL); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4041 | if (!adapter->pmac_id) |
| 4042 | return -ENOMEM; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4043 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4044 | return 0; |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4045 | } |
| 4046 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4047 | static int be_mac_setup(struct be_adapter *adapter) |
| 4048 | { |
| 4049 | u8 mac[ETH_ALEN]; |
| 4050 | int status; |
| 4051 | |
| 4052 | if (is_zero_ether_addr(adapter->netdev->dev_addr)) { |
| 4053 | status = be_cmd_get_perm_mac(adapter, mac); |
| 4054 | if (status) |
| 4055 | return status; |
| 4056 | |
| 4057 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 4058 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 4059 | } else { |
| 4060 | /* Maybe the HW was reset; dev_addr must be re-programmed */ |
| 4061 | memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN); |
| 4062 | } |
| 4063 | |
Ajit Khaparde | 2c7a9dc | 2013-11-22 12:51:28 -0600 | [diff] [blame] | 4064 | /* For BE3-R VFs, the PF programs the initial MAC address */ |
| 4065 | if (!(BEx_chip(adapter) && be_virtfn(adapter))) |
| 4066 | be_cmd_pmac_add(adapter, mac, adapter->if_handle, |
| 4067 | &adapter->pmac_id[0], 0); |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4068 | return 0; |
| 4069 | } |
| 4070 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4071 | static void be_schedule_worker(struct be_adapter *adapter) |
| 4072 | { |
| 4073 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 4074 | adapter->flags |= BE_FLAGS_WORKER_SCHEDULED; |
| 4075 | } |
| 4076 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 4077 | static void be_schedule_err_detection(struct be_adapter *adapter) |
| 4078 | { |
| 4079 | schedule_delayed_work(&adapter->be_err_detection_work, |
| 4080 | msecs_to_jiffies(1000)); |
| 4081 | adapter->flags |= BE_FLAGS_ERR_DETECTION_SCHEDULED; |
| 4082 | } |
| 4083 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4084 | static int be_setup_queues(struct be_adapter *adapter) |
| 4085 | { |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4086 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4087 | int status; |
| 4088 | |
| 4089 | status = be_evt_queues_create(adapter); |
| 4090 | if (status) |
| 4091 | goto err; |
| 4092 | |
| 4093 | status = be_tx_qs_create(adapter); |
| 4094 | if (status) |
| 4095 | goto err; |
| 4096 | |
| 4097 | status = be_rx_cqs_create(adapter); |
| 4098 | if (status) |
| 4099 | goto err; |
| 4100 | |
| 4101 | status = be_mcc_queues_create(adapter); |
| 4102 | if (status) |
| 4103 | goto err; |
| 4104 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4105 | status = netif_set_real_num_rx_queues(netdev, adapter->num_rx_qs); |
| 4106 | if (status) |
| 4107 | goto err; |
| 4108 | |
| 4109 | status = netif_set_real_num_tx_queues(netdev, adapter->num_tx_qs); |
| 4110 | if (status) |
| 4111 | goto err; |
| 4112 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4113 | return 0; |
| 4114 | err: |
| 4115 | dev_err(&adapter->pdev->dev, "queue_setup failed\n"); |
| 4116 | return status; |
| 4117 | } |
| 4118 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4119 | int be_update_queues(struct be_adapter *adapter) |
| 4120 | { |
| 4121 | struct net_device *netdev = adapter->netdev; |
| 4122 | int status; |
| 4123 | |
| 4124 | if (netif_running(netdev)) |
| 4125 | be_close(netdev); |
| 4126 | |
| 4127 | be_cancel_worker(adapter); |
| 4128 | |
| 4129 | /* If any vectors have been shared with RoCE we cannot re-program |
| 4130 | * the MSIx table. |
| 4131 | */ |
| 4132 | if (!adapter->num_msix_roce_vec) |
| 4133 | be_msix_disable(adapter); |
| 4134 | |
| 4135 | be_clear_queues(adapter); |
| 4136 | |
| 4137 | if (!msix_enabled(adapter)) { |
| 4138 | status = be_msix_enable(adapter); |
| 4139 | if (status) |
| 4140 | return status; |
| 4141 | } |
| 4142 | |
| 4143 | status = be_setup_queues(adapter); |
| 4144 | if (status) |
| 4145 | return status; |
| 4146 | |
| 4147 | be_schedule_worker(adapter); |
| 4148 | |
| 4149 | if (netif_running(netdev)) |
| 4150 | status = be_open(netdev); |
| 4151 | |
| 4152 | return status; |
| 4153 | } |
| 4154 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 4155 | static inline int fw_major_num(const char *fw_ver) |
| 4156 | { |
| 4157 | int fw_major = 0, i; |
| 4158 | |
| 4159 | i = sscanf(fw_ver, "%d.", &fw_major); |
| 4160 | if (i != 1) |
| 4161 | return 0; |
| 4162 | |
| 4163 | return fw_major; |
| 4164 | } |
| 4165 | |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4166 | /* If any VFs are already enabled don't FLR the PF */ |
| 4167 | static bool be_reset_required(struct be_adapter *adapter) |
| 4168 | { |
| 4169 | return pci_num_vf(adapter->pdev) ? false : true; |
| 4170 | } |
| 4171 | |
| 4172 | /* Wait for the FW to be ready and perform the required initialization */ |
| 4173 | static int be_func_init(struct be_adapter *adapter) |
| 4174 | { |
| 4175 | int status; |
| 4176 | |
| 4177 | status = be_fw_wait_ready(adapter); |
| 4178 | if (status) |
| 4179 | return status; |
| 4180 | |
| 4181 | if (be_reset_required(adapter)) { |
| 4182 | status = be_cmd_reset_function(adapter); |
| 4183 | if (status) |
| 4184 | return status; |
| 4185 | |
| 4186 | /* Wait for interrupts to quiesce after an FLR */ |
| 4187 | msleep(100); |
| 4188 | |
| 4189 | /* We can clear all errors when function reset succeeds */ |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 4190 | be_clear_error(adapter, BE_CLEAR_ALL); |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | /* Tell FW we're ready to fire cmds */ |
| 4194 | status = be_cmd_fw_init(adapter); |
| 4195 | if (status) |
| 4196 | return status; |
| 4197 | |
| 4198 | /* Allow interrupts for other ULPs running on NIC function */ |
| 4199 | be_intr_set(adapter, true); |
| 4200 | |
| 4201 | return 0; |
| 4202 | } |
| 4203 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 4204 | static int be_setup(struct be_adapter *adapter) |
| 4205 | { |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4206 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4207 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4208 | |
Sathya Perla | f962f84 | 2015-02-23 04:20:16 -0500 | [diff] [blame] | 4209 | status = be_func_init(adapter); |
| 4210 | if (status) |
| 4211 | return status; |
| 4212 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 4213 | be_setup_init(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4214 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4215 | if (!lancer_chip(adapter)) |
| 4216 | be_cmd_req_native_mode(adapter); |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 4217 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 4218 | if (!BE2_chip(adapter) && be_physfn(adapter)) |
| 4219 | be_alloc_sriov_res(adapter); |
| 4220 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4221 | status = be_get_config(adapter); |
| 4222 | if (status) |
| 4223 | goto err; |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 4224 | |
Somnath Kotur | c2bba3d | 2013-05-02 03:37:08 +0000 | [diff] [blame] | 4225 | status = be_msix_enable(adapter); |
| 4226 | if (status) |
| 4227 | goto err; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4228 | |
Kalesh AP | 0700d81 | 2015-01-20 03:51:43 -0500 | [diff] [blame] | 4229 | status = be_if_create(adapter, &adapter->if_handle, |
| 4230 | be_if_cap_flags(adapter), 0); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4231 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4232 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4233 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4234 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 4235 | rtnl_lock(); |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 4236 | status = be_setup_queues(adapter); |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4237 | rtnl_unlock(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4238 | if (status) |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4239 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4240 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4241 | be_cmd_get_fn_privileges(adapter, &adapter->cmd_privileges, 0); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4242 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 4243 | status = be_mac_setup(adapter); |
| 4244 | if (status) |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 4245 | goto err; |
| 4246 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4247 | be_cmd_get_fw_ver(adapter); |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 4248 | dev_info(dev, "FW version is %s\n", adapter->fw_ver); |
Somnath Kotur | 5a56eb1 | 2011-09-30 07:24:28 +0000 | [diff] [blame] | 4249 | |
Somnath Kotur | e9e2a90 | 2013-10-24 14:37:53 +0530 | [diff] [blame] | 4250 | if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) { |
Vasundhara Volam | 5076266 | 2014-09-12 17:39:14 +0530 | [diff] [blame] | 4251 | 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] | 4252 | adapter->fw_ver); |
| 4253 | dev_err(dev, "Please upgrade firmware to version >= 4.0\n"); |
| 4254 | } |
| 4255 | |
Sathya Perla | 1d1e9a4 | 2012-06-05 19:37:17 +0000 | [diff] [blame] | 4256 | if (adapter->vlans_added) |
Sathya Perla | 10329df | 2012-06-05 19:37:18 +0000 | [diff] [blame] | 4257 | be_vid_config(adapter); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4258 | |
| 4259 | be_set_rx_mode(adapter->netdev); |
| 4260 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 4261 | status = be_cmd_set_flow_control(adapter, adapter->tx_fc, |
| 4262 | adapter->rx_fc); |
| 4263 | if (status) |
| 4264 | be_cmd_get_flow_control(adapter, &adapter->tx_fc, |
| 4265 | &adapter->rx_fc); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 4266 | |
Kalesh AP | 00d594c | 2015-01-20 03:51:44 -0500 | [diff] [blame] | 4267 | dev_info(&adapter->pdev->dev, "HW Flow control - TX:%d RX:%d\n", |
| 4268 | adapter->tx_fc, adapter->rx_fc); |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4269 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4270 | if (be_physfn(adapter)) |
| 4271 | be_cmd_set_logical_link_config(adapter, |
| 4272 | IFLA_VF_LINK_STATE_AUTO, 0); |
| 4273 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4274 | if (adapter->num_vfs) |
| 4275 | be_vf_setup(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4276 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4277 | status = be_cmd_get_phy_info(adapter); |
| 4278 | if (!status && be_pause_supported(adapter)) |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 4279 | adapter->phy.fc_autoneg = 1; |
| 4280 | |
Sathya Perla | 68d7bdc | 2013-08-27 16:57:35 +0530 | [diff] [blame] | 4281 | be_schedule_worker(adapter); |
Kalesh AP | e1ad8e3 | 2014-04-14 16:12:41 +0530 | [diff] [blame] | 4282 | adapter->flags |= BE_FLAGS_SETUP_DONE; |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 4283 | return 0; |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 4284 | err: |
| 4285 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 4286 | return status; |
| 4287 | } |
| 4288 | |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4289 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4290 | static void be_netpoll(struct net_device *netdev) |
| 4291 | { |
| 4292 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 4293 | struct be_eq_obj *eqo; |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4294 | int i; |
| 4295 | |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 4296 | for_all_evt_queues(adapter, eqo, i) { |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 4297 | be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0, 0); |
Sathya Perla | e49cc34 | 2012-11-27 19:50:02 +0000 | [diff] [blame] | 4298 | napi_schedule(&eqo->napi); |
| 4299 | } |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 4300 | } |
| 4301 | #endif |
| 4302 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4303 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 4304 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4305 | static bool phy_flashing_required(struct be_adapter *adapter) |
| 4306 | { |
Vasundhara Volam | e02cfd9 | 2015-01-20 03:51:48 -0500 | [diff] [blame] | 4307 | return (adapter->phy.phy_type == PHY_TYPE_TN_8022 && |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 4308 | adapter->phy.interface_type == PHY_TYPE_BASET_10GB); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4311 | static bool is_comp_in_ufi(struct be_adapter *adapter, |
| 4312 | struct flash_section_info *fsec, int type) |
| 4313 | { |
| 4314 | int i = 0, img_type = 0; |
| 4315 | struct flash_section_info_g2 *fsec_g2 = NULL; |
| 4316 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4317 | if (BE2_chip(adapter)) |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4318 | fsec_g2 = (struct flash_section_info_g2 *)fsec; |
| 4319 | |
| 4320 | for (i = 0; i < MAX_FLASH_COMP; i++) { |
| 4321 | if (fsec_g2) |
| 4322 | img_type = le32_to_cpu(fsec_g2->fsec_entry[i].type); |
| 4323 | else |
| 4324 | img_type = le32_to_cpu(fsec->fsec_entry[i].type); |
| 4325 | |
| 4326 | if (img_type == type) |
| 4327 | return true; |
| 4328 | } |
| 4329 | return false; |
| 4330 | |
| 4331 | } |
| 4332 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 4333 | static struct flash_section_info *get_fsec_info(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4334 | int header_size, |
| 4335 | const struct firmware *fw) |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4336 | { |
| 4337 | struct flash_section_info *fsec = NULL; |
| 4338 | const u8 *p = fw->data; |
| 4339 | |
| 4340 | p += header_size; |
| 4341 | while (p < (fw->data + fw->size)) { |
| 4342 | fsec = (struct flash_section_info *)p; |
| 4343 | if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie))) |
| 4344 | return fsec; |
| 4345 | p += 32; |
| 4346 | } |
| 4347 | return NULL; |
| 4348 | } |
| 4349 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4350 | static int be_check_flash_crc(struct be_adapter *adapter, const u8 *p, |
| 4351 | u32 img_offset, u32 img_size, int hdr_size, |
| 4352 | u16 img_optype, bool *crc_match) |
| 4353 | { |
| 4354 | u32 crc_offset; |
| 4355 | int status; |
| 4356 | u8 crc[4]; |
| 4357 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4358 | status = be_cmd_get_flash_crc(adapter, crc, img_optype, img_offset, |
| 4359 | img_size - 4); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4360 | if (status) |
| 4361 | return status; |
| 4362 | |
| 4363 | crc_offset = hdr_size + img_offset + img_size - 4; |
| 4364 | |
| 4365 | /* Skip flashing, if crc of flashed region matches */ |
| 4366 | if (!memcmp(crc, p + crc_offset, 4)) |
| 4367 | *crc_match = true; |
| 4368 | else |
| 4369 | *crc_match = false; |
| 4370 | |
| 4371 | return status; |
| 4372 | } |
| 4373 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4374 | static int be_flash(struct be_adapter *adapter, const u8 *img, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4375 | struct be_dma_mem *flash_cmd, int optype, int img_size, |
| 4376 | u32 img_offset) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4377 | { |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4378 | u32 flash_op, num_bytes, total_bytes = img_size, bytes_sent = 0; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4379 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4380 | int status; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4381 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4382 | while (total_bytes) { |
| 4383 | num_bytes = min_t(u32, 32*1024, total_bytes); |
| 4384 | |
| 4385 | total_bytes -= num_bytes; |
| 4386 | |
| 4387 | if (!total_bytes) { |
| 4388 | if (optype == OPTYPE_PHY_FW) |
| 4389 | flash_op = FLASHROM_OPER_PHY_FLASH; |
| 4390 | else |
| 4391 | flash_op = FLASHROM_OPER_FLASH; |
| 4392 | } else { |
| 4393 | if (optype == OPTYPE_PHY_FW) |
| 4394 | flash_op = FLASHROM_OPER_PHY_SAVE; |
| 4395 | else |
| 4396 | flash_op = FLASHROM_OPER_SAVE; |
| 4397 | } |
| 4398 | |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 4399 | memcpy(req->data_buf, img, num_bytes); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4400 | img += num_bytes; |
| 4401 | status = be_cmd_write_flashrom(adapter, flash_cmd, optype, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4402 | flash_op, img_offset + |
| 4403 | bytes_sent, num_bytes); |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4404 | if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST && |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4405 | optype == OPTYPE_PHY_FW) |
| 4406 | break; |
| 4407 | else if (status) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4408 | return status; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4409 | |
| 4410 | bytes_sent += num_bytes; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4411 | } |
| 4412 | return 0; |
| 4413 | } |
| 4414 | |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 4415 | /* For BE2, BE3 and BE3-R */ |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4416 | static int be_flash_BEx(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4417 | const struct firmware *fw, |
| 4418 | struct be_dma_mem *flash_cmd, int num_of_images) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4419 | { |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4420 | int img_hdrs_size = (num_of_images * sizeof(struct image_hdr)); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4421 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4422 | struct flash_section_info *fsec = NULL; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4423 | int status, i, filehdr_size, num_comp; |
| 4424 | const struct flash_comp *pflashcomp; |
| 4425 | bool crc_match; |
| 4426 | const u8 *p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4427 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4428 | struct flash_comp gen3_flash_types[] = { |
| 4429 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, OPTYPE_ISCSI_ACTIVE, |
| 4430 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_iSCSI}, |
| 4431 | { FLASH_REDBOOT_START_g3, OPTYPE_REDBOOT, |
| 4432 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3, IMAGE_BOOT_CODE}, |
| 4433 | { FLASH_iSCSI_BIOS_START_g3, OPTYPE_BIOS, |
| 4434 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_ISCSI}, |
| 4435 | { FLASH_PXE_BIOS_START_g3, OPTYPE_PXE_BIOS, |
| 4436 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_PXE}, |
| 4437 | { FLASH_FCoE_BIOS_START_g3, OPTYPE_FCOE_BIOS, |
| 4438 | FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_FCoE}, |
| 4439 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, OPTYPE_ISCSI_BACKUP, |
| 4440 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 4441 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, OPTYPE_FCOE_FW_ACTIVE, |
| 4442 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_FCoE}, |
| 4443 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, OPTYPE_FCOE_FW_BACKUP, |
| 4444 | FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_FCoE}, |
| 4445 | { FLASH_NCSI_START_g3, OPTYPE_NCSI_FW, |
| 4446 | FLASH_NCSI_IMAGE_MAX_SIZE_g3, IMAGE_NCSI}, |
| 4447 | { FLASH_PHY_FW_START_g3, OPTYPE_PHY_FW, |
| 4448 | FLASH_PHY_FW_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_PHY} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4449 | }; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4450 | |
| 4451 | struct flash_comp gen2_flash_types[] = { |
| 4452 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, OPTYPE_ISCSI_ACTIVE, |
| 4453 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_iSCSI}, |
| 4454 | { FLASH_REDBOOT_START_g2, OPTYPE_REDBOOT, |
| 4455 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2, IMAGE_BOOT_CODE}, |
| 4456 | { FLASH_iSCSI_BIOS_START_g2, OPTYPE_BIOS, |
| 4457 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_ISCSI}, |
| 4458 | { FLASH_PXE_BIOS_START_g2, OPTYPE_PXE_BIOS, |
| 4459 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_PXE}, |
| 4460 | { FLASH_FCoE_BIOS_START_g2, OPTYPE_FCOE_BIOS, |
| 4461 | FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_FCoE}, |
| 4462 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, OPTYPE_ISCSI_BACKUP, |
| 4463 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_iSCSI}, |
| 4464 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, OPTYPE_FCOE_FW_ACTIVE, |
| 4465 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_FCoE}, |
| 4466 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, OPTYPE_FCOE_FW_BACKUP, |
| 4467 | FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_FCoE} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4468 | }; |
| 4469 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4470 | if (BE3_chip(adapter)) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4471 | pflashcomp = gen3_flash_types; |
| 4472 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 4473 | num_comp = ARRAY_SIZE(gen3_flash_types); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4474 | } else { |
| 4475 | pflashcomp = gen2_flash_types; |
| 4476 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 4477 | num_comp = ARRAY_SIZE(gen2_flash_types); |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4478 | img_hdrs_size = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4479 | } |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 4480 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4481 | /* Get flash section info*/ |
| 4482 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 4483 | if (!fsec) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4484 | dev_err(dev, "Invalid Cookie. FW image may be corrupted\n"); |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4485 | return -1; |
| 4486 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 4487 | for (i = 0; i < num_comp; i++) { |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4488 | if (!is_comp_in_ufi(adapter, fsec, pflashcomp[i].img_type)) |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 4489 | continue; |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4490 | |
| 4491 | if ((pflashcomp[i].optype == OPTYPE_NCSI_FW) && |
| 4492 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 4493 | continue; |
| 4494 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4495 | if (pflashcomp[i].optype == OPTYPE_PHY_FW && |
| 4496 | !phy_flashing_required(adapter)) |
| 4497 | continue; |
| 4498 | |
| 4499 | if (pflashcomp[i].optype == OPTYPE_REDBOOT) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4500 | status = be_check_flash_crc(adapter, fw->data, |
| 4501 | pflashcomp[i].offset, |
| 4502 | pflashcomp[i].size, |
| 4503 | filehdr_size + |
| 4504 | img_hdrs_size, |
| 4505 | OPTYPE_REDBOOT, &crc_match); |
| 4506 | if (status) { |
| 4507 | dev_err(dev, |
| 4508 | "Could not get CRC for 0x%x region\n", |
| 4509 | pflashcomp[i].optype); |
| 4510 | continue; |
| 4511 | } |
| 4512 | |
| 4513 | if (crc_match) |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4514 | continue; |
| 4515 | } |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 4516 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4517 | p = fw->data + filehdr_size + pflashcomp[i].offset + |
| 4518 | img_hdrs_size; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 4519 | if (p + pflashcomp[i].size > fw->data + fw->size) |
| 4520 | return -1; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4521 | |
| 4522 | status = be_flash(adapter, p, flash_cmd, pflashcomp[i].optype, |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4523 | pflashcomp[i].size, 0); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4524 | if (status) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4525 | dev_err(dev, "Flashing section type 0x%x failed\n", |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4526 | pflashcomp[i].img_type); |
| 4527 | return status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4528 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4529 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4530 | return 0; |
| 4531 | } |
| 4532 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4533 | static u16 be_get_img_optype(struct flash_section_entry fsec_entry) |
| 4534 | { |
| 4535 | u32 img_type = le32_to_cpu(fsec_entry.type); |
| 4536 | u16 img_optype = le16_to_cpu(fsec_entry.optype); |
| 4537 | |
| 4538 | if (img_optype != 0xFFFF) |
| 4539 | return img_optype; |
| 4540 | |
| 4541 | switch (img_type) { |
| 4542 | case IMAGE_FIRMWARE_iSCSI: |
| 4543 | img_optype = OPTYPE_ISCSI_ACTIVE; |
| 4544 | break; |
| 4545 | case IMAGE_BOOT_CODE: |
| 4546 | img_optype = OPTYPE_REDBOOT; |
| 4547 | break; |
| 4548 | case IMAGE_OPTION_ROM_ISCSI: |
| 4549 | img_optype = OPTYPE_BIOS; |
| 4550 | break; |
| 4551 | case IMAGE_OPTION_ROM_PXE: |
| 4552 | img_optype = OPTYPE_PXE_BIOS; |
| 4553 | break; |
| 4554 | case IMAGE_OPTION_ROM_FCoE: |
| 4555 | img_optype = OPTYPE_FCOE_BIOS; |
| 4556 | break; |
| 4557 | case IMAGE_FIRMWARE_BACKUP_iSCSI: |
| 4558 | img_optype = OPTYPE_ISCSI_BACKUP; |
| 4559 | break; |
| 4560 | case IMAGE_NCSI: |
| 4561 | img_optype = OPTYPE_NCSI_FW; |
| 4562 | break; |
| 4563 | case IMAGE_FLASHISM_JUMPVECTOR: |
| 4564 | img_optype = OPTYPE_FLASHISM_JUMPVECTOR; |
| 4565 | break; |
| 4566 | case IMAGE_FIRMWARE_PHY: |
| 4567 | img_optype = OPTYPE_SH_PHY_FW; |
| 4568 | break; |
| 4569 | case IMAGE_REDBOOT_DIR: |
| 4570 | img_optype = OPTYPE_REDBOOT_DIR; |
| 4571 | break; |
| 4572 | case IMAGE_REDBOOT_CONFIG: |
| 4573 | img_optype = OPTYPE_REDBOOT_CONFIG; |
| 4574 | break; |
| 4575 | case IMAGE_UFI_DIR: |
| 4576 | img_optype = OPTYPE_UFI_DIR; |
| 4577 | break; |
| 4578 | default: |
| 4579 | break; |
| 4580 | } |
| 4581 | |
| 4582 | return img_optype; |
| 4583 | } |
| 4584 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4585 | static int be_flash_skyhawk(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4586 | const struct firmware *fw, |
| 4587 | struct be_dma_mem *flash_cmd, int num_of_images) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4588 | { |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4589 | int img_hdrs_size = num_of_images * sizeof(struct image_hdr); |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4590 | bool crc_match, old_fw_img, flash_offset_support = true; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4591 | struct device *dev = &adapter->pdev->dev; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4592 | struct flash_section_info *fsec = NULL; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4593 | u32 img_offset, img_size, img_type; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4594 | u16 img_optype, flash_optype; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4595 | int status, i, filehdr_size; |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4596 | const u8 *p; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4597 | |
| 4598 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
| 4599 | fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw); |
| 4600 | if (!fsec) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4601 | dev_err(dev, "Invalid Cookie. FW image may be corrupted\n"); |
Kalesh AP | 56ace3a | 2014-07-17 16:20:20 +0530 | [diff] [blame] | 4602 | return -EINVAL; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4603 | } |
| 4604 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4605 | retry_flash: |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4606 | for (i = 0; i < le32_to_cpu(fsec->fsec_hdr.num_images); i++) { |
| 4607 | img_offset = le32_to_cpu(fsec->fsec_entry[i].offset); |
| 4608 | img_size = le32_to_cpu(fsec->fsec_entry[i].pad_size); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4609 | img_type = le32_to_cpu(fsec->fsec_entry[i].type); |
| 4610 | img_optype = be_get_img_optype(fsec->fsec_entry[i]); |
| 4611 | old_fw_img = fsec->fsec_entry[i].optype == 0xFFFF; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4612 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4613 | if (img_optype == 0xFFFF) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4614 | continue; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4615 | |
| 4616 | if (flash_offset_support) |
| 4617 | flash_optype = OPTYPE_OFFSET_SPECIFIED; |
| 4618 | else |
| 4619 | flash_optype = img_optype; |
| 4620 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4621 | /* Don't bother verifying CRC if an old FW image is being |
| 4622 | * flashed |
| 4623 | */ |
| 4624 | if (old_fw_img) |
| 4625 | goto flash; |
| 4626 | |
| 4627 | status = be_check_flash_crc(adapter, fw->data, img_offset, |
| 4628 | img_size, filehdr_size + |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4629 | img_hdrs_size, flash_optype, |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4630 | &crc_match); |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4631 | if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST || |
| 4632 | base_status(status) == MCC_STATUS_ILLEGAL_FIELD) { |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4633 | /* The current FW image on the card does not support |
| 4634 | * OFFSET based flashing. Retry using older mechanism |
| 4635 | * of OPTYPE based flashing |
| 4636 | */ |
| 4637 | if (flash_optype == OPTYPE_OFFSET_SPECIFIED) { |
| 4638 | flash_offset_support = false; |
| 4639 | goto retry_flash; |
| 4640 | } |
| 4641 | |
| 4642 | /* The current FW image on the card does not recognize |
| 4643 | * the new FLASH op_type. The FW download is partially |
| 4644 | * complete. Reboot the server now to enable FW image |
| 4645 | * to recognize the new FLASH op_type. To complete the |
| 4646 | * remaining process, download the same FW again after |
| 4647 | * the reboot. |
| 4648 | */ |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4649 | dev_err(dev, "Flash incomplete. Reset the server\n"); |
| 4650 | dev_err(dev, "Download FW image again after reset\n"); |
| 4651 | return -EAGAIN; |
| 4652 | } else if (status) { |
| 4653 | dev_err(dev, "Could not get CRC for 0x%x region\n", |
| 4654 | img_optype); |
| 4655 | return -EFAULT; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4658 | if (crc_match) |
| 4659 | continue; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4660 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4661 | flash: |
| 4662 | p = fw->data + filehdr_size + img_offset + img_hdrs_size; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4663 | if (p + img_size > fw->data + fw->size) |
| 4664 | return -1; |
| 4665 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 4666 | status = be_flash(adapter, p, flash_cmd, flash_optype, img_size, |
| 4667 | img_offset); |
| 4668 | |
| 4669 | /* The current FW image on the card does not support OFFSET |
| 4670 | * based flashing. Retry using older mechanism of OPTYPE based |
| 4671 | * flashing |
| 4672 | */ |
| 4673 | if (base_status(status) == MCC_STATUS_ILLEGAL_FIELD && |
| 4674 | flash_optype == OPTYPE_OFFSET_SPECIFIED) { |
| 4675 | flash_offset_support = false; |
| 4676 | goto retry_flash; |
| 4677 | } |
| 4678 | |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4679 | /* For old FW images ignore ILLEGAL_FIELD error or errors on |
| 4680 | * UFI_DIR region |
| 4681 | */ |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 4682 | if (old_fw_img && |
| 4683 | (base_status(status) == MCC_STATUS_ILLEGAL_FIELD || |
| 4684 | (img_optype == OPTYPE_UFI_DIR && |
| 4685 | base_status(status) == MCC_STATUS_FAILED))) { |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 4686 | continue; |
| 4687 | } else if (status) { |
| 4688 | dev_err(dev, "Flashing section type 0x%x failed\n", |
| 4689 | img_type); |
| 4690 | return -EFAULT; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4691 | } |
| 4692 | } |
| 4693 | return 0; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4696 | static int lancer_fw_download(struct be_adapter *adapter, |
Sathya Perla | 748b539 | 2014-05-09 13:29:13 +0530 | [diff] [blame] | 4697 | const struct firmware *fw) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4698 | { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4699 | #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024) |
| 4700 | #define LANCER_FW_DOWNLOAD_LOCATION "/prg" |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4701 | struct device *dev = &adapter->pdev->dev; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4702 | struct be_dma_mem flash_cmd; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4703 | const u8 *data_ptr = NULL; |
| 4704 | u8 *dest_image_ptr = NULL; |
| 4705 | size_t image_size = 0; |
| 4706 | u32 chunk_size = 0; |
| 4707 | u32 data_written = 0; |
| 4708 | u32 offset = 0; |
| 4709 | int status = 0; |
| 4710 | u8 add_status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4711 | u8 change_status; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4712 | |
| 4713 | if (!IS_ALIGNED(fw->size, sizeof(u32))) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4714 | dev_err(dev, "FW image size should be multiple of 4\n"); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4715 | return -EINVAL; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | flash_cmd.size = sizeof(struct lancer_cmd_req_write_object) |
| 4719 | + LANCER_FW_DOWNLOAD_CHUNK; |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4720 | flash_cmd.va = dma_alloc_coherent(dev, flash_cmd.size, |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 4721 | &flash_cmd.dma, GFP_KERNEL); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4722 | if (!flash_cmd.va) |
| 4723 | return -ENOMEM; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4724 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4725 | dest_image_ptr = flash_cmd.va + |
| 4726 | sizeof(struct lancer_cmd_req_write_object); |
| 4727 | image_size = fw->size; |
| 4728 | data_ptr = fw->data; |
| 4729 | |
| 4730 | while (image_size) { |
| 4731 | chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK); |
| 4732 | |
| 4733 | /* Copy the image chunk content. */ |
| 4734 | memcpy(dest_image_ptr, data_ptr, chunk_size); |
| 4735 | |
| 4736 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4737 | chunk_size, offset, |
| 4738 | LANCER_FW_DOWNLOAD_LOCATION, |
| 4739 | &data_written, &change_status, |
| 4740 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4741 | if (status) |
| 4742 | break; |
| 4743 | |
| 4744 | offset += data_written; |
| 4745 | data_ptr += data_written; |
| 4746 | image_size -= data_written; |
| 4747 | } |
| 4748 | |
| 4749 | if (!status) { |
| 4750 | /* Commit the FW written */ |
| 4751 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4752 | 0, offset, |
| 4753 | LANCER_FW_DOWNLOAD_LOCATION, |
| 4754 | &data_written, &change_status, |
| 4755 | &add_status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4758 | dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4759 | if (status) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4760 | dev_err(dev, "Firmware load error\n"); |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4761 | return be_cmd_status(status); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4762 | } |
| 4763 | |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4764 | dev_info(dev, "Firmware flashed successfully\n"); |
| 4765 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4766 | if (change_status == LANCER_FW_RESET_NEEDED) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4767 | dev_info(dev, "Resetting adapter to activate new FW\n"); |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4768 | status = lancer_physdev_ctrl(adapter, |
| 4769 | PHYSDEV_CONTROL_FW_RESET_MASK); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4770 | if (status) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4771 | dev_err(dev, "Adapter busy, could not reset FW\n"); |
| 4772 | dev_err(dev, "Reboot server to activate new FW\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4773 | } |
| 4774 | } else if (change_status != LANCER_NO_RESET_NEEDED) { |
Kalesh AP | bb864e0 | 2014-09-02 09:56:51 +0530 | [diff] [blame] | 4775 | dev_info(dev, "Reboot server to activate new FW\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 4776 | } |
Kalesh AP | 3fb8cb8 | 2014-09-02 09:56:52 +0530 | [diff] [blame] | 4777 | |
| 4778 | return 0; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4779 | } |
| 4780 | |
Vasundhara Volam | a6e6ff6 | 2015-05-06 05:30:37 -0400 | [diff] [blame] | 4781 | /* Check if the flash image file is compatible with the adapter that |
| 4782 | * is being flashed. |
| 4783 | */ |
| 4784 | static bool be_check_ufi_compatibility(struct be_adapter *adapter, |
| 4785 | struct flash_file_hdr_g3 *fhdr) |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4786 | { |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4787 | if (!fhdr) { |
| 4788 | dev_err(&adapter->pdev->dev, "Invalid FW UFI file"); |
| 4789 | return -1; |
| 4790 | } |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4791 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4792 | /* First letter of the build version is used to identify |
| 4793 | * which chip this image file is meant for. |
| 4794 | */ |
| 4795 | switch (fhdr->build[0]) { |
| 4796 | case BLD_STR_UFI_TYPE_SH: |
Vasundhara Volam | a6e6ff6 | 2015-05-06 05:30:37 -0400 | [diff] [blame] | 4797 | if (!skyhawk_chip(adapter)) |
| 4798 | return false; |
| 4799 | break; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4800 | case BLD_STR_UFI_TYPE_BE3: |
Vasundhara Volam | a6e6ff6 | 2015-05-06 05:30:37 -0400 | [diff] [blame] | 4801 | if (!BE3_chip(adapter)) |
| 4802 | return false; |
| 4803 | break; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4804 | case BLD_STR_UFI_TYPE_BE2: |
Vasundhara Volam | a6e6ff6 | 2015-05-06 05:30:37 -0400 | [diff] [blame] | 4805 | if (!BE2_chip(adapter)) |
| 4806 | return false; |
| 4807 | break; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4808 | default: |
| 4809 | return false; |
| 4810 | } |
Vasundhara Volam | a6e6ff6 | 2015-05-06 05:30:37 -0400 | [diff] [blame] | 4811 | |
| 4812 | return (fhdr->asic_type_rev >= adapter->asic_rev); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4815 | static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) |
| 4816 | { |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4817 | struct device *dev = &adapter->pdev->dev; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 4818 | struct flash_file_hdr_g3 *fhdr3; |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4819 | struct image_hdr *img_hdr_ptr; |
| 4820 | int status = 0, i, num_imgs; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4821 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4822 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4823 | fhdr3 = (struct flash_file_hdr_g3 *)fw->data; |
| 4824 | if (!be_check_ufi_compatibility(adapter, fhdr3)) { |
| 4825 | dev_err(dev, "Flash image is not compatible with adapter\n"); |
| 4826 | return -EINVAL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4829 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom); |
| 4830 | flash_cmd.va = dma_alloc_coherent(dev, flash_cmd.size, &flash_cmd.dma, |
| 4831 | GFP_KERNEL); |
| 4832 | if (!flash_cmd.va) |
| 4833 | return -ENOMEM; |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4834 | |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4835 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 4836 | for (i = 0; i < num_imgs; i++) { |
| 4837 | img_hdr_ptr = (struct image_hdr *)(fw->data + |
| 4838 | (sizeof(struct flash_file_hdr_g3) + |
| 4839 | i * sizeof(struct image_hdr))); |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4840 | if (!BE2_chip(adapter) && |
| 4841 | le32_to_cpu(img_hdr_ptr->imageid) != 1) |
| 4842 | continue; |
| 4843 | |
| 4844 | if (skyhawk_chip(adapter)) |
| 4845 | status = be_flash_skyhawk(adapter, fw, &flash_cmd, |
| 4846 | num_imgs); |
| 4847 | else |
| 4848 | status = be_flash_BEx(adapter, fw, &flash_cmd, |
| 4849 | num_imgs); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
Vasundhara Volam | 5d3acd0 | 2015-02-06 08:18:37 -0500 | [diff] [blame] | 4852 | dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma); |
| 4853 | if (!status) |
| 4854 | dev_info(dev, "Firmware flashed successfully\n"); |
Padmanabh Ratnakar | 773a2d7 | 2012-10-20 06:04:16 +0000 | [diff] [blame] | 4855 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4856 | return status; |
| 4857 | } |
| 4858 | |
| 4859 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 4860 | { |
| 4861 | const struct firmware *fw; |
| 4862 | int status; |
| 4863 | |
| 4864 | if (!netif_running(adapter->netdev)) { |
| 4865 | dev_err(&adapter->pdev->dev, |
| 4866 | "Firmware load not allowed (interface is down)\n"); |
Kalesh AP | 940a3fc | 2014-07-17 16:20:19 +0530 | [diff] [blame] | 4867 | return -ENETDOWN; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 4871 | if (status) |
| 4872 | goto fw_exit; |
| 4873 | |
| 4874 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 4875 | |
| 4876 | if (lancer_chip(adapter)) |
| 4877 | status = lancer_fw_download(adapter, fw); |
| 4878 | else |
| 4879 | status = be_fw_download(adapter, fw); |
| 4880 | |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4881 | if (!status) |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 4882 | be_cmd_get_fw_ver(adapter); |
Somnath Kotur | eeb65ce | 2013-05-26 21:08:36 +0000 | [diff] [blame] | 4883 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 4884 | fw_exit: |
| 4885 | release_firmware(fw); |
| 4886 | return status; |
| 4887 | } |
| 4888 | |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 4889 | static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, |
| 4890 | u16 flags) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4891 | { |
| 4892 | struct be_adapter *adapter = netdev_priv(dev); |
| 4893 | struct nlattr *attr, *br_spec; |
| 4894 | int rem; |
| 4895 | int status = 0; |
| 4896 | u16 mode = 0; |
| 4897 | |
| 4898 | if (!sriov_enabled(adapter)) |
| 4899 | return -EOPNOTSUPP; |
| 4900 | |
| 4901 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 4902 | if (!br_spec) |
| 4903 | return -EINVAL; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4904 | |
| 4905 | nla_for_each_nested(attr, br_spec, rem) { |
| 4906 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 4907 | continue; |
| 4908 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 4909 | if (nla_len(attr) < sizeof(mode)) |
| 4910 | return -EINVAL; |
| 4911 | |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4912 | mode = nla_get_u16(attr); |
| 4913 | if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) |
| 4914 | return -EINVAL; |
| 4915 | |
| 4916 | status = be_cmd_set_hsw_config(adapter, 0, 0, |
| 4917 | adapter->if_handle, |
| 4918 | mode == BRIDGE_MODE_VEPA ? |
| 4919 | PORT_FWD_TYPE_VEPA : |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4920 | PORT_FWD_TYPE_VEB, 0); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4921 | if (status) |
| 4922 | goto err; |
| 4923 | |
| 4924 | dev_info(&adapter->pdev->dev, "enabled switch mode: %s\n", |
| 4925 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4926 | |
| 4927 | return status; |
| 4928 | } |
| 4929 | err: |
| 4930 | dev_err(&adapter->pdev->dev, "Failed to set switch mode %s\n", |
| 4931 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 4932 | |
| 4933 | return status; |
| 4934 | } |
| 4935 | |
| 4936 | 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] | 4937 | struct net_device *dev, u32 filter_mask, |
| 4938 | int nlflags) |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4939 | { |
| 4940 | struct be_adapter *adapter = netdev_priv(dev); |
| 4941 | int status = 0; |
| 4942 | u8 hsw_mode; |
| 4943 | |
| 4944 | if (!sriov_enabled(adapter)) |
| 4945 | return 0; |
| 4946 | |
| 4947 | /* BE and Lancer chips support VEB mode only */ |
| 4948 | if (BEx_chip(adapter) || lancer_chip(adapter)) { |
| 4949 | hsw_mode = PORT_FWD_TYPE_VEB; |
| 4950 | } else { |
| 4951 | status = be_cmd_get_hsw_config(adapter, NULL, 0, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 4952 | adapter->if_handle, &hsw_mode, |
| 4953 | NULL); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4954 | if (status) |
| 4955 | return 0; |
| 4956 | } |
| 4957 | |
| 4958 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
| 4959 | hsw_mode == PORT_FWD_TYPE_VEPA ? |
Scott Feldman | 2c3c031 | 2014-11-28 14:34:25 +0100 | [diff] [blame] | 4960 | BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 4961 | 0, 0, nlflags); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 4962 | } |
| 4963 | |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 4964 | #ifdef CONFIG_BE2NET_VXLAN |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4965 | /* VxLAN offload Notes: |
| 4966 | * |
| 4967 | * The stack defines tunnel offload flags (hw_enc_features) for IP and doesn't |
| 4968 | * distinguish various types of transports (VxLAN, GRE, NVGRE ..). So, offload |
| 4969 | * is expected to work across all types of IP tunnels once exported. Skyhawk |
| 4970 | * supports offloads for either VxLAN or NVGRE, exclusively. So we export VxLAN |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 4971 | * offloads in hw_enc_features only when a VxLAN port is added. If other (non |
| 4972 | * VxLAN) tunnels are configured while VxLAN offloads are enabled, offloads for |
| 4973 | * those other tunnels are unexported on the fly through ndo_features_check(). |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4974 | * |
| 4975 | * Skyhawk supports VxLAN offloads only for one UDP dport. So, if the stack |
| 4976 | * adds more than one port, disable offloads and don't re-enable them again |
| 4977 | * until after all the tunnels are removed. |
| 4978 | */ |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4979 | static void be_add_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 4980 | __be16 port) |
| 4981 | { |
| 4982 | struct be_adapter *adapter = netdev_priv(netdev); |
| 4983 | struct device *dev = &adapter->pdev->dev; |
| 4984 | int status; |
| 4985 | |
| 4986 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 4987 | return; |
| 4988 | |
| 4989 | if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) { |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4990 | dev_info(dev, |
| 4991 | "Only one UDP port supported for VxLAN offloads\n"); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4992 | dev_info(dev, "Disabling VxLAN offloads\n"); |
| 4993 | adapter->vxlan_port_count++; |
| 4994 | goto err; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 4995 | } |
| 4996 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 4997 | if (adapter->vxlan_port_count++ >= 1) |
| 4998 | return; |
| 4999 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5000 | status = be_cmd_manage_iface(adapter, adapter->if_handle, |
| 5001 | OP_CONVERT_NORMAL_TO_TUNNEL); |
| 5002 | if (status) { |
| 5003 | dev_warn(dev, "Failed to convert normal interface to tunnel\n"); |
| 5004 | goto err; |
| 5005 | } |
| 5006 | |
| 5007 | status = be_cmd_set_vxlan_port(adapter, port); |
| 5008 | if (status) { |
| 5009 | dev_warn(dev, "Failed to add VxLAN port\n"); |
| 5010 | goto err; |
| 5011 | } |
| 5012 | adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS; |
| 5013 | adapter->vxlan_port = port; |
| 5014 | |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5015 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 5016 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 5017 | NETIF_F_GSO_UDP_TUNNEL; |
| 5018 | netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | ac9a3d8 | 2014-12-19 10:00:18 +0530 | [diff] [blame] | 5019 | netdev->features |= NETIF_F_GSO_UDP_TUNNEL; |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5020 | |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5021 | dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n", |
| 5022 | be16_to_cpu(port)); |
| 5023 | return; |
| 5024 | err: |
| 5025 | be_disable_vxlan_offloads(adapter); |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family, |
| 5029 | __be16 port) |
| 5030 | { |
| 5031 | struct be_adapter *adapter = netdev_priv(netdev); |
| 5032 | |
| 5033 | if (lancer_chip(adapter) || BEx_chip(adapter)) |
| 5034 | return; |
| 5035 | |
| 5036 | if (adapter->vxlan_port != port) |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5037 | goto done; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5038 | |
| 5039 | be_disable_vxlan_offloads(adapter); |
| 5040 | |
| 5041 | dev_info(&adapter->pdev->dev, |
| 5042 | "Disabled VxLAN offloads for UDP port %d\n", |
| 5043 | be16_to_cpu(port)); |
Sriharsha Basavapatna | 630f4b7 | 2014-12-11 03:24:47 -0500 | [diff] [blame] | 5044 | done: |
| 5045 | adapter->vxlan_port_count--; |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5046 | } |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5047 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 5048 | static netdev_features_t be_features_check(struct sk_buff *skb, |
| 5049 | struct net_device *dev, |
| 5050 | netdev_features_t features) |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5051 | { |
Sriharsha Basavapatna | 16dde0d | 2015-01-15 16:08:43 +0530 | [diff] [blame] | 5052 | struct be_adapter *adapter = netdev_priv(dev); |
| 5053 | u8 l4_hdr = 0; |
| 5054 | |
| 5055 | /* The code below restricts offload features for some tunneled packets. |
| 5056 | * Offload features for normal (non tunnel) packets are unchanged. |
| 5057 | */ |
| 5058 | if (!skb->encapsulation || |
| 5059 | !(adapter->flags & BE_FLAGS_VXLAN_OFFLOADS)) |
| 5060 | return features; |
| 5061 | |
| 5062 | /* It's an encapsulated packet and VxLAN offloads are enabled. We |
| 5063 | * should disable tunnel offload features if it's not a VxLAN packet, |
| 5064 | * as tunnel offloads have been enabled only for VxLAN. This is done to |
| 5065 | * allow other tunneled traffic like GRE work fine while VxLAN |
| 5066 | * offloads are configured in Skyhawk-R. |
| 5067 | */ |
| 5068 | switch (vlan_get_protocol(skb)) { |
| 5069 | case htons(ETH_P_IP): |
| 5070 | l4_hdr = ip_hdr(skb)->protocol; |
| 5071 | break; |
| 5072 | case htons(ETH_P_IPV6): |
| 5073 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 5074 | break; |
| 5075 | default: |
| 5076 | return features; |
| 5077 | } |
| 5078 | |
| 5079 | if (l4_hdr != IPPROTO_UDP || |
| 5080 | skb->inner_protocol_type != ENCAP_TYPE_ETHER || |
| 5081 | skb->inner_protocol != htons(ETH_P_TEB) || |
| 5082 | skb_inner_mac_header(skb) - skb_transport_header(skb) != |
| 5083 | sizeof(struct udphdr) + sizeof(struct vxlanhdr)) |
| 5084 | return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK); |
| 5085 | |
| 5086 | return features; |
Joe Stringer | 725d548 | 2014-11-13 16:38:13 -0800 | [diff] [blame] | 5087 | } |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 5088 | #endif |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5089 | |
stephen hemminger | e5686ad | 2012-01-05 19:10:25 +0000 | [diff] [blame] | 5090 | static const struct net_device_ops be_netdev_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5091 | .ndo_open = be_open, |
| 5092 | .ndo_stop = be_close, |
| 5093 | .ndo_start_xmit = be_xmit, |
Sathya Perla | a54769f | 2011-10-24 02:45:00 +0000 | [diff] [blame] | 5094 | .ndo_set_rx_mode = be_set_rx_mode, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5095 | .ndo_set_mac_address = be_mac_addr_set, |
| 5096 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 5097 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5098 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5099 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 5100 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 5101 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 5102 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 5103 | .ndo_set_vf_rate = be_set_vf_tx_rate, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 5104 | .ndo_get_vf_config = be_get_vf_config, |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 5105 | .ndo_set_vf_link_state = be_set_vf_link_state, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 5106 | .ndo_set_vf_spoofchk = be_set_vf_spoofchk, |
Ivan Vecera | 6626873 | 2011-12-08 01:31:21 +0000 | [diff] [blame] | 5107 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5108 | .ndo_poll_controller = be_netpoll, |
| 5109 | #endif |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 5110 | .ndo_bridge_setlink = be_ndo_bridge_setlink, |
| 5111 | .ndo_bridge_getlink = be_ndo_bridge_getlink, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5112 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5113 | .ndo_busy_poll = be_busy_poll, |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5114 | #endif |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 5115 | #ifdef CONFIG_BE2NET_VXLAN |
Sathya Perla | c9c4714 | 2014-03-27 10:46:19 +0530 | [diff] [blame] | 5116 | .ndo_add_vxlan_port = be_add_vxlan_port, |
| 5117 | .ndo_del_vxlan_port = be_del_vxlan_port, |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 5118 | .ndo_features_check = be_features_check, |
Sathya Perla | c5abe7c | 2014-04-01 12:33:59 +0530 | [diff] [blame] | 5119 | #endif |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5120 | }; |
| 5121 | |
| 5122 | static void be_netdev_init(struct net_device *netdev) |
| 5123 | { |
| 5124 | struct be_adapter *adapter = netdev_priv(netdev); |
| 5125 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 5126 | 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] | 5127 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 5128 | NETIF_F_HW_VLAN_CTAG_TX; |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 5129 | if (be_multi_rxq(adapter)) |
| 5130 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 5131 | |
| 5132 | netdev->features |= netdev->hw_features | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 5133 | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 5134 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 5135 | 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] | 5136 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 5137 | |
Ajit Khaparde | fbc13f0 | 2012-03-18 06:23:21 +0000 | [diff] [blame] | 5138 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 5139 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5140 | netdev->flags |= IFF_MULTICAST; |
| 5141 | |
Sarveshwar Bandi | b7e5887 | 2012-06-13 19:51:43 +0000 | [diff] [blame] | 5142 | netif_set_gso_max_size(netdev, 65535 - ETH_HLEN); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 5143 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5144 | netdev->netdev_ops = &be_netdev_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5145 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 5146 | netdev->ethtool_ops = &be_ethtool_ops; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5149 | static void be_cleanup(struct be_adapter *adapter) |
| 5150 | { |
| 5151 | struct net_device *netdev = adapter->netdev; |
| 5152 | |
| 5153 | rtnl_lock(); |
| 5154 | netif_device_detach(netdev); |
| 5155 | if (netif_running(netdev)) |
| 5156 | be_close(netdev); |
| 5157 | rtnl_unlock(); |
| 5158 | |
| 5159 | be_clear(adapter); |
| 5160 | } |
| 5161 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5162 | static int be_resume(struct be_adapter *adapter) |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5163 | { |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5164 | struct net_device *netdev = adapter->netdev; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5165 | int status; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5166 | |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5167 | status = be_setup(adapter); |
| 5168 | if (status) |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5169 | return status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5170 | |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5171 | if (netif_running(netdev)) { |
| 5172 | status = be_open(netdev); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5173 | if (status) |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5174 | return status; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5175 | } |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5176 | |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5177 | netif_device_attach(netdev); |
| 5178 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5179 | return 0; |
| 5180 | } |
| 5181 | |
| 5182 | static int be_err_recover(struct be_adapter *adapter) |
| 5183 | { |
| 5184 | struct device *dev = &adapter->pdev->dev; |
| 5185 | int status; |
| 5186 | |
| 5187 | status = be_resume(adapter); |
| 5188 | if (status) |
| 5189 | goto err; |
| 5190 | |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 5191 | dev_info(dev, "Adapter recovery successful\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5192 | return 0; |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5193 | err: |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 5194 | if (be_physfn(adapter)) |
Somnath Kotur | 4bebb56 | 2013-12-05 12:07:55 +0530 | [diff] [blame] | 5195 | dev_err(dev, "Adapter recovery failed\n"); |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 5196 | else |
| 5197 | dev_err(dev, "Re-trying adapter recovery\n"); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5198 | |
| 5199 | return status; |
| 5200 | } |
| 5201 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5202 | static void be_err_detection_task(struct work_struct *work) |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5203 | { |
| 5204 | struct be_adapter *adapter = |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5205 | container_of(work, struct be_adapter, |
| 5206 | be_err_detection_work.work); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 5207 | int status = 0; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5208 | |
| 5209 | be_detect_error(adapter); |
| 5210 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 5211 | if (be_check_error(adapter, BE_ERROR_HW)) { |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5212 | be_cleanup(adapter); |
Kalesh AP | d0e1b31 | 2015-02-23 04:20:12 -0500 | [diff] [blame] | 5213 | |
| 5214 | /* As of now error recovery support is in Lancer only */ |
| 5215 | if (lancer_chip(adapter)) |
| 5216 | status = be_err_recover(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5217 | } |
| 5218 | |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 5219 | /* Always attempt recovery on VFs */ |
| 5220 | if (!status || be_virtfn(adapter)) |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5221 | be_schedule_err_detection(adapter); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5224 | static void be_log_sfp_info(struct be_adapter *adapter) |
| 5225 | { |
| 5226 | int status; |
| 5227 | |
| 5228 | status = be_cmd_query_sfp_info(adapter); |
| 5229 | if (!status) { |
| 5230 | dev_err(&adapter->pdev->dev, |
| 5231 | "Unqualified SFP+ detected on %c from %s part no: %s", |
| 5232 | adapter->port_name, adapter->phy.vendor_name, |
| 5233 | adapter->phy.vendor_pn); |
| 5234 | } |
| 5235 | adapter->flags &= ~BE_FLAGS_EVT_INCOMPATIBLE_SFP; |
| 5236 | } |
| 5237 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5238 | static void be_worker(struct work_struct *work) |
| 5239 | { |
| 5240 | struct be_adapter *adapter = |
| 5241 | container_of(work, struct be_adapter, work.work); |
| 5242 | struct be_rx_obj *rxo; |
| 5243 | int i; |
| 5244 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5245 | /* when interrupts are not yet enabled, just reap any pending |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5246 | * mcc completions |
| 5247 | */ |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5248 | if (!netif_running(adapter->netdev)) { |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5249 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5250 | be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 5251 | local_bh_enable(); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5252 | goto reschedule; |
| 5253 | } |
| 5254 | |
| 5255 | if (!adapter->stats_cmd_sent) { |
| 5256 | if (lancer_chip(adapter)) |
| 5257 | lancer_cmd_get_pport_stats(adapter, |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 5258 | &adapter->stats_cmd); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5259 | else |
| 5260 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 5261 | } |
| 5262 | |
Vasundhara Volam | d696b5e | 2013-08-06 09:27:16 +0530 | [diff] [blame] | 5263 | if (be_physfn(adapter) && |
| 5264 | MODULO(adapter->work_counter, adapter->be_get_temp_freq) == 0) |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 5265 | be_cmd_get_die_temperature(adapter); |
| 5266 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5267 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 6384a4d | 2013-10-25 10:40:16 +0530 | [diff] [blame] | 5268 | /* Replenish RX-queues starved due to memory |
| 5269 | * allocation failures. |
| 5270 | */ |
| 5271 | if (rxo->rx_post_starved) |
Ajit Khaparde | c30d726 | 2014-09-12 17:39:16 +0530 | [diff] [blame] | 5272 | be_post_rx_frags(rxo, GFP_KERNEL, MAX_RX_POST); |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
Padmanabh Ratnakar | 2094777 | 2015-05-06 05:30:33 -0400 | [diff] [blame] | 5275 | /* EQ-delay update for Skyhawk is done while notifying EQ */ |
| 5276 | if (!skyhawk_chip(adapter)) |
| 5277 | be_eqd_update(adapter, false); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 5278 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5279 | if (adapter->flags & BE_FLAGS_EVT_INCOMPATIBLE_SFP) |
| 5280 | be_log_sfp_info(adapter); |
| 5281 | |
Padmanabh Ratnakar | d8110f6 | 2011-11-25 05:48:23 +0000 | [diff] [blame] | 5282 | reschedule: |
| 5283 | adapter->work_counter++; |
| 5284 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 5285 | } |
| 5286 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5287 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 5288 | { |
| 5289 | if (adapter->csr) |
| 5290 | pci_iounmap(adapter->pdev, adapter->csr); |
| 5291 | if (adapter->db) |
| 5292 | pci_iounmap(adapter->pdev, adapter->db); |
| 5293 | } |
| 5294 | |
| 5295 | static int db_bar(struct be_adapter *adapter) |
| 5296 | { |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 5297 | if (lancer_chip(adapter) || be_virtfn(adapter)) |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5298 | return 0; |
| 5299 | else |
| 5300 | return 4; |
| 5301 | } |
| 5302 | |
| 5303 | static int be_roce_map_pci_bars(struct be_adapter *adapter) |
| 5304 | { |
| 5305 | if (skyhawk_chip(adapter)) { |
| 5306 | adapter->roce_db.size = 4096; |
| 5307 | adapter->roce_db.io_addr = pci_resource_start(adapter->pdev, |
| 5308 | db_bar(adapter)); |
| 5309 | adapter->roce_db.total_size = pci_resource_len(adapter->pdev, |
| 5310 | db_bar(adapter)); |
| 5311 | } |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 5316 | { |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5317 | struct pci_dev *pdev = adapter->pdev; |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5318 | u8 __iomem *addr; |
| 5319 | u32 sli_intf; |
| 5320 | |
| 5321 | pci_read_config_dword(adapter->pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 5322 | adapter->sli_family = (sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 5323 | SLI_INTF_FAMILY_SHIFT; |
| 5324 | adapter->virtfn = (sli_intf & SLI_INTF_FT_MASK) ? 1 : 0; |
| 5325 | |
| 5326 | if (BEx_chip(adapter) && be_physfn(adapter)) { |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5327 | adapter->csr = pci_iomap(pdev, 2, 0); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5328 | if (!adapter->csr) |
| 5329 | return -ENOMEM; |
| 5330 | } |
| 5331 | |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5332 | addr = pci_iomap(pdev, db_bar(adapter), 0); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5333 | if (!addr) |
| 5334 | goto pci_map_err; |
| 5335 | adapter->db = addr; |
| 5336 | |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5337 | if (skyhawk_chip(adapter) || BEx_chip(adapter)) { |
| 5338 | if (be_physfn(adapter)) { |
| 5339 | /* PCICFG is the 2nd BAR in BE2 */ |
| 5340 | addr = pci_iomap(pdev, BE2_chip(adapter) ? 1 : 0, 0); |
| 5341 | if (!addr) |
| 5342 | goto pci_map_err; |
| 5343 | adapter->pcicfg = addr; |
| 5344 | } else { |
| 5345 | adapter->pcicfg = adapter->db + SRIOV_VF_PCICFG_OFFSET; |
| 5346 | } |
| 5347 | } |
| 5348 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5349 | be_roce_map_pci_bars(adapter); |
| 5350 | return 0; |
| 5351 | |
| 5352 | pci_map_err: |
David S. Miller | 0fa74a4 | 2015-03-20 18:51:09 -0400 | [diff] [blame] | 5353 | dev_err(&pdev->dev, "Error in mapping PCI BARs\n"); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5354 | be_unmap_pci_bars(adapter); |
| 5355 | return -ENOMEM; |
| 5356 | } |
| 5357 | |
| 5358 | static void be_drv_cleanup(struct be_adapter *adapter) |
| 5359 | { |
| 5360 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
| 5361 | struct device *dev = &adapter->pdev->dev; |
| 5362 | |
| 5363 | if (mem->va) |
| 5364 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5365 | |
| 5366 | mem = &adapter->rx_filter; |
| 5367 | if (mem->va) |
| 5368 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5369 | |
| 5370 | mem = &adapter->stats_cmd; |
| 5371 | if (mem->va) |
| 5372 | dma_free_coherent(dev, mem->size, mem->va, mem->dma); |
| 5373 | } |
| 5374 | |
| 5375 | /* Allocate and initialize various fields in be_adapter struct */ |
| 5376 | static int be_drv_init(struct be_adapter *adapter) |
| 5377 | { |
| 5378 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 5379 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
| 5380 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
| 5381 | struct be_dma_mem *stats_cmd = &adapter->stats_cmd; |
| 5382 | struct device *dev = &adapter->pdev->dev; |
| 5383 | int status = 0; |
| 5384 | |
| 5385 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 5386 | mbox_mem_alloc->va = dma_alloc_coherent(dev, mbox_mem_alloc->size, |
| 5387 | &mbox_mem_alloc->dma, |
| 5388 | GFP_KERNEL); |
| 5389 | if (!mbox_mem_alloc->va) |
| 5390 | return -ENOMEM; |
| 5391 | |
| 5392 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 5393 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 5394 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 5395 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
| 5396 | |
| 5397 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
| 5398 | rx_filter->va = dma_zalloc_coherent(dev, rx_filter->size, |
| 5399 | &rx_filter->dma, GFP_KERNEL); |
| 5400 | if (!rx_filter->va) { |
| 5401 | status = -ENOMEM; |
| 5402 | goto free_mbox; |
| 5403 | } |
| 5404 | |
| 5405 | if (lancer_chip(adapter)) |
| 5406 | stats_cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 5407 | else if (BE2_chip(adapter)) |
| 5408 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
| 5409 | else if (BE3_chip(adapter)) |
| 5410 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
| 5411 | else |
| 5412 | stats_cmd->size = sizeof(struct be_cmd_req_get_stats_v2); |
| 5413 | stats_cmd->va = dma_zalloc_coherent(dev, stats_cmd->size, |
| 5414 | &stats_cmd->dma, GFP_KERNEL); |
| 5415 | if (!stats_cmd->va) { |
| 5416 | status = -ENOMEM; |
| 5417 | goto free_rx_filter; |
| 5418 | } |
| 5419 | |
| 5420 | mutex_init(&adapter->mbox_lock); |
| 5421 | spin_lock_init(&adapter->mcc_lock); |
| 5422 | spin_lock_init(&adapter->mcc_cq_lock); |
| 5423 | init_completion(&adapter->et_cmd_compl); |
| 5424 | |
| 5425 | pci_save_state(adapter->pdev); |
| 5426 | |
| 5427 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5428 | INIT_DELAYED_WORK(&adapter->be_err_detection_work, |
| 5429 | be_err_detection_task); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5430 | |
| 5431 | adapter->rx_fc = true; |
| 5432 | adapter->tx_fc = true; |
| 5433 | |
| 5434 | /* Must be a power of 2 or else MODULO will BUG_ON */ |
| 5435 | adapter->be_get_temp_freq = 64; |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5436 | |
| 5437 | return 0; |
| 5438 | |
| 5439 | free_rx_filter: |
| 5440 | dma_free_coherent(dev, rx_filter->size, rx_filter->va, rx_filter->dma); |
| 5441 | free_mbox: |
| 5442 | dma_free_coherent(dev, mbox_mem_alloc->size, mbox_mem_alloc->va, |
| 5443 | mbox_mem_alloc->dma); |
| 5444 | return status; |
| 5445 | } |
| 5446 | |
| 5447 | static void be_remove(struct pci_dev *pdev) |
| 5448 | { |
| 5449 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5450 | |
| 5451 | if (!adapter) |
| 5452 | return; |
| 5453 | |
| 5454 | be_roce_dev_remove(adapter); |
| 5455 | be_intr_set(adapter, false); |
| 5456 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5457 | be_cancel_err_detection(adapter); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5458 | |
| 5459 | unregister_netdev(adapter->netdev); |
| 5460 | |
| 5461 | be_clear(adapter); |
| 5462 | |
| 5463 | /* tell fw we're done with firing cmds */ |
| 5464 | be_cmd_fw_clean(adapter); |
| 5465 | |
| 5466 | be_unmap_pci_bars(adapter); |
| 5467 | be_drv_cleanup(adapter); |
| 5468 | |
| 5469 | pci_disable_pcie_error_reporting(pdev); |
| 5470 | |
| 5471 | pci_release_regions(pdev); |
| 5472 | pci_disable_device(pdev); |
| 5473 | |
| 5474 | free_netdev(adapter->netdev); |
| 5475 | } |
| 5476 | |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 5477 | ssize_t be_hwmon_show_temp(struct device *dev, |
| 5478 | struct device_attribute *dev_attr, |
| 5479 | char *buf) |
| 5480 | { |
| 5481 | struct be_adapter *adapter = dev_get_drvdata(dev); |
| 5482 | |
| 5483 | /* Unit: millidegree Celsius */ |
| 5484 | if (adapter->hwmon_info.be_on_die_temp == BE_INVALID_DIE_TEMP) |
| 5485 | return -EIO; |
| 5486 | else |
| 5487 | return sprintf(buf, "%u\n", |
| 5488 | adapter->hwmon_info.be_on_die_temp * 1000); |
| 5489 | } |
| 5490 | |
| 5491 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
| 5492 | be_hwmon_show_temp, NULL, 1); |
| 5493 | |
| 5494 | static struct attribute *be_hwmon_attrs[] = { |
| 5495 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 5496 | NULL |
| 5497 | }; |
| 5498 | |
| 5499 | ATTRIBUTE_GROUPS(be_hwmon); |
| 5500 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5501 | static char *mc_name(struct be_adapter *adapter) |
| 5502 | { |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 5503 | char *str = ""; /* default */ |
| 5504 | |
| 5505 | switch (adapter->mc_type) { |
| 5506 | case UMC: |
| 5507 | str = "UMC"; |
| 5508 | break; |
| 5509 | case FLEX10: |
| 5510 | str = "FLEX10"; |
| 5511 | break; |
| 5512 | case vNIC1: |
| 5513 | str = "vNIC-1"; |
| 5514 | break; |
| 5515 | case nPAR: |
| 5516 | str = "nPAR"; |
| 5517 | break; |
| 5518 | case UFP: |
| 5519 | str = "UFP"; |
| 5520 | break; |
| 5521 | case vNIC2: |
| 5522 | str = "vNIC-2"; |
| 5523 | break; |
| 5524 | default: |
| 5525 | str = ""; |
| 5526 | } |
| 5527 | |
| 5528 | return str; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | static inline char *func_name(struct be_adapter *adapter) |
| 5532 | { |
| 5533 | return be_physfn(adapter) ? "PF" : "VF"; |
| 5534 | } |
| 5535 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 5536 | static inline char *nic_name(struct pci_dev *pdev) |
| 5537 | { |
| 5538 | switch (pdev->device) { |
| 5539 | case OC_DEVICE_ID1: |
| 5540 | return OC_NAME; |
| 5541 | case OC_DEVICE_ID2: |
| 5542 | return OC_NAME_BE; |
| 5543 | case OC_DEVICE_ID3: |
| 5544 | case OC_DEVICE_ID4: |
| 5545 | return OC_NAME_LANCER; |
| 5546 | case BE_DEVICE_ID2: |
| 5547 | return BE3_NAME; |
| 5548 | case OC_DEVICE_ID5: |
| 5549 | case OC_DEVICE_ID6: |
| 5550 | return OC_NAME_SH; |
| 5551 | default: |
| 5552 | return BE_NAME; |
| 5553 | } |
| 5554 | } |
| 5555 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 5556 | 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] | 5557 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5558 | struct be_adapter *adapter; |
| 5559 | struct net_device *netdev; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 5560 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5561 | |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 5562 | dev_info(&pdev->dev, "%s version is %s\n", DRV_NAME, DRV_VER); |
| 5563 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5564 | status = pci_enable_device(pdev); |
| 5565 | if (status) |
| 5566 | goto do_none; |
| 5567 | |
| 5568 | status = pci_request_regions(pdev, DRV_NAME); |
| 5569 | if (status) |
| 5570 | goto disable_dev; |
| 5571 | pci_set_master(pdev); |
| 5572 | |
Sathya Perla | 7f64006 | 2012-06-05 19:37:20 +0000 | [diff] [blame] | 5573 | netdev = alloc_etherdev_mqs(sizeof(*adapter), MAX_TX_QS, MAX_RX_QS); |
Kalesh AP | ddf1169 | 2014-07-17 16:20:28 +0530 | [diff] [blame] | 5574 | if (!netdev) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5575 | status = -ENOMEM; |
| 5576 | goto rel_reg; |
| 5577 | } |
| 5578 | adapter = netdev_priv(netdev); |
| 5579 | adapter->pdev = pdev; |
| 5580 | pci_set_drvdata(pdev, adapter); |
| 5581 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5582 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5583 | |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5584 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5585 | if (!status) { |
| 5586 | netdev->features |= NETIF_F_HIGHDMA; |
| 5587 | } else { |
Russell King | 4c15c24 | 2013-06-26 23:49:11 +0100 | [diff] [blame] | 5588 | status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5589 | if (status) { |
| 5590 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 5591 | goto free_netdev; |
| 5592 | } |
| 5593 | } |
| 5594 | |
Kalesh AP | 2f951a9 | 2014-09-12 17:39:21 +0530 | [diff] [blame] | 5595 | status = pci_enable_pcie_error_reporting(pdev); |
| 5596 | if (!status) |
| 5597 | dev_info(&pdev->dev, "PCIe error reporting enabled\n"); |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 5598 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5599 | status = be_map_pci_bars(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5600 | if (status) |
Sathya Perla | 39f1d94 | 2012-05-08 19:41:24 +0000 | [diff] [blame] | 5601 | goto free_netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5602 | |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5603 | status = be_drv_init(adapter); |
| 5604 | if (status) |
| 5605 | goto unmap_bars; |
| 5606 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5607 | status = be_setup(adapter); |
| 5608 | if (status) |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5609 | goto drv_cleanup; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5610 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 5611 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5612 | status = register_netdev(netdev); |
| 5613 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5614 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5615 | |
Parav Pandit | 045508a | 2012-03-26 14:27:13 +0000 | [diff] [blame] | 5616 | be_roce_dev_add(adapter); |
| 5617 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5618 | be_schedule_err_detection(adapter); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 5619 | |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 5620 | /* On Die temperature not supported for VF. */ |
| 5621 | if (be_physfn(adapter)) { |
| 5622 | adapter->hwmon_info.hwmon_dev = |
| 5623 | devm_hwmon_device_register_with_groups(&pdev->dev, |
| 5624 | DRV_NAME, |
| 5625 | adapter, |
| 5626 | be_hwmon_groups); |
| 5627 | adapter->hwmon_info.be_on_die_temp = BE_INVALID_DIE_TEMP; |
| 5628 | } |
| 5629 | |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 5630 | 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] | 5631 | func_name(adapter), mc_name(adapter), adapter->port_name); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 5632 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5633 | return 0; |
| 5634 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 5635 | unsetup: |
| 5636 | be_clear(adapter); |
Sathya Perla | 78fad34e | 2015-02-23 04:20:08 -0500 | [diff] [blame] | 5637 | drv_cleanup: |
| 5638 | be_drv_cleanup(adapter); |
| 5639 | unmap_bars: |
| 5640 | be_unmap_pci_bars(adapter); |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 5641 | free_netdev: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 5642 | free_netdev(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5643 | rel_reg: |
| 5644 | pci_release_regions(pdev); |
| 5645 | disable_dev: |
| 5646 | pci_disable_device(pdev); |
| 5647 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 5648 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5649 | return status; |
| 5650 | } |
| 5651 | |
| 5652 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5653 | { |
| 5654 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5655 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 5656 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 5657 | be_setup_wol(adapter, true); |
| 5658 | |
Ajit Khaparde | d4360d6 | 2013-11-22 12:51:09 -0600 | [diff] [blame] | 5659 | be_intr_set(adapter, false); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5660 | be_cancel_err_detection(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5661 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5662 | be_cleanup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5663 | |
| 5664 | pci_save_state(pdev); |
| 5665 | pci_disable_device(pdev); |
| 5666 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5667 | return 0; |
| 5668 | } |
| 5669 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5670 | static int be_pci_resume(struct pci_dev *pdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5671 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5672 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5673 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5674 | |
| 5675 | status = pci_enable_device(pdev); |
| 5676 | if (status) |
| 5677 | return status; |
| 5678 | |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 5679 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5680 | pci_restore_state(pdev); |
| 5681 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5682 | status = be_resume(adapter); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 5683 | if (status) |
| 5684 | return status; |
| 5685 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5686 | be_schedule_err_detection(adapter); |
| 5687 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 5688 | if (adapter->wol_en) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 5689 | be_setup_wol(adapter, false); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 5690 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5691 | return 0; |
| 5692 | } |
| 5693 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5694 | /* |
| 5695 | * An FLR will stop BE from DMAing any data. |
| 5696 | */ |
| 5697 | static void be_shutdown(struct pci_dev *pdev) |
| 5698 | { |
| 5699 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5700 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 5701 | if (!adapter) |
| 5702 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5703 | |
Devesh Sharma | d114f99 | 2014-06-10 19:32:15 +0530 | [diff] [blame] | 5704 | be_roce_dev_shutdown(adapter); |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 5705 | cancel_delayed_work_sync(&adapter->work); |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5706 | be_cancel_err_detection(adapter); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 5707 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 5708 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5709 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 5710 | be_cmd_reset_function(adapter); |
| 5711 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5712 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5715 | 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] | 5716 | pci_channel_state_t state) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5717 | { |
| 5718 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5719 | |
| 5720 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 5721 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 5722 | if (!be_check_error(adapter, BE_ERROR_EEH)) { |
| 5723 | be_set_error(adapter, BE_ERROR_EEH); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5724 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5725 | be_cancel_err_detection(adapter); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 5726 | |
Kalesh AP | 87ac1a5 | 2015-02-23 04:20:15 -0500 | [diff] [blame] | 5727 | be_cleanup(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5728 | } |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5729 | |
| 5730 | if (state == pci_channel_io_perm_failure) |
| 5731 | return PCI_ERS_RESULT_DISCONNECT; |
| 5732 | |
| 5733 | pci_disable_device(pdev); |
| 5734 | |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 5735 | /* The error could cause the FW to trigger a flash debug dump. |
| 5736 | * Resetting the card while flash dump is in progress |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 5737 | * can cause it not to recover; wait for it to finish. |
| 5738 | * Wait only for first function as it is needed only once per |
| 5739 | * adapter. |
Somnath Kotur | eeb7fc7 | 2012-05-02 03:41:01 +0000 | [diff] [blame] | 5740 | */ |
Padmanabh Ratnakar | c8a5416 | 2012-10-20 06:03:37 +0000 | [diff] [blame] | 5741 | if (pdev->devfn == 0) |
| 5742 | ssleep(30); |
| 5743 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5744 | return PCI_ERS_RESULT_NEED_RESET; |
| 5745 | } |
| 5746 | |
| 5747 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 5748 | { |
| 5749 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5750 | int status; |
| 5751 | |
| 5752 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5753 | |
| 5754 | status = pci_enable_device(pdev); |
| 5755 | if (status) |
| 5756 | return PCI_ERS_RESULT_DISCONNECT; |
| 5757 | |
| 5758 | pci_set_master(pdev); |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 5759 | pci_set_power_state(pdev, PCI_D0); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5760 | pci_restore_state(pdev); |
| 5761 | |
| 5762 | /* Check if card is ok and fw is ready */ |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 5763 | dev_info(&adapter->pdev->dev, |
| 5764 | "Waiting for FW to be ready after EEH reset\n"); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 5765 | status = be_fw_wait_ready(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5766 | if (status) |
| 5767 | return PCI_ERS_RESULT_DISCONNECT; |
| 5768 | |
Sathya Perla | d6b6d98 | 2012-09-05 01:56:48 +0000 | [diff] [blame] | 5769 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame^] | 5770 | be_clear_error(adapter, BE_CLEAR_ALL); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5771 | return PCI_ERS_RESULT_RECOVERED; |
| 5772 | } |
| 5773 | |
| 5774 | static void be_eeh_resume(struct pci_dev *pdev) |
| 5775 | { |
| 5776 | int status = 0; |
| 5777 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5778 | |
| 5779 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 5780 | |
| 5781 | pci_save_state(pdev); |
| 5782 | |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5783 | status = be_resume(adapter); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 5784 | if (status) |
| 5785 | goto err; |
| 5786 | |
Sathya Perla | eb7dd46 | 2015-02-23 04:20:11 -0500 | [diff] [blame] | 5787 | be_schedule_err_detection(adapter); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5788 | return; |
| 5789 | err: |
| 5790 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5791 | } |
| 5792 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 5793 | static int be_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) |
| 5794 | { |
| 5795 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 5796 | u16 num_vf_qs; |
| 5797 | int status; |
| 5798 | |
| 5799 | if (!num_vfs) |
| 5800 | be_vf_clear(adapter); |
| 5801 | |
| 5802 | adapter->num_vfs = num_vfs; |
| 5803 | |
| 5804 | if (adapter->num_vfs == 0 && pci_vfs_assigned(pdev)) { |
| 5805 | dev_warn(&pdev->dev, |
| 5806 | "Cannot disable VFs while they are assigned\n"); |
| 5807 | return -EBUSY; |
| 5808 | } |
| 5809 | |
| 5810 | /* When the HW is in SRIOV capable configuration, the PF-pool resources |
| 5811 | * are equally distributed across the max-number of VFs. The user may |
| 5812 | * request only a subset of the max-vfs to be enabled. |
| 5813 | * Based on num_vfs, redistribute the resources across num_vfs so that |
| 5814 | * each VF will have access to more number of resources. |
| 5815 | * This facility is not available in BE3 FW. |
| 5816 | * Also, this is done by FW in Lancer chip. |
| 5817 | */ |
| 5818 | if (skyhawk_chip(adapter) && !pci_num_vf(pdev)) { |
| 5819 | num_vf_qs = be_calculate_vf_qs(adapter, adapter->num_vfs); |
| 5820 | status = be_cmd_set_sriov_config(adapter, adapter->pool_res, |
| 5821 | adapter->num_vfs, num_vf_qs); |
| 5822 | if (status) |
| 5823 | dev_err(&pdev->dev, |
| 5824 | "Failed to optimize SR-IOV resources\n"); |
| 5825 | } |
| 5826 | |
| 5827 | status = be_get_resources(adapter); |
| 5828 | if (status) |
| 5829 | return be_cmd_status(status); |
| 5830 | |
| 5831 | /* Updating real_num_tx/rx_queues() requires rtnl_lock() */ |
| 5832 | rtnl_lock(); |
| 5833 | status = be_update_queues(adapter); |
| 5834 | rtnl_unlock(); |
| 5835 | if (status) |
| 5836 | return be_cmd_status(status); |
| 5837 | |
| 5838 | if (adapter->num_vfs) |
| 5839 | status = be_vf_setup(adapter); |
| 5840 | |
| 5841 | if (!status) |
| 5842 | return adapter->num_vfs; |
| 5843 | |
| 5844 | return 0; |
| 5845 | } |
| 5846 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 5847 | static const struct pci_error_handlers be_eeh_handlers = { |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5848 | .error_detected = be_eeh_err_detected, |
| 5849 | .slot_reset = be_eeh_reset, |
| 5850 | .resume = be_eeh_resume, |
| 5851 | }; |
| 5852 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5853 | static struct pci_driver be_driver = { |
| 5854 | .name = DRV_NAME, |
| 5855 | .id_table = be_dev_ids, |
| 5856 | .probe = be_probe, |
| 5857 | .remove = be_remove, |
| 5858 | .suspend = be_suspend, |
Kalesh AP | 484d76f | 2015-02-23 04:20:14 -0500 | [diff] [blame] | 5859 | .resume = be_pci_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 5860 | .shutdown = be_shutdown, |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 5861 | .sriov_configure = be_pci_sriov_configure, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 5862 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5863 | }; |
| 5864 | |
| 5865 | static int __init be_init_module(void) |
| 5866 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5867 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 5868 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5869 | printk(KERN_WARNING DRV_NAME |
| 5870 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 5871 | " Using 2048\n"); |
| 5872 | rx_frag_size = 2048; |
| 5873 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5874 | |
Vasundhara Volam | ace40af | 2015-03-04 00:44:34 -0500 | [diff] [blame] | 5875 | if (num_vfs > 0) { |
| 5876 | pr_info(DRV_NAME " : Module param num_vfs is obsolete."); |
| 5877 | pr_info(DRV_NAME " : Use sysfs method to enable VFs\n"); |
| 5878 | } |
| 5879 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 5880 | return pci_register_driver(&be_driver); |
| 5881 | } |
| 5882 | module_init(be_init_module); |
| 5883 | |
| 5884 | static void __exit be_exit_module(void) |
| 5885 | { |
| 5886 | pci_unregister_driver(&be_driver); |
| 5887 | } |
| 5888 | module_exit(be_exit_module); |