Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tehuti: Use dma_set_mask_and_coherent() and simplify code

Use dma_set_mask_and_coherent() instead of unrolling it with some
dma_set_mask()+dma_set_coherent_mask().

Moreover, as stated in [1], dma_set_mask_and_coherent() with a 64-bit mask
will never fail if dev->dma_mask is non-NULL.
So, if it fails, the 32 bits case will also fail for the same reason.

That said, 'pci_using_dac' can only be 1 after a successful
dma_set_mask_and_coherent().

Simplify code and remove some dead code accordingly.

[1]: https://lkml.org/lkml/2021/6/7/398
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Christophe JAILLET and committed by
David S. Miller
c95e0780 c5180ad0

+10 -18
+10 -18
drivers/net/ethernet/tehuti/tehuti.c
··· 1884 1884 { 1885 1885 struct net_device *ndev; 1886 1886 struct bdx_priv *priv; 1887 - int err, pci_using_dac, port; 1888 1887 unsigned long pciaddr; 1889 1888 u32 regionSize; 1890 1889 struct pci_nic *nic; 1890 + int err, port; 1891 1891 1892 1892 ENTER; 1893 1893 ··· 1900 1900 if (err) /* it triggers interrupt, dunno why. */ 1901 1901 goto err_pci; /* it's not a problem though */ 1902 1902 1903 - if (!(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) && 1904 - !(err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)))) { 1905 - pci_using_dac = 1; 1906 - } else { 1907 - if ((err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) || 1908 - (err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)))) { 1909 - pr_err("No usable DMA configuration, aborting\n"); 1910 - goto err_dma; 1911 - } 1912 - pci_using_dac = 0; 1903 + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 1904 + if (err) { 1905 + pr_err("No usable DMA configuration, aborting\n"); 1906 + goto err_dma; 1913 1907 } 1914 1908 1915 1909 err = pci_request_regions(pdev, BDX_DRV_NAME); ··· 1976 1982 /* these fields are used for info purposes only 1977 1983 * so we can have them same for all ports of the board */ 1978 1984 ndev->if_port = port; 1979 - ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO 1980 - | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | 1981 - NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM 1982 - ; 1985 + ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO | 1986 + NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | 1987 + NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_RXCSUM | 1988 + NETIF_F_HIGHDMA; 1989 + 1983 1990 ndev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 1984 1991 NETIF_F_TSO | NETIF_F_HW_VLAN_CTAG_TX; 1985 - 1986 - if (pci_using_dac) 1987 - ndev->features |= NETIF_F_HIGHDMA; 1988 1992 1989 1993 /************** priv ****************/ 1990 1994 priv = nic->priv[port] = netdev_priv(ndev);