diff options
Diffstat (limited to 'drivers/net/enic/enic_main.c')
-rw-r--r-- | drivers/net/enic/enic_main.c | 379 |
1 files changed, 264 insertions, 115 deletions
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c index 8005b602f776..d69d52ed7726 100644 --- a/drivers/net/enic/enic_main.c +++ b/drivers/net/enic/enic_main.c @@ -44,10 +44,15 @@ #include "enic.h" #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ) +#define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS) +#define MAX_TSO (1 << 16) +#define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1) + +#define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */ /* Supported devices */ static struct pci_device_id enic_id_table[] = { - { PCI_VDEVICE(CISCO, 0x0043) }, + { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) }, { 0, } /* end of table */ }; @@ -256,7 +261,7 @@ static void enic_set_msglevel(struct net_device *netdev, u32 value) enic->msg_enable = value; } -static struct ethtool_ops enic_ethtool_ops = { +static const struct ethtool_ops enic_ethtool_ops = { .get_settings = enic_get_settings, .get_drvinfo = enic_get_drvinfo, .get_msglevel = enic_get_msglevel, @@ -310,7 +315,8 @@ static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, opaque); if (netif_queue_stopped(enic->netdev) && - vnic_wq_desc_avail(&enic->wq[q_number]) >= MAX_SKB_FRAGS + 1) + vnic_wq_desc_avail(&enic->wq[q_number]) >= + (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)) netif_wake_queue(enic->netdev); spin_unlock(&enic->wq_lock[q_number]); @@ -356,7 +362,7 @@ static void enic_mtu_check(struct enic *enic) { u32 mtu = vnic_dev_mtu(enic->vdev); - if (mtu != enic->port_mtu) { + if (mtu && mtu != enic->port_mtu) { if (mtu < enic->netdev->mtu) printk(KERN_WARNING PFX "%s: interface MTU (%d) set higher " @@ -525,7 +531,11 @@ static inline void enic_queue_wq_skb_vlan(struct enic *enic, unsigned int len_left = skb->len - head_len; int eop = (len_left == 0); - /* Queue the main skb fragment */ + /* Queue the main skb fragment. The fragments are no larger + * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less + * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor + * per fragment is queued. + */ enic_queue_wq_desc(wq, skb, pci_map_single(enic->pdev, skb->data, head_len, PCI_DMA_TODEVICE), @@ -547,7 +557,11 @@ static inline void enic_queue_wq_skb_csum_l4(struct enic *enic, unsigned int csum_offset = hdr_len + skb->csum_offset; int eop = (len_left == 0); - /* Queue the main skb fragment */ + /* Queue the main skb fragment. The fragments are no larger + * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less + * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor + * per fragment is queued. + */ enic_queue_wq_desc_csum_l4(wq, skb, pci_map_single(enic->pdev, skb->data, head_len, PCI_DMA_TODEVICE), @@ -565,10 +579,14 @@ static inline void enic_queue_wq_skb_tso(struct enic *enic, struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss, int vlan_tag_insert, unsigned int vlan_tag) { - unsigned int head_len = skb_headlen(skb); - unsigned int len_left = skb->len - head_len; + unsigned int frag_len_left = skb_headlen(skb); + unsigned int len_left = skb->len - frag_len_left; unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); int eop = (len_left == 0); + unsigned int len; + dma_addr_t dma_addr; + unsigned int offset = 0; + skb_frag_t *frag; /* Preload TCP csum field with IP pseudo hdr calculated * with IP length set to zero. HW will later add in length @@ -584,17 +602,49 @@ static inline void enic_queue_wq_skb_tso(struct enic *enic, &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); } - /* Queue the main skb fragment */ - enic_queue_wq_desc_tso(wq, skb, - pci_map_single(enic->pdev, skb->data, - head_len, PCI_DMA_TODEVICE), - head_len, - mss, hdr_len, - vlan_tag_insert, vlan_tag, - eop); + /* Queue WQ_ENET_MAX_DESC_LEN length descriptors + * for the main skb fragment + */ + while (frag_len_left) { + len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN); + dma_addr = pci_map_single(enic->pdev, skb->data + offset, + len, PCI_DMA_TODEVICE); + enic_queue_wq_desc_tso(wq, skb, + dma_addr, + len, + mss, hdr_len, + vlan_tag_insert, vlan_tag, + eop && (len == frag_len_left)); + frag_len_left -= len; + offset += len; + } - if (!eop) - enic_queue_wq_skb_cont(enic, wq, skb, len_left); + if (eop) + return; + + /* Queue WQ_ENET_MAX_DESC_LEN length descriptors + * for additional data fragments + */ + for (frag = skb_shinfo(skb)->frags; len_left; frag++) { + len_left -= frag->size; + frag_len_left = frag->size; + offset = frag->page_offset; + + while (frag_len_left) { + len = min(frag_len_left, + (unsigned int)WQ_ENET_MAX_DESC_LEN); + dma_addr = pci_map_page(enic->pdev, frag->page, + offset, len, + PCI_DMA_TODEVICE); + enic_queue_wq_desc_cont(wq, skb, + dma_addr, + len, + (len_left == 0) && + (len == frag_len_left)); /* EOP? */ + frag_len_left -= len; + offset += len; + } + } } static inline void enic_queue_wq_skb(struct enic *enic, @@ -622,7 +672,8 @@ static inline void enic_queue_wq_skb(struct enic *enic, } /* netif_tx_lock held, process context with BHs disabled, or BH */ -static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) +static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, + struct net_device *netdev) { struct enic *enic = netdev_priv(netdev); struct vnic_wq *wq = &enic->wq[0]; @@ -647,7 +698,8 @@ static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) spin_lock_irqsave(&enic->wq_lock[0], flags); - if (vnic_wq_desc_avail(wq) < skb_shinfo(skb)->nr_frags + 1) { + if (vnic_wq_desc_avail(wq) < + skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) { netif_stop_queue(netdev); /* This is a hard error, log it */ printk(KERN_ERR PFX "%s: BUG! Tx ring full when " @@ -658,7 +710,7 @@ static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) enic_queue_wq_skb(enic, wq, skb); - if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + 1) + if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS) netif_stop_queue(netdev); spin_unlock_irqrestore(&enic->wq_lock[0], flags); @@ -686,8 +738,9 @@ static struct net_device_stats *enic_get_stats(struct net_device *netdev) net_stats->rx_bytes = stats->rx.rx_bytes_ok; net_stats->rx_errors = stats->rx.rx_errors; net_stats->multicast = stats->rx.rx_multicast_frames_ok; + net_stats->rx_over_errors = enic->rq_truncated_pkts; net_stats->rx_crc_errors = enic->rq_bad_fcs; - net_stats->rx_dropped = stats->rx.rx_no_bufs; + net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop; return net_stats; } @@ -817,11 +870,12 @@ static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) dev_kfree_skb_any(buf->os_buf); } -static inline struct sk_buff *enic_rq_alloc_skb(unsigned int size) +static inline struct sk_buff *enic_rq_alloc_skb(struct net_device *netdev, + unsigned int size) { struct sk_buff *skb; - skb = dev_alloc_skb(size + NET_IP_ALIGN); + skb = netdev_alloc_skb(netdev, size + NET_IP_ALIGN); if (skb) skb_reserve(skb, NET_IP_ALIGN); @@ -832,12 +886,13 @@ static inline struct sk_buff *enic_rq_alloc_skb(unsigned int size) static int enic_rq_alloc_buf(struct vnic_rq *rq) { struct enic *enic = vnic_dev_priv(rq->vdev); + struct net_device *netdev = enic->netdev; struct sk_buff *skb; - unsigned int len = enic->netdev->mtu + ETH_HLEN; + unsigned int len = netdev->mtu + ETH_HLEN; unsigned int os_buf_index = 0; dma_addr_t dma_addr; - skb = enic_rq_alloc_skb(len); + skb = enic_rq_alloc_skb(netdev, len); if (!skb) return -ENOMEM; @@ -850,6 +905,50 @@ static int enic_rq_alloc_buf(struct vnic_rq *rq) return 0; } +static int enic_rq_alloc_buf_a1(struct vnic_rq *rq) +{ + struct rq_enet_desc *desc = vnic_rq_next_desc(rq); + + if (vnic_rq_posting_soon(rq)) { + + /* SW workaround for A0 HW erratum: if we're just about + * to write posted_index, insert a dummy desc + * of type resvd + */ + + rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0); + vnic_rq_post(rq, 0, 0, 0, 0); + } else { + return enic_rq_alloc_buf(rq); + } + + return 0; +} + +static int enic_set_rq_alloc_buf(struct enic *enic) +{ + enum vnic_dev_hw_version hw_ver; + int err; + + err = vnic_dev_hw_version(enic->vdev, &hw_ver); + if (err) + return err; + + switch (hw_ver) { + case VNIC_DEV_HW_VER_A1: + enic->rq_alloc_buf = enic_rq_alloc_buf_a1; + break; + case VNIC_DEV_HW_VER_A2: + case VNIC_DEV_HW_VER_UNKNOWN: + enic->rq_alloc_buf = enic_rq_alloc_buf; + break; + default: + return -ENODEV; + } + + return 0; +} + static int enic_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph, u64 *hdr_flags, void *priv) { @@ -931,8 +1030,12 @@ static void enic_rq_indicate_buf(struct vnic_rq *rq, if (packet_error) { - if (bytes_written > 0 && !fcs_ok) - enic->rq_bad_fcs++; + if (!fcs_ok) { + if (bytes_written > 0) + enic->rq_bad_fcs++; + else if (bytes_written == 0) + enic->rq_truncated_pkts++; + } dev_kfree_skb_any(skb); @@ -1057,7 +1160,7 @@ static int enic_poll(struct napi_struct *napi, int budget) /* Replenish RQ */ - vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); + vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf); } else { @@ -1092,7 +1195,7 @@ static int enic_poll_msix(struct napi_struct *napi, int budget) /* Replenish RQ */ - vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); + vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf); /* Return intr event credits for this polling * cycle. An intr event is the completion of a @@ -1218,6 +1321,7 @@ static int enic_notify_set(struct enic *enic) { int err; + spin_lock(&enic->devcmd_lock); switch (vnic_dev_get_intr_mode(enic->vdev)) { case VNIC_DEV_INTR_MODE_INTX: err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY); @@ -1229,6 +1333,7 @@ static int enic_notify_set(struct enic *enic) err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */); break; } + spin_unlock(&enic->devcmd_lock); return err; } @@ -1268,7 +1373,7 @@ static int enic_open(struct net_device *netdev) } for (i = 0; i < enic->rq_count; i++) { - err = vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf); + err = vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf); if (err) { printk(KERN_ERR PFX "%s: Unable to alloc receive buffers.\n", @@ -1282,12 +1387,16 @@ static int enic_open(struct net_device *netdev) for (i = 0; i < enic->rq_count; i++) vnic_rq_enable(&enic->rq[i]); + spin_lock(&enic->devcmd_lock); enic_add_station_addr(enic); + spin_unlock(&enic->devcmd_lock); enic_set_multicast_list(netdev); netif_wake_queue(netdev); napi_enable(&enic->napi); + spin_lock(&enic->devcmd_lock); vnic_dev_enable(enic->vdev); + spin_unlock(&enic->devcmd_lock); for (i = 0; i < enic->intr_count; i++) vnic_intr_unmask(&enic->intr[i]); @@ -1297,7 +1406,9 @@ static int enic_open(struct net_device *netdev) return 0; err_out_notify_unset: + spin_lock(&enic->devcmd_lock); vnic_dev_notify_unset(enic->vdev); + spin_unlock(&enic->devcmd_lock); err_out_free_intr: enic_free_intr(enic); @@ -1313,7 +1424,9 @@ static int enic_stop(struct net_device *netdev) del_timer_sync(&enic->notify_timer); + spin_lock(&enic->devcmd_lock); vnic_dev_disable(enic->vdev); + spin_unlock(&enic->devcmd_lock); napi_disable(&enic->napi); netif_stop_queue(netdev); @@ -1331,7 +1444,9 @@ static int enic_stop(struct net_device *netdev) return err; } + spin_lock(&enic->devcmd_lock); vnic_dev_notify_unset(enic->vdev); + spin_unlock(&enic->devcmd_lock); enic_free_intr(enic); (void)vnic_cq_service(&enic->cq[ENIC_CQ_RQ], @@ -1471,7 +1586,7 @@ static int enic_set_niccfg(struct enic *enic) const u8 ig_vlan_strip_en = 1; /* Enable VLAN tag stripping. RSS not enabled (yet). - */ + */ return enic_set_nic_cfg(enic, rss_default_cpu, rss_hash_type, @@ -1506,8 +1621,8 @@ static void enic_reset(struct work_struct *work) static int enic_set_intr_mode(struct enic *enic) { - unsigned int n = ARRAY_SIZE(enic->rq); - unsigned int m = ARRAY_SIZE(enic->wq); + unsigned int n = 1; + unsigned int m = 1; unsigned int i; /* Set interrupt mode (INTx, MSI, MSI-X) depending @@ -1608,12 +1723,6 @@ static void enic_clear_intr_mode(struct enic *enic) vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); } -static void enic_iounmap(struct enic *enic) -{ - if (enic->bar0.vaddr) - iounmap(enic->bar0.vaddr); -} - static const struct net_device_ops enic_netdev_ops = { .ndo_open = enic_open, .ndo_stop = enic_stop, @@ -1632,6 +1741,97 @@ static const struct net_device_ops enic_netdev_ops = { #endif }; +void enic_dev_deinit(struct enic *enic) +{ + netif_napi_del(&enic->napi); + enic_free_vnic_resources(enic); + enic_clear_intr_mode(enic); +} + +int enic_dev_init(struct enic *enic) +{ + struct net_device *netdev = enic->netdev; + int err; + + /* Get vNIC configuration + */ + + err = enic_get_vnic_config(enic); + if (err) { + printk(KERN_ERR PFX + "Get vNIC configuration failed, aborting.\n"); + return err; + } + + /* Get available resource counts + */ + + enic_get_res_counts(enic); + + /* Set interrupt mode based on resource counts and system + * capabilities + */ + + err = enic_set_intr_mode(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to set intr mode, aborting.\n"); + return err; + } + + /* Allocate and configure vNIC resources + */ + + err = enic_alloc_vnic_resources(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to alloc vNIC resources, aborting.\n"); + goto err_out_free_vnic_resources; + } + + enic_init_vnic_resources(enic); + + err = enic_set_rq_alloc_buf(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to set RQ buffer allocator, aborting.\n"); + goto err_out_free_vnic_resources; + } + + err = enic_set_niccfg(enic); + if (err) { + printk(KERN_ERR PFX + "Failed to config nic, aborting.\n"); + goto err_out_free_vnic_resources; + } + + switch (vnic_dev_get_intr_mode(enic->vdev)) { + default: + netif_napi_add(netdev, &enic->napi, enic_poll, 64); + break; + case VNIC_DEV_INTR_MODE_MSIX: + netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); + break; + } + + return 0; + +err_out_free_vnic_resources: + enic_clear_intr_mode(enic); + enic_free_vnic_resources(enic); + + return err; +} + +static void enic_iounmap(struct enic *enic) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(enic->bar); i++) + if (enic->bar[i].vaddr) + iounmap(enic->bar[i].vaddr); +} + static int __devinit enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -1709,31 +1909,28 @@ static int __devinit enic_probe(struct pci_dev *pdev, using_dac = 1; } - /* Map vNIC resources from BAR0 + /* Map vNIC resources from BAR0-5 */ - if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { - printk(KERN_ERR PFX - "BAR0 not memory-map'able, aborting.\n"); - err = -ENODEV; - goto err_out_release_regions; - } - - enic->bar0.vaddr = pci_iomap(pdev, 0, enic->bar0.len); - enic->bar0.bus_addr = pci_resource_start(pdev, 0); - enic->bar0.len = pci_resource_len(pdev, 0); - - if (!enic->bar0.vaddr) { - printk(KERN_ERR PFX - "Cannot memory-map BAR0 res hdr, aborting.\n"); - err = -ENODEV; - goto err_out_release_regions; + for (i = 0; i < ARRAY_SIZE(enic->bar); i++) { + if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) + continue; + enic->bar[i].len = pci_resource_len(pdev, i); + enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len); + if (!enic->bar[i].vaddr) { + printk(KERN_ERR PFX + "Cannot memory-map BAR %d, aborting.\n", i); + err = -ENODEV; + goto err_out_iounmap; + } + enic->bar[i].bus_addr = pci_resource_start(pdev, i); } /* Register vNIC device */ - enic->vdev = vnic_dev_register(NULL, enic, pdev, &enic->bar0); + enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar, + ARRAY_SIZE(enic->bar)); if (!enic->vdev) { printk(KERN_ERR PFX "vNIC registration failed, aborting.\n"); @@ -1768,51 +1965,13 @@ static int __devinit enic_probe(struct pci_dev *pdev, goto err_out_dev_close; } - /* Get vNIC configuration - */ - - err = enic_get_vnic_config(enic); - if (err) { - printk(KERN_ERR PFX - "Get vNIC configuration failed, aborting.\n"); - goto err_out_dev_close; - } - - /* Get available resource counts - */ - - enic_get_res_counts(enic); - - /* Set interrupt mode based on resource counts and system - * capabilities - */ - - err = enic_set_intr_mode(enic); + err = enic_dev_init(enic); if (err) { printk(KERN_ERR PFX - "Failed to set intr mode, aborting.\n"); + "Device initialization failed, aborting.\n"); goto err_out_dev_close; } - /* Allocate and configure vNIC resources - */ - - err = enic_alloc_vnic_resources(enic); - if (err) { - printk(KERN_ERR PFX - "Failed to alloc vNIC resources, aborting.\n"); - goto err_out_free_vnic_resources; - } - - enic_init_vnic_resources(enic); - - err = enic_set_niccfg(enic); - if (err) { - printk(KERN_ERR PFX - "Failed to config nic, aborting.\n"); - goto err_out_free_vnic_resources; - } - /* Setup notification timer, HW reset task, and locks */ @@ -1837,23 +1996,15 @@ static int __devinit enic_probe(struct pci_dev *pdev, if (err) { printk(KERN_ERR PFX "Invalid MAC address, aborting.\n"); - goto err_out_free_vnic_resources; + goto err_out_dev_deinit; } netdev->netdev_ops = &enic_netdev_ops; netdev->watchdog_timeo = 2 * HZ; netdev->ethtool_ops = &enic_ethtool_ops; - switch (vnic_dev_get_intr_mode(enic->vdev)) { - default: - netif_napi_add(netdev, &enic->napi, enic_poll, 64); - break; - case VNIC_DEV_INTR_MODE_MSIX: - netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); - break; - } - - netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; + netdev->features |= NETIF_F_HW_VLAN_TX | + NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; if (ENIC_SETTING(enic, TXCSUM)) netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; if (ENIC_SETTING(enic, TSO)) @@ -1879,17 +2030,16 @@ static int __devinit enic_probe(struct pci_dev *pdev, if (err) { printk(KERN_ERR PFX "Cannot register net device, aborting.\n"); - goto err_out_free_vnic_resources; + goto err_out_dev_deinit; } return 0; -err_out_free_vnic_resources: - enic_free_vnic_resources(enic); +err_out_dev_deinit: + enic_dev_deinit(enic); err_out_dev_close: vnic_dev_close(enic->vdev); err_out_vnic_unregister: - enic_clear_intr_mode(enic); vnic_dev_unregister(enic->vdev); err_out_iounmap: enic_iounmap(enic); @@ -1913,9 +2063,8 @@ static void __devexit enic_remove(struct pci_dev *pdev) flush_scheduled_work(); unregister_netdev(netdev); - enic_free_vnic_resources(enic); + enic_dev_deinit(enic); vnic_dev_close(enic->vdev); - enic_clear_intr_mode(enic); vnic_dev_unregister(enic->vdev); enic_iounmap(enic); pci_release_regions(pdev); |