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