| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Tehuti Networks(R) Network Driver |
|---|
| 3 | 4 | * ethtool interface implementation |
|---|
| 4 | 5 | * Copyright (C) 2007 Tehuti Networks Ltd. All rights reserved |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | /* |
|---|
| .. | .. |
|---|
| 142 | 138 | * @priv: NIC private structure |
|---|
| 143 | 139 | * @f: fifo to initialize |
|---|
| 144 | 140 | * @fsz_type: fifo size type: 0-4KB, 1-8KB, 2-16KB, 3-32KB |
|---|
| 145 | | - * @reg_XXX: offsets of registers relative to base address |
|---|
| 141 | + * @reg_CFG0: offsets of registers relative to base address |
|---|
| 142 | + * @reg_CFG1: offsets of registers relative to base address |
|---|
| 143 | + * @reg_RPTR: offsets of registers relative to base address |
|---|
| 144 | + * @reg_WPTR: offsets of registers relative to base address |
|---|
| 146 | 145 | * |
|---|
| 147 | 146 | * 1K extra space is allocated at the end of the fifo to simplify |
|---|
| 148 | 147 | * processing of descriptors that wraps around fifo's end |
|---|
| .. | .. |
|---|
| 157 | 156 | u16 memsz = FIFO_SIZE * (1 << fsz_type); |
|---|
| 158 | 157 | |
|---|
| 159 | 158 | memset(f, 0, sizeof(struct fifo)); |
|---|
| 160 | | - /* pci_alloc_consistent gives us 4k-aligned memory */ |
|---|
| 161 | | - f->va = pci_alloc_consistent(priv->pdev, |
|---|
| 162 | | - memsz + FIFO_EXTRA_SPACE, &f->da); |
|---|
| 159 | + /* dma_alloc_coherent gives us 4k-aligned memory */ |
|---|
| 160 | + f->va = dma_alloc_coherent(&priv->pdev->dev, memsz + FIFO_EXTRA_SPACE, |
|---|
| 161 | + &f->da, GFP_ATOMIC); |
|---|
| 163 | 162 | if (!f->va) { |
|---|
| 164 | | - pr_err("pci_alloc_consistent failed\n"); |
|---|
| 163 | + pr_err("dma_alloc_coherent failed\n"); |
|---|
| 165 | 164 | RET(-ENOMEM); |
|---|
| 166 | 165 | } |
|---|
| 167 | 166 | f->reg_CFG0 = reg_CFG0; |
|---|
| .. | .. |
|---|
| 187 | 186 | { |
|---|
| 188 | 187 | ENTER; |
|---|
| 189 | 188 | if (f->va) { |
|---|
| 190 | | - pci_free_consistent(priv->pdev, |
|---|
| 191 | | - f->memsz + FIFO_EXTRA_SPACE, f->va, f->da); |
|---|
| 189 | + dma_free_coherent(&priv->pdev->dev, |
|---|
| 190 | + f->memsz + FIFO_EXTRA_SPACE, f->va, f->da); |
|---|
| 192 | 191 | f->va = NULL; |
|---|
| 193 | 192 | } |
|---|
| 194 | 193 | RET(); |
|---|
| .. | .. |
|---|
| 562 | 561 | |
|---|
| 563 | 562 | /** |
|---|
| 564 | 563 | * bdx_close - Disables a network interface |
|---|
| 565 | | - * @netdev: network interface device structure |
|---|
| 564 | + * @ndev: network interface device structure |
|---|
| 566 | 565 | * |
|---|
| 567 | 566 | * Returns 0, this is not allowed to fail |
|---|
| 568 | 567 | * |
|---|
| .. | .. |
|---|
| 589 | 588 | |
|---|
| 590 | 589 | /** |
|---|
| 591 | 590 | * bdx_open - Called when a network interface is made active |
|---|
| 592 | | - * @netdev: network interface device structure |
|---|
| 591 | + * @ndev: network interface device structure |
|---|
| 593 | 592 | * |
|---|
| 594 | 593 | * Returns 0 on success, negative value on failure |
|---|
| 595 | 594 | * |
|---|
| .. | .. |
|---|
| 702 | 701 | * __bdx_vlan_rx_vid - private helper for adding/killing VLAN vid |
|---|
| 703 | 702 | * @ndev: network device |
|---|
| 704 | 703 | * @vid: VLAN vid |
|---|
| 705 | | - * @op: add or kill operation |
|---|
| 704 | + * @enable: enable or disable vlan |
|---|
| 706 | 705 | * |
|---|
| 707 | 706 | * Passes VLAN filter table to hardware |
|---|
| 708 | 707 | */ |
|---|
| .. | .. |
|---|
| 733 | 732 | /** |
|---|
| 734 | 733 | * bdx_vlan_rx_add_vid - kernel hook for adding VLAN vid to hw filtering table |
|---|
| 735 | 734 | * @ndev: network device |
|---|
| 735 | + * @proto: unused |
|---|
| 736 | 736 | * @vid: VLAN vid to add |
|---|
| 737 | 737 | */ |
|---|
| 738 | 738 | static int bdx_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid) |
|---|
| .. | .. |
|---|
| 744 | 744 | /** |
|---|
| 745 | 745 | * bdx_vlan_rx_kill_vid - kernel hook for killing VLAN vid in hw filtering table |
|---|
| 746 | 746 | * @ndev: network device |
|---|
| 747 | + * @proto: unused |
|---|
| 747 | 748 | * @vid: VLAN vid to kill |
|---|
| 748 | 749 | */ |
|---|
| 749 | 750 | static int bdx_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid) |
|---|
| .. | .. |
|---|
| 754 | 755 | |
|---|
| 755 | 756 | /** |
|---|
| 756 | 757 | * bdx_change_mtu - Change the Maximum Transfer Unit |
|---|
| 757 | | - * @netdev: network interface device structure |
|---|
| 758 | + * @ndev: network interface device structure |
|---|
| 758 | 759 | * @new_mtu: new value for maximum frame size |
|---|
| 759 | 760 | * |
|---|
| 760 | 761 | * Returns 0 on success, negative on failure |
|---|
| .. | .. |
|---|
| 1037 | 1038 | for (i = 0; i < db->nelem; i++) { |
|---|
| 1038 | 1039 | dm = bdx_rxdb_addr_elem(db, i); |
|---|
| 1039 | 1040 | if (dm->dma) { |
|---|
| 1040 | | - pci_unmap_single(priv->pdev, |
|---|
| 1041 | | - dm->dma, f->m.pktsz, |
|---|
| 1042 | | - PCI_DMA_FROMDEVICE); |
|---|
| 1041 | + dma_unmap_single(&priv->pdev->dev, dm->dma, |
|---|
| 1042 | + f->m.pktsz, DMA_FROM_DEVICE); |
|---|
| 1043 | 1043 | dev_kfree_skb(dm->skb); |
|---|
| 1044 | 1044 | } |
|---|
| 1045 | 1045 | } |
|---|
| .. | .. |
|---|
| 1101 | 1101 | |
|---|
| 1102 | 1102 | idx = bdx_rxdb_alloc_elem(db); |
|---|
| 1103 | 1103 | dm = bdx_rxdb_addr_elem(db, idx); |
|---|
| 1104 | | - dm->dma = pci_map_single(priv->pdev, |
|---|
| 1105 | | - skb->data, f->m.pktsz, |
|---|
| 1106 | | - PCI_DMA_FROMDEVICE); |
|---|
| 1104 | + dm->dma = dma_map_single(&priv->pdev->dev, skb->data, |
|---|
| 1105 | + f->m.pktsz, DMA_FROM_DEVICE); |
|---|
| 1107 | 1106 | dm->skb = skb; |
|---|
| 1108 | 1107 | rxfd = (struct rxf_desc *)(f->m.va + f->m.wptr); |
|---|
| 1109 | 1108 | rxfd->info = CPU_CHIP_SWAP32(0x10003); /* INFO=1 BC=3 */ |
|---|
| .. | .. |
|---|
| 1263 | 1262 | (skb2 = netdev_alloc_skb(priv->ndev, len + NET_IP_ALIGN))) { |
|---|
| 1264 | 1263 | skb_reserve(skb2, NET_IP_ALIGN); |
|---|
| 1265 | 1264 | /*skb_put(skb2, len); */ |
|---|
| 1266 | | - pci_dma_sync_single_for_cpu(priv->pdev, |
|---|
| 1267 | | - dm->dma, rxf_fifo->m.pktsz, |
|---|
| 1268 | | - PCI_DMA_FROMDEVICE); |
|---|
| 1265 | + dma_sync_single_for_cpu(&priv->pdev->dev, dm->dma, |
|---|
| 1266 | + rxf_fifo->m.pktsz, |
|---|
| 1267 | + DMA_FROM_DEVICE); |
|---|
| 1269 | 1268 | memcpy(skb2->data, skb->data, len); |
|---|
| 1270 | 1269 | bdx_recycle_skb(priv, rxdd); |
|---|
| 1271 | 1270 | skb = skb2; |
|---|
| 1272 | 1271 | } else { |
|---|
| 1273 | | - pci_unmap_single(priv->pdev, |
|---|
| 1274 | | - dm->dma, rxf_fifo->m.pktsz, |
|---|
| 1275 | | - PCI_DMA_FROMDEVICE); |
|---|
| 1272 | + dma_unmap_single(&priv->pdev->dev, dm->dma, |
|---|
| 1273 | + rxf_fifo->m.pktsz, DMA_FROM_DEVICE); |
|---|
| 1276 | 1274 | bdx_rxdb_free_elem(db, rxdd->va_lo); |
|---|
| 1277 | 1275 | } |
|---|
| 1278 | 1276 | |
|---|
| .. | .. |
|---|
| 1365 | 1363 | * This technique avoids eccessive reading of RPTR and WPTR registers. |
|---|
| 1366 | 1364 | * As our benchmarks shows, it adds 1.5 Gbit/sec to NIS's throuput. |
|---|
| 1367 | 1365 | */ |
|---|
| 1368 | | - |
|---|
| 1369 | | -/************************************************************************* |
|---|
| 1370 | | - * Tx DB * |
|---|
| 1371 | | - *************************************************************************/ |
|---|
| 1372 | | -static inline int bdx_tx_db_size(struct txdb *db) |
|---|
| 1373 | | -{ |
|---|
| 1374 | | - int taken = db->wptr - db->rptr; |
|---|
| 1375 | | - if (taken < 0) |
|---|
| 1376 | | - taken = db->size + 1 + taken; /* (size + 1) equals memsz */ |
|---|
| 1377 | | - |
|---|
| 1378 | | - return db->size - taken; |
|---|
| 1379 | | -} |
|---|
| 1380 | 1366 | |
|---|
| 1381 | 1367 | /** |
|---|
| 1382 | 1368 | * __bdx_tx_db_ptr_next - helper function, increment read/write pointer + wrap |
|---|
| .. | .. |
|---|
| 1494 | 1480 | int i; |
|---|
| 1495 | 1481 | |
|---|
| 1496 | 1482 | db->wptr->len = skb_headlen(skb); |
|---|
| 1497 | | - db->wptr->addr.dma = pci_map_single(priv->pdev, skb->data, |
|---|
| 1498 | | - db->wptr->len, PCI_DMA_TODEVICE); |
|---|
| 1483 | + db->wptr->addr.dma = dma_map_single(&priv->pdev->dev, skb->data, |
|---|
| 1484 | + db->wptr->len, DMA_TO_DEVICE); |
|---|
| 1499 | 1485 | pbl->len = CPU_CHIP_SWAP32(db->wptr->len); |
|---|
| 1500 | 1486 | pbl->pa_lo = CPU_CHIP_SWAP32(L32_64(db->wptr->addr.dma)); |
|---|
| 1501 | 1487 | pbl->pa_hi = CPU_CHIP_SWAP32(H32_64(db->wptr->addr.dma)); |
|---|
| .. | .. |
|---|
| 1505 | 1491 | bdx_tx_db_inc_wptr(db); |
|---|
| 1506 | 1492 | |
|---|
| 1507 | 1493 | for (i = 0; i < nr_frags; i++) { |
|---|
| 1508 | | - const struct skb_frag_struct *frag; |
|---|
| 1494 | + const skb_frag_t *frag; |
|---|
| 1509 | 1495 | |
|---|
| 1510 | 1496 | frag = &skb_shinfo(skb)->frags[i]; |
|---|
| 1511 | 1497 | db->wptr->len = skb_frag_size(frag); |
|---|
| .. | .. |
|---|
| 1732 | 1718 | BDX_ASSERT(db->rptr->len == 0); |
|---|
| 1733 | 1719 | do { |
|---|
| 1734 | 1720 | BDX_ASSERT(db->rptr->addr.dma == 0); |
|---|
| 1735 | | - pci_unmap_page(priv->pdev, db->rptr->addr.dma, |
|---|
| 1736 | | - db->rptr->len, PCI_DMA_TODEVICE); |
|---|
| 1721 | + dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, |
|---|
| 1722 | + db->rptr->len, DMA_TO_DEVICE); |
|---|
| 1737 | 1723 | bdx_tx_db_inc_rptr(db); |
|---|
| 1738 | 1724 | } while (db->rptr->len > 0); |
|---|
| 1739 | 1725 | tx_level -= db->rptr->len; /* '-' koz len is negative */ |
|---|
| 1740 | 1726 | |
|---|
| 1741 | 1727 | /* now should come skb pointer - free it */ |
|---|
| 1742 | | - dev_kfree_skb_irq(db->rptr->addr.skb); |
|---|
| 1728 | + dev_consume_skb_irq(db->rptr->addr.skb); |
|---|
| 1743 | 1729 | bdx_tx_db_inc_rptr(db); |
|---|
| 1744 | 1730 | } |
|---|
| 1745 | 1731 | |
|---|
| .. | .. |
|---|
| 1772 | 1758 | |
|---|
| 1773 | 1759 | /** |
|---|
| 1774 | 1760 | * bdx_tx_free_skbs - frees all skbs from TXD fifo. |
|---|
| 1761 | + * @priv: NIC private structure |
|---|
| 1762 | + * |
|---|
| 1775 | 1763 | * It gets called when OS stops this dev, eg upon "ifconfig down" or rmmod |
|---|
| 1776 | 1764 | */ |
|---|
| 1777 | 1765 | static void bdx_tx_free_skbs(struct bdx_priv *priv) |
|---|
| .. | .. |
|---|
| 1781 | 1769 | ENTER; |
|---|
| 1782 | 1770 | while (db->rptr != db->wptr) { |
|---|
| 1783 | 1771 | if (likely(db->rptr->len)) |
|---|
| 1784 | | - pci_unmap_page(priv->pdev, db->rptr->addr.dma, |
|---|
| 1785 | | - db->rptr->len, PCI_DMA_TODEVICE); |
|---|
| 1772 | + dma_unmap_page(&priv->pdev->dev, db->rptr->addr.dma, |
|---|
| 1773 | + db->rptr->len, DMA_TO_DEVICE); |
|---|
| 1786 | 1774 | else |
|---|
| 1787 | 1775 | dev_kfree_skb(db->rptr->addr.skb); |
|---|
| 1788 | 1776 | bdx_tx_db_inc_rptr(db); |
|---|
| .. | .. |
|---|
| 1918 | 1906 | if (err) /* it triggers interrupt, dunno why. */ |
|---|
| 1919 | 1907 | goto err_pci; /* it's not a problem though */ |
|---|
| 1920 | 1908 | |
|---|
| 1921 | | - if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) && |
|---|
| 1922 | | - !(err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))) { |
|---|
| 1909 | + if (!(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) && |
|---|
| 1910 | + !(err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)))) { |
|---|
| 1923 | 1911 | pci_using_dac = 1; |
|---|
| 1924 | 1912 | } else { |
|---|
| 1925 | | - if ((err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) || |
|---|
| 1926 | | - (err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))) { |
|---|
| 1913 | + if ((err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) || |
|---|
| 1914 | + (err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)))) { |
|---|
| 1927 | 1915 | pr_err("No usable DMA configuration, aborting\n"); |
|---|
| 1928 | 1916 | goto err_dma; |
|---|
| 1929 | 1917 | } |
|---|
| .. | .. |
|---|
| 2378 | 2366 | static void bdx_set_ethtool_ops(struct net_device *netdev) |
|---|
| 2379 | 2367 | { |
|---|
| 2380 | 2368 | static const struct ethtool_ops bdx_ethtool_ops = { |
|---|
| 2369 | + .supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
|---|
| 2370 | + ETHTOOL_COALESCE_MAX_FRAMES, |
|---|
| 2381 | 2371 | .get_drvinfo = bdx_get_drvinfo, |
|---|
| 2382 | 2372 | .get_link = ethtool_op_get_link, |
|---|
| 2383 | 2373 | .get_coalesce = bdx_get_coalesce, |
|---|