Commit 9aaa82d2 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Jakub Kicinski
Browse files

bna: Simplify DMA setting

As stated in [1], dma_set_mask() 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.

So, if dma_set_mask_and_coherent() succeeds, 'using_dac' is known to be
'true'. This variable can be removed.

Simplify code and remove some dead code accordingly.

[1]: https://lkml.org/lkml/2021/6/7/398



Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/1d5a7b3f4fa735f1233c3eb3fa07e71df95fad75.1641658516.git.christophe.jaillet@wanadoo.fr


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ba8a5863
Loading
Loading
Loading
Loading
+10 −24
Original line number Original line Diff line number Diff line
@@ -3421,7 +3421,7 @@ static const struct net_device_ops bnad_netdev_ops = {
};
};


static void
static void
bnad_netdev_init(struct bnad *bnad, bool using_dac)
bnad_netdev_init(struct bnad *bnad)
{
{
	struct net_device *netdev = bnad->netdev;
	struct net_device *netdev = bnad->netdev;


@@ -3434,10 +3434,8 @@ bnad_netdev_init(struct bnad *bnad, bool using_dac)
		NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
		NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
		NETIF_F_TSO | NETIF_F_TSO6;
		NETIF_F_TSO | NETIF_F_TSO6;


	netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
	netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER |

			    NETIF_F_HIGHDMA;
	if (using_dac)
		netdev->features |= NETIF_F_HIGHDMA;


	netdev->mem_start = bnad->mmio_start;
	netdev->mem_start = bnad->mmio_start;
	netdev->mem_end = bnad->mmio_start + bnad->mmio_len - 1;
	netdev->mem_end = bnad->mmio_start + bnad->mmio_len - 1;
@@ -3544,8 +3542,7 @@ bnad_lock_uninit(struct bnad *bnad)


/* PCI Initialization */
/* PCI Initialization */
static int
static int
bnad_pci_init(struct bnad *bnad,
bnad_pci_init(struct bnad *bnad, struct pci_dev *pdev)
	      struct pci_dev *pdev, bool *using_dac)
{
{
	int err;
	int err;


@@ -3555,14 +3552,9 @@ bnad_pci_init(struct bnad *bnad,
	err = pci_request_regions(pdev, BNAD_NAME);
	err = pci_request_regions(pdev, BNAD_NAME);
	if (err)
	if (err)
		goto disable_device;
		goto disable_device;
	if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
		*using_dac = true;
	} else {
		err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
	if (err)
	if (err)
		goto release_regions;
		goto release_regions;
		*using_dac = false;
	}
	pci_set_master(pdev);
	pci_set_master(pdev);
	return 0;
	return 0;


@@ -3585,7 +3577,6 @@ static int
bnad_pci_probe(struct pci_dev *pdev,
bnad_pci_probe(struct pci_dev *pdev,
		const struct pci_device_id *pcidev_id)
		const struct pci_device_id *pcidev_id)
{
{
	bool	using_dac;
	int	err;
	int	err;
	struct bnad *bnad;
	struct bnad *bnad;
	struct bna *bna;
	struct bna *bna;
@@ -3615,13 +3606,8 @@ bnad_pci_probe(struct pci_dev *pdev,
	bnad->id = atomic_inc_return(&bna_id) - 1;
	bnad->id = atomic_inc_return(&bna_id) - 1;


	mutex_lock(&bnad->conf_mutex);
	mutex_lock(&bnad->conf_mutex);
	/*
	/* PCI initialization */
	 * PCI initialization
	err = bnad_pci_init(bnad, pdev);
	 *	Output : using_dac = 1 for 64 bit DMA
	 *			   = 0 for 32 bit DMA
	 */
	using_dac = false;
	err = bnad_pci_init(bnad, pdev, &using_dac);
	if (err)
	if (err)
		goto unlock_mutex;
		goto unlock_mutex;


@@ -3634,7 +3620,7 @@ bnad_pci_probe(struct pci_dev *pdev,
		goto pci_uninit;
		goto pci_uninit;


	/* Initialize netdev structure, set up ethtool ops */
	/* Initialize netdev structure, set up ethtool ops */
	bnad_netdev_init(bnad, using_dac);
	bnad_netdev_init(bnad);


	/* Set link to down state */
	/* Set link to down state */
	netif_carrier_off(netdev);
	netif_carrier_off(netdev);