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