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