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