Lines Matching refs:alx
48 #include "alx.h"
52 static const char alx_drv_name[] = "alx";
72 static int alx_refill_rx_ring(struct alx_priv *alx, gfp_t gfp)
74 struct alx_rx_queue *rxq = alx->qnapi[0]->rxq;
81 if (++next == alx->rx_ringsz)
97 skb = __netdev_alloc_skb(alx->dev, alx->rxbuf_size + 64, gfp);
104 dma = dma_map_single(&alx->hw.pdev->dev,
105 skb->data, alx->rxbuf_size,
107 if (dma_mapping_error(&alx->hw.pdev->dev, dma)) {
121 dma_unmap_len_set(cur_buf, size, alx->rxbuf_size);
126 if (++next == alx->rx_ringsz)
136 alx_write_mem16(&alx->hw, ALX_RFD_PIDX, cur);
142 static struct alx_tx_queue *alx_tx_queue_mapping(struct alx_priv *alx,
147 if (r_idx >= alx->num_txq)
148 r_idx = r_idx % alx->num_txq;
150 return alx->qnapi[r_idx]->txq;
167 struct alx_priv *alx;
173 alx = netdev_priv(txq->netdev);
177 hw_read_idx = alx_read_mem16(&alx->hw, txq->c_reg);
200 if (netif_tx_queue_stopped(tx_queue) && netif_carrier_ok(alx->dev) &&
207 static void alx_schedule_link_check(struct alx_priv *alx)
209 schedule_work(&alx->link_check_wk);
212 static void alx_schedule_reset(struct alx_priv *alx)
214 schedule_work(&alx->reset_wk);
219 struct alx_priv *alx;
226 alx = netdev_priv(rxq->netdev);
238 alx_schedule_reset(alx);
264 if (alx->dev->features & NETIF_F_RXCSUM &&
288 rfd_cleaned -= alx_refill_rx_ring(alx, GFP_ATOMIC);
292 alx_refill_rx_ring(alx, GFP_ATOMIC);
300 struct alx_priv *alx = np->alx;
301 struct alx_hw *hw = &alx->hw;
317 if (alx->hw.pdev->msix_enabled) {
320 spin_lock_irqsave(&alx->irq_lock, flags);
321 alx->int_mask |= ALX_ISR_TX_Q0 | ALX_ISR_RX_Q0;
322 alx_write_mem32(hw, ALX_IMR, alx->int_mask);
323 spin_unlock_irqrestore(&alx->irq_lock, flags);
331 static bool alx_intr_handle_misc(struct alx_priv *alx, u32 intr)
333 struct alx_hw *hw = &alx->hw;
336 netif_warn(alx, hw, alx->dev,
338 alx_schedule_reset(alx);
343 netdev_warn(alx->dev, "alert interrupt: 0x%x\n", intr);
350 alx->int_mask &= ~ALX_ISR_PHY;
351 alx_write_mem32(hw, ALX_IMR, alx->int_mask);
352 alx_schedule_link_check(alx);
358 static irqreturn_t alx_intr_handle(struct alx_priv *alx, u32 intr)
360 struct alx_hw *hw = &alx->hw;
362 spin_lock(&alx->irq_lock);
366 intr &= alx->int_mask;
368 if (alx_intr_handle_misc(alx, intr))
372 napi_schedule(&alx->qnapi[0]->napi);
374 alx->int_mask &= ~ALX_ISR_ALL_QUEUES;
375 alx_write_mem32(hw, ALX_IMR, alx->int_mask);
381 spin_unlock(&alx->irq_lock);
388 struct alx_hw *hw = &np->alx->hw;
402 struct alx_priv *alx = data;
403 struct alx_hw *hw = &alx->hw;
411 intr &= (alx->int_mask & ~ALX_ISR_ALL_QUEUES);
413 if (alx_intr_handle_misc(alx, intr))
427 struct alx_priv *alx = data;
429 return alx_intr_handle(alx, alx_read_mem32(&alx->hw, ALX_ISR));
434 struct alx_priv *alx = data;
435 struct alx_hw *hw = &alx->hw;
440 if (intr & ALX_ISR_DIS || !(intr & alx->int_mask))
443 return alx_intr_handle(alx, intr);
451 static void alx_init_ring_ptrs(struct alx_priv *alx)
453 struct alx_hw *hw = &alx->hw;
454 u32 addr_hi = ((u64)alx->descmem.dma) >> 32;
458 for (i = 0; i < alx->num_napi; i++) {
459 np = alx->qnapi[i];
478 alx_write_mem32(hw, ALX_TPD_RING_SZ, alx->tx_ringsz);
481 alx_write_mem32(hw, ALX_RRD_RING_SZ, alx->rx_ringsz);
482 alx_write_mem32(hw, ALX_RFD_RING_SZ, alx->rx_ringsz);
483 alx_write_mem32(hw, ALX_RFD_BUF_SZ, alx->rxbuf_size);
534 static void alx_free_buffers(struct alx_priv *alx)
538 for (i = 0; i < alx->num_txq; i++)
539 if (alx->qnapi[i] && alx->qnapi[i]->txq)
540 alx_free_txring_buf(alx->qnapi[i]->txq);
542 if (alx->qnapi[0] && alx->qnapi[0]->rxq)
543 alx_free_rxring_buf(alx->qnapi[0]->rxq);
546 static int alx_reinit_rings(struct alx_priv *alx)
548 alx_free_buffers(alx);
550 alx_init_ring_ptrs(alx);
552 if (!alx_refill_rx_ring(alx, GFP_KERNEL))
571 struct alx_priv *alx = netdev_priv(netdev);
572 struct alx_hw *hw = &alx->hw;
600 struct alx_priv *alx = netdev_priv(netdev);
601 struct alx_hw *hw = &alx->hw;
617 static int alx_alloc_tx_ring(struct alx_priv *alx, struct alx_tx_queue *txq,
624 txq->tpd = alx->descmem.virt + offset;
625 txq->tpd_dma = alx->descmem.dma + offset;
631 static int alx_alloc_rx_ring(struct alx_priv *alx, struct alx_rx_queue *rxq,
638 rxq->rrd = alx->descmem.virt + offset;
639 rxq->rrd_dma = alx->descmem.dma + offset;
642 rxq->rfd = alx->descmem.virt + offset;
643 rxq->rfd_dma = alx->descmem.dma + offset;
649 static int alx_alloc_rings(struct alx_priv *alx)
659 alx->descmem.size = sizeof(struct alx_txd) * alx->tx_ringsz *
660 alx->num_txq +
661 sizeof(struct alx_rrd) * alx->rx_ringsz +
662 sizeof(struct alx_rfd) * alx->rx_ringsz;
663 alx->descmem.virt = dma_alloc_coherent(&alx->hw.pdev->dev,
664 alx->descmem.size,
665 &alx->descmem.dma, GFP_KERNEL);
666 if (!alx->descmem.virt)
673 for (i = 0; i < alx->num_txq; i++) {
674 offset = alx_alloc_tx_ring(alx, alx->qnapi[i]->txq, offset);
676 netdev_err(alx->dev, "Allocation of tx buffer failed!\n");
681 offset = alx_alloc_rx_ring(alx, alx->qnapi[0]->rxq, offset);
683 netdev_err(alx->dev, "Allocation of rx buffer failed!\n");
690 static void alx_free_rings(struct alx_priv *alx)
694 alx_free_buffers(alx);
696 for (i = 0; i < alx->num_txq; i++)
697 if (alx->qnapi[i] && alx->qnapi[i]->txq)
698 kfree(alx->qnapi[i]->txq->bufs);
700 if (alx->qnapi[0] && alx->qnapi[0]->rxq)
701 kfree(alx->qnapi[0]->rxq->bufs);
703 if (alx->descmem.virt)
704 dma_free_coherent(&alx->hw.pdev->dev,
705 alx->descmem.size,
706 alx->descmem.virt,
707 alx->descmem.dma);
710 static void alx_free_napis(struct alx_priv *alx)
715 for (i = 0; i < alx->num_napi; i++) {
716 np = alx->qnapi[i];
724 alx->qnapi[i] = NULL;
739 static int alx_alloc_napis(struct alx_priv *alx)
746 alx->int_mask &= ~ALX_ISR_ALL_QUEUES;
749 for (i = 0; i < alx->num_napi; i++) {
754 np->alx = alx;
755 netif_napi_add(alx->dev, &np->napi, alx_poll, 64);
756 alx->qnapi[i] = np;
760 for (i = 0; i < alx->num_txq; i++) {
761 np = alx->qnapi[i];
770 txq->count = alx->tx_ringsz;
771 txq->netdev = alx->dev;
772 txq->dev = &alx->hw.pdev->dev;
774 alx->int_mask |= tx_vect_mask[i];
778 np = alx->qnapi[0];
784 rxq->np = alx->qnapi[0];
786 rxq->count = alx->rx_ringsz;
787 rxq->netdev = alx->dev;
788 rxq->dev = &alx->hw.pdev->dev;
790 alx->int_mask |= rx_vect_mask[0];
795 netdev_err(alx->dev, "error allocating internal structures\n");
796 alx_free_napis(alx);
807 static void alx_config_vector_mapping(struct alx_priv *alx)
809 struct alx_hw *hw = &alx->hw;
813 if (alx->hw.pdev->msix_enabled) {
815 for (i = 0, vector = 1; i < alx->num_txq; i++, vector++) {
830 static int alx_enable_msix(struct alx_priv *alx)
838 err = pci_alloc_irq_vectors(alx->hw.pdev, num_vec, num_vec,
841 netdev_warn(alx->dev, "Enabling MSI-X interrupts failed!\n");
845 alx->num_vec = num_vec;
846 alx->num_napi = num_vec - 1;
847 alx->num_txq = num_txq;
848 alx->num_rxq = num_rxq;
853 static int alx_request_msix(struct alx_priv *alx)
855 struct net_device *netdev = alx->dev;
858 err = request_irq(pci_irq_vector(alx->hw.pdev, 0), alx_intr_msix_misc,
859 0, netdev->name, alx);
863 for (i = 0; i < alx->num_napi; i++) {
864 struct alx_napi *np = alx->qnapi[i];
881 err = request_irq(pci_irq_vector(alx->hw.pdev, vector),
889 free_irq(pci_irq_vector(alx->hw.pdev, free_vector++), alx);
893 free_irq(pci_irq_vector(alx->hw.pdev,free_vector++),
894 alx->qnapi[i]);
900 static int alx_init_intr(struct alx_priv *alx)
904 ret = pci_alloc_irq_vectors(alx->hw.pdev, 1, 1,
909 alx->num_vec = 1;
910 alx->num_napi = 1;
911 alx->num_txq = 1;
912 alx->num_rxq = 1;
916 static void alx_irq_enable(struct alx_priv *alx)
918 struct alx_hw *hw = &alx->hw;
923 alx_write_mem32(hw, ALX_IMR, alx->int_mask);
926 if (alx->hw.pdev->msix_enabled) {
928 for (i = 0; i < alx->num_vec; i++)
933 static void alx_irq_disable(struct alx_priv *alx)
935 struct alx_hw *hw = &alx->hw;
942 if (alx->hw.pdev->msix_enabled) {
943 for (i = 0; i < alx->num_vec; i++) {
945 synchronize_irq(pci_irq_vector(alx->hw.pdev, i));
948 synchronize_irq(pci_irq_vector(alx->hw.pdev, 0));
952 static int alx_realloc_resources(struct alx_priv *alx)
956 alx_free_rings(alx);
957 alx_free_napis(alx);
958 pci_free_irq_vectors(alx->hw.pdev);
960 err = alx_init_intr(alx);
964 err = alx_alloc_napis(alx);
968 err = alx_alloc_rings(alx);
975 static int alx_request_irq(struct alx_priv *alx)
977 struct pci_dev *pdev = alx->hw.pdev;
978 struct alx_hw *hw = &alx->hw;
984 if (alx->hw.pdev->msix_enabled) {
986 err = alx_request_msix(alx);
991 err = alx_realloc_resources(alx);
996 if (alx->hw.pdev->msi_enabled) {
1000 alx->dev->name, alx);
1005 pci_free_irq_vectors(alx->hw.pdev);
1010 alx->dev->name, alx);
1013 alx_config_vector_mapping(alx);
1015 netdev_err(alx->dev, "IRQ registration failed!\n");
1019 static void alx_free_irq(struct alx_priv *alx)
1021 struct pci_dev *pdev = alx->hw.pdev;
1024 free_irq(pci_irq_vector(pdev, 0), alx);
1025 if (alx->hw.pdev->msix_enabled) {
1026 for (i = 0; i < alx->num_napi; i++)
1027 free_irq(pci_irq_vector(pdev, i + 1), alx->qnapi[i]);
1033 static int alx_identify_hw(struct alx_priv *alx)
1035 struct alx_hw *hw = &alx->hw;
1046 static int alx_init_sw(struct alx_priv *alx)
1048 struct pci_dev *pdev = alx->hw.pdev;
1049 struct alx_hw *hw = &alx->hw;
1052 err = alx_identify_hw(alx);
1058 alx->hw.lnk_patch =
1065 hw->mtu = alx->dev->mtu;
1066 alx->rxbuf_size = ALX_MAX_FRAME_LEN(hw->mtu);
1068 alx->dev->min_mtu = 34;
1069 alx->dev->max_mtu = ALX_MAX_FRAME_LEN(ALX_MAX_FRAME_SIZE);
1070 alx->tx_ringsz = 256;
1071 alx->rx_ringsz = 512;
1073 alx->int_mask = ALX_ISR_MISC;
1075 hw->ith_tpd = alx->tx_ringsz / 3;
1108 static void alx_netif_stop(struct alx_priv *alx)
1112 netif_trans_update(alx->dev);
1113 if (netif_carrier_ok(alx->dev)) {
1114 netif_carrier_off(alx->dev);
1115 netif_tx_disable(alx->dev);
1116 for (i = 0; i < alx->num_napi; i++)
1117 napi_disable(&alx->qnapi[i]->napi);
1121 static void alx_halt(struct alx_priv *alx)
1123 struct alx_hw *hw = &alx->hw;
1125 alx_netif_stop(alx);
1133 alx_irq_disable(alx);
1134 alx_free_buffers(alx);
1137 static void alx_configure(struct alx_priv *alx)
1139 struct alx_hw *hw = &alx->hw;
1143 __alx_set_rx_mode(alx->dev);
1148 static void alx_activate(struct alx_priv *alx)
1151 alx_reinit_rings(alx);
1152 alx_configure(alx);
1155 alx_write_mem32(&alx->hw, ALX_ISR, ~(u32)ALX_ISR_DIS);
1157 alx_irq_enable(alx);
1159 alx_schedule_link_check(alx);
1162 static void alx_reinit(struct alx_priv *alx)
1166 alx_halt(alx);
1167 alx_activate(alx);
1172 struct alx_priv *alx = netdev_priv(netdev);
1176 alx->hw.mtu = mtu;
1177 alx->rxbuf_size = max(max_frame, ALX_DEF_RXBUF_SIZE);
1180 alx_reinit(alx);
1184 static void alx_netif_start(struct alx_priv *alx)
1188 netif_tx_wake_all_queues(alx->dev);
1189 for (i = 0; i < alx->num_napi; i++)
1190 napi_enable(&alx->qnapi[i]->napi);
1191 netif_carrier_on(alx->dev);
1194 static int __alx_open(struct alx_priv *alx, bool resume)
1198 err = alx_enable_msix(alx);
1200 err = alx_init_intr(alx);
1206 netif_carrier_off(alx->dev);
1208 err = alx_alloc_napis(alx);
1212 err = alx_alloc_rings(alx);
1216 alx_configure(alx);
1218 err = alx_request_irq(alx);
1226 alx_reinit_rings(alx);
1228 netif_set_real_num_tx_queues(alx->dev, alx->num_txq);
1229 netif_set_real_num_rx_queues(alx->dev, alx->num_rxq);
1232 alx_write_mem32(&alx->hw, ALX_ISR, ~(u32)ALX_ISR_DIS);
1234 alx_irq_enable(alx);
1237 netif_tx_start_all_queues(alx->dev);
1239 alx_schedule_link_check(alx);
1243 alx_free_rings(alx);
1244 alx_free_napis(alx);
1246 pci_free_irq_vectors(alx->hw.pdev);
1250 static void __alx_stop(struct alx_priv *alx)
1252 alx_free_irq(alx);
1254 cancel_work_sync(&alx->link_check_wk);
1255 cancel_work_sync(&alx->reset_wk);
1257 alx_halt(alx);
1258 alx_free_rings(alx);
1259 alx_free_napis(alx);
1280 static void alx_check_link(struct alx_priv *alx)
1282 struct alx_hw *hw = &alx->hw;
1297 spin_lock_irqsave(&alx->irq_lock, flags);
1298 alx->int_mask |= ALX_ISR_PHY;
1299 alx_write_mem32(hw, ALX_IMR, alx->int_mask);
1300 spin_unlock_irqrestore(&alx->irq_lock, flags);
1306 netif_info(alx, link, alx->dev,
1313 alx_netif_start(alx);
1316 alx_netif_stop(alx);
1317 netif_info(alx, link, alx->dev, "Link Down\n");
1321 alx_irq_disable(alx);
1324 err = alx_reinit_rings(alx);
1327 alx_configure(alx);
1330 alx_irq_enable(alx);
1336 alx_schedule_reset(alx);
1352 struct alx_priv *alx;
1354 alx = container_of(work, struct alx_priv, link_check_wk);
1357 alx_check_link(alx);
1363 struct alx_priv *alx = container_of(work, struct alx_priv, reset_wk);
1366 alx_reinit(alx);
1511 struct alx_priv *alx;
1515 alx = netdev_priv(txq->netdev);
1538 alx_write_mem16(&alx->hw, txq->p_reg, txq->write_idx);
1553 struct alx_priv *alx = netdev_priv(netdev);
1554 return alx_start_xmit_ring(skb, alx_tx_queue_mapping(alx, skb));
1559 struct alx_priv *alx = netdev_priv(dev);
1561 alx_schedule_reset(alx);
1567 struct alx_priv *alx = netdev_priv(netdev);
1568 struct alx_hw *hw = &alx->hw;
1588 struct alx_priv *alx = netdev_priv(netdev);
1589 struct alx_hw *hw = &alx->hw;
1602 struct alx_priv *alx = netdev_priv(netdev);
1607 return mdio_mii_ioctl(&alx->hw.mdio, if_mii(ifr), cmd);
1613 struct alx_priv *alx = netdev_priv(netdev);
1616 if (alx->hw.pdev->msix_enabled) {
1617 alx_intr_msix_misc(0, alx);
1618 for (i = 0; i < alx->num_txq; i++)
1619 alx_intr_msix_ring(0, alx->qnapi[i]);
1620 } else if (alx->hw.pdev->msi_enabled)
1621 alx_intr_msi(0, alx);
1623 alx_intr_legacy(0, alx);
1630 struct alx_priv *alx = netdev_priv(dev);
1631 struct alx_hw_stats *hw_stats = &alx->hw.stats;
1633 spin_lock(&alx->stats_lock);
1635 alx_update_hw_stats(&alx->hw);
1671 spin_unlock(&alx->stats_lock);
1694 struct alx_priv *alx;
1703 /* The alx chip can DMA to 64-bit addresses, but it uses a single
1734 netdev = alloc_etherdev_mqs(sizeof(*alx),
1742 alx = netdev_priv(netdev);
1743 spin_lock_init(&alx->hw.mdio_lock);
1744 spin_lock_init(&alx->irq_lock);
1745 spin_lock_init(&alx->stats_lock);
1746 alx->dev = netdev;
1747 alx->hw.pdev = pdev;
1748 alx->msg_enable = NETIF_MSG_LINK | NETIF_MSG_HW | NETIF_MSG_IFUP |
1750 hw = &alx->hw;
1751 pci_set_drvdata(pdev, alx);
1768 err = alx_init_sw(alx);
1830 INIT_WORK(&alx->link_check_wk, alx_link_check);
1831 INIT_WORK(&alx->reset_wk, alx_reset);
1860 struct alx_priv *alx = pci_get_drvdata(pdev);
1861 struct alx_hw *hw = &alx->hw;
1866 unregister_netdev(alx->dev);
1873 free_netdev(alx->dev);
1879 struct alx_priv *alx = dev_get_drvdata(dev);
1881 if (!netif_running(alx->dev))
1883 netif_device_detach(alx->dev);
1884 __alx_stop(alx);
1890 struct alx_priv *alx = dev_get_drvdata(dev);
1891 struct alx_hw *hw = &alx->hw;
1896 if (!netif_running(alx->dev))
1900 err = __alx_open(alx, true);
1905 netif_device_attach(alx->dev);
1920 struct alx_priv *alx = pci_get_drvdata(pdev);
1921 struct net_device *netdev = alx->dev;
1930 alx_halt(alx);
1945 struct alx_priv *alx = pci_get_drvdata(pdev);
1946 struct alx_hw *hw = &alx->hw;
1971 struct alx_priv *alx = pci_get_drvdata(pdev);
1972 struct net_device *netdev = alx->dev;
1979 alx_activate(alx);