Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. |
| 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> |
Kamalesh Babulal | b7c6bfb | 2008-10-13 18:41:01 -0700 | [diff] [blame] | 37 | #include <net/ip6_checksum.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 38 | |
| 39 | #include "cq_enet_desc.h" |
| 40 | #include "vnic_dev.h" |
| 41 | #include "vnic_intr.h" |
| 42 | #include "vnic_stats.h" |
| 43 | #include "enic_res.h" |
| 44 | #include "enic.h" |
| 45 | |
| 46 | #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 47 | |
| 48 | /* Supported devices */ |
| 49 | static struct pci_device_id enic_id_table[] = { |
| 50 | { PCI_VDEVICE(CISCO, 0x0043) }, |
| 51 | { 0, } /* end of table */ |
| 52 | }; |
| 53 | |
| 54 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 55 | MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>"); |
| 56 | MODULE_LICENSE("GPL"); |
| 57 | MODULE_VERSION(DRV_VERSION); |
| 58 | MODULE_DEVICE_TABLE(pci, enic_id_table); |
| 59 | |
| 60 | struct enic_stat { |
| 61 | char name[ETH_GSTRING_LEN]; |
| 62 | unsigned int offset; |
| 63 | }; |
| 64 | |
| 65 | #define ENIC_TX_STAT(stat) \ |
| 66 | { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 } |
| 67 | #define ENIC_RX_STAT(stat) \ |
| 68 | { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 } |
| 69 | |
| 70 | static const struct enic_stat enic_tx_stats[] = { |
| 71 | ENIC_TX_STAT(tx_frames_ok), |
| 72 | ENIC_TX_STAT(tx_unicast_frames_ok), |
| 73 | ENIC_TX_STAT(tx_multicast_frames_ok), |
| 74 | ENIC_TX_STAT(tx_broadcast_frames_ok), |
| 75 | ENIC_TX_STAT(tx_bytes_ok), |
| 76 | ENIC_TX_STAT(tx_unicast_bytes_ok), |
| 77 | ENIC_TX_STAT(tx_multicast_bytes_ok), |
| 78 | ENIC_TX_STAT(tx_broadcast_bytes_ok), |
| 79 | ENIC_TX_STAT(tx_drops), |
| 80 | ENIC_TX_STAT(tx_errors), |
| 81 | ENIC_TX_STAT(tx_tso), |
| 82 | }; |
| 83 | |
| 84 | static const struct enic_stat enic_rx_stats[] = { |
| 85 | ENIC_RX_STAT(rx_frames_ok), |
| 86 | ENIC_RX_STAT(rx_frames_total), |
| 87 | ENIC_RX_STAT(rx_unicast_frames_ok), |
| 88 | ENIC_RX_STAT(rx_multicast_frames_ok), |
| 89 | ENIC_RX_STAT(rx_broadcast_frames_ok), |
| 90 | ENIC_RX_STAT(rx_bytes_ok), |
| 91 | ENIC_RX_STAT(rx_unicast_bytes_ok), |
| 92 | ENIC_RX_STAT(rx_multicast_bytes_ok), |
| 93 | ENIC_RX_STAT(rx_broadcast_bytes_ok), |
| 94 | ENIC_RX_STAT(rx_drop), |
| 95 | ENIC_RX_STAT(rx_no_bufs), |
| 96 | ENIC_RX_STAT(rx_errors), |
| 97 | ENIC_RX_STAT(rx_rss), |
| 98 | ENIC_RX_STAT(rx_crc_errors), |
| 99 | ENIC_RX_STAT(rx_frames_64), |
| 100 | ENIC_RX_STAT(rx_frames_127), |
| 101 | ENIC_RX_STAT(rx_frames_255), |
| 102 | ENIC_RX_STAT(rx_frames_511), |
| 103 | ENIC_RX_STAT(rx_frames_1023), |
| 104 | ENIC_RX_STAT(rx_frames_1518), |
| 105 | ENIC_RX_STAT(rx_frames_to_max), |
| 106 | }; |
| 107 | |
| 108 | static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats); |
| 109 | static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats); |
| 110 | |
| 111 | static int enic_get_settings(struct net_device *netdev, |
| 112 | struct ethtool_cmd *ecmd) |
| 113 | { |
| 114 | struct enic *enic = netdev_priv(netdev); |
| 115 | |
| 116 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); |
| 117 | ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); |
| 118 | ecmd->port = PORT_FIBRE; |
| 119 | ecmd->transceiver = XCVR_EXTERNAL; |
| 120 | |
| 121 | if (netif_carrier_ok(netdev)) { |
| 122 | ecmd->speed = vnic_dev_port_speed(enic->vdev); |
| 123 | ecmd->duplex = DUPLEX_FULL; |
| 124 | } else { |
| 125 | ecmd->speed = -1; |
| 126 | ecmd->duplex = -1; |
| 127 | } |
| 128 | |
| 129 | ecmd->autoneg = AUTONEG_DISABLE; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static void enic_get_drvinfo(struct net_device *netdev, |
| 135 | struct ethtool_drvinfo *drvinfo) |
| 136 | { |
| 137 | struct enic *enic = netdev_priv(netdev); |
| 138 | struct vnic_devcmd_fw_info *fw_info; |
| 139 | |
| 140 | spin_lock(&enic->devcmd_lock); |
| 141 | vnic_dev_fw_info(enic->vdev, &fw_info); |
| 142 | spin_unlock(&enic->devcmd_lock); |
| 143 | |
| 144 | strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 145 | strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version)); |
| 146 | strncpy(drvinfo->fw_version, fw_info->fw_version, |
| 147 | sizeof(drvinfo->fw_version)); |
| 148 | strncpy(drvinfo->bus_info, pci_name(enic->pdev), |
| 149 | sizeof(drvinfo->bus_info)); |
| 150 | } |
| 151 | |
| 152 | static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data) |
| 153 | { |
| 154 | unsigned int i; |
| 155 | |
| 156 | switch (stringset) { |
| 157 | case ETH_SS_STATS: |
| 158 | for (i = 0; i < enic_n_tx_stats; i++) { |
| 159 | memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN); |
| 160 | data += ETH_GSTRING_LEN; |
| 161 | } |
| 162 | for (i = 0; i < enic_n_rx_stats; i++) { |
| 163 | memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN); |
| 164 | data += ETH_GSTRING_LEN; |
| 165 | } |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 170 | static int enic_get_sset_count(struct net_device *netdev, int sset) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 171 | { |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 172 | switch (sset) { |
| 173 | case ETH_SS_STATS: |
| 174 | return enic_n_tx_stats + enic_n_rx_stats; |
| 175 | default: |
| 176 | return -EOPNOTSUPP; |
| 177 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void enic_get_ethtool_stats(struct net_device *netdev, |
| 181 | struct ethtool_stats *stats, u64 *data) |
| 182 | { |
| 183 | struct enic *enic = netdev_priv(netdev); |
| 184 | struct vnic_stats *vstats; |
| 185 | unsigned int i; |
| 186 | |
| 187 | spin_lock(&enic->devcmd_lock); |
| 188 | vnic_dev_stats_dump(enic->vdev, &vstats); |
| 189 | spin_unlock(&enic->devcmd_lock); |
| 190 | |
| 191 | for (i = 0; i < enic_n_tx_stats; i++) |
| 192 | *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset]; |
| 193 | for (i = 0; i < enic_n_rx_stats; i++) |
| 194 | *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset]; |
| 195 | } |
| 196 | |
| 197 | static u32 enic_get_rx_csum(struct net_device *netdev) |
| 198 | { |
| 199 | struct enic *enic = netdev_priv(netdev); |
| 200 | return enic->csum_rx_enabled; |
| 201 | } |
| 202 | |
| 203 | static int enic_set_rx_csum(struct net_device *netdev, u32 data) |
| 204 | { |
| 205 | struct enic *enic = netdev_priv(netdev); |
| 206 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 207 | if (data && !ENIC_SETTING(enic, RXCSUM)) |
| 208 | return -EINVAL; |
| 209 | |
| 210 | enic->csum_rx_enabled = !!data; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int enic_set_tx_csum(struct net_device *netdev, u32 data) |
| 216 | { |
| 217 | struct enic *enic = netdev_priv(netdev); |
| 218 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 219 | if (data && !ENIC_SETTING(enic, TXCSUM)) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | if (data) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 223 | netdev->features |= NETIF_F_HW_CSUM; |
| 224 | else |
| 225 | netdev->features &= ~NETIF_F_HW_CSUM; |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static int enic_set_tso(struct net_device *netdev, u32 data) |
| 231 | { |
| 232 | struct enic *enic = netdev_priv(netdev); |
| 233 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 234 | if (data && !ENIC_SETTING(enic, TSO)) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | if (data) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 238 | netdev->features |= |
| 239 | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN; |
| 240 | else |
| 241 | netdev->features &= |
| 242 | ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static u32 enic_get_msglevel(struct net_device *netdev) |
| 248 | { |
| 249 | struct enic *enic = netdev_priv(netdev); |
| 250 | return enic->msg_enable; |
| 251 | } |
| 252 | |
| 253 | static void enic_set_msglevel(struct net_device *netdev, u32 value) |
| 254 | { |
| 255 | struct enic *enic = netdev_priv(netdev); |
| 256 | enic->msg_enable = value; |
| 257 | } |
| 258 | |
| 259 | static struct ethtool_ops enic_ethtool_ops = { |
| 260 | .get_settings = enic_get_settings, |
| 261 | .get_drvinfo = enic_get_drvinfo, |
| 262 | .get_msglevel = enic_get_msglevel, |
| 263 | .set_msglevel = enic_set_msglevel, |
| 264 | .get_link = ethtool_op_get_link, |
| 265 | .get_strings = enic_get_strings, |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 266 | .get_sset_count = enic_get_sset_count, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 267 | .get_ethtool_stats = enic_get_ethtool_stats, |
| 268 | .get_rx_csum = enic_get_rx_csum, |
| 269 | .set_rx_csum = enic_set_rx_csum, |
| 270 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 271 | .set_tx_csum = enic_set_tx_csum, |
| 272 | .get_sg = ethtool_op_get_sg, |
| 273 | .set_sg = ethtool_op_set_sg, |
| 274 | .get_tso = ethtool_op_get_tso, |
| 275 | .set_tso = enic_set_tso, |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 276 | .get_flags = ethtool_op_get_flags, |
| 277 | .set_flags = ethtool_op_set_flags, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) |
| 281 | { |
| 282 | struct enic *enic = vnic_dev_priv(wq->vdev); |
| 283 | |
| 284 | if (buf->sop) |
| 285 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 286 | buf->len, PCI_DMA_TODEVICE); |
| 287 | else |
| 288 | pci_unmap_page(enic->pdev, buf->dma_addr, |
| 289 | buf->len, PCI_DMA_TODEVICE); |
| 290 | |
| 291 | if (buf->os_buf) |
| 292 | dev_kfree_skb_any(buf->os_buf); |
| 293 | } |
| 294 | |
| 295 | static void enic_wq_free_buf(struct vnic_wq *wq, |
| 296 | struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque) |
| 297 | { |
| 298 | enic_free_wq_buf(wq, buf); |
| 299 | } |
| 300 | |
| 301 | static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, |
| 302 | u8 type, u16 q_number, u16 completed_index, void *opaque) |
| 303 | { |
| 304 | struct enic *enic = vnic_dev_priv(vdev); |
| 305 | |
| 306 | spin_lock(&enic->wq_lock[q_number]); |
| 307 | |
| 308 | vnic_wq_service(&enic->wq[q_number], cq_desc, |
| 309 | completed_index, enic_wq_free_buf, |
| 310 | opaque); |
| 311 | |
| 312 | if (netif_queue_stopped(enic->netdev) && |
| 313 | vnic_wq_desc_avail(&enic->wq[q_number]) >= MAX_SKB_FRAGS + 1) |
| 314 | netif_wake_queue(enic->netdev); |
| 315 | |
| 316 | spin_unlock(&enic->wq_lock[q_number]); |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static void enic_log_q_error(struct enic *enic) |
| 322 | { |
| 323 | unsigned int i; |
| 324 | u32 error_status; |
| 325 | |
| 326 | for (i = 0; i < enic->wq_count; i++) { |
| 327 | error_status = vnic_wq_error_status(&enic->wq[i]); |
| 328 | if (error_status) |
| 329 | printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n", |
| 330 | enic->netdev->name, i, error_status); |
| 331 | } |
| 332 | |
| 333 | for (i = 0; i < enic->rq_count; i++) { |
| 334 | error_status = vnic_rq_error_status(&enic->rq[i]); |
| 335 | if (error_status) |
| 336 | printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n", |
| 337 | enic->netdev->name, i, error_status); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static void enic_link_check(struct enic *enic) |
| 342 | { |
| 343 | int link_status = vnic_dev_link_status(enic->vdev); |
| 344 | int carrier_ok = netif_carrier_ok(enic->netdev); |
| 345 | |
| 346 | if (link_status && !carrier_ok) { |
| 347 | printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name); |
| 348 | netif_carrier_on(enic->netdev); |
| 349 | } else if (!link_status && carrier_ok) { |
| 350 | printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name); |
| 351 | netif_carrier_off(enic->netdev); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | static void enic_mtu_check(struct enic *enic) |
| 356 | { |
| 357 | u32 mtu = vnic_dev_mtu(enic->vdev); |
| 358 | |
| 359 | if (mtu != enic->port_mtu) { |
| 360 | if (mtu < enic->netdev->mtu) |
| 361 | printk(KERN_WARNING PFX |
| 362 | "%s: interface MTU (%d) set higher " |
| 363 | "than switch port MTU (%d)\n", |
| 364 | enic->netdev->name, enic->netdev->mtu, mtu); |
| 365 | enic->port_mtu = mtu; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | static void enic_msglvl_check(struct enic *enic) |
| 370 | { |
| 371 | u32 msg_enable = vnic_dev_msg_lvl(enic->vdev); |
| 372 | |
| 373 | if (msg_enable != enic->msg_enable) { |
| 374 | printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n", |
| 375 | enic->netdev->name, enic->msg_enable, msg_enable); |
| 376 | enic->msg_enable = msg_enable; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static void enic_notify_check(struct enic *enic) |
| 381 | { |
| 382 | enic_msglvl_check(enic); |
| 383 | enic_mtu_check(enic); |
| 384 | enic_link_check(enic); |
| 385 | } |
| 386 | |
| 387 | #define ENIC_TEST_INTR(pba, i) (pba & (1 << i)) |
| 388 | |
| 389 | static irqreturn_t enic_isr_legacy(int irq, void *data) |
| 390 | { |
| 391 | struct net_device *netdev = data; |
| 392 | struct enic *enic = netdev_priv(netdev); |
| 393 | u32 pba; |
| 394 | |
| 395 | vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]); |
| 396 | |
| 397 | pba = vnic_intr_legacy_pba(enic->legacy_pba); |
| 398 | if (!pba) { |
| 399 | vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]); |
| 400 | return IRQ_NONE; /* not our interrupt */ |
| 401 | } |
| 402 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 403 | if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY)) { |
| 404 | vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_NOTIFY]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 405 | enic_notify_check(enic); |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 406 | } |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 407 | |
| 408 | if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) { |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 409 | vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_ERR]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 410 | enic_log_q_error(enic); |
| 411 | /* schedule recovery from WQ/RQ error */ |
| 412 | schedule_work(&enic->reset); |
| 413 | return IRQ_HANDLED; |
| 414 | } |
| 415 | |
| 416 | if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 417 | if (napi_schedule_prep(&enic->napi)) |
| 418 | __napi_schedule(&enic->napi); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 419 | } else { |
| 420 | vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]); |
| 421 | } |
| 422 | |
| 423 | return IRQ_HANDLED; |
| 424 | } |
| 425 | |
| 426 | static irqreturn_t enic_isr_msi(int irq, void *data) |
| 427 | { |
| 428 | struct enic *enic = data; |
| 429 | |
| 430 | /* With MSI, there is no sharing of interrupts, so this is |
| 431 | * our interrupt and there is no need to ack it. The device |
| 432 | * is not providing per-vector masking, so the OS will not |
| 433 | * write to PCI config space to mask/unmask the interrupt. |
| 434 | * We're using mask_on_assertion for MSI, so the device |
| 435 | * automatically masks the interrupt when the interrupt is |
| 436 | * generated. Later, when exiting polling, the interrupt |
| 437 | * will be unmasked (see enic_poll). |
| 438 | * |
| 439 | * Also, the device uses the same PCIe Traffic Class (TC) |
| 440 | * for Memory Write data and MSI, so there are no ordering |
| 441 | * issues; the MSI will always arrive at the Root Complex |
| 442 | * _after_ corresponding Memory Writes (i.e. descriptor |
| 443 | * writes). |
| 444 | */ |
| 445 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 446 | napi_schedule(&enic->napi); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 447 | |
| 448 | return IRQ_HANDLED; |
| 449 | } |
| 450 | |
| 451 | static irqreturn_t enic_isr_msix_rq(int irq, void *data) |
| 452 | { |
| 453 | struct enic *enic = data; |
| 454 | |
| 455 | /* schedule NAPI polling for RQ cleanup */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 456 | napi_schedule(&enic->napi); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 457 | |
| 458 | return IRQ_HANDLED; |
| 459 | } |
| 460 | |
| 461 | static irqreturn_t enic_isr_msix_wq(int irq, void *data) |
| 462 | { |
| 463 | struct enic *enic = data; |
| 464 | unsigned int wq_work_to_do = -1; /* no limit */ |
| 465 | unsigned int wq_work_done; |
| 466 | |
| 467 | wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ], |
| 468 | wq_work_to_do, enic_wq_service, NULL); |
| 469 | |
| 470 | vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ], |
| 471 | wq_work_done, |
| 472 | 1 /* unmask intr */, |
| 473 | 1 /* reset intr timer */); |
| 474 | |
| 475 | return IRQ_HANDLED; |
| 476 | } |
| 477 | |
| 478 | static irqreturn_t enic_isr_msix_err(int irq, void *data) |
| 479 | { |
| 480 | struct enic *enic = data; |
| 481 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 482 | vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_ERR]); |
| 483 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 484 | enic_log_q_error(enic); |
| 485 | |
| 486 | /* schedule recovery from WQ/RQ error */ |
| 487 | schedule_work(&enic->reset); |
| 488 | |
| 489 | return IRQ_HANDLED; |
| 490 | } |
| 491 | |
| 492 | static irqreturn_t enic_isr_msix_notify(int irq, void *data) |
| 493 | { |
| 494 | struct enic *enic = data; |
| 495 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 496 | vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_NOTIFY]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 497 | enic_notify_check(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 498 | |
| 499 | return IRQ_HANDLED; |
| 500 | } |
| 501 | |
| 502 | static inline void enic_queue_wq_skb_cont(struct enic *enic, |
| 503 | struct vnic_wq *wq, struct sk_buff *skb, |
| 504 | unsigned int len_left) |
| 505 | { |
| 506 | skb_frag_t *frag; |
| 507 | |
| 508 | /* Queue additional data fragments */ |
| 509 | for (frag = skb_shinfo(skb)->frags; len_left; frag++) { |
| 510 | len_left -= frag->size; |
| 511 | enic_queue_wq_desc_cont(wq, skb, |
| 512 | pci_map_page(enic->pdev, frag->page, |
| 513 | frag->page_offset, frag->size, |
| 514 | PCI_DMA_TODEVICE), |
| 515 | frag->size, |
| 516 | (len_left == 0)); /* EOP? */ |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | static inline void enic_queue_wq_skb_vlan(struct enic *enic, |
| 521 | struct vnic_wq *wq, struct sk_buff *skb, |
| 522 | int vlan_tag_insert, unsigned int vlan_tag) |
| 523 | { |
| 524 | unsigned int head_len = skb_headlen(skb); |
| 525 | unsigned int len_left = skb->len - head_len; |
| 526 | int eop = (len_left == 0); |
| 527 | |
| 528 | /* Queue the main skb fragment */ |
| 529 | enic_queue_wq_desc(wq, skb, |
| 530 | pci_map_single(enic->pdev, skb->data, |
| 531 | head_len, PCI_DMA_TODEVICE), |
| 532 | head_len, |
| 533 | vlan_tag_insert, vlan_tag, |
| 534 | eop); |
| 535 | |
| 536 | if (!eop) |
| 537 | enic_queue_wq_skb_cont(enic, wq, skb, len_left); |
| 538 | } |
| 539 | |
| 540 | static inline void enic_queue_wq_skb_csum_l4(struct enic *enic, |
| 541 | struct vnic_wq *wq, struct sk_buff *skb, |
| 542 | int vlan_tag_insert, unsigned int vlan_tag) |
| 543 | { |
| 544 | unsigned int head_len = skb_headlen(skb); |
| 545 | unsigned int len_left = skb->len - head_len; |
| 546 | unsigned int hdr_len = skb_transport_offset(skb); |
| 547 | unsigned int csum_offset = hdr_len + skb->csum_offset; |
| 548 | int eop = (len_left == 0); |
| 549 | |
| 550 | /* Queue the main skb fragment */ |
| 551 | enic_queue_wq_desc_csum_l4(wq, skb, |
| 552 | pci_map_single(enic->pdev, skb->data, |
| 553 | head_len, PCI_DMA_TODEVICE), |
| 554 | head_len, |
| 555 | csum_offset, |
| 556 | hdr_len, |
| 557 | vlan_tag_insert, vlan_tag, |
| 558 | eop); |
| 559 | |
| 560 | if (!eop) |
| 561 | enic_queue_wq_skb_cont(enic, wq, skb, len_left); |
| 562 | } |
| 563 | |
| 564 | static inline void enic_queue_wq_skb_tso(struct enic *enic, |
| 565 | struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss, |
| 566 | int vlan_tag_insert, unsigned int vlan_tag) |
| 567 | { |
| 568 | unsigned int head_len = skb_headlen(skb); |
| 569 | unsigned int len_left = skb->len - head_len; |
| 570 | unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 571 | int eop = (len_left == 0); |
| 572 | |
| 573 | /* Preload TCP csum field with IP pseudo hdr calculated |
| 574 | * with IP length set to zero. HW will later add in length |
| 575 | * to each TCP segment resulting from the TSO. |
| 576 | */ |
| 577 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 578 | if (skb->protocol == cpu_to_be16(ETH_P_IP)) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 579 | ip_hdr(skb)->check = 0; |
| 580 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 581 | ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 582 | } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) { |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 583 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 584 | &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
| 585 | } |
| 586 | |
| 587 | /* Queue the main skb fragment */ |
| 588 | enic_queue_wq_desc_tso(wq, skb, |
| 589 | pci_map_single(enic->pdev, skb->data, |
| 590 | head_len, PCI_DMA_TODEVICE), |
| 591 | head_len, |
| 592 | mss, hdr_len, |
| 593 | vlan_tag_insert, vlan_tag, |
| 594 | eop); |
| 595 | |
| 596 | if (!eop) |
| 597 | enic_queue_wq_skb_cont(enic, wq, skb, len_left); |
| 598 | } |
| 599 | |
| 600 | static inline void enic_queue_wq_skb(struct enic *enic, |
| 601 | struct vnic_wq *wq, struct sk_buff *skb) |
| 602 | { |
| 603 | unsigned int mss = skb_shinfo(skb)->gso_size; |
| 604 | unsigned int vlan_tag = 0; |
| 605 | int vlan_tag_insert = 0; |
| 606 | |
| 607 | if (enic->vlan_group && vlan_tx_tag_present(skb)) { |
| 608 | /* VLAN tag from trunking driver */ |
| 609 | vlan_tag_insert = 1; |
| 610 | vlan_tag = vlan_tx_tag_get(skb); |
| 611 | } |
| 612 | |
| 613 | if (mss) |
| 614 | enic_queue_wq_skb_tso(enic, wq, skb, mss, |
| 615 | vlan_tag_insert, vlan_tag); |
| 616 | else if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 617 | enic_queue_wq_skb_csum_l4(enic, wq, skb, |
| 618 | vlan_tag_insert, vlan_tag); |
| 619 | else |
| 620 | enic_queue_wq_skb_vlan(enic, wq, skb, |
| 621 | vlan_tag_insert, vlan_tag); |
| 622 | } |
| 623 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 624 | /* netif_tx_lock held, process context with BHs disabled, or BH */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 625 | static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 626 | { |
| 627 | struct enic *enic = netdev_priv(netdev); |
| 628 | struct vnic_wq *wq = &enic->wq[0]; |
| 629 | unsigned long flags; |
| 630 | |
| 631 | if (skb->len <= 0) { |
| 632 | dev_kfree_skb(skb); |
| 633 | return NETDEV_TX_OK; |
| 634 | } |
| 635 | |
| 636 | /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs, |
| 637 | * which is very likely. In the off chance it's going to take |
| 638 | * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb. |
| 639 | */ |
| 640 | |
| 641 | if (skb_shinfo(skb)->gso_size == 0 && |
| 642 | skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC && |
| 643 | skb_linearize(skb)) { |
| 644 | dev_kfree_skb(skb); |
| 645 | return NETDEV_TX_OK; |
| 646 | } |
| 647 | |
| 648 | spin_lock_irqsave(&enic->wq_lock[0], flags); |
| 649 | |
| 650 | if (vnic_wq_desc_avail(wq) < skb_shinfo(skb)->nr_frags + 1) { |
| 651 | netif_stop_queue(netdev); |
| 652 | /* This is a hard error, log it */ |
| 653 | printk(KERN_ERR PFX "%s: BUG! Tx ring full when " |
| 654 | "queue awake!\n", netdev->name); |
| 655 | spin_unlock_irqrestore(&enic->wq_lock[0], flags); |
| 656 | return NETDEV_TX_BUSY; |
| 657 | } |
| 658 | |
| 659 | enic_queue_wq_skb(enic, wq, skb); |
| 660 | |
| 661 | if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + 1) |
| 662 | netif_stop_queue(netdev); |
| 663 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 664 | spin_unlock_irqrestore(&enic->wq_lock[0], flags); |
| 665 | |
| 666 | return NETDEV_TX_OK; |
| 667 | } |
| 668 | |
| 669 | /* dev_base_lock rwlock held, nominally process context */ |
| 670 | static struct net_device_stats *enic_get_stats(struct net_device *netdev) |
| 671 | { |
| 672 | struct enic *enic = netdev_priv(netdev); |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 673 | struct net_device_stats *net_stats = &netdev->stats; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 674 | struct vnic_stats *stats; |
| 675 | |
| 676 | spin_lock(&enic->devcmd_lock); |
| 677 | vnic_dev_stats_dump(enic->vdev, &stats); |
| 678 | spin_unlock(&enic->devcmd_lock); |
| 679 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 680 | net_stats->tx_packets = stats->tx.tx_frames_ok; |
| 681 | net_stats->tx_bytes = stats->tx.tx_bytes_ok; |
| 682 | net_stats->tx_errors = stats->tx.tx_errors; |
| 683 | net_stats->tx_dropped = stats->tx.tx_drops; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 684 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 685 | net_stats->rx_packets = stats->rx.rx_frames_ok; |
| 686 | net_stats->rx_bytes = stats->rx.rx_bytes_ok; |
| 687 | net_stats->rx_errors = stats->rx.rx_errors; |
| 688 | net_stats->multicast = stats->rx.rx_multicast_frames_ok; |
Scott Feldman | bd9fb1a | 2009-02-09 23:24:08 -0800 | [diff] [blame] | 689 | net_stats->rx_crc_errors = enic->rq_bad_fcs; |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 690 | net_stats->rx_dropped = stats->rx.rx_no_bufs; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 691 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 692 | return net_stats; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void enic_reset_mcaddrs(struct enic *enic) |
| 696 | { |
| 697 | enic->mc_count = 0; |
| 698 | } |
| 699 | |
| 700 | static int enic_set_mac_addr(struct net_device *netdev, char *addr) |
| 701 | { |
| 702 | if (!is_valid_ether_addr(addr)) |
| 703 | return -EADDRNOTAVAIL; |
| 704 | |
| 705 | memcpy(netdev->dev_addr, addr, netdev->addr_len); |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | /* netif_tx_lock held, BHs disabled */ |
| 711 | static void enic_set_multicast_list(struct net_device *netdev) |
| 712 | { |
| 713 | struct enic *enic = netdev_priv(netdev); |
| 714 | struct dev_mc_list *list = netdev->mc_list; |
| 715 | int directed = 1; |
| 716 | int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0; |
| 717 | int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0; |
| 718 | int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0; |
| 719 | int allmulti = (netdev->flags & IFF_ALLMULTI) || |
| 720 | (netdev->mc_count > ENIC_MULTICAST_PERFECT_FILTERS); |
| 721 | u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN]; |
| 722 | unsigned int mc_count = netdev->mc_count; |
| 723 | unsigned int i, j; |
| 724 | |
| 725 | if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS) |
| 726 | mc_count = ENIC_MULTICAST_PERFECT_FILTERS; |
| 727 | |
| 728 | spin_lock(&enic->devcmd_lock); |
| 729 | |
| 730 | vnic_dev_packet_filter(enic->vdev, directed, |
| 731 | multicast, broadcast, promisc, allmulti); |
| 732 | |
| 733 | /* Is there an easier way? Trying to minimize to |
| 734 | * calls to add/del multicast addrs. We keep the |
| 735 | * addrs from the last call in enic->mc_addr and |
| 736 | * look for changes to add/del. |
| 737 | */ |
| 738 | |
| 739 | for (i = 0; list && i < mc_count; i++) { |
| 740 | memcpy(mc_addr[i], list->dmi_addr, ETH_ALEN); |
| 741 | list = list->next; |
| 742 | } |
| 743 | |
| 744 | for (i = 0; i < enic->mc_count; i++) { |
| 745 | for (j = 0; j < mc_count; j++) |
| 746 | if (compare_ether_addr(enic->mc_addr[i], |
| 747 | mc_addr[j]) == 0) |
| 748 | break; |
| 749 | if (j == mc_count) |
| 750 | enic_del_multicast_addr(enic, enic->mc_addr[i]); |
| 751 | } |
| 752 | |
| 753 | for (i = 0; i < mc_count; i++) { |
| 754 | for (j = 0; j < enic->mc_count; j++) |
| 755 | if (compare_ether_addr(mc_addr[i], |
| 756 | enic->mc_addr[j]) == 0) |
| 757 | break; |
| 758 | if (j == enic->mc_count) |
| 759 | enic_add_multicast_addr(enic, mc_addr[i]); |
| 760 | } |
| 761 | |
| 762 | /* Save the list to compare against next time |
| 763 | */ |
| 764 | |
| 765 | for (i = 0; i < mc_count; i++) |
| 766 | memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN); |
| 767 | |
| 768 | enic->mc_count = mc_count; |
| 769 | |
| 770 | spin_unlock(&enic->devcmd_lock); |
| 771 | } |
| 772 | |
| 773 | /* rtnl lock is held */ |
| 774 | static void enic_vlan_rx_register(struct net_device *netdev, |
| 775 | struct vlan_group *vlan_group) |
| 776 | { |
| 777 | struct enic *enic = netdev_priv(netdev); |
| 778 | enic->vlan_group = vlan_group; |
| 779 | } |
| 780 | |
| 781 | /* rtnl lock is held */ |
| 782 | static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 783 | { |
| 784 | struct enic *enic = netdev_priv(netdev); |
| 785 | |
| 786 | spin_lock(&enic->devcmd_lock); |
| 787 | enic_add_vlan(enic, vid); |
| 788 | spin_unlock(&enic->devcmd_lock); |
| 789 | } |
| 790 | |
| 791 | /* rtnl lock is held */ |
| 792 | static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 793 | { |
| 794 | struct enic *enic = netdev_priv(netdev); |
| 795 | |
| 796 | spin_lock(&enic->devcmd_lock); |
| 797 | enic_del_vlan(enic, vid); |
| 798 | spin_unlock(&enic->devcmd_lock); |
| 799 | } |
| 800 | |
| 801 | /* netif_tx_lock held, BHs disabled */ |
| 802 | static void enic_tx_timeout(struct net_device *netdev) |
| 803 | { |
| 804 | struct enic *enic = netdev_priv(netdev); |
| 805 | schedule_work(&enic->reset); |
| 806 | } |
| 807 | |
| 808 | static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) |
| 809 | { |
| 810 | struct enic *enic = vnic_dev_priv(rq->vdev); |
| 811 | |
| 812 | if (!buf->os_buf) |
| 813 | return; |
| 814 | |
| 815 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 816 | buf->len, PCI_DMA_FROMDEVICE); |
| 817 | dev_kfree_skb_any(buf->os_buf); |
| 818 | } |
| 819 | |
| 820 | static inline struct sk_buff *enic_rq_alloc_skb(unsigned int size) |
| 821 | { |
| 822 | struct sk_buff *skb; |
| 823 | |
| 824 | skb = dev_alloc_skb(size + NET_IP_ALIGN); |
| 825 | |
| 826 | if (skb) |
| 827 | skb_reserve(skb, NET_IP_ALIGN); |
| 828 | |
| 829 | return skb; |
| 830 | } |
| 831 | |
| 832 | static int enic_rq_alloc_buf(struct vnic_rq *rq) |
| 833 | { |
| 834 | struct enic *enic = vnic_dev_priv(rq->vdev); |
| 835 | struct sk_buff *skb; |
| 836 | unsigned int len = enic->netdev->mtu + ETH_HLEN; |
| 837 | unsigned int os_buf_index = 0; |
| 838 | dma_addr_t dma_addr; |
| 839 | |
| 840 | skb = enic_rq_alloc_skb(len); |
| 841 | if (!skb) |
| 842 | return -ENOMEM; |
| 843 | |
| 844 | dma_addr = pci_map_single(enic->pdev, skb->data, |
| 845 | len, PCI_DMA_FROMDEVICE); |
| 846 | |
| 847 | enic_queue_rq_desc(rq, skb, os_buf_index, |
| 848 | dma_addr, len); |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int enic_get_skb_header(struct sk_buff *skb, void **iphdr, |
| 854 | void **tcph, u64 *hdr_flags, void *priv) |
| 855 | { |
| 856 | struct cq_enet_rq_desc *cq_desc = priv; |
| 857 | unsigned int ip_len; |
| 858 | struct iphdr *iph; |
| 859 | |
| 860 | u8 type, color, eop, sop, ingress_port, vlan_stripped; |
| 861 | u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof; |
| 862 | u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; |
| 863 | u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc; |
| 864 | u8 packet_error; |
| 865 | u16 q_number, completed_index, bytes_written, vlan, checksum; |
| 866 | u32 rss_hash; |
| 867 | |
| 868 | cq_enet_rq_desc_dec(cq_desc, |
| 869 | &type, &color, &q_number, &completed_index, |
| 870 | &ingress_port, &fcoe, &eop, &sop, &rss_type, |
| 871 | &csum_not_calc, &rss_hash, &bytes_written, |
| 872 | &packet_error, &vlan_stripped, &vlan, &checksum, |
| 873 | &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error, |
| 874 | &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp, |
| 875 | &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment, |
| 876 | &fcs_ok); |
| 877 | |
| 878 | if (!(ipv4 && tcp && !ipv4_fragment)) |
| 879 | return -1; |
| 880 | |
| 881 | skb_reset_network_header(skb); |
| 882 | iph = ip_hdr(skb); |
| 883 | |
| 884 | ip_len = ip_hdrlen(skb); |
| 885 | skb_set_transport_header(skb, ip_len); |
| 886 | |
| 887 | /* check if ip header and tcp header are complete */ |
| 888 | if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb)) |
| 889 | return -1; |
| 890 | |
| 891 | *hdr_flags = LRO_IPV4 | LRO_TCP; |
| 892 | *tcph = tcp_hdr(skb); |
| 893 | *iphdr = iph; |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | static void enic_rq_indicate_buf(struct vnic_rq *rq, |
| 899 | struct cq_desc *cq_desc, struct vnic_rq_buf *buf, |
| 900 | int skipped, void *opaque) |
| 901 | { |
| 902 | struct enic *enic = vnic_dev_priv(rq->vdev); |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 903 | struct net_device *netdev = enic->netdev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 904 | struct sk_buff *skb; |
| 905 | |
| 906 | u8 type, color, eop, sop, ingress_port, vlan_stripped; |
| 907 | u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof; |
| 908 | u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; |
| 909 | u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc; |
| 910 | u8 packet_error; |
| 911 | u16 q_number, completed_index, bytes_written, vlan, checksum; |
| 912 | u32 rss_hash; |
| 913 | |
| 914 | if (skipped) |
| 915 | return; |
| 916 | |
| 917 | skb = buf->os_buf; |
| 918 | prefetch(skb->data - NET_IP_ALIGN); |
| 919 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 920 | buf->len, PCI_DMA_FROMDEVICE); |
| 921 | |
| 922 | cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, |
| 923 | &type, &color, &q_number, &completed_index, |
| 924 | &ingress_port, &fcoe, &eop, &sop, &rss_type, |
| 925 | &csum_not_calc, &rss_hash, &bytes_written, |
| 926 | &packet_error, &vlan_stripped, &vlan, &checksum, |
| 927 | &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error, |
| 928 | &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp, |
| 929 | &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment, |
| 930 | &fcs_ok); |
| 931 | |
| 932 | if (packet_error) { |
| 933 | |
Scott Feldman | bd9fb1a | 2009-02-09 23:24:08 -0800 | [diff] [blame] | 934 | if (bytes_written > 0 && !fcs_ok) |
| 935 | enic->rq_bad_fcs++; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 936 | |
| 937 | dev_kfree_skb_any(skb); |
| 938 | |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | if (eop && bytes_written > 0) { |
| 943 | |
| 944 | /* Good receive |
| 945 | */ |
| 946 | |
| 947 | skb_put(skb, bytes_written); |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 948 | skb->protocol = eth_type_trans(skb, netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 949 | |
| 950 | if (enic->csum_rx_enabled && !csum_not_calc) { |
| 951 | skb->csum = htons(checksum); |
| 952 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 953 | } |
| 954 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 955 | skb->dev = netdev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 956 | |
| 957 | if (enic->vlan_group && vlan_stripped) { |
| 958 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 959 | if ((netdev->features & NETIF_F_LRO) && ipv4) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 960 | lro_vlan_hwaccel_receive_skb(&enic->lro_mgr, |
| 961 | skb, enic->vlan_group, |
| 962 | vlan, cq_desc); |
| 963 | else |
| 964 | vlan_hwaccel_receive_skb(skb, |
| 965 | enic->vlan_group, vlan); |
| 966 | |
| 967 | } else { |
| 968 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 969 | if ((netdev->features & NETIF_F_LRO) && ipv4) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 970 | lro_receive_skb(&enic->lro_mgr, skb, cq_desc); |
| 971 | else |
| 972 | netif_receive_skb(skb); |
| 973 | |
| 974 | } |
| 975 | |
| 976 | } else { |
| 977 | |
| 978 | /* Buffer overflow |
| 979 | */ |
| 980 | |
| 981 | dev_kfree_skb_any(skb); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, |
| 986 | u8 type, u16 q_number, u16 completed_index, void *opaque) |
| 987 | { |
| 988 | struct enic *enic = vnic_dev_priv(vdev); |
| 989 | |
| 990 | vnic_rq_service(&enic->rq[q_number], cq_desc, |
| 991 | completed_index, VNIC_RQ_RETURN_DESC, |
| 992 | enic_rq_indicate_buf, opaque); |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static void enic_rq_drop_buf(struct vnic_rq *rq, |
| 998 | struct cq_desc *cq_desc, struct vnic_rq_buf *buf, |
| 999 | int skipped, void *opaque) |
| 1000 | { |
| 1001 | struct enic *enic = vnic_dev_priv(rq->vdev); |
| 1002 | struct sk_buff *skb = buf->os_buf; |
| 1003 | |
| 1004 | if (skipped) |
| 1005 | return; |
| 1006 | |
| 1007 | pci_unmap_single(enic->pdev, buf->dma_addr, |
| 1008 | buf->len, PCI_DMA_FROMDEVICE); |
| 1009 | |
| 1010 | dev_kfree_skb_any(skb); |
| 1011 | } |
| 1012 | |
| 1013 | static int enic_rq_service_drop(struct vnic_dev *vdev, struct cq_desc *cq_desc, |
| 1014 | u8 type, u16 q_number, u16 completed_index, void *opaque) |
| 1015 | { |
| 1016 | struct enic *enic = vnic_dev_priv(vdev); |
| 1017 | |
| 1018 | vnic_rq_service(&enic->rq[q_number], cq_desc, |
| 1019 | completed_index, VNIC_RQ_RETURN_DESC, |
| 1020 | enic_rq_drop_buf, opaque); |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int enic_poll(struct napi_struct *napi, int budget) |
| 1026 | { |
| 1027 | struct enic *enic = container_of(napi, struct enic, napi); |
| 1028 | struct net_device *netdev = enic->netdev; |
| 1029 | unsigned int rq_work_to_do = budget; |
| 1030 | unsigned int wq_work_to_do = -1; /* no limit */ |
| 1031 | unsigned int work_done, rq_work_done, wq_work_done; |
| 1032 | |
| 1033 | /* Service RQ (first) and WQ |
| 1034 | */ |
| 1035 | |
| 1036 | rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ], |
| 1037 | rq_work_to_do, enic_rq_service, NULL); |
| 1038 | |
| 1039 | wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ], |
| 1040 | wq_work_to_do, enic_wq_service, NULL); |
| 1041 | |
| 1042 | /* Accumulate intr event credits for this polling |
| 1043 | * cycle. An intr event is the completion of a |
| 1044 | * a WQ or RQ packet. |
| 1045 | */ |
| 1046 | |
| 1047 | work_done = rq_work_done + wq_work_done; |
| 1048 | |
| 1049 | if (work_done > 0) |
| 1050 | vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ], |
| 1051 | work_done, |
| 1052 | 0 /* don't unmask intr */, |
| 1053 | 0 /* don't reset intr timer */); |
| 1054 | |
| 1055 | if (rq_work_done > 0) { |
| 1056 | |
| 1057 | /* Replenish RQ |
| 1058 | */ |
| 1059 | |
| 1060 | vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); |
| 1061 | |
| 1062 | } else { |
| 1063 | |
| 1064 | /* If no work done, flush all LROs and exit polling |
| 1065 | */ |
| 1066 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1067 | if (netdev->features & NETIF_F_LRO) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1068 | lro_flush_all(&enic->lro_mgr); |
| 1069 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1070 | napi_complete(napi); |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 1071 | vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | return rq_work_done; |
| 1075 | } |
| 1076 | |
| 1077 | static int enic_poll_msix(struct napi_struct *napi, int budget) |
| 1078 | { |
| 1079 | struct enic *enic = container_of(napi, struct enic, napi); |
| 1080 | struct net_device *netdev = enic->netdev; |
| 1081 | unsigned int work_to_do = budget; |
| 1082 | unsigned int work_done; |
| 1083 | |
| 1084 | /* Service RQ |
| 1085 | */ |
| 1086 | |
| 1087 | work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ], |
| 1088 | work_to_do, enic_rq_service, NULL); |
| 1089 | |
| 1090 | if (work_done > 0) { |
| 1091 | |
| 1092 | /* Replenish RQ |
| 1093 | */ |
| 1094 | |
| 1095 | vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); |
| 1096 | |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 1097 | /* Return intr event credits for this polling |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1098 | * cycle. An intr event is the completion of a |
Scott Feldman | ed8af6b | 2009-02-09 23:23:50 -0800 | [diff] [blame] | 1099 | * RQ packet. |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1100 | */ |
| 1101 | |
| 1102 | vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ], |
| 1103 | work_done, |
| 1104 | 0 /* don't unmask intr */, |
| 1105 | 0 /* don't reset intr timer */); |
| 1106 | } else { |
| 1107 | |
| 1108 | /* If no work done, flush all LROs and exit polling |
| 1109 | */ |
| 1110 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1111 | if (netdev->features & NETIF_F_LRO) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1112 | lro_flush_all(&enic->lro_mgr); |
| 1113 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1114 | napi_complete(napi); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1115 | vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]); |
| 1116 | } |
| 1117 | |
| 1118 | return work_done; |
| 1119 | } |
| 1120 | |
| 1121 | static void enic_notify_timer(unsigned long data) |
| 1122 | { |
| 1123 | struct enic *enic = (struct enic *)data; |
| 1124 | |
| 1125 | enic_notify_check(enic); |
| 1126 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 1127 | mod_timer(&enic->notify_timer, |
| 1128 | round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static void enic_free_intr(struct enic *enic) |
| 1132 | { |
| 1133 | struct net_device *netdev = enic->netdev; |
| 1134 | unsigned int i; |
| 1135 | |
| 1136 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1137 | case VNIC_DEV_INTR_MODE_INTX: |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1138 | free_irq(enic->pdev->irq, netdev); |
| 1139 | break; |
Scott Feldman | 8f4d248 | 2008-09-24 11:23:42 -0700 | [diff] [blame] | 1140 | case VNIC_DEV_INTR_MODE_MSI: |
| 1141 | free_irq(enic->pdev->irq, enic); |
| 1142 | break; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1143 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1144 | for (i = 0; i < ARRAY_SIZE(enic->msix); i++) |
| 1145 | if (enic->msix[i].requested) |
| 1146 | free_irq(enic->msix_entry[i].vector, |
| 1147 | enic->msix[i].devid); |
| 1148 | break; |
| 1149 | default: |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | static int enic_request_intr(struct enic *enic) |
| 1155 | { |
| 1156 | struct net_device *netdev = enic->netdev; |
| 1157 | unsigned int i; |
| 1158 | int err = 0; |
| 1159 | |
| 1160 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1161 | |
| 1162 | case VNIC_DEV_INTR_MODE_INTX: |
| 1163 | |
| 1164 | err = request_irq(enic->pdev->irq, enic_isr_legacy, |
| 1165 | IRQF_SHARED, netdev->name, netdev); |
| 1166 | break; |
| 1167 | |
| 1168 | case VNIC_DEV_INTR_MODE_MSI: |
| 1169 | |
| 1170 | err = request_irq(enic->pdev->irq, enic_isr_msi, |
| 1171 | 0, netdev->name, enic); |
| 1172 | break; |
| 1173 | |
| 1174 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1175 | |
| 1176 | sprintf(enic->msix[ENIC_MSIX_RQ].devname, |
Scott Feldman | 8f4d248 | 2008-09-24 11:23:42 -0700 | [diff] [blame] | 1177 | "%.11s-rx-0", netdev->name); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1178 | enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq; |
| 1179 | enic->msix[ENIC_MSIX_RQ].devid = enic; |
| 1180 | |
| 1181 | sprintf(enic->msix[ENIC_MSIX_WQ].devname, |
Scott Feldman | 8f4d248 | 2008-09-24 11:23:42 -0700 | [diff] [blame] | 1182 | "%.11s-tx-0", netdev->name); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1183 | enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq; |
| 1184 | enic->msix[ENIC_MSIX_WQ].devid = enic; |
| 1185 | |
| 1186 | sprintf(enic->msix[ENIC_MSIX_ERR].devname, |
| 1187 | "%.11s-err", netdev->name); |
| 1188 | enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err; |
| 1189 | enic->msix[ENIC_MSIX_ERR].devid = enic; |
| 1190 | |
| 1191 | sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname, |
| 1192 | "%.11s-notify", netdev->name); |
| 1193 | enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify; |
| 1194 | enic->msix[ENIC_MSIX_NOTIFY].devid = enic; |
| 1195 | |
| 1196 | for (i = 0; i < ARRAY_SIZE(enic->msix); i++) { |
| 1197 | err = request_irq(enic->msix_entry[i].vector, |
| 1198 | enic->msix[i].isr, 0, |
| 1199 | enic->msix[i].devname, |
| 1200 | enic->msix[i].devid); |
| 1201 | if (err) { |
| 1202 | enic_free_intr(enic); |
| 1203 | break; |
| 1204 | } |
| 1205 | enic->msix[i].requested = 1; |
| 1206 | } |
| 1207 | |
| 1208 | break; |
| 1209 | |
| 1210 | default: |
| 1211 | break; |
| 1212 | } |
| 1213 | |
| 1214 | return err; |
| 1215 | } |
| 1216 | |
| 1217 | static int enic_notify_set(struct enic *enic) |
| 1218 | { |
| 1219 | int err; |
| 1220 | |
| 1221 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1222 | case VNIC_DEV_INTR_MODE_INTX: |
| 1223 | err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY); |
| 1224 | break; |
| 1225 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1226 | err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY); |
| 1227 | break; |
| 1228 | default: |
| 1229 | err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */); |
| 1230 | break; |
| 1231 | } |
| 1232 | |
| 1233 | return err; |
| 1234 | } |
| 1235 | |
| 1236 | static void enic_notify_timer_start(struct enic *enic) |
| 1237 | { |
| 1238 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1239 | case VNIC_DEV_INTR_MODE_MSI: |
| 1240 | mod_timer(&enic->notify_timer, jiffies); |
| 1241 | break; |
| 1242 | default: |
| 1243 | /* Using intr for notification for INTx/MSI-X */ |
| 1244 | break; |
| 1245 | }; |
| 1246 | } |
| 1247 | |
| 1248 | /* rtnl lock is held, process context */ |
| 1249 | static int enic_open(struct net_device *netdev) |
| 1250 | { |
| 1251 | struct enic *enic = netdev_priv(netdev); |
| 1252 | unsigned int i; |
| 1253 | int err; |
| 1254 | |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1255 | err = enic_request_intr(enic); |
| 1256 | if (err) { |
| 1257 | printk(KERN_ERR PFX "%s: Unable to request irq.\n", |
| 1258 | netdev->name); |
| 1259 | return err; |
| 1260 | } |
| 1261 | |
| 1262 | err = enic_notify_set(enic); |
| 1263 | if (err) { |
| 1264 | printk(KERN_ERR PFX |
| 1265 | "%s: Failed to alloc notify buffer, aborting.\n", |
| 1266 | netdev->name); |
| 1267 | goto err_out_free_intr; |
| 1268 | } |
| 1269 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1270 | for (i = 0; i < enic->rq_count; i++) { |
| 1271 | err = vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf); |
| 1272 | if (err) { |
| 1273 | printk(KERN_ERR PFX |
| 1274 | "%s: Unable to alloc receive buffers.\n", |
| 1275 | netdev->name); |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1276 | goto err_out_notify_unset; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | for (i = 0; i < enic->wq_count; i++) |
| 1281 | vnic_wq_enable(&enic->wq[i]); |
| 1282 | for (i = 0; i < enic->rq_count; i++) |
| 1283 | vnic_rq_enable(&enic->rq[i]); |
| 1284 | |
| 1285 | enic_add_station_addr(enic); |
| 1286 | enic_set_multicast_list(netdev); |
| 1287 | |
| 1288 | netif_wake_queue(netdev); |
| 1289 | napi_enable(&enic->napi); |
| 1290 | vnic_dev_enable(enic->vdev); |
| 1291 | |
| 1292 | for (i = 0; i < enic->intr_count; i++) |
| 1293 | vnic_intr_unmask(&enic->intr[i]); |
| 1294 | |
| 1295 | enic_notify_timer_start(enic); |
| 1296 | |
| 1297 | return 0; |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1298 | |
| 1299 | err_out_notify_unset: |
| 1300 | vnic_dev_notify_unset(enic->vdev); |
| 1301 | err_out_free_intr: |
| 1302 | enic_free_intr(enic); |
| 1303 | |
| 1304 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* rtnl lock is held, process context */ |
| 1308 | static int enic_stop(struct net_device *netdev) |
| 1309 | { |
| 1310 | struct enic *enic = netdev_priv(netdev); |
| 1311 | unsigned int i; |
| 1312 | int err; |
| 1313 | |
| 1314 | del_timer_sync(&enic->notify_timer); |
| 1315 | |
| 1316 | vnic_dev_disable(enic->vdev); |
| 1317 | napi_disable(&enic->napi); |
| 1318 | netif_stop_queue(netdev); |
| 1319 | |
| 1320 | for (i = 0; i < enic->intr_count; i++) |
| 1321 | vnic_intr_mask(&enic->intr[i]); |
| 1322 | |
| 1323 | for (i = 0; i < enic->wq_count; i++) { |
| 1324 | err = vnic_wq_disable(&enic->wq[i]); |
| 1325 | if (err) |
| 1326 | return err; |
| 1327 | } |
| 1328 | for (i = 0; i < enic->rq_count; i++) { |
| 1329 | err = vnic_rq_disable(&enic->rq[i]); |
| 1330 | if (err) |
| 1331 | return err; |
| 1332 | } |
| 1333 | |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1334 | vnic_dev_notify_unset(enic->vdev); |
| 1335 | enic_free_intr(enic); |
| 1336 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1337 | (void)vnic_cq_service(&enic->cq[ENIC_CQ_RQ], |
| 1338 | -1, enic_rq_service_drop, NULL); |
| 1339 | (void)vnic_cq_service(&enic->cq[ENIC_CQ_WQ], |
| 1340 | -1, enic_wq_service, NULL); |
| 1341 | |
| 1342 | for (i = 0; i < enic->wq_count; i++) |
| 1343 | vnic_wq_clean(&enic->wq[i], enic_free_wq_buf); |
| 1344 | for (i = 0; i < enic->rq_count; i++) |
| 1345 | vnic_rq_clean(&enic->rq[i], enic_free_rq_buf); |
| 1346 | for (i = 0; i < enic->cq_count; i++) |
| 1347 | vnic_cq_clean(&enic->cq[i]); |
| 1348 | for (i = 0; i < enic->intr_count; i++) |
| 1349 | vnic_intr_clean(&enic->intr[i]); |
| 1350 | |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
| 1354 | static int enic_change_mtu(struct net_device *netdev, int new_mtu) |
| 1355 | { |
| 1356 | struct enic *enic = netdev_priv(netdev); |
| 1357 | int running = netif_running(netdev); |
| 1358 | |
Scott Feldman | 25f0a06 | 2008-09-24 11:23:32 -0700 | [diff] [blame] | 1359 | if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU) |
| 1360 | return -EINVAL; |
| 1361 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1362 | if (running) |
| 1363 | enic_stop(netdev); |
| 1364 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1365 | netdev->mtu = new_mtu; |
| 1366 | |
| 1367 | if (netdev->mtu > enic->port_mtu) |
| 1368 | printk(KERN_WARNING PFX |
| 1369 | "%s: interface MTU (%d) set higher " |
| 1370 | "than port MTU (%d)\n", |
| 1371 | netdev->name, netdev->mtu, enic->port_mtu); |
| 1372 | |
| 1373 | if (running) |
| 1374 | enic_open(netdev); |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
| 1379 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1380 | static void enic_poll_controller(struct net_device *netdev) |
| 1381 | { |
| 1382 | struct enic *enic = netdev_priv(netdev); |
| 1383 | struct vnic_dev *vdev = enic->vdev; |
| 1384 | |
| 1385 | switch (vnic_dev_get_intr_mode(vdev)) { |
| 1386 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1387 | enic_isr_msix_rq(enic->pdev->irq, enic); |
| 1388 | enic_isr_msix_wq(enic->pdev->irq, enic); |
| 1389 | break; |
| 1390 | case VNIC_DEV_INTR_MODE_MSI: |
| 1391 | enic_isr_msi(enic->pdev->irq, enic); |
| 1392 | break; |
| 1393 | case VNIC_DEV_INTR_MODE_INTX: |
| 1394 | enic_isr_legacy(enic->pdev->irq, netdev); |
| 1395 | break; |
| 1396 | default: |
| 1397 | break; |
| 1398 | } |
| 1399 | } |
| 1400 | #endif |
| 1401 | |
| 1402 | static int enic_dev_wait(struct vnic_dev *vdev, |
| 1403 | int (*start)(struct vnic_dev *, int), |
| 1404 | int (*finished)(struct vnic_dev *, int *), |
| 1405 | int arg) |
| 1406 | { |
| 1407 | unsigned long time; |
| 1408 | int done; |
| 1409 | int err; |
| 1410 | |
| 1411 | BUG_ON(in_interrupt()); |
| 1412 | |
| 1413 | err = start(vdev, arg); |
| 1414 | if (err) |
| 1415 | return err; |
| 1416 | |
| 1417 | /* Wait for func to complete...2 seconds max |
| 1418 | */ |
| 1419 | |
| 1420 | time = jiffies + (HZ * 2); |
| 1421 | do { |
| 1422 | |
| 1423 | err = finished(vdev, &done); |
| 1424 | if (err) |
| 1425 | return err; |
| 1426 | |
| 1427 | if (done) |
| 1428 | return 0; |
| 1429 | |
| 1430 | schedule_timeout_uninterruptible(HZ / 10); |
| 1431 | |
| 1432 | } while (time_after(time, jiffies)); |
| 1433 | |
| 1434 | return -ETIMEDOUT; |
| 1435 | } |
| 1436 | |
| 1437 | static int enic_dev_open(struct enic *enic) |
| 1438 | { |
| 1439 | int err; |
| 1440 | |
| 1441 | err = enic_dev_wait(enic->vdev, vnic_dev_open, |
| 1442 | vnic_dev_open_done, 0); |
| 1443 | if (err) |
| 1444 | printk(KERN_ERR PFX |
| 1445 | "vNIC device open failed, err %d.\n", err); |
| 1446 | |
| 1447 | return err; |
| 1448 | } |
| 1449 | |
| 1450 | static int enic_dev_soft_reset(struct enic *enic) |
| 1451 | { |
| 1452 | int err; |
| 1453 | |
| 1454 | err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset, |
| 1455 | vnic_dev_soft_reset_done, 0); |
| 1456 | if (err) |
| 1457 | printk(KERN_ERR PFX |
| 1458 | "vNIC soft reset failed, err %d.\n", err); |
| 1459 | |
| 1460 | return err; |
| 1461 | } |
| 1462 | |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1463 | static int enic_set_niccfg(struct enic *enic) |
| 1464 | { |
| 1465 | const u8 rss_default_cpu = 0; |
| 1466 | const u8 rss_hash_type = 0; |
| 1467 | const u8 rss_hash_bits = 0; |
| 1468 | const u8 rss_base_cpu = 0; |
| 1469 | const u8 rss_enable = 0; |
| 1470 | const u8 tso_ipid_split_en = 0; |
| 1471 | const u8 ig_vlan_strip_en = 1; |
| 1472 | |
| 1473 | /* Enable VLAN tag stripping. RSS not enabled (yet). |
| 1474 | */ |
| 1475 | |
| 1476 | return enic_set_nic_cfg(enic, |
| 1477 | rss_default_cpu, rss_hash_type, |
| 1478 | rss_hash_bits, rss_base_cpu, |
| 1479 | rss_enable, tso_ipid_split_en, |
| 1480 | ig_vlan_strip_en); |
| 1481 | } |
| 1482 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1483 | static void enic_reset(struct work_struct *work) |
| 1484 | { |
| 1485 | struct enic *enic = container_of(work, struct enic, reset); |
| 1486 | |
| 1487 | if (!netif_running(enic->netdev)) |
| 1488 | return; |
| 1489 | |
| 1490 | rtnl_lock(); |
| 1491 | |
| 1492 | spin_lock(&enic->devcmd_lock); |
| 1493 | vnic_dev_hang_notify(enic->vdev); |
| 1494 | spin_unlock(&enic->devcmd_lock); |
| 1495 | |
| 1496 | enic_stop(enic->netdev); |
| 1497 | enic_dev_soft_reset(enic); |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1498 | vnic_dev_init(enic->vdev, 0); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1499 | enic_reset_mcaddrs(enic); |
| 1500 | enic_init_vnic_resources(enic); |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1501 | enic_set_niccfg(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1502 | enic_open(enic->netdev); |
| 1503 | |
| 1504 | rtnl_unlock(); |
| 1505 | } |
| 1506 | |
| 1507 | static int enic_set_intr_mode(struct enic *enic) |
| 1508 | { |
| 1509 | unsigned int n = ARRAY_SIZE(enic->rq); |
| 1510 | unsigned int m = ARRAY_SIZE(enic->wq); |
| 1511 | unsigned int i; |
| 1512 | |
| 1513 | /* Set interrupt mode (INTx, MSI, MSI-X) depending |
| 1514 | * system capabilities. |
| 1515 | * |
| 1516 | * Try MSI-X first |
| 1517 | * |
| 1518 | * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs |
| 1519 | * (the second to last INTR is used for WQ/RQ errors) |
| 1520 | * (the last INTR is used for notifications) |
| 1521 | */ |
| 1522 | |
| 1523 | BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2); |
| 1524 | for (i = 0; i < n + m + 2; i++) |
| 1525 | enic->msix_entry[i].entry = i; |
| 1526 | |
| 1527 | if (enic->config.intr_mode < 1 && |
| 1528 | enic->rq_count >= n && |
| 1529 | enic->wq_count >= m && |
| 1530 | enic->cq_count >= n + m && |
| 1531 | enic->intr_count >= n + m + 2 && |
| 1532 | !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) { |
| 1533 | |
| 1534 | enic->rq_count = n; |
| 1535 | enic->wq_count = m; |
| 1536 | enic->cq_count = n + m; |
| 1537 | enic->intr_count = n + m + 2; |
| 1538 | |
| 1539 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX); |
| 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | /* Next try MSI |
| 1545 | * |
| 1546 | * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR |
| 1547 | */ |
| 1548 | |
| 1549 | if (enic->config.intr_mode < 2 && |
| 1550 | enic->rq_count >= 1 && |
| 1551 | enic->wq_count >= 1 && |
| 1552 | enic->cq_count >= 2 && |
| 1553 | enic->intr_count >= 1 && |
| 1554 | !pci_enable_msi(enic->pdev)) { |
| 1555 | |
| 1556 | enic->rq_count = 1; |
| 1557 | enic->wq_count = 1; |
| 1558 | enic->cq_count = 2; |
| 1559 | enic->intr_count = 1; |
| 1560 | |
| 1561 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI); |
| 1562 | |
| 1563 | return 0; |
| 1564 | } |
| 1565 | |
| 1566 | /* Next try INTx |
| 1567 | * |
| 1568 | * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs |
| 1569 | * (the first INTR is used for WQ/RQ) |
| 1570 | * (the second INTR is used for WQ/RQ errors) |
| 1571 | * (the last INTR is used for notifications) |
| 1572 | */ |
| 1573 | |
| 1574 | if (enic->config.intr_mode < 3 && |
| 1575 | enic->rq_count >= 1 && |
| 1576 | enic->wq_count >= 1 && |
| 1577 | enic->cq_count >= 2 && |
| 1578 | enic->intr_count >= 3) { |
| 1579 | |
| 1580 | enic->rq_count = 1; |
| 1581 | enic->wq_count = 1; |
| 1582 | enic->cq_count = 2; |
| 1583 | enic->intr_count = 3; |
| 1584 | |
| 1585 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX); |
| 1586 | |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
| 1590 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); |
| 1591 | |
| 1592 | return -EINVAL; |
| 1593 | } |
| 1594 | |
| 1595 | static void enic_clear_intr_mode(struct enic *enic) |
| 1596 | { |
| 1597 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1598 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1599 | pci_disable_msix(enic->pdev); |
| 1600 | break; |
| 1601 | case VNIC_DEV_INTR_MODE_MSI: |
| 1602 | pci_disable_msi(enic->pdev); |
| 1603 | break; |
| 1604 | default: |
| 1605 | break; |
| 1606 | } |
| 1607 | |
| 1608 | vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); |
| 1609 | } |
| 1610 | |
| 1611 | static void enic_iounmap(struct enic *enic) |
| 1612 | { |
| 1613 | if (enic->bar0.vaddr) |
| 1614 | iounmap(enic->bar0.vaddr); |
| 1615 | } |
| 1616 | |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 1617 | static const struct net_device_ops enic_netdev_ops = { |
| 1618 | .ndo_open = enic_open, |
| 1619 | .ndo_stop = enic_stop, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 1620 | .ndo_start_xmit = enic_hard_start_xmit, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 1621 | .ndo_get_stats = enic_get_stats, |
| 1622 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | fe96aaa | 2009-01-09 11:13:14 +0000 | [diff] [blame] | 1623 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 1624 | .ndo_set_multicast_list = enic_set_multicast_list, |
| 1625 | .ndo_change_mtu = enic_change_mtu, |
| 1626 | .ndo_vlan_rx_register = enic_vlan_rx_register, |
| 1627 | .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid, |
| 1628 | .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid, |
| 1629 | .ndo_tx_timeout = enic_tx_timeout, |
| 1630 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1631 | .ndo_poll_controller = enic_poll_controller, |
| 1632 | #endif |
| 1633 | }; |
| 1634 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1635 | static int __devinit enic_probe(struct pci_dev *pdev, |
| 1636 | const struct pci_device_id *ent) |
| 1637 | { |
| 1638 | struct net_device *netdev; |
| 1639 | struct enic *enic; |
| 1640 | int using_dac = 0; |
| 1641 | unsigned int i; |
| 1642 | int err; |
| 1643 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1644 | /* Allocate net device structure and initialize. Private |
| 1645 | * instance data is initialized to zero. |
| 1646 | */ |
| 1647 | |
| 1648 | netdev = alloc_etherdev(sizeof(struct enic)); |
| 1649 | if (!netdev) { |
| 1650 | printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n"); |
| 1651 | return -ENOMEM; |
| 1652 | } |
| 1653 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1654 | pci_set_drvdata(pdev, netdev); |
| 1655 | |
| 1656 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1657 | |
| 1658 | enic = netdev_priv(netdev); |
| 1659 | enic->netdev = netdev; |
| 1660 | enic->pdev = pdev; |
| 1661 | |
| 1662 | /* Setup PCI resources |
| 1663 | */ |
| 1664 | |
| 1665 | err = pci_enable_device(pdev); |
| 1666 | if (err) { |
| 1667 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1668 | "Cannot enable PCI device, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1669 | goto err_out_free_netdev; |
| 1670 | } |
| 1671 | |
| 1672 | err = pci_request_regions(pdev, DRV_NAME); |
| 1673 | if (err) { |
| 1674 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1675 | "Cannot request PCI regions, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1676 | goto err_out_disable_device; |
| 1677 | } |
| 1678 | |
| 1679 | pci_set_master(pdev); |
| 1680 | |
| 1681 | /* Query PCI controller on system for DMA addressing |
| 1682 | * limitation for the device. Try 40-bit first, and |
| 1683 | * fail to 32-bit. |
| 1684 | */ |
| 1685 | |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 1686 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1687 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1688 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1689 | if (err) { |
| 1690 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1691 | "No usable DMA configuration, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1692 | goto err_out_release_regions; |
| 1693 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1694 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1695 | if (err) { |
| 1696 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1697 | "Unable to obtain 32-bit DMA " |
| 1698 | "for consistent allocations, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1699 | goto err_out_release_regions; |
| 1700 | } |
| 1701 | } else { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 1702 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1703 | if (err) { |
| 1704 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1705 | "Unable to obtain 40-bit DMA " |
| 1706 | "for consistent allocations, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1707 | goto err_out_release_regions; |
| 1708 | } |
| 1709 | using_dac = 1; |
| 1710 | } |
| 1711 | |
| 1712 | /* Map vNIC resources from BAR0 |
| 1713 | */ |
| 1714 | |
| 1715 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1716 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1717 | "BAR0 not memory-map'able, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1718 | err = -ENODEV; |
| 1719 | goto err_out_release_regions; |
| 1720 | } |
| 1721 | |
| 1722 | enic->bar0.vaddr = pci_iomap(pdev, 0, enic->bar0.len); |
| 1723 | enic->bar0.bus_addr = pci_resource_start(pdev, 0); |
| 1724 | enic->bar0.len = pci_resource_len(pdev, 0); |
| 1725 | |
| 1726 | if (!enic->bar0.vaddr) { |
| 1727 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1728 | "Cannot memory-map BAR0 res hdr, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1729 | err = -ENODEV; |
| 1730 | goto err_out_release_regions; |
| 1731 | } |
| 1732 | |
| 1733 | /* Register vNIC device |
| 1734 | */ |
| 1735 | |
| 1736 | enic->vdev = vnic_dev_register(NULL, enic, pdev, &enic->bar0); |
| 1737 | if (!enic->vdev) { |
| 1738 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1739 | "vNIC registration failed, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1740 | err = -ENODEV; |
| 1741 | goto err_out_iounmap; |
| 1742 | } |
| 1743 | |
| 1744 | /* Issue device open to get device in known state |
| 1745 | */ |
| 1746 | |
| 1747 | err = enic_dev_open(enic); |
| 1748 | if (err) { |
| 1749 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1750 | "vNIC dev open failed, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1751 | goto err_out_vnic_unregister; |
| 1752 | } |
| 1753 | |
| 1754 | /* Issue device init to initialize the vnic-to-switch link. |
| 1755 | * We'll start with carrier off and wait for link UP |
| 1756 | * notification later to turn on carrier. We don't need |
| 1757 | * to wait here for the vnic-to-switch link initialization |
| 1758 | * to complete; link UP notification is the indication that |
| 1759 | * the process is complete. |
| 1760 | */ |
| 1761 | |
| 1762 | netif_carrier_off(netdev); |
| 1763 | |
| 1764 | err = vnic_dev_init(enic->vdev, 0); |
| 1765 | if (err) { |
| 1766 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1767 | "vNIC dev init failed, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1768 | goto err_out_dev_close; |
| 1769 | } |
| 1770 | |
| 1771 | /* Get vNIC configuration |
| 1772 | */ |
| 1773 | |
| 1774 | err = enic_get_vnic_config(enic); |
| 1775 | if (err) { |
| 1776 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1777 | "Get vNIC configuration failed, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1778 | goto err_out_dev_close; |
| 1779 | } |
| 1780 | |
| 1781 | /* Get available resource counts |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1782 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1783 | |
| 1784 | enic_get_res_counts(enic); |
| 1785 | |
| 1786 | /* Set interrupt mode based on resource counts and system |
| 1787 | * capabilities |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1788 | */ |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1789 | |
| 1790 | err = enic_set_intr_mode(enic); |
| 1791 | if (err) { |
| 1792 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1793 | "Failed to set intr mode, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1794 | goto err_out_dev_close; |
| 1795 | } |
| 1796 | |
| 1797 | /* Allocate and configure vNIC resources |
| 1798 | */ |
| 1799 | |
| 1800 | err = enic_alloc_vnic_resources(enic); |
| 1801 | if (err) { |
| 1802 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1803 | "Failed to alloc vNIC resources, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1804 | goto err_out_free_vnic_resources; |
| 1805 | } |
| 1806 | |
| 1807 | enic_init_vnic_resources(enic); |
| 1808 | |
Scott Feldman | 68f7170 | 2009-02-09 23:24:24 -0800 | [diff] [blame] | 1809 | err = enic_set_niccfg(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1810 | if (err) { |
| 1811 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1812 | "Failed to config nic, aborting.\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1813 | goto err_out_free_vnic_resources; |
| 1814 | } |
| 1815 | |
| 1816 | /* Setup notification timer, HW reset task, and locks |
| 1817 | */ |
| 1818 | |
| 1819 | init_timer(&enic->notify_timer); |
| 1820 | enic->notify_timer.function = enic_notify_timer; |
| 1821 | enic->notify_timer.data = (unsigned long)enic; |
| 1822 | |
| 1823 | INIT_WORK(&enic->reset, enic_reset); |
| 1824 | |
| 1825 | for (i = 0; i < enic->wq_count; i++) |
| 1826 | spin_lock_init(&enic->wq_lock[i]); |
| 1827 | |
| 1828 | spin_lock_init(&enic->devcmd_lock); |
| 1829 | |
| 1830 | /* Register net device |
| 1831 | */ |
| 1832 | |
| 1833 | enic->port_mtu = enic->config.mtu; |
| 1834 | (void)enic_change_mtu(netdev, enic->port_mtu); |
| 1835 | |
| 1836 | err = enic_set_mac_addr(netdev, enic->mac_addr); |
| 1837 | if (err) { |
| 1838 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1839 | "Invalid MAC address, aborting.\n"); |
| 1840 | goto err_out_free_vnic_resources; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Stephen Hemminger | afe29f7 | 2008-11-19 22:23:26 -0800 | [diff] [blame] | 1843 | netdev->netdev_ops = &enic_netdev_ops; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1844 | netdev->watchdog_timeo = 2 * HZ; |
| 1845 | netdev->ethtool_ops = &enic_ethtool_ops; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1846 | |
| 1847 | switch (vnic_dev_get_intr_mode(enic->vdev)) { |
| 1848 | default: |
| 1849 | netif_napi_add(netdev, &enic->napi, enic_poll, 64); |
| 1850 | break; |
| 1851 | case VNIC_DEV_INTR_MODE_MSIX: |
| 1852 | netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); |
| 1853 | break; |
| 1854 | } |
| 1855 | |
| 1856 | netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 1857 | if (ENIC_SETTING(enic, TXCSUM)) |
| 1858 | netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; |
| 1859 | if (ENIC_SETTING(enic, TSO)) |
| 1860 | netdev->features |= NETIF_F_TSO | |
| 1861 | NETIF_F_TSO6 | NETIF_F_TSO_ECN; |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1862 | if (ENIC_SETTING(enic, LRO)) |
| 1863 | netdev->features |= NETIF_F_LRO; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1864 | if (using_dac) |
| 1865 | netdev->features |= NETIF_F_HIGHDMA; |
| 1866 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1867 | enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM); |
| 1868 | |
Scott Feldman | 86ca9db | 2008-11-21 21:26:55 -0800 | [diff] [blame] | 1869 | enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR; |
| 1870 | enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC; |
| 1871 | enic->lro_mgr.lro_arr = enic->lro_desc; |
| 1872 | enic->lro_mgr.get_skb_header = enic_get_skb_header; |
| 1873 | enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID; |
| 1874 | enic->lro_mgr.dev = netdev; |
| 1875 | enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE; |
| 1876 | enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; |
| 1877 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1878 | err = register_netdev(netdev); |
| 1879 | if (err) { |
| 1880 | printk(KERN_ERR PFX |
Scott Feldman | 4b75a44 | 2008-09-24 11:23:53 -0700 | [diff] [blame] | 1881 | "Cannot register net device, aborting.\n"); |
| 1882 | goto err_out_free_vnic_resources; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | return 0; |
| 1886 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1887 | err_out_free_vnic_resources: |
| 1888 | enic_free_vnic_resources(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1889 | err_out_dev_close: |
| 1890 | vnic_dev_close(enic->vdev); |
| 1891 | err_out_vnic_unregister: |
| 1892 | enic_clear_intr_mode(enic); |
| 1893 | vnic_dev_unregister(enic->vdev); |
| 1894 | err_out_iounmap: |
| 1895 | enic_iounmap(enic); |
| 1896 | err_out_release_regions: |
| 1897 | pci_release_regions(pdev); |
| 1898 | err_out_disable_device: |
| 1899 | pci_disable_device(pdev); |
| 1900 | err_out_free_netdev: |
| 1901 | pci_set_drvdata(pdev, NULL); |
| 1902 | free_netdev(netdev); |
| 1903 | |
| 1904 | return err; |
| 1905 | } |
| 1906 | |
| 1907 | static void __devexit enic_remove(struct pci_dev *pdev) |
| 1908 | { |
| 1909 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 1910 | |
| 1911 | if (netdev) { |
| 1912 | struct enic *enic = netdev_priv(netdev); |
| 1913 | |
| 1914 | flush_scheduled_work(); |
| 1915 | unregister_netdev(netdev); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1916 | enic_free_vnic_resources(enic); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1917 | vnic_dev_close(enic->vdev); |
| 1918 | enic_clear_intr_mode(enic); |
| 1919 | vnic_dev_unregister(enic->vdev); |
| 1920 | enic_iounmap(enic); |
| 1921 | pci_release_regions(pdev); |
| 1922 | pci_disable_device(pdev); |
| 1923 | pci_set_drvdata(pdev, NULL); |
| 1924 | free_netdev(netdev); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | static struct pci_driver enic_driver = { |
| 1929 | .name = DRV_NAME, |
| 1930 | .id_table = enic_id_table, |
| 1931 | .probe = enic_probe, |
| 1932 | .remove = __devexit_p(enic_remove), |
| 1933 | }; |
| 1934 | |
| 1935 | static int __init enic_init_module(void) |
| 1936 | { |
| 1937 | printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION); |
| 1938 | |
| 1939 | return pci_register_driver(&enic_driver); |
| 1940 | } |
| 1941 | |
| 1942 | static void __exit enic_cleanup_module(void) |
| 1943 | { |
| 1944 | pci_unregister_driver(&enic_driver); |
| 1945 | } |
| 1946 | |
| 1947 | module_init(enic_init_module); |
| 1948 | module_exit(enic_cleanup_module); |