Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1 | /* |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 2 | * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved. |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you may redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 16 | * SOFTWARE. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 27 | #include <linux/workqueue.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/netdevice.h> |
| 30 | #include <linux/etherdevice.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 31 | #include <linux/if.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 32 | #include <linux/if_ether.h> |
| 33 | #include <linux/if_vlan.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 34 | #include <linux/in.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/ipv6.h> |
| 37 | #include <linux/tcp.h> |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 38 | #include <linux/rtnetlink.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 39 | #include <linux/prefetch.h> |
Kamalesh Babulal | b7c6bfb | 2008-10-13 18:41:01 -0700 | [diff] [blame] | 40 | #include <net/ip6_checksum.h> |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 41 | #include <linux/ktime.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 42 | |
| 43 | #include "cq_enet_desc.h" |
| 44 | #include "vnic_dev.h" |
| 45 | #include "vnic_intr.h" |
| 46 | #include "vnic_stats.h" |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 47 | #include "vnic_vic.h" |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 48 | #include "enic_res.h" |
| 49 | #include "enic.h" |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 50 | #include "enic_dev.h" |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 51 | #include "enic_pp.h" |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 52 | |
| 53 | #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ) |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 54 | #define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS) |
| 55 | #define MAX_TSO (1 << 16) |
| 56 | #define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1) |
| 57 | |
| 58 | #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */ |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 59 | #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */ |
Roopa Prabhu | 3a4adef | 2012-01-18 04:23:55 +0000 | [diff] [blame] | 60 | #define PCI_DEVICE_ID_CISCO_VIC_ENET_VF 0x0071 /* enet SRIOV VF */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 61 | |
| 62 | /* Supported devices */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 63 | static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = { |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 64 | { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) }, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 65 | { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) }, |
Roopa Prabhu | 3a4adef | 2012-01-18 04:23:55 +0000 | [diff] [blame] | 66 | { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_VF) }, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 67 | { 0, } /* end of table */ |
| 68 | }; |
| 69 | |
| 70 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 71 | MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>"); |
| 72 | MODULE_LICENSE("GPL"); |
| 73 | MODULE_VERSION(DRV_VERSION); |
| 74 | MODULE_DEVICE_TABLE(pci, enic_id_table); |
| 75 | |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 76 | #define ENIC_LARGE_PKT_THRESHOLD 1000 |
| 77 | #define ENIC_MAX_COALESCE_TIMERS 10 |
| 78 | /* Interrupt moderation table, which will be used to decide the |
| 79 | * coalescing timer values |
| 80 | * {rx_rate in Mbps, mapping percentage of the range} |
| 81 | */ |
| 82 | struct enic_intr_mod_table mod_table[ENIC_MAX_COALESCE_TIMERS + 1] = { |
| 83 | {4000, 0}, |
| 84 | {4400, 10}, |
| 85 | {5060, 20}, |
| 86 | {5230, 30}, |
| 87 | {5540, 40}, |
| 88 | {5820, 50}, |
| 89 | {6120, 60}, |
| 90 | {6435, 70}, |
| 91 | {6745, 80}, |
| 92 | {7000, 90}, |
| 93 | {0xFFFFFFFF, 100} |
| 94 | }; |
| 95 | |
| 96 | /* This table helps the driver to pick different ranges for rx coalescing |
| 97 | * timer depending on the link speed. |
| 98 | */ |
| 99 | struct enic_intr_mod_range mod_range[ENIC_MAX_LINK_SPEEDS] = { |
| 100 | {0, 0}, /* 0 - 4 Gbps */ |
| 101 | {0, 3}, /* 4 - 10 Gbps */ |
| 102 | {3, 6}, /* 10 - 40 Gbps */ |
| 103 | }; |
| 104 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 105 | int enic_is_dynamic(struct enic *enic) |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 106 | { |
| 107 | return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN; |
| 108 | } |
| 109 | |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 110 | int enic_sriov_enabled(struct enic *enic) |
| 111 | { |
| 112 | return (enic->priv_flags & ENIC_SRIOV_ENABLED) ? 1 : 0; |
| 113 | } |
| 114 | |
Roopa Prabhu | 3a4adef | 2012-01-18 04:23:55 +0000 | [diff] [blame] | 115 | static int enic_is_sriov_vf(struct enic *enic) |
| 116 | { |
| 117 | return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_VF; |
| 118 | } |
| 119 | |
Roopa Prabhu | 889d13f | 2011-09-22 03:44:38 +0000 | [diff] [blame] | 120 | int enic_is_valid_vf(struct enic *enic, int vf) |
| 121 | { |
| 122 | #ifdef CONFIG_PCI_IOV |
| 123 | return vf >= 0 && vf < enic->num_vfs; |
| 124 | #else |
| 125 | return 0; |
| 126 | #endif |
| 127 | } |
| 128 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 129 | static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) |
| 130 | { |
| 131 | struct enic *enic = vnic_dev_priv(wq->vdev); |
| 132 | |
| 133 | if (buf->sop) |
| 134 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 135 | buf->len, PCI_DMA_TODEVICE); |
| 136 | else |
| 137 | pci_unmap_page(enic->pdev, buf->dma_addr, |
| 138 | buf->len, PCI_DMA_TODEVICE); |
| 139 | |
| 140 | if (buf->os_buf) |
| 141 | dev_kfree_skb_any(buf->os_buf); |
| 142 | } |
| 143 | |
| 144 | static void enic_wq_free_buf(struct vnic_wq *wq, |
| 145 | struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque) |
| 146 | { |
| 147 | enic_free_wq_buf(wq, buf); |
| 148 | } |
| 149 | |
| 150 | static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, |
| 151 | u8 type, u16 q_number, u16 completed_index, void *opaque) |
| 152 | { |
| 153 | struct enic *enic = vnic_dev_priv(vdev); |
| 154 | |
| 155 | spin_lock(&enic->wq_lock[q_number]); |
| 156 | |
| 157 | vnic_wq_service(&enic->wq[q_number], cq_desc, |
| 158 | completed_index, enic_wq_free_buf, |
| 159 | opaque); |
| 160 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 161 | if (netif_tx_queue_stopped(netdev_get_tx_queue(enic->netdev, q_number)) && |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 162 | vnic_wq_desc_avail(&enic->wq[q_number]) >= |
| 163 | (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)) |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 164 | netif_wake_subqueue(enic->netdev, q_number); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 165 | |
| 166 | spin_unlock(&enic->wq_lock[q_number]); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static void enic_log_q_error(struct enic *enic) |
| 172 | { |
| 173 | unsigned int i; |
| 174 | u32 error_status; |
| 175 | |
| 176 | for (i = 0; i < enic->wq_count; i++) { |
| 177 | error_status = vnic_wq_error_status(&enic->wq[i]); |
| 178 | if (error_status) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 179 | netdev_err(enic->netdev, "WQ[%d] error_status %d\n", |
| 180 | i, error_status); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | for (i = 0; i < enic->rq_count; i++) { |
| 184 | error_status = vnic_rq_error_status(&enic->rq[i]); |
| 185 | if (error_status) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 186 | netdev_err(enic->netdev, "RQ[%d] error_status %d\n", |
| 187 | i, error_status); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 191 | static void enic_msglvl_check(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 192 | { |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 193 | u32 msg_enable = vnic_dev_msg_lvl(enic->vdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 194 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 195 | if (msg_enable != enic->msg_enable) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 196 | netdev_info(enic->netdev, "msg lvl changed from 0x%x to 0x%x\n", |
| 197 | enic->msg_enable, msg_enable); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 198 | enic->msg_enable = msg_enable; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
| 202 | static void enic_mtu_check(struct enic *enic) |
| 203 | { |
| 204 | u32 mtu = vnic_dev_mtu(enic->vdev); |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 205 | struct net_device *netdev = enic->netdev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 206 | |
Scott Feldman | 491598a | 2009-09-03 17:02:40 +0000 | [diff] [blame] | 207 | if (mtu && mtu != enic->port_mtu) { |
Scott Feldman | 7c84459 | 2009-12-23 13:27:54 +0000 | [diff] [blame] | 208 | enic->port_mtu = mtu; |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 209 | if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) { |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 210 | mtu = max_t(int, ENIC_MIN_MTU, |
| 211 | min_t(int, ENIC_MAX_MTU, mtu)); |
| 212 | if (mtu != netdev->mtu) |
| 213 | schedule_work(&enic->change_mtu_work); |
| 214 | } else { |
| 215 | if (mtu < netdev->mtu) |
| 216 | netdev_warn(netdev, |
| 217 | "interface MTU (%d) set higher " |
| 218 | "than switch port MTU (%d)\n", |
| 219 | netdev->mtu, mtu); |
| 220 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 224 | static void enic_link_check(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 225 | { |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 226 | int link_status = vnic_dev_link_status(enic->vdev); |
| 227 | int carrier_ok = netif_carrier_ok(enic->netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 228 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 229 | if (link_status && !carrier_ok) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 230 | netdev_info(enic->netdev, "Link UP\n"); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 231 | netif_carrier_on(enic->netdev); |
| 232 | } else if (!link_status && carrier_ok) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 233 | netdev_info(enic->netdev, "Link DOWN\n"); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 234 | netif_carrier_off(enic->netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
| 238 | static void enic_notify_check(struct enic *enic) |
| 239 | { |
| 240 | enic_msglvl_check(enic); |
| 241 | enic_mtu_check(enic); |
| 242 | enic_link_check(enic); |
| 243 | } |
| 244 | |
| 245 | #define ENIC_TEST_INTR(pba, i) (pba & (1 << i)) |
| 246 | |
| 247 | static irqreturn_t enic_isr_legacy(int irq, void *data) |
| 248 | { |
| 249 | struct net_device *netdev = data; |
| 250 | struct enic *enic = netdev_priv(netdev); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 251 | unsigned int io_intr = enic_legacy_io_intr(); |
| 252 | unsigned int err_intr = enic_legacy_err_intr(); |
| 253 | unsigned int notify_intr = enic_legacy_notify_intr(); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 254 | u32 pba; |
| 255 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 256 | vnic_intr_mask(&enic->intr[io_intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 257 | |
| 258 | pba = vnic_intr_legacy_pba(enic->legacy_pba); |
| 259 | if (!pba) { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 260 | vnic_intr_unmask(&enic->intr[io_intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 261 | return IRQ_NONE; /* not our interrupt */ |
| 262 | } |
| 263 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 264 | if (ENIC_TEST_INTR(pba, notify_intr)) { |
| 265 | vnic_intr_return_all_credits(&enic->intr[notify_intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 266 | enic_notify_check(enic); |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 267 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 268 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 269 | if (ENIC_TEST_INTR(pba, err_intr)) { |
| 270 | vnic_intr_return_all_credits(&enic->intr[err_intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 271 | enic_log_q_error(enic); |
| 272 | /* schedule recovery from WQ/RQ error */ |
| 273 | schedule_work(&enic->reset); |
| 274 | return IRQ_HANDLED; |
| 275 | } |
| 276 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 277 | if (ENIC_TEST_INTR(pba, io_intr)) { |
| 278 | if (napi_schedule_prep(&enic->napi[0])) |
| 279 | __napi_schedule(&enic->napi[0]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 280 | } else { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 281 | vnic_intr_unmask(&enic->intr[io_intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | return IRQ_HANDLED; |
| 285 | } |
| 286 | |
| 287 | static irqreturn_t enic_isr_msi(int irq, void *data) |
| 288 | { |
| 289 | struct enic *enic = data; |
| 290 | |
| 291 | /* With MSI, there is no sharing of interrupts, so this is |
| 292 | * our interrupt and there is no need to ack it. The device |
| 293 | * is not providing per-vector masking, so the OS will not |
| 294 | * write to PCI config space to mask/unmask the interrupt. |
| 295 | * We're using mask_on_assertion for MSI, so the device |
| 296 | * automatically masks the interrupt when the interrupt is |
| 297 | * generated. Later, when exiting polling, the interrupt |
| 298 | * will be unmasked (see enic_poll). |
| 299 | * |
| 300 | * Also, the device uses the same PCIe Traffic Class (TC) |
| 301 | * for Memory Write data and MSI, so there are no ordering |
| 302 | * issues; the MSI will always arrive at the Root Complex |
| 303 | * _after_ corresponding Memory Writes (i.e. descriptor |
| 304 | * writes). |
| 305 | */ |
| 306 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 307 | napi_schedule(&enic->napi[0]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 308 | |
| 309 | return IRQ_HANDLED; |
| 310 | } |
| 311 | |
| 312 | static irqreturn_t enic_isr_msix_rq(int irq, void *data) |
| 313 | { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 314 | struct napi_struct *napi = data; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 315 | |
| 316 | /* schedule NAPI polling for RQ cleanup */ |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 317 | napi_schedule(napi); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 318 | |
| 319 | return IRQ_HANDLED; |
| 320 | } |
| 321 | |
| 322 | static irqreturn_t enic_isr_msix_wq(int irq, void *data) |
| 323 | { |
| 324 | struct enic *enic = data; |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 325 | unsigned int cq; |
| 326 | unsigned int intr; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 327 | unsigned int wq_work_to_do = -1; /* no limit */ |
| 328 | unsigned int wq_work_done; |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 329 | unsigned int wq_irq; |
| 330 | |
| 331 | wq_irq = (u32)irq - enic->msix_entry[enic_msix_wq_intr(enic, 0)].vector; |
| 332 | cq = enic_cq_wq(enic, wq_irq); |
| 333 | intr = enic_msix_wq_intr(enic, wq_irq); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 334 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 335 | wq_work_done = vnic_cq_service(&enic->cq[cq], |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 336 | wq_work_to_do, enic_wq_service, NULL); |
| 337 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 338 | vnic_intr_return_credits(&enic->intr[intr], |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 339 | wq_work_done, |
| 340 | 1 /* unmask intr */, |
| 341 | 1 /* reset intr timer */); |
| 342 | |
| 343 | return IRQ_HANDLED; |
| 344 | } |
| 345 | |
| 346 | static irqreturn_t enic_isr_msix_err(int irq, void *data) |
| 347 | { |
| 348 | struct enic *enic = data; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 349 | unsigned int intr = enic_msix_err_intr(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 350 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 351 | vnic_intr_return_all_credits(&enic->intr[intr]); |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 352 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 353 | enic_log_q_error(enic); |
| 354 | |
| 355 | /* schedule recovery from WQ/RQ error */ |
| 356 | schedule_work(&enic->reset); |
| 357 | |
| 358 | return IRQ_HANDLED; |
| 359 | } |
| 360 | |
| 361 | static irqreturn_t enic_isr_msix_notify(int irq, void *data) |
| 362 | { |
| 363 | struct enic *enic = data; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 364 | unsigned int intr = enic_msix_notify_intr(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 365 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 366 | vnic_intr_return_all_credits(&enic->intr[intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 367 | enic_notify_check(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 368 | |
| 369 | return IRQ_HANDLED; |
| 370 | } |
| 371 | |
| 372 | static inline void enic_queue_wq_skb_cont(struct enic *enic, |
| 373 | struct vnic_wq *wq, struct sk_buff *skb, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 374 | unsigned int len_left, int loopback) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 375 | { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 376 | const skb_frag_t *frag; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 377 | |
| 378 | /* Queue additional data fragments */ |
| 379 | for (frag = skb_shinfo(skb)->frags; len_left; frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 380 | len_left -= skb_frag_size(frag); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 381 | enic_queue_wq_desc_cont(wq, skb, |
Ian Campbell | 4bf5adb | 2011-08-29 23:18:27 +0000 | [diff] [blame] | 382 | skb_frag_dma_map(&enic->pdev->dev, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 383 | frag, 0, skb_frag_size(frag), |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 384 | DMA_TO_DEVICE), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 385 | skb_frag_size(frag), |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 386 | (len_left == 0), /* EOP? */ |
| 387 | loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
| 391 | static inline void enic_queue_wq_skb_vlan(struct enic *enic, |
| 392 | struct vnic_wq *wq, struct sk_buff *skb, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 393 | int vlan_tag_insert, unsigned int vlan_tag, int loopback) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 394 | { |
| 395 | unsigned int head_len = skb_headlen(skb); |
| 396 | unsigned int len_left = skb->len - head_len; |
| 397 | int eop = (len_left == 0); |
| 398 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 399 | /* Queue the main skb fragment. The fragments are no larger |
| 400 | * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less |
| 401 | * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor |
| 402 | * per fragment is queued. |
| 403 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 404 | enic_queue_wq_desc(wq, skb, |
| 405 | pci_map_single(enic->pdev, skb->data, |
| 406 | head_len, PCI_DMA_TODEVICE), |
| 407 | head_len, |
| 408 | vlan_tag_insert, vlan_tag, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 409 | eop, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 410 | |
| 411 | if (!eop) |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 412 | enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static inline void enic_queue_wq_skb_csum_l4(struct enic *enic, |
| 416 | struct vnic_wq *wq, struct sk_buff *skb, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 417 | int vlan_tag_insert, unsigned int vlan_tag, int loopback) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 418 | { |
| 419 | unsigned int head_len = skb_headlen(skb); |
| 420 | unsigned int len_left = skb->len - head_len; |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 421 | unsigned int hdr_len = skb_checksum_start_offset(skb); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 422 | unsigned int csum_offset = hdr_len + skb->csum_offset; |
| 423 | int eop = (len_left == 0); |
| 424 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 425 | /* Queue the main skb fragment. The fragments are no larger |
| 426 | * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less |
| 427 | * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor |
| 428 | * per fragment is queued. |
| 429 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 430 | enic_queue_wq_desc_csum_l4(wq, skb, |
| 431 | pci_map_single(enic->pdev, skb->data, |
| 432 | head_len, PCI_DMA_TODEVICE), |
| 433 | head_len, |
| 434 | csum_offset, |
| 435 | hdr_len, |
| 436 | vlan_tag_insert, vlan_tag, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 437 | eop, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 438 | |
| 439 | if (!eop) |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 440 | enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static inline void enic_queue_wq_skb_tso(struct enic *enic, |
| 444 | struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 445 | int vlan_tag_insert, unsigned int vlan_tag, int loopback) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 446 | { |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 447 | unsigned int frag_len_left = skb_headlen(skb); |
| 448 | unsigned int len_left = skb->len - frag_len_left; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 449 | unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 450 | int eop = (len_left == 0); |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 451 | unsigned int len; |
| 452 | dma_addr_t dma_addr; |
| 453 | unsigned int offset = 0; |
| 454 | skb_frag_t *frag; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 455 | |
| 456 | /* Preload TCP csum field with IP pseudo hdr calculated |
| 457 | * with IP length set to zero. HW will later add in length |
| 458 | * to each TCP segment resulting from the TSO. |
| 459 | */ |
| 460 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 461 | if (skb->protocol == cpu_to_be16(ETH_P_IP)) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 462 | ip_hdr(skb)->check = 0; |
| 463 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 464 | ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 465 | } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 466 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 467 | &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 468 | } |
| 469 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 470 | /* Queue WQ_ENET_MAX_DESC_LEN length descriptors |
| 471 | * for the main skb fragment |
| 472 | */ |
| 473 | while (frag_len_left) { |
| 474 | len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN); |
| 475 | dma_addr = pci_map_single(enic->pdev, skb->data + offset, |
| 476 | len, PCI_DMA_TODEVICE); |
| 477 | enic_queue_wq_desc_tso(wq, skb, |
| 478 | dma_addr, |
| 479 | len, |
| 480 | mss, hdr_len, |
| 481 | vlan_tag_insert, vlan_tag, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 482 | eop && (len == frag_len_left), loopback); |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 483 | frag_len_left -= len; |
| 484 | offset += len; |
| 485 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 486 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 487 | if (eop) |
| 488 | return; |
| 489 | |
| 490 | /* Queue WQ_ENET_MAX_DESC_LEN length descriptors |
| 491 | * for additional data fragments |
| 492 | */ |
| 493 | for (frag = skb_shinfo(skb)->frags; len_left; frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 494 | len_left -= skb_frag_size(frag); |
| 495 | frag_len_left = skb_frag_size(frag); |
Ian Campbell | 4bf5adb | 2011-08-29 23:18:27 +0000 | [diff] [blame] | 496 | offset = 0; |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 497 | |
| 498 | while (frag_len_left) { |
| 499 | len = min(frag_len_left, |
| 500 | (unsigned int)WQ_ENET_MAX_DESC_LEN); |
Ian Campbell | 4bf5adb | 2011-08-29 23:18:27 +0000 | [diff] [blame] | 501 | dma_addr = skb_frag_dma_map(&enic->pdev->dev, frag, |
| 502 | offset, len, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 503 | DMA_TO_DEVICE); |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 504 | enic_queue_wq_desc_cont(wq, skb, |
| 505 | dma_addr, |
| 506 | len, |
| 507 | (len_left == 0) && |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 508 | (len == frag_len_left), /* EOP? */ |
| 509 | loopback); |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 510 | frag_len_left -= len; |
| 511 | offset += len; |
| 512 | } |
| 513 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static inline void enic_queue_wq_skb(struct enic *enic, |
| 517 | struct vnic_wq *wq, struct sk_buff *skb) |
| 518 | { |
| 519 | unsigned int mss = skb_shinfo(skb)->gso_size; |
| 520 | unsigned int vlan_tag = 0; |
| 521 | int vlan_tag_insert = 0; |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 522 | int loopback = 0; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 523 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 524 | if (vlan_tx_tag_present(skb)) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 525 | /* VLAN tag from trunking driver */ |
| 526 | vlan_tag_insert = 1; |
| 527 | vlan_tag = vlan_tx_tag_get(skb); |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 528 | } else if (enic->loop_enable) { |
| 529 | vlan_tag = enic->loop_tag; |
| 530 | loopback = 1; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (mss) |
| 534 | enic_queue_wq_skb_tso(enic, wq, skb, mss, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 535 | vlan_tag_insert, vlan_tag, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 536 | else if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 537 | enic_queue_wq_skb_csum_l4(enic, wq, skb, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 538 | vlan_tag_insert, vlan_tag, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 539 | else |
| 540 | enic_queue_wq_skb_vlan(enic, wq, skb, |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 541 | vlan_tag_insert, vlan_tag, loopback); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 544 | /* netif_tx_lock held, process context with BHs disabled, or BH */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 545 | static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, |
Scott Feldman | d87fd25 | 2009-12-23 13:27:59 +0000 | [diff] [blame] | 546 | struct net_device *netdev) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 547 | { |
| 548 | struct enic *enic = netdev_priv(netdev); |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 549 | struct vnic_wq *wq; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 550 | unsigned long flags; |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 551 | unsigned int txq_map; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 552 | |
| 553 | if (skb->len <= 0) { |
Eric W. Biederman | 98d8a65 | 2014-03-15 16:49:05 -0700 | [diff] [blame] | 554 | dev_kfree_skb_any(skb); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 555 | return NETDEV_TX_OK; |
| 556 | } |
| 557 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 558 | txq_map = skb_get_queue_mapping(skb) % enic->wq_count; |
| 559 | wq = &enic->wq[txq_map]; |
| 560 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 561 | /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs, |
| 562 | * which is very likely. In the off chance it's going to take |
| 563 | * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb. |
| 564 | */ |
| 565 | |
| 566 | if (skb_shinfo(skb)->gso_size == 0 && |
| 567 | skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC && |
| 568 | skb_linearize(skb)) { |
Eric W. Biederman | 98d8a65 | 2014-03-15 16:49:05 -0700 | [diff] [blame] | 569 | dev_kfree_skb_any(skb); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 570 | return NETDEV_TX_OK; |
| 571 | } |
| 572 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 573 | spin_lock_irqsave(&enic->wq_lock[txq_map], flags); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 574 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 575 | if (vnic_wq_desc_avail(wq) < |
| 576 | skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) { |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 577 | netif_tx_stop_queue(netdev_get_tx_queue(netdev, txq_map)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 578 | /* This is a hard error, log it */ |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 579 | netdev_err(netdev, "BUG! Tx ring full when queue awake!\n"); |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 580 | spin_unlock_irqrestore(&enic->wq_lock[txq_map], flags); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 581 | return NETDEV_TX_BUSY; |
| 582 | } |
| 583 | |
| 584 | enic_queue_wq_skb(enic, wq, skb); |
| 585 | |
Scott Feldman | ea0d7d9 | 2009-09-03 17:02:03 +0000 | [diff] [blame] | 586 | if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS) |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 587 | netif_tx_stop_queue(netdev_get_tx_queue(netdev, txq_map)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 588 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 589 | spin_unlock_irqrestore(&enic->wq_lock[txq_map], flags); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 590 | |
| 591 | return NETDEV_TX_OK; |
| 592 | } |
| 593 | |
| 594 | /* dev_base_lock rwlock held, nominally process context */ |
stephen hemminger | f20530b | 2011-06-08 14:54:02 +0000 | [diff] [blame] | 595 | static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev, |
| 596 | struct rtnl_link_stats64 *net_stats) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 597 | { |
| 598 | struct enic *enic = netdev_priv(netdev); |
| 599 | struct vnic_stats *stats; |
| 600 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 601 | enic_dev_stats_dump(enic, &stats); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 602 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 603 | net_stats->tx_packets = stats->tx.tx_frames_ok; |
| 604 | net_stats->tx_bytes = stats->tx.tx_bytes_ok; |
| 605 | net_stats->tx_errors = stats->tx.tx_errors; |
| 606 | net_stats->tx_dropped = stats->tx.tx_drops; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 607 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 608 | net_stats->rx_packets = stats->rx.rx_frames_ok; |
| 609 | net_stats->rx_bytes = stats->rx.rx_bytes_ok; |
| 610 | net_stats->rx_errors = stats->rx.rx_errors; |
| 611 | net_stats->multicast = stats->rx.rx_multicast_frames_ok; |
Scott Feldman | 350991e | 2009-09-03 17:02:19 +0000 | [diff] [blame] | 612 | net_stats->rx_over_errors = enic->rq_truncated_pkts; |
Scott Feldman | bd9fb1a | 2009-02-09 23:24:08 -0800 | [diff] [blame] | 613 | net_stats->rx_crc_errors = enic->rq_bad_fcs; |
Scott Feldman | 350991e | 2009-09-03 17:02:19 +0000 | [diff] [blame] | 614 | net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 615 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 616 | return net_stats; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 619 | void enic_reset_addr_lists(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 620 | { |
| 621 | enic->mc_count = 0; |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 622 | enic->uc_count = 0; |
Vasanthy Kolluri | 99ef563 | 2010-06-24 10:50:00 +0000 | [diff] [blame] | 623 | enic->flags = 0; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static int enic_set_mac_addr(struct net_device *netdev, char *addr) |
| 627 | { |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 628 | struct enic *enic = netdev_priv(netdev); |
| 629 | |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 630 | if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) { |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 631 | if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr)) |
| 632 | return -EADDRNOTAVAIL; |
| 633 | } else { |
| 634 | if (!is_valid_ether_addr(addr)) |
| 635 | return -EADDRNOTAVAIL; |
| 636 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 637 | |
| 638 | memcpy(netdev->dev_addr, addr, netdev->addr_len); |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 643 | static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p) |
| 644 | { |
| 645 | struct enic *enic = netdev_priv(netdev); |
| 646 | struct sockaddr *saddr = p; |
| 647 | char *addr = saddr->sa_data; |
| 648 | int err; |
| 649 | |
| 650 | if (netif_running(enic->netdev)) { |
| 651 | err = enic_dev_del_station_addr(enic); |
| 652 | if (err) |
| 653 | return err; |
| 654 | } |
| 655 | |
| 656 | err = enic_set_mac_addr(netdev, addr); |
| 657 | if (err) |
| 658 | return err; |
| 659 | |
| 660 | if (netif_running(enic->netdev)) { |
| 661 | err = enic_dev_add_station_addr(enic); |
| 662 | if (err) |
| 663 | return err; |
| 664 | } |
| 665 | |
| 666 | return err; |
| 667 | } |
| 668 | |
| 669 | static int enic_set_mac_address(struct net_device *netdev, void *p) |
| 670 | { |
Roopa Prabhu | 294dab2 | 2010-08-10 18:54:55 +0000 | [diff] [blame] | 671 | struct sockaddr *saddr = p; |
Vasanthy Kolluri | c76fd32 | 2010-10-20 10:17:04 +0000 | [diff] [blame] | 672 | char *addr = saddr->sa_data; |
| 673 | struct enic *enic = netdev_priv(netdev); |
| 674 | int err; |
Roopa Prabhu | 294dab2 | 2010-08-10 18:54:55 +0000 | [diff] [blame] | 675 | |
Vasanthy Kolluri | c76fd32 | 2010-10-20 10:17:04 +0000 | [diff] [blame] | 676 | err = enic_dev_del_station_addr(enic); |
| 677 | if (err) |
| 678 | return err; |
| 679 | |
| 680 | err = enic_set_mac_addr(netdev, addr); |
| 681 | if (err) |
| 682 | return err; |
| 683 | |
| 684 | return enic_dev_add_station_addr(enic); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 687 | static void enic_update_multicast_addr_list(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 688 | { |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 689 | struct net_device *netdev = enic->netdev; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 690 | struct netdev_hw_addr *ha; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 691 | unsigned int mc_count = netdev_mc_count(netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 692 | u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN]; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 693 | unsigned int i, j; |
| 694 | |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 695 | if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS) { |
| 696 | netdev_warn(netdev, "Registering only %d out of %d " |
| 697 | "multicast addresses\n", |
| 698 | ENIC_MULTICAST_PERFECT_FILTERS, mc_count); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 699 | mc_count = ENIC_MULTICAST_PERFECT_FILTERS; |
Scott Feldman | 9959a18 | 2009-12-23 13:27:43 +0000 | [diff] [blame] | 700 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 701 | |
| 702 | /* Is there an easier way? Trying to minimize to |
| 703 | * calls to add/del multicast addrs. We keep the |
| 704 | * addrs from the last call in enic->mc_addr and |
| 705 | * look for changes to add/del. |
| 706 | */ |
| 707 | |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 708 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 709 | netdev_for_each_mc_addr(ha, netdev) { |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 710 | if (i == mc_count) |
| 711 | break; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 712 | memcpy(mc_addr[i++], ha->addr, ETH_ALEN); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | for (i = 0; i < enic->mc_count; i++) { |
| 716 | for (j = 0; j < mc_count; j++) |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 717 | if (ether_addr_equal(enic->mc_addr[i], mc_addr[j])) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 718 | break; |
| 719 | if (j == mc_count) |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 720 | enic_dev_del_addr(enic, enic->mc_addr[i]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | for (i = 0; i < mc_count; i++) { |
| 724 | for (j = 0; j < enic->mc_count; j++) |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 725 | if (ether_addr_equal(mc_addr[i], enic->mc_addr[j])) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 726 | break; |
| 727 | if (j == enic->mc_count) |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 728 | enic_dev_add_addr(enic, mc_addr[i]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /* Save the list to compare against next time |
| 732 | */ |
| 733 | |
| 734 | for (i = 0; i < mc_count; i++) |
| 735 | memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN); |
| 736 | |
| 737 | enic->mc_count = mc_count; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 740 | static void enic_update_unicast_addr_list(struct enic *enic) |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 741 | { |
| 742 | struct net_device *netdev = enic->netdev; |
| 743 | struct netdev_hw_addr *ha; |
| 744 | unsigned int uc_count = netdev_uc_count(netdev); |
| 745 | u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN]; |
| 746 | unsigned int i, j; |
| 747 | |
| 748 | if (uc_count > ENIC_UNICAST_PERFECT_FILTERS) { |
| 749 | netdev_warn(netdev, "Registering only %d out of %d " |
| 750 | "unicast addresses\n", |
| 751 | ENIC_UNICAST_PERFECT_FILTERS, uc_count); |
| 752 | uc_count = ENIC_UNICAST_PERFECT_FILTERS; |
| 753 | } |
| 754 | |
| 755 | /* Is there an easier way? Trying to minimize to |
| 756 | * calls to add/del unicast addrs. We keep the |
| 757 | * addrs from the last call in enic->uc_addr and |
| 758 | * look for changes to add/del. |
| 759 | */ |
| 760 | |
| 761 | i = 0; |
| 762 | netdev_for_each_uc_addr(ha, netdev) { |
| 763 | if (i == uc_count) |
| 764 | break; |
| 765 | memcpy(uc_addr[i++], ha->addr, ETH_ALEN); |
| 766 | } |
| 767 | |
| 768 | for (i = 0; i < enic->uc_count; i++) { |
| 769 | for (j = 0; j < uc_count; j++) |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 770 | if (ether_addr_equal(enic->uc_addr[i], uc_addr[j])) |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 771 | break; |
| 772 | if (j == uc_count) |
| 773 | enic_dev_del_addr(enic, enic->uc_addr[i]); |
| 774 | } |
| 775 | |
| 776 | for (i = 0; i < uc_count; i++) { |
| 777 | for (j = 0; j < enic->uc_count; j++) |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 778 | if (ether_addr_equal(uc_addr[i], enic->uc_addr[j])) |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 779 | break; |
| 780 | if (j == enic->uc_count) |
| 781 | enic_dev_add_addr(enic, uc_addr[i]); |
| 782 | } |
| 783 | |
| 784 | /* Save the list to compare against next time |
| 785 | */ |
| 786 | |
| 787 | for (i = 0; i < uc_count; i++) |
| 788 | memcpy(enic->uc_addr[i], uc_addr[i], ETH_ALEN); |
| 789 | |
| 790 | enic->uc_count = uc_count; |
| 791 | } |
| 792 | |
| 793 | /* netif_tx_lock held, BHs disabled */ |
| 794 | static void enic_set_rx_mode(struct net_device *netdev) |
| 795 | { |
| 796 | struct enic *enic = netdev_priv(netdev); |
| 797 | int directed = 1; |
| 798 | int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0; |
| 799 | int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0; |
| 800 | int promisc = (netdev->flags & IFF_PROMISC) || |
| 801 | netdev_uc_count(netdev) > ENIC_UNICAST_PERFECT_FILTERS; |
| 802 | int allmulti = (netdev->flags & IFF_ALLMULTI) || |
| 803 | netdev_mc_count(netdev) > ENIC_MULTICAST_PERFECT_FILTERS; |
| 804 | unsigned int flags = netdev->flags | |
| 805 | (allmulti ? IFF_ALLMULTI : 0) | |
| 806 | (promisc ? IFF_PROMISC : 0); |
| 807 | |
| 808 | if (enic->flags != flags) { |
| 809 | enic->flags = flags; |
| 810 | enic_dev_packet_filter(enic, directed, |
| 811 | multicast, broadcast, promisc, allmulti); |
| 812 | } |
| 813 | |
| 814 | if (!promisc) { |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 815 | enic_update_unicast_addr_list(enic); |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 816 | if (!allmulti) |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 817 | enic_update_multicast_addr_list(enic); |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 821 | /* netif_tx_lock held, BHs disabled */ |
| 822 | static void enic_tx_timeout(struct net_device *netdev) |
| 823 | { |
| 824 | struct enic *enic = netdev_priv(netdev); |
| 825 | schedule_work(&enic->reset); |
| 826 | } |
| 827 | |
Roopa Prabhu | 0b1c00f | 2010-12-08 13:53:58 +0000 | [diff] [blame] | 828 | static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 829 | { |
| 830 | struct enic *enic = netdev_priv(netdev); |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 831 | struct enic_port_profile *pp; |
| 832 | int err; |
Roopa Prabhu | 0b1c00f | 2010-12-08 13:53:58 +0000 | [diff] [blame] | 833 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 834 | ENIC_PP_BY_INDEX(enic, vf, pp, &err); |
| 835 | if (err) |
| 836 | return err; |
Roopa Prabhu | 0b1c00f | 2010-12-08 13:53:58 +0000 | [diff] [blame] | 837 | |
Roopa Prabhu | b8622cb | 2012-03-07 03:50:44 +0000 | [diff] [blame] | 838 | if (is_valid_ether_addr(mac) || is_zero_ether_addr(mac)) { |
Roopa Prabhu | b476583 | 2012-02-20 00:11:58 +0000 | [diff] [blame] | 839 | if (vf == PORT_SELF_VF) { |
| 840 | memcpy(pp->vf_mac, mac, ETH_ALEN); |
| 841 | return 0; |
| 842 | } else { |
| 843 | /* |
| 844 | * For sriov vf's set the mac in hw |
| 845 | */ |
| 846 | ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, |
| 847 | vnic_dev_set_mac_addr, mac); |
| 848 | return enic_dev_status_to_errno(err); |
| 849 | } |
Roopa Prabhu | 0b1c00f | 2010-12-08 13:53:58 +0000 | [diff] [blame] | 850 | } else |
| 851 | return -EINVAL; |
| 852 | } |
| 853 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 854 | static int enic_set_vf_port(struct net_device *netdev, int vf, |
| 855 | struct nlattr *port[]) |
| 856 | { |
| 857 | struct enic *enic = netdev_priv(netdev); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 858 | struct enic_port_profile prev_pp; |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 859 | struct enic_port_profile *pp; |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 860 | int err = 0, restore_pp = 1; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 861 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 862 | ENIC_PP_BY_INDEX(enic, vf, pp, &err); |
| 863 | if (err) |
| 864 | return err; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 865 | |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 866 | if (!port[IFLA_PORT_REQUEST]) |
Scott Feldman | 08f382e | 2010-06-01 08:59:33 +0000 | [diff] [blame] | 867 | return -EOPNOTSUPP; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 868 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 869 | memcpy(&prev_pp, pp, sizeof(*enic->pp)); |
| 870 | memset(pp, 0, sizeof(*enic->pp)); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 871 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 872 | pp->set |= ENIC_SET_REQUEST; |
| 873 | pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 874 | |
| 875 | if (port[IFLA_PORT_PROFILE]) { |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 876 | pp->set |= ENIC_SET_NAME; |
| 877 | memcpy(pp->name, nla_data(port[IFLA_PORT_PROFILE]), |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 878 | PORT_PROFILE_MAX); |
| 879 | } |
| 880 | |
| 881 | if (port[IFLA_PORT_INSTANCE_UUID]) { |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 882 | pp->set |= ENIC_SET_INSTANCE; |
| 883 | memcpy(pp->instance_uuid, |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 884 | nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX); |
| 885 | } |
| 886 | |
| 887 | if (port[IFLA_PORT_HOST_UUID]) { |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 888 | pp->set |= ENIC_SET_HOST; |
| 889 | memcpy(pp->host_uuid, |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 890 | nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX); |
| 891 | } |
| 892 | |
Roopa Prabhu | b476583 | 2012-02-20 00:11:58 +0000 | [diff] [blame] | 893 | if (vf == PORT_SELF_VF) { |
| 894 | /* Special case handling: mac came from IFLA_VF_MAC */ |
| 895 | if (!is_zero_ether_addr(prev_pp.vf_mac)) |
| 896 | memcpy(pp->mac_addr, prev_pp.vf_mac, ETH_ALEN); |
Scott Feldman | 418c437 | 2010-05-22 17:29:58 +0000 | [diff] [blame] | 897 | |
Roopa Prabhu | b476583 | 2012-02-20 00:11:58 +0000 | [diff] [blame] | 898 | if (is_zero_ether_addr(netdev->dev_addr)) |
| 899 | eth_hw_addr_random(netdev); |
| 900 | } else { |
| 901 | /* SR-IOV VF: get mac from adapter */ |
| 902 | ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic, |
| 903 | vnic_dev_get_mac_addr, pp->mac_addr); |
| 904 | if (err) { |
| 905 | netdev_err(netdev, "Error getting mac for vf %d\n", vf); |
| 906 | memcpy(pp, &prev_pp, sizeof(*pp)); |
| 907 | return enic_dev_status_to_errno(err); |
| 908 | } |
| 909 | } |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 910 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 911 | err = enic_process_set_pp_request(enic, vf, &prev_pp, &restore_pp); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 912 | if (err) { |
| 913 | if (restore_pp) { |
| 914 | /* Things are still the way they were: Implicit |
| 915 | * DISASSOCIATE failed |
| 916 | */ |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 917 | memcpy(pp, &prev_pp, sizeof(*pp)); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 918 | } else { |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 919 | memset(pp, 0, sizeof(*pp)); |
| 920 | if (vf == PORT_SELF_VF) |
| 921 | memset(netdev->dev_addr, 0, ETH_ALEN); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 922 | } |
| 923 | } else { |
| 924 | /* Set flag to indicate that the port assoc/disassoc |
| 925 | * request has been sent out to fw |
| 926 | */ |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 927 | pp->set |= ENIC_PORT_REQUEST_APPLIED; |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 928 | |
| 929 | /* If DISASSOCIATE, clean up all assigned/saved macaddresses */ |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 930 | if (pp->request == PORT_REQUEST_DISASSOCIATE) { |
| 931 | memset(pp->mac_addr, 0, ETH_ALEN); |
| 932 | if (vf == PORT_SELF_VF) |
| 933 | memset(netdev->dev_addr, 0, ETH_ALEN); |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 934 | } |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Roopa Prabhu | b476583 | 2012-02-20 00:11:58 +0000 | [diff] [blame] | 937 | if (vf == PORT_SELF_VF) |
| 938 | memset(pp->vf_mac, 0, ETH_ALEN); |
Roopa Prabhu | 29639059 | 2010-12-08 13:54:03 +0000 | [diff] [blame] | 939 | |
Roopa Prabhu | 29639059 | 2010-12-08 13:54:03 +0000 | [diff] [blame] | 940 | return err; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static int enic_get_vf_port(struct net_device *netdev, int vf, |
| 944 | struct sk_buff *skb) |
| 945 | { |
| 946 | struct enic *enic = netdev_priv(netdev); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 947 | u16 response = PORT_PROFILE_RESPONSE_SUCCESS; |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 948 | struct enic_port_profile *pp; |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 949 | int err; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 950 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 951 | ENIC_PP_BY_INDEX(enic, vf, pp, &err); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 952 | if (err) |
Roopa Prabhu | b3abfbd | 2011-03-29 20:36:07 +0000 | [diff] [blame] | 953 | return err; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 954 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 955 | if (!(pp->set & ENIC_PORT_REQUEST_APPLIED)) |
| 956 | return -ENODATA; |
| 957 | |
| 958 | err = enic_process_get_pp_request(enic, vf, pp->request, &response); |
| 959 | if (err) |
| 960 | return err; |
| 961 | |
David S. Miller | 1a106de | 2012-04-01 20:22:22 -0400 | [diff] [blame] | 962 | if (nla_put_u16(skb, IFLA_PORT_REQUEST, pp->request) || |
| 963 | nla_put_u16(skb, IFLA_PORT_RESPONSE, response) || |
| 964 | ((pp->set & ENIC_SET_NAME) && |
| 965 | nla_put(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX, pp->name)) || |
| 966 | ((pp->set & ENIC_SET_INSTANCE) && |
| 967 | nla_put(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX, |
| 968 | pp->instance_uuid)) || |
| 969 | ((pp->set & ENIC_SET_HOST) && |
| 970 | nla_put(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX, pp->host_uuid))) |
| 971 | goto nla_put_failure; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 972 | return 0; |
| 973 | |
| 974 | nla_put_failure: |
| 975 | return -EMSGSIZE; |
| 976 | } |
| 977 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 978 | static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) |
| 979 | { |
| 980 | struct enic *enic = vnic_dev_priv(rq->vdev); |
| 981 | |
| 982 | if (!buf->os_buf) |
| 983 | return; |
| 984 | |
| 985 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 986 | buf->len, PCI_DMA_FROMDEVICE); |
| 987 | dev_kfree_skb_any(buf->os_buf); |
| 988 | } |
| 989 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 990 | static int enic_rq_alloc_buf(struct vnic_rq *rq) |
| 991 | { |
| 992 | struct enic *enic = vnic_dev_priv(rq->vdev); |
Scott Feldman | d19e22d | 2009-09-03 17:02:08 +0000 | [diff] [blame] | 993 | struct net_device *netdev = enic->netdev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 994 | struct sk_buff *skb; |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 995 | unsigned int len = netdev->mtu + VLAN_ETH_HLEN; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 996 | unsigned int os_buf_index = 0; |
| 997 | dma_addr_t dma_addr; |
| 998 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 999 | skb = netdev_alloc_skb_ip_align(netdev, len); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1000 | if (!skb) |
| 1001 | return -ENOMEM; |
| 1002 | |
| 1003 | dma_addr = pci_map_single(enic->pdev, skb->data, |
| 1004 | len, PCI_DMA_FROMDEVICE); |
| 1005 | |
| 1006 | enic_queue_rq_desc(rq, skb, os_buf_index, |
| 1007 | dma_addr, len); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1012 | static void enic_intr_update_pkt_size(struct vnic_rx_bytes_counter *pkt_size, |
| 1013 | u32 pkt_len) |
| 1014 | { |
| 1015 | if (ENIC_LARGE_PKT_THRESHOLD <= pkt_len) |
| 1016 | pkt_size->large_pkt_bytes_cnt += pkt_len; |
| 1017 | else |
| 1018 | pkt_size->small_pkt_bytes_cnt += pkt_len; |
| 1019 | } |
| 1020 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1021 | static void enic_rq_indicate_buf(struct vnic_rq *rq, |
| 1022 | struct cq_desc *cq_desc, struct vnic_rq_buf *buf, |
| 1023 | int skipped, void *opaque) |
| 1024 | { |
| 1025 | struct enic *enic = vnic_dev_priv(rq->vdev); |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1026 | struct net_device *netdev = enic->netdev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1027 | struct sk_buff *skb; |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1028 | struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)]; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1029 | |
| 1030 | u8 type, color, eop, sop, ingress_port, vlan_stripped; |
| 1031 | u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof; |
| 1032 | u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; |
| 1033 | u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc; |
| 1034 | u8 packet_error; |
Vasanthy Kolluri | f8cac14 | 2010-06-24 10:49:51 +0000 | [diff] [blame] | 1035 | u16 q_number, completed_index, bytes_written, vlan_tci, checksum; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1036 | u32 rss_hash; |
| 1037 | |
| 1038 | if (skipped) |
| 1039 | return; |
| 1040 | |
| 1041 | skb = buf->os_buf; |
| 1042 | prefetch(skb->data - NET_IP_ALIGN); |
| 1043 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 1044 | buf->len, PCI_DMA_FROMDEVICE); |
| 1045 | |
| 1046 | cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, |
| 1047 | &type, &color, &q_number, &completed_index, |
| 1048 | &ingress_port, &fcoe, &eop, &sop, &rss_type, |
| 1049 | &csum_not_calc, &rss_hash, &bytes_written, |
Vasanthy Kolluri | f8cac14 | 2010-06-24 10:49:51 +0000 | [diff] [blame] | 1050 | &packet_error, &vlan_stripped, &vlan_tci, &checksum, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1051 | &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error, |
| 1052 | &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp, |
| 1053 | &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment, |
| 1054 | &fcs_ok); |
| 1055 | |
| 1056 | if (packet_error) { |
| 1057 | |
Scott Feldman | 350991e | 2009-09-03 17:02:19 +0000 | [diff] [blame] | 1058 | if (!fcs_ok) { |
| 1059 | if (bytes_written > 0) |
| 1060 | enic->rq_bad_fcs++; |
| 1061 | else if (bytes_written == 0) |
| 1062 | enic->rq_truncated_pkts++; |
| 1063 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1064 | |
| 1065 | dev_kfree_skb_any(skb); |
| 1066 | |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | if (eop && bytes_written > 0) { |
| 1071 | |
| 1072 | /* Good receive |
| 1073 | */ |
| 1074 | |
| 1075 | skb_put(skb, bytes_written); |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1076 | skb->protocol = eth_type_trans(skb, netdev); |
govindarajulu.v | bf751ba | 2013-09-04 11:17:15 +0530 | [diff] [blame] | 1077 | skb_record_rx_queue(skb, q_number); |
| 1078 | if (netdev->features & NETIF_F_RXHASH) { |
Tom Herbert | 3739acd | 2013-12-17 23:23:42 -0800 | [diff] [blame] | 1079 | skb_set_hash(skb, rss_hash, |
| 1080 | (rss_type & |
| 1081 | (NIC_CFG_RSS_HASH_TYPE_TCP_IPV6_EX | |
| 1082 | NIC_CFG_RSS_HASH_TYPE_TCP_IPV6 | |
| 1083 | NIC_CFG_RSS_HASH_TYPE_TCP_IPV4)) ? |
| 1084 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
govindarajulu.v | bf751ba | 2013-09-04 11:17:15 +0530 | [diff] [blame] | 1085 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1086 | |
Michał Mirosław | 5ec8f9b | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1087 | if ((netdev->features & NETIF_F_RXCSUM) && !csum_not_calc) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1088 | skb->csum = htons(checksum); |
| 1089 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1090 | } |
| 1091 | |
Jiri Pirko | 6ede746 | 2011-07-20 04:54:18 +0000 | [diff] [blame] | 1092 | if (vlan_stripped) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1093 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1094 | |
Jiri Pirko | 6ede746 | 2011-07-20 04:54:18 +0000 | [diff] [blame] | 1095 | if (netdev->features & NETIF_F_GRO) |
| 1096 | napi_gro_receive(&enic->napi[q_number], skb); |
| 1097 | else |
| 1098 | netif_receive_skb(skb); |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1099 | if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce) |
| 1100 | enic_intr_update_pkt_size(&cq->pkt_size_counter, |
| 1101 | bytes_written); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1102 | } else { |
| 1103 | |
| 1104 | /* Buffer overflow |
| 1105 | */ |
| 1106 | |
| 1107 | dev_kfree_skb_any(skb); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, |
| 1112 | u8 type, u16 q_number, u16 completed_index, void *opaque) |
| 1113 | { |
| 1114 | struct enic *enic = vnic_dev_priv(vdev); |
| 1115 | |
| 1116 | vnic_rq_service(&enic->rq[q_number], cq_desc, |
| 1117 | completed_index, VNIC_RQ_RETURN_DESC, |
| 1118 | enic_rq_indicate_buf, opaque); |
| 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1123 | static int enic_poll(struct napi_struct *napi, int budget) |
| 1124 | { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1125 | struct net_device *netdev = napi->dev; |
| 1126 | struct enic *enic = netdev_priv(netdev); |
| 1127 | unsigned int cq_rq = enic_cq_rq(enic, 0); |
| 1128 | unsigned int cq_wq = enic_cq_wq(enic, 0); |
| 1129 | unsigned int intr = enic_legacy_io_intr(); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1130 | unsigned int rq_work_to_do = budget; |
| 1131 | unsigned int wq_work_to_do = -1; /* no limit */ |
Eric W. Biederman | 4c50254 | 2014-03-14 18:02:08 -0700 | [diff] [blame] | 1132 | unsigned int work_done, rq_work_done = 0, wq_work_done; |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1133 | int err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1134 | |
| 1135 | /* Service RQ (first) and WQ |
| 1136 | */ |
| 1137 | |
Eric W. Biederman | 4c50254 | 2014-03-14 18:02:08 -0700 | [diff] [blame] | 1138 | if (budget > 0) |
| 1139 | rq_work_done = vnic_cq_service(&enic->cq[cq_rq], |
| 1140 | rq_work_to_do, enic_rq_service, NULL); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1141 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1142 | wq_work_done = vnic_cq_service(&enic->cq[cq_wq], |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1143 | wq_work_to_do, enic_wq_service, NULL); |
| 1144 | |
| 1145 | /* Accumulate intr event credits for this polling |
| 1146 | * cycle. An intr event is the completion of a |
| 1147 | * a WQ or RQ packet. |
| 1148 | */ |
| 1149 | |
| 1150 | work_done = rq_work_done + wq_work_done; |
| 1151 | |
| 1152 | if (work_done > 0) |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1153 | vnic_intr_return_credits(&enic->intr[intr], |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1154 | work_done, |
| 1155 | 0 /* don't unmask intr */, |
| 1156 | 0 /* don't reset intr timer */); |
| 1157 | |
Vasanthy Kolluri | 0eb2602 | 2011-02-04 16:17:21 +0000 | [diff] [blame] | 1158 | err = vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1159 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1160 | /* Buffer allocation failed. Stay in polling |
| 1161 | * mode so we can try to fill the ring again. |
| 1162 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1163 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1164 | if (err) |
| 1165 | rq_work_done = rq_work_to_do; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1166 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1167 | if (rq_work_done < rq_work_to_do) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1168 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1169 | /* Some work done, but not enough to stay in polling, |
Vasanthy Kolluri | 88132f5 | 2010-06-24 10:49:25 +0000 | [diff] [blame] | 1170 | * exit polling |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1171 | */ |
| 1172 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1173 | napi_complete(napi); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1174 | vnic_intr_unmask(&enic->intr[intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | return rq_work_done; |
| 1178 | } |
| 1179 | |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1180 | static void enic_set_int_moderation(struct enic *enic, struct vnic_rq *rq) |
| 1181 | { |
| 1182 | unsigned int intr = enic_msix_rq_intr(enic, rq->index); |
| 1183 | struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)]; |
| 1184 | u32 timer = cq->tobe_rx_coal_timeval; |
| 1185 | |
| 1186 | if (cq->tobe_rx_coal_timeval != cq->cur_rx_coal_timeval) { |
| 1187 | vnic_intr_coalescing_timer_set(&enic->intr[intr], timer); |
| 1188 | cq->cur_rx_coal_timeval = cq->tobe_rx_coal_timeval; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | static void enic_calc_int_moderation(struct enic *enic, struct vnic_rq *rq) |
| 1193 | { |
| 1194 | struct enic_rx_coal *rx_coal = &enic->rx_coalesce_setting; |
| 1195 | struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)]; |
| 1196 | struct vnic_rx_bytes_counter *pkt_size_counter = &cq->pkt_size_counter; |
| 1197 | int index; |
| 1198 | u32 timer; |
| 1199 | u32 range_start; |
| 1200 | u32 traffic; |
| 1201 | u64 delta; |
| 1202 | ktime_t now = ktime_get(); |
| 1203 | |
| 1204 | delta = ktime_us_delta(now, cq->prev_ts); |
| 1205 | if (delta < ENIC_AIC_TS_BREAK) |
| 1206 | return; |
| 1207 | cq->prev_ts = now; |
| 1208 | |
| 1209 | traffic = pkt_size_counter->large_pkt_bytes_cnt + |
| 1210 | pkt_size_counter->small_pkt_bytes_cnt; |
| 1211 | /* The table takes Mbps |
| 1212 | * traffic *= 8 => bits |
| 1213 | * traffic *= (10^6 / delta) => bps |
| 1214 | * traffic /= 10^6 => Mbps |
| 1215 | * |
| 1216 | * Combining, traffic *= (8 / delta) |
| 1217 | */ |
| 1218 | |
| 1219 | traffic <<= 3; |
| 1220 | traffic /= delta; |
| 1221 | |
| 1222 | for (index = 0; index < ENIC_MAX_COALESCE_TIMERS; index++) |
| 1223 | if (traffic < mod_table[index].rx_rate) |
| 1224 | break; |
| 1225 | range_start = (pkt_size_counter->small_pkt_bytes_cnt > |
| 1226 | pkt_size_counter->large_pkt_bytes_cnt << 1) ? |
| 1227 | rx_coal->small_pkt_range_start : |
| 1228 | rx_coal->large_pkt_range_start; |
| 1229 | timer = range_start + ((rx_coal->range_end - range_start) * |
| 1230 | mod_table[index].range_percent / 100); |
| 1231 | /* Damping */ |
| 1232 | cq->tobe_rx_coal_timeval = (timer + cq->tobe_rx_coal_timeval) >> 1; |
| 1233 | |
| 1234 | pkt_size_counter->large_pkt_bytes_cnt = 0; |
| 1235 | pkt_size_counter->small_pkt_bytes_cnt = 0; |
| 1236 | } |
| 1237 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1238 | static int enic_poll_msix(struct napi_struct *napi, int budget) |
| 1239 | { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1240 | struct net_device *netdev = napi->dev; |
| 1241 | struct enic *enic = netdev_priv(netdev); |
| 1242 | unsigned int rq = (napi - &enic->napi[0]); |
| 1243 | unsigned int cq = enic_cq_rq(enic, rq); |
| 1244 | unsigned int intr = enic_msix_rq_intr(enic, rq); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1245 | unsigned int work_to_do = budget; |
Eric W. Biederman | 4c50254 | 2014-03-14 18:02:08 -0700 | [diff] [blame] | 1246 | unsigned int work_done = 0; |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1247 | int err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1248 | |
| 1249 | /* Service RQ |
| 1250 | */ |
| 1251 | |
Eric W. Biederman | 4c50254 | 2014-03-14 18:02:08 -0700 | [diff] [blame] | 1252 | if (budget > 0) |
| 1253 | work_done = vnic_cq_service(&enic->cq[cq], |
| 1254 | work_to_do, enic_rq_service, NULL); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1255 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1256 | /* Return intr event credits for this polling |
| 1257 | * cycle. An intr event is the completion of a |
| 1258 | * RQ packet. |
| 1259 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1260 | |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1261 | if (work_done > 0) |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1262 | vnic_intr_return_credits(&enic->intr[intr], |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1263 | work_done, |
| 1264 | 0 /* don't unmask intr */, |
| 1265 | 0 /* don't reset intr timer */); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1266 | |
Vasanthy Kolluri | 0eb2602 | 2011-02-04 16:17:21 +0000 | [diff] [blame] | 1267 | err = vnic_rq_fill(&enic->rq[rq], enic_rq_alloc_buf); |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1268 | |
| 1269 | /* Buffer allocation failed. Stay in polling mode |
| 1270 | * so we can try to fill the ring again. |
| 1271 | */ |
| 1272 | |
| 1273 | if (err) |
| 1274 | work_done = work_to_do; |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1275 | if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce) |
| 1276 | /* Call the function which refreshes |
| 1277 | * the intr coalescing timer value based on |
| 1278 | * the traffic. This is supported only in |
| 1279 | * the case of MSI-x mode |
| 1280 | */ |
| 1281 | enic_calc_int_moderation(enic, &enic->rq[rq]); |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1282 | |
| 1283 | if (work_done < work_to_do) { |
| 1284 | |
| 1285 | /* Some work done, but not enough to stay in polling, |
Vasanthy Kolluri | 88132f5 | 2010-06-24 10:49:25 +0000 | [diff] [blame] | 1286 | * exit polling |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1287 | */ |
| 1288 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1289 | napi_complete(napi); |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1290 | if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce) |
| 1291 | enic_set_int_moderation(enic, &enic->rq[rq]); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1292 | vnic_intr_unmask(&enic->intr[intr]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | return work_done; |
| 1296 | } |
| 1297 | |
| 1298 | static void enic_notify_timer(unsigned long data) |
| 1299 | { |
| 1300 | struct enic *enic = (struct enic *)data; |
| 1301 | |
| 1302 | enic_notify_check(enic); |
| 1303 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 1304 | mod_timer(&enic->notify_timer, |
| 1305 | round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | static void enic_free_intr(struct enic *enic) |
| 1309 | { |
| 1310 | struct net_device *netdev = enic->netdev; |
| 1311 | unsigned int i; |
| 1312 | |
| 1313 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1314 | case VNIC_DEV_INTR_MODE_INTX: |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1315 | free_irq(enic->pdev->irq, netdev); |
| 1316 | break; |
Scott Feldman | 8f4d248 | 2008-09-24 11:23:42 -0700 | [diff] [blame] | 1317 | case VNIC_DEV_INTR_MODE_MSI: |
| 1318 | free_irq(enic->pdev->irq, enic); |
| 1319 | break; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1320 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1321 | for (i = 0; i < ARRAY_SIZE(enic->msix); i++) |
| 1322 | if (enic->msix[i].requested) |
| 1323 | free_irq(enic->msix_entry[i].vector, |
| 1324 | enic->msix[i].devid); |
| 1325 | break; |
| 1326 | default: |
| 1327 | break; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | static int enic_request_intr(struct enic *enic) |
| 1332 | { |
| 1333 | struct net_device *netdev = enic->netdev; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1334 | unsigned int i, intr; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1335 | int err = 0; |
| 1336 | |
| 1337 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1338 | |
| 1339 | case VNIC_DEV_INTR_MODE_INTX: |
| 1340 | |
| 1341 | err = request_irq(enic->pdev->irq, enic_isr_legacy, |
| 1342 | IRQF_SHARED, netdev->name, netdev); |
| 1343 | break; |
| 1344 | |
| 1345 | case VNIC_DEV_INTR_MODE_MSI: |
| 1346 | |
| 1347 | err = request_irq(enic->pdev->irq, enic_isr_msi, |
| 1348 | 0, netdev->name, enic); |
| 1349 | break; |
| 1350 | |
| 1351 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1352 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1353 | for (i = 0; i < enic->rq_count; i++) { |
| 1354 | intr = enic_msix_rq_intr(enic, i); |
Dan Carpenter | 4505f40 | 2013-01-17 21:46:18 +0000 | [diff] [blame] | 1355 | snprintf(enic->msix[intr].devname, |
| 1356 | sizeof(enic->msix[intr].devname), |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1357 | "%.11s-rx-%d", netdev->name, i); |
| 1358 | enic->msix[intr].isr = enic_isr_msix_rq; |
| 1359 | enic->msix[intr].devid = &enic->napi[i]; |
| 1360 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1361 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1362 | for (i = 0; i < enic->wq_count; i++) { |
| 1363 | intr = enic_msix_wq_intr(enic, i); |
Dan Carpenter | 4505f40 | 2013-01-17 21:46:18 +0000 | [diff] [blame] | 1364 | snprintf(enic->msix[intr].devname, |
| 1365 | sizeof(enic->msix[intr].devname), |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1366 | "%.11s-tx-%d", netdev->name, i); |
| 1367 | enic->msix[intr].isr = enic_isr_msix_wq; |
| 1368 | enic->msix[intr].devid = enic; |
| 1369 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1370 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1371 | intr = enic_msix_err_intr(enic); |
Dan Carpenter | 4505f40 | 2013-01-17 21:46:18 +0000 | [diff] [blame] | 1372 | snprintf(enic->msix[intr].devname, |
| 1373 | sizeof(enic->msix[intr].devname), |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1374 | "%.11s-err", netdev->name); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1375 | enic->msix[intr].isr = enic_isr_msix_err; |
| 1376 | enic->msix[intr].devid = enic; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1377 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1378 | intr = enic_msix_notify_intr(enic); |
Dan Carpenter | 4505f40 | 2013-01-17 21:46:18 +0000 | [diff] [blame] | 1379 | snprintf(enic->msix[intr].devname, |
| 1380 | sizeof(enic->msix[intr].devname), |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1381 | "%.11s-notify", netdev->name); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1382 | enic->msix[intr].isr = enic_isr_msix_notify; |
| 1383 | enic->msix[intr].devid = enic; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1384 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1385 | for (i = 0; i < ARRAY_SIZE(enic->msix); i++) |
| 1386 | enic->msix[i].requested = 0; |
| 1387 | |
| 1388 | for (i = 0; i < enic->intr_count; i++) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1389 | err = request_irq(enic->msix_entry[i].vector, |
| 1390 | enic->msix[i].isr, 0, |
| 1391 | enic->msix[i].devname, |
| 1392 | enic->msix[i].devid); |
| 1393 | if (err) { |
| 1394 | enic_free_intr(enic); |
| 1395 | break; |
| 1396 | } |
| 1397 | enic->msix[i].requested = 1; |
| 1398 | } |
| 1399 | |
| 1400 | break; |
| 1401 | |
| 1402 | default: |
| 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | return err; |
| 1407 | } |
| 1408 | |
Scott Feldman | b3d18d1 | 2009-12-23 13:27:30 +0000 | [diff] [blame] | 1409 | static void enic_synchronize_irqs(struct enic *enic) |
| 1410 | { |
| 1411 | unsigned int i; |
| 1412 | |
| 1413 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1414 | case VNIC_DEV_INTR_MODE_INTX: |
| 1415 | case VNIC_DEV_INTR_MODE_MSI: |
| 1416 | synchronize_irq(enic->pdev->irq); |
| 1417 | break; |
| 1418 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1419 | for (i = 0; i < enic->intr_count; i++) |
| 1420 | synchronize_irq(enic->msix_entry[i].vector); |
| 1421 | break; |
| 1422 | default: |
| 1423 | break; |
| 1424 | } |
| 1425 | } |
| 1426 | |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 1427 | static void enic_set_rx_coal_setting(struct enic *enic) |
| 1428 | { |
| 1429 | unsigned int speed; |
| 1430 | int index = -1; |
| 1431 | struct enic_rx_coal *rx_coal = &enic->rx_coalesce_setting; |
| 1432 | |
| 1433 | /* If intr mode is not MSIX, do not do adaptive coalescing */ |
| 1434 | if (VNIC_DEV_INTR_MODE_MSIX != vnic_dev_get_intr_mode(enic->vdev)) { |
| 1435 | netdev_info(enic->netdev, "INTR mode is not MSIX, Not initializing adaptive coalescing"); |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | /* 1. Read the link speed from fw |
| 1440 | * 2. Pick the default range for the speed |
| 1441 | * 3. Update it in enic->rx_coalesce_setting |
| 1442 | */ |
| 1443 | speed = vnic_dev_port_speed(enic->vdev); |
| 1444 | if (ENIC_LINK_SPEED_10G < speed) |
| 1445 | index = ENIC_LINK_40G_INDEX; |
| 1446 | else if (ENIC_LINK_SPEED_4G < speed) |
| 1447 | index = ENIC_LINK_10G_INDEX; |
| 1448 | else |
| 1449 | index = ENIC_LINK_4G_INDEX; |
| 1450 | |
| 1451 | rx_coal->small_pkt_range_start = mod_range[index].small_pkt_range_start; |
| 1452 | rx_coal->large_pkt_range_start = mod_range[index].large_pkt_range_start; |
| 1453 | rx_coal->range_end = ENIC_RX_COALESCE_RANGE_END; |
| 1454 | |
| 1455 | /* Start with the value provided by UCSM */ |
| 1456 | for (index = 0; index < enic->rq_count; index++) |
| 1457 | enic->cq[index].cur_rx_coal_timeval = |
| 1458 | enic->config.intr_timer_usec; |
| 1459 | |
| 1460 | rx_coal->use_adaptive_rx_coalesce = 1; |
| 1461 | } |
| 1462 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1463 | static int enic_dev_notify_set(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1464 | { |
| 1465 | int err; |
| 1466 | |
Scott Feldman | 56ac88b | 2009-09-03 17:02:14 +0000 | [diff] [blame] | 1467 | spin_lock(&enic->devcmd_lock); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1468 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1469 | case VNIC_DEV_INTR_MODE_INTX: |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1470 | err = vnic_dev_notify_set(enic->vdev, |
| 1471 | enic_legacy_notify_intr()); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1472 | break; |
| 1473 | case VNIC_DEV_INTR_MODE_MSIX: |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1474 | err = vnic_dev_notify_set(enic->vdev, |
| 1475 | enic_msix_notify_intr(enic)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | default: |
| 1478 | err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */); |
| 1479 | break; |
| 1480 | } |
Scott Feldman | 56ac88b | 2009-09-03 17:02:14 +0000 | [diff] [blame] | 1481 | spin_unlock(&enic->devcmd_lock); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1482 | |
| 1483 | return err; |
| 1484 | } |
| 1485 | |
| 1486 | static void enic_notify_timer_start(struct enic *enic) |
| 1487 | { |
| 1488 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1489 | case VNIC_DEV_INTR_MODE_MSI: |
| 1490 | mod_timer(&enic->notify_timer, jiffies); |
| 1491 | break; |
| 1492 | default: |
| 1493 | /* Using intr for notification for INTx/MSI-X */ |
| 1494 | break; |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1495 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /* rtnl lock is held, process context */ |
| 1499 | static int enic_open(struct net_device *netdev) |
| 1500 | { |
| 1501 | struct enic *enic = netdev_priv(netdev); |
| 1502 | unsigned int i; |
| 1503 | int err; |
| 1504 | |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1505 | err = enic_request_intr(enic); |
| 1506 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1507 | netdev_err(netdev, "Unable to request irq.\n"); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1508 | return err; |
| 1509 | } |
| 1510 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1511 | err = enic_dev_notify_set(enic); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1512 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1513 | netdev_err(netdev, |
| 1514 | "Failed to alloc notify buffer, aborting.\n"); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1515 | goto err_out_free_intr; |
| 1516 | } |
| 1517 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1518 | for (i = 0; i < enic->rq_count; i++) { |
Vasanthy Kolluri | 0eb2602 | 2011-02-04 16:17:21 +0000 | [diff] [blame] | 1519 | vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf); |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1520 | /* Need at least one buffer on ring to get going */ |
| 1521 | if (vnic_rq_desc_used(&enic->rq[i]) == 0) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1522 | netdev_err(netdev, "Unable to alloc receive buffers\n"); |
Scott Feldman | 2d6ddce | 2009-12-23 13:27:38 +0000 | [diff] [blame] | 1523 | err = -ENOMEM; |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1524 | goto err_out_notify_unset; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | for (i = 0; i < enic->wq_count; i++) |
| 1529 | vnic_wq_enable(&enic->wq[i]); |
| 1530 | for (i = 0; i < enic->rq_count; i++) |
| 1531 | vnic_rq_enable(&enic->rq[i]); |
| 1532 | |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 1533 | if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic)) |
Roopa Prabhu | 29639059 | 2010-12-08 13:54:03 +0000 | [diff] [blame] | 1534 | enic_dev_add_station_addr(enic); |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 1535 | |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 1536 | enic_set_rx_mode(netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1537 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 1538 | netif_tx_wake_all_queues(netdev); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1539 | |
| 1540 | for (i = 0; i < enic->rq_count; i++) |
| 1541 | napi_enable(&enic->napi[i]); |
| 1542 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1543 | enic_dev_enable(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1544 | |
| 1545 | for (i = 0; i < enic->intr_count; i++) |
| 1546 | vnic_intr_unmask(&enic->intr[i]); |
| 1547 | |
| 1548 | enic_notify_timer_start(enic); |
| 1549 | |
| 1550 | return 0; |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1551 | |
| 1552 | err_out_notify_unset: |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1553 | enic_dev_notify_unset(enic); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1554 | err_out_free_intr: |
| 1555 | enic_free_intr(enic); |
| 1556 | |
| 1557 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /* rtnl lock is held, process context */ |
| 1561 | static int enic_stop(struct net_device *netdev) |
| 1562 | { |
| 1563 | struct enic *enic = netdev_priv(netdev); |
| 1564 | unsigned int i; |
| 1565 | int err; |
| 1566 | |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 1567 | for (i = 0; i < enic->intr_count; i++) { |
Scott Feldman | b3d18d1 | 2009-12-23 13:27:30 +0000 | [diff] [blame] | 1568 | vnic_intr_mask(&enic->intr[i]); |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 1569 | (void)vnic_intr_masked(&enic->intr[i]); /* flush write */ |
| 1570 | } |
Scott Feldman | b3d18d1 | 2009-12-23 13:27:30 +0000 | [diff] [blame] | 1571 | |
| 1572 | enic_synchronize_irqs(enic); |
| 1573 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1574 | del_timer_sync(&enic->notify_timer); |
| 1575 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1576 | enic_dev_disable(enic); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1577 | |
| 1578 | for (i = 0; i < enic->rq_count; i++) |
| 1579 | napi_disable(&enic->napi[i]); |
| 1580 | |
Scott Feldman | b3d18d1 | 2009-12-23 13:27:30 +0000 | [diff] [blame] | 1581 | netif_carrier_off(netdev); |
| 1582 | netif_tx_disable(netdev); |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 1583 | |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 1584 | if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic)) |
Roopa Prabhu | 29639059 | 2010-12-08 13:54:03 +0000 | [diff] [blame] | 1585 | enic_dev_del_station_addr(enic); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 1586 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1587 | for (i = 0; i < enic->wq_count; i++) { |
| 1588 | err = vnic_wq_disable(&enic->wq[i]); |
| 1589 | if (err) |
| 1590 | return err; |
| 1591 | } |
| 1592 | for (i = 0; i < enic->rq_count; i++) { |
| 1593 | err = vnic_rq_disable(&enic->rq[i]); |
| 1594 | if (err) |
| 1595 | return err; |
| 1596 | } |
| 1597 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1598 | enic_dev_notify_unset(enic); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1599 | enic_free_intr(enic); |
| 1600 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1601 | for (i = 0; i < enic->wq_count; i++) |
| 1602 | vnic_wq_clean(&enic->wq[i], enic_free_wq_buf); |
| 1603 | for (i = 0; i < enic->rq_count; i++) |
| 1604 | vnic_rq_clean(&enic->rq[i], enic_free_rq_buf); |
| 1605 | for (i = 0; i < enic->cq_count; i++) |
| 1606 | vnic_cq_clean(&enic->cq[i]); |
| 1607 | for (i = 0; i < enic->intr_count; i++) |
| 1608 | vnic_intr_clean(&enic->intr[i]); |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | static int enic_change_mtu(struct net_device *netdev, int new_mtu) |
| 1614 | { |
| 1615 | struct enic *enic = netdev_priv(netdev); |
| 1616 | int running = netif_running(netdev); |
| 1617 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 1618 | if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU) |
| 1619 | return -EINVAL; |
| 1620 | |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 1621 | if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 1622 | return -EOPNOTSUPP; |
| 1623 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1624 | if (running) |
| 1625 | enic_stop(netdev); |
| 1626 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1627 | netdev->mtu = new_mtu; |
| 1628 | |
| 1629 | if (netdev->mtu > enic->port_mtu) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1630 | netdev_warn(netdev, |
| 1631 | "interface MTU (%d) set higher than port MTU (%d)\n", |
| 1632 | netdev->mtu, enic->port_mtu); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1633 | |
| 1634 | if (running) |
| 1635 | enic_open(netdev); |
| 1636 | |
| 1637 | return 0; |
| 1638 | } |
| 1639 | |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 1640 | static void enic_change_mtu_work(struct work_struct *work) |
| 1641 | { |
| 1642 | struct enic *enic = container_of(work, struct enic, change_mtu_work); |
| 1643 | struct net_device *netdev = enic->netdev; |
| 1644 | int new_mtu = vnic_dev_mtu(enic->vdev); |
| 1645 | int err; |
| 1646 | unsigned int i; |
| 1647 | |
| 1648 | new_mtu = max_t(int, ENIC_MIN_MTU, min_t(int, ENIC_MAX_MTU, new_mtu)); |
| 1649 | |
| 1650 | rtnl_lock(); |
| 1651 | |
| 1652 | /* Stop RQ */ |
| 1653 | del_timer_sync(&enic->notify_timer); |
| 1654 | |
| 1655 | for (i = 0; i < enic->rq_count; i++) |
| 1656 | napi_disable(&enic->napi[i]); |
| 1657 | |
| 1658 | vnic_intr_mask(&enic->intr[0]); |
| 1659 | enic_synchronize_irqs(enic); |
| 1660 | err = vnic_rq_disable(&enic->rq[0]); |
| 1661 | if (err) { |
Konstantin Khlebnikov | e057590 | 2013-07-08 11:22:51 +0400 | [diff] [blame] | 1662 | rtnl_unlock(); |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 1663 | netdev_err(netdev, "Unable to disable RQ.\n"); |
| 1664 | return; |
| 1665 | } |
| 1666 | vnic_rq_clean(&enic->rq[0], enic_free_rq_buf); |
| 1667 | vnic_cq_clean(&enic->cq[0]); |
| 1668 | vnic_intr_clean(&enic->intr[0]); |
| 1669 | |
| 1670 | /* Fill RQ with new_mtu-sized buffers */ |
| 1671 | netdev->mtu = new_mtu; |
| 1672 | vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); |
| 1673 | /* Need at least one buffer on ring to get going */ |
| 1674 | if (vnic_rq_desc_used(&enic->rq[0]) == 0) { |
Konstantin Khlebnikov | e057590 | 2013-07-08 11:22:51 +0400 | [diff] [blame] | 1675 | rtnl_unlock(); |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 1676 | netdev_err(netdev, "Unable to alloc receive buffers.\n"); |
| 1677 | return; |
| 1678 | } |
| 1679 | |
| 1680 | /* Start RQ */ |
| 1681 | vnic_rq_enable(&enic->rq[0]); |
| 1682 | napi_enable(&enic->napi[0]); |
| 1683 | vnic_intr_unmask(&enic->intr[0]); |
| 1684 | enic_notify_timer_start(enic); |
| 1685 | |
| 1686 | rtnl_unlock(); |
| 1687 | |
| 1688 | netdev_info(netdev, "interface MTU set as %d\n", netdev->mtu); |
| 1689 | } |
| 1690 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1691 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1692 | static void enic_poll_controller(struct net_device *netdev) |
| 1693 | { |
| 1694 | struct enic *enic = netdev_priv(netdev); |
| 1695 | struct vnic_dev *vdev = enic->vdev; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1696 | unsigned int i, intr; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1697 | |
| 1698 | switch (vnic_dev_get_intr_mode(vdev)) { |
| 1699 | case VNIC_DEV_INTR_MODE_MSIX: |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1700 | for (i = 0; i < enic->rq_count; i++) { |
| 1701 | intr = enic_msix_rq_intr(enic, i); |
Vasanthy Kolluri | 79aeec5 | 2010-12-08 13:05:45 +0000 | [diff] [blame] | 1702 | enic_isr_msix_rq(enic->msix_entry[intr].vector, |
| 1703 | &enic->napi[i]); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1704 | } |
Vasanthy Kolluri | b880a95 | 2011-06-09 10:37:07 +0000 | [diff] [blame] | 1705 | |
| 1706 | for (i = 0; i < enic->wq_count; i++) { |
| 1707 | intr = enic_msix_wq_intr(enic, i); |
| 1708 | enic_isr_msix_wq(enic->msix_entry[intr].vector, enic); |
| 1709 | } |
| 1710 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1711 | break; |
| 1712 | case VNIC_DEV_INTR_MODE_MSI: |
| 1713 | enic_isr_msi(enic->pdev->irq, enic); |
| 1714 | break; |
| 1715 | case VNIC_DEV_INTR_MODE_INTX: |
| 1716 | enic_isr_legacy(enic->pdev->irq, netdev); |
| 1717 | break; |
| 1718 | default: |
| 1719 | break; |
| 1720 | } |
| 1721 | } |
| 1722 | #endif |
| 1723 | |
| 1724 | static int enic_dev_wait(struct vnic_dev *vdev, |
| 1725 | int (*start)(struct vnic_dev *, int), |
| 1726 | int (*finished)(struct vnic_dev *, int *), |
| 1727 | int arg) |
| 1728 | { |
| 1729 | unsigned long time; |
| 1730 | int done; |
| 1731 | int err; |
| 1732 | |
| 1733 | BUG_ON(in_interrupt()); |
| 1734 | |
| 1735 | err = start(vdev, arg); |
| 1736 | if (err) |
| 1737 | return err; |
| 1738 | |
| 1739 | /* Wait for func to complete...2 seconds max |
| 1740 | */ |
| 1741 | |
| 1742 | time = jiffies + (HZ * 2); |
| 1743 | do { |
| 1744 | |
| 1745 | err = finished(vdev, &done); |
| 1746 | if (err) |
| 1747 | return err; |
| 1748 | |
| 1749 | if (done) |
| 1750 | return 0; |
| 1751 | |
| 1752 | schedule_timeout_uninterruptible(HZ / 10); |
| 1753 | |
| 1754 | } while (time_after(time, jiffies)); |
| 1755 | |
| 1756 | return -ETIMEDOUT; |
| 1757 | } |
| 1758 | |
| 1759 | static int enic_dev_open(struct enic *enic) |
| 1760 | { |
| 1761 | int err; |
| 1762 | |
| 1763 | err = enic_dev_wait(enic->vdev, vnic_dev_open, |
| 1764 | vnic_dev_open_done, 0); |
| 1765 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1766 | dev_err(enic_get_dev(enic), "vNIC device open failed, err %d\n", |
| 1767 | err); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1768 | |
| 1769 | return err; |
| 1770 | } |
| 1771 | |
Vasanthy Kolluri | 99ef563 | 2010-06-24 10:50:00 +0000 | [diff] [blame] | 1772 | static int enic_dev_hang_reset(struct enic *enic) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1773 | { |
| 1774 | int err; |
| 1775 | |
Vasanthy Kolluri | 99ef563 | 2010-06-24 10:50:00 +0000 | [diff] [blame] | 1776 | err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset, |
| 1777 | vnic_dev_hang_reset_done, 0); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1778 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 1779 | netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n", |
| 1780 | err); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1781 | |
| 1782 | return err; |
| 1783 | } |
| 1784 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1785 | static int enic_set_rsskey(struct enic *enic) |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1786 | { |
Vasanthy Kolluri | 1f4f067 | 2010-11-15 08:09:55 +0000 | [diff] [blame] | 1787 | dma_addr_t rss_key_buf_pa; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1788 | union vnic_rss_key *rss_key_buf_va = NULL; |
| 1789 | union vnic_rss_key rss_key = { |
| 1790 | .key[0].b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101}, |
| 1791 | .key[1].b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101}, |
| 1792 | .key[2].b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115}, |
| 1793 | .key[3].b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108}, |
| 1794 | }; |
| 1795 | int err; |
| 1796 | |
| 1797 | rss_key_buf_va = pci_alloc_consistent(enic->pdev, |
| 1798 | sizeof(union vnic_rss_key), &rss_key_buf_pa); |
| 1799 | if (!rss_key_buf_va) |
| 1800 | return -ENOMEM; |
| 1801 | |
| 1802 | memcpy(rss_key_buf_va, &rss_key, sizeof(union vnic_rss_key)); |
| 1803 | |
| 1804 | spin_lock(&enic->devcmd_lock); |
| 1805 | err = enic_set_rss_key(enic, |
| 1806 | rss_key_buf_pa, |
| 1807 | sizeof(union vnic_rss_key)); |
| 1808 | spin_unlock(&enic->devcmd_lock); |
| 1809 | |
| 1810 | pci_free_consistent(enic->pdev, sizeof(union vnic_rss_key), |
| 1811 | rss_key_buf_va, rss_key_buf_pa); |
| 1812 | |
| 1813 | return err; |
| 1814 | } |
| 1815 | |
| 1816 | static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits) |
| 1817 | { |
Vasanthy Kolluri | 1f4f067 | 2010-11-15 08:09:55 +0000 | [diff] [blame] | 1818 | dma_addr_t rss_cpu_buf_pa; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1819 | union vnic_rss_cpu *rss_cpu_buf_va = NULL; |
| 1820 | unsigned int i; |
| 1821 | int err; |
| 1822 | |
| 1823 | rss_cpu_buf_va = pci_alloc_consistent(enic->pdev, |
| 1824 | sizeof(union vnic_rss_cpu), &rss_cpu_buf_pa); |
| 1825 | if (!rss_cpu_buf_va) |
| 1826 | return -ENOMEM; |
| 1827 | |
| 1828 | for (i = 0; i < (1 << rss_hash_bits); i++) |
| 1829 | (*rss_cpu_buf_va).cpu[i/4].b[i%4] = i % enic->rq_count; |
| 1830 | |
| 1831 | spin_lock(&enic->devcmd_lock); |
| 1832 | err = enic_set_rss_cpu(enic, |
| 1833 | rss_cpu_buf_pa, |
| 1834 | sizeof(union vnic_rss_cpu)); |
| 1835 | spin_unlock(&enic->devcmd_lock); |
| 1836 | |
| 1837 | pci_free_consistent(enic->pdev, sizeof(union vnic_rss_cpu), |
| 1838 | rss_cpu_buf_va, rss_cpu_buf_pa); |
| 1839 | |
| 1840 | return err; |
| 1841 | } |
| 1842 | |
| 1843 | static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu, |
| 1844 | u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable) |
| 1845 | { |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1846 | const u8 tso_ipid_split_en = 0; |
| 1847 | const u8 ig_vlan_strip_en = 1; |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1848 | int err; |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1849 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1850 | /* Enable VLAN tag stripping. |
| 1851 | */ |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1852 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1853 | spin_lock(&enic->devcmd_lock); |
| 1854 | err = enic_set_nic_cfg(enic, |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1855 | rss_default_cpu, rss_hash_type, |
| 1856 | rss_hash_bits, rss_base_cpu, |
| 1857 | rss_enable, tso_ipid_split_en, |
| 1858 | ig_vlan_strip_en); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1859 | spin_unlock(&enic->devcmd_lock); |
| 1860 | |
| 1861 | return err; |
| 1862 | } |
| 1863 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1864 | static int enic_set_rss_nic_cfg(struct enic *enic) |
| 1865 | { |
| 1866 | struct device *dev = enic_get_dev(enic); |
| 1867 | const u8 rss_default_cpu = 0; |
| 1868 | const u8 rss_hash_type = NIC_CFG_RSS_HASH_TYPE_IPV4 | |
| 1869 | NIC_CFG_RSS_HASH_TYPE_TCP_IPV4 | |
| 1870 | NIC_CFG_RSS_HASH_TYPE_IPV6 | |
| 1871 | NIC_CFG_RSS_HASH_TYPE_TCP_IPV6; |
| 1872 | const u8 rss_hash_bits = 7; |
| 1873 | const u8 rss_base_cpu = 0; |
| 1874 | u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1); |
| 1875 | |
| 1876 | if (rss_enable) { |
| 1877 | if (!enic_set_rsskey(enic)) { |
| 1878 | if (enic_set_rsscpu(enic, rss_hash_bits)) { |
| 1879 | rss_enable = 0; |
| 1880 | dev_warn(dev, "RSS disabled, " |
| 1881 | "Failed to set RSS cpu indirection table."); |
| 1882 | } |
| 1883 | } else { |
| 1884 | rss_enable = 0; |
| 1885 | dev_warn(dev, "RSS disabled, Failed to set RSS key.\n"); |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type, |
| 1890 | rss_hash_bits, rss_base_cpu, rss_enable); |
| 1891 | } |
| 1892 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1893 | static void enic_reset(struct work_struct *work) |
| 1894 | { |
| 1895 | struct enic *enic = container_of(work, struct enic, reset); |
| 1896 | |
| 1897 | if (!netif_running(enic->netdev)) |
| 1898 | return; |
| 1899 | |
| 1900 | rtnl_lock(); |
| 1901 | |
Neel Patel | 0b03856 | 2013-08-16 15:47:40 -0700 | [diff] [blame] | 1902 | spin_lock(&enic->enic_api_lock); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 1903 | enic_dev_hang_notify(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1904 | enic_stop(enic->netdev); |
Vasanthy Kolluri | 99ef563 | 2010-06-24 10:50:00 +0000 | [diff] [blame] | 1905 | enic_dev_hang_reset(enic); |
Vasanthy Kolluri | e0afe53 | 2011-02-17 08:53:12 +0000 | [diff] [blame] | 1906 | enic_reset_addr_lists(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1907 | enic_init_vnic_resources(enic); |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1908 | enic_set_rss_nic_cfg(enic); |
Vasanthy Kolluri | f8cac14 | 2010-06-24 10:49:51 +0000 | [diff] [blame] | 1909 | enic_dev_set_ig_vlan_rewrite_mode(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1910 | enic_open(enic->netdev); |
Neel Patel | 0b03856 | 2013-08-16 15:47:40 -0700 | [diff] [blame] | 1911 | spin_unlock(&enic->enic_api_lock); |
Neel Patel | d765bb4 | 2013-08-16 15:47:41 -0700 | [diff] [blame] | 1912 | call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1913 | |
| 1914 | rtnl_unlock(); |
| 1915 | } |
| 1916 | |
| 1917 | static int enic_set_intr_mode(struct enic *enic) |
| 1918 | { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1919 | unsigned int n = min_t(unsigned int, enic->rq_count, ENIC_RQ_MAX); |
Vasanthy Kolluri | 1cbb1a6 | 2011-02-17 13:57:19 +0000 | [diff] [blame] | 1920 | unsigned int m = min_t(unsigned int, enic->wq_count, ENIC_WQ_MAX); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1921 | unsigned int i; |
| 1922 | |
| 1923 | /* Set interrupt mode (INTx, MSI, MSI-X) depending |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1924 | * on system capabilities. |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1925 | * |
| 1926 | * Try MSI-X first |
| 1927 | * |
| 1928 | * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs |
| 1929 | * (the second to last INTR is used for WQ/RQ errors) |
| 1930 | * (the last INTR is used for notifications) |
| 1931 | */ |
| 1932 | |
| 1933 | BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2); |
| 1934 | for (i = 0; i < n + m + 2; i++) |
| 1935 | enic->msix_entry[i].entry = i; |
| 1936 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1937 | /* Use multiple RQs if RSS is enabled |
| 1938 | */ |
| 1939 | |
| 1940 | if (ENIC_SETTING(enic, RSS) && |
| 1941 | enic->config.intr_mode < 1 && |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1942 | enic->rq_count >= n && |
| 1943 | enic->wq_count >= m && |
| 1944 | enic->cq_count >= n + m && |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1945 | enic->intr_count >= n + m + 2) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1946 | |
Alexander Gordeev | abbb6a3 | 2014-02-18 11:08:02 +0100 | [diff] [blame] | 1947 | if (pci_enable_msix_range(enic->pdev, enic->msix_entry, |
| 1948 | n + m + 2, n + m + 2) > 0) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1949 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1950 | enic->rq_count = n; |
| 1951 | enic->wq_count = m; |
| 1952 | enic->cq_count = n + m; |
| 1953 | enic->intr_count = n + m + 2; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1954 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1955 | vnic_dev_set_intr_mode(enic->vdev, |
| 1956 | VNIC_DEV_INTR_MODE_MSIX); |
| 1957 | |
| 1958 | return 0; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | if (enic->config.intr_mode < 1 && |
| 1963 | enic->rq_count >= 1 && |
| 1964 | enic->wq_count >= m && |
| 1965 | enic->cq_count >= 1 + m && |
| 1966 | enic->intr_count >= 1 + m + 2) { |
Alexander Gordeev | abbb6a3 | 2014-02-18 11:08:02 +0100 | [diff] [blame] | 1967 | if (pci_enable_msix_range(enic->pdev, enic->msix_entry, |
| 1968 | 1 + m + 2, 1 + m + 2) > 0) { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 1969 | |
| 1970 | enic->rq_count = 1; |
| 1971 | enic->wq_count = m; |
| 1972 | enic->cq_count = 1 + m; |
| 1973 | enic->intr_count = 1 + m + 2; |
| 1974 | |
| 1975 | vnic_dev_set_intr_mode(enic->vdev, |
| 1976 | VNIC_DEV_INTR_MODE_MSIX); |
| 1977 | |
| 1978 | return 0; |
| 1979 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | /* Next try MSI |
| 1983 | * |
| 1984 | * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR |
| 1985 | */ |
| 1986 | |
| 1987 | if (enic->config.intr_mode < 2 && |
| 1988 | enic->rq_count >= 1 && |
| 1989 | enic->wq_count >= 1 && |
| 1990 | enic->cq_count >= 2 && |
| 1991 | enic->intr_count >= 1 && |
| 1992 | !pci_enable_msi(enic->pdev)) { |
| 1993 | |
| 1994 | enic->rq_count = 1; |
| 1995 | enic->wq_count = 1; |
| 1996 | enic->cq_count = 2; |
| 1997 | enic->intr_count = 1; |
| 1998 | |
| 1999 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI); |
| 2000 | |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
| 2004 | /* Next try INTx |
| 2005 | * |
| 2006 | * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs |
| 2007 | * (the first INTR is used for WQ/RQ) |
| 2008 | * (the second INTR is used for WQ/RQ errors) |
| 2009 | * (the last INTR is used for notifications) |
| 2010 | */ |
| 2011 | |
| 2012 | if (enic->config.intr_mode < 3 && |
| 2013 | enic->rq_count >= 1 && |
| 2014 | enic->wq_count >= 1 && |
| 2015 | enic->cq_count >= 2 && |
| 2016 | enic->intr_count >= 3) { |
| 2017 | |
| 2018 | enic->rq_count = 1; |
| 2019 | enic->wq_count = 1; |
| 2020 | enic->cq_count = 2; |
| 2021 | enic->intr_count = 3; |
| 2022 | |
| 2023 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX); |
| 2024 | |
| 2025 | return 0; |
| 2026 | } |
| 2027 | |
| 2028 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); |
| 2029 | |
| 2030 | return -EINVAL; |
| 2031 | } |
| 2032 | |
| 2033 | static void enic_clear_intr_mode(struct enic *enic) |
| 2034 | { |
| 2035 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 2036 | case VNIC_DEV_INTR_MODE_MSIX: |
| 2037 | pci_disable_msix(enic->pdev); |
| 2038 | break; |
| 2039 | case VNIC_DEV_INTR_MODE_MSI: |
| 2040 | pci_disable_msi(enic->pdev); |
| 2041 | break; |
| 2042 | default: |
| 2043 | break; |
| 2044 | } |
| 2045 | |
| 2046 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); |
| 2047 | } |
| 2048 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2049 | static const struct net_device_ops enic_netdev_dynamic_ops = { |
| 2050 | .ndo_open = enic_open, |
| 2051 | .ndo_stop = enic_stop, |
| 2052 | .ndo_start_xmit = enic_hard_start_xmit, |
stephen hemminger | f20530b | 2011-06-08 14:54:02 +0000 | [diff] [blame] | 2053 | .ndo_get_stats64 = enic_get_stats, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2054 | .ndo_validate_addr = eth_validate_addr, |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 2055 | .ndo_set_rx_mode = enic_set_rx_mode, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2056 | .ndo_set_mac_address = enic_set_mac_address_dynamic, |
| 2057 | .ndo_change_mtu = enic_change_mtu, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2058 | .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid, |
| 2059 | .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid, |
| 2060 | .ndo_tx_timeout = enic_tx_timeout, |
| 2061 | .ndo_set_vf_port = enic_set_vf_port, |
| 2062 | .ndo_get_vf_port = enic_get_vf_port, |
Roopa Prabhu | 0b1c00f | 2010-12-08 13:53:58 +0000 | [diff] [blame] | 2063 | .ndo_set_vf_mac = enic_set_vf_mac, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2064 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2065 | .ndo_poll_controller = enic_poll_controller, |
| 2066 | #endif |
| 2067 | }; |
| 2068 | |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 2069 | static const struct net_device_ops enic_netdev_ops = { |
| 2070 | .ndo_open = enic_open, |
| 2071 | .ndo_stop = enic_stop, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 2072 | .ndo_start_xmit = enic_hard_start_xmit, |
stephen hemminger | f20530b | 2011-06-08 14:54:02 +0000 | [diff] [blame] | 2073 | .ndo_get_stats64 = enic_get_stats, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 2074 | .ndo_validate_addr = eth_validate_addr, |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2075 | .ndo_set_mac_address = enic_set_mac_address, |
Roopa Prabhu | 319d7e8 | 2010-12-08 13:19:58 +0000 | [diff] [blame] | 2076 | .ndo_set_rx_mode = enic_set_rx_mode, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 2077 | .ndo_change_mtu = enic_change_mtu, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 2078 | .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid, |
| 2079 | .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid, |
| 2080 | .ndo_tx_timeout = enic_tx_timeout, |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2081 | .ndo_set_vf_port = enic_set_vf_port, |
| 2082 | .ndo_get_vf_port = enic_get_vf_port, |
| 2083 | .ndo_set_vf_mac = enic_set_vf_mac, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 2084 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2085 | .ndo_poll_controller = enic_poll_controller, |
| 2086 | #endif |
| 2087 | }; |
| 2088 | |
Vasanthy Kolluri | 2fdba38 | 2010-09-30 13:35:45 +0000 | [diff] [blame] | 2089 | static void enic_dev_deinit(struct enic *enic) |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2090 | { |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 2091 | unsigned int i; |
| 2092 | |
| 2093 | for (i = 0; i < enic->rq_count; i++) |
| 2094 | netif_napi_del(&enic->napi[i]); |
| 2095 | |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2096 | enic_free_vnic_resources(enic); |
| 2097 | enic_clear_intr_mode(enic); |
| 2098 | } |
| 2099 | |
Vasanthy Kolluri | 2fdba38 | 2010-09-30 13:35:45 +0000 | [diff] [blame] | 2100 | static int enic_dev_init(struct enic *enic) |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2101 | { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2102 | struct device *dev = enic_get_dev(enic); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2103 | struct net_device *netdev = enic->netdev; |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 2104 | unsigned int i; |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2105 | int err; |
| 2106 | |
Vasanthy Kolluri | ea7ea65 | 2011-06-17 07:56:48 +0000 | [diff] [blame] | 2107 | /* Get interrupt coalesce timer info */ |
| 2108 | err = enic_dev_intr_coal_timer_info(enic); |
| 2109 | if (err) { |
| 2110 | dev_warn(dev, "Using default conversion factor for " |
| 2111 | "interrupt coalesce timer\n"); |
| 2112 | vnic_dev_intr_coal_timer_info_default(enic->vdev); |
| 2113 | } |
| 2114 | |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2115 | /* Get vNIC configuration |
| 2116 | */ |
| 2117 | |
| 2118 | err = enic_get_vnic_config(enic); |
| 2119 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2120 | dev_err(dev, "Get vNIC configuration failed, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2121 | return err; |
| 2122 | } |
| 2123 | |
| 2124 | /* Get available resource counts |
| 2125 | */ |
| 2126 | |
| 2127 | enic_get_res_counts(enic); |
| 2128 | |
| 2129 | /* Set interrupt mode based on resource counts and system |
| 2130 | * capabilities |
| 2131 | */ |
| 2132 | |
| 2133 | err = enic_set_intr_mode(enic); |
| 2134 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2135 | dev_err(dev, "Failed to set intr mode based on resource " |
| 2136 | "counts and system capabilities, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2137 | return err; |
| 2138 | } |
| 2139 | |
| 2140 | /* Allocate and configure vNIC resources |
| 2141 | */ |
| 2142 | |
| 2143 | err = enic_alloc_vnic_resources(enic); |
| 2144 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2145 | dev_err(dev, "Failed to alloc vNIC resources, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2146 | goto err_out_free_vnic_resources; |
| 2147 | } |
| 2148 | |
| 2149 | enic_init_vnic_resources(enic); |
| 2150 | |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 2151 | err = enic_set_rss_nic_cfg(enic); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2152 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2153 | dev_err(dev, "Failed to config nic, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2154 | goto err_out_free_vnic_resources; |
| 2155 | } |
| 2156 | |
| 2157 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 2158 | default: |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 2159 | netif_napi_add(netdev, &enic->napi[0], enic_poll, 64); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | case VNIC_DEV_INTR_MODE_MSIX: |
Vasanthy Kolluri | 717258b | 2010-10-20 10:16:59 +0000 | [diff] [blame] | 2162 | for (i = 0; i < enic->rq_count; i++) |
| 2163 | netif_napi_add(netdev, &enic->napi[i], |
| 2164 | enic_poll_msix, 64); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2165 | break; |
| 2166 | } |
| 2167 | |
| 2168 | return 0; |
| 2169 | |
| 2170 | err_out_free_vnic_resources: |
| 2171 | enic_clear_intr_mode(enic); |
| 2172 | enic_free_vnic_resources(enic); |
| 2173 | |
| 2174 | return err; |
| 2175 | } |
| 2176 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 2177 | static void enic_iounmap(struct enic *enic) |
| 2178 | { |
| 2179 | unsigned int i; |
| 2180 | |
| 2181 | for (i = 0; i < ARRAY_SIZE(enic->bar); i++) |
| 2182 | if (enic->bar[i].vaddr) |
| 2183 | iounmap(enic->bar[i].vaddr); |
| 2184 | } |
| 2185 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 2186 | static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2187 | { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2188 | struct device *dev = &pdev->dev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2189 | struct net_device *netdev; |
| 2190 | struct enic *enic; |
| 2191 | int using_dac = 0; |
| 2192 | unsigned int i; |
| 2193 | int err; |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2194 | #ifdef CONFIG_PCI_IOV |
| 2195 | int pos = 0; |
| 2196 | #endif |
Roopa Prabhu | b67f231 | 2012-01-19 22:25:36 +0000 | [diff] [blame] | 2197 | int num_pps = 1; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2198 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2199 | /* Allocate net device structure and initialize. Private |
| 2200 | * instance data is initialized to zero. |
| 2201 | */ |
| 2202 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 2203 | netdev = alloc_etherdev_mqs(sizeof(struct enic), |
| 2204 | ENIC_RQ_MAX, ENIC_WQ_MAX); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 2205 | if (!netdev) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2206 | return -ENOMEM; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2207 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2208 | pci_set_drvdata(pdev, netdev); |
| 2209 | |
| 2210 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2211 | |
| 2212 | enic = netdev_priv(netdev); |
| 2213 | enic->netdev = netdev; |
| 2214 | enic->pdev = pdev; |
| 2215 | |
| 2216 | /* Setup PCI resources |
| 2217 | */ |
| 2218 | |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 2219 | err = pci_enable_device_mem(pdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2220 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2221 | dev_err(dev, "Cannot enable PCI device, aborting\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2222 | goto err_out_free_netdev; |
| 2223 | } |
| 2224 | |
| 2225 | err = pci_request_regions(pdev, DRV_NAME); |
| 2226 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2227 | dev_err(dev, "Cannot request PCI regions, aborting\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2228 | goto err_out_disable_device; |
| 2229 | } |
| 2230 | |
| 2231 | pci_set_master(pdev); |
| 2232 | |
| 2233 | /* Query PCI controller on system for DMA addressing |
govindarajulu.v | 624dbf5 | 2013-09-04 11:17:16 +0530 | [diff] [blame] | 2234 | * limitation for the device. Try 64-bit first, and |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2235 | * fail to 32-bit. |
| 2236 | */ |
| 2237 | |
govindarajulu.v | 624dbf5 | 2013-09-04 11:17:16 +0530 | [diff] [blame] | 2238 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2239 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2240 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2241 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2242 | dev_err(dev, "No usable DMA configuration, aborting\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2243 | goto err_out_release_regions; |
| 2244 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2245 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2246 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2247 | dev_err(dev, "Unable to obtain %u-bit DMA " |
| 2248 | "for consistent allocations, aborting\n", 32); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2249 | goto err_out_release_regions; |
| 2250 | } |
| 2251 | } else { |
govindarajulu.v | 624dbf5 | 2013-09-04 11:17:16 +0530 | [diff] [blame] | 2252 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2253 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2254 | dev_err(dev, "Unable to obtain %u-bit DMA " |
govindarajulu.v | 624dbf5 | 2013-09-04 11:17:16 +0530 | [diff] [blame] | 2255 | "for consistent allocations, aborting\n", 64); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2256 | goto err_out_release_regions; |
| 2257 | } |
| 2258 | using_dac = 1; |
| 2259 | } |
| 2260 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 2261 | /* Map vNIC resources from BAR0-5 |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2262 | */ |
| 2263 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 2264 | for (i = 0; i < ARRAY_SIZE(enic->bar); i++) { |
| 2265 | if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) |
| 2266 | continue; |
| 2267 | enic->bar[i].len = pci_resource_len(pdev, i); |
| 2268 | enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len); |
| 2269 | if (!enic->bar[i].vaddr) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2270 | dev_err(dev, "Cannot memory-map BAR %d, aborting\n", i); |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 2271 | err = -ENODEV; |
| 2272 | goto err_out_iounmap; |
| 2273 | } |
| 2274 | enic->bar[i].bus_addr = pci_resource_start(pdev, i); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | /* Register vNIC device |
| 2278 | */ |
| 2279 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 2280 | enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar, |
| 2281 | ARRAY_SIZE(enic->bar)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2282 | if (!enic->vdev) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2283 | dev_err(dev, "vNIC registration failed, aborting\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2284 | err = -ENODEV; |
| 2285 | goto err_out_iounmap; |
| 2286 | } |
| 2287 | |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2288 | #ifdef CONFIG_PCI_IOV |
| 2289 | /* Get number of subvnics */ |
| 2290 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 2291 | if (pos) { |
| 2292 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, |
Dan Carpenter | 413708b | 2012-02-29 21:19:54 +0000 | [diff] [blame] | 2293 | &enic->num_vfs); |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2294 | if (enic->num_vfs) { |
| 2295 | err = pci_enable_sriov(pdev, enic->num_vfs); |
| 2296 | if (err) { |
| 2297 | dev_err(dev, "SRIOV enable failed, aborting." |
| 2298 | " pci_enable_sriov() returned %d\n", |
| 2299 | err); |
| 2300 | goto err_out_vnic_unregister; |
| 2301 | } |
| 2302 | enic->priv_flags |= ENIC_SRIOV_ENABLED; |
Roopa Prabhu | b67f231 | 2012-01-19 22:25:36 +0000 | [diff] [blame] | 2303 | num_pps = enic->num_vfs; |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2304 | } |
| 2305 | } |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2306 | #endif |
Roopa Prabhu | ca2b721 | 2012-01-18 04:24:07 +0000 | [diff] [blame] | 2307 | |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2308 | /* Allocate structure for port profiles */ |
Thomas Meyer | a1de221 | 2011-11-29 11:08:00 +0000 | [diff] [blame] | 2309 | enic->pp = kcalloc(num_pps, sizeof(*enic->pp), GFP_KERNEL); |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2310 | if (!enic->pp) { |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2311 | err = -ENOMEM; |
Roopa Prabhu | ca2b721 | 2012-01-18 04:24:07 +0000 | [diff] [blame] | 2312 | goto err_out_disable_sriov_pp; |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2315 | /* Issue device open to get device in known state |
| 2316 | */ |
| 2317 | |
| 2318 | err = enic_dev_open(enic); |
| 2319 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2320 | dev_err(dev, "vNIC dev open failed, aborting\n"); |
Roopa Prabhu | ca2b721 | 2012-01-18 04:24:07 +0000 | [diff] [blame] | 2321 | goto err_out_disable_sriov; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Vasanthy Kolluri | 6916142 | 2011-02-04 16:17:16 +0000 | [diff] [blame] | 2324 | /* Setup devcmd lock |
| 2325 | */ |
| 2326 | |
| 2327 | spin_lock_init(&enic->devcmd_lock); |
Neel Patel | 0b03856 | 2013-08-16 15:47:40 -0700 | [diff] [blame] | 2328 | spin_lock_init(&enic->enic_api_lock); |
Vasanthy Kolluri | 6916142 | 2011-02-04 16:17:16 +0000 | [diff] [blame] | 2329 | |
| 2330 | /* |
| 2331 | * Set ingress vlan rewrite mode before vnic initialization |
| 2332 | */ |
| 2333 | |
| 2334 | err = enic_dev_set_ig_vlan_rewrite_mode(enic); |
| 2335 | if (err) { |
| 2336 | dev_err(dev, |
| 2337 | "Failed to set ingress vlan rewrite mode, aborting.\n"); |
| 2338 | goto err_out_dev_close; |
| 2339 | } |
| 2340 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2341 | /* Issue device init to initialize the vnic-to-switch link. |
| 2342 | * We'll start with carrier off and wait for link UP |
| 2343 | * notification later to turn on carrier. We don't need |
| 2344 | * to wait here for the vnic-to-switch link initialization |
| 2345 | * to complete; link UP notification is the indication that |
| 2346 | * the process is complete. |
| 2347 | */ |
| 2348 | |
| 2349 | netif_carrier_off(netdev); |
| 2350 | |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2351 | /* Do not call dev_init for a dynamic vnic. |
| 2352 | * For a dynamic vnic, init_prov_info will be |
| 2353 | * called later by an upper layer. |
| 2354 | */ |
| 2355 | |
Roopa Prabhu | 2b68c18 | 2012-02-20 00:12:04 +0000 | [diff] [blame] | 2356 | if (!enic_is_dynamic(enic)) { |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2357 | err = vnic_dev_init(enic->vdev, 0); |
| 2358 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2359 | dev_err(dev, "vNIC dev init failed, aborting\n"); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2360 | goto err_out_dev_close; |
| 2361 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2364 | err = enic_dev_init(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2365 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2366 | dev_err(dev, "Device initialization failed, aborting\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2367 | goto err_out_dev_close; |
| 2368 | } |
| 2369 | |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 2370 | netif_set_real_num_tx_queues(netdev, enic->wq_count); |
govindarajulu.v | bf751ba | 2013-09-04 11:17:15 +0530 | [diff] [blame] | 2371 | netif_set_real_num_rx_queues(netdev, enic->rq_count); |
govindarajulu.v | 822473b | 2013-09-04 11:17:14 +0530 | [diff] [blame] | 2372 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 2373 | /* Setup notification timer, HW reset task, and wq locks |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2374 | */ |
| 2375 | |
| 2376 | init_timer(&enic->notify_timer); |
| 2377 | enic->notify_timer.function = enic_notify_timer; |
| 2378 | enic->notify_timer.data = (unsigned long)enic; |
| 2379 | |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 2380 | enic_set_rx_coal_setting(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2381 | INIT_WORK(&enic->reset, enic_reset); |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 2382 | INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2383 | |
| 2384 | for (i = 0; i < enic->wq_count; i++) |
| 2385 | spin_lock_init(&enic->wq_lock[i]); |
| 2386 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2387 | /* Register net device |
| 2388 | */ |
| 2389 | |
| 2390 | enic->port_mtu = enic->config.mtu; |
| 2391 | (void)enic_change_mtu(netdev, enic->port_mtu); |
| 2392 | |
| 2393 | err = enic_set_mac_addr(netdev, enic->mac_addr); |
| 2394 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2395 | dev_err(dev, "Invalid MAC address, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2396 | goto err_out_dev_deinit; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Scott Feldman | 7c84459 | 2009-12-23 13:27:54 +0000 | [diff] [blame] | 2399 | enic->tx_coalesce_usecs = enic->config.intr_timer_usec; |
Sujith Sankar | 7c2ce6e | 2014-05-20 03:14:05 +0530 | [diff] [blame^] | 2400 | /* rx coalesce time already got initialized. This gets used |
| 2401 | * if adaptive coal is turned off |
| 2402 | */ |
Scott Feldman | 7c84459 | 2009-12-23 13:27:54 +0000 | [diff] [blame] | 2403 | enic->rx_coalesce_usecs = enic->tx_coalesce_usecs; |
| 2404 | |
Roopa Prabhu | 7335903 | 2012-01-18 04:24:02 +0000 | [diff] [blame] | 2405 | if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 2406 | netdev->netdev_ops = &enic_netdev_dynamic_ops; |
| 2407 | else |
| 2408 | netdev->netdev_ops = &enic_netdev_ops; |
| 2409 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2410 | netdev->watchdog_timeo = 2 * HZ; |
Neel Patel | f13bbc2 | 2013-07-22 09:59:18 -0700 | [diff] [blame] | 2411 | enic_set_ethtool_ops(netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2412 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2413 | netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 2414 | if (ENIC_SETTING(enic, LOOP)) { |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2415 | netdev->features &= ~NETIF_F_HW_VLAN_CTAG_TX; |
Vasanthy Kolluri | 1825aca | 2010-06-24 10:51:59 +0000 | [diff] [blame] | 2416 | enic->loop_enable = 1; |
| 2417 | enic->loop_tag = enic->config.loop_tag; |
| 2418 | dev_info(dev, "loopback tag=0x%04x\n", enic->loop_tag); |
| 2419 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2420 | if (ENIC_SETTING(enic, TXCSUM)) |
Michał Mirosław | 5ec8f9b | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2421 | netdev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2422 | if (ENIC_SETTING(enic, TSO)) |
Michał Mirosław | 5ec8f9b | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2423 | netdev->hw_features |= NETIF_F_TSO | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2424 | NETIF_F_TSO6 | NETIF_F_TSO_ECN; |
govindarajulu.v | bf751ba | 2013-09-04 11:17:15 +0530 | [diff] [blame] | 2425 | if (ENIC_SETTING(enic, RSS)) |
| 2426 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 5ec8f9b | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2427 | if (ENIC_SETTING(enic, RXCSUM)) |
| 2428 | netdev->hw_features |= NETIF_F_RXCSUM; |
| 2429 | |
| 2430 | netdev->features |= netdev->hw_features; |
| 2431 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2432 | if (using_dac) |
| 2433 | netdev->features |= NETIF_F_HIGHDMA; |
| 2434 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 2435 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 2436 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2437 | err = register_netdev(netdev); |
| 2438 | if (err) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2439 | dev_err(dev, "Cannot register net device, aborting\n"); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2440 | goto err_out_dev_deinit; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | return 0; |
| 2444 | |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2445 | err_out_dev_deinit: |
| 2446 | enic_dev_deinit(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2447 | err_out_dev_close: |
| 2448 | vnic_dev_close(enic->vdev); |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2449 | err_out_disable_sriov: |
Roopa Prabhu | ca2b721 | 2012-01-18 04:24:07 +0000 | [diff] [blame] | 2450 | kfree(enic->pp); |
| 2451 | err_out_disable_sriov_pp: |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2452 | #ifdef CONFIG_PCI_IOV |
| 2453 | if (enic_sriov_enabled(enic)) { |
| 2454 | pci_disable_sriov(pdev); |
| 2455 | enic->priv_flags &= ~ENIC_SRIOV_ENABLED; |
| 2456 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2457 | err_out_vnic_unregister: |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2458 | #endif |
Roopa Prabhu | 35d87e3 | 2012-01-18 04:24:12 +0000 | [diff] [blame] | 2459 | vnic_dev_unregister(enic->vdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2460 | err_out_iounmap: |
| 2461 | enic_iounmap(enic); |
| 2462 | err_out_release_regions: |
| 2463 | pci_release_regions(pdev); |
| 2464 | err_out_disable_device: |
| 2465 | pci_disable_device(pdev); |
| 2466 | err_out_free_netdev: |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2467 | free_netdev(netdev); |
| 2468 | |
| 2469 | return err; |
| 2470 | } |
| 2471 | |
Bill Pemberton | 854de92 | 2012-12-03 09:23:05 -0500 | [diff] [blame] | 2472 | static void enic_remove(struct pci_dev *pdev) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2473 | { |
| 2474 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2475 | |
| 2476 | if (netdev) { |
| 2477 | struct enic *enic = netdev_priv(netdev); |
| 2478 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 2479 | cancel_work_sync(&enic->reset); |
Roopa Prabhu | c97c894 | 2011-06-03 14:35:17 +0000 | [diff] [blame] | 2480 | cancel_work_sync(&enic->change_mtu_work); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2481 | unregister_netdev(netdev); |
Scott Feldman | 6fdfa97 | 2009-09-03 17:02:45 +0000 | [diff] [blame] | 2482 | enic_dev_deinit(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2483 | vnic_dev_close(enic->vdev); |
Roopa Prabhu | 8749b42 | 2011-09-22 03:44:33 +0000 | [diff] [blame] | 2484 | #ifdef CONFIG_PCI_IOV |
| 2485 | if (enic_sriov_enabled(enic)) { |
| 2486 | pci_disable_sriov(pdev); |
| 2487 | enic->priv_flags &= ~ENIC_SRIOV_ENABLED; |
| 2488 | } |
| 2489 | #endif |
Roopa Prabhu | 3f19279 | 2011-09-22 03:44:43 +0000 | [diff] [blame] | 2490 | kfree(enic->pp); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2491 | vnic_dev_unregister(enic->vdev); |
| 2492 | enic_iounmap(enic); |
| 2493 | pci_release_regions(pdev); |
| 2494 | pci_disable_device(pdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2495 | free_netdev(netdev); |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | static struct pci_driver enic_driver = { |
| 2500 | .name = DRV_NAME, |
| 2501 | .id_table = enic_id_table, |
| 2502 | .probe = enic_probe, |
Bill Pemberton | 854de92 | 2012-12-03 09:23:05 -0500 | [diff] [blame] | 2503 | .remove = enic_remove, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2504 | }; |
| 2505 | |
| 2506 | static int __init enic_init_module(void) |
| 2507 | { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame] | 2508 | pr_info("%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 2509 | |
| 2510 | return pci_register_driver(&enic_driver); |
| 2511 | } |
| 2512 | |
| 2513 | static void __exit enic_cleanup_module(void) |
| 2514 | { |
| 2515 | pci_unregister_driver(&enic_driver); |
| 2516 | } |
| 2517 | |
| 2518 | module_init(enic_init_module); |
| 2519 | module_exit(enic_cleanup_module); |